From 340c151122130b987f4d9417fd29c2f85ac20a81 Mon Sep 17 00:00:00 2001 From: Trekkie Coder Date: Thu, 29 Feb 2024 18:47:24 +0900 Subject: [PATCH] gh-558 Added some arbitration to breakout of split-brain --- proto/bfd.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/proto/bfd.go b/proto/bfd.go index 960836edc..dbd458ac3 100644 --- a/proto/bfd.go +++ b/proto/bfd.go @@ -50,6 +50,7 @@ const ( BFDMinSysTXIntervalUs = 100000 BFDDflSysTXIntervalUs = 200000 BFDMinSysRXIntervalUs = 200000 + BFDIncrDiscVal = 0x10000000 ) type ConfigArgs struct { @@ -82,6 +83,7 @@ type bfdSession struct { Instance string Cxn net.Conn State SessionState + CiState string MyMulti uint8 RemMulti uint8 MyIP net.IP @@ -308,6 +310,12 @@ func (b *bfdSession) RunSessionSM(raw *WireRaw) { tk.LogIt(tk.LogInfo, "%s: BFD State -> UP\n", b.RemoteName) } b.State = BFDUp + if b.CiState == "MASTER" { + // Force reelection + if b.MyDisc <= b.RemDisc { + oldState = BFDDown + } + } } newState := b.State b.Mutex.Unlock() @@ -324,8 +332,8 @@ func (b *bfdSession) checkSessTimeout() { if b.State == BFDUp { if time.Duration(time.Since(b.LastRxTS).Microseconds()) > time.Duration(b.TimeOut) { b.State = BFDDown - b.MyDisc = b.RemDisc + 100 - tk.LogIt(tk.LogInfo, "%s: BFD State -> Down\n", b.RemoteName) + b.MyDisc = b.RemDisc + BFDIncrDiscVal + tk.LogIt(tk.LogInfo, "%s: BFD State -> Down (%v:%v)\n", b.RemoteName, b.MyDisc, b.RemDisc) } } newState := b.State @@ -344,12 +352,17 @@ func (b *bfdSession) sendStateNotification(newState, oldState SessionState, inst if b.MyDisc > b.RemDisc { ciState = "MASTER" } + tk.LogIt(tk.LogInfo, "%s: State change (%v:%v)\n", b.RemoteName, b.MyDisc, b.RemDisc) + b.CiState = ciState b.Notify.BFDSessionNotify(inst, remote, ciState) } else if newState == BFDDown && oldState == BFDUp { ciState := "MASTER" + b.CiState = ciState b.Notify.BFDSessionNotify(inst, remote, ciState) } else if b.RemDisc == b.MyDisc { - b.Notify.BFDSessionNotify(inst, remote, "NOT_DEFINED") + ciState := "NOT_DEFINED" + b.CiState = ciState + b.Notify.BFDSessionNotify(inst, remote, ciState) } }