diff mbox series

[iproute2] iplink: enable to specify newifindex when changing netns

Message ID 20211011125852.7805-1-nicolas.dichtel@6wind.com (mailing list archive)
State Superseded
Delegated to: David Ahern
Headers show
Series [iproute2] iplink: enable to specify newifindex when changing netns | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Nicolas Dichtel Oct. 11, 2021, 12:58 p.m. UTC
When an interface is moved to another netns, it's possible to specify a
new ifindex. Let's add this support.

Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=eeb85a14ee34
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
 ip/iplink.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/ip/iplink.c b/ip/iplink.c
index 18b2ea25b7c2..80b6615319f4 100644
--- a/ip/iplink.c
+++ b/ip/iplink.c
@@ -95,7 +95,7 @@  void iplink_usage(void)
 		"		[ address LLADDR ]\n"
 		"		[ broadcast LLADDR ]\n"
 		"		[ mtu MTU ]\n"
-		"		[ netns { PID | NAME } ]\n"
+		"		[ netns { PID | NAME } [ newindex IXD ] ]\n"
 		"		[ link-netns NAME | link-netnsid ID ]\n"
 		"		[ alias NAME ]\n"
 		"		[ vf NUM [ mac LLADDR ]\n"
@@ -590,6 +590,7 @@  int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type)
 	int numtxqueues = -1;
 	int numrxqueues = -1;
 	int link_netnsid = -1;
+	int newindex = 0;
 	int index = 0;
 	int group = -1;
 	int addr_len = 0;
@@ -683,6 +684,15 @@  int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type)
 					  IFLA_NET_NS_PID, &netns, 4);
 			else
 				invarg("Invalid \"netns\" value\n", *argv);
+		} else if (strcmp(*argv, "newindex") == 0) {
+			NEXT_ARG();
+			if (newindex)
+				duparg("newindex", *argv);
+			newindex = atoi(*argv);
+			if (newindex <= 0)
+				invarg("Invalid \"newindex\" value", *argv);
+			addattr32(&req->n, sizeof(*req), IFLA_NEW_IFINDEX,
+				  newindex);
 		} else if (strcmp(*argv, "multicast") == 0) {
 			NEXT_ARG();
 			req->i.ifi_change |= IFF_MULTICAST;