From cf5ccfb00d9715f051dd001cdef5ab2ba9b89086 Mon Sep 17 00:00:00 2001 From: Nikhil Malik Date: Tue, 27 Feb 2024 10:48:50 +0900 Subject: [PATCH 1/3] 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) From e5312870418495c12c547272bdce47363bd09f70 Mon Sep 17 00:00:00 2001 From: Nikhil Malik Date: Tue, 27 Feb 2024 12:17:12 +0900 Subject: [PATCH 2/3] BFD config update after start BFD --- loxinet/cluster.go | 8 ++++++++ loxinet/loxinet.go | 7 ------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/loxinet/cluster.go b/loxinet/cluster.go index 03938ddc7..0bb002e5a 100644 --- a/loxinet/cluster.go +++ b/loxinet/cluster.go @@ -22,6 +22,7 @@ import ( "net" "os" "time" + nlp "github.com/loxilb-io/loxilb/api/loxinlp" cmn "github.com/loxilb-io/loxilb/common" opts "github.com/loxilb-io/loxilb/options" @@ -108,6 +109,13 @@ func (ci *CIStateH) startBFDProto() { os.Exit(1) } tk.LogIt(tk.LogInfo, "KA - Added BFD remote %s:%s:%vus\n", ci.RemoteIP.String(), ci.SourceIP.String(), txInterval) + 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() + } } // CITicker - Periodic ticker for Cluster module diff --git a/loxinet/loxinet.go b/loxinet/loxinet.go index 90868079c..6f2c8bc0f 100644 --- a/loxinet/loxinet.go +++ b/loxinet/loxinet.go @@ -304,13 +304,6 @@ func loxiNetInit() { 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) From 71317eee9577df09a8aba10d11ac6c7f4e05e509 Mon Sep 17 00:00:00 2001 From: UltraInstinct14 Date: Tue, 27 Feb 2024 12:34:35 +0900 Subject: [PATCH 3/3] Update loxinet.go --- loxinet/loxinet.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loxinet/loxinet.go b/loxinet/loxinet.go index 6f2c8bc0f..014eb634c 100644 --- a/loxinet/loxinet.go +++ b/loxinet/loxinet.go @@ -301,7 +301,7 @@ func loxiNetInit() { prometheus.Init() } - if !opts.Opts.BgpPeerMode && clusterMode { + if !opts.Opts.BgpPeerMode { // Spawn CI maintenance application mh.has.CISpawn() }