]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
bridge: refactor bridge mcast querier function
authorFabian Pfitzner <f.pfitzner@pengutronix.de>
Wed, 25 Jun 2025 08:39:15 +0000 (10:39 +0200)
committerDavid Ahern <dsahern@kernel.org>
Wed, 2 Jul 2025 14:36:01 +0000 (14:36 +0000)
Make code more readable and consistent with other functions.

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

index 480693c91ec07dbbd6ae25b107b68c30f9937cf4..5386aa0178d65f047dfe065623d1ec40fbc798a8 100644 (file)
@@ -49,60 +49,55 @@ void bridge_print_vlan_stats(const struct bridge_vlan_xstats *vstats)
 void bridge_print_mcast_querier_state(const struct rtattr *vtb)
 {
        struct rtattr *bqtb[BRIDGE_QUERIER_MAX + 1];
-
+       const char *querier_ip;
        SPRINT_BUF(other_time);
+       __u64 tval;
 
        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]));
+               querier_ip = format_host_rta(AF_INET,
+                                            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 ",
+                                  querier_ip);
        }
        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_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]) {
+               tval = rta_getattr_u64(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));
+                            "mcast_querier_ipv4_other_timer",
+                            "mcast_querier_ipv4_other_timer %s ",
+                            sprint_time64(tval, 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]));
+               querier_ip = format_host_rta(AF_INET6,
+                                            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 ",
+                                  querier_ip);
        }
        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_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]) {
+               tval = rta_getattr_u64(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));
+                            "mcast_querier_ipv6_other_timer",
+                            "mcast_querier_ipv6_other_timer %s ",
+                            sprint_time64(tval, other_time));
+       }
        close_json_object();
 }