]> ruderich.org/simon Gitweb - linux-network-namespace-labs/linux-network-namespace-labs.git/commitdiff
Add new option "link-l3" to create layer 3 links (no ARP) using netkit
authorSimon Ruderich <simon@ruderich.org>
Sun, 3 Nov 2024 09:32:51 +0000 (10:32 +0100)
committerSimon Ruderich <simon@ruderich.org>
Sun, 3 Nov 2024 09:32:51 +0000 (10:32 +0100)
"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
main.go

index afff143aa36760a074ef6c830b7d38cd89578854..d3239b434a21c99b3cbac7ba3dfab36aead27c88 100644 (file)
--- 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" <node> <node> <net-name>`
-                       err = parseConfigLink(&cfg, xs[1:])
+                       err = parseConfigLink(&cfg, xs[1:], false)
+               case "link-l3":
+                       usage = `"link-l3" <node> <node> <net-name>`
+                       err = parseConfigLink(&cfg, xs[1:], true)
                case "cmd":
                        usage = `"cmd" <string-passed-to-sh-c>`
                        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 0cf8c848ada973494ff3478dfcd5c8d25fa468b0..b0ca64441b31e87a38e6c186e6d3813ee7fa62e6 100644 (file)
--- 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)