]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
bridge: move mcast querier dumping code into a shared function
authorFabian Pfitzner <f.pfitzner@pengutronix.de>
Wed, 25 Jun 2025 08:39:13 +0000 (10:39 +0200)
committerDavid Ahern <dsahern@kernel.org>
Wed, 2 Jul 2025 14:35:30 +0000 (14:35 +0000)
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].

Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Acked-by: Nikolay Aleksandrov <razor@blackwall.org>
Signed-off-by: Fabian Pfitzner <f.pfitzner@pengutronix.de>
Signed-off-by: David Ahern <dsahern@kernel.org>
include/bridge.h
ip/iplink_bridge.c
lib/bridge.c

index 8bcd1e386103bb7ba133fa2cf5da43db49819a04..8b0942b5ba9c5aa6a7e0e9124f06e6c99eb4944b 100644 (file)
@@ -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__ */
index 31e7cb5e4922b5f106f39a695ad48942d06ed98a..76e6908675b7b84f3e1e3c4cd39a1d4b80c673ae 100644 (file)
@@ -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])
index a888a20e20c314414862b8c7d3ecd5158134dfc0..480693c91ec07dbbd6ae25b107b68c30f9937cf4 100644 (file)
@@ -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();
+}