mirror of
https://github.com/vishvananda/netlink
synced 2025-02-20 06:06:56 +00:00
Added tests for Gretap/Gretun devices
fixed parsing IKey/OKey parameters for Gretun fixed parsing Local/Remote parameters for Gretap and Gretun removed irrelevant PMtuDisc parameter from IPv6 Gretaptest
This commit is contained in:
parent
f07d9d5231
commit
55d3a806a2
@ -1974,9 +1974,9 @@ func parseGretapData(link Link, data []syscall.NetlinkRouteAttr) {
|
||||
case nl.IFLA_GRE_IKEY:
|
||||
gre.OKey = ntohl(datum.Value[0:4])
|
||||
case nl.IFLA_GRE_LOCAL:
|
||||
gre.Local = net.IP(datum.Value[0:16])
|
||||
gre.Local = net.IP(datum.Value)
|
||||
case nl.IFLA_GRE_REMOTE:
|
||||
gre.Remote = net.IP(datum.Value[0:16])
|
||||
gre.Remote = net.IP(datum.Value)
|
||||
case nl.IFLA_GRE_ENCAP_SPORT:
|
||||
gre.EncapSport = ntohs(datum.Value[0:2])
|
||||
case nl.IFLA_GRE_ENCAP_DPORT:
|
||||
@ -1985,7 +1985,6 @@ func parseGretapData(link Link, data []syscall.NetlinkRouteAttr) {
|
||||
gre.IFlags = ntohs(datum.Value[0:2])
|
||||
case nl.IFLA_GRE_OFLAGS:
|
||||
gre.OFlags = ntohs(datum.Value[0:2])
|
||||
|
||||
case nl.IFLA_GRE_TTL:
|
||||
gre.Ttl = uint8(datum.Value[0])
|
||||
case nl.IFLA_GRE_TOS:
|
||||
@ -2051,19 +2050,18 @@ func parseGretunData(link Link, data []syscall.NetlinkRouteAttr) {
|
||||
gre := link.(*Gretun)
|
||||
for _, datum := range data {
|
||||
switch datum.Attr.Type {
|
||||
case nl.IFLA_GRE_OKEY:
|
||||
gre.IKey = ntohl(datum.Value[0:4])
|
||||
case nl.IFLA_GRE_IKEY:
|
||||
gre.IKey = ntohl(datum.Value[0:4])
|
||||
case nl.IFLA_GRE_OKEY:
|
||||
gre.OKey = ntohl(datum.Value[0:4])
|
||||
case nl.IFLA_GRE_LOCAL:
|
||||
gre.Local = net.IP(datum.Value[0:16])
|
||||
gre.Local = net.IP(datum.Value)
|
||||
case nl.IFLA_GRE_REMOTE:
|
||||
gre.Remote = net.IP(datum.Value[0:16])
|
||||
gre.Remote = net.IP(datum.Value)
|
||||
case nl.IFLA_GRE_IFLAGS:
|
||||
gre.IFlags = ntohs(datum.Value[0:2])
|
||||
case nl.IFLA_GRE_OFLAGS:
|
||||
gre.OFlags = ntohs(datum.Value[0:2])
|
||||
|
||||
case nl.IFLA_GRE_TTL:
|
||||
gre.Ttl = uint8(datum.Value[0])
|
||||
case nl.IFLA_GRE_TOS:
|
||||
|
137
link_test.go
137
link_test.go
@ -185,17 +185,20 @@ func testLinkAddDel(t *testing.T, link Link) {
|
||||
}
|
||||
}
|
||||
|
||||
if _, ok := link.(*Gretap); ok {
|
||||
_, ok := result.(*Gretap)
|
||||
if gretap, ok := link.(*Gretap); ok {
|
||||
other, ok := result.(*Gretap)
|
||||
if !ok {
|
||||
t.Fatal("Result of create is not a Gretap")
|
||||
}
|
||||
compareGretap(t, gretap, other)
|
||||
}
|
||||
if _, ok := link.(*Gretun); ok {
|
||||
_, ok := result.(*Gretun)
|
||||
|
||||
if gretun, ok := link.(*Gretun); ok {
|
||||
other, ok := result.(*Gretun)
|
||||
if !ok {
|
||||
t.Fatal("Result of create is not a Gretun")
|
||||
}
|
||||
compareGretun(t, gretun, other)
|
||||
}
|
||||
|
||||
if err = LinkDel(link); err != nil {
|
||||
@ -214,6 +217,131 @@ func testLinkAddDel(t *testing.T, link Link) {
|
||||
}
|
||||
}
|
||||
|
||||
func compareGretap(t *testing.T, expected, actual *Gretap) {
|
||||
if actual.IKey != expected.IKey {
|
||||
t.Fatal("Gretap.IKey doesn't match")
|
||||
}
|
||||
|
||||
if actual.OKey != expected.OKey {
|
||||
t.Fatal("Gretap.OKey doesn't match")
|
||||
}
|
||||
|
||||
if actual.EncapSport != expected.EncapSport {
|
||||
t.Fatal("Gretap.EncapSport doesn't match")
|
||||
}
|
||||
|
||||
if actual.EncapDport != expected.EncapDport {
|
||||
t.Fatal("Gretap.EncapDport doesn't match")
|
||||
}
|
||||
|
||||
if expected.Local != nil && !actual.Local.Equal(expected.Local) {
|
||||
t.Fatal("Gretap.Local doesn't match")
|
||||
}
|
||||
|
||||
if expected.Remote != nil && !actual.Remote.Equal(expected.Remote) {
|
||||
t.Fatal("Gretap.Remote doesn't match")
|
||||
}
|
||||
|
||||
if actual.IFlags != expected.IFlags {
|
||||
t.Fatal("Gretap.IFlags doesn't match")
|
||||
}
|
||||
|
||||
if actual.OFlags != expected.OFlags {
|
||||
t.Fatal("Gretap.OFlags doesn't match")
|
||||
}
|
||||
|
||||
if actual.PMtuDisc != expected.PMtuDisc {
|
||||
t.Fatal("Gretap.PMtuDisc doesn't match")
|
||||
}
|
||||
|
||||
if actual.Ttl != expected.Ttl {
|
||||
t.Fatal("Gretap.Ttl doesn't match")
|
||||
}
|
||||
|
||||
if actual.Tos != expected.Tos {
|
||||
t.Fatal("Gretap.Tos doesn't match")
|
||||
}
|
||||
|
||||
if actual.EncapType != expected.EncapType {
|
||||
t.Fatal("Gretap.EncapType doesn't match")
|
||||
}
|
||||
|
||||
if actual.EncapFlags != expected.EncapFlags {
|
||||
t.Fatal("Gretap.EncapFlags doesn't match")
|
||||
}
|
||||
|
||||
if actual.Link != expected.Link {
|
||||
t.Fatal("Gretap.Link doesn't match")
|
||||
}
|
||||
|
||||
/*
|
||||
* NOTE: setting the FlowBased flag doesn't seem to work, but by lack of
|
||||
* a proper way to debug this, this test is disabled for now
|
||||
|
||||
if actual.FlowBased != expected.FlowBased {
|
||||
t.Fatal("Gretap.FlowBased doesn't match")
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
func compareGretun(t *testing.T, expected, actual *Gretun) {
|
||||
if actual.Link != expected.Link {
|
||||
t.Fatal("Gretun.Link doesn't match")
|
||||
}
|
||||
|
||||
if actual.IFlags != expected.IFlags {
|
||||
t.Fatal("Gretun.IFlags doesn't match")
|
||||
}
|
||||
|
||||
if actual.OFlags != expected.OFlags {
|
||||
t.Fatal("Gretun.OFlags doesn't match")
|
||||
}
|
||||
|
||||
if actual.IKey != expected.IKey {
|
||||
t.Fatal("Gretun.IKey doesn't match")
|
||||
}
|
||||
|
||||
if actual.OKey != expected.OKey {
|
||||
t.Fatal("Gretun.OKey doesn't match")
|
||||
}
|
||||
|
||||
if expected.Local != nil && !actual.Local.Equal(expected.Local) {
|
||||
t.Fatal("Gretun.Local doesn't match")
|
||||
}
|
||||
|
||||
if expected.Remote != nil && !actual.Remote.Equal(expected.Remote) {
|
||||
t.Fatal("Gretun.Remote doesn't match")
|
||||
}
|
||||
|
||||
if actual.Ttl != expected.Ttl {
|
||||
t.Fatal("Gretun.Ttl doesn't match")
|
||||
}
|
||||
|
||||
if actual.Tos != expected.Tos {
|
||||
t.Fatal("Gretun.Tos doesn't match")
|
||||
}
|
||||
|
||||
if actual.PMtuDisc != expected.PMtuDisc {
|
||||
t.Fatal("Gretun.PMtuDisc doesn't match")
|
||||
}
|
||||
|
||||
if actual.EncapType != expected.EncapType {
|
||||
t.Fatal("Gretun.EncapType doesn't match")
|
||||
}
|
||||
|
||||
if actual.EncapFlags != expected.EncapFlags {
|
||||
t.Fatal("Gretun.EncapFlags doesn't match")
|
||||
}
|
||||
|
||||
if actual.EncapSport != expected.EncapSport {
|
||||
t.Fatal("Gretun.EncapSport doesn't match")
|
||||
}
|
||||
|
||||
if actual.EncapDport != expected.EncapDport {
|
||||
t.Fatal("Gretun.EncapDport doesn't match")
|
||||
}
|
||||
}
|
||||
|
||||
func compareVxlan(t *testing.T, expected, actual *Vxlan) {
|
||||
|
||||
if actual.VxlanId != expected.VxlanId {
|
||||
@ -325,7 +453,6 @@ func TestLinkAddDelGretap(t *testing.T) {
|
||||
LinkAttrs: LinkAttrs{Name: "foo6"},
|
||||
IKey: 0x101,
|
||||
OKey: 0x101,
|
||||
PMtuDisc: 1,
|
||||
Local: net.ParseIP("2001:db8:abcd::1"),
|
||||
Remote: net.ParseIP("2001:db8:ef33::2")})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user