diff --git a/ipvs/ipvs_test.go b/ipvs/ipvs_test.go index d5f6476..ad9f270 100644 --- a/ipvs/ipvs_test.go +++ b/ipvs/ipvs_test.go @@ -26,6 +26,12 @@ import ( "github.com/google/seesaw/netlink" ) +// Old versions of libnl didn't set NLA_F_TESTED to indicate nested attributes. +// For now let's accept both formats in tests by forcing NLA_F_TESTED on. +func fixNestedAttrs(b []byte) { + b[23] |= 0x80 +} + var testStats = Stats{ Connections: 1234, PacketsIn: 100000, @@ -396,7 +402,7 @@ var ( nlmIPVSAddDestination = []byte{ 0x6c, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x01, 0x00, 0x00, 0x58, 0x00, 0x02, 0x00, + 0x01, 0x01, 0x00, 0x00, 0x58, 0x00, 0x02, 0x80, 0x14, 0x00, 0x01, 0x00, 0x20, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xca, 0xfe, 0x06, 0x00, 0x02, 0x00, @@ -441,7 +447,7 @@ var ( nlmIPVSAddService = []byte{ 0x68, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x01, 0x00, 0x00, 0x54, 0x00, 0x01, 0x00, + 0x01, 0x01, 0x00, 0x00, 0x54, 0x00, 0x01, 0x80, 0x06, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x06, 0x00, 0x02, 0x00, 0x06, 0x00, 0x00, 0x00, 0x14, 0x00, 0x03, 0x00, 0x01, 0x01, 0x01, 0x01, @@ -539,6 +545,7 @@ func TestDestinationNetlinkMarshal(t *testing.T) { if err != nil { t.Fatalf("Failed to get message bytes: %v", err) } + fixNestedAttrs(got) if want := nlmIPVSAddDestination; !bytes.Equal(got, want) { t.Errorf("Got netlink bytes %#v, want %#v", got, want) } @@ -579,6 +586,7 @@ func TestServiceNetlinkMarshal(t *testing.T) { if err != nil { t.Fatalf("Failed to get message bytes: %v", err) } + fixNestedAttrs(got) if want := nlmIPVSAddService; !bytes.Equal(got, want) { t.Errorf("Got netlink bytes %#v, want %#v", got, want) } diff --git a/netlink/message_test.go b/netlink/message_test.go index 2164857..e46164e 100644 --- a/netlink/message_test.go +++ b/netlink/message_test.go @@ -67,6 +67,12 @@ type ipvsIPAddr struct { IP net.IP `netlink:"attr:1"` } +// Old versions of libnl didn't set NLA_F_TESTED to indicate nested attributes. +// For now let's accept both formats in tests by forcing NLA_F_TESTED on. +func fixNestedAttrs(b []byte) { + b[23] |= 0x80 +} + var ( nlmIPVSInfo = []byte{ 0x24, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, @@ -79,7 +85,7 @@ var ( nlmIPVSAddService = []byte{ 0x68, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x01, 0x00, 0x00, 0x54, 0x00, 0x01, 0x00, + 0x01, 0x01, 0x00, 0x00, 0x54, 0x00, 0x01, 0x80, 0x06, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x06, 0x00, 0x02, 0x00, 0x06, 0x00, 0x00, 0x00, 0x14, 0x00, 0x03, 0x00, 0x01, 0x01, 0x01, 0x01, @@ -193,6 +199,7 @@ func TestMessageMarshal(t *testing.T) { if err != nil { t.Fatalf("Failed to get message bytes: %v", err) } + fixNestedAttrs(got) if want := nlmIPVSAddService; !bytes.Equal(got, want) { t.Fatalf("Got netlink bytes %#v, want %#v", got, want) }