blob: 468bd5e1f7f51e2b63e3dac97b27c8b625a5f94f [file] [log] [blame]
Marek Lindnerfc957272011-07-30 12:04:12 +02001/*
2 * Copyright (C) 2007-2011 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
19 *
20 */
21
22#include "main.h"
23#include "bat_ogm.h"
24#include "translation-table.h"
25#include "ring_buffer.h"
26#include "originator.h"
27#include "routing.h"
28#include "gateway_common.h"
29#include "gateway_client.h"
30#include "hard-interface.h"
31#include "send.h"
32
Marek Lindnerd0b9fd82011-07-30 12:33:33 +020033void bat_ogm_init(struct hard_iface *hard_iface)
34{
35 struct batman_ogm_packet *batman_ogm_packet;
36
37 hard_iface->packet_len = BATMAN_OGM_LEN;
38 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
39
40 batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff;
41 batman_ogm_packet->packet_type = BAT_OGM;
42 batman_ogm_packet->version = COMPAT_VERSION;
43 batman_ogm_packet->flags = NO_FLAGS;
44 batman_ogm_packet->ttl = 2;
45 batman_ogm_packet->tq = TQ_MAX_VALUE;
46 batman_ogm_packet->tt_num_changes = 0;
47 batman_ogm_packet->ttvn = 0;
48}
49
50void bat_ogm_init_primary(struct hard_iface *hard_iface)
51{
52 struct batman_ogm_packet *batman_ogm_packet;
53
54 batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff;
55 batman_ogm_packet->flags = PRIMARIES_FIRST_HOP;
56 batman_ogm_packet->ttl = TTL;
57}
58
59void bat_ogm_update_mac(struct hard_iface *hard_iface)
60{
61 struct batman_ogm_packet *batman_ogm_packet;
62
63 batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff;
64 memcpy(batman_ogm_packet->orig,
65 hard_iface->net_dev->dev_addr, ETH_ALEN);
66 memcpy(batman_ogm_packet->prev_sender,
67 hard_iface->net_dev->dev_addr, ETH_ALEN);
68}
69
Marek Lindnerfc957272011-07-30 12:04:12 +020070/* is there another aggregated packet here? */
71static int bat_ogm_aggr_packet(int buff_pos, int packet_len,
72 int tt_num_changes)
73{
74 int next_buff_pos = buff_pos + BATMAN_OGM_LEN + tt_len(tt_num_changes);
75
76 return (next_buff_pos <= packet_len) &&
77 (next_buff_pos <= MAX_AGGREGATION_BYTES);
78}
79
80static void bat_ogm_orig_update(struct bat_priv *bat_priv,
81 struct orig_node *orig_node,
82 const struct ethhdr *ethhdr,
83 const struct batman_ogm_packet
84 *batman_ogm_packet,
85 struct hard_iface *if_incoming,
86 const unsigned char *tt_buff, int is_duplicate)
87{
88 struct neigh_node *neigh_node = NULL, *tmp_neigh_node = NULL;
89 struct neigh_node *router = NULL;
90 struct orig_node *orig_node_tmp;
91 struct hlist_node *node;
92 uint8_t bcast_own_sum_orig, bcast_own_sum_neigh;
93
94 bat_dbg(DBG_BATMAN, bat_priv, "update_originator(): "
95 "Searching and updating originator entry of received packet\n");
96
97 rcu_read_lock();
98 hlist_for_each_entry_rcu(tmp_neigh_node, node,
99 &orig_node->neigh_list, list) {
100 if (compare_eth(tmp_neigh_node->addr, ethhdr->h_source) &&
101 (tmp_neigh_node->if_incoming == if_incoming) &&
102 atomic_inc_not_zero(&tmp_neigh_node->refcount)) {
103 if (neigh_node)
104 neigh_node_free_ref(neigh_node);
105 neigh_node = tmp_neigh_node;
106 continue;
107 }
108
109 if (is_duplicate)
110 continue;
111
112 spin_lock_bh(&tmp_neigh_node->tq_lock);
113 ring_buffer_set(tmp_neigh_node->tq_recv,
114 &tmp_neigh_node->tq_index, 0);
115 tmp_neigh_node->tq_avg =
116 ring_buffer_avg(tmp_neigh_node->tq_recv);
117 spin_unlock_bh(&tmp_neigh_node->tq_lock);
118 }
119
120 if (!neigh_node) {
121 struct orig_node *orig_tmp;
122
123 orig_tmp = get_orig_node(bat_priv, ethhdr->h_source);
124 if (!orig_tmp)
125 goto unlock;
126
127 neigh_node = create_neighbor(orig_node, orig_tmp,
128 ethhdr->h_source, if_incoming);
129
130 orig_node_free_ref(orig_tmp);
131 if (!neigh_node)
132 goto unlock;
133 } else
134 bat_dbg(DBG_BATMAN, bat_priv,
135 "Updating existing last-hop neighbor of originator\n");
136
137 rcu_read_unlock();
138
139 orig_node->flags = batman_ogm_packet->flags;
140 neigh_node->last_valid = jiffies;
141
142 spin_lock_bh(&neigh_node->tq_lock);
143 ring_buffer_set(neigh_node->tq_recv,
144 &neigh_node->tq_index,
145 batman_ogm_packet->tq);
146 neigh_node->tq_avg = ring_buffer_avg(neigh_node->tq_recv);
147 spin_unlock_bh(&neigh_node->tq_lock);
148
149 if (!is_duplicate) {
150 orig_node->last_ttl = batman_ogm_packet->ttl;
151 neigh_node->last_ttl = batman_ogm_packet->ttl;
152 }
153
154 bonding_candidate_add(orig_node, neigh_node);
155
156 /* if this neighbor already is our next hop there is nothing
157 * to change */
158 router = orig_node_get_router(orig_node);
159 if (router == neigh_node)
160 goto update_tt;
161
162 /* if this neighbor does not offer a better TQ we won't consider it */
163 if (router && (router->tq_avg > neigh_node->tq_avg))
164 goto update_tt;
165
166 /* if the TQ is the same and the link not more symmetric we
167 * won't consider it either */
168 if (router && (neigh_node->tq_avg == router->tq_avg)) {
169 orig_node_tmp = router->orig_node;
170 spin_lock_bh(&orig_node_tmp->ogm_cnt_lock);
171 bcast_own_sum_orig =
172 orig_node_tmp->bcast_own_sum[if_incoming->if_num];
173 spin_unlock_bh(&orig_node_tmp->ogm_cnt_lock);
174
175 orig_node_tmp = neigh_node->orig_node;
176 spin_lock_bh(&orig_node_tmp->ogm_cnt_lock);
177 bcast_own_sum_neigh =
178 orig_node_tmp->bcast_own_sum[if_incoming->if_num];
179 spin_unlock_bh(&orig_node_tmp->ogm_cnt_lock);
180
181 if (bcast_own_sum_orig >= bcast_own_sum_neigh)
182 goto update_tt;
183 }
184
185 update_route(bat_priv, orig_node, neigh_node);
186
187update_tt:
188 /* I have to check for transtable changes only if the OGM has been
189 * sent through a primary interface */
190 if (((batman_ogm_packet->orig != ethhdr->h_source) &&
191 (batman_ogm_packet->ttl > 2)) ||
192 (batman_ogm_packet->flags & PRIMARIES_FIRST_HOP))
193 tt_update_orig(bat_priv, orig_node, tt_buff,
194 batman_ogm_packet->tt_num_changes,
195 batman_ogm_packet->ttvn,
196 batman_ogm_packet->tt_crc);
197
198 if (orig_node->gw_flags != batman_ogm_packet->gw_flags)
199 gw_node_update(bat_priv, orig_node,
200 batman_ogm_packet->gw_flags);
201
202 orig_node->gw_flags = batman_ogm_packet->gw_flags;
203
204 /* restart gateway selection if fast or late switching was enabled */
205 if ((orig_node->gw_flags) &&
206 (atomic_read(&bat_priv->gw_mode) == GW_MODE_CLIENT) &&
207 (atomic_read(&bat_priv->gw_sel_class) > 2))
208 gw_check_election(bat_priv, orig_node);
209
210 goto out;
211
212unlock:
213 rcu_read_unlock();
214out:
215 if (neigh_node)
216 neigh_node_free_ref(neigh_node);
217 if (router)
218 neigh_node_free_ref(router);
219}
220
221static int bat_ogm_calc_tq(struct orig_node *orig_node,
222 struct orig_node *orig_neigh_node,
223 struct batman_ogm_packet *batman_ogm_packet,
224 struct hard_iface *if_incoming)
225{
226 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
227 struct neigh_node *neigh_node = NULL, *tmp_neigh_node;
228 struct hlist_node *node;
229 uint8_t total_count;
230 uint8_t orig_eq_count, neigh_rq_count, tq_own;
231 int tq_asym_penalty, ret = 0;
232
233 /* find corresponding one hop neighbor */
234 rcu_read_lock();
235 hlist_for_each_entry_rcu(tmp_neigh_node, node,
236 &orig_neigh_node->neigh_list, list) {
237
238 if (!compare_eth(tmp_neigh_node->addr, orig_neigh_node->orig))
239 continue;
240
241 if (tmp_neigh_node->if_incoming != if_incoming)
242 continue;
243
244 if (!atomic_inc_not_zero(&tmp_neigh_node->refcount))
245 continue;
246
247 neigh_node = tmp_neigh_node;
248 break;
249 }
250 rcu_read_unlock();
251
252 if (!neigh_node)
253 neigh_node = create_neighbor(orig_neigh_node,
254 orig_neigh_node,
255 orig_neigh_node->orig,
256 if_incoming);
257
258 if (!neigh_node)
259 goto out;
260
261 /* if orig_node is direct neighbor update neigh_node last_valid */
262 if (orig_node == orig_neigh_node)
263 neigh_node->last_valid = jiffies;
264
265 orig_node->last_valid = jiffies;
266
267 /* find packet count of corresponding one hop neighbor */
268 spin_lock_bh(&orig_node->ogm_cnt_lock);
269 orig_eq_count = orig_neigh_node->bcast_own_sum[if_incoming->if_num];
270 neigh_rq_count = neigh_node->real_packet_count;
271 spin_unlock_bh(&orig_node->ogm_cnt_lock);
272
273 /* pay attention to not get a value bigger than 100 % */
274 total_count = (orig_eq_count > neigh_rq_count ?
275 neigh_rq_count : orig_eq_count);
276
277 /* if we have too few packets (too less data) we set tq_own to zero */
278 /* if we receive too few packets it is not considered bidirectional */
279 if ((total_count < TQ_LOCAL_BIDRECT_SEND_MINIMUM) ||
280 (neigh_rq_count < TQ_LOCAL_BIDRECT_RECV_MINIMUM))
281 tq_own = 0;
282 else
283 /* neigh_node->real_packet_count is never zero as we
284 * only purge old information when getting new
285 * information */
286 tq_own = (TQ_MAX_VALUE * total_count) / neigh_rq_count;
287
288 /*
289 * 1 - ((1-x) ** 3), normalized to TQ_MAX_VALUE this does
290 * affect the nearly-symmetric links only a little, but
291 * punishes asymmetric links more. This will give a value
292 * between 0 and TQ_MAX_VALUE
293 */
294 tq_asym_penalty = TQ_MAX_VALUE - (TQ_MAX_VALUE *
295 (TQ_LOCAL_WINDOW_SIZE - neigh_rq_count) *
296 (TQ_LOCAL_WINDOW_SIZE - neigh_rq_count) *
297 (TQ_LOCAL_WINDOW_SIZE - neigh_rq_count)) /
298 (TQ_LOCAL_WINDOW_SIZE *
299 TQ_LOCAL_WINDOW_SIZE *
300 TQ_LOCAL_WINDOW_SIZE);
301
302 batman_ogm_packet->tq = ((batman_ogm_packet->tq * tq_own
303 * tq_asym_penalty) /
304 (TQ_MAX_VALUE * TQ_MAX_VALUE));
305
306 bat_dbg(DBG_BATMAN, bat_priv,
307 "bidirectional: "
308 "orig = %-15pM neigh = %-15pM => own_bcast = %2i, "
309 "real recv = %2i, local tq: %3i, asym_penalty: %3i, "
310 "total tq: %3i\n",
311 orig_node->orig, orig_neigh_node->orig, total_count,
312 neigh_rq_count, tq_own, tq_asym_penalty, batman_ogm_packet->tq);
313
314 /* if link has the minimum required transmission quality
315 * consider it bidirectional */
316 if (batman_ogm_packet->tq >= TQ_TOTAL_BIDRECT_LIMIT)
317 ret = 1;
318
319out:
320 if (neigh_node)
321 neigh_node_free_ref(neigh_node);
322 return ret;
323}
324
325/* processes a batman packet for all interfaces, adjusts the sequence number and
326 * finds out whether it is a duplicate.
327 * returns:
328 * 1 the packet is a duplicate
329 * 0 the packet has not yet been received
330 * -1 the packet is old and has been received while the seqno window
331 * was protected. Caller should drop it.
332 */
333static int bat_ogm_update_seqnos(const struct ethhdr *ethhdr,
334 const struct batman_ogm_packet
335 *batman_ogm_packet,
336 const struct hard_iface *if_incoming)
337{
338 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
339 struct orig_node *orig_node;
340 struct neigh_node *tmp_neigh_node;
341 struct hlist_node *node;
342 int is_duplicate = 0;
343 int32_t seq_diff;
344 int need_update = 0;
345 int set_mark, ret = -1;
346
347 orig_node = get_orig_node(bat_priv, batman_ogm_packet->orig);
348 if (!orig_node)
349 return 0;
350
351 spin_lock_bh(&orig_node->ogm_cnt_lock);
352 seq_diff = batman_ogm_packet->seqno - orig_node->last_real_seqno;
353
354 /* signalize caller that the packet is to be dropped. */
355 if (window_protected(bat_priv, seq_diff,
356 &orig_node->batman_seqno_reset))
357 goto out;
358
359 rcu_read_lock();
360 hlist_for_each_entry_rcu(tmp_neigh_node, node,
361 &orig_node->neigh_list, list) {
362
363 is_duplicate |= get_bit_status(tmp_neigh_node->real_bits,
364 orig_node->last_real_seqno,
365 batman_ogm_packet->seqno);
366
367 if (compare_eth(tmp_neigh_node->addr, ethhdr->h_source) &&
368 (tmp_neigh_node->if_incoming == if_incoming))
369 set_mark = 1;
370 else
371 set_mark = 0;
372
373 /* if the window moved, set the update flag. */
374 need_update |= bit_get_packet(bat_priv,
375 tmp_neigh_node->real_bits,
376 seq_diff, set_mark);
377
378 tmp_neigh_node->real_packet_count =
379 bit_packet_count(tmp_neigh_node->real_bits);
380 }
381 rcu_read_unlock();
382
383 if (need_update) {
384 bat_dbg(DBG_BATMAN, bat_priv,
385 "updating last_seqno: old %d, new %d\n",
386 orig_node->last_real_seqno, batman_ogm_packet->seqno);
387 orig_node->last_real_seqno = batman_ogm_packet->seqno;
388 }
389
390 ret = is_duplicate;
391
392out:
393 spin_unlock_bh(&orig_node->ogm_cnt_lock);
394 orig_node_free_ref(orig_node);
395 return ret;
396}
397
398static void bat_ogm_process(const struct ethhdr *ethhdr,
399 struct batman_ogm_packet *batman_ogm_packet,
400 const unsigned char *tt_buff,
401 struct hard_iface *if_incoming)
402{
403 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
404 struct hard_iface *hard_iface;
405 struct orig_node *orig_neigh_node, *orig_node;
406 struct neigh_node *router = NULL, *router_router = NULL;
407 struct neigh_node *orig_neigh_router = NULL;
408 int has_directlink_flag;
409 int is_my_addr = 0, is_my_orig = 0, is_my_oldorig = 0;
410 int is_broadcast = 0, is_bidirectional, is_single_hop_neigh;
411 int is_duplicate;
412 uint32_t if_incoming_seqno;
413
414 /* Silently drop when the batman packet is actually not a
415 * correct packet.
416 *
417 * This might happen if a packet is padded (e.g. Ethernet has a
418 * minimum frame length of 64 byte) and the aggregation interprets
419 * it as an additional length.
420 *
421 * TODO: A more sane solution would be to have a bit in the
422 * batman_ogm_packet to detect whether the packet is the last
423 * packet in an aggregation. Here we expect that the padding
424 * is always zero (or not 0x01)
425 */
426 if (batman_ogm_packet->packet_type != BAT_OGM)
427 return;
428
429 /* could be changed by schedule_own_packet() */
430 if_incoming_seqno = atomic_read(&if_incoming->seqno);
431
432 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
433
434 is_single_hop_neigh = (compare_eth(ethhdr->h_source,
435 batman_ogm_packet->orig) ? 1 : 0);
436
437 bat_dbg(DBG_BATMAN, bat_priv,
438 "Received BATMAN packet via NB: %pM, IF: %s [%pM] "
439 "(from OG: %pM, via prev OG: %pM, seqno %d, ttvn %u, "
440 "crc %u, changes %u, td %d, TTL %d, V %d, IDF %d)\n",
441 ethhdr->h_source, if_incoming->net_dev->name,
442 if_incoming->net_dev->dev_addr, batman_ogm_packet->orig,
443 batman_ogm_packet->prev_sender, batman_ogm_packet->seqno,
444 batman_ogm_packet->ttvn, batman_ogm_packet->tt_crc,
445 batman_ogm_packet->tt_num_changes, batman_ogm_packet->tq,
446 batman_ogm_packet->ttl, batman_ogm_packet->version,
447 has_directlink_flag);
448
449 rcu_read_lock();
450 list_for_each_entry_rcu(hard_iface, &hardif_list, list) {
451 if (hard_iface->if_status != IF_ACTIVE)
452 continue;
453
454 if (hard_iface->soft_iface != if_incoming->soft_iface)
455 continue;
456
457 if (compare_eth(ethhdr->h_source,
458 hard_iface->net_dev->dev_addr))
459 is_my_addr = 1;
460
461 if (compare_eth(batman_ogm_packet->orig,
462 hard_iface->net_dev->dev_addr))
463 is_my_orig = 1;
464
465 if (compare_eth(batman_ogm_packet->prev_sender,
466 hard_iface->net_dev->dev_addr))
467 is_my_oldorig = 1;
468
469 if (is_broadcast_ether_addr(ethhdr->h_source))
470 is_broadcast = 1;
471 }
472 rcu_read_unlock();
473
474 if (batman_ogm_packet->version != COMPAT_VERSION) {
475 bat_dbg(DBG_BATMAN, bat_priv,
476 "Drop packet: incompatible batman version (%i)\n",
477 batman_ogm_packet->version);
478 return;
479 }
480
481 if (is_my_addr) {
482 bat_dbg(DBG_BATMAN, bat_priv,
483 "Drop packet: received my own broadcast (sender: %pM"
484 ")\n",
485 ethhdr->h_source);
486 return;
487 }
488
489 if (is_broadcast) {
490 bat_dbg(DBG_BATMAN, bat_priv, "Drop packet: "
491 "ignoring all packets with broadcast source addr (sender: %pM"
492 ")\n", ethhdr->h_source);
493 return;
494 }
495
496 if (is_my_orig) {
497 unsigned long *word;
498 int offset;
499
500 orig_neigh_node = get_orig_node(bat_priv, ethhdr->h_source);
501 if (!orig_neigh_node)
502 return;
503
504 /* neighbor has to indicate direct link and it has to
505 * come via the corresponding interface */
506 /* save packet seqno for bidirectional check */
507 if (has_directlink_flag &&
508 compare_eth(if_incoming->net_dev->dev_addr,
509 batman_ogm_packet->orig)) {
510 offset = if_incoming->if_num * NUM_WORDS;
511
512 spin_lock_bh(&orig_neigh_node->ogm_cnt_lock);
513 word = &(orig_neigh_node->bcast_own[offset]);
514 bit_mark(word,
515 if_incoming_seqno -
516 batman_ogm_packet->seqno - 2);
517 orig_neigh_node->bcast_own_sum[if_incoming->if_num] =
518 bit_packet_count(word);
519 spin_unlock_bh(&orig_neigh_node->ogm_cnt_lock);
520 }
521
522 bat_dbg(DBG_BATMAN, bat_priv, "Drop packet: "
523 "originator packet from myself (via neighbor)\n");
524 orig_node_free_ref(orig_neigh_node);
525 return;
526 }
527
528 if (is_my_oldorig) {
529 bat_dbg(DBG_BATMAN, bat_priv,
530 "Drop packet: ignoring all rebroadcast echos (sender: "
531 "%pM)\n", ethhdr->h_source);
532 return;
533 }
534
535 orig_node = get_orig_node(bat_priv, batman_ogm_packet->orig);
536 if (!orig_node)
537 return;
538
539 is_duplicate = bat_ogm_update_seqnos(ethhdr, batman_ogm_packet,
540 if_incoming);
541
542 if (is_duplicate == -1) {
543 bat_dbg(DBG_BATMAN, bat_priv,
544 "Drop packet: packet within seqno protection time "
545 "(sender: %pM)\n", ethhdr->h_source);
546 goto out;
547 }
548
549 if (batman_ogm_packet->tq == 0) {
550 bat_dbg(DBG_BATMAN, bat_priv,
551 "Drop packet: originator packet with tq equal 0\n");
552 goto out;
553 }
554
555 router = orig_node_get_router(orig_node);
556 if (router)
557 router_router = orig_node_get_router(router->orig_node);
558
559 /* avoid temporary routing loops */
560 if (router && router_router &&
561 (compare_eth(router->addr, batman_ogm_packet->prev_sender)) &&
562 !(compare_eth(batman_ogm_packet->orig,
563 batman_ogm_packet->prev_sender)) &&
564 (compare_eth(router->addr, router_router->addr))) {
565 bat_dbg(DBG_BATMAN, bat_priv,
566 "Drop packet: ignoring all rebroadcast packets that "
567 "may make me loop (sender: %pM)\n", ethhdr->h_source);
568 goto out;
569 }
570
571 /* if sender is a direct neighbor the sender mac equals
572 * originator mac */
573 orig_neigh_node = (is_single_hop_neigh ?
574 orig_node :
575 get_orig_node(bat_priv, ethhdr->h_source));
576 if (!orig_neigh_node)
577 goto out;
578
579 orig_neigh_router = orig_node_get_router(orig_neigh_node);
580
581 /* drop packet if sender is not a direct neighbor and if we
582 * don't route towards it */
583 if (!is_single_hop_neigh && (!orig_neigh_router)) {
584 bat_dbg(DBG_BATMAN, bat_priv,
585 "Drop packet: OGM via unknown neighbor!\n");
586 goto out_neigh;
587 }
588
589 is_bidirectional = bat_ogm_calc_tq(orig_node, orig_neigh_node,
590 batman_ogm_packet, if_incoming);
591
592 bonding_save_primary(orig_node, orig_neigh_node, batman_ogm_packet);
593
594 /* update ranking if it is not a duplicate or has the same
595 * seqno and similar ttl as the non-duplicate */
596 if (is_bidirectional &&
597 (!is_duplicate ||
598 ((orig_node->last_real_seqno == batman_ogm_packet->seqno) &&
599 (orig_node->last_ttl - 3 <= batman_ogm_packet->ttl))))
600 bat_ogm_orig_update(bat_priv, orig_node, ethhdr,
601 batman_ogm_packet, if_incoming,
602 tt_buff, is_duplicate);
603
604 /* is single hop (direct) neighbor */
605 if (is_single_hop_neigh) {
606
607 /* mark direct link on incoming interface */
608 schedule_forward_packet(orig_node, ethhdr, batman_ogm_packet,
609 1, if_incoming);
610
611 bat_dbg(DBG_BATMAN, bat_priv, "Forwarding packet: "
612 "rebroadcast neighbor packet with direct link flag\n");
613 goto out_neigh;
614 }
615
616 /* multihop originator */
617 if (!is_bidirectional) {
618 bat_dbg(DBG_BATMAN, bat_priv,
619 "Drop packet: not received via bidirectional link\n");
620 goto out_neigh;
621 }
622
623 if (is_duplicate) {
624 bat_dbg(DBG_BATMAN, bat_priv,
625 "Drop packet: duplicate packet received\n");
626 goto out_neigh;
627 }
628
629 bat_dbg(DBG_BATMAN, bat_priv,
630 "Forwarding packet: rebroadcast originator packet\n");
631 schedule_forward_packet(orig_node, ethhdr, batman_ogm_packet,
632 0, if_incoming);
633
634out_neigh:
635 if ((orig_neigh_node) && (!is_single_hop_neigh))
636 orig_node_free_ref(orig_neigh_node);
637out:
638 if (router)
639 neigh_node_free_ref(router);
640 if (router_router)
641 neigh_node_free_ref(router_router);
642 if (orig_neigh_router)
643 neigh_node_free_ref(orig_neigh_router);
644
645 orig_node_free_ref(orig_node);
646}
647
648void bat_ogm_receive(const struct ethhdr *ethhdr, unsigned char *packet_buff,
649 int packet_len, struct hard_iface *if_incoming)
650{
651 struct batman_ogm_packet *batman_ogm_packet;
652 int buff_pos = 0;
653 unsigned char *tt_buff;
654
655 batman_ogm_packet = (struct batman_ogm_packet *)packet_buff;
656
657 /* unpack the aggregated packets and process them one by one */
658 do {
659 /* network to host order for our 32bit seqno and the
660 orig_interval */
661 batman_ogm_packet->seqno = ntohl(batman_ogm_packet->seqno);
662 batman_ogm_packet->tt_crc = ntohs(batman_ogm_packet->tt_crc);
663
664 tt_buff = packet_buff + buff_pos + BATMAN_OGM_LEN;
665
666 bat_ogm_process(ethhdr, batman_ogm_packet,
667 tt_buff, if_incoming);
668
669 buff_pos += BATMAN_OGM_LEN +
670 tt_len(batman_ogm_packet->tt_num_changes);
671
672 batman_ogm_packet = (struct batman_ogm_packet *)
673 (packet_buff + buff_pos);
674 } while (bat_ogm_aggr_packet(buff_pos, packet_len,
675 batman_ogm_packet->tt_num_changes));
676}