2017-11-19 22:05:11 +08:00
|
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2021-01-01 07:00:01 +08:00
|
|
|
|
/* Copyright (C) B.A.T.M.A.N. contributors:
|
2014-02-16 00:47:49 +08:00
|
|
|
|
*
|
|
|
|
|
* Linus Lüssing
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "multicast.h"
|
2015-04-18 01:40:28 +08:00
|
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
|
|
#include <linux/atomic.h>
|
2015-06-16 23:10:25 +08:00
|
|
|
|
#include <linux/bitops.h>
|
2015-06-16 23:10:26 +08:00
|
|
|
|
#include <linux/bug.h>
|
2015-04-18 01:40:28 +08:00
|
|
|
|
#include <linux/byteorder/generic.h>
|
2022-01-22 00:14:44 +08:00
|
|
|
|
#include <linux/container_of.h>
|
2015-04-18 01:40:28 +08:00
|
|
|
|
#include <linux/errno.h>
|
|
|
|
|
#include <linux/etherdevice.h>
|
2017-11-20 00:12:02 +08:00
|
|
|
|
#include <linux/gfp.h>
|
2016-05-11 00:41:24 +08:00
|
|
|
|
#include <linux/icmpv6.h>
|
2016-05-11 00:41:25 +08:00
|
|
|
|
#include <linux/if_bridge.h>
|
2015-04-18 01:40:28 +08:00
|
|
|
|
#include <linux/if_ether.h>
|
2016-05-11 00:41:24 +08:00
|
|
|
|
#include <linux/igmp.h>
|
2015-04-18 01:40:28 +08:00
|
|
|
|
#include <linux/in.h>
|
2016-05-11 00:41:24 +08:00
|
|
|
|
#include <linux/in6.h>
|
2019-05-27 00:35:49 +08:00
|
|
|
|
#include <linux/inetdevice.h>
|
2015-04-18 01:40:28 +08:00
|
|
|
|
#include <linux/ip.h>
|
|
|
|
|
#include <linux/ipv6.h>
|
2016-08-07 04:23:16 +08:00
|
|
|
|
#include <linux/jiffies.h>
|
2015-04-18 01:40:28 +08:00
|
|
|
|
#include <linux/list.h>
|
2015-06-21 20:45:14 +08:00
|
|
|
|
#include <linux/lockdep.h>
|
2015-04-18 01:40:28 +08:00
|
|
|
|
#include <linux/netdevice.h>
|
2018-03-13 18:41:13 +08:00
|
|
|
|
#include <linux/netlink.h>
|
2016-05-11 00:41:25 +08:00
|
|
|
|
#include <linux/printk.h>
|
2015-04-18 01:40:28 +08:00
|
|
|
|
#include <linux/rculist.h>
|
|
|
|
|
#include <linux/rcupdate.h>
|
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
|
#include <linux/slab.h>
|
|
|
|
|
#include <linux/spinlock.h>
|
2023-10-30 22:58:35 +08:00
|
|
|
|
#include <linux/sprintf.h>
|
2015-04-18 01:40:28 +08:00
|
|
|
|
#include <linux/stddef.h>
|
|
|
|
|
#include <linux/string.h>
|
|
|
|
|
#include <linux/types.h>
|
2016-08-07 04:23:16 +08:00
|
|
|
|
#include <linux/workqueue.h>
|
2015-04-18 01:40:28 +08:00
|
|
|
|
#include <net/addrconf.h>
|
2018-03-13 18:41:13 +08:00
|
|
|
|
#include <net/genetlink.h>
|
2016-05-11 00:41:25 +08:00
|
|
|
|
#include <net/if_inet6.h>
|
|
|
|
|
#include <net/ip.h>
|
2015-04-18 01:40:28 +08:00
|
|
|
|
#include <net/ipv6.h>
|
2018-03-13 18:41:13 +08:00
|
|
|
|
#include <net/netlink.h>
|
|
|
|
|
#include <net/sock.h>
|
2017-12-21 17:17:41 +08:00
|
|
|
|
#include <uapi/linux/batadv_packet.h>
|
2018-03-13 18:41:13 +08:00
|
|
|
|
#include <uapi/linux/batman_adv.h>
|
2015-04-18 01:40:28 +08:00
|
|
|
|
|
2020-09-15 15:54:08 +08:00
|
|
|
|
#include "bridge_loop_avoidance.h"
|
2016-05-11 00:41:27 +08:00
|
|
|
|
#include "hard-interface.h"
|
|
|
|
|
#include "hash.h"
|
2016-05-16 05:48:31 +08:00
|
|
|
|
#include "log.h"
|
2018-03-13 18:41:13 +08:00
|
|
|
|
#include "netlink.h"
|
2019-03-23 12:47:41 +08:00
|
|
|
|
#include "send.h"
|
2018-03-13 18:41:13 +08:00
|
|
|
|
#include "soft-interface.h"
|
2014-02-16 00:47:49 +08:00
|
|
|
|
#include "translation-table.h"
|
2016-05-15 17:07:43 +08:00
|
|
|
|
#include "tvlv.h"
|
2014-02-16 00:47:49 +08:00
|
|
|
|
|
2016-08-07 04:23:16 +08:00
|
|
|
|
static void batadv_mcast_mla_update(struct work_struct *work);
|
|
|
|
|
|
|
|
|
|
/**
|
2017-12-03 02:51:47 +08:00
|
|
|
|
* batadv_mcast_start_timer() - schedule the multicast periodic worker
|
2016-08-07 04:23:16 +08:00
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
*/
|
|
|
|
|
static void batadv_mcast_start_timer(struct batadv_priv *bat_priv)
|
|
|
|
|
{
|
|
|
|
|
queue_delayed_work(batadv_event_workqueue, &bat_priv->mcast.work,
|
|
|
|
|
msecs_to_jiffies(BATADV_MCAST_WORK_PERIOD));
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-07 12:08:26 +08:00
|
|
|
|
/**
|
2019-06-12 04:58:40 +08:00
|
|
|
|
* batadv_mcast_get_bridge() - get the bridge on top of the softif if it exists
|
|
|
|
|
* @soft_iface: netdev struct of the mesh interface
|
2019-05-07 12:08:26 +08:00
|
|
|
|
*
|
2019-06-12 04:58:40 +08:00
|
|
|
|
* If the given soft interface has a bridge on top then the refcount
|
|
|
|
|
* of the according net device is increased.
|
2019-05-07 12:08:26 +08:00
|
|
|
|
*
|
2019-06-12 04:58:40 +08:00
|
|
|
|
* Return: NULL if no such bridge exists. Otherwise the net device of the
|
|
|
|
|
* bridge.
|
2019-05-07 12:08:26 +08:00
|
|
|
|
*/
|
2019-06-12 04:58:40 +08:00
|
|
|
|
static struct net_device *batadv_mcast_get_bridge(struct net_device *soft_iface)
|
2019-05-07 12:08:26 +08:00
|
|
|
|
{
|
2019-06-12 04:58:40 +08:00
|
|
|
|
struct net_device *upper = soft_iface;
|
2019-05-07 12:08:26 +08:00
|
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
|
do {
|
|
|
|
|
upper = netdev_master_upper_dev_get_rcu(upper);
|
2021-10-16 19:21:36 +08:00
|
|
|
|
} while (upper && !netif_is_bridge_master(upper));
|
2019-06-12 04:58:40 +08:00
|
|
|
|
|
2021-08-05 19:55:27 +08:00
|
|
|
|
dev_hold(upper);
|
2019-05-07 12:08:26 +08:00
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
|
|
return upper;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-12 04:58:40 +08:00
|
|
|
|
/**
|
|
|
|
|
* batadv_mcast_mla_rtr_flags_softif_get_ipv4() - get mcast router flags from
|
|
|
|
|
* node for IPv4
|
|
|
|
|
* @dev: the interface to check
|
|
|
|
|
*
|
|
|
|
|
* Checks the presence of an IPv4 multicast router on this node.
|
|
|
|
|
*
|
|
|
|
|
* Caller needs to hold rcu read lock.
|
|
|
|
|
*
|
|
|
|
|
* Return: BATADV_NO_FLAGS if present, BATADV_MCAST_WANT_NO_RTR4 otherwise.
|
|
|
|
|
*/
|
|
|
|
|
static u8 batadv_mcast_mla_rtr_flags_softif_get_ipv4(struct net_device *dev)
|
|
|
|
|
{
|
|
|
|
|
struct in_device *in_dev = __in_dev_get_rcu(dev);
|
|
|
|
|
|
|
|
|
|
if (in_dev && IN_DEV_MFORWARD(in_dev))
|
|
|
|
|
return BATADV_NO_FLAGS;
|
|
|
|
|
else
|
|
|
|
|
return BATADV_MCAST_WANT_NO_RTR4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* batadv_mcast_mla_rtr_flags_softif_get_ipv6() - get mcast router flags from
|
|
|
|
|
* node for IPv6
|
|
|
|
|
* @dev: the interface to check
|
|
|
|
|
*
|
|
|
|
|
* Checks the presence of an IPv6 multicast router on this node.
|
|
|
|
|
*
|
|
|
|
|
* Caller needs to hold rcu read lock.
|
|
|
|
|
*
|
|
|
|
|
* Return: BATADV_NO_FLAGS if present, BATADV_MCAST_WANT_NO_RTR6 otherwise.
|
|
|
|
|
*/
|
|
|
|
|
#if IS_ENABLED(CONFIG_IPV6_MROUTE)
|
|
|
|
|
static u8 batadv_mcast_mla_rtr_flags_softif_get_ipv6(struct net_device *dev)
|
|
|
|
|
{
|
|
|
|
|
struct inet6_dev *in6_dev = __in6_dev_get(dev);
|
|
|
|
|
|
2022-02-05 04:15:45 +08:00
|
|
|
|
if (in6_dev && atomic_read(&in6_dev->cnf.mc_forwarding))
|
2019-06-12 04:58:40 +08:00
|
|
|
|
return BATADV_NO_FLAGS;
|
|
|
|
|
else
|
|
|
|
|
return BATADV_MCAST_WANT_NO_RTR6;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
static inline u8
|
|
|
|
|
batadv_mcast_mla_rtr_flags_softif_get_ipv6(struct net_device *dev)
|
|
|
|
|
{
|
|
|
|
|
return BATADV_MCAST_WANT_NO_RTR6;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* batadv_mcast_mla_rtr_flags_softif_get() - get mcast router flags from node
|
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
* @bridge: bridge interface on top of the soft_iface if present,
|
|
|
|
|
* otherwise pass NULL
|
|
|
|
|
*
|
|
|
|
|
* Checks the presence of IPv4 and IPv6 multicast routers on this
|
|
|
|
|
* node.
|
|
|
|
|
*
|
|
|
|
|
* Return:
|
|
|
|
|
* BATADV_NO_FLAGS: Both an IPv4 and IPv6 multicast router is present
|
|
|
|
|
* BATADV_MCAST_WANT_NO_RTR4: No IPv4 multicast router is present
|
|
|
|
|
* BATADV_MCAST_WANT_NO_RTR6: No IPv6 multicast router is present
|
|
|
|
|
* The former two OR'd: no multicast router is present
|
|
|
|
|
*/
|
|
|
|
|
static u8 batadv_mcast_mla_rtr_flags_softif_get(struct batadv_priv *bat_priv,
|
|
|
|
|
struct net_device *bridge)
|
|
|
|
|
{
|
|
|
|
|
struct net_device *dev = bridge ? bridge : bat_priv->soft_iface;
|
|
|
|
|
u8 flags = BATADV_NO_FLAGS;
|
|
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
|
|
|
|
|
|
flags |= batadv_mcast_mla_rtr_flags_softif_get_ipv4(dev);
|
|
|
|
|
flags |= batadv_mcast_mla_rtr_flags_softif_get_ipv6(dev);
|
|
|
|
|
|
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* batadv_mcast_mla_rtr_flags_bridge_get() - get mcast router flags from bridge
|
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
* @bridge: bridge interface on top of the soft_iface if present,
|
|
|
|
|
* otherwise pass NULL
|
|
|
|
|
*
|
|
|
|
|
* Checks the presence of IPv4 and IPv6 multicast routers behind a bridge.
|
|
|
|
|
*
|
|
|
|
|
* Return:
|
|
|
|
|
* BATADV_NO_FLAGS: Both an IPv4 and IPv6 multicast router is present
|
|
|
|
|
* BATADV_MCAST_WANT_NO_RTR4: No IPv4 multicast router is present
|
|
|
|
|
* BATADV_MCAST_WANT_NO_RTR6: No IPv6 multicast router is present
|
|
|
|
|
* The former two OR'd: no multicast router is present
|
|
|
|
|
*/
|
|
|
|
|
static u8 batadv_mcast_mla_rtr_flags_bridge_get(struct batadv_priv *bat_priv,
|
|
|
|
|
struct net_device *bridge)
|
|
|
|
|
{
|
|
|
|
|
struct net_device *dev = bat_priv->soft_iface;
|
2021-05-15 23:22:08 +08:00
|
|
|
|
u8 flags = BATADV_NO_FLAGS;
|
2019-06-12 04:58:40 +08:00
|
|
|
|
|
|
|
|
|
if (!bridge)
|
|
|
|
|
return BATADV_MCAST_WANT_NO_RTR4 | BATADV_MCAST_WANT_NO_RTR6;
|
|
|
|
|
|
2021-05-15 23:22:08 +08:00
|
|
|
|
if (!br_multicast_has_router_adjacent(dev, ETH_P_IP))
|
|
|
|
|
flags |= BATADV_MCAST_WANT_NO_RTR4;
|
|
|
|
|
if (!br_multicast_has_router_adjacent(dev, ETH_P_IPV6))
|
|
|
|
|
flags |= BATADV_MCAST_WANT_NO_RTR6;
|
2019-06-12 04:58:40 +08:00
|
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* batadv_mcast_mla_rtr_flags_get() - get multicast router flags
|
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
* @bridge: bridge interface on top of the soft_iface if present,
|
|
|
|
|
* otherwise pass NULL
|
|
|
|
|
*
|
|
|
|
|
* Checks the presence of IPv4 and IPv6 multicast routers on this
|
|
|
|
|
* node or behind its bridge.
|
|
|
|
|
*
|
|
|
|
|
* Return:
|
|
|
|
|
* BATADV_NO_FLAGS: Both an IPv4 and IPv6 multicast router is present
|
|
|
|
|
* BATADV_MCAST_WANT_NO_RTR4: No IPv4 multicast router is present
|
|
|
|
|
* BATADV_MCAST_WANT_NO_RTR6: No IPv6 multicast router is present
|
|
|
|
|
* The former two OR'd: no multicast router is present
|
|
|
|
|
*/
|
|
|
|
|
static u8 batadv_mcast_mla_rtr_flags_get(struct batadv_priv *bat_priv,
|
|
|
|
|
struct net_device *bridge)
|
|
|
|
|
{
|
|
|
|
|
u8 flags = BATADV_MCAST_WANT_NO_RTR4 | BATADV_MCAST_WANT_NO_RTR6;
|
|
|
|
|
|
|
|
|
|
flags &= batadv_mcast_mla_rtr_flags_softif_get(bat_priv, bridge);
|
|
|
|
|
flags &= batadv_mcast_mla_rtr_flags_bridge_get(bat_priv, bridge);
|
|
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-07 09:09:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* batadv_mcast_mla_forw_flags_get() - get multicast forwarding flags
|
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
*
|
|
|
|
|
* Checks if all active hard interfaces have an MTU larger or equal to 1280
|
|
|
|
|
* bytes (IPv6 minimum MTU).
|
|
|
|
|
*
|
|
|
|
|
* Return: BATADV_MCAST_HAVE_MC_PTYPE_CAPA if yes, BATADV_NO_FLAGS otherwise.
|
|
|
|
|
*/
|
|
|
|
|
static u8 batadv_mcast_mla_forw_flags_get(struct batadv_priv *bat_priv)
|
|
|
|
|
{
|
|
|
|
|
const struct batadv_hard_iface *hard_iface;
|
|
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
|
list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
|
|
|
|
|
if (hard_iface->if_status != BATADV_IF_ACTIVE)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (hard_iface->soft_iface != bat_priv->soft_iface)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (hard_iface->net_dev->mtu < IPV6_MIN_MTU) {
|
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
return BATADV_NO_FLAGS;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
|
|
return BATADV_MCAST_HAVE_MC_PTYPE_CAPA;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-07 12:08:26 +08:00
|
|
|
|
/**
|
|
|
|
|
* batadv_mcast_mla_flags_get() - get the new multicast flags
|
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
*
|
|
|
|
|
* Return: A set of flags for the current/next TVLV, querier and
|
|
|
|
|
* bridge state.
|
|
|
|
|
*/
|
|
|
|
|
static struct batadv_mcast_mla_flags
|
|
|
|
|
batadv_mcast_mla_flags_get(struct batadv_priv *bat_priv)
|
|
|
|
|
{
|
|
|
|
|
struct net_device *dev = bat_priv->soft_iface;
|
|
|
|
|
struct batadv_mcast_querier_state *qr4, *qr6;
|
|
|
|
|
struct batadv_mcast_mla_flags mla_flags;
|
2019-06-12 04:58:40 +08:00
|
|
|
|
struct net_device *bridge;
|
|
|
|
|
|
|
|
|
|
bridge = batadv_mcast_get_bridge(dev);
|
2019-05-07 12:08:26 +08:00
|
|
|
|
|
|
|
|
|
memset(&mla_flags, 0, sizeof(mla_flags));
|
|
|
|
|
mla_flags.enabled = 1;
|
2019-06-12 04:58:40 +08:00
|
|
|
|
mla_flags.tvlv_flags |= batadv_mcast_mla_rtr_flags_get(bat_priv,
|
|
|
|
|
bridge);
|
2023-09-07 09:09:08 +08:00
|
|
|
|
mla_flags.tvlv_flags |= batadv_mcast_mla_forw_flags_get(bat_priv);
|
2019-05-07 12:08:26 +08:00
|
|
|
|
|
2019-06-12 04:58:40 +08:00
|
|
|
|
if (!bridge)
|
2019-05-07 12:08:26 +08:00
|
|
|
|
return mla_flags;
|
|
|
|
|
|
2019-06-12 04:58:40 +08:00
|
|
|
|
dev_put(bridge);
|
|
|
|
|
|
2019-05-07 12:08:26 +08:00
|
|
|
|
mla_flags.bridged = 1;
|
|
|
|
|
qr4 = &mla_flags.querier_ipv4;
|
|
|
|
|
qr6 = &mla_flags.querier_ipv6;
|
|
|
|
|
|
|
|
|
|
if (!IS_ENABLED(CONFIG_BRIDGE_IGMP_SNOOPING))
|
|
|
|
|
pr_warn_once("No bridge IGMP snooping compiled - multicast optimizations disabled\n");
|
|
|
|
|
|
|
|
|
|
qr4->exists = br_multicast_has_querier_anywhere(dev, ETH_P_IP);
|
|
|
|
|
qr4->shadowing = br_multicast_has_querier_adjacent(dev, ETH_P_IP);
|
|
|
|
|
|
|
|
|
|
qr6->exists = br_multicast_has_querier_anywhere(dev, ETH_P_IPV6);
|
|
|
|
|
qr6->shadowing = br_multicast_has_querier_adjacent(dev, ETH_P_IPV6);
|
|
|
|
|
|
|
|
|
|
mla_flags.tvlv_flags |= BATADV_MCAST_WANT_ALL_UNSNOOPABLES;
|
|
|
|
|
|
|
|
|
|
/* 1) If no querier exists at all, then multicast listeners on
|
|
|
|
|
* our local TT clients behind the bridge will keep silent.
|
|
|
|
|
* 2) If the selected querier is on one of our local TT clients,
|
|
|
|
|
* behind the bridge, then this querier might shadow multicast
|
|
|
|
|
* listeners on our local TT clients, behind this bridge.
|
|
|
|
|
*
|
|
|
|
|
* In both cases, we will signalize other batman nodes that
|
|
|
|
|
* we need all multicast traffic of the according protocol.
|
|
|
|
|
*/
|
2019-06-12 04:58:40 +08:00
|
|
|
|
if (!qr4->exists || qr4->shadowing) {
|
2019-05-07 12:08:26 +08:00
|
|
|
|
mla_flags.tvlv_flags |= BATADV_MCAST_WANT_ALL_IPV4;
|
2019-06-12 04:58:40 +08:00
|
|
|
|
mla_flags.tvlv_flags &= ~BATADV_MCAST_WANT_NO_RTR4;
|
|
|
|
|
}
|
2019-05-07 12:08:26 +08:00
|
|
|
|
|
2019-06-12 04:58:40 +08:00
|
|
|
|
if (!qr6->exists || qr6->shadowing) {
|
2019-05-07 12:08:26 +08:00
|
|
|
|
mla_flags.tvlv_flags |= BATADV_MCAST_WANT_ALL_IPV6;
|
2019-06-12 04:58:40 +08:00
|
|
|
|
mla_flags.tvlv_flags &= ~BATADV_MCAST_WANT_NO_RTR6;
|
|
|
|
|
}
|
2019-05-07 12:08:26 +08:00
|
|
|
|
|
|
|
|
|
return mla_flags;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-05 04:02:18 +08:00
|
|
|
|
/**
|
2019-05-27 00:35:49 +08:00
|
|
|
|
* batadv_mcast_mla_is_duplicate() - check whether an address is in a list
|
|
|
|
|
* @mcast_addr: the multicast address to check
|
|
|
|
|
* @mcast_list: the list with multicast addresses to search in
|
2018-03-05 04:02:18 +08:00
|
|
|
|
*
|
2019-05-27 00:35:49 +08:00
|
|
|
|
* Return: true if the given address is already in the given list.
|
|
|
|
|
* Otherwise returns false.
|
2018-03-05 04:02:18 +08:00
|
|
|
|
*/
|
2019-05-27 00:35:49 +08:00
|
|
|
|
static bool batadv_mcast_mla_is_duplicate(u8 *mcast_addr,
|
|
|
|
|
struct hlist_head *mcast_list)
|
2018-03-05 04:02:18 +08:00
|
|
|
|
{
|
2019-05-27 00:35:49 +08:00
|
|
|
|
struct batadv_hw_addr *mcast_entry;
|
2018-03-05 04:02:18 +08:00
|
|
|
|
|
2019-05-27 00:35:49 +08:00
|
|
|
|
hlist_for_each_entry(mcast_entry, mcast_list, list)
|
|
|
|
|
if (batadv_compare_eth(mcast_entry->addr, mcast_addr))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
2018-03-05 04:02:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-05-27 00:35:49 +08:00
|
|
|
|
* batadv_mcast_mla_softif_get_ipv4() - get softif IPv4 multicast listeners
|
|
|
|
|
* @dev: the device to collect multicast addresses from
|
|
|
|
|
* @mcast_list: a list to put found addresses into
|
|
|
|
|
* @flags: flags indicating the new multicast state
|
2018-03-05 04:02:18 +08:00
|
|
|
|
*
|
2019-05-27 00:35:49 +08:00
|
|
|
|
* Collects multicast addresses of IPv4 multicast listeners residing
|
|
|
|
|
* on this kernel on the given soft interface, dev, in
|
|
|
|
|
* the given mcast_list. In general, multicast listeners provided by
|
|
|
|
|
* your multicast receiving applications run directly on this node.
|
|
|
|
|
*
|
|
|
|
|
* Return: -ENOMEM on memory allocation error or the number of
|
|
|
|
|
* items added to the mcast_list otherwise.
|
2018-03-05 04:02:18 +08:00
|
|
|
|
*/
|
2019-05-27 00:35:49 +08:00
|
|
|
|
static int
|
|
|
|
|
batadv_mcast_mla_softif_get_ipv4(struct net_device *dev,
|
|
|
|
|
struct hlist_head *mcast_list,
|
|
|
|
|
struct batadv_mcast_mla_flags *flags)
|
2018-03-05 04:02:18 +08:00
|
|
|
|
{
|
2019-05-27 00:35:49 +08:00
|
|
|
|
struct batadv_hw_addr *new;
|
|
|
|
|
struct in_device *in_dev;
|
|
|
|
|
u8 mcast_addr[ETH_ALEN];
|
|
|
|
|
struct ip_mc_list *pmc;
|
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
|
|
if (flags->tvlv_flags & BATADV_MCAST_WANT_ALL_IPV4)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
rcu_read_lock();
|
2018-03-05 04:02:18 +08:00
|
|
|
|
|
2019-05-27 00:35:49 +08:00
|
|
|
|
in_dev = __in_dev_get_rcu(dev);
|
|
|
|
|
if (!in_dev) {
|
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (pmc = rcu_dereference(in_dev->mc_list); pmc;
|
|
|
|
|
pmc = rcu_dereference(pmc->next_rcu)) {
|
2019-05-27 00:35:50 +08:00
|
|
|
|
if (flags->tvlv_flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES &&
|
|
|
|
|
ipv4_is_local_multicast(pmc->multiaddr))
|
|
|
|
|
continue;
|
|
|
|
|
|
2019-06-12 04:58:40 +08:00
|
|
|
|
if (!(flags->tvlv_flags & BATADV_MCAST_WANT_NO_RTR4) &&
|
|
|
|
|
!ipv4_is_local_multicast(pmc->multiaddr))
|
|
|
|
|
continue;
|
|
|
|
|
|
2019-05-27 00:35:49 +08:00
|
|
|
|
ip_eth_mc_map(pmc->multiaddr, mcast_addr);
|
|
|
|
|
|
|
|
|
|
if (batadv_mcast_mla_is_duplicate(mcast_addr, mcast_list))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
new = kmalloc(sizeof(*new), GFP_ATOMIC);
|
|
|
|
|
if (!new) {
|
|
|
|
|
ret = -ENOMEM;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ether_addr_copy(new->addr, mcast_addr);
|
|
|
|
|
hlist_add_head(&new->list, mcast_list);
|
|
|
|
|
ret++;
|
|
|
|
|
}
|
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
|
|
return ret;
|
2018-03-05 04:02:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-16 00:47:49 +08:00
|
|
|
|
/**
|
2019-05-27 00:35:49 +08:00
|
|
|
|
* batadv_mcast_mla_softif_get_ipv6() - get softif IPv6 multicast listeners
|
2014-02-16 00:47:49 +08:00
|
|
|
|
* @dev: the device to collect multicast addresses from
|
|
|
|
|
* @mcast_list: a list to put found addresses into
|
2019-05-07 12:08:26 +08:00
|
|
|
|
* @flags: flags indicating the new multicast state
|
2014-02-16 00:47:49 +08:00
|
|
|
|
*
|
2019-05-27 00:35:49 +08:00
|
|
|
|
* Collects multicast addresses of IPv6 multicast listeners residing
|
2016-05-11 00:41:25 +08:00
|
|
|
|
* on this kernel on the given soft interface, dev, in
|
|
|
|
|
* the given mcast_list. In general, multicast listeners provided by
|
|
|
|
|
* your multicast receiving applications run directly on this node.
|
|
|
|
|
*
|
2015-09-16 01:00:48 +08:00
|
|
|
|
* Return: -ENOMEM on memory allocation error or the number of
|
2014-02-16 00:47:49 +08:00
|
|
|
|
* items added to the mcast_list otherwise.
|
|
|
|
|
*/
|
2019-05-27 00:35:49 +08:00
|
|
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
2019-05-07 12:08:26 +08:00
|
|
|
|
static int
|
2019-05-27 00:35:49 +08:00
|
|
|
|
batadv_mcast_mla_softif_get_ipv6(struct net_device *dev,
|
|
|
|
|
struct hlist_head *mcast_list,
|
|
|
|
|
struct batadv_mcast_mla_flags *flags)
|
2014-02-16 00:47:49 +08:00
|
|
|
|
{
|
|
|
|
|
struct batadv_hw_addr *new;
|
2019-05-27 00:35:49 +08:00
|
|
|
|
struct inet6_dev *in6_dev;
|
|
|
|
|
u8 mcast_addr[ETH_ALEN];
|
|
|
|
|
struct ifmcaddr6 *pmc6;
|
2014-02-16 00:47:49 +08:00
|
|
|
|
int ret = 0;
|
|
|
|
|
|
2019-05-27 00:35:49 +08:00
|
|
|
|
if (flags->tvlv_flags & BATADV_MCAST_WANT_ALL_IPV6)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
|
|
|
|
|
|
in6_dev = __in6_dev_get(dev);
|
|
|
|
|
if (!in6_dev) {
|
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-26 00:16:55 +08:00
|
|
|
|
for (pmc6 = rcu_dereference(in6_dev->mc_list);
|
|
|
|
|
pmc6;
|
|
|
|
|
pmc6 = rcu_dereference(pmc6->next)) {
|
2019-05-27 00:35:49 +08:00
|
|
|
|
if (IPV6_ADDR_MC_SCOPE(&pmc6->mca_addr) <
|
|
|
|
|
IPV6_ADDR_SCOPE_LINKLOCAL)
|
2018-03-05 04:02:18 +08:00
|
|
|
|
continue;
|
|
|
|
|
|
2019-05-27 00:35:50 +08:00
|
|
|
|
if (flags->tvlv_flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES &&
|
|
|
|
|
ipv6_addr_is_ll_all_nodes(&pmc6->mca_addr))
|
|
|
|
|
continue;
|
|
|
|
|
|
2019-06-12 04:58:40 +08:00
|
|
|
|
if (!(flags->tvlv_flags & BATADV_MCAST_WANT_NO_RTR6) &&
|
|
|
|
|
IPV6_ADDR_MC_SCOPE(&pmc6->mca_addr) >
|
|
|
|
|
IPV6_ADDR_SCOPE_LINKLOCAL)
|
|
|
|
|
continue;
|
|
|
|
|
|
2019-05-27 00:35:49 +08:00
|
|
|
|
ipv6_eth_mc_map(&pmc6->mca_addr, mcast_addr);
|
|
|
|
|
|
|
|
|
|
if (batadv_mcast_mla_is_duplicate(mcast_addr, mcast_list))
|
2018-03-05 04:02:18 +08:00
|
|
|
|
continue;
|
|
|
|
|
|
2014-02-16 00:47:49 +08:00
|
|
|
|
new = kmalloc(sizeof(*new), GFP_ATOMIC);
|
|
|
|
|
if (!new) {
|
|
|
|
|
ret = -ENOMEM;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-27 00:35:49 +08:00
|
|
|
|
ether_addr_copy(new->addr, mcast_addr);
|
2014-02-16 00:47:49 +08:00
|
|
|
|
hlist_add_head(&new->list, mcast_list);
|
|
|
|
|
ret++;
|
|
|
|
|
}
|
2019-05-27 00:35:49 +08:00
|
|
|
|
rcu_read_unlock();
|
2014-02-16 00:47:49 +08:00
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2019-05-27 00:35:49 +08:00
|
|
|
|
#else
|
|
|
|
|
static inline int
|
|
|
|
|
batadv_mcast_mla_softif_get_ipv6(struct net_device *dev,
|
|
|
|
|
struct hlist_head *mcast_list,
|
|
|
|
|
struct batadv_mcast_mla_flags *flags)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2014-02-16 00:47:49 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-05-27 00:35:49 +08:00
|
|
|
|
* batadv_mcast_mla_softif_get() - get softif multicast listeners
|
|
|
|
|
* @dev: the device to collect multicast addresses from
|
|
|
|
|
* @mcast_list: a list to put found addresses into
|
|
|
|
|
* @flags: flags indicating the new multicast state
|
2014-02-16 00:47:49 +08:00
|
|
|
|
*
|
2019-05-27 00:35:49 +08:00
|
|
|
|
* Collects multicast addresses of multicast listeners residing
|
|
|
|
|
* on this kernel on the given soft interface, dev, in
|
|
|
|
|
* the given mcast_list. In general, multicast listeners provided by
|
|
|
|
|
* your multicast receiving applications run directly on this node.
|
|
|
|
|
*
|
2020-06-02 02:13:21 +08:00
|
|
|
|
* If there is a bridge interface on top of dev, collect from that one
|
2019-05-27 00:35:49 +08:00
|
|
|
|
* instead. Just like with IP addresses and routes, multicast listeners
|
|
|
|
|
* will(/should) register to the bridge interface instead of an
|
|
|
|
|
* enslaved bat0.
|
|
|
|
|
*
|
|
|
|
|
* Return: -ENOMEM on memory allocation error or the number of
|
|
|
|
|
* items added to the mcast_list otherwise.
|
2014-02-16 00:47:49 +08:00
|
|
|
|
*/
|
2019-05-27 00:35:49 +08:00
|
|
|
|
static int
|
|
|
|
|
batadv_mcast_mla_softif_get(struct net_device *dev,
|
|
|
|
|
struct hlist_head *mcast_list,
|
|
|
|
|
struct batadv_mcast_mla_flags *flags)
|
2014-02-16 00:47:49 +08:00
|
|
|
|
{
|
2019-05-27 00:35:49 +08:00
|
|
|
|
struct net_device *bridge = batadv_mcast_get_bridge(dev);
|
|
|
|
|
int ret4, ret6 = 0;
|
2014-02-16 00:47:49 +08:00
|
|
|
|
|
2019-05-27 00:35:49 +08:00
|
|
|
|
if (bridge)
|
|
|
|
|
dev = bridge;
|
2014-02-16 00:47:49 +08:00
|
|
|
|
|
2019-05-27 00:35:49 +08:00
|
|
|
|
ret4 = batadv_mcast_mla_softif_get_ipv4(dev, mcast_list, flags);
|
|
|
|
|
if (ret4 < 0)
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
ret6 = batadv_mcast_mla_softif_get_ipv6(dev, mcast_list, flags);
|
|
|
|
|
if (ret6 < 0) {
|
|
|
|
|
ret4 = 0;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
2021-08-05 19:55:27 +08:00
|
|
|
|
dev_put(bridge);
|
2019-05-27 00:35:49 +08:00
|
|
|
|
|
|
|
|
|
return ret4 + ret6;
|
2014-02-16 00:47:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-11 00:41:25 +08:00
|
|
|
|
/**
|
2017-12-03 02:51:47 +08:00
|
|
|
|
* batadv_mcast_mla_br_addr_cpy() - copy a bridge multicast address
|
2016-05-11 00:41:25 +08:00
|
|
|
|
* @dst: destination to write to - a multicast MAC address
|
|
|
|
|
* @src: source to read from - a multicast IP address
|
|
|
|
|
*
|
|
|
|
|
* Converts a given multicast IPv4/IPv6 address from a bridge
|
|
|
|
|
* to its matching multicast MAC address and copies it into the given
|
|
|
|
|
* destination buffer.
|
|
|
|
|
*
|
|
|
|
|
* Caller needs to make sure the destination buffer can hold
|
|
|
|
|
* at least ETH_ALEN bytes.
|
|
|
|
|
*/
|
|
|
|
|
static void batadv_mcast_mla_br_addr_cpy(char *dst, const struct br_ip *src)
|
|
|
|
|
{
|
|
|
|
|
if (src->proto == htons(ETH_P_IP))
|
2020-09-22 15:30:17 +08:00
|
|
|
|
ip_eth_mc_map(src->dst.ip4, dst);
|
2016-05-11 00:41:25 +08:00
|
|
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
|
|
|
|
else if (src->proto == htons(ETH_P_IPV6))
|
2020-09-22 15:30:17 +08:00
|
|
|
|
ipv6_eth_mc_map(&src->dst.ip6, dst);
|
2016-05-11 00:41:25 +08:00
|
|
|
|
#endif
|
|
|
|
|
else
|
|
|
|
|
eth_zero_addr(dst);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-12-03 02:51:47 +08:00
|
|
|
|
* batadv_mcast_mla_bridge_get() - get bridged-in multicast listeners
|
2016-05-11 00:41:25 +08:00
|
|
|
|
* @dev: a bridge slave whose bridge to collect multicast addresses from
|
|
|
|
|
* @mcast_list: a list to put found addresses into
|
2019-05-07 12:08:26 +08:00
|
|
|
|
* @flags: flags indicating the new multicast state
|
2016-05-11 00:41:25 +08:00
|
|
|
|
*
|
|
|
|
|
* Collects multicast addresses of multicast listeners residing
|
|
|
|
|
* on foreign, non-mesh devices which we gave access to our mesh via
|
|
|
|
|
* a bridge on top of the given soft interface, dev, in the given
|
|
|
|
|
* mcast_list.
|
|
|
|
|
*
|
|
|
|
|
* Return: -ENOMEM on memory allocation error or the number of
|
|
|
|
|
* items added to the mcast_list otherwise.
|
|
|
|
|
*/
|
2019-05-07 12:08:26 +08:00
|
|
|
|
static int batadv_mcast_mla_bridge_get(struct net_device *dev,
|
|
|
|
|
struct hlist_head *mcast_list,
|
|
|
|
|
struct batadv_mcast_mla_flags *flags)
|
2016-05-11 00:41:25 +08:00
|
|
|
|
{
|
|
|
|
|
struct list_head bridge_mcast_list = LIST_HEAD_INIT(bridge_mcast_list);
|
|
|
|
|
struct br_ip_list *br_ip_entry, *tmp;
|
2019-05-27 00:35:50 +08:00
|
|
|
|
u8 tvlv_flags = flags->tvlv_flags;
|
2016-05-11 00:41:25 +08:00
|
|
|
|
struct batadv_hw_addr *new;
|
|
|
|
|
u8 mcast_addr[ETH_ALEN];
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
/* we don't need to detect these devices/listeners, the IGMP/MLD
|
|
|
|
|
* snooping code of the Linux bridge already does that for us
|
|
|
|
|
*/
|
|
|
|
|
ret = br_multicast_list_adjacent(dev, &bridge_mcast_list);
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
list_for_each_entry(br_ip_entry, &bridge_mcast_list, list) {
|
2019-05-27 00:35:50 +08:00
|
|
|
|
if (br_ip_entry->addr.proto == htons(ETH_P_IP)) {
|
|
|
|
|
if (tvlv_flags & BATADV_MCAST_WANT_ALL_IPV4)
|
|
|
|
|
continue;
|
2018-03-05 04:02:18 +08:00
|
|
|
|
|
2019-05-27 00:35:50 +08:00
|
|
|
|
if (tvlv_flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES &&
|
2020-09-22 15:30:17 +08:00
|
|
|
|
ipv4_is_local_multicast(br_ip_entry->addr.dst.ip4))
|
2019-05-27 00:35:50 +08:00
|
|
|
|
continue;
|
2019-06-12 04:58:40 +08:00
|
|
|
|
|
|
|
|
|
if (!(tvlv_flags & BATADV_MCAST_WANT_NO_RTR4) &&
|
2020-09-22 15:30:17 +08:00
|
|
|
|
!ipv4_is_local_multicast(br_ip_entry->addr.dst.ip4))
|
2019-06-12 04:58:40 +08:00
|
|
|
|
continue;
|
2019-05-27 00:35:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
|
|
|
|
if (br_ip_entry->addr.proto == htons(ETH_P_IPV6)) {
|
|
|
|
|
if (tvlv_flags & BATADV_MCAST_WANT_ALL_IPV6)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (tvlv_flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES &&
|
2020-09-22 15:30:17 +08:00
|
|
|
|
ipv6_addr_is_ll_all_nodes(&br_ip_entry->addr.dst.ip6))
|
2019-05-27 00:35:50 +08:00
|
|
|
|
continue;
|
2019-06-12 04:58:40 +08:00
|
|
|
|
|
|
|
|
|
if (!(tvlv_flags & BATADV_MCAST_WANT_NO_RTR6) &&
|
2020-09-22 15:30:17 +08:00
|
|
|
|
IPV6_ADDR_MC_SCOPE(&br_ip_entry->addr.dst.ip6) >
|
2019-06-12 04:58:40 +08:00
|
|
|
|
IPV6_ADDR_SCOPE_LINKLOCAL)
|
|
|
|
|
continue;
|
2019-05-27 00:35:50 +08:00
|
|
|
|
}
|
|
|
|
|
#endif
|
2018-03-05 04:02:18 +08:00
|
|
|
|
|
2016-05-11 00:41:25 +08:00
|
|
|
|
batadv_mcast_mla_br_addr_cpy(mcast_addr, &br_ip_entry->addr);
|
|
|
|
|
if (batadv_mcast_mla_is_duplicate(mcast_addr, mcast_list))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
new = kmalloc(sizeof(*new), GFP_ATOMIC);
|
|
|
|
|
if (!new) {
|
|
|
|
|
ret = -ENOMEM;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ether_addr_copy(new->addr, mcast_addr);
|
|
|
|
|
hlist_add_head(&new->list, mcast_list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
list_for_each_entry_safe(br_ip_entry, tmp, &bridge_mcast_list, list) {
|
|
|
|
|
list_del(&br_ip_entry->list);
|
|
|
|
|
kfree(br_ip_entry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-16 00:47:49 +08:00
|
|
|
|
/**
|
2017-12-03 02:51:47 +08:00
|
|
|
|
* batadv_mcast_mla_list_free() - free a list of multicast addresses
|
2014-02-16 00:47:49 +08:00
|
|
|
|
* @mcast_list: the list to free
|
|
|
|
|
*
|
|
|
|
|
* Removes and frees all items in the given mcast_list.
|
|
|
|
|
*/
|
2016-08-07 04:23:15 +08:00
|
|
|
|
static void batadv_mcast_mla_list_free(struct hlist_head *mcast_list)
|
2014-02-16 00:47:49 +08:00
|
|
|
|
{
|
|
|
|
|
struct batadv_hw_addr *mcast_entry;
|
|
|
|
|
struct hlist_node *tmp;
|
|
|
|
|
|
|
|
|
|
hlist_for_each_entry_safe(mcast_entry, tmp, mcast_list, list) {
|
|
|
|
|
hlist_del(&mcast_entry->list);
|
|
|
|
|
kfree(mcast_entry);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-12-03 02:51:47 +08:00
|
|
|
|
* batadv_mcast_mla_tt_retract() - clean up multicast listener announcements
|
2014-02-16 00:47:49 +08:00
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
* @mcast_list: a list of addresses which should _not_ be removed
|
|
|
|
|
*
|
|
|
|
|
* Retracts the announcement of any multicast listener from the
|
|
|
|
|
* translation table except the ones listed in the given mcast_list.
|
|
|
|
|
*
|
|
|
|
|
* If mcast_list is NULL then all are retracted.
|
|
|
|
|
*/
|
|
|
|
|
static void batadv_mcast_mla_tt_retract(struct batadv_priv *bat_priv,
|
|
|
|
|
struct hlist_head *mcast_list)
|
|
|
|
|
{
|
|
|
|
|
struct batadv_hw_addr *mcast_entry;
|
|
|
|
|
struct hlist_node *tmp;
|
|
|
|
|
|
|
|
|
|
hlist_for_each_entry_safe(mcast_entry, tmp, &bat_priv->mcast.mla_list,
|
|
|
|
|
list) {
|
|
|
|
|
if (mcast_list &&
|
|
|
|
|
batadv_mcast_mla_is_duplicate(mcast_entry->addr,
|
|
|
|
|
mcast_list))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
batadv_tt_local_remove(bat_priv, mcast_entry->addr,
|
|
|
|
|
BATADV_NO_FLAGS,
|
|
|
|
|
"mcast TT outdated", false);
|
|
|
|
|
|
|
|
|
|
hlist_del(&mcast_entry->list);
|
|
|
|
|
kfree(mcast_entry);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-12-03 02:51:47 +08:00
|
|
|
|
* batadv_mcast_mla_tt_add() - add multicast listener announcements
|
2014-02-16 00:47:49 +08:00
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
* @mcast_list: a list of addresses which are going to get added
|
|
|
|
|
*
|
|
|
|
|
* Adds multicast listener announcements from the given mcast_list to the
|
|
|
|
|
* translation table if they have not been added yet.
|
|
|
|
|
*/
|
|
|
|
|
static void batadv_mcast_mla_tt_add(struct batadv_priv *bat_priv,
|
|
|
|
|
struct hlist_head *mcast_list)
|
|
|
|
|
{
|
|
|
|
|
struct batadv_hw_addr *mcast_entry;
|
|
|
|
|
struct hlist_node *tmp;
|
|
|
|
|
|
|
|
|
|
if (!mcast_list)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
hlist_for_each_entry_safe(mcast_entry, tmp, mcast_list, list) {
|
|
|
|
|
if (batadv_mcast_mla_is_duplicate(mcast_entry->addr,
|
|
|
|
|
&bat_priv->mcast.mla_list))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!batadv_tt_local_add(bat_priv->soft_iface,
|
|
|
|
|
mcast_entry->addr, BATADV_NO_FLAGS,
|
|
|
|
|
BATADV_NULL_IFINDEX, BATADV_NO_MARK))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
hlist_del(&mcast_entry->list);
|
|
|
|
|
hlist_add_head(&mcast_entry->list, &bat_priv->mcast.mla_list);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-11 00:41:26 +08:00
|
|
|
|
/**
|
2017-12-03 02:51:47 +08:00
|
|
|
|
* batadv_mcast_querier_log() - debug output regarding the querier status on
|
|
|
|
|
* link
|
2016-05-11 00:41:26 +08:00
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
* @str_proto: a string for the querier protocol (e.g. "IGMP" or "MLD")
|
|
|
|
|
* @old_state: the previous querier state on our link
|
|
|
|
|
* @new_state: the new querier state on our link
|
|
|
|
|
*
|
|
|
|
|
* Outputs debug messages to the logging facility with log level 'mcast'
|
|
|
|
|
* regarding changes to the querier status on the link which are relevant
|
|
|
|
|
* to our multicast optimizations.
|
|
|
|
|
*
|
|
|
|
|
* Usually this is about whether a querier appeared or vanished in
|
|
|
|
|
* our mesh or whether the querier is in the suboptimal position of being
|
|
|
|
|
* behind our local bridge segment: Snooping switches will directly
|
|
|
|
|
* forward listener reports to the querier, therefore batman-adv and
|
|
|
|
|
* the bridge will potentially not see these listeners - the querier is
|
|
|
|
|
* potentially shadowing listeners from us then.
|
|
|
|
|
*
|
|
|
|
|
* This is only interesting for nodes with a bridge on top of their
|
|
|
|
|
* soft interface.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
batadv_mcast_querier_log(struct batadv_priv *bat_priv, char *str_proto,
|
|
|
|
|
struct batadv_mcast_querier_state *old_state,
|
|
|
|
|
struct batadv_mcast_querier_state *new_state)
|
|
|
|
|
{
|
|
|
|
|
if (!old_state->exists && new_state->exists)
|
|
|
|
|
batadv_info(bat_priv->soft_iface, "%s Querier appeared\n",
|
|
|
|
|
str_proto);
|
|
|
|
|
else if (old_state->exists && !new_state->exists)
|
|
|
|
|
batadv_info(bat_priv->soft_iface,
|
|
|
|
|
"%s Querier disappeared - multicast optimizations disabled\n",
|
|
|
|
|
str_proto);
|
2019-05-07 12:08:26 +08:00
|
|
|
|
else if (!bat_priv->mcast.mla_flags.bridged && !new_state->exists)
|
2016-05-11 00:41:26 +08:00
|
|
|
|
batadv_info(bat_priv->soft_iface,
|
|
|
|
|
"No %s Querier present - multicast optimizations disabled\n",
|
|
|
|
|
str_proto);
|
|
|
|
|
|
|
|
|
|
if (new_state->exists) {
|
|
|
|
|
if ((!old_state->shadowing && new_state->shadowing) ||
|
|
|
|
|
(!old_state->exists && new_state->shadowing))
|
|
|
|
|
batadv_dbg(BATADV_DBG_MCAST, bat_priv,
|
|
|
|
|
"%s Querier is behind our bridged segment: Might shadow listeners\n",
|
|
|
|
|
str_proto);
|
|
|
|
|
else if (old_state->shadowing && !new_state->shadowing)
|
|
|
|
|
batadv_dbg(BATADV_DBG_MCAST, bat_priv,
|
|
|
|
|
"%s Querier is not behind our bridged segment\n",
|
|
|
|
|
str_proto);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-12-03 02:51:47 +08:00
|
|
|
|
* batadv_mcast_bridge_log() - debug output for topology changes in bridged
|
|
|
|
|
* setups
|
2016-05-11 00:41:26 +08:00
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
2019-05-07 12:08:26 +08:00
|
|
|
|
* @new_flags: flags indicating the new multicast state
|
2016-05-11 00:41:26 +08:00
|
|
|
|
*
|
|
|
|
|
* If no bridges are ever used on this node, then this function does nothing.
|
|
|
|
|
*
|
|
|
|
|
* Otherwise this function outputs debug information to the 'mcast' log level
|
|
|
|
|
* which might be relevant to our multicast optimizations.
|
|
|
|
|
*
|
|
|
|
|
* More precisely, it outputs information when a bridge interface is added or
|
|
|
|
|
* removed from a soft interface. And when a bridge is present, it further
|
|
|
|
|
* outputs information about the querier state which is relevant for the
|
|
|
|
|
* multicast flags this node is going to set.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2019-05-07 12:08:26 +08:00
|
|
|
|
batadv_mcast_bridge_log(struct batadv_priv *bat_priv,
|
|
|
|
|
struct batadv_mcast_mla_flags *new_flags)
|
2016-05-11 00:41:26 +08:00
|
|
|
|
{
|
2019-05-07 12:08:26 +08:00
|
|
|
|
struct batadv_mcast_mla_flags *old_flags = &bat_priv->mcast.mla_flags;
|
|
|
|
|
|
|
|
|
|
if (!old_flags->bridged && new_flags->bridged)
|
2016-05-11 00:41:26 +08:00
|
|
|
|
batadv_dbg(BATADV_DBG_MCAST, bat_priv,
|
|
|
|
|
"Bridge added: Setting Unsnoopables(U)-flag\n");
|
2019-05-07 12:08:26 +08:00
|
|
|
|
else if (old_flags->bridged && !new_flags->bridged)
|
2016-05-11 00:41:26 +08:00
|
|
|
|
batadv_dbg(BATADV_DBG_MCAST, bat_priv,
|
|
|
|
|
"Bridge removed: Unsetting Unsnoopables(U)-flag\n");
|
|
|
|
|
|
2019-05-07 12:08:26 +08:00
|
|
|
|
if (new_flags->bridged) {
|
2016-05-11 00:41:26 +08:00
|
|
|
|
batadv_mcast_querier_log(bat_priv, "IGMP",
|
2019-05-07 12:08:26 +08:00
|
|
|
|
&old_flags->querier_ipv4,
|
|
|
|
|
&new_flags->querier_ipv4);
|
2016-05-11 00:41:26 +08:00
|
|
|
|
batadv_mcast_querier_log(bat_priv, "MLD",
|
2019-05-07 12:08:26 +08:00
|
|
|
|
&old_flags->querier_ipv6,
|
|
|
|
|
&new_flags->querier_ipv6);
|
2016-05-11 00:41:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-01-21 03:50:35 +08:00
|
|
|
|
* batadv_mcast_flags_log() - output debug information about mcast flag changes
|
2016-05-11 00:41:26 +08:00
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
2019-05-07 12:08:26 +08:00
|
|
|
|
* @flags: TVLV flags indicating the new multicast state
|
2016-05-11 00:41:26 +08:00
|
|
|
|
*
|
2020-06-02 02:13:21 +08:00
|
|
|
|
* Whenever the multicast TVLV flags this node announces change, this function
|
|
|
|
|
* should be used to notify userspace about the change.
|
2016-05-11 00:41:26 +08:00
|
|
|
|
*/
|
|
|
|
|
static void batadv_mcast_flags_log(struct batadv_priv *bat_priv, u8 flags)
|
|
|
|
|
{
|
2019-05-07 12:08:26 +08:00
|
|
|
|
bool old_enabled = bat_priv->mcast.mla_flags.enabled;
|
|
|
|
|
u8 old_flags = bat_priv->mcast.mla_flags.tvlv_flags;
|
2023-09-07 09:09:08 +08:00
|
|
|
|
char str_old_flags[] = "[.... . .]";
|
2016-05-11 00:41:26 +08:00
|
|
|
|
|
2023-09-07 09:09:08 +08:00
|
|
|
|
sprintf(str_old_flags, "[%c%c%c%s%s%c]",
|
2016-05-11 00:41:26 +08:00
|
|
|
|
(old_flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES) ? 'U' : '.',
|
|
|
|
|
(old_flags & BATADV_MCAST_WANT_ALL_IPV4) ? '4' : '.',
|
2019-06-12 04:58:40 +08:00
|
|
|
|
(old_flags & BATADV_MCAST_WANT_ALL_IPV6) ? '6' : '.',
|
|
|
|
|
!(old_flags & BATADV_MCAST_WANT_NO_RTR4) ? "R4" : ". ",
|
2023-09-07 09:09:08 +08:00
|
|
|
|
!(old_flags & BATADV_MCAST_WANT_NO_RTR6) ? "R6" : ". ",
|
|
|
|
|
!(old_flags & BATADV_MCAST_HAVE_MC_PTYPE_CAPA) ? 'P' : '.');
|
2016-05-11 00:41:26 +08:00
|
|
|
|
|
|
|
|
|
batadv_dbg(BATADV_DBG_MCAST, bat_priv,
|
2023-09-07 09:09:08 +08:00
|
|
|
|
"Changing multicast flags from '%s' to '[%c%c%c%s%s%c]'\n",
|
2019-05-07 12:08:26 +08:00
|
|
|
|
old_enabled ? str_old_flags : "<undefined>",
|
2016-05-11 00:41:26 +08:00
|
|
|
|
(flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES) ? 'U' : '.',
|
|
|
|
|
(flags & BATADV_MCAST_WANT_ALL_IPV4) ? '4' : '.',
|
2019-06-12 04:58:40 +08:00
|
|
|
|
(flags & BATADV_MCAST_WANT_ALL_IPV6) ? '6' : '.',
|
|
|
|
|
!(flags & BATADV_MCAST_WANT_NO_RTR4) ? "R4" : ". ",
|
2023-09-07 09:09:08 +08:00
|
|
|
|
!(flags & BATADV_MCAST_WANT_NO_RTR6) ? "R6" : ". ",
|
|
|
|
|
!(flags & BATADV_MCAST_HAVE_MC_PTYPE_CAPA) ? 'P' : '.');
|
2016-05-11 00:41:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-16 00:47:51 +08:00
|
|
|
|
/**
|
2019-05-07 12:08:26 +08:00
|
|
|
|
* batadv_mcast_mla_flags_update() - update multicast flags
|
2014-02-16 00:47:51 +08:00
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
2019-05-07 12:08:26 +08:00
|
|
|
|
* @flags: flags indicating the new multicast state
|
2014-02-16 00:47:51 +08:00
|
|
|
|
*
|
|
|
|
|
* Updates the own multicast tvlv with our current multicast related settings,
|
|
|
|
|
* capabilities and inabilities.
|
|
|
|
|
*/
|
2019-05-07 12:08:26 +08:00
|
|
|
|
static void
|
|
|
|
|
batadv_mcast_mla_flags_update(struct batadv_priv *bat_priv,
|
|
|
|
|
struct batadv_mcast_mla_flags *flags)
|
2014-02-16 00:47:51 +08:00
|
|
|
|
{
|
|
|
|
|
struct batadv_tvlv_mcast_data mcast_data;
|
|
|
|
|
|
2019-05-07 12:08:26 +08:00
|
|
|
|
if (!memcmp(flags, &bat_priv->mcast.mla_flags, sizeof(*flags)))
|
|
|
|
|
return;
|
2016-05-11 00:41:26 +08:00
|
|
|
|
|
2019-05-07 12:08:26 +08:00
|
|
|
|
batadv_mcast_bridge_log(bat_priv, flags);
|
|
|
|
|
batadv_mcast_flags_log(bat_priv, flags->tvlv_flags);
|
2016-05-11 00:41:26 +08:00
|
|
|
|
|
2019-05-07 12:08:26 +08:00
|
|
|
|
mcast_data.flags = flags->tvlv_flags;
|
|
|
|
|
memset(mcast_data.reserved, 0, sizeof(mcast_data.reserved));
|
2016-05-11 00:41:26 +08:00
|
|
|
|
|
2019-05-07 12:08:26 +08:00
|
|
|
|
batadv_tvlv_container_register(bat_priv, BATADV_TVLV_MCAST, 2,
|
|
|
|
|
&mcast_data, sizeof(mcast_data));
|
2014-02-16 00:47:51 +08:00
|
|
|
|
|
2019-05-07 12:08:26 +08:00
|
|
|
|
bat_priv->mcast.mla_flags = *flags;
|
2014-02-16 00:47:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-16 00:47:49 +08:00
|
|
|
|
/**
|
2017-12-03 02:51:47 +08:00
|
|
|
|
* __batadv_mcast_mla_update() - update the own MLAs
|
2014-02-16 00:47:49 +08:00
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
*
|
2014-02-16 00:47:51 +08:00
|
|
|
|
* Updates the own multicast listener announcements in the translation
|
|
|
|
|
* table as well as the own, announced multicast tvlv container.
|
2016-08-07 04:23:16 +08:00
|
|
|
|
*
|
|
|
|
|
* Note that non-conflicting reads and writes to bat_priv->mcast.mla_list
|
|
|
|
|
* in batadv_mcast_mla_tt_retract() and batadv_mcast_mla_tt_add() are
|
|
|
|
|
* ensured by the non-parallel execution of the worker this function
|
|
|
|
|
* belongs to.
|
2014-02-16 00:47:49 +08:00
|
|
|
|
*/
|
2016-08-07 04:23:16 +08:00
|
|
|
|
static void __batadv_mcast_mla_update(struct batadv_priv *bat_priv)
|
2014-02-16 00:47:49 +08:00
|
|
|
|
{
|
|
|
|
|
struct net_device *soft_iface = bat_priv->soft_iface;
|
|
|
|
|
struct hlist_head mcast_list = HLIST_HEAD_INIT;
|
2019-05-07 12:08:26 +08:00
|
|
|
|
struct batadv_mcast_mla_flags flags;
|
2014-02-16 00:47:49 +08:00
|
|
|
|
int ret;
|
|
|
|
|
|
2019-05-07 12:08:26 +08:00
|
|
|
|
flags = batadv_mcast_mla_flags_get(bat_priv);
|
2014-02-16 00:47:49 +08:00
|
|
|
|
|
2019-05-07 12:08:26 +08:00
|
|
|
|
ret = batadv_mcast_mla_softif_get(soft_iface, &mcast_list, &flags);
|
2014-02-16 00:47:49 +08:00
|
|
|
|
if (ret < 0)
|
|
|
|
|
goto out;
|
|
|
|
|
|
2019-05-07 12:08:26 +08:00
|
|
|
|
ret = batadv_mcast_mla_bridge_get(soft_iface, &mcast_list, &flags);
|
2016-05-11 00:41:25 +08:00
|
|
|
|
if (ret < 0)
|
|
|
|
|
goto out;
|
|
|
|
|
|
2019-05-07 12:08:26 +08:00
|
|
|
|
spin_lock(&bat_priv->mcast.mla_lock);
|
2014-02-16 00:47:49 +08:00
|
|
|
|
batadv_mcast_mla_tt_retract(bat_priv, &mcast_list);
|
|
|
|
|
batadv_mcast_mla_tt_add(bat_priv, &mcast_list);
|
2019-05-07 12:08:26 +08:00
|
|
|
|
batadv_mcast_mla_flags_update(bat_priv, &flags);
|
|
|
|
|
spin_unlock(&bat_priv->mcast.mla_lock);
|
2014-02-16 00:47:49 +08:00
|
|
|
|
|
|
|
|
|
out:
|
2016-08-07 04:23:15 +08:00
|
|
|
|
batadv_mcast_mla_list_free(&mcast_list);
|
2014-02-16 00:47:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-07 04:23:16 +08:00
|
|
|
|
/**
|
2017-12-03 02:51:47 +08:00
|
|
|
|
* batadv_mcast_mla_update() - update the own MLAs
|
2016-08-07 04:23:16 +08:00
|
|
|
|
* @work: kernel work struct
|
|
|
|
|
*
|
|
|
|
|
* Updates the own multicast listener announcements in the translation
|
|
|
|
|
* table as well as the own, announced multicast tvlv container.
|
|
|
|
|
*
|
|
|
|
|
* In the end, reschedules the work timer.
|
|
|
|
|
*/
|
|
|
|
|
static void batadv_mcast_mla_update(struct work_struct *work)
|
|
|
|
|
{
|
|
|
|
|
struct delayed_work *delayed_work;
|
|
|
|
|
struct batadv_priv_mcast *priv_mcast;
|
|
|
|
|
struct batadv_priv *bat_priv;
|
|
|
|
|
|
|
|
|
|
delayed_work = to_delayed_work(work);
|
|
|
|
|
priv_mcast = container_of(delayed_work, struct batadv_priv_mcast, work);
|
|
|
|
|
bat_priv = container_of(priv_mcast, struct batadv_priv, mcast);
|
|
|
|
|
|
|
|
|
|
__batadv_mcast_mla_update(bat_priv);
|
|
|
|
|
batadv_mcast_start_timer(bat_priv);
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-11 00:41:24 +08:00
|
|
|
|
/**
|
2017-12-03 02:51:47 +08:00
|
|
|
|
* batadv_mcast_is_report_ipv4() - check for IGMP reports
|
2016-05-11 00:41:24 +08:00
|
|
|
|
* @skb: the ethernet frame destined for the mesh
|
|
|
|
|
*
|
|
|
|
|
* This call might reallocate skb data.
|
|
|
|
|
*
|
|
|
|
|
* Checks whether the given frame is a valid IGMP report.
|
|
|
|
|
*
|
|
|
|
|
* Return: If so then true, otherwise false.
|
|
|
|
|
*/
|
|
|
|
|
static bool batadv_mcast_is_report_ipv4(struct sk_buff *skb)
|
|
|
|
|
{
|
2019-01-21 14:26:25 +08:00
|
|
|
|
if (ip_mc_check_igmp(skb) < 0)
|
2016-05-11 00:41:24 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
switch (igmp_hdr(skb)->type) {
|
|
|
|
|
case IGMP_HOST_MEMBERSHIP_REPORT:
|
|
|
|
|
case IGMPV2_HOST_MEMBERSHIP_REPORT:
|
|
|
|
|
case IGMPV3_HOST_MEMBERSHIP_REPORT:
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-16 00:47:53 +08:00
|
|
|
|
/**
|
2017-12-03 02:51:47 +08:00
|
|
|
|
* batadv_mcast_forw_mode_check_ipv4() - check for optimized forwarding
|
|
|
|
|
* potential
|
2014-02-16 00:47:53 +08:00
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
* @skb: the IPv4 packet to check
|
|
|
|
|
* @is_unsnoopable: stores whether the destination is snoopable
|
2019-06-12 04:58:41 +08:00
|
|
|
|
* @is_routable: stores whether the destination is routable
|
2014-02-16 00:47:53 +08:00
|
|
|
|
*
|
|
|
|
|
* Checks whether the given IPv4 packet has the potential to be forwarded with a
|
|
|
|
|
* mode more optimal than classic flooding.
|
|
|
|
|
*
|
2015-09-16 01:00:48 +08:00
|
|
|
|
* Return: If so then 0. Otherwise -EINVAL or -ENOMEM in case of memory
|
|
|
|
|
* allocation failure.
|
2014-02-16 00:47:53 +08:00
|
|
|
|
*/
|
|
|
|
|
static int batadv_mcast_forw_mode_check_ipv4(struct batadv_priv *bat_priv,
|
|
|
|
|
struct sk_buff *skb,
|
2019-06-12 04:58:41 +08:00
|
|
|
|
bool *is_unsnoopable,
|
|
|
|
|
int *is_routable)
|
2014-02-16 00:47:53 +08:00
|
|
|
|
{
|
|
|
|
|
struct iphdr *iphdr;
|
|
|
|
|
|
|
|
|
|
/* We might fail due to out-of-memory -> drop it */
|
|
|
|
|
if (!pskb_may_pull(skb, sizeof(struct ethhdr) + sizeof(*iphdr)))
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
2016-05-11 00:41:24 +08:00
|
|
|
|
if (batadv_mcast_is_report_ipv4(skb))
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
2014-02-16 00:47:53 +08:00
|
|
|
|
iphdr = ip_hdr(skb);
|
|
|
|
|
|
|
|
|
|
/* link-local multicast listeners behind a bridge are
|
|
|
|
|
* not snoopable (see RFC4541, section 2.1.2.2)
|
|
|
|
|
*/
|
2019-06-12 04:58:41 +08:00
|
|
|
|
if (ipv4_is_local_multicast(iphdr->daddr))
|
|
|
|
|
*is_unsnoopable = true;
|
|
|
|
|
else
|
|
|
|
|
*is_routable = ETH_P_IP;
|
2014-02-16 00:47:53 +08:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-11 00:41:24 +08:00
|
|
|
|
/**
|
2017-12-03 02:51:47 +08:00
|
|
|
|
* batadv_mcast_is_report_ipv6() - check for MLD reports
|
2016-05-11 00:41:24 +08:00
|
|
|
|
* @skb: the ethernet frame destined for the mesh
|
|
|
|
|
*
|
|
|
|
|
* This call might reallocate skb data.
|
|
|
|
|
*
|
|
|
|
|
* Checks whether the given frame is a valid MLD report.
|
|
|
|
|
*
|
|
|
|
|
* Return: If so then true, otherwise false.
|
|
|
|
|
*/
|
|
|
|
|
static bool batadv_mcast_is_report_ipv6(struct sk_buff *skb)
|
|
|
|
|
{
|
2019-01-21 14:26:25 +08:00
|
|
|
|
if (ipv6_mc_check_mld(skb) < 0)
|
2016-05-11 00:41:24 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
switch (icmp6_hdr(skb)->icmp6_type) {
|
|
|
|
|
case ICMPV6_MGM_REPORT:
|
|
|
|
|
case ICMPV6_MLD2_REPORT:
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-16 00:47:52 +08:00
|
|
|
|
/**
|
2017-12-03 02:51:47 +08:00
|
|
|
|
* batadv_mcast_forw_mode_check_ipv6() - check for optimized forwarding
|
|
|
|
|
* potential
|
2014-02-16 00:47:52 +08:00
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
* @skb: the IPv6 packet to check
|
2014-02-16 00:47:53 +08:00
|
|
|
|
* @is_unsnoopable: stores whether the destination is snoopable
|
2019-06-12 04:58:41 +08:00
|
|
|
|
* @is_routable: stores whether the destination is routable
|
2014-02-16 00:47:52 +08:00
|
|
|
|
*
|
|
|
|
|
* Checks whether the given IPv6 packet has the potential to be forwarded with a
|
|
|
|
|
* mode more optimal than classic flooding.
|
|
|
|
|
*
|
2015-09-16 01:00:48 +08:00
|
|
|
|
* Return: If so then 0. Otherwise -EINVAL is or -ENOMEM if we are out of memory
|
2014-02-16 00:47:52 +08:00
|
|
|
|
*/
|
|
|
|
|
static int batadv_mcast_forw_mode_check_ipv6(struct batadv_priv *bat_priv,
|
2014-02-16 00:47:53 +08:00
|
|
|
|
struct sk_buff *skb,
|
2019-06-12 04:58:41 +08:00
|
|
|
|
bool *is_unsnoopable,
|
|
|
|
|
int *is_routable)
|
2014-02-16 00:47:52 +08:00
|
|
|
|
{
|
|
|
|
|
struct ipv6hdr *ip6hdr;
|
|
|
|
|
|
|
|
|
|
/* We might fail due to out-of-memory -> drop it */
|
|
|
|
|
if (!pskb_may_pull(skb, sizeof(struct ethhdr) + sizeof(*ip6hdr)))
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
2016-05-11 00:41:24 +08:00
|
|
|
|
if (batadv_mcast_is_report_ipv6(skb))
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
2014-02-16 00:47:52 +08:00
|
|
|
|
ip6hdr = ipv6_hdr(skb);
|
|
|
|
|
|
2019-06-12 04:58:41 +08:00
|
|
|
|
if (IPV6_ADDR_MC_SCOPE(&ip6hdr->daddr) < IPV6_ADDR_SCOPE_LINKLOCAL)
|
2014-02-16 00:47:52 +08:00
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
|
|
/* link-local-all-nodes multicast listeners behind a bridge are
|
|
|
|
|
* not snoopable (see RFC4541, section 3, paragraph 3)
|
|
|
|
|
*/
|
|
|
|
|
if (ipv6_addr_is_ll_all_nodes(&ip6hdr->daddr))
|
2014-02-16 00:47:53 +08:00
|
|
|
|
*is_unsnoopable = true;
|
2019-06-12 04:58:41 +08:00
|
|
|
|
else if (IPV6_ADDR_MC_SCOPE(&ip6hdr->daddr) > IPV6_ADDR_SCOPE_LINKLOCAL)
|
|
|
|
|
*is_routable = ETH_P_IPV6;
|
2014-02-16 00:47:52 +08:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-12-03 02:51:47 +08:00
|
|
|
|
* batadv_mcast_forw_mode_check() - check for optimized forwarding potential
|
2014-02-16 00:47:52 +08:00
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
* @skb: the multicast frame to check
|
2014-02-16 00:47:53 +08:00
|
|
|
|
* @is_unsnoopable: stores whether the destination is snoopable
|
2019-06-12 04:58:41 +08:00
|
|
|
|
* @is_routable: stores whether the destination is routable
|
2014-02-16 00:47:52 +08:00
|
|
|
|
*
|
|
|
|
|
* Checks whether the given multicast ethernet frame has the potential to be
|
|
|
|
|
* forwarded with a mode more optimal than classic flooding.
|
|
|
|
|
*
|
2015-09-16 01:00:48 +08:00
|
|
|
|
* Return: If so then 0. Otherwise -EINVAL is or -ENOMEM if we are out of memory
|
2014-02-16 00:47:52 +08:00
|
|
|
|
*/
|
|
|
|
|
static int batadv_mcast_forw_mode_check(struct batadv_priv *bat_priv,
|
2014-02-16 00:47:53 +08:00
|
|
|
|
struct sk_buff *skb,
|
2019-06-12 04:58:41 +08:00
|
|
|
|
bool *is_unsnoopable,
|
|
|
|
|
int *is_routable)
|
2014-02-16 00:47:52 +08:00
|
|
|
|
{
|
|
|
|
|
struct ethhdr *ethhdr = eth_hdr(skb);
|
|
|
|
|
|
|
|
|
|
if (!atomic_read(&bat_priv->multicast_mode))
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
|
|
switch (ntohs(ethhdr->h_proto)) {
|
2014-02-16 00:47:53 +08:00
|
|
|
|
case ETH_P_IP:
|
|
|
|
|
return batadv_mcast_forw_mode_check_ipv4(bat_priv, skb,
|
2019-06-12 04:58:41 +08:00
|
|
|
|
is_unsnoopable,
|
|
|
|
|
is_routable);
|
2014-02-16 00:47:52 +08:00
|
|
|
|
case ETH_P_IPV6:
|
2017-02-23 00:16:39 +08:00
|
|
|
|
if (!IS_ENABLED(CONFIG_IPV6))
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
2014-02-16 00:47:53 +08:00
|
|
|
|
return batadv_mcast_forw_mode_check_ipv6(bat_priv, skb,
|
2019-06-12 04:58:41 +08:00
|
|
|
|
is_unsnoopable,
|
|
|
|
|
is_routable);
|
2014-02-16 00:47:52 +08:00
|
|
|
|
default:
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-16 00:47:54 +08:00
|
|
|
|
/**
|
2017-12-03 02:51:47 +08:00
|
|
|
|
* batadv_mcast_forw_want_all_ip_count() - count nodes with unspecific mcast
|
2016-03-11 23:36:19 +08:00
|
|
|
|
* interest
|
2014-02-16 00:47:54 +08:00
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
* @ethhdr: ethernet header of a packet
|
|
|
|
|
*
|
2015-09-16 01:00:48 +08:00
|
|
|
|
* Return: the number of nodes which want all IPv4 multicast traffic if the
|
2014-02-16 00:47:54 +08:00
|
|
|
|
* given ethhdr is from an IPv4 packet or the number of nodes which want all
|
|
|
|
|
* IPv6 traffic if it matches an IPv6 packet.
|
|
|
|
|
*/
|
|
|
|
|
static int batadv_mcast_forw_want_all_ip_count(struct batadv_priv *bat_priv,
|
|
|
|
|
struct ethhdr *ethhdr)
|
|
|
|
|
{
|
|
|
|
|
switch (ntohs(ethhdr->h_proto)) {
|
|
|
|
|
case ETH_P_IP:
|
|
|
|
|
return atomic_read(&bat_priv->mcast.num_want_all_ipv4);
|
|
|
|
|
case ETH_P_IPV6:
|
|
|
|
|
return atomic_read(&bat_priv->mcast.num_want_all_ipv6);
|
|
|
|
|
default:
|
|
|
|
|
/* we shouldn't be here... */
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-12 04:58:41 +08:00
|
|
|
|
/**
|
|
|
|
|
* batadv_mcast_forw_rtr_count() - count nodes with a multicast router
|
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
* @protocol: the ethernet protocol type to count multicast routers for
|
|
|
|
|
*
|
|
|
|
|
* Return: the number of nodes which want all routable IPv4 multicast traffic
|
|
|
|
|
* if the protocol is ETH_P_IP or the number of nodes which want all routable
|
|
|
|
|
* IPv6 traffic if the protocol is ETH_P_IPV6. Otherwise returns 0.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static int batadv_mcast_forw_rtr_count(struct batadv_priv *bat_priv,
|
|
|
|
|
int protocol)
|
|
|
|
|
{
|
|
|
|
|
switch (protocol) {
|
|
|
|
|
case ETH_P_IP:
|
|
|
|
|
return atomic_read(&bat_priv->mcast.num_want_all_rtr4);
|
|
|
|
|
case ETH_P_IPV6:
|
|
|
|
|
return atomic_read(&bat_priv->mcast.num_want_all_rtr6);
|
|
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-07 09:09:09 +08:00
|
|
|
|
/**
|
|
|
|
|
* batadv_mcast_forw_mode_by_count() - get forwarding mode by count
|
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
* @skb: the multicast packet to check
|
|
|
|
|
* @vid: the vlan identifier
|
|
|
|
|
* @is_routable: stores whether the destination is routable
|
|
|
|
|
* @count: the number of originators the multicast packet need to be sent to
|
|
|
|
|
*
|
|
|
|
|
* For a multicast packet with multiple destination originators, checks which
|
|
|
|
|
* mode to use. For BATADV_FORW_MCAST it also encapsulates the packet with a
|
|
|
|
|
* complete batman-adv multicast header.
|
|
|
|
|
*
|
|
|
|
|
* Return:
|
|
|
|
|
* BATADV_FORW_MCAST: If all nodes have multicast packet routing
|
|
|
|
|
* capabilities and an MTU >= 1280 on all hard interfaces (including us)
|
|
|
|
|
* and the encapsulated multicast packet with all destination addresses
|
|
|
|
|
* would still fit into an 1280 bytes batman-adv multicast packet
|
|
|
|
|
* (excluding the outer ethernet frame) and we could successfully push
|
|
|
|
|
* the full batman-adv multicast packet header.
|
|
|
|
|
* BATADV_FORW_UCASTS: If the packet cannot be sent in a batman-adv
|
|
|
|
|
* multicast packet and the amount of batman-adv unicast packets needed
|
|
|
|
|
* is smaller or equal to the configured multicast fanout.
|
|
|
|
|
* BATADV_FORW_BCAST: Otherwise.
|
|
|
|
|
*/
|
|
|
|
|
static enum batadv_forw_mode
|
|
|
|
|
batadv_mcast_forw_mode_by_count(struct batadv_priv *bat_priv,
|
|
|
|
|
struct sk_buff *skb, unsigned short vid,
|
|
|
|
|
int is_routable, int count)
|
|
|
|
|
{
|
|
|
|
|
unsigned int mcast_hdrlen = batadv_mcast_forw_packet_hdrlen(count);
|
|
|
|
|
u8 own_tvlv_flags = bat_priv->mcast.mla_flags.tvlv_flags;
|
|
|
|
|
|
|
|
|
|
if (!atomic_read(&bat_priv->mcast.num_no_mc_ptype_capa) &&
|
|
|
|
|
own_tvlv_flags & BATADV_MCAST_HAVE_MC_PTYPE_CAPA &&
|
|
|
|
|
skb->len + mcast_hdrlen <= IPV6_MIN_MTU &&
|
|
|
|
|
batadv_mcast_forw_push(bat_priv, skb, vid, is_routable, count))
|
|
|
|
|
return BATADV_FORW_MCAST;
|
|
|
|
|
|
|
|
|
|
if (count <= atomic_read(&bat_priv->multicast_fanout))
|
|
|
|
|
return BATADV_FORW_UCASTS;
|
|
|
|
|
|
|
|
|
|
return BATADV_FORW_BCAST;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-16 00:47:52 +08:00
|
|
|
|
/**
|
2017-12-03 02:51:47 +08:00
|
|
|
|
* batadv_mcast_forw_mode() - check on how to forward a multicast packet
|
2014-02-16 00:47:52 +08:00
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
2022-12-28 03:34:05 +08:00
|
|
|
|
* @skb: the multicast packet to check
|
2023-09-07 09:09:09 +08:00
|
|
|
|
* @vid: the vlan identifier
|
2022-01-01 13:27:13 +08:00
|
|
|
|
* @is_routable: stores whether the destination is routable
|
2014-02-16 00:47:52 +08:00
|
|
|
|
*
|
2022-12-28 03:34:05 +08:00
|
|
|
|
* Return: The forwarding mode as enum batadv_forw_mode.
|
2014-02-16 00:47:52 +08:00
|
|
|
|
*/
|
|
|
|
|
enum batadv_forw_mode
|
|
|
|
|
batadv_mcast_forw_mode(struct batadv_priv *bat_priv, struct sk_buff *skb,
|
2023-09-07 09:09:09 +08:00
|
|
|
|
unsigned short vid, int *is_routable)
|
2014-02-16 00:47:52 +08:00
|
|
|
|
{
|
2014-02-16 00:47:54 +08:00
|
|
|
|
int ret, tt_count, ip_count, unsnoop_count, total_count;
|
2014-02-16 00:47:53 +08:00
|
|
|
|
bool is_unsnoopable = false;
|
2014-02-16 00:47:52 +08:00
|
|
|
|
struct ethhdr *ethhdr;
|
2019-06-12 04:58:41 +08:00
|
|
|
|
int rtr_count = 0;
|
2014-02-16 00:47:52 +08:00
|
|
|
|
|
2019-06-12 04:58:41 +08:00
|
|
|
|
ret = batadv_mcast_forw_mode_check(bat_priv, skb, &is_unsnoopable,
|
2022-01-01 13:27:13 +08:00
|
|
|
|
is_routable);
|
2014-02-16 00:47:52 +08:00
|
|
|
|
if (ret == -ENOMEM)
|
|
|
|
|
return BATADV_FORW_NONE;
|
|
|
|
|
else if (ret < 0)
|
2022-12-28 03:34:05 +08:00
|
|
|
|
return BATADV_FORW_BCAST;
|
2014-02-16 00:47:52 +08:00
|
|
|
|
|
|
|
|
|
ethhdr = eth_hdr(skb);
|
|
|
|
|
|
|
|
|
|
tt_count = batadv_tt_global_hash_count(bat_priv, ethhdr->h_dest,
|
|
|
|
|
BATADV_NO_FLAGS);
|
2014-02-16 00:47:54 +08:00
|
|
|
|
ip_count = batadv_mcast_forw_want_all_ip_count(bat_priv, ethhdr);
|
2014-02-16 00:47:53 +08:00
|
|
|
|
unsnoop_count = !is_unsnoopable ? 0 :
|
|
|
|
|
atomic_read(&bat_priv->mcast.num_want_all_unsnoopables);
|
2022-01-01 13:27:13 +08:00
|
|
|
|
rtr_count = batadv_mcast_forw_rtr_count(bat_priv, *is_routable);
|
2014-02-16 00:47:53 +08:00
|
|
|
|
|
2019-06-12 04:58:41 +08:00
|
|
|
|
total_count = tt_count + ip_count + unsnoop_count + rtr_count;
|
2014-02-16 00:47:52 +08:00
|
|
|
|
|
2022-12-28 03:34:05 +08:00
|
|
|
|
if (!total_count)
|
2014-02-16 00:47:52 +08:00
|
|
|
|
return BATADV_FORW_NONE;
|
2022-12-28 03:34:05 +08:00
|
|
|
|
else if (unsnoop_count)
|
|
|
|
|
return BATADV_FORW_BCAST;
|
2019-03-23 12:47:41 +08:00
|
|
|
|
|
2023-09-07 09:09:09 +08:00
|
|
|
|
return batadv_mcast_forw_mode_by_count(bat_priv, skb, vid, *is_routable,
|
|
|
|
|
total_count);
|
2019-03-23 12:47:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-15 15:54:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* batadv_mcast_forw_send_orig() - send a multicast packet to an originator
|
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
* @skb: the multicast packet to send
|
|
|
|
|
* @vid: the vlan identifier
|
|
|
|
|
* @orig_node: the originator to send the packet to
|
|
|
|
|
*
|
|
|
|
|
* Return: NET_XMIT_DROP in case of error or NET_XMIT_SUCCESS otherwise.
|
|
|
|
|
*/
|
2022-12-28 03:34:05 +08:00
|
|
|
|
static int batadv_mcast_forw_send_orig(struct batadv_priv *bat_priv,
|
|
|
|
|
struct sk_buff *skb,
|
|
|
|
|
unsigned short vid,
|
|
|
|
|
struct batadv_orig_node *orig_node)
|
2020-09-15 15:54:08 +08:00
|
|
|
|
{
|
|
|
|
|
/* Avoid sending multicast-in-unicast packets to other BLA
|
|
|
|
|
* gateways - they already got the frame from the LAN side
|
|
|
|
|
* we share with them.
|
|
|
|
|
* TODO: Refactor to take BLA into account earlier, to avoid
|
|
|
|
|
* reducing the mcast_fanout count.
|
|
|
|
|
*/
|
|
|
|
|
if (batadv_bla_is_backbone_gw_orig(bat_priv, orig_node->orig, vid)) {
|
|
|
|
|
dev_kfree_skb(skb);
|
|
|
|
|
return NET_XMIT_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return batadv_send_skb_unicast(bat_priv, skb, BATADV_UNICAST, 0,
|
|
|
|
|
orig_node, vid);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-23 12:47:41 +08:00
|
|
|
|
/**
|
|
|
|
|
* batadv_mcast_forw_tt() - forwards a packet to multicast listeners
|
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
* @skb: the multicast packet to transmit
|
|
|
|
|
* @vid: the vlan identifier
|
|
|
|
|
*
|
|
|
|
|
* Sends copies of a frame with multicast destination to any multicast
|
|
|
|
|
* listener registered in the translation table. A transmission is performed
|
|
|
|
|
* via a batman-adv unicast packet for each such destination node.
|
|
|
|
|
*
|
|
|
|
|
* Return: NET_XMIT_DROP on memory allocation failure, NET_XMIT_SUCCESS
|
|
|
|
|
* otherwise.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
batadv_mcast_forw_tt(struct batadv_priv *bat_priv, struct sk_buff *skb,
|
|
|
|
|
unsigned short vid)
|
|
|
|
|
{
|
|
|
|
|
int ret = NET_XMIT_SUCCESS;
|
|
|
|
|
struct sk_buff *newskb;
|
|
|
|
|
|
|
|
|
|
struct batadv_tt_orig_list_entry *orig_entry;
|
|
|
|
|
|
|
|
|
|
struct batadv_tt_global_entry *tt_global;
|
|
|
|
|
const u8 *addr = eth_hdr(skb)->h_dest;
|
|
|
|
|
|
|
|
|
|
tt_global = batadv_tt_global_hash_find(bat_priv, addr, vid);
|
|
|
|
|
if (!tt_global)
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
|
hlist_for_each_entry_rcu(orig_entry, &tt_global->orig_list, list) {
|
|
|
|
|
newskb = skb_copy(skb, GFP_ATOMIC);
|
|
|
|
|
if (!newskb) {
|
|
|
|
|
ret = NET_XMIT_DROP;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-15 15:54:08 +08:00
|
|
|
|
batadv_mcast_forw_send_orig(bat_priv, newskb, vid,
|
|
|
|
|
orig_entry->orig_node);
|
2019-03-23 12:47:41 +08:00
|
|
|
|
}
|
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
|
|
batadv_tt_global_entry_put(tt_global);
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* batadv_mcast_forw_want_all_ipv4() - forward to nodes with want-all-ipv4
|
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
* @skb: the multicast packet to transmit
|
|
|
|
|
* @vid: the vlan identifier
|
|
|
|
|
*
|
|
|
|
|
* Sends copies of a frame with multicast destination to any node with a
|
|
|
|
|
* BATADV_MCAST_WANT_ALL_IPV4 flag set. A transmission is performed via a
|
|
|
|
|
* batman-adv unicast packet for each such destination node.
|
|
|
|
|
*
|
|
|
|
|
* Return: NET_XMIT_DROP on memory allocation failure, NET_XMIT_SUCCESS
|
|
|
|
|
* otherwise.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
batadv_mcast_forw_want_all_ipv4(struct batadv_priv *bat_priv,
|
|
|
|
|
struct sk_buff *skb, unsigned short vid)
|
|
|
|
|
{
|
|
|
|
|
struct batadv_orig_node *orig_node;
|
|
|
|
|
int ret = NET_XMIT_SUCCESS;
|
|
|
|
|
struct sk_buff *newskb;
|
|
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
|
hlist_for_each_entry_rcu(orig_node,
|
|
|
|
|
&bat_priv->mcast.want_all_ipv4_list,
|
|
|
|
|
mcast_want_all_ipv4_node) {
|
|
|
|
|
newskb = skb_copy(skb, GFP_ATOMIC);
|
|
|
|
|
if (!newskb) {
|
|
|
|
|
ret = NET_XMIT_DROP;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-15 15:54:08 +08:00
|
|
|
|
batadv_mcast_forw_send_orig(bat_priv, newskb, vid, orig_node);
|
2019-03-23 12:47:41 +08:00
|
|
|
|
}
|
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* batadv_mcast_forw_want_all_ipv6() - forward to nodes with want-all-ipv6
|
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
* @skb: The multicast packet to transmit
|
|
|
|
|
* @vid: the vlan identifier
|
|
|
|
|
*
|
|
|
|
|
* Sends copies of a frame with multicast destination to any node with a
|
|
|
|
|
* BATADV_MCAST_WANT_ALL_IPV6 flag set. A transmission is performed via a
|
|
|
|
|
* batman-adv unicast packet for each such destination node.
|
|
|
|
|
*
|
|
|
|
|
* Return: NET_XMIT_DROP on memory allocation failure, NET_XMIT_SUCCESS
|
|
|
|
|
* otherwise.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
batadv_mcast_forw_want_all_ipv6(struct batadv_priv *bat_priv,
|
|
|
|
|
struct sk_buff *skb, unsigned short vid)
|
|
|
|
|
{
|
|
|
|
|
struct batadv_orig_node *orig_node;
|
|
|
|
|
int ret = NET_XMIT_SUCCESS;
|
|
|
|
|
struct sk_buff *newskb;
|
|
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
|
hlist_for_each_entry_rcu(orig_node,
|
|
|
|
|
&bat_priv->mcast.want_all_ipv6_list,
|
|
|
|
|
mcast_want_all_ipv6_node) {
|
|
|
|
|
newskb = skb_copy(skb, GFP_ATOMIC);
|
|
|
|
|
if (!newskb) {
|
|
|
|
|
ret = NET_XMIT_DROP;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-15 15:54:08 +08:00
|
|
|
|
batadv_mcast_forw_send_orig(bat_priv, newskb, vid, orig_node);
|
2014-02-16 00:47:52 +08:00
|
|
|
|
}
|
2019-03-23 12:47:41 +08:00
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* batadv_mcast_forw_want_all() - forward packet to nodes in a want-all list
|
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
* @skb: the multicast packet to transmit
|
|
|
|
|
* @vid: the vlan identifier
|
|
|
|
|
*
|
|
|
|
|
* Sends copies of a frame with multicast destination to any node with a
|
|
|
|
|
* BATADV_MCAST_WANT_ALL_IPV4 or BATADV_MCAST_WANT_ALL_IPV6 flag set. A
|
|
|
|
|
* transmission is performed via a batman-adv unicast packet for each such
|
|
|
|
|
* destination node.
|
|
|
|
|
*
|
|
|
|
|
* Return: NET_XMIT_DROP on memory allocation failure or if the protocol family
|
|
|
|
|
* is neither IPv4 nor IPv6. NET_XMIT_SUCCESS otherwise.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
batadv_mcast_forw_want_all(struct batadv_priv *bat_priv,
|
|
|
|
|
struct sk_buff *skb, unsigned short vid)
|
|
|
|
|
{
|
|
|
|
|
switch (ntohs(eth_hdr(skb)->h_proto)) {
|
|
|
|
|
case ETH_P_IP:
|
|
|
|
|
return batadv_mcast_forw_want_all_ipv4(bat_priv, skb, vid);
|
|
|
|
|
case ETH_P_IPV6:
|
|
|
|
|
return batadv_mcast_forw_want_all_ipv6(bat_priv, skb, vid);
|
|
|
|
|
default:
|
|
|
|
|
/* we shouldn't be here... */
|
|
|
|
|
return NET_XMIT_DROP;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-12 04:58:41 +08:00
|
|
|
|
/**
|
|
|
|
|
* batadv_mcast_forw_want_all_rtr4() - forward to nodes with want-all-rtr4
|
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
* @skb: the multicast packet to transmit
|
|
|
|
|
* @vid: the vlan identifier
|
|
|
|
|
*
|
|
|
|
|
* Sends copies of a frame with multicast destination to any node with a
|
|
|
|
|
* BATADV_MCAST_WANT_NO_RTR4 flag unset. A transmission is performed via a
|
|
|
|
|
* batman-adv unicast packet for each such destination node.
|
|
|
|
|
*
|
|
|
|
|
* Return: NET_XMIT_DROP on memory allocation failure, NET_XMIT_SUCCESS
|
|
|
|
|
* otherwise.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
batadv_mcast_forw_want_all_rtr4(struct batadv_priv *bat_priv,
|
|
|
|
|
struct sk_buff *skb, unsigned short vid)
|
|
|
|
|
{
|
|
|
|
|
struct batadv_orig_node *orig_node;
|
|
|
|
|
int ret = NET_XMIT_SUCCESS;
|
|
|
|
|
struct sk_buff *newskb;
|
|
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
|
hlist_for_each_entry_rcu(orig_node,
|
|
|
|
|
&bat_priv->mcast.want_all_rtr4_list,
|
|
|
|
|
mcast_want_all_rtr4_node) {
|
|
|
|
|
newskb = skb_copy(skb, GFP_ATOMIC);
|
|
|
|
|
if (!newskb) {
|
|
|
|
|
ret = NET_XMIT_DROP;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-15 15:54:08 +08:00
|
|
|
|
batadv_mcast_forw_send_orig(bat_priv, newskb, vid, orig_node);
|
2019-06-12 04:58:41 +08:00
|
|
|
|
}
|
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* batadv_mcast_forw_want_all_rtr6() - forward to nodes with want-all-rtr6
|
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
* @skb: The multicast packet to transmit
|
|
|
|
|
* @vid: the vlan identifier
|
|
|
|
|
*
|
|
|
|
|
* Sends copies of a frame with multicast destination to any node with a
|
|
|
|
|
* BATADV_MCAST_WANT_NO_RTR6 flag unset. A transmission is performed via a
|
|
|
|
|
* batman-adv unicast packet for each such destination node.
|
|
|
|
|
*
|
|
|
|
|
* Return: NET_XMIT_DROP on memory allocation failure, NET_XMIT_SUCCESS
|
|
|
|
|
* otherwise.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
batadv_mcast_forw_want_all_rtr6(struct batadv_priv *bat_priv,
|
|
|
|
|
struct sk_buff *skb, unsigned short vid)
|
|
|
|
|
{
|
|
|
|
|
struct batadv_orig_node *orig_node;
|
|
|
|
|
int ret = NET_XMIT_SUCCESS;
|
|
|
|
|
struct sk_buff *newskb;
|
|
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
|
hlist_for_each_entry_rcu(orig_node,
|
|
|
|
|
&bat_priv->mcast.want_all_rtr6_list,
|
|
|
|
|
mcast_want_all_rtr6_node) {
|
|
|
|
|
newskb = skb_copy(skb, GFP_ATOMIC);
|
|
|
|
|
if (!newskb) {
|
|
|
|
|
ret = NET_XMIT_DROP;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-15 15:54:08 +08:00
|
|
|
|
batadv_mcast_forw_send_orig(bat_priv, newskb, vid, orig_node);
|
2019-06-12 04:58:41 +08:00
|
|
|
|
}
|
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* batadv_mcast_forw_want_rtr() - forward packet to nodes in a want-all-rtr list
|
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
* @skb: the multicast packet to transmit
|
|
|
|
|
* @vid: the vlan identifier
|
|
|
|
|
*
|
|
|
|
|
* Sends copies of a frame with multicast destination to any node with a
|
|
|
|
|
* BATADV_MCAST_WANT_NO_RTR4 or BATADV_MCAST_WANT_NO_RTR6 flag unset. A
|
|
|
|
|
* transmission is performed via a batman-adv unicast packet for each such
|
|
|
|
|
* destination node.
|
|
|
|
|
*
|
|
|
|
|
* Return: NET_XMIT_DROP on memory allocation failure or if the protocol family
|
|
|
|
|
* is neither IPv4 nor IPv6. NET_XMIT_SUCCESS otherwise.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
batadv_mcast_forw_want_rtr(struct batadv_priv *bat_priv,
|
|
|
|
|
struct sk_buff *skb, unsigned short vid)
|
|
|
|
|
{
|
|
|
|
|
switch (ntohs(eth_hdr(skb)->h_proto)) {
|
|
|
|
|
case ETH_P_IP:
|
|
|
|
|
return batadv_mcast_forw_want_all_rtr4(bat_priv, skb, vid);
|
|
|
|
|
case ETH_P_IPV6:
|
|
|
|
|
return batadv_mcast_forw_want_all_rtr6(bat_priv, skb, vid);
|
|
|
|
|
default:
|
|
|
|
|
/* we shouldn't be here... */
|
|
|
|
|
return NET_XMIT_DROP;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-23 12:47:41 +08:00
|
|
|
|
/**
|
2020-06-02 02:13:21 +08:00
|
|
|
|
* batadv_mcast_forw_send() - send packet to any detected multicast recipient
|
2019-03-23 12:47:41 +08:00
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
* @skb: the multicast packet to transmit
|
|
|
|
|
* @vid: the vlan identifier
|
2022-01-01 13:27:13 +08:00
|
|
|
|
* @is_routable: stores whether the destination is routable
|
2019-03-23 12:47:41 +08:00
|
|
|
|
*
|
|
|
|
|
* Sends copies of a frame with multicast destination to any node that signaled
|
|
|
|
|
* interest in it, that is either via the translation table or the according
|
|
|
|
|
* want-all flags. A transmission is performed via a batman-adv unicast packet
|
|
|
|
|
* for each such destination node.
|
|
|
|
|
*
|
|
|
|
|
* The given skb is consumed/freed.
|
|
|
|
|
*
|
|
|
|
|
* Return: NET_XMIT_DROP on memory allocation failure or if the protocol family
|
|
|
|
|
* is neither IPv4 nor IPv6. NET_XMIT_SUCCESS otherwise.
|
|
|
|
|
*/
|
|
|
|
|
int batadv_mcast_forw_send(struct batadv_priv *bat_priv, struct sk_buff *skb,
|
2022-01-01 13:27:13 +08:00
|
|
|
|
unsigned short vid, int is_routable)
|
2019-03-23 12:47:41 +08:00
|
|
|
|
{
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
ret = batadv_mcast_forw_tt(bat_priv, skb, vid);
|
|
|
|
|
if (ret != NET_XMIT_SUCCESS) {
|
|
|
|
|
kfree_skb(skb);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret = batadv_mcast_forw_want_all(bat_priv, skb, vid);
|
|
|
|
|
if (ret != NET_XMIT_SUCCESS) {
|
|
|
|
|
kfree_skb(skb);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-01 13:27:13 +08:00
|
|
|
|
if (!is_routable)
|
|
|
|
|
goto skip_mc_router;
|
|
|
|
|
|
2019-06-12 04:58:41 +08:00
|
|
|
|
ret = batadv_mcast_forw_want_rtr(bat_priv, skb, vid);
|
|
|
|
|
if (ret != NET_XMIT_SUCCESS) {
|
|
|
|
|
kfree_skb(skb);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-01 13:27:13 +08:00
|
|
|
|
skip_mc_router:
|
2019-03-23 12:47:41 +08:00
|
|
|
|
consume_skb(skb);
|
|
|
|
|
return ret;
|
2014-02-16 00:47:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-16 00:47:53 +08:00
|
|
|
|
/**
|
2017-12-03 02:51:47 +08:00
|
|
|
|
* batadv_mcast_want_unsnoop_update() - update unsnoop counter and list
|
2014-02-16 00:47:53 +08:00
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
* @orig: the orig_node which multicast state might have changed of
|
|
|
|
|
* @mcast_flags: flags indicating the new multicast state
|
|
|
|
|
*
|
|
|
|
|
* If the BATADV_MCAST_WANT_ALL_UNSNOOPABLES flag of this originator,
|
2020-06-02 02:13:21 +08:00
|
|
|
|
* orig, has toggled then this method updates the counter and the list
|
|
|
|
|
* accordingly.
|
2015-06-16 23:10:26 +08:00
|
|
|
|
*
|
|
|
|
|
* Caller needs to hold orig->mcast_handler_lock.
|
2014-02-16 00:47:53 +08:00
|
|
|
|
*/
|
|
|
|
|
static void batadv_mcast_want_unsnoop_update(struct batadv_priv *bat_priv,
|
|
|
|
|
struct batadv_orig_node *orig,
|
2015-05-27 00:34:26 +08:00
|
|
|
|
u8 mcast_flags)
|
2014-02-16 00:47:53 +08:00
|
|
|
|
{
|
2015-06-16 23:10:26 +08:00
|
|
|
|
struct hlist_node *node = &orig->mcast_want_all_unsnoopables_node;
|
|
|
|
|
struct hlist_head *head = &bat_priv->mcast.want_all_unsnoopables_list;
|
|
|
|
|
|
2015-06-21 20:45:15 +08:00
|
|
|
|
lockdep_assert_held(&orig->mcast_handler_lock);
|
|
|
|
|
|
2014-02-16 00:47:53 +08:00
|
|
|
|
/* switched from flag unset to set */
|
|
|
|
|
if (mcast_flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES &&
|
|
|
|
|
!(orig->mcast_flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES)) {
|
|
|
|
|
atomic_inc(&bat_priv->mcast.num_want_all_unsnoopables);
|
|
|
|
|
|
|
|
|
|
spin_lock_bh(&bat_priv->mcast.want_lists_lock);
|
2015-06-16 23:10:26 +08:00
|
|
|
|
/* flag checks above + mcast_handler_lock prevents this */
|
|
|
|
|
WARN_ON(!hlist_unhashed(node));
|
|
|
|
|
|
|
|
|
|
hlist_add_head_rcu(node, head);
|
2014-02-16 00:47:53 +08:00
|
|
|
|
spin_unlock_bh(&bat_priv->mcast.want_lists_lock);
|
|
|
|
|
/* switched from flag set to unset */
|
|
|
|
|
} else if (!(mcast_flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES) &&
|
|
|
|
|
orig->mcast_flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES) {
|
|
|
|
|
atomic_dec(&bat_priv->mcast.num_want_all_unsnoopables);
|
|
|
|
|
|
|
|
|
|
spin_lock_bh(&bat_priv->mcast.want_lists_lock);
|
2015-06-16 23:10:26 +08:00
|
|
|
|
/* flag checks above + mcast_handler_lock prevents this */
|
|
|
|
|
WARN_ON(hlist_unhashed(node));
|
|
|
|
|
|
|
|
|
|
hlist_del_init_rcu(node);
|
2014-02-16 00:47:53 +08:00
|
|
|
|
spin_unlock_bh(&bat_priv->mcast.want_lists_lock);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-16 00:47:54 +08:00
|
|
|
|
/**
|
2017-12-03 02:51:47 +08:00
|
|
|
|
* batadv_mcast_want_ipv4_update() - update want-all-ipv4 counter and list
|
2014-02-16 00:47:54 +08:00
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
* @orig: the orig_node which multicast state might have changed of
|
|
|
|
|
* @mcast_flags: flags indicating the new multicast state
|
|
|
|
|
*
|
|
|
|
|
* If the BATADV_MCAST_WANT_ALL_IPV4 flag of this originator, orig, has
|
2020-06-02 02:13:21 +08:00
|
|
|
|
* toggled then this method updates the counter and the list accordingly.
|
2015-06-16 23:10:26 +08:00
|
|
|
|
*
|
|
|
|
|
* Caller needs to hold orig->mcast_handler_lock.
|
2014-02-16 00:47:54 +08:00
|
|
|
|
*/
|
|
|
|
|
static void batadv_mcast_want_ipv4_update(struct batadv_priv *bat_priv,
|
|
|
|
|
struct batadv_orig_node *orig,
|
2015-05-27 00:34:26 +08:00
|
|
|
|
u8 mcast_flags)
|
2014-02-16 00:47:54 +08:00
|
|
|
|
{
|
2015-06-16 23:10:26 +08:00
|
|
|
|
struct hlist_node *node = &orig->mcast_want_all_ipv4_node;
|
|
|
|
|
struct hlist_head *head = &bat_priv->mcast.want_all_ipv4_list;
|
|
|
|
|
|
2015-06-21 20:45:15 +08:00
|
|
|
|
lockdep_assert_held(&orig->mcast_handler_lock);
|
|
|
|
|
|
2014-02-16 00:47:54 +08:00
|
|
|
|
/* switched from flag unset to set */
|
|
|
|
|
if (mcast_flags & BATADV_MCAST_WANT_ALL_IPV4 &&
|
|
|
|
|
!(orig->mcast_flags & BATADV_MCAST_WANT_ALL_IPV4)) {
|
|
|
|
|
atomic_inc(&bat_priv->mcast.num_want_all_ipv4);
|
|
|
|
|
|
|
|
|
|
spin_lock_bh(&bat_priv->mcast.want_lists_lock);
|
2015-06-16 23:10:26 +08:00
|
|
|
|
/* flag checks above + mcast_handler_lock prevents this */
|
|
|
|
|
WARN_ON(!hlist_unhashed(node));
|
|
|
|
|
|
|
|
|
|
hlist_add_head_rcu(node, head);
|
2014-02-16 00:47:54 +08:00
|
|
|
|
spin_unlock_bh(&bat_priv->mcast.want_lists_lock);
|
|
|
|
|
/* switched from flag set to unset */
|
|
|
|
|
} else if (!(mcast_flags & BATADV_MCAST_WANT_ALL_IPV4) &&
|
|
|
|
|
orig->mcast_flags & BATADV_MCAST_WANT_ALL_IPV4) {
|
|
|
|
|
atomic_dec(&bat_priv->mcast.num_want_all_ipv4);
|
|
|
|
|
|
|
|
|
|
spin_lock_bh(&bat_priv->mcast.want_lists_lock);
|
2015-06-16 23:10:26 +08:00
|
|
|
|
/* flag checks above + mcast_handler_lock prevents this */
|
|
|
|
|
WARN_ON(hlist_unhashed(node));
|
|
|
|
|
|
|
|
|
|
hlist_del_init_rcu(node);
|
2014-02-16 00:47:54 +08:00
|
|
|
|
spin_unlock_bh(&bat_priv->mcast.want_lists_lock);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-12-03 02:51:47 +08:00
|
|
|
|
* batadv_mcast_want_ipv6_update() - update want-all-ipv6 counter and list
|
2014-02-16 00:47:54 +08:00
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
* @orig: the orig_node which multicast state might have changed of
|
|
|
|
|
* @mcast_flags: flags indicating the new multicast state
|
|
|
|
|
*
|
|
|
|
|
* If the BATADV_MCAST_WANT_ALL_IPV6 flag of this originator, orig, has
|
2020-06-02 02:13:21 +08:00
|
|
|
|
* toggled then this method updates the counter and the list accordingly.
|
2015-06-16 23:10:26 +08:00
|
|
|
|
*
|
|
|
|
|
* Caller needs to hold orig->mcast_handler_lock.
|
2014-02-16 00:47:54 +08:00
|
|
|
|
*/
|
|
|
|
|
static void batadv_mcast_want_ipv6_update(struct batadv_priv *bat_priv,
|
|
|
|
|
struct batadv_orig_node *orig,
|
2015-05-27 00:34:26 +08:00
|
|
|
|
u8 mcast_flags)
|
2014-02-16 00:47:54 +08:00
|
|
|
|
{
|
2015-06-16 23:10:26 +08:00
|
|
|
|
struct hlist_node *node = &orig->mcast_want_all_ipv6_node;
|
|
|
|
|
struct hlist_head *head = &bat_priv->mcast.want_all_ipv6_list;
|
|
|
|
|
|
2015-06-21 20:45:15 +08:00
|
|
|
|
lockdep_assert_held(&orig->mcast_handler_lock);
|
|
|
|
|
|
2014-02-16 00:47:54 +08:00
|
|
|
|
/* switched from flag unset to set */
|
|
|
|
|
if (mcast_flags & BATADV_MCAST_WANT_ALL_IPV6 &&
|
|
|
|
|
!(orig->mcast_flags & BATADV_MCAST_WANT_ALL_IPV6)) {
|
|
|
|
|
atomic_inc(&bat_priv->mcast.num_want_all_ipv6);
|
|
|
|
|
|
|
|
|
|
spin_lock_bh(&bat_priv->mcast.want_lists_lock);
|
2015-06-16 23:10:26 +08:00
|
|
|
|
/* flag checks above + mcast_handler_lock prevents this */
|
|
|
|
|
WARN_ON(!hlist_unhashed(node));
|
|
|
|
|
|
|
|
|
|
hlist_add_head_rcu(node, head);
|
2014-02-16 00:47:54 +08:00
|
|
|
|
spin_unlock_bh(&bat_priv->mcast.want_lists_lock);
|
|
|
|
|
/* switched from flag set to unset */
|
|
|
|
|
} else if (!(mcast_flags & BATADV_MCAST_WANT_ALL_IPV6) &&
|
|
|
|
|
orig->mcast_flags & BATADV_MCAST_WANT_ALL_IPV6) {
|
|
|
|
|
atomic_dec(&bat_priv->mcast.num_want_all_ipv6);
|
|
|
|
|
|
|
|
|
|
spin_lock_bh(&bat_priv->mcast.want_lists_lock);
|
2015-06-16 23:10:26 +08:00
|
|
|
|
/* flag checks above + mcast_handler_lock prevents this */
|
|
|
|
|
WARN_ON(hlist_unhashed(node));
|
|
|
|
|
|
|
|
|
|
hlist_del_init_rcu(node);
|
2014-02-16 00:47:54 +08:00
|
|
|
|
spin_unlock_bh(&bat_priv->mcast.want_lists_lock);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-12 04:58:40 +08:00
|
|
|
|
/**
|
|
|
|
|
* batadv_mcast_want_rtr4_update() - update want-all-rtr4 counter and list
|
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
* @orig: the orig_node which multicast state might have changed of
|
|
|
|
|
* @mcast_flags: flags indicating the new multicast state
|
|
|
|
|
*
|
|
|
|
|
* If the BATADV_MCAST_WANT_NO_RTR4 flag of this originator, orig, has
|
2020-06-02 02:13:21 +08:00
|
|
|
|
* toggled then this method updates the counter and the list accordingly.
|
2019-06-12 04:58:40 +08:00
|
|
|
|
*
|
|
|
|
|
* Caller needs to hold orig->mcast_handler_lock.
|
|
|
|
|
*/
|
|
|
|
|
static void batadv_mcast_want_rtr4_update(struct batadv_priv *bat_priv,
|
|
|
|
|
struct batadv_orig_node *orig,
|
|
|
|
|
u8 mcast_flags)
|
|
|
|
|
{
|
|
|
|
|
struct hlist_node *node = &orig->mcast_want_all_rtr4_node;
|
|
|
|
|
struct hlist_head *head = &bat_priv->mcast.want_all_rtr4_list;
|
|
|
|
|
|
|
|
|
|
lockdep_assert_held(&orig->mcast_handler_lock);
|
|
|
|
|
|
|
|
|
|
/* switched from flag set to unset */
|
|
|
|
|
if (!(mcast_flags & BATADV_MCAST_WANT_NO_RTR4) &&
|
|
|
|
|
orig->mcast_flags & BATADV_MCAST_WANT_NO_RTR4) {
|
|
|
|
|
atomic_inc(&bat_priv->mcast.num_want_all_rtr4);
|
|
|
|
|
|
|
|
|
|
spin_lock_bh(&bat_priv->mcast.want_lists_lock);
|
|
|
|
|
/* flag checks above + mcast_handler_lock prevents this */
|
|
|
|
|
WARN_ON(!hlist_unhashed(node));
|
|
|
|
|
|
|
|
|
|
hlist_add_head_rcu(node, head);
|
|
|
|
|
spin_unlock_bh(&bat_priv->mcast.want_lists_lock);
|
|
|
|
|
/* switched from flag unset to set */
|
|
|
|
|
} else if (mcast_flags & BATADV_MCAST_WANT_NO_RTR4 &&
|
|
|
|
|
!(orig->mcast_flags & BATADV_MCAST_WANT_NO_RTR4)) {
|
|
|
|
|
atomic_dec(&bat_priv->mcast.num_want_all_rtr4);
|
|
|
|
|
|
|
|
|
|
spin_lock_bh(&bat_priv->mcast.want_lists_lock);
|
|
|
|
|
/* flag checks above + mcast_handler_lock prevents this */
|
|
|
|
|
WARN_ON(hlist_unhashed(node));
|
|
|
|
|
|
|
|
|
|
hlist_del_init_rcu(node);
|
|
|
|
|
spin_unlock_bh(&bat_priv->mcast.want_lists_lock);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* batadv_mcast_want_rtr6_update() - update want-all-rtr6 counter and list
|
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
* @orig: the orig_node which multicast state might have changed of
|
|
|
|
|
* @mcast_flags: flags indicating the new multicast state
|
|
|
|
|
*
|
|
|
|
|
* If the BATADV_MCAST_WANT_NO_RTR6 flag of this originator, orig, has
|
2020-06-02 02:13:21 +08:00
|
|
|
|
* toggled then this method updates the counter and the list accordingly.
|
2019-06-12 04:58:40 +08:00
|
|
|
|
*
|
|
|
|
|
* Caller needs to hold orig->mcast_handler_lock.
|
|
|
|
|
*/
|
|
|
|
|
static void batadv_mcast_want_rtr6_update(struct batadv_priv *bat_priv,
|
|
|
|
|
struct batadv_orig_node *orig,
|
|
|
|
|
u8 mcast_flags)
|
|
|
|
|
{
|
|
|
|
|
struct hlist_node *node = &orig->mcast_want_all_rtr6_node;
|
|
|
|
|
struct hlist_head *head = &bat_priv->mcast.want_all_rtr6_list;
|
|
|
|
|
|
|
|
|
|
lockdep_assert_held(&orig->mcast_handler_lock);
|
|
|
|
|
|
|
|
|
|
/* switched from flag set to unset */
|
|
|
|
|
if (!(mcast_flags & BATADV_MCAST_WANT_NO_RTR6) &&
|
|
|
|
|
orig->mcast_flags & BATADV_MCAST_WANT_NO_RTR6) {
|
|
|
|
|
atomic_inc(&bat_priv->mcast.num_want_all_rtr6);
|
|
|
|
|
|
|
|
|
|
spin_lock_bh(&bat_priv->mcast.want_lists_lock);
|
|
|
|
|
/* flag checks above + mcast_handler_lock prevents this */
|
|
|
|
|
WARN_ON(!hlist_unhashed(node));
|
|
|
|
|
|
|
|
|
|
hlist_add_head_rcu(node, head);
|
|
|
|
|
spin_unlock_bh(&bat_priv->mcast.want_lists_lock);
|
|
|
|
|
/* switched from flag unset to set */
|
|
|
|
|
} else if (mcast_flags & BATADV_MCAST_WANT_NO_RTR6 &&
|
|
|
|
|
!(orig->mcast_flags & BATADV_MCAST_WANT_NO_RTR6)) {
|
|
|
|
|
atomic_dec(&bat_priv->mcast.num_want_all_rtr6);
|
|
|
|
|
|
|
|
|
|
spin_lock_bh(&bat_priv->mcast.want_lists_lock);
|
|
|
|
|
/* flag checks above + mcast_handler_lock prevents this */
|
|
|
|
|
WARN_ON(hlist_unhashed(node));
|
|
|
|
|
|
|
|
|
|
hlist_del_init_rcu(node);
|
|
|
|
|
spin_unlock_bh(&bat_priv->mcast.want_lists_lock);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-07 09:09:09 +08:00
|
|
|
|
/**
|
|
|
|
|
* batadv_mcast_have_mc_ptype_update() - update multicast packet type counter
|
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
* @orig: the orig_node which multicast state might have changed of
|
|
|
|
|
* @mcast_flags: flags indicating the new multicast state
|
|
|
|
|
*
|
|
|
|
|
* If the BATADV_MCAST_HAVE_MC_PTYPE_CAPA flag of this originator, orig, has
|
|
|
|
|
* toggled then this method updates the counter accordingly.
|
|
|
|
|
*/
|
|
|
|
|
static void batadv_mcast_have_mc_ptype_update(struct batadv_priv *bat_priv,
|
|
|
|
|
struct batadv_orig_node *orig,
|
|
|
|
|
u8 mcast_flags)
|
|
|
|
|
{
|
|
|
|
|
lockdep_assert_held(&orig->mcast_handler_lock);
|
|
|
|
|
|
|
|
|
|
/* switched from flag set to unset */
|
|
|
|
|
if (!(mcast_flags & BATADV_MCAST_HAVE_MC_PTYPE_CAPA) &&
|
|
|
|
|
orig->mcast_flags & BATADV_MCAST_HAVE_MC_PTYPE_CAPA)
|
|
|
|
|
atomic_inc(&bat_priv->mcast.num_no_mc_ptype_capa);
|
|
|
|
|
/* switched from flag unset to set */
|
|
|
|
|
else if (mcast_flags & BATADV_MCAST_HAVE_MC_PTYPE_CAPA &&
|
|
|
|
|
!(orig->mcast_flags & BATADV_MCAST_HAVE_MC_PTYPE_CAPA))
|
|
|
|
|
atomic_dec(&bat_priv->mcast.num_no_mc_ptype_capa);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-12 04:58:40 +08:00
|
|
|
|
/**
|
|
|
|
|
* batadv_mcast_tvlv_flags_get() - get multicast flags from an OGM TVLV
|
|
|
|
|
* @enabled: whether the originator has multicast TVLV support enabled
|
|
|
|
|
* @tvlv_value: tvlv buffer containing the multicast flags
|
|
|
|
|
* @tvlv_value_len: tvlv buffer length
|
|
|
|
|
*
|
|
|
|
|
* Return: multicast flags for the given tvlv buffer
|
|
|
|
|
*/
|
|
|
|
|
static u8
|
|
|
|
|
batadv_mcast_tvlv_flags_get(bool enabled, void *tvlv_value, u16 tvlv_value_len)
|
|
|
|
|
{
|
|
|
|
|
u8 mcast_flags = BATADV_NO_FLAGS;
|
|
|
|
|
|
|
|
|
|
if (enabled && tvlv_value && tvlv_value_len >= sizeof(mcast_flags))
|
|
|
|
|
mcast_flags = *(u8 *)tvlv_value;
|
|
|
|
|
|
|
|
|
|
if (!enabled) {
|
|
|
|
|
mcast_flags |= BATADV_MCAST_WANT_ALL_IPV4;
|
|
|
|
|
mcast_flags |= BATADV_MCAST_WANT_ALL_IPV6;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* remove redundant flags to avoid sending duplicate packets later */
|
|
|
|
|
if (mcast_flags & BATADV_MCAST_WANT_ALL_IPV4)
|
|
|
|
|
mcast_flags |= BATADV_MCAST_WANT_NO_RTR4;
|
|
|
|
|
|
|
|
|
|
if (mcast_flags & BATADV_MCAST_WANT_ALL_IPV6)
|
|
|
|
|
mcast_flags |= BATADV_MCAST_WANT_NO_RTR6;
|
|
|
|
|
|
|
|
|
|
return mcast_flags;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-16 00:47:51 +08:00
|
|
|
|
/**
|
2017-12-03 02:51:47 +08:00
|
|
|
|
* batadv_mcast_tvlv_ogm_handler() - process incoming multicast tvlv container
|
2014-02-16 00:47:51 +08:00
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
* @orig: the orig_node of the ogm
|
|
|
|
|
* @flags: flags indicating the tvlv state (see batadv_tvlv_handler_flags)
|
|
|
|
|
* @tvlv_value: tvlv buffer containing the multicast data
|
|
|
|
|
* @tvlv_value_len: tvlv buffer length
|
|
|
|
|
*/
|
2016-05-11 00:41:24 +08:00
|
|
|
|
static void batadv_mcast_tvlv_ogm_handler(struct batadv_priv *bat_priv,
|
|
|
|
|
struct batadv_orig_node *orig,
|
|
|
|
|
u8 flags,
|
|
|
|
|
void *tvlv_value,
|
|
|
|
|
u16 tvlv_value_len)
|
2014-02-16 00:47:51 +08:00
|
|
|
|
{
|
|
|
|
|
bool orig_mcast_enabled = !(flags & BATADV_TVLV_HANDLER_OGM_CIFNOTFND);
|
2019-06-12 04:58:40 +08:00
|
|
|
|
u8 mcast_flags;
|
2015-06-16 23:10:26 +08:00
|
|
|
|
|
2019-06-12 04:58:40 +08:00
|
|
|
|
mcast_flags = batadv_mcast_tvlv_flags_get(orig_mcast_enabled,
|
|
|
|
|
tvlv_value, tvlv_value_len);
|
2018-03-25 07:32:04 +08:00
|
|
|
|
|
2015-06-16 23:10:26 +08:00
|
|
|
|
spin_lock_bh(&orig->mcast_handler_lock);
|
2014-02-16 00:47:51 +08:00
|
|
|
|
|
|
|
|
|
if (orig_mcast_enabled &&
|
2015-06-16 23:10:25 +08:00
|
|
|
|
!test_bit(BATADV_ORIG_CAPA_HAS_MCAST, &orig->capabilities)) {
|
|
|
|
|
set_bit(BATADV_ORIG_CAPA_HAS_MCAST, &orig->capabilities);
|
2014-02-16 00:47:51 +08:00
|
|
|
|
} else if (!orig_mcast_enabled &&
|
2018-03-25 07:32:04 +08:00
|
|
|
|
test_bit(BATADV_ORIG_CAPA_HAS_MCAST, &orig->capabilities)) {
|
2015-06-16 23:10:25 +08:00
|
|
|
|
clear_bit(BATADV_ORIG_CAPA_HAS_MCAST, &orig->capabilities);
|
2014-02-16 00:47:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-16 23:10:25 +08:00
|
|
|
|
set_bit(BATADV_ORIG_CAPA_HAS_MCAST, &orig->capa_initialized);
|
2014-02-16 00:47:51 +08:00
|
|
|
|
|
2014-02-16 00:47:53 +08:00
|
|
|
|
batadv_mcast_want_unsnoop_update(bat_priv, orig, mcast_flags);
|
2014-02-16 00:47:54 +08:00
|
|
|
|
batadv_mcast_want_ipv4_update(bat_priv, orig, mcast_flags);
|
|
|
|
|
batadv_mcast_want_ipv6_update(bat_priv, orig, mcast_flags);
|
2019-06-12 04:58:40 +08:00
|
|
|
|
batadv_mcast_want_rtr4_update(bat_priv, orig, mcast_flags);
|
|
|
|
|
batadv_mcast_want_rtr6_update(bat_priv, orig, mcast_flags);
|
2023-09-07 09:09:09 +08:00
|
|
|
|
batadv_mcast_have_mc_ptype_update(bat_priv, orig, mcast_flags);
|
2014-02-16 00:47:53 +08:00
|
|
|
|
|
2014-02-16 00:47:51 +08:00
|
|
|
|
orig->mcast_flags = mcast_flags;
|
2015-06-16 23:10:26 +08:00
|
|
|
|
spin_unlock_bh(&orig->mcast_handler_lock);
|
2014-02-16 00:47:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-12-03 02:51:47 +08:00
|
|
|
|
* batadv_mcast_init() - initialize the multicast optimizations structures
|
2014-02-16 00:47:51 +08:00
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
*/
|
|
|
|
|
void batadv_mcast_init(struct batadv_priv *bat_priv)
|
|
|
|
|
{
|
2016-05-11 00:41:24 +08:00
|
|
|
|
batadv_tvlv_handler_register(bat_priv, batadv_mcast_tvlv_ogm_handler,
|
2022-12-28 03:34:06 +08:00
|
|
|
|
NULL, NULL, BATADV_TVLV_MCAST, 2,
|
2014-02-16 00:47:51 +08:00
|
|
|
|
BATADV_TVLV_HANDLER_OGM_CIFNOTFND);
|
2023-09-07 09:09:08 +08:00
|
|
|
|
batadv_tvlv_handler_register(bat_priv, NULL, NULL,
|
|
|
|
|
batadv_mcast_forw_tracker_tvlv_handler,
|
|
|
|
|
BATADV_TVLV_MCAST_TRACKER, 1,
|
|
|
|
|
BATADV_TVLV_HANDLER_OGM_CIFNOTFND);
|
2016-08-07 04:23:16 +08:00
|
|
|
|
|
|
|
|
|
INIT_DELAYED_WORK(&bat_priv->mcast.work, batadv_mcast_mla_update);
|
|
|
|
|
batadv_mcast_start_timer(bat_priv);
|
2014-02-16 00:47:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-13 18:41:13 +08:00
|
|
|
|
/**
|
|
|
|
|
* batadv_mcast_mesh_info_put() - put multicast info into a netlink message
|
|
|
|
|
* @msg: buffer for the message
|
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
*
|
|
|
|
|
* Return: 0 or error code.
|
|
|
|
|
*/
|
|
|
|
|
int batadv_mcast_mesh_info_put(struct sk_buff *msg,
|
|
|
|
|
struct batadv_priv *bat_priv)
|
|
|
|
|
{
|
2019-05-07 12:08:26 +08:00
|
|
|
|
u32 flags = bat_priv->mcast.mla_flags.tvlv_flags;
|
2018-03-13 18:41:13 +08:00
|
|
|
|
u32 flags_priv = BATADV_NO_FLAGS;
|
|
|
|
|
|
2019-05-07 12:08:26 +08:00
|
|
|
|
if (bat_priv->mcast.mla_flags.bridged) {
|
2018-03-13 18:41:13 +08:00
|
|
|
|
flags_priv |= BATADV_MCAST_FLAGS_BRIDGED;
|
|
|
|
|
|
2019-05-07 12:08:26 +08:00
|
|
|
|
if (bat_priv->mcast.mla_flags.querier_ipv4.exists)
|
2018-03-13 18:41:13 +08:00
|
|
|
|
flags_priv |= BATADV_MCAST_FLAGS_QUERIER_IPV4_EXISTS;
|
2019-05-07 12:08:26 +08:00
|
|
|
|
if (bat_priv->mcast.mla_flags.querier_ipv6.exists)
|
2018-03-13 18:41:13 +08:00
|
|
|
|
flags_priv |= BATADV_MCAST_FLAGS_QUERIER_IPV6_EXISTS;
|
2019-05-07 12:08:26 +08:00
|
|
|
|
if (bat_priv->mcast.mla_flags.querier_ipv4.shadowing)
|
2018-03-13 18:41:13 +08:00
|
|
|
|
flags_priv |= BATADV_MCAST_FLAGS_QUERIER_IPV4_SHADOWING;
|
2019-05-07 12:08:26 +08:00
|
|
|
|
if (bat_priv->mcast.mla_flags.querier_ipv6.shadowing)
|
2018-03-13 18:41:13 +08:00
|
|
|
|
flags_priv |= BATADV_MCAST_FLAGS_QUERIER_IPV6_SHADOWING;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (nla_put_u32(msg, BATADV_ATTR_MCAST_FLAGS, flags) ||
|
|
|
|
|
nla_put_u32(msg, BATADV_ATTR_MCAST_FLAGS_PRIV, flags_priv))
|
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* batadv_mcast_flags_dump_entry() - dump one entry of the multicast flags table
|
|
|
|
|
* to a netlink socket
|
|
|
|
|
* @msg: buffer for the message
|
|
|
|
|
* @portid: netlink port
|
2018-10-31 05:01:30 +08:00
|
|
|
|
* @cb: Control block containing additional options
|
2018-03-13 18:41:13 +08:00
|
|
|
|
* @orig_node: originator to dump the multicast flags of
|
|
|
|
|
*
|
|
|
|
|
* Return: 0 or error code.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
2018-10-31 05:01:30 +08:00
|
|
|
|
batadv_mcast_flags_dump_entry(struct sk_buff *msg, u32 portid,
|
|
|
|
|
struct netlink_callback *cb,
|
2018-03-13 18:41:13 +08:00
|
|
|
|
struct batadv_orig_node *orig_node)
|
|
|
|
|
{
|
|
|
|
|
void *hdr;
|
|
|
|
|
|
2018-10-31 05:01:30 +08:00
|
|
|
|
hdr = genlmsg_put(msg, portid, cb->nlh->nlmsg_seq,
|
|
|
|
|
&batadv_netlink_family, NLM_F_MULTI,
|
|
|
|
|
BATADV_CMD_GET_MCAST_FLAGS);
|
2018-03-13 18:41:13 +08:00
|
|
|
|
if (!hdr)
|
|
|
|
|
return -ENOBUFS;
|
|
|
|
|
|
2018-10-31 05:01:30 +08:00
|
|
|
|
genl_dump_check_consistent(cb, hdr);
|
|
|
|
|
|
2018-03-13 18:41:13 +08:00
|
|
|
|
if (nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN,
|
|
|
|
|
orig_node->orig)) {
|
|
|
|
|
genlmsg_cancel(msg, hdr);
|
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (test_bit(BATADV_ORIG_CAPA_HAS_MCAST,
|
|
|
|
|
&orig_node->capabilities)) {
|
|
|
|
|
if (nla_put_u32(msg, BATADV_ATTR_MCAST_FLAGS,
|
|
|
|
|
orig_node->mcast_flags)) {
|
|
|
|
|
genlmsg_cancel(msg, hdr);
|
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
genlmsg_end(msg, hdr);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* batadv_mcast_flags_dump_bucket() - dump one bucket of the multicast flags
|
|
|
|
|
* table to a netlink socket
|
|
|
|
|
* @msg: buffer for the message
|
|
|
|
|
* @portid: netlink port
|
2018-10-31 05:01:30 +08:00
|
|
|
|
* @cb: Control block containing additional options
|
|
|
|
|
* @hash: hash to dump
|
|
|
|
|
* @bucket: bucket index to dump
|
2018-03-13 18:41:13 +08:00
|
|
|
|
* @idx_skip: How many entries to skip
|
|
|
|
|
*
|
|
|
|
|
* Return: 0 or error code.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
2018-10-31 05:01:30 +08:00
|
|
|
|
batadv_mcast_flags_dump_bucket(struct sk_buff *msg, u32 portid,
|
|
|
|
|
struct netlink_callback *cb,
|
|
|
|
|
struct batadv_hashtable *hash,
|
|
|
|
|
unsigned int bucket, long *idx_skip)
|
2018-03-13 18:41:13 +08:00
|
|
|
|
{
|
|
|
|
|
struct batadv_orig_node *orig_node;
|
|
|
|
|
long idx = 0;
|
|
|
|
|
|
2018-10-31 05:01:30 +08:00
|
|
|
|
spin_lock_bh(&hash->list_locks[bucket]);
|
|
|
|
|
cb->seq = atomic_read(&hash->generation) << 1 | 1;
|
|
|
|
|
|
|
|
|
|
hlist_for_each_entry(orig_node, &hash->table[bucket], hash_entry) {
|
2018-03-13 18:41:13 +08:00
|
|
|
|
if (!test_bit(BATADV_ORIG_CAPA_HAS_MCAST,
|
|
|
|
|
&orig_node->capa_initialized))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (idx < *idx_skip)
|
|
|
|
|
goto skip;
|
|
|
|
|
|
2018-10-31 05:01:30 +08:00
|
|
|
|
if (batadv_mcast_flags_dump_entry(msg, portid, cb, orig_node)) {
|
|
|
|
|
spin_unlock_bh(&hash->list_locks[bucket]);
|
2018-03-13 18:41:13 +08:00
|
|
|
|
*idx_skip = idx;
|
|
|
|
|
|
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
skip:
|
|
|
|
|
idx++;
|
|
|
|
|
}
|
2018-10-31 05:01:30 +08:00
|
|
|
|
spin_unlock_bh(&hash->list_locks[bucket]);
|
2018-03-13 18:41:13 +08:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* __batadv_mcast_flags_dump() - dump multicast flags table to a netlink socket
|
|
|
|
|
* @msg: buffer for the message
|
|
|
|
|
* @portid: netlink port
|
2018-10-31 05:01:30 +08:00
|
|
|
|
* @cb: Control block containing additional options
|
2018-03-13 18:41:13 +08:00
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
* @bucket: current bucket to dump
|
|
|
|
|
* @idx: index in current bucket to the next entry to dump
|
|
|
|
|
*
|
|
|
|
|
* Return: 0 or error code.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
2018-10-31 05:01:30 +08:00
|
|
|
|
__batadv_mcast_flags_dump(struct sk_buff *msg, u32 portid,
|
|
|
|
|
struct netlink_callback *cb,
|
2018-03-13 18:41:13 +08:00
|
|
|
|
struct batadv_priv *bat_priv, long *bucket, long *idx)
|
|
|
|
|
{
|
|
|
|
|
struct batadv_hashtable *hash = bat_priv->orig_hash;
|
|
|
|
|
long bucket_tmp = *bucket;
|
|
|
|
|
long idx_tmp = *idx;
|
|
|
|
|
|
|
|
|
|
while (bucket_tmp < hash->size) {
|
2018-10-31 05:01:30 +08:00
|
|
|
|
if (batadv_mcast_flags_dump_bucket(msg, portid, cb, hash,
|
2019-07-08 04:15:13 +08:00
|
|
|
|
bucket_tmp, &idx_tmp))
|
2018-03-13 18:41:13 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
bucket_tmp++;
|
|
|
|
|
idx_tmp = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*bucket = bucket_tmp;
|
|
|
|
|
*idx = idx_tmp;
|
|
|
|
|
|
|
|
|
|
return msg->len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* batadv_mcast_netlink_get_primary() - get primary interface from netlink
|
|
|
|
|
* callback
|
|
|
|
|
* @cb: netlink callback structure
|
|
|
|
|
* @primary_if: the primary interface pointer to return the result in
|
|
|
|
|
*
|
|
|
|
|
* Return: 0 or error code.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
batadv_mcast_netlink_get_primary(struct netlink_callback *cb,
|
|
|
|
|
struct batadv_hard_iface **primary_if)
|
|
|
|
|
{
|
|
|
|
|
struct batadv_hard_iface *hard_iface = NULL;
|
|
|
|
|
struct net *net = sock_net(cb->skb->sk);
|
|
|
|
|
struct net_device *soft_iface;
|
|
|
|
|
struct batadv_priv *bat_priv;
|
|
|
|
|
int ifindex;
|
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
|
|
ifindex = batadv_netlink_get_ifindex(cb->nlh, BATADV_ATTR_MESH_IFINDEX);
|
|
|
|
|
if (!ifindex)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
|
|
soft_iface = dev_get_by_index(net, ifindex);
|
|
|
|
|
if (!soft_iface || !batadv_softif_is_valid(soft_iface)) {
|
|
|
|
|
ret = -ENODEV;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bat_priv = netdev_priv(soft_iface);
|
|
|
|
|
|
|
|
|
|
hard_iface = batadv_primary_if_get_selected(bat_priv);
|
|
|
|
|
if (!hard_iface || hard_iface->if_status != BATADV_IF_ACTIVE) {
|
|
|
|
|
ret = -ENOENT;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
2021-08-05 19:55:27 +08:00
|
|
|
|
dev_put(soft_iface);
|
2018-03-13 18:41:13 +08:00
|
|
|
|
|
|
|
|
|
if (!ret && primary_if)
|
|
|
|
|
*primary_if = hard_iface;
|
2021-08-09 01:11:08 +08:00
|
|
|
|
else
|
2018-03-13 18:41:13 +08:00
|
|
|
|
batadv_hardif_put(hard_iface);
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* batadv_mcast_flags_dump() - dump multicast flags table to a netlink socket
|
|
|
|
|
* @msg: buffer for the message
|
|
|
|
|
* @cb: callback structure containing arguments
|
|
|
|
|
*
|
|
|
|
|
* Return: message length.
|
|
|
|
|
*/
|
|
|
|
|
int batadv_mcast_flags_dump(struct sk_buff *msg, struct netlink_callback *cb)
|
|
|
|
|
{
|
|
|
|
|
struct batadv_hard_iface *primary_if = NULL;
|
|
|
|
|
int portid = NETLINK_CB(cb->skb).portid;
|
|
|
|
|
struct batadv_priv *bat_priv;
|
|
|
|
|
long *bucket = &cb->args[0];
|
|
|
|
|
long *idx = &cb->args[1];
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
ret = batadv_mcast_netlink_get_primary(cb, &primary_if);
|
|
|
|
|
if (ret)
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
bat_priv = netdev_priv(primary_if->soft_iface);
|
2018-10-31 05:01:30 +08:00
|
|
|
|
ret = __batadv_mcast_flags_dump(msg, portid, cb, bat_priv, bucket, idx);
|
2018-03-13 18:41:13 +08:00
|
|
|
|
|
|
|
|
|
batadv_hardif_put(primary_if);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-16 00:47:49 +08:00
|
|
|
|
/**
|
2017-12-03 02:51:47 +08:00
|
|
|
|
* batadv_mcast_free() - free the multicast optimizations structures
|
2014-02-16 00:47:49 +08:00
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
|
*/
|
|
|
|
|
void batadv_mcast_free(struct batadv_priv *bat_priv)
|
|
|
|
|
{
|
2016-08-07 04:23:16 +08:00
|
|
|
|
cancel_delayed_work_sync(&bat_priv->mcast.work);
|
|
|
|
|
|
2016-05-11 00:41:24 +08:00
|
|
|
|
batadv_tvlv_container_unregister(bat_priv, BATADV_TVLV_MCAST, 2);
|
2024-01-17 13:22:20 +08:00
|
|
|
|
batadv_tvlv_handler_unregister(bat_priv, BATADV_TVLV_MCAST_TRACKER, 1);
|
2016-05-11 00:41:24 +08:00
|
|
|
|
batadv_tvlv_handler_unregister(bat_priv, BATADV_TVLV_MCAST, 2);
|
2014-02-16 00:47:51 +08:00
|
|
|
|
|
2016-08-07 04:23:16 +08:00
|
|
|
|
/* safely calling outside of worker, as worker was canceled above */
|
2014-02-16 00:47:49 +08:00
|
|
|
|
batadv_mcast_mla_tt_retract(bat_priv, NULL);
|
|
|
|
|
}
|
2014-02-16 00:47:51 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2017-12-03 02:51:47 +08:00
|
|
|
|
* batadv_mcast_purge_orig() - reset originator global mcast state modifications
|
2014-02-16 00:47:51 +08:00
|
|
|
|
* @orig: the originator which is going to get purged
|
|
|
|
|
*/
|
|
|
|
|
void batadv_mcast_purge_orig(struct batadv_orig_node *orig)
|
|
|
|
|
{
|
|
|
|
|
struct batadv_priv *bat_priv = orig->bat_priv;
|
|
|
|
|
|
2015-06-16 23:10:26 +08:00
|
|
|
|
spin_lock_bh(&orig->mcast_handler_lock);
|
|
|
|
|
|
2014-02-16 00:47:53 +08:00
|
|
|
|
batadv_mcast_want_unsnoop_update(bat_priv, orig, BATADV_NO_FLAGS);
|
2014-02-16 00:47:54 +08:00
|
|
|
|
batadv_mcast_want_ipv4_update(bat_priv, orig, BATADV_NO_FLAGS);
|
|
|
|
|
batadv_mcast_want_ipv6_update(bat_priv, orig, BATADV_NO_FLAGS);
|
2019-07-08 05:04:57 +08:00
|
|
|
|
batadv_mcast_want_rtr4_update(bat_priv, orig,
|
|
|
|
|
BATADV_MCAST_WANT_NO_RTR4);
|
|
|
|
|
batadv_mcast_want_rtr6_update(bat_priv, orig,
|
|
|
|
|
BATADV_MCAST_WANT_NO_RTR6);
|
2024-01-10 05:58:59 +08:00
|
|
|
|
batadv_mcast_have_mc_ptype_update(bat_priv, orig,
|
|
|
|
|
BATADV_MCAST_HAVE_MC_PTYPE_CAPA);
|
2015-06-16 23:10:26 +08:00
|
|
|
|
|
|
|
|
|
spin_unlock_bh(&orig->mcast_handler_lock);
|
2014-02-16 00:47:51 +08:00
|
|
|
|
}
|