From: Fabian Pfitzner <f.pfitzner@pengutronix.de>
To: netdev@vger.kernel.org
Cc: dsahern@gmail.com, idosch@nvidia.com,
bridge@lists.linux-foundation.org, entwicklung@pengutronix.de,
razor@blackwall.org, Fabian Pfitzner <f.pfitzner@pengutronix.de>
Subject: [PATCH iproute2-next v5 1/3] bridge: move mcast querier dumping code into a shared function
Date: Mon, 23 Jun 2025 11:33:16 +0200 [thread overview]
Message-ID: <20250623093316.1215970-2-f.pfitzner@pengutronix.de> (raw)
In-Reply-To: <20250623093316.1215970-1-f.pfitzner@pengutronix.de>
Put mcast querier dumping code into a shared function. This function
will be called from the bridge utility in a later patch.
Adapt the code such that the vtb parameter is used
instead of tb[IFLA_BR_MCAST_QUERIER_STATE].
Signed-off-by: Fabian Pfitzner <f.pfitzner@pengutronix.de>
---
I decided to not only move the code into a separate function, but also
to adapt it to fit into the function. If I split it into a pure refactoring
and an adapting commit, the former will not compile preventing git bisects.
---
include/bridge.h | 3 +++
ip/iplink_bridge.c | 59 +++-----------------------------------------
lib/bridge.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 67 insertions(+), 56 deletions(-)
diff --git a/include/bridge.h b/include/bridge.h
index 8bcd1e38..8b0942b5 100644
--- a/include/bridge.h
+++ b/include/bridge.h
@@ -3,9 +3,12 @@
#define __BRIDGE_H__ 1
#include <linux/if_bridge.h>
+#include <linux/rtnetlink.h>
void bridge_print_vlan_flags(__u16 flags);
void bridge_print_vlan_stats_only(const struct bridge_vlan_xstats *vstats);
void bridge_print_vlan_stats(const struct bridge_vlan_xstats *vstats);
+void bridge_print_mcast_querier_state(const struct rtattr *vtb);
+
#endif /* __BRIDGE_H__ */
diff --git a/ip/iplink_bridge.c b/ip/iplink_bridge.c
index 31e7cb5e..76e69086 100644
--- a/ip/iplink_bridge.c
+++ b/ip/iplink_bridge.c
@@ -682,62 +682,9 @@ static void bridge_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
rta_getattr_u8(tb[IFLA_BR_MCAST_QUERIER]));
if (tb[IFLA_BR_MCAST_QUERIER_STATE]) {
- struct rtattr *bqtb[BRIDGE_QUERIER_MAX + 1];
- SPRINT_BUF(other_time);
-
- parse_rtattr_nested(bqtb, BRIDGE_QUERIER_MAX, tb[IFLA_BR_MCAST_QUERIER_STATE]);
- memset(other_time, 0, sizeof(other_time));
-
- open_json_object("mcast_querier_state_ipv4");
- if (bqtb[BRIDGE_QUERIER_IP_ADDRESS]) {
- print_string(PRINT_FP,
- NULL,
- "%s ",
- "mcast_querier_ipv4_addr");
- print_color_string(PRINT_ANY,
- COLOR_INET,
- "mcast_querier_ipv4_addr",
- "%s ",
- format_host_rta(AF_INET, bqtb[BRIDGE_QUERIER_IP_ADDRESS]));
- }
- if (bqtb[BRIDGE_QUERIER_IP_PORT])
- print_uint(PRINT_ANY,
- "mcast_querier_ipv4_port",
- "mcast_querier_ipv4_port %u ",
- rta_getattr_u32(bqtb[BRIDGE_QUERIER_IP_PORT]));
- if (bqtb[BRIDGE_QUERIER_IP_OTHER_TIMER])
- print_string(PRINT_ANY,
- "mcast_querier_ipv4_other_timer",
- "mcast_querier_ipv4_other_timer %s ",
- sprint_time64(
- rta_getattr_u64(bqtb[BRIDGE_QUERIER_IP_OTHER_TIMER]),
- other_time));
- close_json_object();
- open_json_object("mcast_querier_state_ipv6");
- if (bqtb[BRIDGE_QUERIER_IPV6_ADDRESS]) {
- print_string(PRINT_FP,
- NULL,
- "%s ",
- "mcast_querier_ipv6_addr");
- print_color_string(PRINT_ANY,
- COLOR_INET6,
- "mcast_querier_ipv6_addr",
- "%s ",
- format_host_rta(AF_INET6, bqtb[BRIDGE_QUERIER_IPV6_ADDRESS]));
- }
- if (bqtb[BRIDGE_QUERIER_IPV6_PORT])
- print_uint(PRINT_ANY,
- "mcast_querier_ipv6_port",
- "mcast_querier_ipv6_port %u ",
- rta_getattr_u32(bqtb[BRIDGE_QUERIER_IPV6_PORT]));
- if (bqtb[BRIDGE_QUERIER_IPV6_OTHER_TIMER])
- print_string(PRINT_ANY,
- "mcast_querier_ipv6_other_timer",
- "mcast_querier_ipv6_other_timer %s ",
- sprint_time64(
- rta_getattr_u64(bqtb[BRIDGE_QUERIER_IPV6_OTHER_TIMER]),
- other_time));
- close_json_object();
+ struct rtattr *vtb = tb[IFLA_BR_MCAST_QUERIER_STATE];
+
+ bridge_print_mcast_querier_state(vtb);
}
if (tb[IFLA_BR_MCAST_HASH_ELASTICITY])
diff --git a/lib/bridge.c b/lib/bridge.c
index a888a20e..480693c9 100644
--- a/lib/bridge.c
+++ b/lib/bridge.c
@@ -45,3 +45,64 @@ void bridge_print_vlan_stats(const struct bridge_vlan_xstats *vstats)
close_json_object();
}
+
+void bridge_print_mcast_querier_state(const struct rtattr *vtb)
+{
+ struct rtattr *bqtb[BRIDGE_QUERIER_MAX + 1];
+
+ SPRINT_BUF(other_time);
+
+ parse_rtattr_nested(bqtb, BRIDGE_QUERIER_MAX, vtb);
+ memset(other_time, 0, sizeof(other_time));
+
+ open_json_object("mcast_querier_state_ipv4");
+ if (bqtb[BRIDGE_QUERIER_IP_ADDRESS]) {
+ print_string(PRINT_FP,
+ NULL,
+ "%s ",
+ "mcast_querier_ipv4_addr");
+ print_color_string(PRINT_ANY,
+ COLOR_INET,
+ "mcast_querier_ipv4_addr",
+ "%s ",
+ format_host_rta(AF_INET, bqtb[BRIDGE_QUERIER_IP_ADDRESS]));
+ }
+ if (bqtb[BRIDGE_QUERIER_IP_PORT])
+ print_uint(PRINT_ANY,
+ "mcast_querier_ipv4_port",
+ "mcast_querier_ipv4_port %u ",
+ rta_getattr_u32(bqtb[BRIDGE_QUERIER_IP_PORT]));
+ if (bqtb[BRIDGE_QUERIER_IP_OTHER_TIMER])
+ print_string(PRINT_ANY,
+ "mcast_querier_ipv4_other_timer",
+ "mcast_querier_ipv4_other_timer %s ",
+ sprint_time64(
+ rta_getattr_u64(bqtb[BRIDGE_QUERIER_IP_OTHER_TIMER]),
+ other_time));
+ close_json_object();
+ open_json_object("mcast_querier_state_ipv6");
+ if (bqtb[BRIDGE_QUERIER_IPV6_ADDRESS]) {
+ print_string(PRINT_FP,
+ NULL,
+ "%s ",
+ "mcast_querier_ipv6_addr");
+ print_color_string(PRINT_ANY,
+ COLOR_INET6,
+ "mcast_querier_ipv6_addr",
+ "%s ",
+ format_host_rta(AF_INET6, bqtb[BRIDGE_QUERIER_IPV6_ADDRESS]));
+ }
+ if (bqtb[BRIDGE_QUERIER_IPV6_PORT])
+ print_uint(PRINT_ANY,
+ "mcast_querier_ipv6_port",
+ "mcast_querier_ipv6_port %u ",
+ rta_getattr_u32(bqtb[BRIDGE_QUERIER_IPV6_PORT]));
+ if (bqtb[BRIDGE_QUERIER_IPV6_OTHER_TIMER])
+ print_string(PRINT_ANY,
+ "mcast_querier_ipv6_other_timer",
+ "mcast_querier_ipv6_other_timer %s ",
+ sprint_time64(
+ rta_getattr_u64(bqtb[BRIDGE_QUERIER_IPV6_OTHER_TIMER]),
+ other_time));
+ close_json_object();
+}
--
2.39.5
next prev parent reply other threads:[~2025-06-23 9:34 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-23 9:33 [PATCH iproute2-next v5 0/3] bridge: dump mcast querier state per vlan Fabian Pfitzner
2025-06-23 9:33 ` Fabian Pfitzner [this message]
2025-06-24 11:55 ` [PATCH iproute2-next v5 1/3] bridge: move mcast querier dumping code into a shared function Ido Schimmel
2025-06-24 12:40 ` Nikolay Aleksandrov
2025-06-23 9:33 ` [PATCH iproute2-next v5 2/3] bridge: dump mcast querier per vlan Fabian Pfitzner
2025-06-24 11:57 ` Ido Schimmel
2025-06-24 12:40 ` Nikolay Aleksandrov
2025-06-23 9:33 ` [PATCH iproute2-next v5 3/3] bridge: refactor bridge mcast querier function Fabian Pfitzner
2025-06-24 12:01 ` Ido Schimmel
2025-06-24 12:41 ` Nikolay Aleksandrov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250623093316.1215970-2-f.pfitzner@pengutronix.de \
--to=f.pfitzner@pengutronix.de \
--cc=bridge@lists.linux-foundation.org \
--cc=dsahern@gmail.com \
--cc=entwicklung@pengutronix.de \
--cc=idosch@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=razor@blackwall.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).