From mboxrd@z Thu Jan 1 00:00:00 1970 From: Atzm Watanabe Subject: Re: [PATCH iproute2] iplink: do not require assigning negative ifindex at link creation Date: Wed, 01 Oct 2014 13:30:28 +0900 Message-ID: <87vbo45s4b.wl%atzm@stratosphere.co.jp> References: <87wq8l5ppn.wl%atzm@stratosphere.co.jp> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Cc: netdev , Cong Wang , Stephen Hemminger To: Cong Wang Return-path: Received: from mail-pa0-f47.google.com ([209.85.220.47]:37556 "EHLO mail-pa0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750750AbaJAEaf (ORCPT ); Wed, 1 Oct 2014 00:30:35 -0400 Received: by mail-pa0-f47.google.com with SMTP id rd3so45462pab.20 for ; Tue, 30 Sep 2014 21:30:34 -0700 (PDT) In-Reply-To: Sender: netdev-owner@vger.kernel.org List-ID: At Tue, 30 Sep 2014 11:26:04 -0700, Cong Wang wrote: > > On Tue, Sep 30, 2014 at 4:10 AM, Atzm Watanabe wrote: > > Since commit 3c682146aeff, iplink requires assigning negative > > ifindex (-1) to the kernel when creating interface without > > specifying index. > > > > Cc: Cong Wang > > Signed-off-by: Atzm Watanabe > > --- > > ip/iplink.c | 5 ++++- > > 1 file changed, 4 insertions(+), 1 deletion(-) > > > > diff --git a/ip/iplink.c b/ip/iplink.c > > index cb9c870..de6b2a9 100644 > > --- a/ip/iplink.c > > +++ b/ip/iplink.c > > @@ -689,7 +689,10 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv) > > addattr_l(&req.n, sizeof(req), IFLA_LINK, &ifindex, 4); > > } > > > > - req.i.ifi_index = index; > > + if (index <= 0) > > + req.i.ifi_index = 0; > > + else > > + req.i.ifi_index = index; > > How about checking if it is -1? > > if (index == -1) > req.i.ifi_index = 0; > else > req.i.ifi_index = index; Agreed, will fix. Because iplink_parse() forbids specifying negative index, it will be actually same. But your suggestion seems more nicer than my patch. Thanks.