From: Stephen Hemminger Date: Sat, 16 Mar 2013 17:18:50 +0000 (-0700) Subject: bridge: add oneline option X-Git-Tag: v3.9.0~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4cd20da16ffa96f3c67ef7b064ad87f6c8547824;p=thirdparty%2Fiproute2.git bridge: add oneline option Split output of 'bridge link' across multiple lines, only show the flags if -d is set, and add --oneline option like ip command. --- diff --git a/bridge/bridge.c b/bridge/bridge.c index 77e260f79..ee08f90af 100644 --- a/bridge/bridge.c +++ b/bridge/bridge.c @@ -17,9 +17,11 @@ struct rtnl_handle rth = { .fd = -1 }; int preferred_family = AF_UNSPEC; int resolve_hosts; +int oneline = 0; int show_stats; int show_details; int timestamp; +char * _SL_ = NULL; static void usage(void) __attribute__((noreturn)); @@ -28,7 +30,8 @@ static void usage(void) fprintf(stderr, "Usage: bridge [ OPTIONS ] OBJECT { COMMAND | help }\n" "where OBJECT := { link | fdb | mdb | vlan | monitor }\n" -" OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails]\n" ); +" OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] |\n" +" -o[neline] | -t[imestamp] \n"); exit(-1); } @@ -88,6 +91,8 @@ main(int argc, char **argv) ++show_stats; } else if (matches(opt, "-details") == 0) { ++show_details; + } else if (matches(opt, "-oneline") == 0) { + ++oneline; } else if (matches(opt, "-timestamp") == 0) { ++timestamp; } else if (matches(opt, "-family") == 0) { @@ -114,6 +119,8 @@ main(int argc, char **argv) argc--; argv++; } + _SL_ = oneline ? "\\" : "\n" ; + if (rtnl_open(&rth, 0) < 0) exit(1); diff --git a/bridge/link.c b/bridge/link.c index 6b5383362..3188b854f 100644 --- a/bridge/link.c +++ b/bridge/link.c @@ -169,18 +169,23 @@ int print_linkinfo(const struct sockaddr_nl *who, if (prtb[IFLA_BRPORT_COST]) fprintf(fp, "cost %u ", rta_getattr_u32(prtb[IFLA_BRPORT_COST])); - if (prtb[IFLA_BRPORT_MODE]) - print_onoff(fp, "hairpin", - rta_getattr_u8(prtb[IFLA_BRPORT_MODE])); - if (prtb[IFLA_BRPORT_GUARD]) - print_onoff(fp, "guard", - rta_getattr_u8(prtb[IFLA_BRPORT_GUARD])); - if (prtb[IFLA_BRPORT_PROTECT]) - print_onoff(fp, "root_block", - rta_getattr_u8(prtb[IFLA_BRPORT_PROTECT])); - if (prtb[IFLA_BRPORT_FAST_LEAVE]) - print_onoff(fp, "fastleave", - rta_getattr_u8(prtb[IFLA_BRPORT_FAST_LEAVE])); + + if (show_details) { + fprintf(fp, "%s ", _SL_); + + if (prtb[IFLA_BRPORT_MODE]) + print_onoff(fp, "hairpin", + rta_getattr_u8(prtb[IFLA_BRPORT_MODE])); + if (prtb[IFLA_BRPORT_GUARD]) + print_onoff(fp, "guard", + rta_getattr_u8(prtb[IFLA_BRPORT_GUARD])); + if (prtb[IFLA_BRPORT_PROTECT]) + print_onoff(fp, "root_block", + rta_getattr_u8(prtb[IFLA_BRPORT_PROTECT])); + if (prtb[IFLA_BRPORT_FAST_LEAVE]) + print_onoff(fp, "fastleave", + rta_getattr_u8(prtb[IFLA_BRPORT_FAST_LEAVE])); + } } else print_portstate(fp, rta_getattr_u8(tb[IFLA_PROTINFO])); }