summaryrefslogtreecommitdiffhomepage
path: root/packet/bgp/bgp_test.go
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2018-06-21 13:41:53 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-06-21 21:17:04 +0900
commit954562d65a90af4e8d2e9bf29e4c2bccc4420b38 (patch)
treef7a52842d6545447ddc2638bad4f1a54ceb5c712 /packet/bgp/bgp_test.go
parente2752ae0bb8318920a54771c086d66cbddbd149a (diff)
packet/bgp: Fix length calc when multiple RTM NLRIs
When multiple RTM NLRIs are composed in a single MP_REACH_NLRI, the current implementation will fail to decode those NLRIs because RouteTargetMembershipNLRI.DecodeFromBytes() tests the length of the given bytes even if including the subsequent bytes. This patch fixes to cut the bytes by using the prefix length before testing the byte length. Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'packet/bgp/bgp_test.go')
-rw-r--r--packet/bgp/bgp_test.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/packet/bgp/bgp_test.go b/packet/bgp/bgp_test.go
index 697c204b..1d6f386f 100644
--- a/packet/bgp/bgp_test.go
+++ b/packet/bgp/bgp_test.go
@@ -91,7 +91,7 @@ func Test_RouteTargetMembershipNLRIString(t *testing.T) {
// TwoOctetAsSpecificExtended
buf := make([]byte, 13)
- buf[0] = 12
+ buf[0] = 96 // in bit length
binary.BigEndian.PutUint32(buf[1:5], 65546)
buf[5] = byte(EC_TYPE_TRANSITIVE_TWO_OCTET_AS_SPECIFIC) // typehigh
binary.BigEndian.PutUint16(buf[7:9], 65000)
@@ -108,6 +108,7 @@ func Test_RouteTargetMembershipNLRIString(t *testing.T) {
// IPv4AddressSpecificExtended
buf = make([]byte, 13)
+ buf[0] = 96 // in bit length
binary.BigEndian.PutUint32(buf[1:5], 65546)
buf[5] = byte(EC_TYPE_TRANSITIVE_IP4_SPECIFIC) // typehigh
ip := net.ParseIP("10.0.0.1").To4()
@@ -125,6 +126,7 @@ func Test_RouteTargetMembershipNLRIString(t *testing.T) {
// FourOctetAsSpecificExtended
buf = make([]byte, 13)
+ buf[0] = 96 // in bit length
binary.BigEndian.PutUint32(buf[1:5], 65546)
buf[5] = byte(EC_TYPE_TRANSITIVE_FOUR_OCTET_AS_SPECIFIC) // typehigh
buf[6] = byte(EC_SUBTYPE_ROUTE_TARGET) // subtype
@@ -142,6 +144,7 @@ func Test_RouteTargetMembershipNLRIString(t *testing.T) {
// OpaqueExtended
buf = make([]byte, 13)
+ buf[0] = 96 // in bit length
binary.BigEndian.PutUint32(buf[1:5], 65546)
buf[5] = byte(EC_TYPE_TRANSITIVE_OPAQUE) // typehigh
binary.BigEndian.PutUint32(buf[9:], 1000000)
@@ -157,6 +160,7 @@ func Test_RouteTargetMembershipNLRIString(t *testing.T) {
// Unknown
buf = make([]byte, 13)
+ buf[0] = 96 // in bit length
binary.BigEndian.PutUint32(buf[1:5], 65546)
buf[5] = 0x04 // typehigh
binary.BigEndian.PutUint32(buf[9:], 1000000)