From e356155477080e21d9c443fc963b7019bbc579ca Mon Sep 17 00:00:00 2001
From: Phil Sutter <psutter@redhat.com>
Date: Tue, 28 Feb 2017 16:12:00 +0100
Subject: [PATCH] iplink: bridge: export bridge_id and designated_root
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1417289
Upstream Status: iproute2.git commit 70dfb0b8836d8
commit 70dfb0b8836d8fb17009b5473b14f4bc470cb68d
Author: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
Date: Tue Feb 9 00:14:19 2016 +0100
iplink: bridge: export bridge_id and designated_root
Netlink returns the bridge_id and designated_root, we just need to
make them visible.
Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
---
ip/iplink_bridge.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/ip/iplink_bridge.c b/ip/iplink_bridge.c
index 1c71f2e..050afaa 100644
--- a/ip/iplink_bridge.c
+++ b/ip/iplink_bridge.c
@@ -13,6 +13,7 @@
#include <stdlib.h>
#include <string.h>
#include <linux/if_link.h>
+#include <netinet/ether.h>
#include "rt_names.h"
#include "utils.h"
@@ -39,6 +40,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)
+{
+ char eaddr[32];
+
+ ether_ntoa_r((const struct ether_addr *)id->addr, eaddr);
+ snprintf(buf, len, "%.2x%.2x.%s", id->prio[0], id->prio[1], eaddr);
+}
+
static int bridge_parse_opt(struct link_util *lu, int argc, char **argv,
struct nlmsghdr *n)
{
@@ -161,6 +171,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,
--
1.8.3.1