summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--packet/validate.go29
-rw-r--r--packet/validate_test.go11
2 files changed, 26 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
}
diff --git a/packet/validate_test.go b/packet/validate_test.go
index 801c3868..90d05548 100644
--- a/packet/validate_test.go
+++ b/packet/validate_test.go
@@ -136,6 +136,17 @@ func Test_Validate_mandatory_missing(t *testing.T) {
assert.Equal(1, missing)
}
+func Test_Validate_mandatory_missing_nocheck(t *testing.T) {
+ assert := assert.New(t)
+ message := bgpupdate().Body.(*BGPUpdate)
+ message.PathAttributes = message.PathAttributes[1:]
+ message.NLRI = nil
+
+ res, err := ValidateUpdateMsg(message)
+ assert.Equal(true, res)
+ assert.NoError(err)
+}
+
func Test_Validate_invalid_origin(t *testing.T) {
assert := assert.New(t)
message := bgpupdate().Body.(*BGPUpdate)