* [PATCH iproute2] iplink: enable to specify newifindex when changing netns
@ 2021-10-11 12:58 Nicolas Dichtel
2021-10-12 9:34 ` [PATCH iproute2 v2] iplink: enable to specify index " Nicolas Dichtel
0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Dichtel @ 2021-10-11 12:58 UTC (permalink / raw)
To: stephen; +Cc: netdev, dsahern, Nicolas Dichtel
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 --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;
--
2.33.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH iproute2 v2] iplink: enable to specify index when changing netns
2021-10-11 12:58 [PATCH iproute2] iplink: enable to specify newifindex when changing netns Nicolas Dichtel
@ 2021-10-12 9:34 ` Nicolas Dichtel
2021-10-16 0:07 ` David Ahern
0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Dichtel @ 2021-10-12 9:34 UTC (permalink / raw)
To: stephen; +Cc: netdev, dsahern, Nicolas Dichtel
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>
---
v1 -> v2:
reuse index option instead adding a new option
ip/iplink.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/ip/iplink.c b/ip/iplink.c
index 18b2ea25b7c2..1d2776c3b5c9 100644
--- a/ip/iplink.c
+++ b/ip/iplink.c
@@ -578,6 +578,7 @@ static int iplink_parse_vf(int vf, int *argcp, char ***argvp,
int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type)
{
+ bool move_netns = false;
char *name = NULL;
char *dev = NULL;
char *link = NULL;
@@ -683,6 +684,7 @@ 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);
+ move_netns = true;
} else if (strcmp(*argv, "multicast") == 0) {
NEXT_ARG();
req->i.ifi_change |= IFF_MULTICAST;
@@ -980,9 +982,11 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type)
}
}
- if (!(req->n.nlmsg_flags & NLM_F_CREATE) && index) {
+ if (index &&
+ (!(req->n.nlmsg_flags & NLM_F_CREATE) &&
+ !move_netns)) {
fprintf(stderr,
- "index can be used only when creating devices.\n");
+ "index can be used only when creating devices or when moving device to another netns.\n");
exit(-1);
}
@@ -1019,6 +1023,9 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type)
/* Not renaming to the same name */
if (name == dev)
name = NULL;
+
+ if (index)
+ addattr32(&req->n, sizeof(*req), IFLA_NEW_IFINDEX, index);
} else {
if (name != dev) {
fprintf(stderr,
--
2.33.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH iproute2 v2] iplink: enable to specify index when changing netns
2021-10-12 9:34 ` [PATCH iproute2 v2] iplink: enable to specify index " Nicolas Dichtel
@ 2021-10-16 0:07 ` David Ahern
0 siblings, 0 replies; 3+ messages in thread
From: David Ahern @ 2021-10-16 0:07 UTC (permalink / raw)
To: Nicolas Dichtel, stephen; +Cc: netdev
On 10/12/21 3:34 AM, Nicolas Dichtel wrote:
> 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>
> ---
>
> v1 -> v2:
> reuse index option instead adding a new option
>
> ip/iplink.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
applied to iproute2-next. Thanks,
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-10-16 0:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-11 12:58 [PATCH iproute2] iplink: enable to specify newifindex when changing netns Nicolas Dichtel
2021-10-12 9:34 ` [PATCH iproute2 v2] iplink: enable to specify index " Nicolas Dichtel
2021-10-16 0:07 ` David Ahern
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).