Commit 4cd20da1 authored by Stephen Hemminger's avatar Stephen Hemminger

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.
parent aa2f1335
...@@ -17,9 +17,11 @@ ...@@ -17,9 +17,11 @@
struct rtnl_handle rth = { .fd = -1 }; struct rtnl_handle rth = { .fd = -1 };
int preferred_family = AF_UNSPEC; int preferred_family = AF_UNSPEC;
int resolve_hosts; int resolve_hosts;
int oneline = 0;
int show_stats; int show_stats;
int show_details; int show_details;
int timestamp; int timestamp;
char * _SL_ = NULL;
static void usage(void) __attribute__((noreturn)); static void usage(void) __attribute__((noreturn));
...@@ -28,7 +30,8 @@ static void usage(void) ...@@ -28,7 +30,8 @@ static void usage(void)
fprintf(stderr, fprintf(stderr,
"Usage: bridge [ OPTIONS ] OBJECT { COMMAND | help }\n" "Usage: bridge [ OPTIONS ] OBJECT { COMMAND | help }\n"
"where OBJECT := { link | fdb | mdb | vlan | monitor }\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); exit(-1);
} }
...@@ -88,6 +91,8 @@ main(int argc, char **argv) ...@@ -88,6 +91,8 @@ main(int argc, char **argv)
++show_stats; ++show_stats;
} else if (matches(opt, "-details") == 0) { } else if (matches(opt, "-details") == 0) {
++show_details; ++show_details;
} else if (matches(opt, "-oneline") == 0) {
++oneline;
} else if (matches(opt, "-timestamp") == 0) { } else if (matches(opt, "-timestamp") == 0) {
++timestamp; ++timestamp;
} else if (matches(opt, "-family") == 0) { } else if (matches(opt, "-family") == 0) {
...@@ -114,6 +119,8 @@ main(int argc, char **argv) ...@@ -114,6 +119,8 @@ main(int argc, char **argv)
argc--; argv++; argc--; argv++;
} }
_SL_ = oneline ? "\\" : "\n" ;
if (rtnl_open(&rth, 0) < 0) if (rtnl_open(&rth, 0) < 0)
exit(1); exit(1);
......
...@@ -169,6 +169,10 @@ int print_linkinfo(const struct sockaddr_nl *who, ...@@ -169,6 +169,10 @@ int print_linkinfo(const struct sockaddr_nl *who,
if (prtb[IFLA_BRPORT_COST]) if (prtb[IFLA_BRPORT_COST])
fprintf(fp, "cost %u ", fprintf(fp, "cost %u ",
rta_getattr_u32(prtb[IFLA_BRPORT_COST])); rta_getattr_u32(prtb[IFLA_BRPORT_COST]));
if (show_details) {
fprintf(fp, "%s ", _SL_);
if (prtb[IFLA_BRPORT_MODE]) if (prtb[IFLA_BRPORT_MODE])
print_onoff(fp, "hairpin", print_onoff(fp, "hairpin",
rta_getattr_u8(prtb[IFLA_BRPORT_MODE])); rta_getattr_u8(prtb[IFLA_BRPORT_MODE]));
...@@ -181,6 +185,7 @@ int print_linkinfo(const struct sockaddr_nl *who, ...@@ -181,6 +185,7 @@ int print_linkinfo(const struct sockaddr_nl *who,
if (prtb[IFLA_BRPORT_FAST_LEAVE]) if (prtb[IFLA_BRPORT_FAST_LEAVE])
print_onoff(fp, "fastleave", print_onoff(fp, "fastleave",
rta_getattr_u8(prtb[IFLA_BRPORT_FAST_LEAVE])); rta_getattr_u8(prtb[IFLA_BRPORT_FAST_LEAVE]));
}
} else } else
print_portstate(fp, rta_getattr_u8(tb[IFLA_PROTINFO])); print_portstate(fp, rta_getattr_u8(tb[IFLA_PROTINFO]));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment