From bf9f871fe13058a9b7ba878228a57d43225a45f4 Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Sun, 26 Apr 2026 16:28:54 +0200 Subject: [PATCH] f-25: netif: Add tap handle Signed-off-by: GnomeZworc --- internal/netif/tap_linux.go | 28 ++++++++++++++++++++++++++++ internal/netif/tap_other.go | 9 +++++++++ 2 files changed, 37 insertions(+) create mode 100644 internal/netif/tap_linux.go create mode 100644 internal/netif/tap_other.go diff --git a/internal/netif/tap_linux.go b/internal/netif/tap_linux.go new file mode 100644 index 0000000..a5abc9c --- /dev/null +++ b/internal/netif/tap_linux.go @@ -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) + }) +} diff --git a/internal/netif/tap_other.go b/internal/netif/tap_other.go new file mode 100644 index 0000000..a81fefb --- /dev/null +++ b/internal/netif/tap_other.go @@ -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") +}