From acd79fa8ea1ec664377cdbca68ee7bdc8861976e Mon Sep 17 00:00:00 2001 From: Ryan Whelan <4249368+rwhelan@users.noreply.github.com> Date: Mon, 1 Apr 2019 11:05:26 -0400 Subject: [PATCH] L3 Interfaces do not have L2 addresses (#13) * L3 Interfaces do not have hardware addresses * tests: L3 Interfaces do not have hardware addresses --- link.go | 22 ++++++++++++++-------- link_test.go | 30 ++++++++++++++---------------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/link.go b/link.go index 59aa71e..4844c35 100644 --- a/link.go +++ b/link.go @@ -327,14 +327,6 @@ func (a *LinkAttributes) MarshalBinary() ([]byte, error) { Type: iflaUnspec, Data: nlenc.Uint16Bytes(0), }, - { - Type: iflaAddress, - Data: a.Address, - }, - { - Type: iflaBroadcast, - Data: a.Broadcast, - }, { Type: iflaIfname, Data: nlenc.Bytes(a.Name), @@ -359,6 +351,20 @@ func (a *LinkAttributes) MarshalBinary() ([]byte, error) { */ } + if len(a.Address) != 0 { + attrs = append(attrs, netlink.Attribute{ + Type: iflaAddress, + Data: a.Address, + }) + } + + if len(a.Broadcast) != 0 { + attrs = append(attrs, netlink.Attribute{ + Type: iflaBroadcast, + Data: a.Broadcast, + }) + } + if a.OperationalState != OperStateUnknown { attrs = append(attrs, netlink.Attribute{ Type: iflaOperState, diff --git a/link_test.go b/link_test.go index 52c8321..004c1d3 100644 --- a/link_test.go +++ b/link_test.go @@ -20,7 +20,6 @@ func TestLinkMessageMarshalBinary(t *testing.T) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x01, 0x00, 0x04, 0x00, 0x02, 0x00, 0x05, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -40,7 +39,6 @@ func TestLinkMessageMarshalBinary(t *testing.T) { 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x01, 0x00, 0x04, 0x00, 0x02, 0x00, 0x05, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -51,8 +49,8 @@ func TestLinkMessageMarshalBinary(t *testing.T) { name: "attributes", m: &LinkMessage{ Attributes: LinkAttributes{ - Address: []byte{0, 0, 0, 0, 0, 0}, - Broadcast: []byte{0, 0, 0, 0, 0, 0}, + Address: []byte{0x40, 0x41, 0x42, 0x43, 0x44, 0x45}, + Broadcast: []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, Name: "lo", }, }, @@ -60,13 +58,13 @@ func TestLinkMessageMarshalBinary(t *testing.T) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x02, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x03, 0x00, 0x6c, 0x6f, 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, + 0x0a, 0x00, 0x01, 0x00, 0x40, 0x41, 0x42, 0x43, + 0x44, 0x45, 0x00, 0x00, 0x0a, 0x00, 0x02, 0x00, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, }, }, { @@ -82,13 +80,13 @@ func TestLinkMessageMarshalBinary(t *testing.T) { 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, + 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, + 0x0a, 0x00, 0x00, 0x01, 0x08, 0x00, 0x02, 0x00, + 0xff, 0xff, 0xff, 0xff, }, }, { @@ -110,13 +108,13 @@ func TestLinkMessageMarshalBinary(t *testing.T) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x02, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x03, 0x00, 0x6c, 0x6f, 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, + 0x0a, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x02, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x12, 0x00, 0x09, 0x00, 0x01, 0x00, 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x02, 0x00, 0x01, 0x02, 0x03, 0x04, @@ -140,13 +138,13 @@ func TestLinkMessageMarshalBinary(t *testing.T) { 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, 0x05, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, + 0x0a, 0x00, 0x00, 0x01, 0x08, 0x00, 0x02, 0x00, + 0xff, 0xff, 0xff, 0xff, 0x05, 0x00, 0x10, 0x00, 0x06, 0x00, 0x00, 0x00, }, },