From patchwork Mon Oct 11 12:58:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Dichtel X-Patchwork-Id: 12549899 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16405C433F5 for ; Mon, 11 Oct 2021 12:58:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DBACD60EE2 for ; Mon, 11 Oct 2021 12:58:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236726AbhJKNA6 (ORCPT ); Mon, 11 Oct 2021 09:00:58 -0400 Received: from host.78.145.23.62.rev.coltfrance.com ([62.23.145.78]:53416 "EHLO smtpservice.6wind.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235323AbhJKNA5 (ORCPT ); Mon, 11 Oct 2021 09:00:57 -0400 Received: from bretzel (bretzel.dev.6wind.com [10.16.0.57]) by smtpservice.6wind.com (Postfix) with ESMTPS id 097B560099; Mon, 11 Oct 2021 14:58:56 +0200 (CEST) Received: from dichtel by bretzel with local (Exim 4.92) (envelope-from ) id 1mZutL-000228-Uu; Mon, 11 Oct 2021 14:58:55 +0200 From: Nicolas Dichtel To: stephen@networkplumber.org Cc: netdev@vger.kernel.org, dsahern@gmail.com, Nicolas Dichtel Subject: [PATCH iproute2] iplink: enable to specify newifindex when changing netns Date: Mon, 11 Oct 2021 14:58:52 +0200 Message-Id: <20211011125852.7805-1-nicolas.dichtel@6wind.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com 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 --- 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;