send.c (3193e8fdfa355289892661d206d1954114a7be95) send.c (9cfc7bd608b97463993b4f3e4775d99022253f8d)
1/*
2 * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors:
1/* Copyright (C) 2007-2012 B.A.T.M.A.N. contributors:
3 *
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
2 *
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
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"
28#include "vis.h"
29#include "gateway_common.h"
30#include "originator.h"
31
32static void send_outstanding_bcast_packet(struct work_struct *work);
33
34/* send out an already prepared packet to the given address via the
18 */
19
20#include "main.h"
21#include "send.h"
22#include "routing.h"
23#include "translation-table.h"
24#include "soft-interface.h"
25#include "hard-interface.h"
26#include "vis.h"
27#include "gateway_common.h"
28#include "originator.h"
29
30static void send_outstanding_bcast_packet(struct work_struct *work);
31
32/* send out an already prepared packet to the given address via the
35 * specified batman interface */
33 * specified batman interface
34 */
36int batadv_send_skb_packet(struct sk_buff *skb, struct hard_iface *hard_iface,
37 const uint8_t *dst_addr)
38{
39 struct ethhdr *ethhdr;
40
41 if (hard_iface->if_status != IF_ACTIVE)
42 goto send_skb_err;
43

--- 20 unchanged lines hidden (view full) ---

64 skb_set_network_header(skb, ETH_HLEN);
65 skb->priority = TC_PRIO_CONTROL;
66 skb->protocol = __constant_htons(ETH_P_BATMAN);
67
68 skb->dev = hard_iface->net_dev;
69
70 /* dev_queue_xmit() returns a negative result on error. However on
71 * congestion and traffic shaping, it drops and returns NET_XMIT_DROP
35int batadv_send_skb_packet(struct sk_buff *skb, struct hard_iface *hard_iface,
36 const uint8_t *dst_addr)
37{
38 struct ethhdr *ethhdr;
39
40 if (hard_iface->if_status != IF_ACTIVE)
41 goto send_skb_err;
42

--- 20 unchanged lines hidden (view full) ---

63 skb_set_network_header(skb, ETH_HLEN);
64 skb->priority = TC_PRIO_CONTROL;
65 skb->protocol = __constant_htons(ETH_P_BATMAN);
66
67 skb->dev = hard_iface->net_dev;
68
69 /* dev_queue_xmit() returns a negative result on error. However on
70 * congestion and traffic shaping, it drops and returns NET_XMIT_DROP
72 * (which is > 0). This will not be treated as an error. */
73
71 * (which is > 0). This will not be treated as an error.
72 */
74 return dev_queue_xmit(skb);
75send_skb_err:
76 kfree_skb(skb);
77 return NET_XMIT_DROP;
78}
79
80void batadv_schedule_bat_ogm(struct hard_iface *hard_iface)
81{
82 struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
83
84 if ((hard_iface->if_status == IF_NOT_IN_USE) ||
85 (hard_iface->if_status == IF_TO_BE_REMOVED))
86 return;
87
73 return dev_queue_xmit(skb);
74send_skb_err:
75 kfree_skb(skb);
76 return NET_XMIT_DROP;
77}
78
79void batadv_schedule_bat_ogm(struct hard_iface *hard_iface)
80{
81 struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
82
83 if ((hard_iface->if_status == IF_NOT_IN_USE) ||
84 (hard_iface->if_status == IF_TO_BE_REMOVED))
85 return;
86
88 /**
89 * the interface gets activated here to avoid race conditions between
87 /* the interface gets activated here to avoid race conditions between
90 * the moment of activating the interface in
91 * hardif_activate_interface() where the originator mac is set and
92 * outdated packets (especially uninitialized mac addresses) in the
93 * packet queue
94 */
95 if (hard_iface->if_status == IF_TO_BE_ACTIVATED)
96 hard_iface->if_status = IF_ACTIVE;
97

--- 29 unchanged lines hidden (view full) ---

127
128/* add a broadcast packet to the queue and setup timers. broadcast packets
129 * are sent multiple times to increase probability for being received.
130 *
131 * This function returns NETDEV_TX_OK on success and NETDEV_TX_BUSY on
132 * errors.
133 *
134 * The skb is not consumed, so the caller should make sure that the
88 * the moment of activating the interface in
89 * hardif_activate_interface() where the originator mac is set and
90 * outdated packets (especially uninitialized mac addresses) in the
91 * packet queue
92 */
93 if (hard_iface->if_status == IF_TO_BE_ACTIVATED)
94 hard_iface->if_status = IF_ACTIVE;
95

--- 29 unchanged lines hidden (view full) ---

125
126/* add a broadcast packet to the queue and setup timers. broadcast packets
127 * are sent multiple times to increase probability for being received.
128 *
129 * This function returns NETDEV_TX_OK on success and NETDEV_TX_BUSY on
130 * errors.
131 *
132 * The skb is not consumed, so the caller should make sure that the
135 * skb is freed. */
133 * skb is freed.
134 */
136int batadv_add_bcast_packet_to_list(struct bat_priv *bat_priv,
137 const struct sk_buff *skb,
138 unsigned long delay)
139{
140 struct hard_iface *primary_if = NULL;
141 struct forw_packet *forw_packet;
142 struct bcast_packet *bcast_packet;
143 struct sk_buff *newskb;

--- 100 unchanged lines hidden (view full) ---

244 hlist_del(&forw_packet->list);
245 spin_unlock_bh(&bat_priv->forw_bat_list_lock);
246
247 if (atomic_read(&bat_priv->mesh_state) == MESH_DEACTIVATING)
248 goto out;
249
250 bat_priv->bat_algo_ops->bat_ogm_emit(forw_packet);
251
135int batadv_add_bcast_packet_to_list(struct bat_priv *bat_priv,
136 const struct sk_buff *skb,
137 unsigned long delay)
138{
139 struct hard_iface *primary_if = NULL;
140 struct forw_packet *forw_packet;
141 struct bcast_packet *bcast_packet;
142 struct sk_buff *newskb;

--- 100 unchanged lines hidden (view full) ---

243 hlist_del(&forw_packet->list);
244 spin_unlock_bh(&bat_priv->forw_bat_list_lock);
245
246 if (atomic_read(&bat_priv->mesh_state) == MESH_DEACTIVATING)
247 goto out;
248
249 bat_priv->bat_algo_ops->bat_ogm_emit(forw_packet);
250
252 /**
253 * we have to have at least one packet in the queue
251 /* we have to have at least one packet in the queue
254 * to determine the queues wake up time unless we are
255 * shutting down
256 */
257 if (forw_packet->own)
258 batadv_schedule_bat_ogm(forw_packet->if_incoming);
259
260out:
261 /* don't count own packet */

--- 18 unchanged lines hidden (view full) ---

280 bat_dbg(DBG_BATMAN, bat_priv,
281 "purge_outstanding_packets()\n");
282
283 /* free bcast list */
284 spin_lock_bh(&bat_priv->forw_bcast_list_lock);
285 hlist_for_each_entry_safe(forw_packet, tmp_node, safe_tmp_node,
286 &bat_priv->forw_bcast_list, list) {
287
252 * to determine the queues wake up time unless we are
253 * shutting down
254 */
255 if (forw_packet->own)
256 batadv_schedule_bat_ogm(forw_packet->if_incoming);
257
258out:
259 /* don't count own packet */

--- 18 unchanged lines hidden (view full) ---

278 bat_dbg(DBG_BATMAN, bat_priv,
279 "purge_outstanding_packets()\n");
280
281 /* free bcast list */
282 spin_lock_bh(&bat_priv->forw_bcast_list_lock);
283 hlist_for_each_entry_safe(forw_packet, tmp_node, safe_tmp_node,
284 &bat_priv->forw_bcast_list, list) {
285
288 /**
289 * if purge_outstanding_packets() was called with an argument
286 /* if purge_outstanding_packets() was called with an argument
290 * we delete only packets belonging to the given interface
291 */
292 if ((hard_iface) &&
293 (forw_packet->if_incoming != hard_iface))
294 continue;
295
296 spin_unlock_bh(&bat_priv->forw_bcast_list_lock);
297
287 * we delete only packets belonging to the given interface
288 */
289 if ((hard_iface) &&
290 (forw_packet->if_incoming != hard_iface))
291 continue;
292
293 spin_unlock_bh(&bat_priv->forw_bcast_list_lock);
294
298 /**
299 * send_outstanding_bcast_packet() will lock the list to
295 /* send_outstanding_bcast_packet() will lock the list to
300 * delete the item from the list
301 */
302 pending = cancel_delayed_work_sync(&forw_packet->delayed_work);
303 spin_lock_bh(&bat_priv->forw_bcast_list_lock);
304
305 if (pending) {
306 hlist_del(&forw_packet->list);
307 forw_packet_free(forw_packet);
308 }
309 }
310 spin_unlock_bh(&bat_priv->forw_bcast_list_lock);
311
312 /* free batman packet list */
313 spin_lock_bh(&bat_priv->forw_bat_list_lock);
314 hlist_for_each_entry_safe(forw_packet, tmp_node, safe_tmp_node,
315 &bat_priv->forw_bat_list, list) {
316
296 * delete the item from the list
297 */
298 pending = cancel_delayed_work_sync(&forw_packet->delayed_work);
299 spin_lock_bh(&bat_priv->forw_bcast_list_lock);
300
301 if (pending) {
302 hlist_del(&forw_packet->list);
303 forw_packet_free(forw_packet);
304 }
305 }
306 spin_unlock_bh(&bat_priv->forw_bcast_list_lock);
307
308 /* free batman packet list */
309 spin_lock_bh(&bat_priv->forw_bat_list_lock);
310 hlist_for_each_entry_safe(forw_packet, tmp_node, safe_tmp_node,
311 &bat_priv->forw_bat_list, list) {
312
317 /**
318 * if purge_outstanding_packets() was called with an argument
313 /* if purge_outstanding_packets() was called with an argument
319 * we delete only packets belonging to the given interface
320 */
321 if ((hard_iface) &&
322 (forw_packet->if_incoming != hard_iface))
323 continue;
324
325 spin_unlock_bh(&bat_priv->forw_bat_list_lock);
326
314 * we delete only packets belonging to the given interface
315 */
316 if ((hard_iface) &&
317 (forw_packet->if_incoming != hard_iface))
318 continue;
319
320 spin_unlock_bh(&bat_priv->forw_bat_list_lock);
321
327 /**
328 * send_outstanding_bat_packet() will lock the list to
322 /* send_outstanding_bat_packet() will lock the list to
329 * delete the item from the list
330 */
331 pending = cancel_delayed_work_sync(&forw_packet->delayed_work);
332 spin_lock_bh(&bat_priv->forw_bat_list_lock);
333
334 if (pending) {
335 hlist_del(&forw_packet->list);
336 forw_packet_free(forw_packet);
337 }
338 }
339 spin_unlock_bh(&bat_priv->forw_bat_list_lock);
340}
323 * delete the item from the list
324 */
325 pending = cancel_delayed_work_sync(&forw_packet->delayed_work);
326 spin_lock_bh(&bat_priv->forw_bat_list_lock);
327
328 if (pending) {
329 hlist_del(&forw_packet->list);
330 forw_packet_free(forw_packet);
331 }
332 }
333 spin_unlock_bh(&bat_priv->forw_bat_list_lock);
334}