Extract AddRoute function

This commit is contained in:
Bryan Boreham committed 2016-05-25 17:29:45 +01:00
1 parent 85023e0a76
commit 4fc2835d92
2 files changed
+17 -17

No files matched your search

+14
View File
@@ -3,6 +3,7 @@ package net
import (
"fmt"
"net"
"os"
"github.com/vishvananda/netlink"
)
@@ -55,3 +56,16 @@ func forEachRoute(ignoreIfaceNames map[string]struct{}, check func(r netlink.Rou
}
return nil
}
func AddRoute(link netlink.Link, scope netlink.Scope, dst *net.IPNet, gw net.IP) error {
err := netlink.RouteAdd(&netlink.Route{
LinkIndex: link.Attrs().Index,
Scope: scope,
Dst: dst,
Gw: gw,
})
if os.IsExist(err) { // squash duplicate route errors
err = nil
}
return err
}