From 1d80152c34f367cad5a467187d574bfa3b1f2d1a Mon Sep 17 00:00:00 2001 From: Kirill Smorodinnikov Date: Wed, 24 Feb 2021 14:59:31 +0300 Subject: Fix LsTLVIgpRouterID.DecodeFromBytes According to https://tools.ietf.org/html/rfc7752#section-3.2.1.4, IGPRouterID could be 4-octet for OSPFv2 or OSPFv3 non-pseudonode. --- pkg/packet/bgp/bgp.go | 9 ++++++--- pkg/packet/bgp/bgp_test.go | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'pkg/packet') diff --git a/pkg/packet/bgp/bgp.go b/pkg/packet/bgp/bgp.go index cb28bd7f..af0656d3 100644 --- a/pkg/packet/bgp/bgp.go +++ b/pkg/packet/bgp/bgp.go @@ -6298,9 +6298,12 @@ func (l *LsTLVIgpRouterID) DecodeFromBytes(data []byte) error { } // https://tools.ietf.org/html/rfc7752#section-3.2.1.4 - // 6, 7, and 8 are the only valid values. - if len(value) < 6 || len(value) > 8 { - return malformedAttrListErr("Incorrect IGP Router ID length") + // 4, 6, 7, and 8 are the only valid values. + switch len(value) { + case 4, 6, 7, 8: + break + default: + return malformedAttrListErr(fmt.Sprintf("Incorrect IGP Router ID length: %d", len(value))) } l.RouterID = value diff --git a/pkg/packet/bgp/bgp_test.go b/pkg/packet/bgp/bgp_test.go index ad313247..0e53293c 100644 --- a/pkg/packet/bgp/bgp_test.go +++ b/pkg/packet/bgp/bgp_test.go @@ -1836,6 +1836,7 @@ func Test_LsTLVIgpRouterID(t *testing.T) { want string err bool }{ + {[]byte{0x02, 0x03, 0x00, 0x04, 0x01, 0x02, 0x03, 0x04}, `{"type":515,"igp_router_id":"[1 2 3 4]"}`, false}, {[]byte{0x02, 0x03, 0x00, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06}, `{"type":515,"igp_router_id":"[1 2 3 4 5 6]"}`, false}, {[]byte{0x02, 0x03, 0x00, 0x07, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, `{"type":515,"igp_router_id":"[1 2 3 4 5 6 7]"}`, false}, {[]byte{0x02, 0x03, 0x00, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, `{"type":515,"igp_router_id":"[1 2 3 4 5 6 7 8]"}`, false}, -- cgit v1.2.3