From 1a4f90339d624df957170f63634ca41d2e72c473 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Fri, 15 Nov 2024 09:18:48 +0100 Subject: [PATCH] Replace (undocumented) "link-l3" option with argument for "link" --- README.adoc | 10 ++++++---- ci/examples | 8 ++++++++ config.go | 20 ++++++++++++------- examples/layer3/README.adoc | 40 +++++++++++++++++++++++++++++++++++++ examples/layer3/lab.conf | 13 ++++++++++++ 5 files changed, 80 insertions(+), 11 deletions(-) create mode 100644 examples/layer3/README.adoc create mode 100644 examples/layer3/lab.conf diff --git a/README.adoc b/README.adoc index 5cc1b86..1ec8238 100644 --- a/README.adoc +++ b/README.adoc @@ -141,13 +141,15 @@ new interface "lo2". === Option "link" - "link" + "link" ["l3"] -"link" creates (veth-)links between nodes. The IP addresses are taken from the -given network name. /31 is used for IPv4- and /127 for IPv6-prefixes. The MAC +"link" creates links between nodes. The IP addresses are taken from the given +network name. /31 is used for IPv4- and /127 for IPv6-prefixes. The MAC address is not static and allocated by the kernel. The link is named after the node "on the other side". Multiple links can be created between two nodes. In -this case "_2", "_3", etc. is appended to the interface name. +this case "_2", "_3", etc. is appended to the interface name. By default veth +interfaces are used, adding "l3" changes this to netkit which provide a +layer-3 connection without needing ARP (requires kernel 6.7, iproute2 6.8). === Option "cmd" diff --git a/ci/examples b/ci/examples index 0a86b93..ff5a73d 100755 --- a/ci/examples +++ b/ci/examples @@ -40,6 +40,14 @@ linux-network-namespace-labs down lab.conf test -z "$(ip netns)" test "$(cd /etc/netns; find)" = "." # directory empty +cd "$examples/layer3" +linux-network-namespace-labs up lab.conf +ip netns exec r1 ip route add 3fff::1/128 dev r2 +ip netns exec r1 ping -c1 3fff::1 +linux-network-namespace-labs down lab.conf +test -z "$(ip netns)" +test "$(cd /etc/netns; find)" = "." # directory empty + cd "$examples/podman-frr" ./run.sh wait_for_route r1 3fff::1 diff --git a/config.go b/config.go index 66cefc0..2773b8d 100644 --- a/config.go +++ b/config.go @@ -93,11 +93,8 @@ func LoadConfig(path string) (*Config, error) { usage = `"node" [...]` err = parseConfigNode(&cfg, xs[1:]) case "link": - usage = `"link" ` - err = parseConfigLink(&cfg, xs[1:], false) - case "link-l3": - usage = `"link-l3" ` - err = parseConfigLink(&cfg, xs[1:], true) + usage = `"link" ["l3"]` + err = parseConfigLink(&cfg, xs[1:]) case "cmd": usage = `"cmd" ` x := strings.TrimSpace(strings.TrimPrefix(l, "cmd")) @@ -183,11 +180,20 @@ func parseConfigNode(cfg *Config, args []string) error { return nil } -func parseConfigLink(cfg *Config, args []string, l3 bool) error { - if len(args) != 3 { +func parseConfigLink(cfg *Config, args []string) error { + if len(args) != 3 && len(args) != 4 { return fmt.Errorf("invalid arguments") } + var l3 bool + if len(args) == 4 { + if args[3] == "l3" { + l3 = true + } else { + return fmt.Errorf("invalid arguments") + } + } + n1 := cfg.Nodes[args[0]] if n1 == nil { return fmt.Errorf("node %q does not exist", args[0]) diff --git a/examples/layer3/README.adoc b/examples/layer3/README.adoc new file mode 100644 index 0000000..9cf9e04 --- /dev/null +++ b/examples/layer3/README.adoc @@ -0,0 +1,40 @@ += README + +Proof of concept lab with two nodes (routers) using a layer-3 link which +doesn't require ARP. + +You need kernel 6.7 and iproute2 6.8. + +Then start the lab (as root) with: + + # ./run.sh + +To enter the node use: + + # ip netns exec r1 sh + + # ip route add 3fff::1/128 dev r2 + # ip -br a + lo UNKNOWN 127.0.0.1/8 ::1/128 + lo2 UNKNOWN 3fff::/128 fe80::dc87:34ff:fe4e:ccee/64 + r2@if335 UP 2001:db8::/127 fe80::200:ff:fe00:0/64 + # ip -br l + lo UNKNOWN 00:00:00:00:00:00 + lo2 UNKNOWN de:87:34:4e:cc:ee + r2@if335 UP 00:00:00:00:00:00 + # ip -6 r + 2001:db8::/127 dev r2 proto kernel metric 256 pref medium + 3fff:: dev lo2 proto kernel metric 256 pref medium + 3fff::1 dev r2 metric 1024 pref medium + fe80::/64 dev lo2 proto kernel metric 256 pref medium + fe80::/64 dev r2 proto kernel metric 256 pref medium + # ping -c1 3fff::1 + PING 3fff::1(3fff::1) 56 data bytes + 64 bytes from 3fff::1: icmp_seq=1 ttl=64 time=0.093 ms + --- 3fff::1 ping statistics --- + 1 packets transmitted, 1 received, 0% packet loss, time 0ms + rtt min/avg/max/mdev = 0.093/0.093/0.093/0.000 ms + +To stop the lab use: + + # linux-network-namespace-labs down lab.conf diff --git a/examples/layer3/lab.conf b/examples/layer3/lab.conf new file mode 100644 index 0000000..9a67eed --- /dev/null +++ b/examples/layer3/lab.conf @@ -0,0 +1,13 @@ +# Start lab with: linux-network-namespace-labs up lab.conf + +# r1 <-> r2 + + +net loops 3fff::/20 +net addrs 2001:db8::/32 + +node r1 loops +node r2 loops + +# Create a layer-3 link which doesn't require ARP +link r1 r2 addrs l3 -- 2.45.2