]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
bridge: Add support for mcast_n_groups, mcast_max_groups
authorPetr Machata <petrm@nvidia.com>
Tue, 7 Feb 2023 10:27:49 +0000 (11:27 +0100)
committerDavid Ahern <dsahern@kernel.org>
Tue, 7 Feb 2023 16:11:02 +0000 (09:11 -0700)
A total of four new bridge attributes are being added to the kernel:
mcast_n_groups and mcast_max_groups, as link and vlan attributes. Add
to the bridge tool the support code to enable setting and querying
these attributes. Example usage:

 # ip link add name br up type bridge vlan_filtering 1 mcast_snooping 1 \
                                      mcast_vlan_snooping 1 mcast_querier 1
 # ip link set dev v1 master br
 # bridge vlan add dev v1 vid 2

 # bridge vlan set dev v1 vid 1 mcast_max_groups 1
 # bridge mdb add dev br port v1 grp 230.1.2.3 temp vid 1
 # bridge mdb add dev br port v1 grp 230.1.2.4 temp vid 1
 Error: bridge: Port-VLAN is already in 1 groups, and mcast_max_groups=1.

 # bridge link set dev v1 mcast_max_groups 1
 # bridge mdb add dev br port v1 grp 230.1.2.3 temp vid 2
 Error: bridge: Port is already in 1 groups, and mcast_max_groups=1.

 # bridge -d link show
 5: v1@v2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master br [...]
     [...] mcast_n_groups 1 mcast_max_groups 1

 # bridge -d vlan show
 port              vlan-id
 br                1 PVID Egress Untagged
                     state forwarding mcast_router 1
 v1                1 PVID Egress Untagged
                     [...] mcast_n_groups 1 mcast_max_groups 1
                   2
                     [...] mcast_n_groups 0 mcast_max_groups 0

This is how the JSON dump looks like:

 # bridge -j -d link show dev v1 | jq
 [
   {
     "ifindex": 4,
     "link": "v2",
     "ifname": "v1",
     "flags": [
       "BROADCAST",
       "MULTICAST"
     ],
     "mtu": 1500,
     "master": "br",
     "state": "disabled",
     "priority": 32,
     "cost": 2,
     "hairpin": false,
     "guard": false,
     "root_block": false,
     "fastleave": false,
     "learning": true,
     "flood": true,
     "mcast_flood": true,
     "bcast_flood": true,
     "mcast_router": 1,
     "mcast_to_unicast": false,
     "neigh_suppress": false,
     "vlan_tunnel": false,
     "isolated": false,
     "locked": false,
     "mab": false,
     "mcast_n_groups": 0,
     "mcast_max_groups": 0
   }
 ]

 # bridge -j -d vlan show dev v1 | jq
 [
   {
     "ifname": "v1",
     "vlans": [
       {
         "vlan": 1,
         "flags": [
           "PVID",
           "Egress Untagged"
         ],
         "state": "forwarding",
         "mcast_router": 1,
         "mcast_n_groups": 0,
         "mcast_max_groups": 1
       }
     ]
   }
 ]

Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
bridge/link.c
bridge/vlan.c

index 337731dff26b42249cfb3ca9bdae8c611edc8cb2..9dd7475d6e4ac26c4d1428a5d386e41795f9594c 100644 (file)
@@ -187,6 +187,18 @@ static void print_protinfo(FILE *fp, struct rtattr *attr)
                if (prtb[IFLA_BRPORT_MAB])
                        print_on_off(PRINT_ANY, "mab", "mab %s ",
                                     rta_getattr_u8(prtb[IFLA_BRPORT_MAB]));
+               if (prtb[IFLA_BRPORT_MCAST_N_GROUPS]) {
+                       struct rtattr *at = prtb[IFLA_BRPORT_MCAST_N_GROUPS];
+
+                       print_uint(PRINT_ANY, "mcast_n_groups",
+                                  "mcast_n_groups %u ", rta_getattr_u32(at));
+               }
+               if (prtb[IFLA_BRPORT_MCAST_MAX_GROUPS]) {
+                       struct rtattr *at = prtb[IFLA_BRPORT_MCAST_MAX_GROUPS];
+
+                       print_uint(PRINT_ANY, "mcast_max_groups",
+                                  "mcast_max_groups %u ", rta_getattr_u32(at));
+               }
        } else
                print_stp_state(rta_getattr_u8(attr));
 }
@@ -282,6 +294,7 @@ static void usage(void)
                "                               [ mcast_flood {on | off} ]\n"
                "                               [ bcast_flood {on | off} ]\n"
                "                               [ mcast_to_unicast {on | off} ]\n"
