summaryrefslogtreecommitdiff
path: root/misc/ss.c
diff options
context:
space:
mode:
authorThayne McCombs <astrothayne@gmail.com>2021-02-14 01:09:13 -0700
committerDavid Ahern <dsahern@kernel.org>2021-02-14 22:09:37 -0700
commitc7897ec2a68b444b8aecc7aaeed8b80a5eefa7ea (patch)
treee242795053e015ae6da3d0c53d64dfe31779b298 /misc/ss.c
parent33e2471e8f47a532123ee2642e97b6a425ac84ac (diff)
downloadiproute2-c7897ec2a68b444b8aecc7aaeed8b80a5eefa7ea.tar.gz
ss: Make leading ":" always optional for sport and dport
The sport and dport conditions in expressions were inconsistent on whether there should be a ":" at the beginning of the port when only a port was provided depending on the family. The link and netlink families required a ":" to work. The vsock family required the ":" to be absent. The inet and inet6 families work with or without a leading ":". This makes the leading ":" optional in all cases, so if sport or dport are used, then it works with a leading ":" or without one, as inet and inet6 did. Signed-off-by: Thayne McCombs <astrothayne@gmail.com> Signed-off-by: David Ahern <dsahern@kernel.org>
Diffstat (limited to 'misc/ss.c')
-rw-r--r--misc/ss.c46
1 files changed, 24 insertions, 22 deletions
diff --git a/misc/ss.c b/misc/ss.c
index aefa1c2f..5c934fa0 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -2111,6 +2111,18 @@ static void vsock_set_inet_prefix(inet_prefix *a, __u32 cid)
memcpy(a->data, &cid, sizeof(cid));
}
+static char* find_port(char *addr, bool is_port)
+{
+ char *port = NULL;
+ if (is_port)
+ port = addr;
+ else
+ port = strchr(addr, ':');
+ if (port && *port == ':')
+ *port++ = '\0';
+ return port;
+}
+
void *parse_hostcond(char *addr, bool is_port)
{
char *port = NULL;
@@ -2152,17 +2164,16 @@ void *parse_hostcond(char *addr, bool is_port)
if (fam == AF_PACKET) {
a.addr.family = AF_PACKET;
a.addr.bitlen = 0;
- port = strchr(addr, ':');
+ port = find_port(addr, is_port);
if (port) {
- *port = 0;
- if (port[1] && strcmp(port+1, "*")) {
- if (get_integer(&a.port, port+1, 0)) {
- if ((a.port = xll_name_to_index(port+1)) <= 0)
+ if (*port && strcmp(port, "*")) {
+ if (get_integer(&a.port, port, 0)) {
+ if ((a.port = xll_name_to_index(port)) <= 0)
return NULL;
}
}
}
- if (addr[0] && strcmp(addr, "*")) {
+ if (!is_port && addr[0] && strcmp(addr, "*")) {
unsigned short tmp;
a.addr.bitlen = 32;
@@ -2176,19 +2187,18 @@ void *parse_hostcond(char *addr, bool is_port)
if (fam == AF_NETLINK) {
a.addr.family = AF_NETLINK;
a.addr.bitlen = 0;
- port = strchr(addr, ':');
+ port = find_port(addr, is_port);
if (port) {
- *port = 0;
- if (port[1] && strcmp(port+1, "*")) {
- if (get_integer(&a.port, port+1, 0)) {
- if (strcmp(port+1, "kernel") == 0)
+ if (*port && strcmp(port, "*")) {
+ if (get_integer(&a.port, port, 0)) {
+ if (strcmp(port, "kernel") == 0)
a.port = 0;
else
return NULL;
}
}
}
- if (addr[0] && strcmp(addr, "*")) {
+ if (!is_port && addr[0] && strcmp(addr, "*")) {
a.addr.bitlen = 32;
if (nl_proto_a2n(&a.addr.data[0], addr) == -1)
return NULL;
@@ -2201,21 +2211,13 @@ void *parse_hostcond(char *addr, bool is_port)
a.addr.family = AF_VSOCK;
- if (is_port)
- port = addr;
- else {
- port = strchr(addr, ':');
- if (port) {
- *port = '\0';
- port++;
- }
- }
+ port = find_port(addr, is_port);
if (port && strcmp(port, "*") &&
get_u32((__u32 *)&a.port, port, 0))
return NULL;
- if (addr[0] && strcmp(addr, "*")) {
+ if (!is_port && addr[0] && strcmp(addr, "*")) {
a.addr.bitlen = 32;
if (get_u32(&cid, addr, 0))
return NULL;