From b57197021f18f3b871b548a6d8b1620b7fd9b4a5 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Thu, 15 Feb 2024 12:41:37 +0100 Subject: [PATCH] mxrouterctl: Fix startup: Don't move lo Make the code, which moves/creates interface in 'start' the same as the code in 'restart'. Most importantly this avoids `mxrouterctl start` to attempt to move 'lo' into the new namespaces. root@jabberwocky:/etc/local/mxrouter# mxrouterctl start ip netns add MXR ip link set lo netns MXR RTNETLINK answers: Invalid argument previous command failed with exit status 2 Fixes da35f49 ("mxrouterctl: Handle interface changes on reload") --- mxrouter/mxrouterctl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mxrouter/mxrouterctl b/mxrouter/mxrouterctl index 4105180..f333ddd 100755 --- a/mxrouter/mxrouterctl +++ b/mxrouter/mxrouterctl @@ -808,13 +808,17 @@ if (!$opt_this_ns) { have_netns($NETNS) and die "already running (network namespace $NETNS already exists)\n"; create_netns($NETNS); - for my $dev (sort keys %$want_if) { - move_dev_into_ns($dev,$NETNS); - } for my $dev (sort keys %$want_veth) { + -d "/sys/class/net/$dev" and next; sys('ip', 'link', 'add', $dev, 'type', 'veth', 'peer', 'name', $dev, 'netns', $NETNS); sys('ip', 'link', 'set', $dev, 'up'); } + # move interfaces which are still in the init namespace + # ignore veth devices and lo, which exists in both namespaces + for my $dev (sort keys %$want_if) { + $dev eq 'lo' || $want_veth->{$dev} and next; + -d "/sys/class/net/$dev" and sys('ip', 'link', 'set', $dev, 'netns', $NETNS); + } system('ip','netns','exec',$NETNS,$0,'--this-ns',@SAVED_ARGV) and exit 1; } elsif ($cmd eq 'stop') { have_netns($NETNS) or die "not running (network namespace $NETNS does not exist)\n";