1 /* Copyright (C) 2007-2017 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;
724 unsigned char *skb_buff;
725 unsigned int skb_size;
726 atomic_t *queue_left = own_packet ? NULL : &bat_priv->batman_queue_left;
728 if (atomic_read(&bat_priv->aggregated_ogms) &&
729 packet_len < BATADV_MAX_AGGREGATION_BYTES)
730 skb_size = BATADV_MAX_AGGREGATION_BYTES;
732 skb_size = packet_len;
734 skb_size += ETH_HLEN;
736 skb = netdev_alloc_skb_ip_align(NULL, skb_size);
740 forw_packet_aggr = batadv_forw_packet_alloc(if_incoming, if_outgoing,
741 queue_left, bat_priv, skb);
742 if (!forw_packet_aggr) {
747 forw_packet_aggr->skb->priority = TC_PRIO_CONTROL;
748 skb_reserve(forw_packet_aggr->skb, ETH_HLEN);
750 skb_buff = skb_put(forw_packet_aggr->skb, packet_len);
751 forw_packet_aggr->packet_len = packet_len;
752 memcpy(skb_buff, packet_buff, packet_len);
754 forw_packet_aggr->own = own_packet;
755 forw_packet_aggr->direct_link_flags = BATADV_NO_FLAGS;
756 forw_packet_aggr->send_time = send_time;
758 /* save packet direct link flag status */
760 forw_packet_aggr->direct_link_flags |= 1;
762 INIT_DELAYED_WORK(&forw_packet_aggr->delayed_work,
763 batadv_iv_send_outstanding_bat_ogm_packet);
765 batadv_forw_packet_ogmv1_queue(bat_priv, forw_packet_aggr, send_time);
768 /* aggregate a new packet into the existing ogm packet */
769 static void batadv_iv_ogm_aggregate(struct batadv_forw_packet *forw_packet_aggr,
770 const unsigned char *packet_buff,
771 int packet_len, bool direct_link)
773 unsigned long new_direct_link_flag;
775 skb_put_data(forw_packet_aggr->skb, packet_buff, packet_len);
776 forw_packet_aggr->packet_len += packet_len;
777 forw_packet_aggr->num_packets++;
779 /* save packet direct link flag status */
781 new_direct_link_flag = BIT(forw_packet_aggr->num_packets);
782 forw_packet_aggr->direct_link_flags |= new_direct_link_flag;
787 * batadv_iv_ogm_queue_add - queue up an OGM for transmission
788 * @bat_priv: the bat priv with all the soft interface information
789 * @packet_buff: pointer to the OGM
790 * @packet_len: (total) length of the OGM
791 * @if_incoming: interface where the packet was received
792 * @if_outgoing: interface for which the retransmission should be considered
793 * @own_packet: true if it is a self-generated ogm
794 * @send_time: timestamp (jiffies) when the packet is to be sent
796 static void batadv_iv_ogm_queue_add(struct batadv_priv *bat_priv,
797 unsigned char *packet_buff,
799 struct batadv_hard_iface *if_incoming,
800 struct batadv_hard_iface *if_outgoing,
801 int own_packet, unsigned long send_time)
803 /* _aggr -> pointer to the packet we want to aggregate with
804 * _pos -> pointer to the position in the queue
806 struct batadv_forw_packet *forw_packet_aggr = NULL;
807 struct batadv_forw_packet *forw_packet_pos = NULL;
808 struct batadv_ogm_packet *batadv_ogm_packet;
810 unsigned long max_aggregation_jiffies;
812 batadv_ogm_packet = (struct batadv_ogm_packet *)packet_buff;
813 direct_link = !!(batadv_ogm_packet->flags & BATADV_DIRECTLINK);
814 max_aggregation_jiffies = msecs_to_jiffies(BATADV_MAX_AGGREGATION_MS);
816 /* find position for the packet in the forward queue */
817 spin_lock_bh(&bat_priv->forw_bat_list_lock);
818 /* own packets are not to be aggregated */
819 if (atomic_read(&bat_priv->aggregated_ogms) && !own_packet) {
820 hlist_for_each_entry(forw_packet_pos,
821 &bat_priv->forw_bat_list, list) {
822 if (batadv_iv_ogm_can_aggregate(batadv_ogm_packet,
823 bat_priv, packet_len,
824 send_time, direct_link,
828 forw_packet_aggr = forw_packet_pos;
834 /* nothing to aggregate with - either aggregation disabled or no
835 * suitable aggregation packet found
837 if (!forw_packet_aggr) {
838 /* the following section can run without the lock */
839 spin_unlock_bh(&bat_priv->forw_bat_list_lock);
841 /* if we could not aggregate this packet with one of the others
842 * we hold it back for a while, so that it might be aggregated
845 if (!own_packet && atomic_read(&bat_priv->aggregated_ogms))
846 send_time += max_aggregation_jiffies;
848 batadv_iv_ogm_aggregate_new(packet_buff, packet_len,
849 send_time, direct_link,
850 if_incoming, if_outgoing,
853 batadv_iv_ogm_aggregate(forw_packet_aggr, packet_buff,
854 packet_len, direct_link);
855 spin_unlock_bh(&bat_priv->forw_bat_list_lock);
859 static void batadv_iv_ogm_forward(struct batadv_orig_node *orig_node,
860 const struct ethhdr *ethhdr,
861 struct batadv_ogm_packet *batadv_ogm_packet,
862 bool is_single_hop_neigh,
863 bool is_from_best_next_hop,
864 struct batadv_hard_iface *if_incoming,
865 struct batadv_hard_iface *if_outgoing)
867 struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
870 if (batadv_ogm_packet->ttl <= 1) {
871 batadv_dbg(BATADV_DBG_BATMAN, bat_priv, "ttl exceeded\n");
875 if (!is_from_best_next_hop) {
876 /* Mark the forwarded packet when it is not coming from our
877 * best next hop. We still need to forward the packet for our
878 * neighbor link quality detection to work in case the packet
879 * originated from a single hop neighbor. Otherwise we can
880 * simply drop the ogm.
882 if (is_single_hop_neigh)
883 batadv_ogm_packet->flags |= BATADV_NOT_BEST_NEXT_HOP;
888 tvlv_len = ntohs(batadv_ogm_packet->tvlv_len);
890 batadv_ogm_packet->ttl--;
891 ether_addr_copy(batadv_ogm_packet->prev_sender, ethhdr->h_source);
893 /* apply hop penalty */
894 batadv_ogm_packet->tq = batadv_hop_penalty(batadv_ogm_packet->tq,
897 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
898 "Forwarding packet: tq: %i, ttl: %i\n",
899 batadv_ogm_packet->tq, batadv_ogm_packet->ttl);
901 if (is_single_hop_neigh)
902 batadv_ogm_packet->flags |= BATADV_DIRECTLINK;
904 batadv_ogm_packet->flags &= ~BATADV_DIRECTLINK;
906 batadv_iv_ogm_queue_add(bat_priv, (unsigned char *)batadv_ogm_packet,
907 BATADV_OGM_HLEN + tvlv_len,
908 if_incoming, if_outgoing, 0,
909 batadv_iv_ogm_fwd_send_time());
913 * batadv_iv_ogm_slide_own_bcast_window - bitshift own OGM broadcast windows for
914 * the given interface
915 * @hard_iface: the interface for which the windows have to be shifted
918 batadv_iv_ogm_slide_own_bcast_window(struct batadv_hard_iface *hard_iface)
920 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
921 struct batadv_hashtable *hash = bat_priv->orig_hash;
922 struct hlist_head *head;
923 struct batadv_orig_node *orig_node;
930 for (i = 0; i < hash->size; i++) {
931 head = &hash->table[i];
934 hlist_for_each_entry_rcu(orig_node, head, hash_entry) {
935 spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock);
936 word_index = hard_iface->if_num * BATADV_NUM_WORDS;
937 word = &orig_node->bat_iv.bcast_own[word_index];
939 batadv_bit_get_packet(bat_priv, word, 1, 0);
940 if_num = hard_iface->if_num;
941 w = &orig_node->bat_iv.bcast_own_sum[if_num];
942 *w = bitmap_weight(word, BATADV_TQ_LOCAL_WINDOW_SIZE);
943 spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock);
950 * batadv_iv_ogm_schedule_buff() - schedule submission of hardif ogm buffer
951 * @hard_iface: interface whose ogm buffer should be transmitted
953 static void batadv_iv_ogm_schedule_buff(struct batadv_hard_iface *hard_iface)
955 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
956 unsigned char **ogm_buff = &hard_iface->bat_iv.ogm_buff;
957 struct batadv_ogm_packet *batadv_ogm_packet;
958 struct batadv_hard_iface *primary_if, *tmp_hard_iface;
959 int *ogm_buff_len = &hard_iface->bat_iv.ogm_buff_len;
962 unsigned long send_time;
964 lockdep_assert_held(&hard_iface->bat_iv.ogm_buff_mutex);
966 /* interface already disabled by batadv_iv_ogm_iface_disable */
970 /* the interface gets activated here to avoid race conditions between
971 * the moment of activating the interface in
972 * hardif_activate_interface() where the originator mac is set and
973 * outdated packets (especially uninitialized mac addresses) in the
976 if (hard_iface->if_status == BATADV_IF_TO_BE_ACTIVATED)
977 hard_iface->if_status = BATADV_IF_ACTIVE;
979 primary_if = batadv_primary_if_get_selected(bat_priv);
981 if (hard_iface == primary_if) {
982 /* tt changes have to be committed before the tvlv data is
983 * appended as it may alter the tt tvlv container
985 batadv_tt_local_commit_changes(bat_priv);
986 tvlv_len = batadv_tvlv_container_ogm_append(bat_priv, ogm_buff,
991 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
992 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
994 /* change sequence number to network order */
995 seqno = (u32)atomic_read(&hard_iface->bat_iv.ogm_seqno);
996 batadv_ogm_packet->seqno = htonl(seqno);
997 atomic_inc(&hard_iface->bat_iv.ogm_seqno);
999 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
1001 send_time = batadv_iv_ogm_emit_send_time(bat_priv);
1003 if (hard_iface != primary_if) {
1004 /* OGMs from secondary interfaces are only scheduled on their
1005 * respective interfaces.
1007 batadv_iv_ogm_queue_add(bat_priv, *ogm_buff, *ogm_buff_len,
1008 hard_iface, hard_iface, 1, send_time);
1012 /* OGMs from primary interfaces are scheduled on all
1016 list_for_each_entry_rcu(tmp_hard_iface, &batadv_hardif_list, list) {
1017 if (tmp_hard_iface->soft_iface != hard_iface->soft_iface)
1020 if (!kref_get_unless_zero(&tmp_hard_iface->refcount))
1023 batadv_iv_ogm_queue_add(bat_priv, *ogm_buff,
1024 *ogm_buff_len, hard_iface,
1025 tmp_hard_iface, 1, send_time);
1027 batadv_hardif_put(tmp_hard_iface);
1033 batadv_hardif_put(primary_if);
1036 static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
1038 if (hard_iface->if_status == BATADV_IF_NOT_IN_USE ||
1039 hard_iface->if_status == BATADV_IF_TO_BE_REMOVED)
1042 mutex_lock(&hard_iface->bat_iv.ogm_buff_mutex);
1043 batadv_iv_ogm_schedule_buff(hard_iface);
1044 mutex_unlock(&hard_iface->bat_iv.ogm_buff_mutex);
1048 * batadv_iv_ogm_orig_update - use OGM to update corresponding data in an
1050 * @bat_priv: the bat priv with all the soft interface information
1051 * @orig_node: the orig node who originally emitted the ogm packet
1052 * @orig_ifinfo: ifinfo for the outgoing interface of the orig_node
1053 * @ethhdr: Ethernet header of the OGM
1054 * @batadv_ogm_packet: the ogm packet
1055 * @if_incoming: interface where the packet was received
1056 * @if_outgoing: interface for which the retransmission should be considered
1057 * @dup_status: the duplicate status of this ogm packet.
1060 batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv,
1061 struct batadv_orig_node *orig_node,
1062 struct batadv_orig_ifinfo *orig_ifinfo,
1063 const struct ethhdr *ethhdr,
1064 const struct batadv_ogm_packet *batadv_ogm_packet,
1065 struct batadv_hard_iface *if_incoming,
1066 struct batadv_hard_iface *if_outgoing,
1067 enum batadv_dup_status dup_status)
1069 struct batadv_neigh_ifinfo *neigh_ifinfo = NULL;
1070 struct batadv_neigh_ifinfo *router_ifinfo = NULL;
1071 struct batadv_neigh_node *neigh_node = NULL;
1072 struct batadv_neigh_node *tmp_neigh_node = NULL;
1073 struct batadv_neigh_node *router = NULL;
1074 struct batadv_orig_node *orig_node_tmp;
1075 unsigned int if_num;
1076 u8 sum_orig, sum_neigh;
1080 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1081 "%s(): Searching and updating originator entry of received packet\n",
1085 hlist_for_each_entry_rcu(tmp_neigh_node,
1086 &orig_node->neigh_list, list) {
1087 neigh_addr = tmp_neigh_node->addr;
1088 if (batadv_compare_eth(neigh_addr, ethhdr->h_source) &&
1089 tmp_neigh_node->if_incoming == if_incoming &&
1090 kref_get_unless_zero(&tmp_neigh_node->refcount)) {
1091 if (WARN(neigh_node, "too many matching neigh_nodes"))
1092 batadv_neigh_node_put(neigh_node);
1093 neigh_node = tmp_neigh_node;
1097 if (dup_status != BATADV_NO_DUP)
1100 /* only update the entry for this outgoing interface */
1101 neigh_ifinfo = batadv_neigh_ifinfo_get(tmp_neigh_node,
1106 spin_lock_bh(&tmp_neigh_node->ifinfo_lock);
1107 batadv_ring_buffer_set(neigh_ifinfo->bat_iv.tq_recv,
1108 &neigh_ifinfo->bat_iv.tq_index, 0);
1109 tq_avg = batadv_ring_buffer_avg(neigh_ifinfo->bat_iv.tq_recv);
1110 neigh_ifinfo->bat_iv.tq_avg = tq_avg;
1111 spin_unlock_bh(&tmp_neigh_node->ifinfo_lock);
1113 batadv_neigh_ifinfo_put(neigh_ifinfo);
1114 neigh_ifinfo = NULL;
1118 struct batadv_orig_node *orig_tmp;
1120 orig_tmp = batadv_iv_ogm_orig_get(bat_priv, ethhdr->h_source);
1124 neigh_node = batadv_iv_ogm_neigh_new(if_incoming,
1126 orig_node, orig_tmp);
1128 batadv_orig_node_put(orig_tmp);
1132 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1133 "Updating existing last-hop neighbor of originator\n");
1137 neigh_ifinfo = batadv_neigh_ifinfo_new(neigh_node, if_outgoing);
1141 neigh_node->last_seen = jiffies;
1143 spin_lock_bh(&neigh_node->ifinfo_lock);
1144 batadv_ring_buffer_set(neigh_ifinfo->bat_iv.tq_recv,
1145 &neigh_ifinfo->bat_iv.tq_index,
1146 batadv_ogm_packet->tq);
1147 tq_avg = batadv_ring_buffer_avg(neigh_ifinfo->bat_iv.tq_recv);
1148 neigh_ifinfo->bat_iv.tq_avg = tq_avg;
1149 spin_unlock_bh(&neigh_node->ifinfo_lock);
1151 if (dup_status == BATADV_NO_DUP) {
1152 orig_ifinfo->last_ttl = batadv_ogm_packet->ttl;
1153 neigh_ifinfo->last_ttl = batadv_ogm_packet->ttl;
1156 /* if this neighbor already is our next hop there is nothing
1159 router = batadv_orig_router_get(orig_node, if_outgoing);
1160 if (router == neigh_node)
1164 router_ifinfo = batadv_neigh_ifinfo_get(router, if_outgoing);
1168 /* if this neighbor does not offer a better TQ we won't
1171 if (router_ifinfo->bat_iv.tq_avg > neigh_ifinfo->bat_iv.tq_avg)
1175 /* if the TQ is the same and the link not more symmetric we
1176 * won't consider it either
1178 if (router_ifinfo &&
1179 neigh_ifinfo->bat_iv.tq_avg == router_ifinfo->bat_iv.tq_avg) {
1180 orig_node_tmp = router->orig_node;
1181 spin_lock_bh(&orig_node_tmp->bat_iv.ogm_cnt_lock);
1182 if_num = router->if_incoming->if_num;
1183 sum_orig = orig_node_tmp->bat_iv.bcast_own_sum[if_num];
1184 spin_unlock_bh(&orig_node_tmp->bat_iv.ogm_cnt_lock);
1186 orig_node_tmp = neigh_node->orig_node;
1187 spin_lock_bh(&orig_node_tmp->bat_iv.ogm_cnt_lock);
1188 if_num = neigh_node->if_incoming->if_num;
1189 sum_neigh = orig_node_tmp->bat_iv.bcast_own_sum[if_num];
1190 spin_unlock_bh(&orig_node_tmp->bat_iv.ogm_cnt_lock);
1192 if (sum_orig >= sum_neigh)
1196 batadv_update_route(bat_priv, orig_node, if_outgoing, neigh_node);
1203 batadv_neigh_node_put(neigh_node);
1205 batadv_neigh_node_put(router);
1207 batadv_neigh_ifinfo_put(neigh_ifinfo);
1209 batadv_neigh_ifinfo_put(router_ifinfo);
1213 * batadv_iv_ogm_calc_tq - calculate tq for current received ogm packet
1214 * @orig_node: the orig node who originally emitted the ogm packet
1215 * @orig_neigh_node: the orig node struct of the neighbor who sent the packet
1216 * @batadv_ogm_packet: the ogm packet
1217 * @if_incoming: interface where the packet was received
1218 * @if_outgoing: interface for which the retransmission should be considered
1220 * Return: true if the link can be considered bidirectional, false otherwise
1222 static bool batadv_iv_ogm_calc_tq(struct batadv_orig_node *orig_node,
1223 struct batadv_orig_node *orig_neigh_node,
1224 struct batadv_ogm_packet *batadv_ogm_packet,
1225 struct batadv_hard_iface *if_incoming,
1226 struct batadv_hard_iface *if_outgoing)
1228 struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
1229 struct batadv_neigh_node *neigh_node = NULL, *tmp_neigh_node;
1230 struct batadv_neigh_ifinfo *neigh_ifinfo;
1232 u8 orig_eq_count, neigh_rq_count, neigh_rq_inv, tq_own;
1233 unsigned int neigh_rq_inv_cube, neigh_rq_max_cube;
1234 unsigned int if_num;
1235 unsigned int tq_asym_penalty, inv_asym_penalty;
1236 unsigned int combined_tq;
1237 unsigned int tq_iface_penalty;
1240 /* find corresponding one hop neighbor */
1242 hlist_for_each_entry_rcu(tmp_neigh_node,
1243 &orig_neigh_node->neigh_list, list) {
1244 if (!batadv_compare_eth(tmp_neigh_node->addr,
1245 orig_neigh_node->orig))
1248 if (tmp_neigh_node->if_incoming != if_incoming)
1251 if (!kref_get_unless_zero(&tmp_neigh_node->refcount))
1254 neigh_node = tmp_neigh_node;
1260 neigh_node = batadv_iv_ogm_neigh_new(if_incoming,
1261 orig_neigh_node->orig,
1268 /* if orig_node is direct neighbor update neigh_node last_seen */
1269 if (orig_node == orig_neigh_node)
1270 neigh_node->last_seen = jiffies;
1272 orig_node->last_seen = jiffies;
1274 /* find packet count of corresponding one hop neighbor */
1275 spin_lock_bh(&orig_neigh_node->bat_iv.ogm_cnt_lock);
1276 if_num = if_incoming->if_num;
1277 orig_eq_count = orig_neigh_node->bat_iv.bcast_own_sum[if_num];
1278 neigh_ifinfo = batadv_neigh_ifinfo_new(neigh_node, if_outgoing);
1280 neigh_rq_count = neigh_ifinfo->bat_iv.real_packet_count;
1281 batadv_neigh_ifinfo_put(neigh_ifinfo);
1285 spin_unlock_bh(&orig_neigh_node->bat_iv.ogm_cnt_lock);
1287 /* pay attention to not get a value bigger than 100 % */
1288 if (orig_eq_count > neigh_rq_count)
1289 total_count = neigh_rq_count;
1291 total_count = orig_eq_count;
1293 /* if we have too few packets (too less data) we set tq_own to zero
1294 * if we receive too few packets it is not considered bidirectional
1296 if (total_count < BATADV_TQ_LOCAL_BIDRECT_SEND_MINIMUM ||
1297 neigh_rq_count < BATADV_TQ_LOCAL_BIDRECT_RECV_MINIMUM)
1300 /* neigh_node->real_packet_count is never zero as we
1301 * only purge old information when getting new
1304 tq_own = (BATADV_TQ_MAX_VALUE * total_count) / neigh_rq_count;
1306 /* 1 - ((1-x) ** 3), normalized to TQ_MAX_VALUE this does
1307 * affect the nearly-symmetric links only a little, but
1308 * punishes asymmetric links more. This will give a value
1309 * between 0 and TQ_MAX_VALUE
1311 neigh_rq_inv = BATADV_TQ_LOCAL_WINDOW_SIZE - neigh_rq_count;
1312 neigh_rq_inv_cube = neigh_rq_inv * neigh_rq_inv * neigh_rq_inv;
1313 neigh_rq_max_cube = BATADV_TQ_LOCAL_WINDOW_SIZE *
1314 BATADV_TQ_LOCAL_WINDOW_SIZE *
1315 BATADV_TQ_LOCAL_WINDOW_SIZE;
1316 inv_asym_penalty = BATADV_TQ_MAX_VALUE * neigh_rq_inv_cube;
1317 inv_asym_penalty /= neigh_rq_max_cube;
1318 tq_asym_penalty = BATADV_TQ_MAX_VALUE - inv_asym_penalty;
1320 /* penalize if the OGM is forwarded on the same interface. WiFi
1321 * interfaces and other half duplex devices suffer from throughput
1322 * drops as they can't send and receive at the same time.
1324 tq_iface_penalty = BATADV_TQ_MAX_VALUE;
1325 if (if_outgoing && (if_incoming == if_outgoing) &&
1326 batadv_is_wifi_hardif(if_outgoing))
1327 tq_iface_penalty = batadv_hop_penalty(BATADV_TQ_MAX_VALUE,
1330 combined_tq = batadv_ogm_packet->tq *
1334 combined_tq /= BATADV_TQ_MAX_VALUE *
1335 BATADV_TQ_MAX_VALUE *
1336 BATADV_TQ_MAX_VALUE;
1337 batadv_ogm_packet->tq = combined_tq;
1339 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1340 "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",
1341 orig_node->orig, orig_neigh_node->orig, total_count,
1342 neigh_rq_count, tq_own, tq_asym_penalty, tq_iface_penalty,
1343 batadv_ogm_packet->tq, if_incoming->net_dev->name,
1344 if_outgoing ? if_outgoing->net_dev->name : "DEFAULT");
1346 /* if link has the minimum required transmission quality
1347 * consider it bidirectional
1349 if (batadv_ogm_packet->tq >= BATADV_TQ_TOTAL_BIDRECT_LIMIT)
1354 batadv_neigh_node_put(neigh_node);
1359 * batadv_iv_ogm_update_seqnos - process a batman packet for all interfaces,
1360 * adjust the sequence number and find out whether it is a duplicate
1361 * @ethhdr: ethernet header of the packet
1362 * @batadv_ogm_packet: OGM packet to be considered
1363 * @if_incoming: interface on which the OGM packet was received
1364 * @if_outgoing: interface for which the retransmission should be considered
1366 * Return: duplicate status as enum batadv_dup_status
1368 static enum batadv_dup_status
1369 batadv_iv_ogm_update_seqnos(const struct ethhdr *ethhdr,
1370 const struct batadv_ogm_packet *batadv_ogm_packet,
1371 const struct batadv_hard_iface *if_incoming,
1372 struct batadv_hard_iface *if_outgoing)
1374 struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
1375 struct batadv_orig_node *orig_node;
1376 struct batadv_orig_ifinfo *orig_ifinfo = NULL;
1377 struct batadv_neigh_node *neigh_node;
1378 struct batadv_neigh_ifinfo *neigh_ifinfo;
1381 bool need_update = false;
1383 enum batadv_dup_status ret = BATADV_NO_DUP;
1384 u32 seqno = ntohl(batadv_ogm_packet->seqno);
1387 unsigned long *bitmap;
1389 orig_node = batadv_iv_ogm_orig_get(bat_priv, batadv_ogm_packet->orig);
1391 return BATADV_NO_DUP;
1393 orig_ifinfo = batadv_orig_ifinfo_new(orig_node, if_outgoing);
1394 if (WARN_ON(!orig_ifinfo)) {
1395 batadv_orig_node_put(orig_node);
1399 spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock);
1400 seq_diff = seqno - orig_ifinfo->last_real_seqno;
1402 /* signalize caller that the packet is to be dropped. */
1403 if (!hlist_empty(&orig_node->neigh_list) &&
1404 batadv_window_protected(bat_priv, seq_diff,
1405 BATADV_TQ_LOCAL_WINDOW_SIZE,
1406 &orig_ifinfo->batman_seqno_reset, NULL)) {
1407 ret = BATADV_PROTECTED;
1412 hlist_for_each_entry_rcu(neigh_node, &orig_node->neigh_list, list) {
1413 neigh_ifinfo = batadv_neigh_ifinfo_new(neigh_node,
1418 neigh_addr = neigh_node->addr;
1419 is_dup = batadv_test_bit(neigh_ifinfo->bat_iv.real_bits,
1420 orig_ifinfo->last_real_seqno,
1423 if (batadv_compare_eth(neigh_addr, ethhdr->h_source) &&
1424 neigh_node->if_incoming == if_incoming) {
1427 ret = BATADV_NEIGH_DUP;
1430 if (is_dup && (ret != BATADV_NEIGH_DUP))
1431 ret = BATADV_ORIG_DUP;
1434 /* if the window moved, set the update flag. */
1435 bitmap = neigh_ifinfo->bat_iv.real_bits;
1436 need_update |= batadv_bit_get_packet(bat_priv, bitmap,
1437 seq_diff, set_mark);
1439 packet_count = bitmap_weight(bitmap,
1440 BATADV_TQ_LOCAL_WINDOW_SIZE);
1441 neigh_ifinfo->bat_iv.real_packet_count = packet_count;
1442 batadv_neigh_ifinfo_put(neigh_ifinfo);
1447 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1448 "%s updating last_seqno: old %u, new %u\n",
1449 if_outgoing ? if_outgoing->net_dev->name : "DEFAULT",
1450 orig_ifinfo->last_real_seqno, seqno);
1451 orig_ifinfo->last_real_seqno = seqno;
1455 spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock);
1456 batadv_orig_node_put(orig_node);
1457 batadv_orig_ifinfo_put(orig_ifinfo);
1462 * batadv_iv_ogm_process_per_outif - process a batman iv OGM for an outgoing if
1463 * @skb: the skb containing the OGM
1464 * @ogm_offset: offset from skb->data to start of ogm header
1465 * @orig_node: the (cached) orig node for the originator of this OGM
1466 * @if_incoming: the interface where this packet was received
1467 * @if_outgoing: the interface for which the packet should be considered
1470 batadv_iv_ogm_process_per_outif(const struct sk_buff *skb, int ogm_offset,
1471 struct batadv_orig_node *orig_node,
1472 struct batadv_hard_iface *if_incoming,
1473 struct batadv_hard_iface *if_outgoing)
1475 struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
1476 struct batadv_hardif_neigh_node *hardif_neigh = NULL;
1477 struct batadv_neigh_node *router = NULL;
1478 struct batadv_neigh_node *router_router = NULL;
1479 struct batadv_orig_node *orig_neigh_node;
1480 struct batadv_orig_ifinfo *orig_ifinfo;
1481 struct batadv_neigh_node *orig_neigh_router = NULL;
1482 struct batadv_neigh_ifinfo *router_ifinfo = NULL;
1483 struct batadv_ogm_packet *ogm_packet;
1484 enum batadv_dup_status dup_status;
1485 bool is_from_best_next_hop = false;
1486 bool is_single_hop_neigh = false;
1487 bool sameseq, similar_ttl;
1488 struct sk_buff *skb_priv;
1489 struct ethhdr *ethhdr;
1493 /* create a private copy of the skb, as some functions change tq value
1496 skb_priv = skb_copy(skb, GFP_ATOMIC);
1500 ethhdr = eth_hdr(skb_priv);
1501 ogm_packet = (struct batadv_ogm_packet *)(skb_priv->data + ogm_offset);
1503 dup_status = batadv_iv_ogm_update_seqnos(ethhdr, ogm_packet,
1504 if_incoming, if_outgoing);
1505 if (batadv_compare_eth(ethhdr->h_source, ogm_packet->orig))
1506 is_single_hop_neigh = true;
1508 if (dup_status == BATADV_PROTECTED) {
1509 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1510 "Drop packet: packet within seqno protection time (sender: %pM)\n",
1515 if (ogm_packet->tq == 0) {
1516 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1517 "Drop packet: originator packet with tq equal 0\n");
1521 if (is_single_hop_neigh) {
1522 hardif_neigh = batadv_hardif_neigh_get(if_incoming,
1525 hardif_neigh->last_seen = jiffies;
1528 router = batadv_orig_router_get(orig_node, if_outgoing);
1530 router_router = batadv_orig_router_get(router->orig_node,
1532 router_ifinfo = batadv_neigh_ifinfo_get(router, if_outgoing);
1535 if ((router_ifinfo && router_ifinfo->bat_iv.tq_avg != 0) &&
1536 (batadv_compare_eth(router->addr, ethhdr->h_source)))
1537 is_from_best_next_hop = true;
1539 prev_sender = ogm_packet->prev_sender;
1540 /* avoid temporary routing loops */
1541 if (router && router_router &&
1542 (batadv_compare_eth(router->addr, prev_sender)) &&
1543 !(batadv_compare_eth(ogm_packet->orig, prev_sender)) &&
1544 (batadv_compare_eth(router->addr, router_router->addr))) {
1545 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1546 "Drop packet: ignoring all rebroadcast packets that may make me loop (sender: %pM)\n",
1551 if (if_outgoing == BATADV_IF_DEFAULT)
1552 batadv_tvlv_ogm_receive(bat_priv, ogm_packet, orig_node);
1554 /* if sender is a direct neighbor the sender mac equals
1557 if (is_single_hop_neigh)
1558 orig_neigh_node = orig_node;
1560 orig_neigh_node = batadv_iv_ogm_orig_get(bat_priv,
1563 if (!orig_neigh_node)
1566 /* Update nc_nodes of the originator */
1567 batadv_nc_update_nc_node(bat_priv, orig_node, orig_neigh_node,
1568 ogm_packet, is_single_hop_neigh);
1570 orig_neigh_router = batadv_orig_router_get(orig_neigh_node,
1573 /* drop packet if sender is not a direct neighbor and if we
1574 * don't route towards it
1576 if (!is_single_hop_neigh && (!orig_neigh_router)) {
1577 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1578 "Drop packet: OGM via unknown neighbor!\n");
1582 is_bidirect = batadv_iv_ogm_calc_tq(orig_node, orig_neigh_node,
1583 ogm_packet, if_incoming,
1586 /* update ranking if it is not a duplicate or has the same
1587 * seqno and similar ttl as the non-duplicate
1589 orig_ifinfo = batadv_orig_ifinfo_new(orig_node, if_outgoing);
1593 sameseq = orig_ifinfo->last_real_seqno == ntohl(ogm_packet->seqno);
1594 similar_ttl = (orig_ifinfo->last_ttl - 3) <= ogm_packet->ttl;
1596 if (is_bidirect && ((dup_status == BATADV_NO_DUP) ||
1597 (sameseq && similar_ttl))) {
1598 batadv_iv_ogm_orig_update(bat_priv, orig_node,
1599 orig_ifinfo, ethhdr,
1600 ogm_packet, if_incoming,
1601 if_outgoing, dup_status);
1603 batadv_orig_ifinfo_put(orig_ifinfo);
1605 /* only forward for specific interface, not for the default one. */
1606 if (if_outgoing == BATADV_IF_DEFAULT)
1609 /* is single hop (direct) neighbor */
1610 if (is_single_hop_neigh) {
1611 /* OGMs from secondary interfaces should only scheduled once
1612 * per interface where it has been received, not multiple times
1614 if ((ogm_packet->ttl <= 2) &&
1615 (if_incoming != if_outgoing)) {
1616 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1617 "Drop packet: OGM from secondary interface and wrong outgoing interface\n");
1620 /* mark direct link on incoming interface */
1621 batadv_iv_ogm_forward(orig_node, ethhdr, ogm_packet,
1622 is_single_hop_neigh,
1623 is_from_best_next_hop, if_incoming,
1626 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1627 "Forwarding packet: rebroadcast neighbor packet with direct link flag\n");
1631 /* multihop originator */
1633 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1634 "Drop packet: not received via bidirectional link\n");
1638 if (dup_status == BATADV_NEIGH_DUP) {
1639 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1640 "Drop packet: duplicate packet received\n");
1644 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1645 "Forwarding packet: rebroadcast originator packet\n");
1646 batadv_iv_ogm_forward(orig_node, ethhdr, ogm_packet,
1647 is_single_hop_neigh, is_from_best_next_hop,
1648 if_incoming, if_outgoing);
1651 if ((orig_neigh_node) && (!is_single_hop_neigh))
1652 batadv_orig_node_put(orig_neigh_node);
1655 batadv_neigh_ifinfo_put(router_ifinfo);
1657 batadv_neigh_node_put(router);
1659 batadv_neigh_node_put(router_router);
1660 if (orig_neigh_router)
1661 batadv_neigh_node_put(orig_neigh_router);
1663 batadv_hardif_neigh_put(hardif_neigh);
1665 consume_skb(skb_priv);
1669 * batadv_iv_ogm_process - process an incoming batman iv OGM
1670 * @skb: the skb containing the OGM
1671 * @ogm_offset: offset to the OGM which should be processed (for aggregates)
1672 * @if_incoming: the interface where this packet was receved
1674 static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
1675 struct batadv_hard_iface *if_incoming)
1677 struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
1678 struct batadv_orig_node *orig_neigh_node, *orig_node;
1679 struct batadv_hard_iface *hard_iface;
1680 struct batadv_ogm_packet *ogm_packet;
1681 u32 if_incoming_seqno;
1682 bool has_directlink_flag;
1683 struct ethhdr *ethhdr;
1684 bool is_my_oldorig = false;
1685 bool is_my_addr = false;
1686 bool is_my_orig = false;
1688 ogm_packet = (struct batadv_ogm_packet *)(skb->data + ogm_offset);
1689 ethhdr = eth_hdr(skb);
1691 /* Silently drop when the batman packet is actually not a
1694 * This might happen if a packet is padded (e.g. Ethernet has a
1695 * minimum frame length of 64 byte) and the aggregation interprets
1696 * it as an additional length.
1698 * TODO: A more sane solution would be to have a bit in the
1699 * batadv_ogm_packet to detect whether the packet is the last
1700 * packet in an aggregation. Here we expect that the padding
1701 * is always zero (or not 0x01)
1703 if (ogm_packet->packet_type != BATADV_IV_OGM)
1706 /* could be changed by schedule_own_packet() */
1707 if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
1709 if (ogm_packet->flags & BATADV_DIRECTLINK)
1710 has_directlink_flag = true;
1712 has_directlink_flag = false;
1714 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1715 "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",
1716 ethhdr->h_source, if_incoming->net_dev->name,
1717 if_incoming->net_dev->dev_addr, ogm_packet->orig,
1718 ogm_packet->prev_sender, ntohl(ogm_packet->seqno),
1719 ogm_packet->tq, ogm_packet->ttl,
1720 ogm_packet->version, has_directlink_flag);
1723 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
1724 if (hard_iface->if_status != BATADV_IF_ACTIVE)
1727 if (hard_iface->soft_iface != if_incoming->soft_iface)
1730 if (batadv_compare_eth(ethhdr->h_source,
1731 hard_iface->net_dev->dev_addr))
1734 if (batadv_compare_eth(ogm_packet->orig,
1735 hard_iface->net_dev->dev_addr))
1738 if (batadv_compare_eth(ogm_packet->prev_sender,
1739 hard_iface->net_dev->dev_addr))
1740 is_my_oldorig = true;
1745 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1746 "Drop packet: received my own broadcast (sender: %pM)\n",
1752 unsigned long *word;
1755 unsigned int if_num;
1758 orig_neigh_node = batadv_iv_ogm_orig_get(bat_priv,
1760 if (!orig_neigh_node)
1763 /* neighbor has to indicate direct link and it has to
1764 * come via the corresponding interface
1765 * save packet seqno for bidirectional check
1767 if (has_directlink_flag &&
1768 batadv_compare_eth(if_incoming->net_dev->dev_addr,
1769 ogm_packet->orig)) {
1770 if_num = if_incoming->if_num;
1771 offset = if_num * BATADV_NUM_WORDS;
1773 spin_lock_bh(&orig_neigh_node->bat_iv.ogm_cnt_lock);
1774 word = &orig_neigh_node->bat_iv.bcast_own[offset];
1775 bit_pos = if_incoming_seqno - 2;
1776 bit_pos -= ntohl(ogm_packet->seqno);
1777 batadv_set_bit(word, bit_pos);
1778 weight = &orig_neigh_node->bat_iv.bcast_own_sum[if_num];
1779 *weight = bitmap_weight(word,
1780 BATADV_TQ_LOCAL_WINDOW_SIZE);
1781 spin_unlock_bh(&orig_neigh_node->bat_iv.ogm_cnt_lock);
1784 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1785 "Drop packet: originator packet from myself (via neighbor)\n");
1786 batadv_orig_node_put(orig_neigh_node);
1790 if (is_my_oldorig) {
1791 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1792 "Drop packet: ignoring all rebroadcast echos (sender: %pM)\n",
1797 if (ogm_packet->flags & BATADV_NOT_BEST_NEXT_HOP) {
1798 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1799 "Drop packet: ignoring all packets not forwarded from the best next hop (sender: %pM)\n",
1804 orig_node = batadv_iv_ogm_orig_get(bat_priv, ogm_packet->orig);
1808 batadv_iv_ogm_process_per_outif(skb, ogm_offset, orig_node,
1809 if_incoming, BATADV_IF_DEFAULT);
1812 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
1813 if (hard_iface->if_status != BATADV_IF_ACTIVE)
1816 if (hard_iface->soft_iface != bat_priv->soft_iface)
1819 if (!kref_get_unless_zero(&hard_iface->refcount))
1822 batadv_iv_ogm_process_per_outif(skb, ogm_offset, orig_node,
1823 if_incoming, hard_iface);
1825 batadv_hardif_put(hard_iface);
1829 batadv_orig_node_put(orig_node);
1832 static void batadv_iv_send_outstanding_bat_ogm_packet(struct work_struct *work)
1834 struct delayed_work *delayed_work;
1835 struct batadv_forw_packet *forw_packet;
1836 struct batadv_priv *bat_priv;
1837 bool dropped = false;
1839 delayed_work = to_delayed_work(work);
1840 forw_packet = container_of(delayed_work, struct batadv_forw_packet,
1842 bat_priv = netdev_priv(forw_packet->if_incoming->soft_iface);
1844 if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_DEACTIVATING) {
1849 batadv_iv_ogm_emit(forw_packet);
1851 /* we have to have at least one packet in the queue to determine the
1852 * queues wake up time unless we are shutting down.
1854 * only re-schedule if this is the "original" copy, e.g. the OGM of the
1855 * primary interface should only be rescheduled once per period, but
1856 * this function will be called for the forw_packet instances of the
1857 * other secondary interfaces as well.
1859 if (forw_packet->own &&
1860 forw_packet->if_incoming == forw_packet->if_outgoing)
1861 batadv_iv_ogm_schedule(forw_packet->if_incoming);
1864 /* do we get something for free()? */
1865 if (batadv_forw_packet_steal(forw_packet,
1866 &bat_priv->forw_bat_list_lock))
1867 batadv_forw_packet_free(forw_packet, dropped);
1870 static int batadv_iv_ogm_receive(struct sk_buff *skb,
1871 struct batadv_hard_iface *if_incoming)
1873 struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
1874 struct batadv_ogm_packet *ogm_packet;
1878 int ret = NET_RX_DROP;
1880 res = batadv_check_management_packet(skb, if_incoming, BATADV_OGM_HLEN);
1884 /* did we receive a B.A.T.M.A.N. IV OGM packet on an interface
1885 * that does not have B.A.T.M.A.N. IV enabled ?
1887 if (bat_priv->algo_ops->iface.enable != batadv_iv_ogm_iface_enable)
1890 batadv_inc_counter(bat_priv, BATADV_CNT_MGMT_RX);
1891 batadv_add_counter(bat_priv, BATADV_CNT_MGMT_RX_BYTES,
1892 skb->len + ETH_HLEN);
1895 ogm_packet = (struct batadv_ogm_packet *)skb->data;
1897 /* unpack the aggregated packets and process them one by one */
1898 while (batadv_iv_ogm_aggr_packet(ogm_offset, skb_headlen(skb),
1900 batadv_iv_ogm_process(skb, ogm_offset, if_incoming);
1902 ogm_offset += BATADV_OGM_HLEN;
1903 ogm_offset += ntohs(ogm_packet->tvlv_len);
1905 packet_pos = skb->data + ogm_offset;
1906 ogm_packet = (struct batadv_ogm_packet *)packet_pos;
1909 ret = NET_RX_SUCCESS;
1912 if (ret == NET_RX_SUCCESS)
1920 #ifdef CONFIG_BATMAN_ADV_DEBUGFS
1922 * batadv_iv_ogm_orig_print_neigh - print neighbors for the originator table
1923 * @orig_node: the orig_node for which the neighbors are printed
1924 * @if_outgoing: outgoing interface for these entries
1925 * @seq: debugfs table seq_file struct
1927 * Must be called while holding an rcu lock.
1930 batadv_iv_ogm_orig_print_neigh(struct batadv_orig_node *orig_node,
1931 struct batadv_hard_iface *if_outgoing,
1932 struct seq_file *seq)
1934 struct batadv_neigh_node *neigh_node;
1935 struct batadv_neigh_ifinfo *n_ifinfo;
1937 hlist_for_each_entry_rcu(neigh_node, &orig_node->neigh_list, list) {
1938 n_ifinfo = batadv_neigh_ifinfo_get(neigh_node, if_outgoing);
1942 seq_printf(seq, " %pM (%3i)",
1944 n_ifinfo->bat_iv.tq_avg);
1946 batadv_neigh_ifinfo_put(n_ifinfo);
1951 * batadv_iv_ogm_orig_print - print the originator table
1952 * @bat_priv: the bat priv with all the soft interface information
1953 * @seq: debugfs table seq_file struct
1954 * @if_outgoing: the outgoing interface for which this should be printed
1956 static void batadv_iv_ogm_orig_print(struct batadv_priv *bat_priv,
1957 struct seq_file *seq,
1958 struct batadv_hard_iface *if_outgoing)
1960 struct batadv_neigh_node *neigh_node;
1961 struct batadv_hashtable *hash = bat_priv->orig_hash;
1962 int last_seen_msecs, last_seen_secs;
1963 struct batadv_orig_node *orig_node;
1964 struct batadv_neigh_ifinfo *n_ifinfo;
1965 unsigned long last_seen_jiffies;
1966 struct hlist_head *head;
1967 int batman_count = 0;
1971 " Originator last-seen (#/255) Nexthop [outgoingIF]: Potential nexthops ...\n");
1973 for (i = 0; i < hash->size; i++) {
1974 head = &hash->table[i];
1977 hlist_for_each_entry_rcu(orig_node, head, hash_entry) {
1978 neigh_node = batadv_orig_router_get(orig_node,
1983 n_ifinfo = batadv_neigh_ifinfo_get(neigh_node,
1988 if (n_ifinfo->bat_iv.tq_avg == 0)
1991 last_seen_jiffies = jiffies - orig_node->last_seen;
1992 last_seen_msecs = jiffies_to_msecs(last_seen_jiffies);
1993 last_seen_secs = last_seen_msecs / 1000;
1994 last_seen_msecs = last_seen_msecs % 1000;
1996 seq_printf(seq, "%pM %4i.%03is (%3i) %pM [%10s]:",
1997 orig_node->orig, last_seen_secs,
1998 last_seen_msecs, n_ifinfo->bat_iv.tq_avg,
2000 neigh_node->if_incoming->net_dev->name);
2002 batadv_iv_ogm_orig_print_neigh(orig_node, if_outgoing,
2004 seq_putc(seq, '\n');
2008 batadv_neigh_node_put(neigh_node);
2010 batadv_neigh_ifinfo_put(n_ifinfo);
2015 if (batman_count == 0)
2016 seq_puts(seq, "No batman nodes in range ...\n");
2021 * batadv_iv_ogm_neigh_get_tq_avg - Get the TQ average for a neighbour on a
2022 * given outgoing interface.
2023 * @neigh_node: Neighbour of interest
2024 * @if_outgoing: Outgoing interface of interest
2025 * @tq_avg: Pointer of where to store the TQ average
2027 * Return: False if no average TQ available, otherwise true.
2030 batadv_iv_ogm_neigh_get_tq_avg(struct batadv_neigh_node *neigh_node,
2031 struct batadv_hard_iface *if_outgoing,
2034 struct batadv_neigh_ifinfo *n_ifinfo;
2036 n_ifinfo = batadv_neigh_ifinfo_get(neigh_node, if_outgoing);
2040 *tq_avg = n_ifinfo->bat_iv.tq_avg;
2041 batadv_neigh_ifinfo_put(n_ifinfo);
2047 * batadv_iv_ogm_orig_dump_subentry - Dump an originator subentry into a
2049 * @msg: Netlink message to dump into
2050 * @portid: Port making netlink request
2051 * @seq: Sequence number of netlink message
2052 * @bat_priv: The bat priv with all the soft interface information
2053 * @if_outgoing: Limit dump to entries with this outgoing interface
2054 * @orig_node: Originator to dump
2055 * @neigh_node: Single hops neighbour
2056 * @best: Is the best originator
2058 * Return: Error code, or 0 on success
2061 batadv_iv_ogm_orig_dump_subentry(struct sk_buff *msg, u32 portid, u32 seq,
2062 struct batadv_priv *bat_priv,
2063 struct batadv_hard_iface *if_outgoing,
2064 struct batadv_orig_node *orig_node,
2065 struct batadv_neigh_node *neigh_node,
2070 unsigned int last_seen_msecs;
2072 last_seen_msecs = jiffies_to_msecs(jiffies - orig_node->last_seen);
2074 if (!batadv_iv_ogm_neigh_get_tq_avg(neigh_node, if_outgoing, &tq_avg))
2077 if (if_outgoing != BATADV_IF_DEFAULT &&
2078 if_outgoing != neigh_node->if_incoming)
2081 hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family,
2082 NLM_F_MULTI, BATADV_CMD_GET_ORIGINATORS);
2086 if (nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN,
2088 nla_put(msg, BATADV_ATTR_NEIGH_ADDRESS, ETH_ALEN,
2089 neigh_node->addr) ||
2090 nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX,
2091 neigh_node->if_incoming->net_dev->ifindex) ||
2092 nla_put_u8(msg, BATADV_ATTR_TQ, tq_avg) ||
2093 nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS,
2095 goto nla_put_failure;
2097 if (best && nla_put_flag(msg, BATADV_ATTR_FLAG_BEST))
2098 goto nla_put_failure;
2100 genlmsg_end(msg, hdr);
2104 genlmsg_cancel(msg, hdr);
2109 * batadv_iv_ogm_orig_dump_entry - Dump an originator entry into a message
2110 * @msg: Netlink message to dump into
2111 * @portid: Port making netlink request
2112 * @seq: Sequence number of netlink message
2113 * @bat_priv: The bat priv with all the soft interface information
2114 * @if_outgoing: Limit dump to entries with this outgoing interface
2115 * @orig_node: Originator to dump
2116 * @sub_s: Number of sub entries to skip
2118 * This function assumes the caller holds rcu_read_lock().
2120 * Return: Error code, or 0 on success
2123 batadv_iv_ogm_orig_dump_entry(struct sk_buff *msg, u32 portid, u32 seq,
2124 struct batadv_priv *bat_priv,
2125 struct batadv_hard_iface *if_outgoing,
2126 struct batadv_orig_node *orig_node, int *sub_s)
2128 struct batadv_neigh_node *neigh_node_best;
2129 struct batadv_neigh_node *neigh_node;
2134 neigh_node_best = batadv_orig_router_get(orig_node, if_outgoing);
2135 if (!neigh_node_best)
2138 if (!batadv_iv_ogm_neigh_get_tq_avg(neigh_node_best, if_outgoing,
2142 if (tq_avg_best == 0)
2145 hlist_for_each_entry_rcu(neigh_node, &orig_node->neigh_list, list) {
2149 best = (neigh_node == neigh_node_best);
2151 if (batadv_iv_ogm_orig_dump_subentry(msg, portid, seq,
2152 bat_priv, if_outgoing,
2153 orig_node, neigh_node,
2155 batadv_neigh_node_put(neigh_node_best);
2163 if (neigh_node_best)
2164 batadv_neigh_node_put(neigh_node_best);
2171 * batadv_iv_ogm_orig_dump_bucket - Dump an originator bucket into a
2173 * @msg: Netlink message to dump into
2174 * @portid: Port making netlink request
2175 * @seq: Sequence number of netlink message
2176 * @bat_priv: The bat priv with all the soft interface information
2177 * @if_outgoing: Limit dump to entries with this outgoing interface
2178 * @head: Bucket to be dumped
2179 * @idx_s: Number of entries to be skipped
2180 * @sub: Number of sub entries to be skipped
2182 * Return: Error code, or 0 on success
2185 batadv_iv_ogm_orig_dump_bucket(struct sk_buff *msg, u32 portid, u32 seq,
2186 struct batadv_priv *bat_priv,
2187 struct batadv_hard_iface *if_outgoing,
2188 struct hlist_head *head, int *idx_s, int *sub)
2190 struct batadv_orig_node *orig_node;
2194 hlist_for_each_entry_rcu(orig_node, head, hash_entry) {
2198 if (batadv_iv_ogm_orig_dump_entry(msg, portid, seq, bat_priv,
2199 if_outgoing, orig_node,
2214 * batadv_iv_ogm_orig_dump - Dump the originators into a message
2215 * @msg: Netlink message to dump into
2216 * @cb: Control block containing additional options
2217 * @bat_priv: The bat priv with all the soft interface information
2218 * @if_outgoing: Limit dump to entries with this outgoing interface
2221 batadv_iv_ogm_orig_dump(struct sk_buff *msg, struct netlink_callback *cb,
2222 struct batadv_priv *bat_priv,
2223 struct batadv_hard_iface *if_outgoing)
2225 struct batadv_hashtable *hash = bat_priv->orig_hash;
2226 struct hlist_head *head;
2227 int bucket = cb->args[0];
2228 int idx = cb->args[1];
2229 int sub = cb->args[2];
2230 int portid = NETLINK_CB(cb->skb).portid;
2232 while (bucket < hash->size) {
2233 head = &hash->table[bucket];
2235 if (batadv_iv_ogm_orig_dump_bucket(msg, portid,
2237 bat_priv, if_outgoing, head,
2244 cb->args[0] = bucket;
2249 #ifdef CONFIG_BATMAN_ADV_DEBUGFS
2251 * batadv_iv_hardif_neigh_print - print a single hop neighbour node
2252 * @seq: neighbour table seq_file struct
2253 * @hardif_neigh: hardif neighbour information
2256 batadv_iv_hardif_neigh_print(struct seq_file *seq,
2257 struct batadv_hardif_neigh_node *hardif_neigh)
2259 int last_secs, last_msecs;
2261 last_secs = jiffies_to_msecs(jiffies - hardif_neigh->last_seen) / 1000;
2262 last_msecs = jiffies_to_msecs(jiffies - hardif_neigh->last_seen) % 1000;
2264 seq_printf(seq, " %10s %pM %4i.%03is\n",
2265 hardif_neigh->if_incoming->net_dev->name,
2266 hardif_neigh->addr, last_secs, last_msecs);
2270 * batadv_iv_ogm_neigh_print - print the single hop neighbour list
2271 * @bat_priv: the bat priv with all the soft interface information
2272 * @seq: neighbour table seq_file struct
2274 static void batadv_iv_neigh_print(struct batadv_priv *bat_priv,
2275 struct seq_file *seq)
2277 struct net_device *net_dev = (struct net_device *)seq->private;
2278 struct batadv_hardif_neigh_node *hardif_neigh;
2279 struct batadv_hard_iface *hard_iface;
2280 int batman_count = 0;
2282 seq_puts(seq, " IF Neighbor last-seen\n");
2285 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
2286 if (hard_iface->soft_iface != net_dev)
2289 hlist_for_each_entry_rcu(hardif_neigh,
2290 &hard_iface->neigh_list, list) {
2291 batadv_iv_hardif_neigh_print(seq, hardif_neigh);
2297 if (batman_count == 0)
2298 seq_puts(seq, "No batman nodes in range ...\n");
2303 * batadv_iv_ogm_neigh_diff - calculate tq difference of two neighbors
2304 * @neigh1: the first neighbor object of the comparison
2305 * @if_outgoing1: outgoing interface for the first neighbor
2306 * @neigh2: the second neighbor object of the comparison
2307 * @if_outgoing2: outgoing interface for the second neighbor
2308 * @diff: pointer to integer receiving the calculated difference
2310 * The content of *@diff is only valid when this function returns true.
2311 * It is less, equal to or greater than 0 if the metric via neigh1 is lower,
2312 * the same as or higher than the metric via neigh2
2314 * Return: true when the difference could be calculated, false otherwise
2316 static bool batadv_iv_ogm_neigh_diff(struct batadv_neigh_node *neigh1,
2317 struct batadv_hard_iface *if_outgoing1,
2318 struct batadv_neigh_node *neigh2,
2319 struct batadv_hard_iface *if_outgoing2,
2322 struct batadv_neigh_ifinfo *neigh1_ifinfo, *neigh2_ifinfo;
2326 neigh1_ifinfo = batadv_neigh_ifinfo_get(neigh1, if_outgoing1);
2327 neigh2_ifinfo = batadv_neigh_ifinfo_get(neigh2, if_outgoing2);
2329 if (!neigh1_ifinfo || !neigh2_ifinfo) {
2334 tq1 = neigh1_ifinfo->bat_iv.tq_avg;
2335 tq2 = neigh2_ifinfo->bat_iv.tq_avg;
2336 *diff = (int)tq1 - (int)tq2;
2340 batadv_neigh_ifinfo_put(neigh1_ifinfo);
2342 batadv_neigh_ifinfo_put(neigh2_ifinfo);
2348 * batadv_iv_ogm_neigh_dump_neigh - Dump a neighbour into a netlink message
2349 * @msg: Netlink message to dump into
2350 * @portid: Port making netlink request
2351 * @seq: Sequence number of netlink message
2352 * @hardif_neigh: Neighbour to be dumped
2354 * Return: Error code, or 0 on success
2357 batadv_iv_ogm_neigh_dump_neigh(struct sk_buff *msg, u32 portid, u32 seq,
2358 struct batadv_hardif_neigh_node *hardif_neigh)
2361 unsigned int last_seen_msecs;
2363 last_seen_msecs = jiffies_to_msecs(jiffies - hardif_neigh->last_seen);
2365 hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family,
2366 NLM_F_MULTI, BATADV_CMD_GET_NEIGHBORS);
2370 if (nla_put(msg, BATADV_ATTR_NEIGH_ADDRESS, ETH_ALEN,
2371 hardif_neigh->addr) ||
2372 nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX,
2373 hardif_neigh->if_incoming->net_dev->ifindex) ||
2374 nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS,
2376 goto nla_put_failure;
2378 genlmsg_end(msg, hdr);
2382 genlmsg_cancel(msg, hdr);
2387 * batadv_iv_ogm_neigh_dump_hardif - Dump the neighbours of a hard interface
2389 * @msg: Netlink message to dump into
2390 * @portid: Port making netlink request
2391 * @seq: Sequence number of netlink message
2392 * @bat_priv: The bat priv with all the soft interface information
2393 * @hard_iface: Hard interface to dump the neighbours for
2394 * @idx_s: Number of entries to skip
2396 * This function assumes the caller holds rcu_read_lock().
2398 * Return: Error code, or 0 on success
2401 batadv_iv_ogm_neigh_dump_hardif(struct sk_buff *msg, u32 portid, u32 seq,
2402 struct batadv_priv *bat_priv,
2403 struct batadv_hard_iface *hard_iface,
2406 struct batadv_hardif_neigh_node *hardif_neigh;
2409 hlist_for_each_entry_rcu(hardif_neigh,
2410 &hard_iface->neigh_list, list) {
2414 if (batadv_iv_ogm_neigh_dump_neigh(msg, portid, seq,
2426 * batadv_iv_ogm_neigh_dump - Dump the neighbours into a message
2427 * @msg: Netlink message to dump into
2428 * @cb: Control block containing additional options
2429 * @bat_priv: The bat priv with all the soft interface information
2430 * @single_hardif: Limit dump to this hard interfaace
2433 batadv_iv_ogm_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb,
2434 struct batadv_priv *bat_priv,
2435 struct batadv_hard_iface *single_hardif)
2437 struct batadv_hard_iface *hard_iface;
2439 int i_hardif_s = cb->args[0];
2440 int idx = cb->args[1];
2441 int portid = NETLINK_CB(cb->skb).portid;
2444 if (single_hardif) {
2445 if (i_hardif_s == 0) {
2446 if (batadv_iv_ogm_neigh_dump_hardif(msg, portid,
2454 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list,
2456 if (hard_iface->soft_iface != bat_priv->soft_iface)
2459 if (i_hardif++ < i_hardif_s)
2462 if (batadv_iv_ogm_neigh_dump_hardif(msg, portid,
2465 hard_iface, &idx)) {
2473 cb->args[0] = i_hardif;
2478 * batadv_iv_ogm_neigh_cmp - compare the metrics of two neighbors
2479 * @neigh1: the first neighbor object of the comparison
2480 * @if_outgoing1: outgoing interface for the first neighbor
2481 * @neigh2: the second neighbor object of the comparison
2482 * @if_outgoing2: outgoing interface for the second neighbor
2484 * Return: a value less, equal to or greater than 0 if the metric via neigh1 is
2485 * lower, the same as or higher than the metric via neigh2
2487 static int batadv_iv_ogm_neigh_cmp(struct batadv_neigh_node *neigh1,
2488 struct batadv_hard_iface *if_outgoing1,
2489 struct batadv_neigh_node *neigh2,
2490 struct batadv_hard_iface *if_outgoing2)
2495 ret = batadv_iv_ogm_neigh_diff(neigh1, if_outgoing1, neigh2,
2496 if_outgoing2, &diff);
2504 * batadv_iv_ogm_neigh_is_sob - check if neigh1 is similarly good or better
2505 * than neigh2 from the metric prospective
2506 * @neigh1: the first neighbor object of the comparison
2507 * @if_outgoing1: outgoing interface for the first neighbor
2508 * @neigh2: the second neighbor object of the comparison
2509 * @if_outgoing2: outgoing interface for the second neighbor
2511 * Return: true if the metric via neigh1 is equally good or better than
2512 * the metric via neigh2, false otherwise.
2515 batadv_iv_ogm_neigh_is_sob(struct batadv_neigh_node *neigh1,
2516 struct batadv_hard_iface *if_outgoing1,
2517 struct batadv_neigh_node *neigh2,
2518 struct batadv_hard_iface *if_outgoing2)
2523 ret = batadv_iv_ogm_neigh_diff(neigh1, if_outgoing1, neigh2,
2524 if_outgoing2, &diff);
2528 ret = diff > -BATADV_TQ_SIMILARITY_THRESHOLD;
2532 static void batadv_iv_iface_enabled(struct batadv_hard_iface *hard_iface)
2534 /* begin scheduling originator messages on that interface */
2535 batadv_iv_ogm_schedule(hard_iface);
2539 * batadv_iv_init_sel_class - initialize GW selection class
2540 * @bat_priv: the bat priv with all the soft interface information
2542 static void batadv_iv_init_sel_class(struct batadv_priv *bat_priv)
2544 /* set default TQ difference threshold to 20 */
2545 atomic_set(&bat_priv->gw.sel_class, 20);
2548 static struct batadv_gw_node *
2549 batadv_iv_gw_get_best_gw_node(struct batadv_priv *bat_priv)
2551 struct batadv_neigh_node *router;
2552 struct batadv_neigh_ifinfo *router_ifinfo;
2553 struct batadv_gw_node *gw_node, *curr_gw = NULL;
2554 u64 max_gw_factor = 0;
2555 u64 tmp_gw_factor = 0;
2558 struct batadv_orig_node *orig_node;
2561 hlist_for_each_entry_rcu(gw_node, &bat_priv->gw.gateway_list, list) {
2562 orig_node = gw_node->orig_node;
2563 router = batadv_orig_router_get(orig_node, BATADV_IF_DEFAULT);
2567 router_ifinfo = batadv_neigh_ifinfo_get(router,
2572 if (!kref_get_unless_zero(&gw_node->refcount))
2575 tq_avg = router_ifinfo->bat_iv.tq_avg;
2577 switch (atomic_read(&bat_priv->gw.sel_class)) {
2578 case 1: /* fast connection */
2579 tmp_gw_factor = tq_avg * tq_avg;
2580 tmp_gw_factor *= gw_node->bandwidth_down;
2581 tmp_gw_factor *= 100 * 100;
2582 tmp_gw_factor >>= 18;
2584 if ((tmp_gw_factor > max_gw_factor) ||
2585 ((tmp_gw_factor == max_gw_factor) &&
2586 (tq_avg > max_tq))) {
2588 batadv_gw_node_put(curr_gw);
2590 kref_get(&curr_gw->refcount);
2594 default: /* 2: stable connection (use best statistic)
2595 * 3: fast-switch (use best statistic but change as
2596 * soon as a better gateway appears)
2597 * XX: late-switch (use best statistic but change as
2598 * soon as a better gateway appears which has
2599 * $routing_class more tq points)
2601 if (tq_avg > max_tq) {
2603 batadv_gw_node_put(curr_gw);
2605 kref_get(&curr_gw->refcount);
2610 if (tq_avg > max_tq)
2613 if (tmp_gw_factor > max_gw_factor)
2614 max_gw_factor = tmp_gw_factor;
2616 batadv_gw_node_put(gw_node);
2619 batadv_neigh_node_put(router);
2621 batadv_neigh_ifinfo_put(router_ifinfo);
2628 static bool batadv_iv_gw_is_eligible(struct batadv_priv *bat_priv,
2629 struct batadv_orig_node *curr_gw_orig,
2630 struct batadv_orig_node *orig_node)
2632 struct batadv_neigh_ifinfo *router_orig_ifinfo = NULL;
2633 struct batadv_neigh_ifinfo *router_gw_ifinfo = NULL;
2634 struct batadv_neigh_node *router_gw = NULL;
2635 struct batadv_neigh_node *router_orig = NULL;
2636 u8 gw_tq_avg, orig_tq_avg;
2639 /* dynamic re-election is performed only on fast or late switch */
2640 if (atomic_read(&bat_priv->gw.sel_class) <= 2)
2643 router_gw = batadv_orig_router_get(curr_gw_orig, BATADV_IF_DEFAULT);
2649 router_gw_ifinfo = batadv_neigh_ifinfo_get(router_gw,
2651 if (!router_gw_ifinfo) {
2656 router_orig = batadv_orig_router_get(orig_node, BATADV_IF_DEFAULT);
2660 router_orig_ifinfo = batadv_neigh_ifinfo_get(router_orig,
2662 if (!router_orig_ifinfo)
2665 gw_tq_avg = router_gw_ifinfo->bat_iv.tq_avg;
2666 orig_tq_avg = router_orig_ifinfo->bat_iv.tq_avg;
2668 /* the TQ value has to be better */
2669 if (orig_tq_avg < gw_tq_avg)
2672 /* if the routing class is greater than 3 the value tells us how much
2673 * greater the TQ value of the new gateway must be
2675 if ((atomic_read(&bat_priv->gw.sel_class) > 3) &&
2676 (orig_tq_avg - gw_tq_avg < atomic_read(&bat_priv->gw.sel_class)))
2679 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
2680 "Restarting gateway selection: better gateway found (tq curr: %i, tq new: %i)\n",
2681 gw_tq_avg, orig_tq_avg);
2685 if (router_gw_ifinfo)
2686 batadv_neigh_ifinfo_put(router_gw_ifinfo);
2687 if (router_orig_ifinfo)
2688 batadv_neigh_ifinfo_put(router_orig_ifinfo);
2690 batadv_neigh_node_put(router_gw);
2692 batadv_neigh_node_put(router_orig);
2697 #ifdef CONFIG_BATMAN_ADV_DEBUGFS
2698 /* fails if orig_node has no router */
2699 static int batadv_iv_gw_write_buffer_text(struct batadv_priv *bat_priv,
2700 struct seq_file *seq,
2701 const struct batadv_gw_node *gw_node)
2703 struct batadv_gw_node *curr_gw;
2704 struct batadv_neigh_node *router;
2705 struct batadv_neigh_ifinfo *router_ifinfo = NULL;
2708 router = batadv_orig_router_get(gw_node->orig_node, BATADV_IF_DEFAULT);
2712 router_ifinfo = batadv_neigh_ifinfo_get(router, BATADV_IF_DEFAULT);
2716 curr_gw = batadv_gw_get_selected_gw_node(bat_priv);
2718 seq_printf(seq, "%s %pM (%3i) %pM [%10s]: %u.%u/%u.%u MBit\n",
2719 (curr_gw == gw_node ? "=>" : " "),
2720 gw_node->orig_node->orig,
2721 router_ifinfo->bat_iv.tq_avg, router->addr,
2722 router->if_incoming->net_dev->name,
2723 gw_node->bandwidth_down / 10,
2724 gw_node->bandwidth_down % 10,
2725 gw_node->bandwidth_up / 10,
2726 gw_node->bandwidth_up % 10);
2727 ret = seq_has_overflowed(seq) ? -1 : 0;
2730 batadv_gw_node_put(curr_gw);
2733 batadv_neigh_ifinfo_put(router_ifinfo);
2735 batadv_neigh_node_put(router);
2739 static void batadv_iv_gw_print(struct batadv_priv *bat_priv,
2740 struct seq_file *seq)
2742 struct batadv_gw_node *gw_node;
2746 " Gateway (#/255) Nexthop [outgoingIF]: advertised uplink bandwidth\n");
2749 hlist_for_each_entry_rcu(gw_node, &bat_priv->gw.gateway_list, list) {
2750 /* fails if orig_node has no router */
2751 if (batadv_iv_gw_write_buffer_text(bat_priv, seq, gw_node) < 0)
2759 seq_puts(seq, "No gateways in range ...\n");
2764 * batadv_iv_gw_dump_entry - Dump a gateway into a message
2765 * @msg: Netlink message to dump into
2766 * @portid: Port making netlink request
2767 * @seq: Sequence number of netlink message
2768 * @bat_priv: The bat priv with all the soft interface information
2769 * @gw_node: Gateway to be dumped
2771 * Return: Error code, or 0 on success
2773 static int batadv_iv_gw_dump_entry(struct sk_buff *msg, u32 portid, u32 seq,
2774 struct batadv_priv *bat_priv,
2775 struct batadv_gw_node *gw_node)
2777 struct batadv_neigh_ifinfo *router_ifinfo = NULL;
2778 struct batadv_neigh_node *router;
2779 struct batadv_gw_node *curr_gw = NULL;
2783 router = batadv_orig_router_get(gw_node->orig_node, BATADV_IF_DEFAULT);
2787 router_ifinfo = batadv_neigh_ifinfo_get(router, BATADV_IF_DEFAULT);
2791 curr_gw = batadv_gw_get_selected_gw_node(bat_priv);
2793 hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family,
2794 NLM_F_MULTI, BATADV_CMD_GET_GATEWAYS);
2802 if (curr_gw == gw_node)
2803 if (nla_put_flag(msg, BATADV_ATTR_FLAG_BEST)) {
2804 genlmsg_cancel(msg, hdr);
2808 if (nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN,
2809 gw_node->orig_node->orig) ||
2810 nla_put_u8(msg, BATADV_ATTR_TQ, router_ifinfo->bat_iv.tq_avg) ||
2811 nla_put(msg, BATADV_ATTR_ROUTER, ETH_ALEN,
2813 nla_put_string(msg, BATADV_ATTR_HARD_IFNAME,
2814 router->if_incoming->net_dev->name) ||
2815 nla_put_u32(msg, BATADV_ATTR_BANDWIDTH_DOWN,
2816 gw_node->bandwidth_down) ||
2817 nla_put_u32(msg, BATADV_ATTR_BANDWIDTH_UP,
2818 gw_node->bandwidth_up)) {
2819 genlmsg_cancel(msg, hdr);
2823 genlmsg_end(msg, hdr);
2828 batadv_gw_node_put(curr_gw);
2830 batadv_neigh_ifinfo_put(router_ifinfo);
2832 batadv_neigh_node_put(router);
2837 * batadv_iv_gw_dump - Dump gateways into a message
2838 * @msg: Netlink message to dump into
2839 * @cb: Control block containing additional options
2840 * @bat_priv: The bat priv with all the soft interface information
2842 static void batadv_iv_gw_dump(struct sk_buff *msg, struct netlink_callback *cb,
2843 struct batadv_priv *bat_priv)
2845 int portid = NETLINK_CB(cb->skb).portid;
2846 struct batadv_gw_node *gw_node;
2847 int idx_skip = cb->args[0];
2851 hlist_for_each_entry_rcu(gw_node, &bat_priv->gw.gateway_list, list) {
2852 if (idx++ < idx_skip)
2855 if (batadv_iv_gw_dump_entry(msg, portid, cb->nlh->nlmsg_seq,
2856 bat_priv, gw_node)) {
2866 cb->args[0] = idx_skip;
2869 static struct batadv_algo_ops batadv_batman_iv __read_mostly = {
2870 .name = "BATMAN_IV",
2872 .enable = batadv_iv_ogm_iface_enable,
2873 .enabled = batadv_iv_iface_enabled,
2874 .disable = batadv_iv_ogm_iface_disable,
2875 .update_mac = batadv_iv_ogm_iface_update_mac,
2876 .primary_set = batadv_iv_ogm_primary_iface_set,
2879 .cmp = batadv_iv_ogm_neigh_cmp,
2880 .is_similar_or_better = batadv_iv_ogm_neigh_is_sob,
2881 #ifdef CONFIG_BATMAN_ADV_DEBUGFS
2882 .print = batadv_iv_neigh_print,
2884 .dump = batadv_iv_ogm_neigh_dump,
2887 #ifdef CONFIG_BATMAN_ADV_DEBUGFS
2888 .print = batadv_iv_ogm_orig_print,
2890 .dump = batadv_iv_ogm_orig_dump,
2891 .free = batadv_iv_ogm_orig_free,
2892 .add_if = batadv_iv_ogm_orig_add_if,
2893 .del_if = batadv_iv_ogm_orig_del_if,
2896 .init_sel_class = batadv_iv_init_sel_class,
2897 .get_best_gw_node = batadv_iv_gw_get_best_gw_node,
2898 .is_eligible = batadv_iv_gw_is_eligible,
2899 #ifdef CONFIG_BATMAN_ADV_DEBUGFS
2900 .print = batadv_iv_gw_print,
2902 .dump = batadv_iv_gw_dump,
2906 int __init batadv_iv_init(void)
2910 /* batman originator packet */
2911 ret = batadv_recv_handler_register(BATADV_IV_OGM,
2912 batadv_iv_ogm_receive);
2916 ret = batadv_algo_register(&batadv_batman_iv);
2918 goto handler_unregister;
2923 batadv_recv_handler_unregister(BATADV_IV_OGM);