From 77089b583aee6128763a3277bf44d2f5d90f9035 Mon Sep 17 00:00:00 2001 From: Hangbin Liu Date: Thu, 22 Sep 2016 16:40:28 +0800 Subject: [PATCH 1/5] misc/ss: tcp cwnd should be unsigned tcp->snd_cwd is a u32, but ss treats it like a signed int. This may results in negative bandwidth calculations. Signed-off-by: Hangbin Liu Acked-by: Phil Sutter --- misc/ss.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/misc/ss.c b/misc/ss.c index 3b268d99..f67557a6 100644 --- a/misc/ss.c +++ b/misc/ss.c @@ -754,11 +754,12 @@ struct tcpstat { int probes; char cong_alg[16]; double rto, ato, rtt, rttvar; - int qack, cwnd, ssthresh, backoff; + int qack, ssthresh, backoff; double send_bps; int snd_wscale; int rcv_wscale; int mss; + unsigned int cwnd; unsigned int lastsnd; unsigned int lastrcv; unsigned int lastack; @@ -1756,7 +1757,7 @@ static void tcp_stats_print(struct tcpstat *s) if (s->mss) printf(" mss:%d", s->mss); if (s->cwnd) - printf(" cwnd:%d", s->cwnd); + printf(" cwnd:%u", s->cwnd); if (s->ssthresh) printf(" ssthresh:%d", s->ssthresh); @@ -1856,7 +1857,7 @@ static int tcp_show_line(char *line, const struct filter *f, int family) return 0; opt[0] = 0; - n = sscanf(data, "%x %x:%x %x:%x %x %d %d %u %d %llx %d %d %d %d %d %[^\n]\n", + n = sscanf(data, "%x %x:%x %x:%x %x %d %d %u %d %llx %d %d %d %u %d %[^\n]\n", &s.ss.state, &s.ss.wq, &s.ss.rq, &s.timer, &s.timeout, &s.retrans, &s.ss.uid, &s.probes, &s.ss.ino, &s.ss.refcnt, &s.ss.sk, &rto, &ato, &s.qack, &s.cwnd, From 22a84711f445ca48bf5633775a02278f066c7232 Mon Sep 17 00:00:00 2001 From: Hangbin Liu Date: Tue, 20 Sep 2016 18:02:12 +0800 Subject: [PATCH 2/5] ip: Use specific slave id The original bond/bridge/vrf and slaves use same id, which make people confused. Use bond/bridge/vrf_slave as id name will make code more clear. Acked-by: Phil Sutter Signed-off-by: Hangbin Liu --- ip/ip_common.h | 2 -- ip/ipaddress.c | 4 +++- ip/iplink.c | 36 +++++++----------------------------- ip/iplink_bond_slave.c | 3 +-- ip/iplink_bridge_slave.c | 3 +-- ip/iplink_vrf.c | 3 +-- ip/ipmacsec.c | 1 - 7 files changed, 13 insertions(+), 39 deletions(-) diff --git a/ip/ip_common.h b/ip/ip_common.h index 93ff5bce..1c1cbdf0 100644 --- a/ip/ip_common.h +++ b/ip/ip_common.h @@ -83,11 +83,9 @@ struct link_util { struct rtattr *); void (*print_help)(struct link_util *, int, char **, FILE *); - bool slave; }; struct link_util *get_link_kind(const char *kind); -struct link_util *get_link_slave_kind(const char *slave_kind); void br_dump_bridge_id(const struct ifla_bridge_id *id, char *buf, size_t len); diff --git a/ip/ipaddress.c b/ip/ipaddress.c index 76bd7b35..fcc3c538 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -232,6 +232,7 @@ static void print_linktype(FILE *fp, struct rtattr *tb) struct rtattr *linkinfo[IFLA_INFO_MAX+1]; struct link_util *lu; struct link_util *slave_lu; + char slave[32]; char *kind; char *slave_kind; @@ -265,8 +266,9 @@ static void print_linktype(FILE *fp, struct rtattr *tb) fprintf(fp, "%s", _SL_); fprintf(fp, " %s_slave ", slave_kind); + snprintf(slave, sizeof(slave), "%s_slave", slave_kind); - slave_lu = get_link_slave_kind(slave_kind); + slave_lu = get_link_kind(slave); if (slave_lu && slave_lu->print_opt) { struct rtattr *attr[slave_lu->maxattr+1], **data = NULL; diff --git a/ip/iplink.c b/ip/iplink.c index 6b1db18a..dec8268a 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -119,15 +119,14 @@ static int on_off(const char *msg, const char *realval) static void *BODY; /* cached dlopen(NULL) handle */ static struct link_util *linkutil_list; -static struct link_util *__get_link_kind(const char *id, bool slave) +struct link_util *get_link_kind(const char *id) { void *dlh; char buf[256]; struct link_util *l; for (l = linkutil_list; l; l = l->next) - if (strcmp(l->id, id) == 0 && - l->slave == slave) + if (strcmp(l->id, id) == 0) return l; snprintf(buf, sizeof(buf), LIBDIR "/ip/link_%s.so", id); @@ -142,10 +141,7 @@ static struct link_util *__get_link_kind(const char *id, bool slave) } } - if (slave) - snprintf(buf, sizeof(buf), "%s_slave_link_util", id); - else - snprintf(buf, sizeof(buf), "%s_link_util", id); + snprintf(buf, sizeof(buf), "%s_link_util", id); l = dlsym(dlh, buf); if (l == NULL) return NULL; @@ -155,16 +151,6 @@ static struct link_util *__get_link_kind(const char *id, bool slave) return l; } -struct link_util *get_link_kind(const char *id) -{ - return __get_link_kind(id, false); -} - -struct link_util *get_link_slave_kind(const char *id) -{ - return __get_link_kind(id, true); -} - static int get_link_mode(const char *mode) { if (strcasecmp(mode, "default") == 0) @@ -872,26 +858,18 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv) if (type) { struct rtattr *linkinfo; - char slavebuf[128], *ulinep = strchr(type, '_'); + char *ulinep = strchr(type, '_'); int iflatype; linkinfo = addattr_nest(&req.n, sizeof(req), IFLA_LINKINFO); addattr_l(&req.n, sizeof(req), IFLA_INFO_KIND, type, strlen(type)); - if (ulinep && !strcmp(ulinep, "_slave")) { - strncpy(slavebuf, type, sizeof(slavebuf)); - slavebuf[sizeof(slavebuf) - 1] = '\0'; - ulinep = strchr(slavebuf, '_'); - /* check in case it was after sizeof(slavebuf) - 1*/ - if (ulinep) - *ulinep = '\0'; - lu = get_link_slave_kind(slavebuf); + lu = get_link_kind(type); + if (ulinep && !strcmp(ulinep, "_slave")) iflatype = IFLA_INFO_SLAVE_DATA; - } else { - lu = get_link_kind(type); + else iflatype = IFLA_INFO_DATA; - } if (lu && argc) { struct rtattr *data = addattr_nest(&req.n, sizeof(req), iflatype); diff --git a/ip/iplink_bond_slave.c b/ip/iplink_bond_slave.c index 9c60dea8..877e2d9e 100644 --- a/ip/iplink_bond_slave.c +++ b/ip/iplink_bond_slave.c @@ -130,10 +130,9 @@ static void bond_slave_print_help(struct link_util *lu, int argc, char **argv, } struct link_util bond_slave_link_util = { - .id = "bond", + .id = "bond_slave", .maxattr = IFLA_BOND_SLAVE_MAX, .print_opt = bond_slave_print_opt, .parse_opt = bond_slave_parse_opt, .print_help = bond_slave_print_help, - .slave = true, }; diff --git a/ip/iplink_bridge_slave.c b/ip/iplink_bridge_slave.c index a44d4e41..6c5c59a9 100644 --- a/ip/iplink_bridge_slave.c +++ b/ip/iplink_bridge_slave.c @@ -293,10 +293,9 @@ static void bridge_slave_print_help(struct link_util *lu, int argc, char **argv, } struct link_util bridge_slave_link_util = { - .id = "bridge", + .id = "bridge_slave", .maxattr = IFLA_BRPORT_MAX, .print_opt = bridge_slave_print_opt, .parse_opt = bridge_slave_parse_opt, .print_help = bridge_slave_print_help, - .slave = true, }; diff --git a/ip/iplink_vrf.c b/ip/iplink_vrf.c index 015b41e1..a238b290 100644 --- a/ip/iplink_vrf.c +++ b/ip/iplink_vrf.c @@ -91,10 +91,9 @@ struct link_util vrf_link_util = { }; struct link_util vrf_slave_link_util = { - .id = "vrf", + .id = "vrf_slave", .maxattr = IFLA_VRF_PORT_MAX, .print_opt = vrf_slave_print_opt, - .slave = true, }; /* returns table id if name is a VRF device */ diff --git a/ip/ipmacsec.c b/ip/ipmacsec.c index 127fa1e3..c9252bb2 100644 --- a/ip/ipmacsec.c +++ b/ip/ipmacsec.c @@ -1265,5 +1265,4 @@ struct link_util macsec_link_util = { .parse_opt = macsec_parse_opt, .print_help = macsec_print_help, .print_opt = macsec_print_opt, - .slave = false, }; From 6cf2609ddb724164cbfa746e388b7942d09a9d64 Mon Sep 17 00:00:00 2001 From: Igor Ryzhov Date: Tue, 4 Oct 2016 13:16:55 +0300 Subject: [PATCH 3/5] fix netlink message length checks Signed-off-by: Igor Ryzhov --- ip/ipaddress.c | 2 +- lib/ll_map.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ip/ipaddress.c b/ip/ipaddress.c index fcc3c538..36148376 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -1218,7 +1218,7 @@ static int print_selected_addrinfo(struct ifinfomsg *ifi, if (n->nlmsg_type != RTM_NEWADDR) continue; - if (n->nlmsg_len < NLMSG_LENGTH(sizeof(ifa))) + if (n->nlmsg_len < NLMSG_LENGTH(sizeof(*ifa))) return -1; if (ifa->ifa_index != ifi->ifi_index || diff --git a/lib/ll_map.c b/lib/ll_map.c index 571d11e1..4e4556c9 100644 --- a/lib/ll_map.c +++ b/lib/ll_map.c @@ -90,7 +90,7 @@ int ll_remember_index(const struct sockaddr_nl *who, if (n->nlmsg_type != RTM_NEWLINK && n->nlmsg_type != RTM_DELLINK) return 0; - if (n->nlmsg_len < NLMSG_LENGTH(sizeof(ifi))) + if (n->nlmsg_len < NLMSG_LENGTH(sizeof(*ifi))) return -1; im = ll_get_by_index(ifi->ifi_index); From afd3921ea9805553bd51a7c00efe33a819e13e8e Mon Sep 17 00:00:00 2001 From: anuradhak Date: Fri, 7 Oct 2016 09:40:18 -0700 Subject: [PATCH 4/5] bridge: Fix garbled json output seen if a vlan filter is specified json objects were started but not completed if the fdb vlan did not match the specified filter vlan. Sample output: $ bridge -j fdb show vlan 111 [{ "mac": "44:38:39:00:69:88", "dev": "br0", "vlan": 111, "master": "br0", "state": "permanent" } ] $ bridge -j fdb show vlan 100 [] $ Signed-off-by: Anuradha Karuppiah --- bridge/fdb.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bridge/fdb.c b/bridge/fdb.c index c6e03793..90f4b154 100644 --- a/bridge/fdb.c +++ b/bridge/fdb.c @@ -100,11 +100,6 @@ int print_fdb(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) if (filter_index && filter_index != r->ndm_ifindex) return 0; - if (jw_global) { - jsonw_pretty(jw_global, 1); - jsonw_start_object(jw_global); - } - parse_rtattr(tb, NDA_MAX, NDA_RTA(r), n->nlmsg_len - NLMSG_LENGTH(sizeof(*r))); @@ -114,6 +109,11 @@ int print_fdb(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) if (filter_vlan && filter_vlan != vid) return 0; + if (jw_global) { + jsonw_pretty(jw_global, 1); + jsonw_start_object(jw_global); + } + if (n->nlmsg_type == RTM_DELNEIGH) { if (jw_global) jsonw_string_field(jw_global, "opCode", "deleted"); From 58d93d00309b56dee4fd4d77d2d615f32ec79d28 Mon Sep 17 00:00:00 2001 From: Sushma Sitaram Date: Wed, 28 Sep 2016 11:30:16 -0700 Subject: [PATCH 5/5] tc: f_u32: Fill in 'linkid' provided by user Currently, 'linkid' input by the user is parsed but 'handle' is appended to the netlink message. # tc filter add dev enp1s0f1 protocol ip parent ffff: prio 99 u32 ht 800: \ order 1 link 1: offset at 0 mask 0f00 shift 6 plus 0 eat match ip \ protocol 6 ff resulted in: filter protocol ip pref 99 u32 fh 800::1 order 1 key ht 800 bkt 0 match 00060000/00ff0000 at 8 offset 0f00>>6 at 0 eat This patch results in: filter protocol ip pref 99 u32 fh 800::1 order 1 key ht 800 bkt 0 link 1: match 00060000/00ff0000 at 8 offset 0f00>>6 at 0 eat Signed-off-by Sushma Sitaram: Sushma Sitaram --- tc/f_u32.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tc/f_u32.c b/tc/f_u32.c index 0ad7ed2b..92c1fcd4 100644 --- a/tc/f_u32.c +++ b/tc/f_u32.c @@ -1071,7 +1071,7 @@ static int u32_parse_opt(struct filter_util *qu, char *handle, fprintf(stderr, "\"link\" must be a hash table.\n"); return -1; } - addattr_l(n, MAX_MSG, TCA_U32_LINK, &handle, 4); + addattr_l(n, MAX_MSG, TCA_U32_LINK, &linkid, 4); } else if (strcmp(*argv, "ht") == 0) { unsigned int ht;