^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* Copyright (C) 2007-2020 B.A.T.M.A.N. contributors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Marek Lindner, Simon Wunderlich
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include "send.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include "main.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/bug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/byteorder/generic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/if.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/if_ether.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/kref.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/printk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/rculist.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/rcupdate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/stddef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include "distributed-arp-table.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include "fragmentation.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include "gateway_client.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include "hard-interface.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include "log.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include "network-coding.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include "originator.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include "routing.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include "soft-interface.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include "translation-table.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static void batadv_send_outstanding_bcast_packet(struct work_struct *work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * batadv_send_skb_packet() - send an already prepared packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * @skb: the packet to send
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * @hard_iface: the interface to use to send the broadcast packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * @dst_addr: the payload destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * Send out an already prepared packet to the given neighbor or broadcast it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * using the specified interface. Either hard_iface or neigh_node must be not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * If neigh_node is NULL, then the packet is broadcasted using hard_iface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * otherwise it is sent as unicast to the given neighbor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * Regardless of the return value, the skb is consumed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * Return: A negative errno code is returned on a failure. A success does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * guarantee the frame will be transmitted as it may be dropped due
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * to congestion or traffic shaping.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) int batadv_send_skb_packet(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct batadv_hard_iface *hard_iface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) const u8 *dst_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct batadv_priv *bat_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct ethhdr *ethhdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) bat_priv = netdev_priv(hard_iface->soft_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (hard_iface->if_status != BATADV_IF_ACTIVE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) goto send_skb_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) if (unlikely(!hard_iface->net_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) goto send_skb_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) if (!(hard_iface->net_dev->flags & IFF_UP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) pr_warn("Interface %s is not up - can't send packet via that interface!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) hard_iface->net_dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) goto send_skb_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) /* push to the ethernet header. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) if (batadv_skb_head_push(skb, ETH_HLEN) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) goto send_skb_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) skb_reset_mac_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) ethhdr = eth_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) ether_addr_copy(ethhdr->h_source, hard_iface->net_dev->dev_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) ether_addr_copy(ethhdr->h_dest, dst_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) ethhdr->h_proto = htons(ETH_P_BATMAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) skb_set_network_header(skb, ETH_HLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) skb->protocol = htons(ETH_P_BATMAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) skb->dev = hard_iface->net_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) /* Save a clone of the skb to use when decoding coded packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) batadv_nc_skb_store_for_decoding(bat_priv, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /* dev_queue_xmit() returns a negative result on error. However on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * congestion and traffic shaping, it drops and returns NET_XMIT_DROP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * (which is > 0). This will not be treated as an error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) ret = dev_queue_xmit(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return net_xmit_eval(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) send_skb_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) return NET_XMIT_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * batadv_send_broadcast_skb() - Send broadcast packet via hard interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * @skb: packet to be transmitted (with batadv header and no outer eth header)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * @hard_iface: outgoing interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * Return: A negative errno code is returned on a failure. A success does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * guarantee the frame will be transmitted as it may be dropped due
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * to congestion or traffic shaping.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) int batadv_send_broadcast_skb(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct batadv_hard_iface *hard_iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) return batadv_send_skb_packet(skb, hard_iface, batadv_broadcast_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * batadv_send_unicast_skb() - Send unicast packet to neighbor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * @skb: packet to be transmitted (with batadv header and no outer eth header)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * @neigh: neighbor which is used as next hop to destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * Return: A negative errno code is returned on a failure. A success does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * guarantee the frame will be transmitted as it may be dropped due
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * to congestion or traffic shaping.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) int batadv_send_unicast_skb(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) struct batadv_neigh_node *neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) #ifdef CONFIG_BATMAN_ADV_BATMAN_V
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct batadv_hardif_neigh_node *hardif_neigh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) ret = batadv_send_skb_packet(skb, neigh->if_incoming, neigh->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) #ifdef CONFIG_BATMAN_ADV_BATMAN_V
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) hardif_neigh = batadv_hardif_neigh_get(neigh->if_incoming, neigh->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) if (hardif_neigh && ret != NET_XMIT_DROP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) hardif_neigh->bat_v.last_unicast_tx = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (hardif_neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) batadv_hardif_neigh_put(hardif_neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * batadv_send_skb_to_orig() - Lookup next-hop and transmit skb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) * @skb: Packet to be transmitted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * @orig_node: Final destination of the packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * @recv_if: Interface used when receiving the packet (can be NULL).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * Looks up the best next-hop towards the passed originator and passes the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * skb on for preparation of MAC header. If the packet originated from this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * host, NULL can be passed as recv_if and no interface alternating is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * attempted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * Return: negative errno code on a failure, -EINPROGRESS if the skb is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * buffered for later transmit or the NET_XMIT status returned by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * lower routine if the packet has been passed down.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) int batadv_send_skb_to_orig(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct batadv_orig_node *orig_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct batadv_hard_iface *recv_if)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) struct batadv_priv *bat_priv = orig_node->bat_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) struct batadv_neigh_node *neigh_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) /* batadv_find_router() increases neigh_nodes refcount if found. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) neigh_node = batadv_find_router(bat_priv, orig_node, recv_if);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (!neigh_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) goto free_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) /* Check if the skb is too large to send in one piece and fragment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * it if needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (atomic_read(&bat_priv->fragmentation) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) skb->len > neigh_node->if_incoming->net_dev->mtu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) /* Fragment and send packet. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) ret = batadv_frag_send_packet(skb, orig_node, neigh_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) /* skb was consumed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) goto put_neigh_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) /* try to network code the packet, if it is received on an interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) * (i.e. being forwarded). If the packet originates from this node or if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) * network coding fails, then send the packet as usual.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (recv_if && batadv_nc_skb_forward(skb, neigh_node))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) ret = -EINPROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) ret = batadv_send_unicast_skb(skb, neigh_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) /* skb was consumed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) put_neigh_node:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) batadv_neigh_node_put(neigh_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) free_skb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * batadv_send_skb_push_fill_unicast() - extend the buffer and initialize the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) * common fields for unicast packets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * @skb: the skb carrying the unicast header to initialize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * @hdr_size: amount of bytes to push at the beginning of the skb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) * @orig_node: the destination node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) * Return: false if the buffer extension was not possible or true otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) batadv_send_skb_push_fill_unicast(struct sk_buff *skb, int hdr_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) struct batadv_orig_node *orig_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) struct batadv_unicast_packet *unicast_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) u8 ttvn = (u8)atomic_read(&orig_node->last_ttvn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (batadv_skb_head_push(skb, hdr_size) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) unicast_packet = (struct batadv_unicast_packet *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) unicast_packet->version = BATADV_COMPAT_VERSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) /* batman packet type: unicast */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) unicast_packet->packet_type = BATADV_UNICAST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) /* set unicast ttl */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) unicast_packet->ttl = BATADV_TTL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) /* copy the destination for faster routing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) ether_addr_copy(unicast_packet->dest, orig_node->orig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) /* set the destination tt version number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) unicast_packet->ttvn = ttvn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) * batadv_send_skb_prepare_unicast() - encapsulate an skb with a unicast header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) * @skb: the skb containing the payload to encapsulate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) * @orig_node: the destination node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * Return: false if the payload could not be encapsulated or true otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static bool batadv_send_skb_prepare_unicast(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) struct batadv_orig_node *orig_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) size_t uni_size = sizeof(struct batadv_unicast_packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) return batadv_send_skb_push_fill_unicast(skb, uni_size, orig_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) * batadv_send_skb_prepare_unicast_4addr() - encapsulate an skb with a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) * unicast 4addr header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) * @skb: the skb containing the payload to encapsulate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * @orig: the destination node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * @packet_subtype: the unicast 4addr packet subtype to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * Return: false if the payload could not be encapsulated or true otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) bool batadv_send_skb_prepare_unicast_4addr(struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) struct batadv_orig_node *orig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) int packet_subtype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) struct batadv_hard_iface *primary_if;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) struct batadv_unicast_4addr_packet *uc_4addr_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) bool ret = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) primary_if = batadv_primary_if_get_selected(bat_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) if (!primary_if)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) /* Pull the header space and fill the unicast_packet substructure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) * We can do that because the first member of the uc_4addr_packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) * is of type struct unicast_packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) if (!batadv_send_skb_push_fill_unicast(skb, sizeof(*uc_4addr_packet),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) orig))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) uc_4addr_packet = (struct batadv_unicast_4addr_packet *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) uc_4addr_packet->u.packet_type = BATADV_UNICAST_4ADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) ether_addr_copy(uc_4addr_packet->src, primary_if->net_dev->dev_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) uc_4addr_packet->subtype = packet_subtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) uc_4addr_packet->reserved = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) ret = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) if (primary_if)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) batadv_hardif_put(primary_if);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) * batadv_send_skb_unicast() - encapsulate and send an skb via unicast
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) * @skb: payload to send
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) * @packet_type: the batman unicast packet type to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) * @packet_subtype: the unicast 4addr packet subtype (only relevant for unicast
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) * 4addr packets)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) * @orig_node: the originator to send the packet to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) * @vid: the vid to be used to search the translation table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) * Wrap the given skb into a batman-adv unicast or unicast-4addr header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) * depending on whether BATADV_UNICAST or BATADV_UNICAST_4ADDR was supplied
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) * as packet_type. Then send this frame to the given orig_node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) * Return: NET_XMIT_DROP in case of error or NET_XMIT_SUCCESS otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) int batadv_send_skb_unicast(struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) struct sk_buff *skb, int packet_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) int packet_subtype,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) struct batadv_orig_node *orig_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) unsigned short vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) struct batadv_unicast_packet *unicast_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) struct ethhdr *ethhdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) int ret = NET_XMIT_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) if (!orig_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) switch (packet_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) case BATADV_UNICAST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) if (!batadv_send_skb_prepare_unicast(skb, orig_node))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) case BATADV_UNICAST_4ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) if (!batadv_send_skb_prepare_unicast_4addr(bat_priv, skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) orig_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) packet_subtype))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) /* this function supports UNICAST and UNICAST_4ADDR only. It
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) * should never be invoked with any other packet type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) /* skb->data might have been reallocated by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) * batadv_send_skb_prepare_unicast{,_4addr}()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) ethhdr = eth_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) unicast_packet = (struct batadv_unicast_packet *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) /* inform the destination node that we are still missing a correct route
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) * for this client. The destination will receive this packet and will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) * try to reroute it because the ttvn contained in the header is less
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) * than the current one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) if (batadv_tt_global_client_is_roaming(bat_priv, ethhdr->h_dest, vid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) unicast_packet->ttvn = unicast_packet->ttvn - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) ret = batadv_send_skb_to_orig(skb, orig_node, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) /* skb was consumed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) * batadv_send_skb_via_tt_generic() - send an skb via TT lookup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) * @skb: payload to send
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) * @packet_type: the batman unicast packet type to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) * @packet_subtype: the unicast 4addr packet subtype (only relevant for unicast
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) * 4addr packets)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) * @dst_hint: can be used to override the destination contained in the skb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) * @vid: the vid to be used to search the translation table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) * Look up the recipient node for the destination address in the ethernet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) * header via the translation table. Wrap the given skb into a batman-adv
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) * unicast or unicast-4addr header depending on whether BATADV_UNICAST or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) * BATADV_UNICAST_4ADDR was supplied as packet_type. Then send this frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) * to the according destination node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) * Return: NET_XMIT_DROP in case of error or NET_XMIT_SUCCESS otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) int batadv_send_skb_via_tt_generic(struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) struct sk_buff *skb, int packet_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) int packet_subtype, u8 *dst_hint,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) unsigned short vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) struct batadv_orig_node *orig_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) u8 *src, *dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) src = ethhdr->h_source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) dst = ethhdr->h_dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) /* if we got an hint! let's send the packet to this client (if any) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) if (dst_hint) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) src = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) dst = dst_hint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) orig_node = batadv_transtable_search(bat_priv, src, dst, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) ret = batadv_send_skb_unicast(bat_priv, skb, packet_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) packet_subtype, orig_node, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) if (orig_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) batadv_orig_node_put(orig_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) * batadv_send_skb_via_gw() - send an skb via gateway lookup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) * @skb: payload to send
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) * @vid: the vid to be used to search the translation table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) * Look up the currently selected gateway. Wrap the given skb into a batman-adv
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) * unicast header and send this frame to this gateway node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) * Return: NET_XMIT_DROP in case of error or NET_XMIT_SUCCESS otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) int batadv_send_skb_via_gw(struct batadv_priv *bat_priv, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) unsigned short vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) struct batadv_orig_node *orig_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) orig_node = batadv_gw_get_selected_orig(bat_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) ret = batadv_send_skb_unicast(bat_priv, skb, BATADV_UNICAST_4ADDR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) BATADV_P_DATA, orig_node, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) if (orig_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) batadv_orig_node_put(orig_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) * batadv_forw_packet_free() - free a forwarding packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) * @forw_packet: The packet to free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) * @dropped: whether the packet is freed because is dropped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) * This frees a forwarding packet and releases any resources it might
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) * have claimed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) void batadv_forw_packet_free(struct batadv_forw_packet *forw_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) bool dropped)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) if (dropped)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) kfree_skb(forw_packet->skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) consume_skb(forw_packet->skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) if (forw_packet->if_incoming)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) batadv_hardif_put(forw_packet->if_incoming);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) if (forw_packet->if_outgoing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) batadv_hardif_put(forw_packet->if_outgoing);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) if (forw_packet->queue_left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) atomic_inc(forw_packet->queue_left);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) kfree(forw_packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) * batadv_forw_packet_alloc() - allocate a forwarding packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) * @if_incoming: The (optional) if_incoming to be grabbed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) * @if_outgoing: The (optional) if_outgoing to be grabbed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) * @queue_left: The (optional) queue counter to decrease
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) * @bat_priv: The bat_priv for the mesh of this forw_packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) * @skb: The raw packet this forwarding packet shall contain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) * Allocates a forwarding packet and tries to get a reference to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) * (optional) if_incoming, if_outgoing and queue_left. If queue_left
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) * is NULL then bat_priv is optional, too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) * Return: An allocated forwarding packet on success, NULL otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) struct batadv_forw_packet *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) batadv_forw_packet_alloc(struct batadv_hard_iface *if_incoming,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) struct batadv_hard_iface *if_outgoing,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) atomic_t *queue_left,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) struct batadv_forw_packet *forw_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) const char *qname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) if (queue_left && !batadv_atomic_dec_not_zero(queue_left)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) qname = "unknown";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) if (queue_left == &bat_priv->bcast_queue_left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) qname = "bcast";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) if (queue_left == &bat_priv->batman_queue_left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) qname = "batman";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) "%s queue is full\n", qname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) forw_packet = kmalloc(sizeof(*forw_packet), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) if (!forw_packet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) if (if_incoming)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) kref_get(&if_incoming->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) if (if_outgoing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) kref_get(&if_outgoing->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) INIT_HLIST_NODE(&forw_packet->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) INIT_HLIST_NODE(&forw_packet->cleanup_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) forw_packet->skb = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) forw_packet->queue_left = queue_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) forw_packet->if_incoming = if_incoming;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) forw_packet->if_outgoing = if_outgoing;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) forw_packet->num_packets = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) return forw_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) if (queue_left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) atomic_inc(queue_left);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) * batadv_forw_packet_was_stolen() - check whether someone stole this packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) * @forw_packet: the forwarding packet to check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) * This function checks whether the given forwarding packet was claimed by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) * someone else for free().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) * Return: True if someone stole it, false otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) batadv_forw_packet_was_stolen(struct batadv_forw_packet *forw_packet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) return !hlist_unhashed(&forw_packet->cleanup_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) * batadv_forw_packet_steal() - claim a forw_packet for free()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) * @forw_packet: the forwarding packet to steal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) * @lock: a key to the store to steal from (e.g. forw_{bat,bcast}_list_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) * This function tries to steal a specific forw_packet from global
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) * visibility for the purpose of getting it for free(). That means
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) * the caller is *not* allowed to requeue it afterwards.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) * Return: True if stealing was successful. False if someone else stole it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) * before us.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) bool batadv_forw_packet_steal(struct batadv_forw_packet *forw_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) spinlock_t *lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) /* did purging routine steal it earlier? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) spin_lock_bh(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) if (batadv_forw_packet_was_stolen(forw_packet)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) spin_unlock_bh(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) hlist_del_init(&forw_packet->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) /* Just to spot misuse of this function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) hlist_add_fake(&forw_packet->cleanup_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) spin_unlock_bh(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) * batadv_forw_packet_list_steal() - claim a list of forward packets for free()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) * @forw_list: the to be stolen forward packets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) * @cleanup_list: a backup pointer, to be able to dispose the packet later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) * @hard_iface: the interface to steal forward packets from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) * This function claims responsibility to free any forw_packet queued on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) * given hard_iface. If hard_iface is NULL forwarding packets on all hard
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) * interfaces will be claimed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) * The packets are being moved from the forw_list to the cleanup_list. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) * makes it possible for already running threads to notice the claim.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) batadv_forw_packet_list_steal(struct hlist_head *forw_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) struct hlist_head *cleanup_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) const struct batadv_hard_iface *hard_iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) struct batadv_forw_packet *forw_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) struct hlist_node *safe_tmp_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) hlist_for_each_entry_safe(forw_packet, safe_tmp_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) forw_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) /* if purge_outstanding_packets() was called with an argument
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) * we delete only packets belonging to the given interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) if (hard_iface &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) forw_packet->if_incoming != hard_iface &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) forw_packet->if_outgoing != hard_iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) hlist_del(&forw_packet->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) hlist_add_head(&forw_packet->cleanup_list, cleanup_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) * batadv_forw_packet_list_free() - free a list of forward packets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) * @head: a list of to be freed forw_packets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) * This function cancels the scheduling of any packet in the provided list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) * waits for any possibly running packet forwarding thread to finish and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) * finally, safely frees this forward packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) * This function might sleep.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) static void batadv_forw_packet_list_free(struct hlist_head *head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) struct batadv_forw_packet *forw_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) struct hlist_node *safe_tmp_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) hlist_for_each_entry_safe(forw_packet, safe_tmp_node, head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) cleanup_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) cancel_delayed_work_sync(&forw_packet->delayed_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) hlist_del(&forw_packet->cleanup_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) batadv_forw_packet_free(forw_packet, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) * batadv_forw_packet_queue() - try to queue a forwarding packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) * @forw_packet: the forwarding packet to queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) * @lock: a key to the store (e.g. forw_{bat,bcast}_list_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) * @head: the shelve to queue it on (e.g. forw_{bat,bcast}_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) * @send_time: timestamp (jiffies) when the packet is to be sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) * This function tries to (re)queue a forwarding packet. Requeuing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) * is prevented if the according interface is shutting down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) * (e.g. if batadv_forw_packet_list_steal() was called for this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) * packet earlier).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) * Calling batadv_forw_packet_queue() after a call to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) * batadv_forw_packet_steal() is forbidden!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) * Caller needs to ensure that forw_packet->delayed_work was initialized.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) static void batadv_forw_packet_queue(struct batadv_forw_packet *forw_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) spinlock_t *lock, struct hlist_head *head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) unsigned long send_time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) spin_lock_bh(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) /* did purging routine steal it from us? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) if (batadv_forw_packet_was_stolen(forw_packet)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) /* If you got it for free() without trouble, then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) * don't get back into the queue after stealing...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) WARN_ONCE(hlist_fake(&forw_packet->cleanup_list),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) "Requeuing after batadv_forw_packet_steal() not allowed!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) spin_unlock_bh(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) hlist_del_init(&forw_packet->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) hlist_add_head(&forw_packet->list, head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) queue_delayed_work(batadv_event_workqueue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) &forw_packet->delayed_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) send_time - jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) spin_unlock_bh(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) * batadv_forw_packet_bcast_queue() - try to queue a broadcast packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) * @forw_packet: the forwarding packet to queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) * @send_time: timestamp (jiffies) when the packet is to be sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) * This function tries to (re)queue a broadcast packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) * Caller needs to ensure that forw_packet->delayed_work was initialized.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) batadv_forw_packet_bcast_queue(struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) struct batadv_forw_packet *forw_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) unsigned long send_time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) batadv_forw_packet_queue(forw_packet, &bat_priv->forw_bcast_list_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) &bat_priv->forw_bcast_list, send_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) * batadv_forw_packet_ogmv1_queue() - try to queue an OGMv1 packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) * @forw_packet: the forwarding packet to queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) * @send_time: timestamp (jiffies) when the packet is to be sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) * This function tries to (re)queue an OGMv1 packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) * Caller needs to ensure that forw_packet->delayed_work was initialized.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) void batadv_forw_packet_ogmv1_queue(struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) struct batadv_forw_packet *forw_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) unsigned long send_time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) batadv_forw_packet_queue(forw_packet, &bat_priv->forw_bat_list_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) &bat_priv->forw_bat_list, send_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) * batadv_add_bcast_packet_to_list() - queue broadcast packet for multiple sends
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) * @skb: broadcast packet to add
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) * @delay: number of jiffies to wait before sending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) * @own_packet: true if it is a self-generated broadcast packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) * add a broadcast packet to the queue and setup timers. broadcast packets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) * are sent multiple times to increase probability for being received.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) * The skb is not consumed, so the caller should make sure that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) * skb is freed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) * Return: NETDEV_TX_OK on success and NETDEV_TX_BUSY on errors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) int batadv_add_bcast_packet_to_list(struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) const struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) unsigned long delay,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) bool own_packet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) struct batadv_hard_iface *primary_if;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) struct batadv_forw_packet *forw_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) struct batadv_bcast_packet *bcast_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) struct sk_buff *newskb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) primary_if = batadv_primary_if_get_selected(bat_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) if (!primary_if)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) newskb = skb_copy(skb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) if (!newskb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) batadv_hardif_put(primary_if);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) forw_packet = batadv_forw_packet_alloc(primary_if, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) &bat_priv->bcast_queue_left,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) bat_priv, newskb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) batadv_hardif_put(primary_if);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) if (!forw_packet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) goto err_packet_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) /* as we have a copy now, it is safe to decrease the TTL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) bcast_packet = (struct batadv_bcast_packet *)newskb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) bcast_packet->ttl--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) forw_packet->own = own_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) INIT_DELAYED_WORK(&forw_packet->delayed_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) batadv_send_outstanding_bcast_packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) batadv_forw_packet_bcast_queue(bat_priv, forw_packet, jiffies + delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) return NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) err_packet_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) kfree_skb(newskb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) return NETDEV_TX_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) * batadv_forw_packet_bcasts_left() - check if a retransmission is necessary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) * @forw_packet: the forwarding packet to check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) * @hard_iface: the interface to check on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) * Checks whether a given packet has any (re)transmissions left on the provided
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) * interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) * hard_iface may be NULL: In that case the number of transmissions this skb had
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) * so far is compared with the maximum amount of retransmissions independent of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) * any interface instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) * Return: True if (re)transmissions are left, false otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) batadv_forw_packet_bcasts_left(struct batadv_forw_packet *forw_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) struct batadv_hard_iface *hard_iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) unsigned int max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) if (hard_iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) max = hard_iface->num_bcasts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) max = BATADV_NUM_BCASTS_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) return BATADV_SKB_CB(forw_packet->skb)->num_bcasts < max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) * batadv_forw_packet_bcasts_inc() - increment retransmission counter of a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) * packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) * @forw_packet: the packet to increase the counter for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) batadv_forw_packet_bcasts_inc(struct batadv_forw_packet *forw_packet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) BATADV_SKB_CB(forw_packet->skb)->num_bcasts++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) * batadv_forw_packet_is_rebroadcast() - check packet for previous transmissions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) * @forw_packet: the packet to check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) * Return: True if this packet was transmitted before, false otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) bool batadv_forw_packet_is_rebroadcast(struct batadv_forw_packet *forw_packet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) return BATADV_SKB_CB(forw_packet->skb)->num_bcasts > 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) static void batadv_send_outstanding_bcast_packet(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) struct batadv_hard_iface *hard_iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) struct batadv_hardif_neigh_node *neigh_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) struct delayed_work *delayed_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) struct batadv_forw_packet *forw_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) struct batadv_bcast_packet *bcast_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) struct sk_buff *skb1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) struct net_device *soft_iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) struct batadv_priv *bat_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) unsigned long send_time = jiffies + msecs_to_jiffies(5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) bool dropped = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) u8 *neigh_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) u8 *orig_neigh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) delayed_work = to_delayed_work(work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) forw_packet = container_of(delayed_work, struct batadv_forw_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) delayed_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) soft_iface = forw_packet->if_incoming->soft_iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) bat_priv = netdev_priv(soft_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_DEACTIVATING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) dropped = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) if (batadv_dat_drop_broadcast_packet(bat_priv, forw_packet)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) dropped = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) bcast_packet = (struct batadv_bcast_packet *)forw_packet->skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) /* rebroadcast packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) if (hard_iface->soft_iface != soft_iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) if (!batadv_forw_packet_bcasts_left(forw_packet, hard_iface))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) if (forw_packet->own) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) neigh_node = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) neigh_addr = eth_hdr(forw_packet->skb)->h_source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) neigh_node = batadv_hardif_neigh_get(hard_iface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) neigh_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) orig_neigh = neigh_node ? neigh_node->orig : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) ret = batadv_hardif_no_broadcast(hard_iface, bcast_packet->orig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) orig_neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) char *type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) switch (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) case BATADV_HARDIF_BCAST_NORECIPIENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) type = "no neighbor";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) case BATADV_HARDIF_BCAST_DUPFWD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) type = "single neighbor is source";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) case BATADV_HARDIF_BCAST_DUPORIG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) type = "single neighbor is originator";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) type = "unknown";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) batadv_dbg(BATADV_DBG_BATMAN, bat_priv, "BCAST packet from orig %pM on %s suppressed: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) bcast_packet->orig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) hard_iface->net_dev->name, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) if (neigh_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) batadv_hardif_neigh_put(neigh_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) if (neigh_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) batadv_hardif_neigh_put(neigh_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) if (!kref_get_unless_zero(&hard_iface->refcount))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) /* send a copy of the saved skb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) skb1 = skb_clone(forw_packet->skb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) if (skb1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) batadv_send_broadcast_skb(skb1, hard_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) batadv_hardif_put(hard_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) batadv_forw_packet_bcasts_inc(forw_packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) /* if we still have some more bcasts to send */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) if (batadv_forw_packet_bcasts_left(forw_packet, NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) batadv_forw_packet_bcast_queue(bat_priv, forw_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) send_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) /* do we get something for free()? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) if (batadv_forw_packet_steal(forw_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) &bat_priv->forw_bcast_list_lock))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) batadv_forw_packet_free(forw_packet, dropped);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) * batadv_purge_outstanding_packets() - stop/purge scheduled bcast/OGMv1 packets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) * @hard_iface: the hard interface to cancel and purge bcast/ogm packets on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) * This method cancels and purges any broadcast and OGMv1 packet on the given
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) * hard_iface. If hard_iface is NULL, broadcast and OGMv1 packets on all hard
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) * interfaces will be canceled and purged.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) * This function might sleep.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) batadv_purge_outstanding_packets(struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) const struct batadv_hard_iface *hard_iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) struct hlist_head head = HLIST_HEAD_INIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) if (hard_iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) "%s(): %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) __func__, hard_iface->net_dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) "%s()\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) /* claim bcast list for free() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) spin_lock_bh(&bat_priv->forw_bcast_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) batadv_forw_packet_list_steal(&bat_priv->forw_bcast_list, &head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) hard_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) spin_unlock_bh(&bat_priv->forw_bcast_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) /* claim batman packet list for free() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) spin_lock_bh(&bat_priv->forw_bat_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) batadv_forw_packet_list_steal(&bat_priv->forw_bat_list, &head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) hard_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) spin_unlock_bh(&bat_priv->forw_bat_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) /* then cancel or wait for packet workers to finish and free */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) batadv_forw_packet_list_free(&head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) }