]> bbs.cooldavid.org Git - net-next-2.6.git/blob - drivers/staging/batman-adv/routing.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ecryptfs...
[net-next-2.6.git] / drivers / staging / batman-adv / routing.c
1 /*
2  * Copyright (C) 2007-2010 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 "routing.h"
24 #include "send.h"
25 #include "hash.h"
26 #include "soft-interface.h"
27 #include "hard-interface.h"
28 #include "icmp_socket.h"
29 #include "translation-table.h"
30 #include "originator.h"
31 #include "types.h"
32 #include "ring_buffer.h"
33 #include "vis.h"
34 #include "aggregation.h"
35
36 static DECLARE_WAIT_QUEUE_HEAD(thread_wait);
37
38 void slide_own_bcast_window(struct batman_if *batman_if)
39 {
40         HASHIT(hashit);
41         struct orig_node *orig_node;
42         TYPE_OF_WORD *word;
43         unsigned long flags;
44
45         spin_lock_irqsave(&orig_hash_lock, flags);
46
47         while (hash_iterate(orig_hash, &hashit)) {
48                 orig_node = hashit.bucket->data;
49                 word = &(orig_node->bcast_own[batman_if->if_num * NUM_WORDS]);
50
51                 bit_get_packet(word, 1, 0);
52                 orig_node->bcast_own_sum[batman_if->if_num] =
53                         bit_packet_count(word);
54         }
55
56         spin_unlock_irqrestore(&orig_hash_lock, flags);
57 }
58
59 static void update_HNA(struct orig_node *orig_node,
60                        unsigned char *hna_buff, int hna_buff_len)
61 {
62         if ((hna_buff_len != orig_node->hna_buff_len) ||
63             ((hna_buff_len > 0) &&
64              (orig_node->hna_buff_len > 0) &&
65              (memcmp(orig_node->hna_buff, hna_buff, hna_buff_len) != 0))) {
66
67                 if (orig_node->hna_buff_len > 0)
68                         hna_global_del_orig(orig_node,
69                                             "originator changed hna");
70
71                 if ((hna_buff_len > 0) && (hna_buff != NULL))
72                         hna_global_add_orig(orig_node, hna_buff, hna_buff_len);
73         }
74 }
75
76 static void update_route(struct orig_node *orig_node,
77                          struct neigh_node *neigh_node,
78                          unsigned char *hna_buff, int hna_buff_len)
79 {
80         /* FIXME: each orig_node->batman_if will be attached to a softif */
81         struct bat_priv *bat_priv = netdev_priv(soft_device);
82
83         /* route deleted */
84         if ((orig_node->router != NULL) && (neigh_node == NULL)) {
85
86                 bat_dbg(DBG_ROUTES, bat_priv, "Deleting route towards: %pM\n",
87                         orig_node->orig);
88                 hna_global_del_orig(orig_node, "originator timed out");
89
90                 /* route added */
91         } else if ((orig_node->router == NULL) && (neigh_node != NULL)) {
92
93                 bat_dbg(DBG_ROUTES, bat_priv,
94                         "Adding route towards: %pM (via %pM)\n",
95                         orig_node->orig, neigh_node->addr);
96                 hna_global_add_orig(orig_node, hna_buff, hna_buff_len);
97
98                 /* route changed */
99         } else {
100                 bat_dbg(DBG_ROUTES, bat_priv,
101                         "Changing route towards: %pM "
102                         "(now via %pM - was via %pM)\n",
103                         orig_node->orig, neigh_node->addr,
104                         orig_node->router->addr);
105         }
106
107         orig_node->router = neigh_node;
108 }
109
110
111 void update_routes(struct orig_node *orig_node,
112                           struct neigh_node *neigh_node,
113                           unsigned char *hna_buff, int hna_buff_len)
114 {
115
116         if (orig_node == NULL)
117                 return;
118
119         if (orig_node->router != neigh_node)
120                 update_route(orig_node, neigh_node, hna_buff, hna_buff_len);
121         /* may be just HNA changed */
122         else
123                 update_HNA(orig_node, hna_buff, hna_buff_len);
124 }
125
126 static int is_bidirectional_neigh(struct orig_node *orig_node,
127                                 struct orig_node *orig_neigh_node,
128                                 struct batman_packet *batman_packet,
129                                 struct batman_if *if_incoming)
130 {
131         /* FIXME: each orig_node->batman_if will be attached to a softif */
132         struct bat_priv *bat_priv = netdev_priv(soft_device);
133         struct neigh_node *neigh_node = NULL, *tmp_neigh_node = NULL;
134         unsigned char total_count;
135
136         if (orig_node == orig_neigh_node) {
137                 list_for_each_entry(tmp_neigh_node,
138                                     &orig_node->neigh_list,
139                                     list) {
140
141                         if (compare_orig(tmp_neigh_node->addr,
142                                          orig_neigh_node->orig) &&
143                             (tmp_neigh_node->if_incoming == if_incoming))
144                                 neigh_node = tmp_neigh_node;
145                 }
146
147                 if (!neigh_node)
148                         neigh_node = create_neighbor(orig_node,
149                                                      orig_neigh_node,
150                                                      orig_neigh_node->orig,
151                                                      if_incoming);
152                 /* create_neighbor failed, return 0 */
153                 if (!neigh_node)
154                         return 0;
155
156                 neigh_node->last_valid = jiffies;
157         } else {
158                 /* find packet count of corresponding one hop neighbor */
159                 list_for_each_entry(tmp_neigh_node,
160                                     &orig_neigh_node->neigh_list, list) {
161
162                         if (compare_orig(tmp_neigh_node->addr,
163                                          orig_neigh_node->orig) &&
164                             (tmp_neigh_node->if_incoming == if_incoming))
165                                 neigh_node = tmp_neigh_node;
166                 }
167
168                 if (!neigh_node)
169                         neigh_node = create_neighbor(orig_neigh_node,
170                                                      orig_neigh_node,
171                                                      orig_neigh_node->orig,
172                                                      if_incoming);
173                 /* create_neighbor failed, return 0 */
174                 if (!neigh_node)
175                         return 0;
176         }
177
178         orig_node->last_valid = jiffies;
179
180         /* pay attention to not get a value bigger than 100 % */
181         total_count = (orig_neigh_node->bcast_own_sum[if_incoming->if_num] >
182                        neigh_node->real_packet_count ?
183                        neigh_node->real_packet_count :
184                        orig_neigh_node->bcast_own_sum[if_incoming->if_num]);
185
186         /* if we have too few packets (too less data) we set tq_own to zero */
187         /* if we receive too few packets it is not considered bidirectional */
188         if ((total_count < TQ_LOCAL_BIDRECT_SEND_MINIMUM) ||
189             (neigh_node->real_packet_count < TQ_LOCAL_BIDRECT_RECV_MINIMUM))
190                 orig_neigh_node->tq_own = 0;
191         else
192                 /* neigh_node->real_packet_count is never zero as we
193                  * only purge old information when getting new
194                  * information */
195                 orig_neigh_node->tq_own = (TQ_MAX_VALUE * total_count) /
196                         neigh_node->real_packet_count;
197
198         /*
199          * 1 - ((1-x) ** 3), normalized to TQ_MAX_VALUE this does
200          * affect the nearly-symmetric links only a little, but
201          * punishes asymmetric links more.  This will give a value
202          * between 0 and TQ_MAX_VALUE
203          */
204         orig_neigh_node->tq_asym_penalty =
205                 TQ_MAX_VALUE -
206                 (TQ_MAX_VALUE *
207                  (TQ_LOCAL_WINDOW_SIZE - neigh_node->real_packet_count) *
208                  (TQ_LOCAL_WINDOW_SIZE - neigh_node->real_packet_count) *
209                  (TQ_LOCAL_WINDOW_SIZE - neigh_node->real_packet_count)) /
210                 (TQ_LOCAL_WINDOW_SIZE *
211                  TQ_LOCAL_WINDOW_SIZE *
212                  TQ_LOCAL_WINDOW_SIZE);
213
214         batman_packet->tq = ((batman_packet->tq *
215                               orig_neigh_node->tq_own *
216                               orig_neigh_node->tq_asym_penalty) /
217                              (TQ_MAX_VALUE * TQ_MAX_VALUE));
218
219         bat_dbg(DBG_BATMAN, bat_priv,
220                 "bidirectional: "
221                 "orig = %-15pM neigh = %-15pM => own_bcast = %2i, "
222                 "real recv = %2i, local tq: %3i, asym_penalty: %3i, "
223                 "total tq: %3i\n",
224                 orig_node->orig, orig_neigh_node->orig, total_count,
225                 neigh_node->real_packet_count, orig_neigh_node->tq_own,
226                 orig_neigh_node->tq_asym_penalty, batman_packet->tq);
227
228         /* if link has the minimum required transmission quality
229          * consider it bidirectional */
230         if (batman_packet->tq >= TQ_TOTAL_BIDRECT_LIMIT)
231                 return 1;
232
233         return 0;
234 }
235
236 static void update_orig(struct orig_node *orig_node, struct ethhdr *ethhdr,
237                         struct batman_packet *batman_packet,
238                         struct batman_if *if_incoming,
239                         unsigned char *hna_buff, int hna_buff_len,
240                         char is_duplicate)
241 {
242         /* FIXME: get bat_priv */
243         struct bat_priv *bat_priv = netdev_priv(soft_device);
244         struct neigh_node *neigh_node = NULL, *tmp_neigh_node = NULL;
245         int tmp_hna_buff_len;
246
247         bat_dbg(DBG_BATMAN, bat_priv, "update_originator(): "
248                 "Searching and updating originator entry of received packet\n");
249
250         list_for_each_entry(tmp_neigh_node, &orig_node->neigh_list, list) {
251                 if (compare_orig(tmp_neigh_node->addr, ethhdr->h_source) &&
252                     (tmp_neigh_node->if_incoming == if_incoming)) {
253                         neigh_node = tmp_neigh_node;
254                         continue;
255                 }
256
257                 if (is_duplicate)
258                         continue;
259
260                 ring_buffer_set(tmp_neigh_node->tq_recv,
261                                 &tmp_neigh_node->tq_index, 0);
262                 tmp_neigh_node->tq_avg =
263                         ring_buffer_avg(tmp_neigh_node->tq_recv);
264         }
265
266         if (!neigh_node) {
267                 struct orig_node *orig_tmp;
268
269                 orig_tmp = get_orig_node(ethhdr->h_source);
270                 if (!orig_tmp)
271                         return;
272
273                 neigh_node = create_neighbor(orig_node,
274                                              orig_tmp,
275                                              ethhdr->h_source, if_incoming);
276                 if (!neigh_node)
277                         return;
278         } else
279                 bat_dbg(DBG_BATMAN, bat_priv,
280                         "Updating existing last-hop neighbor of originator\n");
281
282         orig_node->flags = batman_packet->flags;
283         neigh_node->last_valid = jiffies;
284
285         ring_buffer_set(neigh_node->tq_recv,
286                         &neigh_node->tq_index,
287                         batman_packet->tq);
288         neigh_node->tq_avg = ring_buffer_avg(neigh_node->tq_recv);
289
290         if (!is_duplicate) {
291                 orig_node->last_ttl = batman_packet->ttl;
292                 neigh_node->last_ttl = batman_packet->ttl;
293         }
294
295         tmp_hna_buff_len = (hna_buff_len > batman_packet->num_hna * ETH_ALEN ?
296                             batman_packet->num_hna * ETH_ALEN : hna_buff_len);
297
298         /* if this neighbor already is our next hop there is nothing
299          * to change */
300         if (orig_node->router == neigh_node)
301                 goto update_hna;
302
303         /* if this neighbor does not offer a better TQ we won't consider it */
304         if ((orig_node->router) &&
305             (orig_node->router->tq_avg > neigh_node->tq_avg))
306                 goto update_hna;
307
308         /* if the TQ is the same and the link not more symetric we
309          * won't consider it either */
310         if ((orig_node->router) &&
311              ((neigh_node->tq_avg == orig_node->router->tq_avg) &&
312              (orig_node->router->orig_node->bcast_own_sum[if_incoming->if_num]
313               >= neigh_node->orig_node->bcast_own_sum[if_incoming->if_num])))
314                 goto update_hna;
315
316         update_routes(orig_node, neigh_node, hna_buff, tmp_hna_buff_len);
317         return;
318
319 update_hna:
320         update_routes(orig_node, orig_node->router, hna_buff, tmp_hna_buff_len);
321 }
322
323 /* checks whether the host restarted and is in the protection time.
324  * returns:
325  *  0 if the packet is to be accepted
326  *  1 if the packet is to be ignored.
327  */
328 static int window_protected(int32_t seq_num_diff,
329                                 unsigned long *last_reset)
330 {
331         /* FIXME: each orig_node->batman_if will be attached to a softif */
332         struct bat_priv *bat_priv = netdev_priv(soft_device);
333
334         if ((seq_num_diff <= -TQ_LOCAL_WINDOW_SIZE)
335                 || (seq_num_diff >= EXPECTED_SEQNO_RANGE)) {
336                 if (time_after(jiffies, *last_reset +
337                         msecs_to_jiffies(RESET_PROTECTION_MS))) {
338
339                         *last_reset = jiffies;
340                         bat_dbg(DBG_BATMAN, bat_priv,
341                                 "old packet received, start protection\n");
342
343                         return 0;
344                 } else
345                         return 1;
346         }
347         return 0;
348 }
349
350 /* processes a batman packet for all interfaces, adjusts the sequence number and
351  * finds out whether it is a duplicate.
352  * returns:
353  *   1 the packet is a duplicate
354  *   0 the packet has not yet been received
355  *  -1 the packet is old and has been received while the seqno window
356  *     was protected. Caller should drop it.
357  */
358 static char count_real_packets(struct ethhdr *ethhdr,
359                                struct batman_packet *batman_packet,
360                                struct batman_if *if_incoming)
361 {
362         /* FIXME: each orig_node->batman_if will be attached to a softif */
363         struct bat_priv *bat_priv = netdev_priv(soft_device);
364         struct orig_node *orig_node;
365         struct neigh_node *tmp_neigh_node;
366         char is_duplicate = 0;
367         int32_t seq_diff;
368         int need_update = 0;
369         int set_mark;
370
371         orig_node = get_orig_node(batman_packet->orig);
372         if (orig_node == NULL)
373                 return 0;
374
375         seq_diff = batman_packet->seqno - orig_node->last_real_seqno;
376
377         /* signalize caller that the packet is to be dropped. */
378         if (window_protected(seq_diff, &orig_node->batman_seqno_reset))
379                 return -1;
380
381         list_for_each_entry(tmp_neigh_node, &orig_node->neigh_list, list) {
382
383                 is_duplicate |= get_bit_status(tmp_neigh_node->real_bits,
384                                                orig_node->last_real_seqno,
385                                                batman_packet->seqno);
386
387                 if (compare_orig(tmp_neigh_node->addr, ethhdr->h_source) &&
388                     (tmp_neigh_node->if_incoming == if_incoming))
389                         set_mark = 1;
390                 else
391                         set_mark = 0;
392
393                 /* if the window moved, set the update flag. */
394                 need_update |= bit_get_packet(tmp_neigh_node->real_bits,
395                                                 seq_diff, set_mark);
396
397                 tmp_neigh_node->real_packet_count =
398                         bit_packet_count(tmp_neigh_node->real_bits);
399         }
400
401         if (need_update) {
402                 bat_dbg(DBG_BATMAN, bat_priv,
403                         "updating last_seqno: old %d, new %d\n",
404                         orig_node->last_real_seqno, batman_packet->seqno);
405                 orig_node->last_real_seqno = batman_packet->seqno;
406         }
407
408         return is_duplicate;
409 }
410
411 /* copy primary address for bonding */
412 static void mark_bonding_address(struct bat_priv *bat_priv,
413                                  struct orig_node *orig_node,
414                                  struct orig_node *orig_neigh_node,
415                                  struct batman_packet *batman_packet)
416
417 {
418         if (batman_packet->flags & PRIMARIES_FIRST_HOP)
419                 memcpy(orig_neigh_node->primary_addr,
420                        orig_node->orig, ETH_ALEN);
421
422         return;
423 }
424
425 /* mark possible bond.candidates in the neighbor list */
426 void update_bonding_candidates(struct bat_priv *bat_priv,
427                                struct orig_node *orig_node)
428 {
429         int candidates;
430         int interference_candidate;
431         int best_tq;
432         struct neigh_node *tmp_neigh_node, *tmp_neigh_node2;
433         struct neigh_node *first_candidate, *last_candidate;
434
435         /* update the candidates for this originator */
436         if (!orig_node->router) {
437                 orig_node->bond.candidates = 0;
438                 return;
439         }
440
441         best_tq = orig_node->router->tq_avg;
442
443         /* update bond.candidates */
444
445         candidates = 0;
446
447         /* mark other nodes which also received "PRIMARIES FIRST HOP" packets
448          * as "bonding partner" */
449
450         /* first, zero the list */
451         list_for_each_entry(tmp_neigh_node, &orig_node->neigh_list, list) {
452                 tmp_neigh_node->next_bond_candidate = NULL;
453         }
454
455         first_candidate = NULL;
456         last_candidate = NULL;
457         list_for_each_entry(tmp_neigh_node, &orig_node->neigh_list, list) {
458
459                 /* only consider if it has the same primary address ...  */
460                 if (memcmp(orig_node->orig,
461                                 tmp_neigh_node->orig_node->primary_addr,
462                                 ETH_ALEN) != 0)
463                         continue;
464
465                 /* ... and is good enough to be considered */
466                 if (tmp_neigh_node->tq_avg < best_tq - BONDING_TQ_THRESHOLD)
467                         continue;
468
469                 /* check if we have another candidate with the same
470                  * mac address or interface. If we do, we won't
471                  * select this candidate because of possible interference. */
472
473                 interference_candidate = 0;
474                 list_for_each_entry(tmp_neigh_node2,
475                                 &orig_node->neigh_list, list) {
476
477                         if (tmp_neigh_node2 == tmp_neigh_node)
478                                 continue;
479
480                         /* we only care if the other candidate is even
481                          * considered as candidate. */
482                         if (tmp_neigh_node2->next_bond_candidate == NULL)
483                                 continue;
484
485
486                         if ((tmp_neigh_node->if_incoming ==
487                                 tmp_neigh_node2->if_incoming)
488                                 || (memcmp(tmp_neigh_node->addr,
489                                 tmp_neigh_node2->addr, ETH_ALEN) == 0)) {
490
491                                 interference_candidate = 1;
492                                 break;
493                         }
494                 }
495                 /* don't care further if it is an interference candidate */
496                 if (interference_candidate)
497                         continue;
498
499                 if (first_candidate == NULL) {
500                         first_candidate = tmp_neigh_node;
501                         tmp_neigh_node->next_bond_candidate = first_candidate;
502                 } else
503                         tmp_neigh_node->next_bond_candidate = last_candidate;
504
505                 last_candidate = tmp_neigh_node;
506
507                 candidates++;
508         }
509
510         if (candidates > 0) {
511                 first_candidate->next_bond_candidate = last_candidate;
512                 orig_node->bond.selected = first_candidate;
513         }
514
515         orig_node->bond.candidates = candidates;
516 }
517
518 void receive_bat_packet(struct ethhdr *ethhdr,
519                                 struct batman_packet *batman_packet,
520                                 unsigned char *hna_buff, int hna_buff_len,
521                                 struct batman_if *if_incoming)
522 {
523         /* FIXME: each orig_node->batman_if will be attached to a softif */
524         struct bat_priv *bat_priv = netdev_priv(soft_device);
525         struct batman_if *batman_if;
526         struct orig_node *orig_neigh_node, *orig_node;
527         char has_directlink_flag;
528         char is_my_addr = 0, is_my_orig = 0, is_my_oldorig = 0;
529         char is_broadcast = 0, is_bidirectional, is_single_hop_neigh;
530         char is_duplicate;
531         uint32_t if_incoming_seqno;
532
533         /* Silently drop when the batman packet is actually not a
534          * correct packet.
535          *
536          * This might happen if a packet is padded (e.g. Ethernet has a
537          * minimum frame length of 64 byte) and the aggregation interprets
538          * it as an additional length.
539          *
540          * TODO: A more sane solution would be to have a bit in the
541          * batman_packet to detect whether the packet is the last
542          * packet in an aggregation.  Here we expect that the padding
543          * is always zero (or not 0x01)
544          */
545         if (batman_packet->packet_type != BAT_PACKET)
546                 return;
547
548         /* could be changed by schedule_own_packet() */
549         if_incoming_seqno = atomic_read(&if_incoming->seqno);
550
551         has_directlink_flag = (batman_packet->flags & DIRECTLINK ? 1 : 0);
552
553         is_single_hop_neigh = (compare_orig(ethhdr->h_source,
554                                             batman_packet->orig) ? 1 : 0);
555
556         bat_dbg(DBG_BATMAN, bat_priv,
557                 "Received BATMAN packet via NB: %pM, IF: %s [%s] "
558                 "(from OG: %pM, via prev OG: %pM, seqno %d, tq %d, "
559                 "TTL %d, V %d, IDF %d)\n",
560                 ethhdr->h_source, if_incoming->dev, if_incoming->addr_str,
561                 batman_packet->orig, batman_packet->prev_sender,
562                 batman_packet->seqno, batman_packet->tq, batman_packet->ttl,
563                 batman_packet->version, has_directlink_flag);
564
565         list_for_each_entry_rcu(batman_if, &if_list, list) {
566                 if (batman_if->if_status != IF_ACTIVE)
567                         continue;
568
569                 if (compare_orig(ethhdr->h_source,
570                                  batman_if->net_dev->dev_addr))
571                         is_my_addr = 1;
572
573                 if (compare_orig(batman_packet->orig,
574                                  batman_if->net_dev->dev_addr))
575                         is_my_orig = 1;
576
577                 if (compare_orig(batman_packet->prev_sender,
578                                  batman_if->net_dev->dev_addr))
579                         is_my_oldorig = 1;
580
581                 if (compare_orig(ethhdr->h_source, broadcast_addr))
582                         is_broadcast = 1;
583         }
584
585         if (batman_packet->version != COMPAT_VERSION) {
586                 bat_dbg(DBG_BATMAN, bat_priv,
587                         "Drop packet: incompatible batman version (%i)\n",
588                         batman_packet->version);
589                 return;
590         }
591
592         if (is_my_addr) {
593                 bat_dbg(DBG_BATMAN, bat_priv,
594                         "Drop packet: received my own broadcast (sender: %pM"
595                         ")\n",
596                         ethhdr->h_source);
597                 return;
598         }
599
600         if (is_broadcast) {
601                 bat_dbg(DBG_BATMAN, bat_priv, "Drop packet: "
602                 "ignoring all packets with broadcast source addr (sender: %pM"
603                 ")\n", ethhdr->h_source);
604                 return;
605         }
606
607         if (is_my_orig) {
608                 TYPE_OF_WORD *word;
609                 int offset;
610
611                 orig_neigh_node = get_orig_node(ethhdr->h_source);
612
613                 if (!orig_neigh_node)
614                         return;
615
616                 /* neighbor has to indicate direct link and it has to
617                  * come via the corresponding interface */
618                 /* if received seqno equals last send seqno save new
619                  * seqno for bidirectional check */
620                 if (has_directlink_flag &&
621                     compare_orig(if_incoming->net_dev->dev_addr,
622                                  batman_packet->orig) &&
623                     (batman_packet->seqno - if_incoming_seqno + 2 == 0)) {
624                         offset = if_incoming->if_num * NUM_WORDS;
625                         word = &(orig_neigh_node->bcast_own[offset]);
626                         bit_mark(word, 0);
627                         orig_neigh_node->bcast_own_sum[if_incoming->if_num] =
628                                 bit_packet_count(word);
629                 }
630
631                 bat_dbg(DBG_BATMAN, bat_priv, "Drop packet: "
632                         "originator packet from myself (via neighbor)\n");
633                 return;
634         }
635
636         if (is_my_oldorig) {
637                 bat_dbg(DBG_BATMAN, bat_priv,
638                         "Drop packet: ignoring all rebroadcast echos (sender: "
639                         "%pM)\n", ethhdr->h_source);
640                 return;
641         }
642
643         orig_node = get_orig_node(batman_packet->orig);
644         if (orig_node == NULL)
645                 return;
646
647         is_duplicate = count_real_packets(ethhdr, batman_packet, if_incoming);
648
649         if (is_duplicate == -1) {
650                 bat_dbg(DBG_BATMAN, bat_priv,
651                         "Drop packet: packet within seqno protection time "
652                         "(sender: %pM)\n", ethhdr->h_source);
653                 return;
654         }
655
656         if (batman_packet->tq == 0) {
657                 bat_dbg(DBG_BATMAN, bat_priv,
658                         "Drop packet: originator packet with tq equal 0\n");
659                 return;
660         }
661
662         /* avoid temporary routing loops */
663         if ((orig_node->router) &&
664             (orig_node->router->orig_node->router) &&
665             (compare_orig(orig_node->router->addr,
666                           batman_packet->prev_sender)) &&
667             !(compare_orig(batman_packet->orig, batman_packet->prev_sender)) &&
668             (compare_orig(orig_node->router->addr,
669                           orig_node->router->orig_node->router->addr))) {
670                 bat_dbg(DBG_BATMAN, bat_priv,
671                         "Drop packet: ignoring all rebroadcast packets that "
672                         "may make me loop (sender: %pM)\n", ethhdr->h_source);
673                 return;
674         }
675
676         /* if sender is a direct neighbor the sender mac equals
677          * originator mac */
678         orig_neigh_node = (is_single_hop_neigh ?
679                            orig_node : get_orig_node(ethhdr->h_source));
680         if (orig_neigh_node == NULL)
681                 return;
682
683         /* drop packet if sender is not a direct neighbor and if we
684          * don't route towards it */
685         if (!is_single_hop_neigh &&
686             (orig_neigh_node->router == NULL)) {
687                 bat_dbg(DBG_BATMAN, bat_priv,
688                         "Drop packet: OGM via unknown neighbor!\n");
689                 return;
690         }
691
692         is_bidirectional = is_bidirectional_neigh(orig_node, orig_neigh_node,
693                                                 batman_packet, if_incoming);
694
695         /* update ranking if it is not a duplicate or has the same
696          * seqno and similar ttl as the non-duplicate */
697         if (is_bidirectional &&
698             (!is_duplicate ||
699              ((orig_node->last_real_seqno == batman_packet->seqno) &&
700               (orig_node->last_ttl - 3 <= batman_packet->ttl))))
701                 update_orig(orig_node, ethhdr, batman_packet,
702                             if_incoming, hna_buff, hna_buff_len, is_duplicate);
703
704         mark_bonding_address(bat_priv, orig_node,
705                              orig_neigh_node, batman_packet);
706         update_bonding_candidates(bat_priv, orig_node);
707
708         /* is single hop (direct) neighbor */
709         if (is_single_hop_neigh) {
710
711                 /* mark direct link on incoming interface */
712                 schedule_forward_packet(orig_node, ethhdr, batman_packet,
713                                         1, hna_buff_len, if_incoming);
714
715                 bat_dbg(DBG_BATMAN, bat_priv, "Forwarding packet: "
716                         "rebroadcast neighbor packet with direct link flag\n");
717                 return;
718         }
719
720         /* multihop originator */
721         if (!is_bidirectional) {
722                 bat_dbg(DBG_BATMAN, bat_priv,
723                         "Drop packet: not received via bidirectional link\n");
724                 return;
725         }
726
727         if (is_duplicate) {
728                 bat_dbg(DBG_BATMAN, bat_priv,
729                         "Drop packet: duplicate packet received\n");
730                 return;
731         }
732
733         bat_dbg(DBG_BATMAN, bat_priv,
734                 "Forwarding packet: rebroadcast originator packet\n");
735         schedule_forward_packet(orig_node, ethhdr, batman_packet,
736                                 0, hna_buff_len, if_incoming);
737 }
738
739 int recv_bat_packet(struct sk_buff *skb,
740                                 struct batman_if *batman_if)
741 {
742         struct ethhdr *ethhdr;
743         unsigned long flags;
744         struct sk_buff *skb_old;
745
746         /* drop packet if it has not necessary minimum size */
747         if (skb_headlen(skb) < sizeof(struct batman_packet))
748                 return NET_RX_DROP;
749
750         ethhdr = (struct ethhdr *)skb_mac_header(skb);
751
752         /* packet with broadcast indication but unicast recipient */
753         if (!is_bcast(ethhdr->h_dest))
754                 return NET_RX_DROP;
755
756         /* packet with broadcast sender address */
757         if (is_bcast(ethhdr->h_source))
758                 return NET_RX_DROP;
759
760         /* TODO: we use headlen instead of "length", because
761          * only this data is paged in. */
762
763         /* create a copy of the skb, if needed, to modify it. */
764         if (!skb_clone_writable(skb, skb_headlen(skb))) {
765                 skb_old = skb;
766                 skb = skb_copy(skb, GFP_ATOMIC);
767                 if (!skb)
768                         return NET_RX_DROP;
769                 ethhdr = (struct ethhdr *)skb_mac_header(skb);
770                 kfree_skb(skb_old);
771         }
772
773         spin_lock_irqsave(&orig_hash_lock, flags);
774         receive_aggr_bat_packet(ethhdr,
775                                 skb->data,
776                                 skb_headlen(skb),
777                                 batman_if);
778         spin_unlock_irqrestore(&orig_hash_lock, flags);
779
780         kfree_skb(skb);
781         return NET_RX_SUCCESS;
782 }
783
784 static int recv_my_icmp_packet(struct sk_buff *skb, size_t icmp_len)
785 {
786         /* FIXME: each batman_if will be attached to a softif */
787         struct bat_priv *bat_priv = netdev_priv(soft_device);
788         struct orig_node *orig_node;
789         struct icmp_packet_rr *icmp_packet;
790         struct ethhdr *ethhdr;
791         struct sk_buff *skb_old;
792         struct batman_if *batman_if;
793         int ret;
794         unsigned long flags;
795         uint8_t dstaddr[ETH_ALEN];
796
797         icmp_packet = (struct icmp_packet_rr *)skb->data;
798         ethhdr = (struct ethhdr *)skb_mac_header(skb);
799
800         /* add data to device queue */
801         if (icmp_packet->msg_type != ECHO_REQUEST) {
802                 bat_socket_receive_packet(icmp_packet, icmp_len);
803                 return NET_RX_DROP;
804         }
805
806         if (!bat_priv->primary_if)
807                 return NET_RX_DROP;
808
809         /* answer echo request (ping) */
810         /* get routing information */
811         spin_lock_irqsave(&orig_hash_lock, flags);
812         orig_node = ((struct orig_node *)hash_find(orig_hash,
813                                                    icmp_packet->orig));
814         ret = NET_RX_DROP;
815
816         if ((orig_node != NULL) &&
817             (orig_node->router != NULL)) {
818
819                 /* don't lock while sending the packets ... we therefore
820                  * copy the required data before sending */
821                 batman_if = orig_node->router->if_incoming;
822                 memcpy(dstaddr, orig_node->router->addr, ETH_ALEN);
823                 spin_unlock_irqrestore(&orig_hash_lock, flags);
824
825                 /* create a copy of the skb, if needed, to modify it. */
826                 skb_old = NULL;
827                 if (!skb_clone_writable(skb, icmp_len)) {
828                         skb_old = skb;
829                         skb = skb_copy(skb, GFP_ATOMIC);
830                         if (!skb)
831                                 return NET_RX_DROP;
832                         icmp_packet = (struct icmp_packet_rr *)skb->data;
833                         ethhdr = (struct ethhdr *)skb_mac_header(skb);
834                         kfree_skb(skb_old);
835                 }
836
837                 memcpy(icmp_packet->dst, icmp_packet->orig, ETH_ALEN);
838                 memcpy(icmp_packet->orig,
839                        bat_priv->primary_if->net_dev->dev_addr, ETH_ALEN);
840                 icmp_packet->msg_type = ECHO_REPLY;
841                 icmp_packet->ttl = TTL;
842
843                 send_skb_packet(skb, batman_if, dstaddr);
844                 ret = NET_RX_SUCCESS;
845
846         } else
847                 spin_unlock_irqrestore(&orig_hash_lock, flags);
848
849         return ret;
850 }
851
852 static int recv_icmp_ttl_exceeded(struct sk_buff *skb, size_t icmp_len)
853 {
854         /* FIXME: each batman_if will be attached to a softif */
855         struct bat_priv *bat_priv = netdev_priv(soft_device);
856         struct orig_node *orig_node;
857         struct icmp_packet *icmp_packet;
858         struct ethhdr *ethhdr;
859         struct sk_buff *skb_old;
860         struct batman_if *batman_if;
861         int ret;
862         unsigned long flags;
863         uint8_t dstaddr[ETH_ALEN];
864
865         icmp_packet = (struct icmp_packet *)skb->data;
866         ethhdr = (struct ethhdr *)skb_mac_header(skb);
867
868         /* send TTL exceeded if packet is an echo request (traceroute) */
869         if (icmp_packet->msg_type != ECHO_REQUEST) {
870                 pr_warning("Warning - can't forward icmp packet from %pM to "
871                            "%pM: ttl exceeded\n", icmp_packet->orig,
872                            icmp_packet->dst);
873                 return NET_RX_DROP;
874         }
875
876         if (!bat_priv->primary_if)
877                 return NET_RX_DROP;
878
879         /* get routing information */
880         spin_lock_irqsave(&orig_hash_lock, flags);
881         orig_node = ((struct orig_node *)
882                      hash_find(orig_hash, icmp_packet->orig));
883         ret = NET_RX_DROP;
884
885         if ((orig_node != NULL) &&
886             (orig_node->router != NULL)) {
887
888                 /* don't lock while sending the packets ... we therefore
889                  * copy the required data before sending */
890                 batman_if = orig_node->router->if_incoming;
891                 memcpy(dstaddr, orig_node->router->addr, ETH_ALEN);
892                 spin_unlock_irqrestore(&orig_hash_lock, flags);
893
894                 /* create a copy of the skb, if needed, to modify it. */
895                 if (!skb_clone_writable(skb, icmp_len)) {
896                         skb_old = skb;
897                         skb = skb_copy(skb, GFP_ATOMIC);
898                         if (!skb)
899                                 return NET_RX_DROP;
900                         icmp_packet = (struct icmp_packet *) skb->data;
901                         ethhdr = (struct ethhdr *)skb_mac_header(skb);
902                         kfree_skb(skb_old);
903                 }
904
905                 memcpy(icmp_packet->dst, icmp_packet->orig, ETH_ALEN);
906                 memcpy(icmp_packet->orig,
907                        bat_priv->primary_if->net_dev->dev_addr, ETH_ALEN);
908                 icmp_packet->msg_type = TTL_EXCEEDED;
909                 icmp_packet->ttl = TTL;
910
911                 send_skb_packet(skb, batman_if, dstaddr);
912                 ret = NET_RX_SUCCESS;
913
914         } else
915                 spin_unlock_irqrestore(&orig_hash_lock, flags);
916
917         return ret;
918 }
919
920
921 int recv_icmp_packet(struct sk_buff *skb)
922 {
923         struct icmp_packet_rr *icmp_packet;
924         struct ethhdr *ethhdr;
925         struct orig_node *orig_node;
926         struct sk_buff *skb_old;
927         struct batman_if *batman_if;
928         int hdr_size = sizeof(struct icmp_packet);
929         int ret;
930         unsigned long flags;
931         uint8_t dstaddr[ETH_ALEN];
932
933         /**
934          * we truncate all incoming icmp packets if they don't match our size
935          */
936         if (skb_headlen(skb) >= sizeof(struct icmp_packet_rr))
937                 hdr_size = sizeof(struct icmp_packet_rr);
938
939         /* drop packet if it has not necessary minimum size */
940         if (skb_headlen(skb) < hdr_size)
941                 return NET_RX_DROP;
942
943         ethhdr = (struct ethhdr *)skb_mac_header(skb);
944
945         /* packet with unicast indication but broadcast recipient */
946         if (is_bcast(ethhdr->h_dest))
947                 return NET_RX_DROP;
948
949         /* packet with broadcast sender address */
950         if (is_bcast(ethhdr->h_source))
951                 return NET_RX_DROP;
952
953         /* not for me */
954         if (!is_my_mac(ethhdr->h_dest))
955                 return NET_RX_DROP;
956
957         icmp_packet = (struct icmp_packet_rr *)skb->data;
958
959         /* add record route information if not full */
960         if ((hdr_size == sizeof(struct icmp_packet_rr)) &&
961             (icmp_packet->rr_cur < BAT_RR_LEN)) {
962                 memcpy(&(icmp_packet->rr[icmp_packet->rr_cur]),
963                         ethhdr->h_dest, ETH_ALEN);
964                 icmp_packet->rr_cur++;
965         }
966
967         /* packet for me */
968         if (is_my_mac(icmp_packet->dst))
969                 return recv_my_icmp_packet(skb, hdr_size);
970
971         /* TTL exceeded */
972         if (icmp_packet->ttl < 2)
973                 return recv_icmp_ttl_exceeded(skb, hdr_size);
974
975         ret = NET_RX_DROP;
976
977         /* get routing information */
978         spin_lock_irqsave(&orig_hash_lock, flags);
979         orig_node = ((struct orig_node *)
980                      hash_find(orig_hash, icmp_packet->dst));
981
982         if ((orig_node != NULL) &&
983             (orig_node->router != NULL)) {
984
985                 /* don't lock while sending the packets ... we therefore
986                  * copy the required data before sending */
987                 batman_if = orig_node->router->if_incoming;
988                 memcpy(dstaddr, orig_node->router->addr, ETH_ALEN);
989                 spin_unlock_irqrestore(&orig_hash_lock, flags);
990
991                 /* create a copy of the skb, if needed, to modify it. */
992                 if (!skb_clone_writable(skb, hdr_size)) {
993                         skb_old = skb;
994                         skb = skb_copy(skb, GFP_ATOMIC);
995                         if (!skb)
996                                 return NET_RX_DROP;
997                         icmp_packet = (struct icmp_packet_rr *)skb->data;
998                         ethhdr = (struct ethhdr *)skb_mac_header(skb);
999                         kfree_skb(skb_old);
1000                 }
1001
1002                 /* decrement ttl */
1003                 icmp_packet->ttl--;
1004
1005                 /* route it */
1006                 send_skb_packet(skb, batman_if, dstaddr);
1007                 ret = NET_RX_SUCCESS;
1008
1009         } else
1010                 spin_unlock_irqrestore(&orig_hash_lock, flags);
1011
1012         return ret;
1013 }
1014
1015 /* find a suitable router for this originator, and use
1016  * bonding if possible. */
1017 struct neigh_node *find_router(struct orig_node *orig_node,
1018                 struct batman_if *recv_if)
1019 {
1020         /* FIXME: each orig_node->batman_if will be attached to a softif */
1021         struct bat_priv *bat_priv = netdev_priv(soft_device);
1022         struct orig_node *primary_orig_node;
1023         struct orig_node *router_orig;
1024         struct neigh_node *router, *first_candidate, *best_router;
1025         static uint8_t zero_mac[ETH_ALEN] = {0, 0, 0, 0, 0, 0};
1026         int bonding_enabled;
1027
1028         if (!orig_node)
1029                 return NULL;
1030
1031         if (!orig_node->router)
1032                 return NULL;
1033
1034         /* without bonding, the first node should
1035          * always choose the default router. */
1036
1037         bonding_enabled = atomic_read(&bat_priv->bonding_enabled);
1038         if (!bonding_enabled && (recv_if == NULL))
1039                         return orig_node->router;
1040
1041         router_orig = orig_node->router->orig_node;
1042
1043         /* if we have something in the primary_addr, we can search
1044          * for a potential bonding candidate. */
1045         if (memcmp(router_orig->primary_addr, zero_mac, ETH_ALEN) == 0)
1046                 return orig_node->router;
1047
1048         /* find the orig_node which has the primary interface. might
1049          * even be the same as our router_orig in many cases */
1050
1051         if (memcmp(router_orig->primary_addr,
1052                                 router_orig->orig, ETH_ALEN) == 0) {
1053                 primary_orig_node = router_orig;
1054         } else {
1055                 primary_orig_node = hash_find(orig_hash,
1056                                                 router_orig->primary_addr);
1057                 if (!primary_orig_node)
1058                         return orig_node->router;
1059         }
1060
1061         /* with less than 2 candidates, we can't do any
1062          * bonding and prefer the original router. */
1063
1064         if (primary_orig_node->bond.candidates < 2)
1065                 return orig_node->router;
1066
1067
1068         /* all nodes between should choose a candidate which
1069          * is is not on the interface where the packet came
1070          * in. */
1071         first_candidate = primary_orig_node->bond.selected;
1072         router = first_candidate;
1073
1074         if (bonding_enabled) {
1075                 /* in the bonding case, send the packets in a round
1076                  * robin fashion over the remaining interfaces. */
1077                 do {
1078                         /* recv_if == NULL on the first node. */
1079                         if (router->if_incoming != recv_if)
1080                                 break;
1081
1082                         router = router->next_bond_candidate;
1083                 } while (router != first_candidate);
1084
1085                 primary_orig_node->bond.selected = router->next_bond_candidate;
1086
1087         } else {
1088                 /* if bonding is disabled, use the best of the
1089                  * remaining candidates which are not using
1090                  * this interface. */
1091                 best_router = first_candidate;
1092
1093                 do {
1094                         /* recv_if == NULL on the first node. */
1095                         if ((router->if_incoming != recv_if) &&
1096                                 (router->tq_avg > best_router->tq_avg))
1097                                         best_router = router;
1098
1099                         router = router->next_bond_candidate;
1100                 } while (router != first_candidate);
1101
1102                 router = best_router;
1103         }
1104
1105         return router;
1106 }
1107
1108 int recv_unicast_packet(struct sk_buff *skb, struct batman_if *recv_if)
1109 {
1110         struct unicast_packet *unicast_packet;
1111         struct orig_node *orig_node;
1112         struct neigh_node *router;
1113         struct ethhdr *ethhdr;
1114         struct batman_if *batman_if;
1115         struct sk_buff *skb_old;
1116         uint8_t dstaddr[ETH_ALEN];
1117         int hdr_size = sizeof(struct unicast_packet);
1118         unsigned long flags;
1119
1120         /* drop packet if it has not necessary minimum size */
1121         if (skb_headlen(skb) < hdr_size)
1122                 return NET_RX_DROP;
1123
1124         ethhdr = (struct ethhdr *) skb_mac_header(skb);
1125
1126         /* packet with unicast indication but broadcast recipient */
1127         if (is_bcast(ethhdr->h_dest))
1128                 return NET_RX_DROP;
1129
1130         /* packet with broadcast sender address */
1131         if (is_bcast(ethhdr->h_source))
1132                 return NET_RX_DROP;
1133
1134         /* not for me */
1135         if (!is_my_mac(ethhdr->h_dest))
1136                 return NET_RX_DROP;
1137
1138         unicast_packet = (struct unicast_packet *) skb->data;
1139
1140         /* packet for me */
1141         if (is_my_mac(unicast_packet->dest)) {
1142                 interface_rx(skb, hdr_size);
1143                 return NET_RX_SUCCESS;
1144         }
1145
1146         /* TTL exceeded */
1147         if (unicast_packet->ttl < 2) {
1148                 pr_warning("Warning - can't forward unicast packet from %pM to "
1149                            "%pM: ttl exceeded\n", ethhdr->h_source,
1150                            unicast_packet->dest);
1151                 return NET_RX_DROP;
1152         }
1153
1154         /* get routing information */
1155         spin_lock_irqsave(&orig_hash_lock, flags);
1156         orig_node = ((struct orig_node *)
1157                      hash_find(orig_hash, unicast_packet->dest));
1158
1159         router = find_router(orig_node, recv_if);
1160
1161         if (!router) {
1162                 spin_unlock_irqrestore(&orig_hash_lock, flags);
1163                 return NET_RX_DROP;
1164         }
1165
1166         /* don't lock while sending the packets ... we therefore
1167          * copy the required data before sending */
1168
1169         batman_if = router->if_incoming;
1170         memcpy(dstaddr, router->addr, ETH_ALEN);
1171
1172         spin_unlock_irqrestore(&orig_hash_lock, flags);
1173
1174         /* create a copy of the skb, if needed, to modify it. */
1175         if (!skb_clone_writable(skb, sizeof(struct unicast_packet))) {
1176                 skb_old = skb;
1177                 skb = skb_copy(skb, GFP_ATOMIC);
1178                 if (!skb)
1179                         return NET_RX_DROP;
1180                 unicast_packet = (struct unicast_packet *) skb->data;
1181                 ethhdr = (struct ethhdr *)skb_mac_header(skb);
1182                 kfree_skb(skb_old);
1183         }
1184
1185         /* decrement ttl */
1186         unicast_packet->ttl--;
1187
1188         /* route it */
1189         send_skb_packet(skb, batman_if, dstaddr);
1190
1191         return NET_RX_SUCCESS;
1192 }
1193
1194 int recv_bcast_packet(struct sk_buff *skb)
1195 {
1196         struct orig_node *orig_node;
1197         struct bcast_packet *bcast_packet;
1198         struct ethhdr *ethhdr;
1199         int hdr_size = sizeof(struct bcast_packet);
1200         int32_t seq_diff;
1201         unsigned long flags;
1202
1203         /* drop packet if it has not necessary minimum size */
1204         if (skb_headlen(skb) < hdr_size)
1205                 return NET_RX_DROP;
1206
1207         ethhdr = (struct ethhdr *)skb_mac_header(skb);
1208
1209         /* packet with broadcast indication but unicast recipient */
1210         if (!is_bcast(ethhdr->h_dest))
1211                 return NET_RX_DROP;
1212
1213         /* packet with broadcast sender address */
1214         if (is_bcast(ethhdr->h_source))
1215                 return NET_RX_DROP;
1216
1217         /* ignore broadcasts sent by myself */
1218         if (is_my_mac(ethhdr->h_source))
1219                 return NET_RX_DROP;
1220
1221         bcast_packet = (struct bcast_packet *)skb->data;
1222
1223         /* ignore broadcasts originated by myself */
1224         if (is_my_mac(bcast_packet->orig))
1225                 return NET_RX_DROP;
1226
1227         if (bcast_packet->ttl < 2)
1228                 return NET_RX_DROP;
1229
1230         spin_lock_irqsave(&orig_hash_lock, flags);
1231         orig_node = ((struct orig_node *)
1232                      hash_find(orig_hash, bcast_packet->orig));
1233
1234         if (orig_node == NULL) {
1235                 spin_unlock_irqrestore(&orig_hash_lock, flags);
1236                 return NET_RX_DROP;
1237         }
1238
1239         /* check whether the packet is a duplicate */
1240         if (get_bit_status(orig_node->bcast_bits,
1241                            orig_node->last_bcast_seqno,
1242                            ntohl(bcast_packet->seqno))) {
1243                 spin_unlock_irqrestore(&orig_hash_lock, flags);
1244                 return NET_RX_DROP;
1245         }
1246
1247         seq_diff = ntohl(bcast_packet->seqno) - orig_node->last_bcast_seqno;
1248
1249         /* check whether the packet is old and the host just restarted. */
1250         if (window_protected(seq_diff, &orig_node->bcast_seqno_reset)) {
1251                 spin_unlock_irqrestore(&orig_hash_lock, flags);
1252                 return NET_RX_DROP;
1253         }
1254
1255         /* mark broadcast in flood history, update window position
1256          * if required. */
1257         if (bit_get_packet(orig_node->bcast_bits, seq_diff, 1))
1258                 orig_node->last_bcast_seqno = ntohl(bcast_packet->seqno);
1259
1260         spin_unlock_irqrestore(&orig_hash_lock, flags);
1261         /* rebroadcast packet */
1262         add_bcast_packet_to_list(skb);
1263
1264         /* broadcast for me */
1265         interface_rx(skb, hdr_size);
1266
1267         return NET_RX_SUCCESS;
1268 }
1269
1270 int recv_vis_packet(struct sk_buff *skb)
1271 {
1272         struct vis_packet *vis_packet;
1273         struct ethhdr *ethhdr;
1274         struct bat_priv *bat_priv;
1275         int hdr_size = sizeof(struct vis_packet);
1276
1277         if (skb_headlen(skb) < hdr_size)
1278                 return NET_RX_DROP;
1279
1280         vis_packet = (struct vis_packet *) skb->data;
1281         ethhdr = (struct ethhdr *)skb_mac_header(skb);
1282
1283         /* not for me */
1284         if (!is_my_mac(ethhdr->h_dest))
1285                 return NET_RX_DROP;
1286
1287         /* ignore own packets */
1288         if (is_my_mac(vis_packet->vis_orig))
1289                 return NET_RX_DROP;
1290
1291         if (is_my_mac(vis_packet->sender_orig))
1292                 return NET_RX_DROP;
1293
1294         /* FIXME: each batman_if will be attached to a softif */
1295         bat_priv = netdev_priv(soft_device);
1296
1297         switch (vis_packet->vis_type) {
1298         case VIS_TYPE_SERVER_SYNC:
1299                 /* TODO: handle fragmented skbs properly */
1300                 receive_server_sync_packet(bat_priv, vis_packet,
1301                                            skb_headlen(skb));
1302                 break;
1303
1304         case VIS_TYPE_CLIENT_UPDATE:
1305                 /* TODO: handle fragmented skbs properly */
1306                 receive_client_update_packet(bat_priv, vis_packet,
1307                                              skb_headlen(skb));
1308                 break;
1309
1310         default:        /* ignore unknown packet */
1311                 break;
1312         }
1313
1314         /* We take a copy of the data in the packet, so we should
1315            always free the skbuf. */
1316         return NET_RX_DROP;
1317 }