Merge branch 'iproute2-master' into iproute2-next

Conflicts:
	ip/iproute_lwtunnel.c

In addition to merge conflict between bd59e5b151 and 94a8722f2f,
updated the code added by the latter commit based on the change of the
former (ie., added ret = to the new rta_addattr_l).

Signed-off-by: David Ahern <dsahern@gmail.com>
This commit is contained in:
David Ahern 2018-09-20 17:50:55 -07:00
commit 34212c73b7
27 changed files with 216 additions and 163 deletions

View File

@ -6,10 +6,9 @@
#define MDB_RTR_RTA(r) \
((struct rtattr *)(((char *)(r)) + RTA_ALIGN(sizeof(__u32))))
void print_vlan_info(FILE *fp, struct rtattr *tb);
void print_vlan_info(struct rtattr *tb, int ifindex);
int print_linkinfo(const struct sockaddr_nl *who,
struct nlmsghdr *n,
void *arg);
struct nlmsghdr *n, void *arg);
int print_fdb(const struct sockaddr_nl *who,
struct nlmsghdr *n, void *arg);
int print_mdb(const struct sockaddr_nl *who,

View File

@ -30,7 +30,6 @@ int json;
int timestamp;
char *batch_file;
int force;
const char *_SL_;
static void usage(void) __attribute__((noreturn));

View File

@ -164,7 +164,7 @@ static void print_protinfo(FILE *fp, struct rtattr *attr)
* This is reported by HW devices that have some bridging
* capabilities.
*/
static void print_af_spec(FILE *fp, struct rtattr *attr)
static void print_af_spec(struct rtattr *attr, int ifindex)
{
struct rtattr *aftb[IFLA_BRIDGE_MAX+1];
@ -177,7 +177,7 @@ static void print_af_spec(FILE *fp, struct rtattr *attr)
return;
if (aftb[IFLA_BRIDGE_VLAN_INFO])
print_vlan_info(fp, aftb[IFLA_BRIDGE_VLAN_INFO]);
print_vlan_info(aftb[IFLA_BRIDGE_VLAN_INFO], ifindex);
}
int print_linkinfo(const struct sockaddr_nl *who,
@ -232,7 +232,7 @@ int print_linkinfo(const struct sockaddr_nl *who,
print_protinfo(fp, tb[IFLA_PROTINFO]);
if (tb[IFLA_AF_SPEC])
print_af_spec(fp, tb[IFLA_AF_SPEC]);
print_af_spec(tb[IFLA_AF_SPEC], ifi->ifi_index);
print_string(PRINT_FP, NULL, "%s", "\n");
close_json_object();

View File

@ -107,6 +107,10 @@ static void br_print_router_ports(FILE *f, struct rtattr *attr,
fprintf(f, "%s ", port_ifname);
}
}
if (!show_stats)
print_nl();
close_json_array(PRINT_JSON, NULL);
}
@ -131,15 +135,8 @@ static void print_mdb_entry(FILE *f, int ifindex, const struct br_mdb_entry *e,
if (n->nlmsg_type == RTM_DELMDB)
print_bool(PRINT_ANY, "deleted", "Deleted ", true);
if (is_json_context()) {
print_int(PRINT_JSON, "index", NULL, ifindex);
print_string(PRINT_JSON, "dev", NULL, dev);
} else {
fprintf(f, "%u: ", ifindex);
color_fprintf(f, COLOR_IFNAME, "%s ", dev);
}
print_int(PRINT_ANY, "index", "%u: ", ifindex);
print_color_string(PRINT_ANY, COLOR_IFNAME, "dev", "%s ", dev);
print_string(PRINT_ANY, "port", " %s ",
ll_index_to_name(e->ifindex));
@ -164,6 +161,8 @@ static void print_mdb_entry(FILE *f, int ifindex, const struct br_mdb_entry *e,
print_string(PRINT_ANY, "timer", " %s",
format_timer(timer));
}
print_nl();
close_json_object();
}
@ -208,19 +207,19 @@ static void print_router_entries(FILE *fp, struct nlmsghdr *n,
} else {
struct rtattr *i = RTA_DATA(router);
uint32_t *port_ifindex = RTA_DATA(i);
const char *port_name = ll_index_to_name(*port_ifindex);
if (is_json_context()) {
open_json_array(PRINT_JSON, brifname);
open_json_object(NULL);
print_string(PRINT_JSON, "port", NULL,
ll_index_to_name(*port_ifindex));
port_name);
close_json_object();
close_json_array(PRINT_JSON, NULL);
} else {
fprintf(fp, "router port dev %s master %s\n",
ll_index_to_name(*port_ifindex),
brifname);
port_name, brifname);
}
}
close_json_array(PRINT_JSON, NULL);

View File

