ip: code cleanup

Run all the ip code through checkpatch and have it fix the obvious stuff.
This commit is contained in:
Stephen Hemminger 2016-03-21 11:52:19 -07:00
parent 32a121cba2
commit 56f5daac98
43 changed files with 609 additions and 422 deletions

View File

@ -81,6 +81,7 @@ static void print_tunnel(struct ip6_tnl_parm2 *p)
rt_addr_n2a(AF_INET6, 16, &p->laddr, s2, sizeof(s2)));
if (p->link) {
const char *n = ll_index_to_name(p->link);
if (n)
printf(" dev %s", n);
}
@ -96,6 +97,7 @@ static void print_tunnel(struct ip6_tnl_parm2 *p)
printf(" tclass inherit");
else {
__u32 val = ntohl(p->flowinfo & IP6_FLOWINFO_TCLASS);
printf(" tclass 0x%02x", (__u8)(val >> 20));
}
@ -163,6 +165,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p)
}
} else if (strcmp(*argv, "remote") == 0) {
inet_prefix raddr;
NEXT_ARG();
get_prefix(&raddr, *argv, preferred_family);
if (raddr.family == AF_UNSPEC)
@ -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));
} else if (strcmp(*argv, "local") == 0) {
inet_prefix laddr;
NEXT_ARG();
get_prefix(&laddr, *argv, preferred_family);
if (laddr.family == AF_UNSPEC)
@ -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;
} else {
__u8 uval;
if (get_u8(&uval, *argv, 0) < -1)
invarg("invalid ELIM", *argv);
p->encap_limit = uval;
@ -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, "hlim") == 0) {
__u8 uval;
NEXT_ARG();
if (get_u8(&uval, *argv, 0))
invarg("invalid TTL", *argv);
@ -202,6 +208,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p)
strcmp(*argv, "tos") == 0 ||
matches(*argv, "dsfield") == 0) {
__u8 uval;
NEXT_ARG();
p->flowinfo &= ~IP6_FLOWINFO_TCLASS;
if (strcmp(*argv, "inherit") == 0)
@ -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 ||
strcmp(*argv, "fl") == 0) {
__u32 uval;
NEXT_ARG();
p->flowinfo &= ~IP6_FLOWINFO_FLOWLABEL;
if (strcmp(*argv, "inherit") == 0)
@ -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);
if (cmd == SIOCCHGTUNNEL && count == 0) {
struct ip6_tnl_parm2 old_p;
memset(&old_p, 0, sizeof(old_p));
if (tnl_get_ioctl(*argv, &old_p))
return -1;
@ -326,6 +335,7 @@ static int do_tunnels_list(struct ip6_tnl_parm2 *p)
char buf[512];
int err = -1;
FILE *fp = fopen("/proc/net/dev", "r");
if (fp == NULL) {
perror("fopen");
return -1;

View File

@ -93,7 +93,7 @@ static void usage(void)
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, "<");
if (flags & IFF_UP && !(flags & IFF_RUNNING))
@ -135,7 +135,7 @@ static const char *oper_states[] = {
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);
else {
if (brief) {
@ -161,7 +161,7 @@ int get_operstate(const char *name)
{
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)
return i;
return -1;
@ -202,7 +202,7 @@ static void print_linkmode(FILE *f, struct rtattr *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);
else
fprintf(f, "mode %s ", link_modes[mode]);
@ -286,6 +286,7 @@ static void print_af_spec(FILE *fp, struct rtattr *af_spec_attr)
if (tb[IFLA_INET6_ADDR_GEN_MODE]) {
__u8 mode = rta_getattr_u8(tb[IFLA_INET6_ADDR_GEN_MODE]);
switch (mode) {
case IN6_ADDR_GEN_MODE_EUI64:
fprintf(fp, "addrgenmode eui64 ");
@ -317,6 +318,7 @@ static void print_vfinfo(FILE *fp, struct rtattr *vfinfo)
struct ifla_vf_link_state *vf_linkstate;
struct rtattr *vf[IFLA_VF_MAX + 1] = {};
struct rtattr *tmp;
SPRINT_BUF(b1);
if (vfinfo->rta_type != IFLA_VF_INFO) {
@ -392,7 +394,7 @@ static void print_vfinfo(FILE *fp, struct rtattr *vfinfo)
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 unsigned int base = use_iec ? 1024 : 1000;
@ -635,7 +637,7 @@ int print_linkinfo_brief(const struct sockaddr_nl *who,
int len = n->nlmsg_len;
char *name;
char buf[32] = { 0, };
unsigned m_flag = 0;
unsigned int m_flag = 0;
if (n->nlmsg_type != RTM_NEWLINK && n->nlmsg_type != RTM_DELLINK)
return -1;
@ -660,16 +662,17 @@ int print_linkinfo_brief(const struct sockaddr_nl *who,
if (tb[IFLA_GROUP]) {
int group = *(int *)RTA_DATA(tb[IFLA_GROUP]);
if (filter.group != -1 && group != filter.group)
return -1;
}
if (tb[IFLA_MASTER]) {
int master = *(int *)RTA_DATA(tb[IFLA_MASTER]);
if (filter.master > 0 && master != filter.master)
return -1;
}
else if (filter.master > 0)
} else if (filter.master > 0)
return -1;
if (filter.kind) {
@ -691,6 +694,7 @@ int print_linkinfo_brief(const struct sockaddr_nl *who,
if (tb[IFLA_LINK]) {
SPRINT_BUF(b1);
int iflink = *(int *)RTA_DATA(tb[IFLA_LINK]);
if (iflink == 0)
snprintf(buf, sizeof(buf), "%s@NONE", name);
else {
@ -734,7 +738,7 @@ int print_linkinfo(const struct sockaddr_nl *who,
struct ifinfomsg *ifi = NLMSG_DATA(n);
struct rtattr *tb[IFLA_MAX+1];
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)
return 0;
@ -759,16 +763,17 @@ int print_linkinfo(const struct sockaddr_nl *who,
if (tb[IFLA_GROUP]) {
int group = *(int *)RTA_DATA(tb[IFLA_GROUP]);
if (filter.group != -1 && group != filter.group)
return -1;
}
if (tb[IFLA_MASTER]) {
int master = *(int *)RTA_DATA(tb[IFLA_MASTER]);
if (filter.master > 0 && master != filter.master)
return -1;
}
else if (filter.master > 0)
} else if (filter.master > 0)
return -1;
if (filter.kind) {
@ -792,6 +797,7 @@ int print_linkinfo(const struct sockaddr_nl *who,
if (tb[IFLA_LINK]) {
SPRINT_BUF(b1);
int iflink = *(int *)RTA_DATA(tb[IFLA_LINK]);
if (iflink == 0)
fprintf(fp, "@NONE: ");
else {
@ -842,6 +848,7 @@ int print_linkinfo(const struct sockaddr_nl *who,
if (tb[IFLA_GROUP]) {
SPRINT_BUF(b1);
int group = *(int *)RTA_DATA(tb[IFLA_GROUP]);
fprintf(fp, "group %s ", rtnl_group_n2a(group, b1, sizeof(b1)));
}
@ -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]) {
struct rtattr *i, *vflist = tb[IFLA_VFINFO_LIST];
int rem = RTA_PAYLOAD(vflist);
for (i = RTA_DATA(vflist); RTA_OK(i, rem); i = RTA_NEXT(i, rem))
print_vfinfo(fp, i);
}
@ -966,6 +974,7 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
unsigned int ifa_flags;
struct rtattr *rta_tb[IFA_MAX+1];
char abuf[256];
SPRINT_BUF(b1);
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,
if (filter.label) {
SPRINT_BUF(b1);
const char *label;
if (rta_tb[IFA_LABEL])
label = RTA_DATA(rta_tb[IFA_LABEL]);
else
@ -1008,6 +1018,7 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
if (filter.pfx.family) {
if (rta_tb[IFA_LOCAL]) {
inet_prefix dst;
memset(&dst, 0, sizeof(dst));
dst.family = ifa->ifa_family;
memcpy(&dst.data, RTA_DATA(rta_tb[IFA_LOCAL]), RTA_PAYLOAD(rta_tb[IFA_LOCAL]));
@ -1021,6 +1032,7 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
if (filter.flushb) {
struct nlmsghdr *fn;
if (NLMSG_ALIGN(filter.flushp) + n->nlmsg_len > filter.flushe) {
if (flush_update())
return -1;
@ -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]));
if (rta_tb[IFA_CACHEINFO]) {
struct ifa_cacheinfo *ci = RTA_DATA(rta_tb[IFA_CACHEINFO]);
fprintf(fp, "%s", _SL_);
fprintf(fp, " valid_lft ");
if (ci->ifa_valid == INFINITY_LIFE_TIME)
@ -1175,14 +1188,12 @@ brief_exit:
return 0;
}
struct nlmsg_list
{
struct nlmsg_list {
struct nlmsg_list *next;
struct nlmsghdr h;
};
struct nlmsg_chain
{
struct nlmsg_chain {
struct nlmsg_list *head;
struct nlmsg_list *tail;
};
@ -1383,6 +1394,7 @@ static void ipaddr_filter(struct nlmsg_chain *linfo, struct nlmsg_chain *ainfo)
if (filter.pfx.family && tb[IFA_LOCAL]) {
inet_prefix dst;
memset(&dst, 0, sizeof(dst));
dst.family = ifa->ifa_family;
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)
if (filter.label) {
SPRINT_BUF(b1);
const char *label;
if (tb[IFA_LABEL])
label = RTA_DATA(tb[IFA_LABEL]);
else
@ -1500,7 +1513,8 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
if (filter.family == AF_UNSPEC)
filter.family = filter.pfx.family;
} else if (strcmp(*argv, "scope") == 0) {
unsigned scope = 0;
unsigned int scope = 0;
NEXT_ARG();
filter.scopemask = -1;
if (rtnl_rtscope_a2n(&scope, *argv)) {
@ -1567,6 +1581,7 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
invarg("Invalid \"group\" value\n", *argv);
} else if (strcmp(*argv, "master") == 0) {
int ifindex;
NEXT_ARG();
ifindex = ll_name_to_index(*argv);
if (!ifindex)
@ -1578,8 +1593,7 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
} else {
if (strcmp(*argv, "dev") == 0) {
NEXT_ARG();
}
else if (matches(*argv, "help") == 0)
} else if (matches(*argv, "help") == 0)
usage();
if (filter_dev)
duparg2("dev", *argv);
@ -1820,6 +1834,7 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv)
} else if (matches(*argv, "broadcast") == 0 ||
strcmp(*argv, "brd") == 0) {
inet_prefix addr;
NEXT_ARG();
if (brd_len)
duparg("broadcast", *argv);
@ -1836,6 +1851,7 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv)
}
} else if (strcmp(*argv, "anycast") == 0) {
inet_prefix addr;
NEXT_ARG();
if (any_len)
duparg("anycast", *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);
any_len = addr.bytelen;
} else if (strcmp(*argv, "scope") == 0) {
unsigned scope = 0;
unsigned int scope = 0;
NEXT_ARG();
if (rtnl_rtscope_a2n(&scope, *argv))
invarg("invalid scope value.", *argv);
@ -1931,6 +1948,7 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv)
if (brd_len < 0 && cmd != RTM_DELADDR) {
inet_prefix brd;
int i;
if (req.ifa.ifa_family != AF_INET) {
fprintf(stderr, "Broadcast can be set only for IPv4 addresses\n");
return -1;

View File

@ -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)) {
uint32_t label;
memcpy(&label, RTA_DATA(tb[IFAL_LABEL]), sizeof(label));
fprintf(fp, "label %u ", label);
}

View File

@ -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) ||
(strcmp(*argv, "tid") == 0)) {
__u32 uval;
NEXT_ARG();
if (get_u32(&uval, *argv, 0))
invarg("invalid ID\n", *argv);
@ -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) ||
(strcmp(*argv, "ptid") == 0)) {
__u32 uval;
NEXT_ARG();
if (get_u32(&uval, *argv, 0))
invarg("invalid ID\n", *argv);
@ -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) ||
(strcmp(*argv, "sid") == 0)) {
__u32 uval;
NEXT_ARG();
if (get_u32(&uval, *argv, 0))
invarg("invalid ID\n", *argv);
@ -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) ||
(strcmp(*argv, "psid") == 0)) {
__u32 uval;
NEXT_ARG();
if (get_u32(&uval, *argv, 0))
invarg("invalid ID\n", *argv);
p->peer_session_id = uval;
} else if (strcmp(*argv, "udp_sport") == 0) {
__u16 uval;
NEXT_ARG();
if (get_u16(&uval, *argv, 0))
invarg("invalid port\n", *argv);
p->local_udp_port = uval;
} else if (strcmp(*argv, "udp_dport") == 0) {
__u16 uval;
NEXT_ARG();
if (get_u16(&uval, *argv, 0))
invarg("invalid port\n", *argv);
p->peer_udp_port = uval;
} else if (strcmp(*argv, "offset") == 0) {
__u8 uval;
NEXT_ARG();
if (get_u8(&uval, *argv, 0))
invarg("invalid offset\n", *argv);
p->offset = uval;
} else if (strcmp(*argv, "peer_offset") == 0) {
__u8 uval;
NEXT_ARG();
if (get_u8(&uval, *argv, 0))
invarg("invalid offset\n", *argv);
p->peer_offset = uval;
} else if (strcmp(*argv, "cookie") == 0) {
int slen;
NEXT_ARG();
slen = strlen(*argv);
if ((slen != 8) && (slen != 16))
@ -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);
} else if (strcmp(*argv, "peer_cookie") == 0) {
int slen;
NEXT_ARG();
slen = strlen(*argv);
if ((slen != 8) && (slen != 16))

View File

@ -358,6 +358,7 @@ static int iplink_parse_vf(int vf, int *argcp, char ***argvp,
} else if (matches(*argv, "trust") == 0) {
struct ifla_vf_trust ivt;
NEXT_ARG();
if (matches(*argv, "on") == 0)
ivt.setting = 1;
@ -712,14 +713,12 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
&group, sizeof(group));
else {
if (argc) {
fprintf(stderr, "Garbage instead of arguments "
"\"%s ...\". Try \"ip link "
fprintf(stderr, "Garbage instead of arguments \"%s ...\". Try \"ip link "
"help\".\n", *argv);
return -1;
}
if (flags & NLM_F_CREATE) {
fprintf(stderr, "group cannot be used when "
"creating devices.\n");
fprintf(stderr, "group cannot be used when creating devices.\n");
return -1;
}
@ -733,13 +732,11 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
if (!(flags & NLM_F_CREATE)) {
if (!dev) {
fprintf(stderr, "Not enough information: \"dev\" "
"argument is required.\n");
fprintf(stderr, "Not enough information: \"dev\" argument is required.\n");
exit(-1);
}
if (cmd == RTM_NEWLINK && index != -1) {
fprintf(stderr, "index can be used only when "
"creating devices.\n");
fprintf(stderr, "index can be used only when creating devices.\n");
exit(-1);
}
@ -813,14 +810,13 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
} else if (argc) {
if (matches(*argv, "help") == 0)
usage();
fprintf(stderr, "Garbage instead of arguments \"%s ...\". "
"Try \"ip link help\".\n", *argv);
fprintf(stderr, "Garbage instead of arguments \"%s ...\". Try \"ip link help\".\n",
*argv);
return -1;
}
addattr_nest_end(&req.n, linkinfo);
} else if (flags & NLM_F_CREATE) {
fprintf(stderr, "Not enough information: \"type\" argument "
"is required\n");
fprintf(stderr, "Not enough information: \"type\" argument is required\n");
return -1;
}

View File

@ -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 arp_all_targets, resend_igmp, min_links, lp_interval;
__u32 packets_per_slave;
unsigned ifindex;
unsigned int ifindex;
while (argc > 0) {
if (matches(*argv, "mode") == 0) {
@ -219,6 +219,7 @@ static int bond_parse_opt(struct link_util *lu, int argc, char **argv,
for (i = 0; target && i < BOND_MAX_ARP_TARGETS; i++) {
__u32 addr = get_addr32(target);
addattr32(n, 1024, i, addr);
target = strtok(NULL, ",");
}
@ -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[])
{
unsigned ifindex;
unsigned int ifindex;
if (!tb)
return;

View File

@ -26,7 +26,7 @@ static void print_slave_state(FILE *f, struct rtattr *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);
else
fprintf(f, "state %s ", slave_states[state]);
@ -43,7 +43,7 @@ static void print_slave_mii_status(FILE *f, struct rtattr *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);
else
fprintf(f, "mii_status %s ", slave_mii_status[status]);

View File

@ -24,12 +24,10 @@ static void print_usage(FILE *f)
fprintf(f,
"Usage: ip link set DEVICE type can\n"
"\t[ bitrate BITRATE [ sample-point SAMPLE-POINT] ] |\n"
"\t[ tq TQ prop-seg PROP_SEG phase-seg1 PHASE-SEG1\n "
"\t phase-seg2 PHASE-SEG2 [ sjw SJW ] ]\n"
"\t[ tq TQ prop-seg PROP_SEG phase-seg1 PHASE-SEG1\n \t phase-seg2 PHASE-SEG2 [ sjw SJW ] ]\n"
"\n"
"\t[ dbitrate BITRATE [ dsample-point SAMPLE-POINT] ] |\n"
"\t[ dtq TQ dprop-seg PROP_SEG dphase-seg1 PHASE-SEG1\n "
"\t dphase-seg2 PHASE-SEG2 [ dsjw SJW ] ]\n"
"\t[ dtq TQ dprop-seg PROP_SEG dphase-seg1 PHASE-SEG1\n \t dphase-seg2 PHASE-SEG2 [ dsjw SJW ] ]\n"
"\n"
"\t[ loopback { on | off } ]\n"
"\t[ listen-only { on | off } ]\n"
@ -289,11 +287,9 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (tb[IFLA_CAN_BITTIMING]) {
struct can_bittiming *bt = RTA_DATA(tb[IFLA_CAN_BITTIMING]);
fprintf(f, "\n "
"bitrate %d sample-point %.3f ",
fprintf(f, "\n bitrate %d sample-point %.3f ",
bt->bitrate, (float)bt->sample_point / 1000.);
fprintf(f, "\n "
"tq %d prop-seg %d phase-seg1 %d phase-seg2 %d sjw %d",
fprintf(f, "\n 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->sjw);
}
@ -302,8 +298,7 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
struct can_bittiming_const *btc =
RTA_DATA(tb[IFLA_CAN_BITTIMING_CONST]);
fprintf(f, "\n "
"%s: tseg1 %d..%d tseg2 %d..%d "
fprintf(f, "\n %s: tseg1 %d..%d tseg2 %d..%d "
"sjw 1..%d brp %d..%d brp-inc %d",
btc->name, btc->tseg1_min, btc->tseg1_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[])
struct can_bittiming *dbt =
RTA_DATA(tb[IFLA_CAN_DATA_BITTIMING]);
fprintf(f, "\n "
"dbitrate %d dsample-point %.3f ",
fprintf(f, "\n dbitrate %d dsample-point %.3f ",
dbt->bitrate, (float)dbt->sample_point / 1000.);
fprintf(f, "\n "
"dtq %d dprop-seg %d dphase-seg1 %d "
fprintf(f, "\n dtq %d dprop-seg %d dphase-seg1 %d "
"dphase-seg2 %d dsjw %d",
dbt->tq, dbt->prop_seg, dbt->phase_seg1,
dbt->phase_seg2, dbt->sjw);
@ -328,8 +321,7 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
struct can_bittiming_const *dbtc =
RTA_DATA(tb[IFLA_CAN_DATA_BITTIMING_CONST]);
fprintf(f, "\n "
"%s: dtseg1 %d..%d dtseg2 %d..%d "
fprintf(f, "\n %s: dtseg1 %d..%d dtseg2 %d..%d "
"dsjw 1..%d dbrp %d..%d dbrp-inc %d",
dbtc->name, dbtc->tseg1_min, dbtc->tseg1_max,
dbtc->tseg2_min, dbtc->tseg2_max, dbtc->sjw_max,
@ -351,8 +343,7 @@ static void can_print_xstats(struct link_util *lu,
if (xstats && RTA_PAYLOAD(xstats) == sizeof(*stats)) {
stats = RTA_DATA(xstats);
fprintf(f, "\n "
"re-started bus-errors arbit-lost "
fprintf(f, "\n re-started bus-errors arbit-lost "
"error-warn error-pass bus-off");
fprintf(f, "\n %-10d %-10d %-10d %-10d %-10d %-10d",
stats->restarts, stats->bus_error,

View File

@ -62,7 +62,7 @@ static int geneve_parse_opt(struct link_util *lu, int argc, char **argv,
invarg("invalid remote address", *argv);
} else if (!matches(*argv, "ttl") ||
!matches(*argv, "hoplimit")) {
unsigned uval;
unsigned int uval;
NEXT_ARG();
if (strcmp(*argv, "inherit") != 0) {
@ -153,11 +153,13 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (tb[IFLA_GENEVE_REMOTE]) {
__be32 addr = rta_getattr_u32(tb[IFLA_GENEVE_REMOTE]);
if (addr)
fprintf(f, "remote %s ",
format_host(AF_INET, 4, &addr, s1, sizeof(s1)));
} else if (tb[IFLA_GENEVE_REMOTE6]) {
struct in6_addr addr;
memcpy(&addr, RTA_DATA(tb[IFLA_GENEVE_REMOTE6]), sizeof(struct in6_addr));
if (memcmp(&addr, &in6addr_any, sizeof(addr)) != 0) {
if (IN6_IS_ADDR_MULTICAST(&addr))
@ -168,6 +170,7 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (tb[IFLA_GENEVE_TTL]) {
__u8 ttl = rta_getattr_u8(tb[IFLA_GENEVE_TTL]);
if (ttl)
fprintf(f, "ttl %d ", ttl);
}

View File

@ -22,8 +22,7 @@
static void print_explain(FILE *f)
{
fprintf(f,
"Usage: ... ipoib [pkey PKEY] [mode {datagram | connected}]"
"[umcast {0|1}]\n"
"Usage: ... ipoib [pkey PKEY] [mode {datagram | connected}][umcast {0|1}]\n"
"\n"
"PKEY := 0x8001-0xffff\n"
);
@ -36,8 +35,7 @@ static void explain(void)
static int mode_arg(void)
{
fprintf(stderr, "Error: argument of \"mode\" must be \"datagram\""
"or \"connected\"\n");
fprintf(stderr, "Error: argument of \"mode\" must be \"datagram\"or \"connected\"\n");
return -1;
}

View File

@ -30,8 +30,7 @@ static void explain(void)
static int mode_arg(void)
{
fprintf(stderr, "Error: argument of \"mode\" must be either \"l2\", "
"or \"l3\"\n");
fprintf(stderr, "Error: argument of \"mode\" must be either \"l2\", or \"l3\"\n");
return -1;
}
@ -41,6 +40,7 @@ static int ipvlan_parse_opt(struct link_util *lu, int argc, char **argv,
while (argc > 0) {
if (matches(*argv, "mode") == 0) {
__u16 mode = 0;
NEXT_ARG();
if (strcmp(*argv, "l2") == 0)

View File

@ -41,8 +41,8 @@ static void explain(struct link_util *lu)
static int mode_arg(const char *arg)
{
fprintf(stderr, "Error: argument of \"mode\" must be \"private\", "
"\"vepa\", \"bridge\" or \"passthru\", not \"%s\"\n", arg);
fprintf(stderr, "Error: argument of \"mode\" must be \"private\", \"vepa\", \"bridge\" or \"passthru\", not \"%s\"\n",
arg);
return -1;
}

View File

@ -21,8 +21,7 @@
static void print_explain(FILE *f)
{
fprintf(f,
"Usage: ... vlan [ protocol VLANPROTO ] id VLANID"
" [ FLAG-LIST ]\n"
"Usage: ... vlan [ protocol VLANPROTO ] id VLANID [ FLAG-LIST ]\n"
" [ ingress-qos-map QOS-MAP ] [ egress-qos-map QOS-MAP ]\n"
"\n"
"VLANPROTO: [ 802.1Q / 802.1ad ]\n"
@ -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[])
{
struct ifla_vlan_flags *flags;
SPRINT_BUF(b1);
if (!tb)

View File

@ -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 gaddr6 = IN6ADDR_ANY_INIT;
struct in6_addr daddr6 = IN6ADDR_ANY_INIT;
unsigned link = 0;
unsigned int link = 0;
__u8 tos = 0;
__u8 ttl = 0;
__u8 learning = 1;
@ -122,7 +122,7 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
}
} else if (!matches(*argv, "ttl") ||
!matches(*argv, "hoplimit")) {
unsigned uval;
unsigned int uval;
NEXT_ARG();
if (strcmp(*argv, "inherit") != 0) {
@ -158,6 +158,7 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
} else if (!matches(*argv, "port") ||
!matches(*argv, "srcport")) {
__u16 minport, maxport;
NEXT_ARG();
if (get_u16(&minport, *argv, 0))
invarg("min port", *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[])
{
__u32 vni;
unsigned link;
unsigned int link;
__u8 tos;
__u32 maxaddr;
char s1[1024];
@ -324,6 +325,7 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (tb[IFLA_VXLAN_GROUP]) {
__be32 addr = rta_getattr_u32(tb[IFLA_VXLAN_GROUP]);
if (addr) {
if (IN_MULTICAST(ntohl(addr)))
fprintf(f, "group %s ",
@ -334,6 +336,7 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
}
} else if (tb[IFLA_VXLAN_GROUP6]) {
struct in6_addr addr;
memcpy(&addr, RTA_DATA(tb[IFLA_VXLAN_GROUP6]), sizeof(struct in6_addr));
if (memcmp(&addr, &in6addr_any, sizeof(addr)) != 0) {
if (IN6_IS_ADDR_MULTICAST(&addr))
@ -347,11 +350,13 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (tb[IFLA_VXLAN_LOCAL]) {
__be32 addr = rta_getattr_u32(tb[IFLA_VXLAN_LOCAL]);
if (addr)
fprintf(f, "local %s ",
format_host(AF_INET, 4, &addr, s1, sizeof(s1)));
} else if (tb[IFLA_VXLAN_LOCAL6]) {
struct in6_addr addr;
memcpy(&addr, RTA_DATA(tb[IFLA_VXLAN_LOCAL6]), sizeof(struct in6_addr));
if (memcmp(&addr, &in6addr_any, sizeof(addr)) != 0)
fprintf(f, "local %s ",
@ -404,12 +409,14 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (tb[IFLA_VXLAN_TTL]) {
__u8 ttl = rta_getattr_u8(tb[IFLA_VXLAN_TTL]);
if (ttl)
fprintf(f, "ttl %d ", ttl);
}
if (tb[IFLA_VXLAN_AGEING]) {
__u32 age = rta_getattr_u32(tb[IFLA_VXLAN_AGEING]);
if (age == 0)
fprintf(f, "ageing none ");
else

View File

@ -50,6 +50,7 @@ static int parse_hex(char *str, unsigned char *addr, size_t size)
while (*str && (len < 2 * size)) {
int tmp;
if (str[1] == 0)
return -1;
if (sscanf(str, "%02x", &tmp) != 1)
@ -61,8 +62,7 @@ static int parse_hex(char *str, unsigned char *addr, size_t size)
return len;
}
struct ma_info
{
struct ma_info {
struct ma_info *next;
int index;
int users;
@ -205,6 +205,7 @@ static void print_maddr(FILE *fp, struct ma_info *list)
b1, sizeof(b1)));
} else {
char abuf[256];
switch (list->addr.family) {
case AF_INET:
fprintf(fp, "inet ");
@ -256,8 +257,7 @@ static int multiaddr_list(int argc, char **argv)
if (1) {
if (strcmp(*argv, "dev") == 0) {
NEXT_ARG();
}
else if (matches(*argv, "help") == 0)
} else if (matches(*argv, "help") == 0)
usage();
if (filter.dev)
duparg2("dev", *argv);

View File

@ -30,8 +30,7 @@ int listen_all_nsid;
static void usage(void)
{
fprintf(stderr, "Usage: ip monitor [ all | LISTofOBJECTS ] [ FILE ] "
"[ label ] [all-nsid] [dev DEVICE]\n");
fprintf(stderr, "Usage: ip monitor [ all | LISTofOBJECTS ] [ FILE ] [ label ] [all-nsid] [dev DEVICE]\n");
fprintf(stderr, "LISTofOBJECTS := link | address | route | mroute | prefix |\n");
fprintf(stderr, " neigh | netconf | rule | nsid\n");
fprintf(stderr, "FILE := file FILENAME\n");
@ -139,8 +138,8 @@ static int accept_msg(const struct sockaddr_nl *who,
}
if (n->nlmsg_type != NLMSG_ERROR && n->nlmsg_type != NLMSG_NOOP &&
n->nlmsg_type != NLMSG_DONE) {
fprintf(fp, "Unknown message: type=0x%08x(%d) flags=0x%08x(%d)"
"len=0x%08x(%d)\n", n->nlmsg_type, n->nlmsg_type,
fprintf(fp, "Unknown message: type=0x%08x(%d) flags=0x%08x(%d)len=0x%08x(%d)\n",
n->nlmsg_type, n->nlmsg_type,
n->nlmsg_flags, n->nlmsg_flags, n->nlmsg_len,
n->nlmsg_len);
}
@ -150,7 +149,7 @@ static int accept_msg(const struct sockaddr_nl *who,
int do_ipmonitor(int argc, char **argv)
{
char *file = NULL;
unsigned groups = 0;
unsigned int groups = 0;
int llink = 0;
int laddr = 0;
int lroute = 0;

View File

@ -44,8 +44,7 @@ static void usage(void)
exit(-1);
}
struct rtfilter
{
struct rtfilter {
int tb;
int af;
int iif;
@ -61,6 +60,7 @@ int print_mroute(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
struct rtattr *tb[RTA_MAX+1];
char abuf[256];
char obuf[256];
SPRINT_BUF(b1);
__u32 table;
int iif = 0;
@ -212,6 +212,7 @@ static int mroute_list(int argc, char **argv)
while (argc > 0) {
if (matches(*argv, "table") == 0) {
__u32 tid;
NEXT_ARG();
if (rtnl_rttable_a2n(&tid, *argv)) {
if (strcmp(*argv, "all") == 0) {

View File

@ -54,7 +54,7 @@ static void usage(void)
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)
*state = NUD_PERMANENT;
@ -124,7 +124,8 @@ static int ipneigh_modify(int cmd, int flags, int argc, char **argv)
lla = *argv;
lladdr_ok = 1;
} else if (strcmp(*argv, "nud") == 0) {
unsigned state;
unsigned int state;
NEXT_ARG();
if (nud_state_a2n(&state, *argv))
invarg("nud state is bad", *argv);
@ -239,6 +240,7 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[NDA_DST]) {
if (filter.pfx.family) {
inet_prefix dst;
memset(&dst, 0, sizeof(dst));
dst.family = r->ndm_family;
memcpy(&dst.data, RTA_DATA(tb[NDA_DST]), RTA_PAYLOAD(tb[NDA_DST]));
@ -248,12 +250,14 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
}
if (filter.unused_only && tb[NDA_CACHEINFO]) {
struct nda_cacheinfo *ci = RTA_DATA(tb[NDA_CACHEINFO]);
if (ci->ndm_refcnt)
return 0;
}
if (filter.flushb) {
struct nlmsghdr *fn;
if (NLMSG_ALIGN(filter.flushp) + n->nlmsg_len > filter.flushe) {
if (flush_update())
return -1;
@ -307,11 +311,13 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[NDA_PROBES] && show_stats) {
__u32 p = rta_getattr_u32(tb[NDA_PROBES]);
fprintf(fp, " probes %u", p);
}
if (r->ndm_state) {
int nud = r->ndm_state;
fprintf(fp, " ");
#define PRINT_FLAG(f) if (nud & NUD_##f) { \
@ -376,6 +382,7 @@ static int do_show_or_flush(int argc, char **argv, int flush)
filter_dev = *argv;
} else if (strcmp(*argv, "master") == 0) {
int ifindex;
NEXT_ARG();
ifindex = ll_name_to_index(*argv);
if (!ifindex)
@ -385,7 +392,8 @@ static int do_show_or_flush(int argc, char **argv, int flush)
} else if (strcmp(*argv, "unused") == 0) {
filter.unused_only = 1;
} else if (strcmp(*argv, "nud") == 0) {
unsigned state;
unsigned int state;
NEXT_ARG();
if (!state_given) {
state_given = 1;

View File

@ -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)
{
char **argv = arg;
cmd_exec(argv[1], argv + 1, true);
return 0;
}
@ -426,6 +427,7 @@ static int netns_exec(int argc, char **argv)
static int is_pid(const char *str)
{
int ch;
for (; (ch = *str); str++) {
if (!isdigit(ch))
return 0;
@ -473,6 +475,7 @@ static int netns_pids(int argc, char **argv)
while ((entry = readdir(dir))) {
char pid_net_path[PATH_MAX];
struct stat st;
if (!is_pid(entry->d_name))
continue;
snprintf(pid_net_path, sizeof(pid_net_path), "/proc/%s/ns/net",
@ -737,6 +740,7 @@ static int netns_monitor(int argc, char **argv)
char buf[4096];
struct inotify_event *event;
int fd;
fd = inotify_init();
if (fd < 0) {
fprintf(stderr, "inotify_init failed: %s\n",
@ -754,6 +758,7 @@ static int netns_monitor(int argc, char **argv)
}
for (;;) {
ssize_t len = read(fd, buf, sizeof(buf));
if (len < 0) {
fprintf(stderr, "read failed: %s\n",
strerror(errno));

View File

@ -407,6 +407,7 @@ static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void
if (tb[NDTA_NAME]) {
const char *name = rta_getattr_str(tb[NDTA_NAME]);
fprintf(fp, "%s ", name);
}
@ -419,18 +420,22 @@ static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void
if (tb[NDTA_THRESH1]) {
__u32 thresh1 = rta_getattr_u32(tb[NDTA_THRESH1]);
fprintf(fp, "thresh1 %u ", thresh1);
}
if (tb[NDTA_THRESH2]) {
__u32 thresh2 = rta_getattr_u32(tb[NDTA_THRESH2]);
fprintf(fp, "thresh2 %u ", thresh2);
}
if (tb[NDTA_THRESH3]) {
__u32 thresh3 = rta_getattr_u32(tb[NDTA_THRESH3]);
fprintf(fp, "thresh3 %u ", thresh3);
}
if (tb[NDTA_GC_INTERVAL]) {
unsigned long long gc_int = rta_getattr_u64(tb[NDTA_GC_INTERVAL]);
fprintf(fp, "gc_int %llu ", gc_int);
}
@ -480,18 +485,22 @@ static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void
if (tpb[NDTPA_REFCNT]) {
__u32 refcnt = rta_getattr_u32(tpb[NDTPA_REFCNT]);
fprintf(fp, "refcnt %u ", refcnt);
}
if (tpb[NDTPA_REACHABLE_TIME]) {
unsigned long long reachable = rta_getattr_u64(tpb[NDTPA_REACHABLE_TIME]);
fprintf(fp, "reachable %llu ", reachable);
}
if (tpb[NDTPA_BASE_REACHABLE_TIME]) {
unsigned long long breachable = rta_getattr_u64(tpb[NDTPA_BASE_REACHABLE_TIME]);
fprintf(fp, "base_reachable %llu ", breachable);
}
if (tpb[NDTPA_RETRANS_TIME]) {
unsigned long long retrans = rta_getattr_u64(tpb[NDTPA_RETRANS_TIME]);
fprintf(fp, "retrans %llu ", retrans);
}
@ -501,14 +510,17 @@ static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void
if (tpb[NDTPA_GC_STALETIME]) {
unsigned long long gc_stale = rta_getattr_u64(tpb[NDTPA_GC_STALETIME]);
fprintf(fp, "gc_stale %llu ", gc_stale);
}
if (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);
}
if (tpb[NDTPA_QUEUE_LEN]) {
__u32 queue = rta_getattr_u32(tpb[NDTPA_QUEUE_LEN]);
fprintf(fp, "queue %u ", queue);
}
@ -518,14 +530,17 @@ static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void
if (tpb[NDTPA_APP_PROBES]) {
__u32 aprobe = rta_getattr_u32(tpb[NDTPA_APP_PROBES]);
fprintf(fp, "app_probes %u ", aprobe);
}
if (tpb[NDTPA_UCAST_PROBES]) {
__u32 uprobe = rta_getattr_u32(tpb[NDTPA_UCAST_PROBES]);
fprintf(fp, "ucast_probes %u ", uprobe);
}
if (tpb[NDTPA_MCAST_PROBES]) {
__u32 mprobe = rta_getattr_u32(tpb[NDTPA_MCAST_PROBES]);
fprintf(fp, "mcast_probes %u ", mprobe);
}
@ -535,18 +550,22 @@ static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void
if (tpb[NDTPA_ANYCAST_DELAY]) {
unsigned long long anycast_delay = rta_getattr_u64(tpb[NDTPA_ANYCAST_DELAY]);
fprintf(fp, "anycast_delay %llu ", anycast_delay);
}
if (tpb[NDTPA_PROXY_DELAY]) {
unsigned long long proxy_delay = rta_getattr_u64(tpb[NDTPA_PROXY_DELAY]);
fprintf(fp, "proxy_delay %llu ", proxy_delay);
}
if (tpb[NDTPA_PROXY_QLEN]) {
__u32 pqueue = rta_getattr_u32(tpb[NDTPA_PROXY_QLEN]);
fprintf(fp, "proxy_queue %u ", pqueue);
}
if (tpb[NDTPA_LOCKTIME]) {
unsigned long long locktime = rta_getattr_u64(tpb[NDTPA_LOCKTIME]);
fprintf(fp, "locktime %llu ", locktime);
}

View File

@ -96,6 +96,7 @@ int print_prefix(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[PREFIX_CACHEINFO]) {
struct prefix_cacheinfo *pc;
pc = (struct prefix_cacheinfo *)RTA_DATA(tb[PREFIX_CACHEINFO]);
fprintf(fp, "valid %u ", pc->valid_time);

View File

@ -198,8 +198,10 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
return 0;
if (filter.rvia.family) {
int family = r->rtm_family;
if (tb[RTA_VIA]) {
struct rtvia *via = RTA_DATA(tb[RTA_VIA]);
family = via->rtvia_family;
}
if (family != filter.rvia.family)
@ -226,6 +228,7 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
if (tb[RTA_VIA]) {
size_t len = RTA_PAYLOAD(tb[RTA_VIA]) - 2;
struct rtvia *rtvia = RTA_DATA(tb[RTA_VIA]);
via.family = rtvia->rtvia_family;
memcpy(&via.data, rtvia->rtvia_addr, len);
}
@ -255,6 +258,7 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
return 0;
if (filter.realmmask) {
__u32 realms = 0;
if (tb[RTA_FLOW])
realms = rta_getattr_u32(tb[RTA_FLOW]);
if ((realms^filter.realm)&filter.realmmask)
@ -262,6 +266,7 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
}
if (filter.iifmask) {
int iif = 0;
if (tb[RTA_IIF])
iif = *(int *)RTA_DATA(tb[RTA_IIF]);
if ((iif^filter.iif)&filter.iifmask)
@ -269,6 +274,7 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
}
if (filter.oifmask) {
int oif = 0;
if (tb[RTA_OIF])
oif = *(int *)RTA_DATA(tb[RTA_OIF]);
if ((oif^filter.oif)&filter.oifmask)
@ -276,6 +282,7 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
}
if (filter.markmask) {
int mark = 0;
if (tb[RTA_MARK])
mark = *(int *)RTA_DATA(tb[RTA_MARK]);
if ((mark ^ filter.mark) & filter.markmask)
@ -314,6 +321,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
char abuf[256];
int host_len;
__u32 table;
SPRINT_BUF(b1);
static int hz;
@ -340,6 +348,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (filter.flushb) {
struct nlmsghdr *fn;
if (NLMSG_ALIGN(filter.flushp) + n->nlmsg_len > filter.flushe) {
if (flush_update())
return -1;
@ -424,6 +433,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[RTA_VIA]) {
size_t len = RTA_PAYLOAD(tb[RTA_VIA]) - 2;
struct rtvia *via = RTA_DATA(tb[RTA_VIA]);
fprintf(fp, "via %s %s ",
family_name(via->rtvia_family),
format_host(via->rtvia_family, len, via->rtvia_addr,
@ -466,6 +476,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, "linkdown ");
if (tb[RTA_MARK]) {
unsigned int mark = *(unsigned int *)RTA_DATA(tb[RTA_MARK]);
if (mark) {
if (mark >= 16)
fprintf(fp, " mark 0x%x", mark);
@ -477,6 +488,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[RTA_FLOW] && filter.realmmask != ~0U) {
__u32 to = rta_getattr_u32(tb[RTA_FLOW]);
__u32 from = to>>16;
to &= 0xFFFF;
fprintf(fp, "realm%s ", from ? "s" : "");
if (from) {
@ -515,6 +527,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, "%s%x> ", first ? "<" : "", flags);
if (tb[RTA_CACHEINFO]) {
struct rta_cacheinfo *ci = RTA_DATA(tb[RTA_CACHEINFO]);
if (!hz)
hz = get_user_hz();
if (ci->rta_expires != 0)
@ -537,6 +550,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
}
} else if (r->rtm_family == AF_INET6) {
struct rta_cacheinfo *ci = NULL;
if (tb[RTA_CACHEINFO])
ci = RTA_DATA(tb[RTA_CACHEINFO]);
if ((r->rtm_flags & RTM_F_CLONED) || (ci && ci->rta_expires)) {
@ -563,7 +577,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
}
if (tb[RTA_METRICS]) {
int i;
unsigned mxlock = 0;
unsigned int mxlock = 0;
struct rtattr *mxrta[RTAX_MAX+1];
parse_rtattr(mxrta, RTAX_MAX, RTA_DATA(tb[RTA_METRICS]),
@ -663,6 +677,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[RTA_VIA]) {
size_t len = RTA_PAYLOAD(tb[RTA_VIA]) - 2;
struct rtvia *via = RTA_DATA(tb[RTA_VIA]);
fprintf(fp, "via %s %s ",
family_name(via->rtvia_family),
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)
if (tb[RTA_FLOW]) {
__u32 to = rta_getattr_u32(tb[RTA_FLOW]);
__u32 from = to>>16;
to &= 0xFFFF;
fprintf(fp, " realm%s ", from ? "s" : "");
if (from) {
@ -705,6 +721,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
}
if (tb[RTA_PREF]) {
unsigned int pref = rta_getattr_u8(tb[RTA_PREF]);
fprintf(fp, " pref ");
switch (pref) {
@ -737,6 +754,7 @@ static int parse_one_nh(struct nlmsghdr *n, struct rtmsg *r,
if (strcmp(*argv, "via") == 0) {
inet_prefix addr;
int family;
NEXT_ARG();
family = read_family(*argv);
if (family == AF_UNSPEC)
@ -760,7 +778,8 @@ static int parse_one_nh(struct nlmsghdr *n, struct rtmsg *r,
exit(1);
}
} else if (strcmp(*argv, "weight") == 0) {
unsigned w;
unsigned int w;
NEXT_ARG();
if (get_unsigned(&w, *argv, 0) || w == 0 || w > 256)
invarg("\"weight\" is invalid\n", *argv);
@ -769,6 +788,7 @@ static int parse_one_nh(struct nlmsghdr *n, struct rtmsg *r,
rtnh->rtnh_flags |= RTNH_F_ONLINK;
} else if (matches(*argv, "realms") == 0) {
__u32 realm;
NEXT_ARG();
if (get_rt_realms_or_raw(&realm, *argv))
invarg("\"realm\" value is invalid\n", *argv);
@ -829,7 +849,7 @@ static int parse_nexthops(struct nlmsghdr *n, struct rtmsg *r,
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 nlmsghdr n;
@ -838,7 +858,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
} req;
char mxbuf[256];
struct rtattr *mxrta = (void *)mxbuf;
unsigned mxlock = 0;
unsigned int mxlock = 0;
char *d = NULL;
int gw_ok = 0;
int dst_ok = 0;
@ -870,6 +890,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
while (argc > 0) {
if (strcmp(*argv, "src") == 0) {
inet_prefix addr;
NEXT_ARG();
get_addr(&addr, *argv, req.r.rtm_family);
if (req.r.rtm_family == AF_UNSPEC)
@ -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);
} else if (strcmp(*argv, "as") == 0) {
inet_prefix addr;
NEXT_ARG();
if (strcmp(*argv, "to") == 0) {
NEXT_ARG();
@ -888,6 +910,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
} else if (strcmp(*argv, "via") == 0) {
inet_prefix addr;
int family;
gw_ok = 1;
NEXT_ARG();
family = read_family(*argv);
@ -906,6 +929,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
&addr.family, addr.bytelen+2);
} else if (strcmp(*argv, "from") == 0) {
inet_prefix addr;
NEXT_ARG();
get_prefix(&addr, *argv, req.r.rtm_family);
if (req.r.rtm_family == AF_UNSPEC)
@ -916,12 +940,14 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
} else if (strcmp(*argv, "tos") == 0 ||
matches(*argv, "dsfield") == 0) {
__u32 tos;
NEXT_ARG();
if (rtnl_dsfield_a2n(&tos, *argv))
invarg("\"tos\" value is invalid\n", *argv);
req.r.rtm_tos = tos;
} else if (strcmp(*argv, "expires") == 0) {
__u32 expires;
NEXT_ARG();
if (get_u32(&expires, *argv, 0))
invarg("\"expires\" value is invalid\n", *argv);
@ -932,19 +958,22 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
matches(*argv, "priority") == 0 ||
strcmp(*argv, "preference") == 0) {
__u32 metric;
NEXT_ARG();
if (get_u32(&metric, *argv, 0))
invarg("\"metric\" value is invalid\n", *argv);
addattr32(&req.n, sizeof(req), RTA_PRIORITY, metric);
} else if (strcmp(*argv, "scope") == 0) {
__u32 scope = 0;
NEXT_ARG();
if (rtnl_rtscope_a2n(&scope, *argv))
invarg("invalid \"scope\" value\n", *argv);
req.r.rtm_scope = scope;
scope_ok = 1;
} else if (strcmp(*argv, "mtu") == 0) {
unsigned mtu;
unsigned int mtu;
NEXT_ARG();
if (strcmp(*argv, "lock") == 0) {
mxlock |= (1<<RTAX_MTU);
@ -954,7 +983,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
invarg("\"mtu\" value is invalid\n", *argv);
rta_addattr32(mxrta, sizeof(mxbuf), RTAX_MTU, mtu);
} else if (strcmp(*argv, "hoplimit") == 0) {
unsigned hoplimit;
unsigned int hoplimit;
NEXT_ARG();
if (strcmp(*argv, "lock") == 0) {
mxlock |= (1<<RTAX_HOPLIMIT);
@ -964,7 +994,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
invarg("\"hoplimit\" value is invalid\n", *argv);
rta_addattr32(mxrta, sizeof(mxbuf), RTAX_HOPLIMIT, hoplimit);
} else if (strcmp(*argv, "advmss") == 0) {
unsigned mss;
unsigned int mss;
NEXT_ARG();
if (strcmp(*argv, "lock") == 0) {
mxlock |= (1<<RTAX_ADVMSS);
@ -974,7 +1005,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
invarg("\"mss\" value is invalid\n", *argv);
rta_addattr32(mxrta, sizeof(mxbuf), RTAX_ADVMSS, mss);
} else if (matches(*argv, "reordering") == 0) {
unsigned reord;
unsigned int reord;
NEXT_ARG();
if (strcmp(*argv, "lock") == 0) {
mxlock |= (1<<RTAX_REORDERING);
@ -984,7 +1016,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
invarg("\"reordering\" value is invalid\n", *argv);
rta_addattr32(mxrta, sizeof(mxbuf), RTAX_REORDERING, reord);
} else if (strcmp(*argv, "rtt") == 0) {
unsigned rtt;
unsigned int rtt;
NEXT_ARG();
if (strcmp(*argv, "lock") == 0) {
mxlock |= (1<<RTAX_RTT);
@ -995,7 +1028,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
rta_addattr32(mxrta, sizeof(mxbuf), RTAX_RTT,
(raw) ? rtt : rtt * 8);
} else if (strcmp(*argv, "rto_min") == 0) {
unsigned rto_min;
unsigned int rto_min;
NEXT_ARG();
mxlock |= (1<<RTAX_RTO_MIN);
if (get_time_rtt(&rto_min, *argv, &raw))
@ -1004,7 +1038,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
rta_addattr32(mxrta, sizeof(mxbuf), RTAX_RTO_MIN,
rto_min);
} else if (matches(*argv, "window") == 0) {
unsigned win;
unsigned int win;
NEXT_ARG();
if (strcmp(*argv, "lock") == 0) {
mxlock |= (1<<RTAX_WINDOW);
@ -1014,7 +1049,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
invarg("\"window\" value is invalid\n", *argv);
rta_addattr32(mxrta, sizeof(mxbuf), RTAX_WINDOW, win);
} else if (matches(*argv, "cwnd") == 0) {
unsigned win;
unsigned int win;
NEXT_ARG();
if (strcmp(*argv, "lock") == 0) {
mxlock |= (1<<RTAX_CWND);
@ -1024,7 +1060,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
invarg("\"cwnd\" value is invalid\n", *argv);
rta_addattr32(mxrta, sizeof(mxbuf), RTAX_CWND, win);
} else if (matches(*argv, "initcwnd") == 0) {
unsigned win;
unsigned int win;
NEXT_ARG();
if (strcmp(*argv, "lock") == 0) {
mxlock |= (1<<RTAX_INITCWND);
@ -1034,7 +1071,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
invarg("\"initcwnd\" value is invalid\n", *argv);
rta_addattr32(mxrta, sizeof(mxbuf), RTAX_INITCWND, win);
} else if (matches(*argv, "initrwnd") == 0) {
unsigned win;
unsigned int win;
NEXT_ARG();
if (strcmp(*argv, "lock") == 0) {
mxlock |= (1<<RTAX_INITRWND);
@ -1058,7 +1096,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
rta_addattr32(mxrta, sizeof(mxbuf), RTAX_FEATURES, features);
} else if (matches(*argv, "quickack") == 0) {
unsigned quickack;
unsigned int quickack;
NEXT_ARG();
if (get_unsigned(&quickack, *argv, 0))
invarg("\"quickack\" value is invalid\n", *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,
strlen(*argv));
} else if (matches(*argv, "rttvar") == 0) {
unsigned win;
unsigned int win;
NEXT_ARG();
if (strcmp(*argv, "lock") == 0) {
mxlock |= (1<<RTAX_RTTVAR);
@ -1085,7 +1125,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
rta_addattr32(mxrta, sizeof(mxbuf), RTAX_RTTVAR,
(raw) ? win : win * 4);
} else if (matches(*argv, "ssthresh") == 0) {
unsigned win;
unsigned int win;
NEXT_ARG();
if (strcmp(*argv, "lock") == 0) {
mxlock |= (1<<RTAX_SSTHRESH);
@ -1096,6 +1137,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
rta_addattr32(mxrta, sizeof(mxbuf), RTAX_SSTHRESH, win);
} else if (matches(*argv, "realms") == 0) {
__u32 realm;
NEXT_ARG();
if (get_rt_realms_or_raw(&realm, *argv))
invarg("\"realm\" value is invalid\n", *argv);
@ -1107,12 +1149,14 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
break;
} else if (matches(*argv, "protocol") == 0) {
__u32 prot;
NEXT_ARG();
if (rtnl_rtprot_a2n(&prot, *argv))
invarg("\"protocol\" value is invalid\n", *argv);
req.r.rtm_protocol = prot;
} else if (matches(*argv, "table") == 0) {
__u32 tid;
NEXT_ARG();
if (rtnl_rttable_a2n(&tid, *argv))
invarg("\"table\" value is invalid\n", *argv);
@ -1129,6 +1173,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
d = *argv;
} else if (matches(*argv, "pref") == 0) {
__u8 pref;
NEXT_ARG();
if (strcmp(*argv, "low") == 0)
pref = ICMPV6_ROUTER_PREF_LOW;
@ -1362,6 +1407,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
while (argc > 0) {
if (matches(*argv, "table") == 0) {
__u32 tid;
NEXT_ARG();
if (rtnl_rttable_a2n(&tid, *argv)) {
if (strcmp(*argv, "all") == 0) {
@ -1381,6 +1427,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
} else if (strcmp(*argv, "tos") == 0 ||
matches(*argv, "dsfield") == 0) {
__u32 tos;
NEXT_ARG();
if (rtnl_dsfield_a2n(&tos, *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)
filter.tosmask = -1;
} else if (matches(*argv, "protocol") == 0) {
__u32 prot = 0;
NEXT_ARG();
filter.protocolmask = -1;
if (rtnl_rtprot_a2n(&prot, *argv)) {
@ -1399,6 +1447,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
filter.protocol = prot;
} else if (matches(*argv, "scope") == 0) {
__u32 scope = 0;
NEXT_ARG();
filter.scopemask = -1;
if (rtnl_rtscope_a2n(&scope, *argv)) {
@ -1410,6 +1459,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
filter.scope = scope;
} else if (matches(*argv, "type") == 0) {
int type;
NEXT_ARG();
filter.typemask = -1;
if (rtnl_rtntype_a2n(&type, *argv))
@ -1428,6 +1478,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
filter.markmask = -1;
} else if (strcmp(*argv, "via") == 0) {
int family;
NEXT_ARG();
family = read_family(*argv);
if (family == AF_UNSPEC)
@ -1440,6 +1491,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
get_prefix(&filter.rprefsrc, *argv, do_ipv6);
} else if (matches(*argv, "realms") == 0) {
__u32 realm;
NEXT_ARG();
if (get_rt_realms_or_raw(&realm, *argv))
invarg("invalid realms\n", *argv);
@ -1624,12 +1676,14 @@ static int iproute_get(int argc, char **argv)
if (strcmp(*argv, "tos") == 0 ||
matches(*argv, "dsfield") == 0) {
__u32 tos;
NEXT_ARG();
if (rtnl_dsfield_a2n(&tos, *argv))
invarg("TOS value is invalid\n", *argv);
req.r.rtm_tos = tos;
} else if (matches(*argv, "from") == 0) {
inet_prefix addr;
NEXT_ARG();
if (matches(*argv, "help") == 0)
usage();
@ -1656,6 +1710,7 @@ static int iproute_get(int argc, char **argv)
connected = 1;
} else {
inet_prefix addr;
if (strcmp(*argv, "to") == 0) {
NEXT_ARG();
}

View File

@ -203,6 +203,7 @@ static int parse_encap_ip(struct rtattr *rta, size_t len, int *argcp, char ***ar
while (argc > 0) {
if (strcmp(*argv, "id") == 0) {
__u64 id;
NEXT_ARG();
if (id_ok++)
duparg2("id", *argv);
@ -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));
} else if (strcmp(*argv, "dst") == 0) {
inet_prefix addr;
NEXT_ARG();
if (dst_ok++)
duparg2("dst", *argv);
@ -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);
} else if (strcmp(*argv, "tos") == 0) {
__u32 tos;
NEXT_ARG();
if (tos_ok++)
duparg2("tos", *argv);
@ -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);
} else if (strcmp(*argv, "ttl") == 0) {
__u8 ttl;
NEXT_ARG();
if (ttl_ok++)
duparg2("ttl", *argv);
@ -276,6 +280,7 @@ static int parse_encap_ip6(struct rtattr *rta, size_t len, int *argcp, char ***a
while (argc > 0) {
if (strcmp(*argv, "id") == 0) {
__u64 id;
NEXT_ARG();
if (id_ok++)
duparg2("id", *argv);
@ -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));
} else if (strcmp(*argv, "dst") == 0) {
inet_prefix addr;
NEXT_ARG();
if (dst_ok++)
duparg2("dst", *argv);
@ -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);
} else if (strcmp(*argv, "tc") == 0) {
__u32 tc;
NEXT_ARG();
if (tos_ok++)
duparg2("tc", *argv);
@ -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);
} else if (strcmp(*argv, "hoplimit") == 0) {
__u8 hoplimit;
NEXT_ARG();
if (ttl_ok++)
duparg2("hoplimit", *argv);

View File

@ -58,6 +58,7 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
__u32 table;
struct rtattr *tb[FRA_MAX+1];
char abuf[256];
SPRINT_BUF(b1);
if (n->nlmsg_type != RTM_NEWRULE && n->nlmsg_type != RTM_DELRULE)
@ -157,12 +158,14 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[FRA_SUPPRESS_PREFIXLEN]) {
int pl = rta_getattr_u32(tb[FRA_SUPPRESS_PREFIXLEN]);
if (pl != -1) {
fprintf(fp, "suppress_prefixlength %d ", pl);
}
}
if (tb[FRA_SUPPRESS_IFGROUP]) {
int group = rta_getattr_u32(tb[FRA_SUPPRESS_IFGROUP]);
if (group != -1) {
SPRINT_BUF(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)
if (tb[FRA_FLOW]) {
__u32 to = rta_getattr_u32(tb[FRA_FLOW]);
__u32 from = to>>16;
to &= 0xFFFF;
if (from) {
fprintf(fp, "realms %s/",
@ -351,12 +355,14 @@ static int iprule_modify(int cmd, int argc, char **argv)
req.r.rtm_flags |= FIB_RULE_INVERT;
} else if (strcmp(*argv, "from") == 0) {
inet_prefix dst;
NEXT_ARG();
get_prefix(&dst, *argv, req.r.rtm_family);
req.r.rtm_src_len = dst.bitlen;
addattr_l(&req.n, sizeof(req), FRA_SRC, &dst.data, dst.bytelen);
} else if (strcmp(*argv, "to") == 0) {
inet_prefix dst;
NEXT_ARG();
get_prefix(&dst, *argv, req.r.rtm_family);
req.r.rtm_dst_len = dst.bitlen;
@ -365,6 +371,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
matches(*argv, "order") == 0 ||
matches(*argv, "priority") == 0) {
__u32 pref;
NEXT_ARG();
if (get_u32(&pref, *argv, 0))
invarg("preference value is invalid\n", *argv);
@ -372,6 +379,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
} else if (strcmp(*argv, "tos") == 0 ||
matches(*argv, "dsfield") == 0) {
__u32 tos;
NEXT_ARG();
if (rtnl_dsfield_a2n(&tos, *argv))
invarg("TOS value is invalid\n", *argv);
@ -379,6 +387,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
} else if (strcmp(*argv, "fwmark") == 0) {
char *slash;
__u32 fwmark, fwmask;
NEXT_ARG();
if ((slash = strchr(*argv, '/')) != NULL)
*slash = '\0';
@ -392,6 +401,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
}
} else if (matches(*argv, "realms") == 0) {
__u32 realm;
NEXT_ARG();
if (get_rt_realms_or_raw(&realm, *argv))
invarg("invalid realms\n", *argv);
@ -399,6 +409,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
} else if (matches(*argv, "table") == 0 ||
strcmp(*argv, "lookup") == 0) {
__u32 tid;
NEXT_ARG();
if (rtnl_rttable_a2n(&tid, *argv))
invarg("invalid table ID\n", *argv);
@ -412,6 +423,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
} else if (matches(*argv, "suppress_prefixlength") == 0 ||
strcmp(*argv, "sup_pl") == 0) {
int pl;
NEXT_ARG();
if (get_s32(&pl, *argv, 0) || pl < 0)
invarg("suppress_prefixlength value is invalid\n", *argv);
@ -420,6 +432,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
strcmp(*argv, "sup_group") == 0) {
NEXT_ARG();
int group;
if (rtnl_group_a2n(&group, *argv))
invarg("Invalid \"suppress_ifgroup\" value\n", *argv);
addattr32(&req.n, sizeof(req), FRA_SUPPRESS_IFGROUP, group);
@ -446,6 +459,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
usage();
else if (matches(*argv, "goto") == 0) {
__u32 target;
type = FR_ACT_GOTO;
NEXT_ARG();
if (get_u32(&target, *argv, 0))

View File

@ -168,13 +168,11 @@ static int iptoken_set(int argc, char **argv)
}
if (!have_token) {
fprintf(stderr, "Not enough information: token "
"is required.\n");
fprintf(stderr, "Not enough information: token is required.\n");
return -1;
}
if (!have_dev) {
fprintf(stderr, "Not enough information: \"dev\" "
"argument is required.\n");
fprintf(stderr, "Not enough information: \"dev\" argument is required.\n");
return -1;
}

View File

@ -140,6 +140,7 @@ static int parse_args(int argc, char **argv, struct ifreq *ifr, uid_t *uid, gid_
*uid = user;
else {
struct passwd *pw = getpwnam(*argv);
if (!pw) {
fprintf(stderr, "invalid user \"%s\"\n", *argv);
exit(-1);
@ -156,6 +157,7 @@ static int parse_args(int argc, char **argv, struct ifreq *ifr, uid_t *uid, gid_
*gid = group;
else {
struct group *gr = getgrnam(*argv);
if (!gr) {
fprintf(stderr, "invalid group \"%s\"\n", *argv);
exit(-1);

View File

@ -124,6 +124,7 @@ int xfrm_xfrmproto_getbyname(char *name)
for (i = 0; ; i++) {
const struct typeent *t = &xfrmproto_types[i];
if (!t->t_name || t->t_type == -1)
break;
@ -141,6 +142,7 @@ const char *strxf_xfrmproto(__u8 proto)
for (i = 0; ; i++) {
const struct typeent *t = &xfrmproto_types[i];
if (!t->t_name || t->t_type == -1)
break;
@ -165,6 +167,7 @@ int xfrm_algotype_getbyname(char *name)
for (i = 0; ; i++) {
const struct typeent *t = &algo_types[i];
if (!t->t_name || t->t_type == -1)
break;
@ -182,6 +185,7 @@ const char *strxf_algotype(int type)
for (i = 0; ; i++) {
const struct typeent *t = &algo_types[i];
if (!t->t_name || t->t_type == -1)
break;
@ -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) {
__u32 spi = ntohl(id->spi);
fprintf(fp, "spi 0x%08x", spi);
if (show_stats > 0)
fprintf(fp, "(%u)", spi);
@ -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 char str[32];
if (limit == XFRM_INF)
strcpy(str, "(INF)");
else
@ -692,36 +698,42 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
if (tb[XFRMA_MARK]) {
struct rtattr *rta = tb[XFRMA_MARK];
struct xfrm_mark *m = (struct xfrm_mark *) RTA_DATA(rta);
fprintf(fp, "\tmark %#x/%#x", m->v, m->m);
fprintf(fp, "%s", _SL_);
}
if (tb[XFRMA_ALG_AUTH] && !tb[XFRMA_ALG_AUTH_TRUNC]) {
struct rtattr *rta = tb[XFRMA_ALG_AUTH];
xfrm_algo_print((struct xfrm_algo *) RTA_DATA(rta),
XFRMA_ALG_AUTH, RTA_PAYLOAD(rta), fp, prefix);
}
if (tb[XFRMA_ALG_AUTH_TRUNC]) {
struct rtattr *rta = tb[XFRMA_ALG_AUTH_TRUNC];
xfrm_auth_trunc_print((struct xfrm_algo_auth *) RTA_DATA(rta),
RTA_PAYLOAD(rta), fp, prefix);
}
if (tb[XFRMA_ALG_AEAD]) {
struct rtattr *rta = tb[XFRMA_ALG_AEAD];
xfrm_aead_print((struct xfrm_algo_aead *)RTA_DATA(rta),
RTA_PAYLOAD(rta), fp, prefix);
}
if (tb[XFRMA_ALG_CRYPT]) {
struct rtattr *rta = tb[XFRMA_ALG_CRYPT];
xfrm_algo_print((struct xfrm_algo *) RTA_DATA(rta),
XFRMA_ALG_CRYPT, RTA_PAYLOAD(rta), fp, prefix);
}
if (tb[XFRMA_ALG_COMP]) {
struct rtattr *rta = tb[XFRMA_ALG_COMP];
xfrm_algo_print((struct xfrm_algo *) RTA_DATA(rta),
XFRMA_ALG_COMP, RTA_PAYLOAD(rta), fp, prefix);
}
@ -765,6 +777,7 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
if (tb[XFRMA_TMPL]) {
struct rtattr *rta = tb[XFRMA_TMPL];
xfrm_tmpl_print((struct xfrm_user_tmpl *) RTA_DATA(rta),
RTA_PAYLOAD(rta), fp, prefix);
}
@ -1238,6 +1251,7 @@ static int xfrm_selector_upspec_parse(struct xfrm_selector *sel,
upspec = 0;
else {
struct protoent *pp;
pp = getprotobyname(*argv);
if (pp)
upspec = pp->p_proto;
@ -1304,7 +1318,7 @@ static int xfrm_selector_upspec_parse(struct xfrm_selector *sel,
filter.upspec_dport_mask = XFRM_FILTER_MASK_FULL;
} else if (strcmp(*argv, "key") == 0) {
unsigned uval;
unsigned int uval;
grekey = *argv;

View File

@ -61,11 +61,11 @@ static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
struct rtattr *greinfo[IFLA_GRE_MAX + 1];
__u16 iflags = 0;
__u16 oflags = 0;
unsigned ikey = 0;
unsigned okey = 0;
unsigned saddr = 0;
unsigned daddr = 0;
unsigned link = 0;
unsigned int ikey = 0;
unsigned int okey = 0;
unsigned int saddr = 0;
unsigned int daddr = 0;
unsigned int link = 0;
__u8 pmtudisc = 1;
__u8 ttl = 0;
__u8 tos = 0;
@ -156,7 +156,7 @@ get_failed:
while (argc > 0) {
if (!matches(*argv, "key")) {
unsigned uval;
unsigned int uval;
NEXT_ARG();
iflags |= GRE_KEY;
@ -174,7 +174,7 @@ get_failed:
ikey = okey = uval;
} else if (!matches(*argv, "ikey")) {
unsigned uval;
unsigned int uval;
NEXT_ARG();
iflags |= GRE_KEY;
@ -189,7 +189,7 @@ get_failed:
}
ikey = uval;
} else if (!matches(*argv, "okey")) {
unsigned uval;
unsigned int uval;
NEXT_ARG();
oflags |= GRE_KEY;
@ -239,7 +239,7 @@ get_failed:
}
} else if (!matches(*argv, "ttl") ||
!matches(*argv, "hoplimit")) {
unsigned uval;
unsigned int uval;
NEXT_ARG();
if (strcmp(*argv, "inherit") != 0) {
@ -343,14 +343,14 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
char s2[64];
const char *local = "any";
const char *remote = "any";
unsigned iflags = 0;
unsigned oflags = 0;
unsigned int iflags = 0;
unsigned int oflags = 0;
if (!tb)
return;
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)
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[])
fprintf(f, "remote %s ", remote);
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)
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[])
fprintf(f, "local %s ", local);
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);
if (n)

View File

@ -71,13 +71,13 @@ static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
struct rtattr *greinfo[IFLA_GRE_MAX + 1];
__u16 iflags = 0;
__u16 oflags = 0;
unsigned ikey = 0;
unsigned okey = 0;
unsigned int ikey = 0;
unsigned int okey = 0;
struct in6_addr raddr = IN6ADDR_ANY_INIT;
struct in6_addr laddr = IN6ADDR_ANY_INIT;
unsigned link = 0;
unsigned flowinfo = 0;
unsigned flags = 0;
unsigned int link = 0;
unsigned int flowinfo = 0;
unsigned int flags = 0;
__u8 hop_limit = DEFAULT_TNL_HOP_LIMIT;
__u8 encap_limit = IPV6_DEFAULT_TNL_ENCAP_LIMIT;
int len;
@ -152,7 +152,7 @@ get_failed:
while (argc > 0) {
if (!matches(*argv, "key")) {
unsigned uval;
unsigned int uval;
NEXT_ARG();
iflags |= GRE_KEY;
@ -170,7 +170,7 @@ get_failed:
ikey = okey = uval;
} else if (!matches(*argv, "ikey")) {
unsigned uval;
unsigned int uval;
NEXT_ARG();
iflags |= GRE_KEY;
@ -185,7 +185,7 @@ get_failed:
}
ikey = uval;
} else if (!matches(*argv, "okey")) {
unsigned uval;
unsigned int uval;
NEXT_ARG();
oflags |= GRE_KEY;
@ -215,6 +215,7 @@ get_failed:
oflags |= GRE_CSUM;
} else if (!matches(*argv, "remote")) {
inet_prefix addr;
NEXT_ARG();
get_prefix(&addr, *argv, preferred_family);
if (addr.family == AF_UNSPEC)
@ -222,6 +223,7 @@ get_failed:
memcpy(&raddr, &addr.data, sizeof(raddr));
} else if (!matches(*argv, "local")) {
inet_prefix addr;
NEXT_ARG();
get_prefix(&addr, *argv, preferred_family);
if (addr.family == AF_UNSPEC)
@ -238,6 +240,7 @@ get_failed:
} else if (!matches(*argv, "ttl") ||
!matches(*argv, "hoplimit")) {
__u8 uval;
NEXT_ARG();
if (get_u8(&uval, *argv, 0))
invarg("invalid TTL", *argv);
@ -246,6 +249,7 @@ get_failed:
!matches(*argv, "tclass") ||
!matches(*argv, "dsfield")) {
__u8 uval;
NEXT_ARG();
if (strcmp(*argv, "inherit") == 0)
flags |= IP6_TNL_F_USE_ORIG_TCLASS;
@ -258,6 +262,7 @@ get_failed:
} else if (strcmp(*argv, "flowlabel") == 0 ||
strcmp(*argv, "fl") == 0) {
__u32 uval;
NEXT_ARG();
if (strcmp(*argv, "inherit") == 0)
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[])
char s2[64];
const char *local = "any";
const char *remote = "any";
unsigned iflags = 0;
unsigned oflags = 0;
unsigned flags = 0;
unsigned flowinfo = 0;
unsigned int iflags = 0;
unsigned int oflags = 0;
unsigned int flags = 0;
unsigned int flowinfo = 0;
struct in6_addr in6_addr_any = IN6ADDR_ANY_INIT;
if (!tb)
@ -318,6 +323,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (tb[IFLA_GRE_REMOTE]) {
struct in6_addr addr;
memcpy(&addr, RTA_DATA(tb[IFLA_GRE_REMOTE]), 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[])
if (tb[IFLA_GRE_LOCAL]) {
struct in6_addr addr;
memcpy(&addr, RTA_DATA(tb[IFLA_GRE_LOCAL]), 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[])
fprintf(f, "local %s ", local);
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);
if (n)

View File

@ -159,6 +159,7 @@ get_failed:
invarg("Cannot guess tunnel mode.", *argv);
} else if (strcmp(*argv, "remote") == 0) {
inet_prefix addr;
NEXT_ARG();
get_prefix(&addr, *argv, preferred_family);
if (addr.family == AF_UNSPEC)
@ -166,6 +167,7 @@ get_failed:
memcpy(&raddr, addr.data, addr.bytelen);
} else if (strcmp(*argv, "local") == 0) {
inet_prefix addr;
NEXT_ARG();
get_prefix(&addr, *argv, preferred_family);
if (addr.family == AF_UNSPEC)
@ -180,6 +182,7 @@ get_failed:
strcmp(*argv, "ttl") == 0 ||
strcmp(*argv, "hlim") == 0) {
__u8 uval;
NEXT_ARG();
if (get_u8(&uval, *argv, 0))
invarg("invalid HLIM", *argv);
@ -190,6 +193,7 @@ get_failed:
flags |= IP6_TNL_F_IGN_ENCAP_LIMIT;
} else {
__u8 uval;
if (get_u8(&uval, *argv, 0) < -1)
invarg("invalid ELIM", *argv);
encap_limit = uval;
@ -200,6 +204,7 @@ get_failed:
strcmp(*argv, "tos") == 0 ||
matches(*argv, "dsfield") == 0) {
__u8 uval;
NEXT_ARG();
flowinfo &= ~IP6_FLOWINFO_TCLASS;
if (strcmp(*argv, "inherit") == 0)
@ -213,6 +218,7 @@ get_failed:
} else if (strcmp(*argv, "flowlabel") == 0 ||
strcmp(*argv, "fl") == 0) {
__u32 uval;
NEXT_ARG();
flowinfo &= ~IP6_FLOWINFO_FLOWLABEL;
if (strcmp(*argv, "inherit") == 0)
@ -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])) {
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);
if (n)

View File

@ -197,6 +197,7 @@ get_failed:
strcmp(*argv, "tclass") == 0 ||
matches(*argv, "dsfield") == 0) {
__u32 uval;
NEXT_ARG();
if (strcmp(*argv, "inherit") != 0) {
if (rtnl_dsfield_a2n(&uval, *argv))
@ -262,6 +263,7 @@ get_failed:
encapflags &= ~TUNNEL_ENCAP_FLAG_REMCSUM;
} else if (strcmp(*argv, "6rd-prefix") == 0) {
inet_prefix prefix;
NEXT_ARG();
if (get_prefix(&prefix, *argv, AF_INET6))
invarg("invalid 6rd_prefix\n", *argv);
@ -269,6 +271,7 @@ get_failed:
ip6rdprefixlen = prefix.bitlen;
} else if (strcmp(*argv, "6rd-relay_prefix") == 0) {
inet_prefix prefix;
NEXT_ARG();
if (get_prefix(&prefix, *argv, AF_INET))
invarg("invalid 6rd-relay_prefix\n", *argv);
@ -276,6 +279,7 @@ get_failed:
ip6rdrelayprefixlen = prefix.bitlen;
} else if (strcmp(*argv, "6rd-reset") == 0) {
inet_prefix prefix;
get_prefix(&prefix, "2002::", AF_INET6);
memcpy(&ip6rdprefix, prefix.data, 16);
ip6rdprefixlen = 16;
@ -332,7 +336,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
return;
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)
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[
fprintf(f, "remote %s ", remote);
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)
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[
fprintf(f, "local %s ", local);
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);
if (n)

View File

@ -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 *linkinfo[IFLA_INFO_MAX+1];
struct rtattr *vtiinfo[IFLA_VTI_MAX + 1];
unsigned ikey = 0;
unsigned okey = 0;
unsigned saddr = 0;
unsigned daddr = 0;
unsigned link = 0;
unsigned int ikey = 0;
unsigned int okey = 0;
unsigned int saddr = 0;
unsigned int daddr = 0;
unsigned int link = 0;
int len;
if (!(n->nlmsg_flags & NLM_F_CREATE)) {
@ -114,7 +114,7 @@ get_failed:
while (argc > 0) {
if (!matches(*argv, "key")) {
unsigned uval;
unsigned int uval;
NEXT_ARG();
if (strchr(*argv, '.'))
@ -130,7 +130,7 @@ get_failed:
ikey = okey = uval;
} else if (!matches(*argv, "ikey")) {
unsigned uval;
unsigned int uval;
NEXT_ARG();
if (strchr(*argv, '.'))
@ -144,7 +144,7 @@ get_failed:
}
ikey = uval;
} else if (!matches(*argv, "okey")) {
unsigned uval;
unsigned int uval;
NEXT_ARG();
if (strchr(*argv, '.'))
@ -207,7 +207,7 @@ static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
return;
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)
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[])
fprintf(f, "remote %s ", remote);
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)
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[])
fprintf(f, "local %s ", local);
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);
if (n)

View File

@ -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 in6_addr saddr;
struct in6_addr daddr;
unsigned ikey = 0;
unsigned okey = 0;
unsigned link = 0;
unsigned int ikey = 0;
unsigned int okey = 0;
unsigned int link = 0;
int len;
if (!(n->nlmsg_flags & NLM_F_CREATE)) {
@ -110,7 +110,7 @@ get_failed:
while (argc > 0) {
if (!matches(*argv, "key")) {
unsigned uval;
unsigned int uval;
NEXT_ARG();
if (strchr(*argv, '.'))
@ -126,7 +126,7 @@ get_failed:
ikey = okey = uval;
} else if (!matches(*argv, "ikey")) {
unsigned uval;
unsigned int uval;
NEXT_ARG();
if (strchr(*argv, '.'))
@ -140,7 +140,7 @@ get_failed:
}
ikey = uval;
} else if (!matches(*argv, "okey")) {
unsigned uval;
unsigned int uval;
NEXT_ARG();
if (strchr(*argv, '.'))
@ -160,6 +160,7 @@ get_failed:
exit(-1);
} else {
inet_prefix addr;
get_prefix(&addr, *argv, AF_INET6);
memcpy(&daddr, addr.data, addr.bytelen);
}
@ -170,6 +171,7 @@ get_failed:
exit(-1);
} else {
inet_prefix addr;
get_prefix(&addr, *argv, AF_INET6);
memcpy(&saddr, addr.data, addr.bytelen);
}
@ -222,7 +224,7 @@ static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
fprintf(f, "local %s ", local);
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);
if (n)

View File

@ -25,7 +25,7 @@
#include "utils.h"
#include "libnetlink.h"
int resolve_hosts = 0;
int resolve_hosts;
static int init_phase = 1;
static void write_stamp(FILE *fp)
@ -49,6 +49,7 @@ static int dump_msg(const struct sockaddr_nl *who, struct rtnl_ctrl_data *ctrl,
struct nlmsghdr *n, void *arg)
{
FILE *fp = (FILE *)arg;
if (!init_phase)
write_stamp(fp);
fwrite((void *)n, 1, NLMSG_ALIGN(n->nlmsg_len), fp);
@ -75,7 +76,7 @@ main(int argc, char **argv)
FILE *fp;
struct rtnl_handle rth;
int family = AF_UNSPEC;
unsigned groups = ~0U;
unsigned int groups = ~0U;
int llink = 0;
int laddr = 0;
int lroute = 0;

View File

@ -168,6 +168,7 @@ static int process_msg(const struct sockaddr_nl *who, struct nlmsghdr *n,
if (f.flushb) {
struct nlmsghdr *fn;
TCPM_REQUEST(req2, 128, TCP_METRICS_CMD_DEL, NLM_F_REQUEST);
addattr_l(&req2.n, sizeof(req2), atype, &daddr.data,
@ -333,6 +334,7 @@ static int tcpm_do_cmd(int cmd, int argc, char **argv)
if (strcmp(*argv, "src") == 0 ||
strcmp(*argv, "source") == 0) {
char *who = *argv;
NEXT_ARG();
if (matches(*argv, "help") == 0)
usage();
@ -354,6 +356,7 @@ static int tcpm_do_cmd(int cmd, int argc, char **argv)
}
} else {
char *who = "address";
if (strcmp(*argv, "addr") == 0 ||
strcmp(*argv, "address") == 0) {
who = *argv;
@ -504,7 +507,7 @@ int do_tcp_metrics(int argc, char **argv)
if (matches(argv[0], "help") == 0)
usage();
fprintf(stderr, "Command \"%s\" is unknown, "
"try \"ip tcp_metrics help\".\n", *argv);
fprintf(stderr, "Command \"%s\" is unknown, try \"ip tcp_metrics help\".\n",
*argv);
exit(-1);
}

View File

@ -183,7 +183,7 @@ int tnl_ioctl_get_6rd(const char *name, void *p)
__be32 tnl_parse_key(const char *name, const char *key)
{
unsigned uval;
unsigned int uval;
if (strchr(key, '.'))
return get_addr32(key);

View File

@ -71,6 +71,7 @@ static int xfrm_acquire_print(const struct sockaddr_nl *who,
fprintf(fp, "proto %s ", strxf_xfrmproto(xacq->id.proto));
if (show_stats > 0 || xacq->id.spi) {
__u32 spi = ntohl(xacq->id.spi);
fprintf(fp, "spi 0x%08x", spi);
if (show_stats > 0)
fprintf(fp, "(%u)", spi);
@ -211,6 +212,7 @@ static int xfrm_report_print(const struct sockaddr_nl *who,
static void xfrm_ae_flags_print(__u32 flags, void *arg)
{
FILE *fp = (FILE *)arg;
fprintf(fp, " (0x%x) ", flags);
if (!flags)
return;
@ -353,7 +355,7 @@ extern struct rtnl_handle rth;
int do_xfrm_monitor(int argc, char **argv)
{
char *file = NULL;
unsigned groups = ~((unsigned)0); /* XXX */
unsigned int groups = ~((unsigned)0); /* XXX */
int lacquire = 0;
int lexpire = 0;
int laevent = 0;

View File

@ -33,7 +33,7 @@
#include "xfrm.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
/*
@ -241,7 +241,7 @@ int xfrm_sctx_parse(char *ctxstr, char *s,
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 {
@ -526,7 +526,7 @@ int xfrm_policy_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
fprintf(fp, "Expired ");
if (n->nlmsg_type == XFRM_MSG_DELPOLICY) {
//xfrm_policy_id_print();
/* xfrm_policy_id_print(); */
if (!tb[XFRMA_POLICY]) {
fprintf(stderr, "Buggy XFRM_MSG_DELPOLICY: no XFRMA_POLICY\n");
return -1;
@ -972,6 +972,7 @@ static int print_spdinfo( struct nlmsghdr *n, void *arg)
}
if (tb[XFRMA_SPD_IPV4_HTHRESH]) {
struct xfrmu_spdhthresh *th;
if (RTA_PAYLOAD(tb[XFRMA_SPD_IPV4_HTHRESH]) < sizeof(*th)) {
fprintf(stderr, "SPDinfo: Wrong len %d\n", len);
return -1;
@ -985,6 +986,7 @@ static int print_spdinfo( struct nlmsghdr *n, void *arg)
}
if (tb[XFRMA_SPD_IPV6_HTHRESH]) {
struct xfrmu_spdhthresh *th;
if (RTA_PAYLOAD(tb[XFRMA_SPD_IPV6_HTHRESH]) < sizeof(*th)) {
fprintf(stderr, "SPDinfo: Wrong len %d\n", len);
return -1;

View File

@ -32,7 +32,7 @@
#include "xfrm.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
/*
@ -266,7 +266,7 @@ static int xfrm_state_extra_flag_parse(__u32 *extra_flags, int *argcp, char ***a
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 {
@ -408,6 +408,7 @@ static int xfrm_state_modify(int cmd, unsigned flags, int argc, char **argv)
} else {
/* try to assume ALGO */
int type = xfrm_algotype_getbyname(*argv);
switch (type) {
case XFRMA_ALG_AEAD:
case XFRMA_ALG_CRYPT:
@ -924,7 +925,7 @@ int xfrm_state_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
parse_rtattr(tb, XFRMA_MAX, rta, len);
if (n->nlmsg_type == XFRM_MSG_DELSA) {
//xfrm_policy_id_print();
/* xfrm_policy_id_print(); */
if (!tb[XFRMA_SA]) {
fprintf(stderr, "Buggy XFRM_MSG_DELSA: no XFRMA_SA\n");