diff options
author | Hiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp> | 2015-01-14 19:29:31 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-01-16 18:18:29 +0900 |
commit | 63908917a29f27e2edd0ad43fa25decf5164e038 (patch) | |
tree | f8ea351a5be48d23f253e40877e842f50d057e77 /packet/validate.go | |
parent | 2a1460623e90f461fe325fdb7c33cdd77ffe245b (diff) |
packet: do mandatory attribute check only when NLRI exists
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'packet/validate.go')
-rw-r--r-- | packet/validate.go | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/packet/validate.go b/packet/validate.go index 0b1effaf..248dbb59 100644 --- a/packet/validate.go +++ b/packet/validate.go @@ -39,23 +39,24 @@ func ValidateUpdateMsg(m *BGPUpdate) (bool, error) { } } - // check the existence of well-known mandatory attributes - exist := func(attrs []BGPAttrType) (bool, BGPAttrType) { - for _, attr := range attrs { - _, ok := seen[attr] - if !ok { - return false, attr + if len(m.NLRI) > 0 { + // check the existence of well-known mandatory attributes + exist := func(attrs []BGPAttrType) (bool, BGPAttrType) { + for _, attr := range attrs { + _, ok := seen[attr] + if !ok { + return false, attr + } } + return true, 0 + } + mandatory := []BGPAttrType{BGP_ATTR_TYPE_ORIGIN, BGP_ATTR_TYPE_AS_PATH, 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)} + return false, NewMessageError(eCode, eSubCodeMissing, data, eMsg) } - return true, 0 - } - mandatory := []BGPAttrType{BGP_ATTR_TYPE_ORIGIN, BGP_ATTR_TYPE_AS_PATH, 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)} - return false, NewMessageError(eCode, eSubCodeMissing, data, eMsg) } - return true, nil } |