f-57: netif: MAC anycast de la gateway et création d'un macvlan #57
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
5d314e45e1
commit
fe8c83b1d6
4 changed files with 103 additions and 2 deletions
26
internal/netif/macvlan.go
Normal file
26
internal/netif/macvlan.go
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package netif
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/vishvananda/netlink"
|
||||
)
|
||||
|
||||
func macvlanLink(name string, parentIndex int, mac net.HardwareAddr) *netlink.Macvlan {
|
||||
return &netlink.Macvlan{
|
||||
LinkAttrs: netlink.LinkAttrs{
|
||||
Name: name,
|
||||
ParentIndex: parentIndex,
|
||||
HardwareAddr: mac,
|
||||
},
|
||||
Mode: netlink.MACVLAN_MODE_BRIDGE,
|
||||
}
|
||||
}
|
||||
|
||||
func CreateMacvlan(name, parent string, mac net.HardwareAddr) error {
|
||||
link, err := netlink.LinkByName(parent)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return netlink.LinkAdd(macvlanLink(name, link.Attrs().Index, mac))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue