netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute2] ss: Fix support for device filter by index
@ 2016-07-15 16:29 David Ahern
  2016-07-15 18:53 ` Stephen Hemminger
  0 siblings, 1 reply; 5+ messages in thread
From: David Ahern @ 2016-07-15 16:29 UTC (permalink / raw)
  To: netdev; +Cc: stephen, David Ahern

Support was recently added for device filters. The intent was to allow
the device to be specified by name or index, and using the if%u format
(dev == if5) or the simpler and more intuitive index alone (dev == 5).
The latter case is broken since the index is not saved to the filter
after the strtoul conversion. Further, the tmp variable used for the
conversion shadows another variable used in the function. Fix both.

With this change all 3 variants work as expected:
$ ss -t 'dev == 62'
State   Recv-Q Send-Q         Local Address:Port    Peer Address:Port
ESTAB       0      224         10.0.1.3%mgmt:ssh   192.168.0.50:58442

$ ss -t 'dev == mgmt'
State   Recv-Q Send-Q         Local Address:Port    Peer Address:Port
ESTAB       0      224         10.0.1.3%mgmt:ssh   192.168.0.50:58442

$ ss -t 'dev == if62'
State   Recv-Q Send-Q         Local Address:Port    Peer Address:Port
ESTAB       0      36          10.0.1.3%mgmt:ssh   192.168.0.50:58442

Fixes: 2d2932125616 ("ss: Add support to filter on device")
Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
---
 misc/ss.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/misc/ss.c b/misc/ss.c
index a0f9c6b9623c..abece96c0946 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -1435,11 +1435,13 @@ void *parse_devcond(char *name)
 	a.iface = xll_name_to_index(name);
 	if (a.iface == 0) {
 		char *end;
-		unsigned long res;
+		unsigned long n;
 
-		res = strtoul(name, &end, 0);
-		if (!end || end == name || *end || res > UINT_MAX)
+		n = strtoul(name, &end, 0);
+		if (!end || end == name || *end || n > UINT_MAX)
 			return NULL;
+
+		a.iface = n;
 	}
 
 	res = malloc(sizeof(*res));
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH iproute2] ss: Fix support for device filter by index
  2016-07-15 16:29 David Ahern
@ 2016-07-15 18:53 ` Stephen Hemminger
  2016-07-15 18:56   ` David Ahern
  0 siblings, 1 reply; 5+ messages in thread
From: Stephen Hemminger @ 2016-07-15 18:53 UTC (permalink / raw)
  To: David Ahern; +Cc: netdev

On Fri, 15 Jul 2016 09:29:28 -0700
David Ahern <dsa@cumulusnetworks.com> wrote:

> Support was recently added for device filters. The intent was to allow
> the device to be specified by name or index, and using the if%u format
> (dev == if5) or the simpler and more intuitive index alone (dev == 5).
> The latter case is broken since the index is not saved to the filter
> after the strtoul conversion. Further, the tmp variable used for the
> conversion shadows another variable used in the function. Fix both.
> 
> With this change all 3 variants work as expected:
> $ ss -t 'dev == 62'
> State   Recv-Q Send-Q         Local Address:Port    Peer Address:Port
> ESTAB       0      224         10.0.1.3%mgmt:ssh   192.168.0.50:58442
> 
> $ ss -t 'dev == mgmt'
> State   Recv-Q Send-Q         Local Address:Port    Peer Address:Port
> ESTAB       0      224         10.0.1.3%mgmt:ssh   192.168.0.50:58442
> 
> $ ss -t 'dev == if62'
> State   Recv-Q Send-Q         Local Address:Port    Peer Address:Port
> ESTAB       0      36          10.0.1.3%mgmt:ssh   192.168.0.50:58442
> 
> Fixes: 2d2932125616 ("ss: Add support to filter on device")
> Signed-off-by: David Ahern <dsa@cumulusnetworks.com>

Won't apply to current code.
Please rebase.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH iproute2] ss: Fix support for device filter by index
  2016-07-15 18:53 ` Stephen Hemminger
@ 2016-07-15 18:56   ` David Ahern
  0 siblings, 0 replies; 5+ messages in thread
From: David Ahern @ 2016-07-15 18:56 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev

On 7/15/16 12:53 PM, Stephen Hemminger wrote:
> On Fri, 15 Jul 2016 09:29:28 -0700
> David Ahern <dsa@cumulusnetworks.com> wrote:
>
>> Support was recently added for device filters. The intent was to allow
>> the device to be specified by name or index, and using the if%u format
>> (dev == if5) or the simpler and more intuitive index alone (dev == 5).
>> The latter case is broken since the index is not saved to the filter
>> after the strtoul conversion. Further, the tmp variable used for the
>> conversion shadows another variable used in the function. Fix both.
>>
>> With this change all 3 variants work as expected:
>> $ ss -t 'dev == 62'
>> State   Recv-Q Send-Q         Local Address:Port    Peer Address:Port
>> ESTAB       0      224         10.0.1.3%mgmt:ssh   192.168.0.50:58442
>>
>> $ ss -t 'dev == mgmt'
>> State   Recv-Q Send-Q         Local Address:Port    Peer Address:Port
>> ESTAB       0      224         10.0.1.3%mgmt:ssh   192.168.0.50:58442
>>
>> $ ss -t 'dev == if62'
>> State   Recv-Q Send-Q         Local Address:Port    Peer Address:Port
>> ESTAB       0      36          10.0.1.3%mgmt:ssh   192.168.0.50:58442
>>
>> Fixes: 2d2932125616 ("ss: Add support to filter on device")
>> Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
>
> Won't apply to current code.
> Please rebase.
>

It applies cleanly for me to master branch. That's where the ss dev 
filter is from June:

commit 2d29321256168e13e10fbde3c57f33e70dcb6cc8
Author: David Ahern <dsa@cumulusnetworks.com>
Date:   Mon Jun 27 11:34:25 2016 -0700

     ss: Add support to filter on device

No commits on that file since except 
62000e51e05d635016bae9891a4e00134ed8aefb which does not impact the 
function in question.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH iproute2] ss: Fix support for device filter by index
@ 2016-07-15 22:41 David Ahern
  2016-07-20 18:58 ` Stephen Hemminger
  0 siblings, 1 reply; 5+ messages in thread
