add vti6 support

Signed-off-by: semicomplete <example@example.com>
This commit is contained in:
semicomplete 2018-06-13 20:00:30 +02:00 committed by Flavio Crisciani
parent b1cc70dea2
commit ee06b1df73
3 changed files with 33 additions and 8 deletions

View File

@ -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

View File

@ -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:

View File

@ -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) {