Add support for VRF. With this change we can create VRF interface.

$ sudo ip link add vrf1 type vrf table 1
This commit is contained in:
kishiguro 2016-12-22 06:55:39 -08:00 committed by Vish Ishaya
parent 9f67bd458b
commit ade05d5c8f
3 changed files with 41 additions and 0 deletions

13
link.go
View File

@ -659,6 +659,19 @@ func (iptun *Vti) Type() string {
return "vti"
}
type Vrf struct {
LinkAttrs
Table uint32
}
func (vrf *Vrf) Attrs() *LinkAttrs {
return &vrf.LinkAttrs
}
func (vrf *Vrf) Type() string {
return "vrf"
}
// iproute2 supported devices;
// vlan | veth | vcan | dummy | ifb | macvlan | macvtap |
// bridge | bond | ipoib | ip6tnl | ipip | sit | vxlan |

View File

@ -787,6 +787,8 @@ func (h *Handle) LinkAdd(link Link) error {
addIptunAttrs(iptun, linkInfo)
} else if vti, ok := link.(*Vti); ok {
addVtiAttrs(vti, linkInfo)
} else if vrf, ok := link.(*Vrf); ok {
addVrfAttrs(vrf, linkInfo)
}
req.AddData(linkInfo)
@ -1014,6 +1016,8 @@ func LinkDeserialize(hdr *syscall.NlMsghdr, m []byte) (Link, error) {
link = &Iptun{}
case "vti":
link = &Vti{}
case "vrf":
link = &Vrf{}
default:
link = &GenericLink{LinkType: linkType}
}
@ -1041,6 +1045,8 @@ func LinkDeserialize(hdr *syscall.NlMsghdr, m []byte) (Link, error) {
parseIptunData(link, data)
case "vti":
parseVtiData(link, data)
case "vrf":
parseVrfData(link, data)
}
}
}
@ -1617,3 +1623,20 @@ func parseVtiData(link Link, data []syscall.NetlinkRouteAttr) {
}
}
}
func addVrfAttrs(vrf *Vrf, linkInfo *nl.RtAttr) {
data := nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_DATA, nil)
b := make([]byte, 4)
native.PutUint32(b, uint32(vrf.Table))
nl.NewRtAttrChild(data, nl.IFLA_VRF_TABLE, b)
}
func parseVrfData(link Link, data []syscall.NetlinkRouteAttr) {
vrf := link.(*Vrf)
for _, datum := range data {
switch datum.Attr.Type {
case nl.IFLA_VRF_TABLE:
vrf.Table = native.Uint32(datum.Value[0:4])
}
}
}

View File

@ -447,3 +447,8 @@ const (
IFLA_VTI_REMOTE
IFLA_VTI_MAX = IFLA_VTI_REMOTE
)
const (
IFLA_VRF_UNSPEC = iota
IFLA_VRF_TABLE
)