Skip to content

Commit

Permalink
Fix LsTLVIgpRouterID.DecodeFromBytes
Browse files Browse the repository at this point in the history
According to https://tools.ietf.org/html/rfc7752#section-3.2.1.4, IGPRouterID could be 4-octet for OSPFv2 or OSPFv3 non-pseudonode.
  • Loading branch information
shaitan authored and fujita committed Mar 1, 2021
1 parent f331484 commit 1d80152
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/packet/bgp/bgp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/packet/bgp/bgp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit 1d80152

Please sign in to comment.