From f70827b68c190e3793ace65f116fef8c7c36e752 Mon Sep 17 00:00:00 2001 From: Satoshi Fujimoto Date: Thu, 3 Aug 2017 10:44:27 +0900 Subject: server: Revised Error Handling (RFC7606) This patch enables GoBGP to keep the session established even if the received BGPUpdate message contains some errors, and to handle these errors according to what defined in RFC7606. This feature is enabled when 'treat-as-withdraw' in 'neighbors.error-handling.config' is specified to true in the GoBGP config file. Signed-off-by: Satoshi Fujimoto --- packet/bgp/bgp.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'packet') diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go index 7e60b96e..fb9e2a1c 100644 --- a/packet/bgp/bgp.go +++ b/packet/bgp/bgp.go @@ -7982,6 +7982,31 @@ func (msg *BGPUpdate) IsEndOfRib() (bool, RouteFamily) { return false, RouteFamily(0) } +func TreatAsWithdraw(msg *BGPUpdate) *BGPUpdate { + withdraw := &BGPUpdate{ + WithdrawnRoutesLen: 0, + WithdrawnRoutes: []*IPAddrPrefix{}, + TotalPathAttributeLen: 0, + PathAttributes: make([]PathAttributeInterface, 0, len(msg.PathAttributes)), + NLRI: []*IPAddrPrefix{}, + } + withdraw.WithdrawnRoutes = append(msg.WithdrawnRoutes, msg.NLRI...) + var unreach []AddrPrefixInterface + + for _, p := range msg.PathAttributes { + switch nlri := p.(type) { + case *PathAttributeMpReachNLRI: + unreach = append(unreach, nlri.Value...) + case *PathAttributeMpUnreachNLRI: + unreach = append(unreach, nlri.Value...) + } + } + if len(unreach) != 0 { + withdraw.PathAttributes = append(withdraw.PathAttributes, NewPathAttributeMpUnreachNLRI(unreach)) + } + return withdraw +} + func NewBGPUpdateMessage(withdrawnRoutes []*IPAddrPrefix, pathattrs []PathAttributeInterface, nlri []*IPAddrPrefix) *BGPMessage { return &BGPMessage{ Header: BGPHeader{Type: BGP_MSG_UPDATE}, -- cgit v1.2.3