f-25: netif: Add tap handle

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-04-26 16:28:54 +02:00
commit bf9f871fe1
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
2 changed files with 37 additions and 0 deletions

View 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)
})
}

View 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")
}