diff options
-rw-r--r-- | server/peer.go | 9 | ||||
-rw-r--r-- | table/adj.go | 2 | ||||
-rw-r--r-- | table/message.go | 3 | ||||
-rw-r--r-- | table/path.go | 19 | ||||
-rw-r--r-- | table/table_manager.go | 5 |
5 files changed, 36 insertions, 2 deletions
diff --git a/server/peer.go b/server/peer.go index 0ac082d3..5b4fd701 100644 --- a/server/peer.go +++ b/server/peer.go @@ -93,6 +93,10 @@ func (peer *Peer) isRouteReflectorClient() bool { return peer.conf.RouteReflector.Config.RouteReflectorClient } +func (peer *Peer) isGracefulRestartEnabled() bool { + return peer.fsm.pConf.GracefulRestart.State.Enabled +} + func (peer *Peer) configuredRFlist() []bgp.RouteFamily { rfs, _ := config.AfiSafis(peer.conf.AfiSafis).ToRfList() return rfs @@ -126,6 +130,11 @@ func (peer *Peer) getBestFromLocal(rfList []bgp.RouteFamily) ([]*table.Path, []* } pathList = append(pathList, p) } + if peer.isGracefulRestartEnabled() { + for _, family := range rfList { + pathList = append(pathList, table.NewEOR(family)) + } + } return pathList, filtered } diff --git a/table/adj.go b/table/adj.go index 9e88e155..77660fab 100644 --- a/table/adj.go +++ b/table/adj.go @@ -42,7 +42,7 @@ func NewAdjRib(id string, rfList []bgp.RouteFamily, isCollector bool) *AdjRib { func (adj *AdjRib) Update(pathList []*Path) { for _, path := range pathList { - if path == nil { + if path == nil || path.IsEOR() { continue } rf := path.GetRouteFamily() diff --git a/table/message.go b/table/message.go index 02cdaf3b..23f278bb 100644 --- a/table/message.go +++ b/table/message.go @@ -282,6 +282,9 @@ func CreateUpdateMsgFromPaths(pathList []*Path) []*bgp.BGPMessage { for _, path := range pathList { if path == nil { continue + } else if path.IsEOR() { + msgs = append(msgs, bgp.NewEndOfRib(path.GetRouteFamily())) + continue } y := func(p *Path) bool { if p.GetRouteFamily() != bgp.RF_IPv4_UC { diff --git a/table/path.go b/table/path.go index 3837333f..bb3eb7a3 100644 --- a/table/path.go +++ b/table/path.go @@ -54,6 +54,7 @@ type originInfo struct { isFromZebra bool key string uuid []byte + eor bool } type Path struct { @@ -89,6 +90,24 @@ func NewPath(source *PeerInfo, nlri bgp.AddrPrefixInterface, isWithdraw bool, pa } } +func NewEOR(family bgp.RouteFamily) *Path { + afi, safi := bgp.RouteFamilyToAfiSafi(family) + nlri, _ := bgp.NewPrefixFromRouteFamily(afi, safi) + return &Path{ + info: &originInfo{ + nlri: nlri, + eor: true, + }, + } +} + +func (path *Path) IsEOR() bool { + if path.info != nil && path.info.eor { + return true + } + return false +} + func cloneAsPath(asAttr *bgp.PathAttributeAsPath) *bgp.PathAttributeAsPath { newASparams := make([]bgp.AsPathParamInterface, len(asAttr.Value)) for i, param := range asAttr.Value { diff --git a/table/table_manager.go b/table/table_manager.go index ebfd0beb..afb4deac 100644 --- a/table/table_manager.go +++ b/table/table_manager.go @@ -105,6 +105,9 @@ func ProcessMessage(m *bgp.BGPMessage, peerInfo *PeerInfo, timestamp time.Time) pathList = append(pathList, withdraw2Path(m, peerInfo, timestamp)...) pathList = append(pathList, mpreachNlri2Path(m, peerInfo, timestamp)...) pathList = append(pathList, mpunreachNlri2Path(m, peerInfo, timestamp)...) + if y, f := m.Body.(*bgp.BGPUpdate).IsEndOfRib(); y { + pathList = append(pathList, NewEOR(f)) + } return pathList } @@ -236,7 +239,7 @@ func (manager *TableManager) ProcessPaths(pathList []*Path) []*Destination { m := make(map[string]bool, len(pathList)) dsts := make([]*Destination, 0, len(pathList)) for _, path := range pathList { - if path == nil { + if path == nil || path.IsEOR() { continue } rf := path.GetRouteFamily() |