aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv/bat_iv_ogm.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/batman-adv/bat_iv_ogm.c')
-rw-r--r--net/batman-adv/bat_iv_ogm.c490
1 files changed, 251 insertions, 239 deletions
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 94859d45ed6e..ca6466574c46 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -28,11 +28,11 @@
28#include "send.h" 28#include "send.h"
29#include "bat_algo.h" 29#include "bat_algo.h"
30 30
31static struct neigh_node *bat_iv_ogm_neigh_new(struct hard_iface *hard_iface, 31static struct neigh_node *batadv_iv_ogm_neigh_new(struct hard_iface *hard_iface,
32 const uint8_t *neigh_addr, 32 const uint8_t *neigh_addr,
33 struct orig_node *orig_node, 33 struct orig_node *orig_node,
34 struct orig_node *orig_neigh, 34 struct orig_node *orig_neigh,
35 __be32 seqno) 35 __be32 seqno)
36{ 36{
37 struct neigh_node *neigh_node; 37 struct neigh_node *neigh_node;
38 38
@@ -54,7 +54,7 @@ out:
54 return neigh_node; 54 return neigh_node;
55} 55}
56 56
57static int bat_iv_ogm_iface_enable(struct hard_iface *hard_iface) 57static int batadv_iv_ogm_iface_enable(struct hard_iface *hard_iface)
58{ 58{
59 struct batman_ogm_packet *batman_ogm_packet; 59 struct batman_ogm_packet *batman_ogm_packet;
60 uint32_t random_seqno; 60 uint32_t random_seqno;
@@ -85,13 +85,13 @@ out:
85 return res; 85 return res;
86} 86}
87 87
88static void bat_iv_ogm_iface_disable(struct hard_iface *hard_iface) 88static void batadv_iv_ogm_iface_disable(struct hard_iface *hard_iface)
89{ 89{
90 kfree(hard_iface->packet_buff); 90 kfree(hard_iface->packet_buff);
91 hard_iface->packet_buff = NULL; 91 hard_iface->packet_buff = NULL;
92} 92}
93 93
94static void bat_iv_ogm_iface_update_mac(struct hard_iface *hard_iface) 94static void batadv_iv_ogm_iface_update_mac(struct hard_iface *hard_iface)
95{ 95{
96 struct batman_ogm_packet *batman_ogm_packet; 96 struct batman_ogm_packet *batman_ogm_packet;
97 97
@@ -102,7 +102,7 @@ static void bat_iv_ogm_iface_update_mac(struct hard_iface *hard_iface)
102 hard_iface->net_dev->dev_addr, ETH_ALEN); 102 hard_iface->net_dev->dev_addr, ETH_ALEN);
103} 103}
104 104
105static void bat_iv_ogm_primary_iface_set(struct hard_iface *hard_iface) 105static void batadv_iv_ogm_primary_iface_set(struct hard_iface *hard_iface)
106{ 106{
107 struct batman_ogm_packet *batman_ogm_packet; 107 struct batman_ogm_packet *batman_ogm_packet;
108 108
@@ -112,7 +112,8 @@ static void bat_iv_ogm_primary_iface_set(struct hard_iface *hard_iface)
112} 112}
113 113
114/* when do we schedule our own ogm to be sent */ 114/* when do we schedule our own ogm to be sent */
115static unsigned long bat_iv_ogm_emit_send_time(const struct bat_priv *bat_priv) 115static unsigned long
116batadv_iv_ogm_emit_send_time(const struct bat_priv *bat_priv)
116{ 117{
117 return jiffies + msecs_to_jiffies( 118 return jiffies + msecs_to_jiffies(
118 atomic_read(&bat_priv->orig_interval) - 119 atomic_read(&bat_priv->orig_interval) -
@@ -120,21 +121,21 @@ static unsigned long bat_iv_ogm_emit_send_time(const struct bat_priv *bat_priv)
120} 121}
121 122
122/* when do we schedule a ogm packet to be sent */ 123/* when do we schedule a ogm packet to be sent */
123static unsigned long bat_iv_ogm_fwd_send_time(void) 124static unsigned long batadv_iv_ogm_fwd_send_time(void)
124{ 125{
125 return jiffies + msecs_to_jiffies(random32() % (JITTER/2)); 126 return jiffies + msecs_to_jiffies(random32() % (JITTER/2));
126} 127}
127 128
128/* apply hop penalty for a normal link */ 129/* apply hop penalty for a normal link */
129static uint8_t hop_penalty(uint8_t tq, const struct bat_priv *bat_priv) 130static uint8_t batadv_hop_penalty(uint8_t tq, const struct bat_priv *bat_priv)
130{ 131{
131 int hop_penalty = atomic_read(&bat_priv->hop_penalty); 132 int hop_penalty = atomic_read(&bat_priv->hop_penalty);
132 return (tq * (TQ_MAX_VALUE - hop_penalty)) / (TQ_MAX_VALUE); 133 return (tq * (TQ_MAX_VALUE - hop_penalty)) / (TQ_MAX_VALUE);
133} 134}
134 135
135/* is there another aggregated packet here? */ 136/* is there another aggregated packet here? */
136static int bat_iv_ogm_aggr_packet(int buff_pos, int packet_len, 137static int batadv_iv_ogm_aggr_packet(int buff_pos, int packet_len,
137 int tt_num_changes) 138 int tt_num_changes)
138{ 139{
139 int next_buff_pos = 0; 140 int next_buff_pos = 0;
140 141
@@ -146,7 +147,7 @@ static int bat_iv_ogm_aggr_packet(int buff_pos, int packet_len,
146} 147}
147 148
148/* send a batman ogm to a given interface */ 149/* send a batman ogm to a given interface */
149static void bat_iv_ogm_send_to_if(struct forw_packet *forw_packet, 150static void batadv_iv_ogm_send_to_if(struct forw_packet *forw_packet,
150 struct hard_iface *hard_iface) 151 struct hard_iface *hard_iface)
151{ 152{
152 struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface); 153 struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
@@ -164,8 +165,8 @@ static void bat_iv_ogm_send_to_if(struct forw_packet *forw_packet,
164 batman_ogm_packet = (struct batman_ogm_packet *)forw_packet->skb->data; 165 batman_ogm_packet = (struct batman_ogm_packet *)forw_packet->skb->data;
165 166
166 /* adjust all flags and log packets */ 167 /* adjust all flags and log packets */
167 while (bat_iv_ogm_aggr_packet(buff_pos, forw_packet->packet_len, 168 while (batadv_iv_ogm_aggr_packet(buff_pos, forw_packet->packet_len,
168 batman_ogm_packet->tt_num_changes)) { 169 batman_ogm_packet->tt_num_changes)) {
169 170
170 /* we might have aggregated direct link packets with an 171 /* we might have aggregated direct link packets with an
171 * ordinary base packet 172 * ordinary base packet
@@ -179,16 +180,16 @@ static void bat_iv_ogm_send_to_if(struct forw_packet *forw_packet,
179 fwd_str = (packet_num > 0 ? "Forwarding" : (forw_packet->own ? 180 fwd_str = (packet_num > 0 ? "Forwarding" : (forw_packet->own ?
180 "Sending own" : 181 "Sending own" :
181 "Forwarding")); 182 "Forwarding"));
182 bat_dbg(DBG_BATMAN, bat_priv, 183 batadv_dbg(DBG_BATMAN, bat_priv,
183 "%s %spacket (originator %pM, seqno %u, TQ %d, TTL %d, IDF %s, ttvn %d) on interface %s [%pM]\n", 184 "%s %spacket (originator %pM, seqno %u, TQ %d, TTL %d, IDF %s, ttvn %d) on interface %s [%pM]\n",
184 fwd_str, (packet_num > 0 ? "aggregated " : ""), 185 fwd_str, (packet_num > 0 ? "aggregated " : ""),
185 batman_ogm_packet->orig, 186 batman_ogm_packet->orig,
186 ntohl(batman_ogm_packet->seqno), 187 ntohl(batman_ogm_packet->seqno),
187 batman_ogm_packet->tq, batman_ogm_packet->header.ttl, 188 batman_ogm_packet->tq, batman_ogm_packet->header.ttl,
188 (batman_ogm_packet->flags & DIRECTLINK ? 189 (batman_ogm_packet->flags & DIRECTLINK ?
189 "on" : "off"), 190 "on" : "off"),
190 batman_ogm_packet->ttvn, hard_iface->net_dev->name, 191 batman_ogm_packet->ttvn, hard_iface->net_dev->name,
191 hard_iface->net_dev->dev_addr); 192 hard_iface->net_dev->dev_addr);
192 193
193 buff_pos += BATMAN_OGM_HLEN; 194 buff_pos += BATMAN_OGM_HLEN;
194 buff_pos += batadv_tt_len(batman_ogm_packet->tt_num_changes); 195 buff_pos += batadv_tt_len(batman_ogm_packet->tt_num_changes);
@@ -208,7 +209,7 @@ static void bat_iv_ogm_send_to_if(struct forw_packet *forw_packet,
208} 209}
209 210
210/* send a batman ogm packet */ 211/* send a batman ogm packet */
211static void bat_iv_ogm_emit(struct forw_packet *forw_packet) 212static void batadv_iv_ogm_emit(struct forw_packet *forw_packet)
212{ 213{
213 struct hard_iface *hard_iface; 214 struct hard_iface *hard_iface;
214 struct net_device *soft_iface; 215 struct net_device *soft_iface;
@@ -232,7 +233,7 @@ static void bat_iv_ogm_emit(struct forw_packet *forw_packet)
232 if (forw_packet->if_incoming->if_status != IF_ACTIVE) 233 if (forw_packet->if_incoming->if_status != IF_ACTIVE)
233 goto out; 234 goto out;
234 235
235 primary_if = primary_if_get_selected(bat_priv); 236 primary_if = batadv_primary_if_get_selected(bat_priv);
236 if (!primary_if) 237 if (!primary_if)
237 goto out; 238 goto out;
238 239
@@ -243,14 +244,14 @@ static void bat_iv_ogm_emit(struct forw_packet *forw_packet)
243 (forw_packet->own && (forw_packet->if_incoming != primary_if))) { 244 (forw_packet->own && (forw_packet->if_incoming != primary_if))) {
244 245
245 /* FIXME: what about aggregated packets ? */ 246 /* FIXME: what about aggregated packets ? */
246 bat_dbg(DBG_BATMAN, bat_priv, 247 batadv_dbg(DBG_BATMAN, bat_priv,
247 "%s packet (originator %pM, seqno %u, TTL %d) on interface %s [%pM]\n", 248 "%s packet (originator %pM, seqno %u, TTL %d) on interface %s [%pM]\n",
248 (forw_packet->own ? "Sending own" : "Forwarding"), 249 (forw_packet->own ? "Sending own" : "Forwarding"),
249 batman_ogm_packet->orig, 250 batman_ogm_packet->orig,
250 ntohl(batman_ogm_packet->seqno), 251 ntohl(batman_ogm_packet->seqno),
251 batman_ogm_packet->header.ttl, 252 batman_ogm_packet->header.ttl,
252 forw_packet->if_incoming->net_dev->name, 253 forw_packet->if_incoming->net_dev->name,
253 forw_packet->if_incoming->net_dev->dev_addr); 254 forw_packet->if_incoming->net_dev->dev_addr);
254 255
255 /* skb is only used once and than forw_packet is free'd */ 256 /* skb is only used once and than forw_packet is free'd */
256 batadv_send_skb_packet(forw_packet->skb, 257 batadv_send_skb_packet(forw_packet->skb,
@@ -267,23 +268,23 @@ static void bat_iv_ogm_emit(struct forw_packet *forw_packet)
267 if (hard_iface->soft_iface != soft_iface) 268 if (hard_iface->soft_iface != soft_iface)
268 continue; 269 continue;
269 270
270 bat_iv_ogm_send_to_if(forw_packet, hard_iface); 271 batadv_iv_ogm_send_to_if(forw_packet, hard_iface);
271 } 272 }
272 rcu_read_unlock(); 273 rcu_read_unlock();
273 274
274out: 275out:
275 if (primary_if) 276 if (primary_if)
276 hardif_free_ref(primary_if); 277 batadv_hardif_free_ref(primary_if);
277} 278}
278 279
279/* return true if new_packet can be aggregated with forw_packet */ 280/* return true if new_packet can be aggregated with forw_packet */
280static bool bat_iv_ogm_can_aggregate(const struct batman_ogm_packet 281static bool
281 *new_batman_ogm_packet, 282batadv_iv_ogm_can_aggregate(const struct batman_ogm_packet *new_bat_ogm_packet,
282 struct bat_priv *bat_priv, 283 struct bat_priv *bat_priv,
283 int packet_len, unsigned long send_time, 284 int packet_len, unsigned long send_time,
284 bool directlink, 285 bool directlink,
285 const struct hard_iface *if_incoming, 286 const struct hard_iface *if_incoming,
286 const struct forw_packet *forw_packet) 287 const struct forw_packet *forw_packet)
287{ 288{
288 struct batman_ogm_packet *batman_ogm_packet; 289 struct batman_ogm_packet *batman_ogm_packet;
289 int aggregated_bytes = forw_packet->packet_len + packet_len; 290 int aggregated_bytes = forw_packet->packet_len + packet_len;
@@ -311,7 +312,7 @@ static bool bat_iv_ogm_can_aggregate(const struct batman_ogm_packet
311 * a "global" packet as well as the base 312 * a "global" packet as well as the base
312 * packet 313 * packet
313 */ 314 */
314 primary_if = primary_if_get_selected(bat_priv); 315 primary_if = batadv_primary_if_get_selected(bat_priv);
315 if (!primary_if) 316 if (!primary_if)
316 goto out; 317 goto out;
317 318
@@ -335,7 +336,7 @@ static bool bat_iv_ogm_can_aggregate(const struct batman_ogm_packet
335 * interface only - we still can aggregate 336 * interface only - we still can aggregate
336 */ 337 */
337 if ((directlink) && 338 if ((directlink) &&
338 (new_batman_ogm_packet->header.ttl == 1) && 339 (new_bat_ogm_packet->header.ttl == 1) &&
339 (forw_packet->if_incoming == if_incoming) && 340 (forw_packet->if_incoming == if_incoming) &&
340 341
341 /* packets from direct neighbors or 342 /* packets from direct neighbors or
@@ -352,16 +353,16 @@ static bool bat_iv_ogm_can_aggregate(const struct batman_ogm_packet
352 353
353out: 354out:
354 if (primary_if) 355 if (primary_if)
355 hardif_free_ref(primary_if); 356 batadv_hardif_free_ref(primary_if);
356 return res; 357 return res;
357} 358}
358 359
359/* create a new aggregated packet and add this packet to it */ 360/* create a new aggregated packet and add this packet to it */
360static void bat_iv_ogm_aggregate_new(const unsigned char *packet_buff, 361static void batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff,
361 int packet_len, unsigned long send_time, 362 int packet_len, unsigned long send_time,
362 bool direct_link, 363 bool direct_link,
363 struct hard_iface *if_incoming, 364 struct hard_iface *if_incoming,
364 int own_packet) 365 int own_packet)
365{ 366{
366 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface); 367 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
367 struct forw_packet *forw_packet_aggr; 368 struct forw_packet *forw_packet_aggr;
@@ -373,8 +374,8 @@ static void bat_iv_ogm_aggregate_new(const unsigned char *packet_buff,
373 /* own packet should always be scheduled */ 374 /* own packet should always be scheduled */
374 if (!own_packet) { 375 if (!own_packet) {
375 if (!atomic_dec_not_zero(&bat_priv->batman_queue_left)) { 376 if (!atomic_dec_not_zero(&bat_priv->batman_queue_left)) {
376 bat_dbg(DBG_BATMAN, bat_priv, 377 batadv_dbg(DBG_BATMAN, bat_priv,
377 "batman packet queue full\n"); 378 "batman packet queue full\n");
378 goto out; 379 goto out;
379 } 380 }
380 } 381 }
@@ -431,13 +432,13 @@ static void bat_iv_ogm_aggregate_new(const unsigned char *packet_buff,
431 432
432 return; 433 return;
433out: 434out:
434 hardif_free_ref(if_incoming); 435 batadv_hardif_free_ref(if_incoming);
435} 436}
436 437
437/* aggregate a new packet into the existing ogm packet */ 438/* aggregate a new packet into the existing ogm packet */
438static void bat_iv_ogm_aggregate(struct forw_packet *forw_packet_aggr, 439static void batadv_iv_ogm_aggregate(struct forw_packet *forw_packet_aggr,
439 const unsigned char *packet_buff, 440 const unsigned char *packet_buff,
440 int packet_len, bool direct_link) 441 int packet_len, bool direct_link)
441{ 442{
442 unsigned char *skb_buff; 443 unsigned char *skb_buff;
443 444
@@ -452,10 +453,11 @@ static void bat_iv_ogm_aggregate(struct forw_packet *forw_packet_aggr,
452 (1 << forw_packet_aggr->num_packets); 453 (1 << forw_packet_aggr->num_packets);
453} 454}
454 455
455static void bat_iv_ogm_queue_add(struct bat_priv *bat_priv, 456static void batadv_iv_ogm_queue_add(struct bat_priv *bat_priv,
456 unsigned char *packet_buff, 457 unsigned char *packet_buff,
457 int packet_len, struct hard_iface *if_incoming, 458 int packet_len,
458 int own_packet, unsigned long send_time) 459 struct hard_iface *if_incoming,
460 int own_packet, unsigned long send_time)
459{ 461{
460 /* _aggr -> pointer to the packet we want to aggregate with 462 /* _aggr -> pointer to the packet we want to aggregate with
461 * _pos -> pointer to the position in the queue 463 * _pos -> pointer to the position in the queue
@@ -474,11 +476,11 @@ static void bat_iv_ogm_queue_add(struct bat_priv *bat_priv,
474 if ((atomic_read(&bat_priv->aggregated_ogms)) && (!own_packet)) { 476 if ((atomic_read(&bat_priv->aggregated_ogms)) && (!own_packet)) {
475 hlist_for_each_entry(forw_packet_pos, tmp_node, 477 hlist_for_each_entry(forw_packet_pos, tmp_node,
476 &bat_priv->forw_bat_list, list) { 478 &bat_priv->forw_bat_list, list) {
477 if (bat_iv_ogm_can_aggregate(batman_ogm_packet, 479 if (batadv_iv_ogm_can_aggregate(batman_ogm_packet,
478 bat_priv, packet_len, 480 bat_priv, packet_len,
479 send_time, direct_link, 481 send_time, direct_link,
480 if_incoming, 482 if_incoming,
481 forw_packet_pos)) { 483 forw_packet_pos)) {
482 forw_packet_aggr = forw_packet_pos; 484 forw_packet_aggr = forw_packet_pos;
483 break; 485 break;
484 } 486 }
@@ -500,28 +502,28 @@ static void bat_iv_ogm_queue_add(struct bat_priv *bat_priv,
500 (atomic_read(&bat_priv->aggregated_ogms))) 502 (atomic_read(&bat_priv->aggregated_ogms)))
501 send_time += msecs_to_jiffies(MAX_AGGREGATION_MS); 503 send_time += msecs_to_jiffies(MAX_AGGREGATION_MS);
502 504
503 bat_iv_ogm_aggregate_new(packet_buff, packet_len, 505 batadv_iv_ogm_aggregate_new(packet_buff, packet_len,
504 send_time, direct_link, 506 send_time, direct_link,
505 if_incoming, own_packet); 507 if_incoming, own_packet);
506 } else { 508 } else {
507 bat_iv_ogm_aggregate(forw_packet_aggr, packet_buff, 509 batadv_iv_ogm_aggregate(forw_packet_aggr, packet_buff,
508 packet_len, direct_link); 510 packet_len, direct_link);
509 spin_unlock_bh(&bat_priv->forw_bat_list_lock); 511 spin_unlock_bh(&bat_priv->forw_bat_list_lock);
510 } 512 }
511} 513}
512 514
513static void bat_iv_ogm_forward(struct orig_node *orig_node, 515static void batadv_iv_ogm_forward(struct orig_node *orig_node,
514 const struct ethhdr *ethhdr, 516 const struct ethhdr *ethhdr,
515 struct batman_ogm_packet *batman_ogm_packet, 517 struct batman_ogm_packet *batman_ogm_packet,
516 bool is_single_hop_neigh, 518 bool is_single_hop_neigh,
517 bool is_from_best_next_hop, 519 bool is_from_best_next_hop,
518 struct hard_iface *if_incoming) 520 struct hard_iface *if_incoming)
519{ 521{
520 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface); 522 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
521 uint8_t tt_num_changes; 523 uint8_t tt_num_changes;
522 524
523 if (batman_ogm_packet->header.ttl <= 1) { 525 if (batman_ogm_packet->header.ttl <= 1) {
524 bat_dbg(DBG_BATMAN, bat_priv, "ttl exceeded\n"); 526 batadv_dbg(DBG_BATMAN, bat_priv, "ttl exceeded\n");
525 return; 527 return;
526 } 528 }
527 529
@@ -544,11 +546,12 @@ static void bat_iv_ogm_forward(struct orig_node *orig_node,
544 memcpy(batman_ogm_packet->prev_sender, ethhdr->h_source, ETH_ALEN); 546 memcpy(batman_ogm_packet->prev_sender, ethhdr->h_source, ETH_ALEN);
545 547
546 /* apply hop penalty */ 548 /* apply hop penalty */
547 batman_ogm_packet->tq = hop_penalty(batman_ogm_packet->tq, bat_priv); 549 batman_ogm_packet->tq = batadv_hop_penalty(batman_ogm_packet->tq,
550 bat_priv);
548 551
549 bat_dbg(DBG_BATMAN, bat_priv, 552 batadv_dbg(DBG_BATMAN, bat_priv,
550 "Forwarding packet: tq: %i, ttl: %i\n", 553 "Forwarding packet: tq: %i, ttl: %i\n",
551 batman_ogm_packet->tq, batman_ogm_packet->header.ttl); 554 batman_ogm_packet->tq, batman_ogm_packet->header.ttl);
552 555
553 /* switch of primaries first hop flag when forwarding */ 556 /* switch of primaries first hop flag when forwarding */
554 batman_ogm_packet->flags &= ~PRIMARIES_FIRST_HOP; 557 batman_ogm_packet->flags &= ~PRIMARIES_FIRST_HOP;
@@ -557,12 +560,12 @@ static void bat_iv_ogm_forward(struct orig_node *orig_node,
557 else 560 else
558 batman_ogm_packet->flags &= ~DIRECTLINK; 561 batman_ogm_packet->flags &= ~DIRECTLINK;
559 562
560 bat_iv_ogm_queue_add(bat_priv, (unsigned char *)batman_ogm_packet, 563 batadv_iv_ogm_queue_add(bat_priv, (unsigned char *)batman_ogm_packet,
561 BATMAN_OGM_HLEN + batadv_tt_len(tt_num_changes), 564 BATMAN_OGM_HLEN + batadv_tt_len(tt_num_changes),
562 if_incoming, 0, bat_iv_ogm_fwd_send_time()); 565 if_incoming, 0, batadv_iv_ogm_fwd_send_time());
563} 566}
564 567
565static void bat_iv_ogm_schedule(struct hard_iface *hard_iface) 568static void batadv_iv_ogm_schedule(struct hard_iface *hard_iface)
566{ 569{
567 struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface); 570 struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
568 struct batman_ogm_packet *batman_ogm_packet; 571 struct batman_ogm_packet *batman_ogm_packet;
@@ -570,7 +573,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface)
570 int vis_server, tt_num_changes = 0; 573 int vis_server, tt_num_changes = 0;
571 574
572 vis_server = atomic_read(&bat_priv->vis_mode); 575 vis_server = atomic_read(&bat_priv->vis_mode);
573 primary_if = primary_if_get_selected(bat_priv); 576 primary_if = batadv_primary_if_get_selected(bat_priv);
574 577
575 if (hard_iface == primary_if) 578 if (hard_iface == primary_if)
576 tt_num_changes = batadv_tt_append_diff(bat_priv, 579 tt_num_changes = batadv_tt_append_diff(bat_priv,
@@ -603,38 +606,40 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface)
603 batman_ogm_packet->gw_flags = NO_FLAGS; 606 batman_ogm_packet->gw_flags = NO_FLAGS;
604 607
605 batadv_slide_own_bcast_window(hard_iface); 608 batadv_slide_own_bcast_window(hard_iface);
606 bat_iv_ogm_queue_add(bat_priv, hard_iface->packet_buff, 609 batadv_iv_ogm_queue_add(bat_priv, hard_iface->packet_buff,
607 hard_iface->packet_len, hard_iface, 1, 610 hard_iface->packet_len, hard_iface, 1,
608 bat_iv_ogm_emit_send_time(bat_priv)); 611 batadv_iv_ogm_emit_send_time(bat_priv));
609 612
610 if (primary_if) 613 if (primary_if)
611 hardif_free_ref(primary_if); 614 batadv_hardif_free_ref(primary_if);
612} 615}
613 616
614static void bat_iv_ogm_orig_update(struct bat_priv *bat_priv, 617static void
615 struct orig_node *orig_node, 618batadv_iv_ogm_orig_update(struct bat_priv *bat_priv,
616 const struct ethhdr *ethhdr, 619 struct orig_node *orig_node,
617 const struct batman_ogm_packet 620 const struct ethhdr *ethhdr,
618 *batman_ogm_packet, 621 const struct batman_ogm_packet *batman_ogm_packet,
619 struct hard_iface *if_incoming, 622 struct hard_iface *if_incoming,
620 const unsigned char *tt_buff, 623 const unsigned char *tt_buff,
621 int is_duplicate) 624 int is_duplicate)
622{ 625{
623 struct neigh_node *neigh_node = NULL, *tmp_neigh_node = NULL; 626 struct neigh_node *neigh_node = NULL, *tmp_neigh_node = NULL;
624 struct neigh_node *router = NULL; 627 struct neigh_node *router = NULL;
625 struct orig_node *orig_node_tmp; 628 struct orig_node *orig_node_tmp;
626 struct hlist_node *node; 629 struct hlist_node *node;
627 uint8_t bcast_own_sum_orig, bcast_own_sum_neigh; 630 uint8_t bcast_own_sum_orig, bcast_own_sum_neigh;
631 uint8_t *neigh_addr;
628 632
629 bat_dbg(DBG_BATMAN, bat_priv, 633 batadv_dbg(DBG_BATMAN, bat_priv,
630 "update_originator(): Searching and updating originator entry of received packet\n"); 634 "update_originator(): Searching and updating originator entry of received packet\n");
631 635
632 rcu_read_lock(); 636 rcu_read_lock();
633 hlist_for_each_entry_rcu(tmp_neigh_node, node, 637 hlist_for_each_entry_rcu(tmp_neigh_node, node,
634 &orig_node->neigh_list, list) { 638 &orig_node->neigh_list, list) {
635 if (compare_eth(tmp_neigh_node->addr, ethhdr->h_source) && 639 neigh_addr = tmp_neigh_node->addr;
636 (tmp_neigh_node->if_incoming == if_incoming) && 640 if (batadv_compare_eth(neigh_addr, ethhdr->h_source) &&
637 atomic_inc_not_zero(&tmp_neigh_node->refcount)) { 641 tmp_neigh_node->if_incoming == if_incoming &&
642 atomic_inc_not_zero(&tmp_neigh_node->refcount)) {
638 if (neigh_node) 643 if (neigh_node)
639 batadv_neigh_node_free_ref(neigh_node); 644 batadv_neigh_node_free_ref(neigh_node);
640 neigh_node = tmp_neigh_node; 645 neigh_node = tmp_neigh_node;
@@ -659,16 +664,17 @@ static void bat_iv_ogm_orig_update(struct bat_priv *bat_priv,
659 if (!orig_tmp) 664 if (!orig_tmp)
660 goto unlock; 665 goto unlock;
661 666
662 neigh_node = bat_iv_ogm_neigh_new(if_incoming, ethhdr->h_source, 667 neigh_node = batadv_iv_ogm_neigh_new(if_incoming,
663 orig_node, orig_tmp, 668 ethhdr->h_source,
664 batman_ogm_packet->seqno); 669 orig_node, orig_tmp,
670 batman_ogm_packet->seqno);
665 671
666 batadv_orig_node_free_ref(orig_tmp); 672 batadv_orig_node_free_ref(orig_tmp);
667 if (!neigh_node) 673 if (!neigh_node)
668 goto unlock; 674 goto unlock;
669 } else 675 } else
670 bat_dbg(DBG_BATMAN, bat_priv, 676 batadv_dbg(DBG_BATMAN, bat_priv,
671 "Updating existing last-hop neighbor of originator\n"); 677 "Updating existing last-hop neighbor of originator\n");
672 678
673 rcu_read_unlock(); 679 rcu_read_unlock();
674 680
@@ -757,10 +763,10 @@ out:
757 batadv_neigh_node_free_ref(router); 763 batadv_neigh_node_free_ref(router);
758} 764}
759 765
760static int bat_iv_ogm_calc_tq(struct orig_node *orig_node, 766static int batadv_iv_ogm_calc_tq(struct orig_node *orig_node,
761 struct orig_node *orig_neigh_node, 767 struct orig_node *orig_neigh_node,
762 struct batman_ogm_packet *batman_ogm_packet, 768 struct batman_ogm_packet *batman_ogm_packet,
763 struct hard_iface *if_incoming) 769 struct hard_iface *if_incoming)
764{ 770{
765 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface); 771 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
766 struct neigh_node *neigh_node = NULL, *tmp_neigh_node; 772 struct neigh_node *neigh_node = NULL, *tmp_neigh_node;
@@ -774,7 +780,8 @@ static int bat_iv_ogm_calc_tq(struct orig_node *orig_node,
774 hlist_for_each_entry_rcu(tmp_neigh_node, node, 780 hlist_for_each_entry_rcu(tmp_neigh_node, node,
775 &orig_neigh_node->neigh_list, list) { 781 &orig_neigh_node->neigh_list, list) {
776 782
777 if (!compare_eth(tmp_neigh_node->addr, orig_neigh_node->orig)) 783 if (!batadv_compare_eth(tmp_neigh_node->addr,
784 orig_neigh_node->orig))
778 continue; 785 continue;
779 786
780 if (tmp_neigh_node->if_incoming != if_incoming) 787 if (tmp_neigh_node->if_incoming != if_incoming)
@@ -789,11 +796,11 @@ static int bat_iv_ogm_calc_tq(struct orig_node *orig_node,
789 rcu_read_unlock(); 796 rcu_read_unlock();
790 797
791 if (!neigh_node) 798 if (!neigh_node)
792 neigh_node = bat_iv_ogm_neigh_new(if_incoming, 799 neigh_node = batadv_iv_ogm_neigh_new(if_incoming,
793 orig_neigh_node->orig, 800 orig_neigh_node->orig,
794 orig_neigh_node, 801 orig_neigh_node,
795 orig_neigh_node, 802 orig_neigh_node,
796 batman_ogm_packet->seqno); 803 batman_ogm_packet->seqno);
797 804
798 if (!neigh_node) 805 if (!neigh_node)
799 goto out; 806 goto out;
@@ -844,10 +851,11 @@ static int bat_iv_ogm_calc_tq(struct orig_node *orig_node,
844 * tq_asym_penalty) / 851 * tq_asym_penalty) /
845 (TQ_MAX_VALUE * TQ_MAX_VALUE)); 852 (TQ_MAX_VALUE * TQ_MAX_VALUE));
846 853
847 bat_dbg(DBG_BATMAN, bat_priv, 854 batadv_dbg(DBG_BATMAN, bat_priv,
848 "bidirectional: orig = %-15pM neigh = %-15pM => own_bcast = %2i, real recv = %2i, local tq: %3i, asym_penalty: %3i, total tq: %3i\n", 855 "bidirectional: orig = %-15pM neigh = %-15pM => own_bcast = %2i, real recv = %2i, local tq: %3i, asym_penalty: %3i, total tq: %3i\n",
849 orig_node->orig, orig_neigh_node->orig, total_count, 856 orig_node->orig, orig_neigh_node->orig, total_count,
850 neigh_rq_count, tq_own, tq_asym_penalty, batman_ogm_packet->tq); 857 neigh_rq_count, tq_own,
858 tq_asym_penalty, batman_ogm_packet->tq);
851 859
852 /* if link has the minimum required transmission quality 860 /* if link has the minimum required transmission quality
853 * consider it bidirectional 861 * consider it bidirectional
@@ -869,10 +877,10 @@ out:
869 * -1 the packet is old and has been received while the seqno window 877 * -1 the packet is old and has been received while the seqno window
870 * was protected. Caller should drop it. 878 * was protected. Caller should drop it.
871 */ 879 */
872static int bat_iv_ogm_update_seqnos(const struct ethhdr *ethhdr, 880static int
873 const struct batman_ogm_packet 881batadv_iv_ogm_update_seqnos(const struct ethhdr *ethhdr,
874 *batman_ogm_packet, 882 const struct batman_ogm_packet *batman_ogm_packet,
875 const struct hard_iface *if_incoming) 883 const struct hard_iface *if_incoming)
876{ 884{
877 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface); 885 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
878 struct orig_node *orig_node; 886 struct orig_node *orig_node;
@@ -883,6 +891,7 @@ static int bat_iv_ogm_update_seqnos(const struct ethhdr *ethhdr,
883 int need_update = 0; 891 int need_update = 0;
884 int set_mark, ret = -1; 892 int set_mark, ret = -1;
885 uint32_t seqno = ntohl(batman_ogm_packet->seqno); 893 uint32_t seqno = ntohl(batman_ogm_packet->seqno);
894 uint8_t *neigh_addr;
886 895
887 orig_node = batadv_get_orig_node(bat_priv, batman_ogm_packet->orig); 896 orig_node = batadv_get_orig_node(bat_priv, batman_ogm_packet->orig);
888 if (!orig_node) 897 if (!orig_node)
@@ -901,12 +910,13 @@ static int bat_iv_ogm_update_seqnos(const struct ethhdr *ethhdr,
901 hlist_for_each_entry_rcu(tmp_neigh_node, node, 910 hlist_for_each_entry_rcu(tmp_neigh_node, node,
902 &orig_node->neigh_list, list) { 911 &orig_node->neigh_list, list) {
903 912
904 is_duplicate |= bat_test_bit(tmp_neigh_node->real_bits, 913 is_duplicate |= batadv_test_bit(tmp_neigh_node->real_bits,
905 orig_node->last_real_seqno, 914 orig_node->last_real_seqno,
906 seqno); 915 seqno);
907 916
908 if (compare_eth(tmp_neigh_node->addr, ethhdr->h_source) && 917 neigh_addr = tmp_neigh_node->addr;
909 (tmp_neigh_node->if_incoming == if_incoming)) 918 if (batadv_compare_eth(neigh_addr, ethhdr->h_source) &&
919 tmp_neigh_node->if_incoming == if_incoming)
910 set_mark = 1; 920 set_mark = 1;
911 else 921 else
912 set_mark = 0; 922 set_mark = 0;
@@ -923,9 +933,9 @@ static int bat_iv_ogm_update_seqnos(const struct ethhdr *ethhdr,
923 rcu_read_unlock(); 933 rcu_read_unlock();
924 934
925 if (need_update) { 935 if (need_update) {
926 bat_dbg(DBG_BATMAN, bat_priv, 936 batadv_dbg(DBG_BATMAN, bat_priv,
927 "updating last_seqno: old %u, new %u\n", 937 "updating last_seqno: old %u, new %u\n",
928 orig_node->last_real_seqno, seqno); 938 orig_node->last_real_seqno, seqno);
929 orig_node->last_real_seqno = seqno; 939 orig_node->last_real_seqno = seqno;
930 } 940 }
931 941
@@ -937,10 +947,10 @@ out:
937 return ret; 947 return ret;
938} 948}
939 949
940static void bat_iv_ogm_process(const struct ethhdr *ethhdr, 950static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
941 struct batman_ogm_packet *batman_ogm_packet, 951 struct batman_ogm_packet *batman_ogm_packet,
942 const unsigned char *tt_buff, 952 const unsigned char *tt_buff,
943 struct hard_iface *if_incoming) 953 struct hard_iface *if_incoming)
944{ 954{
945 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface); 955 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
946 struct hard_iface *hard_iface; 956 struct hard_iface *hard_iface;
@@ -949,11 +959,12 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
949 struct neigh_node *orig_neigh_router = NULL; 959 struct neigh_node *orig_neigh_router = NULL;
950 int has_directlink_flag; 960 int has_directlink_flag;
951 int is_my_addr = 0, is_my_orig = 0, is_my_oldorig = 0; 961 int is_my_addr = 0, is_my_orig = 0, is_my_oldorig = 0;
952 int is_broadcast = 0, is_bidirectional; 962 int is_broadcast = 0, is_bidirect;
953 bool is_single_hop_neigh = false; 963 bool is_single_hop_neigh = false;
954 bool is_from_best_next_hop = false; 964 bool is_from_best_next_hop = false;
955 int is_duplicate; 965 int is_duplicate, sameseq, simlar_ttl;
956 uint32_t if_incoming_seqno; 966 uint32_t if_incoming_seqno;
967 uint8_t *prev_sender;
957 968
958 /* Silently drop when the batman packet is actually not a 969 /* Silently drop when the batman packet is actually not a
959 * correct packet. 970 * correct packet.
@@ -975,18 +986,19 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
975 986
976 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0); 987 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
977 988
978 if (compare_eth(ethhdr->h_source, batman_ogm_packet->orig)) 989 if (batadv_compare_eth(ethhdr->h_source, batman_ogm_packet->orig))
979 is_single_hop_neigh = true; 990 is_single_hop_neigh = true;
980 991
981 bat_dbg(DBG_BATMAN, bat_priv, 992 batadv_dbg(DBG_BATMAN, bat_priv,
982 "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", 993 "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",
983 ethhdr->h_source, if_incoming->net_dev->name, 994 ethhdr->h_source, if_incoming->net_dev->name,
984 if_incoming->net_dev->dev_addr, batman_ogm_packet->orig, 995 if_incoming->net_dev->dev_addr, batman_ogm_packet->orig,
985 batman_ogm_packet->prev_sender, ntohl(batman_ogm_packet->seqno), 996 batman_ogm_packet->prev_sender,
986 batman_ogm_packet->ttvn, ntohs(batman_ogm_packet->tt_crc), 997 ntohl(batman_ogm_packet->seqno), batman_ogm_packet->ttvn,
987 batman_ogm_packet->tt_num_changes, batman_ogm_packet->tq, 998 ntohs(batman_ogm_packet->tt_crc),
988 batman_ogm_packet->header.ttl, 999 batman_ogm_packet->tt_num_changes, batman_ogm_packet->tq,
989 batman_ogm_packet->header.version, has_directlink_flag); 1000 batman_ogm_packet->header.ttl,
1001 batman_ogm_packet->header.version, has_directlink_flag);
990 1002
991 rcu_read_lock(); 1003 rcu_read_lock();
992 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) { 1004 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
@@ -996,16 +1008,16 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
996 if (hard_iface->soft_iface != if_incoming->soft_iface) 1008 if (hard_iface->soft_iface != if_incoming->soft_iface)
997 continue; 1009 continue;
998 1010
999 if (compare_eth(ethhdr->h_source, 1011 if (batadv_compare_eth(ethhdr->h_source,
1000 hard_iface->net_dev->dev_addr)) 1012 hard_iface->net_dev->dev_addr))
1001 is_my_addr = 1; 1013 is_my_addr = 1;
1002 1014
1003 if (compare_eth(batman_ogm_packet->orig, 1015 if (batadv_compare_eth(batman_ogm_packet->orig,
1004 hard_iface->net_dev->dev_addr)) 1016 hard_iface->net_dev->dev_addr))
1005 is_my_orig = 1; 1017 is_my_orig = 1;
1006 1018
1007 if (compare_eth(batman_ogm_packet->prev_sender, 1019 if (batadv_compare_eth(batman_ogm_packet->prev_sender,
1008 hard_iface->net_dev->dev_addr)) 1020 hard_iface->net_dev->dev_addr))
1009 is_my_oldorig = 1; 1021 is_my_oldorig = 1;
1010 1022
1011 if (is_broadcast_ether_addr(ethhdr->h_source)) 1023 if (is_broadcast_ether_addr(ethhdr->h_source))
@@ -1014,29 +1026,30 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
1014 rcu_read_unlock(); 1026 rcu_read_unlock();
1015 1027
1016 if (batman_ogm_packet->header.version != COMPAT_VERSION) { 1028 if (batman_ogm_packet->header.version != COMPAT_VERSION) {
1017 bat_dbg(DBG_BATMAN, bat_priv, 1029 batadv_dbg(DBG_BATMAN, bat_priv,
1018 "Drop packet: incompatible batman version (%i)\n", 1030 "Drop packet: incompatible batman version (%i)\n",
1019 batman_ogm_packet->header.version); 1031 batman_ogm_packet->header.version);
1020 return; 1032 return;
1021 } 1033 }
1022 1034
1023 if (is_my_addr) { 1035 if (is_my_addr) {
1024 bat_dbg(DBG_BATMAN, bat_priv, 1036 batadv_dbg(DBG_BATMAN, bat_priv,
1025 "Drop packet: received my own broadcast (sender: %pM)\n", 1037 "Drop packet: received my own broadcast (sender: %pM)\n",
1026 ethhdr->h_source); 1038 ethhdr->h_source);
1027 return; 1039 return;
1028 } 1040 }
1029 1041
1030 if (is_broadcast) { 1042 if (is_broadcast) {
1031 bat_dbg(DBG_BATMAN, bat_priv, 1043 batadv_dbg(DBG_BATMAN, bat_priv,
1032 "Drop packet: ignoring all packets with broadcast source addr (sender: %pM)\n", 1044 "Drop packet: ignoring all packets with broadcast source addr (sender: %pM)\n",
1033 ethhdr->h_source); 1045 ethhdr->h_source);
1034 return; 1046 return;
1035 } 1047 }
1036 1048
1037 if (is_my_orig) { 1049 if (is_my_orig) {
1038 unsigned long *word; 1050 unsigned long *word;
1039 int offset; 1051 int offset;
1052 int32_t bit_pos;
1040 1053
1041 orig_neigh_node = batadv_get_orig_node(bat_priv, 1054 orig_neigh_node = batadv_get_orig_node(bat_priv,
1042 ethhdr->h_source); 1055 ethhdr->h_source);
@@ -1048,37 +1061,37 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
1048 * save packet seqno for bidirectional check 1061 * save packet seqno for bidirectional check
1049 */ 1062 */
1050 if (has_directlink_flag && 1063 if (has_directlink_flag &&
1051 compare_eth(if_incoming->net_dev->dev_addr, 1064 batadv_compare_eth(if_incoming->net_dev->dev_addr,
1052 batman_ogm_packet->orig)) { 1065 batman_ogm_packet->orig)) {
1053 offset = if_incoming->if_num * NUM_WORDS; 1066 offset = if_incoming->if_num * NUM_WORDS;
1054 1067
1055 spin_lock_bh(&orig_neigh_node->ogm_cnt_lock); 1068 spin_lock_bh(&orig_neigh_node->ogm_cnt_lock);
1056 word = &(orig_neigh_node->bcast_own[offset]); 1069 word = &(orig_neigh_node->bcast_own[offset]);
1057 bat_set_bit(word, 1070 bit_pos = if_incoming_seqno - 2;
1058 if_incoming_seqno - 1071 bit_pos -= ntohl(batman_ogm_packet->seqno);
1059 ntohl(batman_ogm_packet->seqno) - 2); 1072 batadv_set_bit(word, bit_pos);
1060 orig_neigh_node->bcast_own_sum[if_incoming->if_num] = 1073 orig_neigh_node->bcast_own_sum[if_incoming->if_num] =
1061 bitmap_weight(word, TQ_LOCAL_WINDOW_SIZE); 1074 bitmap_weight(word, TQ_LOCAL_WINDOW_SIZE);
1062 spin_unlock_bh(&orig_neigh_node->ogm_cnt_lock); 1075 spin_unlock_bh(&orig_neigh_node->ogm_cnt_lock);
1063 } 1076 }
1064 1077
1065 bat_dbg(DBG_BATMAN, bat_priv, 1078 batadv_dbg(DBG_BATMAN, bat_priv,
1066 "Drop packet: originator packet from myself (via neighbor)\n"); 1079 "Drop packet: originator packet from myself (via neighbor)\n");
1067 batadv_orig_node_free_ref(orig_neigh_node); 1080 batadv_orig_node_free_ref(orig_neigh_node);
1068 return; 1081 return;
1069 } 1082 }
1070 1083
1071 if (is_my_oldorig) { 1084 if (is_my_oldorig) {
1072 bat_dbg(DBG_BATMAN, bat_priv, 1085 batadv_dbg(DBG_BATMAN, bat_priv,
1073 "Drop packet: ignoring all rebroadcast echos (sender: %pM)\n", 1086 "Drop packet: ignoring all rebroadcast echos (sender: %pM)\n",
1074 ethhdr->h_source); 1087 ethhdr->h_source);
1075 return; 1088 return;
1076 } 1089 }
1077 1090
1078 if (batman_ogm_packet->flags & NOT_BEST_NEXT_HOP) { 1091 if (batman_ogm_packet->flags & NOT_BEST_NEXT_HOP) {
1079 bat_dbg(DBG_BATMAN, bat_priv, 1092 batadv_dbg(DBG_BATMAN, bat_priv,
1080 "Drop packet: ignoring all packets not forwarded from the best next hop (sender: %pM)\n", 1093 "Drop packet: ignoring all packets not forwarded from the best next hop (sender: %pM)\n",
1081 ethhdr->h_source); 1094 ethhdr->h_source);
1082 return; 1095 return;
1083 } 1096 }
1084 1097
@@ -1086,19 +1099,19 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
1086 if (!orig_node) 1099 if (!orig_node)
1087 return; 1100 return;
1088 1101
1089 is_duplicate = bat_iv_ogm_update_seqnos(ethhdr, batman_ogm_packet, 1102 is_duplicate = batadv_iv_ogm_update_seqnos(ethhdr, batman_ogm_packet,
1090 if_incoming); 1103 if_incoming);
1091 1104
1092 if (is_duplicate == -1) { 1105 if (is_duplicate == -1) {
1093 bat_dbg(DBG_BATMAN, bat_priv, 1106 batadv_dbg(DBG_BATMAN, bat_priv,
1094 "Drop packet: packet within seqno protection time (sender: %pM)\n", 1107 "Drop packet: packet within seqno protection time (sender: %pM)\n",
1095 ethhdr->h_source); 1108 ethhdr->h_source);
1096 goto out; 1109 goto out;
1097 } 1110 }
1098 1111
1099 if (batman_ogm_packet->tq == 0) { 1112 if (batman_ogm_packet->tq == 0) {
1100 bat_dbg(DBG_BATMAN, bat_priv, 1113 batadv_dbg(DBG_BATMAN, bat_priv,
1101 "Drop packet: originator packet with tq equal 0\n"); 1114 "Drop packet: originator packet with tq equal 0\n");
1102 goto out; 1115 goto out;
1103 } 1116 }
1104 1117
@@ -1107,18 +1120,18 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
1107 router_router = batadv_orig_node_get_router(router->orig_node); 1120 router_router = batadv_orig_node_get_router(router->orig_node);
1108 1121
1109 if ((router && router->tq_avg != 0) && 1122 if ((router && router->tq_avg != 0) &&
1110 (compare_eth(router->addr, ethhdr->h_source))) 1123 (batadv_compare_eth(router->addr, ethhdr->h_source)))
1111 is_from_best_next_hop = true; 1124 is_from_best_next_hop = true;
1112 1125
1126 prev_sender = batman_ogm_packet->prev_sender;
1113 /* avoid temporary routing loops */ 1127 /* avoid temporary routing loops */
1114 if (router && router_router && 1128 if (router && router_router &&
1115 (compare_eth(router->addr, batman_ogm_packet->prev_sender)) && 1129 (batadv_compare_eth(router->addr, prev_sender)) &&
1116 !(compare_eth(batman_ogm_packet->orig, 1130 !(batadv_compare_eth(batman_ogm_packet->orig, prev_sender)) &&
1117 batman_ogm_packet->prev_sender)) && 1131 (batadv_compare_eth(router->addr, router_router->addr))) {
1118 (compare_eth(router->addr, router_router->addr))) { 1132 batadv_dbg(DBG_BATMAN, bat_priv,
1119 bat_dbg(DBG_BATMAN, bat_priv, 1133 "Drop packet: ignoring all rebroadcast packets that may make me loop (sender: %pM)\n",
1120 "Drop packet: ignoring all rebroadcast packets that may make me loop (sender: %pM)\n", 1134 ethhdr->h_source);
1121 ethhdr->h_source);
1122 goto out; 1135 goto out;
1123 } 1136 }
1124 1137
@@ -1137,13 +1150,13 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
1137 * don't route towards it 1150 * don't route towards it
1138 */ 1151 */
1139 if (!is_single_hop_neigh && (!orig_neigh_router)) { 1152 if (!is_single_hop_neigh && (!orig_neigh_router)) {
1140 bat_dbg(DBG_BATMAN, bat_priv, 1153 batadv_dbg(DBG_BATMAN, bat_priv,
1141 "Drop packet: OGM via unknown neighbor!\n"); 1154 "Drop packet: OGM via unknown neighbor!\n");
1142 goto out_neigh; 1155 goto out_neigh;
1143 } 1156 }
1144 1157
1145 is_bidirectional = bat_iv_ogm_calc_tq(orig_node, orig_neigh_node, 1158 is_bidirect = batadv_iv_ogm_calc_tq(orig_node, orig_neigh_node,
1146 batman_ogm_packet, if_incoming); 1159 batman_ogm_packet, if_incoming);
1147 1160
1148 batadv_bonding_save_primary(orig_node, orig_neigh_node, 1161 batadv_bonding_save_primary(orig_node, orig_neigh_node,
1149 batman_ogm_packet); 1162 batman_ogm_packet);
@@ -1151,45 +1164,44 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
1151 /* update ranking if it is not a duplicate or has the same 1164 /* update ranking if it is not a duplicate or has the same
1152 * seqno and similar ttl as the non-duplicate 1165 * seqno and similar ttl as the non-duplicate
1153 */ 1166 */
1154 if (is_bidirectional && 1167 sameseq = orig_node->last_real_seqno == ntohl(batman_ogm_packet->seqno);
1155 (!is_duplicate || 1168 simlar_ttl = orig_node->last_ttl - 3 <= batman_ogm_packet->header.ttl;
1156 ((orig_node->last_real_seqno == ntohl(batman_ogm_packet->seqno)) && 1169 if (is_bidirect && (!is_duplicate || (sameseq && simlar_ttl)))
1157 (orig_node->last_ttl - 3 <= batman_ogm_packet->header.ttl)))) 1170 batadv_iv_ogm_orig_update(bat_priv, orig_node, ethhdr,
1158 bat_iv_ogm_orig_update(bat_priv, orig_node, ethhdr, 1171 batman_ogm_packet, if_incoming,
1159 batman_ogm_packet, if_incoming, 1172 tt_buff, is_duplicate);
1160 tt_buff, is_duplicate);
1161 1173
1162 /* is single hop (direct) neighbor */ 1174 /* is single hop (direct) neighbor */
1163 if (is_single_hop_neigh) { 1175 if (is_single_hop_neigh) {
1164 1176
1165 /* mark direct link on incoming interface */ 1177 /* mark direct link on incoming interface */
1166 bat_iv_ogm_forward(orig_node, ethhdr, batman_ogm_packet, 1178 batadv_iv_ogm_forward(orig_node, ethhdr, batman_ogm_packet,
1167 is_single_hop_neigh, is_from_best_next_hop, 1179 is_single_hop_neigh,
1168 if_incoming); 1180 is_from_best_next_hop, if_incoming);
1169 1181
1170 bat_dbg(DBG_BATMAN, bat_priv, 1182 batadv_dbg(DBG_BATMAN, bat_priv,
1171 "Forwarding packet: rebroadcast neighbor packet with direct link flag\n"); 1183 "Forwarding packet: rebroadcast neighbor packet with direct link flag\n");
1172 goto out_neigh; 1184 goto out_neigh;
1173 } 1185 }
1174 1186
1175 /* multihop originator */ 1187 /* multihop originator */
1176 if (!is_bidirectional) { 1188 if (!is_bidirect) {
1177 bat_dbg(DBG_BATMAN, bat_priv, 1189 batadv_dbg(DBG_BATMAN, bat_priv,
1178 "Drop packet: not received via bidirectional link\n"); 1190 "Drop packet: not received via bidirectional link\n");
1179 goto out_neigh; 1191 goto out_neigh;
1180 } 1192 }
1181 1193
1182 if (is_duplicate) { 1194 if (is_duplicate) {
1183 bat_dbg(DBG_BATMAN, bat_priv, 1195 batadv_dbg(DBG_BATMAN, bat_priv,
1184 "Drop packet: duplicate packet received\n"); 1196 "Drop packet: duplicate packet received\n");
1185 goto out_neigh; 1197 goto out_neigh;
1186 } 1198 }
1187 1199
1188 bat_dbg(DBG_BATMAN, bat_priv, 1200 batadv_dbg(DBG_BATMAN, bat_priv,
1189 "Forwarding packet: rebroadcast originator packet\n"); 1201 "Forwarding packet: rebroadcast originator packet\n");
1190 bat_iv_ogm_forward(orig_node, ethhdr, batman_ogm_packet, 1202 batadv_iv_ogm_forward(orig_node, ethhdr, batman_ogm_packet,
1191 is_single_hop_neigh, is_from_best_next_hop, 1203 is_single_hop_neigh, is_from_best_next_hop,
1192 if_incoming); 1204 if_incoming);
1193 1205
1194out_neigh: 1206out_neigh:
1195 if ((orig_neigh_node) && (!is_single_hop_neigh)) 1207 if ((orig_neigh_node) && (!is_single_hop_neigh))
@@ -1205,8 +1217,8 @@ out:
1205 batadv_orig_node_free_ref(orig_node); 1217 batadv_orig_node_free_ref(orig_node);
1206} 1218}
1207 1219
1208static int bat_iv_ogm_receive(struct sk_buff *skb, 1220static int batadv_iv_ogm_receive(struct sk_buff *skb,
1209 struct hard_iface *if_incoming) 1221 struct hard_iface *if_incoming)
1210{ 1222{
1211 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface); 1223 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
1212 struct batman_ogm_packet *batman_ogm_packet; 1224 struct batman_ogm_packet *batman_ogm_packet;
@@ -1222,7 +1234,7 @@ static int bat_iv_ogm_receive(struct sk_buff *skb,
1222 /* did we receive a B.A.T.M.A.N. IV OGM packet on an interface 1234 /* did we receive a B.A.T.M.A.N. IV OGM packet on an interface
1223 * that does not have B.A.T.M.A.N. IV enabled ? 1235 * that does not have B.A.T.M.A.N. IV enabled ?
1224 */ 1236 */
1225 if (bat_priv->bat_algo_ops->bat_ogm_emit != bat_iv_ogm_emit) 1237 if (bat_priv->bat_algo_ops->bat_ogm_emit != batadv_iv_ogm_emit)
1226 return NET_RX_DROP; 1238 return NET_RX_DROP;
1227 1239
1228 batadv_inc_counter(bat_priv, BAT_CNT_MGMT_RX); 1240 batadv_inc_counter(bat_priv, BAT_CNT_MGMT_RX);
@@ -1238,29 +1250,29 @@ static int bat_iv_ogm_receive(struct sk_buff *skb,
1238 do { 1250 do {
1239 tt_buff = packet_buff + buff_pos + BATMAN_OGM_HLEN; 1251 tt_buff = packet_buff + buff_pos + BATMAN_OGM_HLEN;
1240 1252
1241 bat_iv_ogm_process(ethhdr, batman_ogm_packet, 1253 batadv_iv_ogm_process(ethhdr, batman_ogm_packet, tt_buff,
1242 tt_buff, if_incoming); 1254 if_incoming);
1243 1255
1244 buff_pos += BATMAN_OGM_HLEN; 1256 buff_pos += BATMAN_OGM_HLEN;
1245 buff_pos += batadv_tt_len(batman_ogm_packet->tt_num_changes); 1257 buff_pos += batadv_tt_len(batman_ogm_packet->tt_num_changes);
1246 1258
1247 batman_ogm_packet = (struct batman_ogm_packet *) 1259 batman_ogm_packet = (struct batman_ogm_packet *)
1248 (packet_buff + buff_pos); 1260 (packet_buff + buff_pos);
1249 } while (bat_iv_ogm_aggr_packet(buff_pos, packet_len, 1261 } while (batadv_iv_ogm_aggr_packet(buff_pos, packet_len,
1250 batman_ogm_packet->tt_num_changes)); 1262 batman_ogm_packet->tt_num_changes));
1251 1263
1252 kfree_skb(skb); 1264 kfree_skb(skb);
1253 return NET_RX_SUCCESS; 1265 return NET_RX_SUCCESS;
1254} 1266}
1255 1267
1256static struct bat_algo_ops batman_iv __read_mostly = { 1268static struct bat_algo_ops batadv_batman_iv __read_mostly = {
1257 .name = "BATMAN_IV", 1269 .name = "BATMAN_IV",
1258 .bat_iface_enable = bat_iv_ogm_iface_enable, 1270 .bat_iface_enable = batadv_iv_ogm_iface_enable,
1259 .bat_iface_disable = bat_iv_ogm_iface_disable, 1271 .bat_iface_disable = batadv_iv_ogm_iface_disable,
1260 .bat_iface_update_mac = bat_iv_ogm_iface_update_mac, 1272 .bat_iface_update_mac = batadv_iv_ogm_iface_update_mac,
1261 .bat_primary_iface_set = bat_iv_ogm_primary_iface_set, 1273 .bat_primary_iface_set = batadv_iv_ogm_primary_iface_set,
1262 .bat_ogm_schedule = bat_iv_ogm_schedule, 1274 .bat_ogm_schedule = batadv_iv_ogm_schedule,
1263 .bat_ogm_emit = bat_iv_ogm_emit, 1275 .bat_ogm_emit = batadv_iv_ogm_emit,
1264}; 1276};
1265 1277
1266int __init batadv_iv_init(void) 1278int __init batadv_iv_init(void)
@@ -1268,11 +1280,11 @@ int __init batadv_iv_init(void)
1268 int ret; 1280 int ret;
1269 1281
1270 /* batman originator packet */ 1282 /* batman originator packet */
1271 ret = batadv_recv_handler_register(BAT_IV_OGM, bat_iv_ogm_receive); 1283 ret = batadv_recv_handler_register(BAT_IV_OGM, batadv_iv_ogm_receive);
1272 if (ret < 0) 1284 if (ret < 0)
1273 goto out; 1285 goto out;
1274 1286
1275 ret = batadv_algo_register(&batman_iv); 1287 ret = batadv_algo_register(&batadv_batman_iv);
1276 if (ret < 0) 1288 if (ret < 0)
1277 goto handler_unregister; 1289 goto handler_unregister;
1278 1290