diff --git a/link.go b/link.go index 88b822f..a5c07ca 100644 --- a/link.go +++ b/link.go @@ -217,12 +217,14 @@ func (a *LinkAttributes) UnmarshalBinary(b []byte) error { case iflaUnspec: //unused attribute case iflaAddress: - if len(attr.Data) != 6 { + l := len(attr.Data) + if l < 4 || l > 32 { return errInvalidLinkMessageAttr } a.Address = attr.Data case iflaBroadcast: - if len(attr.Data) != 6 { + l := len(attr.Data) + if l < 4 || l > 32 { return errInvalidLinkMessageAttr } a.Broadcast = attr.Data diff --git a/link_test.go b/link_test.go index 2c6d8ad..e245533 100644 --- a/link_test.go +++ b/link_test.go @@ -69,6 +69,28 @@ func TestLinkMessageMarshalBinary(t *testing.T) { 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, }, }, + { + name: "attributes ipip", + m: &LinkMessage{ + Attributes: LinkAttributes{ + Address: []byte{10, 0, 0, 1}, + Broadcast: []byte{255, 255, 255, 255}, + Name: "ipip", + }, + }, + b: []byte{ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x00, 0x01, + 0x08, 0x00, 0x02, 0x00, 0xff, 0xff, 0xff, 0xff, + 0x09, 0x00, 0x03, 0x00, 0x69, 0x70, 0x69, 0x70, + 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x05, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, + 0x00, 0x00, 0x00, 0x00, + }, + }, } for _, tt := range tests { @@ -188,6 +210,28 @@ func TestLinkMessageUnmarshalBinary(t *testing.T) { }, }, }, + { + name: "attributes ipip", + b: []byte{ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x00, 0x01, + 0x08, 0x00, 0x02, 0x00, 0xff, 0xff, 0xff, 0xff, + 0x09, 0x00, 0x03, 0x00, 0x69, 0x70, 0x69, 0x70, + 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x05, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, + 0x00, 0x00, 0x00, 0x00, + }, + m: &LinkMessage{ + Attributes: LinkAttributes{ + Address: []byte{10, 0, 0, 1}, + Broadcast: []byte{255, 255, 255, 255}, + Name: "ipip", + }, + }, + }, } for _, tt := range tests {