f-25: netif: Add tap handle
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
877cfc7260
commit
bf9f871fe1
2 changed files with 37 additions and 0 deletions
28
internal/netif/tap_linux.go
Normal file
28
internal/netif/tap_linux.go
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
//go:build linux
|
||||||
|
|
||||||
|
package netif
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.g3e.fr/syonad/two/internal/netns"
|
||||||
|
"github.com/vishvananda/netlink"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CreateTap(tapID int, bridgeName, vpcName string) error {
|
||||||
|
name := fmt.Sprintf("tap%d", tapID)
|
||||||
|
|
||||||
|
return netns.Call(vpcName, func() error {
|
||||||
|
tap := &netlink.Tuntap{
|
||||||
|
LinkAttrs: netlink.LinkAttrs{Name: name},
|
||||||
|
Mode: netlink.TUNTAP_MODE_TAP,
|
||||||
|
}
|
||||||
|
if err := netlink.LinkAdd(tap); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := BridgeSetMaster(name, bridgeName); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return LinkSetUp(name)
|
||||||
|
})
|
||||||
|
}
|
||||||
9
internal/netif/tap_other.go
Normal file
9
internal/netif/tap_other.go
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
//go:build !linux
|
||||||
|
|
||||||
|
package netif
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
func CreateTap(_ int, _, _ string) error {
|
||||||
|
return errors.New("netif: tap not supported on this platform")
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue