]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
iplink: Follow documented behaviour when "index" is given
authorSerhey Popovych <serhe.popovych@gmail.com>
Wed, 7 Mar 2018 08:40:38 +0000 (10:40 +0200)
committerDavid Ahern <dsahern@gmail.com>
Mon, 12 Mar 2018 00:58:56 +0000 (17:58 -0700)
Both ip-link(8) and error message when "index" parameter is given for
set/delete case says that index can only be given during network
device creation.

Follow this documented behaviour and get rid of ambiguous behaviour in
case of both "dev" and "index" specified for ip link delete scenario
(actually "index" being ignored in favor to "dev").

Prohibit "index" when configuring/deleting group of network devices.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
ip/iplink.c

index b4307ab701e81b853c7ce80f73c91bc2a627eb41..6d3ebdee512529cae9291d6073a0a276c399eb1b 100644 (file)
@@ -964,6 +964,12 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
        argc -= ret;
        argv += ret;
 
+       if (!(flags & NLM_F_CREATE) && index) {
+               fprintf(stderr,
+                       "index can be used only when creating devices.\n");
+               exit(-1);
+       }
+
        if (group != -1) {
                if (dev)
                        addattr_l(&req.n, sizeof(req), IFLA_GROUP,
@@ -994,11 +1000,6 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
                                "Not enough information: \"dev\" argument is required.\n");
                        exit(-1);
                }
-               if (cmd == RTM_NEWLINK && index) {
-                       fprintf(stderr,
-                               "index can be used only when creating devices.\n");
-                       exit(-1);
-               }
 
                req.i.ifi_index = ll_name_to_index(dev);
                if (!req.i.ifi_index)