ss: Fix support for device filter by index

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: 2d29321256 ("ss: Add support to filter on device")
Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
This commit is contained in:
David Ahern 2016-07-15 15:41:35 -07:00 committed by Stephen Hemminger
parent e77fa41d4c
commit 930d3f2819
1 changed files with 5 additions and 3 deletions

View File

@ -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));