@ -252,10 +252,18 @@ static int filter_vlan_check(__u16 vid, __u16 flags)
return 1;
}
static void print_vlan_port(FILE *fp, int ifi_index)
static void open_vlan_port(int ifi_index)
{
print_string(PRINT_ANY, NULL, "%s",
open_json_object(NULL);
print_string(PRINT_ANY, "ifname", "%s",
ll_index_to_name(ifi_index));
open_json_array(PRINT_JSON, "vlans");
}
static void close_vlan_port(void)
{
close_json_array(PRINT_JSON, NULL);
close_json_object();
}
static void print_range(const char *name, __u16 start, __u16 id)
@ -278,7 +286,7 @@ static void print_vlan_tunnel_info(FILE *fp, struct rtattr *tb, int ifindex)
__u32 last_tunid_start = 0;
if (!filter_vlan)
print_vlan_port(fp, ifindex);
open_vlan_port(ifindex);
open_json_array(PRINT_JSON, "tunnel");
for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
@ -323,18 +331,20 @@ static void print_vlan_tunnel_info(FILE *fp, struct rtattr *tb, int ifindex)
continue;
if (filter_vlan)
print_vlan_port(fp, ifindex);
open_vlan_port(ifindex);
open_json_object(NULL);
print_range("vlan", last_vid_start, tunnel_vid);
print_range("tunid", last_tunid_start, tunnel_id);
close_json_object();
if (!is_json_context())
fprintf(fp, "\n");
print_string(PRINT_FP, NULL, "%s", _SL_);
if (filter_vlan)
close_vlan_port();
}
close_json_array(PRINT_JSON, NULL);
if (!filter_vlan)
close_vlan_port();
}
static int print_vlan_tunnel(const struct sockaddr_nl *who,
@ -421,8 +431,8 @@ static int print_vlan(const struct sockaddr_nl *who,
return 0;
}
print_vlan_port(fp, ifm->ifi_index);
print_vlan_info(fp, tb[IFLA_AF_SPEC]);
print_vlan_info(tb[IFLA_AF_SPEC], ifm->ifi_index);
print_string(PRINT_FP, NULL, "%s", _SL_);
fflush(fp);
return 0;
@ -430,11 +440,16 @@ static int print_vlan(const struct sockaddr_nl *who,
static void print_vlan_flags(__u16 flags)
{
if (flags == 0)
return;
open_json_array(PRINT_JSON, "flags");
if (flags & BRIDGE_VLAN_INFO_PVID)
print_null(PRINT_ANY, "pvid", " %s", "PVID");
print_string(PRINT_ANY, NULL, " %s", "PVID");
if (flags & BRIDGE_VLAN_INFO_UNTAGGED)
print_null(PRINT_ANY, "untagged", " %s", "untagged");
print_string(PRINT_ANY, NULL, " %s", "Egress Untagged");
close_json_array(PRINT_JSON, NULL);
}
static void print_one_vlan_stats(const struct bridge_vlan_xstats *vstats)
@ -461,6 +476,7 @@ static void print_vlan_stats_attr(struct rtattr *attr, int ifindex)
{
struct rtattr *brtb[LINK_XSTATS_TYPE_MAX+1];
struct rtattr *i, *list;
const char *ifname;
int rem;
parse_rtattr(brtb, LINK_XSTATS_TYPE_MAX, RTA_DATA(attr),
@ -471,13 +487,12 @@ static void print_vlan_stats_attr(struct rtattr *attr, int ifindex)
list = brtb[LINK_XSTATS_TYPE_BRIDGE];
rem = RTA_PAYLOAD(list);
open_json_object(NULL);
ifname = ll_index_to_name(ifindex);
open_json_object(ifname);
print_color_string(PRINT_ANY, COLOR_IFNAME,
"dev", "%-16s",
ll_index_to_name(ifindex));
print_color_string(PRINT_FP, COLOR_IFNAME,
NULL, "%-16s", ifname);
open_json_array(PRINT_JSON, "xstats");
for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
const struct bridge_vlan_xstats *vstats = RTA_DATA(i);
@ -494,7 +509,6 @@ static void print_vlan_stats_attr(struct rtattr *attr, int ifindex)
print_one_vlan_stats(vstats);
}
close_json_array(PRINT_ANY, "\n");
close_json_object();
}
@ -623,16 +637,13 @@ static int vlan_show(int argc, char **argv)
return 0;
}
void print_vlan_info(FILE *fp, struct rtattr *tb)
void print_vlan_info(struct rtattr *tb, int ifindex)
{
struct rtattr *i, *list = tb;
int rem = RTA_PAYLOAD(list);
__u16 last_vid_start = 0;
if (!is_json_context())
fprintf(fp, "%s", _SL_);
open_json_array(PRINT_JSON, "vlan");
open_vlan_port(ifindex);
for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
struct bridge_vlan_info *vinfo;
@ -656,9 +667,9 @@ void print_vlan_info(FILE *fp, struct rtattr *tb)
print_vlan_flags(vinfo->flags);
close_json_object();
print_string(PRINT_FP, NULL, "%s", _SL_);
}
close_json_array(PRINT_ANY, "\n");
close_vlan_port();
}
int do_vlan(int argc, char **argv)

View File

@ -41,6 +41,8 @@ void close_json_object(void);
void open_json_array(enum output_type type, const char *delim);
void close_json_array(enum output_type type, const char *delim);
void print_nl(void);
#define _PRINT_FUNC(type_name, type) \
void print_color_##type_name(enum output_type t, \
enum color_attr color, \

View File

@ -21,8 +21,8 @@ struct { \
}, \
}
extern int genl_resolve_family(struct rtnl_handle *grth, const char *family);
extern int genl_init_handle(struct rtnl_handle *grth, const char *family,
int *genl_family);
int genl_resolve_family(struct rtnl_handle *grth, const char *family);
int genl_init_handle(struct rtnl_handle *grth, const char *family,
int *genl_family);
#endif /* __LIBGENL_H__ */

View File

@ -33,7 +33,6 @@ int oneline;
int brief;
int json;
int timestamp;
const char *_SL_;
int force;
int max_flush_loops = 10;
int batch_mode;

View File

