Message ID | 1454932527-30569-2-git-send-email-razor@blackwall.org |
---|---|
State | Superseded, archived |
Delegated to: | stephen hemminger |
Headers | show |
On Mon, 8 Feb 2016 12:55:07 +0100 Nikolay Aleksandrov <razor@blackwall.org> wrote: > > +static void br_dump_bridge_id(const struct ifla_bridge_id *id, char *buf, > + size_t len) > +{ > + const unsigned char *x = (const unsigned char *)id; > + > + snprintf(buf, len, "%.2x%.2x.%.2x%.2x%.2x%.2x%.2x%.2x", x[0], x[1], > + x[2], x[3], x[4], x[5], x[6], x[7]); > +} Please don't reinvent ether_ntoa_r
On 02/08/2016 11:21 PM, Stephen Hemminger wrote: > On Mon, 8 Feb 2016 12:55:07 +0100 > Nikolay Aleksandrov <razor@blackwall.org> wrote: > >> >> +static void br_dump_bridge_id(const struct ifla_bridge_id *id, char *buf, >> + size_t len) >> +{ >> + const unsigned char *x = (const unsigned char *)id; >> + >> + snprintf(buf, len, "%.2x%.2x.%.2x%.2x%.2x%.2x%.2x%.2x", x[0], x[1], >> + x[2], x[3], x[4], x[5], x[6], x[7]); >> +} > > Please don't reinvent ether_ntoa_r > This was taken from bridge-utils, it actually includes 2 more bytes, it's not only an ethernet address.
On 02/08/2016 11:25 PM, Nikolay Aleksandrov wrote: > On 02/08/2016 11:21 PM, Stephen Hemminger wrote: >> On Mon, 8 Feb 2016 12:55:07 +0100 >> Nikolay Aleksandrov <razor@blackwall.org> wrote: >> >>> >>> +static void br_dump_bridge_id(const struct ifla_bridge_id *id, char *buf, >>> + size_t len) >>> +{ >>> + const unsigned char *x = (const unsigned char *)id; >>> + >>> + snprintf(buf, len, "%.2x%.2x.%.2x%.2x%.2x%.2x%.2x%.2x", x[0], x[1], >>> + x[2], x[3], x[4], x[5], x[6], x[7]); >>> +} >> >> Please don't reinvent ether_ntoa_r >> > This was taken from bridge-utils, it actually includes 2 more bytes, it's > not only an ethernet address. > Also the output is very different, i.e. bridge_id 8000.000000000000 there're no colons.
diff --git a/ip/iplink_bridge.c b/ip/iplink_bridge.c index 00804093dcb5..6978e58e6b74 100644 --- a/ip/iplink_bridge.c +++ b/ip/iplink_bridge.c @@ -39,6 +39,15 @@ static void explain(void) print_explain(stderr); } +static void br_dump_bridge_id(const struct ifla_bridge_id *id, char *buf, + size_t len) +{ + const unsigned char *x = (const unsigned char *)id; + + snprintf(buf, len, "%.2x%.2x.%.2x%.2x%.2x%.2x%.2x%.2x", x[0], x[1], + x[2], x[3], x[4], x[5], x[6], x[7]); +} + static int bridge_parse_opt(struct link_util *lu, int argc, char **argv, struct nlmsghdr *n) { @@ -155,6 +164,22 @@ static void bridge_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ll_proto_n2a(rta_getattr_u16(tb[IFLA_BR_VLAN_PROTOCOL]), b1, sizeof(b1))); } + + if (tb[IFLA_BR_BRIDGE_ID]) { + char bridge_id[32]; + + br_dump_bridge_id(RTA_DATA(tb[IFLA_BR_BRIDGE_ID]), bridge_id, + sizeof(bridge_id)); + fprintf(f, "bridge_id %s ", bridge_id); + } + + if (tb[IFLA_BR_ROOT_ID]) { + char root_id[32]; + + br_dump_bridge_id(RTA_DATA(tb[IFLA_BR_BRIDGE_ID]), root_id, + sizeof(root_id)); + fprintf(f, "designated_root %s ", root_id); + } } static void bridge_print_help(struct link_util *lu, int argc, char **argv,