From cf5ccfb00d9715f051dd001cdef5ab2ba9b89086 Mon Sep 17 00:00:00 2001 From: Nikhil Malik Date: Tue, 27 Feb 2024 10:48:50 +0900 Subject: [PATCH] BFD config auto-apply on restart --- api/loxinlp/nlp.go | 21 +++++++++++++++++++++ loxinet/loxinet.go | 9 ++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/api/loxinlp/nlp.go b/api/loxinlp/nlp.go index dd8296c87..a84c1b381 100644 --- a/api/loxinlp/nlp.go +++ b/api/loxinlp/nlp.go @@ -217,6 +217,27 @@ func applyEPConfig() bool { return true } +func ApplyBFDConfig() bool { + var resp struct { + Attr []cmn.BFDMod `json:"Attr"` + } + byteBuf, err := os.ReadFile("/etc/loxilb/BFDconfig.txt") + if err != nil { + fmt.Println(err.Error()) + return false + } + + // Unmashal to Json + if err := json.Unmarshal(byteBuf, &resp); err != nil { + fmt.Printf("Error: Failed to unmarshal File: (%s)\n", err.Error()) + return false + } + for _, bfd := range resp.Attr { + hooks.NetBFDAdd(&bfd) + } + return true +} + func applyRoutes(name string) { tk.LogIt(tk.LogDebug, "[NLP] Applying Route Config for %s \n", name) command := "loxicmd apply --per-intf " + name + " -r -c /etc/loxilb/ipconfig/" diff --git a/loxinet/loxinet.go b/loxinet/loxinet.go index 014eb634c..90868079c 100644 --- a/loxinet/loxinet.go +++ b/loxinet/loxinet.go @@ -301,9 +301,16 @@ func loxiNetInit() { prometheus.Init() } - if !opts.Opts.BgpPeerMode { + if !opts.Opts.BgpPeerMode && clusterMode { // Spawn CI maintenance application mh.has.CISpawn() + if _, err := os.Stat("/etc/loxilb/BFDconfig.txt"); errors.Is(err, os.ErrNotExist) { + if err != nil { + tk.LogIt(tk.LogInfo, "[Init] No BFD config file : %s \n", err.Error()) + } + } else { + nlp.ApplyBFDConfig() + } } // Initialize the loxinet global ticker(s) mh.tDone = make(chan bool)