+               "                               [ mcast_max_groups MAX_GROUPS ]\n"
                "                               [ neigh_suppress {on | off} ]\n"
                "                               [ vlan_tunnel {on | off} ]\n"
                "                               [ isolated {on | off} ]\n"
@@ -317,6 +330,7 @@ static int brlink_modify(int argc, char **argv)
        __s8 mcast_flood = -1;
        __s8 bcast_flood = -1;
        __s8 mcast_to_unicast = -1;
+       __s32 max_groups = -1;
        __s8 locked = -1;
        __s8 macauth = -1;
        __s8 isolated = -1;
@@ -389,6 +403,10 @@ static int brlink_modify(int argc, char **argv)
                        mcast_to_unicast = parse_on_off("mcast_to_unicast", *argv, &ret);
                        if (ret)
                                return ret;
+               } else if (strcmp(*argv, "mcast_max_groups") == 0) {
+                       NEXT_ARG();
+                       if (get_s32(&max_groups, *argv, 0))
+                               invarg("invalid mcast_max_groups", *argv);
                } else if (strcmp(*argv, "cost") == 0) {
                        NEXT_ARG();
                        cost = atoi(*argv);
@@ -505,6 +523,9 @@ static int brlink_modify(int argc, char **argv)
        if (mcast_to_unicast >= 0)
                addattr8(&req.n, sizeof(req), IFLA_BRPORT_MCAST_TO_UCAST,
                         mcast_to_unicast);
+       if (max_groups >= 0)
+               addattr32(&req.n, sizeof(req), IFLA_BRPORT_MCAST_MAX_GROUPS,
+                         max_groups);
        if (learning >= 0)
                addattr8(&req.n, sizeof(req), IFLA_BRPORT_LEARNING, learning);
        if (learning_sync >= 0)
index 13df1e845ea57ce1efb26ea14dcf837222967d7f..44e1ba39f01d9b75fb58b7c77e5ac5889995932a 100644 (file)
@@ -37,6 +37,7 @@ static void usage(void)
                "                                                     [ self ] [ master ]\n"
                "       bridge vlan { set } vid VLAN_ID dev DEV [ state STP_STATE ]\n"
                "                                               [ mcast_router MULTICAST_ROUTER ]\n"
+               "                                               [ mcast_max_groups MAX_GROUPS ]\n"
                "       bridge vlan { show } [ dev DEV ] [ vid VLAN_ID ]\n"
                "       bridge vlan { tunnelshow } [ dev DEV ] [ vid VLAN_ID ]\n"
                "       bridge vlan global { set } vid VLAN_ID dev DEV\n"
@@ -344,6 +345,15 @@ static int vlan_option_set(int argc, char **argv)
                        addattr8(&req.n, sizeof(req),
                                 BRIDGE_VLANDB_ENTRY_MCAST_ROUTER,
                                 mcast_router);
+               } else if (strcmp(*argv, "mcast_max_groups") == 0) {
+                       __u32 max_groups;
+
+                       NEXT_ARG();
+                       if (get_u32(&max_groups, *argv, 0))
+                               invarg("invalid mcast_max_groups", *argv);
+                       addattr32(&req.n, sizeof(req),
+                                 BRIDGE_VLANDB_ENTRY_MCAST_MAX_GROUPS,
+                                 max_groups);
                } else {
                        if (matches(*argv, "help") == 0)
                                NEXT_ARG();
@@ -1021,6 +1031,16 @@ static void print_vlan_opts(struct rtattr *a, int ifindex)
                print_uint(PRINT_ANY, "mcast_router", "mcast_router %u ",
                           rta_getattr_u8(vattr));
        }
+       if (vtb[BRIDGE_VLANDB_ENTRY_MCAST_N_GROUPS]) {
+               vattr = vtb[BRIDGE_VLANDB_ENTRY_MCAST_N_GROUPS];
+               print_uint(PRINT_ANY, "mcast_n_groups", "mcast_n_groups %u ",
+                          rta_getattr_u32(vattr));
+       }
+       if (vtb[BRIDGE_VLANDB_ENTRY_MCAST_MAX_GROUPS]) {
+               vattr = vtb[BRIDGE_VLANDB_ENTRY_MCAST_MAX_GROUPS];
+               print_uint(PRINT_ANY, "mcast_max_groups", "mcast_max_groups %u ",
+                          rta_getattr_u32(vattr));
+       }
        print_nl();
        if (show_stats)
                __print_one_vlan_stats(&vstats);