diff options
author | Eiichiro Watanabe <a16tochjp@gmail.com> | 2019-03-21 15:55:10 +0900 |
---|---|---|
committer | Eiichiro Watanabe <a16tochjp@gmail.com> | 2019-03-21 15:57:00 +0900 |
commit | 344f053729fa0f742ba949a863d5b40b11275667 (patch) | |
tree | d9650e1d5e131d293897714203b9d73f193c6780 /pkg | |
parent | 276518c8269a2403bf79cdeba7c33b644c238214 (diff) |
pkg/packt/bgp: add test when receiving an update with invalid AS_PATH Length
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/packet/bgp/bgp_test.go | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/pkg/packet/bgp/bgp_test.go b/pkg/packet/bgp/bgp_test.go index 43bf73a0..2f4b4588 100644 --- a/pkg/packet/bgp/bgp_test.go +++ b/pkg/packet/bgp/bgp_test.go @@ -176,9 +176,30 @@ func Test_RouteTargetMembershipNLRIString(t *testing.T) { func Test_MalformedUpdateMsg(t *testing.T) { assert := assert.New(t) + var bufin []byte + var u *BGPUpdate + var err error + + // Invalid AS_PATH + bufin = []byte{ + 0x00, 0x00, // Withdraws(0) + 0x00, 0x16, // Attrs Len(22) + 0x40, 0x01, 0x01, 0x00, // Attr(ORIGIN) + 0x40, 0x03, 0x04, 0xc0, // Attr(NEXT_HOP) + 0xa8, 0x01, 0x64, + 0x40, 0x02, 0x17, // Attr(AS_PATH) - invalid length + 0x02, 0x03, 0xfd, 0xe8, + 0xfd, 0xe8, 0xfd, 0xe8, + 0x08, 0x0a, // NLRI + } + + u = &BGPUpdate{} + err = u.DecodeFromBytes(bufin) + assert.Error(err) + assert.Equal(ERROR_HANDLING_TREAT_AS_WITHDRAW, err.(*MessageError).ErrorHandling) // Invalid AGGREGATOR - bufin := []byte{ + bufin = []byte{ 0x00, 0x00, // Withdraws(0) 0x00, 0x16, // Attrs Len(22) 0xc0, 0x07, 0x05, // Flag, Type(7), Length(5) @@ -190,8 +211,8 @@ func Test_MalformedUpdateMsg(t *testing.T) { 0x40, 0x02, 0x00, // Attr(AS_PATH) } - u := &BGPUpdate{} - err := u.DecodeFromBytes(bufin) + u = &BGPUpdate{} + err = u.DecodeFromBytes(bufin) assert.Error(err) assert.Equal(ERROR_HANDLING_ATTRIBUTE_DISCARD, err.(*MessageError).ErrorHandling) |