Skip to content

Commit

Permalink
Add support for VRF. With this change we can create VRF interface.
Browse files Browse the repository at this point in the history
$ sudo ip link add vrf1 type vrf table 1
  • Loading branch information
kishiguro authored and vishvananda committed Jan 5, 2017
1 parent 9f67bd4 commit ade05d5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
13 changes: 13 additions & 0 deletions link.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
23 changes: 23 additions & 0 deletions link_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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}
}
Expand Down Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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])
}
}
}
5 changes: 5 additions & 0 deletions nl/link_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,8 @@ const (
IFLA_VTI_REMOTE
IFLA_VTI_MAX = IFLA_VTI_REMOTE
)

const (
IFLA_VRF_UNSPEC = iota
IFLA_VRF_TABLE
)

0 comments on commit ade05d5

Please sign in to comment.