Commit 56f5daac authored by Stephen Hemminger's avatar Stephen Hemminger

ip: code cleanup

Run all the ip code through checkpatch and have it fix the obvious stuff.
parent 32a121cb
...@@ -50,7 +50,7 @@ static void usage(void) ...@@ -50,7 +50,7 @@ static void usage(void)
fprintf(stderr, " [ mode { ip6ip6 | ipip6 | ip6gre | vti6 | any } ]\n"); fprintf(stderr, " [ mode { ip6ip6 | ipip6 | ip6gre | vti6 | any } ]\n");
fprintf(stderr, " [ remote ADDR local ADDR ] [ dev PHYS_DEV ]\n"); fprintf(stderr, " [ remote ADDR local ADDR ] [ dev PHYS_DEV ]\n");
fprintf(stderr, " [ encaplimit ELIM ]\n"); fprintf(stderr, " [ encaplimit ELIM ]\n");
fprintf(stderr ," [ hoplimit TTL ] [ tclass TCLASS ] [ flowlabel FLOWLABEL ]\n"); fprintf(stderr, " [ hoplimit TTL ] [ tclass TCLASS ] [ flowlabel FLOWLABEL ]\n");
fprintf(stderr, " [ dscp inherit ]\n"); fprintf(stderr, " [ dscp inherit ]\n");
fprintf(stderr, " [ [i|o]seq ] [ [i|o]key KEY ] [ [i|o]csum ]\n"); fprintf(stderr, " [ [i|o]seq ] [ [i|o]key KEY ] [ [i|o]csum ]\n");
fprintf(stderr, "\n"); fprintf(stderr, "\n");
...@@ -81,6 +81,7 @@ static void print_tunnel(struct ip6_tnl_parm2 *p) ...@@ -81,6 +81,7 @@ static void print_tunnel(struct ip6_tnl_parm2 *p)
rt_addr_n2a(AF_INET6, 16, &p->laddr, s2, sizeof(s2))); rt_addr_n2a(AF_INET6, 16, &p->laddr, s2, sizeof(s2)));
if (p->link) { if (p->link) {
const char *n = ll_index_to_name(p->link); const char *n = ll_index_to_name(p->link);
if (n) if (n)
printf(" dev %s", n); printf(" dev %s", n);
} }
...@@ -96,6 +97,7 @@ static void print_tunnel(struct ip6_tnl_parm2 *p) ...@@ -96,6 +97,7 @@ static void print_tunnel(struct ip6_tnl_parm2 *p)
printf(" tclass inherit"); printf(" tclass inherit");
else { else {
__u32 val = ntohl(p->flowinfo & IP6_FLOWINFO_TCLASS); __u32 val = ntohl(p->flowinfo & IP6_FLOWINFO_TCLASS);
printf(" tclass 0x%02x", (__u8)(val >> 20)); printf(" tclass 0x%02x", (__u8)(val >> 20));
} }
...@@ -158,11 +160,12 @@ static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p) ...@@ -158,11 +160,12 @@ static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p)
strcmp(*argv, "any") == 0) strcmp(*argv, "any") == 0)
p->proto = 0; p->proto = 0;
else { else {
fprintf(stderr,"Unknown tunnel mode \"%s\"\n", *argv); fprintf(stderr, "Unknown tunnel mode \"%s\"\n", *argv);
exit(-1); exit(-1);
} }
} else if (strcmp(*argv, "remote") == 0) { } else if (strcmp(*argv, "remote") == 0) {
inet_prefix raddr; inet_prefix raddr;
NEXT_ARG(); NEXT_ARG();
get_prefix(&raddr, *argv, preferred_family); get_prefix(&raddr, *argv, preferred_family);
if (raddr.family == AF_UNSPEC) if (raddr.family == AF_UNSPEC)
...@@ -170,6 +173,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p) ...@@ -170,6 +173,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p)
memcpy(&p->raddr, &raddr.data, sizeof(p->raddr)); memcpy(&p->raddr, &raddr.data, sizeof(p->raddr));
} else if (strcmp(*argv, "local") == 0) { } else if (strcmp(*argv, "local") == 0) {
inet_prefix laddr; inet_prefix laddr;
NEXT_ARG(); NEXT_ARG();
get_prefix(&laddr, *argv, preferred_family); get_prefix(&laddr, *argv, preferred_family);
if (laddr.family == AF_UNSPEC) if (laddr.family == AF_UNSPEC)
...@@ -184,6 +188,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p) ...@@ -184,6 +188,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p)
p->flags |= IP6_TNL_F_IGN_ENCAP_LIMIT; p->flags |= IP6_TNL_F_IGN_ENCAP_LIMIT;
} else { } else {
__u8 uval; __u8 uval;
if (get_u8(&uval, *argv, 0) < -1) if (get_u8(&uval, *argv, 0) < -1)
invarg("invalid ELIM", *argv); invarg("invalid ELIM", *argv);
p->encap_limit = uval; p->encap_limit = uval;
...@@ -193,6 +198,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p) ...@@ -193,6 +198,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p)
strcmp(*argv, "ttl") == 0 || strcmp(*argv, "ttl") == 0 ||
strcmp(*argv, "hlim") == 0) { strcmp(*argv, "hlim") == 0) {
__u8 uval; __u8 uval;
NEXT_ARG(); NEXT_ARG();
if (get_u8(&uval, *argv, 0)) if (get_u8(&uval, *argv, 0))
invarg("invalid TTL", *argv); invarg("invalid TTL", *argv);
...@@ -202,6 +208,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p) ...@@ -202,6 +208,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p)
strcmp(*argv, "tos") == 0 || strcmp(*argv, "tos") == 0 ||
matches(*argv, "dsfield") == 0) { matches(*argv, "dsfield") == 0) {
__u8 uval; __u8 uval;
NEXT_ARG(); NEXT_ARG();
p->flowinfo &= ~IP6_FLOWINFO_TCLASS; p->flowinfo &= ~IP6_FLOWINFO_TCLASS;
if (strcmp(*argv, "inherit") == 0) if (strcmp(*argv, "inherit") == 0)
...@@ -215,6 +222,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p) ...@@ -215,6 +222,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p)
} else if (strcmp(*argv, "flowlabel") == 0 || } else if (strcmp(*argv, "flowlabel") == 0 ||
strcmp(*argv, "fl") == 0) { strcmp(*argv, "fl") == 0) {
__u32 uval; __u32 uval;
NEXT_ARG(); NEXT_ARG();
p->flowinfo &= ~IP6_FLOWINFO_FLOWLABEL; p->flowinfo &= ~IP6_FLOWINFO_FLOWLABEL;
if (strcmp(*argv, "inherit") == 0) if (strcmp(*argv, "inherit") == 0)
...@@ -269,6 +277,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p) ...@@ -269,6 +277,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p)
strncpy(p->name, *argv, IFNAMSIZ - 1); strncpy(p->name, *argv, IFNAMSIZ - 1);
if (cmd == SIOCCHGTUNNEL && count == 0) { if (cmd == SIOCCHGTUNNEL && count == 0) {
struct ip6_tnl_parm2 old_p; struct ip6_tnl_parm2 old_p;
memset(&old_p, 0, sizeof(old_p)); memset(&old_p, 0, sizeof(old_p));
if (tnl_get_ioctl(*argv, &old_p)) if (tnl_get_ioctl(*argv, &old_p))
return -1; return -1;
...@@ -326,6 +335,7 @@ static int do_tunnels_list(struct ip6_tnl_parm2 *p) ...@@ -326,6 +335,7 @@ static int do_tunnels_list(struct ip6_tnl_parm2 *p)
char buf[512]; char buf[512];
int err = -1; int err = -1;
FILE *fp = fopen("/proc/net/dev", "r"); FILE *fp = fopen("/proc/net/dev", "r");
if (fp == NULL) { if (fp == NULL) {
perror("fopen"); perror("fopen");
return -1; return -1;
...@@ -387,14 +397,14 @@ static int do_tunnels_list(struct ip6_tnl_parm2 *p) ...@@ -387,14 +397,14 @@ static int do_tunnels_list(struct ip6_tnl_parm2 *p)
static int do_show(int argc, char **argv) static int do_show(int argc, char **argv)
{ {
struct ip6_tnl_parm2 p; struct ip6_tnl_parm2 p;
ll_init_map(&rth); ll_init_map(&rth);
ip6_tnl_parm_init(&p, 0); ip6_tnl_parm_init(&p, 0);
p.proto = 0; /* default to any */ p.proto = 0; /* default to any */
if (parse_args(argc, argv, SIOCGETTUNNEL, &p) < 0) if (parse_args(argc, argv, SIOCGETTUNNEL, &p) < 0)
return -1; return -1;
if (!p.name[0] || show_stats) if (!p.name[0] || show_stats)
do_tunnels_list(&p); do_tunnels_list(&p);
...@@ -405,7 +415,7 @@ static int do_show(int argc, char **argv) ...@@ -405,7 +415,7 @@ static int do_show(int argc, char **argv)
printf("\n"); printf("\n");
} }
return 0; return 0;
} }
static int do_add(int cmd, int argc, char **argv) static int do_add(int cmd, int argc, char **argv)
......
...@@ -93,7 +93,7 @@ static void usage(void) ...@@ -93,7 +93,7 @@ static void usage(void)
exit(-1); exit(-1);
} }
static void print_link_flags(FILE *fp, unsigned flags, unsigned mdown) static void print_link_flags(FILE *fp, unsigned int flags, unsigned int mdown)
{ {
fprintf(fp, "<"); fprintf(fp, "<");
if (flags & IFF_UP && !(flags & IFF_RUNNING)) if (flags & IFF_UP && !(flags & IFF_RUNNING))
...@@ -135,7 +135,7 @@ static const char *oper_states[] = { ...@@ -135,7 +135,7 @@ static const char *oper_states[] = {
static void print_operstate(FILE *f, __u8 state) static void print_operstate(FILE *f, __u8 state)
{ {
if (state >= sizeof(oper_states)/sizeof(oper_states[0])) if (state >= ARRAY_SIZE(oper_states))
fprintf(f, "state %#x ", state); fprintf(f, "state %#x ", state);
else { else {
if (brief) { if (brief) {
...@@ -161,7 +161,7 @@ int get_operstate(const char *name) ...@@ -161,7 +161,7 @@ int get_operstate(const char *name)
{ {
int i; int i;
for (i = 0; i < sizeof(oper_states)/sizeof(oper_states[0]); i++) for (i = 0; i < ARRAY_SIZE(oper_states); i++)
if (strcasecmp(name, oper_states[i]) == 0) if (strcasecmp(name, oper_states[i]) == 0)
return i; return i;
return -1; return -1;
...@@ -202,7 +202,7 @@ static void print_linkmode(FILE *f, struct rtattr *tb) ...@@ -202,7 +202,7 @@ static void print_linkmode(FILE *f, struct rtattr *tb)
{ {
unsigned int mode = rta_getattr_u8(tb); unsigned int mode = rta_getattr_u8(tb);
if (mode >= sizeof(link_modes) / sizeof(link_modes[0])) if (mode >= ARRAY_SIZE(link_modes))
fprintf(f, "mode %d ", mode); fprintf(f, "mode %d ", mode);
else else
fprintf(f, "mode %s ", link_modes[mode]); fprintf(f, "mode %s ", link_modes[mode]);
...@@ -286,6 +286,7 @@ static void print_af_spec(FILE *fp, struct rtattr *af_spec_attr) ...@@ -286,6 +286,7 @@ static void print_af_spec(FILE *fp, struct rtattr *af_spec_attr)
if (tb[IFLA_INET6_ADDR_GEN_MODE]) { if (tb[IFLA_INET6_ADDR_GEN_MODE]) {
__u8 mode = rta_getattr_u8(tb[IFLA_INET6_ADDR_GEN_MODE]); __u8 mode = rta_getattr_u8(tb[IFLA_INET6_ADDR_GEN_MODE]);
switch (mode) { switch (mode) {
case IN6_ADDR_GEN_MODE_EUI64: case IN6_ADDR_GEN_MODE_EUI64:
fprintf(fp, "addrgenmode eui64 "); fprintf(fp, "addrgenmode eui64 ");
...@@ -317,6 +318,7 @@ static void print_vfinfo(FILE *fp, struct rtattr *vfinfo) ...@@ -317,6 +318,7 @@ static void print_vfinfo(FILE *fp, struct rtattr *vfinfo)
struct ifla_vf_link_state *vf_linkstate; struct ifla_vf_link_state *vf_linkstate;
struct rtattr *vf[IFLA_VF_MAX + 1] = {}; struct rtattr *vf[IFLA_VF_MAX + 1] = {};
struct rtattr *tmp; struct rtattr *tmp;
SPRINT_BUF(b1); SPRINT_BUF(b1);
if (vfinfo->rta_type != IFLA_VF_INFO) { if (vfinfo->rta_type != IFLA_VF_INFO) {
...@@ -392,7 +394,7 @@ static void print_vfinfo(FILE *fp, struct rtattr *vfinfo) ...@@ -392,7 +394,7 @@ static void print_vfinfo(FILE *fp, struct rtattr *vfinfo)
print_vf_stats64(fp, vf[IFLA_VF_STATS]); print_vf_stats64(fp, vf[IFLA_VF_STATS]);
} }
static void print_num(FILE *fp, unsigned width, uint64_t count) static void print_num(FILE *fp, unsigned int width, uint64_t count)
{ {
const char *prefix = "kMGTPE"; const char *prefix = "kMGTPE";
const unsigned int base = use_iec ? 1024 : 1000; const unsigned int base = use_iec ? 1024 : 1000;
...@@ -408,7 +410,7 @@ static void print_num(FILE *fp, unsigned width, uint64_t count) ...@@ -408,7 +410,7 @@ static void print_num(FILE *fp, unsigned width, uint64_t count)
/* increase value by a factor of 1000/1024 and print /* increase value by a factor of 1000/1024 and print
* if result is something a human can read */ * if result is something a human can read */
for(;;) { for (;;) {
powi *= base; powi *= base;
if (count / base < powi) if (count / base < powi)
break; break;
...@@ -462,7 +464,7 @@ static void print_vf_stats64(FILE *fp, struct rtattr *vfstats) ...@@ -462,7 +464,7 @@ static void print_vf_stats64(FILE *fp, struct rtattr *vfstats)
} }
static void print_link_stats64(FILE *fp, const struct rtnl_link_stats64 *s, static void print_link_stats64(FILE *fp, const struct rtnl_link_stats64 *s,
const struct rtattr *carrier_changes) const struct rtattr *carrier_changes)
{ {
/* RX stats */ /* RX stats */
fprintf(fp, " RX: bytes packets errors dropped overrun mcast %s%s", fprintf(fp, " RX: bytes packets errors dropped overrun mcast %s%s",
...@@ -514,7 +516,7 @@ static void print_link_stats64(FILE *fp, const struct rtnl_link_stats64 *s, ...@@ -514,7 +516,7 @@ static void print_link_stats64(FILE *fp, const struct rtnl_link_stats64 *s,
if (show_stats > 1) { if (show_stats > 1) {
fprintf(fp, "%s", _SL_); fprintf(fp, "%s", _SL_);
fprintf(fp, " TX errors: aborted fifo window heartbeat"); fprintf(fp, " TX errors: aborted fifo window heartbeat");
if (carrier_changes) if (carrier_changes)
fprintf(fp, " transns"); fprintf(fp, " transns");
fprintf(fp, "%s", _SL_); fprintf(fp, "%s", _SL_);
...@@ -524,7 +526,7 @@ static void print_link_stats64(FILE *fp, const struct rtnl_link_stats64 *s, ...@@ -524,7 +526,7 @@ static void print_link_stats64(FILE *fp, const struct rtnl_link_stats64 *s,
print_num(fp, 7, s->tx_window_errors); print_num(fp, 7, s->tx_window_errors);
print_num(fp, 7, s->tx_heartbeat_errors); print_num(fp, 7, s->tx_heartbeat_errors);
if (carrier_changes) if (carrier_changes)
print_num(fp, 7, *(uint32_t*)RTA_DATA(carrier_changes)); print_num(fp, 7, *(uint32_t *)RTA_DATA(carrier_changes));
} }
} }
...@@ -580,7 +582,7 @@ static void print_link_stats32(FILE *fp, const struct rtnl_link_stats *s, ...@@ -580,7 +582,7 @@ static void print_link_stats32(FILE *fp, const struct rtnl_link_stats *s,
if (show_stats > 1) { if (show_stats > 1) {
fprintf(fp, "%s", _SL_); fprintf(fp, "%s", _SL_);
fprintf(fp, " TX errors: aborted fifo window heartbeat"); fprintf(fp, " TX errors: aborted fifo window heartbeat");
if (carrier_changes) if (carrier_changes)
fprintf(fp, " transns"); fprintf(fp, " transns");
fprintf(fp, "%s", _SL_); fprintf(fp, "%s", _SL_);
...@@ -590,7 +592,7 @@ static void print_link_stats32(FILE *fp, const struct rtnl_link_stats *s, ...@@ -590,7 +592,7 @@ static void print_link_stats32(FILE *fp, const struct rtnl_link_stats *s,
print_num(fp, 7, s->tx_window_errors); print_num(fp, 7, s->tx_window_errors);
print_num(fp, 7, s->tx_heartbeat_errors); print_num(fp, 7, s->tx_heartbeat_errors);
if (carrier_changes) if (carrier_changes)
print_num(fp, 7, *(uint32_t*)RTA_DATA(carrier_changes)); print_num(fp, 7, *(uint32_t *)RTA_DATA(carrier_changes));
} }
} }
...@@ -618,7 +620,7 @@ static void __print_link_stats(FILE *fp, struct rtattr **tb) ...@@ -618,7 +620,7 @@ static void __print_link_stats(FILE *fp, struct rtattr **tb)
static void print_link_stats(FILE *fp, struct nlmsghdr *n) static void print_link_stats(FILE *fp, struct nlmsghdr *n)
{ {
struct ifinfomsg *ifi = NLMSG_DATA(n); struct ifinfomsg *ifi = NLMSG_DATA(n);
struct rtattr * tb[IFLA_MAX+1]; struct rtattr *tb[IFLA_MAX+1];
parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi),
n->nlmsg_len - NLMSG_LENGTH(sizeof(*ifi))); n->nlmsg_len - NLMSG_LENGTH(sizeof(*ifi)));
...@@ -629,13 +631,13 @@ static void print_link_stats(FILE *fp, struct nlmsghdr *n) ...@@ -629,13 +631,13 @@ static void print_link_stats(FILE *fp, struct nlmsghdr *n)
int print_linkinfo_brief(const struct sockaddr_nl *who, int print_linkinfo_brief(const struct sockaddr_nl *who,
struct nlmsghdr *n, void *arg) struct nlmsghdr *n, void *arg)
{ {
FILE *fp = (FILE*)arg; FILE *fp = (FILE *)arg;
struct ifinfomsg *ifi = NLMSG_DATA(n); struct ifinfomsg *ifi = NLMSG_DATA(n);
struct rtattr * tb[IFLA_MAX+1]; struct rtattr *tb[IFLA_MAX+1];
int len = n->nlmsg_len; int len = n->nlmsg_len;
char *name; char *name;
char buf[32] = { 0, }; char buf[32] = { 0, };
unsigned m_flag = 0; unsigned int m_flag = 0;
if (n->nlmsg_type != RTM_NEWLINK && n->nlmsg_type != RTM_DELLINK) if (n->nlmsg_type != RTM_NEWLINK && n->nlmsg_type != RTM_DELLINK)
return -1; return -1;
...@@ -659,17 +661,18 @@ int print_linkinfo_brief(const struct sockaddr_nl *who, ...@@ -659,17 +661,18 @@ int print_linkinfo_brief(const struct sockaddr_nl *who,
return -1; return -1;
if (tb[IFLA_GROUP]) { if (tb[IFLA_GROUP]) {
int group = *(int*)RTA_DATA(tb[IFLA_GROUP]); int group = *(int *)RTA_DATA(tb[IFLA_GROUP]);
if (filter.group != -1 && group != filter.group) if (filter.group != -1 && group != filter.group)
return -1; return -1;
} }
if (tb[IFLA_MASTER]) { if (tb[IFLA_MASTER]) {
int master = *(int*)RTA_DATA(tb[IFLA_MASTER]); int master = *(int *)RTA_DATA(tb[IFLA_MASTER]);
if (filter.master > 0 && master != filter.master) if (filter.master > 0 && master != filter.master)
return -1; return -1;
} } else if (filter.master > 0)
else if (filter.master > 0)
return -1; return -1;
if (filter.kind) { if (filter.kind) {
...@@ -690,7 +693,8 @@ int print_linkinfo_brief(const struct sockaddr_nl *who, ...@@ -690,7 +693,8 @@ int print_linkinfo_brief(const struct sockaddr_nl *who,
if (tb[IFLA_LINK]) { if (tb[IFLA_LINK]) {
SPRINT_BUF(b1); SPRINT_BUF(b1);
int iflink = *(int*)RTA_DATA(tb[IFLA_LINK]); int iflink = *(int *)RTA_DATA(tb[IFLA_LINK]);
if (iflink == 0) if (iflink == 0)
snprintf(buf, sizeof(buf), "%s@NONE", name); snprintf(buf, sizeof(buf), "%s@NONE", name);
else { else {
...@@ -730,11 +734,11 @@ int print_linkinfo_brief(const struct sockaddr_nl *who, ...@@ -730,11 +734,11 @@ int print_linkinfo_brief(const struct sockaddr_nl *who,
int print_linkinfo(const struct sockaddr_nl *who, int print_linkinfo(const struct sockaddr_nl *who,
struct nlmsghdr *n, void *arg) struct nlmsghdr *n, void *arg)
{ {
FILE *fp = (FILE*)arg; FILE *fp = (FILE *)arg;
struct ifinfomsg *ifi = NLMSG_DATA(n); struct ifinfomsg *ifi = NLMSG_DATA(n);
struct rtattr * tb[IFLA_MAX+1]; struct rtattr *tb[IFLA_MAX+1];
int len = n->nlmsg_len; int len = n->nlmsg_len;
unsigned m_flag = 0; unsigned int m_flag = 0;
if (n->nlmsg_type != RTM_NEWLINK && n->nlmsg_type != RTM_DELLINK) if (n->nlmsg_type != RTM_NEWLINK && n->nlmsg_type != RTM_DELLINK)
return 0; return 0;
...@@ -758,17 +762,18 @@ int print_linkinfo(const struct sockaddr_nl *who, ...@@ -758,17 +762,18 @@ int print_linkinfo(const struct sockaddr_nl *who,
return 0; return 0;
if (tb[IFLA_GROUP]) { if (tb[IFLA_GROUP]) {
int group = *(int*)RTA_DATA(tb[IFLA_GROUP]); int group = *(int *)RTA_DATA(tb[IFLA_GROUP]);
if (filter.group != -1 && group != filter.group) if (filter.group != -1 && group != filter.group)
return -1; return -1;
} }
if (tb[IFLA_MASTER]) { if (tb[IFLA_MASTER]) {
int master = *(int*)RTA_DATA(tb[IFLA_MASTER]); int master = *(int *)RTA_DATA(tb[IFLA_MASTER]);
if (filter.master > 0 && master != filter.master) if (filter.master > 0 && master != filter.master)
return -1; return -1;
} } else if (filter.master > 0)
else if (filter.master > 0)
return -1; return -1;
if (filter.kind) { if (filter.kind) {
...@@ -791,7 +796,8 @@ int print_linkinfo(const struct sockaddr_nl *who, ...@@ -791,7 +796,8 @@ int print_linkinfo(const struct sockaddr_nl *who,
if (tb[IFLA_LINK]) { if (tb[IFLA_LINK]) {
SPRINT_BUF(b1); SPRINT_BUF(b1);
int iflink = *(int*)RTA_DATA(tb[IFLA_LINK]); int iflink = *(int *)RTA_DATA(tb[IFLA_LINK]);
if (iflink == 0) if (iflink == 0)
fprintf(fp, "@NONE: "); fprintf(fp, "@NONE: ");
else { else {
...@@ -809,12 +815,12 @@ int print_linkinfo(const struct sockaddr_nl *who, ...@@ -809,12 +815,12 @@ int print_linkinfo(const struct sockaddr_nl *who,
print_link_flags(fp, ifi->ifi_flags, m_flag); print_link_flags(fp, ifi->ifi_flags, m_flag);
if (tb[IFLA_MTU]) if (tb[IFLA_MTU])
fprintf(fp, "mtu %u ", *(int*)RTA_DATA(tb[IFLA_MTU])); fprintf(fp, "mtu %u ", *(int *)RTA_DATA(tb[IFLA_MTU]));
if (tb[IFLA_QDISC]) if (tb[IFLA_QDISC])
fprintf(fp, "qdisc %s ", rta_getattr_str(tb[IFLA_QDISC])); fprintf(fp, "qdisc %s ", rta_getattr_str(tb[IFLA_QDISC]));
if (tb[IFLA_MASTER]) { if (tb[IFLA_MASTER]) {
SPRINT_BUF(b1); SPRINT_BUF(b1);
fprintf(fp, "master %s ", ll_idx_n2a(*(int*)RTA_DATA(tb[IFLA_MASTER]), b1)); fprintf(fp, "master %s ", ll_idx_n2a(*(int *)RTA_DATA(tb[IFLA_MASTER]), b1));
} }
if (tb[IFLA_PHYS_PORT_ID]) { if (tb[IFLA_PHYS_PORT_ID]) {
...@@ -841,7 +847,8 @@ int print_linkinfo(const struct sockaddr_nl *who, ...@@ -841,7 +847,8 @@ int print_linkinfo(const struct sockaddr_nl *who,
if (tb[IFLA_GROUP]) { if (tb[IFLA_GROUP]) {
SPRINT_BUF(b1); SPRINT_BUF(b1);
int group = *(int*)RTA_DATA(tb[IFLA_GROUP]); int group = *(int *)RTA_DATA(tb[IFLA_GROUP]);
fprintf(fp, "group %s ", rtnl_group_n2a(group, b1, sizeof(b1))); fprintf(fp, "group %s ", rtnl_group_n2a(group, b1, sizeof(b1)));
} }
...@@ -873,7 +880,7 @@ int print_linkinfo(const struct sockaddr_nl *who, ...@@ -873,7 +880,7 @@ int print_linkinfo(const struct sockaddr_nl *who,
} }
if (tb[IFLA_LINK_NETNSID]) { if (tb[IFLA_LINK_NETNSID]) {
int id = *(int*)RTA_DATA(tb[IFLA_LINK_NETNSID]); int id = *(int *)RTA_DATA(tb[IFLA_LINK_NETNSID]);
if (id >= 0) if (id >= 0)
fprintf(fp, " link-netnsid %d", id); fprintf(fp, " link-netnsid %d", id);
...@@ -888,7 +895,7 @@ int print_linkinfo(const struct sockaddr_nl *who, ...@@ -888,7 +895,7 @@ int print_linkinfo(const struct sockaddr_nl *who,
if (tb[IFLA_PROMISCUITY] && show_details) if (tb[IFLA_PROMISCUITY] && show_details)
fprintf(fp, " promiscuity %u ", fprintf(fp, " promiscuity %u ",
*(int*)RTA_DATA(tb[IFLA_PROMISCUITY])); *(int *)RTA_DATA(tb[IFLA_PROMISCUITY]));
if (tb[IFLA_LINKINFO] && show_details) if (tb[IFLA_LINKINFO] && show_details)
print_linktype(fp, tb[IFLA_LINKINFO]); print_linktype(fp, tb[IFLA_LINKINFO]);
...@@ -909,6 +916,7 @@ int print_linkinfo(const struct sockaddr_nl *who, ...@@ -909,6 +916,7 @@ int print_linkinfo(const struct sockaddr_nl *who,
if ((do_link || show_details) && tb[IFLA_VFINFO_LIST] && tb[IFLA_NUM_VF]) { if ((do_link || show_details) && tb[IFLA_VFINFO_LIST] && tb[IFLA_NUM_VF]) {
struct rtattr *i, *vflist = tb[IFLA_VFINFO_LIST]; struct rtattr *i, *vflist = tb[IFLA_VFINFO_LIST];
int rem = RTA_PAYLOAD(vflist); int rem = RTA_PAYLOAD(vflist);
for (i = RTA_DATA(vflist); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) for (i = RTA_DATA(vflist); RTA_OK(i, rem); i = RTA_NEXT(i, rem))
print_vfinfo(fp, i); print_vfinfo(fp, i);
} }
...@@ -964,8 +972,9 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n, ...@@ -964,8 +972,9 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
int deprecated = 0; int deprecated = 0;
/* Use local copy of ifa_flags to not interfere with filtering code */ /* Use local copy of ifa_flags to not interfere with filtering code */
unsigned int ifa_flags; unsigned int ifa_flags;
struct rtattr * rta_tb[IFA_MAX+1]; struct rtattr *rta_tb[IFA_MAX+1];
char abuf[256]; char abuf[256];
SPRINT_BUF(b1); SPRINT_BUF(b1);
if (n->nlmsg_type != RTM_NEWADDR && n->nlmsg_type != RTM_DELADDR) if (n->nlmsg_type != RTM_NEWADDR && n->nlmsg_type != RTM_DELADDR)
...@@ -998,6 +1007,7 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n, ...@@ -998,6 +1007,7 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
if (filter.label) { if (filter.label) {
SPRINT_BUF(b1); SPRINT_BUF(b1);
const char *label; const char *label;
if (rta_tb[IFA_LABEL]) if (rta_tb[IFA_LABEL])
label = RTA_DATA(rta_tb[IFA_LABEL]); label = RTA_DATA(rta_tb[IFA_LABEL]);
else else
...@@ -1008,6 +1018,7 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n, ...@@ -1008,6 +1018,7 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
if (filter.pfx.family) { if (filter.pfx.family) {
if (rta_tb[IFA_LOCAL]) { if (rta_tb[IFA_LOCAL]) {
inet_prefix dst; inet_prefix dst;
memset(&dst, 0, sizeof(dst)); memset(&dst, 0, sizeof(dst));
dst.family = ifa->ifa_family; dst.family = ifa->ifa_family;
memcpy(&dst.data, RTA_DATA(rta_tb[IFA_LOCAL]), RTA_PAYLOAD(rta_tb[IFA_LOCAL])); memcpy(&dst.data, RTA_DATA(rta_tb[IFA_LOCAL]), RTA_PAYLOAD(rta_tb[IFA_LOCAL]));
...@@ -1021,16 +1032,17 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n, ...@@ -1021,16 +1032,17 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
if (filter.flushb) { if (filter.flushb) {
struct nlmsghdr *fn; struct nlmsghdr *fn;
if (NLMSG_ALIGN(filter.flushp) + n->nlmsg_len > filter.flushe) { if (NLMSG_ALIGN(filter.flushp) + n->nlmsg_len > filter.flushe) {
if (flush_update()) if (flush_update())
return -1; return -1;
} }
fn = (struct nlmsghdr*)(filter.flushb + NLMSG_ALIGN(filter.flushp)); fn = (struct nlmsghdr *)(filter.flushb + NLMSG_ALIGN(filter.flushp));
memcpy(fn, n, n->nlmsg_len); memcpy(fn, n, n->nlmsg_len);
fn->nlmsg_type = RTM_DELADDR; fn->nlmsg_type = RTM_DELADDR;
fn->nlmsg_flags = NLM_F_REQUEST; fn->nlmsg_flags = NLM_F_REQUEST;
fn->nlmsg_seq = ++rth.seq; fn->nlmsg_seq = ++rth.seq;
filter.flushp = (((char*)fn) + n->nlmsg_len) - filter.flushb; filter.flushp = (((char *)fn) + n->nlmsg_len) - filter.flushb;
filter.flushed++; filter.flushed++;
if (show_stats < 2) if (show_stats < 2)
return 0; return 0;
...@@ -1153,6 +1165,7 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n, ...@@ -1153,6 +1165,7 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
fprintf(fp, "%s", rta_getattr_str(rta_tb[IFA_LABEL])); fprintf(fp, "%s", rta_getattr_str(rta_tb[IFA_LABEL]));
if (rta_tb[IFA_CACHEINFO]) { if (rta_tb[IFA_CACHEINFO]) {
struct ifa_cacheinfo *ci = RTA_DATA(rta_tb[IFA_CACHEINFO]); struct ifa_cacheinfo *ci = RTA_DATA(rta_tb[IFA_CACHEINFO]);
fprintf(fp, "%s", _SL_); fprintf(fp, "%s", _SL_);
fprintf(fp, " valid_lft "); fprintf(fp, " valid_lft ");
if (ci->ifa_valid == INFINITY_LIFE_TIME) if (ci->ifa_valid == INFINITY_LIFE_TIME)
...@@ -1175,14 +1188,12 @@ brief_exit: ...@@ -1175,14 +1188,12 @@ brief_exit:
return 0; return 0;
} }
struct nlmsg_list struct nlmsg_list {
{
struct nlmsg_list *next; struct nlmsg_list *next;
struct nlmsghdr h; struct nlmsghdr h;
}; };
struct nlmsg_chain struct nlmsg_chain {
{
struct nlmsg_list *head; struct nlmsg_list *head;
struct nlmsg_list *tail; struct nlmsg_list *tail;
}; };
...@@ -1190,7 +1201,7 @@ struct nlmsg_chain ...@@ -1190,7 +1201,7 @@ struct nlmsg_chain
static int print_selected_addrinfo(struct ifinfomsg *ifi, static int print_selected_addrinfo(struct ifinfomsg *ifi,
struct nlmsg_list *ainfo, FILE *fp) struct nlmsg_list *ainfo, FILE *fp)
{ {
for ( ;ainfo ; ainfo = ainfo->next) { for ( ; ainfo ; ainfo = ainfo->next) {
struct nlmsghdr *n = &ainfo->h; struct nlmsghdr *n = &ainfo->h;
struct ifaddrmsg *ifa = NLMSG_DATA(n); struct ifaddrmsg *ifa = NLMSG_DATA(n);
...@@ -1223,7 +1234,7 @@ static int store_nlmsg(const struct sockaddr_nl *who, struct nlmsghdr *n, ...@@ -1223,7 +1234,7 @@ static int store_nlmsg(const struct sockaddr_nl *who, struct nlmsghdr *n,
struct nlmsg_chain *lchain = (struct nlmsg_chain *)arg; struct nlmsg_chain *lchain = (struct nlmsg_chain *)arg;
struct nlmsg_list *h; struct nlmsg_list *h;
h = malloc(n->nlmsg_len+sizeof(void*)); h = malloc(n->nlmsg_len+sizeof(void *));
if (h == NULL) if (h == NULL)
return -1; return -1;
...@@ -1352,7 +1363,7 @@ static void ipaddr_filter(struct nlmsg_chain *linfo, struct nlmsg_chain *ainfo) ...@@ -1352,7 +1363,7 @@ static void ipaddr_filter(struct nlmsg_chain *linfo, struct nlmsg_chain *ainfo)
struct nlmsg_list *l, **lp; struct nlmsg_list *l, **lp;
lp = &linfo->head; lp = &linfo->head;
while ( (l = *lp) != NULL) { while ((l = *lp) != NULL) {
int ok = 0; int ok = 0;
int missing_net_address = 1; int missing_net_address = 1;
struct ifinfomsg *ifi = NLMSG_DATA(&l->h); struct ifinfomsg *ifi = NLMSG_DATA(&l->h);
...@@ -1383,6 +1394,7 @@ static void ipaddr_filter(struct nlmsg_chain *linfo, struct nlmsg_chain *ainfo) ...@@ -1383,6 +1394,7 @@ static void ipaddr_filter(struct nlmsg_chain *linfo, struct nlmsg_chain *ainfo)
if (filter.pfx.family && tb[IFA_LOCAL]) { if (filter.pfx.family && tb[IFA_LOCAL]) {
inet_prefix dst; inet_prefix dst;
memset(&dst, 0, sizeof(dst)); memset(&dst, 0, sizeof(dst));
dst.family = ifa->ifa_family; dst.family = ifa->ifa_family;
memcpy(&dst.data, RTA_DATA(tb[IFA_LOCAL]), RTA_PAYLOAD(tb[IFA_LOCAL])); memcpy(&dst.data, RTA_DATA(tb[IFA_LOCAL]), RTA_PAYLOAD(tb[IFA_LOCAL]));
...@@ -1392,6 +1404,7 @@ static void ipaddr_filter(struct nlmsg_chain *linfo, struct nlmsg_chain *ainfo) ...@@ -1392,6 +1404,7 @@ static void ipaddr_filter(struct nlmsg_chain *linfo, struct nlmsg_chain *ainfo)
if (filter.label) { if (filter.label) {
SPRINT_BUF(b1); SPRINT_BUF(b1);
const char *label; const char *label;
if (tb[IFA_LABEL]) if (tb[IFA_LABEL])
label = RTA_DATA(tb[IFA_LABEL]); label = RTA_DATA(tb[IFA_LABEL]);
else else
...@@ -1441,7 +1454,7 @@ static int ipaddr_flush(void) ...@@ -1441,7 +1454,7 @@ static int ipaddr_flush(void)
if (round == 0) if (round == 0)
printf("Nothing to flush.\n"); printf("Nothing to flush.\n");
else else
printf("*** Flush is complete after %d round%s ***\n", round, round>1?"s":""); printf("*** Flush is complete after %d round%s ***\n", round, round > 1?"s":"");
} }
fflush(stdout); fflush(stdout);
return 0; return 0;
...@@ -1500,7 +1513,8 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action) ...@@ -1500,7 +1513,8 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
if (filter.family == AF_UNSPEC) if (filter.family == AF_UNSPEC)
filter.family = filter.pfx.family; filter.family = filter.pfx.family;
} else if (strcmp(*argv, "scope") == 0) { } else if (strcmp(*argv, "scope") == 0) {
unsigned scope = 0; unsigned int scope = 0;
NEXT_ARG(); NEXT_ARG();
filter.scopemask = -1; filter.scopemask = -1;
if (rtnl_rtscope_a2n(&scope, *argv)) { if (rtnl_rtscope_a2n(&scope, *argv)) {
...@@ -1567,6 +1581,7 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action) ...@@ -1567,6 +1581,7 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
invarg("Invalid \"group\" value\n", *argv); invarg("Invalid \"group\" value\n", *argv);
} else if (strcmp(*argv, "master") == 0) { } else if (strcmp(*argv, "master") == 0) {
int ifindex; int ifindex;
NEXT_ARG(); NEXT_ARG();
ifindex = ll_name_to_index(*argv); ifindex = ll_name_to_index(*argv);
if (!ifindex) if (!ifindex)
...@@ -1578,8 +1593,7 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action) ...@@ -1578,8 +1593,7 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
} else { } else {
if (strcmp(*argv, "dev") == 0) { if (strcmp(*argv, "dev") == 0) {
NEXT_ARG(); NEXT_ARG();
} } else if (matches(*argv, "help") == 0)
else if (matches(*argv, "help") == 0)
usage(); usage();
if (filter_dev) if (filter_dev)
duparg2("dev", *argv); duparg2("dev", *argv);
...@@ -1757,7 +1771,7 @@ void ipaddr_reset_filter(int oneline, int ifindex) ...@@ -1757,7 +1771,7 @@ void ipaddr_reset_filter(int oneline, int ifindex)
static int default_scope(inet_prefix *lcl) static int default_scope(inet_prefix *lcl)
{ {
if (lcl->family == AF_INET) { if (lcl->family == AF_INET) {
if (lcl->bytelen >= 1 && *(__u8*)&lcl->data == 127) if (lcl->bytelen >= 1 && *(__u8 *)&lcl->data == 127)
return RT_SCOPE_HOST; return RT_SCOPE_HOST;
} }
return 0; return 0;
...@@ -1820,6 +1834,7 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv) ...@@ -1820,6 +1834,7 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv)
} else if (matches(*argv, "broadcast") == 0 || } else if (matches(*argv, "broadcast") == 0 ||
strcmp(*argv, "brd") == 0) { strcmp(*argv, "brd") == 0) {
inet_prefix addr; inet_prefix addr;
NEXT_ARG(); NEXT_ARG();
if (brd_len) if (brd_len)
duparg("broadcast", *argv); duparg("broadcast", *argv);
...@@ -1836,6 +1851,7 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv) ...@@ -1836,6 +1851,7 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv)
} }
} else if (strcmp(*argv, "anycast") == 0) { } else if (strcmp(*argv, "anycast") == 0) {
inet_prefix addr; inet_prefix addr;
NEXT_ARG(); NEXT_ARG();
if (any_len) if (any_len)
duparg("anycast", *argv); duparg("anycast", *argv);
...@@ -1845,7 +1861,8 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv) ...@@ -1845,7 +1861,8 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv)
addattr_l(&req.n, sizeof(req), IFA_ANYCAST, &addr.data, addr.bytelen); addattr_l(&req.n, sizeof(req), IFA_ANYCAST, &addr.data, addr.bytelen);
any_len = addr.bytelen; any_len = addr.bytelen;
} else if (strcmp(*argv, "scope") == 0) { } else if (strcmp(*argv, "scope") == 0) {
unsigned scope = 0; unsigned int scope = 0;
NEXT_ARG(); NEXT_ARG();
if (rtnl_rtscope_a2n(&scope, *argv)) if (rtnl_rtscope_a2n(&scope, *argv))
invarg("invalid scope value.", *argv); invarg("invalid scope value.", *argv);
...@@ -1931,6 +1948,7 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv) ...@@ -1931,6 +1948,7 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv)
if (brd_len < 0 && cmd != RTM_DELADDR) { if (brd_len < 0 && cmd != RTM_DELADDR) {
inet_prefix brd; inet_prefix brd;
int i; int i;
if (req.ifa.ifa_family != AF_INET) { if (req.ifa.ifa_family != AF_INET) {
fprintf(stderr, "Broadcast can be set only for IPv4 addresses\n"); fprintf(stderr, "Broadcast can be set only for IPv4 addresses\n");
return -1; return -1;
......
...@@ -40,8 +40,8 @@ ...@@ -40,8 +40,8 @@
#include "utils.h" #include "utils.h"
#include "ip_common.h" #include "ip_common.h"
#define IFAL_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrlblmsg)))) #define IFAL_RTA(r) ((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrlblmsg))))
#define IFAL_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifaddrlblmsg)) #define IFAL_PAYLOAD(n) NLMSG_PAYLOAD(n, sizeof(struct ifaddrlblmsg))
extern struct rtnl_handle rth; extern struct rtnl_handle rth;
...@@ -56,7 +56,7 @@ static void usage(void) ...@@ -56,7 +56,7 @@ static void usage(void)
int print_addrlabel(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) int print_addrlabel(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
{ {
FILE *fp = (FILE*)arg; FILE *fp = (FILE *)arg;
struct ifaddrlblmsg *ifal = NLMSG_DATA(n); struct ifaddrlblmsg *ifal = NLMSG_DATA(n);
int len = n->nlmsg_len; int len = n->nlmsg_len;
struct rtattr *tb[IFAL_MAX+1]; struct rtattr *tb[IFAL_MAX+1];
...@@ -88,6 +88,7 @@ int print_addrlabel(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg ...@@ -88,6 +88,7 @@ int print_addrlabel(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg
if (tb[IFAL_LABEL] && RTA_PAYLOAD(tb[IFAL_LABEL]) == sizeof(uint32_t)) { if (tb[IFAL_LABEL] && RTA_PAYLOAD(tb[IFAL_LABEL]) == sizeof(uint32_t)) {
uint32_t label; uint32_t label;
memcpy(&label, RTA_DATA(tb[IFAL_LABEL]), sizeof(label)); memcpy(&label, RTA_DATA(tb[IFAL_LABEL]), sizeof(label));
fprintf(fp, "label %u ", label); fprintf(fp, "label %u ", label);
} }
...@@ -128,7 +129,7 @@ static int ipaddrlabel_modify(int cmd, int argc, char **argv) ...@@ -128,7 +129,7 @@ static int ipaddrlabel_modify(int cmd, int argc, char **argv)
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
struct ifaddrlblmsg ifal; struct ifaddrlblmsg ifal;
char buf[1024]; char buf[1024];
} req; } req;
inet_prefix prefix; inet_prefix prefix;
...@@ -195,7 +196,7 @@ static int flush_addrlabel(const struct sockaddr_nl *who, struct nlmsghdr *n, vo ...@@ -195,7 +196,7 @@ static int flush_addrlabel(const struct sockaddr_nl *who, struct nlmsghdr *n, vo
struct rtnl_handle rth2; struct rtnl_handle rth2;
struct rtmsg *r = NLMSG_DATA(n); struct rtmsg *r = NLMSG_DATA(n);
int len = n->nlmsg_len; int len = n->nlmsg_len;
struct rtattr * tb[IFAL_MAX+1]; struct rtattr *tb[IFAL_MAX+1];
len -= NLMSG_LENGTH(sizeof(*r)); len -= NLMSG_LENGTH(sizeof(*r));
if (len < 0) if (len < 0)
......
...@@ -526,6 +526,7 @@ static int parse_args(int argc, char **argv, int cmd, struct l2tp_parm *p) ...@@ -526,6 +526,7 @@ static int parse_args(int argc, char **argv, int cmd, struct l2tp_parm *p)
} else if ((strcmp(*argv, "tunnel_id") == 0) || } else if ((strcmp(*argv, "tunnel_id") == 0) ||
(strcmp(*argv, "tid") == 0)) { (strcmp(*argv, "tid") == 0)) {
__u32 uval; __u32 uval;
NEXT_ARG(); NEXT_ARG();
if (get_u32(&uval, *argv, 0)) if (get_u32(&uval, *argv, 0))
invarg("invalid ID\n", *argv); invarg("invalid ID\n", *argv);
...@@ -533,6 +534,7 @@ static int parse_args(int argc, char **argv, int cmd, struct l2tp_parm *p) ...@@ -533,6 +534,7 @@ static int parse_args(int argc, char **argv, int cmd, struct l2tp_parm *p)
} else if ((strcmp(*argv, "peer_tunnel_id") == 0) || } else if ((strcmp(*argv, "peer_tunnel_id") == 0) ||
(strcmp(*argv, "ptid") == 0)) { (strcmp(*argv, "ptid") == 0)) {
__u32 uval; __u32 uval;
NEXT_ARG(); NEXT_ARG();
if (get_u32(&uval, *argv, 0)) if (get_u32(&uval, *argv, 0))
invarg("invalid ID\n", *argv); invarg("invalid ID\n", *argv);
...@@ -540,6 +542,7 @@ static int parse_args(int argc, char **argv, int cmd, struct l2tp_parm *p) ...@@ -540,6 +542,7 @@ static int parse_args(int argc, char **argv, int cmd, struct l2tp_parm *p)
} else if ((strcmp(*argv, "session_id") == 0) || } else if ((strcmp(*argv, "session_id") == 0) ||
(strcmp(*argv, "sid") == 0)) { (strcmp(*argv, "sid") == 0)) {
__u32 uval; __u32 uval;
NEXT_ARG(); NEXT_ARG();
if (get_u32(&uval, *argv, 0)) if (get_u32(&uval, *argv, 0))
invarg("invalid ID\n", *argv); invarg("invalid ID\n", *argv);
...@@ -547,36 +550,42 @@ static int parse_args(int argc, char **argv, int cmd, struct l2tp_parm *p) ...@@ -547,36 +550,42 @@ static int parse_args(int argc, char **argv, int cmd, struct l2tp_parm *p)
} else if ((strcmp(*argv, "peer_session_id") == 0) || } else if ((strcmp(*argv, "peer_session_id") == 0) ||
(strcmp(*argv, "psid") == 0)) { (strcmp(*argv, "psid") == 0)) {
__u32 uval; __u32 uval;
NEXT_ARG(); NEXT_ARG();
if (get_u32(&uval, *argv, 0)) if (get_u32(&uval, *argv, 0))
invarg("invalid ID\n", *argv); invarg("invalid ID\n", *argv);
p->peer_session_id = uval; p->peer_session_id = uval;
} else if (strcmp(*argv, "udp_sport") == 0) { } else if (strcmp(*argv, "udp_sport") == 0) {
__u16 uval; __u16 uval;
NEXT_ARG(); NEXT_ARG();
if (get_u16(&uval, *argv, 0)) if (get_u16(&uval, *argv, 0))
invarg("invalid port\n", *argv); invarg("invalid port\n", *argv);
p->local_udp_port = uval; p->local_udp_port = uval;
} else if (strcmp(*argv, "udp_dport") == 0) { } else if (strcmp(*argv, "udp_dport") == 0) {
__u16 uval; __u16 uval;
NEXT_ARG(); NEXT_ARG();
if (get_u16(&uval, *argv, 0)) if (get_u16(&uval, *argv, 0))
invarg("invalid port\n", *argv); invarg("invalid port\n", *argv);
p->peer_udp_port = uval; p->peer_udp_port = uval;
} else if (strcmp(*argv, "offset") == 0) { } else if (strcmp(*argv, "offset") == 0) {
__u8 uval; __u8 uval;
NEXT_ARG(); NEXT_ARG();
if (get_u8(&uval, *argv, 0)) if (get_u8(&uval, *argv, 0))
invarg("invalid offset\n", *argv); invarg("invalid offset\n", *argv);
p->offset = uval; p->offset = uval;
} else if (strcmp(*argv, "peer_offset") == 0) { } else if (strcmp(*argv, "peer_offset") == 0) {
__u8 uval; __u8 uval;
NEXT_ARG(); NEXT_ARG();
if (get_u8(&uval, *argv, 0)) if (get_u8(&uval, *argv, 0))
invarg("invalid offset\n", *argv); invarg("invalid offset\n", *argv);
p->peer_offset = uval; p->peer_offset = uval;
} else if (strcmp(*argv, "cookie") == 0) { } else if (strcmp(*argv, "cookie") == 0) {
int slen; int slen;
NEXT_ARG(); NEXT_ARG();
slen = strlen(*argv); slen = strlen(*argv);
if ((slen != 8) && (slen != 16)) if ((slen != 8) && (slen != 16))
...@@ -587,6 +596,7 @@ static int parse_args(int argc, char **argv, int cmd, struct l2tp_parm *p) ...@@ -587,6 +596,7 @@ static int parse_args(int argc, char **argv, int cmd, struct l2tp_parm *p)
invarg("cookie must be a hex string\n", *argv); invarg("cookie must be a hex string\n", *argv);
} else if (strcmp(*argv, "peer_cookie") == 0) { } else if (strcmp(*argv, "peer_cookie") == 0) {
int slen; int slen;
NEXT_ARG(); NEXT_ARG();
slen = strlen(*argv); slen = strlen(*argv);
if ((slen != 8) && (slen != 16)) if ((slen != 8) && (slen != 16))
......
...@@ -358,6 +358,7 @@ static int iplink_parse_vf(int vf, int *argcp, char ***argvp, ...@@ -358,6 +358,7 @@ static int iplink_parse_vf(int vf, int *argcp, char ***argvp,
} else if (matches(*argv, "trust") == 0) { } else if (matches(*argv, "trust") == 0) {
struct ifla_vf_trust ivt; struct ifla_vf_trust ivt;
NEXT_ARG(); NEXT_ARG();
if (matches(*argv, "on") == 0) if (matches(*argv, "on") == 0)
ivt.setting = 1; ivt.setting = 1;
...@@ -712,14 +713,12 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv) ...@@ -712,14 +713,12 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
&group, sizeof(group)); &group, sizeof(group));
else { else {
if (argc) { if (argc) {
fprintf(stderr, "Garbage instead of arguments " fprintf(stderr, "Garbage instead of arguments \"%s ...\". Try \"ip link "
"\"%s ...\". Try \"ip link "
"help\".\n", *argv); "help\".\n", *argv);
return -1; return -1;
} }
if (flags & NLM_F_CREATE) { if (flags & NLM_F_CREATE) {
fprintf(stderr, "group cannot be used when " fprintf(stderr, "group cannot be used when creating devices.\n");
"creating devices.\n");
return -1; return -1;
} }
...@@ -733,13 +732,11 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv) ...@@ -733,13 +732,11 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
if (!(flags & NLM_F_CREATE)) { if (!(flags & NLM_F_CREATE)) {
if (!dev) { if (!dev) {
fprintf(stderr, "Not enough information: \"dev\" " fprintf(stderr, "Not enough information: \"dev\" argument is required.\n");
"argument is required.\n");
exit(-1); exit(-1);
} }
if (cmd == RTM_NEWLINK && index != -1) { if (cmd == RTM_NEWLINK && index != -1) {
fprintf(stderr, "index can be used only when " fprintf(stderr, "index can be used only when creating devices.\n");
"creating devices.\n");
exit(-1); exit(-1);
} }
...@@ -813,14 +810,13 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv) ...@@ -813,14 +810,13 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
} else if (argc) { } else if (argc) {
if (matches(*argv, "help") == 0) if (matches(*argv, "help") == 0)
usage(); usage();
fprintf(stderr, "Garbage instead of arguments \"%s ...\". " fprintf(stderr, "Garbage instead of arguments \"%s ...\". Try \"ip link help\".\n",
"Try \"ip link help\".\n", *argv); *argv);
return -1; return -1;
} }
addattr_nest_end(&req.n, linkinfo); addattr_nest_end(&req.n, linkinfo);
} else if (flags & NLM_F_CREATE) { } else if (flags & NLM_F_CREATE) {
fprintf(stderr, "Not enough information: \"type\" argument " fprintf(stderr, "Not enough information: \"type\" argument is required\n");
"is required\n");
return -1; return -1;
} }
......
...@@ -166,7 +166,7 @@ static int bond_parse_opt(struct link_util *lu, int argc, char **argv, ...@@ -166,7 +166,7 @@ static int bond_parse_opt(struct link_util *lu, int argc, char **argv,
__u32 miimon, updelay, downdelay, arp_interval, arp_validate; __u32 miimon, updelay, downdelay, arp_interval, arp_validate;
__u32 arp_all_targets, resend_igmp, min_links, lp_interval; __u32 arp_all_targets, resend_igmp, min_links, lp_interval;
__u32 packets_per_slave; __u32 packets_per_slave;
unsigned ifindex; unsigned int ifindex;
while (argc > 0) { while (argc > 0) {
if (matches(*argv, "mode") == 0) { if (matches(*argv, "mode") == 0) {
...@@ -209,7 +209,7 @@ static int bond_parse_opt(struct link_util *lu, int argc, char **argv, ...@@ -209,7 +209,7 @@ static int bond_parse_opt(struct link_util *lu, int argc, char **argv,
invarg("invalid arp_interval", *argv); invarg("invalid arp_interval", *argv);
addattr32(n, 1024, IFLA_BOND_ARP_INTERVAL, arp_interval); addattr32(n, 1024, IFLA_BOND_ARP_INTERVAL, arp_interval);
} else if (matches(*argv, "arp_ip_target") == 0) { } else if (matches(*argv, "arp_ip_target") == 0) {
struct rtattr * nest = addattr_nest(n, 1024, struct rtattr *nest = addattr_nest(n, 1024,
IFLA_BOND_ARP_IP_TARGET); IFLA_BOND_ARP_IP_TARGET);
if (NEXT_ARG_OK()) { if (NEXT_ARG_OK()) {
NEXT_ARG(); NEXT_ARG();
...@@ -217,8 +217,9 @@ static int bond_parse_opt(struct link_util *lu, int argc, char **argv, ...@@ -217,8 +217,9 @@ static int bond_parse_opt(struct link_util *lu, int argc, char **argv,
char *target = strtok(targets, ","); char *target = strtok(targets, ",");
int i; int i;
for(i = 0; target && i < BOND_MAX_ARP_TARGETS; i++) { for (i = 0; target && i < BOND_MAX_ARP_TARGETS; i++) {
__u32 addr = get_addr32(target); __u32 addr = get_addr32(target);
addattr32(n, 1024, i, addr); addattr32(n, 1024, i, addr);
target = strtok(NULL, ","); target = strtok(NULL, ",");
} }
...@@ -368,7 +369,7 @@ static int bond_parse_opt(struct link_util *lu, int argc, char **argv, ...@@ -368,7 +369,7 @@ static int bond_parse_opt(struct link_util *lu, int argc, char **argv,
static void bond_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) static void bond_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
{ {
unsigned ifindex; unsigned int ifindex;
if (!tb) if (!tb)
return; return;
......
...@@ -26,7 +26,7 @@ static void print_slave_state(FILE *f, struct rtattr *tb) ...@@ -26,7 +26,7 @@ static void print_slave_state(FILE *f, struct rtattr *tb)
{ {
unsigned int state = rta_getattr_u8(tb); unsigned int state = rta_getattr_u8(tb);
if (state >= sizeof(slave_states) / sizeof(slave_states[0])) if (state >= ARRAY_SIZE(slave_states))
fprintf(f, "state %d ", state); fprintf(f, "state %d ", state);
else else
fprintf(f, "state %s ", slave_states[state]); fprintf(f, "state %s ", slave_states[state]);
...@@ -43,7 +43,7 @@ static void print_slave_mii_status(FILE *f, struct rtattr *tb) ...@@ -43,7 +43,7 @@ static void print_slave_mii_status(FILE *f, struct rtattr *tb)
{ {
unsigned int status = rta_getattr_u8(tb); unsigned int status = rta_getattr_u8(tb);
if (status >= sizeof(slave_mii_status) / sizeof(slave_mii_status[0])) if (status >= ARRAY_SIZE(slave_mii_status))
fprintf(f, "mii_status %d ", status); fprintf(f, "mii_status %d ", status);
else else
fprintf(f, "mii_status %s ", slave_mii_status[status]); fprintf(f, "mii_status %s ", slave_mii_status[status]);
......
...@@ -24,7 +24,7 @@ static void print_explain(FILE *f) ...@@ -24,7 +24,7 @@ static void print_explain(FILE *f)
fprintf(f, fprintf(f,
"Usage: ... bridge_slave [ state STATE ] [ priority PRIO ] [cost COST ]\n" "Usage: ... bridge_slave [ state STATE ] [ priority PRIO ] [cost COST ]\n"
" [ guard {on | off} ]\n" " [ guard {on | off} ]\n"
" [ hairpin {on | off} ] \n" " [ hairpin {on | off} ]\n"
" [ fastleave {on | off} ]\n" " [ fastleave {on | off} ]\n"
" [ root_block {on | off} ]\n" " [ root_block {on | off} ]\n"
" [ learning {on | off} ]\n" " [ learning {on | off} ]\n"
......
...@@ -23,13 +23,11 @@ static void print_usage(FILE *f) ...@@ -23,13 +23,11 @@ static void print_usage(FILE *f)
{ {
fprintf(f, fprintf(f,
"Usage: ip link set DEVICE type can\n" "Usage: ip link set DEVICE type can\n"
"\t[ bitrate BITRATE [ sample-point SAMPLE-POINT] ] | \n" "\t[ bitrate BITRATE [ sample-point SAMPLE-POINT] ] |\n"
"\t[ tq TQ prop-seg PROP_SEG phase-seg1 PHASE-SEG1\n " "\t[ tq TQ prop-seg PROP_SEG phase-seg1 PHASE-SEG1\n \t phase-seg2 PHASE-SEG2 [ sjw SJW ] ]\n"
"\t phase-seg2 PHASE-SEG2 [ sjw SJW ] ]\n"
"\n" "\n"
"\t[ dbitrate BITRATE [ dsample-point SAMPLE-POINT] ] | \n" "\t[ dbitrate BITRATE [ dsample-point SAMPLE-POINT] ] |\n"
"\t[ dtq TQ dprop-seg PROP_SEG dphase-seg1 PHASE-SEG1\n " "\t[ dtq TQ dprop-seg PROP_SEG dphase-seg1 PHASE-SEG1\n \t dphase-seg2 PHASE-SEG2 [ dsjw SJW ] ]\n"
"\t dphase-seg2 PHASE-SEG2 [ dsjw SJW ] ]\n"
"\n" "\n"
"\t[ loopback { on | off } ]\n" "\t[ loopback { on | off } ]\n"
"\t[ listen-only { on | off } ]\n" "\t[ listen-only { on | off } ]\n"
...@@ -73,7 +71,7 @@ static int get_float(float *val, const char *arg) ...@@ -73,7 +71,7 @@ static int get_float(float *val, const char *arg)
return 0; return 0;
} }
static void set_ctrlmode(char* name, char *arg, static void set_ctrlmode(char *name, char *arg,
struct can_ctrlmode *cm, __u32 flags) struct can_ctrlmode *cm, __u32 flags)
{ {
if (strcmp(arg, "on") == 0) { if (strcmp(arg, "on") == 0) {
...@@ -289,11 +287,9 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -289,11 +287,9 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (tb[IFLA_CAN_BITTIMING]) { if (tb[IFLA_CAN_BITTIMING]) {
struct can_bittiming *bt = RTA_DATA(tb[IFLA_CAN_BITTIMING]); struct can_bittiming *bt = RTA_DATA(tb[IFLA_CAN_BITTIMING]);
fprintf(f, "\n " fprintf(f, "\n bitrate %d sample-point %.3f ",
"bitrate %d sample-point %.3f ",
bt->bitrate, (float)bt->sample_point / 1000.); bt->bitrate, (float)bt->sample_point / 1000.);
fprintf(f, "\n " fprintf(f, "\n tq %d prop-seg %d phase-seg1 %d phase-seg2 %d sjw %d",
"tq %d prop-seg %d phase-seg1 %d phase-seg2 %d sjw %d",
bt->tq, bt->prop_seg, bt->phase_seg1, bt->phase_seg2, bt->tq, bt->prop_seg, bt->phase_seg1, bt->phase_seg2,
bt->sjw); bt->sjw);
} }
...@@ -302,8 +298,7 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -302,8 +298,7 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
struct can_bittiming_const *btc = struct can_bittiming_const *btc =
RTA_DATA(tb[IFLA_CAN_BITTIMING_CONST]); RTA_DATA(tb[IFLA_CAN_BITTIMING_CONST]);
fprintf(f, "\n " fprintf(f, "\n %s: tseg1 %d..%d tseg2 %d..%d "
"%s: tseg1 %d..%d tseg2 %d..%d "
"sjw 1..%d brp %d..%d brp-inc %d", "sjw 1..%d brp %d..%d brp-inc %d",
btc->name, btc->tseg1_min, btc->tseg1_max, btc->name, btc->tseg1_min, btc->tseg1_max,
btc->tseg2_min, btc->tseg2_max, btc->sjw_max, btc->tseg2_min, btc->tseg2_max, btc->sjw_max,
...@@ -314,11 +309,9 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -314,11 +309,9 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
struct can_bittiming *dbt = struct can_bittiming *dbt =
RTA_DATA(tb[IFLA_CAN_DATA_BITTIMING]); RTA_DATA(tb[IFLA_CAN_DATA_BITTIMING]);
fprintf(f, "\n " fprintf(f, "\n dbitrate %d dsample-point %.3f ",
"dbitrate %d dsample-point %.3f ",
dbt->bitrate, (float)dbt->sample_point / 1000.); dbt->bitrate, (float)dbt->sample_point / 1000.);
fprintf(f, "\n " fprintf(f, "\n dtq %d dprop-seg %d dphase-seg1 %d "
"dtq %d dprop-seg %d dphase-seg1 %d "
"dphase-seg2 %d dsjw %d", "dphase-seg2 %d dsjw %d",
dbt->tq, dbt->prop_seg, dbt->phase_seg1, dbt->tq, dbt->prop_seg, dbt->phase_seg1,
dbt->phase_seg2, dbt->sjw); dbt->phase_seg2, dbt->sjw);
...@@ -328,8 +321,7 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -328,8 +321,7 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
struct can_bittiming_const *dbtc = struct can_bittiming_const *dbtc =
RTA_DATA(tb[IFLA_CAN_DATA_BITTIMING_CONST]); RTA_DATA(tb[IFLA_CAN_DATA_BITTIMING_CONST]);
fprintf(f, "\n " fprintf(f, "\n %s: dtseg1 %d..%d dtseg2 %d..%d "
"%s: dtseg1 %d..%d dtseg2 %d..%d "
"dsjw 1..%d dbrp %d..%d dbrp-inc %d", "dsjw 1..%d dbrp %d..%d dbrp-inc %d",
dbtc->name, dbtc->tseg1_min, dbtc->tseg1_max, dbtc->name, dbtc->tseg1_min, dbtc->tseg1_max,
dbtc->tseg2_min, dbtc->tseg2_max, dbtc->sjw_max, dbtc->tseg2_min, dbtc->tseg2_max, dbtc->sjw_max,
...@@ -351,8 +343,7 @@ static void can_print_xstats(struct link_util *lu, ...@@ -351,8 +343,7 @@ static void can_print_xstats(struct link_util *lu,
if (xstats && RTA_PAYLOAD(xstats) == sizeof(*stats)) { if (xstats && RTA_PAYLOAD(xstats) == sizeof(*stats)) {
stats = RTA_DATA(xstats); stats = RTA_DATA(xstats);
fprintf(f, "\n " fprintf(f, "\n re-started bus-errors arbit-lost "
"re-started bus-errors arbit-lost "
"error-warn error-pass bus-off"); "error-warn error-pass bus-off");
fprintf(f, "\n %-10d %-10d %-10d %-10d %-10d %-10d", fprintf(f, "\n %-10d %-10d %-10d %-10d %-10d %-10d",
stats->restarts, stats->bus_error, stats->restarts, stats->bus_error,
......
...@@ -62,7 +62,7 @@ static int geneve_parse_opt(struct link_util *lu, int argc, char **argv, ...@@ -62,7 +62,7 @@ static int geneve_parse_opt(struct link_util *lu, int argc, char **argv,
invarg("invalid remote address", *argv); invarg("invalid remote address", *argv);
} else if (!matches(*argv, "ttl") || } else if (!matches(*argv, "ttl") ||
!matches(*argv, "hoplimit")) { !matches(*argv, "hoplimit")) {
unsigned uval; unsigned int uval;
NEXT_ARG(); NEXT_ARG();
if (strcmp(*argv, "inherit") != 0) { if (strcmp(*argv, "inherit") != 0) {
...@@ -153,11 +153,13 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -153,11 +153,13 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (tb[IFLA_GENEVE_REMOTE]) { if (tb[IFLA_GENEVE_REMOTE]) {
__be32 addr = rta_getattr_u32(tb[IFLA_GENEVE_REMOTE]); __be32 addr = rta_getattr_u32(tb[IFLA_GENEVE_REMOTE]);
if (addr) if (addr)
fprintf(f, "remote %s ", fprintf(f, "remote %s ",
format_host(AF_INET, 4, &addr, s1, sizeof(s1))); format_host(AF_INET, 4, &addr, s1, sizeof(s1)));
} else if (tb[IFLA_GENEVE_REMOTE6]) { } else if (tb[IFLA_GENEVE_REMOTE6]) {
struct in6_addr addr; struct in6_addr addr;
memcpy(&addr, RTA_DATA(tb[IFLA_GENEVE_REMOTE6]), sizeof(struct in6_addr)); memcpy(&addr, RTA_DATA(tb[IFLA_GENEVE_REMOTE6]), sizeof(struct in6_addr));
if (memcmp(&addr, &in6addr_any, sizeof(addr)) != 0) { if (memcmp(&addr, &in6addr_any, sizeof(addr)) != 0) {
if (IN6_IS_ADDR_MULTICAST(&addr)) if (IN6_IS_ADDR_MULTICAST(&addr))
...@@ -168,6 +170,7 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -168,6 +170,7 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (tb[IFLA_GENEVE_TTL]) { if (tb[IFLA_GENEVE_TTL]) {
__u8 ttl = rta_getattr_u8(tb[IFLA_GENEVE_TTL]); __u8 ttl = rta_getattr_u8(tb[IFLA_GENEVE_TTL]);
if (ttl) if (ttl)
fprintf(f, "ttl %d ", ttl); fprintf(f, "ttl %d ", ttl);
} }
......
...@@ -22,8 +22,7 @@ ...@@ -22,8 +22,7 @@
static void print_explain(FILE *f) static void print_explain(FILE *f)
{ {
fprintf(f, fprintf(f,
"Usage: ... ipoib [pkey PKEY] [mode {datagram | connected}]" "Usage: ... ipoib [pkey PKEY] [mode {datagram | connected}][umcast {0|1}]\n"
"[umcast {0|1}]\n"
"\n" "\n"
"PKEY := 0x8001-0xffff\n" "PKEY := 0x8001-0xffff\n"
); );
...@@ -36,8 +35,7 @@ static void explain(void) ...@@ -36,8 +35,7 @@ static void explain(void)
static int mode_arg(void) static int mode_arg(void)
{ {
fprintf(stderr, "Error: argument of \"mode\" must be \"datagram\"" fprintf(stderr, "Error: argument of \"mode\" must be \"datagram\"or \"connected\"\n");
"or \"connected\"\n");
return -1; return -1;
} }
......
...@@ -30,8 +30,7 @@ static void explain(void) ...@@ -30,8 +30,7 @@ static void explain(void)
static int mode_arg(void) static int mode_arg(void)
{ {
fprintf(stderr, "Error: argument of \"mode\" must be either \"l2\", " fprintf(stderr, "Error: argument of \"mode\" must be either \"l2\", or \"l3\"\n");
"or \"l3\"\n");
return -1; return -1;
} }
...@@ -41,6 +40,7 @@ static int ipvlan_parse_opt(struct link_util *lu, int argc, char **argv, ...@@ -41,6 +40,7 @@ static int ipvlan_parse_opt(struct link_util *lu, int argc, char **argv,
while (argc > 0) { while (argc > 0) {
if (matches(*argv, "mode") == 0) { if (matches(*argv, "mode") == 0) {
__u16 mode = 0; __u16 mode = 0;
NEXT_ARG(); NEXT_ARG();
if (strcmp(*argv, "l2") == 0) if (strcmp(*argv, "l2") == 0)
......
...@@ -41,9 +41,9 @@ static void explain(struct link_util *lu) ...@@ -41,9 +41,9 @@ static void explain(struct link_util *lu)
static int mode_arg(const char *arg) static int mode_arg(const char *arg)
{ {
fprintf(stderr, "Error: argument of \"mode\" must be \"private\", " fprintf(stderr, "Error: argument of \"mode\" must be \"private\", \"vepa\", \"bridge\" or \"passthru\", not \"%s\"\n",
"\"vepa\", \"bridge\" or \"passthru\", not \"%s\"\n", arg); arg);
return -1; return -1;
} }
static int macvlan_parse_opt(struct link_util *lu, int argc, char **argv, static int macvlan_parse_opt(struct link_util *lu, int argc, char **argv,
......
...@@ -21,8 +21,7 @@ ...@@ -21,8 +21,7 @@
static void print_explain(FILE *f) static void print_explain(FILE *f)
{ {
fprintf(f, fprintf(f,
"Usage: ... vlan [ protocol VLANPROTO ] id VLANID" "Usage: ... vlan [ protocol VLANPROTO ] id VLANID [ FLAG-LIST ]\n"
" [ FLAG-LIST ]\n"
" [ ingress-qos-map QOS-MAP ] [ egress-qos-map QOS-MAP ]\n" " [ ingress-qos-map QOS-MAP ] [ egress-qos-map QOS-MAP ]\n"
"\n" "\n"
"VLANPROTO: [ 802.1Q / 802.1ad ]\n" "VLANPROTO: [ 802.1Q / 802.1ad ]\n"
...@@ -182,7 +181,7 @@ static void vlan_print_flags(FILE *fp, __u32 flags) ...@@ -182,7 +181,7 @@ static void vlan_print_flags(FILE *fp, __u32 flags)
{ {
fprintf(fp, "<"); fprintf(fp, "<");
#define _PF(f) if (flags & VLAN_FLAG_##f) { \ #define _PF(f) if (flags & VLAN_FLAG_##f) { \
flags &= ~ VLAN_FLAG_##f; \ flags &= ~VLAN_FLAG_##f; \
fprintf(fp, #f "%s", flags ? "," : ""); \ fprintf(fp, #f "%s", flags ? "," : ""); \
} }
_PF(REORDER_HDR); _PF(REORDER_HDR);
...@@ -198,6 +197,7 @@ static void vlan_print_flags(FILE *fp, __u32 flags) ...@@ -198,6 +197,7 @@ static void vlan_print_flags(FILE *fp, __u32 flags)
static void vlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) static void vlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
{ {
struct ifla_vlan_flags *flags; struct ifla_vlan_flags *flags;
SPRINT_BUF(b1); SPRINT_BUF(b1);
if (!tb) if (!tb)
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
static void vrf_explain(FILE *f) static void vrf_explain(FILE *f)
{ {
fprintf(f, "Usage: ... vrf table TABLEID \n"); fprintf(f, "Usage: ... vrf table TABLEID\n");
} }
static void explain(void) static void explain(void)
...@@ -91,8 +91,8 @@ struct link_util vrf_link_util = { ...@@ -91,8 +91,8 @@ struct link_util vrf_link_util = {
}; };
struct link_util vrf_slave_link_util = { struct link_util vrf_slave_link_util = {
.id = "vrf", .id = "vrf",
.maxattr = IFLA_VRF_PORT_MAX, .maxattr = IFLA_VRF_PORT_MAX,
.print_opt = vrf_slave_print_opt, .print_opt = vrf_slave_print_opt,
.slave = true, .slave = true,
}; };
...@@ -55,7 +55,7 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv, ...@@ -55,7 +55,7 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
struct in6_addr saddr6 = IN6ADDR_ANY_INIT; struct in6_addr saddr6 = IN6ADDR_ANY_INIT;
struct in6_addr gaddr6 = IN6ADDR_ANY_INIT; struct in6_addr gaddr6 = IN6ADDR_ANY_INIT;
struct in6_addr daddr6 = IN6ADDR_ANY_INIT; struct in6_addr daddr6 = IN6ADDR_ANY_INIT;
unsigned link = 0; unsigned int link = 0;
__u8 tos = 0; __u8 tos = 0;
__u8 ttl = 0; __u8 ttl = 0;
__u8 learning = 1; __u8 learning = 1;
...@@ -122,7 +122,7 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv, ...@@ -122,7 +122,7 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
} }
} else if (!matches(*argv, "ttl") || } else if (!matches(*argv, "ttl") ||
!matches(*argv, "hoplimit")) { !matches(*argv, "hoplimit")) {
unsigned uval; unsigned int uval;
NEXT_ARG(); NEXT_ARG();
if (strcmp(*argv, "inherit") != 0) { if (strcmp(*argv, "inherit") != 0) {
...@@ -158,6 +158,7 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv, ...@@ -158,6 +158,7 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
} else if (!matches(*argv, "port") || } else if (!matches(*argv, "port") ||
!matches(*argv, "srcport")) { !matches(*argv, "srcport")) {
__u16 minport, maxport; __u16 minport, maxport;
NEXT_ARG(); NEXT_ARG();
if (get_u16(&minport, *argv, 0)) if (get_u16(&minport, *argv, 0))
invarg("min port", *argv); invarg("min port", *argv);
...@@ -166,7 +167,7 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv, ...@@ -166,7 +167,7 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
invarg("max port", *argv); invarg("max port", *argv);
range.low = htons(minport); range.low = htons(minport);
range.high = htons(maxport); range.high = htons(maxport);
} else if (!matches(*argv, "dstport")){ } else if (!matches(*argv, "dstport")) {
NEXT_ARG(); NEXT_ARG();
if (get_u16(&dstport, *argv, 0)) if (get_u16(&dstport, *argv, 0))
invarg("dst port", *argv); invarg("dst port", *argv);
...@@ -306,7 +307,7 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv, ...@@ -306,7 +307,7 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
{ {
__u32 vni; __u32 vni;
unsigned link; unsigned int link;
__u8 tos; __u8 tos;
__u32 maxaddr; __u32 maxaddr;
char s1[1024]; char s1[1024];
...@@ -324,6 +325,7 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -324,6 +325,7 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (tb[IFLA_VXLAN_GROUP]) { if (tb[IFLA_VXLAN_GROUP]) {
__be32 addr = rta_getattr_u32(tb[IFLA_VXLAN_GROUP]); __be32 addr = rta_getattr_u32(tb[IFLA_VXLAN_GROUP]);
if (addr) { if (addr) {
if (IN_MULTICAST(ntohl(addr))) if (IN_MULTICAST(ntohl(addr)))
fprintf(f, "group %s ", fprintf(f, "group %s ",
...@@ -334,6 +336,7 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -334,6 +336,7 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
} }
} else if (tb[IFLA_VXLAN_GROUP6]) { } else if (tb[IFLA_VXLAN_GROUP6]) {
struct in6_addr addr; struct in6_addr addr;
memcpy(&addr, RTA_DATA(tb[IFLA_VXLAN_GROUP6]), sizeof(struct in6_addr)); memcpy(&addr, RTA_DATA(tb[IFLA_VXLAN_GROUP6]), sizeof(struct in6_addr));
if (memcmp(&addr, &in6addr_any, sizeof(addr)) != 0) { if (memcmp(&addr, &in6addr_any, sizeof(addr)) != 0) {
if (IN6_IS_ADDR_MULTICAST(&addr)) if (IN6_IS_ADDR_MULTICAST(&addr))
...@@ -347,11 +350,13 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -347,11 +350,13 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (tb[IFLA_VXLAN_LOCAL]) { if (tb[IFLA_VXLAN_LOCAL]) {
__be32 addr = rta_getattr_u32(tb[IFLA_VXLAN_LOCAL]); __be32 addr = rta_getattr_u32(tb[IFLA_VXLAN_LOCAL]);
if (addr) if (addr)
fprintf(f, "local %s ", fprintf(f, "local %s ",
format_host(AF_INET, 4, &addr, s1, sizeof(s1))); format_host(AF_INET, 4, &addr, s1, sizeof(s1)));
} else if (tb[IFLA_VXLAN_LOCAL6]) { } else if (tb[IFLA_VXLAN_LOCAL6]) {
struct in6_addr addr; struct in6_addr addr;
memcpy(&addr, RTA_DATA(tb[IFLA_VXLAN_LOCAL6]), sizeof(struct in6_addr)); memcpy(&addr, RTA_DATA(tb[IFLA_VXLAN_LOCAL6]), sizeof(struct in6_addr));
if (memcmp(&addr, &in6addr_any, sizeof(addr)) != 0) if (memcmp(&addr, &in6addr_any, sizeof(addr)) != 0)
fprintf(f, "local %s ", fprintf(f, "local %s ",
...@@ -404,12 +409,14 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -404,12 +409,14 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (tb[IFLA_VXLAN_TTL]) { if (tb[IFLA_VXLAN_TTL]) {
__u8 ttl = rta_getattr_u8(tb[IFLA_VXLAN_TTL]); __u8 ttl = rta_getattr_u8(tb[IFLA_VXLAN_TTL]);
if (ttl) if (ttl)
fprintf(f, "ttl %d ", ttl); fprintf(f, "ttl %d ", ttl);
} }
if (tb[IFLA_VXLAN_AGEING]) { if (tb[IFLA_VXLAN_AGEING]) {
__u32 age = rta_getattr_u32(tb[IFLA_VXLAN_AGEING]); __u32 age = rta_getattr_u32(tb[IFLA_VXLAN_AGEING]);
if (age == 0) if (age == 0)
fprintf(f, "ageing none "); fprintf(f, "ageing none ");
else else
......
...@@ -50,6 +50,7 @@ static int parse_hex(char *str, unsigned char *addr, size_t size) ...@@ -50,6 +50,7 @@ static int parse_hex(char *str, unsigned char *addr, size_t size)
while (*str && (len < 2 * size)) { while (*str && (len < 2 * size)) {
int tmp; int tmp;
if (str[1] == 0) if (str[1] == 0)
return -1; return -1;
if (sscanf(str, "%02x", &tmp) != 1) if (sscanf(str, "%02x", &tmp) != 1)
...@@ -61,8 +62,7 @@ static int parse_hex(char *str, unsigned char *addr, size_t size) ...@@ -61,8 +62,7 @@ static int parse_hex(char *str, unsigned char *addr, size_t size)
return len; return len;
} }
struct ma_info struct ma_info {
{
struct ma_info *next; struct ma_info *next;
int index; int index;
int users; int users;
...@@ -105,7 +105,7 @@ static void read_dev_mcast(struct ma_info **result_p) ...@@ -105,7 +105,7 @@ static void read_dev_mcast(struct ma_info **result_p)
m.addr.family = AF_PACKET; m.addr.family = AF_PACKET;
len = parse_hex(hexa, (unsigned char*)&m.addr.data, sizeof (m.addr.data)); len = parse_hex(hexa, (unsigned char *)&m.addr.data, sizeof(m.addr.data));
if (len >= 0) { if (len >= 0) {
struct ma_info *ma = malloc(sizeof(m)); struct ma_info *ma = malloc(sizeof(m));
...@@ -149,7 +149,7 @@ static void read_igmp(struct ma_info **result_p) ...@@ -149,7 +149,7 @@ static void read_igmp(struct ma_info **result_p)
if (filter.dev && strcmp(filter.dev, m.name)) if (filter.dev && strcmp(filter.dev, m.name))
continue; continue;
sscanf(buf, "%08x%d", (__u32*)&m.addr.data, &m.users); sscanf(buf, "%08x%d", (__u32 *)&m.addr.data, &m.users);
ma = malloc(sizeof(m)); ma = malloc(sizeof(m));
memcpy(ma, &m, sizeof(m)); memcpy(ma, &m, sizeof(m));
...@@ -180,7 +180,7 @@ static void read_igmp6(struct ma_info **result_p) ...@@ -180,7 +180,7 @@ static void read_igmp6(struct ma_info **result_p)
m.addr.family = AF_INET6; m.addr.family = AF_INET6;
len = parse_hex(hexa, (unsigned char*)&m.addr.data, sizeof (m.addr.data)); len = parse_hex(hexa, (unsigned char *)&m.addr.data, sizeof(m.addr.data));
if (len >= 0) { if (len >= 0) {
struct ma_info *ma = malloc(sizeof(m)); struct ma_info *ma = malloc(sizeof(m));
...@@ -200,12 +200,13 @@ static void print_maddr(FILE *fp, struct ma_info *list) ...@@ -200,12 +200,13 @@ static void print_maddr(FILE *fp, struct ma_info *list)
if (list->addr.family == AF_PACKET) { if (list->addr.family == AF_PACKET) {
SPRINT_BUF(b1); SPRINT_BUF(b1);
fprintf(fp, "link %s", ll_addr_n2a((unsigned char*)list->addr.data, fprintf(fp, "link %s", ll_addr_n2a((unsigned char *)list->addr.data,
list->addr.bytelen, 0, list->addr.bytelen, 0,
b1, sizeof(b1))); b1, sizeof(b1)));
} else { } else {
char abuf[256]; char abuf[256];
switch(list->addr.family) {
switch (list->addr.family) {
case AF_INET: case AF_INET:
fprintf(fp, "inet "); fprintf(fp, "inet ");
break; break;
...@@ -256,8 +257,7 @@ static int multiaddr_list(int argc, char **argv) ...@@ -256,8 +257,7 @@ static int multiaddr_list(int argc, char **argv)
if (1) { if (1) {
if (strcmp(*argv, "dev") == 0) { if (strcmp(*argv, "dev") == 0) {
NEXT_ARG(); NEXT_ARG();
} } else if (matches(*argv, "help") == 0)
else if (matches(*argv, "help") == 0)
usage(); usage();
if (filter.dev) if (filter.dev)
duparg2("dev", *argv); duparg2("dev", *argv);
...@@ -320,7 +320,7 @@ static int multiaddr_modify(int cmd, int argc, char **argv) ...@@ -320,7 +320,7 @@ static int multiaddr_modify(int cmd, int argc, char **argv)
perror("Cannot create socket"); perror("Cannot create socket");
exit(1); exit(1);
} }
if (ioctl(fd, cmd, (char*)&ifr) != 0) { if (ioctl(fd, cmd, (char *)&ifr) != 0) {
perror("ioctl"); perror("ioctl");
exit(1); exit(1);
} }
......
...@@ -30,8 +30,7 @@ int listen_all_nsid; ...@@ -30,8 +30,7 @@ int listen_all_nsid;
static void usage(void) static void usage(void)
{ {
fprintf(stderr, "Usage: ip monitor [ all | LISTofOBJECTS ] [ FILE ] " fprintf(stderr, "Usage: ip monitor [ all | LISTofOBJECTS ] [ FILE ] [ label ] [all-nsid] [dev DEVICE]\n");
"[ label ] [all-nsid] [dev DEVICE]\n");
fprintf(stderr, "LISTofOBJECTS := link | address | route | mroute | prefix |\n"); fprintf(stderr, "LISTofOBJECTS := link | address | route | mroute | prefix |\n");
fprintf(stderr, " neigh | netconf | rule | nsid\n"); fprintf(stderr, " neigh | netconf | rule | nsid\n");
fprintf(stderr, "FILE := file FILENAME\n"); fprintf(stderr, "FILE := file FILENAME\n");
...@@ -58,7 +57,7 @@ static int accept_msg(const struct sockaddr_nl *who, ...@@ -58,7 +57,7 @@ static int accept_msg(const struct sockaddr_nl *who,
struct rtnl_ctrl_data *ctrl, struct rtnl_ctrl_data *ctrl,
struct nlmsghdr *n, void *arg) struct nlmsghdr *n, void *arg)
{ {
FILE *fp = (FILE*)arg; FILE *fp = (FILE *)arg;
if (n->nlmsg_type == RTM_NEWROUTE || n->nlmsg_type == RTM_DELROUTE) { if (n->nlmsg_type == RTM_NEWROUTE || n->nlmsg_type == RTM_DELROUTE) {
struct rtmsg *r = NLMSG_DATA(n); struct rtmsg *r = NLMSG_DATA(n);
...@@ -139,8 +138,8 @@ static int accept_msg(const struct sockaddr_nl *who, ...@@ -139,8 +138,8 @@ static int accept_msg(const struct sockaddr_nl *who,
} }
if (n->nlmsg_type != NLMSG_ERROR && n->nlmsg_type != NLMSG_NOOP && if (n->nlmsg_type != NLMSG_ERROR && n->nlmsg_type != NLMSG_NOOP &&
n->nlmsg_type != NLMSG_DONE) { n->nlmsg_type != NLMSG_DONE) {
fprintf(fp, "Unknown message: type=0x%08x(%d) flags=0x%08x(%d)" fprintf(fp, "Unknown message: type=0x%08x(%d) flags=0x%08x(%d)len=0x%08x(%d)\n",
"len=0x%08x(%d)\n", n->nlmsg_type, n->nlmsg_type, n->nlmsg_type, n->nlmsg_type,
n->nlmsg_flags, n->nlmsg_flags, n->nlmsg_len, n->nlmsg_flags, n->nlmsg_flags, n->nlmsg_len,
n->nlmsg_len); n->nlmsg_len);
} }
...@@ -150,17 +149,17 @@ static int accept_msg(const struct sockaddr_nl *who, ...@@ -150,17 +149,17 @@ static int accept_msg(const struct sockaddr_nl *who,
int do_ipmonitor(int argc, char **argv) int do_ipmonitor(int argc, char **argv)
{ {
char *file = NULL; char *file = NULL;
unsigned groups = 0; unsigned int groups = 0;
int llink=0; int llink = 0;
int laddr=0; int laddr = 0;
int lroute=0; int lroute = 0;
int lmroute=0; int lmroute = 0;
int lprefix=0; int lprefix = 0;
int lneigh=0; int lneigh = 0;
int lnetconf=0; int lnetconf = 0;
int lrule=0; int lrule = 0;
int lnsid=0; int lnsid = 0;
int ifindex=0; int ifindex = 0;
groups |= nl_mgrp(RTNLGRP_LINK); groups |= nl_mgrp(RTNLGRP_LINK);
groups |= nl_mgrp(RTNLGRP_IPV4_IFADDR); groups |= nl_mgrp(RTNLGRP_IPV4_IFADDR);
...@@ -187,19 +186,19 @@ int do_ipmonitor(int argc, char **argv) ...@@ -187,19 +186,19 @@ int do_ipmonitor(int argc, char **argv)
} else if (matches(*argv, "label") == 0) { } else if (matches(*argv, "label") == 0) {
prefix_banner = 1; prefix_banner = 1;
} else if (matches(*argv, "link") == 0) { } else if (matches(*argv, "link") == 0) {
llink=1; llink = 1;
groups = 0; groups = 0;
} else if (matches(*argv, "address") == 0) { } else if (matches(*argv, "address") == 0) {
laddr=1; laddr = 1;
groups = 0; groups = 0;
} else if (matches(*argv, "route") == 0) { } else if (matches(*argv, "route") == 0) {
lroute=1; lroute = 1;
groups = 0; groups = 0;
} else if (matches(*argv, "mroute") == 0) { } else if (matches(*argv, "mroute") == 0) {
lmroute=1; lmroute = 1;
groups = 0; groups = 0;
} else if (matches(*argv, "prefix") == 0) { } else if (matches(*argv, "prefix") == 0) {
lprefix=1; lprefix = 1;
groups = 0; groups = 0;
} else if (matches(*argv, "neigh") == 0) { } else if (matches(*argv, "neigh") == 0) {
lneigh = 1; lneigh = 1;
...@@ -214,7 +213,7 @@ int do_ipmonitor(int argc, char **argv) ...@@ -214,7 +213,7 @@ int do_ipmonitor(int argc, char **argv)
lnsid = 1; lnsid = 1;
groups = 0; groups = 0;
} else if (strcmp(*argv, "all") == 0) { } else if (strcmp(*argv, "all") == 0) {
prefix_banner=1; prefix_banner = 1;
} else if (matches(*argv, "all-nsid") == 0) { } else if (matches(*argv, "all-nsid") == 0) {
listen_all_nsid = 1; listen_all_nsid = 1;
} else if (matches(*argv, "help") == 0) { } else if (matches(*argv, "help") == 0) {
......
...@@ -44,8 +44,7 @@ static void usage(void) ...@@ -44,8 +44,7 @@ static void usage(void)
exit(-1); exit(-1);
} }
struct rtfilter struct rtfilter {
{
int tb; int tb;
int af; int af;
int iif; int iif;
...@@ -55,12 +54,13 @@ struct rtfilter ...@@ -55,12 +54,13 @@ struct rtfilter
int print_mroute(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) int print_mroute(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
{ {
FILE *fp = (FILE*)arg; FILE *fp = (FILE *)arg;
struct rtmsg *r = NLMSG_DATA(n); struct rtmsg *r = NLMSG_DATA(n);
int len = n->nlmsg_len; int len = n->nlmsg_len;
struct rtattr * tb[RTA_MAX+1]; struct rtattr *tb[RTA_MAX+1];
char abuf[256]; char abuf[256];
char obuf[256]; char obuf[256];
SPRINT_BUF(b1); SPRINT_BUF(b1);
__u32 table; __u32 table;
int iif = 0; int iif = 0;
...@@ -90,7 +90,7 @@ int print_mroute(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -90,7 +90,7 @@ int print_mroute(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
return 0; return 0;
if (tb[RTA_IIF]) if (tb[RTA_IIF])
iif = *(int*)RTA_DATA(tb[RTA_IIF]); iif = *(int *)RTA_DATA(tb[RTA_IIF]);
if (filter.iif && filter.iif != iif) if (filter.iif && filter.iif != iif)
return 0; return 0;
...@@ -212,6 +212,7 @@ static int mroute_list(int argc, char **argv) ...@@ -212,6 +212,7 @@ static int mroute_list(int argc, char **argv)
while (argc > 0) { while (argc > 0) {
if (matches(*argv, "table") == 0) { if (matches(*argv, "table") == 0) {
__u32 tid; __u32 tid;
NEXT_ARG(); NEXT_ARG();
if (rtnl_rttable_a2n(&tid, *argv)) { if (rtnl_rttable_a2n(&tid, *argv)) {
if (strcmp(*argv, "all") == 0) { if (strcmp(*argv, "all") == 0) {
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
static struct static struct
{ {
int family; int family;
int index; int index;
int state; int state;
int unused_only; int unused_only;
inet_prefix pfx; inet_prefix pfx;
...@@ -50,11 +50,11 @@ static void usage(void) ...@@ -50,11 +50,11 @@ static void usage(void)
" { ADDR [ lladdr LLADDR ] [ nud STATE ] | proxy ADDR } [ dev DEV ]\n"); " { ADDR [ lladdr LLADDR ] [ nud STATE ] | proxy ADDR } [ dev DEV ]\n");
fprintf(stderr, " ip neigh { show | flush } [ proxy ] [ to PREFIX ] [ dev DEV ] [ nud STATE ]\n\n"); fprintf(stderr, " ip neigh { show | flush } [ proxy ] [ to PREFIX ] [ dev DEV ] [ nud STATE ]\n\n");
fprintf(stderr, "STATE := { permanent | noarp | stale | reachable | none |\n" fprintf(stderr, "STATE := { permanent | noarp | stale | reachable | none |\n"
" incomplete | delay | probe | failed }\n"); " incomplete | delay | probe | failed }\n");
exit(-1); exit(-1);
} }
static int nud_state_a2n(unsigned *state, const char *arg) static int nud_state_a2n(unsigned int *state, const char *arg)
{ {
if (matches(arg, "permanent") == 0) if (matches(arg, "permanent") == 0)
*state = NUD_PERMANENT; *state = NUD_PERMANENT;
...@@ -77,7 +77,7 @@ static int nud_state_a2n(unsigned *state, const char *arg) ...@@ -77,7 +77,7 @@ static int nud_state_a2n(unsigned *state, const char *arg)
else { else {
if (get_unsigned(state, arg, 0)) if (get_unsigned(state, arg, 0))
return -1; return -1;
if (*state>=0x100 || (*state&((*state)-1))) if (*state >= 0x100 || (*state&((*state)-1)))
return -1; return -1;
} }
return 0; return 0;
...@@ -99,13 +99,13 @@ static int ipneigh_modify(int cmd, int flags, int argc, char **argv) ...@@ -99,13 +99,13 @@ static int ipneigh_modify(int cmd, int flags, int argc, char **argv)
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
struct ndmsg ndm; struct ndmsg ndm;
char buf[256]; char buf[256];
} req; } req;
char *dev = NULL; char *dev = NULL;
int dst_ok = 0; int dst_ok = 0;
int dev_ok = 0; int dev_ok = 0;
int lladdr_ok = 0; int lladdr_ok = 0;
char * lla = NULL; char *lla = NULL;
inet_prefix dst; inet_prefix dst;
memset(&req, 0, sizeof(req)); memset(&req, 0, sizeof(req));
...@@ -124,7 +124,8 @@ static int ipneigh_modify(int cmd, int flags, int argc, char **argv) ...@@ -124,7 +124,8 @@ static int ipneigh_modify(int cmd, int flags, int argc, char **argv)
lla = *argv; lla = *argv;
lladdr_ok = 1; lladdr_ok = 1;
} else if (strcmp(*argv, "nud") == 0) { } else if (strcmp(*argv, "nud") == 0) {
unsigned state; unsigned int state;
NEXT_ARG(); NEXT_ARG();
if (nud_state_a2n(&state, *argv)) if (nud_state_a2n(&state, *argv))
invarg("nud state is bad", *argv); invarg("nud state is bad", *argv);
...@@ -193,10 +194,10 @@ static int ipneigh_modify(int cmd, int flags, int argc, char **argv) ...@@ -193,10 +194,10 @@ static int ipneigh_modify(int cmd, int flags, int argc, char **argv)
int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
{ {
FILE *fp = (FILE*)arg; FILE *fp = (FILE *)arg;
struct ndmsg *r = NLMSG_DATA(n); struct ndmsg *r = NLMSG_DATA(n);
int len = n->nlmsg_len; int len = n->nlmsg_len;
struct rtattr * tb[NDA_MAX+1]; struct rtattr *tb[NDA_MAX+1];
char abuf[256]; char abuf[256];
static int logit = 1; static int logit = 1;
...@@ -223,7 +224,7 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -223,7 +224,7 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (!(filter.state&r->ndm_state) && if (!(filter.state&r->ndm_state) &&
!(r->ndm_flags & NTF_PROXY) && !(r->ndm_flags & NTF_PROXY) &&
(r->ndm_state || !(filter.state&0x100)) && (r->ndm_state || !(filter.state&0x100)) &&
(r->ndm_family != AF_DECnet)) (r->ndm_family != AF_DECnet))
return 0; return 0;
if (filter.master && !(n->nlmsg_flags & NLM_F_DUMP_FILTERED)) { if (filter.master && !(n->nlmsg_flags & NLM_F_DUMP_FILTERED)) {
...@@ -239,6 +240,7 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -239,6 +240,7 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[NDA_DST]) { if (tb[NDA_DST]) {
if (filter.pfx.family) { if (filter.pfx.family) {
inet_prefix dst; inet_prefix dst;
memset(&dst, 0, sizeof(dst)); memset(&dst, 0, sizeof(dst));
dst.family = r->ndm_family; dst.family = r->ndm_family;
memcpy(&dst.data, RTA_DATA(tb[NDA_DST]), RTA_PAYLOAD(tb[NDA_DST])); memcpy(&dst.data, RTA_DATA(tb[NDA_DST]), RTA_PAYLOAD(tb[NDA_DST]));
...@@ -248,22 +250,24 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -248,22 +250,24 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
} }
if (filter.unused_only && tb[NDA_CACHEINFO]) { if (filter.unused_only && tb[NDA_CACHEINFO]) {
struct nda_cacheinfo *ci = RTA_DATA(tb[NDA_CACHEINFO]); struct nda_cacheinfo *ci = RTA_DATA(tb[NDA_CACHEINFO]);
if (ci->ndm_refcnt) if (ci->ndm_refcnt)
return 0; return 0;
} }
if (filter.flushb) { if (filter.flushb) {
struct nlmsghdr *fn; struct nlmsghdr *fn;
if (NLMSG_ALIGN(filter.flushp) + n->nlmsg_len > filter.flushe) { if (NLMSG_ALIGN(filter.flushp) + n->nlmsg_len > filter.flushe) {
if (flush_update()) if (flush_update())
return -1; return -1;
} }
fn = (struct nlmsghdr*)(filter.flushb + NLMSG_ALIGN(filter.flushp)); fn = (struct nlmsghdr *)(filter.flushb + NLMSG_ALIGN(filter.flushp));
memcpy(fn, n, n->nlmsg_len); memcpy(fn, n, n->nlmsg_len);
fn->nlmsg_type = RTM_DELNEIGH; fn->nlmsg_type = RTM_DELNEIGH;
fn->nlmsg_flags = NLM_F_REQUEST; fn->nlmsg_flags = NLM_F_REQUEST;
fn->nlmsg_seq = ++rth.seq; fn->nlmsg_seq = ++rth.seq;
filter.flushp = (((char*)fn) + n->nlmsg_len) - filter.flushb; filter.flushp = (((char *)fn) + n->nlmsg_len) - filter.flushb;
filter.flushed++; filter.flushed++;
if (show_stats < 2) if (show_stats < 2)
return 0; return 0;
...@@ -307,11 +311,13 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -307,11 +311,13 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[NDA_PROBES] && show_stats) { if (tb[NDA_PROBES] && show_stats) {
__u32 p = rta_getattr_u32(tb[NDA_PROBES]); __u32 p = rta_getattr_u32(tb[NDA_PROBES]);
fprintf(fp, " probes %u", p); fprintf(fp, " probes %u", p);
} }
if (r->ndm_state) { if (r->ndm_state) {
int nud = r->ndm_state; int nud = r->ndm_state;
fprintf(fp, " "); fprintf(fp, " ");
#define PRINT_FLAG(f) if (nud & NUD_##f) { \ #define PRINT_FLAG(f) if (nud & NUD_##f) { \
...@@ -344,7 +350,7 @@ static int do_show_or_flush(int argc, char **argv, int flush) ...@@ -344,7 +350,7 @@ static int do_show_or_flush(int argc, char **argv, int flush)
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
struct ndmsg ndm; struct ndmsg ndm;
char buf[256]; char buf[256];
} req; } req;
char *filter_dev = NULL; char *filter_dev = NULL;
int state_given = 0; int state_given = 0;
...@@ -376,6 +382,7 @@ static int do_show_or_flush(int argc, char **argv, int flush) ...@@ -376,6 +382,7 @@ static int do_show_or_flush(int argc, char **argv, int flush)
filter_dev = *argv; filter_dev = *argv;
} else if (strcmp(*argv, "master") == 0) { } else if (strcmp(*argv, "master") == 0) {
int ifindex; int ifindex;
NEXT_ARG(); NEXT_ARG();
ifindex = ll_name_to_index(*argv); ifindex = ll_name_to_index(*argv);
if (!ifindex) if (!ifindex)
...@@ -385,7 +392,8 @@ static int do_show_or_flush(int argc, char **argv, int flush) ...@@ -385,7 +392,8 @@ static int do_show_or_flush(int argc, char **argv, int flush)
} else if (strcmp(*argv, "unused") == 0) { } else if (strcmp(*argv, "unused") == 0) {
filter.unused_only = 1; filter.unused_only = 1;
} else if (strcmp(*argv, "nud") == 0) { } else if (strcmp(*argv, "nud") == 0) {
unsigned state; unsigned int state;
NEXT_ARG(); NEXT_ARG();
if (!state_given) { if (!state_given) {
state_given = 1; state_given = 1;
...@@ -450,7 +458,7 @@ static int do_show_or_flush(int argc, char **argv, int flush) ...@@ -450,7 +458,7 @@ static int do_show_or_flush(int argc, char **argv, int flush)
if (round == 0) if (round == 0)
printf("Nothing to flush.\n"); printf("Nothing to flush.\n");
else else
printf("*** Flush is complete after %d round%s ***\n", round, round>1?"s":""); printf("*** Flush is complete after %d round%s ***\n", round, round > 1?"s":"");
} }
fflush(stdout); fflush(stdout);
return 0; return 0;
......
...@@ -38,12 +38,12 @@ static void usage(void) ...@@ -38,12 +38,12 @@ static void usage(void)
exit(-1); exit(-1);
} }
#define NETCONF_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct netconfmsg)))) #define NETCONF_RTA(r) ((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct netconfmsg))))
int print_netconf(const struct sockaddr_nl *who, struct rtnl_ctrl_data *ctrl, int print_netconf(const struct sockaddr_nl *who, struct rtnl_ctrl_data *ctrl,
struct nlmsghdr *n, void *arg) struct nlmsghdr *n, void *arg)
{ {
FILE *fp = (FILE*)arg; FILE *fp = (FILE *)arg;
struct netconfmsg *ncm = NLMSG_DATA(n); struct netconfmsg *ncm = NLMSG_DATA(n);
int len = n->nlmsg_len; int len = n->nlmsg_len;
struct rtattr *tb[NETCONFA_MAX+1]; struct rtattr *tb[NETCONFA_MAX+1];
......
...@@ -389,6 +389,7 @@ static int cmd_exec(const char *cmd, char **argv, bool do_fork) ...@@ -389,6 +389,7 @@ static int cmd_exec(const char *cmd, char **argv, bool do_fork)
static int on_netns_exec(char *nsname, void *arg) static int on_netns_exec(char *nsname, void *arg)
{ {
char **argv = arg; char **argv = arg;
cmd_exec(argv[1], argv + 1, true); cmd_exec(argv[1], argv + 1, true);
return 0; return 0;
} }
...@@ -426,6 +427,7 @@ static int netns_exec(int argc, char **argv) ...@@ -426,6 +427,7 @@ static int netns_exec(int argc, char **argv)
static int is_pid(const char *str) static int is_pid(const char *str)
{ {
int ch; int ch;
for (; (ch = *str); str++) { for (; (ch = *str); str++) {
if (!isdigit(ch)) if (!isdigit(ch))
return 0; return 0;
...@@ -470,9 +472,10 @@ static int netns_pids(int argc, char **argv) ...@@ -470,9 +472,10 @@ static int netns_pids(int argc, char **argv)
strerror(errno)); strerror(errno));
return -1; return -1;
} }
while((entry = readdir(dir))) { while ((entry = readdir(dir))) {
char pid_net_path[PATH_MAX]; char pid_net_path[PATH_MAX];
struct stat st; struct stat st;
if (!is_pid(entry->d_name)) if (!is_pid(entry->d_name))
continue; continue;
snprintf(pid_net_path, sizeof(pid_net_path), "/proc/%s/ns/net", snprintf(pid_net_path, sizeof(pid_net_path), "/proc/%s/ns/net",
...@@ -535,7 +538,7 @@ static int netns_identify(int argc, char **argv) ...@@ -535,7 +538,7 @@ static int netns_identify(int argc, char **argv)
return -1; return -1;
} }
while((entry = readdir(dir))) { while ((entry = readdir(dir))) {
char name_path[PATH_MAX]; char name_path[PATH_MAX];
struct stat st; struct stat st;
...@@ -737,6 +740,7 @@ static int netns_monitor(int argc, char **argv) ...@@ -737,6 +740,7 @@ static int netns_monitor(int argc, char **argv)
char buf[4096]; char buf[4096];
struct inotify_event *event; struct inotify_event *event;
int fd; int fd;
fd = inotify_init(); fd = inotify_init();
if (fd < 0) { if (fd < 0) {
fprintf(stderr, "inotify_init failed: %s\n", fprintf(stderr, "inotify_init failed: %s\n",
...@@ -752,8 +756,9 @@ static int netns_monitor(int argc, char **argv) ...@@ -752,8 +756,9 @@ static int netns_monitor(int argc, char **argv)
strerror(errno)); strerror(errno));
return -1; return -1;
} }
for(;;) { for (;;) {
ssize_t len = read(fd, buf, sizeof(buf)); ssize_t len = read(fd, buf, sizeof(buf));
if (len < 0) { if (len < 0) {
fprintf(stderr, "read failed: %s\n", fprintf(stderr, "read failed: %s\n",
strerror(errno)); strerror(errno));
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
static struct static struct
{ {
int family; int family;
int index; int index;
#define NONE_DEV (-1) #define NONE_DEV (-1)
char name[1024]; char name[1024];
} filter; } filter;
...@@ -65,7 +65,7 @@ static int ipntable_modify(int cmd, int flags, int argc, char **argv) ...@@ -65,7 +65,7 @@ static int ipntable_modify(int cmd, int flags, int argc, char **argv)
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
struct ndtmsg ndtm; struct ndtmsg ndtm;
char buf[1024]; char buf[1024];
} req; } req;
char *namep = NULL; char *namep = NULL;
char *threshsp = NULL; char *threshsp = NULL;
...@@ -351,7 +351,7 @@ static const char *ntable_strtime_delta(__u32 msec) ...@@ -351,7 +351,7 @@ static const char *ntable_strtime_delta(__u32 msec)
static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
{ {
FILE *fp = (FILE*)arg; FILE *fp = (FILE *)arg;
struct ndtmsg *ndtm = NLMSG_DATA(n); struct ndtmsg *ndtm = NLMSG_DATA(n);
int len = n->nlmsg_len; int len = n->nlmsg_len;
struct rtattr *tb[NDTA_MAX+1]; struct rtattr *tb[NDTA_MAX+1];
...@@ -407,6 +407,7 @@ static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void ...@@ -407,6 +407,7 @@ static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void
if (tb[NDTA_NAME]) { if (tb[NDTA_NAME]) {
const char *name = rta_getattr_str(tb[NDTA_NAME]); const char *name = rta_getattr_str(tb[NDTA_NAME]);
fprintf(fp, "%s ", name); fprintf(fp, "%s ", name);
} }
...@@ -419,18 +420,22 @@ static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void ...@@ -419,18 +420,22 @@ static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void
if (tb[NDTA_THRESH1]) { if (tb[NDTA_THRESH1]) {
__u32 thresh1 = rta_getattr_u32(tb[NDTA_THRESH1]); __u32 thresh1 = rta_getattr_u32(tb[NDTA_THRESH1]);
fprintf(fp, "thresh1 %u ", thresh1); fprintf(fp, "thresh1 %u ", thresh1);
} }
if (tb[NDTA_THRESH2]) { if (tb[NDTA_THRESH2]) {
__u32 thresh2 = rta_getattr_u32(tb[NDTA_THRESH2]); __u32 thresh2 = rta_getattr_u32(tb[NDTA_THRESH2]);
fprintf(fp, "thresh2 %u ", thresh2); fprintf(fp, "thresh2 %u ", thresh2);
} }
if (tb[NDTA_THRESH3]) { if (tb[NDTA_THRESH3]) {
__u32 thresh3 = rta_getattr_u32(tb[NDTA_THRESH3]); __u32 thresh3 = rta_getattr_u32(tb[NDTA_THRESH3]);
fprintf(fp, "thresh3 %u ", thresh3); fprintf(fp, "thresh3 %u ", thresh3);
} }
if (tb[NDTA_GC_INTERVAL]) { if (tb[NDTA_GC_INTERVAL]) {
unsigned long long gc_int = rta_getattr_u64(tb[NDTA_GC_INTERVAL]); unsigned long long gc_int = rta_getattr_u64(tb[NDTA_GC_INTERVAL]);
fprintf(fp, "gc_int %llu ", gc_int); fprintf(fp, "gc_int %llu ", gc_int);
} }
...@@ -480,18 +485,22 @@ static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void ...@@ -480,18 +485,22 @@ static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void
if (tpb[NDTPA_REFCNT]) { if (tpb[NDTPA_REFCNT]) {
__u32 refcnt = rta_getattr_u32(tpb[NDTPA_REFCNT]); __u32 refcnt = rta_getattr_u32(tpb[NDTPA_REFCNT]);
fprintf(fp, "refcnt %u ", refcnt); fprintf(fp, "refcnt %u ", refcnt);
} }
if (tpb[NDTPA_REACHABLE_TIME]) { if (tpb[NDTPA_REACHABLE_TIME]) {
unsigned long long reachable = rta_getattr_u64(tpb[NDTPA_REACHABLE_TIME]); unsigned long long reachable = rta_getattr_u64(tpb[NDTPA_REACHABLE_TIME]);
fprintf(fp, "reachable %llu ", reachable); fprintf(fp, "reachable %llu ", reachable);
} }
if (tpb[NDTPA_BASE_REACHABLE_TIME]) { if (tpb[NDTPA_BASE_REACHABLE_TIME]) {
unsigned long long breachable = rta_getattr_u64(tpb[NDTPA_BASE_REACHABLE_TIME]); unsigned long long breachable = rta_getattr_u64(tpb[NDTPA_BASE_REACHABLE_TIME]);
fprintf(fp, "base_reachable %llu ", breachable); fprintf(fp, "base_reachable %llu ", breachable);
} }
if (tpb[NDTPA_RETRANS_TIME]) { if (tpb[NDTPA_RETRANS_TIME]) {
unsigned long long retrans = rta_getattr_u64(tpb[NDTPA_RETRANS_TIME]); unsigned long long retrans = rta_getattr_u64(tpb[NDTPA_RETRANS_TIME]);
fprintf(fp, "retrans %llu ", retrans); fprintf(fp, "retrans %llu ", retrans);
} }
...@@ -501,14 +510,17 @@ static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void ...@@ -501,14 +510,17 @@ static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void
if (tpb[NDTPA_GC_STALETIME]) { if (tpb[NDTPA_GC_STALETIME]) {
unsigned long long gc_stale = rta_getattr_u64(tpb[NDTPA_GC_STALETIME]); unsigned long long gc_stale = rta_getattr_u64(tpb[NDTPA_GC_STALETIME]);
fprintf(fp, "gc_stale %llu ", gc_stale); fprintf(fp, "gc_stale %llu ", gc_stale);
} }
if (tpb[NDTPA_DELAY_PROBE_TIME]) { if (tpb[NDTPA_DELAY_PROBE_TIME]) {
unsigned long long delay_probe = rta_getattr_u64(tpb[NDTPA_DELAY_PROBE_TIME]); unsigned long long delay_probe = rta_getattr_u64(tpb[NDTPA_DELAY_PROBE_TIME]);
fprintf(fp, "delay_probe %llu ", delay_probe); fprintf(fp, "delay_probe %llu ", delay_probe);
} }
if (tpb[NDTPA_QUEUE_LEN]) { if (tpb[NDTPA_QUEUE_LEN]) {
__u32 queue = rta_getattr_u32(tpb[NDTPA_QUEUE_LEN]); __u32 queue = rta_getattr_u32(tpb[NDTPA_QUEUE_LEN]);
fprintf(fp, "queue %u ", queue); fprintf(fp, "queue %u ", queue);
} }
...@@ -518,14 +530,17 @@ static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void ...@@ -518,14 +530,17 @@ static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void
if (tpb[NDTPA_APP_PROBES]) { if (tpb[NDTPA_APP_PROBES]) {
__u32 aprobe = rta_getattr_u32(tpb[NDTPA_APP_PROBES]); __u32 aprobe = rta_getattr_u32(tpb[NDTPA_APP_PROBES]);
fprintf(fp, "app_probes %u ", aprobe); fprintf(fp, "app_probes %u ", aprobe);
} }
if (tpb[NDTPA_UCAST_PROBES]) { if (tpb[NDTPA_UCAST_PROBES]) {
__u32 uprobe = rta_getattr_u32(tpb[NDTPA_UCAST_PROBES]); __u32 uprobe = rta_getattr_u32(tpb[NDTPA_UCAST_PROBES]);
fprintf(fp, "ucast_probes %u ", uprobe); fprintf(fp, "ucast_probes %u ", uprobe);
} }
if (tpb[NDTPA_MCAST_PROBES]) { if (tpb[NDTPA_MCAST_PROBES]) {
__u32 mprobe = rta_getattr_u32(tpb[NDTPA_MCAST_PROBES]); __u32 mprobe = rta_getattr_u32(tpb[NDTPA_MCAST_PROBES]);
fprintf(fp, "mcast_probes %u ", mprobe); fprintf(fp, "mcast_probes %u ", mprobe);
} }
...@@ -535,18 +550,22 @@ static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void ...@@ -535,18 +550,22 @@ static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void
if (tpb[NDTPA_ANYCAST_DELAY]) { if (tpb[NDTPA_ANYCAST_DELAY]) {
unsigned long long anycast_delay = rta_getattr_u64(tpb[NDTPA_ANYCAST_DELAY]); unsigned long long anycast_delay = rta_getattr_u64(tpb[NDTPA_ANYCAST_DELAY]);
fprintf(fp, "anycast_delay %llu ", anycast_delay); fprintf(fp, "anycast_delay %llu ", anycast_delay);
} }
if (tpb[NDTPA_PROXY_DELAY]) { if (tpb[NDTPA_PROXY_DELAY]) {
unsigned long long proxy_delay = rta_getattr_u64(tpb[NDTPA_PROXY_DELAY]); unsigned long long proxy_delay = rta_getattr_u64(tpb[NDTPA_PROXY_DELAY]);
fprintf(fp, "proxy_delay %llu ", proxy_delay); fprintf(fp, "proxy_delay %llu ", proxy_delay);
} }
if (tpb[NDTPA_PROXY_QLEN]) { if (tpb[NDTPA_PROXY_QLEN]) {
__u32 pqueue = rta_getattr_u32(tpb[NDTPA_PROXY_QLEN]); __u32 pqueue = rta_getattr_u32(tpb[NDTPA_PROXY_QLEN]);
fprintf(fp, "proxy_queue %u ", pqueue); fprintf(fp, "proxy_queue %u ", pqueue);
} }
if (tpb[NDTPA_LOCKTIME]) { if (tpb[NDTPA_LOCKTIME]) {
unsigned long long locktime = rta_getattr_u64(tpb[NDTPA_LOCKTIME]); unsigned long long locktime = rta_getattr_u64(tpb[NDTPA_LOCKTIME]);
fprintf(fp, "locktime %llu ", locktime); fprintf(fp, "locktime %llu ", locktime);
} }
......
...@@ -37,10 +37,10 @@ ...@@ -37,10 +37,10 @@
int print_prefix(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) int print_prefix(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
{ {
FILE *fp = (FILE*)arg; FILE *fp = (FILE *)arg;
struct prefixmsg *prefix = NLMSG_DATA(n); struct prefixmsg *prefix = NLMSG_DATA(n);
int len = n->nlmsg_len; int len = n->nlmsg_len;
struct rtattr * tb[RTA_MAX+1]; struct rtattr *tb[RTA_MAX+1];
int family = preferred_family; int family = preferred_family;
if (n->nlmsg_type != RTM_NEWPREFIX) { if (n->nlmsg_type != RTM_NEWPREFIX) {
...@@ -96,6 +96,7 @@ int print_prefix(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -96,6 +96,7 @@ int print_prefix(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[PREFIX_CACHEINFO]) { if (tb[PREFIX_CACHEINFO]) {
struct prefix_cacheinfo *pc; struct prefix_cacheinfo *pc;
pc = (struct prefix_cacheinfo *)RTA_DATA(tb[PREFIX_CACHEINFO]); pc = (struct prefix_cacheinfo *)RTA_DATA(tb[PREFIX_CACHEINFO]);
fprintf(fp, "valid %u ", pc->valid_time); fprintf(fp, "valid %u ", pc->valid_time);
......
...@@ -48,7 +48,7 @@ static const char *mx_names[RTAX_MAX+1] = { ...@@ -48,7 +48,7 @@ static const char *mx_names[RTAX_MAX+1] = {
[RTAX_SSTHRESH] = "ssthresh", [RTAX_SSTHRESH] = "ssthresh",
[RTAX_CWND] = "cwnd", [RTAX_CWND] = "cwnd",
[RTAX_ADVMSS] = "advmss", [RTAX_ADVMSS] = "advmss",
[RTAX_REORDERING]="reordering", [RTAX_REORDERING] = "reordering",
[RTAX_HOPLIMIT] = "hoplimit", [RTAX_HOPLIMIT] = "hoplimit",
[RTAX_INITCWND] = "initcwnd", [RTAX_INITCWND] = "initcwnd",
[RTAX_FEATURES] = "features", [RTAX_FEATURES] = "features",
...@@ -198,8 +198,10 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len) ...@@ -198,8 +198,10 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
return 0; return 0;
if (filter.rvia.family) { if (filter.rvia.family) {
int family = r->rtm_family; int family = r->rtm_family;
if (tb[RTA_VIA]) { if (tb[RTA_VIA]) {
struct rtvia *via = RTA_DATA(tb[RTA_VIA]); struct rtvia *via = RTA_DATA(tb[RTA_VIA]);
family = via->rtvia_family; family = via->rtvia_family;
} }
if (family != filter.rvia.family) if (family != filter.rvia.family)
...@@ -218,7 +220,7 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len) ...@@ -218,7 +220,7 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
if (tb[RTA_SRC]) if (tb[RTA_SRC])
memcpy(&src.data, RTA_DATA(tb[RTA_SRC]), (r->rtm_src_len+7)/8); memcpy(&src.data, RTA_DATA(tb[RTA_SRC]), (r->rtm_src_len+7)/8);
} }
if (filter.rvia.bitlen>0) { if (filter.rvia.bitlen > 0) {
memset(&via, 0, sizeof(via)); memset(&via, 0, sizeof(via));
via.family = r->rtm_family; via.family = r->rtm_family;
if (tb[RTA_GATEWAY]) if (tb[RTA_GATEWAY])
...@@ -226,11 +228,12 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len) ...@@ -226,11 +228,12 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
if (tb[RTA_VIA]) { if (tb[RTA_VIA]) {
size_t len = RTA_PAYLOAD(tb[RTA_VIA]) - 2; size_t len = RTA_PAYLOAD(tb[RTA_VIA]) - 2;
struct rtvia *rtvia = RTA_DATA(tb[RTA_VIA]); struct rtvia *rtvia = RTA_DATA(tb[RTA_VIA]);
via.family = rtvia->rtvia_family; via.family = rtvia->rtvia_family;
memcpy(&via.data, rtvia->rtvia_addr, len); memcpy(&via.data, rtvia->rtvia_addr, len);
} }
} }
if (filter.rprefsrc.bitlen>0) { if (filter.rprefsrc.bitlen > 0) {
memset(&prefsrc, 0, sizeof(prefsrc)); memset(&prefsrc, 0, sizeof(prefsrc));
prefsrc.family = r->rtm_family; prefsrc.family = r->rtm_family;
if (tb[RTA_PREFSRC]) if (tb[RTA_PREFSRC])
...@@ -255,6 +258,7 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len) ...@@ -255,6 +258,7 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
return 0; return 0;
if (filter.realmmask) { if (filter.realmmask) {
__u32 realms = 0; __u32 realms = 0;
if (tb[RTA_FLOW]) if (tb[RTA_FLOW])
realms = rta_getattr_u32(tb[RTA_FLOW]); realms = rta_getattr_u32(tb[RTA_FLOW]);
if ((realms^filter.realm)&filter.realmmask) if ((realms^filter.realm)&filter.realmmask)
...@@ -262,20 +266,23 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len) ...@@ -262,20 +266,23 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
} }
if (filter.iifmask) { if (filter.iifmask) {
int iif = 0; int iif = 0;
if (tb[RTA_IIF]) if (tb[RTA_IIF])
iif = *(int*)RTA_DATA(tb[RTA_IIF]); iif = *(int *)RTA_DATA(tb[RTA_IIF]);
if ((iif^filter.iif)&filter.iifmask) if ((iif^filter.iif)&filter.iifmask)
return 0; return 0;
} }
if (filter.oifmask) { if (filter.oifmask) {
int oif = 0; int oif = 0;
if (tb[RTA_OIF]) if (tb[RTA_OIF])
oif = *(int*)RTA_DATA(tb[RTA_OIF]); oif = *(int *)RTA_DATA(tb[RTA_OIF]);
if ((oif^filter.oif)&filter.oifmask) if ((oif^filter.oif)&filter.oifmask)
return 0; return 0;
} }
if (filter.markmask) { if (filter.markmask) {
int mark = 0; int mark = 0;
if (tb[RTA_MARK]) if (tb[RTA_MARK])
mark = *(int *)RTA_DATA(tb[RTA_MARK]); mark = *(int *)RTA_DATA(tb[RTA_MARK]);
if ((mark ^ filter.mark) & filter.markmask) if ((mark ^ filter.mark) & filter.markmask)
...@@ -286,7 +293,7 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len) ...@@ -286,7 +293,7 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
r->rtm_dst_len == 0 && r->rtm_dst_len == 0 &&
r->rtm_type == RTN_UNREACHABLE && r->rtm_type == RTN_UNREACHABLE &&
tb[RTA_PRIORITY] && tb[RTA_PRIORITY] &&
*(int*)RTA_DATA(tb[RTA_PRIORITY]) == -1) *(int *)RTA_DATA(tb[RTA_PRIORITY]) == -1)
return 0; return 0;
return 1; return 1;
...@@ -307,13 +314,14 @@ static void print_rtax_features(FILE *fp, unsigned int features) ...@@ -307,13 +314,14 @@ static void print_rtax_features(FILE *fp, unsigned int features)
int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
{ {
FILE *fp = (FILE*)arg; FILE *fp = (FILE *)arg;
struct rtmsg *r = NLMSG_DATA(n); struct rtmsg *r = NLMSG_DATA(n);
int len = n->nlmsg_len; int len = n->nlmsg_len;
struct rtattr * tb[RTA_MAX+1]; struct rtattr *tb[RTA_MAX+1];
char abuf[256]; char abuf[256];
int host_len; int host_len;
__u32 table; __u32 table;
SPRINT_BUF(b1); SPRINT_BUF(b1);
static int hz; static int hz;
...@@ -340,16 +348,17 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -340,16 +348,17 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (filter.flushb) { if (filter.flushb) {
struct nlmsghdr *fn; struct nlmsghdr *fn;
if (NLMSG_ALIGN(filter.flushp) + n->nlmsg_len > filter.flushe) { if (NLMSG_ALIGN(filter.flushp) + n->nlmsg_len > filter.flushe) {
if (flush_update()) if (flush_update())
return -1; return -1;
} }
fn = (struct nlmsghdr*)(filter.flushb + NLMSG_ALIGN(filter.flushp)); fn = (struct nlmsghdr *)(filter.flushb + NLMSG_ALIGN(filter.flushp));
memcpy(fn, n, n->nlmsg_len); memcpy(fn, n, n->nlmsg_len);
fn->nlmsg_type = RTM_DELROUTE; fn->nlmsg_type = RTM_DELROUTE;
fn->nlmsg_flags = NLM_F_REQUEST; fn->nlmsg_flags = NLM_F_REQUEST;
fn->nlmsg_seq = ++rth.seq; fn->nlmsg_seq = ++rth.seq;
filter.flushp = (((char*)fn) + n->nlmsg_len) - filter.flushb; filter.flushp = (((char *)fn) + n->nlmsg_len) - filter.flushb;
filter.flushed++; filter.flushed++;
if (show_stats < 2) if (show_stats < 2)
return 0; return 0;
...@@ -424,13 +433,14 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -424,13 +433,14 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[RTA_VIA]) { if (tb[RTA_VIA]) {
size_t len = RTA_PAYLOAD(tb[RTA_VIA]) - 2; size_t len = RTA_PAYLOAD(tb[RTA_VIA]) - 2;
struct rtvia *via = RTA_DATA(tb[RTA_VIA]); struct rtvia *via = RTA_DATA(tb[RTA_VIA]);
fprintf(fp, "via %s %s ", fprintf(fp, "via %s %s ",
family_name(via->rtvia_family), family_name(via->rtvia_family),
format_host(via->rtvia_family, len, via->rtvia_addr, format_host(via->rtvia_family, len, via->rtvia_addr,
abuf, sizeof(abuf))); abuf, sizeof(abuf)));
} }
if (tb[RTA_OIF] && filter.oifmask != -1) if (tb[RTA_OIF] && filter.oifmask != -1)
fprintf(fp, "dev %s ", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_OIF]))); fprintf(fp, "dev %s ", ll_index_to_name(*(int *)RTA_DATA(tb[RTA_OIF])));
if (table && (table != RT_TABLE_MAIN || show_details > 0) && !filter.tb) if (table && (table != RT_TABLE_MAIN || show_details > 0) && !filter.tb)
fprintf(fp, " table %s ", rtnl_rttable_n2a(table, b1, sizeof(b1))); fprintf(fp, " table %s ", rtnl_rttable_n2a(table, b1, sizeof(b1)));
...@@ -465,7 +475,8 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -465,7 +475,8 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (r->rtm_flags & RTNH_F_LINKDOWN) if (r->rtm_flags & RTNH_F_LINKDOWN)
fprintf(fp, "linkdown "); fprintf(fp, "linkdown ");
if (tb[RTA_MARK]) { if (tb[RTA_MARK]) {
unsigned int mark = *(unsigned int*)RTA_DATA(tb[RTA_MARK]); unsigned int mark = *(unsigned int *)RTA_DATA(tb[RTA_MARK]);
if (mark) { if (mark) {
if (mark >= 16) if (mark >= 16)
fprintf(fp, " mark 0x%x", mark); fprintf(fp, " mark 0x%x", mark);
...@@ -477,6 +488,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -477,6 +488,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[RTA_FLOW] && filter.realmmask != ~0U) { if (tb[RTA_FLOW] && filter.realmmask != ~0U) {
__u32 to = rta_getattr_u32(tb[RTA_FLOW]); __u32 to = rta_getattr_u32(tb[RTA_FLOW]);
__u32 from = to>>16; __u32 from = to>>16;
to &= 0xFFFF; to &= 0xFFFF;
fprintf(fp, "realm%s ", from ? "s" : ""); fprintf(fp, "realm%s ", from ? "s" : "");
if (from) { if (from) {
...@@ -492,7 +504,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -492,7 +504,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, "%s cache ", _SL_); fprintf(fp, "%s cache ", _SL_);
#define PRTFL(fl,flname) if (flags&RTCF_##fl) { \ #define PRTFL(fl, flname) if (flags&RTCF_##fl) { \
flags &= ~RTCF_##fl; \ flags &= ~RTCF_##fl; \
fprintf(fp, "%s" flname "%s", first ? "<" : "", flags ? "," : "> "); \ fprintf(fp, "%s" flname "%s", first ? "<" : "", flags ? "," : "> "); \
first = 0; } first = 0; }
...@@ -515,6 +527,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -515,6 +527,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, "%s%x> ", first ? "<" : "", flags); fprintf(fp, "%s%x> ", first ? "<" : "", flags);
if (tb[RTA_CACHEINFO]) { if (tb[RTA_CACHEINFO]) {
struct rta_cacheinfo *ci = RTA_DATA(tb[RTA_CACHEINFO]); struct rta_cacheinfo *ci = RTA_DATA(tb[RTA_CACHEINFO]);
if (!hz) if (!hz)
hz = get_user_hz(); hz = get_user_hz();
if (ci->rta_expires != 0) if (ci->rta_expires != 0)
...@@ -537,6 +550,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -537,6 +550,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
} }
} else if (r->rtm_family == AF_INET6) { } else if (r->rtm_family == AF_INET6) {
struct rta_cacheinfo *ci = NULL; struct rta_cacheinfo *ci = NULL;
if (tb[RTA_CACHEINFO]) if (tb[RTA_CACHEINFO])
ci = RTA_DATA(tb[RTA_CACHEINFO]); ci = RTA_DATA(tb[RTA_CACHEINFO]);
if ((r->rtm_flags & RTM_F_CLONED) || (ci && ci->rta_expires)) { if ((r->rtm_flags & RTM_F_CLONED) || (ci && ci->rta_expires)) {
...@@ -563,15 +577,15 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -563,15 +577,15 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
} }
if (tb[RTA_METRICS]) { if (tb[RTA_METRICS]) {
int i; int i;
unsigned mxlock = 0; unsigned int mxlock = 0;
struct rtattr *mxrta[RTAX_MAX+1]; struct rtattr *mxrta[RTAX_MAX+1];
parse_rtattr(mxrta, RTAX_MAX, RTA_DATA(tb[RTA_METRICS]), parse_rtattr(mxrta, RTAX_MAX, RTA_DATA(tb[RTA_METRICS]),
RTA_PAYLOAD(tb[RTA_METRICS])); RTA_PAYLOAD(tb[RTA_METRICS]));
if (mxrta[RTAX_LOCK]) if (mxrta[RTAX_LOCK])
mxlock = *(unsigned*)RTA_DATA(mxrta[RTAX_LOCK]); mxlock = *(unsigned *)RTA_DATA(mxrta[RTAX_LOCK]);
for (i=2; i<= RTAX_MAX; i++) { for (i = 2; i <= RTAX_MAX; i++) {
__u32 val = 0U; __u32 val = 0U;
if (mxrta[i] == NULL) if (mxrta[i] == NULL)
...@@ -583,7 +597,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -583,7 +597,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (i == RTAX_HOPLIMIT && (int)val == -1) if (i == RTAX_HOPLIMIT && (int)val == -1)
continue; continue;
if (i < sizeof(mx_names)/sizeof(char*) && mx_names[i]) if (i < sizeof(mx_names)/sizeof(char *) && mx_names[i])
fprintf(fp, " %s", mx_names[i]); fprintf(fp, " %s", mx_names[i]);
else else
fprintf(fp, " metric %d", i); fprintf(fp, " metric %d", i);
...@@ -619,7 +633,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -619,7 +633,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
} }
} }
if (tb[RTA_IIF] && filter.iifmask != -1) { if (tb[RTA_IIF] && filter.iifmask != -1) {
fprintf(fp, " iif %s", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_IIF]))); fprintf(fp, " iif %s", ll_index_to_name(*(int *)RTA_DATA(tb[RTA_IIF])));
} }
if (tb[RTA_MULTIPATH]) { if (tb[RTA_MULTIPATH]) {
struct rtnexthop *nh = RTA_DATA(tb[RTA_MULTIPATH]); struct rtnexthop *nh = RTA_DATA(tb[RTA_MULTIPATH]);
...@@ -663,6 +677,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -663,6 +677,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[RTA_VIA]) { if (tb[RTA_VIA]) {
size_t len = RTA_PAYLOAD(tb[RTA_VIA]) - 2; size_t len = RTA_PAYLOAD(tb[RTA_VIA]) - 2;
struct rtvia *via = RTA_DATA(tb[RTA_VIA]); struct rtvia *via = RTA_DATA(tb[RTA_VIA]);
fprintf(fp, "via %s %s ", fprintf(fp, "via %s %s ",
family_name(via->rtvia_family), family_name(via->rtvia_family),
format_host(via->rtvia_family, len, via->rtvia_addr, format_host(via->rtvia_family, len, via->rtvia_addr,
...@@ -671,6 +686,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -671,6 +686,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[RTA_FLOW]) { if (tb[RTA_FLOW]) {
__u32 to = rta_getattr_u32(tb[RTA_FLOW]); __u32 to = rta_getattr_u32(tb[RTA_FLOW]);
__u32 from = to>>16; __u32 from = to>>16;
to &= 0xFFFF; to &= 0xFFFF;
fprintf(fp, " realm%s ", from ? "s" : ""); fprintf(fp, " realm%s ", from ? "s" : "");
if (from) { if (from) {
...@@ -705,6 +721,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -705,6 +721,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
} }
if (tb[RTA_PREF]) { if (tb[RTA_PREF]) {
unsigned int pref = rta_getattr_u8(tb[RTA_PREF]); unsigned int pref = rta_getattr_u8(tb[RTA_PREF]);
fprintf(fp, " pref "); fprintf(fp, " pref ");
switch (pref) { switch (pref) {
...@@ -737,6 +754,7 @@ static int parse_one_nh(struct nlmsghdr *n, struct rtmsg *r, ...@@ -737,6 +754,7 @@ static int parse_one_nh(struct nlmsghdr *n, struct rtmsg *r,
if (strcmp(*argv, "via") == 0) { if (strcmp(*argv, "via") == 0) {
inet_prefix addr; inet_prefix addr;
int family; int family;
NEXT_ARG(); NEXT_ARG();
family = read_family(*argv); family = read_family(*argv);
if (family == AF_UNSPEC) if (family == AF_UNSPEC)
...@@ -760,7 +778,8 @@ static int parse_one_nh(struct nlmsghdr *n, struct rtmsg *r, ...@@ -760,7 +778,8 @@ static int parse_one_nh(struct nlmsghdr *n, struct rtmsg *r,
exit(1); exit(1);
} }
} else if (strcmp(*argv, "weight") == 0) { } else if (strcmp(*argv, "weight") == 0) {
unsigned w; unsigned int w;
NEXT_ARG(); NEXT_ARG();
if (get_unsigned(&w, *argv, 0) || w == 0 || w > 256) if (get_unsigned(&w, *argv, 0) || w == 0 || w > 256)
invarg("\"weight\" is invalid\n", *argv); invarg("\"weight\" is invalid\n", *argv);
...@@ -769,6 +788,7 @@ static int parse_one_nh(struct nlmsghdr *n, struct rtmsg *r, ...@@ -769,6 +788,7 @@ static int parse_one_nh(struct nlmsghdr *n, struct rtmsg *r,
rtnh->rtnh_flags |= RTNH_F_ONLINK; rtnh->rtnh_flags |= RTNH_F_ONLINK;
} else if (matches(*argv, "realms") == 0) { } else if (matches(*argv, "realms") == 0) {
__u32 realm; __u32 realm;
NEXT_ARG(); NEXT_ARG();
if (get_rt_realms_or_raw(&realm, *argv)) if (get_rt_realms_or_raw(&realm, *argv))
invarg("\"realm\" value is invalid\n", *argv); invarg("\"realm\" value is invalid\n", *argv);
...@@ -801,7 +821,7 @@ static int parse_nexthops(struct nlmsghdr *n, struct rtmsg *r, ...@@ -801,7 +821,7 @@ static int parse_nexthops(struct nlmsghdr *n, struct rtmsg *r,
int argc, char **argv) int argc, char **argv)
{ {
char buf[1024]; char buf[1024];
struct rtattr *rta = (void*)buf; struct rtattr *rta = (void *)buf;
struct rtnexthop *rtnh; struct rtnexthop *rtnh;
rta->rta_type = RTA_MULTIPATH; rta->rta_type = RTA_MULTIPATH;
...@@ -829,16 +849,16 @@ static int parse_nexthops(struct nlmsghdr *n, struct rtmsg *r, ...@@ -829,16 +849,16 @@ static int parse_nexthops(struct nlmsghdr *n, struct rtmsg *r,
return 0; return 0;
} }
static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) static int iproute_modify(int cmd, unsigned int flags, int argc, char **argv)
{ {
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
struct rtmsg r; struct rtmsg r;
char buf[1024]; char buf[1024];
} req; } req;
char mxbuf[256]; char mxbuf[256];
struct rtattr * mxrta = (void*)mxbuf; struct rtattr *mxrta = (void *)mxbuf;
unsigned mxlock = 0; unsigned int mxlock = 0;
char *d = NULL; char *d = NULL;
int gw_ok = 0; int gw_ok = 0;
int dst_ok = 0; int dst_ok = 0;
...@@ -870,6 +890,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -870,6 +890,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "src") == 0) { if (strcmp(*argv, "src") == 0) {
inet_prefix addr; inet_prefix addr;
NEXT_ARG(); NEXT_ARG();
get_addr(&addr, *argv, req.r.rtm_family); get_addr(&addr, *argv, req.r.rtm_family);
if (req.r.rtm_family == AF_UNSPEC) if (req.r.rtm_family == AF_UNSPEC)
...@@ -877,6 +898,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -877,6 +898,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
addattr_l(&req.n, sizeof(req), RTA_PREFSRC, &addr.data, addr.bytelen); addattr_l(&req.n, sizeof(req), RTA_PREFSRC, &addr.data, addr.bytelen);
} else if (strcmp(*argv, "as") == 0) { } else if (strcmp(*argv, "as") == 0) {
inet_prefix addr; inet_prefix addr;
NEXT_ARG(); NEXT_ARG();
if (strcmp(*argv, "to") == 0) { if (strcmp(*argv, "to") == 0) {
NEXT_ARG(); NEXT_ARG();
...@@ -888,6 +910,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -888,6 +910,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
} else if (strcmp(*argv, "via") == 0) { } else if (strcmp(*argv, "via") == 0) {
inet_prefix addr; inet_prefix addr;
int family; int family;
gw_ok = 1; gw_ok = 1;
NEXT_ARG(); NEXT_ARG();
family = read_family(*argv); family = read_family(*argv);
...@@ -906,6 +929,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -906,6 +929,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
&addr.family, addr.bytelen+2); &addr.family, addr.bytelen+2);
} else if (strcmp(*argv, "from") == 0) { } else if (strcmp(*argv, "from") == 0) {
inet_prefix addr; inet_prefix addr;
NEXT_ARG(); NEXT_ARG();
get_prefix(&addr, *argv, req.r.rtm_family); get_prefix(&addr, *argv, req.r.rtm_family);
if (req.r.rtm_family == AF_UNSPEC) if (req.r.rtm_family == AF_UNSPEC)
...@@ -916,12 +940,14 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -916,12 +940,14 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
} else if (strcmp(*argv, "tos") == 0 || } else if (strcmp(*argv, "tos") == 0 ||
matches(*argv, "dsfield") == 0) { matches(*argv, "dsfield") == 0) {
__u32 tos; __u32 tos;
NEXT_ARG(); NEXT_ARG();
if (rtnl_dsfield_a2n(&tos, *argv)) if (rtnl_dsfield_a2n(&tos, *argv))
invarg("\"tos\" value is invalid\n", *argv); invarg("\"tos\" value is invalid\n", *argv);
req.r.rtm_tos = tos; req.r.rtm_tos = tos;
} else if (strcmp(*argv, "expires") == 0 ) { } else if (strcmp(*argv, "expires") == 0) {
__u32 expires; __u32 expires;
NEXT_ARG(); NEXT_ARG();
if (get_u32(&expires, *argv, 0)) if (get_u32(&expires, *argv, 0))
invarg("\"expires\" value is invalid\n", *argv); invarg("\"expires\" value is invalid\n", *argv);
...@@ -932,19 +958,22 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -932,19 +958,22 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
matches(*argv, "priority") == 0 || matches(*argv, "priority") == 0 ||
strcmp(*argv, "preference") == 0) { strcmp(*argv, "preference") == 0) {
__u32 metric; __u32 metric;
NEXT_ARG(); NEXT_ARG();
if (get_u32(&metric, *argv, 0)) if (get_u32(&metric, *argv, 0))
invarg("\"metric\" value is invalid\n", *argv); invarg("\"metric\" value is invalid\n", *argv);
addattr32(&req.n, sizeof(req), RTA_PRIORITY, metric); addattr32(&req.n, sizeof(req), RTA_PRIORITY, metric);
} else if (strcmp(*argv, "scope") == 0) { } else if (strcmp(*argv, "scope") == 0) {
__u32 scope = 0; __u32 scope = 0;
NEXT_ARG(); NEXT_ARG();
if (rtnl_rtscope_a2n(&scope, *argv)) if (rtnl_rtscope_a2n(&scope, *argv))
invarg("invalid \"scope\" value\n", *argv); invarg("invalid \"scope\" value\n", *argv);
req.r.rtm_scope = scope; req.r.rtm_scope = scope;
scope_ok = 1; scope_ok = 1;
} else if (strcmp(*argv, "mtu") == 0) { } else if (strcmp(*argv, "mtu") == 0) {
unsigned mtu; unsigned int mtu;
NEXT_ARG(); NEXT_ARG();
if (strcmp(*argv, "lock") == 0) { if (strcmp(*argv, "lock") == 0) {
mxlock |= (1<<RTAX_MTU); mxlock |= (1<<RTAX_MTU);
...@@ -954,7 +983,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -954,7 +983,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
invarg("\"mtu\" value is invalid\n", *argv); invarg("\"mtu\" value is invalid\n", *argv);
rta_addattr32(mxrta, sizeof(mxbuf), RTAX_MTU, mtu); rta_addattr32(mxrta, sizeof(mxbuf), RTAX_MTU, mtu);
} else if (strcmp(*argv, "hoplimit") == 0) { } else if (strcmp(*argv, "hoplimit") == 0) {
unsigned hoplimit; unsigned int hoplimit;
NEXT_ARG(); NEXT_ARG();
if (strcmp(*argv, "lock") == 0) { if (strcmp(*argv, "lock") == 0) {
mxlock |= (1<<RTAX_HOPLIMIT); mxlock |= (1<<RTAX_HOPLIMIT);
...@@ -964,7 +994,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -964,7 +994,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
invarg("\"hoplimit\" value is invalid\n", *argv); invarg("\"hoplimit\" value is invalid\n", *argv);
rta_addattr32(mxrta, sizeof(mxbuf), RTAX_HOPLIMIT, hoplimit); rta_addattr32(mxrta, sizeof(mxbuf), RTAX_HOPLIMIT, hoplimit);
} else if (strcmp(*argv, "advmss") == 0) { } else if (strcmp(*argv, "advmss") == 0) {
unsigned mss; unsigned int mss;
NEXT_ARG(); NEXT_ARG();
if (strcmp(*argv, "lock") == 0) { if (strcmp(*argv, "lock") == 0) {
mxlock |= (1<<RTAX_ADVMSS); mxlock |= (1<<RTAX_ADVMSS);
...@@ -974,7 +1005,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -974,7 +1005,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
invarg("\"mss\" value is invalid\n", *argv); invarg("\"mss\" value is invalid\n", *argv);
rta_addattr32(mxrta, sizeof(mxbuf), RTAX_ADVMSS, mss); rta_addattr32(mxrta, sizeof(mxbuf), RTAX_ADVMSS, mss);
} else if (matches(*argv, "reordering") == 0) { } else if (matches(*argv, "reordering") == 0) {
unsigned reord; unsigned int reord;
NEXT_ARG(); NEXT_ARG();
if (strcmp(*argv, "lock") == 0) { if (strcmp(*argv, "lock") == 0) {
mxlock |= (1<<RTAX_REORDERING); mxlock |= (1<<RTAX_REORDERING);
...@@ -984,7 +1016,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -984,7 +1016,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
invarg("\"reordering\" value is invalid\n", *argv); invarg("\"reordering\" value is invalid\n", *argv);
rta_addattr32(mxrta, sizeof(mxbuf), RTAX_REORDERING, reord); rta_addattr32(mxrta, sizeof(mxbuf), RTAX_REORDERING, reord);
} else if (strcmp(*argv, "rtt") == 0) { } else if (strcmp(*argv, "rtt") == 0) {
unsigned rtt; unsigned int rtt;
NEXT_ARG(); NEXT_ARG();
if (strcmp(*argv, "lock") == 0) { if (strcmp(*argv, "lock") == 0) {
mxlock |= (1<<RTAX_RTT); mxlock |= (1<<RTAX_RTT);
...@@ -995,7 +1028,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -995,7 +1028,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
rta_addattr32(mxrta, sizeof(mxbuf), RTAX_RTT, rta_addattr32(mxrta, sizeof(mxbuf), RTAX_RTT,
(raw) ? rtt : rtt * 8); (raw) ? rtt : rtt * 8);
} else if (strcmp(*argv, "rto_min") == 0) { } else if (strcmp(*argv, "rto_min") == 0) {
unsigned rto_min; unsigned int rto_min;
NEXT_ARG(); NEXT_ARG();
mxlock |= (1<<RTAX_RTO_MIN); mxlock |= (1<<RTAX_RTO_MIN);
if (get_time_rtt(&rto_min, *argv, &raw)) if (get_time_rtt(&rto_min, *argv, &raw))
...@@ -1004,7 +1038,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -1004,7 +1038,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
rta_addattr32(mxrta, sizeof(mxbuf), RTAX_RTO_MIN, rta_addattr32(mxrta, sizeof(mxbuf), RTAX_RTO_MIN,
rto_min); rto_min);
} else if (matches(*argv, "window") == 0) { } else if (matches(*argv, "window") == 0) {
unsigned win; unsigned int win;
NEXT_ARG(); NEXT_ARG();
if (strcmp(*argv, "lock") == 0) { if (strcmp(*argv, "lock") == 0) {
mxlock |= (1<<RTAX_WINDOW); mxlock |= (1<<RTAX_WINDOW);
...@@ -1014,7 +1049,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -1014,7 +1049,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
invarg("\"window\" value is invalid\n", *argv); invarg("\"window\" value is invalid\n", *argv);
rta_addattr32(mxrta, sizeof(mxbuf), RTAX_WINDOW, win); rta_addattr32(mxrta, sizeof(mxbuf), RTAX_WINDOW, win);
} else if (matches(*argv, "cwnd") == 0) { } else if (matches(*argv, "cwnd") == 0) {
unsigned win; unsigned int win;
NEXT_ARG(); NEXT_ARG();
if (strcmp(*argv, "lock") == 0) { if (strcmp(*argv, "lock") == 0) {
mxlock |= (1<<RTAX_CWND); mxlock |= (1<<RTAX_CWND);
...@@ -1024,7 +1060,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -1024,7 +1060,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
invarg("\"cwnd\" value is invalid\n", *argv); invarg("\"cwnd\" value is invalid\n", *argv);
rta_addattr32(mxrta, sizeof(mxbuf), RTAX_CWND, win); rta_addattr32(mxrta, sizeof(mxbuf), RTAX_CWND, win);
} else if (matches(*argv, "initcwnd") == 0) { } else if (matches(*argv, "initcwnd") == 0) {
unsigned win; unsigned int win;
NEXT_ARG(); NEXT_ARG();
if (strcmp(*argv, "lock") == 0) { if (strcmp(*argv, "lock") == 0) {
mxlock |= (1<<RTAX_INITCWND); mxlock |= (1<<RTAX_INITCWND);
...@@ -1034,7 +1071,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -1034,7 +1071,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
invarg("\"initcwnd\" value is invalid\n", *argv); invarg("\"initcwnd\" value is invalid\n", *argv);
rta_addattr32(mxrta, sizeof(mxbuf), RTAX_INITCWND, win); rta_addattr32(mxrta, sizeof(mxbuf), RTAX_INITCWND, win);
} else if (matches(*argv, "initrwnd") == 0) { } else if (matches(*argv, "initrwnd") == 0) {
unsigned win; unsigned int win;
NEXT_ARG(); NEXT_ARG();
if (strcmp(*argv, "lock") == 0) { if (strcmp(*argv, "lock") == 0) {
mxlock |= (1<<RTAX_INITRWND); mxlock |= (1<<RTAX_INITRWND);
...@@ -1058,7 +1096,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -1058,7 +1096,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
rta_addattr32(mxrta, sizeof(mxbuf), RTAX_FEATURES, features); rta_addattr32(mxrta, sizeof(mxbuf), RTAX_FEATURES, features);
} else if (matches(*argv, "quickack") == 0) { } else if (matches(*argv, "quickack") == 0) {
unsigned quickack; unsigned int quickack;
NEXT_ARG(); NEXT_ARG();
if (get_unsigned(&quickack, *argv, 0)) if (get_unsigned(&quickack, *argv, 0))
invarg("\"quickack\" value is invalid\n", *argv); invarg("\"quickack\" value is invalid\n", *argv);
...@@ -1074,7 +1113,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -1074,7 +1113,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
rta_addattr_l(mxrta, sizeof(mxbuf), RTAX_CC_ALGO, *argv, rta_addattr_l(mxrta, sizeof(mxbuf), RTAX_CC_ALGO, *argv,
strlen(*argv)); strlen(*argv));
} else if (matches(*argv, "rttvar") == 0) { } else if (matches(*argv, "rttvar") == 0) {
unsigned win; unsigned int win;
NEXT_ARG(); NEXT_ARG();
if (strcmp(*argv, "lock") == 0) { if (strcmp(*argv, "lock") == 0) {
mxlock |= (1<<RTAX_RTTVAR); mxlock |= (1<<RTAX_RTTVAR);
...@@ -1085,7 +1125,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -1085,7 +1125,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
rta_addattr32(mxrta, sizeof(mxbuf), RTAX_RTTVAR, rta_addattr32(mxrta, sizeof(mxbuf), RTAX_RTTVAR,
(raw) ? win : win * 4); (raw) ? win : win * 4);
} else if (matches(*argv, "ssthresh") == 0) { } else if (matches(*argv, "ssthresh") == 0) {
unsigned win; unsigned int win;
NEXT_ARG(); NEXT_ARG();
if (strcmp(*argv, "lock") == 0) { if (strcmp(*argv, "lock") == 0) {
mxlock |= (1<<RTAX_SSTHRESH); mxlock |= (1<<RTAX_SSTHRESH);
...@@ -1096,6 +1137,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -1096,6 +1137,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
rta_addattr32(mxrta, sizeof(mxbuf), RTAX_SSTHRESH, win); rta_addattr32(mxrta, sizeof(mxbuf), RTAX_SSTHRESH, win);
} else if (matches(*argv, "realms") == 0) { } else if (matches(*argv, "realms") == 0) {
__u32 realm; __u32 realm;
NEXT_ARG(); NEXT_ARG();
if (get_rt_realms_or_raw(&realm, *argv)) if (get_rt_realms_or_raw(&realm, *argv))
invarg("\"realm\" value is invalid\n", *argv); invarg("\"realm\" value is invalid\n", *argv);
...@@ -1107,12 +1149,14 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -1107,12 +1149,14 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
break; break;
} else if (matches(*argv, "protocol") == 0) { } else if (matches(*argv, "protocol") == 0) {
__u32 prot; __u32 prot;
NEXT_ARG(); NEXT_ARG();
if (rtnl_rtprot_a2n(&prot, *argv)) if (rtnl_rtprot_a2n(&prot, *argv))
invarg("\"protocol\" value is invalid\n", *argv); invarg("\"protocol\" value is invalid\n", *argv);
req.r.rtm_protocol = prot; req.r.rtm_protocol = prot;
} else if (matches(*argv, "table") == 0) { } else if (matches(*argv, "table") == 0) {
__u32 tid; __u32 tid;
NEXT_ARG(); NEXT_ARG();
if (rtnl_rttable_a2n(&tid, *argv)) if (rtnl_rttable_a2n(&tid, *argv))
invarg("\"table\" value is invalid\n", *argv); invarg("\"table\" value is invalid\n", *argv);
...@@ -1129,6 +1173,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -1129,6 +1173,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
d = *argv; d = *argv;
} else if (matches(*argv, "pref") == 0) { } else if (matches(*argv, "pref") == 0) {
__u8 pref; __u8 pref;
NEXT_ARG(); NEXT_ARG();
if (strcmp(*argv, "low") == 0) if (strcmp(*argv, "low") == 0)
pref = ICMPV6_ROUTER_PREF_LOW; pref = ICMPV6_ROUTER_PREF_LOW;
...@@ -1141,7 +1186,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -1141,7 +1186,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
addattr8(&req.n, sizeof(req), RTA_PREF, pref); addattr8(&req.n, sizeof(req), RTA_PREF, pref);
} else if (strcmp(*argv, "encap") == 0) { } else if (strcmp(*argv, "encap") == 0) {
char buf[1024]; char buf[1024];
struct rtattr *rta = (void*)buf; struct rtattr *rta = (void *)buf;
rta->rta_type = RTA_ENCAP; rta->rta_type = RTA_ENCAP;
rta->rta_len = RTA_LENGTH(0); rta->rta_len = RTA_LENGTH(0);
...@@ -1262,7 +1307,7 @@ static int rtnl_rtcache_request(struct rtnl_handle *rth, int family) ...@@ -1262,7 +1307,7 @@ static int rtnl_rtcache_request(struct rtnl_handle *rth, int family)
req.rtm.rtm_family = family; req.rtm.rtm_family = family;
req.rtm.rtm_flags |= RTM_F_CLONED; req.rtm.rtm_flags |= RTM_F_CLONED;
return sendto(rth->fd, (void*)&req, sizeof(req), 0, (struct sockaddr*)&nladdr, sizeof(nladdr)); return sendto(rth->fd, (void *)&req, sizeof(req), 0, (struct sockaddr *)&nladdr, sizeof(nladdr));
} }
static int iproute_flush_cache(void) static int iproute_flush_cache(void)
...@@ -1270,19 +1315,19 @@ static int iproute_flush_cache(void) ...@@ -1270,19 +1315,19 @@ static int iproute_flush_cache(void)
#define ROUTE_FLUSH_PATH "/proc/sys/net/ipv4/route/flush" #define ROUTE_FLUSH_PATH "/proc/sys/net/ipv4/route/flush"
int len; int len;
int flush_fd = open (ROUTE_FLUSH_PATH, O_WRONLY); int flush_fd = open(ROUTE_FLUSH_PATH, O_WRONLY);
char *buffer = "-1"; char *buffer = "-1";
if (flush_fd < 0) { if (flush_fd < 0) {
fprintf (stderr, "Cannot open \"%s\": %s\n", fprintf(stderr, "Cannot open \"%s\": %s\n",
ROUTE_FLUSH_PATH, strerror(errno)); ROUTE_FLUSH_PATH, strerror(errno));
return -1; return -1;
} }
len = strlen (buffer); len = strlen(buffer);
if ((write (flush_fd, (void *)buffer, len)) < len) { if ((write(flush_fd, (void *)buffer, len)) < len) {
fprintf (stderr, "Cannot flush routing cache\n"); fprintf(stderr, "Cannot flush routing cache\n");
close(flush_fd); close(flush_fd);
return -1; return -1;
} }
...@@ -1362,6 +1407,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action) ...@@ -1362,6 +1407,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
while (argc > 0) { while (argc > 0) {
if (matches(*argv, "table") == 0) { if (matches(*argv, "table") == 0) {
__u32 tid; __u32 tid;
NEXT_ARG(); NEXT_ARG();
if (rtnl_rttable_a2n(&tid, *argv)) { if (rtnl_rttable_a2n(&tid, *argv)) {
if (strcmp(*argv, "all") == 0) { if (strcmp(*argv, "all") == 0) {
...@@ -1381,6 +1427,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action) ...@@ -1381,6 +1427,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
} else if (strcmp(*argv, "tos") == 0 || } else if (strcmp(*argv, "tos") == 0 ||
matches(*argv, "dsfield") == 0) { matches(*argv, "dsfield") == 0) {
__u32 tos; __u32 tos;
NEXT_ARG(); NEXT_ARG();
if (rtnl_dsfield_a2n(&tos, *argv)) if (rtnl_dsfield_a2n(&tos, *argv))
invarg("TOS value is invalid\n", *argv); invarg("TOS value is invalid\n", *argv);
...@@ -1388,6 +1435,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action) ...@@ -1388,6 +1435,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
filter.tosmask = -1; filter.tosmask = -1;
} else if (matches(*argv, "protocol") == 0) { } else if (matches(*argv, "protocol") == 0) {
__u32 prot = 0; __u32 prot = 0;
NEXT_ARG(); NEXT_ARG();
filter.protocolmask = -1; filter.protocolmask = -1;
if (rtnl_rtprot_a2n(&prot, *argv)) { if (rtnl_rtprot_a2n(&prot, *argv)) {
...@@ -1399,6 +1447,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action) ...@@ -1399,6 +1447,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
filter.protocol = prot; filter.protocol = prot;
} else if (matches(*argv, "scope") == 0) { } else if (matches(*argv, "scope") == 0) {
__u32 scope = 0; __u32 scope = 0;
NEXT_ARG(); NEXT_ARG();
filter.scopemask = -1; filter.scopemask = -1;
if (rtnl_rtscope_a2n(&scope, *argv)) { if (rtnl_rtscope_a2n(&scope, *argv)) {
...@@ -1410,6 +1459,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action) ...@@ -1410,6 +1459,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
filter.scope = scope; filter.scope = scope;
} else if (matches(*argv, "type") == 0) { } else if (matches(*argv, "type") == 0) {
int type; int type;
NEXT_ARG(); NEXT_ARG();
filter.typemask = -1; filter.typemask = -1;
if (rtnl_rtntype_a2n(&type, *argv)) if (rtnl_rtntype_a2n(&type, *argv))
...@@ -1428,6 +1478,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action) ...@@ -1428,6 +1478,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
filter.markmask = -1; filter.markmask = -1;
} else if (strcmp(*argv, "via") == 0) { } else if (strcmp(*argv, "via") == 0) {
int family; int family;
NEXT_ARG(); NEXT_ARG();
family = read_family(*argv); family = read_family(*argv);
if (family == AF_UNSPEC) if (family == AF_UNSPEC)
...@@ -1440,6 +1491,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action) ...@@ -1440,6 +1491,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
get_prefix(&filter.rprefsrc, *argv, do_ipv6); get_prefix(&filter.rprefsrc, *argv, do_ipv6);
} else if (matches(*argv, "realms") == 0) { } else if (matches(*argv, "realms") == 0) {
__u32 realm; __u32 realm;
NEXT_ARG(); NEXT_ARG();
if (get_rt_realms_or_raw(&realm, *argv)) if (get_rt_realms_or_raw(&realm, *argv))
invarg("invalid realms\n", *argv); invarg("invalid realms\n", *argv);
...@@ -1547,7 +1599,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action) ...@@ -1547,7 +1599,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
if (round == 0 && (!filter.cloned || do_ipv6 == AF_INET6)) if (round == 0 && (!filter.cloned || do_ipv6 == AF_INET6))
printf("Nothing to flush.\n"); printf("Nothing to flush.\n");
else else
printf("*** Flush is complete after %d round%s ***\n", round, round>1?"s":""); printf("*** Flush is complete after %d round%s ***\n", round, round > 1?"s":"");
} }
fflush(stdout); fflush(stdout);
return 0; return 0;
...@@ -1595,7 +1647,7 @@ static int iproute_get(int argc, char **argv) ...@@ -1595,7 +1647,7 @@ static int iproute_get(int argc, char **argv)
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
struct rtmsg r; struct rtmsg r;
char buf[1024]; char buf[1024];
} req; } req;
char *idev = NULL; char *idev = NULL;
char *odev = NULL; char *odev = NULL;
...@@ -1624,12 +1676,14 @@ static int iproute_get(int argc, char **argv) ...@@ -1624,12 +1676,14 @@ static int iproute_get(int argc, char **argv)
if (strcmp(*argv, "tos") == 0 || if (strcmp(*argv, "tos") == 0 ||
matches(*argv, "dsfield") == 0) { matches(*argv, "dsfield") == 0) {
__u32 tos; __u32 tos;
NEXT_ARG(); NEXT_ARG();
if (rtnl_dsfield_a2n(&tos, *argv)) if (rtnl_dsfield_a2n(&tos, *argv))
invarg("TOS value is invalid\n", *argv); invarg("TOS value is invalid\n", *argv);
req.r.rtm_tos = tos; req.r.rtm_tos = tos;
} else if (matches(*argv, "from") == 0) { } else if (matches(*argv, "from") == 0) {
inet_prefix addr; inet_prefix addr;
NEXT_ARG(); NEXT_ARG();
if (matches(*argv, "help") == 0) if (matches(*argv, "help") == 0)
usage(); usage();
...@@ -1656,6 +1710,7 @@ static int iproute_get(int argc, char **argv) ...@@ -1656,6 +1710,7 @@ static int iproute_get(int argc, char **argv)
connected = 1; connected = 1;
} else { } else {
inet_prefix addr; inet_prefix addr;
if (strcmp(*argv, "to") == 0) { if (strcmp(*argv, "to") == 0) {
NEXT_ARG(); NEXT_ARG();
} }
...@@ -1708,9 +1763,9 @@ static int iproute_get(int argc, char **argv) ...@@ -1708,9 +1763,9 @@ static int iproute_get(int argc, char **argv)
if (connected && !from_ok) { if (connected && !from_ok) {
struct rtmsg *r = NLMSG_DATA(&req.n); struct rtmsg *r = NLMSG_DATA(&req.n);
int len = req.n.nlmsg_len; int len = req.n.nlmsg_len;
struct rtattr * tb[RTA_MAX+1]; struct rtattr *tb[RTA_MAX+1];
if (print_route(NULL, &req.n, (void*)stdout) < 0) { if (print_route(NULL, &req.n, (void *)stdout) < 0) {
fprintf(stderr, "An error :-)\n"); fprintf(stderr, "An error :-)\n");
exit(1); exit(1);
} }
...@@ -1749,7 +1804,7 @@ static int iproute_get(int argc, char **argv) ...@@ -1749,7 +1804,7 @@ static int iproute_get(int argc, char **argv)
return -2; return -2;
} }
if (print_route(NULL, &req.n, (void*)stdout) < 0) { if (print_route(NULL, &req.n, (void *)stdout) < 0) {
fprintf(stderr, "An error :-)\n"); fprintf(stderr, "An error :-)\n");
return -1; return -1;
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* 2 of the License, or (at your option) any later version. * 2 of the License, or (at your option) any later version.
* *
* Authors: Roopa Prabhu, <roopa@cumulusnetworks.com> * Authors: Roopa Prabhu, <roopa@cumulusnetworks.com>
* Thomas Graf <tgraf@suug.ch> * Thomas Graf <tgraf@suug.ch>
* *
*/ */
...@@ -203,6 +203,7 @@ static int parse_encap_ip(struct rtattr *rta, size_t len, int *argcp, char ***ar ...@@ -203,6 +203,7 @@ static int parse_encap_ip(struct rtattr *rta, size_t len, int *argcp, char ***ar
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "id") == 0) { if (strcmp(*argv, "id") == 0) {
__u64 id; __u64 id;
NEXT_ARG(); NEXT_ARG();
if (id_ok++) if (id_ok++)
duparg2("id", *argv); duparg2("id", *argv);
...@@ -211,6 +212,7 @@ static int parse_encap_ip(struct rtattr *rta, size_t len, int *argcp, char ***ar ...@@ -211,6 +212,7 @@ static int parse_encap_ip(struct rtattr *rta, size_t len, int *argcp, char ***ar
rta_addattr64(rta, len, LWTUNNEL_IP_ID, htonll(id)); rta_addattr64(rta, len, LWTUNNEL_IP_ID, htonll(id));
} else if (strcmp(*argv, "dst") == 0) { } else if (strcmp(*argv, "dst") == 0) {
inet_prefix addr; inet_prefix addr;
NEXT_ARG(); NEXT_ARG();
if (dst_ok++) if (dst_ok++)
duparg2("dst", *argv); duparg2("dst", *argv);
...@@ -218,6 +220,7 @@ static int parse_encap_ip(struct rtattr *rta, size_t len, int *argcp, char ***ar ...@@ -218,6 +220,7 @@ static int parse_encap_ip(struct rtattr *rta, size_t len, int *argcp, char ***ar
rta_addattr_l(rta, len, LWTUNNEL_IP_DST, &addr.data, addr.bytelen); rta_addattr_l(rta, len, LWTUNNEL_IP_DST, &addr.data, addr.bytelen);
} else if (strcmp(*argv, "tos") == 0) { } else if (strcmp(*argv, "tos") == 0) {
__u32 tos; __u32 tos;
NEXT_ARG(); NEXT_ARG();
if (tos_ok++) if (tos_ok++)
duparg2("tos", *argv); duparg2("tos", *argv);
...@@ -226,6 +229,7 @@ static int parse_encap_ip(struct rtattr *rta, size_t len, int *argcp, char ***ar ...@@ -226,6 +229,7 @@ static int parse_encap_ip(struct rtattr *rta, size_t len, int *argcp, char ***ar
rta_addattr8(rta, len, LWTUNNEL_IP_TOS, tos); rta_addattr8(rta, len, LWTUNNEL_IP_TOS, tos);
} else if (strcmp(*argv, "ttl") == 0) { } else if (strcmp(*argv, "ttl") == 0) {
__u8 ttl; __u8 ttl;
NEXT_ARG(); NEXT_ARG();
if (ttl_ok++) if (ttl_ok++)
duparg2("ttl", *argv); duparg2("ttl", *argv);
...@@ -276,6 +280,7 @@ static int parse_encap_ip6(struct rtattr *rta, size_t len, int *argcp, char ***a ...@@ -276,6 +280,7 @@ static int parse_encap_ip6(struct rtattr *rta, size_t len, int *argcp, char ***a
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "id") == 0) { if (strcmp(*argv, "id") == 0) {
__u64 id; __u64 id;
NEXT_ARG(); NEXT_ARG();
if (id_ok++) if (id_ok++)
duparg2("id", *argv); duparg2("id", *argv);
...@@ -284,6 +289,7 @@ static int parse_encap_ip6(struct rtattr *rta, size_t len, int *argcp, char ***a ...@@ -284,6 +289,7 @@ static int parse_encap_ip6(struct rtattr *rta, size_t len, int *argcp, char ***a
rta_addattr64(rta, len, LWTUNNEL_IP6_ID, htonll(id)); rta_addattr64(rta, len, LWTUNNEL_IP6_ID, htonll(id));
} else if (strcmp(*argv, "dst") == 0) { } else if (strcmp(*argv, "dst") == 0) {
inet_prefix addr; inet_prefix addr;
NEXT_ARG(); NEXT_ARG();
if (dst_ok++) if (dst_ok++)
duparg2("dst", *argv); duparg2("dst", *argv);
...@@ -291,6 +297,7 @@ static int parse_encap_ip6(struct rtattr *rta, size_t len, int *argcp, char ***a ...@@ -291,6 +297,7 @@ static int parse_encap_ip6(struct rtattr *rta, size_t len, int *argcp, char ***a
rta_addattr_l(rta, len, LWTUNNEL_IP6_DST, &addr.data, addr.bytelen); rta_addattr_l(rta, len, LWTUNNEL_IP6_DST, &addr.data, addr.bytelen);
} else if (strcmp(*argv, "tc") == 0) { } else if (strcmp(*argv, "tc") == 0) {
__u32 tc; __u32 tc;
NEXT_ARG(); NEXT_ARG();
if (tos_ok++) if (tos_ok++)
duparg2("tc", *argv); duparg2("tc", *argv);
...@@ -299,6 +306,7 @@ static int parse_encap_ip6(struct rtattr *rta, size_t len, int *argcp, char ***a ...@@ -299,6 +306,7 @@ static int parse_encap_ip6(struct rtattr *rta, size_t len, int *argcp, char ***a
rta_addattr8(rta, len, LWTUNNEL_IP6_TC, tc); rta_addattr8(rta, len, LWTUNNEL_IP6_TC, tc);
} else if (strcmp(*argv, "hoplimit") == 0) { } else if (strcmp(*argv, "hoplimit") == 0) {
__u8 hoplimit; __u8 hoplimit;
NEXT_ARG(); NEXT_ARG();
if (ttl_ok++) if (ttl_ok++)
duparg2("hoplimit", *argv); duparg2("hoplimit", *argv);
......
...@@ -51,13 +51,14 @@ static void usage(void) ...@@ -51,13 +51,14 @@ static void usage(void)
int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
{ {
FILE *fp = (FILE*)arg; FILE *fp = (FILE *)arg;
struct rtmsg *r = NLMSG_DATA(n); struct rtmsg *r = NLMSG_DATA(n);
int len = n->nlmsg_len; int len = n->nlmsg_len;
int host_len = -1; int host_len = -1;
__u32 table; __u32 table;
struct rtattr * tb[FRA_MAX+1]; struct rtattr *tb[FRA_MAX+1];
char abuf[256]; char abuf[256];
SPRINT_BUF(b1); SPRINT_BUF(b1);
if (n->nlmsg_type != RTM_NEWRULE && n->nlmsg_type != RTM_DELRULE) if (n->nlmsg_type != RTM_NEWRULE && n->nlmsg_type != RTM_DELRULE)
...@@ -75,7 +76,7 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -75,7 +76,7 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, "Deleted "); fprintf(fp, "Deleted ");
if (tb[FRA_PRIORITY]) if (tb[FRA_PRIORITY])
fprintf(fp, "%u:\t", *(unsigned*)RTA_DATA(tb[FRA_PRIORITY])); fprintf(fp, "%u:\t", *(unsigned *)RTA_DATA(tb[FRA_PRIORITY]));
else else
fprintf(fp, "0:\t"); fprintf(fp, "0:\t");
...@@ -157,12 +158,14 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -157,12 +158,14 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[FRA_SUPPRESS_PREFIXLEN]) { if (tb[FRA_SUPPRESS_PREFIXLEN]) {
int pl = rta_getattr_u32(tb[FRA_SUPPRESS_PREFIXLEN]); int pl = rta_getattr_u32(tb[FRA_SUPPRESS_PREFIXLEN]);
if (pl != -1) { if (pl != -1) {
fprintf(fp, "suppress_prefixlength %d ", pl); fprintf(fp, "suppress_prefixlength %d ", pl);
} }
} }
if (tb[FRA_SUPPRESS_IFGROUP]) { if (tb[FRA_SUPPRESS_IFGROUP]) {
int group = rta_getattr_u32(tb[FRA_SUPPRESS_IFGROUP]); int group = rta_getattr_u32(tb[FRA_SUPPRESS_IFGROUP]);
if (group != -1) { if (group != -1) {
SPRINT_BUF(b1); SPRINT_BUF(b1);
fprintf(fp, "suppress_ifgroup %s ", rtnl_group_n2a(group, b1, sizeof(b1))); fprintf(fp, "suppress_ifgroup %s ", rtnl_group_n2a(group, b1, sizeof(b1)));
...@@ -173,6 +176,7 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -173,6 +176,7 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[FRA_FLOW]) { if (tb[FRA_FLOW]) {
__u32 to = rta_getattr_u32(tb[FRA_FLOW]); __u32 to = rta_getattr_u32(tb[FRA_FLOW]);
__u32 from = to>>16; __u32 from = to>>16;
to &= 0xFFFF; to &= 0xFFFF;
if (from) { if (from) {
fprintf(fp, "realms %s/", fprintf(fp, "realms %s/",
...@@ -326,7 +330,7 @@ static int iprule_modify(int cmd, int argc, char **argv) ...@@ -326,7 +330,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
struct rtmsg r; struct rtmsg r;
char buf[1024]; char buf[1024];
} req; } req;
memset(&req, 0, sizeof(req)); memset(&req, 0, sizeof(req));
...@@ -351,12 +355,14 @@ static int iprule_modify(int cmd, int argc, char **argv) ...@@ -351,12 +355,14 @@ static int iprule_modify(int cmd, int argc, char **argv)
req.r.rtm_flags |= FIB_RULE_INVERT; req.r.rtm_flags |= FIB_RULE_INVERT;
} else if (strcmp(*argv, "from") == 0) { } else if (strcmp(*argv, "from") == 0) {
inet_prefix dst; inet_prefix dst;
NEXT_ARG(); NEXT_ARG();
get_prefix(&dst, *argv, req.r.rtm_family); get_prefix(&dst, *argv, req.r.rtm_family);
req.r.rtm_src_len = dst.bitlen; req.r.rtm_src_len = dst.bitlen;
addattr_l(&req.n, sizeof(req), FRA_SRC, &dst.data, dst.bytelen); addattr_l(&req.n, sizeof(req), FRA_SRC, &dst.data, dst.bytelen);
} else if (strcmp(*argv, "to") == 0) { } else if (strcmp(*argv, "to") == 0) {
inet_prefix dst; inet_prefix dst;
NEXT_ARG(); NEXT_ARG();
get_prefix(&dst, *argv, req.r.rtm_family); get_prefix(&dst, *argv, req.r.rtm_family);
req.r.rtm_dst_len = dst.bitlen; req.r.rtm_dst_len = dst.bitlen;
...@@ -365,6 +371,7 @@ static int iprule_modify(int cmd, int argc, char **argv) ...@@ -365,6 +371,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
matches(*argv, "order") == 0 || matches(*argv, "order") == 0 ||
matches(*argv, "priority") == 0) { matches(*argv, "priority") == 0) {
__u32 pref; __u32 pref;
NEXT_ARG(); NEXT_ARG();
if (get_u32(&pref, *argv, 0)) if (get_u32(&pref, *argv, 0))
invarg("preference value is invalid\n", *argv); invarg("preference value is invalid\n", *argv);
...@@ -372,6 +379,7 @@ static int iprule_modify(int cmd, int argc, char **argv) ...@@ -372,6 +379,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
} else if (strcmp(*argv, "tos") == 0 || } else if (strcmp(*argv, "tos") == 0 ||
matches(*argv, "dsfield") == 0) { matches(*argv, "dsfield") == 0) {
__u32 tos; __u32 tos;
NEXT_ARG(); NEXT_ARG();
if (rtnl_dsfield_a2n(&tos, *argv)) if (rtnl_dsfield_a2n(&tos, *argv))
invarg("TOS value is invalid\n", *argv); invarg("TOS value is invalid\n", *argv);
...@@ -379,6 +387,7 @@ static int iprule_modify(int cmd, int argc, char **argv) ...@@ -379,6 +387,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
} else if (strcmp(*argv, "fwmark") == 0) { } else if (strcmp(*argv, "fwmark") == 0) {
char *slash; char *slash;
__u32 fwmark, fwmask; __u32 fwmark, fwmask;
NEXT_ARG(); NEXT_ARG();
if ((slash = strchr(*argv, '/')) != NULL) if ((slash = strchr(*argv, '/')) != NULL)
*slash = '\0'; *slash = '\0';
...@@ -392,6 +401,7 @@ static int iprule_modify(int cmd, int argc, char **argv) ...@@ -392,6 +401,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
} }
} else if (matches(*argv, "realms") == 0) { } else if (matches(*argv, "realms") == 0) {
__u32 realm; __u32 realm;
NEXT_ARG(); NEXT_ARG();
if (get_rt_realms_or_raw(&realm, *argv)) if (get_rt_realms_or_raw(&realm, *argv))
invarg("invalid realms\n", *argv); invarg("invalid realms\n", *argv);
...@@ -399,6 +409,7 @@ static int iprule_modify(int cmd, int argc, char **argv) ...@@ -399,6 +409,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
} else if (matches(*argv, "table") == 0 || } else if (matches(*argv, "table") == 0 ||
strcmp(*argv, "lookup") == 0) { strcmp(*argv, "lookup") == 0) {
__u32 tid; __u32 tid;
NEXT_ARG(); NEXT_ARG();
if (rtnl_rttable_a2n(&tid, *argv)) if (rtnl_rttable_a2n(&tid, *argv))
invarg("invalid table ID\n", *argv); invarg("invalid table ID\n", *argv);
...@@ -412,6 +423,7 @@ static int iprule_modify(int cmd, int argc, char **argv) ...@@ -412,6 +423,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
} else if (matches(*argv, "suppress_prefixlength") == 0 || } else if (matches(*argv, "suppress_prefixlength") == 0 ||
strcmp(*argv, "sup_pl") == 0) { strcmp(*argv, "sup_pl") == 0) {
int pl; int pl;
NEXT_ARG(); NEXT_ARG();
if (get_s32(&pl, *argv, 0) || pl < 0) if (get_s32(&pl, *argv, 0) || pl < 0)
invarg("suppress_prefixlength value is invalid\n", *argv); invarg("suppress_prefixlength value is invalid\n", *argv);
...@@ -420,6 +432,7 @@ static int iprule_modify(int cmd, int argc, char **argv) ...@@ -420,6 +432,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
strcmp(*argv, "sup_group") == 0) { strcmp(*argv, "sup_group") == 0) {
NEXT_ARG(); NEXT_ARG();
int group; int group;
if (rtnl_group_a2n(&group, *argv)) if (rtnl_group_a2n(&group, *argv))
invarg("Invalid \"suppress_ifgroup\" value\n", *argv); invarg("Invalid \"suppress_ifgroup\" value\n", *argv);
addattr32(&req.n, sizeof(req), FRA_SUPPRESS_IFGROUP, group); addattr32(&req.n, sizeof(req), FRA_SUPPRESS_IFGROUP, group);
...@@ -446,6 +459,7 @@ static int iprule_modify(int cmd, int argc, char **argv) ...@@ -446,6 +459,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
usage(); usage();
else if (matches(*argv, "goto") == 0) { else if (matches(*argv, "goto") == 0) {
__u32 target; __u32 target;
type = FR_ACT_GOTO; type = FR_ACT_GOTO;
NEXT_ARG(); NEXT_ARG();
if (get_u32(&target, *argv, 0)) if (get_u32(&target, *argv, 0))
...@@ -480,7 +494,7 @@ static int flush_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *a ...@@ -480,7 +494,7 @@ static int flush_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *a
struct rtnl_handle rth2; struct rtnl_handle rth2;
struct rtmsg *r = NLMSG_DATA(n); struct rtmsg *r = NLMSG_DATA(n);
int len = n->nlmsg_len; int len = n->nlmsg_len;
struct rtattr * tb[FRA_MAX+1]; struct rtattr *tb[FRA_MAX+1];
len -= NLMSG_LENGTH(sizeof(*r)); len -= NLMSG_LENGTH(sizeof(*r));
if (len < 0) if (len < 0)
......
...@@ -168,13 +168,11 @@ static int iptoken_set(int argc, char **argv) ...@@ -168,13 +168,11 @@ static int iptoken_set(int argc, char **argv)
} }
if (!have_token) { if (!have_token) {
fprintf(stderr, "Not enough information: token " fprintf(stderr, "Not enough information: token is required.\n");
"is required.\n");
return -1; return -1;
} }
if (!have_dev) { if (!have_dev) {
fprintf(stderr, "Not enough information: \"dev\" " fprintf(stderr, "Not enough information: \"dev\" argument is required.\n");
"argument is required.\n");
return -1; return -1;
} }
......
...@@ -36,7 +36,7 @@ static void usage(void) __attribute__((noreturn)); ...@@ -36,7 +36,7 @@ static void usage(void) __attribute__((noreturn));
static void usage(void) static void usage(void)
{ {
fprintf(stderr, "Usage: ip tuntap { add | del | show | list | lst | help } [ dev PHYS_DEV ] \n"); fprintf(stderr, "Usage: ip tuntap { add | del | show | list | lst | help } [ dev PHYS_DEV ]\n");
fprintf(stderr, " [ mode { tun | tap } ] [ user USER ] [ group GROUP ]\n"); fprintf(stderr, " [ mode { tun | tap } ] [ user USER ] [ group GROUP ]\n");
fprintf(stderr, " [ one_queue ] [ pi ] [ vnet_hdr ] [ multi_queue ]\n"); fprintf(stderr, " [ one_queue ] [ pi ] [ vnet_hdr ] [ multi_queue ]\n");
fprintf(stderr, "\n"); fprintf(stderr, "\n");
...@@ -117,18 +117,18 @@ static int parse_args(int argc, char **argv, struct ifreq *ifr, uid_t *uid, gid_ ...@@ -117,18 +117,18 @@ static int parse_args(int argc, char **argv, struct ifreq *ifr, uid_t *uid, gid_
NEXT_ARG(); NEXT_ARG();
if (matches(*argv, "tun") == 0) { if (matches(*argv, "tun") == 0) {
if (ifr->ifr_flags & IFF_TAP) { if (ifr->ifr_flags & IFF_TAP) {
fprintf(stderr,"You managed to ask for more than one tunnel mode.\n"); fprintf(stderr, "You managed to ask for more than one tunnel mode.\n");
exit(-1); exit(-1);
} }
ifr->ifr_flags |= IFF_TUN; ifr->ifr_flags |= IFF_TUN;
} else if (matches(*argv, "tap") == 0) { } else if (matches(*argv, "tap") == 0) {
if (ifr->ifr_flags & IFF_TUN) { if (ifr->ifr_flags & IFF_TUN) {
fprintf(stderr,"You managed to ask for more than one tunnel mode.\n"); fprintf(stderr, "You managed to ask for more than one tunnel mode.\n");
exit(-1); exit(-1);
} }
ifr->ifr_flags |= IFF_TAP; ifr->ifr_flags |= IFF_TAP;
} else { } else {
fprintf(stderr,"Unknown tunnel mode \"%s\"\n", *argv); fprintf(stderr, "Unknown tunnel mode \"%s\"\n", *argv);
exit(-1); exit(-1);
} }
} else if (uid && matches(*argv, "user") == 0) { } else if (uid && matches(*argv, "user") == 0) {
...@@ -140,6 +140,7 @@ static int parse_args(int argc, char **argv, struct ifreq *ifr, uid_t *uid, gid_ ...@@ -140,6 +140,7 @@ static int parse_args(int argc, char **argv, struct ifreq *ifr, uid_t *uid, gid_
*uid = user; *uid = user;
else { else {
struct passwd *pw = getpwnam(*argv); struct passwd *pw = getpwnam(*argv);
if (!pw) { if (!pw) {
fprintf(stderr, "invalid user \"%s\"\n", *argv); fprintf(stderr, "invalid user \"%s\"\n", *argv);
exit(-1); exit(-1);
...@@ -156,6 +157,7 @@ static int parse_args(int argc, char **argv, struct ifreq *ifr, uid_t *uid, gid_ ...@@ -156,6 +157,7 @@ static int parse_args(int argc, char **argv, struct ifreq *ifr, uid_t *uid, gid_
*gid = group; *gid = group;
else { else {
struct group *gr = getgrnam(*argv); struct group *gr = getgrnam(*argv);
if (!gr) { if (!gr) {
fprintf(stderr, "invalid group \"%s\"\n", *argv); fprintf(stderr, "invalid group \"%s\"\n", *argv);
exit(-1); exit(-1);
...@@ -313,9 +315,9 @@ int do_iptuntap(int argc, char **argv) ...@@ -313,9 +315,9 @@ int do_iptuntap(int argc, char **argv)
if (matches(*argv, "delete") == 0) if (matches(*argv, "delete") == 0)
return do_del(argc-1, argv+1); return do_del(argc-1, argv+1);
if (matches(*argv, "show") == 0 || if (matches(*argv, "show") == 0 ||
matches(*argv, "lst") == 0 || matches(*argv, "lst") == 0 ||
matches(*argv, "list") == 0) matches(*argv, "list") == 0)
return do_show(argc-1, argv+1); return do_show(argc-1, argv+1);
if (matches(*argv, "help") == 0) if (matches(*argv, "help") == 0)
usage(); usage();
} else } else
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
strncat(buf, str, len); \ strncat(buf, str, len); \
buf[sizeof(buf) - 1] = '\0'; \ buf[sizeof(buf) - 1] = '\0'; \
} \ } \
} while(0); } while (0);
struct xfrm_filter filter; struct xfrm_filter filter;
...@@ -111,7 +111,7 @@ struct typeent { ...@@ -111,7 +111,7 @@ struct typeent {
int t_type; int t_type;
}; };
static const struct typeent xfrmproto_types[]= { static const struct typeent xfrmproto_types[] = {
{ "esp", IPPROTO_ESP }, { "ah", IPPROTO_AH }, { "comp", IPPROTO_COMP }, { "esp", IPPROTO_ESP }, { "ah", IPPROTO_AH }, { "comp", IPPROTO_COMP },
{ "route2", IPPROTO_ROUTING }, { "hao", IPPROTO_DSTOPTS }, { "route2", IPPROTO_ROUTING }, { "hao", IPPROTO_DSTOPTS },
{ "ipsec-any", IPSEC_PROTO_ANY }, { "ipsec-any", IPSEC_PROTO_ANY },
...@@ -124,6 +124,7 @@ int xfrm_xfrmproto_getbyname(char *name) ...@@ -124,6 +124,7 @@ int xfrm_xfrmproto_getbyname(char *name)
for (i = 0; ; i++) { for (i = 0; ; i++) {
const struct typeent *t = &xfrmproto_types[i]; const struct typeent *t = &xfrmproto_types[i];
if (!t->t_name || t->t_type == -1) if (!t->t_name || t->t_type == -1)
break; break;
...@@ -141,6 +142,7 @@ const char *strxf_xfrmproto(__u8 proto) ...@@ -141,6 +142,7 @@ const char *strxf_xfrmproto(__u8 proto)
for (i = 0; ; i++) { for (i = 0; ; i++) {
const struct typeent *t = &xfrmproto_types[i]; const struct typeent *t = &xfrmproto_types[i];
if (!t->t_name || t->t_type == -1) if (!t->t_name || t->t_type == -1)
break; break;
...@@ -152,7 +154,7 @@ const char *strxf_xfrmproto(__u8 proto) ...@@ -152,7 +154,7 @@ const char *strxf_xfrmproto(__u8 proto)
return str; return str;
} }
static const struct typeent algo_types[]= { static const struct typeent algo_types[] = {
{ "enc", XFRMA_ALG_CRYPT }, { "auth", XFRMA_ALG_AUTH }, { "enc", XFRMA_ALG_CRYPT }, { "auth", XFRMA_ALG_AUTH },
{ "comp", XFRMA_ALG_COMP }, { "aead", XFRMA_ALG_AEAD }, { "comp", XFRMA_ALG_COMP }, { "aead", XFRMA_ALG_AEAD },
{ "auth-trunc", XFRMA_ALG_AUTH_TRUNC }, { "auth-trunc", XFRMA_ALG_AUTH_TRUNC },
...@@ -165,6 +167,7 @@ int xfrm_algotype_getbyname(char *name) ...@@ -165,6 +167,7 @@ int xfrm_algotype_getbyname(char *name)
for (i = 0; ; i++) { for (i = 0; ; i++) {
const struct typeent *t = &algo_types[i]; const struct typeent *t = &algo_types[i];
if (!t->t_name || t->t_type == -1) if (!t->t_name || t->t_type == -1)
break; break;
...@@ -182,6 +185,7 @@ const char *strxf_algotype(int type) ...@@ -182,6 +185,7 @@ const char *strxf_algotype(int type)
for (i = 0; ; i++) { for (i = 0; ; i++) {
const struct typeent *t = &algo_types[i]; const struct typeent *t = &algo_types[i];
if (!t->t_name || t->t_type == -1) if (!t->t_name || t->t_type == -1)
break; break;
...@@ -302,6 +306,7 @@ void xfrm_id_info_print(xfrm_address_t *saddr, struct xfrm_id *id, ...@@ -302,6 +306,7 @@ void xfrm_id_info_print(xfrm_address_t *saddr, struct xfrm_id *id,
if (show_stats > 0 || force_spi || id->spi) { if (show_stats > 0 || force_spi || id->spi) {
__u32 spi = ntohl(id->spi); __u32 spi = ntohl(id->spi);
fprintf(fp, "spi 0x%08x", spi); fprintf(fp, "spi 0x%08x", spi);
if (show_stats > 0) if (show_stats > 0)
fprintf(fp, "(%u)", spi); fprintf(fp, "(%u)", spi);
...@@ -340,6 +345,7 @@ void xfrm_id_info_print(xfrm_address_t *saddr, struct xfrm_id *id, ...@@ -340,6 +345,7 @@ void xfrm_id_info_print(xfrm_address_t *saddr, struct xfrm_id *id,
static const char *strxf_limit(__u64 limit) static const char *strxf_limit(__u64 limit)
{ {
static char str[32]; static char str[32];
if (limit == XFRM_INF) if (limit == XFRM_INF)
strcpy(str, "(INF)"); strcpy(str, "(INF)");
else else
...@@ -389,7 +395,7 @@ void xfrm_lifetime_print(struct xfrm_lifetime_cfg *cfg, ...@@ -389,7 +395,7 @@ void xfrm_lifetime_print(struct xfrm_lifetime_cfg *cfg,
if (cfg) { if (cfg) {
if (prefix) if (prefix)
fputs(prefix, fp); fputs(prefix, fp);
fprintf(fp, "lifetime config:%s",_SL_); fprintf(fp, "lifetime config:%s", _SL_);
if (prefix) if (prefix)
fputs(prefix, fp); fputs(prefix, fp);
...@@ -538,7 +544,7 @@ static void __xfrm_algo_print(struct xfrm_algo *algo, int type, int len, ...@@ -538,7 +544,7 @@ static void __xfrm_algo_print(struct xfrm_algo *algo, int type, int len,
if (keylen > 0) { if (keylen > 0) {
fprintf(fp, "0x"); fprintf(fp, "0x");
for (i = 0; i < keylen; i ++) for (i = 0; i < keylen; i++)
fprintf(fp, "%.2x", (unsigned char)algo->alg_key[i]); fprintf(fp, "%.2x", (unsigned char)algo->alg_key[i]);
if (show_stats > 0) if (show_stats > 0)
...@@ -692,36 +698,42 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family, ...@@ -692,36 +698,42 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
if (tb[XFRMA_MARK]) { if (tb[XFRMA_MARK]) {
struct rtattr *rta = tb[XFRMA_MARK]; struct rtattr *rta = tb[XFRMA_MARK];
struct xfrm_mark *m = (struct xfrm_mark *) RTA_DATA(rta); struct xfrm_mark *m = (struct xfrm_mark *) RTA_DATA(rta);
fprintf(fp, "\tmark %#x/%#x", m->v, m->m); fprintf(fp, "\tmark %#x/%#x", m->v, m->m);
fprintf(fp, "%s", _SL_); fprintf(fp, "%s", _SL_);
} }
if (tb[XFRMA_ALG_AUTH] && !tb[XFRMA_ALG_AUTH_TRUNC]) { if (tb[XFRMA_ALG_AUTH] && !tb[XFRMA_ALG_AUTH_TRUNC]) {
struct rtattr *rta = tb[XFRMA_ALG_AUTH]; struct rtattr *rta = tb[XFRMA_ALG_AUTH];
xfrm_algo_print((struct xfrm_algo *) RTA_DATA(rta), xfrm_algo_print((struct xfrm_algo *) RTA_DATA(rta),
XFRMA_ALG_AUTH, RTA_PAYLOAD(rta), fp, prefix); XFRMA_ALG_AUTH, RTA_PAYLOAD(rta), fp, prefix);
} }
if (tb[XFRMA_ALG_AUTH_TRUNC]) { if (tb[XFRMA_ALG_AUTH_TRUNC]) {
struct rtattr *rta = tb[XFRMA_ALG_AUTH_TRUNC]; struct rtattr *rta = tb[XFRMA_ALG_AUTH_TRUNC];
xfrm_auth_trunc_print((struct xfrm_algo_auth *) RTA_DATA(rta), xfrm_auth_trunc_print((struct xfrm_algo_auth *) RTA_DATA(rta),
RTA_PAYLOAD(rta), fp, prefix); RTA_PAYLOAD(rta), fp, prefix);
} }
if (tb[XFRMA_ALG_AEAD]) { if (tb[XFRMA_ALG_AEAD]) {
struct rtattr *rta = tb[XFRMA_ALG_AEAD]; struct rtattr *rta = tb[XFRMA_ALG_AEAD];
xfrm_aead_print((struct xfrm_algo_aead *)RTA_DATA(rta), xfrm_aead_print((struct xfrm_algo_aead *)RTA_DATA(rta),
RTA_PAYLOAD(rta), fp, prefix); RTA_PAYLOAD(rta), fp, prefix);
} }
if (tb[XFRMA_ALG_CRYPT]) { if (tb[XFRMA_ALG_CRYPT]) {
struct rtattr *rta = tb[XFRMA_ALG_CRYPT]; struct rtattr *rta = tb[XFRMA_ALG_CRYPT];
xfrm_algo_print((struct xfrm_algo *) RTA_DATA(rta), xfrm_algo_print((struct xfrm_algo *) RTA_DATA(rta),
XFRMA_ALG_CRYPT, RTA_PAYLOAD(rta), fp, prefix); XFRMA_ALG_CRYPT, RTA_PAYLOAD(rta), fp, prefix);
} }
if (tb[XFRMA_ALG_COMP]) { if (tb[XFRMA_ALG_COMP]) {
struct rtattr *rta = tb[XFRMA_ALG_COMP]; struct rtattr *rta = tb[XFRMA_ALG_COMP];
xfrm_algo_print((struct xfrm_algo *) RTA_DATA(rta), xfrm_algo_print((struct xfrm_algo *) RTA_DATA(rta),
XFRMA_ALG_COMP, RTA_PAYLOAD(rta), fp, prefix); XFRMA_ALG_COMP, RTA_PAYLOAD(rta), fp, prefix);
} }
...@@ -765,6 +777,7 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family, ...@@ -765,6 +777,7 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
if (tb[XFRMA_TMPL]) { if (tb[XFRMA_TMPL]) {
struct rtattr *rta = tb[XFRMA_TMPL]; struct rtattr *rta = tb[XFRMA_TMPL];
xfrm_tmpl_print((struct xfrm_user_tmpl *) RTA_DATA(rta), xfrm_tmpl_print((struct xfrm_user_tmpl *) RTA_DATA(rta),
RTA_PAYLOAD(rta), fp, prefix); RTA_PAYLOAD(rta), fp, prefix);
} }
...@@ -1140,11 +1153,11 @@ int xfrm_id_parse(xfrm_address_t *saddr, struct xfrm_id *id, __u16 *family, ...@@ -1140,11 +1153,11 @@ int xfrm_id_parse(xfrm_address_t *saddr, struct xfrm_id *id, __u16 *family,
if (id->spi && id->proto) { if (id->spi && id->proto) {
if (xfrm_xfrmproto_is_ro(id->proto)) { if (xfrm_xfrmproto_is_ro(id->proto)) {
fprintf(stderr, "\"spi\" is invalid with XFRM-PROTO value \"%s\"\n", fprintf(stderr, "\"spi\" is invalid with XFRM-PROTO value \"%s\"\n",
strxf_xfrmproto(id->proto)); strxf_xfrmproto(id->proto));
exit(1); exit(1);
} else if (id->proto == IPPROTO_COMP && ntohl(id->spi) >= 0x10000) { } else if (id->proto == IPPROTO_COMP && ntohl(id->spi) >= 0x10000) {
fprintf(stderr, "SPI value is too large with XFRM-PROTO value \"%s\"\n", fprintf(stderr, "SPI value is too large with XFRM-PROTO value \"%s\"\n",
strxf_xfrmproto(id->proto)); strxf_xfrmproto(id->proto));
exit(1); exit(1);
} }
} }
...@@ -1238,6 +1251,7 @@ static int xfrm_selector_upspec_parse(struct xfrm_selector *sel, ...@@ -1238,6 +1251,7 @@ static int xfrm_selector_upspec_parse(struct xfrm_selector *sel,
upspec = 0; upspec = 0;
else { else {
struct protoent *pp; struct protoent *pp;
pp = getprotobyname(*argv); pp = getprotobyname(*argv);
if (pp) if (pp)
upspec = pp->p_proto; upspec = pp->p_proto;
...@@ -1304,7 +1318,7 @@ static int xfrm_selector_upspec_parse(struct xfrm_selector *sel, ...@@ -1304,7 +1318,7 @@ static int xfrm_selector_upspec_parse(struct xfrm_selector *sel,
filter.upspec_dport_mask = XFRM_FILTER_MASK_FULL; filter.upspec_dport_mask = XFRM_FILTER_MASK_FULL;
} else if (strcmp(*argv, "key") == 0) { } else if (strcmp(*argv, "key") == 0) {
unsigned uval; unsigned int uval;
grekey = *argv; grekey = *argv;
...@@ -1313,7 +1327,7 @@ static int xfrm_selector_upspec_parse(struct xfrm_selector *sel, ...@@ -1313,7 +1327,7 @@ static int xfrm_selector_upspec_parse(struct xfrm_selector *sel,
if (strchr(*argv, '.')) if (strchr(*argv, '.'))
uval = htonl(get_addr32(*argv)); uval = htonl(get_addr32(*argv));
else { else {
if (get_unsigned(&uval, *argv, 0)<0) { if (get_unsigned(&uval, *argv, 0) < 0) {
fprintf(stderr, "value after \"key\" is invalid\n"); fprintf(stderr, "value after \"key\" is invalid\n");
exit(-1); exit(-1);
} }
......
...@@ -61,11 +61,11 @@ static int gre_parse_opt(struct link_util *lu, int argc, char **argv, ...@@ -61,11 +61,11 @@ static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
struct rtattr *greinfo[IFLA_GRE_MAX + 1]; struct rtattr *greinfo[IFLA_GRE_MAX + 1];
__u16 iflags = 0; __u16 iflags = 0;
__u16 oflags = 0; __u16 oflags = 0;
unsigned ikey = 0; unsigned int ikey = 0;
unsigned okey = 0; unsigned int okey = 0;
unsigned saddr = 0; unsigned int saddr = 0;
unsigned daddr = 0; unsigned int daddr = 0;
unsigned link = 0; unsigned int link = 0;
__u8 pmtudisc = 1; __u8 pmtudisc = 1;
__u8 ttl = 0; __u8 ttl = 0;
__u8 tos = 0; __u8 tos = 0;
...@@ -156,7 +156,7 @@ get_failed: ...@@ -156,7 +156,7 @@ get_failed:
while (argc > 0) { while (argc > 0) {
if (!matches(*argv, "key")) { if (!matches(*argv, "key")) {
unsigned uval; unsigned int uval;
NEXT_ARG(); NEXT_ARG();
iflags |= GRE_KEY; iflags |= GRE_KEY;
...@@ -174,14 +174,14 @@ get_failed: ...@@ -174,14 +174,14 @@ get_failed:
ikey = okey = uval; ikey = okey = uval;
} else if (!matches(*argv, "ikey")) { } else if (!matches(*argv, "ikey")) {
unsigned uval; unsigned int uval;
NEXT_ARG(); NEXT_ARG();
iflags |= GRE_KEY; iflags |= GRE_KEY;
if (strchr(*argv, '.')) if (strchr(*argv, '.'))
uval = get_addr32(*argv); uval = get_addr32(*argv);
else { else {
if (get_unsigned(&uval, *argv, 0)<0) { if (get_unsigned(&uval, *argv, 0) < 0) {
fprintf(stderr, "invalid value for \"ikey\": \"%s\"; it should be an unsigned integer\n", *argv); fprintf(stderr, "invalid value for \"ikey\": \"%s\"; it should be an unsigned integer\n", *argv);
exit(-1); exit(-1);
} }
...@@ -189,14 +189,14 @@ get_failed: ...@@ -189,14 +189,14 @@ get_failed:
} }
ikey = uval; ikey = uval;
} else if (!matches(*argv, "okey")) { } else if (!matches(*argv, "okey")) {
unsigned uval; unsigned int uval;
NEXT_ARG(); NEXT_ARG();
oflags |= GRE_KEY; oflags |= GRE_KEY;
if (strchr(*argv, '.')) if (strchr(*argv, '.'))
uval = get_addr32(*argv); uval = get_addr32(*argv);
else { else {
if (get_unsigned(&uval, *argv, 0)<0) { if (get_unsigned(&uval, *argv, 0) < 0) {
fprintf(stderr, "invalid value for \"okey\": \"%s\"; it should be an unsigned integer\n", *argv); fprintf(stderr, "invalid value for \"okey\": \"%s\"; it should be an unsigned integer\n", *argv);
exit(-1); exit(-1);
} }
...@@ -239,7 +239,7 @@ get_failed: ...@@ -239,7 +239,7 @@ get_failed:
} }
} else if (!matches(*argv, "ttl") || } else if (!matches(*argv, "ttl") ||
!matches(*argv, "hoplimit")) { !matches(*argv, "hoplimit")) {
unsigned uval; unsigned int uval;
NEXT_ARG(); NEXT_ARG();
if (strcmp(*argv, "inherit") != 0) { if (strcmp(*argv, "inherit") != 0) {
...@@ -343,14 +343,14 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -343,14 +343,14 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
char s2[64]; char s2[64];
const char *local = "any"; const char *local = "any";
const char *remote = "any"; const char *remote = "any";
unsigned iflags = 0; unsigned int iflags = 0;
unsigned oflags = 0; unsigned int oflags = 0;
if (!tb) if (!tb)
return; return;
if (tb[IFLA_GRE_REMOTE]) { if (tb[IFLA_GRE_REMOTE]) {
unsigned addr = rta_getattr_u32(tb[IFLA_GRE_REMOTE]); unsigned int addr = rta_getattr_u32(tb[IFLA_GRE_REMOTE]);
if (addr) if (addr)
remote = format_host(AF_INET, 4, &addr, s1, sizeof(s1)); remote = format_host(AF_INET, 4, &addr, s1, sizeof(s1));
...@@ -359,7 +359,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -359,7 +359,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
fprintf(f, "remote %s ", remote); fprintf(f, "remote %s ", remote);
if (tb[IFLA_GRE_LOCAL]) { if (tb[IFLA_GRE_LOCAL]) {
unsigned addr = rta_getattr_u32(tb[IFLA_GRE_LOCAL]); unsigned int addr = rta_getattr_u32(tb[IFLA_GRE_LOCAL]);
if (addr) if (addr)
local = format_host(AF_INET, 4, &addr, s1, sizeof(s1)); local = format_host(AF_INET, 4, &addr, s1, sizeof(s1));
...@@ -368,7 +368,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -368,7 +368,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
fprintf(f, "local %s ", local); fprintf(f, "local %s ", local);
if (tb[IFLA_GRE_LINK] && rta_getattr_u32(tb[IFLA_GRE_LINK])) { if (tb[IFLA_GRE_LINK] && rta_getattr_u32(tb[IFLA_GRE_LINK])) {
unsigned link = rta_getattr_u32(tb[IFLA_GRE_LINK]); unsigned int link = rta_getattr_u32(tb[IFLA_GRE_LINK]);
const char *n = if_indextoname(link, s2); const char *n = if_indextoname(link, s2);
if (n) if (n)
......
...@@ -71,13 +71,13 @@ static int gre_parse_opt(struct link_util *lu, int argc, char **argv, ...@@ -71,13 +71,13 @@ static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
struct rtattr *greinfo[IFLA_GRE_MAX + 1]; struct rtattr *greinfo[IFLA_GRE_MAX + 1];
__u16 iflags = 0; __u16 iflags = 0;
__u16 oflags = 0; __u16 oflags = 0;
unsigned ikey = 0; unsigned int ikey = 0;
unsigned okey = 0; unsigned int okey = 0;
struct in6_addr raddr = IN6ADDR_ANY_INIT; struct in6_addr raddr = IN6ADDR_ANY_INIT;
struct in6_addr laddr = IN6ADDR_ANY_INIT; struct in6_addr laddr = IN6ADDR_ANY_INIT;
unsigned link = 0; unsigned int link = 0;
unsigned flowinfo = 0; unsigned int flowinfo = 0;
unsigned flags = 0; unsigned int flags = 0;
__u8 hop_limit = DEFAULT_TNL_HOP_LIMIT; __u8 hop_limit = DEFAULT_TNL_HOP_LIMIT;
__u8 encap_limit = IPV6_DEFAULT_TNL_ENCAP_LIMIT; __u8 encap_limit = IPV6_DEFAULT_TNL_ENCAP_LIMIT;
int len; int len;
...@@ -152,7 +152,7 @@ get_failed: ...@@ -152,7 +152,7 @@ get_failed:
while (argc > 0) { while (argc > 0) {
if (!matches(*argv, "key")) { if (!matches(*argv, "key")) {
unsigned uval; unsigned int uval;
NEXT_ARG(); NEXT_ARG();
iflags |= GRE_KEY; iflags |= GRE_KEY;
...@@ -170,14 +170,14 @@ get_failed: ...@@ -170,14 +170,14 @@ get_failed:
ikey = okey = uval; ikey = okey = uval;
} else if (!matches(*argv, "ikey")) { } else if (!matches(*argv, "ikey")) {
unsigned uval; unsigned int uval;
NEXT_ARG(); NEXT_ARG();
iflags |= GRE_KEY; iflags |= GRE_KEY;
if (strchr(*argv, '.')) if (strchr(*argv, '.'))
uval = get_addr32(*argv); uval = get_addr32(*argv);
else { else {
if (get_unsigned(&uval, *argv, 0)<0) { if (get_unsigned(&uval, *argv, 0) < 0) {
fprintf(stderr, "invalid value of \"ikey\"\n"); fprintf(stderr, "invalid value of \"ikey\"\n");
exit(-1); exit(-1);
} }
...@@ -185,14 +185,14 @@ get_failed: ...@@ -185,14 +185,14 @@ get_failed:
} }
ikey = uval; ikey = uval;
} else if (!matches(*argv, "okey")) { } else if (!matches(*argv, "okey")) {
unsigned uval; unsigned int uval;
NEXT_ARG(); NEXT_ARG();
oflags |= GRE_KEY; oflags |= GRE_KEY;
if (strchr(*argv, '.')) if (strchr(*argv, '.'))
uval = get_addr32(*argv); uval = get_addr32(*argv);
else { else {
if (get_unsigned(&uval, *argv, 0)<0) { if (get_unsigned(&uval, *argv, 0) < 0) {
fprintf(stderr, "invalid value of \"okey\"\n"); fprintf(stderr, "invalid value of \"okey\"\n");
exit(-1); exit(-1);
} }
...@@ -215,6 +215,7 @@ get_failed: ...@@ -215,6 +215,7 @@ get_failed:
oflags |= GRE_CSUM; oflags |= GRE_CSUM;
} else if (!matches(*argv, "remote")) { } else if (!matches(*argv, "remote")) {
inet_prefix addr; inet_prefix addr;
NEXT_ARG(); NEXT_ARG();
get_prefix(&addr, *argv, preferred_family); get_prefix(&addr, *argv, preferred_family);
if (addr.family == AF_UNSPEC) if (addr.family == AF_UNSPEC)
...@@ -222,6 +223,7 @@ get_failed: ...@@ -222,6 +223,7 @@ get_failed:
memcpy(&raddr, &addr.data, sizeof(raddr)); memcpy(&raddr, &addr.data, sizeof(raddr));
} else if (!matches(*argv, "local")) { } else if (!matches(*argv, "local")) {
inet_prefix addr; inet_prefix addr;
NEXT_ARG(); NEXT_ARG();
get_prefix(&addr, *argv, preferred_family); get_prefix(&addr, *argv, preferred_family);
if (addr.family == AF_UNSPEC) if (addr.family == AF_UNSPEC)
...@@ -238,6 +240,7 @@ get_failed: ...@@ -238,6 +240,7 @@ get_failed:
} else if (!matches(*argv, "ttl") || } else if (!matches(*argv, "ttl") ||
!matches(*argv, "hoplimit")) { !matches(*argv, "hoplimit")) {
__u8 uval; __u8 uval;
NEXT_ARG(); NEXT_ARG();
if (get_u8(&uval, *argv, 0)) if (get_u8(&uval, *argv, 0))
invarg("invalid TTL", *argv); invarg("invalid TTL", *argv);
...@@ -246,6 +249,7 @@ get_failed: ...@@ -246,6 +249,7 @@ get_failed:
!matches(*argv, "tclass") || !matches(*argv, "tclass") ||
!matches(*argv, "dsfield")) { !matches(*argv, "dsfield")) {
__u8 uval; __u8 uval;
NEXT_ARG(); NEXT_ARG();
if (strcmp(*argv, "inherit") == 0) if (strcmp(*argv, "inherit") == 0)
flags |= IP6_TNL_F_USE_ORIG_TCLASS; flags |= IP6_TNL_F_USE_ORIG_TCLASS;
...@@ -258,6 +262,7 @@ get_failed: ...@@ -258,6 +262,7 @@ get_failed:
} else if (strcmp(*argv, "flowlabel") == 0 || } else if (strcmp(*argv, "flowlabel") == 0 ||
strcmp(*argv, "fl") == 0) { strcmp(*argv, "fl") == 0) {
__u32 uval; __u32 uval;
NEXT_ARG(); NEXT_ARG();
if (strcmp(*argv, "inherit") == 0) if (strcmp(*argv, "inherit") == 0)
flags |= IP6_TNL_F_USE_ORIG_FLOWLABEL; flags |= IP6_TNL_F_USE_ORIG_FLOWLABEL;
...@@ -301,10 +306,10 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -301,10 +306,10 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
char s2[64]; char s2[64];
const char *local = "any"; const char *local = "any";
const char *remote = "any"; const char *remote = "any";
unsigned iflags = 0; unsigned int iflags = 0;
unsigned oflags = 0; unsigned int oflags = 0;
unsigned flags = 0; unsigned int flags = 0;
unsigned flowinfo = 0; unsigned int flowinfo = 0;
struct in6_addr in6_addr_any = IN6ADDR_ANY_INIT; struct in6_addr in6_addr_any = IN6ADDR_ANY_INIT;
if (!tb) if (!tb)
...@@ -318,6 +323,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -318,6 +323,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (tb[IFLA_GRE_REMOTE]) { if (tb[IFLA_GRE_REMOTE]) {
struct in6_addr addr; struct in6_addr addr;
memcpy(&addr, RTA_DATA(tb[IFLA_GRE_REMOTE]), sizeof(addr)); memcpy(&addr, RTA_DATA(tb[IFLA_GRE_REMOTE]), sizeof(addr));
if (memcmp(&addr, &in6_addr_any, sizeof(addr))) if (memcmp(&addr, &in6_addr_any, sizeof(addr)))
...@@ -328,6 +334,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -328,6 +334,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (tb[IFLA_GRE_LOCAL]) { if (tb[IFLA_GRE_LOCAL]) {
struct in6_addr addr; struct in6_addr addr;
memcpy(&addr, RTA_DATA(tb[IFLA_GRE_LOCAL]), sizeof(addr)); memcpy(&addr, RTA_DATA(tb[IFLA_GRE_LOCAL]), sizeof(addr));
if (memcmp(&addr, &in6_addr_any, sizeof(addr))) if (memcmp(&addr, &in6_addr_any, sizeof(addr)))
...@@ -337,7 +344,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -337,7 +344,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
fprintf(f, "local %s ", local); fprintf(f, "local %s ", local);
if (tb[IFLA_GRE_LINK] && rta_getattr_u32(tb[IFLA_GRE_LINK])) { if (tb[IFLA_GRE_LINK] && rta_getattr_u32(tb[IFLA_GRE_LINK])) {
unsigned link = rta_getattr_u32(tb[IFLA_GRE_LINK]); unsigned int link = rta_getattr_u32(tb[IFLA_GRE_LINK]);
const char *n = if_indextoname(link, s2); const char *n = if_indextoname(link, s2);
if (n) if (n)
......
...@@ -35,7 +35,7 @@ static void print_usage(FILE *f) ...@@ -35,7 +35,7 @@ static void print_usage(FILE *f)
fprintf(f, " [ mode { ip6ip6 | ipip6 | any } ]\n"); fprintf(f, " [ mode { ip6ip6 | ipip6 | any } ]\n");
fprintf(f, " type ip6tnl [ remote ADDR ] [ local ADDR ]\n"); fprintf(f, " type ip6tnl [ remote ADDR ] [ local ADDR ]\n");
fprintf(f, " [ dev PHYS_DEV ] [ encaplimit ELIM ]\n"); fprintf(f, " [ dev PHYS_DEV ] [ encaplimit ELIM ]\n");
fprintf(f ," [ hoplimit HLIM ] [ tclass TCLASS ] [ flowlabel FLOWLABEL ]\n"); fprintf(f, " [ hoplimit HLIM ] [ tclass TCLASS ] [ flowlabel FLOWLABEL ]\n");
fprintf(f, " [ dscp inherit ] [ fwmark inherit ]\n"); fprintf(f, " [ dscp inherit ] [ fwmark inherit ]\n");
fprintf(f, "\n"); fprintf(f, "\n");
fprintf(f, "Where: NAME := STRING\n"); fprintf(f, "Where: NAME := STRING\n");
...@@ -159,6 +159,7 @@ get_failed: ...@@ -159,6 +159,7 @@ get_failed:
invarg("Cannot guess tunnel mode.", *argv); invarg("Cannot guess tunnel mode.", *argv);
} else if (strcmp(*argv, "remote") == 0) { } else if (strcmp(*argv, "remote") == 0) {
inet_prefix addr; inet_prefix addr;
NEXT_ARG(); NEXT_ARG();
get_prefix(&addr, *argv, preferred_family); get_prefix(&addr, *argv, preferred_family);
if (addr.family == AF_UNSPEC) if (addr.family == AF_UNSPEC)
...@@ -166,6 +167,7 @@ get_failed: ...@@ -166,6 +167,7 @@ get_failed:
memcpy(&raddr, addr.data, addr.bytelen); memcpy(&raddr, addr.data, addr.bytelen);
} else if (strcmp(*argv, "local") == 0) { } else if (strcmp(*argv, "local") == 0) {
inet_prefix addr; inet_prefix addr;
NEXT_ARG(); NEXT_ARG();
get_prefix(&addr, *argv, preferred_family); get_prefix(&addr, *argv, preferred_family);
if (addr.family == AF_UNSPEC) if (addr.family == AF_UNSPEC)
...@@ -180,6 +182,7 @@ get_failed: ...@@ -180,6 +182,7 @@ get_failed:
strcmp(*argv, "ttl") == 0 || strcmp(*argv, "ttl") == 0 ||
strcmp(*argv, "hlim") == 0) { strcmp(*argv, "hlim") == 0) {
__u8 uval; __u8 uval;
NEXT_ARG(); NEXT_ARG();
if (get_u8(&uval, *argv, 0)) if (get_u8(&uval, *argv, 0))
invarg("invalid HLIM", *argv); invarg("invalid HLIM", *argv);
...@@ -190,6 +193,7 @@ get_failed: ...@@ -190,6 +193,7 @@ get_failed:
flags |= IP6_TNL_F_IGN_ENCAP_LIMIT; flags |= IP6_TNL_F_IGN_ENCAP_LIMIT;
} else { } else {
__u8 uval; __u8 uval;
if (get_u8(&uval, *argv, 0) < -1) if (get_u8(&uval, *argv, 0) < -1)
invarg("invalid ELIM", *argv); invarg("invalid ELIM", *argv);
encap_limit = uval; encap_limit = uval;
...@@ -200,6 +204,7 @@ get_failed: ...@@ -200,6 +204,7 @@ get_failed:
strcmp(*argv, "tos") == 0 || strcmp(*argv, "tos") == 0 ||
matches(*argv, "dsfield") == 0) { matches(*argv, "dsfield") == 0) {
__u8 uval; __u8 uval;
NEXT_ARG(); NEXT_ARG();
flowinfo &= ~IP6_FLOWINFO_TCLASS; flowinfo &= ~IP6_FLOWINFO_TCLASS;
if (strcmp(*argv, "inherit") == 0) if (strcmp(*argv, "inherit") == 0)
...@@ -213,6 +218,7 @@ get_failed: ...@@ -213,6 +218,7 @@ get_failed:
} else if (strcmp(*argv, "flowlabel") == 0 || } else if (strcmp(*argv, "flowlabel") == 0 ||
strcmp(*argv, "fl") == 0) { strcmp(*argv, "fl") == 0) {
__u32 uval; __u32 uval;
NEXT_ARG(); NEXT_ARG();
flowinfo &= ~IP6_FLOWINFO_FLOWLABEL; flowinfo &= ~IP6_FLOWINFO_FLOWLABEL;
if (strcmp(*argv, "inherit") == 0) if (strcmp(*argv, "inherit") == 0)
...@@ -299,7 +305,7 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb ...@@ -299,7 +305,7 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb
} }
if (tb[IFLA_IPTUN_LINK] && rta_getattr_u32(tb[IFLA_IPTUN_LINK])) { if (tb[IFLA_IPTUN_LINK] && rta_getattr_u32(tb[IFLA_IPTUN_LINK])) {
unsigned link = rta_getattr_u32(tb[IFLA_IPTUN_LINK]); unsigned int link = rta_getattr_u32(tb[IFLA_IPTUN_LINK]);
const char *n = if_indextoname(link, s2); const char *n = if_indextoname(link, s2);
if (n) if (n)
......
...@@ -197,6 +197,7 @@ get_failed: ...@@ -197,6 +197,7 @@ get_failed:
strcmp(*argv, "tclass") == 0 || strcmp(*argv, "tclass") == 0 ||
matches(*argv, "dsfield") == 0) { matches(*argv, "dsfield") == 0) {
__u32 uval; __u32 uval;
NEXT_ARG(); NEXT_ARG();
if (strcmp(*argv, "inherit") != 0) { if (strcmp(*argv, "inherit") != 0) {
if (rtnl_dsfield_a2n(&uval, *argv)) if (rtnl_dsfield_a2n(&uval, *argv))
...@@ -262,6 +263,7 @@ get_failed: ...@@ -262,6 +263,7 @@ get_failed:
encapflags &= ~TUNNEL_ENCAP_FLAG_REMCSUM; encapflags &= ~TUNNEL_ENCAP_FLAG_REMCSUM;
} else if (strcmp(*argv, "6rd-prefix") == 0) { } else if (strcmp(*argv, "6rd-prefix") == 0) {
inet_prefix prefix; inet_prefix prefix;
NEXT_ARG(); NEXT_ARG();
if (get_prefix(&prefix, *argv, AF_INET6)) if (get_prefix(&prefix, *argv, AF_INET6))
invarg("invalid 6rd_prefix\n", *argv); invarg("invalid 6rd_prefix\n", *argv);
...@@ -269,6 +271,7 @@ get_failed: ...@@ -269,6 +271,7 @@ get_failed:
ip6rdprefixlen = prefix.bitlen; ip6rdprefixlen = prefix.bitlen;
} else if (strcmp(*argv, "6rd-relay_prefix") == 0) { } else if (strcmp(*argv, "6rd-relay_prefix") == 0) {
inet_prefix prefix; inet_prefix prefix;
NEXT_ARG(); NEXT_ARG();
if (get_prefix(&prefix, *argv, AF_INET)) if (get_prefix(&prefix, *argv, AF_INET))
invarg("invalid 6rd-relay_prefix\n", *argv); invarg("invalid 6rd-relay_prefix\n", *argv);
...@@ -276,6 +279,7 @@ get_failed: ...@@ -276,6 +279,7 @@ get_failed:
ip6rdrelayprefixlen = prefix.bitlen; ip6rdrelayprefixlen = prefix.bitlen;
} else if (strcmp(*argv, "6rd-reset") == 0) { } else if (strcmp(*argv, "6rd-reset") == 0) {
inet_prefix prefix; inet_prefix prefix;
get_prefix(&prefix, "2002::", AF_INET6); get_prefix(&prefix, "2002::", AF_INET6);
memcpy(&ip6rdprefix, prefix.data, 16); memcpy(&ip6rdprefix, prefix.data, 16);
ip6rdprefixlen = 16; ip6rdprefixlen = 16;
...@@ -332,7 +336,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[ ...@@ -332,7 +336,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
return; return;
if (tb[IFLA_IPTUN_REMOTE]) { if (tb[IFLA_IPTUN_REMOTE]) {
unsigned addr = rta_getattr_u32(tb[IFLA_IPTUN_REMOTE]); unsigned int addr = rta_getattr_u32(tb[IFLA_IPTUN_REMOTE]);
if (addr) if (addr)
remote = format_host(AF_INET, 4, &addr, s1, sizeof(s1)); remote = format_host(AF_INET, 4, &addr, s1, sizeof(s1));
...@@ -341,7 +345,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[ ...@@ -341,7 +345,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
fprintf(f, "remote %s ", remote); fprintf(f, "remote %s ", remote);
if (tb[IFLA_IPTUN_LOCAL]) { if (tb[IFLA_IPTUN_LOCAL]) {
unsigned addr = rta_getattr_u32(tb[IFLA_IPTUN_LOCAL]); unsigned int addr = rta_getattr_u32(tb[IFLA_IPTUN_LOCAL]);
if (addr) if (addr)
local = format_host(AF_INET, 4, &addr, s1, sizeof(s1)); local = format_host(AF_INET, 4, &addr, s1, sizeof(s1));
...@@ -350,7 +354,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[ ...@@ -350,7 +354,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
fprintf(f, "local %s ", local); fprintf(f, "local %s ", local);
if (tb[IFLA_IPTUN_LINK] && rta_getattr_u32(tb[IFLA_IPTUN_LINK])) { if (tb[IFLA_IPTUN_LINK] && rta_getattr_u32(tb[IFLA_IPTUN_LINK])) {
unsigned link = rta_getattr_u32(tb[IFLA_IPTUN_LINK]); unsigned int link = rta_getattr_u32(tb[IFLA_IPTUN_LINK]);
const char *n = if_indextoname(link, s2); const char *n = if_indextoname(link, s2);
if (n) if (n)
......
...@@ -37,7 +37,7 @@ static int veth_parse_opt(struct link_util *lu, int argc, char **argv, ...@@ -37,7 +37,7 @@ static int veth_parse_opt(struct link_util *lu, int argc, char **argv,
char *type = NULL; char *type = NULL;
int index = 0; int index = 0;
int err, len; int err, len;
struct rtattr * data; struct rtattr *data;
int group; int group;
struct ifinfomsg *ifm, *peer_ifm; struct ifinfomsg *ifm, *peer_ifm;
unsigned int ifi_flags, ifi_change; unsigned int ifi_flags, ifi_change;
......
...@@ -55,11 +55,11 @@ static int vti_parse_opt(struct link_util *lu, int argc, char **argv, ...@@ -55,11 +55,11 @@ static int vti_parse_opt(struct link_util *lu, int argc, char **argv,
struct rtattr *tb[IFLA_MAX + 1]; struct rtattr *tb[IFLA_MAX + 1];
struct rtattr *linkinfo[IFLA_INFO_MAX+1]; struct rtattr *linkinfo[IFLA_INFO_MAX+1];
struct rtattr *vtiinfo[IFLA_VTI_MAX + 1]; struct rtattr *vtiinfo[IFLA_VTI_MAX + 1];
unsigned ikey = 0; unsigned int ikey = 0;
unsigned okey = 0; unsigned int okey = 0;
unsigned saddr = 0; unsigned int saddr = 0;
unsigned daddr = 0; unsigned int daddr = 0;
unsigned link = 0; unsigned int link = 0;
int len; int len;
if (!(n->nlmsg_flags & NLM_F_CREATE)) { if (!(n->nlmsg_flags & NLM_F_CREATE)) {
...@@ -114,7 +114,7 @@ get_failed: ...@@ -114,7 +114,7 @@ get_failed:
while (argc > 0) { while (argc > 0) {
if (!matches(*argv, "key")) { if (!matches(*argv, "key")) {
unsigned uval; unsigned int uval;
NEXT_ARG(); NEXT_ARG();
if (strchr(*argv, '.')) if (strchr(*argv, '.'))
...@@ -130,7 +130,7 @@ get_failed: ...@@ -130,7 +130,7 @@ get_failed:
ikey = okey = uval; ikey = okey = uval;
} else if (!matches(*argv, "ikey")) { } else if (!matches(*argv, "ikey")) {
unsigned uval; unsigned int uval;
NEXT_ARG(); NEXT_ARG();
if (strchr(*argv, '.')) if (strchr(*argv, '.'))
...@@ -144,7 +144,7 @@ get_failed: ...@@ -144,7 +144,7 @@ get_failed:
} }
ikey = uval; ikey = uval;
} else if (!matches(*argv, "okey")) { } else if (!matches(*argv, "okey")) {
unsigned uval; unsigned int uval;
NEXT_ARG(); NEXT_ARG();
if (strchr(*argv, '.')) if (strchr(*argv, '.'))
...@@ -207,7 +207,7 @@ static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -207,7 +207,7 @@ static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
return; return;
if (tb[IFLA_VTI_REMOTE]) { if (tb[IFLA_VTI_REMOTE]) {
unsigned addr = *(__u32 *)RTA_DATA(tb[IFLA_VTI_REMOTE]); unsigned int addr = *(__u32 *)RTA_DATA(tb[IFLA_VTI_REMOTE]);
if (addr) if (addr)
remote = format_host(AF_INET, 4, &addr, s1, sizeof(s1)); remote = format_host(AF_INET, 4, &addr, s1, sizeof(s1));
...@@ -216,7 +216,7 @@ static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -216,7 +216,7 @@ static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
fprintf(f, "remote %s ", remote); fprintf(f, "remote %s ", remote);
if (tb[IFLA_VTI_LOCAL]) { if (tb[IFLA_VTI_LOCAL]) {
unsigned addr = *(__u32 *)RTA_DATA(tb[IFLA_VTI_LOCAL]); unsigned int addr = *(__u32 *)RTA_DATA(tb[IFLA_VTI_LOCAL]);
if (addr) if (addr)
local = format_host(AF_INET, 4, &addr, s1, sizeof(s1)); local = format_host(AF_INET, 4, &addr, s1, sizeof(s1));
...@@ -225,7 +225,7 @@ static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -225,7 +225,7 @@ static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
fprintf(f, "local %s ", local); fprintf(f, "local %s ", local);
if (tb[IFLA_VTI_LINK] && *(__u32 *)RTA_DATA(tb[IFLA_VTI_LINK])) { if (tb[IFLA_VTI_LINK] && *(__u32 *)RTA_DATA(tb[IFLA_VTI_LINK])) {
unsigned link = *(__u32 *)RTA_DATA(tb[IFLA_VTI_LINK]); unsigned int link = *(__u32 *)RTA_DATA(tb[IFLA_VTI_LINK]);
const char *n = if_indextoname(link, s2); const char *n = if_indextoname(link, s2);
if (n) if (n)
......
...@@ -53,9 +53,9 @@ static int vti6_parse_opt(struct link_util *lu, int argc, char **argv, ...@@ -53,9 +53,9 @@ static int vti6_parse_opt(struct link_util *lu, int argc, char **argv,
struct rtattr *vtiinfo[IFLA_VTI_MAX + 1]; struct rtattr *vtiinfo[IFLA_VTI_MAX + 1];
struct in6_addr saddr; struct in6_addr saddr;
struct in6_addr daddr; struct in6_addr daddr;
unsigned ikey = 0; unsigned int ikey = 0;
unsigned okey = 0; unsigned int okey = 0;
unsigned link = 0; unsigned int link = 0;
int len; int len;
if (!(n->nlmsg_flags & NLM_F_CREATE)) { if (!(n->nlmsg_flags & NLM_F_CREATE)) {
...@@ -110,7 +110,7 @@ get_failed: ...@@ -110,7 +110,7 @@ get_failed:
while (argc > 0) { while (argc > 0) {
if (!matches(*argv, "key")) { if (!matches(*argv, "key")) {
unsigned uval; unsigned int uval;
NEXT_ARG(); NEXT_ARG();
if (strchr(*argv, '.')) if (strchr(*argv, '.'))
...@@ -126,7 +126,7 @@ get_failed: ...@@ -126,7 +126,7 @@ get_failed:
ikey = okey = uval; ikey = okey = uval;
} else if (!matches(*argv, "ikey")) { } else if (!matches(*argv, "ikey")) {
unsigned uval; unsigned int uval;
NEXT_ARG(); NEXT_ARG();
if (strchr(*argv, '.')) if (strchr(*argv, '.'))
...@@ -140,7 +140,7 @@ get_failed: ...@@ -140,7 +140,7 @@ get_failed:
} }
ikey = uval; ikey = uval;
} else if (!matches(*argv, "okey")) { } else if (!matches(*argv, "okey")) {
unsigned uval; unsigned int uval;
NEXT_ARG(); NEXT_ARG();
if (strchr(*argv, '.')) if (strchr(*argv, '.'))
...@@ -160,6 +160,7 @@ get_failed: ...@@ -160,6 +160,7 @@ get_failed:
exit(-1); exit(-1);
} else { } else {
inet_prefix addr; inet_prefix addr;
get_prefix(&addr, *argv, AF_INET6); get_prefix(&addr, *argv, AF_INET6);
memcpy(&daddr, addr.data, addr.bytelen); memcpy(&daddr, addr.data, addr.bytelen);
} }
...@@ -170,6 +171,7 @@ get_failed: ...@@ -170,6 +171,7 @@ get_failed:
exit(-1); exit(-1);
} else { } else {
inet_prefix addr; inet_prefix addr;
get_prefix(&addr, *argv, AF_INET6); get_prefix(&addr, *argv, AF_INET6);
memcpy(&saddr, addr.data, addr.bytelen); memcpy(&saddr, addr.data, addr.bytelen);
} }
...@@ -222,7 +224,7 @@ static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -222,7 +224,7 @@ static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
fprintf(f, "local %s ", local); fprintf(f, "local %s ", local);
if (tb[IFLA_VTI_LINK] && *(__u32 *)RTA_DATA(tb[IFLA_VTI_LINK])) { if (tb[IFLA_VTI_LINK] && *(__u32 *)RTA_DATA(tb[IFLA_VTI_LINK])) {
unsigned link = *(__u32 *)RTA_DATA(tb[IFLA_VTI_LINK]); unsigned int link = *(__u32 *)RTA_DATA(tb[IFLA_VTI_LINK]);
const char *n = if_indextoname(link, s2); const char *n = if_indextoname(link, s2);
if (n) if (n)
......
...@@ -25,13 +25,13 @@ ...@@ -25,13 +25,13 @@
#include "utils.h" #include "utils.h"
#include "libnetlink.h" #include "libnetlink.h"
int resolve_hosts = 0; int resolve_hosts;
static int init_phase = 1; static int init_phase = 1;
static void write_stamp(FILE *fp) static void write_stamp(FILE *fp)
{ {
char buf[128]; char buf[128];
struct nlmsghdr *n1 = (void*)buf; struct nlmsghdr *n1 = (void *)buf;
struct timeval tv; struct timeval tv;
n1->nlmsg_type = NLMSG_TSTAMP; n1->nlmsg_type = NLMSG_TSTAMP;
...@@ -40,18 +40,19 @@ static void write_stamp(FILE *fp) ...@@ -40,18 +40,19 @@ static void write_stamp(FILE *fp)
n1->nlmsg_pid = 0; n1->nlmsg_pid = 0;
n1->nlmsg_len = NLMSG_LENGTH(4*2); n1->nlmsg_len = NLMSG_LENGTH(4*2);
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
((__u32*)NLMSG_DATA(n1))[0] = tv.tv_sec; ((__u32 *)NLMSG_DATA(n1))[0] = tv.tv_sec;
((__u32*)NLMSG_DATA(n1))[1] = tv.tv_usec; ((__u32 *)NLMSG_DATA(n1))[1] = tv.tv_usec;
fwrite((void*)n1, 1, NLMSG_ALIGN(n1->nlmsg_len), fp); fwrite((void *)n1, 1, NLMSG_ALIGN(n1->nlmsg_len), fp);
} }
static int dump_msg(const struct sockaddr_nl *who, struct rtnl_ctrl_data *ctrl, static int dump_msg(const struct sockaddr_nl *who, struct rtnl_ctrl_data *ctrl,
struct nlmsghdr *n, void *arg) struct nlmsghdr *n, void *arg)
{ {
FILE *fp = (FILE*)arg; FILE *fp = (FILE *)arg;
if (!init_phase) if (!init_phase)
write_stamp(fp); write_stamp(fp);
fwrite((void*)n, 1, NLMSG_ALIGN(n->nlmsg_len), fp); fwrite((void *)n, 1, NLMSG_ALIGN(n->nlmsg_len), fp);
fflush(fp); fflush(fp);
return 0; return 0;
} }
...@@ -75,7 +76,7 @@ main(int argc, char **argv) ...@@ -75,7 +76,7 @@ main(int argc, char **argv)
FILE *fp; FILE *fp;
struct rtnl_handle rth; struct rtnl_handle rth;
int family = AF_UNSPEC; int family = AF_UNSPEC;
unsigned groups = ~0U; unsigned int groups = ~0U;
int llink = 0; int llink = 0;
int laddr = 0; int laddr = 0;
int lroute = 0; int lroute = 0;
...@@ -115,13 +116,13 @@ main(int argc, char **argv) ...@@ -115,13 +116,13 @@ main(int argc, char **argv)
usage(); usage();
file = argv[1]; file = argv[1];
} else if (matches(argv[1], "link") == 0) { } else if (matches(argv[1], "link") == 0) {
llink=1; llink = 1;
groups = 0; groups = 0;
} else if (matches(argv[1], "address") == 0) { } else if (matches(argv[1], "address") == 0) {
laddr=1; laddr = 1;
groups = 0; groups = 0;
} else if (matches(argv[1], "route") == 0) { } else if (matches(argv[1], "route") == 0) {
lroute=1; lroute = 1;
groups = 0; groups = 0;
} else if (strcmp(argv[1], "all") == 0) { } else if (strcmp(argv[1], "all") == 0) {
groups = ~0U; groups = ~0U;
...@@ -176,7 +177,7 @@ main(int argc, char **argv) ...@@ -176,7 +177,7 @@ main(int argc, char **argv)
init_phase = 0; init_phase = 0;
if (rtnl_listen(&rth, dump_msg, (void*)fp) < 0) if (rtnl_listen(&rth, dump_msg, (void *)fp) < 0)
exit(2); exit(2);
exit(0); exit(0);
......
...@@ -168,6 +168,7 @@ static int process_msg(const struct sockaddr_nl *who, struct nlmsghdr *n, ...@@ -168,6 +168,7 @@ static int process_msg(const struct sockaddr_nl *who, struct nlmsghdr *n,
if (f.flushb) { if (f.flushb) {
struct nlmsghdr *fn; struct nlmsghdr *fn;
TCPM_REQUEST(req2, 128, TCP_METRICS_CMD_DEL, NLM_F_REQUEST); TCPM_REQUEST(req2, 128, TCP_METRICS_CMD_DEL, NLM_F_REQUEST);
addattr_l(&req2.n, sizeof(req2), atype, &daddr.data, addattr_l(&req2.n, sizeof(req2), atype, &daddr.data,
...@@ -333,6 +334,7 @@ static int tcpm_do_cmd(int cmd, int argc, char **argv) ...@@ -333,6 +334,7 @@ static int tcpm_do_cmd(int cmd, int argc, char **argv)
if (strcmp(*argv, "src") == 0 || if (strcmp(*argv, "src") == 0 ||
strcmp(*argv, "source") == 0) { strcmp(*argv, "source") == 0) {
char *who = *argv; char *who = *argv;
NEXT_ARG(); NEXT_ARG();
if (matches(*argv, "help") == 0) if (matches(*argv, "help") == 0)
usage(); usage();
...@@ -354,6 +356,7 @@ static int tcpm_do_cmd(int cmd, int argc, char **argv) ...@@ -354,6 +356,7 @@ static int tcpm_do_cmd(int cmd, int argc, char **argv)
} }
} else { } else {
char *who = "address"; char *who = "address";
if (strcmp(*argv, "addr") == 0 || if (strcmp(*argv, "addr") == 0 ||
strcmp(*argv, "address") == 0) { strcmp(*argv, "address") == 0) {
who = *argv; who = *argv;
...@@ -504,7 +507,7 @@ int do_tcp_metrics(int argc, char **argv) ...@@ -504,7 +507,7 @@ int do_tcp_metrics(int argc, char **argv)
if (matches(argv[0], "help") == 0) if (matches(argv[0], "help") == 0)
usage(); usage();
fprintf(stderr, "Command \"%s\" is unknown, " fprintf(stderr, "Command \"%s\" is unknown, try \"ip tcp_metrics help\".\n",
"try \"ip tcp_metrics help\".\n", *argv); *argv);
exit(-1); exit(-1);
} }
...@@ -72,7 +72,7 @@ int tnl_get_ioctl(const char *basedev, void *p) ...@@ -72,7 +72,7 @@ int tnl_get_ioctl(const char *basedev, void *p)
int err; int err;
strncpy(ifr.ifr_name, basedev, IFNAMSIZ); strncpy(ifr.ifr_name, basedev, IFNAMSIZ);
ifr.ifr_ifru.ifru_data = (void*)p; ifr.ifr_ifru.ifru_data = (void *)p;
fd = socket(preferred_family, SOCK_DGRAM, 0); fd = socket(preferred_family, SOCK_DGRAM, 0);
if (fd < 0) { if (fd < 0) {
...@@ -183,7 +183,7 @@ int tnl_ioctl_get_6rd(const char *name, void *p) ...@@ -183,7 +183,7 @@ int tnl_ioctl_get_6rd(const char *name, void *p)
__be32 tnl_parse_key(const char *name, const char *key) __be32 tnl_parse_key(const char *name, const char *key)
{ {
unsigned uval; unsigned int uval;
if (strchr(key, '.')) if (strchr(key, '.'))
return get_addr32(key); return get_addr32(key);
...@@ -209,10 +209,10 @@ void tnl_print_stats(const char *buf) ...@@ -209,10 +209,10 @@ void tnl_print_stats(const char *buf)
tx_fifo, tx_colls, tx_carrier, rx_multi; tx_fifo, tx_colls, tx_carrier, rx_multi;
if (sscanf(buf, "%lu%lu%lu%lu%lu%lu%lu%*d%lu%lu%lu%lu%lu%lu%lu", if (sscanf(buf, "%lu%lu%lu%lu%lu%lu%lu%*d%lu%lu%lu%lu%lu%lu%lu",
&rx_bytes, &rx_packets, &rx_errs, &rx_drops, &rx_bytes, &rx_packets, &rx_errs, &rx_drops,
&rx_fifo, &rx_frame, &rx_multi, &rx_fifo, &rx_frame, &rx_multi,
&tx_bytes, &tx_packets, &tx_errs, &tx_drops, &tx_bytes, &tx_packets, &tx_errs, &tx_drops,
&tx_fifo, &tx_colls, &tx_carrier) != 14) &tx_fifo, &tx_colls, &tx_carrier) != 14)
return; return;
printf("%s", _SL_); printf("%s", _SL_);
......
...@@ -46,10 +46,10 @@ static void usage(void) ...@@ -46,10 +46,10 @@ static void usage(void)
static int xfrm_acquire_print(const struct sockaddr_nl *who, static int xfrm_acquire_print(const struct sockaddr_nl *who,
struct nlmsghdr *n, void *arg) struct nlmsghdr *n, void *arg)
{ {
FILE *fp = (FILE*)arg; FILE *fp = (FILE *)arg;
struct xfrm_user_acquire *xacq = NLMSG_DATA(n); struct xfrm_user_acquire *xacq = NLMSG_DATA(n);
int len = n->nlmsg_len; int len = n->nlmsg_len;
struct rtattr * tb[XFRMA_MAX+1]; struct rtattr *tb[XFRMA_MAX+1];
__u16 family; __u16 family;
len -= NLMSG_LENGTH(sizeof(*xacq)); len -= NLMSG_LENGTH(sizeof(*xacq));
...@@ -71,6 +71,7 @@ static int xfrm_acquire_print(const struct sockaddr_nl *who, ...@@ -71,6 +71,7 @@ static int xfrm_acquire_print(const struct sockaddr_nl *who,
fprintf(fp, "proto %s ", strxf_xfrmproto(xacq->id.proto)); fprintf(fp, "proto %s ", strxf_xfrmproto(xacq->id.proto));
if (show_stats > 0 || xacq->id.spi) { if (show_stats > 0 || xacq->id.spi) {
__u32 spi = ntohl(xacq->id.spi); __u32 spi = ntohl(xacq->id.spi);
fprintf(fp, "spi 0x%08x", spi); fprintf(fp, "spi 0x%08x", spi);
if (show_stats > 0) if (show_stats > 0)
fprintf(fp, "(%u)", spi); fprintf(fp, "(%u)", spi);
...@@ -107,7 +108,7 @@ static int xfrm_acquire_print(const struct sockaddr_nl *who, ...@@ -107,7 +108,7 @@ static int xfrm_acquire_print(const struct sockaddr_nl *who,
static int xfrm_state_flush_print(const struct sockaddr_nl *who, static int xfrm_state_flush_print(const struct sockaddr_nl *who,
struct nlmsghdr *n, void *arg) struct nlmsghdr *n, void *arg)
{ {
FILE *fp = (FILE*)arg; FILE *fp = (FILE *)arg;
struct xfrm_usersa_flush *xsf = NLMSG_DATA(n); struct xfrm_usersa_flush *xsf = NLMSG_DATA(n);
int len = n->nlmsg_len; int len = n->nlmsg_len;
const char *str; const char *str;
...@@ -137,8 +138,8 @@ static int xfrm_state_flush_print(const struct sockaddr_nl *who, ...@@ -137,8 +138,8 @@ static int xfrm_state_flush_print(const struct sockaddr_nl *who,
static int xfrm_policy_flush_print(const struct sockaddr_nl *who, static int xfrm_policy_flush_print(const struct sockaddr_nl *who,
struct nlmsghdr *n, void *arg) struct nlmsghdr *n, void *arg)
{ {
struct rtattr * tb[XFRMA_MAX+1]; struct rtattr *tb[XFRMA_MAX+1];
FILE *fp = (FILE*)arg; FILE *fp = (FILE *)arg;
int len = n->nlmsg_len; int len = n->nlmsg_len;
len -= NLMSG_SPACE(0); len -= NLMSG_SPACE(0);
...@@ -175,10 +176,10 @@ static int xfrm_policy_flush_print(const struct sockaddr_nl *who, ...@@ -175,10 +176,10 @@ static int xfrm_policy_flush_print(const struct sockaddr_nl *who,
static int xfrm_report_print(const struct sockaddr_nl *who, static int xfrm_report_print(const struct sockaddr_nl *who,
struct nlmsghdr *n, void *arg) struct nlmsghdr *n, void *arg)
{ {
FILE *fp = (FILE*)arg; FILE *fp = (FILE *)arg;
struct xfrm_user_report *xrep = NLMSG_DATA(n); struct xfrm_user_report *xrep = NLMSG_DATA(n);
int len = n->nlmsg_len; int len = n->nlmsg_len;
struct rtattr * tb[XFRMA_MAX+1]; struct rtattr *tb[XFRMA_MAX+1];
__u16 family; __u16 family;
len -= NLMSG_LENGTH(sizeof(*xrep)); len -= NLMSG_LENGTH(sizeof(*xrep));
...@@ -210,7 +211,8 @@ static int xfrm_report_print(const struct sockaddr_nl *who, ...@@ -210,7 +211,8 @@ static int xfrm_report_print(const struct sockaddr_nl *who,
static void xfrm_ae_flags_print(__u32 flags, void *arg) static void xfrm_ae_flags_print(__u32 flags, void *arg)
{ {
FILE *fp = (FILE*)arg; FILE *fp = (FILE *)arg;
fprintf(fp, " (0x%x) ", flags); fprintf(fp, " (0x%x) ", flags);
if (!flags) if (!flags)
return; return;
...@@ -241,13 +243,13 @@ static void xfrm_usersa_print(const struct xfrm_usersa_id *sa_id, __u32 reqid, F ...@@ -241,13 +243,13 @@ static void xfrm_usersa_print(const struct xfrm_usersa_id *sa_id, __u32 reqid, F
static int xfrm_ae_print(const struct sockaddr_nl *who, static int xfrm_ae_print(const struct sockaddr_nl *who,
struct nlmsghdr *n, void *arg) struct nlmsghdr *n, void *arg)
{ {
FILE *fp = (FILE*)arg; FILE *fp = (FILE *)arg;
struct xfrm_aevent_id *id = NLMSG_DATA(n); struct xfrm_aevent_id *id = NLMSG_DATA(n);
char abuf[256]; char abuf[256];
fprintf(fp, "Async event "); fprintf(fp, "Async event ");
xfrm_ae_flags_print(id->flags, arg); xfrm_ae_flags_print(id->flags, arg);
fprintf(fp,"\n\t"); fprintf(fp, "\n\t");
memset(abuf, '\0', sizeof(abuf)); memset(abuf, '\0', sizeof(abuf));
fprintf(fp, "src %s ", rt_addr_n2a(id->sa_id.family, fprintf(fp, "src %s ", rt_addr_n2a(id->sa_id.family,
sizeof(id->saddr), &id->saddr, sizeof(id->saddr), &id->saddr,
...@@ -272,7 +274,7 @@ static void xfrm_print_addr(FILE *fp, int family, xfrm_address_t *a) ...@@ -272,7 +274,7 @@ static void xfrm_print_addr(FILE *fp, int family, xfrm_address_t *a)
static int xfrm_mapping_print(const struct sockaddr_nl *who, static int xfrm_mapping_print(const struct sockaddr_nl *who,
struct nlmsghdr *n, void *arg) struct nlmsghdr *n, void *arg)
{ {
FILE *fp = (FILE*)arg; FILE *fp = (FILE *)arg;
struct xfrm_user_mapping *map = NLMSG_DATA(n); struct xfrm_user_mapping *map = NLMSG_DATA(n);
fprintf(fp, "Mapping change "); fprintf(fp, "Mapping change ");
...@@ -293,7 +295,7 @@ static int xfrm_accept_msg(const struct sockaddr_nl *who, ...@@ -293,7 +295,7 @@ static int xfrm_accept_msg(const struct sockaddr_nl *who,
struct rtnl_ctrl_data *ctrl, struct rtnl_ctrl_data *ctrl,
struct nlmsghdr *n, void *arg) struct nlmsghdr *n, void *arg)
{ {
FILE *fp = (FILE*)arg; FILE *fp = (FILE *)arg;
if (timestamp) if (timestamp)
print_timestamp(fp); print_timestamp(fp);
...@@ -353,13 +355,13 @@ extern struct rtnl_handle rth; ...@@ -353,13 +355,13 @@ extern struct rtnl_handle rth;
int do_xfrm_monitor(int argc, char **argv) int do_xfrm_monitor(int argc, char **argv)
{ {
char *file = NULL; char *file = NULL;
unsigned groups = ~((unsigned)0); /* XXX */ unsigned int groups = ~((unsigned)0); /* XXX */
int lacquire=0; int lacquire = 0;
int lexpire=0; int lexpire = 0;
int laevent=0; int laevent = 0;
int lpolicy=0; int lpolicy = 0;
int lsa=0; int lsa = 0;
int lreport=0; int lreport = 0;
rtnl_close(&rth); rtnl_close(&rth);
...@@ -370,22 +372,22 @@ int do_xfrm_monitor(int argc, char **argv) ...@@ -370,22 +372,22 @@ int do_xfrm_monitor(int argc, char **argv)
} else if (matches(*argv, "all-nsid") == 0) { } else if (matches(*argv, "all-nsid") == 0) {
listen_all_nsid = 1; listen_all_nsid = 1;
} else if (matches(*argv, "acquire") == 0) { } else if (matches(*argv, "acquire") == 0) {
lacquire=1; lacquire = 1;
groups = 0; groups = 0;
} else if (matches(*argv, "expire") == 0) { } else if (matches(*argv, "expire") == 0) {
lexpire=1; lexpire = 1;
groups = 0; groups = 0;
} else if (matches(*argv, "SA") == 0) { } else if (matches(*argv, "SA") == 0) {
lsa=1; lsa = 1;
groups = 0; groups = 0;
} else if (matches(*argv, "aevent") == 0) { } else if (matches(*argv, "aevent") == 0) {
laevent=1; laevent = 1;
groups = 0; groups = 0;
} else if (matches(*argv, "policy") == 0) { } else if (matches(*argv, "policy") == 0) {
lpolicy=1; lpolicy = 1;
groups = 0; groups = 0;
} else if (matches(*argv, "report") == 0) { } else if (matches(*argv, "report") == 0) {
lreport=1; lreport = 1;
groups = 0; groups = 0;
} else if (matches(*argv, "help") == 0) { } else if (matches(*argv, "help") == 0) {
usage(); usage();
...@@ -428,7 +430,7 @@ int do_xfrm_monitor(int argc, char **argv) ...@@ -428,7 +430,7 @@ int do_xfrm_monitor(int argc, char **argv)
if (listen_all_nsid && rtnl_listen_all_nsid(&rth) < 0) if (listen_all_nsid && rtnl_listen_all_nsid(&rth) < 0)
exit(1); exit(1);
if (rtnl_listen(&rth, xfrm_accept_msg, (void*)stdout) < 0) if (rtnl_listen(&rth, xfrm_accept_msg, (void *)stdout) < 0)
exit(2); exit(2);
return 0; return 0;
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
#include "xfrm.h" #include "xfrm.h"
#include "ip_common.h" #include "ip_common.h"
//#define NLMSG_DELETEALL_BUF_SIZE (4096-512) /* #define NLMSG_DELETEALL_BUF_SIZE (4096-512) */
#define NLMSG_DELETEALL_BUF_SIZE 8192 #define NLMSG_DELETEALL_BUF_SIZE 8192
/* /*
...@@ -241,7 +241,7 @@ int xfrm_sctx_parse(char *ctxstr, char *s, ...@@ -241,7 +241,7 @@ int xfrm_sctx_parse(char *ctxstr, char *s,
return 0; return 0;
} }
static int xfrm_policy_modify(int cmd, unsigned flags, int argc, char **argv) static int xfrm_policy_modify(int cmd, unsigned int flags, int argc, char **argv)
{ {
struct rtnl_handle rth; struct rtnl_handle rth;
struct { struct {
...@@ -376,7 +376,7 @@ static int xfrm_policy_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -376,7 +376,7 @@ static int xfrm_policy_modify(int cmd, unsigned flags, int argc, char **argv)
int r = addattr_l(&req.n, sizeof(req.buf), XFRMA_MARK, int r = addattr_l(&req.n, sizeof(req.buf), XFRMA_MARK,
(void *)&mark, sizeof(mark)); (void *)&mark, sizeof(mark));
if (r < 0) { if (r < 0) {
fprintf(stderr, "%s: XFRMA_MARK failed\n",__func__); fprintf(stderr, "%s: XFRMA_MARK failed\n", __func__);
exit(1); exit(1);
} }
} }
...@@ -459,13 +459,13 @@ static int xfrm_policy_filter_match(struct xfrm_userpolicy_info *xpinfo, ...@@ -459,13 +459,13 @@ static int xfrm_policy_filter_match(struct xfrm_userpolicy_info *xpinfo,
int xfrm_policy_print(const struct sockaddr_nl *who, struct nlmsghdr *n, int xfrm_policy_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
void *arg) void *arg)
{ {
struct rtattr * tb[XFRMA_MAX+1]; struct rtattr *tb[XFRMA_MAX+1];
struct rtattr * rta; struct rtattr *rta;
struct xfrm_userpolicy_info *xpinfo = NULL; struct xfrm_userpolicy_info *xpinfo = NULL;
struct xfrm_user_polexpire *xpexp = NULL; struct xfrm_user_polexpire *xpexp = NULL;
struct xfrm_userpolicy_id *xpid = NULL; struct xfrm_userpolicy_id *xpid = NULL;
__u8 ptype = XFRM_POLICY_TYPE_MAIN; __u8 ptype = XFRM_POLICY_TYPE_MAIN;
FILE *fp = (FILE*)arg; FILE *fp = (FILE *)arg;
int len = n->nlmsg_len; int len = n->nlmsg_len;
if (n->nlmsg_type != XFRM_MSG_NEWPOLICY && if (n->nlmsg_type != XFRM_MSG_NEWPOLICY &&
...@@ -526,7 +526,7 @@ int xfrm_policy_print(const struct sockaddr_nl *who, struct nlmsghdr *n, ...@@ -526,7 +526,7 @@ int xfrm_policy_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
fprintf(fp, "Expired "); fprintf(fp, "Expired ");
if (n->nlmsg_type == XFRM_MSG_DELPOLICY) { if (n->nlmsg_type == XFRM_MSG_DELPOLICY) {
//xfrm_policy_id_print(); /* xfrm_policy_id_print(); */
if (!tb[XFRMA_POLICY]) { if (!tb[XFRMA_POLICY]) {
fprintf(stderr, "Buggy XFRM_MSG_DELPOLICY: no XFRMA_POLICY\n"); fprintf(stderr, "Buggy XFRM_MSG_DELPOLICY: no XFRMA_POLICY\n");
return -1; return -1;
...@@ -659,7 +659,7 @@ static int xfrm_policy_get_or_delete(int argc, char **argv, int delete, ...@@ -659,7 +659,7 @@ static int xfrm_policy_get_or_delete(int argc, char **argv, int delete,
int r = addattr_l(&req.n, sizeof(req.buf), XFRMA_MARK, int r = addattr_l(&req.n, sizeof(req.buf), XFRMA_MARK,
(void *)&mark, sizeof(mark)); (void *)&mark, sizeof(mark));
if (r < 0) { if (r < 0) {
fprintf(stderr, "%s: XFRMA_MARK failed\n",__func__); fprintf(stderr, "%s: XFRMA_MARK failed\n", __func__);
exit(1); exit(1);
} }
} }
...@@ -691,7 +691,7 @@ static int xfrm_policy_get(int argc, char **argv) ...@@ -691,7 +691,7 @@ static int xfrm_policy_get(int argc, char **argv)
xfrm_policy_get_or_delete(argc, argv, 0, n, sizeof(buf)); xfrm_policy_get_or_delete(argc, argv, 0, n, sizeof(buf));
if (xfrm_policy_print(NULL, n, (void*)stdout) < 0) { if (xfrm_policy_print(NULL, n, (void *)stdout) < 0) {
fprintf(stderr, "An error :-)\n"); fprintf(stderr, "An error :-)\n");
exit(1); exit(1);
} }
...@@ -761,7 +761,7 @@ static int xfrm_policy_keep(const struct sockaddr_nl *who, ...@@ -761,7 +761,7 @@ static int xfrm_policy_keep(const struct sockaddr_nl *who,
xpid->index = xpinfo->index; xpid->index = xpinfo->index;
xb->offset += new_n->nlmsg_len; xb->offset += new_n->nlmsg_len;
xb->nlmsg_count ++; xb->nlmsg_count++;
return 0; return 0;
} }
...@@ -915,12 +915,12 @@ static int xfrm_policy_list_or_deleteall(int argc, char **argv, int deleteall) ...@@ -915,12 +915,12 @@ static int xfrm_policy_list_or_deleteall(int argc, char **argv, int deleteall)
exit(0); exit(0);
} }
static int print_spdinfo( struct nlmsghdr *n, void *arg) static int print_spdinfo(struct nlmsghdr *n, void *arg)
{ {
FILE *fp = (FILE*)arg; FILE *fp = (FILE *)arg;
__u32 *f = NLMSG_DATA(n); __u32 *f = NLMSG_DATA(n);
struct rtattr * tb[XFRMA_SPD_MAX+1]; struct rtattr *tb[XFRMA_SPD_MAX+1];
struct rtattr * rta; struct rtattr *rta;
int len = n->nlmsg_len; int len = n->nlmsg_len;
...@@ -933,7 +933,7 @@ static int print_spdinfo( struct nlmsghdr *n, void *arg) ...@@ -933,7 +933,7 @@ static int print_spdinfo( struct nlmsghdr *n, void *arg)
rta = XFRMSAPD_RTA(f); rta = XFRMSAPD_RTA(f);
parse_rtattr(tb, XFRMA_SPD_MAX, rta, len); parse_rtattr(tb, XFRMA_SPD_MAX, rta, len);
fprintf(fp,"\t SPD"); fprintf(fp, "\t SPD");
if (tb[XFRMA_SPD_INFO]) { if (tb[XFRMA_SPD_INFO]) {
struct xfrmu_spdinfo *si; struct xfrmu_spdinfo *si;
...@@ -942,16 +942,16 @@ static int print_spdinfo( struct nlmsghdr *n, void *arg) ...@@ -942,16 +942,16 @@ static int print_spdinfo( struct nlmsghdr *n, void *arg)
return -1; return -1;
} }
si = RTA_DATA(tb[XFRMA_SPD_INFO]); si = RTA_DATA(tb[XFRMA_SPD_INFO]);
fprintf(fp," IN %d", si->incnt); fprintf(fp, " IN %d", si->incnt);
fprintf(fp," OUT %d", si->outcnt); fprintf(fp, " OUT %d", si->outcnt);
fprintf(fp," FWD %d", si->fwdcnt); fprintf(fp, " FWD %d", si->fwdcnt);
if (show_stats) { if (show_stats) {
fprintf(fp," (Sock:"); fprintf(fp, " (Sock:");
fprintf(fp," IN %d", si->inscnt); fprintf(fp, " IN %d", si->inscnt);
fprintf(fp," OUT %d", si->outscnt); fprintf(fp, " OUT %d", si->outscnt);
fprintf(fp," FWD %d", si->fwdscnt); fprintf(fp, " FWD %d", si->fwdscnt);
fprintf(fp,")"); fprintf(fp, ")");
} }
fprintf(fp, "%s", _SL_); fprintf(fp, "%s", _SL_);
...@@ -965,34 +965,36 @@ static int print_spdinfo( struct nlmsghdr *n, void *arg) ...@@ -965,34 +965,36 @@ static int print_spdinfo( struct nlmsghdr *n, void *arg)
return -1; return -1;
} }
sh = RTA_DATA(tb[XFRMA_SPD_HINFO]); sh = RTA_DATA(tb[XFRMA_SPD_HINFO]);
fprintf(fp,"\t SPD buckets:"); fprintf(fp, "\t SPD buckets:");
fprintf(fp," count %d", sh->spdhcnt); fprintf(fp, " count %d", sh->spdhcnt);
fprintf(fp," Max %d", sh->spdhmcnt); fprintf(fp, " Max %d", sh->spdhmcnt);
fprintf(fp, "%s", _SL_); fprintf(fp, "%s", _SL_);
} }
if (tb[XFRMA_SPD_IPV4_HTHRESH]) { if (tb[XFRMA_SPD_IPV4_HTHRESH]) {
struct xfrmu_spdhthresh *th; struct xfrmu_spdhthresh *th;
if (RTA_PAYLOAD(tb[XFRMA_SPD_IPV4_HTHRESH]) < sizeof(*th)) { if (RTA_PAYLOAD(tb[XFRMA_SPD_IPV4_HTHRESH]) < sizeof(*th)) {
fprintf(stderr, "SPDinfo: Wrong len %d\n", len); fprintf(stderr, "SPDinfo: Wrong len %d\n", len);
return -1; return -1;
} }
th = RTA_DATA(tb[XFRMA_SPD_IPV4_HTHRESH]); th = RTA_DATA(tb[XFRMA_SPD_IPV4_HTHRESH]);
fprintf(fp,"\t SPD IPv4 thresholds:"); fprintf(fp, "\t SPD IPv4 thresholds:");
fprintf(fp," local %d", th->lbits); fprintf(fp, " local %d", th->lbits);
fprintf(fp," remote %d", th->rbits); fprintf(fp, " remote %d", th->rbits);
fprintf(fp, "%s", _SL_); fprintf(fp, "%s", _SL_);
} }
if (tb[XFRMA_SPD_IPV6_HTHRESH]) { if (tb[XFRMA_SPD_IPV6_HTHRESH]) {
struct xfrmu_spdhthresh *th; struct xfrmu_spdhthresh *th;
if (RTA_PAYLOAD(tb[XFRMA_SPD_IPV6_HTHRESH]) < sizeof(*th)) { if (RTA_PAYLOAD(tb[XFRMA_SPD_IPV6_HTHRESH]) < sizeof(*th)) {
fprintf(stderr, "SPDinfo: Wrong len %d\n", len); fprintf(stderr, "SPDinfo: Wrong len %d\n", len);
return -1; return -1;
} }
th = RTA_DATA(tb[XFRMA_SPD_IPV6_HTHRESH]); th = RTA_DATA(tb[XFRMA_SPD_IPV6_HTHRESH]);
fprintf(fp,"\t SPD IPv6 thresholds:"); fprintf(fp, "\t SPD IPv6 thresholds:");
fprintf(fp," local %d", th->lbits); fprintf(fp, " local %d", th->lbits);
fprintf(fp," remote %d", th->rbits); fprintf(fp, " remote %d", th->rbits);
fprintf(fp, "%s", _SL_); fprintf(fp, "%s", _SL_);
} }
} }
...@@ -1000,7 +1002,7 @@ static int print_spdinfo( struct nlmsghdr *n, void *arg) ...@@ -1000,7 +1002,7 @@ static int print_spdinfo( struct nlmsghdr *n, void *arg)
if (oneline) if (oneline)
fprintf(fp, "\n"); fprintf(fp, "\n");
return 0; return 0;
} }
static int xfrm_spd_setinfo(int argc, char **argv) static int xfrm_spd_setinfo(int argc, char **argv)
...@@ -1093,7 +1095,7 @@ static int xfrm_spd_getinfo(int argc, char **argv) ...@@ -1093,7 +1095,7 @@ static int xfrm_spd_getinfo(int argc, char **argv)
if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0)
exit(2); exit(2);
print_spdinfo(&req.n, (void*)stdout); print_spdinfo(&req.n, (void *)stdout);
rtnl_close(&rth); rtnl_close(&rth);
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include "xfrm.h" #include "xfrm.h"
#include "ip_common.h" #include "ip_common.h"
//#define NLMSG_DELETEALL_BUF_SIZE (4096-512) /* #define NLMSG_DELETEALL_BUF_SIZE (4096-512) */
#define NLMSG_DELETEALL_BUF_SIZE 8192 #define NLMSG_DELETEALL_BUF_SIZE 8192
/* /*
...@@ -107,7 +107,7 @@ static void usage(void) ...@@ -107,7 +107,7 @@ static void usage(void)
fprintf(stderr, "LIMIT-LIST := [ LIMIT-LIST ] limit LIMIT\n"); fprintf(stderr, "LIMIT-LIST := [ LIMIT-LIST ] limit LIMIT\n");
fprintf(stderr, "LIMIT := { time-soft | time-hard | time-use-soft | time-use-hard } SECONDS |\n"); fprintf(stderr, "LIMIT := { time-soft | time-hard | time-use-soft | time-use-hard } SECONDS |\n");
fprintf(stderr, " { byte-soft | byte-hard } SIZE | { packet-soft | packet-hard } COUNT\n"); fprintf(stderr, " { byte-soft | byte-hard } SIZE | { packet-soft | packet-hard } COUNT\n");
fprintf(stderr, "ENCAP := { espinudp | espinudp-nonike } SPORT DPORT OADDR\n"); fprintf(stderr, "ENCAP := { espinudp | espinudp-nonike } SPORT DPORT OADDR\n");
exit(-1); exit(-1);
} }
...@@ -142,7 +142,7 @@ static int xfrm_algo_parse(struct xfrm_algo *alg, enum xfrm_attr_type_t type, ...@@ -142,7 +142,7 @@ static int xfrm_algo_parse(struct xfrm_algo *alg, enum xfrm_attr_type_t type,
if (len > max) if (len > max)
invarg("ALGO-KEYMAT value makes buffer overflow\n", key); invarg("ALGO-KEYMAT value makes buffer overflow\n", key);
for (i = - (plen % 2), j = 0; j < len; i += 2, j++) { for (i = -(plen % 2), j = 0; j < len; i += 2, j++) {
char vbuf[3]; char vbuf[3];
__u8 val; __u8 val;
...@@ -266,13 +266,13 @@ static int xfrm_state_extra_flag_parse(__u32 *extra_flags, int *argcp, char ***a ...@@ -266,13 +266,13 @@ static int xfrm_state_extra_flag_parse(__u32 *extra_flags, int *argcp, char ***a
return 0; return 0;
} }
static int xfrm_state_modify(int cmd, unsigned flags, int argc, char **argv) static int xfrm_state_modify(int cmd, unsigned int flags, int argc, char **argv)
{ {
struct rtnl_handle rth; struct rtnl_handle rth;
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
struct xfrm_usersa_info xsinfo; struct xfrm_usersa_info xsinfo;
char buf[RTA_BUF_SIZE]; char buf[RTA_BUF_SIZE];
} req; } req;
struct xfrm_replay_state replay; struct xfrm_replay_state replay;
struct xfrm_replay_state_esn replay_esn; struct xfrm_replay_state_esn replay_esn;
...@@ -356,7 +356,7 @@ static int xfrm_state_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -356,7 +356,7 @@ static int xfrm_state_modify(int cmd, unsigned flags, int argc, char **argv)
} else if (strcmp(*argv, "encap") == 0) { } else if (strcmp(*argv, "encap") == 0) {
struct xfrm_encap_tmpl encap; struct xfrm_encap_tmpl encap;
inet_prefix oa; inet_prefix oa;
NEXT_ARG(); NEXT_ARG();
xfrm_encap_type_parse(&encap.encap_type, &argc, &argv); xfrm_encap_type_parse(&encap.encap_type, &argc, &argv);
NEXT_ARG(); NEXT_ARG();
if (get_u16(&encap.encap_sport, *argv, 0)) if (get_u16(&encap.encap_sport, *argv, 0))
...@@ -408,6 +408,7 @@ static int xfrm_state_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -408,6 +408,7 @@ static int xfrm_state_modify(int cmd, unsigned flags, int argc, char **argv)
} else { } else {
/* try to assume ALGO */ /* try to assume ALGO */
int type = xfrm_algotype_getbyname(*argv); int type = xfrm_algotype_getbyname(*argv);
switch (type) { switch (type) {
case XFRMA_ALG_AEAD: case XFRMA_ALG_AEAD:
case XFRMA_ALG_CRYPT: case XFRMA_ALG_CRYPT:
...@@ -701,7 +702,7 @@ static int xfrm_state_allocspi(int argc, char **argv) ...@@ -701,7 +702,7 @@ static int xfrm_state_allocspi(int argc, char **argv)
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
struct xfrm_userspi_info xspi; struct xfrm_userspi_info xspi;
char buf[RTA_BUF_SIZE]; char buf[RTA_BUF_SIZE];
} req; } req;
char *idp = NULL; char *idp = NULL;
char *minp = NULL; char *minp = NULL;
...@@ -827,7 +828,7 @@ static int xfrm_state_allocspi(int argc, char **argv) ...@@ -827,7 +828,7 @@ static int xfrm_state_allocspi(int argc, char **argv)
if (rtnl_talk(&rth, &req.n, res_n, sizeof(res_buf)) < 0) if (rtnl_talk(&rth, &req.n, res_n, sizeof(res_buf)) < 0)
exit(2); exit(2);
if (xfrm_state_print(NULL, res_n, (void*)stdout) < 0) { if (xfrm_state_print(NULL, res_n, (void *)stdout) < 0) {
fprintf(stderr, "An error :-)\n"); fprintf(stderr, "An error :-)\n");
exit(1); exit(1);
} }
...@@ -868,9 +869,9 @@ static int xfrm_state_filter_match(struct xfrm_usersa_info *xsinfo) ...@@ -868,9 +869,9 @@ static int xfrm_state_filter_match(struct xfrm_usersa_info *xsinfo)
int xfrm_state_print(const struct sockaddr_nl *who, struct nlmsghdr *n, int xfrm_state_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
void *arg) void *arg)
{ {
FILE *fp = (FILE*)arg; FILE *fp = (FILE *)arg;
struct rtattr * tb[XFRMA_MAX+1]; struct rtattr *tb[XFRMA_MAX+1];
struct rtattr * rta; struct rtattr *rta;
struct xfrm_usersa_info *xsinfo = NULL; struct xfrm_usersa_info *xsinfo = NULL;
struct xfrm_user_expire *xexp = NULL; struct xfrm_user_expire *xexp = NULL;
struct xfrm_usersa_id *xsid = NULL; struct xfrm_usersa_id *xsid = NULL;
...@@ -924,7 +925,7 @@ int xfrm_state_print(const struct sockaddr_nl *who, struct nlmsghdr *n, ...@@ -924,7 +925,7 @@ int xfrm_state_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
parse_rtattr(tb, XFRMA_MAX, rta, len); parse_rtattr(tb, XFRMA_MAX, rta, len);
if (n->nlmsg_type == XFRM_MSG_DELSA) { if (n->nlmsg_type == XFRM_MSG_DELSA) {
//xfrm_policy_id_print(); /* xfrm_policy_id_print(); */
if (!tb[XFRMA_SA]) { if (!tb[XFRMA_SA]) {
fprintf(stderr, "Buggy XFRM_MSG_DELSA: no XFRMA_SA\n"); fprintf(stderr, "Buggy XFRM_MSG_DELSA: no XFRMA_SA\n");
...@@ -958,7 +959,7 @@ static int xfrm_state_get_or_delete(int argc, char **argv, int delete) ...@@ -958,7 +959,7 @@ static int xfrm_state_get_or_delete(int argc, char **argv, int delete)
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
struct xfrm_usersa_id xsid; struct xfrm_usersa_id xsid;
char buf[RTA_BUF_SIZE]; char buf[RTA_BUF_SIZE];
} req; } req;
struct xfrm_id id; struct xfrm_id id;
char *idp = NULL; char *idp = NULL;
...@@ -1025,7 +1026,7 @@ static int xfrm_state_get_or_delete(int argc, char **argv, int delete) ...@@ -1025,7 +1026,7 @@ static int xfrm_state_get_or_delete(int argc, char **argv, int delete)
if (rtnl_talk(&rth, &req.n, res_n, sizeof(req)) < 0) if (rtnl_talk(&rth, &req.n, res_n, sizeof(req)) < 0)
exit(2); exit(2);
if (xfrm_state_print(NULL, res_n, (void*)stdout) < 0) { if (xfrm_state_print(NULL, res_n, (void *)stdout) < 0) {
fprintf(stderr, "An error :-)\n"); fprintf(stderr, "An error :-)\n");
exit(1); exit(1);
} }
...@@ -1087,7 +1088,7 @@ static int xfrm_state_keep(const struct sockaddr_nl *who, ...@@ -1087,7 +1088,7 @@ static int xfrm_state_keep(const struct sockaddr_nl *who,
sizeof(xsid->daddr)); sizeof(xsid->daddr));
xb->offset += new_n->nlmsg_len; xb->offset += new_n->nlmsg_len;
xb->nlmsg_count ++; xb->nlmsg_count++;
return 0; return 0;
} }
...@@ -1097,7 +1098,7 @@ static int xfrm_state_list_or_deleteall(int argc, char **argv, int deleteall) ...@@ -1097,7 +1098,7 @@ static int xfrm_state_list_or_deleteall(int argc, char **argv, int deleteall)
char *idp = NULL; char *idp = NULL;
struct rtnl_handle rth; struct rtnl_handle rth;
if(argc > 0) if (argc > 0)
filter.use = 1; filter.use = 1;
filter.xsinfo.family = preferred_family; filter.xsinfo.family = preferred_family;
...@@ -1231,7 +1232,7 @@ static int xfrm_state_list_or_deleteall(int argc, char **argv, int deleteall) ...@@ -1231,7 +1232,7 @@ static int xfrm_state_list_or_deleteall(int argc, char **argv, int deleteall)
static int print_sadinfo(struct nlmsghdr *n, void *arg) static int print_sadinfo(struct nlmsghdr *n, void *arg)
{ {
FILE *fp = (FILE*)arg; FILE *fp = (FILE *)arg;
__u32 *f = NLMSG_DATA(n); __u32 *f = NLMSG_DATA(n);
struct rtattr *tb[XFRMA_SAD_MAX+1]; struct rtattr *tb[XFRMA_SAD_MAX+1];
struct rtattr *rta; struct rtattr *rta;
...@@ -1249,11 +1250,11 @@ static int print_sadinfo(struct nlmsghdr *n, void *arg) ...@@ -1249,11 +1250,11 @@ static int print_sadinfo(struct nlmsghdr *n, void *arg)
parse_rtattr(tb, XFRMA_SAD_MAX, rta, len); parse_rtattr(tb, XFRMA_SAD_MAX, rta, len);
if (tb[XFRMA_SAD_CNT]) { if (tb[XFRMA_SAD_CNT]) {
fprintf(fp,"\t SAD"); fprintf(fp, "\t SAD");
cnt = (__u32 *)RTA_DATA(tb[XFRMA_SAD_CNT]); cnt = (__u32 *)RTA_DATA(tb[XFRMA_SAD_CNT]);
fprintf(fp," count %d", *cnt); fprintf(fp, " count %d", *cnt);
} else { } else {
fprintf(fp,"BAD SAD info returned\n"); fprintf(fp, "BAD SAD info returned\n");
return -1; return -1;
} }
...@@ -1262,20 +1263,20 @@ static int print_sadinfo(struct nlmsghdr *n, void *arg) ...@@ -1262,20 +1263,20 @@ static int print_sadinfo(struct nlmsghdr *n, void *arg)
struct xfrmu_sadhinfo *si; struct xfrmu_sadhinfo *si;
if (RTA_PAYLOAD(tb[XFRMA_SAD_HINFO]) < sizeof(*si)) { if (RTA_PAYLOAD(tb[XFRMA_SAD_HINFO]) < sizeof(*si)) {
fprintf(fp,"BAD SAD length returned\n"); fprintf(fp, "BAD SAD length returned\n");
return -1; return -1;
} }
si = RTA_DATA(tb[XFRMA_SAD_HINFO]); si = RTA_DATA(tb[XFRMA_SAD_HINFO]);
fprintf(fp," (buckets "); fprintf(fp, " (buckets ");
fprintf(fp,"count %d", si->sadhcnt); fprintf(fp, "count %d", si->sadhcnt);
fprintf(fp," Max %d", si->sadhmcnt); fprintf(fp, " Max %d", si->sadhmcnt);
fprintf(fp,")"); fprintf(fp, ")");
} }
} }
fprintf(fp,"\n"); fprintf(fp, "\n");
return 0; return 0;
} }
static int xfrm_sad_getinfo(int argc, char **argv) static int xfrm_sad_getinfo(int argc, char **argv)
...@@ -1299,7 +1300,7 @@ static int xfrm_sad_getinfo(int argc, char **argv) ...@@ -1299,7 +1300,7 @@ static int xfrm_sad_getinfo(int argc, char **argv)
if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0)
exit(2); exit(2);
print_sadinfo(&req.n, (void*)stdout); print_sadinfo(&req.n, (void *)stdout);
rtnl_close(&rth); rtnl_close(&rth);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment