diff --git a/bridge/monitor.c b/bridge/monitor.c index 76e7d477..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) { @@ -74,14 +63,13 @@ static int accept_msg(const struct sockaddr_nl *who, fprintf(fp, "[MDB]"); return print_mdb(who, n, arg); - case 15: - return show_mark(fp, n); + case NLMSG_TSTAMP: + print_nlmsg_timestamp(fp, n); + return 0; 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/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/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/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/ipaddress.c b/ip/ipaddress.c index 28dfe8ce..d5e863dd 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -255,15 +255,37 @@ 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; 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); @@ -277,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. @@ -313,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"); @@ -658,6 +685,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])); 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/ipmonitor.c b/ip/ipmonitor.c index 4708e54d..5ec8f418 100644 --- a/ip/ipmonitor.c +++ b/ip/ipmonitor.c @@ -125,13 +125,8 @@ static int accept_msg(const struct sockaddr_nl *who, print_netconf(who, n, arg); return 0; } - if (n->nlmsg_type == 15) { - 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); + if (n->nlmsg_type == NLMSG_TSTAMP) { + print_nlmsg_timestamp(fp, n); return 0; } if (n->nlmsg_type != NLMSG_ERROR && n->nlmsg_type != NLMSG_NOOP && 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/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; 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); +} 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); +} diff --git a/misc/ss.c b/misc/ss.c index 08d210ae..f434f57f 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<action, b1, sizeof (b1))); fprintf(f, "\n\t index %d ref %d bind %d", parm->index, parm->refcnt, parm->bindcnt);