From ee0067a918e229cd0f3689364b4ce5eadbe3abdd Mon Sep 17 00:00:00 2001 From: Jiri Pirko Date: Thu, 8 Jan 2015 09:49:55 +0100 Subject: [PATCH 1/8] iplink: print out addrgenmode attribute addrgenmode is currently write only by ip. So display this information if provided by kernel as well. Signed-off-by: Jiri Pirko --- ip/ipaddress.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/ip/ipaddress.c b/ip/ipaddress.c index 28dfe8ce..d8bda302 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -255,6 +255,29 @@ static void print_linktype(FILE *fp, struct rtattr *tb) } } +static void print_af_spec(FILE *fp, struct rtattr *af_spec_attr) +{ + struct rtattr *inet6_attr; + struct rtattr *tb[IFLA_INET6_MAX + 1]; + + inet6_attr = parse_rtattr_one_nested(AF_INET6, af_spec_attr); + if (!inet6_attr) + return; + + parse_rtattr_nested(tb, IFLA_INET6_MAX, inet6_attr); + + if (tb[IFLA_INET6_ADDR_GEN_MODE]) { + switch (rta_getattr_u8(tb[IFLA_INET6_ADDR_GEN_MODE])) { + case IN6_ADDR_GEN_MODE_EUI64: + fprintf(fp, "addrgenmode eui64 "); + break; + case IN6_ADDR_GEN_MODE_NONE: + fprintf(fp, "addrgenmode none "); + break; + } + } +} + static void print_vfinfo(FILE *fp, struct rtattr *vfinfo) { struct ifla_vf_mac *vf_mac; @@ -658,6 +681,9 @@ int print_linkinfo(const struct sockaddr_nl *who, if (tb[IFLA_LINKINFO] && show_details) print_linktype(fp, tb[IFLA_LINKINFO]); + if (do_link && tb[IFLA_AF_SPEC] && show_details) + print_af_spec(fp, tb[IFLA_AF_SPEC]); + if ((do_link || show_details) && tb[IFLA_IFALIAS]) { fprintf(fp, "%s alias %s", _SL_, rta_getattr_str(tb[IFLA_IFALIAS])); From 564663b4ca6237bb55d62c3977ac7afabb100da3 Mon Sep 17 00:00:00 2001 From: Jamal Hadi Salim Date: Sun, 11 Jan 2015 09:31:30 -0500 Subject: [PATCH 2/8] actions: Get vlan action to work in pipeline When specified in a graph such as: action vlan ... action foobar the vlan action chewed more than it can swallow Signed-off-by: Jamal Hadi Salim --- tc/m_vlan.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tc/m_vlan.c b/tc/m_vlan.c index 171d2683..32db5ed5 100644 --- a/tc/m_vlan.c +++ b/tc/m_vlan.c @@ -103,20 +103,25 @@ static int parse_vlan(struct action_util *a, int *argc_p, char ***argv_p, if (argc) { if (matches(*argv, "reclassify") == 0) { parm.action = TC_ACT_RECLASSIFY; - NEXT_ARG(); + argc--; + argv++; } else if (matches(*argv, "pipe") == 0) { parm.action = TC_ACT_PIPE; - NEXT_ARG(); + argc--; + argv++; } else if (matches(*argv, "drop") == 0 || matches(*argv, "shot") == 0) { parm.action = TC_ACT_SHOT; - NEXT_ARG(); + argc--; + argv++; } else if (matches(*argv, "continue") == 0) { parm.action = TC_ACT_UNSPEC; - NEXT_ARG(); + argc--; + argv++; } else if (matches(*argv, "pass") == 0) { parm.action = TC_ACT_OK; - NEXT_ARG(); + argc--; + argv++; } } @@ -198,6 +203,7 @@ static int print_vlan(struct action_util *au, FILE *f, struct rtattr *arg) } break; } + fprintf(f, " %s", action_n2a(parm->action, b1, sizeof (b1))); fprintf(f, "\n\t index %d ref %d bind %d", parm->index, parm->refcnt, parm->bindcnt); From 8c29ae7cc2494e251520584e83698c1a9f1912e5 Mon Sep 17 00:00:00 2001 From: Vadim Kochan Date: Fri, 9 Jan 2015 21:24:31 +0200 Subject: [PATCH 3/8] ip link: Fix crash on older kernels when show VF dev The issue was caused that ifla_vf_rate does not exist on older kernels and should be checked if it exists as nested attr. Signed-off-by: Vadim Kochan Reported-by: William Dauchy Tested-by: William Dauchy --- ip/ipaddress.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/ip/ipaddress.c b/ip/ipaddress.c index d8bda302..d5e863dd 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -282,11 +282,10 @@ static void print_vfinfo(FILE *fp, struct rtattr *vfinfo) { struct ifla_vf_mac *vf_mac; struct ifla_vf_vlan *vf_vlan; - struct ifla_vf_rate *vf_rate; struct ifla_vf_tx_rate *vf_tx_rate; struct ifla_vf_spoofchk *vf_spoofchk; struct ifla_vf_link_state *vf_linkstate; - struct rtattr *vf[IFLA_VF_MAX+1]; + struct rtattr *vf[IFLA_VF_MAX + 1] = {}; struct rtattr *tmp; SPRINT_BUF(b1); @@ -300,7 +299,6 @@ static void print_vfinfo(FILE *fp, struct rtattr *vfinfo) vf_mac = RTA_DATA(vf[IFLA_VF_MAC]); vf_vlan = RTA_DATA(vf[IFLA_VF_VLAN]); vf_tx_rate = RTA_DATA(vf[IFLA_VF_TX_RATE]); - vf_rate = RTA_DATA(vf[IFLA_VF_RATE]); /* Check if the spoof checking vf info type is supported by * this kernel. @@ -336,10 +334,16 @@ static void print_vfinfo(FILE *fp, struct rtattr *vfinfo) fprintf(fp, ", qos %d", vf_vlan->qos); if (vf_tx_rate->rate) fprintf(fp, ", tx rate %d (Mbps)", vf_tx_rate->rate); - if (vf_rate->max_tx_rate) - fprintf(fp, ", max_tx_rate %dMbps", vf_rate->max_tx_rate); - if (vf_rate->min_tx_rate) - fprintf(fp, ", min_tx_rate %dMbps", vf_rate->min_tx_rate); + + if (vf[IFLA_VF_RATE]) { + struct ifla_vf_rate *vf_rate = RTA_DATA(vf[IFLA_VF_RATE]); + + if (vf_rate->max_tx_rate) + fprintf(fp, ", max_tx_rate %dMbps", vf_rate->max_tx_rate); + if (vf_rate->min_tx_rate) + fprintf(fp, ", min_tx_rate %dMbps", vf_rate->min_tx_rate); + } + if (vf_spoofchk && vf_spoofchk->setting != -1) { if (vf_spoofchk->setting) fprintf(fp, ", spoof checking on"); From ace5cb31b1f0f8f4e5644808234f9843409e86a6 Mon Sep 17 00:00:00 2001 From: Vadim Kochan Date: Thu, 8 Jan 2015 02:42:54 +0200 Subject: [PATCH 4/8] ss: Fix case when UDP is printed as ipproto-xxx When 'ss' prints UDP sockets info together with RAW sockets e.g.: $ ss -a then UDP sockets are resolved as "ipproto-xxx". It was caused that dg_proto was set after printing UDP socket info from netlink. So fixed issue by moving setting dg_proto before printing info from Netlink. Signed-off-by: Vadim Kochan --- misc/ss.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/misc/ss.c b/misc/ss.c index 08d210ae..7c944639 100644 --- a/misc/ss.c +++ b/misc/ss.c @@ -2287,12 +2287,12 @@ static int udp_show(struct filter *f) { FILE *fp = NULL; + dg_proto = UDP_PROTO; + if (!getenv("PROC_NET_UDP") && !getenv("PROC_ROOT") && inet_show_netlink(f, NULL, IPPROTO_UDP) == 0) return 0; - dg_proto = UDP_PROTO; - if (f->families&(1< Date: Thu, 8 Jan 2015 04:30:43 +0200 Subject: [PATCH 5/8] ss: Usage filter state names, options alignment Signed-off-by: Vadim Kochan --- misc/ss.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/misc/ss.c b/misc/ss.c index 7c944639..f434f57f 100644 --- a/misc/ss.c +++ b/misc/ss.c @@ -3192,30 +3192,30 @@ static void _usage(FILE *dest) fprintf(dest, "Usage: ss [ OPTIONS ]\n" " ss [ OPTIONS ] [ FILTER ]\n" -" -h, --help this message\n" -" -V, --version output version information\n" -" -n, --numeric don't resolve service names\n" +" -h, --help this message\n" +" -V, --version output version information\n" +" -n, --numeric don't resolve service names\n" " -r, --resolve resolve host names\n" -" -a, --all display all sockets\n" -" -l, --listening display listening sockets\n" +" -a, --all display all sockets\n" +" -l, --listening display listening sockets\n" " -o, --options show timer information\n" " -e, --extended show detailed socket information\n" " -m, --memory show socket memory usage\n" -" -p, --processes show process using socket\n" -" -i, --info show internal TCP information\n" -" -s, --summary show socket usage summary\n" +" -p, --processes show process using socket\n" +" -i, --info show internal TCP information\n" +" -s, --summary show socket usage summary\n" " -b, --bpf show bpf filter socket information\n" -" -Z, --context display process SELinux security contexts\n" -" -z, --contexts display process and socket SELinux security contexts\n" +" -Z, --context display process SELinux security contexts\n" +" -z, --contexts display process and socket SELinux security contexts\n" "\n" " -4, --ipv4 display only IP version 4 sockets\n" " -6, --ipv6 display only IP version 6 sockets\n" -" -0, --packet display PACKET sockets\n" -" -t, --tcp display only TCP sockets\n" -" -u, --udp display only UDP sockets\n" -" -d, --dccp display only DCCP sockets\n" -" -w, --raw display only RAW sockets\n" -" -x, --unix display only Unix domain sockets\n" +" -0, --packet display PACKET sockets\n" +" -t, --tcp display only TCP sockets\n" +" -u, --udp display only UDP sockets\n" +" -d, --dccp display only DCCP sockets\n" +" -w, --raw display only RAW sockets\n" +" -x, --unix display only Unix domain sockets\n" " -f, --family=FAMILY display sockets of type FAMILY\n" "\n" " -A, --query=QUERY, --socket=QUERY\n" @@ -3223,7 +3223,13 @@ static void _usage(FILE *dest) "\n" " -D, --diag=FILE Dump raw information about TCP sockets to FILE\n" " -F, --filter=FILE read filter information from FILE\n" -" FILTER := [ state TCP-STATE ] [ EXPRESSION ]\n" +" FILTER := [ state STATE-FILTER ] [ EXPRESSION ]\n" +" STATE-FILTER := {all|connected|synchronized|bucket|big|TCP-STATES}\n" +" TCP-STATES := {established|syn-sent|syn-recv|fin-wait-{1,2}|time-wait|closed|close-wait|last-ack|listen|closing}\n" +" connected := {established|syn-sent|syn-recv|fin-wait-{1,2}|time-wait|close-wait|last-ack|closing}\n" +" synchronized := {established|syn-recv|fin-wait-{1,2}|time-wait|close-wait|last-ack|closing}\n" +" bucket := {syn-recv|time-wait}\n" +" big := {established|syn-sent|fin-wait-{1,2}|closed|close-wait|last-ack|listen|closing}\n" ); } From 27b14f2e87c721e361e1926087a6f9566d25d764 Mon Sep 17 00:00:00 2001 From: Vadim Kochan Date: Tue, 13 Jan 2015 20:14:23 +0200 Subject: [PATCH 6/8] Add define for nlmsg_types with timestamp Add #define for nlmsg_type = 15 Signed-off-by: Vadim Kochan --- bridge/monitor.c | 4 +--- include/libnetlink.h | 4 ++++ ip/ipmonitor.c | 2 +- ip/rtmon.c | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/bridge/monitor.c b/bridge/monitor.c index 76e7d477..f00e0a6b 100644 --- a/bridge/monitor.c +++ b/bridge/monitor.c @@ -74,14 +74,12 @@ static int accept_msg(const struct sockaddr_nl *who, fprintf(fp, "[MDB]"); return print_mdb(who, n, arg); - case 15: + case NLMSG_TSTAMP: return show_mark(fp, n); default: return 0; } - - } int do_monitor(int argc, char **argv) diff --git a/include/libnetlink.h b/include/libnetlink.h index de7c85f3..d081e542 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -158,5 +158,9 @@ extern int rtnl_from_file(FILE *, rtnl_filter_t handler, #define NDTA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ndtmsg)) #endif +/* User defined nlmsg_type which is used mostly for logging netlink + * messages from dump file */ +#define NLMSG_TSTAMP 15 + #endif /* __LIBNETLINK_H__ */ diff --git a/ip/ipmonitor.c b/ip/ipmonitor.c index 4708e54d..f40daac0 100644 --- a/ip/ipmonitor.c +++ b/ip/ipmonitor.c @@ -125,7 +125,7 @@ static int accept_msg(const struct sockaddr_nl *who, print_netconf(who, n, arg); return 0; } - if (n->nlmsg_type == 15) { + if (n->nlmsg_type == NLMSG_TSTAMP) { char *tstr; time_t secs = ((__u32*)NLMSG_DATA(n))[0]; long usecs = ((__u32*)NLMSG_DATA(n))[1]; diff --git a/ip/rtmon.c b/ip/rtmon.c index 9227eacc..ff685e53 100644 --- a/ip/rtmon.c +++ b/ip/rtmon.c @@ -34,7 +34,7 @@ static void write_stamp(FILE *fp) struct nlmsghdr *n1 = (void*)buf; struct timeval tv; - n1->nlmsg_type = 15; + n1->nlmsg_type = NLMSG_TSTAMP; n1->nlmsg_flags = 0; n1->nlmsg_seq = 0; n1->nlmsg_pid = 0; From ddb1129b7569235e29990dfeab8c02c4f7258c18 Mon Sep 17 00:00:00 2001 From: Vadim Kochan Date: Tue, 13 Jan 2015 20:14:24 +0200 Subject: [PATCH 7/8] Use one func to print timestamp from nlmsg Signed-off-by: Vadim Kochan --- bridge/monitor.c | 14 ++------------ include/utils.h | 2 ++ ip/ipmonitor.c | 7 +------ lib/utils.c | 10 ++++++++++ 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/bridge/monitor.c b/bridge/monitor.c index f00e0a6b..9e1ed48c 100644 --- a/bridge/monitor.c +++ b/bridge/monitor.c @@ -35,17 +35,6 @@ static void usage(void) exit(-1); } -static int show_mark(FILE *fp, const struct nlmsghdr *n) -{ - char *tstr; - time_t secs = ((__u32*)NLMSG_DATA(n))[0]; - long usecs = ((__u32*)NLMSG_DATA(n))[1]; - tstr = asctime(localtime(&secs)); - tstr[strlen(tstr)-1] = 0; - fprintf(fp, "Timestamp: %s %lu us\n", tstr, usecs); - return 0; -} - static int accept_msg(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) { @@ -75,7 +64,8 @@ static int accept_msg(const struct sockaddr_nl *who, return print_mdb(who, n, arg); case NLMSG_TSTAMP: - return show_mark(fp, n); + print_nlmsg_timestamp(fp, n); + return 0; default: return 0; diff --git a/include/utils.h b/include/utils.h index eecbc398..e1fe7cfc 100644 --- a/include/utils.h +++ b/include/utils.h @@ -148,6 +148,7 @@ static inline __u32 nl_mgrp(__u32 group) int print_timestamp(FILE *fp); +void print_nlmsg_timestamp(FILE *fp, const struct nlmsghdr *n); #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) @@ -160,4 +161,5 @@ struct iplink_req; int iplink_parse(int argc, char **argv, struct iplink_req *req, char **name, char **type, char **link, char **dev, int *group, int *index); + #endif /* __UTILS_H__ */ diff --git a/ip/ipmonitor.c b/ip/ipmonitor.c index f40daac0..5ec8f418 100644 --- a/ip/ipmonitor.c +++ b/ip/ipmonitor.c @@ -126,12 +126,7 @@ static int accept_msg(const struct sockaddr_nl *who, return 0; } if (n->nlmsg_type == NLMSG_TSTAMP) { - char *tstr; - time_t secs = ((__u32*)NLMSG_DATA(n))[0]; - long usecs = ((__u32*)NLMSG_DATA(n))[1]; - tstr = asctime(localtime(&secs)); - tstr[strlen(tstr)-1] = 0; - fprintf(fp, "Timestamp: %s %lu us\n", tstr, usecs); + print_nlmsg_timestamp(fp, n); return 0; } if (n->nlmsg_type != NLMSG_ERROR && n->nlmsg_type != NLMSG_NOOP && diff --git a/lib/utils.c b/lib/utils.c index 64915f3a..f65ceaaf 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -868,3 +868,13 @@ int inet_get_addr(const char *src, __u32 *dst, struct in6_addr *dst6) else return inet_pton(AF_INET, src, dst); } + +void print_nlmsg_timestamp(FILE *fp, const struct nlmsghdr *n) +{ + char *tstr; + time_t secs = ((__u32*)NLMSG_DATA(n))[0]; + long usecs = ((__u32*)NLMSG_DATA(n))[1]; + tstr = asctime(localtime(&secs)); + tstr[strlen(tstr)-1] = 0; + fprintf(fp, "Timestamp: %s %lu us\n", tstr, usecs); +} From c3087c10f167ab30fc8f4fbe9897156a619f1c67 Mon Sep 17 00:00:00 2001 From: Vadim Kochan Date: Tue, 13 Jan 2015 22:08:44 +0200 Subject: [PATCH 8/8] netns: Rename & move get_netns_fd to lib Renamed get_netns_fd -> netns_get_fd and moved to lib/namespace.c Signed-off-by: Vadim Kochan --- include/namespace.h | 1 + ip/ip_common.h | 1 - ip/iplink.c | 3 ++- ip/ipnetns.c | 15 --------------- lib/namespace.c | 15 +++++++++++++++ 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/include/namespace.h b/include/namespace.h index 2f13e659..b8c5cad6 100644 --- a/include/namespace.h +++ b/include/namespace.h @@ -42,5 +42,6 @@ static int setns(int fd, int nstype) #endif /* HAVE_SETNS */ extern int netns_switch(char *netns); +extern int netns_get_fd(const char *netns); #endif /* __NAMESPACE_H__ */ diff --git a/ip/ip_common.h b/ip/ip_common.h index 75bfb824..89a495ea 100644 --- a/ip/ip_common.h +++ b/ip/ip_common.h @@ -87,7 +87,6 @@ struct link_util struct link_util *get_link_kind(const char *kind); struct link_util *get_link_slave_kind(const char *slave_kind); -int get_netns_fd(const char *name); #ifndef INFINITY_LIFE_TIME #define INFINITY_LIFE_TIME 0xFFFFFFFFU diff --git a/ip/iplink.c b/ip/iplink.c index 2709173a..c93d1dc3 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -32,6 +32,7 @@ #include "rt_names.h" #include "utils.h" #include "ip_common.h" +#include "namespace.h" #define IPLINK_IOCTL_COMPAT 1 #ifndef LIBDIR @@ -440,7 +441,7 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, NEXT_ARG(); if (netns != -1) duparg("netns", *argv); - if ((netns = get_netns_fd(*argv)) >= 0) + if ((netns = netns_get_fd(*argv)) >= 0) addattr_l(&req->n, sizeof(*req), IFLA_NET_NS_FD, &netns, 4); else if (get_integer(&netns, *argv, 0) == 0) addattr_l(&req->n, sizeof(*req), IFLA_NET_NS_PID, &netns, 4); diff --git a/ip/ipnetns.c b/ip/ipnetns.c index 519d5183..123318eb 100644 --- a/ip/ipnetns.c +++ b/ip/ipnetns.c @@ -31,21 +31,6 @@ static int usage(void) exit(-1); } -int get_netns_fd(const char *name) -{ - char pathbuf[MAXPATHLEN]; - const char *path, *ptr; - - path = name; - ptr = strchr(name, '/'); - if (!ptr) { - snprintf(pathbuf, sizeof(pathbuf), "%s/%s", - NETNS_RUN_DIR, name ); - path = pathbuf; - } - return open(path, O_RDONLY); -} - static int netns_list(int argc, char **argv) { struct dirent *entry; diff --git a/lib/namespace.c b/lib/namespace.c index 1554ce08..65c1e3d7 100644 --- a/lib/namespace.c +++ b/lib/namespace.c @@ -84,3 +84,18 @@ int netns_switch(char *name) bind_etc(name); return 0; } + +int netns_get_fd(const char *name) +{ + char pathbuf[MAXPATHLEN]; + const char *path, *ptr; + + path = name; + ptr = strchr(name, '/'); + if (!ptr) { + snprintf(pathbuf, sizeof(pathbuf), "%s/%s", + NETNS_RUN_DIR, name ); + path = pathbuf; + } + return open(path, O_RDONLY); +}