netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Serhey Popovich <serhe.popovych@gmail.com>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH iproute2 1/3] iplink: Improve index parameter handling
Date: Mon, 18 Dec 2017 23:37:09 +0200	[thread overview]
Message-ID: <18e98fc6-4145-0bb9-143d-d4305d22bdc8@gmail.com> (raw)
In-Reply-To: <20171218132231.6dcf7b54@xeon-e3>


[-- Attachment #1.1: Type: text/plain, Size: 2230 bytes --]

Stephen Hemminger wrote:
> On Mon, 18 Dec 2017 23:02:07 +0200
> Serhey Popovich <serhe.popovych@gmail.com> wrote:
> 
>> Stephen Hemminger wrote:
>>> On Mon, 18 Dec 2017 20:54:06 +0200
>>> Serhey Popovych <serhe.popovych@gmail.com> wrote:
>>>   
>>>> diff --git a/ip/iplink.c b/ip/iplink.c
>>>> index 1e685cc..4f9c169 100644
>>>> --- a/ip/iplink.c
>>>> +++ b/ip/iplink.c
>>>> @@ -586,8 +586,10 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req,
>>>>  			*name = *argv;
>>>>  		} else if (strcmp(*argv, "index") == 0) {
>>>>  			NEXT_ARG();
>>>> +			if (*index)
>>>> +				duparg("index", *argv);
>>>>  			*index = atoi(*argv);
>>>> -			if (*index < 0)
>>>> +			if (*index <= 0)  
>>>
>>> Why not use strtoul instead of atoi?  
>> Do not see reason for strtoul() instead atoi():
>>
>>   1) main arg: indexes in kernel represented as "int", which is
>>      signed. <= 0 values are reserved for various special purposes
>>      (see net/core/fib_rules.c on how device matching implemented).
>>
>>      Configuring network device manually with index <= 0 is not correct
>>      (however possible). Kernel itself never chooses ifindex <= 0.
>>
>>      Having unsigned int > 0x7fffffff actually means index <= 0.
>>
>>   2) this is not single place in iproute2 where it is used: not
>>      going to remove last user.
>>
>>   3) make changes clear and transparent for review.
> 
> I would rather all of iproute2 correctly handles unsigned values.
> Too much code is old K&R style C "the world is an int" and "who needs
> to check for negative".

You are right :(. I'm just trying to improve things a bit.

> 
> There already is get_unsigned() in iproute2 util functions.
This is good one based on strtoul(). But do we want to submit say
index = (unsigned int)2147483648(0x7fffffff) to the kernel that is
illegal from it's perspective?

Or do you mean I can prepare treewide change to replace atoi() with
get_unsigned()/get_integer() where appropriate?

We already check if (*index < 0) since commit 3c682146aeff
(iplink: forbid negative ifindex and modifying ifindex), and I just
put index == 0 in the same range of invalid indexes.

> Why not use that?
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 490 bytes --]

  reply	other threads:[~2017-12-18 21:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-18 18:54 [PATCH iproute2 0/3] Improve iplink index, alias and name parameters handling Serhey Popovych
2017-12-18 18:54 ` [PATCH iproute2 1/3] iplink: Improve index parameter handling Serhey Popovych
2017-12-18 19:23   ` Stephen Hemminger
2017-12-18 21:02     ` Serhey Popovich
2017-12-18 21:22       ` Stephen Hemminger
2017-12-18 21:37         ` Serhey Popovich [this message]
2017-12-19 15:59           ` Stephen Hemminger
2017-12-19 16:05             ` Serhey Popovich
2017-12-18 18:54 ` [PATCH iproute2 2/3] iplink: Process "alias" parameter correctly Serhey Popovych
2017-12-18 18:54 ` [PATCH iproute2 3/3] iplink: Kill redundant network device name checks Serhey Popovych

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=18e98fc6-4145-0bb9-143d-d4305d22bdc8@gmail.com \
    --to=serhe.popovych@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).