summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorStephen Hemminger <stephen@networkplumber.org>2021-02-23 23:03:42 -0800
committerStephen Hemminger <stephen@networkplumber.org>2021-02-23 23:03:42 -0800
commit52c5f3f0432562f5416fc093aff5166b6d2702ed (patch)
tree6352dc72a20f9a65e96f79a4a1502af4efad042b /misc
parentbbddfcec6c32781e5b4915ef4ce6b9b13eed82ef (diff)
parentc7897ec2a68b444b8aecc7aaeed8b80a5eefa7ea (diff)
downloadiproute2-52c5f3f0432562f5416fc093aff5166b6d2702ed.tar.gz
Merge git://git.kernel.org/pub/scm/network/iproute2/iproute2-next
Diffstat (limited to 'misc')
-rw-r--r--misc/ss.c98
1 files changed, 49 insertions, 49 deletions
diff --git a/misc/ss.c b/misc/ss.c
index ad46f9db..894ad405 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;
@@ -2119,35 +2131,49 @@ void *parse_hostcond(char *addr, bool is_port)
int fam = preferred_family;
struct filter *f = &current_filter;
- if (fam == AF_UNIX || strncmp(addr, "unix:", 5) == 0) {
+ if (strncmp(addr, "unix:", 5) == 0) {
+ fam = AF_UNIX;
+ addr += 5;
+ } else if (strncmp(addr, "link:", 5) == 0) {
+ fam = AF_PACKET;
+ addr += 5;
+ } else if (strncmp(addr, "netlink:", 8) == 0) {
+ fam = AF_NETLINK;
+ addr += 8;
+ } else if (strncmp(addr, "vsock:", 6) == 0) {
+ fam = AF_VSOCK;
+ addr += 6;
+ } else if (strncmp(addr, "inet:", 5) == 0) {
+ fam = AF_INET;
+ addr += 5;
+ } else if (strncmp(addr, "inet6:", 6) == 0) {
+ fam = AF_INET6;
+ addr += 6;
+ }
+
+ if (fam == AF_UNIX) {
char *p;
a.addr.family = AF_UNIX;
- if (strncmp(addr, "unix:", 5) == 0)
- addr += 5;
p = strdup(addr);
a.addr.bitlen = 8*strlen(p);
memcpy(a.addr.data, &p, sizeof(p));
- fam = AF_UNIX;
goto out;
}
- if (fam == AF_PACKET || strncmp(addr, "link:", 5) == 0) {
+ if (fam == AF_PACKET) {
a.addr.family = AF_PACKET;
a.addr.bitlen = 0;
- if (strncmp(addr, "link:", 5) == 0)
- addr += 5;
- 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;
@@ -2155,77 +2181,51 @@ void *parse_hostcond(char *addr, bool is_port)
return NULL;
a.addr.data[0] = ntohs(tmp);
}
- fam = AF_PACKET;
goto out;
}
- if (fam == AF_NETLINK || strncmp(addr, "netlink:", 8) == 0) {
+ if (fam == AF_NETLINK) {
a.addr.family = AF_NETLINK;
a.addr.bitlen = 0;
- if (strncmp(addr, "netlink:", 8) == 0)
- addr += 8;
- 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;
}
- fam = AF_NETLINK;
goto out;
}
- if (fam == AF_VSOCK || strncmp(addr, "vsock:", 6) == 0) {
+ if (fam == AF_VSOCK) {
__u32 cid = ~(__u32)0;
a.addr.family = AF_VSOCK;
- if (strncmp(addr, "vsock:", 6) == 0)
- addr += 6;
-
- 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;
}
vsock_set_inet_prefix(&a.addr, cid);
- fam = AF_VSOCK;
goto out;
}
- if (fam == AF_INET || !strncmp(addr, "inet:", 5)) {
- fam = AF_INET;
- if (!strncmp(addr, "inet:", 5))
- addr += 5;
- } else if (fam == AF_INET6 || !strncmp(addr, "inet6:", 6)) {
- fam = AF_INET6;
- if (!strncmp(addr, "inet6:", 6))
- addr += 6;
- }
-
/* URL-like literal [] */
if (addr[0] == '[') {
addr++;