f-41: frr, sysctl, netif: primitives du L3VNI #41
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
0f31b2faf4
commit
94c2f82867
11 changed files with 910 additions and 0 deletions
|
|
@ -19,3 +19,11 @@ func AddrAdd(iface string, ip net.IP) error {
|
|||
}
|
||||
return netlink.AddrAdd(link, addr)
|
||||
}
|
||||
|
||||
func AddrAddPrefix(iface string, prefix *net.IPNet) error {
|
||||
link, err := netlink.LinkByName(iface)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return netlink.AddrAdd(link, &netlink.Addr{IPNet: prefix})
|
||||
}
|
||||
|
|
|
|||
27
internal/netif/route.go
Normal file
27
internal/netif/route.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package netif
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/vishvananda/netlink"
|
||||
)
|
||||
|
||||
func RouteReplaceVia(table int, dst *net.IPNet, gw net.IP, iface string) error {
|
||||
link, err := netlink.LinkByName(iface)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return netlink.RouteReplace(&netlink.Route{
|
||||
LinkIndex: link.Attrs().Index,
|
||||
Dst: dst,
|
||||
Gw: gw,
|
||||
Table: table,
|
||||
})
|
||||
}
|
||||
|
||||
func RouteDel(table int, dst *net.IPNet) error {
|
||||
return netlink.RouteDel(&netlink.Route{
|
||||
Dst: dst,
|
||||
Table: table,
|
||||
})
|
||||
}
|
||||
16
internal/netif/vrf.go
Normal file
16
internal/netif/vrf.go
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
package netif
|
||||
|
||||
import (
|
||||
"github.com/vishvananda/netlink"
|
||||
)
|
||||
|
||||
func CreateVRF(name string, table uint32) error {
|
||||
vrf := &netlink.Vrf{
|
||||
LinkAttrs: netlink.LinkAttrs{Name: name},
|
||||
Table: table,
|
||||
}
|
||||
if err := netlink.LinkAdd(vrf); err != nil {
|
||||
return err
|
||||
}
|
||||
return netlink.LinkSetUp(vrf)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue