Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions protocols/bgp/server/fsm_open_sent.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ func (s *openSentState) openMsgReceived(openMsg *packet.BGPOpen) (state, string)
return s.handleOpenMessage(openMsg)
}

// RFC6286, Sect 2.2: If the BGP Identifier field of the OPEN message is zero,
// or if it is the same as the BGP Identifier of the local BGP speaker and the
// message is from an internal peer, then the Error Subcode is set to "Bad BGP Identifier".
if openMsg.BGPIdentifier == 0 || (s.fsm.peer.localASN == s.fsm.peer.peerASN && s.fsm.peer.routerID == openMsg.BGPIdentifier) {
s.fsm.sendNotification(packet.OpenMessageError, packet.BadBGPIdentifier)
return newIdleState(s.fsm), fmt.Sprintf("Bad BGP Identifier %d", openMsg.BGPIdentifier)
}


stopTimer(s.fsm.connectRetryTimer)
if s.fsm.peer.collisionHandling(s.fsm) {
return s.cease()
Expand Down
20 changes: 19 additions & 1 deletion protocols/bgp/server/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func (p *peer) collisionHandling(callingFSM *FSM) bool {
continue
}

if p.routerID < callingFSM.neighborID {
if p.shouldCeaseOnCollision(callingFSM) {
fsm.cease()
} else {
return true
Expand All @@ -244,6 +244,24 @@ func (p *peer) collisionHandling(callingFSM *FSM) bool {
return false
}

func (p *peer) shouldCeaseOnCollision(callingFSM *FSM) bool {
// RFC6286: For a BGP speaker that supports the AS-wide Unique BGP Identifier,
// the procedures for connection collision resolution are extended as
// follows to deal with the case in which the two BGP speakers share the
// same BGP Identifier (thus, it is only applicable to an external
// peer):
//
// If the BGP Identifiers of the peers involved in the connection
// collision are identical, then the connection initiated by the BGP
// speaker with the larger AS number is preserved.
if p.routerID == callingFSM.neighborID {
return p.localASN < callingFSM.peer.peerASN
}

// RFC4271 collision handling
return p.routerID < callingFSM.neighborID
}

func isOpenConfirmState(s state) bool {
switch s.(type) {
case openConfirmState:
Expand Down
3 changes: 2 additions & 1 deletion route/bgp_path_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ func (bgpc *bgpPathACache) get(p *BGPPathA) *BGPPathA {
return x
}

bgpc.cache[*p] = p
bgpc.cache[p] = p

bgpc.cacheMu.Unlock()
return p
}