Merge branch 'bridge-mdb-limit'
Petr Machata says: ==================== bridge: Limit number of MDB entries per port, port-vlan The MDB maintained by the bridge is limited. When the bridge is configured for IGMP / MLD snooping, a buggy or malicious client can easily exhaust its capacity. In SW datapath, the capacity is configurable through the IFLA_BR_MCAST_HASH_MAX parameter, but ultimately is finite. Obviously a similar limit exists in the HW datapath for purposes of offloading. In order to prevent the issue of unilateral exhaustion of MDB resources, introduce two parameters in each of two contexts: - Per-port and (when BROPT_MCAST_VLAN_SNOOPING_ENABLED is enabled) per-port-VLAN number of MDB entries that the port is member in. - Per-port and (when BROPT_MCAST_VLAN_SNOOPING_ENABLED is enabled) per-port-VLAN maximum permitted number of MDB entries, or 0 for no limit. Per-port number of entries keeps track of the total number of MDB entries configured on a given port. The per-port-VLAN value then keeps track of the subset of MDB entries configured specifically for the given VLAN, on that port. The number is adjusted as port_groups are created and deleted, and therefore under multicast lock. A maximum value, if non-zero, then places a limit on the number of entries that can be configured in a given context. Attempts to add entries above the maximum are rejected. Rejection reason of netlink-based requests to add MDB entries is communicated through extack. This channel is unavailable for rejections triggered from the control path. To address this lack of visibility, the patchset adds a tracepoint, bridge:br_mdb_full: # perf record -e bridge:br_mdb_full & # [...] # perf script | cut -d: -f4- dev v2 af 2 src ::ffff:0.0.0.0 grp ::ffff:239.1.1.112/00:00:00:00:00:00 vid 0 dev v2 af 10 src :: grp ff0e::112/00:00:00:00:00:00 vid 0 dev v2 af 2 src ::ffff:0.0.0.0 grp ::ffff:239.1.1.112/00:00:00:00:00:00 vid 10 dev v2 af 10 src 2001:db8:1::1 grp ff0e::1/00:00:00:00:00:00 vid 10 dev v2 af 2 src ::ffff:192.0.2.1 grp ::ffff:239.1.1.1/00:00:00:00:00:00 vid 10 Another option to consume the tracepoint is e.g. through the bpftrace tool: # bpftrace -e ' tracepoint:bridge:br_mdb_full /args->af != 0/ { printf("dev %s src %s grp %s vid %u\n", str(args->dev), ntop(args->src), ntop(args->grp), args->vid); } tracepoint:bridge:br_mdb_full /args->af == 0/ { printf("dev %s grp %s vid %u\n", str(args->dev), macaddr(args->grpmac), args->vid); }' This tracepoint is triggered for mcast_hash_max exhaustions as well. The following is an example of how the feature is used. A more extensive example is available in patch #8: # 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. The patchset progresses as follows: - In patch #1, set strict_start_type at two bridge-related policies. The reason is we are adding a new attribute to one of these, and want the new attribute to be parsed strictly. The other was adjusted for completeness' sake. - In patches #2 to #5, br_mdb and br_multicast code is adjusted to make the following additions smoother. - In patch #6, add the tracepoint. - In patch #7, the code to maintain number of MDB entries is added as struct net_bridge_mcast_port::mdb_n_entries. The maximum is added, too, as struct net_bridge_mcast_port::mdb_max_entries, however at this point there is no way to set the value yet, and since 0 is treated as "no limit", the functionality doesn't change at this point. Note however, that mcast_hash_max violations already do trigger at this point. - In patch #8, netlink plumbing is added: reading of number of entries, and reading and writing of maximum. The per-port values are passed through RTM_NEWLINK / RTM_GETLINK messages in IFLA_BRPORT_MCAST_N_GROUPS and _MAX_GROUPS, inside IFLA_PROTINFO nest. The per-port-vlan values are passed through RTM_GETVLAN / RTM_NEWVLAN messages in BRIDGE_VLANDB_ENTRY_MCAST_N_GROUPS, _MAX_GROUPS, inside BRIDGE_VLANDB_ENTRY. The following patches deal with the selftest: - Patches #9 and #10 clean up and move around some selftest code. - Patches #11 to #14 add helpers and generalize the existing IGMP / MLD support to allow generating packets with configurable group addresses and varying source lists for (S,G) memberships. - Patch #15 adds code to generate IGMP leave and MLD done packets. - Patch #16 finally adds the selftest itself. v3: - Patch #7: - Access mdb_max_/_n_entries through READ_/WRITE_ONCE - Move extack setting to br_multicast_port_ngroups_inc_one(). Since we use NL_SET_ERR_MSG_FMT_MOD, the correct context (port / port-vlan) can be passed through an argument. This also removes the need for more READ/WRITE_ONCE's at the extack-setting site. - Patch #8: - Move the br_multicast_port_ctx_vlan_disabled() check out to the _vlan_ helpers callers. Thus these helpers cannot fail, which makes them very similar to the _port_ helpers. Have them take the MC context directly and unify them. v2: - Cover letter: - Add an example of a bpftrace-based probe script - Patch #6: - Report IPv4 as an IPv6-mapped address through the IPv6 buffer as well, to save ring buffer space. - Patch #7: - In br_multicast_port_ngroups_inc_one(), bounce if n>=max, not if n==max - Adjust extack messages to mention ngroups, now that the bounces appear when n>=max, not n==max - In __br_multicast_enable_port_ctx(), do not reset max to 0. Also do not count number of entries by going through _inc, as that would end up incorrectly bouncing the entries. - Patch #8: - Drop locks around accesses in br_multicast_{port,vlan}_ngroups_{get,set_max}(), - Drop bounces due to max<n in br_multicast_{port,vlan}_ngroups_set_max(). - Patch #12: - In the comment at payload_template_calc_checksum(), s/%#02x/%02x/, that's the mausezahn payload format. - Patch #16: - Adjust the tests that check setting max below n and reset of max on VLAN snooping enablement - Make test naming uniform - Enable testing of control path (IGMP/MLD) in mcast_vlan_snooping bridge - Reorganize the code so that test instances (per bridge type and configuration type) always come right after the test, in order of {d,q,qvs}{4,6}{cfg,ctl}. Then groups of selftests are at the end of the file. Similarly adjust invocation order of the tests. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
commit
cb3086cee6
@ -122,6 +122,64 @@ TRACE_EVENT(br_fdb_update,
|
||||
__entry->flags)
|
||||
);
|
||||
|
||||
TRACE_EVENT(br_mdb_full,
|
||||
|
||||
TP_PROTO(const struct net_device *dev,
|
||||
const struct br_ip *group),
|
||||
|
||||
TP_ARGS(dev, group),
|
||||
|
||||
TP_STRUCT__entry(
|
||||
__string(dev, dev->name)
|
||||
__field(int, af)
|
||||
__field(u16, vid)
|
||||
__array(__u8, src, 16)
|
||||
__array(__u8, grp, 16)
|
||||
__array(__u8, grpmac, ETH_ALEN) /* For af == 0. */
|
||||
),
|
||||
|
||||
TP_fast_assign(
|
||||
struct in6_addr *in6;
|
||||
|
||||
__assign_str(dev, dev->name);
|
||||
__entry->vid = group->vid;
|
||||
|
||||
if (!group->proto) {
|
||||
__entry->af = 0;
|
||||
|
||||
memset(__entry->src, 0, sizeof(__entry->src));
|
||||
memset(__entry->grp, 0, sizeof(__entry->grp));
|
||||
memcpy(__entry->grpmac, group->dst.mac_addr, ETH_ALEN);
|
||||
} else if (group->proto == htons(ETH_P_IP)) {
|
||||
__entry->af = AF_INET;
|
||||
|
||||
in6 = (struct in6_addr *)__entry->src;
|
||||
ipv6_addr_set_v4mapped(group->src.ip4, in6);
|
||||
|
||||
in6 = (struct in6_addr *)__entry->grp;
|
||||
ipv6_addr_set_v4mapped(group->dst.ip4, in6);
|
||||
|
||||
memset(__entry->grpmac, 0, ETH_ALEN);
|
||||
|
||||
#if IS_ENABLED(CONFIG_IPV6)
|
||||
} else {
|
||||
__entry->af = AF_INET6;
|
||||
|
||||
in6 = (struct in6_addr *)__entry->src;
|
||||
*in6 = group->src.ip6;
|
||||
|
||||
in6 = (struct in6_addr *)__entry->grp;
|
||||
*in6 = group->dst.ip6;
|
||||
|
||||
memset(__entry->grpmac, 0, ETH_ALEN);
|
||||
#endif
|
||||
}
|
||||
),
|
||||
|
||||
TP_printk("dev %s af %u src %pI6c grp %pI6c/%pM vid %u",
|
||||
__get_str(dev), __entry->af, __entry->src, __entry->grp,
|
||||
__entry->grpmac, __entry->vid)
|
||||
);
|
||||
|
||||
#endif /* _TRACE_BRIDGE_H */
|
||||
|
||||
|
@ -523,6 +523,8 @@ enum {
|
||||
BRIDGE_VLANDB_ENTRY_TUNNEL_INFO,
|
||||
BRIDGE_VLANDB_ENTRY_STATS,
|
||||
BRIDGE_VLANDB_ENTRY_MCAST_ROUTER,
|
||||
BRIDGE_VLANDB_ENTRY_MCAST_N_GROUPS,
|
||||
BRIDGE_VLANDB_ENTRY_MCAST_MAX_GROUPS,
|
||||
__BRIDGE_VLANDB_ENTRY_MAX,
|
||||
};
|
||||
#define BRIDGE_VLANDB_ENTRY_MAX (__BRIDGE_VLANDB_ENTRY_MAX - 1)
|
||||
|
@ -567,6 +567,8 @@ enum {
|
||||
IFLA_BRPORT_MCAST_EHT_HOSTS_CNT,
|
||||
IFLA_BRPORT_LOCKED,
|
||||
IFLA_BRPORT_MAB,
|
||||
IFLA_BRPORT_MCAST_N_GROUPS,
|
||||
IFLA_BRPORT_MCAST_MAX_GROUPS,
|
||||
__IFLA_BRPORT_MAX
|
||||
};
|
||||
#define IFLA_BRPORT_MAX (__IFLA_BRPORT_MAX - 1)
|
||||
|
@ -849,11 +849,10 @@ static int br_mdb_add_group_sg(const struct br_mdb_config *cfg,
|
||||
}
|
||||
|
||||
p = br_multicast_new_port_group(cfg->p, &cfg->group, *pp, flags, NULL,
|
||||
MCAST_INCLUDE, cfg->rt_protocol);
|
||||
if (unlikely(!p)) {
|
||||
NL_SET_ERR_MSG_MOD(extack, "Couldn't allocate new (S, G) port group");
|
||||
MCAST_INCLUDE, cfg->rt_protocol, extack);
|
||||
if (unlikely(!p))
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
rcu_assign_pointer(*pp, p);
|
||||
if (!(flags & MDB_PG_FLAGS_PERMANENT) && !cfg->src_entry)
|
||||
mod_timer(&p->timer,
|
||||
@ -1075,11 +1074,10 @@ static int br_mdb_add_group_star_g(const struct br_mdb_config *cfg,
|
||||
}
|
||||
|
||||
p = br_multicast_new_port_group(cfg->p, &cfg->group, *pp, flags, NULL,
|
||||
cfg->filter_mode, cfg->rt_protocol);
|
||||
if (unlikely(!p)) {
|
||||
NL_SET_ERR_MSG_MOD(extack, "Couldn't allocate new (*, G) port group");
|
||||
cfg->filter_mode, cfg->rt_protocol,
|
||||
extack);
|
||||
if (unlikely(!p))
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
err = br_mdb_add_group_srcs(cfg, p, brmctx, extack);
|
||||
if (err)
|
||||
@ -1101,8 +1099,7 @@ static int br_mdb_add_group_star_g(const struct br_mdb_config *cfg,
|
||||
return 0;
|
||||
|
||||
err_del_port_group:
|
||||
hlist_del_init(&p->mglist);
|
||||
kfree(p);
|
||||
br_multicast_del_port_group(p);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include <net/ip6_checksum.h>
|
||||
#include <net/addrconf.h>
|
||||
#endif
|
||||
#include <trace/events/bridge.h>
|
||||
|
||||
#include "br_private.h"
|
||||
#include "br_private_mcast_eht.h"
|
||||
@ -234,6 +235,29 @@ out:
|
||||
return pmctx;
|
||||
}
|
||||
|
||||
static struct net_bridge_mcast_port *
|
||||
br_multicast_port_vid_to_port_ctx(struct net_bridge_port *port, u16 vid)
|
||||
{
|
||||
struct net_bridge_mcast_port *pmctx = NULL;
|
||||
struct net_bridge_vlan *vlan;
|
||||
|
||||
lockdep_assert_held_once(&port->br->multicast_lock);
|
||||
|
||||
if (!br_opt_get(port->br, BROPT_MCAST_VLAN_SNOOPING_ENABLED))
|
||||
return NULL;
|
||||
|
||||
/* Take RCU to access the vlan. */
|
||||
rcu_read_lock();
|
||||
|
||||
vlan = br_vlan_find(nbp_vlan_group_rcu(port), vid);
|
||||
if (vlan && !br_multicast_port_ctx_vlan_disabled(&vlan->port_mcast_ctx))
|
||||
pmctx = &vlan->port_mcast_ctx;
|
||||
|
||||
rcu_read_unlock();
|
||||
|
||||
return pmctx;
|
||||
}
|
||||
|
||||
/* when snooping we need to check if the contexts should be used
|
||||
* in the following order:
|
||||
* - if pmctx is non-NULL (port), check if it should be used
|
||||
@ -668,6 +692,101 @@ void br_multicast_del_group_src(struct net_bridge_group_src *src,
|
||||
__br_multicast_del_group_src(src);
|
||||
}
|
||||
|
||||
static int
|
||||
br_multicast_port_ngroups_inc_one(struct net_bridge_mcast_port *pmctx,
|
||||
struct netlink_ext_ack *extack,
|
||||
const char *what)
|
||||
{
|
||||
u32 max = READ_ONCE(pmctx->mdb_max_entries);
|
||||
u32 n = READ_ONCE(pmctx->mdb_n_entries);
|
||||
|
||||
if (max && n >= max) {
|
||||
NL_SET_ERR_MSG_FMT_MOD(extack, "%s is already in %u groups, and mcast_max_groups=%u",
|
||||
what, n, max);
|
||||
return -E2BIG;
|
||||
}
|
||||
|
||||
WRITE_ONCE(pmctx->mdb_n_entries, n + 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void br_multicast_port_ngroups_dec_one(struct net_bridge_mcast_port *pmctx)
|
||||
{
|
||||
u32 n = READ_ONCE(pmctx->mdb_n_entries);
|
||||
|
||||
WARN_ON_ONCE(n == 0);
|
||||
WRITE_ONCE(pmctx->mdb_n_entries, n - 1);
|
||||
}
|
||||
|
||||
static int br_multicast_port_ngroups_inc(struct net_bridge_port *port,
|
||||
const struct br_ip *group,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
struct net_bridge_mcast_port *pmctx;
|
||||
int err;
|
||||
|
||||
lockdep_assert_held_once(&port->br->multicast_lock);
|
||||
|
||||
/* Always count on the port context. */
|
||||
err = br_multicast_port_ngroups_inc_one(&port->multicast_ctx, extack,
|
||||
"Port");
|
||||
if (err) {
|
||||
trace_br_mdb_full(port->dev, group);
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Only count on the VLAN context if VID is given, and if snooping on
|
||||
* that VLAN is enabled.
|
||||
*/
|
||||
if (!group->vid)
|
||||
return 0;
|
||||
|
||||
pmctx = br_multicast_port_vid_to_port_ctx(port, group->vid);
|
||||
if (!pmctx)
|
||||
return 0;
|
||||
|
||||
err = br_multicast_port_ngroups_inc_one(pmctx, extack, "Port-VLAN");
|
||||
if (err) {
|
||||
trace_br_mdb_full(port->dev, group);
|
||||
goto dec_one_out;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
dec_one_out:
|
||||
br_multicast_port_ngroups_dec_one(&port->multicast_ctx);
|
||||
return err;
|
||||
}
|
||||
|
||||
static void br_multicast_port_ngroups_dec(struct net_bridge_port *port, u16 vid)
|
||||
{
|
||||
struct net_bridge_mcast_port *pmctx;
|
||||
|
||||
lockdep_assert_held_once(&port->br->multicast_lock);
|
||||
|
||||
if (vid) {
|
||||
pmctx = br_multicast_port_vid_to_port_ctx(port, vid);
|
||||
if (pmctx)
|
||||
br_multicast_port_ngroups_dec_one(pmctx);
|
||||
}
|
||||
br_multicast_port_ngroups_dec_one(&port->multicast_ctx);
|
||||
}
|
||||
|
||||
u32 br_multicast_ngroups_get(const struct net_bridge_mcast_port *pmctx)
|
||||
{
|
||||
return READ_ONCE(pmctx->mdb_n_entries);
|
||||
}
|
||||
|
||||
void br_multicast_ngroups_set_max(struct net_bridge_mcast_port *pmctx, u32 max)
|
||||
{
|
||||
WRITE_ONCE(pmctx->mdb_max_entries, max);
|
||||
}
|
||||
|
||||
u32 br_multicast_ngroups_get_max(const struct net_bridge_mcast_port *pmctx)
|
||||
{
|
||||
return READ_ONCE(pmctx->mdb_max_entries);
|
||||
}
|
||||
|
||||
static void br_multicast_destroy_port_group(struct net_bridge_mcast_gc *gc)
|
||||
{
|
||||
struct net_bridge_port_group *pg;
|
||||
@ -702,6 +821,7 @@ void br_multicast_del_pg(struct net_bridge_mdb_entry *mp,
|
||||
} else {
|
||||
br_multicast_star_g_handle_mode(pg, MCAST_INCLUDE);
|
||||
}
|
||||
br_multicast_port_ngroups_dec(pg->key.port, pg->key.addr.vid);
|
||||
hlist_add_head(&pg->mcast_gc.gc_node, &br->mcast_gc_list);
|
||||
queue_work(system_long_wq, &br->mcast_gc_work);
|
||||
|
||||
@ -1165,6 +1285,7 @@ struct net_bridge_mdb_entry *br_multicast_new_group(struct net_bridge *br,
|
||||
return mp;
|
||||
|
||||
if (atomic_read(&br->mdb_hash_tbl.nelems) >= br->hash_max) {
|
||||
trace_br_mdb_full(br->dev, group);
|
||||
br_mc_disabled_update(br->dev, false, NULL);
|
||||
br_opt_toggle(br, BROPT_MULTICAST_ENABLED, false);
|
||||
return ERR_PTR(-E2BIG);
|
||||
@ -1284,13 +1405,21 @@ struct net_bridge_port_group *br_multicast_new_port_group(
|
||||
unsigned char flags,
|
||||
const unsigned char *src,
|
||||
u8 filter_mode,
|
||||
u8 rt_protocol)
|
||||
u8 rt_protocol,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
struct net_bridge_port_group *p;
|
||||
int err;
|
||||
|
||||
err = br_multicast_port_ngroups_inc(port, group, extack);
|
||||
if (err)
|
||||
return NULL;
|
||||
|
||||
p = kzalloc(sizeof(*p), GFP_ATOMIC);
|
||||
if (unlikely(!p))
|
||||
return NULL;
|
||||
if (unlikely(!p)) {
|
||||
NL_SET_ERR_MSG_MOD(extack, "Couldn't allocate new port group");
|
||||
goto dec_out;
|
||||
}
|
||||
|
||||
p->key.addr = *group;
|
||||
p->key.port = port;
|
||||
@ -1305,8 +1434,8 @@ struct net_bridge_port_group *br_multicast_new_port_group(
|
||||
if (!br_multicast_is_star_g(group) &&
|
||||
rhashtable_lookup_insert_fast(&port->br->sg_port_tbl, &p->rhnode,
|
||||
br_sg_port_rht_params)) {
|
||||
kfree(p);
|
||||
return NULL;
|
||||
NL_SET_ERR_MSG_MOD(extack, "Couldn't insert new port group");
|
||||
goto free_out;
|
||||
}
|
||||
|
||||
rcu_assign_pointer(p->next, next);
|
||||
@ -1320,6 +1449,25 @@ struct net_bridge_port_group *br_multicast_new_port_group(
|
||||
eth_broadcast_addr(p->eth_addr);
|
||||
|
||||
return p;
|
||||
|
||||
free_out:
|
||||
kfree(p);
|
||||
dec_out:
|
||||
br_multicast_port_ngroups_dec(port, group->vid);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void br_multicast_del_port_group(struct net_bridge_port_group *p)
|
||||
{
|
||||
struct net_bridge_port *port = p->key.port;
|
||||
__u16 vid = p->key.addr.vid;
|
||||
|
||||
hlist_del_init(&p->mglist);
|
||||
if (!br_multicast_is_star_g(&p->key.addr))
|
||||
rhashtable_remove_fast(&port->br->sg_port_tbl, &p->rhnode,
|
||||
br_sg_port_rht_params);
|
||||
kfree(p);
|
||||
br_multicast_port_ngroups_dec(port, vid);
|
||||
}
|
||||
|
||||
void br_multicast_host_join(const struct net_bridge_mcast *brmctx,
|
||||
@ -1387,7 +1535,7 @@ __br_multicast_add_group(struct net_bridge_mcast *brmctx,
|
||||
}
|
||||
|
||||
p = br_multicast_new_port_group(pmctx->port, group, *pp, 0, src,
|
||||
filter_mode, RTPROT_KERNEL);
|
||||
filter_mode, RTPROT_KERNEL, NULL);
|
||||
if (unlikely(!p)) {
|
||||
p = ERR_PTR(-ENOMEM);
|
||||
goto out;
|
||||
@ -1933,6 +2081,25 @@ static void __br_multicast_enable_port_ctx(struct net_bridge_mcast_port *pmctx)
|
||||
br_ip4_multicast_add_router(brmctx, pmctx);
|
||||
br_ip6_multicast_add_router(brmctx, pmctx);
|
||||
}
|
||||
|
||||
if (br_multicast_port_ctx_is_vlan(pmctx)) {
|
||||
struct net_bridge_port_group *pg;
|
||||
u32 n = 0;
|
||||
|
||||
/* The mcast_n_groups counter might be wrong. First,
|
||||
* BR_VLFLAG_MCAST_ENABLED is toggled before temporary entries
|
||||
* are flushed, thus mcast_n_groups after the toggle does not
|
||||
* reflect the true values. And second, permanent entries added
|
||||
* while BR_VLFLAG_MCAST_ENABLED was disabled, are not reflected
|
||||
* either. Thus we have to refresh the counter.
|
||||
*/
|
||||
|
||||
hlist_for_each_entry(pg, &pmctx->port->mglist, mglist) {
|
||||
if (pg->key.addr.vid == pmctx->vlan->vid)
|
||||
n++;
|
||||
}
|
||||
WRITE_ONCE(pmctx->mdb_n_entries, n);
|
||||
}
|
||||
}
|
||||
|
||||
void br_multicast_enable_port(struct net_bridge_port *port)
|
||||
|
@ -202,6 +202,8 @@ static inline size_t br_port_info_size(void)
|
||||
+ nla_total_size_64bit(sizeof(u64)) /* IFLA_BRPORT_HOLD_TIMER */
|
||||
#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
|
||||
+ nla_total_size(sizeof(u8)) /* IFLA_BRPORT_MULTICAST_ROUTER */
|
||||
+ nla_total_size(sizeof(u32)) /* IFLA_BRPORT_MCAST_N_GROUPS */
|
||||
+ nla_total_size(sizeof(u32)) /* IFLA_BRPORT_MCAST_MAX_GROUPS */
|
||||
#endif
|
||||
+ nla_total_size(sizeof(u16)) /* IFLA_BRPORT_GROUP_FWD_MASK */
|
||||
+ nla_total_size(sizeof(u8)) /* IFLA_BRPORT_MRP_RING_OPEN */
|
||||
@ -298,7 +300,11 @@ static int br_port_fill_attrs(struct sk_buff *skb,
|
||||
nla_put_u32(skb, IFLA_BRPORT_MCAST_EHT_HOSTS_LIMIT,
|
||||
p->multicast_eht_hosts_limit) ||
|
||||
nla_put_u32(skb, IFLA_BRPORT_MCAST_EHT_HOSTS_CNT,
|
||||
p->multicast_eht_hosts_cnt))
|
||||
p->multicast_eht_hosts_cnt) ||
|
||||
nla_put_u32(skb, IFLA_BRPORT_MCAST_N_GROUPS,
|
||||
br_multicast_ngroups_get(&p->multicast_ctx)) ||
|
||||
nla_put_u32(skb, IFLA_BRPORT_MCAST_MAX_GROUPS,
|
||||
br_multicast_ngroups_get_max(&p->multicast_ctx)))
|
||||
return -EMSGSIZE;
|
||||
#endif
|
||||
|
||||
@ -858,6 +864,8 @@ static int br_afspec(struct net_bridge *br,
|
||||
}
|
||||
|
||||
static const struct nla_policy br_port_policy[IFLA_BRPORT_MAX + 1] = {
|
||||
[IFLA_BRPORT_UNSPEC] = { .strict_start_type =
|
||||
IFLA_BRPORT_MCAST_EHT_HOSTS_LIMIT + 1 },
|
||||
[IFLA_BRPORT_STATE] = { .type = NLA_U8 },
|
||||
[IFLA_BRPORT_COST] = { .type = NLA_U32 },
|
||||
[IFLA_BRPORT_PRIORITY] = { .type = NLA_U16 },
|
||||
@ -881,6 +889,8 @@ static const struct nla_policy br_port_policy[IFLA_BRPORT_MAX + 1] = {
|
||||
[IFLA_BRPORT_MAB] = { .type = NLA_U8 },
|
||||
[IFLA_BRPORT_BACKUP_PORT] = { .type = NLA_U32 },
|
||||
[IFLA_BRPORT_MCAST_EHT_HOSTS_LIMIT] = { .type = NLA_U32 },
|
||||
[IFLA_BRPORT_MCAST_N_GROUPS] = { .type = NLA_REJECT },
|
||||
[IFLA_BRPORT_MCAST_MAX_GROUPS] = { .type = NLA_U32 },
|
||||
};
|
||||
|
||||
/* Change the state of the port and notify spanning tree */
|
||||
@ -1015,6 +1025,13 @@ static int br_setport(struct net_bridge_port *p, struct nlattr *tb[],
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
|
||||
if (tb[IFLA_BRPORT_MCAST_MAX_GROUPS]) {
|
||||
u32 max_groups;
|
||||
|
||||
max_groups = nla_get_u32(tb[IFLA_BRPORT_MCAST_MAX_GROUPS]);
|
||||
br_multicast_ngroups_set_max(&p->multicast_ctx, max_groups);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (tb[IFLA_BRPORT_GROUP_FWD_MASK]) {
|
||||
|
@ -188,6 +188,9 @@ initvars:
|
||||
}
|
||||
|
||||
static const struct nla_policy vlan_tunnel_policy[IFLA_BRIDGE_VLAN_TUNNEL_MAX + 1] = {
|
||||
[IFLA_BRIDGE_VLAN_TUNNEL_UNSPEC] = {
|
||||
.strict_start_type = IFLA_BRIDGE_VLAN_TUNNEL_FLAGS + 1
|
||||
},
|
||||
[IFLA_BRIDGE_VLAN_TUNNEL_ID] = { .type = NLA_U32 },
|
||||
[IFLA_BRIDGE_VLAN_TUNNEL_VID] = { .type = NLA_U16 },
|
||||
[IFLA_BRIDGE_VLAN_TUNNEL_FLAGS] = { .type = NLA_U16 },
|
||||
|
@ -126,6 +126,8 @@ struct net_bridge_mcast_port {
|
||||
struct hlist_node ip6_rlist;
|
||||
#endif /* IS_ENABLED(CONFIG_IPV6) */
|
||||
unsigned char multicast_router;
|
||||
u32 mdb_n_entries;
|
||||
u32 mdb_max_entries;
|
||||
#endif /* CONFIG_BRIDGE_IGMP_SNOOPING */
|
||||
};
|
||||
|
||||
@ -956,7 +958,9 @@ br_multicast_new_port_group(struct net_bridge_port *port,
|
||||
const struct br_ip *group,
|
||||
struct net_bridge_port_group __rcu *next,
|
||||
unsigned char flags, const unsigned char *src,
|
||||
u8 filter_mode, u8 rt_protocol);
|
||||
u8 filter_mode, u8 rt_protocol,
|
||||
struct netlink_ext_ack *extack);
|
||||
void br_multicast_del_port_group(struct net_bridge_port_group *p);
|
||||
int br_mdb_hash_init(struct net_bridge *br);
|
||||
void br_mdb_hash_fini(struct net_bridge *br);
|
||||
void br_mdb_notify(struct net_device *dev, struct net_bridge_mdb_entry *mp,
|
||||
@ -974,6 +978,9 @@ void br_multicast_uninit_stats(struct net_bridge *br);
|
||||
void br_multicast_get_stats(const struct net_bridge *br,
|
||||
const struct net_bridge_port *p,
|
||||
struct br_mcast_stats *dest);
|
||||
u32 br_multicast_ngroups_get(const struct net_bridge_mcast_port *pmctx);
|
||||
void br_multicast_ngroups_set_max(struct net_bridge_mcast_port *pmctx, u32 max);
|
||||
u32 br_multicast_ngroups_get_max(const struct net_bridge_mcast_port *pmctx);
|
||||
void br_mdb_init(void);
|
||||
void br_mdb_uninit(void);
|
||||
void br_multicast_host_join(const struct net_bridge_mcast *brmctx,
|
||||
@ -1757,7 +1764,8 @@ static inline u16 br_vlan_flags(const struct net_bridge_vlan *v, u16 pvid)
|
||||
#ifdef CONFIG_BRIDGE_VLAN_FILTERING
|
||||
bool br_vlan_opts_eq_range(const struct net_bridge_vlan *v_curr,
|
||||
const struct net_bridge_vlan *range_end);
|
||||
bool br_vlan_opts_fill(struct sk_buff *skb, const struct net_bridge_vlan *v);
|
||||
bool br_vlan_opts_fill(struct sk_buff *skb, const struct net_bridge_vlan *v,
|
||||
const struct net_bridge_port *p);
|
||||
size_t br_vlan_opts_nl_size(void);
|
||||
int br_vlan_process_options(const struct net_bridge *br,
|
||||
const struct net_bridge_port *p,
|
||||
|
@ -1816,6 +1816,7 @@ out_err:
|
||||
/* v_opts is used to dump the options which must be equal in the whole range */
|
||||
static bool br_vlan_fill_vids(struct sk_buff *skb, u16 vid, u16 vid_range,
|
||||
const struct net_bridge_vlan *v_opts,
|
||||
const struct net_bridge_port *p,
|
||||
u16 flags,
|
||||
bool dump_stats)
|
||||
{
|
||||
@ -1842,7 +1843,7 @@ static bool br_vlan_fill_vids(struct sk_buff *skb, u16 vid, u16 vid_range,
|
||||
goto out_err;
|
||||
|
||||
if (v_opts) {
|
||||
if (!br_vlan_opts_fill(skb, v_opts))
|
||||
if (!br_vlan_opts_fill(skb, v_opts, p))
|
||||
goto out_err;
|
||||
|
||||
if (dump_stats && !br_vlan_stats_fill(skb, v_opts))
|
||||
@ -1925,7 +1926,7 @@ void br_vlan_notify(const struct net_bridge *br,
|
||||
goto out_kfree;
|
||||
}
|
||||
|
||||
if (!br_vlan_fill_vids(skb, vid, vid_range, v, flags, false))
|
||||
if (!br_vlan_fill_vids(skb, vid, vid_range, v, p, flags, false))
|
||||
goto out_err;
|
||||
|
||||
nlmsg_end(skb, nlh);
|
||||
@ -2030,7 +2031,7 @@ static int br_vlan_dump_dev(const struct net_device *dev,
|
||||
|
||||
if (!br_vlan_fill_vids(skb, range_start->vid,
|
||||
range_end->vid, range_start,
|
||||
vlan_flags, dump_stats)) {
|
||||
p, vlan_flags, dump_stats)) {
|
||||
err = -EMSGSIZE;
|
||||
break;
|
||||
}
|
||||
@ -2056,7 +2057,7 @@ update_end:
|
||||
else if (!dump_global &&
|
||||
!br_vlan_fill_vids(skb, range_start->vid,
|
||||
range_end->vid, range_start,
|
||||
br_vlan_flags(range_start, pvid),
|
||||
p, br_vlan_flags(range_start, pvid),
|
||||
dump_stats))
|
||||
err = -EMSGSIZE;
|
||||
}
|
||||
@ -2131,6 +2132,8 @@ static const struct nla_policy br_vlan_db_policy[BRIDGE_VLANDB_ENTRY_MAX + 1] =
|
||||
[BRIDGE_VLANDB_ENTRY_STATE] = { .type = NLA_U8 },
|
||||
[BRIDGE_VLANDB_ENTRY_TUNNEL_INFO] = { .type = NLA_NESTED },
|
||||
[BRIDGE_VLANDB_ENTRY_MCAST_ROUTER] = { .type = NLA_U8 },
|
||||
[BRIDGE_VLANDB_ENTRY_MCAST_N_GROUPS] = { .type = NLA_REJECT },
|
||||
[BRIDGE_VLANDB_ENTRY_MCAST_MAX_GROUPS] = { .type = NLA_U32 },
|
||||
};
|
||||
|
||||
static int br_vlan_rtm_process_one(struct net_device *dev,
|
||||
|
@ -48,7 +48,8 @@ bool br_vlan_opts_eq_range(const struct net_bridge_vlan *v_curr,
|
||||
curr_mc_rtr == range_mc_rtr;
|
||||
}
|
||||
|
||||
bool br_vlan_opts_fill(struct sk_buff *skb, const struct net_bridge_vlan *v)
|
||||
bool br_vlan_opts_fill(struct sk_buff *skb, const struct net_bridge_vlan *v,
|
||||
const struct net_bridge_port *p)
|
||||
{
|
||||
if (nla_put_u8(skb, BRIDGE_VLANDB_ENTRY_STATE, br_vlan_get_state(v)) ||
|
||||
!__vlan_tun_put(skb, v))
|
||||
@ -58,6 +59,12 @@ bool br_vlan_opts_fill(struct sk_buff *skb, const struct net_bridge_vlan *v)
|
||||
if (nla_put_u8(skb, BRIDGE_VLANDB_ENTRY_MCAST_ROUTER,
|
||||
br_vlan_multicast_router(v)))
|
||||
return false;
|
||||
if (p && !br_multicast_port_ctx_vlan_disabled(&v->port_mcast_ctx) &&
|
||||
(nla_put_u32(skb, BRIDGE_VLANDB_ENTRY_MCAST_N_GROUPS,
|
||||
br_multicast_ngroups_get(&v->port_mcast_ctx)) ||
|
||||
nla_put_u32(skb, BRIDGE_VLANDB_ENTRY_MCAST_MAX_GROUPS,
|
||||
br_multicast_ngroups_get_max(&v->port_mcast_ctx))))
|
||||
return false;
|
||||
#endif
|
||||
|
||||
return true;
|
||||
@ -70,6 +77,8 @@ size_t br_vlan_opts_nl_size(void)
|
||||
+ nla_total_size(sizeof(u32)) /* BRIDGE_VLANDB_TINFO_ID */
|
||||
#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
|
||||
+ nla_total_size(sizeof(u8)) /* BRIDGE_VLANDB_ENTRY_MCAST_ROUTER */
|
||||
+ nla_total_size(sizeof(u32)) /* BRIDGE_VLANDB_ENTRY_MCAST_N_GROUPS */
|
||||
+ nla_total_size(sizeof(u32)) /* BRIDGE_VLANDB_ENTRY_MCAST_MAX_GROUPS */
|
||||
#endif
|
||||
+ 0;
|
||||
}
|
||||
@ -212,6 +221,22 @@ static int br_vlan_process_one_opts(const struct net_bridge *br,
|
||||
return err;
|
||||
*changed = true;
|
||||
}
|
||||
if (tb[BRIDGE_VLANDB_ENTRY_MCAST_MAX_GROUPS]) {
|
||||
u32 val;
|
||||
|
||||
if (!p) {
|
||||
NL_SET_ERR_MSG_MOD(extack, "Can't set mcast_max_groups for non-port vlans");
|
||||
return -EINVAL;
|
||||
}
|
||||
if (br_multicast_port_ctx_vlan_disabled(&v->port_mcast_ctx)) {
|
||||
NL_SET_ERR_MSG_MOD(extack, "Multicast snooping disabled on this VLAN");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
val = nla_get_u32(tb[BRIDGE_VLANDB_ENTRY_MCAST_MAX_GROUPS]);
|
||||
br_multicast_ngroups_set_max(&v->port_mcast_ctx, val);
|
||||
*changed = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
@ -41,6 +41,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(br_fdb_add);
|
||||
EXPORT_TRACEPOINT_SYMBOL_GPL(br_fdb_external_learn_add);
|
||||
EXPORT_TRACEPOINT_SYMBOL_GPL(fdb_delete);
|
||||
EXPORT_TRACEPOINT_SYMBOL_GPL(br_fdb_update);
|
||||
EXPORT_TRACEPOINT_SYMBOL_GPL(br_mdb_full);
|
||||
#endif
|
||||
|
||||
#if IS_ENABLED(CONFIG_PAGE_POOL)
|
||||
|
@ -58,7 +58,7 @@
|
||||
#include "dev.h"
|
||||
|
||||
#define RTNL_MAX_TYPE 50
|
||||
#define RTNL_SLAVE_MAX_TYPE 40
|
||||
#define RTNL_SLAVE_MAX_TYPE 42
|
||||
|
||||
struct rtnl_link {
|
||||
rtnl_doit_func doit;
|
||||
|
@ -4,6 +4,7 @@ TEST_PROGS = bridge_igmp.sh \
|
||||
bridge_locked_port.sh \
|
||||
bridge_mdb.sh \
|
||||
bridge_mdb_host.sh \
|
||||
bridge_mdb_max.sh \
|
||||
bridge_mdb_port_down.sh \
|
||||
bridge_mld.sh \
|
||||
bridge_port_isolation.sh \
|
||||
|
@ -1018,26 +1018,6 @@ fwd_test()
|
||||
ip -6 address del fe80::1/64 dev br0
|
||||
}
|
||||
|
||||
igmpv3_is_in_get()
|
||||
{
|
||||
local igmpv3
|
||||
|
||||
igmpv3=$(:
|
||||
)"22:"$( : Type - Membership Report
|
||||
)"00:"$( : Reserved
|
||||
)"2a:f8:"$( : Checksum
|
||||
)"00:00:"$( : Reserved
|
||||
)"00:01:"$( : Number of Group Records
|
||||
)"01:"$( : Record Type - IS_IN
|
||||
)"00:"$( : Aux Data Len
|
||||
)"00:01:"$( : Number of Sources
|
||||
)"ef:01:01:01:"$( : Multicast Address - 239.1.1.1
|
||||
)"c0:00:02:02"$( : Source Address - 192.0.2.2
|
||||
)
|
||||
|
||||
echo $igmpv3
|
||||
}
|
||||
|
||||
ctrl_igmpv3_is_in_test()
|
||||
{
|
||||
RET=0
|
||||
@ -1049,7 +1029,7 @@ ctrl_igmpv3_is_in_test()
|
||||
|
||||
# IS_IN ( 192.0.2.2 )
|
||||
$MZ $h1.10 -c 1 -A 192.0.2.1 -B 239.1.1.1 \
|
||||
-t ip proto=2,p=$(igmpv3_is_in_get) -q
|
||||
-t ip proto=2,p=$(igmpv3_is_in_get 239.1.1.1 192.0.2.2) -q
|
||||
|
||||
bridge -d mdb show dev br0 vid 10 | grep 239.1.1.1 | grep -q 192.0.2.2
|
||||
check_fail $? "Permanent entry affected by IGMP packet"
|
||||
@ -1062,7 +1042,7 @@ ctrl_igmpv3_is_in_test()
|
||||
|
||||
# IS_IN ( 192.0.2.2 )
|
||||
$MZ $h1.10 -c 1 -A 192.0.2.1 -B 239.1.1.1 \
|
||||
-t ip proto=2,p=$(igmpv3_is_in_get) -q
|
||||
-t ip proto=2,p=$(igmpv3_is_in_get 239.1.1.1 192.0.2.2) -q
|
||||
|
||||
bridge -d mdb show dev br0 vid 10 | grep 239.1.1.1 | grep -v "src" | \
|
||||
grep -q 192.0.2.2
|
||||
@ -1074,36 +1054,7 @@ ctrl_igmpv3_is_in_test()
|
||||
|
||||
bridge mdb del dev br0 port $swp1 grp 239.1.1.1 vid 10
|
||||
|
||||
log_test "IGMPv3 MODE_IS_INCLUE tests"
|
||||
}
|
||||
|
||||
mldv2_is_in_get()
|
||||
{
|
||||
local hbh
|
||||
local icmpv6
|
||||
|
||||
hbh=$(:
|
||||
)"3a:"$( : Next Header - ICMPv6
|
||||
)"00:"$( : Hdr Ext Len
|
||||
)"00:00:00:00:00:00:"$( : Options and Padding
|
||||
)
|
||||
|
||||
icmpv6=$(:
|
||||
)"8f:"$( : Type - MLDv2 Report
|
||||
)"00:"$( : Code
|
||||
)"45:39:"$( : Checksum
|
||||
)"00:00:"$( : Reserved
|
||||
)"00:01:"$( : Number of Group Records
|
||||
)"01:"$( : Record Type - IS_IN
|
||||
)"00:"$( : Aux Data Len
|
||||
)"00:01:"$( : Number of Sources
|
||||
)"ff:0e:00:00:00:00:00:00:"$( : Multicast address - ff0e::1
|
||||
)"00:00:00:00:00:00:00:01:"$( :
|
||||
)"20:01:0d:b8:00:01:00:00:"$( : Source Address - 2001:db8:1::2
|
||||
)"00:00:00:00:00:00:00:02:"$( :
|
||||
)
|
||||
|
||||
echo ${hbh}${icmpv6}
|
||||
log_test "IGMPv3 MODE_IS_INCLUDE tests"
|
||||
}
|
||||
|
||||
ctrl_mldv2_is_in_test()
|
||||
@ -1116,8 +1067,9 @@ ctrl_mldv2_is_in_test()
|
||||
filter_mode include source_list 2001:db8:1::1
|
||||
|
||||
# IS_IN ( 2001:db8:1::2 )
|
||||
local p=$(mldv2_is_in_get fe80::1 ff0e::1 2001:db8:1::2)
|
||||
$MZ -6 $h1.10 -c 1 -A fe80::1 -B ff0e::1 \
|
||||
-t ip hop=1,next=0,p=$(mldv2_is_in_get) -q
|
||||
-t ip hop=1,next=0,p="$p" -q
|
||||
|
||||
bridge -d mdb show dev br0 vid 10 | grep ff0e::1 | \
|
||||
grep -q 2001:db8:1::2
|
||||
@ -1131,7 +1083,7 @@ ctrl_mldv2_is_in_test()
|
||||
|
||||
# IS_IN ( 2001:db8:1::2 )
|
||||
$MZ -6 $h1.10 -c 1 -A fe80::1 -B ff0e::1 \
|
||||
-t ip hop=1,next=0,p=$(mldv2_is_in_get) -q
|
||||
-t ip hop=1,next=0,p="$p" -q
|
||||
|
||||
bridge -d mdb show dev br0 vid 10 | grep ff0e::1 | grep -v "src" | \
|
||||
grep -q 2001:db8:1::2
|
||||
|
1336
tools/testing/selftests/net/forwarding/bridge_mdb_max.sh
Executable file
1336
tools/testing/selftests/net/forwarding/bridge_mdb_max.sh
Executable file
File diff suppressed because it is too large
Load Diff
@ -1671,3 +1671,219 @@ hw_stats_monitor_test()
|
||||
|
||||
log_test "${type}_stats notifications"
|
||||
}
|
||||
|
||||
ipv4_to_bytes()
|
||||
{
|
||||
local IP=$1; shift
|
||||
|
||||
printf '%02x:' ${IP//./ } |
|
||||
sed 's/:$//'
|
||||
}
|
||||
|
||||
# Convert a given IPv6 address, `IP' such that the :: token, if present, is
|
||||
# expanded, and each 16-bit group is padded with zeroes to be 4 hexadecimal
|
||||
# digits. An optional `BYTESEP' parameter can be given to further separate
|
||||
# individual bytes of each 16-bit group.
|
||||
expand_ipv6()
|
||||
{
|
||||
local IP=$1; shift
|
||||
local bytesep=$1; shift
|
||||
|
||||
local cvt_ip=${IP/::/_}
|
||||
local colons=${cvt_ip//[^:]/}
|
||||
local allcol=:::::::
|
||||
# IP where :: -> the appropriate number of colons:
|
||||
local allcol_ip=${cvt_ip/_/${allcol:${#colons}}}
|
||||
|
||||
echo $allcol_ip | tr : '\n' |
|
||||
sed s/^/0000/ |
|
||||
sed 's/.*\(..\)\(..\)/\1'"$bytesep"'\2/' |
|
||||
tr '\n' : |
|
||||
sed 's/:$//'
|
||||
}
|
||||
|
||||
ipv6_to_bytes()
|
||||
{
|
||||
local IP=$1; shift
|
||||
|
||||
expand_ipv6 "$IP" :
|
||||
}
|
||||
|
||||
u16_to_bytes()
|
||||
{
|
||||
local u16=$1; shift
|
||||
|
||||
printf "%04x" $u16 | sed 's/^/000/;s/^.*\(..\)\(..\)$/\1:\2/'
|
||||
}
|
||||
|
||||
# Given a mausezahn-formatted payload (colon-separated bytes given as %02x),
|
||||
# possibly with a keyword CHECKSUM stashed where a 16-bit checksum should be,
|
||||
# calculate checksum as per RFC 1071, assuming the CHECKSUM field (if any)
|
||||
# stands for 00:00.
|
||||
payload_template_calc_checksum()
|
||||
{
|
||||
local payload=$1; shift
|
||||
|
||||
(
|
||||
# Set input radix.
|
||||
echo "16i"
|
||||
# Push zero for the initial checksum.
|
||||
echo 0
|
||||
|
||||
# Pad the payload with a terminating 00: in case we get an odd
|
||||
# number of bytes.
|
||||
echo "${payload%:}:00:" |
|
||||
sed 's/CHECKSUM/00:00/g' |
|
||||
tr '[:lower:]' '[:upper:]' |
|
||||
# Add the word to the checksum.
|
||||
sed 's/\(..\):\(..\):/\1\2+\n/g' |
|
||||
# Strip the extra odd byte we pushed if left unconverted.
|
||||
sed 's/\(..\):$//'
|
||||
|
||||
echo "10000 ~ +" # Calculate and add carry.
|
||||
echo "FFFF r - p" # Bit-flip and print.
|
||||
) |
|
||||
dc |
|
||||
tr '[:upper:]' '[:lower:]'
|
||||
}
|
||||
|
||||
payload_template_expand_checksum()
|
||||
{
|
||||
local payload=$1; shift
|
||||
local checksum=$1; shift
|
||||
|
||||
local ckbytes=$(u16_to_bytes $checksum)
|
||||
|
||||
echo "$payload" | sed "s/CHECKSUM/$ckbytes/g"
|
||||
}
|
||||
|
||||
payload_template_nbytes()
|
||||
{
|
||||
local payload=$1; shift
|
||||
|
||||
payload_template_expand_checksum "${payload%:}" 0 |
|
||||
sed 's/:/\n/g' | wc -l
|
||||
}
|
||||
|
||||
igmpv3_is_in_get()
|
||||
{
|
||||
local GRP=$1; shift
|
||||
local sources=("$@")
|
||||
|
||||
local igmpv3
|
||||
local nsources=$(u16_to_bytes ${#sources[@]})
|
||||
|
||||
# IS_IN ( $sources )
|
||||
igmpv3=$(:
|
||||
)"22:"$( : Type - Membership Report
|
||||
)"00:"$( : Reserved
|
||||
)"CHECKSUM:"$( : Checksum
|
||||
)"00:00:"$( : Reserved
|
||||
)"00:01:"$( : Number of Group Records
|
||||
)"01:"$( : Record Type - IS_IN
|
||||
)"00:"$( : Aux Data Len
|
||||
)"${nsources}:"$( : Number of Sources
|
||||
)"$(ipv4_to_bytes $GRP):"$( : Multicast Address
|
||||
)"$(for src in "${sources[@]}"; do
|
||||
ipv4_to_bytes $src
|
||||
echo -n :
|
||||
done)"$( : Source Addresses
|
||||
)
|
||||
local checksum=$(payload_template_calc_checksum "$igmpv3")
|
||||
|
||||
payload_template_expand_checksum "$igmpv3" $checksum
|
||||
}
|
||||
|
||||
igmpv2_leave_get()
|
||||
{
|
||||
local GRP=$1; shift
|
||||
|
||||
local payload=$(:
|
||||
)"17:"$( : Type - Leave Group
|
||||
)"00:"$( : Max Resp Time - not meaningful
|
||||
)"CHECKSUM:"$( : Checksum
|
||||
)"$(ipv4_to_bytes $GRP)"$( : Group Address
|
||||
)
|
||||
local checksum=$(payload_template_calc_checksum "$payload")
|
||||
|
||||
payload_template_expand_checksum "$payload" $checksum
|
||||
}
|
||||
|
||||
mldv2_is_in_get()
|
||||
{
|
||||
local SIP=$1; shift
|
||||
local GRP=$1; shift
|
||||
local sources=("$@")
|
||||
|
||||
local hbh
|
||||
local icmpv6
|
||||
local nsources=$(u16_to_bytes ${#sources[@]})
|
||||
|
||||
hbh=$(:
|
||||
)"3a:"$( : Next Header - ICMPv6
|
||||
)"00:"$( : Hdr Ext Len
|
||||
)"00:00:00:00:00:00:"$( : Options and Padding
|
||||
)
|
||||
|
||||
icmpv6=$(:
|
||||
)"8f:"$( : Type - MLDv2 Report
|
||||
)"00:"$( : Code
|
||||
)"CHECKSUM:"$( : Checksum
|
||||
)"00:00:"$( : Reserved
|
||||
)"00:01:"$( : Number of Group Records
|
||||
)"01:"$( : Record Type - IS_IN
|
||||
)"00:"$( : Aux Data Len
|
||||
)"${nsources}:"$( : Number of Sources
|
||||
)"$(ipv6_to_bytes $GRP):"$( : Multicast address
|
||||
)"$(for src in "${sources[@]}"; do
|
||||
ipv6_to_bytes $src
|
||||
echo -n :
|
||||
done)"$( : Source Addresses
|
||||
)
|
||||
|
||||
local len=$(u16_to_bytes $(payload_template_nbytes $icmpv6))
|
||||
local sudohdr=$(:
|
||||
)"$(ipv6_to_bytes $SIP):"$( : SIP
|
||||
)"$(ipv6_to_bytes $GRP):"$( : DIP is multicast address
|
||||
)"${len}:"$( : Upper-layer length
|
||||
)"00:3a:"$( : Zero and next-header
|
||||
)
|
||||
local checksum=$(payload_template_calc_checksum ${sudohdr}${icmpv6})
|
||||
|
||||
payload_template_expand_checksum "$hbh$icmpv6" $checksum
|
||||
}
|
||||
|
||||
mldv1_done_get()
|
||||
{
|
||||
local SIP=$1; shift
|
||||
local GRP=$1; shift
|
||||
|
||||
local hbh
|
||||
local icmpv6
|
||||
|
||||
hbh=$(:
|
||||
)"3a:"$( : Next Header - ICMPv6
|
||||
)"00:"$( : Hdr Ext Len
|
||||
)"00:00:00:00:00:00:"$( : Options and Padding
|
||||
)
|
||||
|
||||
icmpv6=$(:
|
||||
)"84:"$( : Type - MLDv1 Done
|
||||
)"00:"$( : Code
|
||||
)"CHECKSUM:"$( : Checksum
|
||||
)"00:00:"$( : Max Resp Delay - not meaningful
|
||||
)"00:00:"$( : Reserved
|
||||
)"$(ipv6_to_bytes $GRP):"$( : Multicast address
|
||||
)
|
||||
|
||||
local len=$(u16_to_bytes $(payload_template_nbytes $icmpv6))
|
||||
local sudohdr=$(:
|
||||
)"$(ipv6_to_bytes $SIP):"$( : SIP
|
||||
)"$(ipv6_to_bytes $GRP):"$( : DIP is multicast address
|
||||
)"${len}:"$( : Upper-layer length
|
||||
)"00:3a:"$( : Zero and next-header
|
||||
)
|
||||
local checksum=$(payload_template_calc_checksum ${sudohdr}${icmpv6})
|
||||
|
||||
payload_template_expand_checksum "$hbh$icmpv6" $checksum
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user