blob: 62b52b663afb7264d11006f9dc1e1a7ec06be753 [file] [log] [blame]
Marek Lindnerfc957272011-07-30 12:04:12 +02001/*
Sven Eckelmann567db7b2012-01-01 00:41:38 +01002 * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors:
Marek Lindnerfc957272011-07-30 12:04:12 +02003 *
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"
Marek Lindnerfc957272011-07-30 12:04:12 +020023#include "translation-table.h"
24#include "ring_buffer.h"
25#include "originator.h"
26#include "routing.h"
27#include "gateway_common.h"
28#include "gateway_client.h"
29#include "hard-interface.h"
30#include "send.h"
Marek Lindner1c280472011-11-28 17:40:17 +080031#include "bat_algo.h"
Marek Lindnerfc957272011-07-30 12:04:12 +020032
Marek Lindner7ae8b282012-03-01 15:35:21 +080033static struct neigh_node *bat_iv_ogm_neigh_new(struct hard_iface *hard_iface,
34 const uint8_t *neigh_addr,
35 struct orig_node *orig_node,
36 struct orig_node *orig_neigh,
Al Viroe0f52112012-04-22 07:46:29 +010037 __be32 seqno)
Marek Lindner7ae8b282012-03-01 15:35:21 +080038{
39 struct neigh_node *neigh_node;
40
Al Viroe0f52112012-04-22 07:46:29 +010041 neigh_node = batadv_neigh_node_new(hard_iface, neigh_addr,
42 ntohl(seqno));
Marek Lindner7ae8b282012-03-01 15:35:21 +080043 if (!neigh_node)
44 goto out;
45
46 INIT_LIST_HEAD(&neigh_node->bonding_list);
Marek Lindner7ae8b282012-03-01 15:35:21 +080047
48 neigh_node->orig_node = orig_neigh;
49 neigh_node->if_incoming = hard_iface;
50
51 spin_lock_bh(&orig_node->neigh_list_lock);
52 hlist_add_head_rcu(&neigh_node->list, &orig_node->neigh_list);
53 spin_unlock_bh(&orig_node->neigh_list_lock);
54
55out:
56 return neigh_node;
57}
58
Marek Lindner77af7572012-02-07 17:20:48 +080059static int bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
Marek Lindnerd0b9fd82011-07-30 12:33:33 +020060{
61 struct batman_ogm_packet *batman_ogm_packet;
Marek Lindnerd7d32ec2012-02-07 17:20:46 +080062 uint32_t random_seqno;
Sven Eckelmann5346c352012-05-05 13:27:28 +020063 int res = -ENOMEM;
Marek Lindnerd7d32ec2012-02-07 17:20:46 +080064
65 /* randomize initial seqno to avoid collision */
66 get_random_bytes(&random_seqno, sizeof(random_seqno));
67 atomic_set(&hard_iface->seqno, random_seqno);
Marek Lindnerd0b9fd82011-07-30 12:33:33 +020068
Marek Lindner76e3d7f2012-02-07 17:20:50 +080069 hard_iface->packet_len = BATMAN_OGM_HLEN;
Marek Lindnerd0b9fd82011-07-30 12:33:33 +020070 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
71
Marek Lindner77af7572012-02-07 17:20:48 +080072 if (!hard_iface->packet_buff)
73 goto out;
74
Marek Lindnerd0b9fd82011-07-30 12:33:33 +020075 batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff;
Marek Lindner1eeb4792012-02-07 17:20:51 +080076 batman_ogm_packet->header.packet_type = BAT_IV_OGM;
Sven Eckelmann76543d12011-11-20 15:47:38 +010077 batman_ogm_packet->header.version = COMPAT_VERSION;
78 batman_ogm_packet->header.ttl = 2;
Marek Lindnerd0b9fd82011-07-30 12:33:33 +020079 batman_ogm_packet->flags = NO_FLAGS;
Marek Lindnerd0b9fd82011-07-30 12:33:33 +020080 batman_ogm_packet->tq = TQ_MAX_VALUE;
81 batman_ogm_packet->tt_num_changes = 0;
82 batman_ogm_packet->ttvn = 0;
Marek Lindner77af7572012-02-07 17:20:48 +080083
84 res = 0;
85
86out:
87 return res;
Marek Lindnerd0b9fd82011-07-30 12:33:33 +020088}
89
Marek Lindner00a50072012-02-07 17:20:47 +080090static void bat_iv_ogm_iface_disable(struct hard_iface *hard_iface)
91{
92 kfree(hard_iface->packet_buff);
93 hard_iface->packet_buff = NULL;
94}
95
Marek Lindnerc3229392012-03-11 06:17:50 +080096static void bat_iv_ogm_iface_update_mac(struct hard_iface *hard_iface)
Marek Lindnerd0b9fd82011-07-30 12:33:33 +020097{
98 struct batman_ogm_packet *batman_ogm_packet;
99
100 batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff;
101 memcpy(batman_ogm_packet->orig,
102 hard_iface->net_dev->dev_addr, ETH_ALEN);
103 memcpy(batman_ogm_packet->prev_sender,
104 hard_iface->net_dev->dev_addr, ETH_ALEN);
105}
106
Marek Lindnerc3229392012-03-11 06:17:50 +0800107static void bat_iv_ogm_primary_iface_set(struct hard_iface *hard_iface)
108{
109 struct batman_ogm_packet *batman_ogm_packet;
110
111 batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff;
112 batman_ogm_packet->flags = PRIMARIES_FIRST_HOP;
113 batman_ogm_packet->header.ttl = TTL;
114}
115
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200116/* when do we schedule our own ogm to be sent */
Marek Lindner01c42242011-11-28 21:31:55 +0800117static unsigned long bat_iv_ogm_emit_send_time(const struct bat_priv *bat_priv)
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200118{
119 return jiffies + msecs_to_jiffies(
120 atomic_read(&bat_priv->orig_interval) -
121 JITTER + (random32() % 2*JITTER));
122}
123
124/* when do we schedule a ogm packet to be sent */
Marek Lindner01c42242011-11-28 21:31:55 +0800125static unsigned long bat_iv_ogm_fwd_send_time(void)
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200126{
127 return jiffies + msecs_to_jiffies(random32() % (JITTER/2));
128}
129
130/* apply hop penalty for a normal link */
131static uint8_t hop_penalty(uint8_t tq, const struct bat_priv *bat_priv)
132{
133 int hop_penalty = atomic_read(&bat_priv->hop_penalty);
134 return (tq * (TQ_MAX_VALUE - hop_penalty)) / (TQ_MAX_VALUE);
135}
136
Marek Lindnerfc957272011-07-30 12:04:12 +0200137/* is there another aggregated packet here? */
Marek Lindner01c42242011-11-28 21:31:55 +0800138static int bat_iv_ogm_aggr_packet(int buff_pos, int packet_len,
139 int tt_num_changes)
Marek Lindnerfc957272011-07-30 12:04:12 +0200140{
Sven Eckelmann08c36d32012-05-12 02:09:39 +0200141 int next_buff_pos = 0;
142
143 next_buff_pos += buff_pos + BATMAN_OGM_HLEN;
144 next_buff_pos += batadv_tt_len(tt_num_changes);
Marek Lindnerfc957272011-07-30 12:04:12 +0200145
146 return (next_buff_pos <= packet_len) &&
147 (next_buff_pos <= MAX_AGGREGATION_BYTES);
148}
149
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200150/* send a batman ogm to a given interface */
Marek Lindner01c42242011-11-28 21:31:55 +0800151static void bat_iv_ogm_send_to_if(struct forw_packet *forw_packet,
152 struct hard_iface *hard_iface)
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200153{
154 struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
155 char *fwd_str;
156 uint8_t packet_num;
157 int16_t buff_pos;
158 struct batman_ogm_packet *batman_ogm_packet;
159 struct sk_buff *skb;
160
161 if (hard_iface->if_status != IF_ACTIVE)
162 return;
163
164 packet_num = 0;
165 buff_pos = 0;
166 batman_ogm_packet = (struct batman_ogm_packet *)forw_packet->skb->data;
167
168 /* adjust all flags and log packets */
Marek Lindner01c42242011-11-28 21:31:55 +0800169 while (bat_iv_ogm_aggr_packet(buff_pos, forw_packet->packet_len,
170 batman_ogm_packet->tt_num_changes)) {
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200171
172 /* we might have aggregated direct link packets with an
173 * ordinary base packet */
174 if ((forw_packet->direct_link_flags & (1 << packet_num)) &&
175 (forw_packet->if_incoming == hard_iface))
176 batman_ogm_packet->flags |= DIRECTLINK;
177 else
178 batman_ogm_packet->flags &= ~DIRECTLINK;
179
180 fwd_str = (packet_num > 0 ? "Forwarding" : (forw_packet->own ?
181 "Sending own" :
182 "Forwarding"));
183 bat_dbg(DBG_BATMAN, bat_priv,
Antonio Quartullic97c72b2012-02-26 15:39:41 +0100184 "%s %spacket (originator %pM, seqno %u, TQ %d, TTL %d, IDF %s, ttvn %d) on interface %s [%pM]\n",
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200185 fwd_str, (packet_num > 0 ? "aggregated " : ""),
186 batman_ogm_packet->orig,
187 ntohl(batman_ogm_packet->seqno),
Sven Eckelmann76543d12011-11-20 15:47:38 +0100188 batman_ogm_packet->tq, batman_ogm_packet->header.ttl,
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200189 (batman_ogm_packet->flags & DIRECTLINK ?
190 "on" : "off"),
191 batman_ogm_packet->ttvn, hard_iface->net_dev->name,
192 hard_iface->net_dev->dev_addr);
193
Sven Eckelmann08c36d32012-05-12 02:09:39 +0200194 buff_pos += BATMAN_OGM_HLEN;
195 buff_pos += batadv_tt_len(batman_ogm_packet->tt_num_changes);
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200196 packet_num++;
197 batman_ogm_packet = (struct batman_ogm_packet *)
198 (forw_packet->skb->data + buff_pos);
199 }
200
201 /* create clone because function is called more than once */
202 skb = skb_clone(forw_packet->skb, GFP_ATOMIC);
Martin Hundebøllf8214862012-04-20 17:02:45 +0200203 if (skb) {
204 batadv_inc_counter(bat_priv, BAT_CNT_MGMT_TX);
205 batadv_add_counter(bat_priv, BAT_CNT_MGMT_TX_BYTES,
206 skb->len + ETH_HLEN);
Sven Eckelmann9455e342012-05-12 02:09:37 +0200207 batadv_send_skb_packet(skb, hard_iface, broadcast_addr);
Martin Hundebøllf8214862012-04-20 17:02:45 +0200208 }
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200209}
210
211/* send a batman ogm packet */
Marek Lindner01c42242011-11-28 21:31:55 +0800212static void bat_iv_ogm_emit(struct forw_packet *forw_packet)
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200213{
214 struct hard_iface *hard_iface;
215 struct net_device *soft_iface;
216 struct bat_priv *bat_priv;
217 struct hard_iface *primary_if = NULL;
218 struct batman_ogm_packet *batman_ogm_packet;
219 unsigned char directlink;
220
221 batman_ogm_packet = (struct batman_ogm_packet *)
222 (forw_packet->skb->data);
223 directlink = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
224
225 if (!forw_packet->if_incoming) {
Sven Eckelmann86ceb362012-03-07 09:07:45 +0100226 pr_err("Error - can't forward packet: incoming iface not specified\n");
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200227 goto out;
228 }
229
230 soft_iface = forw_packet->if_incoming->soft_iface;
231 bat_priv = netdev_priv(soft_iface);
232
233 if (forw_packet->if_incoming->if_status != IF_ACTIVE)
234 goto out;
235
236 primary_if = primary_if_get_selected(bat_priv);
237 if (!primary_if)
238 goto out;
239
240 /* multihomed peer assumed */
241 /* non-primary OGMs are only broadcasted on their interface */
Sven Eckelmann76543d12011-11-20 15:47:38 +0100242 if ((directlink && (batman_ogm_packet->header.ttl == 1)) ||
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200243 (forw_packet->own && (forw_packet->if_incoming != primary_if))) {
244
245 /* FIXME: what about aggregated packets ? */
246 bat_dbg(DBG_BATMAN, bat_priv,
Antonio Quartullic97c72b2012-02-26 15:39:41 +0100247 "%s packet (originator %pM, seqno %u, TTL %d) on interface %s [%pM]\n",
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200248 (forw_packet->own ? "Sending own" : "Forwarding"),
249 batman_ogm_packet->orig,
250 ntohl(batman_ogm_packet->seqno),
Sven Eckelmann76543d12011-11-20 15:47:38 +0100251 batman_ogm_packet->header.ttl,
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200252 forw_packet->if_incoming->net_dev->name,
253 forw_packet->if_incoming->net_dev->dev_addr);
254
255 /* skb is only used once and than forw_packet is free'd */
Sven Eckelmann9455e342012-05-12 02:09:37 +0200256 batadv_send_skb_packet(forw_packet->skb,
257 forw_packet->if_incoming,
258 broadcast_addr);
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200259 forw_packet->skb = NULL;
260
261 goto out;
262 }
263
264 /* broadcast on every interface */
265 rcu_read_lock();
266 list_for_each_entry_rcu(hard_iface, &hardif_list, list) {
267 if (hard_iface->soft_iface != soft_iface)
268 continue;
269
Marek Lindner01c42242011-11-28 21:31:55 +0800270 bat_iv_ogm_send_to_if(forw_packet, hard_iface);
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200271 }
272 rcu_read_unlock();
273
274out:
275 if (primary_if)
276 hardif_free_ref(primary_if);
277}
278
279/* return true if new_packet can be aggregated with forw_packet */
Marek Lindner01c42242011-11-28 21:31:55 +0800280static bool bat_iv_ogm_can_aggregate(const struct batman_ogm_packet
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200281 *new_batman_ogm_packet,
Marek Lindner01c42242011-11-28 21:31:55 +0800282 struct bat_priv *bat_priv,
283 int packet_len, unsigned long send_time,
284 bool directlink,
285 const struct hard_iface *if_incoming,
286 const struct forw_packet *forw_packet)
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200287{
288 struct batman_ogm_packet *batman_ogm_packet;
289 int aggregated_bytes = forw_packet->packet_len + packet_len;
290 struct hard_iface *primary_if = NULL;
291 bool res = false;
292
293 batman_ogm_packet = (struct batman_ogm_packet *)forw_packet->skb->data;
294
295 /**
296 * we can aggregate the current packet to this aggregated packet
297 * if:
298 *
299 * - the send time is within our MAX_AGGREGATION_MS time
300 * - the resulting packet wont be bigger than
301 * MAX_AGGREGATION_BYTES
302 */
303
304 if (time_before(send_time, forw_packet->send_time) &&
305 time_after_eq(send_time + msecs_to_jiffies(MAX_AGGREGATION_MS),
306 forw_packet->send_time) &&
307 (aggregated_bytes <= MAX_AGGREGATION_BYTES)) {
308
309 /**
310 * check aggregation compatibility
311 * -> direct link packets are broadcasted on
312 * their interface only
313 * -> aggregate packet if the current packet is
314 * a "global" packet as well as the base
315 * packet
316 */
317
318 primary_if = primary_if_get_selected(bat_priv);
319 if (!primary_if)
320 goto out;
321
322 /* packets without direct link flag and high TTL
323 * are flooded through the net */
324 if ((!directlink) &&
325 (!(batman_ogm_packet->flags & DIRECTLINK)) &&
Sven Eckelmann76543d12011-11-20 15:47:38 +0100326 (batman_ogm_packet->header.ttl != 1) &&
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200327
328 /* own packets originating non-primary
329 * interfaces leave only that interface */
330 ((!forw_packet->own) ||
331 (forw_packet->if_incoming == primary_if))) {
332 res = true;
333 goto out;
334 }
335
336 /* if the incoming packet is sent via this one
337 * interface only - we still can aggregate */
338 if ((directlink) &&
Sven Eckelmann76543d12011-11-20 15:47:38 +0100339 (new_batman_ogm_packet->header.ttl == 1) &&
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200340 (forw_packet->if_incoming == if_incoming) &&
341
342 /* packets from direct neighbors or
343 * own secondary interface packets
344 * (= secondary interface packets in general) */
345 (batman_ogm_packet->flags & DIRECTLINK ||
346 (forw_packet->own &&
347 forw_packet->if_incoming != primary_if))) {
348 res = true;
349 goto out;
350 }
351 }
352
353out:
354 if (primary_if)
355 hardif_free_ref(primary_if);
356 return res;
357}
358
359/* create a new aggregated packet and add this packet to it */
Marek Lindner01c42242011-11-28 21:31:55 +0800360static void bat_iv_ogm_aggregate_new(const unsigned char *packet_buff,
361 int packet_len, unsigned long send_time,
362 bool direct_link,
363 struct hard_iface *if_incoming,
364 int own_packet)
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200365{
366 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
367 struct forw_packet *forw_packet_aggr;
368 unsigned char *skb_buff;
369
370 if (!atomic_inc_not_zero(&if_incoming->refcount))
371 return;
372
373 /* own packet should always be scheduled */
374 if (!own_packet) {
375 if (!atomic_dec_not_zero(&bat_priv->batman_queue_left)) {
376 bat_dbg(DBG_BATMAN, bat_priv,
377 "batman packet queue full\n");
378 goto out;
379 }
380 }
381
382 forw_packet_aggr = kmalloc(sizeof(*forw_packet_aggr), GFP_ATOMIC);
383 if (!forw_packet_aggr) {
384 if (!own_packet)
385 atomic_inc(&bat_priv->batman_queue_left);
386 goto out;
387 }
388
389 if ((atomic_read(&bat_priv->aggregated_ogms)) &&
390 (packet_len < MAX_AGGREGATION_BYTES))
391 forw_packet_aggr->skb = dev_alloc_skb(MAX_AGGREGATION_BYTES +
Antonio Quartulli0d125072012-02-18 11:27:34 +0100392 ETH_HLEN);
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200393 else
Antonio Quartulli0d125072012-02-18 11:27:34 +0100394 forw_packet_aggr->skb = dev_alloc_skb(packet_len + ETH_HLEN);
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200395
396 if (!forw_packet_aggr->skb) {
397 if (!own_packet)
398 atomic_inc(&bat_priv->batman_queue_left);
399 kfree(forw_packet_aggr);
400 goto out;
401 }
Antonio Quartulli0d125072012-02-18 11:27:34 +0100402 skb_reserve(forw_packet_aggr->skb, ETH_HLEN);
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200403
404 INIT_HLIST_NODE(&forw_packet_aggr->list);
405
406 skb_buff = skb_put(forw_packet_aggr->skb, packet_len);
407 forw_packet_aggr->packet_len = packet_len;
408 memcpy(skb_buff, packet_buff, packet_len);
409
410 forw_packet_aggr->own = own_packet;
411 forw_packet_aggr->if_incoming = if_incoming;
412 forw_packet_aggr->num_packets = 0;
413 forw_packet_aggr->direct_link_flags = NO_FLAGS;
414 forw_packet_aggr->send_time = send_time;
415
416 /* save packet direct link flag status */
417 if (direct_link)
418 forw_packet_aggr->direct_link_flags |= 1;
419
420 /* add new packet to packet list */
421 spin_lock_bh(&bat_priv->forw_bat_list_lock);
422 hlist_add_head(&forw_packet_aggr->list, &bat_priv->forw_bat_list);
423 spin_unlock_bh(&bat_priv->forw_bat_list_lock);
424
425 /* start timer for this packet */
426 INIT_DELAYED_WORK(&forw_packet_aggr->delayed_work,
Sven Eckelmann9455e342012-05-12 02:09:37 +0200427 batadv_send_outstanding_bat_ogm_packet);
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200428 queue_delayed_work(bat_event_workqueue,
429 &forw_packet_aggr->delayed_work,
430 send_time - jiffies);
431
432 return;
433out:
434 hardif_free_ref(if_incoming);
435}
436
437/* aggregate a new packet into the existing ogm packet */
Marek Lindner01c42242011-11-28 21:31:55 +0800438static void bat_iv_ogm_aggregate(struct forw_packet *forw_packet_aggr,
439 const unsigned char *packet_buff,
440 int packet_len, bool direct_link)
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200441{
442 unsigned char *skb_buff;
443
444 skb_buff = skb_put(forw_packet_aggr->skb, packet_len);
445 memcpy(skb_buff, packet_buff, packet_len);
446 forw_packet_aggr->packet_len += packet_len;
447 forw_packet_aggr->num_packets++;
448
449 /* save packet direct link flag status */
450 if (direct_link)
451 forw_packet_aggr->direct_link_flags |=
452 (1 << forw_packet_aggr->num_packets);
453}
454
Marek Lindner01c42242011-11-28 21:31:55 +0800455static void bat_iv_ogm_queue_add(struct bat_priv *bat_priv,
456 unsigned char *packet_buff,
457 int packet_len, struct hard_iface *if_incoming,
458 int own_packet, unsigned long send_time)
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200459{
460 /**
461 * _aggr -> pointer to the packet we want to aggregate with
462 * _pos -> pointer to the position in the queue
463 */
464 struct forw_packet *forw_packet_aggr = NULL, *forw_packet_pos = NULL;
465 struct hlist_node *tmp_node;
466 struct batman_ogm_packet *batman_ogm_packet;
467 bool direct_link;
468
469 batman_ogm_packet = (struct batman_ogm_packet *)packet_buff;
470 direct_link = batman_ogm_packet->flags & DIRECTLINK ? 1 : 0;
471
472 /* find position for the packet in the forward queue */
473 spin_lock_bh(&bat_priv->forw_bat_list_lock);
474 /* own packets are not to be aggregated */
475 if ((atomic_read(&bat_priv->aggregated_ogms)) && (!own_packet)) {
476 hlist_for_each_entry(forw_packet_pos, tmp_node,
477 &bat_priv->forw_bat_list, list) {
Marek Lindner01c42242011-11-28 21:31:55 +0800478 if (bat_iv_ogm_can_aggregate(batman_ogm_packet,
479 bat_priv, packet_len,
480 send_time, direct_link,
481 if_incoming,
482 forw_packet_pos)) {
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200483 forw_packet_aggr = forw_packet_pos;
484 break;
485 }
486 }
487 }
488
489 /* nothing to aggregate with - either aggregation disabled or no
490 * suitable aggregation packet found */
491 if (!forw_packet_aggr) {
492 /* the following section can run without the lock */
493 spin_unlock_bh(&bat_priv->forw_bat_list_lock);
494
495 /**
496 * if we could not aggregate this packet with one of the others
497 * we hold it back for a while, so that it might be aggregated
498 * later on
499 */
500 if ((!own_packet) &&
501 (atomic_read(&bat_priv->aggregated_ogms)))
502 send_time += msecs_to_jiffies(MAX_AGGREGATION_MS);
503
Marek Lindner01c42242011-11-28 21:31:55 +0800504 bat_iv_ogm_aggregate_new(packet_buff, packet_len,
505 send_time, direct_link,
506 if_incoming, own_packet);
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200507 } else {
Marek Lindner01c42242011-11-28 21:31:55 +0800508 bat_iv_ogm_aggregate(forw_packet_aggr, packet_buff,
509 packet_len, direct_link);
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200510 spin_unlock_bh(&bat_priv->forw_bat_list_lock);
511 }
512}
513
Marek Lindner01c42242011-11-28 21:31:55 +0800514static void bat_iv_ogm_forward(struct orig_node *orig_node,
515 const struct ethhdr *ethhdr,
516 struct batman_ogm_packet *batman_ogm_packet,
Marek Lindner75cd33f2012-03-01 15:35:16 +0800517 bool is_single_hop_neigh,
Marek Lindner13b25412012-03-11 06:17:53 +0800518 bool is_from_best_next_hop,
Marek Lindner75cd33f2012-03-01 15:35:16 +0800519 struct hard_iface *if_incoming)
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200520{
521 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200522 uint8_t tt_num_changes;
523
Sven Eckelmann76543d12011-11-20 15:47:38 +0100524 if (batman_ogm_packet->header.ttl <= 1) {
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200525 bat_dbg(DBG_BATMAN, bat_priv, "ttl exceeded\n");
526 return;
527 }
528
Marek Lindner13b25412012-03-11 06:17:53 +0800529 if (!is_from_best_next_hop) {
530 /* Mark the forwarded packet when it is not coming from our
531 * best next hop. We still need to forward the packet for our
532 * neighbor link quality detection to work in case the packet
533 * originated from a single hop neighbor. Otherwise we can
534 * simply drop the ogm.
535 */
536 if (is_single_hop_neigh)
537 batman_ogm_packet->flags |= NOT_BEST_NEXT_HOP;
538 else
539 return;
540 }
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200541
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200542 tt_num_changes = batman_ogm_packet->tt_num_changes;
543
Sven Eckelmann76543d12011-11-20 15:47:38 +0100544 batman_ogm_packet->header.ttl--;
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200545 memcpy(batman_ogm_packet->prev_sender, ethhdr->h_source, ETH_ALEN);
546
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200547 /* apply hop penalty */
548 batman_ogm_packet->tq = hop_penalty(batman_ogm_packet->tq, bat_priv);
549
550 bat_dbg(DBG_BATMAN, bat_priv,
Marek Lindner13b25412012-03-11 06:17:53 +0800551 "Forwarding packet: tq: %i, ttl: %i\n",
552 batman_ogm_packet->tq, batman_ogm_packet->header.ttl);
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200553
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200554 /* switch of primaries first hop flag when forwarding */
555 batman_ogm_packet->flags &= ~PRIMARIES_FIRST_HOP;
Marek Lindner75cd33f2012-03-01 15:35:16 +0800556 if (is_single_hop_neigh)
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200557 batman_ogm_packet->flags |= DIRECTLINK;
558 else
559 batman_ogm_packet->flags &= ~DIRECTLINK;
560
Marek Lindner01c42242011-11-28 21:31:55 +0800561 bat_iv_ogm_queue_add(bat_priv, (unsigned char *)batman_ogm_packet,
Sven Eckelmann08c36d32012-05-12 02:09:39 +0200562 BATMAN_OGM_HLEN + batadv_tt_len(tt_num_changes),
Marek Lindner01c42242011-11-28 21:31:55 +0800563 if_incoming, 0, bat_iv_ogm_fwd_send_time());
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200564}
565
Marek Lindnerbe9aa4c2012-05-07 04:22:05 +0800566static void bat_iv_ogm_schedule(struct hard_iface *hard_iface)
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200567{
568 struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
569 struct batman_ogm_packet *batman_ogm_packet;
570 struct hard_iface *primary_if;
Marek Lindnerbe9aa4c2012-05-07 04:22:05 +0800571 int vis_server, tt_num_changes = 0;
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200572
573 vis_server = atomic_read(&bat_priv->vis_mode);
574 primary_if = primary_if_get_selected(bat_priv);
575
Marek Lindnerbe9aa4c2012-05-07 04:22:05 +0800576 if (hard_iface == primary_if)
577 tt_num_changes = batadv_tt_append_diff(bat_priv,
578 &hard_iface->packet_buff,
579 &hard_iface->packet_len,
580 BATMAN_OGM_HLEN);
581
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200582 batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff;
583
584 /* change sequence number to network order */
585 batman_ogm_packet->seqno =
586 htonl((uint32_t)atomic_read(&hard_iface->seqno));
Marek Lindnerbe9aa4c2012-05-07 04:22:05 +0800587 atomic_inc(&hard_iface->seqno);
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200588
589 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
Antonio Quartulli66a1b2b2012-04-14 13:15:26 +0200590 batman_ogm_packet->tt_crc = htons(bat_priv->tt_crc);
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200591 if (tt_num_changes >= 0)
592 batman_ogm_packet->tt_num_changes = tt_num_changes;
593
594 if (vis_server == VIS_TYPE_SERVER_SYNC)
595 batman_ogm_packet->flags |= VIS_SERVER;
596 else
597 batman_ogm_packet->flags &= ~VIS_SERVER;
598
599 if ((hard_iface == primary_if) &&
600 (atomic_read(&bat_priv->gw_mode) == GW_MODE_SERVER))
601 batman_ogm_packet->gw_flags =
602 (uint8_t)atomic_read(&bat_priv->gw_bandwidth);
603 else
604 batman_ogm_packet->gw_flags = NO_FLAGS;
605
Sven Eckelmann30d3c512012-05-12 02:09:36 +0200606 batadv_slide_own_bcast_window(hard_iface);
Marek Lindner01c42242011-11-28 21:31:55 +0800607 bat_iv_ogm_queue_add(bat_priv, hard_iface->packet_buff,
608 hard_iface->packet_len, hard_iface, 1,
609 bat_iv_ogm_emit_send_time(bat_priv));
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200610
611 if (primary_if)
612 hardif_free_ref(primary_if);
613}
614
Marek Lindner01c42242011-11-28 21:31:55 +0800615static void bat_iv_ogm_orig_update(struct bat_priv *bat_priv,
616 struct orig_node *orig_node,
617 const struct ethhdr *ethhdr,
618 const struct batman_ogm_packet
Marek Lindnerfc957272011-07-30 12:04:12 +0200619 *batman_ogm_packet,
Marek Lindner01c42242011-11-28 21:31:55 +0800620 struct hard_iface *if_incoming,
621 const unsigned char *tt_buff,
622 int is_duplicate)
Marek Lindnerfc957272011-07-30 12:04:12 +0200623{
624 struct neigh_node *neigh_node = NULL, *tmp_neigh_node = NULL;
625 struct neigh_node *router = NULL;
626 struct orig_node *orig_node_tmp;
627 struct hlist_node *node;
628 uint8_t bcast_own_sum_orig, bcast_own_sum_neigh;
629
Sven Eckelmann86ceb362012-03-07 09:07:45 +0100630 bat_dbg(DBG_BATMAN, bat_priv,
631 "update_originator(): Searching and updating originator entry of received packet\n");
Marek Lindnerfc957272011-07-30 12:04:12 +0200632
633 rcu_read_lock();
634 hlist_for_each_entry_rcu(tmp_neigh_node, node,
635 &orig_node->neigh_list, list) {
636 if (compare_eth(tmp_neigh_node->addr, ethhdr->h_source) &&
637 (tmp_neigh_node->if_incoming == if_incoming) &&
638 atomic_inc_not_zero(&tmp_neigh_node->refcount)) {
639 if (neigh_node)
Sven Eckelmann7d211ef2012-05-12 02:09:34 +0200640 batadv_neigh_node_free_ref(neigh_node);
Marek Lindnerfc957272011-07-30 12:04:12 +0200641 neigh_node = tmp_neigh_node;
642 continue;
643 }
644
645 if (is_duplicate)
646 continue;
647
Marek Lindnere3b0d0d2012-03-17 15:28:32 +0800648 spin_lock_bh(&tmp_neigh_node->lq_update_lock);
Sven Eckelmann925a6672012-05-12 02:09:35 +0200649 batadv_ring_buffer_set(tmp_neigh_node->tq_recv,
650 &tmp_neigh_node->tq_index, 0);
Marek Lindnerfc957272011-07-30 12:04:12 +0200651 tmp_neigh_node->tq_avg =
Sven Eckelmann925a6672012-05-12 02:09:35 +0200652 batadv_ring_buffer_avg(tmp_neigh_node->tq_recv);
Marek Lindnere3b0d0d2012-03-17 15:28:32 +0800653 spin_unlock_bh(&tmp_neigh_node->lq_update_lock);
Marek Lindnerfc957272011-07-30 12:04:12 +0200654 }
655
656 if (!neigh_node) {
657 struct orig_node *orig_tmp;
658
Sven Eckelmann7d211ef2012-05-12 02:09:34 +0200659 orig_tmp = batadv_get_orig_node(bat_priv, ethhdr->h_source);
Marek Lindnerfc957272011-07-30 12:04:12 +0200660 if (!orig_tmp)
661 goto unlock;
662
Marek Lindner7ae8b282012-03-01 15:35:21 +0800663 neigh_node = bat_iv_ogm_neigh_new(if_incoming, ethhdr->h_source,
664 orig_node, orig_tmp,
665 batman_ogm_packet->seqno);
Marek Lindnerfc957272011-07-30 12:04:12 +0200666
Sven Eckelmann7d211ef2012-05-12 02:09:34 +0200667 batadv_orig_node_free_ref(orig_tmp);
Marek Lindnerfc957272011-07-30 12:04:12 +0200668 if (!neigh_node)
669 goto unlock;
670 } else
671 bat_dbg(DBG_BATMAN, bat_priv,
672 "Updating existing last-hop neighbor of originator\n");
673
674 rcu_read_unlock();
675
676 orig_node->flags = batman_ogm_packet->flags;
Marek Lindnerd7b2a972012-03-01 15:35:19 +0800677 neigh_node->last_seen = jiffies;
Marek Lindnerfc957272011-07-30 12:04:12 +0200678
Marek Lindnere3b0d0d2012-03-17 15:28:32 +0800679 spin_lock_bh(&neigh_node->lq_update_lock);
Sven Eckelmann925a6672012-05-12 02:09:35 +0200680 batadv_ring_buffer_set(neigh_node->tq_recv,
681 &neigh_node->tq_index,
682 batman_ogm_packet->tq);
683 neigh_node->tq_avg = batadv_ring_buffer_avg(neigh_node->tq_recv);
Marek Lindnere3b0d0d2012-03-17 15:28:32 +0800684 spin_unlock_bh(&neigh_node->lq_update_lock);
Marek Lindnerfc957272011-07-30 12:04:12 +0200685
686 if (!is_duplicate) {
Sven Eckelmann76543d12011-11-20 15:47:38 +0100687 orig_node->last_ttl = batman_ogm_packet->header.ttl;
688 neigh_node->last_ttl = batman_ogm_packet->header.ttl;
Marek Lindnerfc957272011-07-30 12:04:12 +0200689 }
690
Sven Eckelmann30d3c512012-05-12 02:09:36 +0200691 batadv_bonding_candidate_add(orig_node, neigh_node);
Marek Lindnerfc957272011-07-30 12:04:12 +0200692
693 /* if this neighbor already is our next hop there is nothing
694 * to change */
Sven Eckelmann7d211ef2012-05-12 02:09:34 +0200695 router = batadv_orig_node_get_router(orig_node);
Marek Lindnerfc957272011-07-30 12:04:12 +0200696 if (router == neigh_node)
697 goto update_tt;
698
699 /* if this neighbor does not offer a better TQ we won't consider it */
700 if (router && (router->tq_avg > neigh_node->tq_avg))
701 goto update_tt;
702
703 /* if the TQ is the same and the link not more symmetric we
704 * won't consider it either */
705 if (router && (neigh_node->tq_avg == router->tq_avg)) {
706 orig_node_tmp = router->orig_node;
707 spin_lock_bh(&orig_node_tmp->ogm_cnt_lock);
708 bcast_own_sum_orig =
709 orig_node_tmp->bcast_own_sum[if_incoming->if_num];
710 spin_unlock_bh(&orig_node_tmp->ogm_cnt_lock);
711
712 orig_node_tmp = neigh_node->orig_node;
713 spin_lock_bh(&orig_node_tmp->ogm_cnt_lock);
714 bcast_own_sum_neigh =
715 orig_node_tmp->bcast_own_sum[if_incoming->if_num];
716 spin_unlock_bh(&orig_node_tmp->ogm_cnt_lock);
717
718 if (bcast_own_sum_orig >= bcast_own_sum_neigh)
719 goto update_tt;
720 }
721
Sven Eckelmann30d3c512012-05-12 02:09:36 +0200722 batadv_update_route(bat_priv, orig_node, neigh_node);
Marek Lindnerfc957272011-07-30 12:04:12 +0200723
724update_tt:
725 /* I have to check for transtable changes only if the OGM has been
726 * sent through a primary interface */
727 if (((batman_ogm_packet->orig != ethhdr->h_source) &&
Sven Eckelmann76543d12011-11-20 15:47:38 +0100728 (batman_ogm_packet->header.ttl > 2)) ||
Marek Lindnerfc957272011-07-30 12:04:12 +0200729 (batman_ogm_packet->flags & PRIMARIES_FIRST_HOP))
Sven Eckelmann08c36d32012-05-12 02:09:39 +0200730 batadv_tt_update_orig(bat_priv, orig_node, tt_buff,
731 batman_ogm_packet->tt_num_changes,
732 batman_ogm_packet->ttvn,
733 ntohs(batman_ogm_packet->tt_crc));
Marek Lindnerfc957272011-07-30 12:04:12 +0200734
735 if (orig_node->gw_flags != batman_ogm_packet->gw_flags)
Sven Eckelmann7cf06bc2012-05-12 02:09:29 +0200736 batadv_gw_node_update(bat_priv, orig_node,
737 batman_ogm_packet->gw_flags);
Marek Lindnerfc957272011-07-30 12:04:12 +0200738
739 orig_node->gw_flags = batman_ogm_packet->gw_flags;
740
741 /* restart gateway selection if fast or late switching was enabled */
742 if ((orig_node->gw_flags) &&
743 (atomic_read(&bat_priv->gw_mode) == GW_MODE_CLIENT) &&
744 (atomic_read(&bat_priv->gw_sel_class) > 2))
Sven Eckelmann7cf06bc2012-05-12 02:09:29 +0200745 batadv_gw_check_election(bat_priv, orig_node);
Marek Lindnerfc957272011-07-30 12:04:12 +0200746
747 goto out;
748
749unlock:
750 rcu_read_unlock();
751out:
752 if (neigh_node)
Sven Eckelmann7d211ef2012-05-12 02:09:34 +0200753 batadv_neigh_node_free_ref(neigh_node);
Marek Lindnerfc957272011-07-30 12:04:12 +0200754 if (router)
Sven Eckelmann7d211ef2012-05-12 02:09:34 +0200755 batadv_neigh_node_free_ref(router);
Marek Lindnerfc957272011-07-30 12:04:12 +0200756}
757
Marek Lindner01c42242011-11-28 21:31:55 +0800758static int bat_iv_ogm_calc_tq(struct orig_node *orig_node,
759 struct orig_node *orig_neigh_node,
760 struct batman_ogm_packet *batman_ogm_packet,
761 struct hard_iface *if_incoming)
Marek Lindnerfc957272011-07-30 12:04:12 +0200762{
763 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
764 struct neigh_node *neigh_node = NULL, *tmp_neigh_node;
765 struct hlist_node *node;
766 uint8_t total_count;
767 uint8_t orig_eq_count, neigh_rq_count, tq_own;
768 int tq_asym_penalty, ret = 0;
769
770 /* find corresponding one hop neighbor */
771 rcu_read_lock();
772 hlist_for_each_entry_rcu(tmp_neigh_node, node,
773 &orig_neigh_node->neigh_list, list) {
774
775 if (!compare_eth(tmp_neigh_node->addr, orig_neigh_node->orig))
776 continue;
777
778 if (tmp_neigh_node->if_incoming != if_incoming)
779 continue;
780
781 if (!atomic_inc_not_zero(&tmp_neigh_node->refcount))
782 continue;
783
784 neigh_node = tmp_neigh_node;
785 break;
786 }
787 rcu_read_unlock();
788
789 if (!neigh_node)
Marek Lindner7ae8b282012-03-01 15:35:21 +0800790 neigh_node = bat_iv_ogm_neigh_new(if_incoming,
791 orig_neigh_node->orig,
792 orig_neigh_node,
793 orig_neigh_node,
794 batman_ogm_packet->seqno);
Marek Lindnerfc957272011-07-30 12:04:12 +0200795
796 if (!neigh_node)
797 goto out;
798
Marek Lindnerd7b2a972012-03-01 15:35:19 +0800799 /* if orig_node is direct neighbor update neigh_node last_seen */
Marek Lindnerfc957272011-07-30 12:04:12 +0200800 if (orig_node == orig_neigh_node)
Marek Lindnerd7b2a972012-03-01 15:35:19 +0800801 neigh_node->last_seen = jiffies;
Marek Lindnerfc957272011-07-30 12:04:12 +0200802
Marek Lindnerd7b2a972012-03-01 15:35:19 +0800803 orig_node->last_seen = jiffies;
Marek Lindnerfc957272011-07-30 12:04:12 +0200804
805 /* find packet count of corresponding one hop neighbor */
806 spin_lock_bh(&orig_node->ogm_cnt_lock);
807 orig_eq_count = orig_neigh_node->bcast_own_sum[if_incoming->if_num];
808 neigh_rq_count = neigh_node->real_packet_count;
809 spin_unlock_bh(&orig_node->ogm_cnt_lock);
810
811 /* pay attention to not get a value bigger than 100 % */
812 total_count = (orig_eq_count > neigh_rq_count ?
813 neigh_rq_count : orig_eq_count);
814
815 /* if we have too few packets (too less data) we set tq_own to zero */
816 /* if we receive too few packets it is not considered bidirectional */
817 if ((total_count < TQ_LOCAL_BIDRECT_SEND_MINIMUM) ||
818 (neigh_rq_count < TQ_LOCAL_BIDRECT_RECV_MINIMUM))
819 tq_own = 0;
820 else
821 /* neigh_node->real_packet_count is never zero as we
822 * only purge old information when getting new
823 * information */
824 tq_own = (TQ_MAX_VALUE * total_count) / neigh_rq_count;
825
Sven Eckelmann21a12362012-03-07 09:07:46 +0100826 /* 1 - ((1-x) ** 3), normalized to TQ_MAX_VALUE this does
Marek Lindnerfc957272011-07-30 12:04:12 +0200827 * affect the nearly-symmetric links only a little, but
828 * punishes asymmetric links more. This will give a value
829 * between 0 and TQ_MAX_VALUE
830 */
831 tq_asym_penalty = TQ_MAX_VALUE - (TQ_MAX_VALUE *
832 (TQ_LOCAL_WINDOW_SIZE - neigh_rq_count) *
833 (TQ_LOCAL_WINDOW_SIZE - neigh_rq_count) *
834 (TQ_LOCAL_WINDOW_SIZE - neigh_rq_count)) /
835 (TQ_LOCAL_WINDOW_SIZE *
836 TQ_LOCAL_WINDOW_SIZE *
837 TQ_LOCAL_WINDOW_SIZE);
838
839 batman_ogm_packet->tq = ((batman_ogm_packet->tq * tq_own
840 * tq_asym_penalty) /
841 (TQ_MAX_VALUE * TQ_MAX_VALUE));
842
843 bat_dbg(DBG_BATMAN, bat_priv,
Sven Eckelmann86ceb362012-03-07 09:07:45 +0100844 "bidirectional: orig = %-15pM neigh = %-15pM => own_bcast = %2i, real recv = %2i, local tq: %3i, asym_penalty: %3i, total tq: %3i\n",
Marek Lindnerfc957272011-07-30 12:04:12 +0200845 orig_node->orig, orig_neigh_node->orig, total_count,
846 neigh_rq_count, tq_own, tq_asym_penalty, batman_ogm_packet->tq);
847
848 /* if link has the minimum required transmission quality
849 * consider it bidirectional */
850 if (batman_ogm_packet->tq >= TQ_TOTAL_BIDRECT_LIMIT)
851 ret = 1;
852
853out:
854 if (neigh_node)
Sven Eckelmann7d211ef2012-05-12 02:09:34 +0200855 batadv_neigh_node_free_ref(neigh_node);
Marek Lindnerfc957272011-07-30 12:04:12 +0200856 return ret;
857}
858
859/* processes a batman packet for all interfaces, adjusts the sequence number and
860 * finds out whether it is a duplicate.
861 * returns:
862 * 1 the packet is a duplicate
863 * 0 the packet has not yet been received
864 * -1 the packet is old and has been received while the seqno window
865 * was protected. Caller should drop it.
866 */
Marek Lindner01c42242011-11-28 21:31:55 +0800867static int bat_iv_ogm_update_seqnos(const struct ethhdr *ethhdr,
868 const struct batman_ogm_packet
Marek Lindnerfc957272011-07-30 12:04:12 +0200869 *batman_ogm_packet,
Marek Lindner01c42242011-11-28 21:31:55 +0800870 const struct hard_iface *if_incoming)
Marek Lindnerfc957272011-07-30 12:04:12 +0200871{
872 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
873 struct orig_node *orig_node;
874 struct neigh_node *tmp_neigh_node;
875 struct hlist_node *node;
876 int is_duplicate = 0;
877 int32_t seq_diff;
878 int need_update = 0;
879 int set_mark, ret = -1;
Al Viroe0f52112012-04-22 07:46:29 +0100880 uint32_t seqno = ntohl(batman_ogm_packet->seqno);
Marek Lindnerfc957272011-07-30 12:04:12 +0200881
Sven Eckelmann7d211ef2012-05-12 02:09:34 +0200882 orig_node = batadv_get_orig_node(bat_priv, batman_ogm_packet->orig);
Marek Lindnerfc957272011-07-30 12:04:12 +0200883 if (!orig_node)
884 return 0;
885
886 spin_lock_bh(&orig_node->ogm_cnt_lock);
Al Viroe0f52112012-04-22 07:46:29 +0100887 seq_diff = seqno - orig_node->last_real_seqno;
Marek Lindnerfc957272011-07-30 12:04:12 +0200888
889 /* signalize caller that the packet is to be dropped. */
Antonio Quartulli1e5cc262012-02-26 15:39:42 +0100890 if (!hlist_empty(&orig_node->neigh_list) &&
Sven Eckelmann30d3c512012-05-12 02:09:36 +0200891 batadv_window_protected(bat_priv, seq_diff,
892 &orig_node->batman_seqno_reset))
Marek Lindnerfc957272011-07-30 12:04:12 +0200893 goto out;
894
895 rcu_read_lock();
896 hlist_for_each_entry_rcu(tmp_neigh_node, node,
897 &orig_node->neigh_list, list) {
898
Sven Eckelmann0079d2c2012-02-04 17:34:52 +0100899 is_duplicate |= bat_test_bit(tmp_neigh_node->real_bits,
900 orig_node->last_real_seqno,
Al Viroe0f52112012-04-22 07:46:29 +0100901 seqno);
Marek Lindnerfc957272011-07-30 12:04:12 +0200902
903 if (compare_eth(tmp_neigh_node->addr, ethhdr->h_source) &&
904 (tmp_neigh_node->if_incoming == if_incoming))
905 set_mark = 1;
906 else
907 set_mark = 0;
908
909 /* if the window moved, set the update flag. */
Sven Eckelmann0f5f93222012-05-12 02:09:25 +0200910 need_update |= batadv_bit_get_packet(bat_priv,
911 tmp_neigh_node->real_bits,
912 seq_diff, set_mark);
Marek Lindnerfc957272011-07-30 12:04:12 +0200913
914 tmp_neigh_node->real_packet_count =
Sven Eckelmann0079d2c2012-02-04 17:34:52 +0100915 bitmap_weight(tmp_neigh_node->real_bits,
916 TQ_LOCAL_WINDOW_SIZE);
Marek Lindnerfc957272011-07-30 12:04:12 +0200917 }
918 rcu_read_unlock();
919
920 if (need_update) {
921 bat_dbg(DBG_BATMAN, bat_priv,
Antonio Quartullic97c72b2012-02-26 15:39:41 +0100922 "updating last_seqno: old %u, new %u\n",
Al Viroe0f52112012-04-22 07:46:29 +0100923 orig_node->last_real_seqno, seqno);
924 orig_node->last_real_seqno = seqno;
Marek Lindnerfc957272011-07-30 12:04:12 +0200925 }
926
927 ret = is_duplicate;
928
929out:
930 spin_unlock_bh(&orig_node->ogm_cnt_lock);
Sven Eckelmann7d211ef2012-05-12 02:09:34 +0200931 batadv_orig_node_free_ref(orig_node);
Marek Lindnerfc957272011-07-30 12:04:12 +0200932 return ret;
933}
934
Marek Lindner01c42242011-11-28 21:31:55 +0800935static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
936 struct batman_ogm_packet *batman_ogm_packet,
937 const unsigned char *tt_buff,
938 struct hard_iface *if_incoming)
Marek Lindnerfc957272011-07-30 12:04:12 +0200939{
940 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
941 struct hard_iface *hard_iface;
942 struct orig_node *orig_neigh_node, *orig_node;
943 struct neigh_node *router = NULL, *router_router = NULL;
944 struct neigh_node *orig_neigh_router = NULL;
945 int has_directlink_flag;
946 int is_my_addr = 0, is_my_orig = 0, is_my_oldorig = 0;
Marek Lindner75cd33f2012-03-01 15:35:16 +0800947 int is_broadcast = 0, is_bidirectional;
948 bool is_single_hop_neigh = false;
Marek Lindner13b25412012-03-11 06:17:53 +0800949 bool is_from_best_next_hop = false;
Marek Lindnerfc957272011-07-30 12:04:12 +0200950 int is_duplicate;
951 uint32_t if_incoming_seqno;
952
953 /* Silently drop when the batman packet is actually not a
954 * correct packet.
955 *
956 * This might happen if a packet is padded (e.g. Ethernet has a
957 * minimum frame length of 64 byte) and the aggregation interprets
958 * it as an additional length.
959 *
960 * TODO: A more sane solution would be to have a bit in the
961 * batman_ogm_packet to detect whether the packet is the last
962 * packet in an aggregation. Here we expect that the padding
963 * is always zero (or not 0x01)
964 */
Marek Lindner1eeb4792012-02-07 17:20:51 +0800965 if (batman_ogm_packet->header.packet_type != BAT_IV_OGM)
Marek Lindnerfc957272011-07-30 12:04:12 +0200966 return;
967
968 /* could be changed by schedule_own_packet() */
969 if_incoming_seqno = atomic_read(&if_incoming->seqno);
970
971 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
972
Marek Lindner75cd33f2012-03-01 15:35:16 +0800973 if (compare_eth(ethhdr->h_source, batman_ogm_packet->orig))
974 is_single_hop_neigh = true;
Marek Lindnerfc957272011-07-30 12:04:12 +0200975
976 bat_dbg(DBG_BATMAN, bat_priv,
Antonio Quartullic97c72b2012-02-26 15:39:41 +0100977 "Received BATMAN packet via NB: %pM, IF: %s [%pM] (from OG: %pM, via prev OG: %pM, seqno %u, ttvn %u, crc %u, changes %u, td %d, TTL %d, V %d, IDF %d)\n",
Marek Lindnerfc957272011-07-30 12:04:12 +0200978 ethhdr->h_source, if_incoming->net_dev->name,
979 if_incoming->net_dev->dev_addr, batman_ogm_packet->orig,
Al Viroe0f52112012-04-22 07:46:29 +0100980 batman_ogm_packet->prev_sender, ntohl(batman_ogm_packet->seqno),
Al Viro16a70342012-04-22 07:45:29 +0100981 batman_ogm_packet->ttvn, ntohs(batman_ogm_packet->tt_crc),
Marek Lindnerfc957272011-07-30 12:04:12 +0200982 batman_ogm_packet->tt_num_changes, batman_ogm_packet->tq,
Sven Eckelmann76543d12011-11-20 15:47:38 +0100983 batman_ogm_packet->header.ttl,
984 batman_ogm_packet->header.version, has_directlink_flag);
Marek Lindnerfc957272011-07-30 12:04:12 +0200985
986 rcu_read_lock();
987 list_for_each_entry_rcu(hard_iface, &hardif_list, list) {
988 if (hard_iface->if_status != IF_ACTIVE)
989 continue;
990
991 if (hard_iface->soft_iface != if_incoming->soft_iface)
992 continue;
993
994 if (compare_eth(ethhdr->h_source,
995 hard_iface->net_dev->dev_addr))
996 is_my_addr = 1;
997
998 if (compare_eth(batman_ogm_packet->orig,
999 hard_iface->net_dev->dev_addr))
1000 is_my_orig = 1;
1001
1002 if (compare_eth(batman_ogm_packet->prev_sender,
1003 hard_iface->net_dev->dev_addr))
1004 is_my_oldorig = 1;
1005
1006 if (is_broadcast_ether_addr(ethhdr->h_source))
1007 is_broadcast = 1;
1008 }
1009 rcu_read_unlock();
1010
Sven Eckelmann76543d12011-11-20 15:47:38 +01001011 if (batman_ogm_packet->header.version != COMPAT_VERSION) {
Marek Lindnerfc957272011-07-30 12:04:12 +02001012 bat_dbg(DBG_BATMAN, bat_priv,
1013 "Drop packet: incompatible batman version (%i)\n",
Sven Eckelmann76543d12011-11-20 15:47:38 +01001014 batman_ogm_packet->header.version);
Marek Lindnerfc957272011-07-30 12:04:12 +02001015 return;
1016 }
1017
1018 if (is_my_addr) {
1019 bat_dbg(DBG_BATMAN, bat_priv,
Sven Eckelmann86ceb362012-03-07 09:07:45 +01001020 "Drop packet: received my own broadcast (sender: %pM)\n",
Marek Lindnerfc957272011-07-30 12:04:12 +02001021 ethhdr->h_source);
1022 return;
1023 }
1024
1025 if (is_broadcast) {
Sven Eckelmann86ceb362012-03-07 09:07:45 +01001026 bat_dbg(DBG_BATMAN, bat_priv,
1027 "Drop packet: ignoring all packets with broadcast source addr (sender: %pM)\n",
1028 ethhdr->h_source);
Marek Lindnerfc957272011-07-30 12:04:12 +02001029 return;
1030 }
1031
1032 if (is_my_orig) {
1033 unsigned long *word;
1034 int offset;
1035
Sven Eckelmann7d211ef2012-05-12 02:09:34 +02001036 orig_neigh_node = batadv_get_orig_node(bat_priv,
1037 ethhdr->h_source);
Marek Lindnerfc957272011-07-30 12:04:12 +02001038 if (!orig_neigh_node)
1039 return;
1040
1041 /* neighbor has to indicate direct link and it has to
1042 * come via the corresponding interface */
1043 /* save packet seqno for bidirectional check */
1044 if (has_directlink_flag &&
1045 compare_eth(if_incoming->net_dev->dev_addr,
1046 batman_ogm_packet->orig)) {
1047 offset = if_incoming->if_num * NUM_WORDS;
1048
1049 spin_lock_bh(&orig_neigh_node->ogm_cnt_lock);
1050 word = &(orig_neigh_node->bcast_own[offset]);
Sven Eckelmann0079d2c2012-02-04 17:34:52 +01001051 bat_set_bit(word,
1052 if_incoming_seqno -
Al Viroe0f52112012-04-22 07:46:29 +01001053 ntohl(batman_ogm_packet->seqno) - 2);
Marek Lindnerfc957272011-07-30 12:04:12 +02001054 orig_neigh_node->bcast_own_sum[if_incoming->if_num] =
Sven Eckelmann0079d2c2012-02-04 17:34:52 +01001055 bitmap_weight(word, TQ_LOCAL_WINDOW_SIZE);
Marek Lindnerfc957272011-07-30 12:04:12 +02001056 spin_unlock_bh(&orig_neigh_node->ogm_cnt_lock);
1057 }
1058
Sven Eckelmann86ceb362012-03-07 09:07:45 +01001059 bat_dbg(DBG_BATMAN, bat_priv,
1060 "Drop packet: originator packet from myself (via neighbor)\n");
Sven Eckelmann7d211ef2012-05-12 02:09:34 +02001061 batadv_orig_node_free_ref(orig_neigh_node);
Marek Lindnerfc957272011-07-30 12:04:12 +02001062 return;
1063 }
1064
1065 if (is_my_oldorig) {
1066 bat_dbg(DBG_BATMAN, bat_priv,
Sven Eckelmann86ceb362012-03-07 09:07:45 +01001067 "Drop packet: ignoring all rebroadcast echos (sender: %pM)\n",
1068 ethhdr->h_source);
Marek Lindnerfc957272011-07-30 12:04:12 +02001069 return;
1070 }
1071
Marek Lindner13b25412012-03-11 06:17:53 +08001072 if (batman_ogm_packet->flags & NOT_BEST_NEXT_HOP) {
1073 bat_dbg(DBG_BATMAN, bat_priv,
Marek Lindnerfefa5322012-03-17 15:28:34 +08001074 "Drop packet: ignoring all packets not forwarded from the best next hop (sender: %pM)\n",
1075 ethhdr->h_source);
Marek Lindner13b25412012-03-11 06:17:53 +08001076 return;
1077 }
1078
Sven Eckelmann7d211ef2012-05-12 02:09:34 +02001079 orig_node = batadv_get_orig_node(bat_priv, batman_ogm_packet->orig);
Marek Lindnerfc957272011-07-30 12:04:12 +02001080 if (!orig_node)
1081 return;
1082
Marek Lindner01c42242011-11-28 21:31:55 +08001083 is_duplicate = bat_iv_ogm_update_seqnos(ethhdr, batman_ogm_packet,
1084 if_incoming);
Marek Lindnerfc957272011-07-30 12:04:12 +02001085
1086 if (is_duplicate == -1) {
1087 bat_dbg(DBG_BATMAN, bat_priv,
Sven Eckelmann86ceb362012-03-07 09:07:45 +01001088 "Drop packet: packet within seqno protection time (sender: %pM)\n",
1089 ethhdr->h_source);
Marek Lindnerfc957272011-07-30 12:04:12 +02001090 goto out;
1091 }
1092
1093 if (batman_ogm_packet->tq == 0) {
1094 bat_dbg(DBG_BATMAN, bat_priv,
1095 "Drop packet: originator packet with tq equal 0\n");
1096 goto out;
1097 }
1098
Sven Eckelmann7d211ef2012-05-12 02:09:34 +02001099 router = batadv_orig_node_get_router(orig_node);
Marek Lindnerfc957272011-07-30 12:04:12 +02001100 if (router)
Sven Eckelmann7d211ef2012-05-12 02:09:34 +02001101 router_router = batadv_orig_node_get_router(router->orig_node);
Marek Lindnerfc957272011-07-30 12:04:12 +02001102
Marek Lindner13b25412012-03-11 06:17:53 +08001103 if ((router && router->tq_avg != 0) &&
1104 (compare_eth(router->addr, ethhdr->h_source)))
1105 is_from_best_next_hop = true;
1106
Marek Lindnerfc957272011-07-30 12:04:12 +02001107 /* avoid temporary routing loops */
1108 if (router && router_router &&
1109 (compare_eth(router->addr, batman_ogm_packet->prev_sender)) &&
1110 !(compare_eth(batman_ogm_packet->orig,
1111 batman_ogm_packet->prev_sender)) &&
1112 (compare_eth(router->addr, router_router->addr))) {
1113 bat_dbg(DBG_BATMAN, bat_priv,
Sven Eckelmann86ceb362012-03-07 09:07:45 +01001114 "Drop packet: ignoring all rebroadcast packets that may make me loop (sender: %pM)\n",
1115 ethhdr->h_source);
Marek Lindnerfc957272011-07-30 12:04:12 +02001116 goto out;
1117 }
1118
1119 /* if sender is a direct neighbor the sender mac equals
1120 * originator mac */
1121 orig_neigh_node = (is_single_hop_neigh ?
1122 orig_node :
Sven Eckelmann7d211ef2012-05-12 02:09:34 +02001123 batadv_get_orig_node(bat_priv, ethhdr->h_source));
Marek Lindnerfc957272011-07-30 12:04:12 +02001124 if (!orig_neigh_node)
1125 goto out;
1126
Sven Eckelmann7d211ef2012-05-12 02:09:34 +02001127 orig_neigh_router = batadv_orig_node_get_router(orig_neigh_node);
Marek Lindnerfc957272011-07-30 12:04:12 +02001128
1129 /* drop packet if sender is not a direct neighbor and if we
1130 * don't route towards it */
1131 if (!is_single_hop_neigh && (!orig_neigh_router)) {
1132 bat_dbg(DBG_BATMAN, bat_priv,
1133 "Drop packet: OGM via unknown neighbor!\n");
1134 goto out_neigh;
1135 }
1136
Marek Lindner01c42242011-11-28 21:31:55 +08001137 is_bidirectional = bat_iv_ogm_calc_tq(orig_node, orig_neigh_node,
1138 batman_ogm_packet, if_incoming);
Marek Lindnerfc957272011-07-30 12:04:12 +02001139
Sven Eckelmann30d3c512012-05-12 02:09:36 +02001140 batadv_bonding_save_primary(orig_node, orig_neigh_node,
1141 batman_ogm_packet);
Marek Lindnerfc957272011-07-30 12:04:12 +02001142
1143 /* update ranking if it is not a duplicate or has the same
1144 * seqno and similar ttl as the non-duplicate */
1145 if (is_bidirectional &&
1146 (!is_duplicate ||
Al Viroe0f52112012-04-22 07:46:29 +01001147 ((orig_node->last_real_seqno == ntohl(batman_ogm_packet->seqno)) &&
Sven Eckelmann76543d12011-11-20 15:47:38 +01001148 (orig_node->last_ttl - 3 <= batman_ogm_packet->header.ttl))))
Marek Lindner01c42242011-11-28 21:31:55 +08001149 bat_iv_ogm_orig_update(bat_priv, orig_node, ethhdr,
1150 batman_ogm_packet, if_incoming,
1151 tt_buff, is_duplicate);
Marek Lindnerfc957272011-07-30 12:04:12 +02001152
1153 /* is single hop (direct) neighbor */
1154 if (is_single_hop_neigh) {
1155
1156 /* mark direct link on incoming interface */
Marek Lindner01c42242011-11-28 21:31:55 +08001157 bat_iv_ogm_forward(orig_node, ethhdr, batman_ogm_packet,
Marek Lindner13b25412012-03-11 06:17:53 +08001158 is_single_hop_neigh, is_from_best_next_hop,
1159 if_incoming);
Marek Lindnerfc957272011-07-30 12:04:12 +02001160
Sven Eckelmann86ceb362012-03-07 09:07:45 +01001161 bat_dbg(DBG_BATMAN, bat_priv,
1162 "Forwarding packet: rebroadcast neighbor packet with direct link flag\n");
Marek Lindnerfc957272011-07-30 12:04:12 +02001163 goto out_neigh;
1164 }
1165
1166 /* multihop originator */
1167 if (!is_bidirectional) {
1168 bat_dbg(DBG_BATMAN, bat_priv,
1169 "Drop packet: not received via bidirectional link\n");
1170 goto out_neigh;
1171 }
1172
1173 if (is_duplicate) {
1174 bat_dbg(DBG_BATMAN, bat_priv,
1175 "Drop packet: duplicate packet received\n");
1176 goto out_neigh;
1177 }
1178
1179 bat_dbg(DBG_BATMAN, bat_priv,
1180 "Forwarding packet: rebroadcast originator packet\n");
Marek Lindner01c42242011-11-28 21:31:55 +08001181 bat_iv_ogm_forward(orig_node, ethhdr, batman_ogm_packet,
Marek Lindner13b25412012-03-11 06:17:53 +08001182 is_single_hop_neigh, is_from_best_next_hop,
1183 if_incoming);
Marek Lindnerfc957272011-07-30 12:04:12 +02001184
1185out_neigh:
1186 if ((orig_neigh_node) && (!is_single_hop_neigh))
Sven Eckelmann7d211ef2012-05-12 02:09:34 +02001187 batadv_orig_node_free_ref(orig_neigh_node);
Marek Lindnerfc957272011-07-30 12:04:12 +02001188out:
1189 if (router)
Sven Eckelmann7d211ef2012-05-12 02:09:34 +02001190 batadv_neigh_node_free_ref(router);
Marek Lindnerfc957272011-07-30 12:04:12 +02001191 if (router_router)
Sven Eckelmann7d211ef2012-05-12 02:09:34 +02001192 batadv_neigh_node_free_ref(router_router);
Marek Lindnerfc957272011-07-30 12:04:12 +02001193 if (orig_neigh_router)
Sven Eckelmann7d211ef2012-05-12 02:09:34 +02001194 batadv_neigh_node_free_ref(orig_neigh_router);
Marek Lindnerfc957272011-07-30 12:04:12 +02001195
Sven Eckelmann7d211ef2012-05-12 02:09:34 +02001196 batadv_orig_node_free_ref(orig_node);
Marek Lindnerfc957272011-07-30 12:04:12 +02001197}
1198
Marek Lindnerc3e29312012-03-04 16:56:25 +08001199static int bat_iv_ogm_receive(struct sk_buff *skb,
1200 struct hard_iface *if_incoming)
Marek Lindnerfc957272011-07-30 12:04:12 +02001201{
Marek Lindneredbf12b2012-03-11 06:17:49 +08001202 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
Marek Lindnerfc957272011-07-30 12:04:12 +02001203 struct batman_ogm_packet *batman_ogm_packet;
Marek Lindner8780dad2011-12-05 04:01:51 +08001204 struct ethhdr *ethhdr;
1205 int buff_pos = 0, packet_len;
1206 unsigned char *tt_buff, *packet_buff;
Marek Lindnerc3e29312012-03-04 16:56:25 +08001207 bool ret;
1208
Sven Eckelmann30d3c512012-05-12 02:09:36 +02001209 ret = batadv_check_management_packet(skb, if_incoming, BATMAN_OGM_HLEN);
Marek Lindnerc3e29312012-03-04 16:56:25 +08001210 if (!ret)
1211 return NET_RX_DROP;
Marek Lindnerfc957272011-07-30 12:04:12 +02001212
Marek Lindneredbf12b2012-03-11 06:17:49 +08001213 /* did we receive a B.A.T.M.A.N. IV OGM packet on an interface
1214 * that does not have B.A.T.M.A.N. IV enabled ?
1215 */
1216 if (bat_priv->bat_algo_ops->bat_ogm_emit != bat_iv_ogm_emit)
1217 return NET_RX_DROP;
1218
Martin Hundebøllf8214862012-04-20 17:02:45 +02001219 batadv_inc_counter(bat_priv, BAT_CNT_MGMT_RX);
1220 batadv_add_counter(bat_priv, BAT_CNT_MGMT_RX_BYTES,
1221 skb->len + ETH_HLEN);
1222
Marek Lindner8780dad2011-12-05 04:01:51 +08001223 packet_len = skb_headlen(skb);
1224 ethhdr = (struct ethhdr *)skb_mac_header(skb);
1225 packet_buff = skb->data;
Marek Lindnerfc957272011-07-30 12:04:12 +02001226 batman_ogm_packet = (struct batman_ogm_packet *)packet_buff;
1227
1228 /* unpack the aggregated packets and process them one by one */
1229 do {
Marek Lindner76e3d7f2012-02-07 17:20:50 +08001230 tt_buff = packet_buff + buff_pos + BATMAN_OGM_HLEN;
Marek Lindnerfc957272011-07-30 12:04:12 +02001231
Marek Lindner01c42242011-11-28 21:31:55 +08001232 bat_iv_ogm_process(ethhdr, batman_ogm_packet,
1233 tt_buff, if_incoming);
Marek Lindnerfc957272011-07-30 12:04:12 +02001234
Sven Eckelmann08c36d32012-05-12 02:09:39 +02001235 buff_pos += BATMAN_OGM_HLEN;
1236 buff_pos += batadv_tt_len(batman_ogm_packet->tt_num_changes);
Marek Lindnerfc957272011-07-30 12:04:12 +02001237
1238 batman_ogm_packet = (struct batman_ogm_packet *)
1239 (packet_buff + buff_pos);
Marek Lindner01c42242011-11-28 21:31:55 +08001240 } while (bat_iv_ogm_aggr_packet(buff_pos, packet_len,
1241 batman_ogm_packet->tt_num_changes));
Marek Lindnerc3e29312012-03-04 16:56:25 +08001242
1243 kfree_skb(skb);
1244 return NET_RX_SUCCESS;
Marek Lindnerfc957272011-07-30 12:04:12 +02001245}
Marek Lindner1c280472011-11-28 17:40:17 +08001246
1247static struct bat_algo_ops batman_iv __read_mostly = {
Marek Lindner519d3492012-04-18 17:15:57 +08001248 .name = "BATMAN_IV",
Marek Lindnerc2aca022012-02-07 17:20:45 +08001249 .bat_iface_enable = bat_iv_ogm_iface_enable,
Marek Lindner00a50072012-02-07 17:20:47 +08001250 .bat_iface_disable = bat_iv_ogm_iface_disable,
Marek Lindnerc3229392012-03-11 06:17:50 +08001251 .bat_iface_update_mac = bat_iv_ogm_iface_update_mac,
Marek Lindnercd8b78e2012-02-07 17:20:49 +08001252 .bat_primary_iface_set = bat_iv_ogm_primary_iface_set,
Marek Lindner01c42242011-11-28 21:31:55 +08001253 .bat_ogm_schedule = bat_iv_ogm_schedule,
1254 .bat_ogm_emit = bat_iv_ogm_emit,
Marek Lindner1c280472011-11-28 17:40:17 +08001255};
1256
Sven Eckelmann81c524f2012-05-12 02:09:22 +02001257int __init batadv_iv_init(void)
Marek Lindner1c280472011-11-28 17:40:17 +08001258{
Marek Lindnerc3e29312012-03-04 16:56:25 +08001259 int ret;
1260
1261 /* batman originator packet */
1262 ret = recv_handler_register(BAT_IV_OGM, bat_iv_ogm_receive);
1263 if (ret < 0)
1264 goto out;
1265
1266 ret = bat_algo_register(&batman_iv);
1267 if (ret < 0)
1268 goto handler_unregister;
1269
1270 goto out;
1271
1272handler_unregister:
1273 recv_handler_unregister(BAT_IV_OGM);
1274out:
1275 return ret;
Marek Lindner1c280472011-11-28 17:40:17 +08001276}