From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf0-f68.google.com ([209.85.215.68]:34954 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752112AbeBTTkW (ORCPT ); Tue, 20 Feb 2018 14:40:22 -0500 Received: by mail-lf0-f68.google.com with SMTP id 70so5884287lfw.2 for ; Tue, 20 Feb 2018 11:40:22 -0800 (PST) From: Serhey Popovych To: netdev@vger.kernel.org Cc: dsahern@gmail.com Subject: [PATCH iproute2-next 5/8] iplink: Follow documented behaviour when "index" is given Date: Tue, 20 Feb 2018 21:39:55 +0200 Message-Id: <1519155598-22137-6-git-send-email-serhe.popovych@gmail.com> In-Reply-To: <1519155598-22137-1-git-send-email-serhe.popovych@gmail.com> References: <1519155598-22137-1-git-send-email-serhe.popovych@gmail.com> Sender: netdev-owner@vger.kernel.org List-ID: 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 --- ip/iplink.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ip/iplink.c b/ip/iplink.c index 131c268..1adfaa0 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -974,6 +974,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"); + return -1; + } + if (group != -1) { if (dev) addattr_l(&req.n, sizeof(req), IFLA_GROUP, @@ -1004,11 +1010,6 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv) "Not enough information: \"dev\" argument is required.\n"); return -1; } - if (cmd == RTM_NEWLINK && index) { - fprintf(stderr, - "index can be used only when creating devices.\n"); - return -1; - } req.i.ifi_index = ll_name_to_index(dev); if (!req.i.ifi_index) -- 1.7.10.4