Sven Eckelmann | 7db7d9f | 2017-11-19 15:05:11 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Sven Eckelmann | 6b1aea8 | 2018-01-01 00:00:00 +0100 | [diff] [blame] | 2 | /* Copyright (C) 2014-2018 B.A.T.M.A.N. contributors: |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 3 | * |
| 4 | * Linus Lüssing |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of version 2 of the GNU General Public |
| 8 | * License as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 19 | #include "multicast.h" |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 20 | #include "main.h" |
| 21 | |
| 22 | #include <linux/atomic.h> |
Linus Lüssing | 9c936e3 | 2015-06-16 17:10:25 +0200 | [diff] [blame] | 23 | #include <linux/bitops.h> |
Linus Lüssing | 8a4023c | 2015-06-16 17:10:26 +0200 | [diff] [blame] | 24 | #include <linux/bug.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 25 | #include <linux/byteorder/generic.h> |
| 26 | #include <linux/errno.h> |
| 27 | #include <linux/etherdevice.h> |
Sven Eckelmann | b92b94a | 2017-11-19 17:12:02 +0100 | [diff] [blame] | 28 | #include <linux/gfp.h> |
Linus Lüssing | bd2a979 | 2016-05-10 18:41:24 +0200 | [diff] [blame] | 29 | #include <linux/icmpv6.h> |
Linus Lüssing | 687937a | 2016-05-10 18:41:25 +0200 | [diff] [blame] | 30 | #include <linux/if_bridge.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 31 | #include <linux/if_ether.h> |
Linus Lüssing | bd2a979 | 2016-05-10 18:41:24 +0200 | [diff] [blame] | 32 | #include <linux/igmp.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 33 | #include <linux/in.h> |
Linus Lüssing | bd2a979 | 2016-05-10 18:41:24 +0200 | [diff] [blame] | 34 | #include <linux/in6.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 35 | #include <linux/ip.h> |
| 36 | #include <linux/ipv6.h> |
Linus Lüssing | cbebd36 | 2016-08-06 22:23:16 +0200 | [diff] [blame] | 37 | #include <linux/jiffies.h> |
Linus Lüssing | 72f7b2d | 2016-05-10 18:41:26 +0200 | [diff] [blame] | 38 | #include <linux/kernel.h> |
Sven Eckelmann | 7c12439 | 2016-01-16 10:29:56 +0100 | [diff] [blame] | 39 | #include <linux/kref.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 40 | #include <linux/list.h> |
Sven Eckelmann | 2c72d65 | 2015-06-21 14:45:14 +0200 | [diff] [blame] | 41 | #include <linux/lockdep.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 42 | #include <linux/netdevice.h> |
Linus Lüssing | 687937a | 2016-05-10 18:41:25 +0200 | [diff] [blame] | 43 | #include <linux/printk.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 44 | #include <linux/rculist.h> |
| 45 | #include <linux/rcupdate.h> |
Linus Lüssing | 4e3e823 | 2016-05-10 18:41:27 +0200 | [diff] [blame] | 46 | #include <linux/seq_file.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 47 | #include <linux/skbuff.h> |
| 48 | #include <linux/slab.h> |
| 49 | #include <linux/spinlock.h> |
| 50 | #include <linux/stddef.h> |
| 51 | #include <linux/string.h> |
| 52 | #include <linux/types.h> |
Linus Lüssing | cbebd36 | 2016-08-06 22:23:16 +0200 | [diff] [blame] | 53 | #include <linux/workqueue.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 54 | #include <net/addrconf.h> |
Linus Lüssing | 687937a | 2016-05-10 18:41:25 +0200 | [diff] [blame] | 55 | #include <net/if_inet6.h> |
| 56 | #include <net/ip.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 57 | #include <net/ipv6.h> |
Sven Eckelmann | fec149f | 2017-12-21 10:17:41 +0100 | [diff] [blame] | 58 | #include <uapi/linux/batadv_packet.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 59 | |
Linus Lüssing | 4e3e823 | 2016-05-10 18:41:27 +0200 | [diff] [blame] | 60 | #include "hard-interface.h" |
| 61 | #include "hash.h" |
Sven Eckelmann | ba41208 | 2016-05-15 23:48:31 +0200 | [diff] [blame] | 62 | #include "log.h" |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 63 | #include "translation-table.h" |
Markus Pargmann | 1f8dce4 | 2016-05-15 11:07:43 +0200 | [diff] [blame] | 64 | #include "tvlv.h" |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 65 | |
Linus Lüssing | cbebd36 | 2016-08-06 22:23:16 +0200 | [diff] [blame] | 66 | static void batadv_mcast_mla_update(struct work_struct *work); |
| 67 | |
| 68 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 69 | * batadv_mcast_start_timer() - schedule the multicast periodic worker |
Linus Lüssing | cbebd36 | 2016-08-06 22:23:16 +0200 | [diff] [blame] | 70 | * @bat_priv: the bat priv with all the soft interface information |
| 71 | */ |
| 72 | static void batadv_mcast_start_timer(struct batadv_priv *bat_priv) |
| 73 | { |
| 74 | queue_delayed_work(batadv_event_workqueue, &bat_priv->mcast.work, |
| 75 | msecs_to_jiffies(BATADV_MCAST_WORK_PERIOD)); |
| 76 | } |
| 77 | |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 78 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 79 | * batadv_mcast_get_bridge() - get the bridge on top of the softif if it exists |
Linus Lüssing | 687937a | 2016-05-10 18:41:25 +0200 | [diff] [blame] | 80 | * @soft_iface: netdev struct of the mesh interface |
| 81 | * |
| 82 | * If the given soft interface has a bridge on top then the refcount |
| 83 | * of the according net device is increased. |
| 84 | * |
| 85 | * Return: NULL if no such bridge exists. Otherwise the net device of the |
| 86 | * bridge. |
| 87 | */ |
| 88 | static struct net_device *batadv_mcast_get_bridge(struct net_device *soft_iface) |
| 89 | { |
| 90 | struct net_device *upper = soft_iface; |
| 91 | |
| 92 | rcu_read_lock(); |
| 93 | do { |
| 94 | upper = netdev_master_upper_dev_get_rcu(upper); |
| 95 | } while (upper && !(upper->priv_flags & IFF_EBRIDGE)); |
| 96 | |
| 97 | if (upper) |
| 98 | dev_hold(upper); |
| 99 | rcu_read_unlock(); |
| 100 | |
| 101 | return upper; |
| 102 | } |
| 103 | |
| 104 | /** |
Linus Lüssing | 6b25360 | 2018-03-04 21:02:18 +0100 | [diff] [blame^] | 105 | * batadv_mcast_addr_is_ipv4() - check if multicast MAC is IPv4 |
| 106 | * @addr: the MAC address to check |
| 107 | * |
| 108 | * Return: True, if MAC address is one reserved for IPv4 multicast, false |
| 109 | * otherwise. |
| 110 | */ |
| 111 | static bool batadv_mcast_addr_is_ipv4(const u8 *addr) |
| 112 | { |
| 113 | static const u8 prefix[] = {0x01, 0x00, 0x5E}; |
| 114 | |
| 115 | return memcmp(prefix, addr, sizeof(prefix)) == 0; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * batadv_mcast_addr_is_ipv6() - check if multicast MAC is IPv6 |
| 120 | * @addr: the MAC address to check |
| 121 | * |
| 122 | * Return: True, if MAC address is one reserved for IPv6 multicast, false |
| 123 | * otherwise. |
| 124 | */ |
| 125 | static bool batadv_mcast_addr_is_ipv6(const u8 *addr) |
| 126 | { |
| 127 | static const u8 prefix[] = {0x33, 0x33}; |
| 128 | |
| 129 | return memcmp(prefix, addr, sizeof(prefix)) == 0; |
| 130 | } |
| 131 | |
| 132 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 133 | * batadv_mcast_mla_softif_get() - get softif multicast listeners |
Linus Lüssing | 6b25360 | 2018-03-04 21:02:18 +0100 | [diff] [blame^] | 134 | * @bat_priv: the bat priv with all the soft interface information |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 135 | * @dev: the device to collect multicast addresses from |
| 136 | * @mcast_list: a list to put found addresses into |
| 137 | * |
Linus Lüssing | 687937a | 2016-05-10 18:41:25 +0200 | [diff] [blame] | 138 | * Collects multicast addresses of multicast listeners residing |
| 139 | * on this kernel on the given soft interface, dev, in |
| 140 | * the given mcast_list. In general, multicast listeners provided by |
| 141 | * your multicast receiving applications run directly on this node. |
| 142 | * |
| 143 | * If there is a bridge interface on top of dev, collects from that one |
| 144 | * instead. Just like with IP addresses and routes, multicast listeners |
| 145 | * will(/should) register to the bridge interface instead of an |
| 146 | * enslaved bat0. |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 147 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 148 | * Return: -ENOMEM on memory allocation error or the number of |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 149 | * items added to the mcast_list otherwise. |
| 150 | */ |
Linus Lüssing | 6b25360 | 2018-03-04 21:02:18 +0100 | [diff] [blame^] | 151 | static int batadv_mcast_mla_softif_get(struct batadv_priv *bat_priv, |
| 152 | struct net_device *dev, |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 153 | struct hlist_head *mcast_list) |
| 154 | { |
Linus Lüssing | 6b25360 | 2018-03-04 21:02:18 +0100 | [diff] [blame^] | 155 | bool all_ipv4 = bat_priv->mcast.flags & BATADV_MCAST_WANT_ALL_IPV4; |
| 156 | bool all_ipv6 = bat_priv->mcast.flags & BATADV_MCAST_WANT_ALL_IPV6; |
Linus Lüssing | 687937a | 2016-05-10 18:41:25 +0200 | [diff] [blame] | 157 | struct net_device *bridge = batadv_mcast_get_bridge(dev); |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 158 | struct netdev_hw_addr *mc_list_entry; |
| 159 | struct batadv_hw_addr *new; |
| 160 | int ret = 0; |
| 161 | |
Linus Lüssing | 687937a | 2016-05-10 18:41:25 +0200 | [diff] [blame] | 162 | netif_addr_lock_bh(bridge ? bridge : dev); |
| 163 | netdev_for_each_mc_addr(mc_list_entry, bridge ? bridge : dev) { |
Linus Lüssing | 6b25360 | 2018-03-04 21:02:18 +0100 | [diff] [blame^] | 164 | if (all_ipv4 && batadv_mcast_addr_is_ipv4(mc_list_entry->addr)) |
| 165 | continue; |
| 166 | |
| 167 | if (all_ipv6 && batadv_mcast_addr_is_ipv6(mc_list_entry->addr)) |
| 168 | continue; |
| 169 | |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 170 | new = kmalloc(sizeof(*new), GFP_ATOMIC); |
| 171 | if (!new) { |
| 172 | ret = -ENOMEM; |
| 173 | break; |
| 174 | } |
| 175 | |
| 176 | ether_addr_copy(new->addr, mc_list_entry->addr); |
| 177 | hlist_add_head(&new->list, mcast_list); |
| 178 | ret++; |
| 179 | } |
Linus Lüssing | 687937a | 2016-05-10 18:41:25 +0200 | [diff] [blame] | 180 | netif_addr_unlock_bh(bridge ? bridge : dev); |
| 181 | |
| 182 | if (bridge) |
| 183 | dev_put(bridge); |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 184 | |
| 185 | return ret; |
| 186 | } |
| 187 | |
| 188 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 189 | * batadv_mcast_mla_is_duplicate() - check whether an address is in a list |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 190 | * @mcast_addr: the multicast address to check |
| 191 | * @mcast_list: the list with multicast addresses to search in |
| 192 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 193 | * Return: true if the given address is already in the given list. |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 194 | * Otherwise returns false. |
| 195 | */ |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 196 | static bool batadv_mcast_mla_is_duplicate(u8 *mcast_addr, |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 197 | struct hlist_head *mcast_list) |
| 198 | { |
| 199 | struct batadv_hw_addr *mcast_entry; |
| 200 | |
| 201 | hlist_for_each_entry(mcast_entry, mcast_list, list) |
| 202 | if (batadv_compare_eth(mcast_entry->addr, mcast_addr)) |
| 203 | return true; |
| 204 | |
| 205 | return false; |
| 206 | } |
| 207 | |
| 208 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 209 | * batadv_mcast_mla_br_addr_cpy() - copy a bridge multicast address |
Linus Lüssing | 687937a | 2016-05-10 18:41:25 +0200 | [diff] [blame] | 210 | * @dst: destination to write to - a multicast MAC address |
| 211 | * @src: source to read from - a multicast IP address |
| 212 | * |
| 213 | * Converts a given multicast IPv4/IPv6 address from a bridge |
| 214 | * to its matching multicast MAC address and copies it into the given |
| 215 | * destination buffer. |
| 216 | * |
| 217 | * Caller needs to make sure the destination buffer can hold |
| 218 | * at least ETH_ALEN bytes. |
| 219 | */ |
| 220 | static void batadv_mcast_mla_br_addr_cpy(char *dst, const struct br_ip *src) |
| 221 | { |
| 222 | if (src->proto == htons(ETH_P_IP)) |
| 223 | ip_eth_mc_map(src->u.ip4, dst); |
| 224 | #if IS_ENABLED(CONFIG_IPV6) |
| 225 | else if (src->proto == htons(ETH_P_IPV6)) |
| 226 | ipv6_eth_mc_map(&src->u.ip6, dst); |
| 227 | #endif |
| 228 | else |
| 229 | eth_zero_addr(dst); |
| 230 | } |
| 231 | |
| 232 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 233 | * batadv_mcast_mla_bridge_get() - get bridged-in multicast listeners |
Linus Lüssing | 6b25360 | 2018-03-04 21:02:18 +0100 | [diff] [blame^] | 234 | * @bat_priv: the bat priv with all the soft interface information |
Linus Lüssing | 687937a | 2016-05-10 18:41:25 +0200 | [diff] [blame] | 235 | * @dev: a bridge slave whose bridge to collect multicast addresses from |
| 236 | * @mcast_list: a list to put found addresses into |
| 237 | * |
| 238 | * Collects multicast addresses of multicast listeners residing |
| 239 | * on foreign, non-mesh devices which we gave access to our mesh via |
| 240 | * a bridge on top of the given soft interface, dev, in the given |
| 241 | * mcast_list. |
| 242 | * |
| 243 | * Return: -ENOMEM on memory allocation error or the number of |
| 244 | * items added to the mcast_list otherwise. |
| 245 | */ |
Linus Lüssing | 6b25360 | 2018-03-04 21:02:18 +0100 | [diff] [blame^] | 246 | static int batadv_mcast_mla_bridge_get(struct batadv_priv *bat_priv, |
| 247 | struct net_device *dev, |
Linus Lüssing | 687937a | 2016-05-10 18:41:25 +0200 | [diff] [blame] | 248 | struct hlist_head *mcast_list) |
| 249 | { |
| 250 | struct list_head bridge_mcast_list = LIST_HEAD_INIT(bridge_mcast_list); |
Linus Lüssing | 6b25360 | 2018-03-04 21:02:18 +0100 | [diff] [blame^] | 251 | bool all_ipv4 = bat_priv->mcast.flags & BATADV_MCAST_WANT_ALL_IPV4; |
| 252 | bool all_ipv6 = bat_priv->mcast.flags & BATADV_MCAST_WANT_ALL_IPV6; |
Linus Lüssing | 687937a | 2016-05-10 18:41:25 +0200 | [diff] [blame] | 253 | struct br_ip_list *br_ip_entry, *tmp; |
| 254 | struct batadv_hw_addr *new; |
| 255 | u8 mcast_addr[ETH_ALEN]; |
| 256 | int ret; |
| 257 | |
| 258 | /* we don't need to detect these devices/listeners, the IGMP/MLD |
| 259 | * snooping code of the Linux bridge already does that for us |
| 260 | */ |
| 261 | ret = br_multicast_list_adjacent(dev, &bridge_mcast_list); |
| 262 | if (ret < 0) |
| 263 | goto out; |
| 264 | |
| 265 | list_for_each_entry(br_ip_entry, &bridge_mcast_list, list) { |
Linus Lüssing | 6b25360 | 2018-03-04 21:02:18 +0100 | [diff] [blame^] | 266 | if (all_ipv4 && br_ip_entry->addr.proto == htons(ETH_P_IP)) |
| 267 | continue; |
| 268 | |
| 269 | if (all_ipv6 && br_ip_entry->addr.proto == htons(ETH_P_IPV6)) |
| 270 | continue; |
| 271 | |
Linus Lüssing | 687937a | 2016-05-10 18:41:25 +0200 | [diff] [blame] | 272 | batadv_mcast_mla_br_addr_cpy(mcast_addr, &br_ip_entry->addr); |
| 273 | if (batadv_mcast_mla_is_duplicate(mcast_addr, mcast_list)) |
| 274 | continue; |
| 275 | |
| 276 | new = kmalloc(sizeof(*new), GFP_ATOMIC); |
| 277 | if (!new) { |
| 278 | ret = -ENOMEM; |
| 279 | break; |
| 280 | } |
| 281 | |
| 282 | ether_addr_copy(new->addr, mcast_addr); |
| 283 | hlist_add_head(&new->list, mcast_list); |
| 284 | } |
| 285 | |
| 286 | out: |
| 287 | list_for_each_entry_safe(br_ip_entry, tmp, &bridge_mcast_list, list) { |
| 288 | list_del(&br_ip_entry->list); |
| 289 | kfree(br_ip_entry); |
| 290 | } |
| 291 | |
| 292 | return ret; |
| 293 | } |
| 294 | |
| 295 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 296 | * batadv_mcast_mla_list_free() - free a list of multicast addresses |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 297 | * @mcast_list: the list to free |
| 298 | * |
| 299 | * Removes and frees all items in the given mcast_list. |
| 300 | */ |
Linus Lüssing | b776976 | 2016-08-06 22:23:15 +0200 | [diff] [blame] | 301 | static void batadv_mcast_mla_list_free(struct hlist_head *mcast_list) |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 302 | { |
| 303 | struct batadv_hw_addr *mcast_entry; |
| 304 | struct hlist_node *tmp; |
| 305 | |
| 306 | hlist_for_each_entry_safe(mcast_entry, tmp, mcast_list, list) { |
| 307 | hlist_del(&mcast_entry->list); |
| 308 | kfree(mcast_entry); |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 313 | * batadv_mcast_mla_tt_retract() - clean up multicast listener announcements |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 314 | * @bat_priv: the bat priv with all the soft interface information |
| 315 | * @mcast_list: a list of addresses which should _not_ be removed |
| 316 | * |
| 317 | * Retracts the announcement of any multicast listener from the |
| 318 | * translation table except the ones listed in the given mcast_list. |
| 319 | * |
| 320 | * If mcast_list is NULL then all are retracted. |
Linus Lüssing | cbebd36 | 2016-08-06 22:23:16 +0200 | [diff] [blame] | 321 | * |
| 322 | * Do not call outside of the mcast worker! (or cancel mcast worker first) |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 323 | */ |
| 324 | static void batadv_mcast_mla_tt_retract(struct batadv_priv *bat_priv, |
| 325 | struct hlist_head *mcast_list) |
| 326 | { |
| 327 | struct batadv_hw_addr *mcast_entry; |
| 328 | struct hlist_node *tmp; |
| 329 | |
Linus Lüssing | cbebd36 | 2016-08-06 22:23:16 +0200 | [diff] [blame] | 330 | WARN_ON(delayed_work_pending(&bat_priv->mcast.work)); |
Sven Eckelmann | 2c72d65 | 2015-06-21 14:45:14 +0200 | [diff] [blame] | 331 | |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 332 | hlist_for_each_entry_safe(mcast_entry, tmp, &bat_priv->mcast.mla_list, |
| 333 | list) { |
| 334 | if (mcast_list && |
| 335 | batadv_mcast_mla_is_duplicate(mcast_entry->addr, |
| 336 | mcast_list)) |
| 337 | continue; |
| 338 | |
| 339 | batadv_tt_local_remove(bat_priv, mcast_entry->addr, |
| 340 | BATADV_NO_FLAGS, |
| 341 | "mcast TT outdated", false); |
| 342 | |
| 343 | hlist_del(&mcast_entry->list); |
| 344 | kfree(mcast_entry); |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 349 | * batadv_mcast_mla_tt_add() - add multicast listener announcements |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 350 | * @bat_priv: the bat priv with all the soft interface information |
| 351 | * @mcast_list: a list of addresses which are going to get added |
| 352 | * |
| 353 | * Adds multicast listener announcements from the given mcast_list to the |
| 354 | * translation table if they have not been added yet. |
Linus Lüssing | cbebd36 | 2016-08-06 22:23:16 +0200 | [diff] [blame] | 355 | * |
| 356 | * Do not call outside of the mcast worker! (or cancel mcast worker first) |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 357 | */ |
| 358 | static void batadv_mcast_mla_tt_add(struct batadv_priv *bat_priv, |
| 359 | struct hlist_head *mcast_list) |
| 360 | { |
| 361 | struct batadv_hw_addr *mcast_entry; |
| 362 | struct hlist_node *tmp; |
| 363 | |
Linus Lüssing | cbebd36 | 2016-08-06 22:23:16 +0200 | [diff] [blame] | 364 | WARN_ON(delayed_work_pending(&bat_priv->mcast.work)); |
Sven Eckelmann | 2c72d65 | 2015-06-21 14:45:14 +0200 | [diff] [blame] | 365 | |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 366 | if (!mcast_list) |
| 367 | return; |
| 368 | |
| 369 | hlist_for_each_entry_safe(mcast_entry, tmp, mcast_list, list) { |
| 370 | if (batadv_mcast_mla_is_duplicate(mcast_entry->addr, |
| 371 | &bat_priv->mcast.mla_list)) |
| 372 | continue; |
| 373 | |
| 374 | if (!batadv_tt_local_add(bat_priv->soft_iface, |
| 375 | mcast_entry->addr, BATADV_NO_FLAGS, |
| 376 | BATADV_NULL_IFINDEX, BATADV_NO_MARK)) |
| 377 | continue; |
| 378 | |
| 379 | hlist_del(&mcast_entry->list); |
| 380 | hlist_add_head(&mcast_entry->list, &bat_priv->mcast.mla_list); |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 385 | * batadv_mcast_has_bridge() - check whether the soft-iface is bridged |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 386 | * @bat_priv: the bat priv with all the soft interface information |
| 387 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 388 | * Checks whether there is a bridge on top of our soft interface. |
| 389 | * |
| 390 | * Return: true if there is a bridge, false otherwise. |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 391 | */ |
| 392 | static bool batadv_mcast_has_bridge(struct batadv_priv *bat_priv) |
| 393 | { |
| 394 | struct net_device *upper = bat_priv->soft_iface; |
| 395 | |
| 396 | rcu_read_lock(); |
| 397 | do { |
| 398 | upper = netdev_master_upper_dev_get_rcu(upper); |
| 399 | } while (upper && !(upper->priv_flags & IFF_EBRIDGE)); |
| 400 | rcu_read_unlock(); |
| 401 | |
| 402 | return upper; |
| 403 | } |
| 404 | |
| 405 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 406 | * batadv_mcast_querier_log() - debug output regarding the querier status on |
| 407 | * link |
Linus Lüssing | 72f7b2d | 2016-05-10 18:41:26 +0200 | [diff] [blame] | 408 | * @bat_priv: the bat priv with all the soft interface information |
| 409 | * @str_proto: a string for the querier protocol (e.g. "IGMP" or "MLD") |
| 410 | * @old_state: the previous querier state on our link |
| 411 | * @new_state: the new querier state on our link |
| 412 | * |
| 413 | * Outputs debug messages to the logging facility with log level 'mcast' |
| 414 | * regarding changes to the querier status on the link which are relevant |
| 415 | * to our multicast optimizations. |
| 416 | * |
| 417 | * Usually this is about whether a querier appeared or vanished in |
| 418 | * our mesh or whether the querier is in the suboptimal position of being |
| 419 | * behind our local bridge segment: Snooping switches will directly |
| 420 | * forward listener reports to the querier, therefore batman-adv and |
| 421 | * the bridge will potentially not see these listeners - the querier is |
| 422 | * potentially shadowing listeners from us then. |
| 423 | * |
| 424 | * This is only interesting for nodes with a bridge on top of their |
| 425 | * soft interface. |
| 426 | */ |
| 427 | static void |
| 428 | batadv_mcast_querier_log(struct batadv_priv *bat_priv, char *str_proto, |
| 429 | struct batadv_mcast_querier_state *old_state, |
| 430 | struct batadv_mcast_querier_state *new_state) |
| 431 | { |
| 432 | if (!old_state->exists && new_state->exists) |
| 433 | batadv_info(bat_priv->soft_iface, "%s Querier appeared\n", |
| 434 | str_proto); |
| 435 | else if (old_state->exists && !new_state->exists) |
| 436 | batadv_info(bat_priv->soft_iface, |
| 437 | "%s Querier disappeared - multicast optimizations disabled\n", |
| 438 | str_proto); |
| 439 | else if (!bat_priv->mcast.bridged && !new_state->exists) |
| 440 | batadv_info(bat_priv->soft_iface, |
| 441 | "No %s Querier present - multicast optimizations disabled\n", |
| 442 | str_proto); |
| 443 | |
| 444 | if (new_state->exists) { |
| 445 | if ((!old_state->shadowing && new_state->shadowing) || |
| 446 | (!old_state->exists && new_state->shadowing)) |
| 447 | batadv_dbg(BATADV_DBG_MCAST, bat_priv, |
| 448 | "%s Querier is behind our bridged segment: Might shadow listeners\n", |
| 449 | str_proto); |
| 450 | else if (old_state->shadowing && !new_state->shadowing) |
| 451 | batadv_dbg(BATADV_DBG_MCAST, bat_priv, |
| 452 | "%s Querier is not behind our bridged segment\n", |
| 453 | str_proto); |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 458 | * batadv_mcast_bridge_log() - debug output for topology changes in bridged |
| 459 | * setups |
Linus Lüssing | 72f7b2d | 2016-05-10 18:41:26 +0200 | [diff] [blame] | 460 | * @bat_priv: the bat priv with all the soft interface information |
| 461 | * @bridged: a flag about whether the soft interface is currently bridged or not |
| 462 | * @querier_ipv4: (maybe) new status of a potential, selected IGMP querier |
| 463 | * @querier_ipv6: (maybe) new status of a potential, selected MLD querier |
| 464 | * |
| 465 | * If no bridges are ever used on this node, then this function does nothing. |
| 466 | * |
| 467 | * Otherwise this function outputs debug information to the 'mcast' log level |
| 468 | * which might be relevant to our multicast optimizations. |
| 469 | * |
| 470 | * More precisely, it outputs information when a bridge interface is added or |
| 471 | * removed from a soft interface. And when a bridge is present, it further |
| 472 | * outputs information about the querier state which is relevant for the |
| 473 | * multicast flags this node is going to set. |
| 474 | */ |
| 475 | static void |
| 476 | batadv_mcast_bridge_log(struct batadv_priv *bat_priv, bool bridged, |
| 477 | struct batadv_mcast_querier_state *querier_ipv4, |
| 478 | struct batadv_mcast_querier_state *querier_ipv6) |
| 479 | { |
| 480 | if (!bat_priv->mcast.bridged && bridged) |
| 481 | batadv_dbg(BATADV_DBG_MCAST, bat_priv, |
| 482 | "Bridge added: Setting Unsnoopables(U)-flag\n"); |
| 483 | else if (bat_priv->mcast.bridged && !bridged) |
| 484 | batadv_dbg(BATADV_DBG_MCAST, bat_priv, |
| 485 | "Bridge removed: Unsetting Unsnoopables(U)-flag\n"); |
| 486 | |
| 487 | if (bridged) { |
| 488 | batadv_mcast_querier_log(bat_priv, "IGMP", |
| 489 | &bat_priv->mcast.querier_ipv4, |
| 490 | querier_ipv4); |
| 491 | batadv_mcast_querier_log(bat_priv, "MLD", |
| 492 | &bat_priv->mcast.querier_ipv6, |
| 493 | querier_ipv6); |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 498 | * batadv_mcast_flags_logs() - output debug information about mcast flag changes |
Linus Lüssing | 72f7b2d | 2016-05-10 18:41:26 +0200 | [diff] [blame] | 499 | * @bat_priv: the bat priv with all the soft interface information |
| 500 | * @flags: flags indicating the new multicast state |
| 501 | * |
| 502 | * Whenever the multicast flags this nodes announces changes (@mcast_flags vs. |
| 503 | * bat_priv->mcast.flags), this notifies userspace via the 'mcast' log level. |
| 504 | */ |
| 505 | static void batadv_mcast_flags_log(struct batadv_priv *bat_priv, u8 flags) |
| 506 | { |
| 507 | u8 old_flags = bat_priv->mcast.flags; |
| 508 | char str_old_flags[] = "[...]"; |
| 509 | |
| 510 | sprintf(str_old_flags, "[%c%c%c]", |
| 511 | (old_flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES) ? 'U' : '.', |
| 512 | (old_flags & BATADV_MCAST_WANT_ALL_IPV4) ? '4' : '.', |
| 513 | (old_flags & BATADV_MCAST_WANT_ALL_IPV6) ? '6' : '.'); |
| 514 | |
| 515 | batadv_dbg(BATADV_DBG_MCAST, bat_priv, |
| 516 | "Changing multicast flags from '%s' to '[%c%c%c]'\n", |
| 517 | bat_priv->mcast.enabled ? str_old_flags : "<undefined>", |
| 518 | (flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES) ? 'U' : '.', |
| 519 | (flags & BATADV_MCAST_WANT_ALL_IPV4) ? '4' : '.', |
| 520 | (flags & BATADV_MCAST_WANT_ALL_IPV6) ? '6' : '.'); |
| 521 | } |
| 522 | |
| 523 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 524 | * batadv_mcast_mla_tvlv_update() - update multicast tvlv |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 525 | * @bat_priv: the bat priv with all the soft interface information |
| 526 | * |
| 527 | * Updates the own multicast tvlv with our current multicast related settings, |
| 528 | * capabilities and inabilities. |
| 529 | * |
Linus Lüssing | 687937a | 2016-05-10 18:41:25 +0200 | [diff] [blame] | 530 | * Return: false if we want all IPv4 && IPv6 multicast traffic and true |
| 531 | * otherwise. |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 532 | */ |
| 533 | static bool batadv_mcast_mla_tvlv_update(struct batadv_priv *bat_priv) |
| 534 | { |
| 535 | struct batadv_tvlv_mcast_data mcast_data; |
Linus Lüssing | 687937a | 2016-05-10 18:41:25 +0200 | [diff] [blame] | 536 | struct batadv_mcast_querier_state querier4 = {false, false}; |
| 537 | struct batadv_mcast_querier_state querier6 = {false, false}; |
| 538 | struct net_device *dev = bat_priv->soft_iface; |
Linus Lüssing | 72f7b2d | 2016-05-10 18:41:26 +0200 | [diff] [blame] | 539 | bool bridged; |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 540 | |
| 541 | mcast_data.flags = BATADV_NO_FLAGS; |
| 542 | memset(mcast_data.reserved, 0, sizeof(mcast_data.reserved)); |
| 543 | |
Linus Lüssing | 72f7b2d | 2016-05-10 18:41:26 +0200 | [diff] [blame] | 544 | bridged = batadv_mcast_has_bridge(bat_priv); |
| 545 | if (!bridged) |
Linus Lüssing | 687937a | 2016-05-10 18:41:25 +0200 | [diff] [blame] | 546 | goto update; |
| 547 | |
Sven Eckelmann | c1bacea | 2017-02-22 17:16:39 +0100 | [diff] [blame] | 548 | if (!IS_ENABLED(CONFIG_BRIDGE_IGMP_SNOOPING)) |
| 549 | pr_warn_once("No bridge IGMP snooping compiled - multicast optimizations disabled\n"); |
Linus Lüssing | 687937a | 2016-05-10 18:41:25 +0200 | [diff] [blame] | 550 | |
| 551 | querier4.exists = br_multicast_has_querier_anywhere(dev, ETH_P_IP); |
| 552 | querier4.shadowing = br_multicast_has_querier_adjacent(dev, ETH_P_IP); |
| 553 | |
| 554 | querier6.exists = br_multicast_has_querier_anywhere(dev, ETH_P_IPV6); |
| 555 | querier6.shadowing = br_multicast_has_querier_adjacent(dev, ETH_P_IPV6); |
| 556 | |
| 557 | mcast_data.flags |= BATADV_MCAST_WANT_ALL_UNSNOOPABLES; |
| 558 | |
| 559 | /* 1) If no querier exists at all, then multicast listeners on |
| 560 | * our local TT clients behind the bridge will keep silent. |
| 561 | * 2) If the selected querier is on one of our local TT clients, |
| 562 | * behind the bridge, then this querier might shadow multicast |
| 563 | * listeners on our local TT clients, behind this bridge. |
| 564 | * |
| 565 | * In both cases, we will signalize other batman nodes that |
| 566 | * we need all multicast traffic of the according protocol. |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 567 | */ |
Linus Lüssing | 687937a | 2016-05-10 18:41:25 +0200 | [diff] [blame] | 568 | if (!querier4.exists || querier4.shadowing) |
| 569 | mcast_data.flags |= BATADV_MCAST_WANT_ALL_IPV4; |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 570 | |
Linus Lüssing | 687937a | 2016-05-10 18:41:25 +0200 | [diff] [blame] | 571 | if (!querier6.exists || querier6.shadowing) |
| 572 | mcast_data.flags |= BATADV_MCAST_WANT_ALL_IPV6; |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 573 | |
Linus Lüssing | 687937a | 2016-05-10 18:41:25 +0200 | [diff] [blame] | 574 | update: |
Linus Lüssing | 72f7b2d | 2016-05-10 18:41:26 +0200 | [diff] [blame] | 575 | batadv_mcast_bridge_log(bat_priv, bridged, &querier4, &querier6); |
| 576 | |
| 577 | bat_priv->mcast.querier_ipv4.exists = querier4.exists; |
| 578 | bat_priv->mcast.querier_ipv4.shadowing = querier4.shadowing; |
| 579 | |
| 580 | bat_priv->mcast.querier_ipv6.exists = querier6.exists; |
| 581 | bat_priv->mcast.querier_ipv6.shadowing = querier6.shadowing; |
| 582 | |
| 583 | bat_priv->mcast.bridged = bridged; |
| 584 | |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 585 | if (!bat_priv->mcast.enabled || |
| 586 | mcast_data.flags != bat_priv->mcast.flags) { |
Linus Lüssing | 72f7b2d | 2016-05-10 18:41:26 +0200 | [diff] [blame] | 587 | batadv_mcast_flags_log(bat_priv, mcast_data.flags); |
Linus Lüssing | bd2a979 | 2016-05-10 18:41:24 +0200 | [diff] [blame] | 588 | batadv_tvlv_container_register(bat_priv, BATADV_TVLV_MCAST, 2, |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 589 | &mcast_data, sizeof(mcast_data)); |
| 590 | bat_priv->mcast.flags = mcast_data.flags; |
| 591 | bat_priv->mcast.enabled = true; |
| 592 | } |
| 593 | |
Linus Lüssing | 687937a | 2016-05-10 18:41:25 +0200 | [diff] [blame] | 594 | return !(mcast_data.flags & |
Linus Lüssing | 4d7de48 | 2016-07-11 11:16:36 +0200 | [diff] [blame] | 595 | (BATADV_MCAST_WANT_ALL_IPV4 | BATADV_MCAST_WANT_ALL_IPV6)); |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 599 | * __batadv_mcast_mla_update() - update the own MLAs |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 600 | * @bat_priv: the bat priv with all the soft interface information |
| 601 | * |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 602 | * Updates the own multicast listener announcements in the translation |
| 603 | * table as well as the own, announced multicast tvlv container. |
Linus Lüssing | cbebd36 | 2016-08-06 22:23:16 +0200 | [diff] [blame] | 604 | * |
| 605 | * Note that non-conflicting reads and writes to bat_priv->mcast.mla_list |
| 606 | * in batadv_mcast_mla_tt_retract() and batadv_mcast_mla_tt_add() are |
| 607 | * ensured by the non-parallel execution of the worker this function |
| 608 | * belongs to. |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 609 | */ |
Linus Lüssing | cbebd36 | 2016-08-06 22:23:16 +0200 | [diff] [blame] | 610 | static void __batadv_mcast_mla_update(struct batadv_priv *bat_priv) |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 611 | { |
| 612 | struct net_device *soft_iface = bat_priv->soft_iface; |
| 613 | struct hlist_head mcast_list = HLIST_HEAD_INIT; |
| 614 | int ret; |
| 615 | |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 616 | if (!batadv_mcast_mla_tvlv_update(bat_priv)) |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 617 | goto update; |
| 618 | |
Linus Lüssing | 6b25360 | 2018-03-04 21:02:18 +0100 | [diff] [blame^] | 619 | ret = batadv_mcast_mla_softif_get(bat_priv, soft_iface, &mcast_list); |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 620 | if (ret < 0) |
| 621 | goto out; |
| 622 | |
Linus Lüssing | 6b25360 | 2018-03-04 21:02:18 +0100 | [diff] [blame^] | 623 | ret = batadv_mcast_mla_bridge_get(bat_priv, soft_iface, &mcast_list); |
Linus Lüssing | 687937a | 2016-05-10 18:41:25 +0200 | [diff] [blame] | 624 | if (ret < 0) |
| 625 | goto out; |
| 626 | |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 627 | update: |
| 628 | batadv_mcast_mla_tt_retract(bat_priv, &mcast_list); |
| 629 | batadv_mcast_mla_tt_add(bat_priv, &mcast_list); |
| 630 | |
| 631 | out: |
Linus Lüssing | b776976 | 2016-08-06 22:23:15 +0200 | [diff] [blame] | 632 | batadv_mcast_mla_list_free(&mcast_list); |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 636 | * batadv_mcast_mla_update() - update the own MLAs |
Linus Lüssing | cbebd36 | 2016-08-06 22:23:16 +0200 | [diff] [blame] | 637 | * @work: kernel work struct |
| 638 | * |
| 639 | * Updates the own multicast listener announcements in the translation |
| 640 | * table as well as the own, announced multicast tvlv container. |
| 641 | * |
| 642 | * In the end, reschedules the work timer. |
| 643 | */ |
| 644 | static void batadv_mcast_mla_update(struct work_struct *work) |
| 645 | { |
| 646 | struct delayed_work *delayed_work; |
| 647 | struct batadv_priv_mcast *priv_mcast; |
| 648 | struct batadv_priv *bat_priv; |
| 649 | |
| 650 | delayed_work = to_delayed_work(work); |
| 651 | priv_mcast = container_of(delayed_work, struct batadv_priv_mcast, work); |
| 652 | bat_priv = container_of(priv_mcast, struct batadv_priv, mcast); |
| 653 | |
| 654 | __batadv_mcast_mla_update(bat_priv); |
| 655 | batadv_mcast_start_timer(bat_priv); |
| 656 | } |
| 657 | |
| 658 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 659 | * batadv_mcast_is_report_ipv4() - check for IGMP reports |
Linus Lüssing | bd2a979 | 2016-05-10 18:41:24 +0200 | [diff] [blame] | 660 | * @skb: the ethernet frame destined for the mesh |
| 661 | * |
| 662 | * This call might reallocate skb data. |
| 663 | * |
| 664 | * Checks whether the given frame is a valid IGMP report. |
| 665 | * |
| 666 | * Return: If so then true, otherwise false. |
| 667 | */ |
| 668 | static bool batadv_mcast_is_report_ipv4(struct sk_buff *skb) |
| 669 | { |
| 670 | if (ip_mc_check_igmp(skb, NULL) < 0) |
| 671 | return false; |
| 672 | |
| 673 | switch (igmp_hdr(skb)->type) { |
| 674 | case IGMP_HOST_MEMBERSHIP_REPORT: |
| 675 | case IGMPV2_HOST_MEMBERSHIP_REPORT: |
| 676 | case IGMPV3_HOST_MEMBERSHIP_REPORT: |
| 677 | return true; |
| 678 | } |
| 679 | |
| 680 | return false; |
| 681 | } |
| 682 | |
| 683 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 684 | * batadv_mcast_forw_mode_check_ipv4() - check for optimized forwarding |
| 685 | * potential |
Linus Lüssing | ab49886 | 2014-02-15 17:47:53 +0100 | [diff] [blame] | 686 | * @bat_priv: the bat priv with all the soft interface information |
| 687 | * @skb: the IPv4 packet to check |
| 688 | * @is_unsnoopable: stores whether the destination is snoopable |
| 689 | * |
| 690 | * Checks whether the given IPv4 packet has the potential to be forwarded with a |
| 691 | * mode more optimal than classic flooding. |
| 692 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 693 | * Return: If so then 0. Otherwise -EINVAL or -ENOMEM in case of memory |
| 694 | * allocation failure. |
Linus Lüssing | ab49886 | 2014-02-15 17:47:53 +0100 | [diff] [blame] | 695 | */ |
| 696 | static int batadv_mcast_forw_mode_check_ipv4(struct batadv_priv *bat_priv, |
| 697 | struct sk_buff *skb, |
| 698 | bool *is_unsnoopable) |
| 699 | { |
| 700 | struct iphdr *iphdr; |
| 701 | |
| 702 | /* We might fail due to out-of-memory -> drop it */ |
| 703 | if (!pskb_may_pull(skb, sizeof(struct ethhdr) + sizeof(*iphdr))) |
| 704 | return -ENOMEM; |
| 705 | |
Linus Lüssing | bd2a979 | 2016-05-10 18:41:24 +0200 | [diff] [blame] | 706 | if (batadv_mcast_is_report_ipv4(skb)) |
| 707 | return -EINVAL; |
| 708 | |
Linus Lüssing | ab49886 | 2014-02-15 17:47:53 +0100 | [diff] [blame] | 709 | iphdr = ip_hdr(skb); |
| 710 | |
| 711 | /* TODO: Implement Multicast Router Discovery (RFC4286), |
| 712 | * then allow scope > link local, too |
| 713 | */ |
| 714 | if (!ipv4_is_local_multicast(iphdr->daddr)) |
| 715 | return -EINVAL; |
| 716 | |
| 717 | /* link-local multicast listeners behind a bridge are |
| 718 | * not snoopable (see RFC4541, section 2.1.2.2) |
| 719 | */ |
| 720 | *is_unsnoopable = true; |
| 721 | |
| 722 | return 0; |
| 723 | } |
| 724 | |
Linus Lüssing | bd2a979 | 2016-05-10 18:41:24 +0200 | [diff] [blame] | 725 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 726 | * batadv_mcast_is_report_ipv6() - check for MLD reports |
Linus Lüssing | bd2a979 | 2016-05-10 18:41:24 +0200 | [diff] [blame] | 727 | * @skb: the ethernet frame destined for the mesh |
| 728 | * |
| 729 | * This call might reallocate skb data. |
| 730 | * |
| 731 | * Checks whether the given frame is a valid MLD report. |
| 732 | * |
| 733 | * Return: If so then true, otherwise false. |
| 734 | */ |
| 735 | static bool batadv_mcast_is_report_ipv6(struct sk_buff *skb) |
| 736 | { |
| 737 | if (ipv6_mc_check_mld(skb, NULL) < 0) |
| 738 | return false; |
| 739 | |
| 740 | switch (icmp6_hdr(skb)->icmp6_type) { |
| 741 | case ICMPV6_MGM_REPORT: |
| 742 | case ICMPV6_MLD2_REPORT: |
| 743 | return true; |
| 744 | } |
| 745 | |
| 746 | return false; |
| 747 | } |
| 748 | |
Linus Lüssing | ab49886 | 2014-02-15 17:47:53 +0100 | [diff] [blame] | 749 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 750 | * batadv_mcast_forw_mode_check_ipv6() - check for optimized forwarding |
| 751 | * potential |
Linus Lüssing | 1d8ab8d | 2014-02-15 17:47:52 +0100 | [diff] [blame] | 752 | * @bat_priv: the bat priv with all the soft interface information |
| 753 | * @skb: the IPv6 packet to check |
Linus Lüssing | ab49886 | 2014-02-15 17:47:53 +0100 | [diff] [blame] | 754 | * @is_unsnoopable: stores whether the destination is snoopable |
Linus Lüssing | 1d8ab8d | 2014-02-15 17:47:52 +0100 | [diff] [blame] | 755 | * |
| 756 | * Checks whether the given IPv6 packet has the potential to be forwarded with a |
| 757 | * mode more optimal than classic flooding. |
| 758 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 759 | * Return: If so then 0. Otherwise -EINVAL is or -ENOMEM if we are out of memory |
Linus Lüssing | 1d8ab8d | 2014-02-15 17:47:52 +0100 | [diff] [blame] | 760 | */ |
| 761 | static int batadv_mcast_forw_mode_check_ipv6(struct batadv_priv *bat_priv, |
Linus Lüssing | ab49886 | 2014-02-15 17:47:53 +0100 | [diff] [blame] | 762 | struct sk_buff *skb, |
| 763 | bool *is_unsnoopable) |
Linus Lüssing | 1d8ab8d | 2014-02-15 17:47:52 +0100 | [diff] [blame] | 764 | { |
| 765 | struct ipv6hdr *ip6hdr; |
| 766 | |
| 767 | /* We might fail due to out-of-memory -> drop it */ |
| 768 | if (!pskb_may_pull(skb, sizeof(struct ethhdr) + sizeof(*ip6hdr))) |
| 769 | return -ENOMEM; |
| 770 | |
Linus Lüssing | bd2a979 | 2016-05-10 18:41:24 +0200 | [diff] [blame] | 771 | if (batadv_mcast_is_report_ipv6(skb)) |
| 772 | return -EINVAL; |
| 773 | |
Linus Lüssing | 1d8ab8d | 2014-02-15 17:47:52 +0100 | [diff] [blame] | 774 | ip6hdr = ipv6_hdr(skb); |
| 775 | |
| 776 | /* TODO: Implement Multicast Router Discovery (RFC4286), |
| 777 | * then allow scope > link local, too |
| 778 | */ |
| 779 | if (IPV6_ADDR_MC_SCOPE(&ip6hdr->daddr) != IPV6_ADDR_SCOPE_LINKLOCAL) |
| 780 | return -EINVAL; |
| 781 | |
| 782 | /* link-local-all-nodes multicast listeners behind a bridge are |
| 783 | * not snoopable (see RFC4541, section 3, paragraph 3) |
| 784 | */ |
| 785 | if (ipv6_addr_is_ll_all_nodes(&ip6hdr->daddr)) |
Linus Lüssing | ab49886 | 2014-02-15 17:47:53 +0100 | [diff] [blame] | 786 | *is_unsnoopable = true; |
Linus Lüssing | 1d8ab8d | 2014-02-15 17:47:52 +0100 | [diff] [blame] | 787 | |
| 788 | return 0; |
| 789 | } |
| 790 | |
| 791 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 792 | * batadv_mcast_forw_mode_check() - check for optimized forwarding potential |
Linus Lüssing | 1d8ab8d | 2014-02-15 17:47:52 +0100 | [diff] [blame] | 793 | * @bat_priv: the bat priv with all the soft interface information |
| 794 | * @skb: the multicast frame to check |
Linus Lüssing | ab49886 | 2014-02-15 17:47:53 +0100 | [diff] [blame] | 795 | * @is_unsnoopable: stores whether the destination is snoopable |
Linus Lüssing | 1d8ab8d | 2014-02-15 17:47:52 +0100 | [diff] [blame] | 796 | * |
| 797 | * Checks whether the given multicast ethernet frame has the potential to be |
| 798 | * forwarded with a mode more optimal than classic flooding. |
| 799 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 800 | * Return: If so then 0. Otherwise -EINVAL is or -ENOMEM if we are out of memory |
Linus Lüssing | 1d8ab8d | 2014-02-15 17:47:52 +0100 | [diff] [blame] | 801 | */ |
| 802 | static int batadv_mcast_forw_mode_check(struct batadv_priv *bat_priv, |
Linus Lüssing | ab49886 | 2014-02-15 17:47:53 +0100 | [diff] [blame] | 803 | struct sk_buff *skb, |
| 804 | bool *is_unsnoopable) |
Linus Lüssing | 1d8ab8d | 2014-02-15 17:47:52 +0100 | [diff] [blame] | 805 | { |
| 806 | struct ethhdr *ethhdr = eth_hdr(skb); |
| 807 | |
| 808 | if (!atomic_read(&bat_priv->multicast_mode)) |
| 809 | return -EINVAL; |
| 810 | |
| 811 | if (atomic_read(&bat_priv->mcast.num_disabled)) |
| 812 | return -EINVAL; |
| 813 | |
| 814 | switch (ntohs(ethhdr->h_proto)) { |
Linus Lüssing | ab49886 | 2014-02-15 17:47:53 +0100 | [diff] [blame] | 815 | case ETH_P_IP: |
| 816 | return batadv_mcast_forw_mode_check_ipv4(bat_priv, skb, |
| 817 | is_unsnoopable); |
Linus Lüssing | 1d8ab8d | 2014-02-15 17:47:52 +0100 | [diff] [blame] | 818 | case ETH_P_IPV6: |
Sven Eckelmann | c1bacea | 2017-02-22 17:16:39 +0100 | [diff] [blame] | 819 | if (!IS_ENABLED(CONFIG_IPV6)) |
| 820 | return -EINVAL; |
| 821 | |
Linus Lüssing | ab49886 | 2014-02-15 17:47:53 +0100 | [diff] [blame] | 822 | return batadv_mcast_forw_mode_check_ipv6(bat_priv, skb, |
| 823 | is_unsnoopable); |
Linus Lüssing | 1d8ab8d | 2014-02-15 17:47:52 +0100 | [diff] [blame] | 824 | default: |
| 825 | return -EINVAL; |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 830 | * batadv_mcast_forw_want_all_ip_count() - count nodes with unspecific mcast |
Antonio Quartulli | 6d030de | 2016-03-11 16:36:19 +0100 | [diff] [blame] | 831 | * interest |
Linus Lüssing | 4c8755d | 2014-02-15 17:47:54 +0100 | [diff] [blame] | 832 | * @bat_priv: the bat priv with all the soft interface information |
| 833 | * @ethhdr: ethernet header of a packet |
| 834 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 835 | * Return: the number of nodes which want all IPv4 multicast traffic if the |
Linus Lüssing | 4c8755d | 2014-02-15 17:47:54 +0100 | [diff] [blame] | 836 | * given ethhdr is from an IPv4 packet or the number of nodes which want all |
| 837 | * IPv6 traffic if it matches an IPv6 packet. |
| 838 | */ |
| 839 | static int batadv_mcast_forw_want_all_ip_count(struct batadv_priv *bat_priv, |
| 840 | struct ethhdr *ethhdr) |
| 841 | { |
| 842 | switch (ntohs(ethhdr->h_proto)) { |
| 843 | case ETH_P_IP: |
| 844 | return atomic_read(&bat_priv->mcast.num_want_all_ipv4); |
| 845 | case ETH_P_IPV6: |
| 846 | return atomic_read(&bat_priv->mcast.num_want_all_ipv6); |
| 847 | default: |
| 848 | /* we shouldn't be here... */ |
| 849 | return 0; |
| 850 | } |
| 851 | } |
| 852 | |
| 853 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 854 | * batadv_mcast_forw_tt_node_get() - get a multicast tt node |
Linus Lüssing | 1d8ab8d | 2014-02-15 17:47:52 +0100 | [diff] [blame] | 855 | * @bat_priv: the bat priv with all the soft interface information |
| 856 | * @ethhdr: the ether header containing the multicast destination |
| 857 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 858 | * Return: an orig_node matching the multicast address provided by ethhdr |
Linus Lüssing | 1d8ab8d | 2014-02-15 17:47:52 +0100 | [diff] [blame] | 859 | * via a translation table lookup. This increases the returned nodes refcount. |
| 860 | */ |
| 861 | static struct batadv_orig_node * |
| 862 | batadv_mcast_forw_tt_node_get(struct batadv_priv *bat_priv, |
| 863 | struct ethhdr *ethhdr) |
| 864 | { |
| 865 | return batadv_transtable_search(bat_priv, ethhdr->h_source, |
| 866 | ethhdr->h_dest, BATADV_NO_FLAGS); |
| 867 | } |
| 868 | |
| 869 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 870 | * batadv_mcast_forw_ipv4_node_get() - get a node with an ipv4 flag |
Linus Lüssing | 4c8755d | 2014-02-15 17:47:54 +0100 | [diff] [blame] | 871 | * @bat_priv: the bat priv with all the soft interface information |
| 872 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 873 | * Return: an orig_node which has the BATADV_MCAST_WANT_ALL_IPV4 flag set and |
Linus Lüssing | 4c8755d | 2014-02-15 17:47:54 +0100 | [diff] [blame] | 874 | * increases its refcount. |
| 875 | */ |
| 876 | static struct batadv_orig_node * |
| 877 | batadv_mcast_forw_ipv4_node_get(struct batadv_priv *bat_priv) |
| 878 | { |
| 879 | struct batadv_orig_node *tmp_orig_node, *orig_node = NULL; |
| 880 | |
| 881 | rcu_read_lock(); |
| 882 | hlist_for_each_entry_rcu(tmp_orig_node, |
| 883 | &bat_priv->mcast.want_all_ipv4_list, |
| 884 | mcast_want_all_ipv4_node) { |
Sven Eckelmann | 7c12439 | 2016-01-16 10:29:56 +0100 | [diff] [blame] | 885 | if (!kref_get_unless_zero(&tmp_orig_node->refcount)) |
Linus Lüssing | 4c8755d | 2014-02-15 17:47:54 +0100 | [diff] [blame] | 886 | continue; |
| 887 | |
| 888 | orig_node = tmp_orig_node; |
| 889 | break; |
| 890 | } |
| 891 | rcu_read_unlock(); |
| 892 | |
| 893 | return orig_node; |
| 894 | } |
| 895 | |
| 896 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 897 | * batadv_mcast_forw_ipv6_node_get() - get a node with an ipv6 flag |
Linus Lüssing | 4c8755d | 2014-02-15 17:47:54 +0100 | [diff] [blame] | 898 | * @bat_priv: the bat priv with all the soft interface information |
| 899 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 900 | * Return: an orig_node which has the BATADV_MCAST_WANT_ALL_IPV6 flag set |
Linus Lüssing | 4c8755d | 2014-02-15 17:47:54 +0100 | [diff] [blame] | 901 | * and increases its refcount. |
| 902 | */ |
| 903 | static struct batadv_orig_node * |
| 904 | batadv_mcast_forw_ipv6_node_get(struct batadv_priv *bat_priv) |
| 905 | { |
| 906 | struct batadv_orig_node *tmp_orig_node, *orig_node = NULL; |
| 907 | |
| 908 | rcu_read_lock(); |
| 909 | hlist_for_each_entry_rcu(tmp_orig_node, |
| 910 | &bat_priv->mcast.want_all_ipv6_list, |
| 911 | mcast_want_all_ipv6_node) { |
Sven Eckelmann | 7c12439 | 2016-01-16 10:29:56 +0100 | [diff] [blame] | 912 | if (!kref_get_unless_zero(&tmp_orig_node->refcount)) |
Linus Lüssing | 4c8755d | 2014-02-15 17:47:54 +0100 | [diff] [blame] | 913 | continue; |
| 914 | |
| 915 | orig_node = tmp_orig_node; |
| 916 | break; |
| 917 | } |
| 918 | rcu_read_unlock(); |
| 919 | |
| 920 | return orig_node; |
| 921 | } |
| 922 | |
| 923 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 924 | * batadv_mcast_forw_ip_node_get() - get a node with an ipv4/ipv6 flag |
Linus Lüssing | 4c8755d | 2014-02-15 17:47:54 +0100 | [diff] [blame] | 925 | * @bat_priv: the bat priv with all the soft interface information |
| 926 | * @ethhdr: an ethernet header to determine the protocol family from |
| 927 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 928 | * Return: an orig_node which has the BATADV_MCAST_WANT_ALL_IPV4 or |
Linus Lüssing | 4c8755d | 2014-02-15 17:47:54 +0100 | [diff] [blame] | 929 | * BATADV_MCAST_WANT_ALL_IPV6 flag, depending on the provided ethhdr, set and |
| 930 | * increases its refcount. |
| 931 | */ |
| 932 | static struct batadv_orig_node * |
| 933 | batadv_mcast_forw_ip_node_get(struct batadv_priv *bat_priv, |
| 934 | struct ethhdr *ethhdr) |
| 935 | { |
| 936 | switch (ntohs(ethhdr->h_proto)) { |
| 937 | case ETH_P_IP: |
| 938 | return batadv_mcast_forw_ipv4_node_get(bat_priv); |
| 939 | case ETH_P_IPV6: |
| 940 | return batadv_mcast_forw_ipv6_node_get(bat_priv); |
| 941 | default: |
| 942 | /* we shouldn't be here... */ |
| 943 | return NULL; |
| 944 | } |
| 945 | } |
| 946 | |
| 947 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 948 | * batadv_mcast_forw_unsnoop_node_get() - get a node with an unsnoopable flag |
Linus Lüssing | ab49886 | 2014-02-15 17:47:53 +0100 | [diff] [blame] | 949 | * @bat_priv: the bat priv with all the soft interface information |
| 950 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 951 | * Return: an orig_node which has the BATADV_MCAST_WANT_ALL_UNSNOOPABLES flag |
Linus Lüssing | ab49886 | 2014-02-15 17:47:53 +0100 | [diff] [blame] | 952 | * set and increases its refcount. |
| 953 | */ |
| 954 | static struct batadv_orig_node * |
| 955 | batadv_mcast_forw_unsnoop_node_get(struct batadv_priv *bat_priv) |
| 956 | { |
| 957 | struct batadv_orig_node *tmp_orig_node, *orig_node = NULL; |
| 958 | |
| 959 | rcu_read_lock(); |
| 960 | hlist_for_each_entry_rcu(tmp_orig_node, |
| 961 | &bat_priv->mcast.want_all_unsnoopables_list, |
| 962 | mcast_want_all_unsnoopables_node) { |
Sven Eckelmann | 7c12439 | 2016-01-16 10:29:56 +0100 | [diff] [blame] | 963 | if (!kref_get_unless_zero(&tmp_orig_node->refcount)) |
Linus Lüssing | ab49886 | 2014-02-15 17:47:53 +0100 | [diff] [blame] | 964 | continue; |
| 965 | |
| 966 | orig_node = tmp_orig_node; |
| 967 | break; |
| 968 | } |
| 969 | rcu_read_unlock(); |
| 970 | |
| 971 | return orig_node; |
| 972 | } |
| 973 | |
| 974 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 975 | * batadv_mcast_forw_mode() - check on how to forward a multicast packet |
Linus Lüssing | 1d8ab8d | 2014-02-15 17:47:52 +0100 | [diff] [blame] | 976 | * @bat_priv: the bat priv with all the soft interface information |
| 977 | * @skb: The multicast packet to check |
| 978 | * @orig: an originator to be set to forward the skb to |
| 979 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 980 | * Return: the forwarding mode as enum batadv_forw_mode and in case of |
Linus Lüssing | 1d8ab8d | 2014-02-15 17:47:52 +0100 | [diff] [blame] | 981 | * BATADV_FORW_SINGLE set the orig to the single originator the skb |
| 982 | * should be forwarded to. |
| 983 | */ |
| 984 | enum batadv_forw_mode |
| 985 | batadv_mcast_forw_mode(struct batadv_priv *bat_priv, struct sk_buff *skb, |
| 986 | struct batadv_orig_node **orig) |
| 987 | { |
Linus Lüssing | 4c8755d | 2014-02-15 17:47:54 +0100 | [diff] [blame] | 988 | int ret, tt_count, ip_count, unsnoop_count, total_count; |
Linus Lüssing | ab49886 | 2014-02-15 17:47:53 +0100 | [diff] [blame] | 989 | bool is_unsnoopable = false; |
Linus Lüssing | 1d8ab8d | 2014-02-15 17:47:52 +0100 | [diff] [blame] | 990 | struct ethhdr *ethhdr; |
Linus Lüssing | 1d8ab8d | 2014-02-15 17:47:52 +0100 | [diff] [blame] | 991 | |
Linus Lüssing | ab49886 | 2014-02-15 17:47:53 +0100 | [diff] [blame] | 992 | ret = batadv_mcast_forw_mode_check(bat_priv, skb, &is_unsnoopable); |
Linus Lüssing | 1d8ab8d | 2014-02-15 17:47:52 +0100 | [diff] [blame] | 993 | if (ret == -ENOMEM) |
| 994 | return BATADV_FORW_NONE; |
| 995 | else if (ret < 0) |
| 996 | return BATADV_FORW_ALL; |
| 997 | |
| 998 | ethhdr = eth_hdr(skb); |
| 999 | |
| 1000 | tt_count = batadv_tt_global_hash_count(bat_priv, ethhdr->h_dest, |
| 1001 | BATADV_NO_FLAGS); |
Linus Lüssing | 4c8755d | 2014-02-15 17:47:54 +0100 | [diff] [blame] | 1002 | ip_count = batadv_mcast_forw_want_all_ip_count(bat_priv, ethhdr); |
Linus Lüssing | ab49886 | 2014-02-15 17:47:53 +0100 | [diff] [blame] | 1003 | unsnoop_count = !is_unsnoopable ? 0 : |
| 1004 | atomic_read(&bat_priv->mcast.num_want_all_unsnoopables); |
Linus Lüssing | 1d8ab8d | 2014-02-15 17:47:52 +0100 | [diff] [blame] | 1005 | |
Linus Lüssing | 4c8755d | 2014-02-15 17:47:54 +0100 | [diff] [blame] | 1006 | total_count = tt_count + ip_count + unsnoop_count; |
Linus Lüssing | ab49886 | 2014-02-15 17:47:53 +0100 | [diff] [blame] | 1007 | |
| 1008 | switch (total_count) { |
Linus Lüssing | 1d8ab8d | 2014-02-15 17:47:52 +0100 | [diff] [blame] | 1009 | case 1: |
Linus Lüssing | ab49886 | 2014-02-15 17:47:53 +0100 | [diff] [blame] | 1010 | if (tt_count) |
| 1011 | *orig = batadv_mcast_forw_tt_node_get(bat_priv, ethhdr); |
Linus Lüssing | 4c8755d | 2014-02-15 17:47:54 +0100 | [diff] [blame] | 1012 | else if (ip_count) |
| 1013 | *orig = batadv_mcast_forw_ip_node_get(bat_priv, ethhdr); |
Linus Lüssing | ab49886 | 2014-02-15 17:47:53 +0100 | [diff] [blame] | 1014 | else if (unsnoop_count) |
| 1015 | *orig = batadv_mcast_forw_unsnoop_node_get(bat_priv); |
| 1016 | |
Linus Lüssing | 1d8ab8d | 2014-02-15 17:47:52 +0100 | [diff] [blame] | 1017 | if (*orig) |
| 1018 | return BATADV_FORW_SINGLE; |
| 1019 | |
| 1020 | /* fall through */ |
| 1021 | case 0: |
| 1022 | return BATADV_FORW_NONE; |
| 1023 | default: |
| 1024 | return BATADV_FORW_ALL; |
| 1025 | } |
| 1026 | } |
| 1027 | |
| 1028 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 1029 | * batadv_mcast_want_unsnoop_update() - update unsnoop counter and list |
Linus Lüssing | ab49886 | 2014-02-15 17:47:53 +0100 | [diff] [blame] | 1030 | * @bat_priv: the bat priv with all the soft interface information |
| 1031 | * @orig: the orig_node which multicast state might have changed of |
| 1032 | * @mcast_flags: flags indicating the new multicast state |
| 1033 | * |
| 1034 | * If the BATADV_MCAST_WANT_ALL_UNSNOOPABLES flag of this originator, |
| 1035 | * orig, has toggled then this method updates counter and list accordingly. |
Linus Lüssing | 8a4023c | 2015-06-16 17:10:26 +0200 | [diff] [blame] | 1036 | * |
| 1037 | * Caller needs to hold orig->mcast_handler_lock. |
Linus Lüssing | ab49886 | 2014-02-15 17:47:53 +0100 | [diff] [blame] | 1038 | */ |
| 1039 | static void batadv_mcast_want_unsnoop_update(struct batadv_priv *bat_priv, |
| 1040 | struct batadv_orig_node *orig, |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 1041 | u8 mcast_flags) |
Linus Lüssing | ab49886 | 2014-02-15 17:47:53 +0100 | [diff] [blame] | 1042 | { |
Linus Lüssing | 8a4023c | 2015-06-16 17:10:26 +0200 | [diff] [blame] | 1043 | struct hlist_node *node = &orig->mcast_want_all_unsnoopables_node; |
| 1044 | struct hlist_head *head = &bat_priv->mcast.want_all_unsnoopables_list; |
| 1045 | |
Sven Eckelmann | 5274cd6 | 2015-06-21 14:45:15 +0200 | [diff] [blame] | 1046 | lockdep_assert_held(&orig->mcast_handler_lock); |
| 1047 | |
Linus Lüssing | ab49886 | 2014-02-15 17:47:53 +0100 | [diff] [blame] | 1048 | /* switched from flag unset to set */ |
| 1049 | if (mcast_flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES && |
| 1050 | !(orig->mcast_flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES)) { |
| 1051 | atomic_inc(&bat_priv->mcast.num_want_all_unsnoopables); |
| 1052 | |
| 1053 | spin_lock_bh(&bat_priv->mcast.want_lists_lock); |
Linus Lüssing | 8a4023c | 2015-06-16 17:10:26 +0200 | [diff] [blame] | 1054 | /* flag checks above + mcast_handler_lock prevents this */ |
| 1055 | WARN_ON(!hlist_unhashed(node)); |
| 1056 | |
| 1057 | hlist_add_head_rcu(node, head); |
Linus Lüssing | ab49886 | 2014-02-15 17:47:53 +0100 | [diff] [blame] | 1058 | spin_unlock_bh(&bat_priv->mcast.want_lists_lock); |
| 1059 | /* switched from flag set to unset */ |
| 1060 | } else if (!(mcast_flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES) && |
| 1061 | orig->mcast_flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES) { |
| 1062 | atomic_dec(&bat_priv->mcast.num_want_all_unsnoopables); |
| 1063 | |
| 1064 | spin_lock_bh(&bat_priv->mcast.want_lists_lock); |
Linus Lüssing | 8a4023c | 2015-06-16 17:10:26 +0200 | [diff] [blame] | 1065 | /* flag checks above + mcast_handler_lock prevents this */ |
| 1066 | WARN_ON(hlist_unhashed(node)); |
| 1067 | |
| 1068 | hlist_del_init_rcu(node); |
Linus Lüssing | ab49886 | 2014-02-15 17:47:53 +0100 | [diff] [blame] | 1069 | spin_unlock_bh(&bat_priv->mcast.want_lists_lock); |
| 1070 | } |
| 1071 | } |
| 1072 | |
| 1073 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 1074 | * batadv_mcast_want_ipv4_update() - update want-all-ipv4 counter and list |
Linus Lüssing | 4c8755d | 2014-02-15 17:47:54 +0100 | [diff] [blame] | 1075 | * @bat_priv: the bat priv with all the soft interface information |
| 1076 | * @orig: the orig_node which multicast state might have changed of |
| 1077 | * @mcast_flags: flags indicating the new multicast state |
| 1078 | * |
| 1079 | * If the BATADV_MCAST_WANT_ALL_IPV4 flag of this originator, orig, has |
| 1080 | * toggled then this method updates counter and list accordingly. |
Linus Lüssing | 8a4023c | 2015-06-16 17:10:26 +0200 | [diff] [blame] | 1081 | * |
| 1082 | * Caller needs to hold orig->mcast_handler_lock. |
Linus Lüssing | 4c8755d | 2014-02-15 17:47:54 +0100 | [diff] [blame] | 1083 | */ |
| 1084 | static void batadv_mcast_want_ipv4_update(struct batadv_priv *bat_priv, |
| 1085 | struct batadv_orig_node *orig, |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 1086 | u8 mcast_flags) |
Linus Lüssing | 4c8755d | 2014-02-15 17:47:54 +0100 | [diff] [blame] | 1087 | { |
Linus Lüssing | 8a4023c | 2015-06-16 17:10:26 +0200 | [diff] [blame] | 1088 | struct hlist_node *node = &orig->mcast_want_all_ipv4_node; |
| 1089 | struct hlist_head *head = &bat_priv->mcast.want_all_ipv4_list; |
| 1090 | |
Sven Eckelmann | 5274cd6 | 2015-06-21 14:45:15 +0200 | [diff] [blame] | 1091 | lockdep_assert_held(&orig->mcast_handler_lock); |
| 1092 | |
Linus Lüssing | 4c8755d | 2014-02-15 17:47:54 +0100 | [diff] [blame] | 1093 | /* switched from flag unset to set */ |
| 1094 | if (mcast_flags & BATADV_MCAST_WANT_ALL_IPV4 && |
| 1095 | !(orig->mcast_flags & BATADV_MCAST_WANT_ALL_IPV4)) { |
| 1096 | atomic_inc(&bat_priv->mcast.num_want_all_ipv4); |
| 1097 | |
| 1098 | spin_lock_bh(&bat_priv->mcast.want_lists_lock); |
Linus Lüssing | 8a4023c | 2015-06-16 17:10:26 +0200 | [diff] [blame] | 1099 | /* flag checks above + mcast_handler_lock prevents this */ |
| 1100 | WARN_ON(!hlist_unhashed(node)); |
| 1101 | |
| 1102 | hlist_add_head_rcu(node, head); |
Linus Lüssing | 4c8755d | 2014-02-15 17:47:54 +0100 | [diff] [blame] | 1103 | spin_unlock_bh(&bat_priv->mcast.want_lists_lock); |
| 1104 | /* switched from flag set to unset */ |
| 1105 | } else if (!(mcast_flags & BATADV_MCAST_WANT_ALL_IPV4) && |
| 1106 | orig->mcast_flags & BATADV_MCAST_WANT_ALL_IPV4) { |
| 1107 | atomic_dec(&bat_priv->mcast.num_want_all_ipv4); |
| 1108 | |
| 1109 | spin_lock_bh(&bat_priv->mcast.want_lists_lock); |
Linus Lüssing | 8a4023c | 2015-06-16 17:10:26 +0200 | [diff] [blame] | 1110 | /* flag checks above + mcast_handler_lock prevents this */ |
| 1111 | WARN_ON(hlist_unhashed(node)); |
| 1112 | |
| 1113 | hlist_del_init_rcu(node); |
Linus Lüssing | 4c8755d | 2014-02-15 17:47:54 +0100 | [diff] [blame] | 1114 | spin_unlock_bh(&bat_priv->mcast.want_lists_lock); |
| 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 1119 | * batadv_mcast_want_ipv6_update() - update want-all-ipv6 counter and list |
Linus Lüssing | 4c8755d | 2014-02-15 17:47:54 +0100 | [diff] [blame] | 1120 | * @bat_priv: the bat priv with all the soft interface information |
| 1121 | * @orig: the orig_node which multicast state might have changed of |
| 1122 | * @mcast_flags: flags indicating the new multicast state |
| 1123 | * |
| 1124 | * If the BATADV_MCAST_WANT_ALL_IPV6 flag of this originator, orig, has |
| 1125 | * toggled then this method updates counter and list accordingly. |
Linus Lüssing | 8a4023c | 2015-06-16 17:10:26 +0200 | [diff] [blame] | 1126 | * |
| 1127 | * Caller needs to hold orig->mcast_handler_lock. |
Linus Lüssing | 4c8755d | 2014-02-15 17:47:54 +0100 | [diff] [blame] | 1128 | */ |
| 1129 | static void batadv_mcast_want_ipv6_update(struct batadv_priv *bat_priv, |
| 1130 | struct batadv_orig_node *orig, |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 1131 | u8 mcast_flags) |
Linus Lüssing | 4c8755d | 2014-02-15 17:47:54 +0100 | [diff] [blame] | 1132 | { |
Linus Lüssing | 8a4023c | 2015-06-16 17:10:26 +0200 | [diff] [blame] | 1133 | struct hlist_node *node = &orig->mcast_want_all_ipv6_node; |
| 1134 | struct hlist_head *head = &bat_priv->mcast.want_all_ipv6_list; |
| 1135 | |
Sven Eckelmann | 5274cd6 | 2015-06-21 14:45:15 +0200 | [diff] [blame] | 1136 | lockdep_assert_held(&orig->mcast_handler_lock); |
| 1137 | |
Linus Lüssing | 4c8755d | 2014-02-15 17:47:54 +0100 | [diff] [blame] | 1138 | /* switched from flag unset to set */ |
| 1139 | if (mcast_flags & BATADV_MCAST_WANT_ALL_IPV6 && |
| 1140 | !(orig->mcast_flags & BATADV_MCAST_WANT_ALL_IPV6)) { |
| 1141 | atomic_inc(&bat_priv->mcast.num_want_all_ipv6); |
| 1142 | |
| 1143 | spin_lock_bh(&bat_priv->mcast.want_lists_lock); |
Linus Lüssing | 8a4023c | 2015-06-16 17:10:26 +0200 | [diff] [blame] | 1144 | /* flag checks above + mcast_handler_lock prevents this */ |
| 1145 | WARN_ON(!hlist_unhashed(node)); |
| 1146 | |
| 1147 | hlist_add_head_rcu(node, head); |
Linus Lüssing | 4c8755d | 2014-02-15 17:47:54 +0100 | [diff] [blame] | 1148 | spin_unlock_bh(&bat_priv->mcast.want_lists_lock); |
| 1149 | /* switched from flag set to unset */ |
| 1150 | } else if (!(mcast_flags & BATADV_MCAST_WANT_ALL_IPV6) && |
| 1151 | orig->mcast_flags & BATADV_MCAST_WANT_ALL_IPV6) { |
| 1152 | atomic_dec(&bat_priv->mcast.num_want_all_ipv6); |
| 1153 | |
| 1154 | spin_lock_bh(&bat_priv->mcast.want_lists_lock); |
Linus Lüssing | 8a4023c | 2015-06-16 17:10:26 +0200 | [diff] [blame] | 1155 | /* flag checks above + mcast_handler_lock prevents this */ |
| 1156 | WARN_ON(hlist_unhashed(node)); |
| 1157 | |
| 1158 | hlist_del_init_rcu(node); |
Linus Lüssing | 4c8755d | 2014-02-15 17:47:54 +0100 | [diff] [blame] | 1159 | spin_unlock_bh(&bat_priv->mcast.want_lists_lock); |
| 1160 | } |
| 1161 | } |
| 1162 | |
| 1163 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 1164 | * batadv_mcast_tvlv_ogm_handler() - process incoming multicast tvlv container |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 1165 | * @bat_priv: the bat priv with all the soft interface information |
| 1166 | * @orig: the orig_node of the ogm |
| 1167 | * @flags: flags indicating the tvlv state (see batadv_tvlv_handler_flags) |
| 1168 | * @tvlv_value: tvlv buffer containing the multicast data |
| 1169 | * @tvlv_value_len: tvlv buffer length |
| 1170 | */ |
Linus Lüssing | bd2a979 | 2016-05-10 18:41:24 +0200 | [diff] [blame] | 1171 | static void batadv_mcast_tvlv_ogm_handler(struct batadv_priv *bat_priv, |
| 1172 | struct batadv_orig_node *orig, |
| 1173 | u8 flags, |
| 1174 | void *tvlv_value, |
| 1175 | u16 tvlv_value_len) |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 1176 | { |
| 1177 | bool orig_mcast_enabled = !(flags & BATADV_TVLV_HANDLER_OGM_CIFNOTFND); |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 1178 | u8 mcast_flags = BATADV_NO_FLAGS; |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 1179 | bool orig_initialized; |
| 1180 | |
Linus Lüssing | 8a4023c | 2015-06-16 17:10:26 +0200 | [diff] [blame] | 1181 | if (orig_mcast_enabled && tvlv_value && |
Sven Eckelmann | 825ffe1 | 2017-08-23 21:52:13 +0200 | [diff] [blame] | 1182 | tvlv_value_len >= sizeof(mcast_flags)) |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 1183 | mcast_flags = *(u8 *)tvlv_value; |
Linus Lüssing | 8a4023c | 2015-06-16 17:10:26 +0200 | [diff] [blame] | 1184 | |
| 1185 | spin_lock_bh(&orig->mcast_handler_lock); |
Linus Lüssing | 9c936e3 | 2015-06-16 17:10:25 +0200 | [diff] [blame] | 1186 | orig_initialized = test_bit(BATADV_ORIG_CAPA_HAS_MCAST, |
| 1187 | &orig->capa_initialized); |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 1188 | |
| 1189 | /* If mcast support is turned on decrease the disabled mcast node |
| 1190 | * counter only if we had increased it for this node before. If this |
| 1191 | * is a completely new orig_node no need to decrease the counter. |
| 1192 | */ |
| 1193 | if (orig_mcast_enabled && |
Linus Lüssing | 9c936e3 | 2015-06-16 17:10:25 +0200 | [diff] [blame] | 1194 | !test_bit(BATADV_ORIG_CAPA_HAS_MCAST, &orig->capabilities)) { |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 1195 | if (orig_initialized) |
| 1196 | atomic_dec(&bat_priv->mcast.num_disabled); |
Linus Lüssing | 9c936e3 | 2015-06-16 17:10:25 +0200 | [diff] [blame] | 1197 | set_bit(BATADV_ORIG_CAPA_HAS_MCAST, &orig->capabilities); |
Linus Lüssing | e8829f0 | 2014-10-30 05:40:46 +0100 | [diff] [blame] | 1198 | /* If mcast support is being switched off or if this is an initial |
| 1199 | * OGM without mcast support then increase the disabled mcast |
| 1200 | * node counter. |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 1201 | */ |
| 1202 | } else if (!orig_mcast_enabled && |
Linus Lüssing | 9c936e3 | 2015-06-16 17:10:25 +0200 | [diff] [blame] | 1203 | (test_bit(BATADV_ORIG_CAPA_HAS_MCAST, &orig->capabilities) || |
Linus Lüssing | e8829f0 | 2014-10-30 05:40:46 +0100 | [diff] [blame] | 1204 | !orig_initialized)) { |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 1205 | atomic_inc(&bat_priv->mcast.num_disabled); |
Linus Lüssing | 9c936e3 | 2015-06-16 17:10:25 +0200 | [diff] [blame] | 1206 | clear_bit(BATADV_ORIG_CAPA_HAS_MCAST, &orig->capabilities); |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 1207 | } |
| 1208 | |
Linus Lüssing | 9c936e3 | 2015-06-16 17:10:25 +0200 | [diff] [blame] | 1209 | set_bit(BATADV_ORIG_CAPA_HAS_MCAST, &orig->capa_initialized); |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 1210 | |
Linus Lüssing | ab49886 | 2014-02-15 17:47:53 +0100 | [diff] [blame] | 1211 | batadv_mcast_want_unsnoop_update(bat_priv, orig, mcast_flags); |
Linus Lüssing | 4c8755d | 2014-02-15 17:47:54 +0100 | [diff] [blame] | 1212 | batadv_mcast_want_ipv4_update(bat_priv, orig, mcast_flags); |
| 1213 | batadv_mcast_want_ipv6_update(bat_priv, orig, mcast_flags); |
Linus Lüssing | ab49886 | 2014-02-15 17:47:53 +0100 | [diff] [blame] | 1214 | |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 1215 | orig->mcast_flags = mcast_flags; |
Linus Lüssing | 8a4023c | 2015-06-16 17:10:26 +0200 | [diff] [blame] | 1216 | spin_unlock_bh(&orig->mcast_handler_lock); |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 1220 | * batadv_mcast_init() - initialize the multicast optimizations structures |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 1221 | * @bat_priv: the bat priv with all the soft interface information |
| 1222 | */ |
| 1223 | void batadv_mcast_init(struct batadv_priv *bat_priv) |
| 1224 | { |
Linus Lüssing | bd2a979 | 2016-05-10 18:41:24 +0200 | [diff] [blame] | 1225 | batadv_tvlv_handler_register(bat_priv, batadv_mcast_tvlv_ogm_handler, |
| 1226 | NULL, BATADV_TVLV_MCAST, 2, |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 1227 | BATADV_TVLV_HANDLER_OGM_CIFNOTFND); |
Linus Lüssing | cbebd36 | 2016-08-06 22:23:16 +0200 | [diff] [blame] | 1228 | |
| 1229 | INIT_DELAYED_WORK(&bat_priv->mcast.work, batadv_mcast_mla_update); |
| 1230 | batadv_mcast_start_timer(bat_priv); |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 1231 | } |
| 1232 | |
Sven Eckelmann | dc1cbd1 | 2016-07-16 09:31:20 +0200 | [diff] [blame] | 1233 | #ifdef CONFIG_BATMAN_ADV_DEBUGFS |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 1234 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 1235 | * batadv_mcast_flags_print_header() - print own mcast flags to debugfs table |
Linus Lüssing | 4e3e823 | 2016-05-10 18:41:27 +0200 | [diff] [blame] | 1236 | * @bat_priv: the bat priv with all the soft interface information |
| 1237 | * @seq: debugfs table seq_file struct |
| 1238 | * |
| 1239 | * Prints our own multicast flags including a more specific reason why |
| 1240 | * they are set, that is prints the bridge and querier state too, to |
| 1241 | * the debugfs table specified via @seq. |
| 1242 | */ |
| 1243 | static void batadv_mcast_flags_print_header(struct batadv_priv *bat_priv, |
| 1244 | struct seq_file *seq) |
| 1245 | { |
| 1246 | u8 flags = bat_priv->mcast.flags; |
| 1247 | char querier4, querier6, shadowing4, shadowing6; |
| 1248 | bool bridged = bat_priv->mcast.bridged; |
| 1249 | |
| 1250 | if (bridged) { |
| 1251 | querier4 = bat_priv->mcast.querier_ipv4.exists ? '.' : '4'; |
| 1252 | querier6 = bat_priv->mcast.querier_ipv6.exists ? '.' : '6'; |
| 1253 | shadowing4 = bat_priv->mcast.querier_ipv4.shadowing ? '4' : '.'; |
| 1254 | shadowing6 = bat_priv->mcast.querier_ipv6.shadowing ? '6' : '.'; |
| 1255 | } else { |
| 1256 | querier4 = '?'; |
| 1257 | querier6 = '?'; |
| 1258 | shadowing4 = '?'; |
| 1259 | shadowing6 = '?'; |
| 1260 | } |
| 1261 | |
| 1262 | seq_printf(seq, "Multicast flags (own flags: [%c%c%c])\n", |
| 1263 | (flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES) ? 'U' : '.', |
| 1264 | (flags & BATADV_MCAST_WANT_ALL_IPV4) ? '4' : '.', |
| 1265 | (flags & BATADV_MCAST_WANT_ALL_IPV6) ? '6' : '.'); |
| 1266 | seq_printf(seq, "* Bridged [U]\t\t\t\t%c\n", bridged ? 'U' : '.'); |
| 1267 | seq_printf(seq, "* No IGMP/MLD Querier [4/6]:\t\t%c/%c\n", |
| 1268 | querier4, querier6); |
| 1269 | seq_printf(seq, "* Shadowing IGMP/MLD Querier [4/6]:\t%c/%c\n", |
| 1270 | shadowing4, shadowing6); |
| 1271 | seq_puts(seq, "-------------------------------------------\n"); |
| 1272 | seq_printf(seq, " %-10s %s\n", "Originator", "Flags"); |
| 1273 | } |
| 1274 | |
| 1275 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 1276 | * batadv_mcast_flags_seq_print_text() - print the mcast flags of other nodes |
Linus Lüssing | 4e3e823 | 2016-05-10 18:41:27 +0200 | [diff] [blame] | 1277 | * @seq: seq file to print on |
| 1278 | * @offset: not used |
| 1279 | * |
| 1280 | * This prints a table of (primary) originators and their according |
| 1281 | * multicast flags, including (in the header) our own. |
| 1282 | * |
| 1283 | * Return: always 0 |
| 1284 | */ |
| 1285 | int batadv_mcast_flags_seq_print_text(struct seq_file *seq, void *offset) |
| 1286 | { |
| 1287 | struct net_device *net_dev = (struct net_device *)seq->private; |
| 1288 | struct batadv_priv *bat_priv = netdev_priv(net_dev); |
| 1289 | struct batadv_hard_iface *primary_if; |
| 1290 | struct batadv_hashtable *hash = bat_priv->orig_hash; |
| 1291 | struct batadv_orig_node *orig_node; |
| 1292 | struct hlist_head *head; |
| 1293 | u8 flags; |
| 1294 | u32 i; |
| 1295 | |
| 1296 | primary_if = batadv_seq_print_text_primary_if_get(seq); |
| 1297 | if (!primary_if) |
| 1298 | return 0; |
| 1299 | |
| 1300 | batadv_mcast_flags_print_header(bat_priv, seq); |
| 1301 | |
| 1302 | for (i = 0; i < hash->size; i++) { |
| 1303 | head = &hash->table[i]; |
| 1304 | |
| 1305 | rcu_read_lock(); |
| 1306 | hlist_for_each_entry_rcu(orig_node, head, hash_entry) { |
| 1307 | if (!test_bit(BATADV_ORIG_CAPA_HAS_MCAST, |
| 1308 | &orig_node->capa_initialized)) |
| 1309 | continue; |
| 1310 | |
| 1311 | if (!test_bit(BATADV_ORIG_CAPA_HAS_MCAST, |
| 1312 | &orig_node->capabilities)) { |
| 1313 | seq_printf(seq, "%pM -\n", orig_node->orig); |
| 1314 | continue; |
| 1315 | } |
| 1316 | |
| 1317 | flags = orig_node->mcast_flags; |
| 1318 | |
| 1319 | seq_printf(seq, "%pM [%c%c%c]\n", orig_node->orig, |
| 1320 | (flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES) |
| 1321 | ? 'U' : '.', |
| 1322 | (flags & BATADV_MCAST_WANT_ALL_IPV4) |
| 1323 | ? '4' : '.', |
| 1324 | (flags & BATADV_MCAST_WANT_ALL_IPV6) |
| 1325 | ? '6' : '.'); |
| 1326 | } |
| 1327 | rcu_read_unlock(); |
| 1328 | } |
| 1329 | |
| 1330 | batadv_hardif_put(primary_if); |
| 1331 | |
| 1332 | return 0; |
| 1333 | } |
Sven Eckelmann | dc1cbd1 | 2016-07-16 09:31:20 +0200 | [diff] [blame] | 1334 | #endif |
Linus Lüssing | 4e3e823 | 2016-05-10 18:41:27 +0200 | [diff] [blame] | 1335 | |
| 1336 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 1337 | * batadv_mcast_free() - free the multicast optimizations structures |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 1338 | * @bat_priv: the bat priv with all the soft interface information |
| 1339 | */ |
| 1340 | void batadv_mcast_free(struct batadv_priv *bat_priv) |
| 1341 | { |
Linus Lüssing | cbebd36 | 2016-08-06 22:23:16 +0200 | [diff] [blame] | 1342 | cancel_delayed_work_sync(&bat_priv->mcast.work); |
| 1343 | |
Linus Lüssing | bd2a979 | 2016-05-10 18:41:24 +0200 | [diff] [blame] | 1344 | batadv_tvlv_container_unregister(bat_priv, BATADV_TVLV_MCAST, 2); |
| 1345 | batadv_tvlv_handler_unregister(bat_priv, BATADV_TVLV_MCAST, 2); |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 1346 | |
Linus Lüssing | cbebd36 | 2016-08-06 22:23:16 +0200 | [diff] [blame] | 1347 | /* safely calling outside of worker, as worker was canceled above */ |
Linus Lüssing | c5caf4e | 2014-02-15 17:47:49 +0100 | [diff] [blame] | 1348 | batadv_mcast_mla_tt_retract(bat_priv, NULL); |
| 1349 | } |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 1350 | |
| 1351 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 1352 | * batadv_mcast_purge_orig() - reset originator global mcast state modifications |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 1353 | * @orig: the originator which is going to get purged |
| 1354 | */ |
| 1355 | void batadv_mcast_purge_orig(struct batadv_orig_node *orig) |
| 1356 | { |
| 1357 | struct batadv_priv *bat_priv = orig->bat_priv; |
| 1358 | |
Linus Lüssing | 8a4023c | 2015-06-16 17:10:26 +0200 | [diff] [blame] | 1359 | spin_lock_bh(&orig->mcast_handler_lock); |
| 1360 | |
Linus Lüssing | 9c936e3 | 2015-06-16 17:10:25 +0200 | [diff] [blame] | 1361 | if (!test_bit(BATADV_ORIG_CAPA_HAS_MCAST, &orig->capabilities) && |
| 1362 | test_bit(BATADV_ORIG_CAPA_HAS_MCAST, &orig->capa_initialized)) |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 1363 | atomic_dec(&bat_priv->mcast.num_disabled); |
Linus Lüssing | ab49886 | 2014-02-15 17:47:53 +0100 | [diff] [blame] | 1364 | |
| 1365 | batadv_mcast_want_unsnoop_update(bat_priv, orig, BATADV_NO_FLAGS); |
Linus Lüssing | 4c8755d | 2014-02-15 17:47:54 +0100 | [diff] [blame] | 1366 | batadv_mcast_want_ipv4_update(bat_priv, orig, BATADV_NO_FLAGS); |
| 1367 | batadv_mcast_want_ipv6_update(bat_priv, orig, BATADV_NO_FLAGS); |
Linus Lüssing | 8a4023c | 2015-06-16 17:10:26 +0200 | [diff] [blame] | 1368 | |
| 1369 | spin_unlock_bh(&orig->mcast_handler_lock); |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame] | 1370 | } |