blob: e78670c3c4b73abf85c474a7a590ebbb1cb494de [file] [log] [blame]
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001/*
Sven Eckelmann64afe352011-01-27 10:38:15 +01002 * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00003 *
4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#include "main.h"
23#include "send.h"
24#include "routing.h"
25#include "translation-table.h"
26#include "soft-interface.h"
27#include "hard-interface.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000028#include "vis.h"
29#include "aggregation.h"
30#include "gateway_common.h"
31#include "originator.h"
32
33static void send_outstanding_bcast_packet(struct work_struct *work);
34
35/* apply hop penalty for a normal link */
36static uint8_t hop_penalty(const uint8_t tq, struct bat_priv *bat_priv)
37{
38 int hop_penalty = atomic_read(&bat_priv->hop_penalty);
39 return (tq * (TQ_MAX_VALUE - hop_penalty)) / (TQ_MAX_VALUE);
40}
41
42/* when do we schedule our own packet to be sent */
43static unsigned long own_send_time(struct bat_priv *bat_priv)
44{
45 return jiffies + msecs_to_jiffies(
46 atomic_read(&bat_priv->orig_interval) -
47 JITTER + (random32() % 2*JITTER));
48}
49
50/* when do we schedule a forwarded packet to be sent */
Simon Wunderlich74ef1152010-12-29 16:15:19 +000051static unsigned long forward_send_time(void)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000052{
53 return jiffies + msecs_to_jiffies(random32() % (JITTER/2));
54}
55
56/* send out an already prepared packet to the given address via the
57 * specified batman interface */
58int send_skb_packet(struct sk_buff *skb,
Marek Lindnere6c10f42011-02-18 12:33:20 +000059 struct hard_iface *hard_iface,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000060 uint8_t *dst_addr)
61{
62 struct ethhdr *ethhdr;
63
Marek Lindnere6c10f42011-02-18 12:33:20 +000064 if (hard_iface->if_status != IF_ACTIVE)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000065 goto send_skb_err;
66
Marek Lindnere6c10f42011-02-18 12:33:20 +000067 if (unlikely(!hard_iface->net_dev))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000068 goto send_skb_err;
69
Marek Lindnere6c10f42011-02-18 12:33:20 +000070 if (!(hard_iface->net_dev->flags & IFF_UP)) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000071 pr_warning("Interface %s is not up - can't send packet via "
Marek Lindnere6c10f42011-02-18 12:33:20 +000072 "that interface!\n", hard_iface->net_dev->name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000073 goto send_skb_err;
74 }
75
76 /* push to the ethernet header. */
77 if (my_skb_head_push(skb, sizeof(struct ethhdr)) < 0)
78 goto send_skb_err;
79
80 skb_reset_mac_header(skb);
81
82 ethhdr = (struct ethhdr *) skb_mac_header(skb);
Marek Lindnere6c10f42011-02-18 12:33:20 +000083 memcpy(ethhdr->h_source, hard_iface->net_dev->dev_addr, ETH_ALEN);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000084 memcpy(ethhdr->h_dest, dst_addr, ETH_ALEN);
85 ethhdr->h_proto = __constant_htons(ETH_P_BATMAN);
86
87 skb_set_network_header(skb, ETH_HLEN);
88 skb->priority = TC_PRIO_CONTROL;
89 skb->protocol = __constant_htons(ETH_P_BATMAN);
90
Marek Lindnere6c10f42011-02-18 12:33:20 +000091 skb->dev = hard_iface->net_dev;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000092
93 /* dev_queue_xmit() returns a negative result on error. However on
94 * congestion and traffic shaping, it drops and returns NET_XMIT_DROP
95 * (which is > 0). This will not be treated as an error. */
96
97 return dev_queue_xmit(skb);
98send_skb_err:
99 kfree_skb(skb);
100 return NET_XMIT_DROP;
101}
102
103/* Send a packet to a given interface */
104static void send_packet_to_if(struct forw_packet *forw_packet,
Marek Lindnere6c10f42011-02-18 12:33:20 +0000105 struct hard_iface *hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000106{
Marek Lindnere6c10f42011-02-18 12:33:20 +0000107 struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000108 char *fwd_str;
109 uint8_t packet_num;
110 int16_t buff_pos;
111 struct batman_packet *batman_packet;
112 struct sk_buff *skb;
113
Marek Lindnere6c10f42011-02-18 12:33:20 +0000114 if (hard_iface->if_status != IF_ACTIVE)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000115 return;
116
117 packet_num = 0;
118 buff_pos = 0;
119 batman_packet = (struct batman_packet *)forw_packet->skb->data;
120
121 /* adjust all flags and log packets */
122 while (aggregated_packet(buff_pos,
123 forw_packet->packet_len,
124 batman_packet->num_hna)) {
125
126 /* we might have aggregated direct link packets with an
127 * ordinary base packet */
128 if ((forw_packet->direct_link_flags & (1 << packet_num)) &&
Marek Lindnere6c10f42011-02-18 12:33:20 +0000129 (forw_packet->if_incoming == hard_iface))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000130 batman_packet->flags |= DIRECTLINK;
131 else
132 batman_packet->flags &= ~DIRECTLINK;
133
134 fwd_str = (packet_num > 0 ? "Forwarding" : (forw_packet->own ?
135 "Sending own" :
136 "Forwarding"));
137 bat_dbg(DBG_BATMAN, bat_priv,
138 "%s %spacket (originator %pM, seqno %d, TQ %d, TTL %d,"
139 " IDF %s) on interface %s [%pM]\n",
140 fwd_str, (packet_num > 0 ? "aggregated " : ""),
141 batman_packet->orig, ntohl(batman_packet->seqno),
142 batman_packet->tq, batman_packet->ttl,
143 (batman_packet->flags & DIRECTLINK ?
144 "on" : "off"),
Marek Lindnere6c10f42011-02-18 12:33:20 +0000145 hard_iface->net_dev->name,
146 hard_iface->net_dev->dev_addr);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000147
148 buff_pos += sizeof(struct batman_packet) +
149 (batman_packet->num_hna * ETH_ALEN);
150 packet_num++;
151 batman_packet = (struct batman_packet *)
152 (forw_packet->skb->data + buff_pos);
153 }
154
155 /* create clone because function is called more than once */
156 skb = skb_clone(forw_packet->skb, GFP_ATOMIC);
157 if (skb)
Marek Lindnere6c10f42011-02-18 12:33:20 +0000158 send_skb_packet(skb, hard_iface, broadcast_addr);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000159}
160
161/* send a batman packet */
162static void send_packet(struct forw_packet *forw_packet)
163{
Marek Lindnere6c10f42011-02-18 12:33:20 +0000164 struct hard_iface *hard_iface;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000165 struct net_device *soft_iface;
166 struct bat_priv *bat_priv;
167 struct batman_packet *batman_packet =
168 (struct batman_packet *)(forw_packet->skb->data);
169 unsigned char directlink = (batman_packet->flags & DIRECTLINK ? 1 : 0);
170
171 if (!forw_packet->if_incoming) {
172 pr_err("Error - can't forward packet: incoming iface not "
173 "specified\n");
174 return;
175 }
176
177 soft_iface = forw_packet->if_incoming->soft_iface;
178 bat_priv = netdev_priv(soft_iface);
179
180 if (forw_packet->if_incoming->if_status != IF_ACTIVE)
181 return;
182
183 /* multihomed peer assumed */
184 /* non-primary OGMs are only broadcasted on their interface */
185 if ((directlink && (batman_packet->ttl == 1)) ||
186 (forw_packet->own && (forw_packet->if_incoming->if_num > 0))) {
187
188 /* FIXME: what about aggregated packets ? */
189 bat_dbg(DBG_BATMAN, bat_priv,
190 "%s packet (originator %pM, seqno %d, TTL %d) "
191 "on interface %s [%pM]\n",
192 (forw_packet->own ? "Sending own" : "Forwarding"),
193 batman_packet->orig, ntohl(batman_packet->seqno),
194 batman_packet->ttl,
195 forw_packet->if_incoming->net_dev->name,
196 forw_packet->if_incoming->net_dev->dev_addr);
197
198 /* skb is only used once and than forw_packet is free'd */
199 send_skb_packet(forw_packet->skb, forw_packet->if_incoming,
200 broadcast_addr);
201 forw_packet->skb = NULL;
202
203 return;
204 }
205
206 /* broadcast on every interface */
207 rcu_read_lock();
Marek Lindnere6c10f42011-02-18 12:33:20 +0000208 list_for_each_entry_rcu(hard_iface, &hardif_list, list) {
209 if (hard_iface->soft_iface != soft_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000210 continue;
211
Marek Lindnere6c10f42011-02-18 12:33:20 +0000212 send_packet_to_if(forw_packet, hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000213 }
214 rcu_read_unlock();
215}
216
217static void rebuild_batman_packet(struct bat_priv *bat_priv,
Marek Lindnere6c10f42011-02-18 12:33:20 +0000218 struct hard_iface *hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000219{
220 int new_len;
221 unsigned char *new_buff;
222 struct batman_packet *batman_packet;
223
224 new_len = sizeof(struct batman_packet) +
225 (bat_priv->num_local_hna * ETH_ALEN);
226 new_buff = kmalloc(new_len, GFP_ATOMIC);
227
228 /* keep old buffer if kmalloc should fail */
229 if (new_buff) {
Marek Lindnere6c10f42011-02-18 12:33:20 +0000230 memcpy(new_buff, hard_iface->packet_buff,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000231 sizeof(struct batman_packet));
232 batman_packet = (struct batman_packet *)new_buff;
233
234 batman_packet->num_hna = hna_local_fill_buffer(bat_priv,
235 new_buff + sizeof(struct batman_packet),
236 new_len - sizeof(struct batman_packet));
237
Marek Lindnere6c10f42011-02-18 12:33:20 +0000238 kfree(hard_iface->packet_buff);
239 hard_iface->packet_buff = new_buff;
240 hard_iface->packet_len = new_len;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000241 }
242}
243
Marek Lindnere6c10f42011-02-18 12:33:20 +0000244void schedule_own_packet(struct hard_iface *hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000245{
Marek Lindnere6c10f42011-02-18 12:33:20 +0000246 struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000247 unsigned long send_time;
248 struct batman_packet *batman_packet;
249 int vis_server;
250
Marek Lindnere6c10f42011-02-18 12:33:20 +0000251 if ((hard_iface->if_status == IF_NOT_IN_USE) ||
252 (hard_iface->if_status == IF_TO_BE_REMOVED))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000253 return;
254
255 vis_server = atomic_read(&bat_priv->vis_mode);
256
257 /**
258 * the interface gets activated here to avoid race conditions between
259 * the moment of activating the interface in
260 * hardif_activate_interface() where the originator mac is set and
261 * outdated packets (especially uninitialized mac addresses) in the
262 * packet queue
263 */
Marek Lindnere6c10f42011-02-18 12:33:20 +0000264 if (hard_iface->if_status == IF_TO_BE_ACTIVATED)
265 hard_iface->if_status = IF_ACTIVE;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000266
267 /* if local hna has changed and interface is a primary interface */
268 if ((atomic_read(&bat_priv->hna_local_changed)) &&
Marek Lindnere6c10f42011-02-18 12:33:20 +0000269 (hard_iface == bat_priv->primary_if))
270 rebuild_batman_packet(bat_priv, hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000271
272 /**
273 * NOTE: packet_buff might just have been re-allocated in
274 * rebuild_batman_packet()
275 */
Marek Lindnere6c10f42011-02-18 12:33:20 +0000276 batman_packet = (struct batman_packet *)hard_iface->packet_buff;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000277
278 /* change sequence number to network order */
279 batman_packet->seqno =
Marek Lindnere6c10f42011-02-18 12:33:20 +0000280 htonl((uint32_t)atomic_read(&hard_iface->seqno));
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000281
282 if (vis_server == VIS_TYPE_SERVER_SYNC)
283 batman_packet->flags |= VIS_SERVER;
284 else
285 batman_packet->flags &= ~VIS_SERVER;
286
Marek Lindnere6c10f42011-02-18 12:33:20 +0000287 if ((hard_iface == bat_priv->primary_if) &&
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000288 (atomic_read(&bat_priv->gw_mode) == GW_MODE_SERVER))
289 batman_packet->gw_flags =
290 (uint8_t)atomic_read(&bat_priv->gw_bandwidth);
291 else
292 batman_packet->gw_flags = 0;
293
Marek Lindnere6c10f42011-02-18 12:33:20 +0000294 atomic_inc(&hard_iface->seqno);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000295
Marek Lindnere6c10f42011-02-18 12:33:20 +0000296 slide_own_bcast_window(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000297 send_time = own_send_time(bat_priv);
298 add_bat_packet_to_list(bat_priv,
Marek Lindnere6c10f42011-02-18 12:33:20 +0000299 hard_iface->packet_buff,
300 hard_iface->packet_len,
301 hard_iface, 1, send_time);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000302}
303
304void schedule_forward_packet(struct orig_node *orig_node,
305 struct ethhdr *ethhdr,
306 struct batman_packet *batman_packet,
307 uint8_t directlink, int hna_buff_len,
Marek Lindnere6c10f42011-02-18 12:33:20 +0000308 struct hard_iface *if_incoming)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000309{
310 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
Linus Lüssinge1a53822011-03-14 22:43:37 +0000311 struct neigh_node *router;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000312 unsigned char in_tq, in_ttl, tq_avg = 0;
313 unsigned long send_time;
314
315 if (batman_packet->ttl <= 1) {
316 bat_dbg(DBG_BATMAN, bat_priv, "ttl exceeded\n");
317 return;
318 }
319
Linus Lüssinge1a53822011-03-14 22:43:37 +0000320 router = orig_node_get_router(orig_node);
321
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000322 in_tq = batman_packet->tq;
323 in_ttl = batman_packet->ttl;
324
325 batman_packet->ttl--;
326 memcpy(batman_packet->prev_sender, ethhdr->h_source, ETH_ALEN);
327
328 /* rebroadcast tq of our best ranking neighbor to ensure the rebroadcast
329 * of our best tq value */
Linus Lüssinge1a53822011-03-14 22:43:37 +0000330 if (router && router->tq_avg != 0) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000331
332 /* rebroadcast ogm of best ranking neighbor as is */
Linus Lüssinge1a53822011-03-14 22:43:37 +0000333 if (!compare_eth(router->addr, ethhdr->h_source)) {
334 batman_packet->tq = router->tq_avg;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000335
Linus Lüssinge1a53822011-03-14 22:43:37 +0000336 if (router->last_ttl)
337 batman_packet->ttl = router->last_ttl - 1;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000338 }
339
Linus Lüssinge1a53822011-03-14 22:43:37 +0000340 tq_avg = router->tq_avg;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000341 }
342
Linus Lüssinge1a53822011-03-14 22:43:37 +0000343 if (router)
344 neigh_node_free_ref(router);
345
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000346 /* apply hop penalty */
347 batman_packet->tq = hop_penalty(batman_packet->tq, bat_priv);
348
349 bat_dbg(DBG_BATMAN, bat_priv,
350 "Forwarding packet: tq_orig: %i, tq_avg: %i, "
351 "tq_forw: %i, ttl_orig: %i, ttl_forw: %i\n",
352 in_tq, tq_avg, batman_packet->tq, in_ttl - 1,
353 batman_packet->ttl);
354
355 batman_packet->seqno = htonl(batman_packet->seqno);
356
357 /* switch of primaries first hop flag when forwarding */
358 batman_packet->flags &= ~PRIMARIES_FIRST_HOP;
359 if (directlink)
360 batman_packet->flags |= DIRECTLINK;
361 else
362 batman_packet->flags &= ~DIRECTLINK;
363
Simon Wunderlich74ef1152010-12-29 16:15:19 +0000364 send_time = forward_send_time();
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000365 add_bat_packet_to_list(bat_priv,
366 (unsigned char *)batman_packet,
367 sizeof(struct batman_packet) + hna_buff_len,
368 if_incoming, 0, send_time);
369}
370
371static void forw_packet_free(struct forw_packet *forw_packet)
372{
373 if (forw_packet->skb)
374 kfree_skb(forw_packet->skb);
375 kfree(forw_packet);
376}
377
378static void _add_bcast_packet_to_list(struct bat_priv *bat_priv,
379 struct forw_packet *forw_packet,
380 unsigned long send_time)
381{
382 INIT_HLIST_NODE(&forw_packet->list);
383
384 /* add new packet to packet list */
385 spin_lock_bh(&bat_priv->forw_bcast_list_lock);
386 hlist_add_head(&forw_packet->list, &bat_priv->forw_bcast_list);
387 spin_unlock_bh(&bat_priv->forw_bcast_list_lock);
388
389 /* start timer for this packet */
390 INIT_DELAYED_WORK(&forw_packet->delayed_work,
391 send_outstanding_bcast_packet);
392 queue_delayed_work(bat_event_workqueue, &forw_packet->delayed_work,
393 send_time);
394}
395
396#define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0)
397/* add a broadcast packet to the queue and setup timers. broadcast packets
398 * are sent multiple times to increase probability for beeing received.
399 *
400 * This function returns NETDEV_TX_OK on success and NETDEV_TX_BUSY on
401 * errors.
402 *
403 * The skb is not consumed, so the caller should make sure that the
404 * skb is freed. */
405int add_bcast_packet_to_list(struct bat_priv *bat_priv, struct sk_buff *skb)
406{
407 struct forw_packet *forw_packet;
408 struct bcast_packet *bcast_packet;
409
410 if (!atomic_dec_not_zero(&bat_priv->bcast_queue_left)) {
411 bat_dbg(DBG_BATMAN, bat_priv, "bcast packet queue full\n");
412 goto out;
413 }
414
415 if (!bat_priv->primary_if)
416 goto out;
417
418 forw_packet = kmalloc(sizeof(struct forw_packet), GFP_ATOMIC);
419
420 if (!forw_packet)
421 goto out_and_inc;
422
423 skb = skb_copy(skb, GFP_ATOMIC);
424 if (!skb)
425 goto packet_free;
426
427 /* as we have a copy now, it is safe to decrease the TTL */
428 bcast_packet = (struct bcast_packet *)skb->data;
429 bcast_packet->ttl--;
430
431 skb_reset_mac_header(skb);
432
433 forw_packet->skb = skb;
434 forw_packet->if_incoming = bat_priv->primary_if;
435
436 /* how often did we send the bcast packet ? */
437 forw_packet->num_packets = 0;
438
439 _add_bcast_packet_to_list(bat_priv, forw_packet, 1);
440 return NETDEV_TX_OK;
441
442packet_free:
443 kfree(forw_packet);
444out_and_inc:
445 atomic_inc(&bat_priv->bcast_queue_left);
446out:
447 return NETDEV_TX_BUSY;
448}
449
450static void send_outstanding_bcast_packet(struct work_struct *work)
451{
Marek Lindnere6c10f42011-02-18 12:33:20 +0000452 struct hard_iface *hard_iface;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000453 struct delayed_work *delayed_work =
454 container_of(work, struct delayed_work, work);
455 struct forw_packet *forw_packet =
456 container_of(delayed_work, struct forw_packet, delayed_work);
457 struct sk_buff *skb1;
458 struct net_device *soft_iface = forw_packet->if_incoming->soft_iface;
459 struct bat_priv *bat_priv = netdev_priv(soft_iface);
460
461 spin_lock_bh(&bat_priv->forw_bcast_list_lock);
462 hlist_del(&forw_packet->list);
463 spin_unlock_bh(&bat_priv->forw_bcast_list_lock);
464
465 if (atomic_read(&bat_priv->mesh_state) == MESH_DEACTIVATING)
466 goto out;
467
468 /* rebroadcast packet */
469 rcu_read_lock();
Marek Lindnere6c10f42011-02-18 12:33:20 +0000470 list_for_each_entry_rcu(hard_iface, &hardif_list, list) {
471 if (hard_iface->soft_iface != soft_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000472 continue;
473
474 /* send a copy of the saved skb */
475 skb1 = skb_clone(forw_packet->skb, GFP_ATOMIC);
476 if (skb1)
Marek Lindnere6c10f42011-02-18 12:33:20 +0000477 send_skb_packet(skb1, hard_iface, broadcast_addr);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000478 }
479 rcu_read_unlock();
480
481 forw_packet->num_packets++;
482
483 /* if we still have some more bcasts to send */
484 if (forw_packet->num_packets < 3) {
485 _add_bcast_packet_to_list(bat_priv, forw_packet,
486 ((5 * HZ) / 1000));
487 return;
488 }
489
490out:
491 forw_packet_free(forw_packet);
492 atomic_inc(&bat_priv->bcast_queue_left);
493}
494
495void send_outstanding_bat_packet(struct work_struct *work)
496{
497 struct delayed_work *delayed_work =
498 container_of(work, struct delayed_work, work);
499 struct forw_packet *forw_packet =
500 container_of(delayed_work, struct forw_packet, delayed_work);
501 struct bat_priv *bat_priv;
502
503 bat_priv = netdev_priv(forw_packet->if_incoming->soft_iface);
504 spin_lock_bh(&bat_priv->forw_bat_list_lock);
505 hlist_del(&forw_packet->list);
506 spin_unlock_bh(&bat_priv->forw_bat_list_lock);
507
508 if (atomic_read(&bat_priv->mesh_state) == MESH_DEACTIVATING)
509 goto out;
510
511 send_packet(forw_packet);
512
513 /**
514 * we have to have at least one packet in the queue
515 * to determine the queues wake up time unless we are
516 * shutting down
517 */
518 if (forw_packet->own)
519 schedule_own_packet(forw_packet->if_incoming);
520
521out:
522 /* don't count own packet */
523 if (!forw_packet->own)
524 atomic_inc(&bat_priv->batman_queue_left);
525
526 forw_packet_free(forw_packet);
527}
528
529void purge_outstanding_packets(struct bat_priv *bat_priv,
Marek Lindnere6c10f42011-02-18 12:33:20 +0000530 struct hard_iface *hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000531{
532 struct forw_packet *forw_packet;
533 struct hlist_node *tmp_node, *safe_tmp_node;
534
Marek Lindnere6c10f42011-02-18 12:33:20 +0000535 if (hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000536 bat_dbg(DBG_BATMAN, bat_priv,
537 "purge_outstanding_packets(): %s\n",
Marek Lindnere6c10f42011-02-18 12:33:20 +0000538 hard_iface->net_dev->name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000539 else
540 bat_dbg(DBG_BATMAN, bat_priv,
541 "purge_outstanding_packets()\n");
542
543 /* free bcast list */
544 spin_lock_bh(&bat_priv->forw_bcast_list_lock);
545 hlist_for_each_entry_safe(forw_packet, tmp_node, safe_tmp_node,
546 &bat_priv->forw_bcast_list, list) {
547
548 /**
549 * if purge_outstanding_packets() was called with an argmument
550 * we delete only packets belonging to the given interface
551 */
Marek Lindnere6c10f42011-02-18 12:33:20 +0000552 if ((hard_iface) &&
553 (forw_packet->if_incoming != hard_iface))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000554 continue;
555
556 spin_unlock_bh(&bat_priv->forw_bcast_list_lock);
557
558 /**
559 * send_outstanding_bcast_packet() will lock the list to
560 * delete the item from the list
561 */
562 cancel_delayed_work_sync(&forw_packet->delayed_work);
563 spin_lock_bh(&bat_priv->forw_bcast_list_lock);
564 }
565 spin_unlock_bh(&bat_priv->forw_bcast_list_lock);
566
567 /* free batman packet list */
568 spin_lock_bh(&bat_priv->forw_bat_list_lock);
569 hlist_for_each_entry_safe(forw_packet, tmp_node, safe_tmp_node,
570 &bat_priv->forw_bat_list, list) {
571
572 /**
573 * if purge_outstanding_packets() was called with an argmument
574 * we delete only packets belonging to the given interface
575 */
Marek Lindnere6c10f42011-02-18 12:33:20 +0000576 if ((hard_iface) &&
577 (forw_packet->if_incoming != hard_iface))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000578 continue;
579
580 spin_unlock_bh(&bat_priv->forw_bat_list_lock);
581
582 /**
583 * send_outstanding_bat_packet() will lock the list to
584 * delete the item from the list
585 */
586 cancel_delayed_work_sync(&forw_packet->delayed_work);
587 spin_lock_bh(&bat_priv->forw_bat_list_lock);
588 }
589 spin_unlock_bh(&bat_priv->forw_bat_list_lock);
590}