VRF CNI: Add an optional table parameter.

When specified from the user, the VRF will get assigned to the given
tableid instead of having the CNI to choose for a free one.

Signed-off-by: Federico Paolinelli <fpaoline@redhat.com>
This commit is contained in:
Federico Paolinelli
2020-09-18 11:27:46 +02:00
parent ccd872bd7a
commit b34402abd3
4 changed files with 107 additions and 7 deletions

View File

@ -35,15 +35,19 @@ func findVRF(name string) (*netlink.Vrf, error) {
}
// createVRF creates a new VRF and sets it up.
func createVRF(name string) (*netlink.Vrf, error) {
func createVRF(name string, tableID uint32) (*netlink.Vrf, error) {
links, err := netlink.LinkList()
if err != nil {
return nil, fmt.Errorf("createVRF: Failed to find links %v", err)
}
tableID, err := findFreeRoutingTableID(links)
if err != nil {
return nil, err
if tableID == 0 {
tableID, err = findFreeRoutingTableID(links)
if err != nil {
return nil, err
}
}
vrf := &netlink.Vrf{
LinkAttrs: netlink.LinkAttrs{
Name: name,