diff --git a/link.go b/link.go index c3a4288..00ef341 100644 --- a/link.go +++ b/link.go @@ -781,7 +781,10 @@ func (vti *Vti) Attrs() *LinkAttrs { return &vti.LinkAttrs } -func (iptun *Vti) Type() string { +func (vti *Vti) Type() string { + if vti.Local.To4() == nil { + return "vti6" + } return "vti" } @@ -846,7 +849,7 @@ func (gtp *GTP) Type() string { // iproute2 supported devices; // vlan | veth | vcan | dummy | ifb | macvlan | macvtap | // bridge | bond | ipoib | ip6tnl | ipip | sit | vxlan | -// gre | gretap | ip6gre | ip6gretap | vti | nlmon | +// gre | gretap | ip6gre | ip6gretap | vti | vti6 | nlmon | // bond_slave | ipvlan // LinkNotFoundError wraps the various not found errors when diff --git a/link_linux.go b/link_linux.go index 5189a4c..02ef679 100644 --- a/link_linux.go +++ b/link_linux.go @@ -1415,7 +1415,7 @@ func LinkDeserialize(hdr *unix.NlMsghdr, m []byte) (Link, error) { link = &Gretun{} case "ip6gre": link = &Gretun{} - case "vti": + case "vti", "vti6": link = &Vti{} case "vrf": link = &Vrf{} @@ -1454,7 +1454,7 @@ func LinkDeserialize(hdr *unix.NlMsghdr, m []byte) (Link, error) { parseGretunData(link, data) case "ip6gre": parseGretunData(link, data) - case "vti": + case "vti", "vti6": parseVtiData(link, data) case "vrf": parseVrfData(link, data) @@ -2304,12 +2304,27 @@ func parseSittunData(link Link, data []syscall.NetlinkRouteAttr) { func addVtiAttrs(vti *Vti, linkInfo *nl.RtAttr) { data := nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_DATA, nil) - ip := vti.Local.To4() + family := FAMILY_V4 + if vti.Local.To4() == nil { + family = FAMILY_V6 + } + + var ip net.IP + + if family == FAMILY_V4 { + ip = vti.Local.To4() + } else { + ip = vti.Local + } if ip != nil { nl.NewRtAttrChild(data, nl.IFLA_VTI_LOCAL, []byte(ip)) } - ip = vti.Remote.To4() + if family == FAMILY_V4 { + ip = vti.Remote.To4() + } else { + ip = vti.Remote + } if ip != nil { nl.NewRtAttrChild(data, nl.IFLA_VTI_REMOTE, []byte(ip)) } @@ -2327,9 +2342,9 @@ func parseVtiData(link Link, data []syscall.NetlinkRouteAttr) { for _, datum := range data { switch datum.Attr.Type { case nl.IFLA_VTI_LOCAL: - vti.Local = net.IP(datum.Value[0:4]) + vti.Local = net.IP(datum.Value) case nl.IFLA_VTI_REMOTE: - vti.Remote = net.IP(datum.Value[0:4]) + vti.Remote = net.IP(datum.Value) case nl.IFLA_VTI_IKEY: vti.IKey = ntohl(datum.Value[0:4]) case nl.IFLA_VTI_OKEY: diff --git a/link_test.go b/link_test.go index 980de37..22b7f2f 100644 --- a/link_test.go +++ b/link_test.go @@ -1482,6 +1482,13 @@ func TestLinkAddDelVti(t *testing.T) { OKey: 0x101, Local: net.IPv4(127, 0, 0, 1), Remote: net.IPv4(127, 0, 0, 1)}) + + testLinkAddDel(t, &Vti{ + LinkAttrs: LinkAttrs{Name: "vtibar"}, + IKey: 0x101, + OKey: 0x101, + Local: net.IPv6loopback, + Remote: net.IPv6loopback}) } func TestBridgeCreationWithMulticastSnooping(t *testing.T) {