blob: d60e1ba0bc150e600f8ee6d9076c9ab4714e8674 [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;
Sven Eckelmann76543d12011-11-20 15:47:38 +010041 batman_ogm_packet->header.packet_type = BAT_OGM;
42 batman_ogm_packet->header.version = COMPAT_VERSION;
43 batman_ogm_packet->header.ttl = 2;
Marek Lindnerd0b9fd82011-07-30 12:33:33 +020044 batman_ogm_packet->flags = NO_FLAGS;
Marek Lindnerd0b9fd82011-07-30 12:33:33 +020045 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;
Sven Eckelmann76543d12011-11-20 15:47:38 +010056 batman_ogm_packet->header.ttl = TTL;
Marek Lindnerd0b9fd82011-07-30 12:33:33 +020057}
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 Lindnerb9dacc52011-08-03 09:09:30 +020070/* when do we schedule our own ogm to be sent */
71static unsigned long bat_ogm_emit_send_time(const struct bat_priv *bat_priv)
72{
73 return jiffies + msecs_to_jiffies(
74 atomic_read(&bat_priv->orig_interval) -
75 JITTER + (random32() % 2*JITTER));
76}
77
78/* when do we schedule a ogm packet to be sent */
79static unsigned long bat_ogm_fwd_send_time(void)
80{
81 return jiffies + msecs_to_jiffies(random32() % (JITTER/2));
82}
83
84/* apply hop penalty for a normal link */
85static uint8_t hop_penalty(uint8_t tq, const struct bat_priv *bat_priv)
86{
87 int hop_penalty = atomic_read(&bat_priv->hop_penalty);
88 return (tq * (TQ_MAX_VALUE - hop_penalty)) / (TQ_MAX_VALUE);
89}
90
Marek Lindnerfc957272011-07-30 12:04:12 +020091/* is there another aggregated packet here? */
92static int bat_ogm_aggr_packet(int buff_pos, int packet_len,
93 int tt_num_changes)
94{
95 int next_buff_pos = buff_pos + BATMAN_OGM_LEN + tt_len(tt_num_changes);
96
97 return (next_buff_pos <= packet_len) &&
98 (next_buff_pos <= MAX_AGGREGATION_BYTES);
99}
100
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200101/* send a batman ogm to a given interface */
102static void bat_ogm_send_to_if(struct forw_packet *forw_packet,
103 struct hard_iface *hard_iface)
104{
105 struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
106 char *fwd_str;
107 uint8_t packet_num;
108 int16_t buff_pos;
109 struct batman_ogm_packet *batman_ogm_packet;
110 struct sk_buff *skb;
111
112 if (hard_iface->if_status != IF_ACTIVE)
113 return;
114
115 packet_num = 0;
116 buff_pos = 0;
117 batman_ogm_packet = (struct batman_ogm_packet *)forw_packet->skb->data;
118
119 /* adjust all flags and log packets */
120 while (bat_ogm_aggr_packet(buff_pos, forw_packet->packet_len,
121 batman_ogm_packet->tt_num_changes)) {
122
123 /* we might have aggregated direct link packets with an
124 * ordinary base packet */
125 if ((forw_packet->direct_link_flags & (1 << packet_num)) &&
126 (forw_packet->if_incoming == hard_iface))
127 batman_ogm_packet->flags |= DIRECTLINK;
128 else
129 batman_ogm_packet->flags &= ~DIRECTLINK;
130
131 fwd_str = (packet_num > 0 ? "Forwarding" : (forw_packet->own ?
132 "Sending own" :
133 "Forwarding"));
134 bat_dbg(DBG_BATMAN, bat_priv,
135 "%s %spacket (originator %pM, seqno %d, TQ %d, TTL %d,"
136 " IDF %s, ttvn %d) on interface %s [%pM]\n",
137 fwd_str, (packet_num > 0 ? "aggregated " : ""),
138 batman_ogm_packet->orig,
139 ntohl(batman_ogm_packet->seqno),
Sven Eckelmann76543d12011-11-20 15:47:38 +0100140 batman_ogm_packet->tq, batman_ogm_packet->header.ttl,
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200141 (batman_ogm_packet->flags & DIRECTLINK ?
142 "on" : "off"),
143 batman_ogm_packet->ttvn, hard_iface->net_dev->name,
144 hard_iface->net_dev->dev_addr);
145
146 buff_pos += BATMAN_OGM_LEN +
147 tt_len(batman_ogm_packet->tt_num_changes);
148 packet_num++;
149 batman_ogm_packet = (struct batman_ogm_packet *)
150 (forw_packet->skb->data + buff_pos);
151 }
152
153 /* create clone because function is called more than once */
154 skb = skb_clone(forw_packet->skb, GFP_ATOMIC);
155 if (skb)
156 send_skb_packet(skb, hard_iface, broadcast_addr);
157}
158
159/* send a batman ogm packet */
160void bat_ogm_emit(struct forw_packet *forw_packet)
161{
162 struct hard_iface *hard_iface;
163 struct net_device *soft_iface;
164 struct bat_priv *bat_priv;
165 struct hard_iface *primary_if = NULL;
166 struct batman_ogm_packet *batman_ogm_packet;
167 unsigned char directlink;
168
169 batman_ogm_packet = (struct batman_ogm_packet *)
170 (forw_packet->skb->data);
171 directlink = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
172
173 if (!forw_packet->if_incoming) {
174 pr_err("Error - can't forward packet: incoming iface not "
175 "specified\n");
176 goto out;
177 }
178
179 soft_iface = forw_packet->if_incoming->soft_iface;
180 bat_priv = netdev_priv(soft_iface);
181
182 if (forw_packet->if_incoming->if_status != IF_ACTIVE)
183 goto out;
184
185 primary_if = primary_if_get_selected(bat_priv);
186 if (!primary_if)
187 goto out;
188
189 /* multihomed peer assumed */
190 /* non-primary OGMs are only broadcasted on their interface */
Sven Eckelmann76543d12011-11-20 15:47:38 +0100191 if ((directlink && (batman_ogm_packet->header.ttl == 1)) ||
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200192 (forw_packet->own && (forw_packet->if_incoming != primary_if))) {
193
194 /* FIXME: what about aggregated packets ? */
195 bat_dbg(DBG_BATMAN, bat_priv,
196 "%s packet (originator %pM, seqno %d, TTL %d) "
197 "on interface %s [%pM]\n",
198 (forw_packet->own ? "Sending own" : "Forwarding"),
199 batman_ogm_packet->orig,
200 ntohl(batman_ogm_packet->seqno),
Sven Eckelmann76543d12011-11-20 15:47:38 +0100201 batman_ogm_packet->header.ttl,
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200202 forw_packet->if_incoming->net_dev->name,
203 forw_packet->if_incoming->net_dev->dev_addr);
204
205 /* skb is only used once and than forw_packet is free'd */
206 send_skb_packet(forw_packet->skb, forw_packet->if_incoming,
207 broadcast_addr);
208 forw_packet->skb = NULL;
209
210 goto out;
211 }
212
213 /* broadcast on every interface */
214 rcu_read_lock();
215 list_for_each_entry_rcu(hard_iface, &hardif_list, list) {
216 if (hard_iface->soft_iface != soft_iface)
217 continue;
218
219 bat_ogm_send_to_if(forw_packet, hard_iface);
220 }
221 rcu_read_unlock();
222
223out:
224 if (primary_if)
225 hardif_free_ref(primary_if);
226}
227
228/* return true if new_packet can be aggregated with forw_packet */
229static bool bat_ogm_can_aggregate(const struct batman_ogm_packet
230 *new_batman_ogm_packet,
231 struct bat_priv *bat_priv,
232 int packet_len, unsigned long send_time,
233 bool directlink,
234 const struct hard_iface *if_incoming,
235 const struct forw_packet *forw_packet)
236{
237 struct batman_ogm_packet *batman_ogm_packet;
238 int aggregated_bytes = forw_packet->packet_len + packet_len;
239 struct hard_iface *primary_if = NULL;
240 bool res = false;
241
242 batman_ogm_packet = (struct batman_ogm_packet *)forw_packet->skb->data;
243
244 /**
245 * we can aggregate the current packet to this aggregated packet
246 * if:
247 *
248 * - the send time is within our MAX_AGGREGATION_MS time
249 * - the resulting packet wont be bigger than
250 * MAX_AGGREGATION_BYTES
251 */
252
253 if (time_before(send_time, forw_packet->send_time) &&
254 time_after_eq(send_time + msecs_to_jiffies(MAX_AGGREGATION_MS),
255 forw_packet->send_time) &&
256 (aggregated_bytes <= MAX_AGGREGATION_BYTES)) {
257
258 /**
259 * check aggregation compatibility
260 * -> direct link packets are broadcasted on
261 * their interface only
262 * -> aggregate packet if the current packet is
263 * a "global" packet as well as the base
264 * packet
265 */
266
267 primary_if = primary_if_get_selected(bat_priv);
268 if (!primary_if)
269 goto out;
270
271 /* packets without direct link flag and high TTL
272 * are flooded through the net */
273 if ((!directlink) &&
274 (!(batman_ogm_packet->flags & DIRECTLINK)) &&
Sven Eckelmann76543d12011-11-20 15:47:38 +0100275 (batman_ogm_packet->header.ttl != 1) &&
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200276
277 /* own packets originating non-primary
278 * interfaces leave only that interface */
279 ((!forw_packet->own) ||
280 (forw_packet->if_incoming == primary_if))) {
281 res = true;
282 goto out;
283 }
284
285 /* if the incoming packet is sent via this one
286 * interface only - we still can aggregate */
287 if ((directlink) &&
Sven Eckelmann76543d12011-11-20 15:47:38 +0100288 (new_batman_ogm_packet->header.ttl == 1) &&
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200289 (forw_packet->if_incoming == if_incoming) &&
290
291 /* packets from direct neighbors or
292 * own secondary interface packets
293 * (= secondary interface packets in general) */
294 (batman_ogm_packet->flags & DIRECTLINK ||
295 (forw_packet->own &&
296 forw_packet->if_incoming != primary_if))) {
297 res = true;
298 goto out;
299 }
300 }
301
302out:
303 if (primary_if)
304 hardif_free_ref(primary_if);
305 return res;
306}
307
308/* create a new aggregated packet and add this packet to it */
309static void bat_ogm_aggregate_new(const unsigned char *packet_buff,
310 int packet_len, unsigned long send_time,
311 bool direct_link,
312 struct hard_iface *if_incoming,
313 int own_packet)
314{
315 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
316 struct forw_packet *forw_packet_aggr;
317 unsigned char *skb_buff;
318
319 if (!atomic_inc_not_zero(&if_incoming->refcount))
320 return;
321
322 /* own packet should always be scheduled */
323 if (!own_packet) {
324 if (!atomic_dec_not_zero(&bat_priv->batman_queue_left)) {
325 bat_dbg(DBG_BATMAN, bat_priv,
326 "batman packet queue full\n");
327 goto out;
328 }
329 }
330
331 forw_packet_aggr = kmalloc(sizeof(*forw_packet_aggr), GFP_ATOMIC);
332 if (!forw_packet_aggr) {
333 if (!own_packet)
334 atomic_inc(&bat_priv->batman_queue_left);
335 goto out;
336 }
337
338 if ((atomic_read(&bat_priv->aggregated_ogms)) &&
339 (packet_len < MAX_AGGREGATION_BYTES))
340 forw_packet_aggr->skb = dev_alloc_skb(MAX_AGGREGATION_BYTES +
341 sizeof(struct ethhdr));
342 else
343 forw_packet_aggr->skb = dev_alloc_skb(packet_len +
344 sizeof(struct ethhdr));
345
346 if (!forw_packet_aggr->skb) {
347 if (!own_packet)
348 atomic_inc(&bat_priv->batman_queue_left);
349 kfree(forw_packet_aggr);
350 goto out;
351 }
352 skb_reserve(forw_packet_aggr->skb, sizeof(struct ethhdr));
353
354 INIT_HLIST_NODE(&forw_packet_aggr->list);
355
356 skb_buff = skb_put(forw_packet_aggr->skb, packet_len);
357 forw_packet_aggr->packet_len = packet_len;
358 memcpy(skb_buff, packet_buff, packet_len);
359
360 forw_packet_aggr->own = own_packet;
361 forw_packet_aggr->if_incoming = if_incoming;
362 forw_packet_aggr->num_packets = 0;
363 forw_packet_aggr->direct_link_flags = NO_FLAGS;
364 forw_packet_aggr->send_time = send_time;
365
366 /* save packet direct link flag status */
367 if (direct_link)
368 forw_packet_aggr->direct_link_flags |= 1;
369
370 /* add new packet to packet list */
371 spin_lock_bh(&bat_priv->forw_bat_list_lock);
372 hlist_add_head(&forw_packet_aggr->list, &bat_priv->forw_bat_list);
373 spin_unlock_bh(&bat_priv->forw_bat_list_lock);
374
375 /* start timer for this packet */
376 INIT_DELAYED_WORK(&forw_packet_aggr->delayed_work,
377 send_outstanding_bat_ogm_packet);
378 queue_delayed_work(bat_event_workqueue,
379 &forw_packet_aggr->delayed_work,
380 send_time - jiffies);
381
382 return;
383out:
384 hardif_free_ref(if_incoming);
385}
386
387/* aggregate a new packet into the existing ogm packet */
388static void bat_ogm_aggregate(struct forw_packet *forw_packet_aggr,
389 const unsigned char *packet_buff,
390 int packet_len, bool direct_link)
391{
392 unsigned char *skb_buff;
393
394 skb_buff = skb_put(forw_packet_aggr->skb, packet_len);
395 memcpy(skb_buff, packet_buff, packet_len);
396 forw_packet_aggr->packet_len += packet_len;
397 forw_packet_aggr->num_packets++;
398
399 /* save packet direct link flag status */
400 if (direct_link)
401 forw_packet_aggr->direct_link_flags |=
402 (1 << forw_packet_aggr->num_packets);
403}
404
405static void bat_ogm_queue_add(struct bat_priv *bat_priv,
406 unsigned char *packet_buff,
407 int packet_len, struct hard_iface *if_incoming,
408 int own_packet, unsigned long send_time)
409{
410 /**
411 * _aggr -> pointer to the packet we want to aggregate with
412 * _pos -> pointer to the position in the queue
413 */
414 struct forw_packet *forw_packet_aggr = NULL, *forw_packet_pos = NULL;
415 struct hlist_node *tmp_node;
416 struct batman_ogm_packet *batman_ogm_packet;
417 bool direct_link;
418
419 batman_ogm_packet = (struct batman_ogm_packet *)packet_buff;
420 direct_link = batman_ogm_packet->flags & DIRECTLINK ? 1 : 0;
421
422 /* find position for the packet in the forward queue */
423 spin_lock_bh(&bat_priv->forw_bat_list_lock);
424 /* own packets are not to be aggregated */
425 if ((atomic_read(&bat_priv->aggregated_ogms)) && (!own_packet)) {
426 hlist_for_each_entry(forw_packet_pos, tmp_node,
427 &bat_priv->forw_bat_list, list) {
428 if (bat_ogm_can_aggregate(batman_ogm_packet,
429 bat_priv, packet_len,
430 send_time, direct_link,
431 if_incoming,
432 forw_packet_pos)) {
433 forw_packet_aggr = forw_packet_pos;
434 break;
435 }
436 }
437 }
438
439 /* nothing to aggregate with - either aggregation disabled or no
440 * suitable aggregation packet found */
441 if (!forw_packet_aggr) {
442 /* the following section can run without the lock */
443 spin_unlock_bh(&bat_priv->forw_bat_list_lock);
444
445 /**
446 * if we could not aggregate this packet with one of the others
447 * we hold it back for a while, so that it might be aggregated
448 * later on
449 */
450 if ((!own_packet) &&
451 (atomic_read(&bat_priv->aggregated_ogms)))
452 send_time += msecs_to_jiffies(MAX_AGGREGATION_MS);
453
454 bat_ogm_aggregate_new(packet_buff, packet_len,
455 send_time, direct_link,
456 if_incoming, own_packet);
457 } else {
458 bat_ogm_aggregate(forw_packet_aggr, packet_buff, packet_len,
459 direct_link);
460 spin_unlock_bh(&bat_priv->forw_bat_list_lock);
461 }
462}
463
464static void bat_ogm_forward(struct orig_node *orig_node,
465 const struct ethhdr *ethhdr,
466 struct batman_ogm_packet *batman_ogm_packet,
467 int directlink, struct hard_iface *if_incoming)
468{
469 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
470 struct neigh_node *router;
471 uint8_t in_tq, in_ttl, tq_avg = 0;
472 uint8_t tt_num_changes;
473
Sven Eckelmann76543d12011-11-20 15:47:38 +0100474 if (batman_ogm_packet->header.ttl <= 1) {
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200475 bat_dbg(DBG_BATMAN, bat_priv, "ttl exceeded\n");
476 return;
477 }
478
479 router = orig_node_get_router(orig_node);
480
481 in_tq = batman_ogm_packet->tq;
Sven Eckelmann76543d12011-11-20 15:47:38 +0100482 in_ttl = batman_ogm_packet->header.ttl;
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200483 tt_num_changes = batman_ogm_packet->tt_num_changes;
484
Sven Eckelmann76543d12011-11-20 15:47:38 +0100485 batman_ogm_packet->header.ttl--;
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200486 memcpy(batman_ogm_packet->prev_sender, ethhdr->h_source, ETH_ALEN);
487
488 /* rebroadcast tq of our best ranking neighbor to ensure the rebroadcast
489 * of our best tq value */
490 if (router && router->tq_avg != 0) {
491
492 /* rebroadcast ogm of best ranking neighbor as is */
493 if (!compare_eth(router->addr, ethhdr->h_source)) {
494 batman_ogm_packet->tq = router->tq_avg;
495
496 if (router->last_ttl)
Sven Eckelmann76543d12011-11-20 15:47:38 +0100497 batman_ogm_packet->header.ttl =
498 router->last_ttl - 1;
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200499 }
500
501 tq_avg = router->tq_avg;
502 }
503
504 if (router)
505 neigh_node_free_ref(router);
506
507 /* apply hop penalty */
508 batman_ogm_packet->tq = hop_penalty(batman_ogm_packet->tq, bat_priv);
509
510 bat_dbg(DBG_BATMAN, bat_priv,
511 "Forwarding packet: tq_orig: %i, tq_avg: %i, "
512 "tq_forw: %i, ttl_orig: %i, ttl_forw: %i\n",
513 in_tq, tq_avg, batman_ogm_packet->tq, in_ttl - 1,
Sven Eckelmann76543d12011-11-20 15:47:38 +0100514 batman_ogm_packet->header.ttl);
Marek Lindnerb9dacc52011-08-03 09:09:30 +0200515
516 batman_ogm_packet->seqno = htonl(batman_ogm_packet->seqno);
517 batman_ogm_packet->tt_crc = htons(batman_ogm_packet->tt_crc);
518
519 /* switch of primaries first hop flag when forwarding */
520 batman_ogm_packet->flags &= ~PRIMARIES_FIRST_HOP;
521 if (directlink)
522 batman_ogm_packet->flags |= DIRECTLINK;
523 else
524 batman_ogm_packet->flags &= ~DIRECTLINK;
525
526 bat_ogm_queue_add(bat_priv, (unsigned char *)batman_ogm_packet,
527 BATMAN_OGM_LEN + tt_len(tt_num_changes),
528 if_incoming, 0, bat_ogm_fwd_send_time());
529}
530
531void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
532{
533 struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
534 struct batman_ogm_packet *batman_ogm_packet;
535 struct hard_iface *primary_if;
536 int vis_server;
537
538 vis_server = atomic_read(&bat_priv->vis_mode);
539 primary_if = primary_if_get_selected(bat_priv);
540
541 batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff;
542
543 /* change sequence number to network order */
544 batman_ogm_packet->seqno =
545 htonl((uint32_t)atomic_read(&hard_iface->seqno));
546
547 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
548 batman_ogm_packet->tt_crc = htons((uint16_t)
549 atomic_read(&bat_priv->tt_crc));
550 if (tt_num_changes >= 0)
551 batman_ogm_packet->tt_num_changes = tt_num_changes;
552
553 if (vis_server == VIS_TYPE_SERVER_SYNC)
554 batman_ogm_packet->flags |= VIS_SERVER;
555 else
556 batman_ogm_packet->flags &= ~VIS_SERVER;
557
558 if ((hard_iface == primary_if) &&
559 (atomic_read(&bat_priv->gw_mode) == GW_MODE_SERVER))
560 batman_ogm_packet->gw_flags =
561 (uint8_t)atomic_read(&bat_priv->gw_bandwidth);
562 else
563 batman_ogm_packet->gw_flags = NO_FLAGS;
564
565 atomic_inc(&hard_iface->seqno);
566
567 slide_own_bcast_window(hard_iface);
568 bat_ogm_queue_add(bat_priv, hard_iface->packet_buff,
569 hard_iface->packet_len, hard_iface, 1,
570 bat_ogm_emit_send_time(bat_priv));
571
572 if (primary_if)
573 hardif_free_ref(primary_if);
574}
575
Marek Lindnerfc957272011-07-30 12:04:12 +0200576static void bat_ogm_orig_update(struct bat_priv *bat_priv,
577 struct orig_node *orig_node,
578 const struct ethhdr *ethhdr,
579 const struct batman_ogm_packet
580 *batman_ogm_packet,
581 struct hard_iface *if_incoming,
582 const unsigned char *tt_buff, int is_duplicate)
583{
584 struct neigh_node *neigh_node = NULL, *tmp_neigh_node = NULL;
585 struct neigh_node *router = NULL;
586 struct orig_node *orig_node_tmp;
587 struct hlist_node *node;
588 uint8_t bcast_own_sum_orig, bcast_own_sum_neigh;
589
590 bat_dbg(DBG_BATMAN, bat_priv, "update_originator(): "
591 "Searching and updating originator entry of received packet\n");
592
593 rcu_read_lock();
594 hlist_for_each_entry_rcu(tmp_neigh_node, node,
595 &orig_node->neigh_list, list) {
596 if (compare_eth(tmp_neigh_node->addr, ethhdr->h_source) &&
597 (tmp_neigh_node->if_incoming == if_incoming) &&
598 atomic_inc_not_zero(&tmp_neigh_node->refcount)) {
599 if (neigh_node)
600 neigh_node_free_ref(neigh_node);
601 neigh_node = tmp_neigh_node;
602 continue;
603 }
604
605 if (is_duplicate)
606 continue;
607
608 spin_lock_bh(&tmp_neigh_node->tq_lock);
609 ring_buffer_set(tmp_neigh_node->tq_recv,
610 &tmp_neigh_node->tq_index, 0);
611 tmp_neigh_node->tq_avg =
612 ring_buffer_avg(tmp_neigh_node->tq_recv);
613 spin_unlock_bh(&tmp_neigh_node->tq_lock);
614 }
615
616 if (!neigh_node) {
617 struct orig_node *orig_tmp;
618
619 orig_tmp = get_orig_node(bat_priv, ethhdr->h_source);
620 if (!orig_tmp)
621 goto unlock;
622
623 neigh_node = create_neighbor(orig_node, orig_tmp,
624 ethhdr->h_source, if_incoming);
625
626 orig_node_free_ref(orig_tmp);
627 if (!neigh_node)
628 goto unlock;
629 } else
630 bat_dbg(DBG_BATMAN, bat_priv,
631 "Updating existing last-hop neighbor of originator\n");
632
633 rcu_read_unlock();
634
635 orig_node->flags = batman_ogm_packet->flags;
636 neigh_node->last_valid = jiffies;
637
638 spin_lock_bh(&neigh_node->tq_lock);
639 ring_buffer_set(neigh_node->tq_recv,
640 &neigh_node->tq_index,
641 batman_ogm_packet->tq);
642 neigh_node->tq_avg = ring_buffer_avg(neigh_node->tq_recv);
643 spin_unlock_bh(&neigh_node->tq_lock);
644
645 if (!is_duplicate) {
Sven Eckelmann76543d12011-11-20 15:47:38 +0100646 orig_node->last_ttl = batman_ogm_packet->header.ttl;
647 neigh_node->last_ttl = batman_ogm_packet->header.ttl;
Marek Lindnerfc957272011-07-30 12:04:12 +0200648 }
649
650 bonding_candidate_add(orig_node, neigh_node);
651
652 /* if this neighbor already is our next hop there is nothing
653 * to change */
654 router = orig_node_get_router(orig_node);
655 if (router == neigh_node)
656 goto update_tt;
657
658 /* if this neighbor does not offer a better TQ we won't consider it */
659 if (router && (router->tq_avg > neigh_node->tq_avg))
660 goto update_tt;
661
662 /* if the TQ is the same and the link not more symmetric we
663 * won't consider it either */
664 if (router && (neigh_node->tq_avg == router->tq_avg)) {
665 orig_node_tmp = router->orig_node;
666 spin_lock_bh(&orig_node_tmp->ogm_cnt_lock);
667 bcast_own_sum_orig =
668 orig_node_tmp->bcast_own_sum[if_incoming->if_num];
669 spin_unlock_bh(&orig_node_tmp->ogm_cnt_lock);
670
671 orig_node_tmp = neigh_node->orig_node;
672 spin_lock_bh(&orig_node_tmp->ogm_cnt_lock);
673 bcast_own_sum_neigh =
674 orig_node_tmp->bcast_own_sum[if_incoming->if_num];
675 spin_unlock_bh(&orig_node_tmp->ogm_cnt_lock);
676
677 if (bcast_own_sum_orig >= bcast_own_sum_neigh)
678 goto update_tt;
679 }
680
681 update_route(bat_priv, orig_node, neigh_node);
682
683update_tt:
684 /* I have to check for transtable changes only if the OGM has been
685 * sent through a primary interface */
686 if (((batman_ogm_packet->orig != ethhdr->h_source) &&
Sven Eckelmann76543d12011-11-20 15:47:38 +0100687 (batman_ogm_packet->header.ttl > 2)) ||
Marek Lindnerfc957272011-07-30 12:04:12 +0200688 (batman_ogm_packet->flags & PRIMARIES_FIRST_HOP))
689 tt_update_orig(bat_priv, orig_node, tt_buff,
690 batman_ogm_packet->tt_num_changes,
691 batman_ogm_packet->ttvn,
692 batman_ogm_packet->tt_crc);
693
694 if (orig_node->gw_flags != batman_ogm_packet->gw_flags)
695 gw_node_update(bat_priv, orig_node,
696 batman_ogm_packet->gw_flags);
697
698 orig_node->gw_flags = batman_ogm_packet->gw_flags;
699
700 /* restart gateway selection if fast or late switching was enabled */
701 if ((orig_node->gw_flags) &&
702 (atomic_read(&bat_priv->gw_mode) == GW_MODE_CLIENT) &&
703 (atomic_read(&bat_priv->gw_sel_class) > 2))
704 gw_check_election(bat_priv, orig_node);
705
706 goto out;
707
708unlock:
709 rcu_read_unlock();
710out:
711 if (neigh_node)
712 neigh_node_free_ref(neigh_node);
713 if (router)
714 neigh_node_free_ref(router);
715}
716
717static int bat_ogm_calc_tq(struct orig_node *orig_node,
718 struct orig_node *orig_neigh_node,
719 struct batman_ogm_packet *batman_ogm_packet,
720 struct hard_iface *if_incoming)
721{
722 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
723 struct neigh_node *neigh_node = NULL, *tmp_neigh_node;
724 struct hlist_node *node;
725 uint8_t total_count;
726 uint8_t orig_eq_count, neigh_rq_count, tq_own;
727 int tq_asym_penalty, ret = 0;
728
729 /* find corresponding one hop neighbor */
730 rcu_read_lock();
731 hlist_for_each_entry_rcu(tmp_neigh_node, node,
732 &orig_neigh_node->neigh_list, list) {
733
734 if (!compare_eth(tmp_neigh_node->addr, orig_neigh_node->orig))
735 continue;
736
737 if (tmp_neigh_node->if_incoming != if_incoming)
738 continue;
739
740 if (!atomic_inc_not_zero(&tmp_neigh_node->refcount))
741 continue;
742
743 neigh_node = tmp_neigh_node;
744 break;
745 }
746 rcu_read_unlock();
747
748 if (!neigh_node)
749 neigh_node = create_neighbor(orig_neigh_node,
750 orig_neigh_node,
751 orig_neigh_node->orig,
752 if_incoming);
753
754 if (!neigh_node)
755 goto out;
756
757 /* if orig_node is direct neighbor update neigh_node last_valid */
758 if (orig_node == orig_neigh_node)
759 neigh_node->last_valid = jiffies;
760
761 orig_node->last_valid = jiffies;
762
763 /* find packet count of corresponding one hop neighbor */
764 spin_lock_bh(&orig_node->ogm_cnt_lock);
765 orig_eq_count = orig_neigh_node->bcast_own_sum[if_incoming->if_num];
766 neigh_rq_count = neigh_node->real_packet_count;
767 spin_unlock_bh(&orig_node->ogm_cnt_lock);
768
769 /* pay attention to not get a value bigger than 100 % */
770 total_count = (orig_eq_count > neigh_rq_count ?
771 neigh_rq_count : orig_eq_count);
772
773 /* if we have too few packets (too less data) we set tq_own to zero */
774 /* if we receive too few packets it is not considered bidirectional */
775 if ((total_count < TQ_LOCAL_BIDRECT_SEND_MINIMUM) ||
776 (neigh_rq_count < TQ_LOCAL_BIDRECT_RECV_MINIMUM))
777 tq_own = 0;
778 else
779 /* neigh_node->real_packet_count is never zero as we
780 * only purge old information when getting new
781 * information */
782 tq_own = (TQ_MAX_VALUE * total_count) / neigh_rq_count;
783
784 /*
785 * 1 - ((1-x) ** 3), normalized to TQ_MAX_VALUE this does
786 * affect the nearly-symmetric links only a little, but
787 * punishes asymmetric links more. This will give a value
788 * between 0 and TQ_MAX_VALUE
789 */
790 tq_asym_penalty = TQ_MAX_VALUE - (TQ_MAX_VALUE *
791 (TQ_LOCAL_WINDOW_SIZE - neigh_rq_count) *
792 (TQ_LOCAL_WINDOW_SIZE - neigh_rq_count) *
793 (TQ_LOCAL_WINDOW_SIZE - neigh_rq_count)) /
794 (TQ_LOCAL_WINDOW_SIZE *
795 TQ_LOCAL_WINDOW_SIZE *
796 TQ_LOCAL_WINDOW_SIZE);
797
798 batman_ogm_packet->tq = ((batman_ogm_packet->tq * tq_own
799 * tq_asym_penalty) /
800 (TQ_MAX_VALUE * TQ_MAX_VALUE));
801
802 bat_dbg(DBG_BATMAN, bat_priv,
803 "bidirectional: "
804 "orig = %-15pM neigh = %-15pM => own_bcast = %2i, "
805 "real recv = %2i, local tq: %3i, asym_penalty: %3i, "
806 "total tq: %3i\n",
807 orig_node->orig, orig_neigh_node->orig, total_count,
808 neigh_rq_count, tq_own, tq_asym_penalty, batman_ogm_packet->tq);
809
810 /* if link has the minimum required transmission quality
811 * consider it bidirectional */
812 if (batman_ogm_packet->tq >= TQ_TOTAL_BIDRECT_LIMIT)
813 ret = 1;
814
815out:
816 if (neigh_node)
817 neigh_node_free_ref(neigh_node);
818 return ret;
819}
820
821/* processes a batman packet for all interfaces, adjusts the sequence number and
822 * finds out whether it is a duplicate.
823 * returns:
824 * 1 the packet is a duplicate
825 * 0 the packet has not yet been received
826 * -1 the packet is old and has been received while the seqno window
827 * was protected. Caller should drop it.
828 */
829static int bat_ogm_update_seqnos(const struct ethhdr *ethhdr,
830 const struct batman_ogm_packet
831 *batman_ogm_packet,
832 const struct hard_iface *if_incoming)
833{
834 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
835 struct orig_node *orig_node;
836 struct neigh_node *tmp_neigh_node;
837 struct hlist_node *node;
838 int is_duplicate = 0;
839 int32_t seq_diff;
840 int need_update = 0;
841 int set_mark, ret = -1;
842
843 orig_node = get_orig_node(bat_priv, batman_ogm_packet->orig);
844 if (!orig_node)
845 return 0;
846
847 spin_lock_bh(&orig_node->ogm_cnt_lock);
848 seq_diff = batman_ogm_packet->seqno - orig_node->last_real_seqno;
849
850 /* signalize caller that the packet is to be dropped. */
851 if (window_protected(bat_priv, seq_diff,
852 &orig_node->batman_seqno_reset))
853 goto out;
854
855 rcu_read_lock();
856 hlist_for_each_entry_rcu(tmp_neigh_node, node,
857 &orig_node->neigh_list, list) {
858
859 is_duplicate |= get_bit_status(tmp_neigh_node->real_bits,
860 orig_node->last_real_seqno,
861 batman_ogm_packet->seqno);
862
863 if (compare_eth(tmp_neigh_node->addr, ethhdr->h_source) &&
864 (tmp_neigh_node->if_incoming == if_incoming))
865 set_mark = 1;
866 else
867 set_mark = 0;
868
869 /* if the window moved, set the update flag. */
870 need_update |= bit_get_packet(bat_priv,
871 tmp_neigh_node->real_bits,
872 seq_diff, set_mark);
873
874 tmp_neigh_node->real_packet_count =
875 bit_packet_count(tmp_neigh_node->real_bits);
876 }
877 rcu_read_unlock();
878
879 if (need_update) {
880 bat_dbg(DBG_BATMAN, bat_priv,
881 "updating last_seqno: old %d, new %d\n",
882 orig_node->last_real_seqno, batman_ogm_packet->seqno);
883 orig_node->last_real_seqno = batman_ogm_packet->seqno;
884 }
885
886 ret = is_duplicate;
887
888out:
889 spin_unlock_bh(&orig_node->ogm_cnt_lock);
890 orig_node_free_ref(orig_node);
891 return ret;
892}
893
894static void bat_ogm_process(const struct ethhdr *ethhdr,
895 struct batman_ogm_packet *batman_ogm_packet,
896 const unsigned char *tt_buff,
897 struct hard_iface *if_incoming)
898{
899 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
900 struct hard_iface *hard_iface;
901 struct orig_node *orig_neigh_node, *orig_node;
902 struct neigh_node *router = NULL, *router_router = NULL;
903 struct neigh_node *orig_neigh_router = NULL;
904 int has_directlink_flag;
905 int is_my_addr = 0, is_my_orig = 0, is_my_oldorig = 0;
906 int is_broadcast = 0, is_bidirectional, is_single_hop_neigh;
907 int is_duplicate;
908 uint32_t if_incoming_seqno;
909
910 /* Silently drop when the batman packet is actually not a
911 * correct packet.
912 *
913 * This might happen if a packet is padded (e.g. Ethernet has a
914 * minimum frame length of 64 byte) and the aggregation interprets
915 * it as an additional length.
916 *
917 * TODO: A more sane solution would be to have a bit in the
918 * batman_ogm_packet to detect whether the packet is the last
919 * packet in an aggregation. Here we expect that the padding
920 * is always zero (or not 0x01)
921 */
Sven Eckelmann76543d12011-11-20 15:47:38 +0100922 if (batman_ogm_packet->header.packet_type != BAT_OGM)
Marek Lindnerfc957272011-07-30 12:04:12 +0200923 return;
924
925 /* could be changed by schedule_own_packet() */
926 if_incoming_seqno = atomic_read(&if_incoming->seqno);
927
928 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
929
930 is_single_hop_neigh = (compare_eth(ethhdr->h_source,
931 batman_ogm_packet->orig) ? 1 : 0);
932
933 bat_dbg(DBG_BATMAN, bat_priv,
934 "Received BATMAN packet via NB: %pM, IF: %s [%pM] "
935 "(from OG: %pM, via prev OG: %pM, seqno %d, ttvn %u, "
936 "crc %u, changes %u, td %d, TTL %d, V %d, IDF %d)\n",
937 ethhdr->h_source, if_incoming->net_dev->name,
938 if_incoming->net_dev->dev_addr, batman_ogm_packet->orig,
939 batman_ogm_packet->prev_sender, batman_ogm_packet->seqno,
940 batman_ogm_packet->ttvn, batman_ogm_packet->tt_crc,
941 batman_ogm_packet->tt_num_changes, batman_ogm_packet->tq,
Sven Eckelmann76543d12011-11-20 15:47:38 +0100942 batman_ogm_packet->header.ttl,
943 batman_ogm_packet->header.version, has_directlink_flag);
Marek Lindnerfc957272011-07-30 12:04:12 +0200944
945 rcu_read_lock();
946 list_for_each_entry_rcu(hard_iface, &hardif_list, list) {
947 if (hard_iface->if_status != IF_ACTIVE)
948 continue;
949
950 if (hard_iface->soft_iface != if_incoming->soft_iface)
951 continue;
952
953 if (compare_eth(ethhdr->h_source,
954 hard_iface->net_dev->dev_addr))
955 is_my_addr = 1;
956
957 if (compare_eth(batman_ogm_packet->orig,
958 hard_iface->net_dev->dev_addr))
959 is_my_orig = 1;
960
961 if (compare_eth(batman_ogm_packet->prev_sender,
962 hard_iface->net_dev->dev_addr))
963 is_my_oldorig = 1;
964
965 if (is_broadcast_ether_addr(ethhdr->h_source))
966 is_broadcast = 1;
967 }
968 rcu_read_unlock();
969
Sven Eckelmann76543d12011-11-20 15:47:38 +0100970 if (batman_ogm_packet->header.version != COMPAT_VERSION) {
Marek Lindnerfc957272011-07-30 12:04:12 +0200971 bat_dbg(DBG_BATMAN, bat_priv,
972 "Drop packet: incompatible batman version (%i)\n",
Sven Eckelmann76543d12011-11-20 15:47:38 +0100973 batman_ogm_packet->header.version);
Marek Lindnerfc957272011-07-30 12:04:12 +0200974 return;
975 }
976
977 if (is_my_addr) {
978 bat_dbg(DBG_BATMAN, bat_priv,
979 "Drop packet: received my own broadcast (sender: %pM"
980 ")\n",
981 ethhdr->h_source);
982 return;
983 }
984
985 if (is_broadcast) {
986 bat_dbg(DBG_BATMAN, bat_priv, "Drop packet: "
987 "ignoring all packets with broadcast source addr (sender: %pM"
988 ")\n", ethhdr->h_source);
989 return;
990 }
991
992 if (is_my_orig) {
993 unsigned long *word;
994 int offset;
995
996 orig_neigh_node = get_orig_node(bat_priv, ethhdr->h_source);
997 if (!orig_neigh_node)
998 return;
999
1000 /* neighbor has to indicate direct link and it has to
1001 * come via the corresponding interface */
1002 /* save packet seqno for bidirectional check */
1003 if (has_directlink_flag &&
1004 compare_eth(if_incoming->net_dev->dev_addr,
1005 batman_ogm_packet->orig)) {
1006 offset = if_incoming->if_num * NUM_WORDS;
1007
1008 spin_lock_bh(&orig_neigh_node->ogm_cnt_lock);
1009 word = &(orig_neigh_node->bcast_own[offset]);
1010 bit_mark(word,
1011 if_incoming_seqno -
1012 batman_ogm_packet->seqno - 2);
1013 orig_neigh_node->bcast_own_sum[if_incoming->if_num] =
1014 bit_packet_count(word);
1015 spin_unlock_bh(&orig_neigh_node->ogm_cnt_lock);
1016 }
1017
1018 bat_dbg(DBG_BATMAN, bat_priv, "Drop packet: "
1019 "originator packet from myself (via neighbor)\n");
1020 orig_node_free_ref(orig_neigh_node);
1021 return;
1022 }
1023
1024 if (is_my_oldorig) {
1025 bat_dbg(DBG_BATMAN, bat_priv,
1026 "Drop packet: ignoring all rebroadcast echos (sender: "
1027 "%pM)\n", ethhdr->h_source);
1028 return;
1029 }
1030
1031 orig_node = get_orig_node(bat_priv, batman_ogm_packet->orig);
1032 if (!orig_node)
1033 return;
1034
1035 is_duplicate = bat_ogm_update_seqnos(ethhdr, batman_ogm_packet,
1036 if_incoming);
1037
1038 if (is_duplicate == -1) {
1039 bat_dbg(DBG_BATMAN, bat_priv,
1040 "Drop packet: packet within seqno protection time "
1041 "(sender: %pM)\n", ethhdr->h_source);
1042 goto out;
1043 }
1044
1045 if (batman_ogm_packet->tq == 0) {
1046 bat_dbg(DBG_BATMAN, bat_priv,
1047 "Drop packet: originator packet with tq equal 0\n");
1048 goto out;
1049 }
1050
1051 router = orig_node_get_router(orig_node);
1052 if (router)
1053 router_router = orig_node_get_router(router->orig_node);
1054
1055 /* avoid temporary routing loops */
1056 if (router && router_router &&
1057 (compare_eth(router->addr, batman_ogm_packet->prev_sender)) &&
1058 !(compare_eth(batman_ogm_packet->orig,
1059 batman_ogm_packet->prev_sender)) &&
1060 (compare_eth(router->addr, router_router->addr))) {
1061 bat_dbg(DBG_BATMAN, bat_priv,
1062 "Drop packet: ignoring all rebroadcast packets that "
1063 "may make me loop (sender: %pM)\n", ethhdr->h_source);
1064 goto out;
1065 }
1066
1067 /* if sender is a direct neighbor the sender mac equals
1068 * originator mac */
1069 orig_neigh_node = (is_single_hop_neigh ?
1070 orig_node :
1071 get_orig_node(bat_priv, ethhdr->h_source));
1072 if (!orig_neigh_node)
1073 goto out;
1074
1075 orig_neigh_router = orig_node_get_router(orig_neigh_node);
1076
1077 /* drop packet if sender is not a direct neighbor and if we
1078 * don't route towards it */
1079 if (!is_single_hop_neigh && (!orig_neigh_router)) {
1080 bat_dbg(DBG_BATMAN, bat_priv,
1081 "Drop packet: OGM via unknown neighbor!\n");
1082 goto out_neigh;
1083 }
1084
1085 is_bidirectional = bat_ogm_calc_tq(orig_node, orig_neigh_node,
1086 batman_ogm_packet, if_incoming);
1087
1088 bonding_save_primary(orig_node, orig_neigh_node, batman_ogm_packet);
1089
1090 /* update ranking if it is not a duplicate or has the same
1091 * seqno and similar ttl as the non-duplicate */
1092 if (is_bidirectional &&
1093 (!is_duplicate ||
1094 ((orig_node->last_real_seqno == batman_ogm_packet->seqno) &&
Sven Eckelmann76543d12011-11-20 15:47:38 +01001095 (orig_node->last_ttl - 3 <= batman_ogm_packet->header.ttl))))
Marek Lindnerfc957272011-07-30 12:04:12 +02001096 bat_ogm_orig_update(bat_priv, orig_node, ethhdr,
1097 batman_ogm_packet, if_incoming,
1098 tt_buff, is_duplicate);
1099
1100 /* is single hop (direct) neighbor */
1101 if (is_single_hop_neigh) {
1102
1103 /* mark direct link on incoming interface */
Marek Lindnerb9dacc52011-08-03 09:09:30 +02001104 bat_ogm_forward(orig_node, ethhdr, batman_ogm_packet,
1105 1, if_incoming);
Marek Lindnerfc957272011-07-30 12:04:12 +02001106
1107 bat_dbg(DBG_BATMAN, bat_priv, "Forwarding packet: "
1108 "rebroadcast neighbor packet with direct link flag\n");
1109 goto out_neigh;
1110 }
1111
1112 /* multihop originator */
1113 if (!is_bidirectional) {
1114 bat_dbg(DBG_BATMAN, bat_priv,
1115 "Drop packet: not received via bidirectional link\n");
1116 goto out_neigh;
1117 }
1118
1119 if (is_duplicate) {
1120 bat_dbg(DBG_BATMAN, bat_priv,
1121 "Drop packet: duplicate packet received\n");
1122 goto out_neigh;
1123 }
1124
1125 bat_dbg(DBG_BATMAN, bat_priv,
1126 "Forwarding packet: rebroadcast originator packet\n");
Marek Lindnerb9dacc52011-08-03 09:09:30 +02001127 bat_ogm_forward(orig_node, ethhdr, batman_ogm_packet, 0, if_incoming);
Marek Lindnerfc957272011-07-30 12:04:12 +02001128
1129out_neigh:
1130 if ((orig_neigh_node) && (!is_single_hop_neigh))
1131 orig_node_free_ref(orig_neigh_node);
1132out:
1133 if (router)
1134 neigh_node_free_ref(router);
1135 if (router_router)
1136 neigh_node_free_ref(router_router);
1137 if (orig_neigh_router)
1138 neigh_node_free_ref(orig_neigh_router);
1139
1140 orig_node_free_ref(orig_node);
1141}
1142
1143void bat_ogm_receive(const struct ethhdr *ethhdr, unsigned char *packet_buff,
1144 int packet_len, struct hard_iface *if_incoming)
1145{
1146 struct batman_ogm_packet *batman_ogm_packet;
1147 int buff_pos = 0;
1148 unsigned char *tt_buff;
1149
1150 batman_ogm_packet = (struct batman_ogm_packet *)packet_buff;
1151
1152 /* unpack the aggregated packets and process them one by one */
1153 do {
1154 /* network to host order for our 32bit seqno and the
1155 orig_interval */
1156 batman_ogm_packet->seqno = ntohl(batman_ogm_packet->seqno);
1157 batman_ogm_packet->tt_crc = ntohs(batman_ogm_packet->tt_crc);
1158
1159 tt_buff = packet_buff + buff_pos + BATMAN_OGM_LEN;
1160
1161 bat_ogm_process(ethhdr, batman_ogm_packet,
1162 tt_buff, if_incoming);
1163
1164 buff_pos += BATMAN_OGM_LEN +
1165 tt_len(batman_ogm_packet->tt_num_changes);
1166
1167 batman_ogm_packet = (struct batman_ogm_packet *)
1168 (packet_buff + buff_pos);
1169 } while (bat_ogm_aggr_packet(buff_pos, packet_len,
1170 batman_ogm_packet->tt_num_changes));
1171}