From: David Ahern @ 2016-07-15 22:41 UTC (permalink / raw)
  To: netdev; +Cc: stephen, David Ahern

Support was recently added for device filters. The intent was to allow
the device to be specified by name or index, and using the if%u format
(dev == if5) or the simpler and more intuitive index alone (dev == 5).
The latter case is broken since the index is not saved to the filter
after the strtoul conversion. Further, the tmp variable used for the
conversion shadows another variable used in the function. Fix both.

With this change all 3 variants work as expected:
$ ss -t 'dev == 62'
State   Recv-Q Send-Q         Local Address:Port    Peer Address:Port
ESTAB       0      224         10.0.1.3%mgmt:ssh   192.168.0.50:58442

$ ss -t 'dev == mgmt'
State   Recv-Q Send-Q         Local Address:Port    Peer Address:Port
ESTAB       0      224         10.0.1.3%mgmt:ssh   192.168.0.50:58442

$ ss -t 'dev == if62'
State   Recv-Q Send-Q         Local Address:Port    Peer Address:Port
ESTAB       0      36          10.0.1.3%mgmt:ssh   192.168.0.50:58442

Fixes: 2d2932125616 ("ss: Add support to filter on device")
Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
---
No changes since last version. Applies cleanly to master branch.

 misc/ss.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/misc/ss.c b/misc/ss.c
index a0f9c6b9623c..abece96c0946 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -1435,11 +1435,13 @@ void *parse_devcond(char *name)
 	a.iface = xll_name_to_index(name);
 	if (a.iface == 0) {
 		char *end;
-		unsigned long res;
+		unsigned long n;
 
-		res = strtoul(name, &end, 0);
-		if (!end || end == name || *end || res > UINT_MAX)
+		n = strtoul(name, &end, 0);
+		if (!end || end == name || *end || n > UINT_MAX)
 			return NULL;
+
+		a.iface = n;
 	}
 
 	res = malloc(sizeof(*res));
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH iproute2] ss: Fix support for device filter by index
  2016-07-15 22:41 [PATCH iproute2] ss: Fix support for device filter by index David Ahern
@ 2016-07-20 18:58 ` Stephen Hemminger
  0 siblings, 0 replies; 5+ messages in thread
From: Stephen Hemminger @ 2016-07-20 18:58 UTC (permalink / raw)
  To: David Ahern; +Cc: netdev

On Fri, 15 Jul 2016 15:41:35 -0700
David Ahern <dsa@cumulusnetworks.com> wrote:

> Support was recently added for device filters. The intent was to allow
> the device to be specified by name or index, and using the if%u format
> (dev == if5) or the simpler and more intuitive index alone (dev == 5).
> The latter case is broken since the index is not saved to the filter
> after the strtoul conversion. Further, the tmp variable used for the
> conversion shadows another variable used in the function. Fix both.
> 
> With this change all 3 variants work as expected:
> $ ss -t 'dev == 62'
> State   Recv-Q Send-Q         Local Address:Port    Peer Address:Port
> ESTAB       0      224         10.0.1.3%mgmt:ssh   192.168.0.50:58442
> 
> $ ss -t 'dev == mgmt'
> State   Recv-Q Send-Q         Local Address:Port    Peer Address:Port
> ESTAB       0      224         10.0.1.3%mgmt:ssh   192.168.0.50:58442
> 
> $ ss -t 'dev == if62'
> State   Recv-Q Send-Q         Local Address:Port    Peer Address:Port
> ESTAB       0      36          10.0.1.3%mgmt:ssh   192.168.0.50:58442
> 
> Fixes: 2d2932125616 ("ss: Add support to filter on device")
> Signed-off-by: David Ahern <dsa@cumulusnetworks.com>

Both applied

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-07-20 19:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-15 22:41 [PATCH iproute2] ss: Fix support for device filter by index David Ahern
2016-07-20 18:58 ` Stephen Hemminger
  -- strict thread matches above, loose matches on Subject: below --
2016-07-15 16:29 David Ahern
2016-07-15 18:53 ` Stephen Hemminger
2016-07-15 18:56   ` David Ahern

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).