summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--packet/bgp/bgp_test.go78
-rw-r--r--packet/bgp/validate_test.go9
2 files changed, 87 insertions, 0 deletions
diff --git a/packet/bgp/bgp_test.go b/packet/bgp/bgp_test.go
index 2c1ead8e..7afda3bc 100644
--- a/packet/bgp/bgp_test.go
+++ b/packet/bgp/bgp_test.go
@@ -153,6 +153,84 @@ func Test_RouteTargetMembershipNLRIString(t *testing.T) {
}
+func Test_MalformedUpdateMsg(t *testing.T) {
+ assert := assert.New(t)
+
+ // Invalid AGGREGATOR
+ bufin := []byte{
+ 0x00, 0x00, // Withdraws(0)
+ 0x00, 0x16, // Attrs Len(22)
+ 0xc0, 0x07, 0x05, // Flag, Type(7), Length(5)
+ 0x00, 0x00, 0x00, 0x64, // aggregator - invalid length
+ 0x00,
+ 0x40, 0x01, 0x01, 0x00, // Attr(ORIGIN)
+ 0x40, 0x03, 0x04, 0xc0, // Attr(NEXT_HOP)
+ 0xa8, 0x01, 0x64,
+ 0x40, 0x02, 0x00, // Attr(AS_PATH)
+ }
+
+ u := &BGPUpdate{}
+ err := u.DecodeFromBytes(bufin)
+ assert.Error(err)
+ assert.Equal(ERROR_HANDLING_ATTRIBUTE_DISCARD, err.(*MessageError).ErrorHandling)
+
+ // Invalid MP_REACH_NLRI
+ bufin = []byte{
+ 0x00, 0x00, // Withdraws(0)
+ 0x00, 0x27, // Attrs Len(39)
+ 0x80, 0x0e, 0x1d, // Flag, Type(14), Length(29)
+ 0x00, 0x02, 0x01, // afi(2), safi(1)
+ 0x0f, 0x00, 0x00, 0x00, // nexthop - invalid nexthop length
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0xff,
+ 0xff, 0x0a, 0x00, 0x00,
+ 0x00, // SNPA(0)
+ 0x40, 0x20, 0x01, 0x0d, // NLRI
+ 0xb8, 0x00, 0x01, 0x00,
+ 0x00,
+ 0x40, 0x01, 0x01, 0x00, // Attr(ORIGIN)
+ 0x40, 0x02, 0x00, // Attr(AS_PATH)
+ }
+
+ err = u.DecodeFromBytes(bufin)
+ assert.Error(err)
+ assert.Equal(ERROR_HANDLING_AFISAFI_DISABLE, err.(*MessageError).ErrorHandling)
+
+ // Invalid flag
+ bufin = []byte{
+ 0x00, 0x00, // Withdraws(0)
+ 0x00, 0x0e, // Attrs Len(14)
+ 0xc0, 0x01, 0x01, 0x00, // Attr(ORIGIN) - invalid flag
+ 0x40, 0x03, 0x04, 0xc0, // Attr(NEXT_HOP)
+ 0xa8, 0x01, 0x64,
+ 0x40, 0x02, 0x00, // Attr(AS_PATH)
+ }
+
+ err = u.DecodeFromBytes(bufin)
+ assert.Error(err)
+ assert.Equal(ERROR_HANDLING_TREAT_AS_WITHDRAW, err.(*MessageError).ErrorHandling)
+
+ // Invalid AGGREGATOR and MULTI_EXIT_DESC
+ bufin = []byte{
+ 0x00, 0x00, // Withdraws(0)
+ 0x00, 0x1e, // Attrs Len(30)
+ 0xc0, 0x07, 0x05, 0x00, // Attr(AGGREGATOR) - invalid length
+ 0x00, 0x00, 0x64, 0x00,
+ 0x80, 0x04, 0x05, 0x00, // Attr(MULTI_EXIT_DESC) - invalid length
+ 0x00, 0x00, 0x00, 0x64,
+ 0x40, 0x01, 0x01, 0x00, // Attr(ORIGIN)
+ 0x40, 0x02, 0x00, // Attr(AS_PATH)
+ 0x40, 0x03, 0x04, 0xc0, // Attr(NEXT_HOP)
+ 0xa8, 0x01, 0x64,
+ 0x20, 0xc8, 0xc8, 0xc8, // NLRI
+ 0xc8,
+ }
+
+ err = u.DecodeFromBytes(bufin)
+ assert.Error(err)
+ assert.Equal(ERROR_HANDLING_TREAT_AS_WITHDRAW, err.(*MessageError).ErrorHandling)
+}
+
func Test_RFC5512(t *testing.T) {
assert := assert.New(t)
diff --git a/packet/bgp/validate_test.go b/packet/bgp/validate_test.go
index 05b2fed7..2620fbb7 100644
--- a/packet/bgp/validate_test.go
+++ b/packet/bgp/validate_test.go
@@ -157,6 +157,7 @@ func Test_Validate_duplicate_attribute(t *testing.T) {
e := err.(*MessageError)
assert.Equal(uint8(BGP_ERROR_UPDATE_MESSAGE_ERROR), e.TypeCode)
assert.Equal(uint8(BGP_ERROR_SUB_MALFORMED_ATTRIBUTE_LIST), e.SubTypeCode)
+ assert.Equal(ERROR_HANDLING_ATTRIBUTE_DISCARD, e.ErrorHandling)
assert.Nil(e.Data)
}
@@ -170,6 +171,7 @@ func Test_Validate_mandatory_missing(t *testing.T) {
e := err.(*MessageError)
assert.Equal(uint8(BGP_ERROR_UPDATE_MESSAGE_ERROR), e.TypeCode)
assert.Equal(uint8(BGP_ERROR_SUB_MISSING_WELL_KNOWN_ATTRIBUTE), e.SubTypeCode)
+ assert.Equal(ERROR_HANDLING_TREAT_AS_WITHDRAW, e.ErrorHandling)
missing, _ := binary.Uvarint(e.Data)
assert.Equal(uint64(1), missing)
}
@@ -200,6 +202,7 @@ func Test_Validate_invalid_origin(t *testing.T) {
e := err.(*MessageError)
assert.Equal(uint8(BGP_ERROR_UPDATE_MESSAGE_ERROR), e.TypeCode)
assert.Equal(uint8(BGP_ERROR_SUB_INVALID_ORIGIN_ATTRIBUTE), e.SubTypeCode)
+ assert.Equal(ERROR_HANDLING_TREAT_AS_WITHDRAW, e.ErrorHandling)
assert.Equal(originBytes, e.Data)
}
@@ -221,6 +224,7 @@ func Test_Validate_invalid_nexthop_zero(t *testing.T) {
e := err.(*MessageError)
assert.Equal(uint8(BGP_ERROR_UPDATE_MESSAGE_ERROR), e.TypeCode)
assert.Equal(uint8(BGP_ERROR_SUB_INVALID_NEXT_HOP_ATTRIBUTE), e.SubTypeCode)
+ assert.Equal(ERROR_HANDLING_TREAT_AS_WITHDRAW, e.ErrorHandling)
assert.Equal(nexthopBytes, e.Data)
}
@@ -242,6 +246,7 @@ func Test_Validate_invalid_nexthop_lo(t *testing.T) {
e := err.(*MessageError)
assert.Equal(uint8(BGP_ERROR_UPDATE_MESSAGE_ERROR), e.TypeCode)
assert.Equal(uint8(BGP_ERROR_SUB_INVALID_NEXT_HOP_ATTRIBUTE), e.SubTypeCode)
+ assert.Equal(ERROR_HANDLING_TREAT_AS_WITHDRAW, e.ErrorHandling)
assert.Equal(nexthopBytes, e.Data)
}
@@ -263,6 +268,7 @@ func Test_Validate_invalid_nexthop_de(t *testing.T) {
e := err.(*MessageError)
assert.Equal(uint8(BGP_ERROR_UPDATE_MESSAGE_ERROR), e.TypeCode)
assert.Equal(uint8(BGP_ERROR_SUB_INVALID_NEXT_HOP_ATTRIBUTE), e.SubTypeCode)
+ assert.Equal(ERROR_HANDLING_TREAT_AS_WITHDRAW, e.ErrorHandling)
assert.Equal(nexthopBytes, e.Data)
}
@@ -283,6 +289,7 @@ func Test_Validate_unrecognized_well_known(t *testing.T) {
e := err.(*MessageError)
assert.Equal(uint8(BGP_ERROR_UPDATE_MESSAGE_ERROR), e.TypeCode)
assert.Equal(uint8(BGP_ERROR_SUB_UNRECOGNIZED_WELL_KNOWN_ATTRIBUTE), e.SubTypeCode)
+ assert.Equal(ERROR_HANDLING_SESSION_RESET, e.ErrorHandling)
assert.Equal(unknownBytes, e.Data)
}
@@ -316,6 +323,7 @@ func Test_Validate_aspath(t *testing.T) {
e := err.(*MessageError)
assert.Equal(uint8(BGP_ERROR_UPDATE_MESSAGE_ERROR), e.TypeCode)
assert.Equal(uint8(BGP_ERROR_SUB_MALFORMED_AS_PATH), e.SubTypeCode)
+ assert.Equal(ERROR_HANDLING_TREAT_AS_WITHDRAW, e.ErrorHandling)
assert.Nil(e.Data)
// CONFED_SEQ
@@ -339,6 +347,7 @@ func Test_Validate_aspath(t *testing.T) {
e = err.(*MessageError)
assert.Equal(uint8(BGP_ERROR_UPDATE_MESSAGE_ERROR), e.TypeCode)
assert.Equal(uint8(BGP_ERROR_SUB_MALFORMED_AS_PATH), e.SubTypeCode)
+ assert.Equal(ERROR_HANDLING_TREAT_AS_WITHDRAW, e.ErrorHandling)
assert.Nil(e.Data)
}