From 3be9e14f071377b023a2c2c70def4f5c49ac257a Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sun, 3 Nov 2024 10:32:51 +0100 Subject: [PATCH] Add new option "link-l3" to create layer 3 links (no ARP) using netkit "link" uses veth which is layer 2 and requires ARP to function. netkit requires Linux kernel >= 6.7 and iproute2 >= 6.8. Thanks to lemmi in OFTC/#kernelnewbies for telling me about netkit. --- config.go | 10 ++++++++-- main.go | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/config.go b/config.go index afff143..d3239b4 100644 --- a/config.go +++ b/config.go @@ -47,6 +47,8 @@ type Node struct { } type Link struct { + Layer3 bool + A struct { Node *Node Addrs []netip.Prefix @@ -91,7 +93,10 @@ func LoadConfig(path string) (*Config, error) { err = parseConfigNode(&cfg, xs[1:]) case "link": usage = `"link" ` - err = parseConfigLink(&cfg, xs[1:]) + err = parseConfigLink(&cfg, xs[1:], false) + case "link-l3": + usage = `"link-l3" ` + err = parseConfigLink(&cfg, xs[1:], true) case "cmd": usage = `"cmd" ` x := strings.TrimSpace(strings.TrimPrefix(l, "cmd")) @@ -170,7 +175,7 @@ func parseConfigNode(cfg *Config, args []string) error { return nil } -func parseConfigLink(cfg *Config, args []string) error { +func parseConfigLink(cfg *Config, args []string, l3 bool) error { if len(args) != 3 { return fmt.Errorf("invalid arguments") } @@ -198,6 +203,7 @@ func parseConfigLink(cfg *Config, args []string) error { } var l Link + l.Layer3 = l3 l.A.Node = n1 l.B.Node = n2 diff --git a/main.go b/main.go index 0cf8c84..b0ca644 100644 --- a/main.go +++ b/main.go @@ -108,7 +108,11 @@ func main() { lb = nextFreeIface(nsb, lb) } - ip("link", "add", "tmpa", "type", "veth", "peer", "name", "tmpb") + t := "veth" + if link.Layer3 { + t = "netkit" // since kernel 6.7, iproute2 6.8 + } + ip("link", "add", "tmpa", "type", t, "peer", "name", "tmpb") ip("link", "set", "tmpa", "netns", nsa) ip("link", "set", "tmpb", "netns", nsb) ip("-n", nsa, "link", "set", "tmpa", "name", la) -- 2.45.2