diff --git a/protocols/bgp/server/fsm_established.go b/protocols/bgp/server/fsm_established.go index 9c14c322bd63df84c19563caa0a4d40adcae81ff..3d973b61edb6cbe8ce5abece9b63ef9a098207b7 100644 --- a/protocols/bgp/server/fsm_established.go +++ b/protocols/bgp/server/fsm_established.go @@ -222,14 +222,7 @@ func (s *establishedState) updates(u *packet.BGPUpdate) { for r := u.NLRI; r != nil; r = r.Next { pfx := bnet.NewPfx(bnet.IPv4(r.IP), r.Pfxlen) - path := &route.Path{ - Type: route.BGPPathType, - BGPPath: &route.BGPPath{ - Source: s.fsm.peer.addr, - EBGP: s.fsm.peer.localASN != s.fsm.peer.peerASN, - }, - } - + path := s.newRoutePath() s.processAttributes(u.PathAttributes, path) s.fsm.adjRIBIn.AddPath(pfx, path) @@ -237,14 +230,11 @@ func (s *establishedState) updates(u *packet.BGPUpdate) { } func (s *establishedState) multiProtocolUpdates(u *packet.BGPUpdate) { - path := &route.Path{ - Type: route.BGPPathType, - BGPPath: &route.BGPPath{ - Source: s.fsm.peer.addr, - EBGP: s.fsm.peer.localASN != s.fsm.peer.peerASN, - }, + if !s.fsm.options.SupportsMultiProtocol { + return } + path := s.newRoutePath() s.processAttributes(u.PathAttributes, path) for pa := u.PathAttributes; pa != nil; pa = pa.Next { @@ -257,6 +247,16 @@ func (s *establishedState) multiProtocolUpdates(u *packet.BGPUpdate) { } } +func (s *establishedState) newRoutePath() *route.Path { + return &route.Path{ + Type: route.BGPPathType, + BGPPath: &route.BGPPath{ + Source: s.fsm.peer.addr, + EBGP: s.fsm.peer.localASN != s.fsm.peer.peerASN, + }, + } +} + func (s *establishedState) multiProtocolUpdate(path *route.Path, nlri packet.MultiProtocolReachNLRI) { for _, pfx := range nlri.Prefixes { s.fsm.adjRIBIn.AddPath(pfx, path)