blob: 81d69fb97c17b71d9ccf0ad78909a301a8f569ab [file] [log] [blame]
Antonio Quartulli0b873932013-01-04 03:05:31 +01001/* Copyright (C) 2007-2013 B.A.T.M.A.N. contributors:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00002 *
3 * Marek Lindner, Simon Wunderlich
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public
7 * License as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000018 */
19
20#include "main.h"
Antonio Quartullic384ea32011-06-26 03:37:18 +020021#include "distributed-arp-table.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000022#include "send.h"
23#include "routing.h"
24#include "translation-table.h"
25#include "soft-interface.h"
26#include "hard-interface.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000027#include "gateway_common.h"
28#include "originator.h"
Martin Hundebøll612d2b42013-01-25 11:12:42 +010029#include "network-coding.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000030
Antonio Quartulliaf5d4f72012-11-26 00:38:50 +010031#include <linux/if_ether.h>
32
Sven Eckelmannbb079c82012-05-16 20:23:14 +020033static void batadv_send_outstanding_bcast_packet(struct work_struct *work);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000034
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000035/* send out an already prepared packet to the given address via the
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +020036 * specified batman interface
37 */
Sven Eckelmann56303d32012-06-05 22:31:31 +020038int batadv_send_skb_packet(struct sk_buff *skb,
39 struct batadv_hard_iface *hard_iface,
Sven Eckelmann9455e342012-05-12 02:09:37 +020040 const uint8_t *dst_addr)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000041{
Martin Hundebøll612d2b42013-01-25 11:12:42 +010042 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000043 struct ethhdr *ethhdr;
44
Sven Eckelmanne9a4f292012-06-03 22:19:19 +020045 if (hard_iface->if_status != BATADV_IF_ACTIVE)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000046 goto send_skb_err;
47
Marek Lindnere6c10f42011-02-18 12:33:20 +000048 if (unlikely(!hard_iface->net_dev))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000049 goto send_skb_err;
50
Marek Lindnere6c10f42011-02-18 12:33:20 +000051 if (!(hard_iface->net_dev->flags & IFF_UP)) {
Sven Eckelmann67969582012-03-26 16:22:45 +020052 pr_warn("Interface %s is not up - can't send packet via that interface!\n",
53 hard_iface->net_dev->name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000054 goto send_skb_err;
55 }
56
57 /* push to the ethernet header. */
Sven Eckelmann04b482a2012-05-12 02:09:38 +020058 if (batadv_skb_head_push(skb, ETH_HLEN) < 0)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000059 goto send_skb_err;
60
61 skb_reset_mac_header(skb);
62
Antonio Quartulli7ed4be92013-04-08 15:08:18 +020063 ethhdr = eth_hdr(skb);
Marek Lindnere6c10f42011-02-18 12:33:20 +000064 memcpy(ethhdr->h_source, hard_iface->net_dev->dev_addr, ETH_ALEN);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000065 memcpy(ethhdr->h_dest, dst_addr, ETH_ALEN);
Antonio Quartulliaf5d4f72012-11-26 00:38:50 +010066 ethhdr->h_proto = __constant_htons(ETH_P_BATMAN);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000067
68 skb_set_network_header(skb, ETH_HLEN);
Antonio Quartulliaf5d4f72012-11-26 00:38:50 +010069 skb->protocol = __constant_htons(ETH_P_BATMAN);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000070
Marek Lindnere6c10f42011-02-18 12:33:20 +000071 skb->dev = hard_iface->net_dev;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000072
Martin Hundebøll612d2b42013-01-25 11:12:42 +010073 /* Save a clone of the skb to use when decoding coded packets */
74 batadv_nc_skb_store_for_decoding(bat_priv, skb);
75
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000076 /* dev_queue_xmit() returns a negative result on error. However on
77 * congestion and traffic shaping, it drops and returns NET_XMIT_DROP
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +020078 * (which is > 0). This will not be treated as an error.
79 */
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000080 return dev_queue_xmit(skb);
81send_skb_err:
82 kfree_skb(skb);
83 return NET_XMIT_DROP;
84}
85
Martin Hundebøllbb351ba2012-10-16 16:13:48 +020086/**
87 * batadv_send_skb_to_orig - Lookup next-hop and transmit skb.
88 * @skb: Packet to be transmitted.
89 * @orig_node: Final destination of the packet.
90 * @recv_if: Interface used when receiving the packet (can be NULL).
91 *
92 * Looks up the best next-hop towards the passed originator and passes the
93 * skb on for preparation of MAC header. If the packet originated from this
94 * host, NULL can be passed as recv_if and no interface alternating is
95 * attempted.
96 *
Martin Hundebølle91ecfc2013-04-20 13:54:39 +020097 * Returns NET_XMIT_SUCCESS on success, NET_XMIT_DROP on failure, or
98 * NET_XMIT_POLICED if the skb is buffered for later transmit.
Martin Hundebøllbb351ba2012-10-16 16:13:48 +020099 */
Martin Hundebølle91ecfc2013-04-20 13:54:39 +0200100int batadv_send_skb_to_orig(struct sk_buff *skb,
101 struct batadv_orig_node *orig_node,
102 struct batadv_hard_iface *recv_if)
Martin Hundebøllbb351ba2012-10-16 16:13:48 +0200103{
104 struct batadv_priv *bat_priv = orig_node->bat_priv;
105 struct batadv_neigh_node *neigh_node;
Martin Hundebølle91ecfc2013-04-20 13:54:39 +0200106 int ret = NET_XMIT_DROP;
Martin Hundebøllbb351ba2012-10-16 16:13:48 +0200107
108 /* batadv_find_router() increases neigh_nodes refcount if found. */
109 neigh_node = batadv_find_router(bat_priv, orig_node, recv_if);
110 if (!neigh_node)
Martin Hundebølle91ecfc2013-04-20 13:54:39 +0200111 return ret;
Martin Hundebøllbb351ba2012-10-16 16:13:48 +0200112
Martin Hundebølle91ecfc2013-04-20 13:54:39 +0200113 /* try to network code the packet, if it is received on an interface
114 * (i.e. being forwarded). If the packet originates from this node or if
115 * network coding fails, then send the packet as usual.
116 */
117 if (recv_if && batadv_nc_skb_forward(skb, neigh_node)) {
118 ret = NET_XMIT_POLICED;
119 } else {
120 batadv_send_skb_packet(skb, neigh_node->if_incoming,
121 neigh_node->addr);
122 ret = NET_XMIT_SUCCESS;
123 }
Martin Hundebøllbb351ba2012-10-16 16:13:48 +0200124
125 batadv_neigh_node_free_ref(neigh_node);
126
Martin Hundebølle91ecfc2013-04-20 13:54:39 +0200127 return ret;
Martin Hundebøllbb351ba2012-10-16 16:13:48 +0200128}
129
Sven Eckelmann56303d32012-06-05 22:31:31 +0200130void batadv_schedule_bat_ogm(struct batadv_hard_iface *hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000131{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200132 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000133
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200134 if ((hard_iface->if_status == BATADV_IF_NOT_IN_USE) ||
135 (hard_iface->if_status == BATADV_IF_TO_BE_REMOVED))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000136 return;
137
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +0200138 /* the interface gets activated here to avoid race conditions between
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000139 * the moment of activating the interface in
140 * hardif_activate_interface() where the originator mac is set and
141 * outdated packets (especially uninitialized mac addresses) in the
142 * packet queue
143 */
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200144 if (hard_iface->if_status == BATADV_IF_TO_BE_ACTIVATED)
145 hard_iface->if_status = BATADV_IF_ACTIVE;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000146
Marek Lindnerbe9aa4c2012-05-07 04:22:05 +0800147 bat_priv->bat_algo_ops->bat_ogm_schedule(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000148}
149
Sven Eckelmann56303d32012-06-05 22:31:31 +0200150static void batadv_forw_packet_free(struct batadv_forw_packet *forw_packet)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000151{
152 if (forw_packet->skb)
153 kfree_skb(forw_packet->skb);
Sven Eckelmann6d5808d2011-05-11 20:59:06 +0200154 if (forw_packet->if_incoming)
Sven Eckelmanne5d89252012-05-12 13:48:54 +0200155 batadv_hardif_free_ref(forw_packet->if_incoming);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000156 kfree(forw_packet);
157}
158
Sven Eckelmann56303d32012-06-05 22:31:31 +0200159static void
160_batadv_add_bcast_packet_to_list(struct batadv_priv *bat_priv,
161 struct batadv_forw_packet *forw_packet,
162 unsigned long send_time)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000163{
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000164 /* add new packet to packet list */
165 spin_lock_bh(&bat_priv->forw_bcast_list_lock);
166 hlist_add_head(&forw_packet->list, &bat_priv->forw_bcast_list);
167 spin_unlock_bh(&bat_priv->forw_bcast_list_lock);
168
169 /* start timer for this packet */
Sven Eckelmann3193e8f2012-05-12 02:09:42 +0200170 queue_delayed_work(batadv_event_workqueue, &forw_packet->delayed_work,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000171 send_time);
172}
173
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000174/* add a broadcast packet to the queue and setup timers. broadcast packets
Antonio Quartulli015758d2011-07-09 17:52:13 +0200175 * are sent multiple times to increase probability for being received.
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000176 *
177 * This function returns NETDEV_TX_OK on success and NETDEV_TX_BUSY on
178 * errors.
179 *
180 * The skb is not consumed, so the caller should make sure that the
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +0200181 * skb is freed.
182 */
Sven Eckelmann56303d32012-06-05 22:31:31 +0200183int batadv_add_bcast_packet_to_list(struct batadv_priv *bat_priv,
Sven Eckelmann9455e342012-05-12 02:09:37 +0200184 const struct sk_buff *skb,
185 unsigned long delay)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000186{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200187 struct batadv_hard_iface *primary_if = NULL;
188 struct batadv_forw_packet *forw_packet;
Sven Eckelmann96412692012-06-05 22:31:30 +0200189 struct batadv_bcast_packet *bcast_packet;
Sven Eckelmann747e4222011-05-14 23:14:50 +0200190 struct sk_buff *newskb;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000191
Sven Eckelmann3e348192012-05-16 20:23:22 +0200192 if (!batadv_atomic_dec_not_zero(&bat_priv->bcast_queue_left)) {
Sven Eckelmann39c75a52012-06-03 22:19:22 +0200193 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
194 "bcast packet queue full\n");
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000195 goto out;
196 }
197
Sven Eckelmanne5d89252012-05-12 13:48:54 +0200198 primary_if = batadv_primary_if_get_selected(bat_priv);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200199 if (!primary_if)
Marek Lindnerca06c6e2011-05-14 20:01:22 +0200200 goto out_and_inc;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000201
Sven Eckelmann704509b2011-05-14 23:14:54 +0200202 forw_packet = kmalloc(sizeof(*forw_packet), GFP_ATOMIC);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000203
204 if (!forw_packet)
205 goto out_and_inc;
206
Sven Eckelmann747e4222011-05-14 23:14:50 +0200207 newskb = skb_copy(skb, GFP_ATOMIC);
208 if (!newskb)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000209 goto packet_free;
210
211 /* as we have a copy now, it is safe to decrease the TTL */
Sven Eckelmann96412692012-06-05 22:31:30 +0200212 bcast_packet = (struct batadv_bcast_packet *)newskb->data;
Sven Eckelmann76543d12011-11-20 15:47:38 +0100213 bcast_packet->header.ttl--;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000214
Sven Eckelmann747e4222011-05-14 23:14:50 +0200215 skb_reset_mac_header(newskb);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000216
Sven Eckelmann747e4222011-05-14 23:14:50 +0200217 forw_packet->skb = newskb;
Marek Lindner32ae9b22011-04-20 15:40:58 +0200218 forw_packet->if_incoming = primary_if;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000219
220 /* how often did we send the bcast packet ? */
221 forw_packet->num_packets = 0;
222
Antonio Quartulli72414442012-12-25 13:14:37 +0100223 INIT_DELAYED_WORK(&forw_packet->delayed_work,
224 batadv_send_outstanding_bcast_packet);
225
Sven Eckelmannbb079c82012-05-16 20:23:14 +0200226 _batadv_add_bcast_packet_to_list(bat_priv, forw_packet, delay);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000227 return NETDEV_TX_OK;
228
229packet_free:
230 kfree(forw_packet);
231out_and_inc:
232 atomic_inc(&bat_priv->bcast_queue_left);
233out:
Marek Lindner32ae9b22011-04-20 15:40:58 +0200234 if (primary_if)
Sven Eckelmanne5d89252012-05-12 13:48:54 +0200235 batadv_hardif_free_ref(primary_if);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000236 return NETDEV_TX_BUSY;
237}
238
Sven Eckelmannbb079c82012-05-16 20:23:14 +0200239static void batadv_send_outstanding_bcast_packet(struct work_struct *work)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000240{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200241 struct batadv_hard_iface *hard_iface;
Sven Eckelmannbbb1f902012-07-08 17:13:15 +0200242 struct delayed_work *delayed_work;
Sven Eckelmann56303d32012-06-05 22:31:31 +0200243 struct batadv_forw_packet *forw_packet;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000244 struct sk_buff *skb1;
Sven Eckelmann56303d32012-06-05 22:31:31 +0200245 struct net_device *soft_iface;
246 struct batadv_priv *bat_priv;
247
Sven Eckelmannbbb1f902012-07-08 17:13:15 +0200248 delayed_work = container_of(work, struct delayed_work, work);
Sven Eckelmann56303d32012-06-05 22:31:31 +0200249 forw_packet = container_of(delayed_work, struct batadv_forw_packet,
250 delayed_work);
251 soft_iface = forw_packet->if_incoming->soft_iface;
252 bat_priv = netdev_priv(soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000253
254 spin_lock_bh(&bat_priv->forw_bcast_list_lock);
255 hlist_del(&forw_packet->list);
256 spin_unlock_bh(&bat_priv->forw_bcast_list_lock);
257
Sven Eckelmann39c75a52012-06-03 22:19:22 +0200258 if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_DEACTIVATING)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000259 goto out;
260
Antonio Quartullic384ea32011-06-26 03:37:18 +0200261 if (batadv_dat_drop_broadcast_packet(bat_priv, forw_packet))
262 goto out;
263
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000264 /* rebroadcast packet */
265 rcu_read_lock();
Sven Eckelmann3193e8f2012-05-12 02:09:42 +0200266 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
Marek Lindnere6c10f42011-02-18 12:33:20 +0000267 if (hard_iface->soft_iface != soft_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000268 continue;
269
Matthias Schiffercaf65bf2013-03-09 23:14:23 +0100270 if (forw_packet->num_packets >= hard_iface->num_bcasts)
271 continue;
272
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000273 /* send a copy of the saved skb */
274 skb1 = skb_clone(forw_packet->skb, GFP_ATOMIC);
275 if (skb1)
Sven Eckelmann9455e342012-05-12 02:09:37 +0200276 batadv_send_skb_packet(skb1, hard_iface,
Sven Eckelmann3193e8f2012-05-12 02:09:42 +0200277 batadv_broadcast_addr);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000278 }
279 rcu_read_unlock();
280
281 forw_packet->num_packets++;
282
283 /* if we still have some more bcasts to send */
Matthias Schiffercaf65bf2013-03-09 23:14:23 +0100284 if (forw_packet->num_packets < BATADV_NUM_BCASTS_MAX) {
Sven Eckelmannbb079c82012-05-16 20:23:14 +0200285 _batadv_add_bcast_packet_to_list(bat_priv, forw_packet,
286 msecs_to_jiffies(5));
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000287 return;
288 }
289
290out:
Sven Eckelmannbb079c82012-05-16 20:23:14 +0200291 batadv_forw_packet_free(forw_packet);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000292 atomic_inc(&bat_priv->bcast_queue_left);
293}
294
Sven Eckelmann9455e342012-05-12 02:09:37 +0200295void batadv_send_outstanding_bat_ogm_packet(struct work_struct *work)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000296{
Sven Eckelmannbbb1f902012-07-08 17:13:15 +0200297 struct delayed_work *delayed_work;
Sven Eckelmann56303d32012-06-05 22:31:31 +0200298 struct batadv_forw_packet *forw_packet;
299 struct batadv_priv *bat_priv;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000300
Sven Eckelmannbbb1f902012-07-08 17:13:15 +0200301 delayed_work = container_of(work, struct delayed_work, work);
Sven Eckelmann56303d32012-06-05 22:31:31 +0200302 forw_packet = container_of(delayed_work, struct batadv_forw_packet,
303 delayed_work);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000304 bat_priv = netdev_priv(forw_packet->if_incoming->soft_iface);
305 spin_lock_bh(&bat_priv->forw_bat_list_lock);
306 hlist_del(&forw_packet->list);
307 spin_unlock_bh(&bat_priv->forw_bat_list_lock);
308
Sven Eckelmann39c75a52012-06-03 22:19:22 +0200309 if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_DEACTIVATING)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000310 goto out;
311
Marek Lindner01c42242011-11-28 21:31:55 +0800312 bat_priv->bat_algo_ops->bat_ogm_emit(forw_packet);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000313
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +0200314 /* we have to have at least one packet in the queue
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000315 * to determine the queues wake up time unless we are
316 * shutting down
317 */
318 if (forw_packet->own)
Sven Eckelmann9455e342012-05-12 02:09:37 +0200319 batadv_schedule_bat_ogm(forw_packet->if_incoming);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000320
321out:
322 /* don't count own packet */
323 if (!forw_packet->own)
324 atomic_inc(&bat_priv->batman_queue_left);
325
Sven Eckelmannbb079c82012-05-16 20:23:14 +0200326 batadv_forw_packet_free(forw_packet);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000327}
328
Sven Eckelmann56303d32012-06-05 22:31:31 +0200329void
330batadv_purge_outstanding_packets(struct batadv_priv *bat_priv,
331 const struct batadv_hard_iface *hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000332{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200333 struct batadv_forw_packet *forw_packet;
Sasha Levinb67bfe02013-02-27 17:06:00 -0800334 struct hlist_node *safe_tmp_node;
Sven Eckelmann6d5808d2011-05-11 20:59:06 +0200335 bool pending;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000336
Marek Lindnere6c10f42011-02-18 12:33:20 +0000337 if (hard_iface)
Sven Eckelmann39c75a52012-06-03 22:19:22 +0200338 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
Sven Eckelmann1eda58b2012-05-12 13:48:58 +0200339 "purge_outstanding_packets(): %s\n",
340 hard_iface->net_dev->name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000341 else
Sven Eckelmann39c75a52012-06-03 22:19:22 +0200342 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
Sven Eckelmann1eda58b2012-05-12 13:48:58 +0200343 "purge_outstanding_packets()\n");
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000344
345 /* free bcast list */
346 spin_lock_bh(&bat_priv->forw_bcast_list_lock);
Sasha Levinb67bfe02013-02-27 17:06:00 -0800347 hlist_for_each_entry_safe(forw_packet, safe_tmp_node,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000348 &bat_priv->forw_bcast_list, list) {
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +0200349 /* if purge_outstanding_packets() was called with an argument
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000350 * we delete only packets belonging to the given interface
351 */
Marek Lindnere6c10f42011-02-18 12:33:20 +0000352 if ((hard_iface) &&
353 (forw_packet->if_incoming != hard_iface))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000354 continue;
355
356 spin_unlock_bh(&bat_priv->forw_bcast_list_lock);
357
Sven Eckelmannbb079c82012-05-16 20:23:14 +0200358 /* batadv_send_outstanding_bcast_packet() will lock the list to
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000359 * delete the item from the list
360 */
Sven Eckelmann6d5808d2011-05-11 20:59:06 +0200361 pending = cancel_delayed_work_sync(&forw_packet->delayed_work);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000362 spin_lock_bh(&bat_priv->forw_bcast_list_lock);
Sven Eckelmann6d5808d2011-05-11 20:59:06 +0200363
364 if (pending) {
365 hlist_del(&forw_packet->list);
Sven Eckelmannbb079c82012-05-16 20:23:14 +0200366 batadv_forw_packet_free(forw_packet);
Sven Eckelmann6d5808d2011-05-11 20:59:06 +0200367 }
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000368 }
369 spin_unlock_bh(&bat_priv->forw_bcast_list_lock);
370
371 /* free batman packet list */
372 spin_lock_bh(&bat_priv->forw_bat_list_lock);
Sasha Levinb67bfe02013-02-27 17:06:00 -0800373 hlist_for_each_entry_safe(forw_packet, safe_tmp_node,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000374 &bat_priv->forw_bat_list, list) {
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +0200375 /* if purge_outstanding_packets() was called with an argument
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000376 * we delete only packets belonging to the given interface
377 */
Marek Lindnere6c10f42011-02-18 12:33:20 +0000378 if ((hard_iface) &&
379 (forw_packet->if_incoming != hard_iface))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000380 continue;
381
382 spin_unlock_bh(&bat_priv->forw_bat_list_lock);
383
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +0200384 /* send_outstanding_bat_packet() will lock the list to
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000385 * delete the item from the list
386 */
Sven Eckelmann6d5808d2011-05-11 20:59:06 +0200387 pending = cancel_delayed_work_sync(&forw_packet->delayed_work);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000388 spin_lock_bh(&bat_priv->forw_bat_list_lock);
Sven Eckelmann6d5808d2011-05-11 20:59:06 +0200389
390 if (pending) {
391 hlist_del(&forw_packet->list);
Sven Eckelmannbb079c82012-05-16 20:23:14 +0200392 batadv_forw_packet_free(forw_packet);
Sven Eckelmann6d5808d2011-05-11 20:59:06 +0200393 }
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000394 }
395 spin_unlock_bh(&bat_priv->forw_bat_list_lock);
396}