L3 Interfaces do not have L2 addresses (#13)

* L3 Interfaces do not have hardware addresses

* tests: L3 Interfaces do not have hardware addresses
This commit is contained in:
Ryan Whelan 2019-04-01 11:05:26 -04:00 committed by Jeroen Simonetti
parent 192bbe2104
commit acd79fa8ea
2 changed files with 28 additions and 24 deletions

22
link.go
View File

@ -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,

View File

@ -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,
},
},