f-15: ia: first subnet try
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
bf00d74a26
commit
cad1a9f46b
7 changed files with 445 additions and 0 deletions
21
internal/netif/addr.go
Normal file
21
internal/netif/addr.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package netif
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/vishvananda/netlink"
|
||||
)
|
||||
|
||||
func AddrAdd(iface string, ip net.IP) error {
|
||||
link, err := netlink.LinkByName(iface)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
addr := &netlink.Addr{
|
||||
IPNet: &net.IPNet{
|
||||
IP: ip,
|
||||
Mask: net.CIDRMask(32, 32),
|
||||
},
|
||||
}
|
||||
return netlink.AddrAdd(link, addr)
|
||||
}
|
||||
21
internal/netif/route_linux.go
Normal file
21
internal/netif/route_linux.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
//go:build linux
|
||||
|
||||
package netif
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/vishvananda/netlink"
|
||||
)
|
||||
|
||||
func RouteAdd(iface string, subnet *net.IPNet) error {
|
||||
link, err := netlink.LinkByName(iface)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return netlink.RouteAdd(&netlink.Route{
|
||||
LinkIndex: link.Attrs().Index,
|
||||
Dst: subnet,
|
||||
Scope: netlink.SCOPE_LINK,
|
||||
})
|
||||
}
|
||||
9
internal/netif/route_other.go
Normal file
9
internal/netif/route_other.go
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
//go:build !linux
|
||||
|
||||
package netif
|
||||
|
||||
import "net"
|
||||
|
||||
func RouteAdd(_ string, _ *net.IPNet) error {
|
||||
return nil
|
||||
}
|
||||
20
internal/netif/vxlan.go
Normal file
20
internal/netif/vxlan.go
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
package netif
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/vishvananda/netlink"
|
||||
)
|
||||
|
||||
func CreateVxlan(name string, vxlanID int, localIP net.IP) error {
|
||||
vxlan := &netlink.Vxlan{
|
||||
LinkAttrs: netlink.LinkAttrs{
|
||||
Name: name,
|
||||
},
|
||||
VxlanId: vxlanID,
|
||||
Port: 4789,
|
||||
SrcAddr: localIP,
|
||||
Learning: false,
|
||||
}
|
||||
return netlink.LinkAdd(vxlan)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue