1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2007-2018 B.A.T.M.A.N. contributors:
4 * Marek Lindner, Simon Wunderlich
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.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 #include "bat_iv_ogm.h"
22 #include <linux/atomic.h>
23 #include <linux/bitmap.h>
24 #include <linux/bitops.h>
25 #include <linux/bug.h>
26 #include <linux/byteorder/generic.h>
27 #include <linux/cache.h>
28 #include <linux/errno.h>
29 #include <linux/etherdevice.h>
30 #include <linux/gfp.h>
31 #include <linux/if_ether.h>
32 #include <linux/init.h>
33 #include <linux/jiffies.h>
34 #include <linux/kernel.h>
35 #include <linux/kref.h>
36 #include <linux/list.h>
37 #include <linux/lockdep.h>
38 #include <linux/mutex.h>
39 #include <linux/netdevice.h>
40 #include <linux/netlink.h>
41 #include <linux/pkt_sched.h>
42 #include <linux/printk.h>
43 #include <linux/random.h>
44 #include <linux/rculist.h>
45 #include <linux/rcupdate.h>
46 #include <linux/seq_file.h>
47 #include <linux/skbuff.h>
48 #include <linux/slab.h>
49 #include <linux/spinlock.h>
50 #include <linux/stddef.h>
51 #include <linux/string.h>
52 #include <linux/types.h>
53 #include <linux/workqueue.h>
54 #include <net/genetlink.h>
55 #include <net/netlink.h>
56 #include <uapi/linux/batadv_packet.h>
57 #include <uapi/linux/batman_adv.h>
61 #include "gateway_client.h"
62 #include "hard-interface.h"
66 #include "network-coding.h"
67 #include "originator.h"
70 #include "translation-table.h"
73 static void batadv_iv_send_outstanding_bat_ogm_packet(struct work_struct *work);
76 * enum batadv_dup_status - duplicate status
78 enum batadv_dup_status {
79 /** @BATADV_NO_DUP: the packet is no duplicate */
83 * @BATADV_ORIG_DUP: OGM is a duplicate in the originator (but not for
88 /** @BATADV_NEIGH_DUP: OGM is a duplicate for the neighbor */
92 * @BATADV_PROTECTED: originator is currently protected (after reboot)
98 * batadv_ring_buffer_set() - update the ring buffer with the given value
99 * @lq_recv: pointer to the ring buffer
100 * @lq_index: index to store the value at
101 * @value: value to store in the ring buffer
103 static void batadv_ring_buffer_set(u8 lq_recv[], u8 *lq_index, u8 value)
105 lq_recv[*lq_index] = value;
106 *lq_index = (*lq_index + 1) % BATADV_TQ_GLOBAL_WINDOW_SIZE;
110 * batadv_ring_buffer_avg() - compute the average of all non-zero values stored
111 * in the given ring buffer
112 * @lq_recv: pointer to the ring buffer
114 * Return: computed average value.
116 static u8 batadv_ring_buffer_avg(const u8 lq_recv[])
125 while (i < BATADV_TQ_GLOBAL_WINDOW_SIZE) {
138 return (u8)(sum / count);
142 * batadv_iv_ogm_orig_free() - free the private resources allocated for this
144 * @orig_node: the orig_node for which the resources have to be free'd
146 static void batadv_iv_ogm_orig_free(struct batadv_orig_node *orig_node)
148 kfree(orig_node->bat_iv.bcast_own);
149 kfree(orig_node->bat_iv.bcast_own_sum);
153 * batadv_iv_ogm_orig_add_if() - change the private structures of the orig_node
154 * to include the new hard-interface
155 * @orig_node: the orig_node that has to be changed
156 * @max_if_num: the current amount of interfaces
158 * Return: 0 on success, a negative error code otherwise.
160 static int batadv_iv_ogm_orig_add_if(struct batadv_orig_node *orig_node,
161 unsigned int max_if_num)
167 spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock);
169 old_size = (max_if_num - 1) * sizeof(unsigned long) * BATADV_NUM_WORDS;
170 data_ptr = kmalloc_array(max_if_num,
171 BATADV_NUM_WORDS * sizeof(unsigned long),
176 memcpy(data_ptr, orig_node->bat_iv.bcast_own, old_size);
177 kfree(orig_node->bat_iv.bcast_own);
178 orig_node->bat_iv.bcast_own = data_ptr;
180 data_ptr = kmalloc_array(max_if_num, sizeof(u8), GFP_ATOMIC);
184 memcpy(data_ptr, orig_node->bat_iv.bcast_own_sum,
185 (max_if_num - 1) * sizeof(u8));
186 kfree(orig_node->bat_iv.bcast_own_sum);
187 orig_node->bat_iv.bcast_own_sum = data_ptr;
192 spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock);
198 * batadv_iv_ogm_drop_bcast_own_entry() - drop section of bcast_own
199 * @orig_node: the orig_node that has to be changed
200 * @max_if_num: the current amount of interfaces
201 * @del_if_num: the index of the interface being removed
204 batadv_iv_ogm_drop_bcast_own_entry(struct batadv_orig_node *orig_node,
205 unsigned int max_if_num,
206 unsigned int del_if_num)
212 lockdep_assert_held(&orig_node->bat_iv.ogm_cnt_lock);
214 chunk_size = sizeof(unsigned long) * BATADV_NUM_WORDS;
215 data_ptr = kmalloc_array(max_if_num, chunk_size, GFP_ATOMIC);
217 /* use old buffer when new one could not be allocated */
218 data_ptr = orig_node->bat_iv.bcast_own;
220 /* copy first part */
221 memmove(data_ptr, orig_node->bat_iv.bcast_own, del_if_num * chunk_size);
223 /* copy second part */
224 if_offset = (del_if_num + 1) * chunk_size;
225 memmove((char *)data_ptr + del_if_num * chunk_size,
226 (uint8_t *)orig_node->bat_iv.bcast_own + if_offset,
227 (max_if_num - del_if_num) * chunk_size);
229 /* bcast_own was shrunk down in new buffer; free old one */
230 if (orig_node->bat_iv.bcast_own != data_ptr) {
231 kfree(orig_node->bat_iv.bcast_own);
232 orig_node->bat_iv.bcast_own = data_ptr;
237 * batadv_iv_ogm_drop_bcast_own_sum_entry() - drop section of bcast_own_sum
238 * @orig_node: the orig_node that has to be changed
239 * @max_if_num: the current amount of interfaces
240 * @del_if_num: the index of the interface being removed
243 batadv_iv_ogm_drop_bcast_own_sum_entry(struct batadv_orig_node *orig_node,
244 unsigned int max_if_num,
245 unsigned int del_if_num)
250 lockdep_assert_held(&orig_node->bat_iv.ogm_cnt_lock);
252 data_ptr = kmalloc_array(max_if_num, sizeof(u8), GFP_ATOMIC);
254 /* use old buffer when new one could not be allocated */
255 data_ptr = orig_node->bat_iv.bcast_own_sum;
257 memmove(data_ptr, orig_node->bat_iv.bcast_own_sum,
258 del_if_num * sizeof(u8));
260 if_offset = (del_if_num + 1) * sizeof(u8);
261 memmove((char *)data_ptr + del_if_num * sizeof(u8),
262 orig_node->bat_iv.bcast_own_sum + if_offset,
263 (max_if_num - del_if_num) * sizeof(u8));
265 /* bcast_own_sum was shrunk down in new buffer; free old one */
266 if (orig_node->bat_iv.bcast_own_sum != data_ptr) {
267 kfree(orig_node->bat_iv.bcast_own_sum);
268 orig_node->bat_iv.bcast_own_sum = data_ptr;
273 * batadv_iv_ogm_orig_del_if() - change the private structures of the orig_node
274 * to exclude the removed interface
275 * @orig_node: the orig_node that has to be changed
276 * @max_if_num: the current amount of interfaces
277 * @del_if_num: the index of the interface being removed
279 * Return: 0 on success, a negative error code otherwise.
281 static int batadv_iv_ogm_orig_del_if(struct batadv_orig_node *orig_node,
282 unsigned int max_if_num,
283 unsigned int del_if_num)
285 spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock);
287 if (max_if_num == 0) {
288 kfree(orig_node->bat_iv.bcast_own);
289 kfree(orig_node->bat_iv.bcast_own_sum);
290 orig_node->bat_iv.bcast_own = NULL;
291 orig_node->bat_iv.bcast_own_sum = NULL;
293 batadv_iv_ogm_drop_bcast_own_entry(orig_node, max_if_num,
295 batadv_iv_ogm_drop_bcast_own_sum_entry(orig_node, max_if_num,
299 spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock);
305 * batadv_iv_ogm_orig_get() - retrieve or create (if does not exist) an
307 * @bat_priv: the bat priv with all the soft interface information
308 * @addr: mac address of the originator
310 * Return: the originator object corresponding to the passed mac address or NULL
312 * If the object does not exists it is created an initialised.
314 static struct batadv_orig_node *
315 batadv_iv_ogm_orig_get(struct batadv_priv *bat_priv, const u8 *addr)
317 struct batadv_orig_node *orig_node;
321 orig_node = batadv_orig_hash_find(bat_priv, addr);
325 orig_node = batadv_orig_node_new(bat_priv, addr);
329 spin_lock_init(&orig_node->bat_iv.ogm_cnt_lock);
331 size = bat_priv->num_ifaces * sizeof(unsigned long) * BATADV_NUM_WORDS;
332 orig_node->bat_iv.bcast_own = kzalloc(size, GFP_ATOMIC);
333 if (!orig_node->bat_iv.bcast_own)
336 size = bat_priv->num_ifaces * sizeof(u8);
337 orig_node->bat_iv.bcast_own_sum = kzalloc(size, GFP_ATOMIC);
338 if (!orig_node->bat_iv.bcast_own_sum)
341 kref_get(&orig_node->refcount);
342 hash_added = batadv_hash_add(bat_priv->orig_hash, batadv_compare_orig,
343 batadv_choose_orig, orig_node,
344 &orig_node->hash_entry);
346 goto free_orig_node_hash;
351 batadv_orig_node_put(orig_node);
353 batadv_orig_node_put(orig_node);
358 static struct batadv_neigh_node *
359 batadv_iv_ogm_neigh_new(struct batadv_hard_iface *hard_iface,
360 const u8 *neigh_addr,
361 struct batadv_orig_node *orig_node,
362 struct batadv_orig_node *orig_neigh)
364 struct batadv_neigh_node *neigh_node;
366 neigh_node = batadv_neigh_node_get_or_create(orig_node,
367 hard_iface, neigh_addr);
371 neigh_node->orig_node = orig_neigh;
377 static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
379 struct batadv_ogm_packet *batadv_ogm_packet;
380 unsigned char *ogm_buff;
383 mutex_lock(&hard_iface->bat_iv.ogm_buff_mutex);
385 /* randomize initial seqno to avoid collision */
386 get_random_bytes(&random_seqno, sizeof(random_seqno));
387 atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
389 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
390 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
392 mutex_unlock(&hard_iface->bat_iv.ogm_buff_mutex);
396 hard_iface->bat_iv.ogm_buff = ogm_buff;
398 batadv_ogm_packet = (struct batadv_ogm_packet *)ogm_buff;
399 batadv_ogm_packet->packet_type = BATADV_IV_OGM;
400 batadv_ogm_packet->version = BATADV_COMPAT_VERSION;
401 batadv_ogm_packet->ttl = 2;
402 batadv_ogm_packet->flags = BATADV_NO_FLAGS;
403 batadv_ogm_packet->reserved = 0;
404 batadv_ogm_packet->tq = BATADV_TQ_MAX_VALUE;
406 mutex_unlock(&hard_iface->bat_iv.ogm_buff_mutex);
411 static void batadv_iv_ogm_iface_disable(struct batadv_hard_iface *hard_iface)
413 mutex_lock(&hard_iface->bat_iv.ogm_buff_mutex);
415 kfree(hard_iface->bat_iv.ogm_buff);
416 hard_iface->bat_iv.ogm_buff = NULL;
418 mutex_unlock(&hard_iface->bat_iv.ogm_buff_mutex);
421 static void batadv_iv_ogm_iface_update_mac(struct batadv_hard_iface *hard_iface)
423 struct batadv_ogm_packet *batadv_ogm_packet;
426 mutex_lock(&hard_iface->bat_iv.ogm_buff_mutex);
428 ogm_buff = hard_iface->bat_iv.ogm_buff;
432 batadv_ogm_packet = ogm_buff;
433 ether_addr_copy(batadv_ogm_packet->orig,
434 hard_iface->net_dev->dev_addr);
435 ether_addr_copy(batadv_ogm_packet->prev_sender,
436 hard_iface->net_dev->dev_addr);
439 mutex_unlock(&hard_iface->bat_iv.ogm_buff_mutex);
443 batadv_iv_ogm_primary_iface_set(struct batadv_hard_iface *hard_iface)
445 struct batadv_ogm_packet *batadv_ogm_packet;
448 mutex_lock(&hard_iface->bat_iv.ogm_buff_mutex);
450 ogm_buff = hard_iface->bat_iv.ogm_buff;
454 batadv_ogm_packet = ogm_buff;
455 batadv_ogm_packet->ttl = BATADV_TTL;
458 mutex_unlock(&hard_iface->bat_iv.ogm_buff_mutex);
461 /* when do we schedule our own ogm to be sent */
463 batadv_iv_ogm_emit_send_time(const struct batadv_priv *bat_priv)
467 msecs = atomic_read(&bat_priv->orig_interval) - BATADV_JITTER;
468 msecs += prandom_u32() % (2 * BATADV_JITTER);
470 return jiffies + msecs_to_jiffies(msecs);
473 /* when do we schedule a ogm packet to be sent */
474 static unsigned long batadv_iv_ogm_fwd_send_time(void)
476 return jiffies + msecs_to_jiffies(prandom_u32() % (BATADV_JITTER / 2));
479 /* apply hop penalty for a normal link */
480 static u8 batadv_hop_penalty(u8 tq, const struct batadv_priv *bat_priv)
482 int hop_penalty = atomic_read(&bat_priv->hop_penalty);
485 new_tq = tq * (BATADV_TQ_MAX_VALUE - hop_penalty);
486 new_tq /= BATADV_TQ_MAX_VALUE;
492 * batadv_iv_ogm_aggr_packet() - checks if there is another OGM attached
493 * @buff_pos: current position in the skb
494 * @packet_len: total length of the skb
495 * @ogm_packet: potential OGM in buffer
497 * Return: true if there is enough space for another OGM, false otherwise.
500 batadv_iv_ogm_aggr_packet(int buff_pos, int packet_len,
501 const struct batadv_ogm_packet *ogm_packet)
503 int next_buff_pos = 0;
505 /* check if there is enough space for the header */
506 next_buff_pos += buff_pos + sizeof(*ogm_packet);
507 if (next_buff_pos > packet_len)
510 /* check if there is enough space for the optional TVLV */
511 next_buff_pos += ntohs(ogm_packet->tvlv_len);
513 return (next_buff_pos <= packet_len) &&
514 (next_buff_pos <= BATADV_MAX_AGGREGATION_BYTES);
517 /* send a batman ogm to a given interface */
518 static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet,
519 struct batadv_hard_iface *hard_iface)
521 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
525 struct batadv_ogm_packet *batadv_ogm_packet;
529 if (hard_iface->if_status != BATADV_IF_ACTIVE)
534 packet_pos = forw_packet->skb->data;
535 batadv_ogm_packet = (struct batadv_ogm_packet *)packet_pos;
537 /* adjust all flags and log packets */
538 while (batadv_iv_ogm_aggr_packet(buff_pos, forw_packet->packet_len,
539 batadv_ogm_packet)) {
540 /* we might have aggregated direct link packets with an
541 * ordinary base packet
543 if (forw_packet->direct_link_flags & BIT(packet_num) &&
544 forw_packet->if_incoming == hard_iface)
545 batadv_ogm_packet->flags |= BATADV_DIRECTLINK;
547 batadv_ogm_packet->flags &= ~BATADV_DIRECTLINK;
549 if (packet_num > 0 || !forw_packet->own)
550 fwd_str = "Forwarding";
552 fwd_str = "Sending own";
554 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
555 "%s %spacket (originator %pM, seqno %u, TQ %d, TTL %d, IDF %s) on interface %s [%pM]\n",
556 fwd_str, (packet_num > 0 ? "aggregated " : ""),
557 batadv_ogm_packet->orig,
558 ntohl(batadv_ogm_packet->seqno),
559 batadv_ogm_packet->tq, batadv_ogm_packet->ttl,
560 ((batadv_ogm_packet->flags & BATADV_DIRECTLINK) ?
562 hard_iface->net_dev->name,
563 hard_iface->net_dev->dev_addr);
565 buff_pos += BATADV_OGM_HLEN;
566 buff_pos += ntohs(batadv_ogm_packet->tvlv_len);
568 packet_pos = forw_packet->skb->data + buff_pos;
569 batadv_ogm_packet = (struct batadv_ogm_packet *)packet_pos;
572 /* create clone because function is called more than once */
573 skb = skb_clone(forw_packet->skb, GFP_ATOMIC);
575 batadv_inc_counter(bat_priv, BATADV_CNT_MGMT_TX);
576 batadv_add_counter(bat_priv, BATADV_CNT_MGMT_TX_BYTES,
577 skb->len + ETH_HLEN);
578 batadv_send_broadcast_skb(skb, hard_iface);
582 /* send a batman ogm packet */
583 static void batadv_iv_ogm_emit(struct batadv_forw_packet *forw_packet)
585 struct net_device *soft_iface;
587 if (!forw_packet->if_incoming) {
588 pr_err("Error - can't forward packet: incoming iface not specified\n");
592 soft_iface = forw_packet->if_incoming->soft_iface;
594 if (WARN_ON(!forw_packet->if_outgoing))
597 if (forw_packet->if_outgoing->soft_iface != soft_iface) {
598 pr_warn("%s: soft interface switch for queued OGM\n", __func__);
602 if (forw_packet->if_incoming->if_status != BATADV_IF_ACTIVE)
605 /* only for one specific outgoing interface */
606 batadv_iv_ogm_send_to_if(forw_packet, forw_packet->if_outgoing);
610 * batadv_iv_ogm_can_aggregate() - find out if an OGM can be aggregated on an
611 * existing forward packet
612 * @new_bat_ogm_packet: OGM packet to be aggregated
613 * @bat_priv: the bat priv with all the soft interface information
614 * @packet_len: (total) length of the OGM
615 * @send_time: timestamp (jiffies) when the packet is to be sent
616 * @directlink: true if this is a direct link packet
617 * @if_incoming: interface where the packet was received
618 * @if_outgoing: interface for which the retransmission should be considered
619 * @forw_packet: the forwarded packet which should be checked
621 * Return: true if new_packet can be aggregated with forw_packet
624 batadv_iv_ogm_can_aggregate(const struct batadv_ogm_packet *new_bat_ogm_packet,
625 struct batadv_priv *bat_priv,
626 int packet_len, unsigned long send_time,
628 const struct batadv_hard_iface *if_incoming,
629 const struct batadv_hard_iface *if_outgoing,
630 const struct batadv_forw_packet *forw_packet)
632 struct batadv_ogm_packet *batadv_ogm_packet;
633 int aggregated_bytes = forw_packet->packet_len + packet_len;
634 struct batadv_hard_iface *primary_if = NULL;
636 unsigned long aggregation_end_time;
638 batadv_ogm_packet = (struct batadv_ogm_packet *)forw_packet->skb->data;
639 aggregation_end_time = send_time;
640 aggregation_end_time += msecs_to_jiffies(BATADV_MAX_AGGREGATION_MS);
642 /* we can aggregate the current packet to this aggregated packet
645 * - the send time is within our MAX_AGGREGATION_MS time
646 * - the resulting packet wont be bigger than
647 * MAX_AGGREGATION_BYTES
648 * otherwise aggregation is not possible
650 if (!time_before(send_time, forw_packet->send_time) ||
651 !time_after_eq(aggregation_end_time, forw_packet->send_time))
654 if (aggregated_bytes > BATADV_MAX_AGGREGATION_BYTES)
657 /* packet is not leaving on the same interface. */
658 if (forw_packet->if_outgoing != if_outgoing)
661 /* check aggregation compatibility
662 * -> direct link packets are broadcasted on
663 * their interface only
664 * -> aggregate packet if the current packet is
665 * a "global" packet as well as the base
668 primary_if = batadv_primary_if_get_selected(bat_priv);
672 /* packets without direct link flag and high TTL
673 * are flooded through the net
676 !(batadv_ogm_packet->flags & BATADV_DIRECTLINK) &&
677 batadv_ogm_packet->ttl != 1 &&
679 /* own packets originating non-primary
680 * interfaces leave only that interface
682 (!forw_packet->own ||
683 forw_packet->if_incoming == primary_if)) {
688 /* if the incoming packet is sent via this one
689 * interface only - we still can aggregate
692 new_bat_ogm_packet->ttl == 1 &&
693 forw_packet->if_incoming == if_incoming &&
695 /* packets from direct neighbors or
696 * own secondary interface packets
697 * (= secondary interface packets in general)
699 (batadv_ogm_packet->flags & BATADV_DIRECTLINK ||
701 forw_packet->if_incoming != primary_if))) {
708 batadv_hardif_put(primary_if);
713 * batadv_iv_ogm_aggregate_new() - create a new aggregated packet and add this
715 * @packet_buff: pointer to the OGM
716 * @packet_len: (total) length of the OGM
717 * @send_time: timestamp (jiffies) when the packet is to be sent
718 * @direct_link: whether this OGM has direct link status
719 * @if_incoming: interface where the packet was received
720 * @if_outgoing: interface for which the retransmission should be considered
721 * @own_packet: true if it is a self-generated ogm
723 static void batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff,
724 int packet_len, unsigned long send_time,
726 struct batadv_hard_iface *if_incoming,
727 struct batadv_hard_iface *if_outgoing,
730 struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
731 struct batadv_forw_packet *forw_packet_aggr;
733 unsigned char *skb_buff;
734 unsigned int skb_size;
735 atomic_t *queue_left = own_packet ? NULL : &bat_priv->batman_queue_left;
737 if (atomic_read(&bat_priv->aggregated_ogms) &&
738 packet_len < BATADV_MAX_AGGREGATION_BYTES)
739 skb_size = BATADV_MAX_AGGREGATION_BYTES;
741 skb_size = packet_len;
743 skb_size += ETH_HLEN;
745 skb = netdev_alloc_skb_ip_align(NULL, skb_size);
749 forw_packet_aggr = batadv_forw_packet_alloc(if_incoming, if_outgoing,
750 queue_left, bat_priv, skb);
751 if (!forw_packet_aggr) {
756 forw_packet_aggr->skb->priority = TC_PRIO_CONTROL;
757 skb_reserve(forw_packet_aggr->skb, ETH_HLEN);
759 skb_buff = skb_put(forw_packet_aggr->skb, packet_len);
760 forw_packet_aggr->packet_len = packet_len;
761 memcpy(skb_buff, packet_buff, packet_len);
763 forw_packet_aggr->own = own_packet;
764 forw_packet_aggr->direct_link_flags = BATADV_NO_FLAGS;
765 forw_packet_aggr->send_time = send_time;
767 /* save packet direct link flag status */
769 forw_packet_aggr->direct_link_flags |= 1;
771 INIT_DELAYED_WORK(&forw_packet_aggr->delayed_work,
772 batadv_iv_send_outstanding_bat_ogm_packet);
774 batadv_forw_packet_ogmv1_queue(bat_priv, forw_packet_aggr, send_time);
777 /* aggregate a new packet into the existing ogm packet */
778 static void batadv_iv_ogm_aggregate(struct batadv_forw_packet *forw_packet_aggr,
779 const unsigned char *packet_buff,
780 int packet_len, bool direct_link)
782 unsigned long new_direct_link_flag;
784 skb_put_data(forw_packet_aggr->skb, packet_buff, packet_len);
785 forw_packet_aggr->packet_len += packet_len;
786 forw_packet_aggr->num_packets++;
788 /* save packet direct link flag status */
790 new_direct_link_flag = BIT(forw_packet_aggr->num_packets);
791 forw_packet_aggr->direct_link_flags |= new_direct_link_flag;
796 * batadv_iv_ogm_queue_add() - queue up an OGM for transmission
797 * @bat_priv: the bat priv with all the soft interface information
798 * @packet_buff: pointer to the OGM
799 * @packet_len: (total) length of the OGM
800 * @if_incoming: interface where the packet was received
801 * @if_outgoing: interface for which the retransmission should be considered
802 * @own_packet: true if it is a self-generated ogm
803 * @send_time: timestamp (jiffies) when the packet is to be sent
805 static void batadv_iv_ogm_queue_add(struct batadv_priv *bat_priv,
806 unsigned char *packet_buff,
808 struct batadv_hard_iface *if_incoming,
809 struct batadv_hard_iface *if_outgoing,
810 int own_packet, unsigned long send_time)
812 /* _aggr -> pointer to the packet we want to aggregate with
813 * _pos -> pointer to the position in the queue
815 struct batadv_forw_packet *forw_packet_aggr = NULL;
816 struct batadv_forw_packet *forw_packet_pos = NULL;
817 struct batadv_ogm_packet *batadv_ogm_packet;
819 unsigned long max_aggregation_jiffies;
821 batadv_ogm_packet = (struct batadv_ogm_packet *)packet_buff;
822 direct_link = !!(batadv_ogm_packet->flags & BATADV_DIRECTLINK);
823 max_aggregation_jiffies = msecs_to_jiffies(BATADV_MAX_AGGREGATION_MS);
825 /* find position for the packet in the forward queue */
826 spin_lock_bh(&bat_priv->forw_bat_list_lock);
827 /* own packets are not to be aggregated */
828 if (atomic_read(&bat_priv->aggregated_ogms) && !own_packet) {
829 hlist_for_each_entry(forw_packet_pos,
830 &bat_priv->forw_bat_list, list) {
831 if (batadv_iv_ogm_can_aggregate(batadv_ogm_packet,
832 bat_priv, packet_len,
833 send_time, direct_link,
837 forw_packet_aggr = forw_packet_pos;
843 /* nothing to aggregate with - either aggregation disabled or no
844 * suitable aggregation packet found
846 if (!forw_packet_aggr) {
847 /* the following section can run without the lock */
848 spin_unlock_bh(&bat_priv->forw_bat_list_lock);
850 /* if we could not aggregate this packet with one of the others
851 * we hold it back for a while, so that it might be aggregated
854 if (!own_packet && atomic_read(&bat_priv->aggregated_ogms))
855 send_time += max_aggregation_jiffies;
857 batadv_iv_ogm_aggregate_new(packet_buff, packet_len,
858 send_time, direct_link,
859 if_incoming, if_outgoing,
862 batadv_iv_ogm_aggregate(forw_packet_aggr, packet_buff,
863 packet_len, direct_link);
864 spin_unlock_bh(&bat_priv->forw_bat_list_lock);
868 static void batadv_iv_ogm_forward(struct batadv_orig_node *orig_node,
869 const struct ethhdr *ethhdr,
870 struct batadv_ogm_packet *batadv_ogm_packet,
871 bool is_single_hop_neigh,
872 bool is_from_best_next_hop,
873 struct batadv_hard_iface *if_incoming,
874 struct batadv_hard_iface *if_outgoing)
876 struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
879 if (batadv_ogm_packet->ttl <= 1) {
880 batadv_dbg(BATADV_DBG_BATMAN, bat_priv, "ttl exceeded\n");
884 if (!is_from_best_next_hop) {
885 /* Mark the forwarded packet when it is not coming from our
886 * best next hop. We still need to forward the packet for our
887 * neighbor link quality detection to work in case the packet
888 * originated from a single hop neighbor. Otherwise we can
889 * simply drop the ogm.
891 if (is_single_hop_neigh)
892 batadv_ogm_packet->flags |= BATADV_NOT_BEST_NEXT_HOP;
897 tvlv_len = ntohs(batadv_ogm_packet->tvlv_len);
899 batadv_ogm_packet->ttl--;
900 ether_addr_copy(batadv_ogm_packet->prev_sender, ethhdr->h_source);
902 /* apply hop penalty */
903 batadv_ogm_packet->tq = batadv_hop_penalty(batadv_ogm_packet->tq,
906 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
907 "Forwarding packet: tq: %i, ttl: %i\n",
908 batadv_ogm_packet->tq, batadv_ogm_packet->ttl);
910 if (is_single_hop_neigh)
911 batadv_ogm_packet->flags |= BATADV_DIRECTLINK;
913 batadv_ogm_packet->flags &= ~BATADV_DIRECTLINK;
915 batadv_iv_ogm_queue_add(bat_priv, (unsigned char *)batadv_ogm_packet,
916 BATADV_OGM_HLEN + tvlv_len,
917 if_incoming, if_outgoing, 0,
918 batadv_iv_ogm_fwd_send_time());
922 * batadv_iv_ogm_slide_own_bcast_window() - bitshift own OGM broadcast windows
923 * for the given interface
924 * @hard_iface: the interface for which the windows have to be shifted
927 batadv_iv_ogm_slide_own_bcast_window(struct batadv_hard_iface *hard_iface)
929 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
930 struct batadv_hashtable *hash = bat_priv->orig_hash;
931 struct hlist_head *head;
932 struct batadv_orig_node *orig_node;
939 for (i = 0; i < hash->size; i++) {
940 head = &hash->table[i];
943 hlist_for_each_entry_rcu(orig_node, head, hash_entry) {
944 spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock);
945 word_index = hard_iface->if_num * BATADV_NUM_WORDS;
946 word = &orig_node->bat_iv.bcast_own[word_index];
948 batadv_bit_get_packet(bat_priv, word, 1, 0);
949 if_num = hard_iface->if_num;
950 w = &orig_node->bat_iv.bcast_own_sum[if_num];
951 *w = bitmap_weight(word, BATADV_TQ_LOCAL_WINDOW_SIZE);
952 spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock);
959 * batadv_iv_ogm_schedule_buff() - schedule submission of hardif ogm buffer
960 * @hard_iface: interface whose ogm buffer should be transmitted
962 static void batadv_iv_ogm_schedule_buff(struct batadv_hard_iface *hard_iface)
964 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
965 unsigned char **ogm_buff = &hard_iface->bat_iv.ogm_buff;
966 struct batadv_ogm_packet *batadv_ogm_packet;
967 struct batadv_hard_iface *primary_if, *tmp_hard_iface;
968 int *ogm_buff_len = &hard_iface->bat_iv.ogm_buff_len;
971 unsigned long send_time;
973 lockdep_assert_held(&hard_iface->bat_iv.ogm_buff_mutex);
975 /* interface already disabled by batadv_iv_ogm_iface_disable */
979 /* the interface gets activated here to avoid race conditions between
980 * the moment of activating the interface in
981 * hardif_activate_interface() where the originator mac is set and
982 * outdated packets (especially uninitialized mac addresses) in the
985 if (hard_iface->if_status == BATADV_IF_TO_BE_ACTIVATED)
986 hard_iface->if_status = BATADV_IF_ACTIVE;
988 primary_if = batadv_primary_if_get_selected(bat_priv);
990 if (hard_iface == primary_if) {
991 /* tt changes have to be committed before the tvlv data is
992 * appended as it may alter the tt tvlv container
994 batadv_tt_local_commit_changes(bat_priv);
995 tvlv_len = batadv_tvlv_container_ogm_append(bat_priv, ogm_buff,
1000 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
1001 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
1003 /* change sequence number to network order */
1004 seqno = (u32)atomic_read(&hard_iface->bat_iv.ogm_seqno);
1005 batadv_ogm_packet->seqno = htonl(seqno);
1006 atomic_inc(&hard_iface->bat_iv.ogm_seqno);
1008 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
1010 send_time = batadv_iv_ogm_emit_send_time(bat_priv);
1012 if (hard_iface != primary_if) {
1013 /* OGMs from secondary interfaces are only scheduled on their
1014 * respective interfaces.
1016 batadv_iv_ogm_queue_add(bat_priv, *ogm_buff, *ogm_buff_len,
1017 hard_iface, hard_iface, 1, send_time);
1021 /* OGMs from primary interfaces are scheduled on all
1025 list_for_each_entry_rcu(tmp_hard_iface, &batadv_hardif_list, list) {
1026 if (tmp_hard_iface->soft_iface != hard_iface->soft_iface)
1029 if (!kref_get_unless_zero(&tmp_hard_iface->refcount))
1032 batadv_iv_ogm_queue_add(bat_priv, *ogm_buff,
1033 *ogm_buff_len, hard_iface,
1034 tmp_hard_iface, 1, send_time);
1036 batadv_hardif_put(tmp_hard_iface);
1042 batadv_hardif_put(primary_if);
1045 static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
1047 if (hard_iface->if_status == BATADV_IF_NOT_IN_USE ||
1048 hard_iface->if_status == BATADV_IF_TO_BE_REMOVED)
1051 mutex_lock(&hard_iface->bat_iv.ogm_buff_mutex);
1052 batadv_iv_ogm_schedule_buff(hard_iface);
1053 mutex_unlock(&hard_iface->bat_iv.ogm_buff_mutex);
1057 * batadv_iv_ogm_orig_update() - use OGM to update corresponding data in an
1059 * @bat_priv: the bat priv with all the soft interface information
1060 * @orig_node: the orig node who originally emitted the ogm packet
1061 * @orig_ifinfo: ifinfo for the outgoing interface of the orig_node
1062 * @ethhdr: Ethernet header of the OGM
1063 * @batadv_ogm_packet: the ogm packet
1064 * @if_incoming: interface where the packet was received
1065 * @if_outgoing: interface for which the retransmission should be considered
1066 * @dup_status: the duplicate status of this ogm packet.
1069 batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv,
1070 struct batadv_orig_node *orig_node,
1071 struct batadv_orig_ifinfo *orig_ifinfo,
1072 const struct ethhdr *ethhdr,
1073 const struct batadv_ogm_packet *batadv_ogm_packet,
1074 struct batadv_hard_iface *if_incoming,
1075 struct batadv_hard_iface *if_outgoing,
1076 enum batadv_dup_status dup_status)
1078 struct batadv_neigh_ifinfo *neigh_ifinfo = NULL;
1079 struct batadv_neigh_ifinfo *router_ifinfo = NULL;
1080 struct batadv_neigh_node *neigh_node = NULL;
1081 struct batadv_neigh_node *tmp_neigh_node = NULL;
1082 struct batadv_neigh_node *router = NULL;
1083 struct batadv_orig_node *orig_node_tmp;
1084 unsigned int if_num;
1085 u8 sum_orig, sum_neigh;
1089 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1090 "%s(): Searching and updating originator entry of received packet\n",
1094 hlist_for_each_entry_rcu(tmp_neigh_node,
1095 &orig_node->neigh_list, list) {
1096 neigh_addr = tmp_neigh_node->addr;
1097 if (batadv_compare_eth(neigh_addr, ethhdr->h_source) &&
1098 tmp_neigh_node->if_incoming == if_incoming &&
1099 kref_get_unless_zero(&tmp_neigh_node->refcount)) {
1100 if (WARN(neigh_node, "too many matching neigh_nodes"))
1101 batadv_neigh_node_put(neigh_node);
1102 neigh_node = tmp_neigh_node;
1106 if (dup_status != BATADV_NO_DUP)
1109 /* only update the entry for this outgoing interface */
1110 neigh_ifinfo = batadv_neigh_ifinfo_get(tmp_neigh_node,
1115 spin_lock_bh(&tmp_neigh_node->ifinfo_lock);
1116 batadv_ring_buffer_set(neigh_ifinfo->bat_iv.tq_recv,
1117 &neigh_ifinfo->bat_iv.tq_index, 0);
1118 tq_avg = batadv_ring_buffer_avg(neigh_ifinfo->bat_iv.tq_recv);
1119 neigh_ifinfo->bat_iv.tq_avg = tq_avg;
1120 spin_unlock_bh(&tmp_neigh_node->ifinfo_lock);
1122 batadv_neigh_ifinfo_put(neigh_ifinfo);
1123 neigh_ifinfo = NULL;
1127 struct batadv_orig_node *orig_tmp;
1129 orig_tmp = batadv_iv_ogm_orig_get(bat_priv, ethhdr->h_source);
1133 neigh_node = batadv_iv_ogm_neigh_new(if_incoming,
1135 orig_node, orig_tmp);
1137 batadv_orig_node_put(orig_tmp);
1141 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1142 "Updating existing last-hop neighbor of originator\n");
1146 neigh_ifinfo = batadv_neigh_ifinfo_new(neigh_node, if_outgoing);
1150 neigh_node->last_seen = jiffies;
1152 spin_lock_bh(&neigh_node->ifinfo_lock);
1153 batadv_ring_buffer_set(neigh_ifinfo->bat_iv.tq_recv,
1154 &neigh_ifinfo->bat_iv.tq_index,
1155 batadv_ogm_packet->tq);
1156 tq_avg = batadv_ring_buffer_avg(neigh_ifinfo->bat_iv.tq_recv);
1157 neigh_ifinfo->bat_iv.tq_avg = tq_avg;
1158 spin_unlock_bh(&neigh_node->ifinfo_lock);
1160 if (dup_status == BATADV_NO_DUP) {
1161 orig_ifinfo->last_ttl = batadv_ogm_packet->ttl;
1162 neigh_ifinfo->last_ttl = batadv_ogm_packet->ttl;
1165 /* if this neighbor already is our next hop there is nothing
1168 router = batadv_orig_router_get(orig_node, if_outgoing);
1169 if (router == neigh_node)
1173 router_ifinfo = batadv_neigh_ifinfo_get(router, if_outgoing);
1177 /* if this neighbor does not offer a better TQ we won't
1180 if (router_ifinfo->bat_iv.tq_avg > neigh_ifinfo->bat_iv.tq_avg)
1184 /* if the TQ is the same and the link not more symmetric we
1185 * won't consider it either
1187 if (router_ifinfo &&
1188 neigh_ifinfo->bat_iv.tq_avg == router_ifinfo->bat_iv.tq_avg) {
1189 orig_node_tmp = router->orig_node;
1190 spin_lock_bh(&orig_node_tmp->bat_iv.ogm_cnt_lock);
1191 if_num = router->if_incoming->if_num;
1192 sum_orig = orig_node_tmp->bat_iv.bcast_own_sum[if_num];
1193 spin_unlock_bh(&orig_node_tmp->bat_iv.ogm_cnt_lock);
1195 orig_node_tmp = neigh_node->orig_node;
1196 spin_lock_bh(&orig_node_tmp->bat_iv.ogm_cnt_lock);
1197 if_num = neigh_node->if_incoming->if_num;
1198 sum_neigh = orig_node_tmp->bat_iv.bcast_own_sum[if_num];
1199 spin_unlock_bh(&orig_node_tmp->bat_iv.ogm_cnt_lock);
1201 if (sum_orig >= sum_neigh)
1205 batadv_update_route(bat_priv, orig_node, if_outgoing, neigh_node);
1212 batadv_neigh_node_put(neigh_node);
1214 batadv_neigh_node_put(router);
1216 batadv_neigh_ifinfo_put(neigh_ifinfo);
1218 batadv_neigh_ifinfo_put(router_ifinfo);
1222 * batadv_iv_ogm_calc_tq() - calculate tq for current received ogm packet
1223 * @orig_node: the orig node who originally emitted the ogm packet
1224 * @orig_neigh_node: the orig node struct of the neighbor who sent the packet
1225 * @batadv_ogm_packet: the ogm packet
1226 * @if_incoming: interface where the packet was received
1227 * @if_outgoing: interface for which the retransmission should be considered
1229 * Return: true if the link can be considered bidirectional, false otherwise
1231 static bool batadv_iv_ogm_calc_tq(struct batadv_orig_node *orig_node,
1232 struct batadv_orig_node *orig_neigh_node,
1233 struct batadv_ogm_packet *batadv_ogm_packet,
1234 struct batadv_hard_iface *if_incoming,
1235 struct batadv_hard_iface *if_outgoing)
1237 struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
1238 struct batadv_neigh_node *neigh_node = NULL, *tmp_neigh_node;
1239 struct batadv_neigh_ifinfo *neigh_ifinfo;
1241 u8 orig_eq_count, neigh_rq_count, neigh_rq_inv, tq_own;
1242 unsigned int neigh_rq_inv_cube, neigh_rq_max_cube;
1243 unsigned int if_num;
1244 unsigned int tq_asym_penalty, inv_asym_penalty;
1245 unsigned int combined_tq;
1246 unsigned int tq_iface_penalty;
1249 /* find corresponding one hop neighbor */
1251 hlist_for_each_entry_rcu(tmp_neigh_node,
1252 &orig_neigh_node->neigh_list, list) {
1253 if (!batadv_compare_eth(tmp_neigh_node->addr,
1254 orig_neigh_node->orig))
1257 if (tmp_neigh_node->if_incoming != if_incoming)
1260 if (!kref_get_unless_zero(&tmp_neigh_node->refcount))
1263 neigh_node = tmp_neigh_node;
1269 neigh_node = batadv_iv_ogm_neigh_new(if_incoming,
1270 orig_neigh_node->orig,
1277 /* if orig_node is direct neighbor update neigh_node last_seen */
1278 if (orig_node == orig_neigh_node)
1279 neigh_node->last_seen = jiffies;
1281 orig_node->last_seen = jiffies;
1283 /* find packet count of corresponding one hop neighbor */
1284 spin_lock_bh(&orig_neigh_node->bat_iv.ogm_cnt_lock);
1285 if_num = if_incoming->if_num;
1286 orig_eq_count = orig_neigh_node->bat_iv.bcast_own_sum[if_num];
1287 neigh_ifinfo = batadv_neigh_ifinfo_new(neigh_node, if_outgoing);
1289 neigh_rq_count = neigh_ifinfo->bat_iv.real_packet_count;
1290 batadv_neigh_ifinfo_put(neigh_ifinfo);
1294 spin_unlock_bh(&orig_neigh_node->bat_iv.ogm_cnt_lock);
1296 /* pay attention to not get a value bigger than 100 % */
1297 if (orig_eq_count > neigh_rq_count)
1298 total_count = neigh_rq_count;
1300 total_count = orig_eq_count;
1302 /* if we have too few packets (too less data) we set tq_own to zero
1303 * if we receive too few packets it is not considered bidirectional
1305 if (total_count < BATADV_TQ_LOCAL_BIDRECT_SEND_MINIMUM ||
1306 neigh_rq_count < BATADV_TQ_LOCAL_BIDRECT_RECV_MINIMUM)
1309 /* neigh_node->real_packet_count is never zero as we
1310 * only purge old information when getting new
1313 tq_own = (BATADV_TQ_MAX_VALUE * total_count) / neigh_rq_count;
1315 /* 1 - ((1-x) ** 3), normalized to TQ_MAX_VALUE this does
1316 * affect the nearly-symmetric links only a little, but
1317 * punishes asymmetric links more. This will give a value
1318 * between 0 and TQ_MAX_VALUE
1320 neigh_rq_inv = BATADV_TQ_LOCAL_WINDOW_SIZE - neigh_rq_count;
1321 neigh_rq_inv_cube = neigh_rq_inv * neigh_rq_inv * neigh_rq_inv;
1322 neigh_rq_max_cube = BATADV_TQ_LOCAL_WINDOW_SIZE *
1323 BATADV_TQ_LOCAL_WINDOW_SIZE *
1324 BATADV_TQ_LOCAL_WINDOW_SIZE;
1325 inv_asym_penalty = BATADV_TQ_MAX_VALUE * neigh_rq_inv_cube;
1326 inv_asym_penalty /= neigh_rq_max_cube;
1327 tq_asym_penalty = BATADV_TQ_MAX_VALUE - inv_asym_penalty;
1329 /* penalize if the OGM is forwarded on the same interface. WiFi
1330 * interfaces and other half duplex devices suffer from throughput
1331 * drops as they can't send and receive at the same time.
1333 tq_iface_penalty = BATADV_TQ_MAX_VALUE;
1334 if (if_outgoing && if_incoming == if_outgoing &&
1335 batadv_is_wifi_hardif(if_outgoing))
1336 tq_iface_penalty = batadv_hop_penalty(BATADV_TQ_MAX_VALUE,
1339 combined_tq = batadv_ogm_packet->tq *
1343 combined_tq /= BATADV_TQ_MAX_VALUE *
1344 BATADV_TQ_MAX_VALUE *
1345 BATADV_TQ_MAX_VALUE;
1346 batadv_ogm_packet->tq = combined_tq;
1348 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1349 "bidirectional: orig = %pM neigh = %pM => own_bcast = %2i, real recv = %2i, local tq: %3i, asym_penalty: %3i, iface_penalty: %3i, total tq: %3i, if_incoming = %s, if_outgoing = %s\n",
1350 orig_node->orig, orig_neigh_node->orig, total_count,
1351 neigh_rq_count, tq_own, tq_asym_penalty, tq_iface_penalty,
1352 batadv_ogm_packet->tq, if_incoming->net_dev->name,
1353 if_outgoing ? if_outgoing->net_dev->name : "DEFAULT");
1355 /* if link has the minimum required transmission quality
1356 * consider it bidirectional
1358 if (batadv_ogm_packet->tq >= BATADV_TQ_TOTAL_BIDRECT_LIMIT)
1363 batadv_neigh_node_put(neigh_node);
1368 * batadv_iv_ogm_update_seqnos() - process a batman packet for all interfaces,
1369 * adjust the sequence number and find out whether it is a duplicate
1370 * @ethhdr: ethernet header of the packet
1371 * @batadv_ogm_packet: OGM packet to be considered
1372 * @if_incoming: interface on which the OGM packet was received
1373 * @if_outgoing: interface for which the retransmission should be considered
1375 * Return: duplicate status as enum batadv_dup_status
1377 static enum batadv_dup_status
1378 batadv_iv_ogm_update_seqnos(const struct ethhdr *ethhdr,
1379 const struct batadv_ogm_packet *batadv_ogm_packet,
1380 const struct batadv_hard_iface *if_incoming,
1381 struct batadv_hard_iface *if_outgoing)
1383 struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
1384 struct batadv_orig_node *orig_node;
1385 struct batadv_orig_ifinfo *orig_ifinfo = NULL;
1386 struct batadv_neigh_node *neigh_node;
1387 struct batadv_neigh_ifinfo *neigh_ifinfo;
1390 bool need_update = false;
1392 enum batadv_dup_status ret = BATADV_NO_DUP;
1393 u32 seqno = ntohl(batadv_ogm_packet->seqno);
1396 unsigned long *bitmap;
1398 orig_node = batadv_iv_ogm_orig_get(bat_priv, batadv_ogm_packet->orig);
1400 return BATADV_NO_DUP;
1402 orig_ifinfo = batadv_orig_ifinfo_new(orig_node, if_outgoing);
1403 if (WARN_ON(!orig_ifinfo)) {
1404 batadv_orig_node_put(orig_node);
1408 spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock);
1409 seq_diff = seqno - orig_ifinfo->last_real_seqno;
1411 /* signalize caller that the packet is to be dropped. */
1412 if (!hlist_empty(&orig_node->neigh_list) &&
1413 batadv_window_protected(bat_priv, seq_diff,
1414 BATADV_TQ_LOCAL_WINDOW_SIZE,
1415 &orig_ifinfo->batman_seqno_reset, NULL)) {
1416 ret = BATADV_PROTECTED;
1421 hlist_for_each_entry_rcu(neigh_node, &orig_node->neigh_list, list) {
1422 neigh_ifinfo = batadv_neigh_ifinfo_new(neigh_node,
1427 neigh_addr = neigh_node->addr;
1428 is_dup = batadv_test_bit(neigh_ifinfo->bat_iv.real_bits,
1429 orig_ifinfo->last_real_seqno,
1432 if (batadv_compare_eth(neigh_addr, ethhdr->h_source) &&
1433 neigh_node->if_incoming == if_incoming) {
1436 ret = BATADV_NEIGH_DUP;
1439 if (is_dup && ret != BATADV_NEIGH_DUP)
1440 ret = BATADV_ORIG_DUP;
1443 /* if the window moved, set the update flag. */
1444 bitmap = neigh_ifinfo->bat_iv.real_bits;
1445 need_update |= batadv_bit_get_packet(bat_priv, bitmap,
1446 seq_diff, set_mark);
1448 packet_count = bitmap_weight(bitmap,
1449 BATADV_TQ_LOCAL_WINDOW_SIZE);
1450 neigh_ifinfo->bat_iv.real_packet_count = packet_count;
1451 batadv_neigh_ifinfo_put(neigh_ifinfo);
1456 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1457 "%s updating last_seqno: old %u, new %u\n",
1458 if_outgoing ? if_outgoing->net_dev->name : "DEFAULT",
1459 orig_ifinfo->last_real_seqno, seqno);
1460 orig_ifinfo->last_real_seqno = seqno;
1464 spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock);
1465 batadv_orig_node_put(orig_node);
1466 batadv_orig_ifinfo_put(orig_ifinfo);
1471 * batadv_iv_ogm_process_per_outif() - process a batman iv OGM for an outgoing
1473 * @skb: the skb containing the OGM
1474 * @ogm_offset: offset from skb->data to start of ogm header
1475 * @orig_node: the (cached) orig node for the originator of this OGM
1476 * @if_incoming: the interface where this packet was received
1477 * @if_outgoing: the interface for which the packet should be considered
1480 batadv_iv_ogm_process_per_outif(const struct sk_buff *skb, int ogm_offset,
1481 struct batadv_orig_node *orig_node,
1482 struct batadv_hard_iface *if_incoming,
1483 struct batadv_hard_iface *if_outgoing)
1485 struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
1486 struct batadv_hardif_neigh_node *hardif_neigh = NULL;
1487 struct batadv_neigh_node *router = NULL;
1488 struct batadv_neigh_node *router_router = NULL;
1489 struct batadv_orig_node *orig_neigh_node;
1490 struct batadv_orig_ifinfo *orig_ifinfo;
1491 struct batadv_neigh_node *orig_neigh_router = NULL;
1492 struct batadv_neigh_ifinfo *router_ifinfo = NULL;
1493 struct batadv_ogm_packet *ogm_packet;
1494 enum batadv_dup_status dup_status;
1495 bool is_from_best_next_hop = false;
1496 bool is_single_hop_neigh = false;
1497 bool sameseq, similar_ttl;
1498 struct sk_buff *skb_priv;
1499 struct ethhdr *ethhdr;
1503 /* create a private copy of the skb, as some functions change tq value
1506 skb_priv = skb_copy(skb, GFP_ATOMIC);
1510 ethhdr = eth_hdr(skb_priv);
1511 ogm_packet = (struct batadv_ogm_packet *)(skb_priv->data + ogm_offset);
1513 dup_status = batadv_iv_ogm_update_seqnos(ethhdr, ogm_packet,
1514 if_incoming, if_outgoing);
1515 if (batadv_compare_eth(ethhdr->h_source, ogm_packet->orig))
1516 is_single_hop_neigh = true;
1518 if (dup_status == BATADV_PROTECTED) {
1519 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1520 "Drop packet: packet within seqno protection time (sender: %pM)\n",
1525 if (ogm_packet->tq == 0) {
1526 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1527 "Drop packet: originator packet with tq equal 0\n");
1531 if (is_single_hop_neigh) {
1532 hardif_neigh = batadv_hardif_neigh_get(if_incoming,
1535 hardif_neigh->last_seen = jiffies;
1538 router = batadv_orig_router_get(orig_node, if_outgoing);
1540 router_router = batadv_orig_router_get(router->orig_node,
1542 router_ifinfo = batadv_neigh_ifinfo_get(router, if_outgoing);
1545 if ((router_ifinfo && router_ifinfo->bat_iv.tq_avg != 0) &&
1546 (batadv_compare_eth(router->addr, ethhdr->h_source)))
1547 is_from_best_next_hop = true;
1549 prev_sender = ogm_packet->prev_sender;
1550 /* avoid temporary routing loops */
1551 if (router && router_router &&
1552 (batadv_compare_eth(router->addr, prev_sender)) &&
1553 !(batadv_compare_eth(ogm_packet->orig, prev_sender)) &&
1554 (batadv_compare_eth(router->addr, router_router->addr))) {
1555 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1556 "Drop packet: ignoring all rebroadcast packets that may make me loop (sender: %pM)\n",
1561 if (if_outgoing == BATADV_IF_DEFAULT)
1562 batadv_tvlv_ogm_receive(bat_priv, ogm_packet, orig_node);
1564 /* if sender is a direct neighbor the sender mac equals
1567 if (is_single_hop_neigh)
1568 orig_neigh_node = orig_node;
1570 orig_neigh_node = batadv_iv_ogm_orig_get(bat_priv,
1573 if (!orig_neigh_node)
1576 /* Update nc_nodes of the originator */
1577 batadv_nc_update_nc_node(bat_priv, orig_node, orig_neigh_node,
1578 ogm_packet, is_single_hop_neigh);
1580 orig_neigh_router = batadv_orig_router_get(orig_neigh_node,
1583 /* drop packet if sender is not a direct neighbor and if we
1584 * don't route towards it
1586 if (!is_single_hop_neigh && !orig_neigh_router) {
1587 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1588 "Drop packet: OGM via unknown neighbor!\n");
1592 is_bidirect = batadv_iv_ogm_calc_tq(orig_node, orig_neigh_node,
1593 ogm_packet, if_incoming,
1596 /* update ranking if it is not a duplicate or has the same
1597 * seqno and similar ttl as the non-duplicate
1599 orig_ifinfo = batadv_orig_ifinfo_new(orig_node, if_outgoing);
1603 sameseq = orig_ifinfo->last_real_seqno == ntohl(ogm_packet->seqno);
1604 similar_ttl = (orig_ifinfo->last_ttl - 3) <= ogm_packet->ttl;
1606 if (is_bidirect && (dup_status == BATADV_NO_DUP ||
1607 (sameseq && similar_ttl))) {
1608 batadv_iv_ogm_orig_update(bat_priv, orig_node,
1609 orig_ifinfo, ethhdr,
1610 ogm_packet, if_incoming,
1611 if_outgoing, dup_status);
1613 batadv_orig_ifinfo_put(orig_ifinfo);
1615 /* only forward for specific interface, not for the default one. */
1616 if (if_outgoing == BATADV_IF_DEFAULT)
1619 /* is single hop (direct) neighbor */
1620 if (is_single_hop_neigh) {
1621 /* OGMs from secondary interfaces should only scheduled once
1622 * per interface where it has been received, not multiple times
1624 if (ogm_packet->ttl <= 2 &&
1625 if_incoming != if_outgoing) {
1626 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1627 "Drop packet: OGM from secondary interface and wrong outgoing interface\n");
1630 /* mark direct link on incoming interface */
1631 batadv_iv_ogm_forward(orig_node, ethhdr, ogm_packet,
1632 is_single_hop_neigh,
1633 is_from_best_next_hop, if_incoming,
1636 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1637 "Forwarding packet: rebroadcast neighbor packet with direct link flag\n");
1641 /* multihop originator */
1643 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1644 "Drop packet: not received via bidirectional link\n");
1648 if (dup_status == BATADV_NEIGH_DUP) {
1649 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1650 "Drop packet: duplicate packet received\n");
1654 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1655 "Forwarding packet: rebroadcast originator packet\n");
1656 batadv_iv_ogm_forward(orig_node, ethhdr, ogm_packet,
1657 is_single_hop_neigh, is_from_best_next_hop,
1658 if_incoming, if_outgoing);
1661 if (orig_neigh_node && !is_single_hop_neigh)
1662 batadv_orig_node_put(orig_neigh_node);
1665 batadv_neigh_ifinfo_put(router_ifinfo);
1667 batadv_neigh_node_put(router);
1669 batadv_neigh_node_put(router_router);
1670 if (orig_neigh_router)
1671 batadv_neigh_node_put(orig_neigh_router);
1673 batadv_hardif_neigh_put(hardif_neigh);
1675 consume_skb(skb_priv);
1679 * batadv_iv_ogm_process() - process an incoming batman iv OGM
1680 * @skb: the skb containing the OGM
1681 * @ogm_offset: offset to the OGM which should be processed (for aggregates)
1682 * @if_incoming: the interface where this packet was receved
1684 static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
1685 struct batadv_hard_iface *if_incoming)
1687 struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
1688 struct batadv_orig_node *orig_neigh_node, *orig_node;
1689 struct batadv_hard_iface *hard_iface;
1690 struct batadv_ogm_packet *ogm_packet;
1691 u32 if_incoming_seqno;
1692 bool has_directlink_flag;
1693 struct ethhdr *ethhdr;
1694 bool is_my_oldorig = false;
1695 bool is_my_addr = false;
1696 bool is_my_orig = false;
1698 ogm_packet = (struct batadv_ogm_packet *)(skb->data + ogm_offset);
1699 ethhdr = eth_hdr(skb);
1701 /* Silently drop when the batman packet is actually not a
1704 * This might happen if a packet is padded (e.g. Ethernet has a
1705 * minimum frame length of 64 byte) and the aggregation interprets
1706 * it as an additional length.
1708 * TODO: A more sane solution would be to have a bit in the
1709 * batadv_ogm_packet to detect whether the packet is the last
1710 * packet in an aggregation. Here we expect that the padding
1711 * is always zero (or not 0x01)
1713 if (ogm_packet->packet_type != BATADV_IV_OGM)
1716 /* could be changed by schedule_own_packet() */
1717 if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
1719 if (ogm_packet->flags & BATADV_DIRECTLINK)
1720 has_directlink_flag = true;
1722 has_directlink_flag = false;
1724 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1725 "Received BATMAN packet via NB: %pM, IF: %s [%pM] (from OG: %pM, via prev OG: %pM, seqno %u, tq %d, TTL %d, V %d, IDF %d)\n",
1726 ethhdr->h_source, if_incoming->net_dev->name,
1727 if_incoming->net_dev->dev_addr, ogm_packet->orig,
1728 ogm_packet->prev_sender, ntohl(ogm_packet->seqno),
1729 ogm_packet->tq, ogm_packet->ttl,
1730 ogm_packet->version, has_directlink_flag);
1733 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
1734 if (hard_iface->if_status != BATADV_IF_ACTIVE)
1737 if (hard_iface->soft_iface != if_incoming->soft_iface)
1740 if (batadv_compare_eth(ethhdr->h_source,
1741 hard_iface->net_dev->dev_addr))
1744 if (batadv_compare_eth(ogm_packet->orig,
1745 hard_iface->net_dev->dev_addr))
1748 if (batadv_compare_eth(ogm_packet->prev_sender,
1749 hard_iface->net_dev->dev_addr))
1750 is_my_oldorig = true;
1755 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1756 "Drop packet: received my own broadcast (sender: %pM)\n",
1762 unsigned long *word;
1765 unsigned int if_num;
1768 orig_neigh_node = batadv_iv_ogm_orig_get(bat_priv,
1770 if (!orig_neigh_node)
1773 /* neighbor has to indicate direct link and it has to
1774 * come via the corresponding interface
1775 * save packet seqno for bidirectional check
1777 if (has_directlink_flag &&
1778 batadv_compare_eth(if_incoming->net_dev->dev_addr,
1779 ogm_packet->orig)) {
1780 if_num = if_incoming->if_num;
1781 offset = if_num * BATADV_NUM_WORDS;
1783 spin_lock_bh(&orig_neigh_node->bat_iv.ogm_cnt_lock);
1784 word = &orig_neigh_node->bat_iv.bcast_own[offset];
1785 bit_pos = if_incoming_seqno - 2;
1786 bit_pos -= ntohl(ogm_packet->seqno);
1787 batadv_set_bit(word, bit_pos);
1788 weight = &orig_neigh_node->bat_iv.bcast_own_sum[if_num];
1789 *weight = bitmap_weight(word,
1790 BATADV_TQ_LOCAL_WINDOW_SIZE);
1791 spin_unlock_bh(&orig_neigh_node->bat_iv.ogm_cnt_lock);
1794 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1795 "Drop packet: originator packet from myself (via neighbor)\n");
1796 batadv_orig_node_put(orig_neigh_node);
1800 if (is_my_oldorig) {
1801 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1802 "Drop packet: ignoring all rebroadcast echos (sender: %pM)\n",
1807 if (ogm_packet->flags & BATADV_NOT_BEST_NEXT_HOP) {
1808 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1809 "Drop packet: ignoring all packets not forwarded from the best next hop (sender: %pM)\n",
1814 orig_node = batadv_iv_ogm_orig_get(bat_priv, ogm_packet->orig);
1818 batadv_iv_ogm_process_per_outif(skb, ogm_offset, orig_node,
1819 if_incoming, BATADV_IF_DEFAULT);
1822 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
1823 if (hard_iface->if_status != BATADV_IF_ACTIVE)
1826 if (hard_iface->soft_iface != bat_priv->soft_iface)
1829 if (!kref_get_unless_zero(&hard_iface->refcount))
1832 batadv_iv_ogm_process_per_outif(skb, ogm_offset, orig_node,
1833 if_incoming, hard_iface);
1835 batadv_hardif_put(hard_iface);
1839 batadv_orig_node_put(orig_node);
1842 static void batadv_iv_send_outstanding_bat_ogm_packet(struct work_struct *work)
1844 struct delayed_work *delayed_work;
1845 struct batadv_forw_packet *forw_packet;
1846 struct batadv_priv *bat_priv;
1847 bool dropped = false;
1849 delayed_work = to_delayed_work(work);
1850 forw_packet = container_of(delayed_work, struct batadv_forw_packet,
1852 bat_priv = netdev_priv(forw_packet->if_incoming->soft_iface);
1854 if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_DEACTIVATING) {
1859 batadv_iv_ogm_emit(forw_packet);
1861 /* we have to have at least one packet in the queue to determine the
1862 * queues wake up time unless we are shutting down.
1864 * only re-schedule if this is the "original" copy, e.g. the OGM of the
1865 * primary interface should only be rescheduled once per period, but
1866 * this function will be called for the forw_packet instances of the
1867 * other secondary interfaces as well.
1869 if (forw_packet->own &&
1870 forw_packet->if_incoming == forw_packet->if_outgoing)
1871 batadv_iv_ogm_schedule(forw_packet->if_incoming);
1874 /* do we get something for free()? */
1875 if (batadv_forw_packet_steal(forw_packet,
1876 &bat_priv->forw_bat_list_lock))
1877 batadv_forw_packet_free(forw_packet, dropped);
1880 static int batadv_iv_ogm_receive(struct sk_buff *skb,
1881 struct batadv_hard_iface *if_incoming)
1883 struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
1884 struct batadv_ogm_packet *ogm_packet;
1888 int ret = NET_RX_DROP;
1890 res = batadv_check_management_packet(skb, if_incoming, BATADV_OGM_HLEN);
1894 /* did we receive a B.A.T.M.A.N. IV OGM packet on an interface
1895 * that does not have B.A.T.M.A.N. IV enabled ?
1897 if (bat_priv->algo_ops->iface.enable != batadv_iv_ogm_iface_enable)
1900 batadv_inc_counter(bat_priv, BATADV_CNT_MGMT_RX);
1901 batadv_add_counter(bat_priv, BATADV_CNT_MGMT_RX_BYTES,
1902 skb->len + ETH_HLEN);
1905 ogm_packet = (struct batadv_ogm_packet *)skb->data;
1907 /* unpack the aggregated packets and process them one by one */
1908 while (batadv_iv_ogm_aggr_packet(ogm_offset, skb_headlen(skb),
1910 batadv_iv_ogm_process(skb, ogm_offset, if_incoming);
1912 ogm_offset += BATADV_OGM_HLEN;
1913 ogm_offset += ntohs(ogm_packet->tvlv_len);
1915 packet_pos = skb->data + ogm_offset;
1916 ogm_packet = (struct batadv_ogm_packet *)packet_pos;
1919 ret = NET_RX_SUCCESS;
1922 if (ret == NET_RX_SUCCESS)
1930 #ifdef CONFIG_BATMAN_ADV_DEBUGFS
1932 * batadv_iv_ogm_orig_print_neigh() - print neighbors for the originator table
1933 * @orig_node: the orig_node for which the neighbors are printed
1934 * @if_outgoing: outgoing interface for these entries
1935 * @seq: debugfs table seq_file struct
1937 * Must be called while holding an rcu lock.
1940 batadv_iv_ogm_orig_print_neigh(struct batadv_orig_node *orig_node,
1941 struct batadv_hard_iface *if_outgoing,
1942 struct seq_file *seq)
1944 struct batadv_neigh_node *neigh_node;
1945 struct batadv_neigh_ifinfo *n_ifinfo;
1947 hlist_for_each_entry_rcu(neigh_node, &orig_node->neigh_list, list) {
1948 n_ifinfo = batadv_neigh_ifinfo_get(neigh_node, if_outgoing);
1952 seq_printf(seq, " %pM (%3i)",
1954 n_ifinfo->bat_iv.tq_avg);
1956 batadv_neigh_ifinfo_put(n_ifinfo);
1961 * batadv_iv_ogm_orig_print() - print the originator table
1962 * @bat_priv: the bat priv with all the soft interface information
1963 * @seq: debugfs table seq_file struct
1964 * @if_outgoing: the outgoing interface for which this should be printed
1966 static void batadv_iv_ogm_orig_print(struct batadv_priv *bat_priv,
1967 struct seq_file *seq,
1968 struct batadv_hard_iface *if_outgoing)
1970 struct batadv_neigh_node *neigh_node;
1971 struct batadv_hashtable *hash = bat_priv->orig_hash;
1972 int last_seen_msecs, last_seen_secs;
1973 struct batadv_orig_node *orig_node;
1974 struct batadv_neigh_ifinfo *n_ifinfo;
1975 unsigned long last_seen_jiffies;
1976 struct hlist_head *head;
1977 int batman_count = 0;
1981 " Originator last-seen (#/255) Nexthop [outgoingIF]: Potential nexthops ...\n");
1983 for (i = 0; i < hash->size; i++) {
1984 head = &hash->table[i];
1987 hlist_for_each_entry_rcu(orig_node, head, hash_entry) {
1988 neigh_node = batadv_orig_router_get(orig_node,
1993 n_ifinfo = batadv_neigh_ifinfo_get(neigh_node,
1998 if (n_ifinfo->bat_iv.tq_avg == 0)
2001 last_seen_jiffies = jiffies - orig_node->last_seen;
2002 last_seen_msecs = jiffies_to_msecs(last_seen_jiffies);
2003 last_seen_secs = last_seen_msecs / 1000;
2004 last_seen_msecs = last_seen_msecs % 1000;
2006 seq_printf(seq, "%pM %4i.%03is (%3i) %pM [%10s]:",
2007 orig_node->orig, last_seen_secs,
2008 last_seen_msecs, n_ifinfo->bat_iv.tq_avg,
2010 neigh_node->if_incoming->net_dev->name);
2012 batadv_iv_ogm_orig_print_neigh(orig_node, if_outgoing,
2014 seq_putc(seq, '\n');
2018 batadv_neigh_node_put(neigh_node);
2020 batadv_neigh_ifinfo_put(n_ifinfo);
2025 if (batman_count == 0)
2026 seq_puts(seq, "No batman nodes in range ...\n");
2031 * batadv_iv_ogm_neigh_get_tq_avg() - Get the TQ average for a neighbour on a
2032 * given outgoing interface.
2033 * @neigh_node: Neighbour of interest
2034 * @if_outgoing: Outgoing interface of interest
2035 * @tq_avg: Pointer of where to store the TQ average
2037 * Return: False if no average TQ available, otherwise true.
2040 batadv_iv_ogm_neigh_get_tq_avg(struct batadv_neigh_node *neigh_node,
2041 struct batadv_hard_iface *if_outgoing,
2044 struct batadv_neigh_ifinfo *n_ifinfo;
2046 n_ifinfo = batadv_neigh_ifinfo_get(neigh_node, if_outgoing);
2050 *tq_avg = n_ifinfo->bat_iv.tq_avg;
2051 batadv_neigh_ifinfo_put(n_ifinfo);
2057 * batadv_iv_ogm_orig_dump_subentry() - Dump an originator subentry into a
2059 * @msg: Netlink message to dump into
2060 * @portid: Port making netlink request
2061 * @seq: Sequence number of netlink message
2062 * @bat_priv: The bat priv with all the soft interface information
2063 * @if_outgoing: Limit dump to entries with this outgoing interface
2064 * @orig_node: Originator to dump
2065 * @neigh_node: Single hops neighbour
2066 * @best: Is the best originator
2068 * Return: Error code, or 0 on success
2071 batadv_iv_ogm_orig_dump_subentry(struct sk_buff *msg, u32 portid, u32 seq,
2072 struct batadv_priv *bat_priv,
2073 struct batadv_hard_iface *if_outgoing,
2074 struct batadv_orig_node *orig_node,
2075 struct batadv_neigh_node *neigh_node,
2080 unsigned int last_seen_msecs;
2082 last_seen_msecs = jiffies_to_msecs(jiffies - orig_node->last_seen);
2084 if (!batadv_iv_ogm_neigh_get_tq_avg(neigh_node, if_outgoing, &tq_avg))
2087 if (if_outgoing != BATADV_IF_DEFAULT &&
2088 if_outgoing != neigh_node->if_incoming)
2091 hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family,
2092 NLM_F_MULTI, BATADV_CMD_GET_ORIGINATORS);
2096 if (nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN,
2098 nla_put(msg, BATADV_ATTR_NEIGH_ADDRESS, ETH_ALEN,
2099 neigh_node->addr) ||
2100 nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX,
2101 neigh_node->if_incoming->net_dev->ifindex) ||
2102 nla_put_u8(msg, BATADV_ATTR_TQ, tq_avg) ||
2103 nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS,
2105 goto nla_put_failure;
2107 if (best && nla_put_flag(msg, BATADV_ATTR_FLAG_BEST))
2108 goto nla_put_failure;
2110 genlmsg_end(msg, hdr);
2114 genlmsg_cancel(msg, hdr);
2119 * batadv_iv_ogm_orig_dump_entry() - Dump an originator entry into a message
2120 * @msg: Netlink message to dump into
2121 * @portid: Port making netlink request
2122 * @seq: Sequence number of netlink message
2123 * @bat_priv: The bat priv with all the soft interface information
2124 * @if_outgoing: Limit dump to entries with this outgoing interface
2125 * @orig_node: Originator to dump
2126 * @sub_s: Number of sub entries to skip
2128 * This function assumes the caller holds rcu_read_lock().
2130 * Return: Error code, or 0 on success
2133 batadv_iv_ogm_orig_dump_entry(struct sk_buff *msg, u32 portid, u32 seq,
2134 struct batadv_priv *bat_priv,
2135 struct batadv_hard_iface *if_outgoing,
2136 struct batadv_orig_node *orig_node, int *sub_s)
2138 struct batadv_neigh_node *neigh_node_best;
2139 struct batadv_neigh_node *neigh_node;
2144 neigh_node_best = batadv_orig_router_get(orig_node, if_outgoing);
2145 if (!neigh_node_best)
2148 if (!batadv_iv_ogm_neigh_get_tq_avg(neigh_node_best, if_outgoing,
2152 if (tq_avg_best == 0)
2155 hlist_for_each_entry_rcu(neigh_node, &orig_node->neigh_list, list) {
2159 best = (neigh_node == neigh_node_best);
2161 if (batadv_iv_ogm_orig_dump_subentry(msg, portid, seq,
2162 bat_priv, if_outgoing,
2163 orig_node, neigh_node,
2165 batadv_neigh_node_put(neigh_node_best);
2173 if (neigh_node_best)
2174 batadv_neigh_node_put(neigh_node_best);
2181 * batadv_iv_ogm_orig_dump_bucket() - Dump an originator bucket into a
2183 * @msg: Netlink message to dump into
2184 * @portid: Port making netlink request
2185 * @seq: Sequence number of netlink message
2186 * @bat_priv: The bat priv with all the soft interface information
2187 * @if_outgoing: Limit dump to entries with this outgoing interface
2188 * @head: Bucket to be dumped
2189 * @idx_s: Number of entries to be skipped
2190 * @sub: Number of sub entries to be skipped
2192 * Return: Error code, or 0 on success
2195 batadv_iv_ogm_orig_dump_bucket(struct sk_buff *msg, u32 portid, u32 seq,
2196 struct batadv_priv *bat_priv,
2197 struct batadv_hard_iface *if_outgoing,
2198 struct hlist_head *head, int *idx_s, int *sub)
2200 struct batadv_orig_node *orig_node;
2204 hlist_for_each_entry_rcu(orig_node, head, hash_entry) {
2208 if (batadv_iv_ogm_orig_dump_entry(msg, portid, seq, bat_priv,
2209 if_outgoing, orig_node,
2224 * batadv_iv_ogm_orig_dump() - Dump the originators into a message
2225 * @msg: Netlink message to dump into
2226 * @cb: Control block containing additional options
2227 * @bat_priv: The bat priv with all the soft interface information
2228 * @if_outgoing: Limit dump to entries with this outgoing interface
2231 batadv_iv_ogm_orig_dump(struct sk_buff *msg, struct netlink_callback *cb,
2232 struct batadv_priv *bat_priv,
2233 struct batadv_hard_iface *if_outgoing)
2235 struct batadv_hashtable *hash = bat_priv->orig_hash;
2236 struct hlist_head *head;
2237 int bucket = cb->args[0];
2238 int idx = cb->args[1];
2239 int sub = cb->args[2];
2240 int portid = NETLINK_CB(cb->skb).portid;
2242 while (bucket < hash->size) {
2243 head = &hash->table[bucket];
2245 if (batadv_iv_ogm_orig_dump_bucket(msg, portid,
2247 bat_priv, if_outgoing, head,
2254 cb->args[0] = bucket;
2259 #ifdef CONFIG_BATMAN_ADV_DEBUGFS
2261 * batadv_iv_hardif_neigh_print() - print a single hop neighbour node
2262 * @seq: neighbour table seq_file struct
2263 * @hardif_neigh: hardif neighbour information
2266 batadv_iv_hardif_neigh_print(struct seq_file *seq,
2267 struct batadv_hardif_neigh_node *hardif_neigh)
2269 int last_secs, last_msecs;
2271 last_secs = jiffies_to_msecs(jiffies - hardif_neigh->last_seen) / 1000;
2272 last_msecs = jiffies_to_msecs(jiffies - hardif_neigh->last_seen) % 1000;
2274 seq_printf(seq, " %10s %pM %4i.%03is\n",
2275 hardif_neigh->if_incoming->net_dev->name,
2276 hardif_neigh->addr, last_secs, last_msecs);
2280 * batadv_iv_ogm_neigh_print() - print the single hop neighbour list
2281 * @bat_priv: the bat priv with all the soft interface information
2282 * @seq: neighbour table seq_file struct
2284 static void batadv_iv_neigh_print(struct batadv_priv *bat_priv,
2285 struct seq_file *seq)
2287 struct net_device *net_dev = (struct net_device *)seq->private;
2288 struct batadv_hardif_neigh_node *hardif_neigh;
2289 struct batadv_hard_iface *hard_iface;
2290 int batman_count = 0;
2292 seq_puts(seq, " IF Neighbor last-seen\n");
2295 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
2296 if (hard_iface->soft_iface != net_dev)
2299 hlist_for_each_entry_rcu(hardif_neigh,
2300 &hard_iface->neigh_list, list) {
2301 batadv_iv_hardif_neigh_print(seq, hardif_neigh);
2307 if (batman_count == 0)
2308 seq_puts(seq, "No batman nodes in range ...\n");
2313 * batadv_iv_ogm_neigh_diff() - calculate tq difference of two neighbors
2314 * @neigh1: the first neighbor object of the comparison
2315 * @if_outgoing1: outgoing interface for the first neighbor
2316 * @neigh2: the second neighbor object of the comparison
2317 * @if_outgoing2: outgoing interface for the second neighbor
2318 * @diff: pointer to integer receiving the calculated difference
2320 * The content of *@diff is only valid when this function returns true.
2321 * It is less, equal to or greater than 0 if the metric via neigh1 is lower,
2322 * the same as or higher than the metric via neigh2
2324 * Return: true when the difference could be calculated, false otherwise
2326 static bool batadv_iv_ogm_neigh_diff(struct batadv_neigh_node *neigh1,
2327 struct batadv_hard_iface *if_outgoing1,
2328 struct batadv_neigh_node *neigh2,
2329 struct batadv_hard_iface *if_outgoing2,
2332 struct batadv_neigh_ifinfo *neigh1_ifinfo, *neigh2_ifinfo;
2336 neigh1_ifinfo = batadv_neigh_ifinfo_get(neigh1, if_outgoing1);
2337 neigh2_ifinfo = batadv_neigh_ifinfo_get(neigh2, if_outgoing2);
2339 if (!neigh1_ifinfo || !neigh2_ifinfo) {
2344 tq1 = neigh1_ifinfo->bat_iv.tq_avg;
2345 tq2 = neigh2_ifinfo->bat_iv.tq_avg;
2346 *diff = (int)tq1 - (int)tq2;
2350 batadv_neigh_ifinfo_put(neigh1_ifinfo);
2352 batadv_neigh_ifinfo_put(neigh2_ifinfo);
2358 * batadv_iv_ogm_neigh_dump_neigh() - Dump a neighbour into a netlink message
2359 * @msg: Netlink message to dump into
2360 * @portid: Port making netlink request
2361 * @seq: Sequence number of netlink message
2362 * @hardif_neigh: Neighbour to be dumped
2364 * Return: Error code, or 0 on success
2367 batadv_iv_ogm_neigh_dump_neigh(struct sk_buff *msg, u32 portid, u32 seq,
2368 struct batadv_hardif_neigh_node *hardif_neigh)
2371 unsigned int last_seen_msecs;
2373 last_seen_msecs = jiffies_to_msecs(jiffies - hardif_neigh->last_seen);
2375 hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family,
2376 NLM_F_MULTI, BATADV_CMD_GET_NEIGHBORS);
2380 if (nla_put(msg, BATADV_ATTR_NEIGH_ADDRESS, ETH_ALEN,
2381 hardif_neigh->addr) ||
2382 nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX,
2383 hardif_neigh->if_incoming->net_dev->ifindex) ||
2384 nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS,
2386 goto nla_put_failure;
2388 genlmsg_end(msg, hdr);
2392 genlmsg_cancel(msg, hdr);
2397 * batadv_iv_ogm_neigh_dump_hardif() - Dump the neighbours of a hard interface
2399 * @msg: Netlink message to dump into
2400 * @portid: Port making netlink request
2401 * @seq: Sequence number of netlink message
2402 * @bat_priv: The bat priv with all the soft interface information
2403 * @hard_iface: Hard interface to dump the neighbours for
2404 * @idx_s: Number of entries to skip
2406 * This function assumes the caller holds rcu_read_lock().
2408 * Return: Error code, or 0 on success
2411 batadv_iv_ogm_neigh_dump_hardif(struct sk_buff *msg, u32 portid, u32 seq,
2412 struct batadv_priv *bat_priv,
2413 struct batadv_hard_iface *hard_iface,
2416 struct batadv_hardif_neigh_node *hardif_neigh;
2419 hlist_for_each_entry_rcu(hardif_neigh,
2420 &hard_iface->neigh_list, list) {
2424 if (batadv_iv_ogm_neigh_dump_neigh(msg, portid, seq,
2436 * batadv_iv_ogm_neigh_dump() - Dump the neighbours into a message
2437 * @msg: Netlink message to dump into
2438 * @cb: Control block containing additional options
2439 * @bat_priv: The bat priv with all the soft interface information
2440 * @single_hardif: Limit dump to this hard interfaace
2443 batadv_iv_ogm_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb,
2444 struct batadv_priv *bat_priv,
2445 struct batadv_hard_iface *single_hardif)
2447 struct batadv_hard_iface *hard_iface;
2449 int i_hardif_s = cb->args[0];
2450 int idx = cb->args[1];
2451 int portid = NETLINK_CB(cb->skb).portid;
2454 if (single_hardif) {
2455 if (i_hardif_s == 0) {
2456 if (batadv_iv_ogm_neigh_dump_hardif(msg, portid,
2464 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list,
2466 if (hard_iface->soft_iface != bat_priv->soft_iface)
2469 if (i_hardif++ < i_hardif_s)
2472 if (batadv_iv_ogm_neigh_dump_hardif(msg, portid,
2475 hard_iface, &idx)) {
2483 cb->args[0] = i_hardif;
2488 * batadv_iv_ogm_neigh_cmp() - compare the metrics of two neighbors
2489 * @neigh1: the first neighbor object of the comparison
2490 * @if_outgoing1: outgoing interface for the first neighbor
2491 * @neigh2: the second neighbor object of the comparison
2492 * @if_outgoing2: outgoing interface for the second neighbor
2494 * Return: a value less, equal to or greater than 0 if the metric via neigh1 is
2495 * lower, the same as or higher than the metric via neigh2
2497 static int batadv_iv_ogm_neigh_cmp(struct batadv_neigh_node *neigh1,
2498 struct batadv_hard_iface *if_outgoing1,
2499 struct batadv_neigh_node *neigh2,
2500 struct batadv_hard_iface *if_outgoing2)
2505 ret = batadv_iv_ogm_neigh_diff(neigh1, if_outgoing1, neigh2,
2506 if_outgoing2, &diff);
2514 * batadv_iv_ogm_neigh_is_sob() - check if neigh1 is similarly good or better
2515 * than neigh2 from the metric prospective
2516 * @neigh1: the first neighbor object of the comparison
2517 * @if_outgoing1: outgoing interface for the first neighbor
2518 * @neigh2: the second neighbor object of the comparison
2519 * @if_outgoing2: outgoing interface for the second neighbor
2521 * Return: true if the metric via neigh1 is equally good or better than
2522 * the metric via neigh2, false otherwise.
2525 batadv_iv_ogm_neigh_is_sob(struct batadv_neigh_node *neigh1,
2526 struct batadv_hard_iface *if_outgoing1,
2527 struct batadv_neigh_node *neigh2,
2528 struct batadv_hard_iface *if_outgoing2)
2533 ret = batadv_iv_ogm_neigh_diff(neigh1, if_outgoing1, neigh2,
2534 if_outgoing2, &diff);
2538 ret = diff > -BATADV_TQ_SIMILARITY_THRESHOLD;
2542 static void batadv_iv_iface_enabled(struct batadv_hard_iface *hard_iface)
2544 /* begin scheduling originator messages on that interface */
2545 batadv_iv_ogm_schedule(hard_iface);
2549 * batadv_iv_init_sel_class() - initialize GW selection class
2550 * @bat_priv: the bat priv with all the soft interface information
2552 static void batadv_iv_init_sel_class(struct batadv_priv *bat_priv)
2554 /* set default TQ difference threshold to 20 */
2555 atomic_set(&bat_priv->gw.sel_class, 20);
2558 static struct batadv_gw_node *
2559 batadv_iv_gw_get_best_gw_node(struct batadv_priv *bat_priv)
2561 struct batadv_neigh_node *router;
2562 struct batadv_neigh_ifinfo *router_ifinfo;
2563 struct batadv_gw_node *gw_node, *curr_gw = NULL;
2564 u64 max_gw_factor = 0;
2565 u64 tmp_gw_factor = 0;
2568 struct batadv_orig_node *orig_node;
2571 hlist_for_each_entry_rcu(gw_node, &bat_priv->gw.gateway_list, list) {
2572 orig_node = gw_node->orig_node;
2573 router = batadv_orig_router_get(orig_node, BATADV_IF_DEFAULT);
2577 router_ifinfo = batadv_neigh_ifinfo_get(router,
2582 if (!kref_get_unless_zero(&gw_node->refcount))
2585 tq_avg = router_ifinfo->bat_iv.tq_avg;
2587 switch (atomic_read(&bat_priv->gw.sel_class)) {
2588 case 1: /* fast connection */
2589 tmp_gw_factor = tq_avg * tq_avg;
2590 tmp_gw_factor *= gw_node->bandwidth_down;
2591 tmp_gw_factor *= 100 * 100;
2592 tmp_gw_factor >>= 18;
2594 if (tmp_gw_factor > max_gw_factor ||
2595 (tmp_gw_factor == max_gw_factor &&
2598 batadv_gw_node_put(curr_gw);
2600 kref_get(&curr_gw->refcount);
2604 default: /* 2: stable connection (use best statistic)
2605 * 3: fast-switch (use best statistic but change as
2606 * soon as a better gateway appears)
2607 * XX: late-switch (use best statistic but change as
2608 * soon as a better gateway appears which has
2609 * $routing_class more tq points)
2611 if (tq_avg > max_tq) {
2613 batadv_gw_node_put(curr_gw);
2615 kref_get(&curr_gw->refcount);
2620 if (tq_avg > max_tq)
2623 if (tmp_gw_factor > max_gw_factor)
2624 max_gw_factor = tmp_gw_factor;
2626 batadv_gw_node_put(gw_node);
2629 batadv_neigh_node_put(router);
2631 batadv_neigh_ifinfo_put(router_ifinfo);
2638 static bool batadv_iv_gw_is_eligible(struct batadv_priv *bat_priv,
2639 struct batadv_orig_node *curr_gw_orig,
2640 struct batadv_orig_node *orig_node)
2642 struct batadv_neigh_ifinfo *router_orig_ifinfo = NULL;
2643 struct batadv_neigh_ifinfo *router_gw_ifinfo = NULL;
2644 struct batadv_neigh_node *router_gw = NULL;
2645 struct batadv_neigh_node *router_orig = NULL;
2646 u8 gw_tq_avg, orig_tq_avg;
2649 /* dynamic re-election is performed only on fast or late switch */
2650 if (atomic_read(&bat_priv->gw.sel_class) <= 2)
2653 router_gw = batadv_orig_router_get(curr_gw_orig, BATADV_IF_DEFAULT);
2659 router_gw_ifinfo = batadv_neigh_ifinfo_get(router_gw,
2661 if (!router_gw_ifinfo) {
2666 router_orig = batadv_orig_router_get(orig_node, BATADV_IF_DEFAULT);
2670 router_orig_ifinfo = batadv_neigh_ifinfo_get(router_orig,
2672 if (!router_orig_ifinfo)
2675 gw_tq_avg = router_gw_ifinfo->bat_iv.tq_avg;
2676 orig_tq_avg = router_orig_ifinfo->bat_iv.tq_avg;
2678 /* the TQ value has to be better */
2679 if (orig_tq_avg < gw_tq_avg)
2682 /* if the routing class is greater than 3 the value tells us how much
2683 * greater the TQ value of the new gateway must be
2685 if ((atomic_read(&bat_priv->gw.sel_class) > 3) &&
2686 (orig_tq_avg - gw_tq_avg < atomic_read(&bat_priv->gw.sel_class)))
2689 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
2690 "Restarting gateway selection: better gateway found (tq curr: %i, tq new: %i)\n",
2691 gw_tq_avg, orig_tq_avg);
2695 if (router_gw_ifinfo)
2696 batadv_neigh_ifinfo_put(router_gw_ifinfo);
2697 if (router_orig_ifinfo)
2698 batadv_neigh_ifinfo_put(router_orig_ifinfo);
2700 batadv_neigh_node_put(router_gw);
2702 batadv_neigh_node_put(router_orig);
2707 #ifdef CONFIG_BATMAN_ADV_DEBUGFS
2708 /* fails if orig_node has no router */
2709 static int batadv_iv_gw_write_buffer_text(struct batadv_priv *bat_priv,
2710 struct seq_file *seq,
2711 const struct batadv_gw_node *gw_node)
2713 struct batadv_gw_node *curr_gw;
2714 struct batadv_neigh_node *router;
2715 struct batadv_neigh_ifinfo *router_ifinfo = NULL;
2718 router = batadv_orig_router_get(gw_node->orig_node, BATADV_IF_DEFAULT);
2722 router_ifinfo = batadv_neigh_ifinfo_get(router, BATADV_IF_DEFAULT);
2726 curr_gw = batadv_gw_get_selected_gw_node(bat_priv);
2728 seq_printf(seq, "%s %pM (%3i) %pM [%10s]: %u.%u/%u.%u MBit\n",
2729 (curr_gw == gw_node ? "=>" : " "),
2730 gw_node->orig_node->orig,
2731 router_ifinfo->bat_iv.tq_avg, router->addr,
2732 router->if_incoming->net_dev->name,
2733 gw_node->bandwidth_down / 10,
2734 gw_node->bandwidth_down % 10,
2735 gw_node->bandwidth_up / 10,
2736 gw_node->bandwidth_up % 10);
2737 ret = seq_has_overflowed(seq) ? -1 : 0;
2740 batadv_gw_node_put(curr_gw);
2743 batadv_neigh_ifinfo_put(router_ifinfo);
2745 batadv_neigh_node_put(router);
2749 static void batadv_iv_gw_print(struct batadv_priv *bat_priv,
2750 struct seq_file *seq)
2752 struct batadv_gw_node *gw_node;
2756 " Gateway (#/255) Nexthop [outgoingIF]: advertised uplink bandwidth\n");
2759 hlist_for_each_entry_rcu(gw_node, &bat_priv->gw.gateway_list, list) {
2760 /* fails if orig_node has no router */
2761 if (batadv_iv_gw_write_buffer_text(bat_priv, seq, gw_node) < 0)
2769 seq_puts(seq, "No gateways in range ...\n");
2774 * batadv_iv_gw_dump_entry() - Dump a gateway into a message
2775 * @msg: Netlink message to dump into
2776 * @portid: Port making netlink request
2777 * @seq: Sequence number of netlink message
2778 * @bat_priv: The bat priv with all the soft interface information
2779 * @gw_node: Gateway to be dumped
2781 * Return: Error code, or 0 on success
2783 static int batadv_iv_gw_dump_entry(struct sk_buff *msg, u32 portid, u32 seq,
2784 struct batadv_priv *bat_priv,
2785 struct batadv_gw_node *gw_node)
2787 struct batadv_neigh_ifinfo *router_ifinfo = NULL;
2788 struct batadv_neigh_node *router;
2789 struct batadv_gw_node *curr_gw = NULL;
2793 router = batadv_orig_router_get(gw_node->orig_node, BATADV_IF_DEFAULT);
2797 router_ifinfo = batadv_neigh_ifinfo_get(router, BATADV_IF_DEFAULT);
2801 curr_gw = batadv_gw_get_selected_gw_node(bat_priv);
2803 hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family,
2804 NLM_F_MULTI, BATADV_CMD_GET_GATEWAYS);
2812 if (curr_gw == gw_node)
2813 if (nla_put_flag(msg, BATADV_ATTR_FLAG_BEST)) {
2814 genlmsg_cancel(msg, hdr);
2818 if (nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN,
2819 gw_node->orig_node->orig) ||
2820 nla_put_u8(msg, BATADV_ATTR_TQ, router_ifinfo->bat_iv.tq_avg) ||
2821 nla_put(msg, BATADV_ATTR_ROUTER, ETH_ALEN,
2823 nla_put_string(msg, BATADV_ATTR_HARD_IFNAME,
2824 router->if_incoming->net_dev->name) ||
2825 nla_put_u32(msg, BATADV_ATTR_BANDWIDTH_DOWN,
2826 gw_node->bandwidth_down) ||
2827 nla_put_u32(msg, BATADV_ATTR_BANDWIDTH_UP,
2828 gw_node->bandwidth_up)) {
2829 genlmsg_cancel(msg, hdr);
2833 genlmsg_end(msg, hdr);
2838 batadv_gw_node_put(curr_gw);
2840 batadv_neigh_ifinfo_put(router_ifinfo);
2842 batadv_neigh_node_put(router);
2847 * batadv_iv_gw_dump() - Dump gateways into a message
2848 * @msg: Netlink message to dump into
2849 * @cb: Control block containing additional options
2850 * @bat_priv: The bat priv with all the soft interface information
2852 static void batadv_iv_gw_dump(struct sk_buff *msg, struct netlink_callback *cb,
2853 struct batadv_priv *bat_priv)
2855 int portid = NETLINK_CB(cb->skb).portid;
2856 struct batadv_gw_node *gw_node;
2857 int idx_skip = cb->args[0];
2861 hlist_for_each_entry_rcu(gw_node, &bat_priv->gw.gateway_list, list) {
2862 if (idx++ < idx_skip)
2865 if (batadv_iv_gw_dump_entry(msg, portid, cb->nlh->nlmsg_seq,
2866 bat_priv, gw_node)) {
2876 cb->args[0] = idx_skip;
2879 static struct batadv_algo_ops batadv_batman_iv __read_mostly = {
2880 .name = "BATMAN_IV",
2882 .enable = batadv_iv_ogm_iface_enable,
2883 .enabled = batadv_iv_iface_enabled,
2884 .disable = batadv_iv_ogm_iface_disable,
2885 .update_mac = batadv_iv_ogm_iface_update_mac,
2886 .primary_set = batadv_iv_ogm_primary_iface_set,
2889 .cmp = batadv_iv_ogm_neigh_cmp,
2890 .is_similar_or_better = batadv_iv_ogm_neigh_is_sob,
2891 #ifdef CONFIG_BATMAN_ADV_DEBUGFS
2892 .print = batadv_iv_neigh_print,
2894 .dump = batadv_iv_ogm_neigh_dump,
2897 #ifdef CONFIG_BATMAN_ADV_DEBUGFS
2898 .print = batadv_iv_ogm_orig_print,
2900 .dump = batadv_iv_ogm_orig_dump,
2901 .free = batadv_iv_ogm_orig_free,
2902 .add_if = batadv_iv_ogm_orig_add_if,
2903 .del_if = batadv_iv_ogm_orig_del_if,
2906 .init_sel_class = batadv_iv_init_sel_class,
2907 .get_best_gw_node = batadv_iv_gw_get_best_gw_node,
2908 .is_eligible = batadv_iv_gw_is_eligible,
2909 #ifdef CONFIG_BATMAN_ADV_DEBUGFS
2910 .print = batadv_iv_gw_print,
2912 .dump = batadv_iv_gw_dump,
2917 * batadv_iv_init() - B.A.T.M.A.N. IV initialization function
2919 * Return: 0 on success or negative error number in case of failure
2921 int __init batadv_iv_init(void)
2925 /* batman originator packet */
2926 ret = batadv_recv_handler_register(BATADV_IV_OGM,
2927 batadv_iv_ogm_receive);
2931 ret = batadv_algo_register(&batadv_batman_iv);
2933 goto handler_unregister;
2938 batadv_recv_handler_unregister(BATADV_IV_OGM);