@ -240,7 +240,7 @@ static void print_linktype(FILE *fp, struct rtattr *tb)
const char *kind
= rta_getattr_str(linkinfo[IFLA_INFO_KIND]);
print_string(PRINT_FP, NULL, "%s", _SL_);
print_nl();
print_string(PRINT_ANY, "info_kind", " %s ", kind);
lu = get_link_kind(kind);
@ -269,7 +269,7 @@ static void print_linktype(FILE *fp, struct rtattr *tb)
const char *slave_kind
= rta_getattr_str(linkinfo[IFLA_INFO_SLAVE_KIND]);
print_string(PRINT_FP, NULL, "%s", _SL_);
print_nl();
print_string(PRINT_ANY,
"info_slave_kind",
" %s_slave ",
@ -765,7 +765,7 @@ static void print_link_stats(FILE *fp, struct nlmsghdr *n)
parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi),
n->nlmsg_len - NLMSG_LENGTH(sizeof(*ifi)));
__print_link_stats(fp, tb);
fprintf(fp, "%s", _SL_);
print_nl();
}
static int print_linkinfo_brief(FILE *fp, const char *name,
@ -929,7 +929,7 @@ int print_linkinfo(const struct sockaddr_nl *who,
print_link_event(fp, rta_getattr_u32(tb[IFLA_EVENT]));
if (!filter.family || filter.family == AF_PACKET || show_details) {
print_string(PRINT_FP, NULL, "%s", _SL_);
print_nl();
print_string(PRINT_ANY,
"link_type",
" link/%s ",
@ -1090,7 +1090,7 @@ int print_linkinfo(const struct sockaddr_nl *who,
xdp_dump(fp, tb[IFLA_XDP], true, true);
if (do_link && show_stats) {
print_string(PRINT_FP, NULL, "%s", _SL_);
print_nl();
__print_link_stats(fp, tb);
}
@ -1418,7 +1418,7 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
if (rta_tb[IFA_CACHEINFO]) {
struct ifa_cacheinfo *ci = RTA_DATA(rta_tb[IFA_CACHEINFO]);
print_string(PRINT_FP, NULL, "%s", _SL_);
print_nl();
print_string(PRINT_FP, NULL, " valid_lft ", NULL);
if (ci->ifa_valid == INFINITY_LIFE_TIME) {

View File

@ -128,7 +128,7 @@ static int print_ila_mapping(const struct sockaddr_nl *who,
else
print_string(PRINT_FP, NULL, "%s", "-");
print_string(PRINT_FP, NULL, "%s", _SL_);
print_nl();
close_json_object();
return 0;

View File

@ -219,7 +219,7 @@ static void print_tunnel(const struct l2tp_data *data)
print_string(PRINT_ANY, "encap", " encap %s",
p->encap == L2TP_ENCAPTYPE_UDP ? "UDP" :
p->encap == L2TP_ENCAPTYPE_IP ? "IP" : "??");
print_string(PRINT_FP, NULL, "%s", _SL_);
print_nl();
print_string(PRINT_ANY, "local", " From %s ",
inet_ntop(p->local_ip.family, p->local_ip.data,
@ -227,11 +227,11 @@ static void print_tunnel(const struct l2tp_data *data)
print_string(PRINT_ANY, "peer", "to %s",
inet_ntop(p->peer_ip.family, p->peer_ip.data,
buf, sizeof(buf)));
print_string(PRINT_FP, NULL, "%s", _SL_);
print_nl();
print_uint(PRINT_ANY, "peer_tunnel", " Peer tunnel %u",
p->peer_tunnel_id);
print_string(PRINT_FP, NULL, "%s", _SL_);
print_nl();
if (p->encap == L2TP_ENCAPTYPE_UDP) {
print_string(PRINT_FP, NULL,
@ -241,7 +241,7 @@ static void print_tunnel(const struct l2tp_data *data)
p->local_udp_port);
print_uint(PRINT_ANY, "peer_port", "/%hu",
p->peer_udp_port);
print_string(PRINT_FP, NULL, "%s", _SL_);
print_nl();
switch (p->local_ip.family) {
case AF_INET:
@ -283,18 +283,18 @@ static void print_session(struct l2tp_data *data)
print_uint(PRINT_ANY, "session_id", "Session %u", p->session_id);
print_uint(PRINT_ANY, "tunnel_id", " in tunnel %u", p->tunnel_id);
print_string(PRINT_FP, NULL, "%s", _SL_);
print_nl();
print_uint(PRINT_ANY, "peer_session_id",
" Peer session %u,", p->peer_session_id);
print_uint(PRINT_ANY, "peer_tunnel_id",
" tunnel %u", p->peer_tunnel_id);
print_string(PRINT_FP, NULL, "%s", _SL_);
print_nl();
if (p->ifname != NULL) {
print_color_string(PRINT_ANY, COLOR_IFNAME,
"interface", " interface name: %s" , p->ifname);
print_string(PRINT_FP, NULL, "%s", _SL_);
print_nl();
}
/* Show offsets only for plain console output (for legacy scripts) */

View File

@ -627,7 +627,7 @@ static void print_attrs(struct rtattr *attrs[])
if (attrs[MACSEC_SECY_ATTR_CIPHER_SUITE]) {
__u64 cid = rta_getattr_u64(attrs[MACSEC_SECY_ATTR_CIPHER_SUITE]);
print_string(PRINT_FP, NULL, "%s", _SL_);
print_nl();
print_string(PRINT_ANY, "cipher_suite",
" cipher suite: %s,", cs_id_to_name(cid));
}

View File

@ -240,7 +240,7 @@ static void print_mlist(FILE *fp, struct ma_info *list)
print_uint(PRINT_ANY, "ifindex", "%d:", list->index);
print_color_string(PRINT_ANY, COLOR_IFNAME,
"ifname", "\t%s", list->name);
print_string(PRINT_FP, NULL, "%s", _SL_);
print_nl();
cur_index = list->index;
open_json_array(PRINT_JSON, "maddr");

View File

@ -181,7 +181,7 @@ int print_mroute(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (show_stats && tb[RTA_MFC_STATS]) {
struct rta_mfc_stats *mfcs = RTA_DATA(tb[RTA_MFC_STATS]);
print_string(PRINT_FP, NULL, "%s", _SL_);
print_nl();
print_u64(PRINT_ANY, "packets", " %"PRIu64" packets,",
mfcs->mfcs_packets);
print_u64(PRINT_ANY, "bytes", " %"PRIu64" bytes", mfcs->mfcs_bytes);

View File

@ -346,7 +346,7 @@ static void print_ndtconfig(const struct ndt_config *ndtc)
"entry_size %u ", ndtc->ndtc_entry_size);
print_uint(PRINT_ANY, "entries", "entries %u ", ndtc->ndtc_entries);
print_string(PRINT_FP, NULL, "%s", _SL_);
print_nl();
print_string(PRINT_ANY, "last_flush",
" last_flush %s ",
@ -355,7 +355,7 @@ static void print_ndtconfig(const struct ndt_config *ndtc)
"last_rand %s ",
ntable_strtime_delta(ndtc->ndtc_last_rand));
print_string(PRINT_FP, NULL, "%s", _SL_);
print_nl();
print_uint(PRINT_ANY, "hash_rnd",
" hash_rnd %u ", ndtc->ndtc_hash_rnd);
@ -367,7 +367,7 @@ static void print_ndtconfig(const struct ndt_config *ndtc)
print_uint(PRINT_ANY, "proxy_qlen",
"proxy_qlen %u ", ndtc->ndtc_proxy_qlen);
print_string(PRINT_FP, NULL, "%s", _SL_);
print_nl();
}
static void print_ndtparams(struct rtattr *tpb[])
@ -379,7 +379,7 @@ static void print_ndtparams(struct rtattr *tpb[])
print_string(PRINT_FP, NULL, " dev ", NULL);
print_color_string(PRINT_ANY, COLOR_IFNAME,
"dev", "%s ", ll_index_to_name(ifindex));
print_string(PRINT_FP, NULL, "%s", _SL_);
print_nl();
}
print_string(PRINT_FP, NULL, " ", NULL);
@ -482,7 +482,7 @@ static void print_ndtparams(struct rtattr *tpb[])
print_u64(PRINT_ANY, "locktime", "locktime %llu ", locktime);
}
print_string(PRINT_FP, NULL, "%s", _SL_);
print_nl();
}
static void print_ndtstats(const struct ndt_stats *ndts)
@ -517,7 +517,7 @@ static void print_ndtstats(const struct ndt_stats *ndts)
print_u64(PRINT_ANY, "forced_gc_runs", "forced_gc_runs %llu ",
ndts->ndts_forced_gc_runs);
print_string(PRINT_FP, NULL, "%s", _SL_);
print_nl();
}
static int print_ntable(const struct sockaddr_nl *who,
@ -579,7 +579,7 @@ static int print_ntable(const struct sockaddr_nl *who,
print_string(PRINT_ANY, "name", "%s ", name);
}
print_string(PRINT_FP, NULL, "%s", _SL_);
print_nl();
ret = (tb[NDTA_THRESH1] || tb[NDTA_THRESH2] || tb[NDTA_THRESH3] ||
tb[NDTA_GC_INTERVAL]);
@ -611,7 +611,7 @@ static int print_ntable(const struct sockaddr_nl *who,
}
if (ret)
print_string(PRINT_FP, NULL, "%s", _SL_);
print_nl();
if (tb[NDTA_CONFIG] && show_stats)
print_ndtconfig(RTA_DATA(tb[NDTA_CONFIG]));

View File

@ -941,7 +941,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
}
static int parse_one_nh(struct nlmsghdr *n, struct rtmsg *r,
struct rtattr *rta, struct rtnexthop *rtnh,
struct rtattr *rta, size_t len, struct rtnexthop *rtnh,
int *argcp, char ***argvp)
{
int argc = *argcp;
@ -962,11 +962,16 @@ static int parse_one_nh(struct nlmsghdr *n, struct rtmsg *r,
if (r->rtm_family == AF_UNSPEC)
r->rtm_family = addr.family;
if (addr.family == r->rtm_family) {
rta_addattr_l(rta, 4096, RTA_GATEWAY, &addr.data, addr.bytelen);
rtnh->rtnh_len += sizeof(struct rtattr) + addr.bytelen;
if (rta_addattr_l(rta, len, RTA_GATEWAY,
&addr.data, addr.bytelen))
return -1;
rtnh->rtnh_len += sizeof(struct rtattr)
+ addr.bytelen;
} else {
rta_addattr_l(rta, 4096, RTA_VIA, &addr.family, addr.bytelen+2);
rtnh->rtnh_len += RTA_SPACE(addr.bytelen+2);
if (rta_addattr_l(rta, len, RTA_VIA,
&addr.family, addr.bytelen + 2))
return -1;
rtnh->rtnh_len += RTA_SPACE(addr.bytelen + 2);
}
} else if (strcmp(*argv, "dev") == 0) {
NEXT_ARG();
@ -988,13 +993,15 @@ static int parse_one_nh(struct nlmsghdr *n, struct rtmsg *r,
NEXT_ARG();
if (get_rt_realms_or_raw(&realm, *argv))
invarg("\"realm\" value is invalid\n", *argv);
rta_addattr32(rta, 4096, RTA_FLOW, realm);
if (rta_addattr32(rta, len, RTA_FLOW, realm))
return -1;
rtnh->rtnh_len += sizeof(struct rtattr) + 4;
} else if (strcmp(*argv, "encap") == 0) {
int len = rta->rta_len;
int old_len = rta->rta_len;
lwt_parse_encap(rta, 4096, &argc, &argv);
rtnh->rtnh_len += rta->rta_len - len;
if (lwt_parse_encap(rta, len, &argc, &argv))
return -1;
rtnh->rtnh_len += rta->rta_len - old_len;
} else if (strcmp(*argv, "as") == 0) {
inet_prefix addr;
@ -1002,8 +1009,9 @@ static int parse_one_nh(struct nlmsghdr *n, struct rtmsg *r,
if (strcmp(*argv, "to") == 0)
NEXT_ARG();
get_addr(&addr, *argv, r->rtm_family);
rta_addattr_l(rta, 4096, RTA_NEWDST, &addr.data,
addr.bytelen);
if (rta_addattr_l(rta, len, RTA_NEWDST,
&addr.data, addr.bytelen))
return -1;
rtnh->rtnh_len += sizeof(struct rtattr) + addr.bytelen;
} else
break;
@ -1016,7 +1024,7 @@ static int parse_one_nh(struct nlmsghdr *n, struct rtmsg *r,
static int parse_nexthops(struct nlmsghdr *n, struct rtmsg *r,
int argc, char **argv)
{
char buf[1024];
char buf[4096];
struct rtattr *rta = (void *)buf;
struct rtnexthop *rtnh;
@ -1036,7 +1044,7 @@ static int parse_nexthops(struct nlmsghdr *n, struct rtmsg *r,
memset(rtnh, 0, sizeof(*rtnh));
rtnh->rtnh_len = sizeof(*rtnh);
rta->rta_len += rtnh->rtnh_len;
if (parse_one_nh(n, r, rta, rtnh, &argc, &argv)) {
if (parse_one_nh(n, r, rta, 4096, rtnh, &argc, &argv)) {
fprintf(stderr, "Error: cannot parse nexthop\n");
exit(-1);
}
@ -1044,7 +1052,8 @@ static int parse_nexthops(struct nlmsghdr *n, struct rtmsg *r,
}
if (rta->rta_len > RTA_LENGTH(0))
addattr_l(n, 1024, RTA_MULTIPATH, RTA_DATA(rta), RTA_PAYLOAD(rta));
return addattr_l(n, 4096, RTA_MULTIPATH,
RTA_DATA(rta), RTA_PAYLOAD(rta));
return 0;
}
@ -1053,7 +1062,7 @@ static int iproute_modify(int cmd, unsigned int flags, int argc, char **argv)
struct {
struct nlmsghdr n;
struct rtmsg r;
char buf[1024];
char buf[4096];
} req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)),
.n.nlmsg_flags = NLM_F_REQUEST | flags,
@ -1484,8 +1493,8 @@ static int iproute_modify(int cmd, unsigned int flags, int argc, char **argv)
addattr_l(&req.n, sizeof(req), RTA_METRICS, RTA_DATA(mxrta), RTA_PAYLOAD(mxrta));
}
if (nhs_ok)
parse_nexthops(&req.n, &req.r, argc, argv);
if (nhs_ok && parse_nexthops(&req.n, &req.r, argc, argv))
return -1;
if (req.r.rtm_family == AF_UNSPEC)
req.r.rtm_family = AF_INET;

View File

@ -538,8 +538,9 @@ static int parse_encap_seg6(struct rtattr *rta, size_t len, int *argcp,
memcpy(tuninfo->srh, srh, srhlen);
rta_addattr_l(rta, len, SEG6_IPTUNNEL_SRH, tuninfo,
sizeof(*tuninfo) + srhlen);
if (rta_addattr_l(rta, len, SEG6_IPTUNNEL_SRH, tuninfo,
sizeof(*tuninfo) + srhlen))
return -1;
free(tuninfo);
free(srh);
@ -611,6 +612,7 @@ static int parse_encap_seg6local(struct rtattr *rta, size_t len, int *argcp,
char segbuf[1024];
inet_prefix addr;
__u32 hmac = 0;
int ret = 0;
while (argc > 0) {
if (strcmp(*argv, "action") == 0) {
@ -620,27 +622,28 @@ static int parse_encap_seg6local(struct rtattr *rta, size_t len, int *argcp,
action = read_action_type(*argv);
if (!action)
invarg("\"action\" value is invalid\n", *argv);
rta_addattr32(rta, len, SEG6_LOCAL_ACTION, action);
ret = rta_addattr32(rta, len, SEG6_LOCAL_ACTION,
action);
} else if (strcmp(*argv, "table") == 0) {
NEXT_ARG();
if (table_ok++)
duparg2("table", *argv);
get_u32(&table, *argv, 0);
rta_addattr32(rta, len, SEG6_LOCAL_TABLE, table);
ret = rta_addattr32(rta, len, SEG6_LOCAL_TABLE, table);
} else if (strcmp(*argv, "nh4") == 0) {
NEXT_ARG();
if (nh4_ok++)
duparg2("nh4", *argv);
get_addr(&addr, *argv, AF_INET);
rta_addattr_l(rta, len, SEG6_LOCAL_NH4, &addr.data,
addr.bytelen);
ret = rta_addattr_l(rta, len, SEG6_LOCAL_NH4,
&addr.data, addr.bytelen);
} else if (strcmp(*argv, "nh6") == 0) {
NEXT_ARG();
if (nh6_ok++)
duparg2("nh6", *argv);
get_addr(&addr, *argv, AF_INET6);
rta_addattr_l(rta, len, SEG6_LOCAL_NH6, &addr.data,
addr.bytelen);
ret = rta_addattr_l(rta, len, SEG6_LOCAL_NH6,
&addr.data, addr.bytelen);
} else if (strcmp(*argv, "iif") == 0) {
NEXT_ARG();
if (iif_ok++)
@ -648,7 +651,7 @@ static int parse_encap_seg6local(struct rtattr *rta, size_t len, int *argcp,
iif = ll_name_to_index(*argv);
if (!iif)
exit(nodev(*argv));
rta_addattr32(rta, len, SEG6_LOCAL_IIF, iif);
ret = rta_addattr32(rta, len, SEG6_LOCAL_IIF, iif);
} else if (strcmp(*argv, "oif") == 0) {
NEXT_ARG();
if (oif_ok++)
@ -656,7 +659,7 @@ static int parse_encap_seg6local(struct rtattr *rta, size_t len, int *argcp,
oif = ll_name_to_index(*argv);
if (!oif)
exit(nodev(*argv));
rta_addattr32(rta, len, SEG6_LOCAL_OIF, oif);
ret = rta_addattr32(rta, len, SEG6_LOCAL_OIF, oif);
} else if (strcmp(*argv, "srh") == 0) {
NEXT_ARG();
if (srh_ok++)
@ -691,6 +694,8 @@ static int parse_encap_seg6local(struct rtattr *rta, size_t len, int *argcp,
} else {
break;
}
if (ret)
return ret;
argc--; argv++;
}
@ -705,14 +710,14 @@ static int parse_encap_seg6local(struct rtattr *rta, size_t len, int *argcp,
srh = parse_srh(segbuf, hmac,
action == SEG6_LOCAL_ACTION_END_B6_ENCAP);
srhlen = (srh->hdrlen + 1) << 3;
rta_addattr_l(rta, len, SEG6_LOCAL_SRH, srh, srhlen);
ret = rta_addattr_l(rta, len, SEG6_LOCAL_SRH, srh, srhlen);
free(srh);
}
*argcp = argc + 1;
*argvp = argv - 1;
return 0;
return ret;
}
static int parse_encap_mpls(struct rtattr *rta, size_t len,
@ -730,8 +735,9 @@ static int parse_encap_mpls(struct rtattr *rta, size_t len,
exit(1);
}
rta_addattr_l(rta, len, MPLS_IPTUNNEL_DST, &addr.data,
addr.bytelen);
if (rta_addattr_l(rta, len, MPLS_IPTUNNEL_DST,
&addr.data, addr.bytelen))
return -1;
argc--;
argv++;
@ -745,7 +751,8 @@ static int parse_encap_mpls(struct rtattr *rta, size_t len,
duparg2("ttl", *argv);
if (get_u8(&ttl, *argv, 0))
invarg("\"ttl\" value is invalid\n", *argv);
rta_addattr8(rta, len, MPLS_IPTUNNEL_TTL, ttl);
if (rta_addattr8(rta, len, MPLS_IPTUNNEL_TTL, ttl))
return -1;
} else {
break;
}
@ -768,6 +775,7 @@ static int parse_encap_ip(struct rtattr *rta, size_t len,
int id_ok = 0, dst_ok = 0, src_ok = 0, tos_ok = 0, ttl_ok = 0;
char **argv = *argvp;
int argc = *argcp;
int ret = 0;
while (argc > 0) {
if (strcmp(*argv, "id") == 0) {
@ -778,7 +786,7 @@ static int parse_encap_ip(struct rtattr *rta, size_t len,
duparg2("id", *argv);
if (get_be64(&id, *argv, 0))
invarg("\"id\" value is invalid\n", *argv);
rta_addattr64(rta, len, LWTUNNEL_IP_ID, id);
ret = rta_addattr64(rta, len, LWTUNNEL_IP_ID, id);
} else if (strcmp(*argv, "dst") == 0) {
inet_prefix addr;
@ -786,8 +794,8 @@ static int parse_encap_ip(struct rtattr *rta, size_t len,
if (dst_ok++)
duparg2("dst", *argv);
get_addr(&addr, *argv, AF_INET);
rta_addattr_l(rta, len, LWTUNNEL_IP_DST,
&addr.data, addr.bytelen);
ret = rta_addattr_l(rta, len, LWTUNNEL_IP_DST,
&addr.data, addr.bytelen);
} else if (strcmp(*argv, "src") == 0) {
inet_prefix addr;
@ -795,8 +803,8 @@ static int parse_encap_ip(struct rtattr *rta, size_t len,
if (src_ok++)
duparg2("src", *argv);
get_addr(&addr, *argv, AF_INET);
rta_addattr_l(rta, len, LWTUNNEL_IP_SRC,
&addr.data, addr.bytelen);
ret = rta_addattr_l(rta, len, LWTUNNEL_IP_SRC,
&addr.data, addr.bytelen);
} else if (strcmp(*argv, "tos") == 0) {
__u32 tos;
@ -805,7 +813,7 @@ static int parse_encap_ip(struct rtattr *rta, size_t len,
duparg2("tos", *argv);
if (rtnl_dsfield_a2n(&tos, *argv))
invarg("\"tos\" value is invalid\n", *argv);
rta_addattr8(rta, len, LWTUNNEL_IP_TOS, tos);
ret = rta_addattr8(rta, len, LWTUNNEL_IP_TOS, tos);
} else if (strcmp(*argv, "ttl") == 0) {
__u8 ttl;
@ -814,10 +822,12 @@ static int parse_encap_ip(struct rtattr *rta, size_t len,
duparg2("ttl", *argv);
if (get_u8(&ttl, *argv, 0))
invarg("\"ttl\" value is invalid\n", *argv);
rta_addattr8(rta, len, LWTUNNEL_IP_TTL, ttl);
ret = rta_addattr8(rta, len, LWTUNNEL_IP_TTL, ttl);
} else {
break;
}
if (ret)
break;
argc--; argv++;
}
@ -828,7 +838,7 @@ static int parse_encap_ip(struct rtattr *rta, size_t len,
*argcp = argc + 1;
*argvp = argv - 1;
return 0;
return ret;
}
static int parse_encap_ila(struct rtattr *rta, size_t len,
@ -837,6 +847,7 @@ static int parse_encap_ila(struct rtattr *rta, size_t len,
__u64 locator;
int argc = *argcp;
char **argv = *argvp;
int ret = 0;
if (get_addr64(&locator, *argv) < 0) {
fprintf(stderr, "Bad locator: %s\n", *argv);
@ -845,7 +856,8 @@ static int parse_encap_ila(struct rtattr *rta, size_t len,
argc--; argv++;
rta_addattr64(rta, 1024, ILA_ATTR_LOCATOR, locator);
if (rta_addattr64(rta, 1024, ILA_ATTR_LOCATOR, locator))
return -1;
while (argc > 0) {
if (strcmp(*argv, "csum-mode") == 0) {
@ -858,8 +870,8 @@ static int parse_encap_ila(struct rtattr *rta, size_t len,
invarg("\"csum-mode\" value is invalid\n",
*argv);
rta_addattr8(rta, 1024, ILA_ATTR_CSUM_MODE,
(__u8)csum_mode);
ret = rta_addattr8(rta, 1024, ILA_ATTR_CSUM_MODE,
(__u8)csum_mode);
argc--; argv++;
} else if (strcmp(*argv, "ident-type") == 0) {
@ -872,8 +884,8 @@ static int parse_encap_ila(struct rtattr *rta, size_t len,
invarg("\"ident-type\" value is invalid\n",
*argv);
rta_addattr8(rta, 1024, ILA_ATTR_IDENT_TYPE,
(__u8)ident_type);
ret = rta_addattr8(rta, 1024, ILA_ATTR_IDENT_TYPE,
(__u8)ident_type);
argc--; argv++;
} else if (strcmp(*argv, "hook-type") == 0) {
@ -886,13 +898,15 @@ static int parse_encap_ila(struct rtattr *rta, size_t len,
invarg("\"hook-type\" value is invalid\n",
*argv);
rta_addattr8(rta, 1024, ILA_ATTR_HOOK_TYPE,
(__u8)hook_type);
ret = rta_addattr8(rta, 1024, ILA_ATTR_HOOK_TYPE,
(__u8)hook_type);
argc--; argv++;
} else {
break;
}
if (ret)
break;
}
/* argv is currently the first unparsed argument,
@ -902,7 +916,7 @@ static int parse_encap_ila(struct rtattr *rta, size_t len,
*argcp = argc + 1;
*argvp = argv - 1;
return 0;
return ret;
}
static int parse_encap_ip6(struct rtattr *rta, size_t len,
@ -911,6 +925,7 @@ static int parse_encap_ip6(struct rtattr *rta, size_t len,
int id_ok = 0, dst_ok = 0, src_ok = 0, tos_ok = 0, ttl_ok = 0;
char **argv = *argvp;
int argc = *argcp;
int ret = 0;
while (argc > 0) {
if (strcmp(*argv, "id") == 0) {
@ -921,7 +936,7 @@ static int parse_encap_ip6(struct rtattr *rta, size_t len,
duparg2("id", *argv);
if (get_be64(&id, *argv, 0))
invarg("\"id\" value is invalid\n", *argv);
rta_addattr64(rta, len, LWTUNNEL_IP6_ID, id);
ret = rta_addattr64(rta, len, LWTUNNEL_IP6_ID, id);
} else if (strcmp(*argv, "dst") == 0) {
inet_prefix addr;
@ -929,8 +944,8 @@ static int parse_encap_ip6(struct rtattr *rta, size_t len,
if (dst_ok++)
duparg2("dst", *argv);
get_addr(&addr, *argv, AF_INET6);
rta_addattr_l(rta, len, LWTUNNEL_IP6_DST,
&addr.data, addr.bytelen);
ret = rta_addattr_l(rta, len, LWTUNNEL_IP6_DST,
&addr.data, addr.bytelen);
} else if (strcmp(*argv, "src") == 0) {
inet_prefix addr;
@ -938,8 +953,8 @@ static int parse_encap_ip6(struct rtattr *rta, size_t len,
if (src_ok++)
duparg2("src", *argv);
get_addr(&addr, *argv, AF_INET6);
rta_addattr_l(rta, len, LWTUNNEL_IP6_SRC,
&addr.data, addr.bytelen);
ret = rta_addattr_l(rta, len, LWTUNNEL_IP6_SRC,
&addr.data, addr.bytelen);
} else if (strcmp(*argv, "tc") == 0) {
__u32 tc;
@ -948,7 +963,7 @@ static int parse_encap_ip6(struct rtattr *rta, size_t len,
duparg2("tc", *argv);
if (rtnl_dsfield_a2n(&tc, *argv))
invarg("\"tc\" value is invalid\n", *argv);
rta_addattr8(rta, len, LWTUNNEL_IP6_TC, tc);
ret = rta_addattr8(rta, len, LWTUNNEL_IP6_TC, tc);
} else if (strcmp(*argv, "hoplimit") == 0) {
__u8 hoplimit;
@ -958,10 +973,13 @@ static int parse_encap_ip6(struct rtattr *rta, size_t len,
if (get_u8(&hoplimit, *argv, 0))
invarg("\"hoplimit\" value is invalid\n",
*argv);
rta_addattr8(rta, len, LWTUNNEL_IP6_HOPLIMIT, hoplimit);
ret = rta_addattr8(rta, len, LWTUNNEL_IP6_HOPLIMIT,
hoplimit);
} else {
break;
}
if (ret)
break;
argc--; argv++;
}
@ -972,7 +990,7 @@ static int parse_encap_ip6(struct rtattr *rta, size_t len,
*argcp = argc + 1;
*argvp = argv - 1;
return 0;
return ret;
}
static void lwt_bpf_usage(void)
@ -1039,6 +1057,7 @@ int lwt_parse_encap(struct rtattr *rta, size_t len, int *argcp, char ***argvp)
int argc = *argcp;
char **argv = *argvp;
__u16 type;
int ret = 0;
NEXT_ARG();
type = read_encap_type(*argv);
@ -1055,37 +1074,40 @@ int lwt_parse_encap(struct rtattr *rta, size_t len, int *argcp, char ***argvp)
nest = rta_nest(rta, 1024, RTA_ENCAP);
switch (type) {
case LWTUNNEL_ENCAP_MPLS:
parse_encap_mpls(rta, len, &argc, &argv);
ret = parse_encap_mpls(rta, len, &argc, &argv);
break;
case LWTUNNEL_ENCAP_IP:
parse_encap_ip(rta, len, &argc, &argv);
ret = parse_encap_ip(rta, len, &argc, &argv);
break;
case LWTUNNEL_ENCAP_ILA:
parse_encap_ila(rta, len, &argc, &argv);
ret = parse_encap_ila(rta, len, &argc, &argv);
break;
case LWTUNNEL_ENCAP_IP6:
parse_encap_ip6(rta, len, &argc, &argv);
ret = parse_encap_ip6(rta, len, &argc, &argv);
break;
case LWTUNNEL_ENCAP_BPF:
if (parse_encap_bpf(rta, len, &argc, &argv) < 0)
exit(-1);
break;
case LWTUNNEL_ENCAP_SEG6:
parse_encap_seg6(rta, len, &argc, &argv);
ret = parse_encap_seg6(rta, len, &argc, &argv);
break;
case LWTUNNEL_ENCAP_SEG6_LOCAL:
parse_encap_seg6local(rta, len, &argc, &argv);
ret = parse_encap_seg6local(rta, len, &argc, &argv);
break;
default:
fprintf(stderr, "Error: unsupported encap type\n");
break;
}
if (ret)
return ret;
rta_nest_end(rta, nest);
rta_addattr16(rta, 1024, RTA_ENCAP_TYPE, type);
ret = rta_addattr16(rta, 1024, RTA_ENCAP_TYPE, type);
*argcp = argc;
*argvp = argv;
return 0;
return ret;
}

View File

@ -222,3 +222,10 @@ void print_color_null(enum output_type type,
color_fprintf(stdout, color, fmt, value);
}
}
/* Print line seperator (if not in JSON mode) */
void print_nl(void)
{
if (!_jw)
printf("%s", _SL_);
}

View File

@ -617,7 +617,6 @@ static int __rtnl_talk_iov(struct rtnl_handle *rtnl, struct iovec *iov,
msg.msg_iovlen = 1;
i = 0;
while (1) {
next:
status = rtnl_recvmsg(rtnl->fd, &msg, &buf);
++i;
@ -660,27 +659,23 @@ next:
if (l < sizeof(struct nlmsgerr)) {
fprintf(stderr, "ERROR truncated\n");
} else if (!err->error) {
free(buf);
return -1;
}
if (!err->error)
/* check messages from kernel */
nl_dump_ext_ack(h, errfn);
if (answer)
*answer = (struct nlmsghdr *)buf;
else
free(buf);
if (h->nlmsg_seq == seq)
return 0;
else if (i < iovlen)
goto next;
return 0;
}
if (rtnl->proto != NETLINK_SOCK_DIAG &&
show_rtnl_err)
rtnl_talk_error(h, err, errfn);
errno = -err->error;
free(buf);
if (answer)
*answer = (struct nlmsghdr *)buf;
else
free(buf);
return -i;
}

View File

@ -42,6 +42,7 @@
int resolve_hosts;
int timestamp_short;
int pretty;
const char *_SL_ = "\n";
int read_prop(const char *dev, char *prop, long *value)
{

View File

@ -8,7 +8,7 @@ dev
classid
.B | root) [ handle
major:
.B ] mqprio [ numtc
.B ] mqprio [ num_tc
tcs
.B ] [ map
P0 P1 P2...

View File

@ -279,7 +279,7 @@ struct ib_uverbs_query_port {
};
struct ib_uverbs_query_port_resp {
__u32 port_cap_flags;
__u32 port_cap_flags; /* see ib_uverbs_query_port_cap_flags */
__u32 max_msg_sz;
__u32 bad_pkey_cntr;
__u32 qkey_viol_cntr;
@ -299,7 +299,8 @@ struct ib_uverbs_query_port_resp {
__u8 active_speed;
__u8 phys_state;
__u8 link_layer;
__u8 reserved[2];
__u8 flags; /* see ib_uverbs_query_port_flags */
__u8 reserved;
};
struct ib_uverbs_alloc_pd {

View File

@ -20,6 +20,7 @@ static int link_help(struct rd *rd)
static const char *caps_to_str(uint32_t idx)
{
#define RDMA_PORT_FLAGS(x) \
x(RESERVED, 0) \
x(SM, 1) \
x(NOTICE, 2) \
x(TRAP, 3) \
@ -32,7 +33,9 @@ static const char *caps_to_str(uint32_t idx)
x(SM_DISABLED, 10) \
x(SYS_IMAGE_GUID, 11) \
x(PKEY_SW_EXT_PORT_TRAP, 12) \
x(CABLE_INFO, 13) \
x(EXTENDED_SPEEDS, 14) \
x(CAP_MASK2, 15) \
x(CM, 16) \
x(SNMP_TUNNEL, 17) \
x(REINIT, 18) \
@ -43,7 +46,12 @@ static const char *caps_to_str(uint32_t idx)
x(BOOT_MGMT, 23) \
x(LINK_LATENCY, 24) \
x(CLIENT_REG, 25) \
x(IP_BASED_GIDS, 26)
x(OTHER_LOCAL_CHANGES, 26) \
x(LINK_SPPED_WIDTH, 27) \
x(VENDOR_SPECIFIC_MADS, 28) \
x(MULT_PKER_TRAP, 29) \
x(MULT_FDB, 30) \
x(HIERARCHY_INFO, 31)
enum { RDMA_PORT_FLAGS(RDMA_BITMAP_ENUM) };
@ -51,9 +59,7 @@ static const char *caps_to_str(uint32_t idx)
rdma_port_names[] = { RDMA_PORT_FLAGS(RDMA_BITMAP_NAMES) };
#undef RDMA_PORT_FLAGS
if (idx < ARRAY_SIZE(rdma_port_names) && rdma_port_names[idx])
return rdma_port_names[idx];
return "UNKNOWN";
return rdma_port_names[idx];
}
static void link_print_caps(struct rd *rd, struct nlattr **tb)

View File

@ -468,6 +468,8 @@ static int cake_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
if (nat)
print_string(PRINT_FP, NULL, "nat ", NULL);
else
print_string(PRINT_FP, NULL, "nonat ", NULL);
print_bool(PRINT_JSON, "nat", NULL, nat);
if (tb[TCA_CAKE_WASH] &&
@ -508,6 +510,8 @@ static int cake_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
if (wash)
print_string(PRINT_FP, NULL, "wash ", NULL);
else
print_string(PRINT_FP, NULL, "nowash ", NULL);
print_bool(PRINT_JSON, "wash", NULL, wash);
if (ingress)
@ -520,10 +524,12 @@ static int cake_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
else if (ack_filter == CAKE_ACK_FILTER)
print_string(PRINT_ANY, "ack-filter", "ack-filter ", "enabled");
else
print_string(PRINT_JSON, "ack-filter", NULL, "disabled");
print_string(PRINT_ANY, "ack-filter", "no-ack-filter ", "disabled");
if (split_gso)
print_string(PRINT_FP, NULL, "split-gso ", NULL);
else
print_string(PRINT_FP, NULL, "no-split-gso ", NULL);
print_bool(PRINT_JSON, "split_gso", NULL, split_gso);
if (interval)

View File

@ -94,7 +94,6 @@ struct qdisc_util pfifo_head_drop_qdisc_util = {
.print_qopt = fifo_print_opt,
};
extern int prio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt);
struct qdisc_util pfifo_fast_qdisc_util = {
.id = "pfifo_fast",
.print_qopt = prio_print_opt,

View File

@ -167,8 +167,7 @@ static int mqprio_parse_opt(struct qdisc_util *qu, int argc,
explain();
return -1;
} else {
fprintf(stderr, "Unknown argument\n");
return -1;
invarg("unknown argument", *argv);
}
argc--; argv++;
}

View File

@ -43,7 +43,6 @@ bool use_names;
int json;
int color;
int oneline;
const char *_SL_;
static char *conf_file;