Merge branch 'iproute2-master' into next

Signed-off-by: David Ahern <dsahern@gmail.com>
This commit is contained in:
David Ahern 2019-04-26 11:13:54 -07:00
commit 10fb5faec1
12 changed files with 139 additions and 81 deletions

View File

@ -8,8 +8,8 @@
void print_vlan_info(struct rtattr *tb, int ifindex);
int print_linkinfo(struct nlmsghdr *n, void *arg);
int print_mdb_mon(struct nlmsghdr *n, void *arg);
int print_fdb(struct nlmsghdr *n, void *arg);
int print_mdb(struct nlmsghdr *n, void *arg);
int do_fdb(int argc, char **argv);
int do_mdb(int argc, char **argv);

View File

@ -132,9 +132,6 @@ static void print_mdb_entry(FILE *f, int ifindex, const struct br_mdb_entry *e,
open_json_object(NULL);
if (n->nlmsg_type == RTM_DELMDB)
print_bool(PRINT_ANY, "deleted", "Deleted ", true);
print_int(PRINT_ANY, "index", "%u: ", ifindex);
print_color_string(PRINT_ANY, COLOR_IFNAME, "dev", "%s ", dev);
print_string(PRINT_ANY, "port", " %s ",
@ -189,10 +186,8 @@ static void print_mdb_entries(FILE *fp, struct nlmsghdr *n,
int rem = RTA_PAYLOAD(mdb);
struct rtattr *i;
open_json_array(PRINT_JSON, "mdb");
for (i = RTA_DATA(mdb); RTA_OK(i, rem); i = RTA_NEXT(i, rem))
br_print_mdb_entry(fp, ifindex, i, n);
close_json_array(PRINT_JSON, NULL);
}
static void print_router_entries(FILE *fp, struct nlmsghdr *n,
@ -200,7 +195,6 @@ static void print_router_entries(FILE *fp, struct nlmsghdr *n,
{
const char *brifname = ll_index_to_name(ifindex);
open_json_array(PRINT_JSON, "router");
if (n->nlmsg_type == RTM_GETMDB) {
if (show_details)
br_print_router_ports(fp, router, brifname);
@ -222,15 +216,12 @@ static void print_router_entries(FILE *fp, struct nlmsghdr *n,
port_name, brifname);
}
}
close_json_array(PRINT_JSON, NULL);
}
int print_mdb(struct nlmsghdr *n, void *arg)
static int __parse_mdb_nlmsg(struct nlmsghdr *n, struct rtattr **tb)
{
FILE *fp = arg;
struct br_port_msg *r = NLMSG_DATA(n);
int len = n->nlmsg_len;
struct rtattr *tb[MDBA_MAX+1];
if (n->nlmsg_type != RTM_GETMDB &&
n->nlmsg_type != RTM_NEWMDB &&
@ -253,6 +244,54 @@ int print_mdb(struct nlmsghdr *n, void *arg)
parse_rtattr(tb, MDBA_MAX, MDBA_RTA(r), n->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));
return 1;
}
static int print_mdbs(struct nlmsghdr *n, void *arg)
{
struct br_port_msg *r = NLMSG_DATA(n);
struct rtattr *tb[MDBA_MAX+1];
FILE *fp = arg;
int ret;
ret = __parse_mdb_nlmsg(n, tb);
if (ret != 1)
return ret;
if (tb[MDBA_MDB])
print_mdb_entries(fp, n, r->ifindex, tb[MDBA_MDB]);
return 0;
}
static int print_rtrs(struct nlmsghdr *n, void *arg)
{
struct br_port_msg *r = NLMSG_DATA(n);
struct rtattr *tb[MDBA_MAX+1];
FILE *fp = arg;
int ret;
ret = __parse_mdb_nlmsg(n, tb);
if (ret != 1)
return ret;
if (tb[MDBA_ROUTER])
print_router_entries(fp, n, r->ifindex, tb[MDBA_ROUTER]);
return 0;
}
int print_mdb_mon(struct nlmsghdr *n, void *arg)
{
struct br_port_msg *r = NLMSG_DATA(n);
struct rtattr *tb[MDBA_MAX+1];
FILE *fp = arg;
int ret;
ret = __parse_mdb_nlmsg(n, tb);
if (ret != 1)
return ret;
if (n->nlmsg_type == RTM_DELMDB)
print_bool(PRINT_ANY, "deleted", "Deleted ", true);
@ -291,18 +330,35 @@ static int mdb_show(int argc, char **argv)
}
new_json_obj(json);
open_json_object(NULL);
/* get mdb entries*/
/* get mdb entries */
if (rtnl_mdbdump_req(&rth, PF_BRIDGE) < 0) {
perror("Cannot send dump request");
return -1;
}
if (rtnl_dump_filter(&rth, print_mdb, stdout) < 0) {
open_json_array(PRINT_JSON, "mdb");
if (rtnl_dump_filter(&rth, print_mdbs, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
return -1;
}
close_json_array(PRINT_JSON, NULL);
/* get router ports */
if (rtnl_mdbdump_req(&rth, PF_BRIDGE) < 0) {
perror("Cannot send dump request");
return -1;
}
open_json_object("router");
if (rtnl_dump_filter(&rth, print_rtrs, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
return -1;
}
close_json_object();
close_json_object();
delete_json_obj();
fflush(stdout);

View File

@ -61,7 +61,7 @@ static int accept_msg(struct rtnl_ctrl_data *ctrl,
case RTM_DELMDB:
if (prefix_banner)
fprintf(fp, "[MDB]");
return print_mdb(n, arg);
return print_mdb_mon(n, arg);
case NLMSG_TSTAMP:
print_nlmsg_timestamp(fp, n);

View File

@ -252,11 +252,11 @@ static int filter_vlan_check(__u16 vid, __u16 flags)
return 1;
}
static void open_vlan_port(int ifi_index)
static void open_vlan_port(int ifi_index, const char *fmt)
{
open_json_object(NULL);
print_string(PRINT_ANY, "ifname", "%s",
ll_index_to_name(ifi_index));
print_color_string(PRINT_ANY, COLOR_IFNAME, "ifname", fmt,
ll_index_to_name(ifi_index));
open_json_array(PRINT_JSON, "vlans");
}
@ -286,7 +286,7 @@ static void print_vlan_tunnel_info(FILE *fp, struct rtattr *tb, int ifindex)
__u32 last_tunid_start = 0;
if (!filter_vlan)
open_vlan_port(ifindex);
open_vlan_port(ifindex, "%s");
open_json_array(PRINT_JSON, "tunnel");
for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
@ -331,7 +331,7 @@ static void print_vlan_tunnel_info(FILE *fp, struct rtattr *tb, int ifindex)
continue;
if (filter_vlan)
open_vlan_port(ifindex);
open_vlan_port(ifindex, "%s");
open_json_object(NULL);
print_range("vlan", last_vid_start, tunnel_vid);
@ -463,7 +463,7 @@ static void print_one_vlan_stats(const struct bridge_vlan_xstats *vstats)
print_lluint(PRINT_ANY, "tx_bytes",
" TX: %llu bytes",
vstats->tx_bytes);
print_lluint(PRINT_ANY, "tx_packets", " %llu packets",
print_lluint(PRINT_ANY, "tx_packets", " %llu packets\n",
vstats->tx_packets);
close_json_object();
}
@ -472,7 +472,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;
bool found_vlan = false;
int rem;
parse_rtattr(brtb, LINK_XSTATS_TYPE_MAX, RTA_DATA(attr),
@ -483,12 +483,6 @@ static void print_vlan_stats_attr(struct rtattr *attr, int ifindex)
list = brtb[LINK_XSTATS_TYPE_BRIDGE];
rem = RTA_PAYLOAD(list);
ifname = ll_index_to_name(ifindex);
open_vlan_port(ifindex);
print_color_string(PRINT_FP, COLOR_IFNAME,
NULL, "%-16s", ifname);
for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
const struct bridge_vlan_xstats *vstats = RTA_DATA(i);
@ -503,9 +497,19 @@ static void print_vlan_stats_attr(struct rtattr *attr, int ifindex)
!(vstats->flags & BRIDGE_VLAN_INFO_BRENTRY))
continue;
/* found vlan stats, first time print the interface name */
if (!found_vlan) {
open_vlan_port(ifindex, "%-16s");
found_vlan = true;
} else {
print_string(PRINT_FP, NULL, "%-16s", "");
}
print_one_vlan_stats(vstats);
}
close_vlan_port();
/* vlan_port is opened only if there are any vlan stats */
if (found_vlan)
close_vlan_port();
}
static int print_vlan_stats(struct nlmsghdr *n, void *arg)
@ -632,7 +636,7 @@ void print_vlan_info(struct rtattr *tb, int ifindex)
int rem = RTA_PAYLOAD(list);
__u16 last_vid_start = 0;
open_vlan_port(ifindex);
open_vlan_port(ifindex, "%s");
for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
struct bridge_vlan_info *vinfo;

View File

@ -251,7 +251,7 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
return;
if (tb[IFLA_GENEVE_COLLECT_METADATA]) {
print_bool(PRINT_ANY, "external", "external", true);
print_bool(PRINT_ANY, "external", "external ", true);
return;
}

View File

@ -418,7 +418,7 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (tb[IFLA_VXLAN_COLLECT_METADATA] &&
rta_getattr_u8(tb[IFLA_VXLAN_COLLECT_METADATA])) {
print_bool(PRINT_ANY, "external", "external", true);
print_bool(PRINT_ANY, "external", "external ", true);
return;
}

View File

@ -273,34 +273,30 @@ int print_rule(struct nlmsghdr *n, void *arg)
print_color_string(PRINT_ANY, ifa_family_color(frh->family),
"src", "%s", src);
if (frh->src_len != host_len)
print_uint(PRINT_ANY, "srclen", "/%u ", frh->src_len);
else
print_string(PRINT_FP, NULL, " ", NULL);
print_uint(PRINT_ANY, "srclen", "/%u", frh->src_len);
} else if (frh->src_len) {
print_string(PRINT_ANY, "src", "from %s", "0");
print_uint(PRINT_ANY, "srclen", "/%u ", frh->src_len);
print_uint(PRINT_ANY, "srclen", "/%u", frh->src_len);
} else {
print_string(PRINT_ANY, "src", "from %s ", "all");
print_string(PRINT_ANY, "src", "from %s", "all");
}
if (tb[FRA_DST]) {
const char *dst = rt_addr_n2a_rta(frh->family, tb[FRA_DST]);
print_string(PRINT_FP, NULL, "to ", NULL);
print_string(PRINT_FP, NULL, " to ", NULL);
print_color_string(PRINT_ANY, ifa_family_color(frh->family),
"dst", "%s", dst);
if (frh->dst_len != host_len)
print_uint(PRINT_ANY, "dstlen", "/%u ", frh->dst_len);
else
print_string(PRINT_FP, NULL, " ", NULL);
print_uint(PRINT_ANY, "dstlen", "/%u", frh->dst_len);
} else if (frh->dst_len) {
print_string(PRINT_ANY, "dst", "to %s", "0");
print_uint(PRINT_ANY, "dstlen", "/%u ", frh->dst_len);
print_string(PRINT_ANY, "dst", " to %s", "0");
print_uint(PRINT_ANY, "dstlen", "/%u", frh->dst_len);
}
if (frh->tos) {
print_string(PRINT_ANY, "tos",
"tos %s ",
" tos %s",
rtnl_dsfield_n2a(frh->tos, b1, sizeof(b1)));
}
@ -312,34 +308,34 @@ int print_rule(struct nlmsghdr *n, void *arg)
if (tb[FRA_FWMASK] &&
(mask = rta_getattr_u32(tb[FRA_FWMASK])) != 0xFFFFFFFF) {
print_0xhex(PRINT_ANY, "fwmark", "fwmark %#llx", mark);
print_0xhex(PRINT_ANY, "fwmask", "/%#llx ", mask);
print_0xhex(PRINT_ANY, "fwmark", " fwmark %#llx", mark);
print_0xhex(PRINT_ANY, "fwmask", "/%#llx", mask);
} else {
print_0xhex(PRINT_ANY, "fwmark", "fwmark %#llx ", mark);
print_0xhex(PRINT_ANY, "fwmark", " fwmark %#llx", mark);
}
}
if (tb[FRA_IFNAME]) {
if (!is_json_context())
fprintf(fp, "iif ");
fprintf(fp, " iif ");
print_color_string(PRINT_ANY, COLOR_IFNAME,
"iif", "%s ",
"iif", "%s",
rta_getattr_str(tb[FRA_IFNAME]));
if (frh->flags & FIB_RULE_IIF_DETACHED)
print_null(PRINT_ANY, "iif_detached", "[detached] ",
print_null(PRINT_ANY, "iif_detached", " [detached]",
NULL);
}
if (tb[FRA_OIFNAME]) {
if (!is_json_context())
fprintf(fp, "oif ");
fprintf(fp, " oif ");
print_color_string(PRINT_ANY, COLOR_IFNAME, "oif", "%s ",
print_color_string(PRINT_ANY, COLOR_IFNAME, "oif", "%s",
rta_getattr_str(tb[FRA_OIFNAME]));
if (frh->flags & FIB_RULE_OIF_DETACHED)
print_null(PRINT_ANY, "oif_detached", "[detached] ",
print_null(PRINT_ANY, "oif_detached", " [detached]",
NULL);
}
@ -348,19 +344,19 @@ int print_rule(struct nlmsghdr *n, void *arg)
if (mdev)
print_null(PRINT_ANY, "l3mdev",
"lookup [l3mdev-table] ", NULL);
" lookup [l3mdev-table]", NULL);
}
if (tb[FRA_UID_RANGE]) {
struct fib_rule_uid_range *r = RTA_DATA(tb[FRA_UID_RANGE]);
print_uint(PRINT_ANY, "uid_start", "uidrange %u", r->start);
print_uint(PRINT_ANY, "uid_end", "-%u ", r->end);
print_uint(PRINT_ANY, "uid_start", " uidrange %u", r->start);
print_uint(PRINT_ANY, "uid_end", "-%u", r->end);
}
if (tb[FRA_IP_PROTO]) {
SPRINT_BUF(pbuf);
print_string(PRINT_ANY, "ipproto", "ipproto %s ",
print_string(PRINT_ANY, "ipproto", " ipproto %s",
inet_proto_n2a(rta_getattr_u8(tb[FRA_IP_PROTO]),
pbuf, sizeof(pbuf)));
}
@ -369,11 +365,11 @@ int print_rule(struct nlmsghdr *n, void *arg)
struct fib_rule_port_range *r = RTA_DATA(tb[FRA_SPORT_RANGE]);
if (r->start == r->end) {
print_uint(PRINT_ANY, "sport", "sport %u ", r->start);
print_uint(PRINT_ANY, "sport", " sport %u", r->start);
} else {
print_uint(PRINT_ANY, "sport_start", "sport %u",
print_uint(PRINT_ANY, "sport_start", " sport %u",
r->start);
print_uint(PRINT_ANY, "sport_end", "-%u ", r->end);
print_uint(PRINT_ANY, "sport_end", "-%u", r->end);
}
}
@ -381,24 +377,24 @@ int print_rule(struct nlmsghdr *n, void *arg)
struct fib_rule_port_range *r = RTA_DATA(tb[FRA_DPORT_RANGE]);
if (r->start == r->end) {
print_uint(PRINT_ANY, "dport", "dport %u ", r->start);
print_uint(PRINT_ANY, "dport", " dport %u", r->start);
} else {
print_uint(PRINT_ANY, "dport_start", "dport %u",
print_uint(PRINT_ANY, "dport_start", " dport %u",
r->start);
print_uint(PRINT_ANY, "dport_end", "-%u ", r->end);
print_uint(PRINT_ANY, "dport_end", "-%u", r->end);
}
}
if (tb[FRA_TUN_ID]) {
__u64 tun_id = ntohll(rta_getattr_u64(tb[FRA_TUN_ID]));
print_u64(PRINT_ANY, "tun_id", "tun_id %llu ", tun_id);
print_u64(PRINT_ANY, "tun_id", " tun_id %llu", tun_id);
}
table = frh_get_table(frh, tb);
if (table) {
print_string(PRINT_ANY, "table",
"lookup %s ",
" lookup %s",
rtnl_rttable_n2a(table, b1, sizeof(b1)));
if (tb[FRA_SUPPRESS_PREFIXLEN]) {
@ -406,7 +402,7 @@ int print_rule(struct nlmsghdr *n, void *arg)
if (pl != -1)
print_int(PRINT_ANY, "suppress_prefixlen",
"suppress_prefixlength %d ", pl);
" suppress_prefixlength %d", pl);
}
if (tb[FRA_SUPPRESS_IFGROUP]) {
@ -417,7 +413,7 @@ int print_rule(struct nlmsghdr *n, void *arg)
= rtnl_group_n2a(group, b1, sizeof(b1));
print_string(PRINT_ANY, "suppress_ifgroup",
"suppress_ifgroup %s ", grname);
" suppress_ifgroup %s", grname);
}
}
}
@ -429,10 +425,12 @@ int print_rule(struct nlmsghdr *n, void *arg)
to &= 0xFFFF;
if (from)
print_string(PRINT_ANY,
"flow_from", "realms %s/",
"flow_from", " realms %s/",
rtnl_rtrealm_n2a(from, b1, sizeof(b1)));
else
print_string(PRINT_FP, NULL, " realms ", NULL);
print_string(PRINT_ANY, "flow_to", "%s ",
print_string(PRINT_ANY, "flow_to", "%s",
rtnl_rtrealm_n2a(to, b1, sizeof(b1)));
}
@ -443,24 +441,24 @@ int print_rule(struct nlmsghdr *n, void *arg)
gateway = format_host_rta(frh->family, tb[RTA_GATEWAY]);
print_string(PRINT_ANY, "nat_gateway",
"map-to %s ", gateway);
" map-to %s", gateway);
} else {
print_null(PRINT_ANY, "masquerade", "masquerade", NULL);
print_null(PRINT_ANY, "masquerade", " masquerade", NULL);
}
} else if (frh->action == FR_ACT_GOTO) {
if (tb[FRA_GOTO])
print_uint(PRINT_ANY, "goto", "goto %u",
print_uint(PRINT_ANY, "goto", " goto %u",
rta_getattr_u32(tb[FRA_GOTO]));
else
print_string(PRINT_ANY, "goto", "goto %s", "none");
print_string(PRINT_ANY, "goto", " goto %s", "none");
if (frh->flags & FIB_RULE_UNRESOLVED)
print_null(PRINT_ANY, "unresolved",
" [unresolved]", NULL);
} else if (frh->action == FR_ACT_NOP) {
print_null(PRINT_ANY, "nop", "nop", NULL);
print_null(PRINT_ANY, "nop", " nop", NULL);
} else if (frh->action != FR_ACT_TO_TBL) {
print_string(PRINT_ANY, "action", "%s",
print_string(PRINT_ANY, "action", " %s",
rtnl_rtntype_n2a(frh->action, b1, sizeof(b1)));
}
@ -468,7 +466,7 @@ int print_rule(struct nlmsghdr *n, void *arg)
__u8 protocol = rta_getattr_u8(tb[FRA_PROTOCOL]);
if ((protocol && protocol != RTPROT_KERNEL) || show_details > 0) {
print_string(PRINT_ANY, "protocol", " proto %s ",
print_string(PRINT_ANY, "protocol", " proto %s",
rtnl_rtprot_n2a(protocol, b1, sizeof(b1)));
}
}

View File

@ -436,7 +436,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
return;
if (tb[IFLA_GRE_COLLECT_METADATA]) {
print_bool(PRINT_ANY, "external", "external", true);
print_bool(PRINT_ANY, "external", "external ", true);
return;
}

View File

@ -465,7 +465,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
return;
if (tb[IFLA_GRE_COLLECT_METADATA]) {
print_bool(PRINT_ANY, "external", "external", true);
print_bool(PRINT_ANY, "external", "external ", true);
return;
}

View File

@ -354,7 +354,7 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb
return;
if (tb[IFLA_IPTUN_COLLECT_METADATA]) {
print_bool(PRINT_ANY, "external", "external", true);
print_bool(PRINT_ANY, "external", "external ", true);
return;
}

View File

@ -374,7 +374,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
return;
if (tb[IFLA_IPTUN_COLLECT_METADATA]) {
print_bool(PRINT_ANY, "external", "external", true);
print_bool(PRINT_ANY, "external", "external ", true);
return;
}

View File

@ -8,8 +8,8 @@
%locations
%token-table
%error-verbose
%name-prefix "ematch_"
%define parse.error verbose
%define api.prefix {ematch_}
%union {
unsigned int i;