mirror of
https://github.com/jsimonetti/rtnetlink.git
synced 2026-03-28 15:31:09 +01:00
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:
parent
192bbe2104
commit
acd79fa8ea
22
link.go
22
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,
|
||||
|
||||
30
link_test.go
30
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,
|
||||
},
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user