Skip to content

Commit

Permalink
add vti6 support
Browse files Browse the repository at this point in the history
Signed-off-by: semicomplete <example@example.com>
  • Loading branch information
semicomplete authored and Flavio Crisciani committed Jun 19, 2018
1 parent b1cc70d commit ee06b1d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
7 changes: 5 additions & 2 deletions link.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down Expand Up @@ -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
Expand Down
27 changes: 21 additions & 6 deletions link_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
}
Expand All @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ee06b1d

Please sign in to comment.