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