From f662b657abc3341d32eeba302d776ecada28e852 Mon Sep 17 00:00:00 2001 From: Satoshi Fujimoto Date: Fri, 4 Aug 2017 15:15:01 +0900 Subject: [PATCH] bgp/validate: Check Wellknown Attributes exist with MultiProtocol RFC4760 says "An UPDATE message that carries the MP_REACH_NLRI MUST also carry the ORIGIN and the AS_PATH attributes". This patch adds a validation to comply with it. Signed-off-by: Satoshi Fujimoto --- packet/bgp/validate.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packet/bgp/validate.go b/packet/bgp/validate.go index 77a125b9..be44e605 100644 --- a/packet/bgp/validate.go +++ b/packet/bgp/validate.go @@ -37,7 +37,7 @@ func ValidateUpdateMsg(m *BGPUpdate, rfs map[RouteFamily]BGPAddPathMode, doConfe } } - if len(m.NLRI) > 0 { + if _, ok := seen[BGP_ATTR_TYPE_MP_REACH_NLRI]; ok || len(m.NLRI) > 0 { // check the existence of well-known mandatory attributes exist := func(attrs []BGPAttrType) (bool, BGPAttrType) { for _, attr := range attrs { @@ -48,7 +48,10 @@ func ValidateUpdateMsg(m *BGPUpdate, rfs map[RouteFamily]BGPAddPathMode, doConfe } return true, 0 } - mandatory := []BGPAttrType{BGP_ATTR_TYPE_ORIGIN, BGP_ATTR_TYPE_AS_PATH, BGP_ATTR_TYPE_NEXT_HOP} + mandatory := []BGPAttrType{BGP_ATTR_TYPE_ORIGIN, BGP_ATTR_TYPE_AS_PATH} + if len(m.NLRI) > 0 { + mandatory = append(mandatory, BGP_ATTR_TYPE_NEXT_HOP) + } if ok, t := exist(mandatory); !ok { eMsg := "well-known mandatory attributes are not present. type : " + strconv.Itoa(int(t)) data := []byte{byte(t)}