1 /* Copyright (C) 2007-2016 B.A.T.M.A.N. contributors:
3 * Marek Lindner, Simon Wunderlich
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public
7 * License as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 #include "bat_iv_ogm.h"
21 #include <linux/atomic.h>
22 #include <linux/bitmap.h>
23 #include <linux/bitops.h>
24 #include <linux/bug.h>
25 #include <linux/byteorder/generic.h>
26 #include <linux/cache.h>
27 #include <linux/errno.h>
28 #include <linux/etherdevice.h>
30 #include <linux/if_ether.h>
31 #include <linux/init.h>
32 #include <linux/jiffies.h>
33 #include <linux/kernel.h>
34 #include <linux/kref.h>
35 #include <linux/list.h>
36 #include <linux/lockdep.h>
37 #include <linux/mutex.h>
38 #include <linux/netdevice.h>
39 #include <linux/netlink.h>
40 #include <linux/pkt_sched.h>
41 #include <linux/printk.h>
42 #include <linux/random.h>
43 #include <linux/rculist.h>
44 #include <linux/rcupdate.h>
45 #include <linux/seq_file.h>
46 #include <linux/skbuff.h>
47 #include <linux/slab.h>
48 #include <linux/spinlock.h>
49 #include <linux/stddef.h>
50 #include <linux/string.h>
51 #include <linux/types.h>
52 #include <linux/workqueue.h>
53 #include <net/genetlink.h>
54 #include <net/netlink.h>
55 #include <uapi/linux/batman_adv.h>
59 #include "gateway_client.h"
60 #include "hard-interface.h"
64 #include "network-coding.h"
65 #include "originator.h"
69 #include "translation-table.h"
72 static void batadv_iv_send_outstanding_bat_ogm_packet(struct work_struct *work);
75 * enum batadv_dup_status - duplicate status
76 * @BATADV_NO_DUP: the packet is no duplicate
77 * @BATADV_ORIG_DUP: OGM is a duplicate in the originator (but not for the
79 * @BATADV_NEIGH_DUP: OGM is a duplicate for the neighbor
80 * @BATADV_PROTECTED: originator is currently protected (after reboot)
82 enum batadv_dup_status {
90 * batadv_ring_buffer_set - update the ring buffer with the given value
91 * @lq_recv: pointer to the ring buffer
92 * @lq_index: index to store the value at
93 * @value: value to store in the ring buffer
95 static void batadv_ring_buffer_set(u8 lq_recv[], u8 *lq_index, u8 value)
97 lq_recv[*lq_index] = value;
98 *lq_index = (*lq_index + 1) % BATADV_TQ_GLOBAL_WINDOW_SIZE;
102 * batadv_ring_buffer_avg - compute the average of all non-zero values stored
103 * in the given ring buffer
104 * @lq_recv: pointer to the ring buffer
106 * Return: computed average value.
108 static u8 batadv_ring_buffer_avg(const u8 lq_recv[])
117 while (i < BATADV_TQ_GLOBAL_WINDOW_SIZE) {
130 return (u8)(sum / count);
134 * batadv_iv_ogm_orig_free - free the private resources allocated for this
136 * @orig_node: the orig_node for which the resources have to be free'd
138 static void batadv_iv_ogm_orig_free(struct batadv_orig_node *orig_node)
140 kfree(orig_node->bat_iv.bcast_own);
141 kfree(orig_node->bat_iv.bcast_own_sum);
145 * batadv_iv_ogm_orig_add_if - change the private structures of the orig_node to
146 * include the new hard-interface
147 * @orig_node: the orig_node that has to be changed
148 * @max_if_num: the current amount of interfaces
150 * Return: 0 on success, a negative error code otherwise.
152 static int batadv_iv_ogm_orig_add_if(struct batadv_orig_node *orig_node,
153 unsigned int max_if_num)
159 spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock);
161 old_size = (max_if_num - 1) * sizeof(unsigned long) * BATADV_NUM_WORDS;
162 data_ptr = kmalloc_array(max_if_num,
163 BATADV_NUM_WORDS * sizeof(unsigned long),
168 memcpy(data_ptr, orig_node->bat_iv.bcast_own, old_size);
169 kfree(orig_node->bat_iv.bcast_own);
170 orig_node->bat_iv.bcast_own = data_ptr;
172 data_ptr = kmalloc_array(max_if_num, sizeof(u8), GFP_ATOMIC);
176 memcpy(data_ptr, orig_node->bat_iv.bcast_own_sum,
177 (max_if_num - 1) * sizeof(u8));
178 kfree(orig_node->bat_iv.bcast_own_sum);
179 orig_node->bat_iv.bcast_own_sum = data_ptr;
184 spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock);
190 * batadv_iv_ogm_drop_bcast_own_entry - drop section of bcast_own
191 * @orig_node: the orig_node that has to be changed
192 * @max_if_num: the current amount of interfaces
193 * @del_if_num: the index of the interface being removed
196 batadv_iv_ogm_drop_bcast_own_entry(struct batadv_orig_node *orig_node,
197 unsigned int max_if_num,
198 unsigned int del_if_num)
204 lockdep_assert_held(&orig_node->bat_iv.ogm_cnt_lock);
206 chunk_size = sizeof(unsigned long) * BATADV_NUM_WORDS;
207 data_ptr = kmalloc_array(max_if_num, chunk_size, GFP_ATOMIC);
209 /* use old buffer when new one could not be allocated */
210 data_ptr = orig_node->bat_iv.bcast_own;
212 /* copy first part */
213 memmove(data_ptr, orig_node->bat_iv.bcast_own, del_if_num * chunk_size);
215 /* copy second part */
216 if_offset = (del_if_num + 1) * chunk_size;
217 memmove((char *)data_ptr + del_if_num * chunk_size,
218 (uint8_t *)orig_node->bat_iv.bcast_own + if_offset,
219 (max_if_num - del_if_num) * chunk_size);
221 /* bcast_own was shrunk down in new buffer; free old one */
222 if (orig_node->bat_iv.bcast_own != data_ptr) {
223 kfree(orig_node->bat_iv.bcast_own);
224 orig_node->bat_iv.bcast_own = data_ptr;
229 * batadv_iv_ogm_drop_bcast_own_sum_entry - drop section of bcast_own_sum
230 * @orig_node: the orig_node that has to be changed
231 * @max_if_num: the current amount of interfaces
232 * @del_if_num: the index of the interface being removed
235 batadv_iv_ogm_drop_bcast_own_sum_entry(struct batadv_orig_node *orig_node,
236 unsigned int max_if_num,
237 unsigned int del_if_num)
242 lockdep_assert_held(&orig_node->bat_iv.ogm_cnt_lock);
244 data_ptr = kmalloc_array(max_if_num, sizeof(u8), GFP_ATOMIC);
246 /* use old buffer when new one could not be allocated */
247 data_ptr = orig_node->bat_iv.bcast_own_sum;
249 memmove(data_ptr, orig_node->bat_iv.bcast_own_sum,
250 del_if_num * sizeof(u8));
252 if_offset = (del_if_num + 1) * sizeof(u8);
253 memmove((char *)data_ptr + del_if_num * sizeof(u8),
254 orig_node->bat_iv.bcast_own_sum + if_offset,
255 (max_if_num - del_if_num) * sizeof(u8));
257 /* bcast_own_sum was shrunk down in new buffer; free old one */
258 if (orig_node->bat_iv.bcast_own_sum != data_ptr) {
259 kfree(orig_node->bat_iv.bcast_own_sum);
260 orig_node->bat_iv.bcast_own_sum = data_ptr;
265 * batadv_iv_ogm_orig_del_if - change the private structures of the orig_node to
266 * exclude the removed interface
267 * @orig_node: the orig_node that has to be changed
268 * @max_if_num: the current amount of interfaces
269 * @del_if_num: the index of the interface being removed
271 * Return: 0 on success, a negative error code otherwise.
273 static int batadv_iv_ogm_orig_del_if(struct batadv_orig_node *orig_node,
274 unsigned int max_if_num,
275 unsigned int del_if_num)
277 spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock);
279 if (max_if_num == 0) {
280 kfree(orig_node->bat_iv.bcast_own);
281 kfree(orig_node->bat_iv.bcast_own_sum);
282 orig_node->bat_iv.bcast_own = NULL;
283 orig_node->bat_iv.bcast_own_sum = NULL;
285 batadv_iv_ogm_drop_bcast_own_entry(orig_node, max_if_num,
287 batadv_iv_ogm_drop_bcast_own_sum_entry(orig_node, max_if_num,
291 spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock);
297 * batadv_iv_ogm_orig_get - retrieve or create (if does not exist) an originator
298 * @bat_priv: the bat priv with all the soft interface information
299 * @addr: mac address of the originator
301 * Return: the originator object corresponding to the passed mac address or NULL
303 * If the object does not exists it is created an initialised.
305 static struct batadv_orig_node *
306 batadv_iv_ogm_orig_get(struct batadv_priv *bat_priv, const u8 *addr)
308 struct batadv_orig_node *orig_node;
312 orig_node = batadv_orig_hash_find(bat_priv, addr);
316 orig_node = batadv_orig_node_new(bat_priv, addr);
320 spin_lock_init(&orig_node->bat_iv.ogm_cnt_lock);
322 size = bat_priv->num_ifaces * sizeof(unsigned long) * BATADV_NUM_WORDS;
323 orig_node->bat_iv.bcast_own = kzalloc(size, GFP_ATOMIC);
324 if (!orig_node->bat_iv.bcast_own)
327 size = bat_priv->num_ifaces * sizeof(u8);
328 orig_node->bat_iv.bcast_own_sum = kzalloc(size, GFP_ATOMIC);
329 if (!orig_node->bat_iv.bcast_own_sum)
332 kref_get(&orig_node->refcount);
333 hash_added = batadv_hash_add(bat_priv->orig_hash, batadv_compare_orig,
334 batadv_choose_orig, orig_node,
335 &orig_node->hash_entry);
337 goto free_orig_node_hash;
342 batadv_orig_node_put(orig_node);
344 batadv_orig_node_put(orig_node);
349 static struct batadv_neigh_node *
350 batadv_iv_ogm_neigh_new(struct batadv_hard_iface *hard_iface,
351 const u8 *neigh_addr,
352 struct batadv_orig_node *orig_node,
353 struct batadv_orig_node *orig_neigh)
355 struct batadv_neigh_node *neigh_node;
357 neigh_node = batadv_neigh_node_get_or_create(orig_node,
358 hard_iface, neigh_addr);
362 neigh_node->orig_node = orig_neigh;
368 static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
370 struct batadv_ogm_packet *batadv_ogm_packet;
371 unsigned char *ogm_buff;
374 mutex_lock(&hard_iface->bat_iv.ogm_buff_mutex);
376 /* randomize initial seqno to avoid collision */
377 get_random_bytes(&random_seqno, sizeof(random_seqno));
378 atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
380 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
381 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
383 mutex_unlock(&hard_iface->bat_iv.ogm_buff_mutex);
387 hard_iface->bat_iv.ogm_buff = ogm_buff;
389 batadv_ogm_packet = (struct batadv_ogm_packet *)ogm_buff;
390 batadv_ogm_packet->packet_type = BATADV_IV_OGM;
391 batadv_ogm_packet->version = BATADV_COMPAT_VERSION;
392 batadv_ogm_packet->ttl = 2;
393 batadv_ogm_packet->flags = BATADV_NO_FLAGS;
394 batadv_ogm_packet->reserved = 0;
395 batadv_ogm_packet->tq = BATADV_TQ_MAX_VALUE;
397 mutex_unlock(&hard_iface->bat_iv.ogm_buff_mutex);
402 static void batadv_iv_ogm_iface_disable(struct batadv_hard_iface *hard_iface)
404 mutex_lock(&hard_iface->bat_iv.ogm_buff_mutex);
406 kfree(hard_iface->bat_iv.ogm_buff);
407 hard_iface->bat_iv.ogm_buff = NULL;
409 mutex_unlock(&hard_iface->bat_iv.ogm_buff_mutex);
412 static void batadv_iv_ogm_iface_update_mac(struct batadv_hard_iface *hard_iface)
414 struct batadv_ogm_packet *batadv_ogm_packet;
417 mutex_lock(&hard_iface->bat_iv.ogm_buff_mutex);
419 ogm_buff = hard_iface->bat_iv.ogm_buff;
423 batadv_ogm_packet = ogm_buff;
424 ether_addr_copy(batadv_ogm_packet->orig,
425 hard_iface->net_dev->dev_addr);
426 ether_addr_copy(batadv_ogm_packet->prev_sender,
427 hard_iface->net_dev->dev_addr);
430 mutex_unlock(&hard_iface->bat_iv.ogm_buff_mutex);
434 batadv_iv_ogm_primary_iface_set(struct batadv_hard_iface *hard_iface)
436 struct batadv_ogm_packet *batadv_ogm_packet;
439 mutex_lock(&hard_iface->bat_iv.ogm_buff_mutex);
441 ogm_buff = hard_iface->bat_iv.ogm_buff;
445 batadv_ogm_packet = ogm_buff;
446 batadv_ogm_packet->ttl = BATADV_TTL;
449 mutex_unlock(&hard_iface->bat_iv.ogm_buff_mutex);
452 /* when do we schedule our own ogm to be sent */
454 batadv_iv_ogm_emit_send_time(const struct batadv_priv *bat_priv)
458 msecs = atomic_read(&bat_priv->orig_interval) - BATADV_JITTER;
459 msecs += prandom_u32() % (2 * BATADV_JITTER);
461 return jiffies + msecs_to_jiffies(msecs);
464 /* when do we schedule a ogm packet to be sent */
465 static unsigned long batadv_iv_ogm_fwd_send_time(void)
467 return jiffies + msecs_to_jiffies(prandom_u32() % (BATADV_JITTER / 2));
470 /* apply hop penalty for a normal link */
471 static u8 batadv_hop_penalty(u8 tq, const struct batadv_priv *bat_priv)
473 int hop_penalty = atomic_read(&bat_priv->hop_penalty);
476 new_tq = tq * (BATADV_TQ_MAX_VALUE - hop_penalty);
477 new_tq /= BATADV_TQ_MAX_VALUE;
483 * batadv_iv_ogm_aggr_packet - checks if there is another OGM attached
484 * @buff_pos: current position in the skb
485 * @packet_len: total length of the skb
486 * @ogm_packet: potential OGM in buffer
488 * Return: true if there is enough space for another OGM, false otherwise.
491 batadv_iv_ogm_aggr_packet(int buff_pos, int packet_len,
492 const struct batadv_ogm_packet *ogm_packet)
494 int next_buff_pos = 0;
496 /* check if there is enough space for the header */
497 next_buff_pos += buff_pos + sizeof(*ogm_packet);
498 if (next_buff_pos > packet_len)
501 /* check if there is enough space for the optional TVLV */
502 next_buff_pos += ntohs(ogm_packet->tvlv_len);
504 return (next_buff_pos <= packet_len) &&
505 (next_buff_pos <= BATADV_MAX_AGGREGATION_BYTES);
508 /* send a batman ogm to a given interface */
509 static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet,
510 struct batadv_hard_iface *hard_iface)
512 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
516 struct batadv_ogm_packet *batadv_ogm_packet;
520 if (hard_iface->if_status != BATADV_IF_ACTIVE)
525 packet_pos = forw_packet->skb->data;
526 batadv_ogm_packet = (struct batadv_ogm_packet *)packet_pos;
528 /* adjust all flags and log packets */
529 while (batadv_iv_ogm_aggr_packet(buff_pos, forw_packet->packet_len,
530 batadv_ogm_packet)) {
531 /* we might have aggregated direct link packets with an
532 * ordinary base packet
534 if (forw_packet->direct_link_flags & BIT(packet_num) &&
535 forw_packet->if_incoming == hard_iface)
536 batadv_ogm_packet->flags |= BATADV_DIRECTLINK;
538 batadv_ogm_packet->flags &= ~BATADV_DIRECTLINK;
540 if (packet_num > 0 || !forw_packet->own)
541 fwd_str = "Forwarding";
543 fwd_str = "Sending own";
545 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
546 "%s %spacket (originator %pM, seqno %u, TQ %d, TTL %d, IDF %s) on interface %s [%pM]\n",
547 fwd_str, (packet_num > 0 ? "aggregated " : ""),
548 batadv_ogm_packet->orig,
549 ntohl(batadv_ogm_packet->seqno),
550 batadv_ogm_packet->tq, batadv_ogm_packet->ttl,
551 ((batadv_ogm_packet->flags & BATADV_DIRECTLINK) ?
553 hard_iface->net_dev->name,
554 hard_iface->net_dev->dev_addr);
556 buff_pos += BATADV_OGM_HLEN;
557 buff_pos += ntohs(batadv_ogm_packet->tvlv_len);
559 packet_pos = forw_packet->skb->data + buff_pos;
560 batadv_ogm_packet = (struct batadv_ogm_packet *)packet_pos;
563 /* create clone because function is called more than once */
564 skb = skb_clone(forw_packet->skb, GFP_ATOMIC);
566 batadv_inc_counter(bat_priv, BATADV_CNT_MGMT_TX);
567 batadv_add_counter(bat_priv, BATADV_CNT_MGMT_TX_BYTES,
568 skb->len + ETH_HLEN);
569 batadv_send_broadcast_skb(skb, hard_iface);
573 /* send a batman ogm packet */
574 static void batadv_iv_ogm_emit(struct batadv_forw_packet *forw_packet)
576 struct net_device *soft_iface;
578 if (!forw_packet->if_incoming) {
579 pr_err("Error - can't forward packet: incoming iface not specified\n");
583 soft_iface = forw_packet->if_incoming->soft_iface;
585 if (WARN_ON(!forw_packet->if_outgoing))
588 if (forw_packet->if_outgoing->soft_iface != soft_iface) {
589 pr_warn("%s: soft interface switch for queued OGM\n", __func__);
593 if (forw_packet->if_incoming->if_status != BATADV_IF_ACTIVE)
596 /* only for one specific outgoing interface */
597 batadv_iv_ogm_send_to_if(forw_packet, forw_packet->if_outgoing);
601 * batadv_iv_ogm_can_aggregate - find out if an OGM can be aggregated on an
602 * existing forward packet
603 * @new_bat_ogm_packet: OGM packet to be aggregated
604 * @bat_priv: the bat priv with all the soft interface information
605 * @packet_len: (total) length of the OGM
606 * @send_time: timestamp (jiffies) when the packet is to be sent
607 * @directlink: true if this is a direct link packet
608 * @if_incoming: interface where the packet was received
609 * @if_outgoing: interface for which the retransmission should be considered
610 * @forw_packet: the forwarded packet which should be checked
612 * Return: true if new_packet can be aggregated with forw_packet
615 batadv_iv_ogm_can_aggregate(const struct batadv_ogm_packet *new_bat_ogm_packet,
616 struct batadv_priv *bat_priv,
617 int packet_len, unsigned long send_time,
619 const struct batadv_hard_iface *if_incoming,
620 const struct batadv_hard_iface *if_outgoing,
621 const struct batadv_forw_packet *forw_packet)
623 struct batadv_ogm_packet *batadv_ogm_packet;
624 int aggregated_bytes = forw_packet->packet_len + packet_len;
625 struct batadv_hard_iface *primary_if = NULL;
627 unsigned long aggregation_end_time;
629 batadv_ogm_packet = (struct batadv_ogm_packet *)forw_packet->skb->data;
630 aggregation_end_time = send_time;
631 aggregation_end_time += msecs_to_jiffies(BATADV_MAX_AGGREGATION_MS);
633 /* we can aggregate the current packet to this aggregated packet
636 * - the send time is within our MAX_AGGREGATION_MS time
637 * - the resulting packet wont be bigger than
638 * MAX_AGGREGATION_BYTES
639 * otherwise aggregation is not possible
641 if (!time_before(send_time, forw_packet->send_time) ||
642 !time_after_eq(aggregation_end_time, forw_packet->send_time))
645 if (aggregated_bytes > BATADV_MAX_AGGREGATION_BYTES)
648 /* packet is not leaving on the same interface. */
649 if (forw_packet->if_outgoing != if_outgoing)
652 /* check aggregation compatibility
653 * -> direct link packets are broadcasted on
654 * their interface only
655 * -> aggregate packet if the current packet is
656 * a "global" packet as well as the base
659 primary_if = batadv_primary_if_get_selected(bat_priv);
663 /* packets without direct link flag and high TTL
664 * are flooded through the net
667 !(batadv_ogm_packet->flags & BATADV_DIRECTLINK) &&
668 batadv_ogm_packet->ttl != 1 &&
670 /* own packets originating non-primary
671 * interfaces leave only that interface
673 (!forw_packet->own ||
674 forw_packet->if_incoming == primary_if)) {
679 /* if the incoming packet is sent via this one
680 * interface only - we still can aggregate
683 new_bat_ogm_packet->ttl == 1 &&
684 forw_packet->if_incoming == if_incoming &&
686 /* packets from direct neighbors or
687 * own secondary interface packets
688 * (= secondary interface packets in general)
690 (batadv_ogm_packet->flags & BATADV_DIRECTLINK ||
692 forw_packet->if_incoming != primary_if))) {
699 batadv_hardif_put(primary_if);
704 * batadv_iv_ogm_aggregate_new - create a new aggregated packet and add this
706 * @packet_buff: pointer to the OGM
707 * @packet_len: (total) length of the OGM
708 * @send_time: timestamp (jiffies) when the packet is to be sent
709 * @direct_link: whether this OGM has direct link status
710 * @if_incoming: interface where the packet was received
711 * @if_outgoing: interface for which the retransmission should be considered
712 * @own_packet: true if it is a self-generated ogm
714 static void batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff,
715 int packet_len, unsigned long send_time,
717 struct batadv_hard_iface *if_incoming,
718 struct batadv_hard_iface *if_outgoing,
721 struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
722 struct batadv_forw_packet *forw_packet_aggr;
723 unsigned char *skb_buff;
724 unsigned int skb_size;
725 atomic_t *queue_left = own_packet ? NULL : &bat_priv->batman_queue_left;
727 forw_packet_aggr = batadv_forw_packet_alloc(if_incoming, if_outgoing,
728 queue_left, bat_priv);
729 if (!forw_packet_aggr)
732 if (atomic_read(&bat_priv->aggregated_ogms) &&
733 packet_len < BATADV_MAX_AGGREGATION_BYTES)
734 skb_size = BATADV_MAX_AGGREGATION_BYTES;
736 skb_size = packet_len;
738 skb_size += ETH_HLEN;
740 forw_packet_aggr->skb = netdev_alloc_skb_ip_align(NULL, skb_size);
741 if (!forw_packet_aggr->skb) {
742 batadv_forw_packet_free(forw_packet_aggr);
746 forw_packet_aggr->skb->priority = TC_PRIO_CONTROL;
747 skb_reserve(forw_packet_aggr->skb, ETH_HLEN);
749 skb_buff = skb_put(forw_packet_aggr->skb, packet_len);
750 forw_packet_aggr->packet_len = packet_len;
751 memcpy(skb_buff, packet_buff, packet_len);
753 forw_packet_aggr->own = own_packet;
754 forw_packet_aggr->direct_link_flags = BATADV_NO_FLAGS;
755 forw_packet_aggr->send_time = send_time;
757 /* save packet direct link flag status */
759 forw_packet_aggr->direct_link_flags |= 1;
761 /* add new packet to packet list */
762 spin_lock_bh(&bat_priv->forw_bat_list_lock);
763 hlist_add_head(&forw_packet_aggr->list, &bat_priv->forw_bat_list);
764 spin_unlock_bh(&bat_priv->forw_bat_list_lock);
766 /* start timer for this packet */
767 INIT_DELAYED_WORK(&forw_packet_aggr->delayed_work,
768 batadv_iv_send_outstanding_bat_ogm_packet);
769 queue_delayed_work(batadv_event_workqueue,
770 &forw_packet_aggr->delayed_work,
771 send_time - jiffies);
774 /* aggregate a new packet into the existing ogm packet */
775 static void batadv_iv_ogm_aggregate(struct batadv_forw_packet *forw_packet_aggr,
776 const unsigned char *packet_buff,
777 int packet_len, bool direct_link)
779 unsigned char *skb_buff;
780 unsigned long new_direct_link_flag;
782 skb_buff = skb_put(forw_packet_aggr->skb, packet_len);
783 memcpy(skb_buff, packet_buff, packet_len);
784 forw_packet_aggr->packet_len += packet_len;
785 forw_packet_aggr->num_packets++;
787 /* save packet direct link flag status */
789 new_direct_link_flag = BIT(forw_packet_aggr->num_packets);
790 forw_packet_aggr->direct_link_flags |= new_direct_link_flag;
795 * batadv_iv_ogm_queue_add - queue up an OGM for transmission
796 * @bat_priv: the bat priv with all the soft interface information
797 * @packet_buff: pointer to the OGM
798 * @packet_len: (total) length of the OGM
799 * @if_incoming: interface where the packet was received
800 * @if_outgoing: interface for which the retransmission should be considered
801 * @own_packet: true if it is a self-generated ogm
802 * @send_time: timestamp (jiffies) when the packet is to be sent
804 static void batadv_iv_ogm_queue_add(struct batadv_priv *bat_priv,
805 unsigned char *packet_buff,
807 struct batadv_hard_iface *if_incoming,
808 struct batadv_hard_iface *if_outgoing,
809 int own_packet, unsigned long send_time)
811 /* _aggr -> pointer to the packet we want to aggregate with
812 * _pos -> pointer to the position in the queue
814 struct batadv_forw_packet *forw_packet_aggr = NULL;
815 struct batadv_forw_packet *forw_packet_pos = NULL;
816 struct batadv_ogm_packet *batadv_ogm_packet;
818 unsigned long max_aggregation_jiffies;
820 batadv_ogm_packet = (struct batadv_ogm_packet *)packet_buff;
821 direct_link = !!(batadv_ogm_packet->flags & BATADV_DIRECTLINK);
822 max_aggregation_jiffies = msecs_to_jiffies(BATADV_MAX_AGGREGATION_MS);
824 /* find position for the packet in the forward queue */
825 spin_lock_bh(&bat_priv->forw_bat_list_lock);
826 /* own packets are not to be aggregated */
827 if (atomic_read(&bat_priv->aggregated_ogms) && !own_packet) {
828 hlist_for_each_entry(forw_packet_pos,
829 &bat_priv->forw_bat_list, list) {
830 if (batadv_iv_ogm_can_aggregate(batadv_ogm_packet,
831 bat_priv, packet_len,
832 send_time, direct_link,
836 forw_packet_aggr = forw_packet_pos;
842 /* nothing to aggregate with - either aggregation disabled or no
843 * suitable aggregation packet found
845 if (!forw_packet_aggr) {
846 /* the following section can run without the lock */
847 spin_unlock_bh(&bat_priv->forw_bat_list_lock);
849 /* if we could not aggregate this packet with one of the others
850 * we hold it back for a while, so that it might be aggregated
853 if (!own_packet && atomic_read(&bat_priv->aggregated_ogms))
854 send_time += max_aggregation_jiffies;
856 batadv_iv_ogm_aggregate_new(packet_buff, packet_len,
857 send_time, direct_link,
858 if_incoming, if_outgoing,
861 batadv_iv_ogm_aggregate(forw_packet_aggr, packet_buff,
862 packet_len, direct_link);
863 spin_unlock_bh(&bat_priv->forw_bat_list_lock);
867 static void batadv_iv_ogm_forward(struct batadv_orig_node *orig_node,
868 const struct ethhdr *ethhdr,
869 struct batadv_ogm_packet *batadv_ogm_packet,
870 bool is_single_hop_neigh,
871 bool is_from_best_next_hop,
872 struct batadv_hard_iface *if_incoming,
873 struct batadv_hard_iface *if_outgoing)
875 struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
878 if (batadv_ogm_packet->ttl <= 1) {
879 batadv_dbg(BATADV_DBG_BATMAN, bat_priv, "ttl exceeded\n");
883 if (!is_from_best_next_hop) {
884 /* Mark the forwarded packet when it is not coming from our
885 * best next hop. We still need to forward the packet for our
886 * neighbor link quality detection to work in case the packet
887 * originated from a single hop neighbor. Otherwise we can
888 * simply drop the ogm.
890 if (is_single_hop_neigh)
891 batadv_ogm_packet->flags |= BATADV_NOT_BEST_NEXT_HOP;
896 tvlv_len = ntohs(batadv_ogm_packet->tvlv_len);
898 batadv_ogm_packet->ttl--;
899 ether_addr_copy(batadv_ogm_packet->prev_sender, ethhdr->h_source);
901 /* apply hop penalty */
902 batadv_ogm_packet->tq = batadv_hop_penalty(batadv_ogm_packet->tq,
905 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
906 "Forwarding packet: tq: %i, ttl: %i\n",
907 batadv_ogm_packet->tq, batadv_ogm_packet->ttl);
909 if (is_single_hop_neigh)
910 batadv_ogm_packet->flags |= BATADV_DIRECTLINK;
912 batadv_ogm_packet->flags &= ~BATADV_DIRECTLINK;
914 batadv_iv_ogm_queue_add(bat_priv, (unsigned char *)batadv_ogm_packet,
915 BATADV_OGM_HLEN + tvlv_len,
916 if_incoming, if_outgoing, 0,
917 batadv_iv_ogm_fwd_send_time());
921 * batadv_iv_ogm_slide_own_bcast_window - bitshift own OGM broadcast windows for
922 * the given interface
923 * @hard_iface: the interface for which the windows have to be shifted
926 batadv_iv_ogm_slide_own_bcast_window(struct batadv_hard_iface *hard_iface)
928 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
929 struct batadv_hashtable *hash = bat_priv->orig_hash;
930 struct hlist_head *head;
931 struct batadv_orig_node *orig_node;
938 for (i = 0; i < hash->size; i++) {
939 head = &hash->table[i];
942 hlist_for_each_entry_rcu(orig_node, head, hash_entry) {
943 spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock);
944 word_index = hard_iface->if_num * BATADV_NUM_WORDS;
945 word = &orig_node->bat_iv.bcast_own[word_index];
947 batadv_bit_get_packet(bat_priv, word, 1, 0);
948 if_num = hard_iface->if_num;
949 w = &orig_node->bat_iv.bcast_own_sum[if_num];
950 *w = bitmap_weight(word, BATADV_TQ_LOCAL_WINDOW_SIZE);
951 spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock);
958 * batadv_iv_ogm_schedule_buff() - schedule submission of hardif ogm buffer
959 * @hard_iface: interface whose ogm buffer should be transmitted
961 static void batadv_iv_ogm_schedule_buff(struct batadv_hard_iface *hard_iface)
963 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
964 unsigned char **ogm_buff = &hard_iface->bat_iv.ogm_buff;
965 struct batadv_ogm_packet *batadv_ogm_packet;
966 struct batadv_hard_iface *primary_if, *tmp_hard_iface;
967 int *ogm_buff_len = &hard_iface->bat_iv.ogm_buff_len;
970 unsigned long send_time;
972 lockdep_assert_held(&hard_iface->bat_iv.ogm_buff_mutex);
974 /* interface already disabled by batadv_iv_ogm_iface_disable */
978 /* the interface gets activated here to avoid race conditions between
979 * the moment of activating the interface in
980 * hardif_activate_interface() where the originator mac is set and
981 * outdated packets (especially uninitialized mac addresses) in the
984 if (hard_iface->if_status == BATADV_IF_TO_BE_ACTIVATED)
985 hard_iface->if_status = BATADV_IF_ACTIVE;
987 primary_if = batadv_primary_if_get_selected(bat_priv);
989 if (hard_iface == primary_if) {
990 /* tt changes have to be committed before the tvlv data is
991 * appended as it may alter the tt tvlv container
993 batadv_tt_local_commit_changes(bat_priv);
994 tvlv_len = batadv_tvlv_container_ogm_append(bat_priv, ogm_buff,
999 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
1000 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
1002 /* change sequence number to network order */
1003 seqno = (u32)atomic_read(&hard_iface->bat_iv.ogm_seqno);
1004 batadv_ogm_packet->seqno = htonl(seqno);
1005 atomic_inc(&hard_iface->bat_iv.ogm_seqno);
1007 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
1009 send_time = batadv_iv_ogm_emit_send_time(bat_priv);
1011 if (hard_iface != primary_if) {
1012 /* OGMs from secondary interfaces are only scheduled on their
1013 * respective interfaces.
1015 batadv_iv_ogm_queue_add(bat_priv, *ogm_buff, *ogm_buff_len,
1016 hard_iface, hard_iface, 1, send_time);
1020 /* OGMs from primary interfaces are scheduled on all
1024 list_for_each_entry_rcu(tmp_hard_iface, &batadv_hardif_list, list) {
1025 if (tmp_hard_iface->soft_iface != hard_iface->soft_iface)
1028 if (!kref_get_unless_zero(&tmp_hard_iface->refcount))
1031 batadv_iv_ogm_queue_add(bat_priv, *ogm_buff,
1032 *ogm_buff_len, hard_iface,
1033 tmp_hard_iface, 1, send_time);
1035 batadv_hardif_put(tmp_hard_iface);
1041 batadv_hardif_put(primary_if);
1044 static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
1046 if (hard_iface->if_status == BATADV_IF_NOT_IN_USE ||
1047 hard_iface->if_status == BATADV_IF_TO_BE_REMOVED)
1050 mutex_lock(&hard_iface->bat_iv.ogm_buff_mutex);
1051 batadv_iv_ogm_schedule_buff(hard_iface);
1052 mutex_unlock(&hard_iface->bat_iv.ogm_buff_mutex);
1056 * batadv_iv_ogm_orig_update - use OGM to update corresponding data in an
1058 * @bat_priv: the bat priv with all the soft interface information
1059 * @orig_node: the orig node who originally emitted the ogm packet
1060 * @orig_ifinfo: ifinfo for the outgoing interface of the orig_node
1061 * @ethhdr: Ethernet header of the OGM
1062 * @batadv_ogm_packet: the ogm packet
1063 * @if_incoming: interface where the packet was received
1064 * @if_outgoing: interface for which the retransmission should be considered
1065 * @dup_status: the duplicate status of this ogm packet.
1068 batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv,
1069 struct batadv_orig_node *orig_node,
1070 struct batadv_orig_ifinfo *orig_ifinfo,
1071 const struct ethhdr *ethhdr,
1072 const struct batadv_ogm_packet *batadv_ogm_packet,
1073 struct batadv_hard_iface *if_incoming,
1074 struct batadv_hard_iface *if_outgoing,
1075 enum batadv_dup_status dup_status)
1077 struct batadv_neigh_ifinfo *neigh_ifinfo = NULL;
1078 struct batadv_neigh_ifinfo *router_ifinfo = NULL;
1079 struct batadv_neigh_node *neigh_node = NULL;
1080 struct batadv_neigh_node *tmp_neigh_node = NULL;
1081 struct batadv_neigh_node *router = NULL;
1082 struct batadv_orig_node *orig_node_tmp;
1083 unsigned int if_num;
1084 u8 sum_orig, sum_neigh;
1088 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1089 "update_originator(): Searching and updating originator entry of received packet\n");
1092 hlist_for_each_entry_rcu(tmp_neigh_node,
1093 &orig_node->neigh_list, list) {
1094 neigh_addr = tmp_neigh_node->addr;
1095 if (batadv_compare_eth(neigh_addr, ethhdr->h_source) &&
1096 tmp_neigh_node->if_incoming == if_incoming &&
1097 kref_get_unless_zero(&tmp_neigh_node->refcount)) {
1098 if (WARN(neigh_node, "too many matching neigh_nodes"))
1099 batadv_neigh_node_put(neigh_node);
1100 neigh_node = tmp_neigh_node;
1104 if (dup_status != BATADV_NO_DUP)
1107 /* only update the entry for this outgoing interface */
1108 neigh_ifinfo = batadv_neigh_ifinfo_get(tmp_neigh_node,
1113 spin_lock_bh(&tmp_neigh_node->ifinfo_lock);
1114 batadv_ring_buffer_set(neigh_ifinfo->bat_iv.tq_recv,
1115 &neigh_ifinfo->bat_iv.tq_index, 0);
1116 tq_avg = batadv_ring_buffer_avg(neigh_ifinfo->bat_iv.tq_recv);
1117 neigh_ifinfo->bat_iv.tq_avg = tq_avg;
1118 spin_unlock_bh(&tmp_neigh_node->ifinfo_lock);
1120 batadv_neigh_ifinfo_put(neigh_ifinfo);
1121 neigh_ifinfo = NULL;
1125 struct batadv_orig_node *orig_tmp;
1127 orig_tmp = batadv_iv_ogm_orig_get(bat_priv, ethhdr->h_source);
1131 neigh_node = batadv_iv_ogm_neigh_new(if_incoming,
1133 orig_node, orig_tmp);
1135 batadv_orig_node_put(orig_tmp);
1139 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1140 "Updating existing last-hop neighbor of originator\n");
1144 neigh_ifinfo = batadv_neigh_ifinfo_new(neigh_node, if_outgoing);
1148 neigh_node->last_seen = jiffies;
1150 spin_lock_bh(&neigh_node->ifinfo_lock);
1151 batadv_ring_buffer_set(neigh_ifinfo->bat_iv.tq_recv,
1152 &neigh_ifinfo->bat_iv.tq_index,
1153 batadv_ogm_packet->tq);
1154 tq_avg = batadv_ring_buffer_avg(neigh_ifinfo->bat_iv.tq_recv);
1155 neigh_ifinfo->bat_iv.tq_avg = tq_avg;
1156 spin_unlock_bh(&neigh_node->ifinfo_lock);
1158 if (dup_status == BATADV_NO_DUP) {
1159 orig_ifinfo->last_ttl = batadv_ogm_packet->ttl;
1160 neigh_ifinfo->last_ttl = batadv_ogm_packet->ttl;
1163 /* if this neighbor already is our next hop there is nothing
1166 router = batadv_orig_router_get(orig_node, if_outgoing);
1167 if (router == neigh_node)
1171 router_ifinfo = batadv_neigh_ifinfo_get(router, if_outgoing);
1175 /* if this neighbor does not offer a better TQ we won't
1178 if (router_ifinfo->bat_iv.tq_avg > neigh_ifinfo->bat_iv.tq_avg)
1182 /* if the TQ is the same and the link not more symmetric we
1183 * won't consider it either
1185 if (router_ifinfo &&
1186 neigh_ifinfo->bat_iv.tq_avg == router_ifinfo->bat_iv.tq_avg) {
1187 orig_node_tmp = router->orig_node;
1188 spin_lock_bh(&orig_node_tmp->bat_iv.ogm_cnt_lock);
1189 if_num = router->if_incoming->if_num;
1190 sum_orig = orig_node_tmp->bat_iv.bcast_own_sum[if_num];
1191 spin_unlock_bh(&orig_node_tmp->bat_iv.ogm_cnt_lock);
1193 orig_node_tmp = neigh_node->orig_node;
1194 spin_lock_bh(&orig_node_tmp->bat_iv.ogm_cnt_lock);
1195 if_num = neigh_node->if_incoming->if_num;
1196 sum_neigh = orig_node_tmp->bat_iv.bcast_own_sum[if_num];
1197 spin_unlock_bh(&orig_node_tmp->bat_iv.ogm_cnt_lock);
1199 if (sum_orig >= sum_neigh)
1203 batadv_update_route(bat_priv, orig_node, if_outgoing, neigh_node);
1210 batadv_neigh_node_put(neigh_node);
1212 batadv_neigh_node_put(router);
1214 batadv_neigh_ifinfo_put(neigh_ifinfo);
1216 batadv_neigh_ifinfo_put(router_ifinfo);
1220 * batadv_iv_ogm_calc_tq - calculate tq for current received ogm packet
1221 * @orig_node: the orig node who originally emitted the ogm packet
1222 * @orig_neigh_node: the orig node struct of the neighbor who sent the packet
1223 * @batadv_ogm_packet: the ogm packet
1224 * @if_incoming: interface where the packet was received
1225 * @if_outgoing: interface for which the retransmission should be considered
1227 * Return: true if the link can be considered bidirectional, false otherwise
1229 static bool batadv_iv_ogm_calc_tq(struct batadv_orig_node *orig_node,
1230 struct batadv_orig_node *orig_neigh_node,
1231 struct batadv_ogm_packet *batadv_ogm_packet,
1232 struct batadv_hard_iface *if_incoming,
1233 struct batadv_hard_iface *if_outgoing)
1235 struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
1236 struct batadv_neigh_node *neigh_node = NULL, *tmp_neigh_node;
1237 struct batadv_neigh_ifinfo *neigh_ifinfo;
1239 u8 orig_eq_count, neigh_rq_count, neigh_rq_inv, tq_own;
1240 unsigned int neigh_rq_inv_cube, neigh_rq_max_cube;
1241 unsigned int if_num;
1242 unsigned int tq_asym_penalty, inv_asym_penalty;
1243 unsigned int combined_tq;
1244 unsigned int tq_iface_penalty;
1247 /* find corresponding one hop neighbor */
1249 hlist_for_each_entry_rcu(tmp_neigh_node,
1250 &orig_neigh_node->neigh_list, list) {
1251 if (!batadv_compare_eth(tmp_neigh_node->addr,
1252 orig_neigh_node->orig))
1255 if (tmp_neigh_node->if_incoming != if_incoming)
1258 if (!kref_get_unless_zero(&tmp_neigh_node->refcount))
1261 neigh_node = tmp_neigh_node;
1267 neigh_node = batadv_iv_ogm_neigh_new(if_incoming,
1268 orig_neigh_node->orig,
1275 /* if orig_node is direct neighbor update neigh_node last_seen */
1276 if (orig_node == orig_neigh_node)
1277 neigh_node->last_seen = jiffies;
1279 orig_node->last_seen = jiffies;
1281 /* find packet count of corresponding one hop neighbor */
1282 spin_lock_bh(&orig_neigh_node->bat_iv.ogm_cnt_lock);
1283 if_num = if_incoming->if_num;
1284 orig_eq_count = orig_neigh_node->bat_iv.bcast_own_sum[if_num];
1285 neigh_ifinfo = batadv_neigh_ifinfo_new(neigh_node, if_outgoing);
1287 neigh_rq_count = neigh_ifinfo->bat_iv.real_packet_count;
1288 batadv_neigh_ifinfo_put(neigh_ifinfo);
1292 spin_unlock_bh(&orig_neigh_node->bat_iv.ogm_cnt_lock);
1294 /* pay attention to not get a value bigger than 100 % */
1295 if (orig_eq_count > neigh_rq_count)
1296 total_count = neigh_rq_count;
1298 total_count = orig_eq_count;
1300 /* if we have too few packets (too less data) we set tq_own to zero
1301 * if we receive too few packets it is not considered bidirectional
1303 if (total_count < BATADV_TQ_LOCAL_BIDRECT_SEND_MINIMUM ||
1304 neigh_rq_count < BATADV_TQ_LOCAL_BIDRECT_RECV_MINIMUM)
1307 /* neigh_node->real_packet_count is never zero as we
1308 * only purge old information when getting new
1311 tq_own = (BATADV_TQ_MAX_VALUE * total_count) / neigh_rq_count;
1313 /* 1 - ((1-x) ** 3), normalized to TQ_MAX_VALUE this does
1314 * affect the nearly-symmetric links only a little, but
1315 * punishes asymmetric links more. This will give a value
1316 * between 0 and TQ_MAX_VALUE
1318 neigh_rq_inv = BATADV_TQ_LOCAL_WINDOW_SIZE - neigh_rq_count;
1319 neigh_rq_inv_cube = neigh_rq_inv * neigh_rq_inv * neigh_rq_inv;
1320 neigh_rq_max_cube = BATADV_TQ_LOCAL_WINDOW_SIZE *
1321 BATADV_TQ_LOCAL_WINDOW_SIZE *
1322 BATADV_TQ_LOCAL_WINDOW_SIZE;
1323 inv_asym_penalty = BATADV_TQ_MAX_VALUE * neigh_rq_inv_cube;
1324 inv_asym_penalty /= neigh_rq_max_cube;
1325 tq_asym_penalty = BATADV_TQ_MAX_VALUE - inv_asym_penalty;
1327 /* penalize if the OGM is forwarded on the same interface. WiFi
1328 * interfaces and other half duplex devices suffer from throughput
1329 * drops as they can't send and receive at the same time.
1331 tq_iface_penalty = BATADV_TQ_MAX_VALUE;
1332 if (if_outgoing && (if_incoming == if_outgoing) &&
1333 batadv_is_wifi_netdev(if_outgoing->net_dev))
1334 tq_iface_penalty = batadv_hop_penalty(BATADV_TQ_MAX_VALUE,
1337 combined_tq = batadv_ogm_packet->tq *
1341 combined_tq /= BATADV_TQ_MAX_VALUE *
1342 BATADV_TQ_MAX_VALUE *
1343 BATADV_TQ_MAX_VALUE;
1344 batadv_ogm_packet->tq = combined_tq;
1346 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1347 "bidirectional: orig = %-15pM neigh = %-15pM => 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",
1348 orig_node->orig, orig_neigh_node->orig, total_count,
1349 neigh_rq_count, tq_own, tq_asym_penalty, tq_iface_penalty,
1350 batadv_ogm_packet->tq, if_incoming->net_dev->name,
1351 if_outgoing ? if_outgoing->net_dev->name : "DEFAULT");
1353 /* if link has the minimum required transmission quality
1354 * consider it bidirectional
1356 if (batadv_ogm_packet->tq >= BATADV_TQ_TOTAL_BIDRECT_LIMIT)
1361 batadv_neigh_node_put(neigh_node);
1366 * batadv_iv_ogm_update_seqnos - process a batman packet for all interfaces,
1367 * adjust the sequence number and find out whether it is a duplicate
1368 * @ethhdr: ethernet header of the packet
1369 * @batadv_ogm_packet: OGM packet to be considered
1370 * @if_incoming: interface on which the OGM packet was received
1371 * @if_outgoing: interface for which the retransmission should be considered
1373 * Return: duplicate status as enum batadv_dup_status
1375 static enum batadv_dup_status
1376 batadv_iv_ogm_update_seqnos(const struct ethhdr *ethhdr,
1377 const struct batadv_ogm_packet *batadv_ogm_packet,
1378 const struct batadv_hard_iface *if_incoming,
1379 struct batadv_hard_iface *if_outgoing)
1381 struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
1382 struct batadv_orig_node *orig_node;
1383 struct batadv_orig_ifinfo *orig_ifinfo = NULL;
1384 struct batadv_neigh_node *neigh_node;
1385 struct batadv_neigh_ifinfo *neigh_ifinfo;
1388 bool need_update = false;
1390 enum batadv_dup_status ret = BATADV_NO_DUP;
1391 u32 seqno = ntohl(batadv_ogm_packet->seqno);
1394 unsigned long *bitmap;
1396 orig_node = batadv_iv_ogm_orig_get(bat_priv, batadv_ogm_packet->orig);
1398 return BATADV_NO_DUP;
1400 orig_ifinfo = batadv_orig_ifinfo_new(orig_node, if_outgoing);
1401 if (WARN_ON(!orig_ifinfo)) {
1402 batadv_orig_node_put(orig_node);
1406 spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock);
1407 seq_diff = seqno - orig_ifinfo->last_real_seqno;
1409 /* signalize caller that the packet is to be dropped. */
1410 if (!hlist_empty(&orig_node->neigh_list) &&
1411 batadv_window_protected(bat_priv, seq_diff,
1412 BATADV_TQ_LOCAL_WINDOW_SIZE,
1413 &orig_ifinfo->batman_seqno_reset, NULL)) {
1414 ret = BATADV_PROTECTED;
1419 hlist_for_each_entry_rcu(neigh_node, &orig_node->neigh_list, list) {
1420 neigh_ifinfo = batadv_neigh_ifinfo_new(neigh_node,
1425 neigh_addr = neigh_node->addr;
1426 is_dup = batadv_test_bit(neigh_ifinfo->bat_iv.real_bits,
1427 orig_ifinfo->last_real_seqno,
1430 if (batadv_compare_eth(neigh_addr, ethhdr->h_source) &&
1431 neigh_node->if_incoming == if_incoming) {
1434 ret = BATADV_NEIGH_DUP;
1437 if (is_dup && (ret != BATADV_NEIGH_DUP))
1438 ret = BATADV_ORIG_DUP;
1441 /* if the window moved, set the update flag. */
1442 bitmap = neigh_ifinfo->bat_iv.real_bits;
1443 need_update |= batadv_bit_get_packet(bat_priv, bitmap,
1444 seq_diff, set_mark);
1446 packet_count = bitmap_weight(bitmap,
1447 BATADV_TQ_LOCAL_WINDOW_SIZE);
1448 neigh_ifinfo->bat_iv.real_packet_count = packet_count;
1449 batadv_neigh_ifinfo_put(neigh_ifinfo);
1454 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1455 "%s updating last_seqno: old %u, new %u\n",
1456 if_outgoing ? if_outgoing->net_dev->name : "DEFAULT",
1457 orig_ifinfo->last_real_seqno, seqno);
1458 orig_ifinfo->last_real_seqno = seqno;
1462 spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock);
1463 batadv_orig_node_put(orig_node);
1464 batadv_orig_ifinfo_put(orig_ifinfo);
1469 * batadv_iv_ogm_process_per_outif - process a batman iv OGM for an outgoing if
1470 * @skb: the skb containing the OGM
1471 * @ogm_offset: offset from skb->data to start of ogm header
1472 * @orig_node: the (cached) orig node for the originator of this OGM
1473 * @if_incoming: the interface where this packet was received
1474 * @if_outgoing: the interface for which the packet should be considered
1477 batadv_iv_ogm_process_per_outif(const struct sk_buff *skb, int ogm_offset,
1478 struct batadv_orig_node *orig_node,
1479 struct batadv_hard_iface *if_incoming,
1480 struct batadv_hard_iface *if_outgoing)
1482 struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
1483 struct batadv_hardif_neigh_node *hardif_neigh = NULL;
1484 struct batadv_neigh_node *router = NULL;
1485 struct batadv_neigh_node *router_router = NULL;
1486 struct batadv_orig_node *orig_neigh_node;
1487 struct batadv_orig_ifinfo *orig_ifinfo;
1488 struct batadv_neigh_node *orig_neigh_router = NULL;
1489 struct batadv_neigh_ifinfo *router_ifinfo = NULL;
1490 struct batadv_ogm_packet *ogm_packet;
1491 enum batadv_dup_status dup_status;
1492 bool is_from_best_next_hop = false;
1493 bool is_single_hop_neigh = false;
1494 bool sameseq, similar_ttl;
1495 struct sk_buff *skb_priv;
1496 struct ethhdr *ethhdr;
1500 /* create a private copy of the skb, as some functions change tq value
1503 skb_priv = skb_copy(skb, GFP_ATOMIC);
1507 ethhdr = eth_hdr(skb_priv);
1508 ogm_packet = (struct batadv_ogm_packet *)(skb_priv->data + ogm_offset);
1510 dup_status = batadv_iv_ogm_update_seqnos(ethhdr, ogm_packet,
1511 if_incoming, if_outgoing);
1512 if (batadv_compare_eth(ethhdr->h_source, ogm_packet->orig))
1513 is_single_hop_neigh = true;
1515 if (dup_status == BATADV_PROTECTED) {
1516 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1517 "Drop packet: packet within seqno protection time (sender: %pM)\n",
1522 if (ogm_packet->tq == 0) {
1523 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1524 "Drop packet: originator packet with tq equal 0\n");
1528 if (is_single_hop_neigh) {
1529 hardif_neigh = batadv_hardif_neigh_get(if_incoming,
1532 hardif_neigh->last_seen = jiffies;
1535 router = batadv_orig_router_get(orig_node, if_outgoing);
1537 router_router = batadv_orig_router_get(router->orig_node,
1539 router_ifinfo = batadv_neigh_ifinfo_get(router, if_outgoing);
1542 if ((router_ifinfo && router_ifinfo->bat_iv.tq_avg != 0) &&
1543 (batadv_compare_eth(router->addr, ethhdr->h_source)))
1544 is_from_best_next_hop = true;
1546 prev_sender = ogm_packet->prev_sender;
1547 /* avoid temporary routing loops */
1548 if (router && router_router &&
1549 (batadv_compare_eth(router->addr, prev_sender)) &&
1550 !(batadv_compare_eth(ogm_packet->orig, prev_sender)) &&
1551 (batadv_compare_eth(router->addr, router_router->addr))) {
1552 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1553 "Drop packet: ignoring all rebroadcast packets that may make me loop (sender: %pM)\n",
1558 if (if_outgoing == BATADV_IF_DEFAULT)
1559 batadv_tvlv_ogm_receive(bat_priv, ogm_packet, orig_node);
1561 /* if sender is a direct neighbor the sender mac equals
1564 if (is_single_hop_neigh)
1565 orig_neigh_node = orig_node;
1567 orig_neigh_node = batadv_iv_ogm_orig_get(bat_priv,
1570 if (!orig_neigh_node)
1573 /* Update nc_nodes of the originator */
1574 batadv_nc_update_nc_node(bat_priv, orig_node, orig_neigh_node,
1575 ogm_packet, is_single_hop_neigh);
1577 orig_neigh_router = batadv_orig_router_get(orig_neigh_node,
1580 /* drop packet if sender is not a direct neighbor and if we
1581 * don't route towards it
1583 if (!is_single_hop_neigh && (!orig_neigh_router)) {
1584 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1585 "Drop packet: OGM via unknown neighbor!\n");
1589 is_bidirect = batadv_iv_ogm_calc_tq(orig_node, orig_neigh_node,
1590 ogm_packet, if_incoming,
1593 /* update ranking if it is not a duplicate or has the same
1594 * seqno and similar ttl as the non-duplicate
1596 orig_ifinfo = batadv_orig_ifinfo_new(orig_node, if_outgoing);
1600 sameseq = orig_ifinfo->last_real_seqno == ntohl(ogm_packet->seqno);
1601 similar_ttl = (orig_ifinfo->last_ttl - 3) <= ogm_packet->ttl;
1603 if (is_bidirect && ((dup_status == BATADV_NO_DUP) ||
1604 (sameseq && similar_ttl))) {
1605 batadv_iv_ogm_orig_update(bat_priv, orig_node,
1606 orig_ifinfo, ethhdr,
1607 ogm_packet, if_incoming,
1608 if_outgoing, dup_status);
1610 batadv_orig_ifinfo_put(orig_ifinfo);
1612 /* only forward for specific interface, not for the default one. */
1613 if (if_outgoing == BATADV_IF_DEFAULT)
1616 /* is single hop (direct) neighbor */
1617 if (is_single_hop_neigh) {
1618 /* OGMs from secondary interfaces should only scheduled once
1619 * per interface where it has been received, not multiple times
1621 if ((ogm_packet->ttl <= 2) &&
1622 (if_incoming != if_outgoing)) {
1623 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1624 "Drop packet: OGM from secondary interface and wrong outgoing interface\n");
1627 /* mark direct link on incoming interface */
1628 batadv_iv_ogm_forward(orig_node, ethhdr, ogm_packet,
1629 is_single_hop_neigh,
1630 is_from_best_next_hop, if_incoming,
1633 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1634 "Forwarding packet: rebroadcast neighbor packet with direct link flag\n");
1638 /* multihop originator */
1640 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1641 "Drop packet: not received via bidirectional link\n");
1645 if (dup_status == BATADV_NEIGH_DUP) {
1646 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1647 "Drop packet: duplicate packet received\n");
1651 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1652 "Forwarding packet: rebroadcast originator packet\n");
1653 batadv_iv_ogm_forward(orig_node, ethhdr, ogm_packet,
1654 is_single_hop_neigh, is_from_best_next_hop,
1655 if_incoming, if_outgoing);
1658 if ((orig_neigh_node) && (!is_single_hop_neigh))
1659 batadv_orig_node_put(orig_neigh_node);
1662 batadv_neigh_ifinfo_put(router_ifinfo);
1664 batadv_neigh_node_put(router);
1666 batadv_neigh_node_put(router_router);
1667 if (orig_neigh_router)
1668 batadv_neigh_node_put(orig_neigh_router);
1670 batadv_hardif_neigh_put(hardif_neigh);
1672 kfree_skb(skb_priv);
1676 * batadv_iv_ogm_process - process an incoming batman iv OGM
1677 * @skb: the skb containing the OGM
1678 * @ogm_offset: offset to the OGM which should be processed (for aggregates)
1679 * @if_incoming: the interface where this packet was receved
1681 static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
1682 struct batadv_hard_iface *if_incoming)
1684 struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
1685 struct batadv_orig_node *orig_neigh_node, *orig_node;
1686 struct batadv_hard_iface *hard_iface;
1687 struct batadv_ogm_packet *ogm_packet;
1688 u32 if_incoming_seqno;
1689 bool has_directlink_flag;
1690 struct ethhdr *ethhdr;
1691 bool is_my_oldorig = false;
1692 bool is_my_addr = false;
1693 bool is_my_orig = false;
1695 ogm_packet = (struct batadv_ogm_packet *)(skb->data + ogm_offset);
1696 ethhdr = eth_hdr(skb);
1698 /* Silently drop when the batman packet is actually not a
1701 * This might happen if a packet is padded (e.g. Ethernet has a
1702 * minimum frame length of 64 byte) and the aggregation interprets
1703 * it as an additional length.
1705 * TODO: A more sane solution would be to have a bit in the
1706 * batadv_ogm_packet to detect whether the packet is the last
1707 * packet in an aggregation. Here we expect that the padding
1708 * is always zero (or not 0x01)
1710 if (ogm_packet->packet_type != BATADV_IV_OGM)
1713 /* could be changed by schedule_own_packet() */
1714 if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
1716 if (ogm_packet->flags & BATADV_DIRECTLINK)
1717 has_directlink_flag = true;
1719 has_directlink_flag = false;
1721 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1722 "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",
1723 ethhdr->h_source, if_incoming->net_dev->name,
1724 if_incoming->net_dev->dev_addr, ogm_packet->orig,
1725 ogm_packet->prev_sender, ntohl(ogm_packet->seqno),
1726 ogm_packet->tq, ogm_packet->ttl,
1727 ogm_packet->version, has_directlink_flag);
1730 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
1731 if (hard_iface->if_status != BATADV_IF_ACTIVE)
1734 if (hard_iface->soft_iface != if_incoming->soft_iface)
1737 if (batadv_compare_eth(ethhdr->h_source,
1738 hard_iface->net_dev->dev_addr))
1741 if (batadv_compare_eth(ogm_packet->orig,
1742 hard_iface->net_dev->dev_addr))
1745 if (batadv_compare_eth(ogm_packet->prev_sender,
1746 hard_iface->net_dev->dev_addr))
1747 is_my_oldorig = true;
1752 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1753 "Drop packet: received my own broadcast (sender: %pM)\n",
1759 unsigned long *word;
1762 unsigned int if_num;
1765 orig_neigh_node = batadv_iv_ogm_orig_get(bat_priv,
1767 if (!orig_neigh_node)
1770 /* neighbor has to indicate direct link and it has to
1771 * come via the corresponding interface
1772 * save packet seqno for bidirectional check
1774 if (has_directlink_flag &&
1775 batadv_compare_eth(if_incoming->net_dev->dev_addr,
1776 ogm_packet->orig)) {
1777 if_num = if_incoming->if_num;
1778 offset = if_num * BATADV_NUM_WORDS;
1780 spin_lock_bh(&orig_neigh_node->bat_iv.ogm_cnt_lock);
1781 word = &orig_neigh_node->bat_iv.bcast_own[offset];
1782 bit_pos = if_incoming_seqno - 2;
1783 bit_pos -= ntohl(ogm_packet->seqno);
1784 batadv_set_bit(word, bit_pos);
1785 weight = &orig_neigh_node->bat_iv.bcast_own_sum[if_num];
1786 *weight = bitmap_weight(word,
1787 BATADV_TQ_LOCAL_WINDOW_SIZE);
1788 spin_unlock_bh(&orig_neigh_node->bat_iv.ogm_cnt_lock);
1791 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1792 "Drop packet: originator packet from myself (via neighbor)\n");
1793 batadv_orig_node_put(orig_neigh_node);
1797 if (is_my_oldorig) {
1798 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1799 "Drop packet: ignoring all rebroadcast echos (sender: %pM)\n",
1804 if (ogm_packet->flags & BATADV_NOT_BEST_NEXT_HOP) {
1805 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1806 "Drop packet: ignoring all packets not forwarded from the best next hop (sender: %pM)\n",
1811 orig_node = batadv_iv_ogm_orig_get(bat_priv, ogm_packet->orig);
1815 batadv_iv_ogm_process_per_outif(skb, ogm_offset, orig_node,
1816 if_incoming, BATADV_IF_DEFAULT);
1819 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
1820 if (hard_iface->if_status != BATADV_IF_ACTIVE)
1823 if (hard_iface->soft_iface != bat_priv->soft_iface)
1826 if (!kref_get_unless_zero(&hard_iface->refcount))
1829 batadv_iv_ogm_process_per_outif(skb, ogm_offset, orig_node,
1830 if_incoming, hard_iface);
1832 batadv_hardif_put(hard_iface);
1836 batadv_orig_node_put(orig_node);
1839 static void batadv_iv_send_outstanding_bat_ogm_packet(struct work_struct *work)
1841 struct delayed_work *delayed_work;
1842 struct batadv_forw_packet *forw_packet;
1843 struct batadv_priv *bat_priv;
1845 delayed_work = to_delayed_work(work);
1846 forw_packet = container_of(delayed_work, struct batadv_forw_packet,
1848 bat_priv = netdev_priv(forw_packet->if_incoming->soft_iface);
1849 spin_lock_bh(&bat_priv->forw_bat_list_lock);
1850 hlist_del(&forw_packet->list);
1851 spin_unlock_bh(&bat_priv->forw_bat_list_lock);
1853 if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_DEACTIVATING)
1856 batadv_iv_ogm_emit(forw_packet);
1858 /* we have to have at least one packet in the queue to determine the
1859 * queues wake up time unless we are shutting down.
1861 * only re-schedule if this is the "original" copy, e.g. the OGM of the
1862 * primary interface should only be rescheduled once per period, but
1863 * this function will be called for the forw_packet instances of the
1864 * other secondary interfaces as well.
1866 if (forw_packet->own &&
1867 forw_packet->if_incoming == forw_packet->if_outgoing)
1868 batadv_iv_ogm_schedule(forw_packet->if_incoming);
1871 batadv_forw_packet_free(forw_packet);
1874 static int batadv_iv_ogm_receive(struct sk_buff *skb,
1875 struct batadv_hard_iface *if_incoming)
1877 struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
1878 struct batadv_ogm_packet *ogm_packet;
1883 ret = batadv_check_management_packet(skb, if_incoming, BATADV_OGM_HLEN);
1887 /* did we receive a B.A.T.M.A.N. IV OGM packet on an interface
1888 * that does not have B.A.T.M.A.N. IV enabled ?
1890 if (bat_priv->algo_ops->iface.enable != batadv_iv_ogm_iface_enable)
1893 batadv_inc_counter(bat_priv, BATADV_CNT_MGMT_RX);
1894 batadv_add_counter(bat_priv, BATADV_CNT_MGMT_RX_BYTES,
1895 skb->len + ETH_HLEN);
1898 ogm_packet = (struct batadv_ogm_packet *)skb->data;
1900 /* unpack the aggregated packets and process them one by one */
1901 while (batadv_iv_ogm_aggr_packet(ogm_offset, skb_headlen(skb),
1903 batadv_iv_ogm_process(skb, ogm_offset, if_incoming);
1905 ogm_offset += BATADV_OGM_HLEN;
1906 ogm_offset += ntohs(ogm_packet->tvlv_len);
1908 packet_pos = skb->data + ogm_offset;
1909 ogm_packet = (struct batadv_ogm_packet *)packet_pos;
1913 return NET_RX_SUCCESS;
1916 #ifdef CONFIG_BATMAN_ADV_DEBUGFS
1918 * batadv_iv_ogm_orig_print_neigh - print neighbors for the originator table
1919 * @orig_node: the orig_node for which the neighbors are printed
1920 * @if_outgoing: outgoing interface for these entries
1921 * @seq: debugfs table seq_file struct
1923 * Must be called while holding an rcu lock.
1926 batadv_iv_ogm_orig_print_neigh(struct batadv_orig_node *orig_node,
1927 struct batadv_hard_iface *if_outgoing,
1928 struct seq_file *seq)
1930 struct batadv_neigh_node *neigh_node;
1931 struct batadv_neigh_ifinfo *n_ifinfo;
1933 hlist_for_each_entry_rcu(neigh_node, &orig_node->neigh_list, list) {
1934 n_ifinfo = batadv_neigh_ifinfo_get(neigh_node, if_outgoing);
1938 seq_printf(seq, " %pM (%3i)",
1940 n_ifinfo->bat_iv.tq_avg);
1942 batadv_neigh_ifinfo_put(n_ifinfo);
1947 * batadv_iv_ogm_orig_print - print the originator table
1948 * @bat_priv: the bat priv with all the soft interface information
1949 * @seq: debugfs table seq_file struct
1950 * @if_outgoing: the outgoing interface for which this should be printed
1952 static void batadv_iv_ogm_orig_print(struct batadv_priv *bat_priv,
1953 struct seq_file *seq,
1954 struct batadv_hard_iface *if_outgoing)
1956 struct batadv_neigh_node *neigh_node;
1957 struct batadv_hashtable *hash = bat_priv->orig_hash;
1958 int last_seen_msecs, last_seen_secs;
1959 struct batadv_orig_node *orig_node;
1960 struct batadv_neigh_ifinfo *n_ifinfo;
1961 unsigned long last_seen_jiffies;
1962 struct hlist_head *head;
1963 int batman_count = 0;
1967 " Originator last-seen (#/255) Nexthop [outgoingIF]: Potential nexthops ...\n");
1969 for (i = 0; i < hash->size; i++) {
1970 head = &hash->table[i];
1973 hlist_for_each_entry_rcu(orig_node, head, hash_entry) {
1974 neigh_node = batadv_orig_router_get(orig_node,
1979 n_ifinfo = batadv_neigh_ifinfo_get(neigh_node,
1984 if (n_ifinfo->bat_iv.tq_avg == 0)
1987 last_seen_jiffies = jiffies - orig_node->last_seen;
1988 last_seen_msecs = jiffies_to_msecs(last_seen_jiffies);
1989 last_seen_secs = last_seen_msecs / 1000;
1990 last_seen_msecs = last_seen_msecs % 1000;
1992 seq_printf(seq, "%pM %4i.%03is (%3i) %pM [%10s]:",
1993 orig_node->orig, last_seen_secs,
1994 last_seen_msecs, n_ifinfo->bat_iv.tq_avg,
1996 neigh_node->if_incoming->net_dev->name);
1998 batadv_iv_ogm_orig_print_neigh(orig_node, if_outgoing,
2000 seq_puts(seq, "\n");
2004 batadv_neigh_node_put(neigh_node);
2006 batadv_neigh_ifinfo_put(n_ifinfo);
2011 if (batman_count == 0)
2012 seq_puts(seq, "No batman nodes in range ...\n");
2017 * batadv_iv_ogm_neigh_get_tq_avg - Get the TQ average for a neighbour on a
2018 * given outgoing interface.
2019 * @neigh_node: Neighbour of interest
2020 * @if_outgoing: Outgoing interface of interest
2021 * @tq_avg: Pointer of where to store the TQ average
2023 * Return: False if no average TQ available, otherwise true.
2026 batadv_iv_ogm_neigh_get_tq_avg(struct batadv_neigh_node *neigh_node,
2027 struct batadv_hard_iface *if_outgoing,
2030 struct batadv_neigh_ifinfo *n_ifinfo;
2032 n_ifinfo = batadv_neigh_ifinfo_get(neigh_node, if_outgoing);
2036 *tq_avg = n_ifinfo->bat_iv.tq_avg;
2037 batadv_neigh_ifinfo_put(n_ifinfo);
2043 * batadv_iv_ogm_orig_dump_subentry - Dump an originator subentry into a
2045 * @msg: Netlink message to dump into
2046 * @portid: Port making netlink request
2047 * @seq: Sequence number of netlink message
2048 * @bat_priv: The bat priv with all the soft interface information
2049 * @if_outgoing: Limit dump to entries with this outgoing interface
2050 * @orig_node: Originator to dump
2051 * @neigh_node: Single hops neighbour
2052 * @best: Is the best originator
2054 * Return: Error code, or 0 on success
2057 batadv_iv_ogm_orig_dump_subentry(struct sk_buff *msg, u32 portid, u32 seq,
2058 struct batadv_priv *bat_priv,
2059 struct batadv_hard_iface *if_outgoing,
2060 struct batadv_orig_node *orig_node,
2061 struct batadv_neigh_node *neigh_node,
2066 unsigned int last_seen_msecs;
2068 last_seen_msecs = jiffies_to_msecs(jiffies - orig_node->last_seen);
2070 if (!batadv_iv_ogm_neigh_get_tq_avg(neigh_node, if_outgoing, &tq_avg))
2073 if (if_outgoing != BATADV_IF_DEFAULT &&
2074 if_outgoing != neigh_node->if_incoming)
2077 hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family,
2078 NLM_F_MULTI, BATADV_CMD_GET_ORIGINATORS);
2082 if (nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN,
2084 nla_put(msg, BATADV_ATTR_NEIGH_ADDRESS, ETH_ALEN,
2085 neigh_node->addr) ||
2086 nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX,
2087 neigh_node->if_incoming->net_dev->ifindex) ||
2088 nla_put_u8(msg, BATADV_ATTR_TQ, tq_avg) ||
2089 nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS,
2091 goto nla_put_failure;
2093 if (best && nla_put_flag(msg, BATADV_ATTR_FLAG_BEST))
2094 goto nla_put_failure;
2096 genlmsg_end(msg, hdr);
2100 genlmsg_cancel(msg, hdr);
2105 * batadv_iv_ogm_orig_dump_entry - Dump an originator entry into a message
2106 * @msg: Netlink message to dump into
2107 * @portid: Port making netlink request
2108 * @seq: Sequence number of netlink message
2109 * @bat_priv: The bat priv with all the soft interface information
2110 * @if_outgoing: Limit dump to entries with this outgoing interface
2111 * @orig_node: Originator to dump
2112 * @sub_s: Number of sub entries to skip
2114 * This function assumes the caller holds rcu_read_lock().
2116 * Return: Error code, or 0 on success
2119 batadv_iv_ogm_orig_dump_entry(struct sk_buff *msg, u32 portid, u32 seq,
2120 struct batadv_priv *bat_priv,
2121 struct batadv_hard_iface *if_outgoing,
2122 struct batadv_orig_node *orig_node, int *sub_s)
2124 struct batadv_neigh_node *neigh_node_best;
2125 struct batadv_neigh_node *neigh_node;
2130 neigh_node_best = batadv_orig_router_get(orig_node, if_outgoing);
2131 if (!neigh_node_best)
2134 if (!batadv_iv_ogm_neigh_get_tq_avg(neigh_node_best, if_outgoing,
2138 if (tq_avg_best == 0)
2141 hlist_for_each_entry_rcu(neigh_node, &orig_node->neigh_list, list) {
2145 best = (neigh_node == neigh_node_best);
2147 if (batadv_iv_ogm_orig_dump_subentry(msg, portid, seq,
2148 bat_priv, if_outgoing,
2149 orig_node, neigh_node,
2151 batadv_neigh_node_put(neigh_node_best);
2159 if (neigh_node_best)
2160 batadv_neigh_node_put(neigh_node_best);
2167 * batadv_iv_ogm_orig_dump_bucket - Dump an originator bucket into a
2169 * @msg: Netlink message to dump into
2170 * @portid: Port making netlink request
2171 * @seq: Sequence number of netlink message
2172 * @bat_priv: The bat priv with all the soft interface information
2173 * @if_outgoing: Limit dump to entries with this outgoing interface
2174 * @head: Bucket to be dumped
2175 * @idx_s: Number of entries to be skipped
2176 * @sub: Number of sub entries to be skipped
2178 * Return: Error code, or 0 on success
2181 batadv_iv_ogm_orig_dump_bucket(struct sk_buff *msg, u32 portid, u32 seq,
2182 struct batadv_priv *bat_priv,
2183 struct batadv_hard_iface *if_outgoing,
2184 struct hlist_head *head, int *idx_s, int *sub)
2186 struct batadv_orig_node *orig_node;
2190 hlist_for_each_entry_rcu(orig_node, head, hash_entry) {
2194 if (batadv_iv_ogm_orig_dump_entry(msg, portid, seq, bat_priv,
2195 if_outgoing, orig_node,
2210 * batadv_iv_ogm_orig_dump - Dump the originators into a message
2211 * @msg: Netlink message to dump into
2212 * @cb: Control block containing additional options
2213 * @bat_priv: The bat priv with all the soft interface information
2214 * @if_outgoing: Limit dump to entries with this outgoing interface
2217 batadv_iv_ogm_orig_dump(struct sk_buff *msg, struct netlink_callback *cb,
2218 struct batadv_priv *bat_priv,
2219 struct batadv_hard_iface *if_outgoing)
2221 struct batadv_hashtable *hash = bat_priv->orig_hash;
2222 struct hlist_head *head;
2223 int bucket = cb->args[0];
2224 int idx = cb->args[1];
2225 int sub = cb->args[2];
2226 int portid = NETLINK_CB(cb->skb).portid;
2228 while (bucket < hash->size) {
2229 head = &hash->table[bucket];
2231 if (batadv_iv_ogm_orig_dump_bucket(msg, portid,
2233 bat_priv, if_outgoing, head,
2240 cb->args[0] = bucket;
2245 #ifdef CONFIG_BATMAN_ADV_DEBUGFS
2247 * batadv_iv_hardif_neigh_print - print a single hop neighbour node
2248 * @seq: neighbour table seq_file struct
2249 * @hardif_neigh: hardif neighbour information
2252 batadv_iv_hardif_neigh_print(struct seq_file *seq,
2253 struct batadv_hardif_neigh_node *hardif_neigh)
2255 int last_secs, last_msecs;
2257 last_secs = jiffies_to_msecs(jiffies - hardif_neigh->last_seen) / 1000;
2258 last_msecs = jiffies_to_msecs(jiffies - hardif_neigh->last_seen) % 1000;
2260 seq_printf(seq, " %10s %pM %4i.%03is\n",
2261 hardif_neigh->if_incoming->net_dev->name,
2262 hardif_neigh->addr, last_secs, last_msecs);
2266 * batadv_iv_ogm_neigh_print - print the single hop neighbour list
2267 * @bat_priv: the bat priv with all the soft interface information
2268 * @seq: neighbour table seq_file struct
2270 static void batadv_iv_neigh_print(struct batadv_priv *bat_priv,
2271 struct seq_file *seq)
2273 struct net_device *net_dev = (struct net_device *)seq->private;
2274 struct batadv_hardif_neigh_node *hardif_neigh;
2275 struct batadv_hard_iface *hard_iface;
2276 int batman_count = 0;
2278 seq_puts(seq, " IF Neighbor last-seen\n");
2281 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
2282 if (hard_iface->soft_iface != net_dev)
2285 hlist_for_each_entry_rcu(hardif_neigh,
2286 &hard_iface->neigh_list, list) {
2287 batadv_iv_hardif_neigh_print(seq, hardif_neigh);
2293 if (batman_count == 0)
2294 seq_puts(seq, "No batman nodes in range ...\n");
2299 * batadv_iv_ogm_neigh_diff - calculate tq difference of two neighbors
2300 * @neigh1: the first neighbor object of the comparison
2301 * @if_outgoing1: outgoing interface for the first neighbor
2302 * @neigh2: the second neighbor object of the comparison
2303 * @if_outgoing2: outgoing interface for the second neighbor
2304 * @diff: pointer to integer receiving the calculated difference
2306 * The content of *@diff is only valid when this function returns true.
2307 * It is less, equal to or greater than 0 if the metric via neigh1 is lower,
2308 * the same as or higher than the metric via neigh2
2310 * Return: true when the difference could be calculated, false otherwise
2312 static bool batadv_iv_ogm_neigh_diff(struct batadv_neigh_node *neigh1,
2313 struct batadv_hard_iface *if_outgoing1,
2314 struct batadv_neigh_node *neigh2,
2315 struct batadv_hard_iface *if_outgoing2,
2318 struct batadv_neigh_ifinfo *neigh1_ifinfo, *neigh2_ifinfo;
2322 neigh1_ifinfo = batadv_neigh_ifinfo_get(neigh1, if_outgoing1);
2323 neigh2_ifinfo = batadv_neigh_ifinfo_get(neigh2, if_outgoing2);
2325 if (!neigh1_ifinfo || !neigh2_ifinfo) {
2330 tq1 = neigh1_ifinfo->bat_iv.tq_avg;
2331 tq2 = neigh2_ifinfo->bat_iv.tq_avg;
2332 *diff = (int)tq1 - (int)tq2;
2336 batadv_neigh_ifinfo_put(neigh1_ifinfo);
2338 batadv_neigh_ifinfo_put(neigh2_ifinfo);
2344 * batadv_iv_ogm_neigh_dump_neigh - Dump a neighbour into a netlink message
2345 * @msg: Netlink message to dump into
2346 * @portid: Port making netlink request
2347 * @seq: Sequence number of netlink message
2348 * @hardif_neigh: Neighbour to be dumped
2350 * Return: Error code, or 0 on success
2353 batadv_iv_ogm_neigh_dump_neigh(struct sk_buff *msg, u32 portid, u32 seq,
2354 struct batadv_hardif_neigh_node *hardif_neigh)
2357 unsigned int last_seen_msecs;
2359 last_seen_msecs = jiffies_to_msecs(jiffies - hardif_neigh->last_seen);
2361 hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family,
2362 NLM_F_MULTI, BATADV_CMD_GET_NEIGHBORS);
2366 if (nla_put(msg, BATADV_ATTR_NEIGH_ADDRESS, ETH_ALEN,
2367 hardif_neigh->addr) ||
2368 nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX,
2369 hardif_neigh->if_incoming->net_dev->ifindex) ||
2370 nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS,
2372 goto nla_put_failure;
2374 genlmsg_end(msg, hdr);
2378 genlmsg_cancel(msg, hdr);
2383 * batadv_iv_ogm_neigh_dump_hardif - Dump the neighbours of a hard interface
2385 * @msg: Netlink message to dump into
2386 * @portid: Port making netlink request
2387 * @seq: Sequence number of netlink message
2388 * @bat_priv: The bat priv with all the soft interface information
2389 * @hard_iface: Hard interface to dump the neighbours for
2390 * @idx_s: Number of entries to skip
2392 * This function assumes the caller holds rcu_read_lock().
2394 * Return: Error code, or 0 on success
2397 batadv_iv_ogm_neigh_dump_hardif(struct sk_buff *msg, u32 portid, u32 seq,
2398 struct batadv_priv *bat_priv,
2399 struct batadv_hard_iface *hard_iface,
2402 struct batadv_hardif_neigh_node *hardif_neigh;
2405 hlist_for_each_entry_rcu(hardif_neigh,
2406 &hard_iface->neigh_list, list) {
2410 if (batadv_iv_ogm_neigh_dump_neigh(msg, portid, seq,
2422 * batadv_iv_ogm_neigh_dump - Dump the neighbours into a message
2423 * @msg: Netlink message to dump into
2424 * @cb: Control block containing additional options
2425 * @bat_priv: The bat priv with all the soft interface information
2426 * @single_hardif: Limit dump to this hard interfaace
2429 batadv_iv_ogm_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb,
2430 struct batadv_priv *bat_priv,
2431 struct batadv_hard_iface *single_hardif)
2433 struct batadv_hard_iface *hard_iface;
2435 int i_hardif_s = cb->args[0];
2436 int idx = cb->args[1];
2437 int portid = NETLINK_CB(cb->skb).portid;
2440 if (single_hardif) {
2441 if (i_hardif_s == 0) {
2442 if (batadv_iv_ogm_neigh_dump_hardif(msg, portid,
2450 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list,
2452 if (hard_iface->soft_iface != bat_priv->soft_iface)
2455 if (i_hardif++ < i_hardif_s)
2458 if (batadv_iv_ogm_neigh_dump_hardif(msg, portid,
2461 hard_iface, &idx)) {
2469 cb->args[0] = i_hardif;
2474 * batadv_iv_ogm_neigh_cmp - compare the metrics of two neighbors
2475 * @neigh1: the first neighbor object of the comparison
2476 * @if_outgoing1: outgoing interface for the first neighbor
2477 * @neigh2: the second neighbor object of the comparison
2478 * @if_outgoing2: outgoing interface for the second neighbor
2480 * Return: a value less, equal to or greater than 0 if the metric via neigh1 is
2481 * lower, the same as or higher than the metric via neigh2
2483 static int batadv_iv_ogm_neigh_cmp(struct batadv_neigh_node *neigh1,
2484 struct batadv_hard_iface *if_outgoing1,
2485 struct batadv_neigh_node *neigh2,
2486 struct batadv_hard_iface *if_outgoing2)
2491 ret = batadv_iv_ogm_neigh_diff(neigh1, if_outgoing1, neigh2,
2492 if_outgoing2, &diff);
2500 * batadv_iv_ogm_neigh_is_sob - check if neigh1 is similarly good or better
2501 * than neigh2 from the metric prospective
2502 * @neigh1: the first neighbor object of the comparison
2503 * @if_outgoing1: outgoing interface for the first neighbor
2504 * @neigh2: the second neighbor object of the comparison
2505 * @if_outgoing2: outgoing interface for the second neighbor
2507 * Return: true if the metric via neigh1 is equally good or better than
2508 * the metric via neigh2, false otherwise.
2511 batadv_iv_ogm_neigh_is_sob(struct batadv_neigh_node *neigh1,
2512 struct batadv_hard_iface *if_outgoing1,
2513 struct batadv_neigh_node *neigh2,
2514 struct batadv_hard_iface *if_outgoing2)
2519 ret = batadv_iv_ogm_neigh_diff(neigh1, if_outgoing1, neigh2,
2520 if_outgoing2, &diff);
2524 ret = diff > -BATADV_TQ_SIMILARITY_THRESHOLD;
2528 static void batadv_iv_iface_enabled(struct batadv_hard_iface *hard_iface)
2530 /* begin scheduling originator messages on that interface */
2531 batadv_iv_ogm_schedule(hard_iface);
2535 * batadv_iv_init_sel_class - initialize GW selection class
2536 * @bat_priv: the bat priv with all the soft interface information
2538 static void batadv_iv_init_sel_class(struct batadv_priv *bat_priv)
2540 /* set default TQ difference threshold to 20 */
2541 atomic_set(&bat_priv->gw.sel_class, 20);
2544 static struct batadv_gw_node *
2545 batadv_iv_gw_get_best_gw_node(struct batadv_priv *bat_priv)
2547 struct batadv_neigh_node *router;
2548 struct batadv_neigh_ifinfo *router_ifinfo;
2549 struct batadv_gw_node *gw_node, *curr_gw = NULL;
2550 u64 max_gw_factor = 0;
2551 u64 tmp_gw_factor = 0;
2554 struct batadv_orig_node *orig_node;
2557 hlist_for_each_entry_rcu(gw_node, &bat_priv->gw.list, list) {
2558 orig_node = gw_node->orig_node;
2559 router = batadv_orig_router_get(orig_node, BATADV_IF_DEFAULT);
2563 router_ifinfo = batadv_neigh_ifinfo_get(router,
2568 if (!kref_get_unless_zero(&gw_node->refcount))
2571 tq_avg = router_ifinfo->bat_iv.tq_avg;
2573 switch (atomic_read(&bat_priv->gw.sel_class)) {
2574 case 1: /* fast connection */
2575 tmp_gw_factor = tq_avg * tq_avg;
2576 tmp_gw_factor *= gw_node->bandwidth_down;
2577 tmp_gw_factor *= 100 * 100;
2578 tmp_gw_factor >>= 18;
2580 if ((tmp_gw_factor > max_gw_factor) ||
2581 ((tmp_gw_factor == max_gw_factor) &&
2582 (tq_avg > max_tq))) {
2584 batadv_gw_node_put(curr_gw);
2586 kref_get(&curr_gw->refcount);
2590 default: /* 2: stable connection (use best statistic)
2591 * 3: fast-switch (use best statistic but change as
2592 * soon as a better gateway appears)
2593 * XX: late-switch (use best statistic but change as
2594 * soon as a better gateway appears which has
2595 * $routing_class more tq points)
2597 if (tq_avg > max_tq) {
2599 batadv_gw_node_put(curr_gw);
2601 kref_get(&curr_gw->refcount);
2606 if (tq_avg > max_tq)
2609 if (tmp_gw_factor > max_gw_factor)
2610 max_gw_factor = tmp_gw_factor;
2612 batadv_gw_node_put(gw_node);
2615 batadv_neigh_node_put(router);
2617 batadv_neigh_ifinfo_put(router_ifinfo);
2624 static bool batadv_iv_gw_is_eligible(struct batadv_priv *bat_priv,
2625 struct batadv_orig_node *curr_gw_orig,
2626 struct batadv_orig_node *orig_node)
2628 struct batadv_neigh_ifinfo *router_orig_ifinfo = NULL;
2629 struct batadv_neigh_ifinfo *router_gw_ifinfo = NULL;
2630 struct batadv_neigh_node *router_gw = NULL;
2631 struct batadv_neigh_node *router_orig = NULL;
2632 u8 gw_tq_avg, orig_tq_avg;
2635 /* dynamic re-election is performed only on fast or late switch */
2636 if (atomic_read(&bat_priv->gw.sel_class) <= 2)
2639 router_gw = batadv_orig_router_get(curr_gw_orig, BATADV_IF_DEFAULT);
2645 router_gw_ifinfo = batadv_neigh_ifinfo_get(router_gw,
2647 if (!router_gw_ifinfo) {
2652 router_orig = batadv_orig_router_get(orig_node, BATADV_IF_DEFAULT);
2656 router_orig_ifinfo = batadv_neigh_ifinfo_get(router_orig,
2658 if (!router_orig_ifinfo)
2661 gw_tq_avg = router_gw_ifinfo->bat_iv.tq_avg;
2662 orig_tq_avg = router_orig_ifinfo->bat_iv.tq_avg;
2664 /* the TQ value has to be better */
2665 if (orig_tq_avg < gw_tq_avg)
2668 /* if the routing class is greater than 3 the value tells us how much
2669 * greater the TQ value of the new gateway must be
2671 if ((atomic_read(&bat_priv->gw.sel_class) > 3) &&
2672 (orig_tq_avg - gw_tq_avg < atomic_read(&bat_priv->gw.sel_class)))
2675 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
2676 "Restarting gateway selection: better gateway found (tq curr: %i, tq new: %i)\n",
2677 gw_tq_avg, orig_tq_avg);
2681 if (router_gw_ifinfo)
2682 batadv_neigh_ifinfo_put(router_gw_ifinfo);
2683 if (router_orig_ifinfo)
2684 batadv_neigh_ifinfo_put(router_orig_ifinfo);
2686 batadv_neigh_node_put(router_gw);
2688 batadv_neigh_node_put(router_orig);
2693 #ifdef CONFIG_BATMAN_ADV_DEBUGFS
2694 /* fails if orig_node has no router */
2695 static int batadv_iv_gw_write_buffer_text(struct batadv_priv *bat_priv,
2696 struct seq_file *seq,
2697 const struct batadv_gw_node *gw_node)
2699 struct batadv_gw_node *curr_gw;
2700 struct batadv_neigh_node *router;
2701 struct batadv_neigh_ifinfo *router_ifinfo = NULL;
2704 router = batadv_orig_router_get(gw_node->orig_node, BATADV_IF_DEFAULT);
2708 router_ifinfo = batadv_neigh_ifinfo_get(router, BATADV_IF_DEFAULT);
2712 curr_gw = batadv_gw_get_selected_gw_node(bat_priv);
2714 seq_printf(seq, "%s %pM (%3i) %pM [%10s]: %u.%u/%u.%u MBit\n",
2715 (curr_gw == gw_node ? "=>" : " "),
2716 gw_node->orig_node->orig,
2717 router_ifinfo->bat_iv.tq_avg, router->addr,
2718 router->if_incoming->net_dev->name,
2719 gw_node->bandwidth_down / 10,
2720 gw_node->bandwidth_down % 10,
2721 gw_node->bandwidth_up / 10,
2722 gw_node->bandwidth_up % 10);
2723 ret = seq_has_overflowed(seq) ? -1 : 0;
2726 batadv_gw_node_put(curr_gw);
2729 batadv_neigh_ifinfo_put(router_ifinfo);
2731 batadv_neigh_node_put(router);
2735 static void batadv_iv_gw_print(struct batadv_priv *bat_priv,
2736 struct seq_file *seq)
2738 struct batadv_gw_node *gw_node;
2742 " Gateway (#/255) Nexthop [outgoingIF]: advertised uplink bandwidth\n");
2745 hlist_for_each_entry_rcu(gw_node, &bat_priv->gw.list, list) {
2746 /* fails if orig_node has no router */
2747 if (batadv_iv_gw_write_buffer_text(bat_priv, seq, gw_node) < 0)
2755 seq_puts(seq, "No gateways in range ...\n");
2760 * batadv_iv_gw_dump_entry - Dump a gateway into a message
2761 * @msg: Netlink message to dump into
2762 * @portid: Port making netlink request
2763 * @seq: Sequence number of netlink message
2764 * @bat_priv: The bat priv with all the soft interface information
2765 * @gw_node: Gateway to be dumped
2767 * Return: Error code, or 0 on success
2769 static int batadv_iv_gw_dump_entry(struct sk_buff *msg, u32 portid, u32 seq,
2770 struct batadv_priv *bat_priv,
2771 struct batadv_gw_node *gw_node)
2773 struct batadv_neigh_ifinfo *router_ifinfo = NULL;
2774 struct batadv_neigh_node *router;
2775 struct batadv_gw_node *curr_gw = NULL;
2779 router = batadv_orig_router_get(gw_node->orig_node, BATADV_IF_DEFAULT);
2783 router_ifinfo = batadv_neigh_ifinfo_get(router, BATADV_IF_DEFAULT);
2787 curr_gw = batadv_gw_get_selected_gw_node(bat_priv);
2789 hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family,
2790 NLM_F_MULTI, BATADV_CMD_GET_GATEWAYS);
2798 if (curr_gw == gw_node)
2799 if (nla_put_flag(msg, BATADV_ATTR_FLAG_BEST)) {
2800 genlmsg_cancel(msg, hdr);
2804 if (nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN,
2805 gw_node->orig_node->orig) ||
2806 nla_put_u8(msg, BATADV_ATTR_TQ, router_ifinfo->bat_iv.tq_avg) ||
2807 nla_put(msg, BATADV_ATTR_ROUTER, ETH_ALEN,
2809 nla_put_string(msg, BATADV_ATTR_HARD_IFNAME,
2810 router->if_incoming->net_dev->name) ||
2811 nla_put_u32(msg, BATADV_ATTR_BANDWIDTH_DOWN,
2812 gw_node->bandwidth_down) ||
2813 nla_put_u32(msg, BATADV_ATTR_BANDWIDTH_UP,
2814 gw_node->bandwidth_up)) {
2815 genlmsg_cancel(msg, hdr);
2819 genlmsg_end(msg, hdr);
2824 batadv_gw_node_put(curr_gw);
2826 batadv_neigh_ifinfo_put(router_ifinfo);
2828 batadv_neigh_node_put(router);
2833 * batadv_iv_gw_dump - Dump gateways into a message
2834 * @msg: Netlink message to dump into
2835 * @cb: Control block containing additional options
2836 * @bat_priv: The bat priv with all the soft interface information
2838 static void batadv_iv_gw_dump(struct sk_buff *msg, struct netlink_callback *cb,
2839 struct batadv_priv *bat_priv)
2841 int portid = NETLINK_CB(cb->skb).portid;
2842 struct batadv_gw_node *gw_node;
2843 int idx_skip = cb->args[0];
2847 hlist_for_each_entry_rcu(gw_node, &bat_priv->gw.list, list) {
2848 if (idx++ < idx_skip)
2851 if (batadv_iv_gw_dump_entry(msg, portid, cb->nlh->nlmsg_seq,
2852 bat_priv, gw_node)) {
2862 cb->args[0] = idx_skip;
2865 static struct batadv_algo_ops batadv_batman_iv __read_mostly = {
2866 .name = "BATMAN_IV",
2868 .enable = batadv_iv_ogm_iface_enable,
2869 .enabled = batadv_iv_iface_enabled,
2870 .disable = batadv_iv_ogm_iface_disable,
2871 .update_mac = batadv_iv_ogm_iface_update_mac,
2872 .primary_set = batadv_iv_ogm_primary_iface_set,
2875 .cmp = batadv_iv_ogm_neigh_cmp,
2876 .is_similar_or_better = batadv_iv_ogm_neigh_is_sob,
2877 #ifdef CONFIG_BATMAN_ADV_DEBUGFS
2878 .print = batadv_iv_neigh_print,
2880 .dump = batadv_iv_ogm_neigh_dump,
2883 #ifdef CONFIG_BATMAN_ADV_DEBUGFS
2884 .print = batadv_iv_ogm_orig_print,
2886 .dump = batadv_iv_ogm_orig_dump,
2887 .free = batadv_iv_ogm_orig_free,
2888 .add_if = batadv_iv_ogm_orig_add_if,
2889 .del_if = batadv_iv_ogm_orig_del_if,
2892 .init_sel_class = batadv_iv_init_sel_class,
2893 .get_best_gw_node = batadv_iv_gw_get_best_gw_node,
2894 .is_eligible = batadv_iv_gw_is_eligible,
2895 #ifdef CONFIG_BATMAN_ADV_DEBUGFS
2896 .print = batadv_iv_gw_print,
2898 .dump = batadv_iv_gw_dump,
2902 int __init batadv_iv_init(void)
2906 /* batman originator packet */
2907 ret = batadv_recv_handler_register(BATADV_IV_OGM,
2908 batadv_iv_ogm_receive);
2912 ret = batadv_algo_register(&batadv_batman_iv);
2914 goto handler_unregister;
2919 batadv_recv_handler_unregister(BATADV_IV_OGM);