Sven Eckelmann | 7db7d9f | 2017-11-19 15:05:11 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Sven Eckelmann | 68e039f | 2020-01-01 00:00:01 +0100 | [diff] [blame] | 2 | /* Copyright (C) 2007-2020 B.A.T.M.A.N. contributors: |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 3 | * |
| 4 | * Marek Lindner, Simon Wunderlich |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
Sven Eckelmann | a2d0816 | 2016-05-15 11:07:46 +0200 | [diff] [blame] | 7 | #include "bat_iv_ogm.h" |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 8 | #include "main.h" |
| 9 | |
| 10 | #include <linux/atomic.h> |
| 11 | #include <linux/bitmap.h> |
| 12 | #include <linux/bitops.h> |
| 13 | #include <linux/bug.h> |
| 14 | #include <linux/byteorder/generic.h> |
| 15 | #include <linux/cache.h> |
| 16 | #include <linux/errno.h> |
| 17 | #include <linux/etherdevice.h> |
Sven Eckelmann | b92b94a | 2017-11-19 17:12:02 +0100 | [diff] [blame] | 18 | #include <linux/gfp.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 19 | #include <linux/if_ether.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/jiffies.h> |
Antonio Quartulli | f0d9725 | 2016-05-03 01:45:34 +0800 | [diff] [blame] | 22 | #include <linux/kernel.h> |
Sven Eckelmann | 77ae32e | 2016-01-16 10:29:53 +0100 | [diff] [blame] | 23 | #include <linux/kref.h> |
Sven Eckelmann | fcafa5e | 2016-05-15 11:07:42 +0200 | [diff] [blame] | 24 | #include <linux/list.h> |
Sven Eckelmann | 40e220b | 2019-10-03 17:02:01 +0200 | [diff] [blame] | 25 | #include <linux/lockdep.h> |
| 26 | #include <linux/mutex.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 27 | #include <linux/netdevice.h> |
Matthias Schiffer | 024f99c | 2016-07-03 13:31:40 +0200 | [diff] [blame] | 28 | #include <linux/netlink.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 29 | #include <linux/pkt_sched.h> |
| 30 | #include <linux/printk.h> |
| 31 | #include <linux/random.h> |
| 32 | #include <linux/rculist.h> |
| 33 | #include <linux/rcupdate.h> |
| 34 | #include <linux/seq_file.h> |
| 35 | #include <linux/skbuff.h> |
| 36 | #include <linux/slab.h> |
| 37 | #include <linux/spinlock.h> |
| 38 | #include <linux/stddef.h> |
| 39 | #include <linux/string.h> |
| 40 | #include <linux/types.h> |
| 41 | #include <linux/workqueue.h> |
Matthias Schiffer | 024f99c | 2016-07-03 13:31:40 +0200 | [diff] [blame] | 42 | #include <net/genetlink.h> |
| 43 | #include <net/netlink.h> |
Sven Eckelmann | fec149f | 2017-12-21 10:17:41 +0100 | [diff] [blame] | 44 | #include <uapi/linux/batadv_packet.h> |
Matthias Schiffer | 024f99c | 2016-07-03 13:31:40 +0200 | [diff] [blame] | 45 | #include <uapi/linux/batman_adv.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 46 | |
Sven Eckelmann | a2d0816 | 2016-05-15 11:07:46 +0200 | [diff] [blame] | 47 | #include "bat_algo.h" |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 48 | #include "bitarray.h" |
Antonio Quartulli | 34d99cf | 2016-07-03 12:46:33 +0200 | [diff] [blame] | 49 | #include "gateway_client.h" |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 50 | #include "hard-interface.h" |
| 51 | #include "hash.h" |
Sven Eckelmann | ba41208 | 2016-05-15 23:48:31 +0200 | [diff] [blame] | 52 | #include "log.h" |
Matthias Schiffer | 024f99c | 2016-07-03 13:31:40 +0200 | [diff] [blame] | 53 | #include "netlink.h" |
Martin Hundebøll | d56b170 | 2013-01-25 11:12:39 +0100 | [diff] [blame] | 54 | #include "network-coding.h" |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 55 | #include "originator.h" |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 56 | #include "routing.h" |
| 57 | #include "send.h" |
| 58 | #include "translation-table.h" |
Markus Pargmann | 1f8dce4 | 2016-05-15 11:07:43 +0200 | [diff] [blame] | 59 | #include "tvlv.h" |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 60 | |
Antonio Quartulli | f0d9725 | 2016-05-03 01:45:34 +0800 | [diff] [blame] | 61 | static void batadv_iv_send_outstanding_bat_ogm_packet(struct work_struct *work); |
| 62 | |
Antonio Quartulli | 791c2a2 | 2013-08-17 12:44:44 +0200 | [diff] [blame] | 63 | /** |
Martin Hundebøll | 95298a9 | 2014-07-15 09:41:05 +0200 | [diff] [blame] | 64 | * enum batadv_dup_status - duplicate status |
Antonio Quartulli | 791c2a2 | 2013-08-17 12:44:44 +0200 | [diff] [blame] | 65 | */ |
| 66 | enum batadv_dup_status { |
Sven Eckelmann | 8b84cc4 | 2017-12-02 19:51:48 +0100 | [diff] [blame] | 67 | /** @BATADV_NO_DUP: the packet is no duplicate */ |
Antonio Quartulli | 791c2a2 | 2013-08-17 12:44:44 +0200 | [diff] [blame] | 68 | BATADV_NO_DUP = 0, |
Sven Eckelmann | 8b84cc4 | 2017-12-02 19:51:48 +0100 | [diff] [blame] | 69 | |
| 70 | /** |
| 71 | * @BATADV_ORIG_DUP: OGM is a duplicate in the originator (but not for |
| 72 | * the neighbor) |
| 73 | */ |
Antonio Quartulli | 791c2a2 | 2013-08-17 12:44:44 +0200 | [diff] [blame] | 74 | BATADV_ORIG_DUP, |
Sven Eckelmann | 8b84cc4 | 2017-12-02 19:51:48 +0100 | [diff] [blame] | 75 | |
| 76 | /** @BATADV_NEIGH_DUP: OGM is a duplicate for the neighbor */ |
Antonio Quartulli | 791c2a2 | 2013-08-17 12:44:44 +0200 | [diff] [blame] | 77 | BATADV_NEIGH_DUP, |
Sven Eckelmann | 8b84cc4 | 2017-12-02 19:51:48 +0100 | [diff] [blame] | 78 | |
| 79 | /** |
| 80 | * @BATADV_PROTECTED: originator is currently protected (after reboot) |
| 81 | */ |
Antonio Quartulli | 791c2a2 | 2013-08-17 12:44:44 +0200 | [diff] [blame] | 82 | BATADV_PROTECTED, |
| 83 | }; |
| 84 | |
Antonio Quartulli | 24a5dee | 2013-04-08 09:38:12 +0200 | [diff] [blame] | 85 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 86 | * batadv_ring_buffer_set() - update the ring buffer with the given value |
Antonio Quartulli | 24a5dee | 2013-04-08 09:38:12 +0200 | [diff] [blame] | 87 | * @lq_recv: pointer to the ring buffer |
| 88 | * @lq_index: index to store the value at |
| 89 | * @value: value to store in the ring buffer |
| 90 | */ |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 91 | static void batadv_ring_buffer_set(u8 lq_recv[], u8 *lq_index, u8 value) |
Antonio Quartulli | 24a5dee | 2013-04-08 09:38:12 +0200 | [diff] [blame] | 92 | { |
| 93 | lq_recv[*lq_index] = value; |
| 94 | *lq_index = (*lq_index + 1) % BATADV_TQ_GLOBAL_WINDOW_SIZE; |
| 95 | } |
| 96 | |
| 97 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 98 | * batadv_ring_buffer_avg() - compute the average of all non-zero values stored |
Antonio Quartulli | 24a5dee | 2013-04-08 09:38:12 +0200 | [diff] [blame] | 99 | * in the given ring buffer |
| 100 | * @lq_recv: pointer to the ring buffer |
| 101 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 102 | * Return: computed average value. |
Antonio Quartulli | 24a5dee | 2013-04-08 09:38:12 +0200 | [diff] [blame] | 103 | */ |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 104 | static u8 batadv_ring_buffer_avg(const u8 lq_recv[]) |
Antonio Quartulli | 24a5dee | 2013-04-08 09:38:12 +0200 | [diff] [blame] | 105 | { |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 106 | const u8 *ptr; |
| 107 | u16 count = 0; |
| 108 | u16 i = 0; |
| 109 | u16 sum = 0; |
Antonio Quartulli | 24a5dee | 2013-04-08 09:38:12 +0200 | [diff] [blame] | 110 | |
| 111 | ptr = lq_recv; |
| 112 | |
| 113 | while (i < BATADV_TQ_GLOBAL_WINDOW_SIZE) { |
| 114 | if (*ptr != 0) { |
| 115 | count++; |
| 116 | sum += *ptr; |
| 117 | } |
| 118 | |
| 119 | i++; |
| 120 | ptr++; |
| 121 | } |
| 122 | |
| 123 | if (count == 0) |
| 124 | return 0; |
| 125 | |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 126 | return (u8)(sum / count); |
Antonio Quartulli | 24a5dee | 2013-04-08 09:38:12 +0200 | [diff] [blame] | 127 | } |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 128 | |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 129 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 130 | * batadv_iv_ogm_orig_get() - retrieve or create (if does not exist) an |
| 131 | * originator |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 132 | * @bat_priv: the bat priv with all the soft interface information |
| 133 | * @addr: mac address of the originator |
| 134 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 135 | * Return: the originator object corresponding to the passed mac address or NULL |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 136 | * on failure. |
| 137 | * If the object does not exists it is created an initialised. |
| 138 | */ |
| 139 | static struct batadv_orig_node * |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 140 | batadv_iv_ogm_orig_get(struct batadv_priv *bat_priv, const u8 *addr) |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 141 | { |
| 142 | struct batadv_orig_node *orig_node; |
Sven Eckelmann | f22e089 | 2017-12-26 15:14:01 +0100 | [diff] [blame] | 143 | int hash_added; |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 144 | |
| 145 | orig_node = batadv_orig_hash_find(bat_priv, addr); |
| 146 | if (orig_node) |
| 147 | return orig_node; |
| 148 | |
| 149 | orig_node = batadv_orig_node_new(bat_priv, addr); |
| 150 | if (!orig_node) |
| 151 | return NULL; |
| 152 | |
| 153 | spin_lock_init(&orig_node->bat_iv.ogm_cnt_lock); |
| 154 | |
Sven Eckelmann | 55db2d5 | 2016-07-15 17:39:21 +0200 | [diff] [blame] | 155 | kref_get(&orig_node->refcount); |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 156 | hash_added = batadv_hash_add(bat_priv->orig_hash, batadv_compare_orig, |
| 157 | batadv_choose_orig, orig_node, |
| 158 | &orig_node->hash_entry); |
| 159 | if (hash_added != 0) |
Sven Eckelmann | 55db2d5 | 2016-07-15 17:39:21 +0200 | [diff] [blame] | 160 | goto free_orig_node_hash; |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 161 | |
| 162 | return orig_node; |
| 163 | |
Sven Eckelmann | 55db2d5 | 2016-07-15 17:39:21 +0200 | [diff] [blame] | 164 | free_orig_node_hash: |
Sven Eckelmann | dee222c7 | 2018-08-16 16:54:45 +0200 | [diff] [blame] | 165 | /* reference for batadv_hash_add */ |
Sven Eckelmann | 5d96731 | 2016-01-17 11:01:09 +0100 | [diff] [blame] | 166 | batadv_orig_node_put(orig_node); |
Sven Eckelmann | dee222c7 | 2018-08-16 16:54:45 +0200 | [diff] [blame] | 167 | /* reference from batadv_orig_node_new */ |
Sven Eckelmann | 5d96731 | 2016-01-17 11:01:09 +0100 | [diff] [blame] | 168 | batadv_orig_node_put(orig_node); |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 169 | |
| 170 | return NULL; |
| 171 | } |
| 172 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 173 | static struct batadv_neigh_node * |
| 174 | batadv_iv_ogm_neigh_new(struct batadv_hard_iface *hard_iface, |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 175 | const u8 *neigh_addr, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 176 | struct batadv_orig_node *orig_node, |
Antonio Quartulli | 863dd7a | 2013-03-25 13:49:46 +0100 | [diff] [blame] | 177 | struct batadv_orig_node *orig_neigh) |
Marek Lindner | 7ae8b28 | 2012-03-01 15:35:21 +0800 | [diff] [blame] | 178 | { |
Marek Lindner | 741aa06 | 2015-07-26 04:57:43 +0800 | [diff] [blame] | 179 | struct batadv_neigh_node *neigh_node; |
Marek Lindner | 7ae8b28 | 2012-03-01 15:35:21 +0800 | [diff] [blame] | 180 | |
Marek Lindner | 6f0a6b5 | 2016-05-03 01:52:08 +0800 | [diff] [blame] | 181 | neigh_node = batadv_neigh_node_get_or_create(orig_node, |
| 182 | hard_iface, neigh_addr); |
Marek Lindner | 7ae8b28 | 2012-03-01 15:35:21 +0800 | [diff] [blame] | 183 | if (!neigh_node) |
| 184 | goto out; |
| 185 | |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 186 | neigh_node->orig_node = orig_neigh; |
Marek Lindner | 7ae8b28 | 2012-03-01 15:35:21 +0800 | [diff] [blame] | 187 | |
Marek Lindner | 7ae8b28 | 2012-03-01 15:35:21 +0800 | [diff] [blame] | 188 | out: |
| 189 | return neigh_node; |
| 190 | } |
| 191 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 192 | static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface) |
Marek Lindner | d0b9fd8 | 2011-07-30 12:33:33 +0200 | [diff] [blame] | 193 | { |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 194 | struct batadv_ogm_packet *batadv_ogm_packet; |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 195 | unsigned char *ogm_buff; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 196 | u32 random_seqno; |
Marek Lindner | d7d32ec | 2012-02-07 17:20:46 +0800 | [diff] [blame] | 197 | |
Sven Eckelmann | 40e220b | 2019-10-03 17:02:01 +0200 | [diff] [blame] | 198 | mutex_lock(&hard_iface->bat_iv.ogm_buff_mutex); |
| 199 | |
Marek Lindner | d7d32ec | 2012-02-07 17:20:46 +0800 | [diff] [blame] | 200 | /* randomize initial seqno to avoid collision */ |
| 201 | get_random_bytes(&random_seqno, sizeof(random_seqno)); |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 202 | atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno); |
Marek Lindner | d0b9fd8 | 2011-07-30 12:33:33 +0200 | [diff] [blame] | 203 | |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 204 | hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN; |
| 205 | ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC); |
Sven Eckelmann | 40e220b | 2019-10-03 17:02:01 +0200 | [diff] [blame] | 206 | if (!ogm_buff) { |
| 207 | mutex_unlock(&hard_iface->bat_iv.ogm_buff_mutex); |
Markus Pargmann | 42d9f2c | 2014-12-26 12:41:26 +0100 | [diff] [blame] | 208 | return -ENOMEM; |
Sven Eckelmann | 40e220b | 2019-10-03 17:02:01 +0200 | [diff] [blame] | 209 | } |
Marek Lindner | 77af757 | 2012-02-07 17:20:48 +0800 | [diff] [blame] | 210 | |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 211 | hard_iface->bat_iv.ogm_buff = ogm_buff; |
| 212 | |
| 213 | batadv_ogm_packet = (struct batadv_ogm_packet *)ogm_buff; |
Simon Wunderlich | a40d9b0 | 2013-12-02 20:38:31 +0100 | [diff] [blame] | 214 | batadv_ogm_packet->packet_type = BATADV_IV_OGM; |
| 215 | batadv_ogm_packet->version = BATADV_COMPAT_VERSION; |
| 216 | batadv_ogm_packet->ttl = 2; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 217 | batadv_ogm_packet->flags = BATADV_NO_FLAGS; |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 218 | batadv_ogm_packet->reserved = 0; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 219 | batadv_ogm_packet->tq = BATADV_TQ_MAX_VALUE; |
Marek Lindner | 77af757 | 2012-02-07 17:20:48 +0800 | [diff] [blame] | 220 | |
Sven Eckelmann | 40e220b | 2019-10-03 17:02:01 +0200 | [diff] [blame] | 221 | mutex_unlock(&hard_iface->bat_iv.ogm_buff_mutex); |
| 222 | |
Markus Pargmann | 42d9f2c | 2014-12-26 12:41:26 +0100 | [diff] [blame] | 223 | return 0; |
Marek Lindner | d0b9fd8 | 2011-07-30 12:33:33 +0200 | [diff] [blame] | 224 | } |
| 225 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 226 | static void batadv_iv_ogm_iface_disable(struct batadv_hard_iface *hard_iface) |
Marek Lindner | 00a5007 | 2012-02-07 17:20:47 +0800 | [diff] [blame] | 227 | { |
Sven Eckelmann | 40e220b | 2019-10-03 17:02:01 +0200 | [diff] [blame] | 228 | mutex_lock(&hard_iface->bat_iv.ogm_buff_mutex); |
| 229 | |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 230 | kfree(hard_iface->bat_iv.ogm_buff); |
| 231 | hard_iface->bat_iv.ogm_buff = NULL; |
Sven Eckelmann | 40e220b | 2019-10-03 17:02:01 +0200 | [diff] [blame] | 232 | |
| 233 | mutex_unlock(&hard_iface->bat_iv.ogm_buff_mutex); |
Marek Lindner | 00a5007 | 2012-02-07 17:20:47 +0800 | [diff] [blame] | 234 | } |
| 235 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 236 | static void batadv_iv_ogm_iface_update_mac(struct batadv_hard_iface *hard_iface) |
Marek Lindner | d0b9fd8 | 2011-07-30 12:33:33 +0200 | [diff] [blame] | 237 | { |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 238 | struct batadv_ogm_packet *batadv_ogm_packet; |
Sven Eckelmann | 40e220b | 2019-10-03 17:02:01 +0200 | [diff] [blame] | 239 | void *ogm_buff; |
Marek Lindner | d0b9fd8 | 2011-07-30 12:33:33 +0200 | [diff] [blame] | 240 | |
Sven Eckelmann | 40e220b | 2019-10-03 17:02:01 +0200 | [diff] [blame] | 241 | mutex_lock(&hard_iface->bat_iv.ogm_buff_mutex); |
| 242 | |
| 243 | ogm_buff = hard_iface->bat_iv.ogm_buff; |
| 244 | if (!ogm_buff) |
| 245 | goto unlock; |
| 246 | |
| 247 | batadv_ogm_packet = ogm_buff; |
Antonio Quartulli | 8fdd015 | 2014-01-22 00:42:11 +0100 | [diff] [blame] | 248 | ether_addr_copy(batadv_ogm_packet->orig, |
| 249 | hard_iface->net_dev->dev_addr); |
| 250 | ether_addr_copy(batadv_ogm_packet->prev_sender, |
| 251 | hard_iface->net_dev->dev_addr); |
Sven Eckelmann | 40e220b | 2019-10-03 17:02:01 +0200 | [diff] [blame] | 252 | |
| 253 | unlock: |
| 254 | mutex_unlock(&hard_iface->bat_iv.ogm_buff_mutex); |
Marek Lindner | d0b9fd8 | 2011-07-30 12:33:33 +0200 | [diff] [blame] | 255 | } |
| 256 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 257 | static void |
| 258 | batadv_iv_ogm_primary_iface_set(struct batadv_hard_iface *hard_iface) |
Marek Lindner | c322939 | 2012-03-11 06:17:50 +0800 | [diff] [blame] | 259 | { |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 260 | struct batadv_ogm_packet *batadv_ogm_packet; |
Sven Eckelmann | 40e220b | 2019-10-03 17:02:01 +0200 | [diff] [blame] | 261 | void *ogm_buff; |
Marek Lindner | c322939 | 2012-03-11 06:17:50 +0800 | [diff] [blame] | 262 | |
Sven Eckelmann | 40e220b | 2019-10-03 17:02:01 +0200 | [diff] [blame] | 263 | mutex_lock(&hard_iface->bat_iv.ogm_buff_mutex); |
| 264 | |
| 265 | ogm_buff = hard_iface->bat_iv.ogm_buff; |
| 266 | if (!ogm_buff) |
| 267 | goto unlock; |
| 268 | |
| 269 | batadv_ogm_packet = ogm_buff; |
Simon Wunderlich | a40d9b0 | 2013-12-02 20:38:31 +0100 | [diff] [blame] | 270 | batadv_ogm_packet->ttl = BATADV_TTL; |
Sven Eckelmann | 40e220b | 2019-10-03 17:02:01 +0200 | [diff] [blame] | 271 | |
| 272 | unlock: |
| 273 | mutex_unlock(&hard_iface->bat_iv.ogm_buff_mutex); |
Marek Lindner | c322939 | 2012-03-11 06:17:50 +0800 | [diff] [blame] | 274 | } |
| 275 | |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 276 | /* when do we schedule our own ogm to be sent */ |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 277 | static unsigned long |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 278 | batadv_iv_ogm_emit_send_time(const struct batadv_priv *bat_priv) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 279 | { |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 280 | unsigned int msecs; |
| 281 | |
| 282 | msecs = atomic_read(&bat_priv->orig_interval) - BATADV_JITTER; |
Akinobu Mita | e76e432 | 2012-12-24 11:14:07 +0900 | [diff] [blame] | 283 | msecs += prandom_u32() % (2 * BATADV_JITTER); |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 284 | |
| 285 | return jiffies + msecs_to_jiffies(msecs); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | /* when do we schedule a ogm packet to be sent */ |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 289 | static unsigned long batadv_iv_ogm_fwd_send_time(void) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 290 | { |
Akinobu Mita | e76e432 | 2012-12-24 11:14:07 +0900 | [diff] [blame] | 291 | return jiffies + msecs_to_jiffies(prandom_u32() % (BATADV_JITTER / 2)); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | /* apply hop penalty for a normal link */ |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 295 | static u8 batadv_hop_penalty(u8 tq, const struct batadv_priv *bat_priv) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 296 | { |
| 297 | int hop_penalty = atomic_read(&bat_priv->hop_penalty); |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 298 | int new_tq; |
| 299 | |
| 300 | new_tq = tq * (BATADV_TQ_MAX_VALUE - hop_penalty); |
| 301 | new_tq /= BATADV_TQ_MAX_VALUE; |
| 302 | |
| 303 | return new_tq; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 304 | } |
| 305 | |
Simon Wunderlich | 600184b | 2015-11-23 19:57:21 +0100 | [diff] [blame] | 306 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 307 | * batadv_iv_ogm_aggr_packet() - checks if there is another OGM attached |
Simon Wunderlich | 600184b | 2015-11-23 19:57:21 +0100 | [diff] [blame] | 308 | * @buff_pos: current position in the skb |
| 309 | * @packet_len: total length of the skb |
Sven Eckelmann | a15d56a | 2019-08-22 08:55:36 +0200 | [diff] [blame] | 310 | * @ogm_packet: potential OGM in buffer |
Simon Wunderlich | 600184b | 2015-11-23 19:57:21 +0100 | [diff] [blame] | 311 | * |
| 312 | * Return: true if there is enough space for another OGM, false otherwise. |
| 313 | */ |
Sven Eckelmann | a15d56a | 2019-08-22 08:55:36 +0200 | [diff] [blame] | 314 | static bool |
| 315 | batadv_iv_ogm_aggr_packet(int buff_pos, int packet_len, |
| 316 | const struct batadv_ogm_packet *ogm_packet) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 317 | { |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 318 | int next_buff_pos = 0; |
| 319 | |
Sven Eckelmann | a15d56a | 2019-08-22 08:55:36 +0200 | [diff] [blame] | 320 | /* check if there is enough space for the header */ |
| 321 | next_buff_pos += buff_pos + sizeof(*ogm_packet); |
| 322 | if (next_buff_pos > packet_len) |
| 323 | return false; |
| 324 | |
| 325 | /* check if there is enough space for the optional TVLV */ |
| 326 | next_buff_pos += ntohs(ogm_packet->tvlv_len); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 327 | |
| 328 | return (next_buff_pos <= packet_len) && |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 329 | (next_buff_pos <= BATADV_MAX_AGGREGATION_BYTES); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 330 | } |
| 331 | |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 332 | /* send a batman ogm to a given interface */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 333 | static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet, |
| 334 | struct batadv_hard_iface *hard_iface) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 335 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 336 | struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); |
Markus Pargmann | de12bae | 2014-12-26 12:41:28 +0100 | [diff] [blame] | 337 | const char *fwd_str; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 338 | u8 packet_num; |
| 339 | s16 buff_pos; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 340 | struct batadv_ogm_packet *batadv_ogm_packet; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 341 | struct sk_buff *skb; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 342 | u8 *packet_pos; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 343 | |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 344 | if (hard_iface->if_status != BATADV_IF_ACTIVE) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 345 | return; |
| 346 | |
| 347 | packet_num = 0; |
| 348 | buff_pos = 0; |
Sven Eckelmann | c67893d | 2012-07-08 18:33:51 +0200 | [diff] [blame] | 349 | packet_pos = forw_packet->skb->data; |
| 350 | batadv_ogm_packet = (struct batadv_ogm_packet *)packet_pos; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 351 | |
| 352 | /* adjust all flags and log packets */ |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 353 | while (batadv_iv_ogm_aggr_packet(buff_pos, forw_packet->packet_len, |
Sven Eckelmann | a15d56a | 2019-08-22 08:55:36 +0200 | [diff] [blame] | 354 | batadv_ogm_packet)) { |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 355 | /* we might have aggregated direct link packets with an |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 356 | * ordinary base packet |
| 357 | */ |
Sven Eckelmann | 8de47de | 2012-07-08 16:32:09 +0200 | [diff] [blame] | 358 | if (forw_packet->direct_link_flags & BIT(packet_num) && |
| 359 | forw_packet->if_incoming == hard_iface) |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 360 | batadv_ogm_packet->flags |= BATADV_DIRECTLINK; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 361 | else |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 362 | batadv_ogm_packet->flags &= ~BATADV_DIRECTLINK; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 363 | |
Sven Eckelmann | c67893d | 2012-07-08 18:33:51 +0200 | [diff] [blame] | 364 | if (packet_num > 0 || !forw_packet->own) |
| 365 | fwd_str = "Forwarding"; |
| 366 | else |
| 367 | fwd_str = "Sending own"; |
| 368 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 369 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 370 | "%s %spacket (originator %pM, seqno %u, TQ %d, TTL %d, IDF %s) on interface %s [%pM]\n", |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 371 | fwd_str, (packet_num > 0 ? "aggregated " : ""), |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 372 | batadv_ogm_packet->orig, |
| 373 | ntohl(batadv_ogm_packet->seqno), |
Simon Wunderlich | a40d9b0 | 2013-12-02 20:38:31 +0100 | [diff] [blame] | 374 | batadv_ogm_packet->tq, batadv_ogm_packet->ttl, |
Sven Eckelmann | a2f2b6c | 2015-04-23 18:22:24 +0200 | [diff] [blame] | 375 | ((batadv_ogm_packet->flags & BATADV_DIRECTLINK) ? |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 376 | "on" : "off"), |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 377 | hard_iface->net_dev->name, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 378 | hard_iface->net_dev->dev_addr); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 379 | |
Sven Eckelmann | 7e071c7 | 2012-06-03 22:19:13 +0200 | [diff] [blame] | 380 | buff_pos += BATADV_OGM_HLEN; |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 381 | buff_pos += ntohs(batadv_ogm_packet->tvlv_len); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 382 | packet_num++; |
Sven Eckelmann | c67893d | 2012-07-08 18:33:51 +0200 | [diff] [blame] | 383 | packet_pos = forw_packet->skb->data + buff_pos; |
| 384 | batadv_ogm_packet = (struct batadv_ogm_packet *)packet_pos; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | /* create clone because function is called more than once */ |
| 388 | skb = skb_clone(forw_packet->skb, GFP_ATOMIC); |
Martin Hundebøll | f821486 | 2012-04-20 17:02:45 +0200 | [diff] [blame] | 389 | if (skb) { |
Sven Eckelmann | d69909d | 2012-06-03 22:19:20 +0200 | [diff] [blame] | 390 | batadv_inc_counter(bat_priv, BATADV_CNT_MGMT_TX); |
| 391 | batadv_add_counter(bat_priv, BATADV_CNT_MGMT_TX_BYTES, |
Martin Hundebøll | f821486 | 2012-04-20 17:02:45 +0200 | [diff] [blame] | 392 | skb->len + ETH_HLEN); |
Antonio Quartulli | 95d3927 | 2016-01-16 16:40:15 +0800 | [diff] [blame] | 393 | batadv_send_broadcast_skb(skb, hard_iface); |
Martin Hundebøll | f821486 | 2012-04-20 17:02:45 +0200 | [diff] [blame] | 394 | } |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | /* send a batman ogm packet */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 398 | static void batadv_iv_ogm_emit(struct batadv_forw_packet *forw_packet) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 399 | { |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 400 | struct net_device *soft_iface; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 401 | |
| 402 | if (!forw_packet->if_incoming) { |
Sven Eckelmann | 86ceb36 | 2012-03-07 09:07:45 +0100 | [diff] [blame] | 403 | pr_err("Error - can't forward packet: incoming iface not specified\n"); |
Linus LĂĽssing | f55a2e8 | 2016-06-14 22:56:50 +0200 | [diff] [blame] | 404 | return; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | soft_iface = forw_packet->if_incoming->soft_iface; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 408 | |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 409 | if (WARN_ON(!forw_packet->if_outgoing)) |
Linus LĂĽssing | f55a2e8 | 2016-06-14 22:56:50 +0200 | [diff] [blame] | 410 | return; |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 411 | |
| 412 | if (WARN_ON(forw_packet->if_outgoing->soft_iface != soft_iface)) |
Linus LĂĽssing | f55a2e8 | 2016-06-14 22:56:50 +0200 | [diff] [blame] | 413 | return; |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 414 | |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 415 | if (forw_packet->if_incoming->if_status != BATADV_IF_ACTIVE) |
Linus LĂĽssing | f55a2e8 | 2016-06-14 22:56:50 +0200 | [diff] [blame] | 416 | return; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 417 | |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 418 | /* only for one specific outgoing interface */ |
| 419 | batadv_iv_ogm_send_to_if(forw_packet, forw_packet->if_outgoing); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 420 | } |
| 421 | |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 422 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 423 | * batadv_iv_ogm_can_aggregate() - find out if an OGM can be aggregated on an |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 424 | * existing forward packet |
| 425 | * @new_bat_ogm_packet: OGM packet to be aggregated |
| 426 | * @bat_priv: the bat priv with all the soft interface information |
| 427 | * @packet_len: (total) length of the OGM |
| 428 | * @send_time: timestamp (jiffies) when the packet is to be sent |
Martin Hundebøll | 95298a9 | 2014-07-15 09:41:05 +0200 | [diff] [blame] | 429 | * @directlink: true if this is a direct link packet |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 430 | * @if_incoming: interface where the packet was received |
| 431 | * @if_outgoing: interface for which the retransmission should be considered |
| 432 | * @forw_packet: the forwarded packet which should be checked |
| 433 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 434 | * Return: true if new_packet can be aggregated with forw_packet |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 435 | */ |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 436 | static bool |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 437 | batadv_iv_ogm_can_aggregate(const struct batadv_ogm_packet *new_bat_ogm_packet, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 438 | struct batadv_priv *bat_priv, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 439 | int packet_len, unsigned long send_time, |
| 440 | bool directlink, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 441 | const struct batadv_hard_iface *if_incoming, |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 442 | const struct batadv_hard_iface *if_outgoing, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 443 | const struct batadv_forw_packet *forw_packet) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 444 | { |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 445 | struct batadv_ogm_packet *batadv_ogm_packet; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 446 | int aggregated_bytes = forw_packet->packet_len + packet_len; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 447 | struct batadv_hard_iface *primary_if = NULL; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 448 | bool res = false; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 449 | unsigned long aggregation_end_time; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 450 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 451 | batadv_ogm_packet = (struct batadv_ogm_packet *)forw_packet->skb->data; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 452 | aggregation_end_time = send_time; |
| 453 | aggregation_end_time += msecs_to_jiffies(BATADV_MAX_AGGREGATION_MS); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 454 | |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 455 | /* we can aggregate the current packet to this aggregated packet |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 456 | * if: |
| 457 | * |
| 458 | * - the send time is within our MAX_AGGREGATION_MS time |
| 459 | * - the resulting packet wont be bigger than |
| 460 | * MAX_AGGREGATION_BYTES |
Markus Pargmann | 8f34b38 | 2014-12-26 12:41:29 +0100 | [diff] [blame] | 461 | * otherwise aggregation is not possible |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 462 | */ |
Markus Pargmann | 8f34b38 | 2014-12-26 12:41:29 +0100 | [diff] [blame] | 463 | if (!time_before(send_time, forw_packet->send_time) || |
| 464 | !time_after_eq(aggregation_end_time, forw_packet->send_time)) |
| 465 | return false; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 466 | |
Markus Pargmann | 8f34b38 | 2014-12-26 12:41:29 +0100 | [diff] [blame] | 467 | if (aggregated_bytes > BATADV_MAX_AGGREGATION_BYTES) |
| 468 | return false; |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 469 | |
Markus Pargmann | 8f34b38 | 2014-12-26 12:41:29 +0100 | [diff] [blame] | 470 | /* packet is not leaving on the same interface. */ |
| 471 | if (forw_packet->if_outgoing != if_outgoing) |
| 472 | return false; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 473 | |
Markus Pargmann | 8f34b38 | 2014-12-26 12:41:29 +0100 | [diff] [blame] | 474 | /* check aggregation compatibility |
| 475 | * -> direct link packets are broadcasted on |
| 476 | * their interface only |
| 477 | * -> aggregate packet if the current packet is |
| 478 | * a "global" packet as well as the base |
| 479 | * packet |
| 480 | */ |
| 481 | primary_if = batadv_primary_if_get_selected(bat_priv); |
| 482 | if (!primary_if) |
| 483 | return false; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 484 | |
Markus Pargmann | 8f34b38 | 2014-12-26 12:41:29 +0100 | [diff] [blame] | 485 | /* packets without direct link flag and high TTL |
| 486 | * are flooded through the net |
| 487 | */ |
| 488 | if (!directlink && |
| 489 | !(batadv_ogm_packet->flags & BATADV_DIRECTLINK) && |
| 490 | batadv_ogm_packet->ttl != 1 && |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 491 | |
Markus Pargmann | 8f34b38 | 2014-12-26 12:41:29 +0100 | [diff] [blame] | 492 | /* own packets originating non-primary |
| 493 | * interfaces leave only that interface |
| 494 | */ |
| 495 | (!forw_packet->own || |
| 496 | forw_packet->if_incoming == primary_if)) { |
| 497 | res = true; |
| 498 | goto out; |
| 499 | } |
| 500 | |
| 501 | /* if the incoming packet is sent via this one |
| 502 | * interface only - we still can aggregate |
| 503 | */ |
| 504 | if (directlink && |
| 505 | new_bat_ogm_packet->ttl == 1 && |
| 506 | forw_packet->if_incoming == if_incoming && |
| 507 | |
| 508 | /* packets from direct neighbors or |
| 509 | * own secondary interface packets |
| 510 | * (= secondary interface packets in general) |
| 511 | */ |
| 512 | (batadv_ogm_packet->flags & BATADV_DIRECTLINK || |
| 513 | (forw_packet->own && |
| 514 | forw_packet->if_incoming != primary_if))) { |
| 515 | res = true; |
| 516 | goto out; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | out: |
| 520 | if (primary_if) |
Sven Eckelmann | 82047ad | 2016-01-17 11:01:10 +0100 | [diff] [blame] | 521 | batadv_hardif_put(primary_if); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 522 | return res; |
| 523 | } |
| 524 | |
Simon Wunderlich | 1b371d1 | 2014-01-15 21:17:54 +0100 | [diff] [blame] | 525 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 526 | * batadv_iv_ogm_aggregate_new() - create a new aggregated packet and add this |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 527 | * packet to it. |
| 528 | * @packet_buff: pointer to the OGM |
| 529 | * @packet_len: (total) length of the OGM |
| 530 | * @send_time: timestamp (jiffies) when the packet is to be sent |
| 531 | * @direct_link: whether this OGM has direct link status |
| 532 | * @if_incoming: interface where the packet was received |
| 533 | * @if_outgoing: interface for which the retransmission should be considered |
| 534 | * @own_packet: true if it is a self-generated ogm |
| 535 | */ |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 536 | static void batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff, |
| 537 | int packet_len, unsigned long send_time, |
| 538 | bool direct_link, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 539 | struct batadv_hard_iface *if_incoming, |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 540 | struct batadv_hard_iface *if_outgoing, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 541 | int own_packet) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 542 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 543 | struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface); |
| 544 | struct batadv_forw_packet *forw_packet_aggr; |
Linus LĂĽssing | 99ba18e | 2017-02-17 11:17:06 +0100 | [diff] [blame] | 545 | struct sk_buff *skb; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 546 | unsigned char *skb_buff; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 547 | unsigned int skb_size; |
Linus LĂĽssing | a65e548 | 2016-06-20 21:39:54 +0200 | [diff] [blame] | 548 | atomic_t *queue_left = own_packet ? NULL : &bat_priv->batman_queue_left; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 549 | |
Markus Pargmann | 940d156 | 2014-12-26 12:41:31 +0100 | [diff] [blame] | 550 | if (atomic_read(&bat_priv->aggregated_ogms) && |
| 551 | packet_len < BATADV_MAX_AGGREGATION_BYTES) |
Sven Eckelmann | 5b24657 | 2012-11-04 17:11:45 +0100 | [diff] [blame] | 552 | skb_size = BATADV_MAX_AGGREGATION_BYTES; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 553 | else |
Sven Eckelmann | 5b24657 | 2012-11-04 17:11:45 +0100 | [diff] [blame] | 554 | skb_size = packet_len; |
| 555 | |
Antonio Quartulli | 41ab6c4 | 2013-04-02 22:28:44 +0200 | [diff] [blame] | 556 | skb_size += ETH_HLEN; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 557 | |
Linus LĂĽssing | 99ba18e | 2017-02-17 11:17:06 +0100 | [diff] [blame] | 558 | skb = netdev_alloc_skb_ip_align(NULL, skb_size); |
| 559 | if (!skb) |
| 560 | return; |
| 561 | |
| 562 | forw_packet_aggr = batadv_forw_packet_alloc(if_incoming, if_outgoing, |
| 563 | queue_left, bat_priv, skb); |
| 564 | if (!forw_packet_aggr) { |
| 565 | kfree_skb(skb); |
Linus LĂĽssing | a65e548 | 2016-06-20 21:39:54 +0200 | [diff] [blame] | 566 | return; |
| 567 | } |
| 568 | |
Simon Wunderlich | c54f38c | 2013-07-29 17:56:44 +0200 | [diff] [blame] | 569 | forw_packet_aggr->skb->priority = TC_PRIO_CONTROL; |
Antonio Quartulli | 41ab6c4 | 2013-04-02 22:28:44 +0200 | [diff] [blame] | 570 | skb_reserve(forw_packet_aggr->skb, ETH_HLEN); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 571 | |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 572 | skb_buff = skb_put(forw_packet_aggr->skb, packet_len); |
| 573 | forw_packet_aggr->packet_len = packet_len; |
| 574 | memcpy(skb_buff, packet_buff, packet_len); |
| 575 | |
| 576 | forw_packet_aggr->own = own_packet; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 577 | forw_packet_aggr->direct_link_flags = BATADV_NO_FLAGS; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 578 | forw_packet_aggr->send_time = send_time; |
| 579 | |
| 580 | /* save packet direct link flag status */ |
| 581 | if (direct_link) |
| 582 | forw_packet_aggr->direct_link_flags |= 1; |
| 583 | |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 584 | INIT_DELAYED_WORK(&forw_packet_aggr->delayed_work, |
Antonio Quartulli | f0d9725 | 2016-05-03 01:45:34 +0800 | [diff] [blame] | 585 | batadv_iv_send_outstanding_bat_ogm_packet); |
Linus LĂĽssing | 9b4aec6 | 2016-11-01 09:44:44 +0100 | [diff] [blame] | 586 | |
| 587 | batadv_forw_packet_ogmv1_queue(bat_priv, forw_packet_aggr, send_time); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | /* aggregate a new packet into the existing ogm packet */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 591 | static void batadv_iv_ogm_aggregate(struct batadv_forw_packet *forw_packet_aggr, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 592 | const unsigned char *packet_buff, |
| 593 | int packet_len, bool direct_link) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 594 | { |
Sven Eckelmann | 8de47de | 2012-07-08 16:32:09 +0200 | [diff] [blame] | 595 | unsigned long new_direct_link_flag; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 596 | |
Sven Eckelmann | e04de48 | 2017-06-18 09:59:28 +0200 | [diff] [blame] | 597 | skb_put_data(forw_packet_aggr->skb, packet_buff, packet_len); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 598 | forw_packet_aggr->packet_len += packet_len; |
| 599 | forw_packet_aggr->num_packets++; |
| 600 | |
| 601 | /* save packet direct link flag status */ |
Sven Eckelmann | 8de47de | 2012-07-08 16:32:09 +0200 | [diff] [blame] | 602 | if (direct_link) { |
| 603 | new_direct_link_flag = BIT(forw_packet_aggr->num_packets); |
| 604 | forw_packet_aggr->direct_link_flags |= new_direct_link_flag; |
| 605 | } |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 606 | } |
| 607 | |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 608 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 609 | * batadv_iv_ogm_queue_add() - queue up an OGM for transmission |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 610 | * @bat_priv: the bat priv with all the soft interface information |
| 611 | * @packet_buff: pointer to the OGM |
| 612 | * @packet_len: (total) length of the OGM |
| 613 | * @if_incoming: interface where the packet was received |
| 614 | * @if_outgoing: interface for which the retransmission should be considered |
| 615 | * @own_packet: true if it is a self-generated ogm |
| 616 | * @send_time: timestamp (jiffies) when the packet is to be sent |
| 617 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 618 | static void batadv_iv_ogm_queue_add(struct batadv_priv *bat_priv, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 619 | unsigned char *packet_buff, |
| 620 | int packet_len, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 621 | struct batadv_hard_iface *if_incoming, |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 622 | struct batadv_hard_iface *if_outgoing, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 623 | int own_packet, unsigned long send_time) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 624 | { |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 625 | /* _aggr -> pointer to the packet we want to aggregate with |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 626 | * _pos -> pointer to the position in the queue |
| 627 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 628 | struct batadv_forw_packet *forw_packet_aggr = NULL; |
| 629 | struct batadv_forw_packet *forw_packet_pos = NULL; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 630 | struct batadv_ogm_packet *batadv_ogm_packet; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 631 | bool direct_link; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 632 | unsigned long max_aggregation_jiffies; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 633 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 634 | batadv_ogm_packet = (struct batadv_ogm_packet *)packet_buff; |
Markus Pargmann | 5648915 | 2014-12-26 12:41:32 +0100 | [diff] [blame] | 635 | direct_link = !!(batadv_ogm_packet->flags & BATADV_DIRECTLINK); |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 636 | max_aggregation_jiffies = msecs_to_jiffies(BATADV_MAX_AGGREGATION_MS); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 637 | |
| 638 | /* find position for the packet in the forward queue */ |
| 639 | spin_lock_bh(&bat_priv->forw_bat_list_lock); |
| 640 | /* own packets are not to be aggregated */ |
Markus Pargmann | 5648915 | 2014-12-26 12:41:32 +0100 | [diff] [blame] | 641 | if (atomic_read(&bat_priv->aggregated_ogms) && !own_packet) { |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 642 | hlist_for_each_entry(forw_packet_pos, |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 643 | &bat_priv->forw_bat_list, list) { |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 644 | if (batadv_iv_ogm_can_aggregate(batadv_ogm_packet, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 645 | bat_priv, packet_len, |
| 646 | send_time, direct_link, |
| 647 | if_incoming, |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 648 | if_outgoing, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 649 | forw_packet_pos)) { |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 650 | forw_packet_aggr = forw_packet_pos; |
| 651 | break; |
| 652 | } |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | /* nothing to aggregate with - either aggregation disabled or no |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 657 | * suitable aggregation packet found |
| 658 | */ |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 659 | if (!forw_packet_aggr) { |
| 660 | /* the following section can run without the lock */ |
| 661 | spin_unlock_bh(&bat_priv->forw_bat_list_lock); |
| 662 | |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 663 | /* if we could not aggregate this packet with one of the others |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 664 | * we hold it back for a while, so that it might be aggregated |
| 665 | * later on |
| 666 | */ |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 667 | if (!own_packet && atomic_read(&bat_priv->aggregated_ogms)) |
| 668 | send_time += max_aggregation_jiffies; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 669 | |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 670 | batadv_iv_ogm_aggregate_new(packet_buff, packet_len, |
| 671 | send_time, direct_link, |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 672 | if_incoming, if_outgoing, |
| 673 | own_packet); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 674 | } else { |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 675 | batadv_iv_ogm_aggregate(forw_packet_aggr, packet_buff, |
| 676 | packet_len, direct_link); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 677 | spin_unlock_bh(&bat_priv->forw_bat_list_lock); |
| 678 | } |
| 679 | } |
| 680 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 681 | static void batadv_iv_ogm_forward(struct batadv_orig_node *orig_node, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 682 | const struct ethhdr *ethhdr, |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 683 | struct batadv_ogm_packet *batadv_ogm_packet, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 684 | bool is_single_hop_neigh, |
| 685 | bool is_from_best_next_hop, |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 686 | struct batadv_hard_iface *if_incoming, |
| 687 | struct batadv_hard_iface *if_outgoing) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 688 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 689 | struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface); |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 690 | u16 tvlv_len; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 691 | |
Simon Wunderlich | a40d9b0 | 2013-12-02 20:38:31 +0100 | [diff] [blame] | 692 | if (batadv_ogm_packet->ttl <= 1) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 693 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, "ttl exceeded\n"); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 694 | return; |
| 695 | } |
| 696 | |
Marek Lindner | 13b2541 | 2012-03-11 06:17:53 +0800 | [diff] [blame] | 697 | if (!is_from_best_next_hop) { |
| 698 | /* Mark the forwarded packet when it is not coming from our |
| 699 | * best next hop. We still need to forward the packet for our |
| 700 | * neighbor link quality detection to work in case the packet |
| 701 | * originated from a single hop neighbor. Otherwise we can |
| 702 | * simply drop the ogm. |
| 703 | */ |
| 704 | if (is_single_hop_neigh) |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 705 | batadv_ogm_packet->flags |= BATADV_NOT_BEST_NEXT_HOP; |
Marek Lindner | 13b2541 | 2012-03-11 06:17:53 +0800 | [diff] [blame] | 706 | else |
| 707 | return; |
| 708 | } |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 709 | |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 710 | tvlv_len = ntohs(batadv_ogm_packet->tvlv_len); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 711 | |
Simon Wunderlich | a40d9b0 | 2013-12-02 20:38:31 +0100 | [diff] [blame] | 712 | batadv_ogm_packet->ttl--; |
Antonio Quartulli | 8fdd015 | 2014-01-22 00:42:11 +0100 | [diff] [blame] | 713 | ether_addr_copy(batadv_ogm_packet->prev_sender, ethhdr->h_source); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 714 | |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 715 | /* apply hop penalty */ |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 716 | batadv_ogm_packet->tq = batadv_hop_penalty(batadv_ogm_packet->tq, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 717 | bat_priv); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 718 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 719 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 720 | "Forwarding packet: tq: %i, ttl: %i\n", |
Simon Wunderlich | a40d9b0 | 2013-12-02 20:38:31 +0100 | [diff] [blame] | 721 | batadv_ogm_packet->tq, batadv_ogm_packet->ttl); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 722 | |
Marek Lindner | 75cd33f | 2012-03-01 15:35:16 +0800 | [diff] [blame] | 723 | if (is_single_hop_neigh) |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 724 | batadv_ogm_packet->flags |= BATADV_DIRECTLINK; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 725 | else |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 726 | batadv_ogm_packet->flags &= ~BATADV_DIRECTLINK; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 727 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 728 | batadv_iv_ogm_queue_add(bat_priv, (unsigned char *)batadv_ogm_packet, |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 729 | BATADV_OGM_HLEN + tvlv_len, |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 730 | if_incoming, if_outgoing, 0, |
| 731 | batadv_iv_ogm_fwd_send_time()); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 732 | } |
| 733 | |
Antonio Quartulli | d989661 | 2013-04-17 17:44:43 +0200 | [diff] [blame] | 734 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 735 | * batadv_iv_ogm_slide_own_bcast_window() - bitshift own OGM broadcast windows |
| 736 | * for the given interface |
Antonio Quartulli | d989661 | 2013-04-17 17:44:43 +0200 | [diff] [blame] | 737 | * @hard_iface: the interface for which the windows have to be shifted |
| 738 | */ |
| 739 | static void |
| 740 | batadv_iv_ogm_slide_own_bcast_window(struct batadv_hard_iface *hard_iface) |
| 741 | { |
| 742 | struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); |
| 743 | struct batadv_hashtable *hash = bat_priv->orig_hash; |
| 744 | struct hlist_head *head; |
| 745 | struct batadv_orig_node *orig_node; |
Sven Eckelmann | dee222c7 | 2018-08-16 16:54:45 +0200 | [diff] [blame] | 746 | struct batadv_orig_ifinfo *orig_ifinfo; |
Antonio Quartulli | d989661 | 2013-04-17 17:44:43 +0200 | [diff] [blame] | 747 | unsigned long *word; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 748 | u32 i; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 749 | u8 *w; |
Antonio Quartulli | d989661 | 2013-04-17 17:44:43 +0200 | [diff] [blame] | 750 | |
| 751 | for (i = 0; i < hash->size; i++) { |
| 752 | head = &hash->table[i]; |
| 753 | |
| 754 | rcu_read_lock(); |
| 755 | hlist_for_each_entry_rcu(orig_node, head, hash_entry) { |
Sven Eckelmann | dee222c7 | 2018-08-16 16:54:45 +0200 | [diff] [blame] | 756 | hlist_for_each_entry_rcu(orig_ifinfo, |
| 757 | &orig_node->ifinfo_list, |
| 758 | list) { |
| 759 | if (orig_ifinfo->if_outgoing != hard_iface) |
| 760 | continue; |
Antonio Quartulli | d989661 | 2013-04-17 17:44:43 +0200 | [diff] [blame] | 761 | |
Sven Eckelmann | dee222c7 | 2018-08-16 16:54:45 +0200 | [diff] [blame] | 762 | spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock); |
| 763 | word = orig_ifinfo->bat_iv.bcast_own; |
| 764 | batadv_bit_get_packet(bat_priv, word, 1, 0); |
| 765 | w = &orig_ifinfo->bat_iv.bcast_own_sum; |
| 766 | *w = bitmap_weight(word, |
| 767 | BATADV_TQ_LOCAL_WINDOW_SIZE); |
| 768 | spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock); |
| 769 | } |
Antonio Quartulli | d989661 | 2013-04-17 17:44:43 +0200 | [diff] [blame] | 770 | } |
| 771 | rcu_read_unlock(); |
| 772 | } |
| 773 | } |
| 774 | |
Sven Eckelmann | 40e220b | 2019-10-03 17:02:01 +0200 | [diff] [blame] | 775 | /** |
| 776 | * batadv_iv_ogm_schedule_buff() - schedule submission of hardif ogm buffer |
| 777 | * @hard_iface: interface whose ogm buffer should be transmitted |
| 778 | */ |
| 779 | static void batadv_iv_ogm_schedule_buff(struct batadv_hard_iface *hard_iface) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 780 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 781 | struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 782 | unsigned char **ogm_buff = &hard_iface->bat_iv.ogm_buff; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 783 | struct batadv_ogm_packet *batadv_ogm_packet; |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 784 | struct batadv_hard_iface *primary_if, *tmp_hard_iface; |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 785 | int *ogm_buff_len = &hard_iface->bat_iv.ogm_buff_len; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 786 | u32 seqno; |
| 787 | u16 tvlv_len = 0; |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 788 | unsigned long send_time; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 789 | |
Sven Eckelmann | 40e220b | 2019-10-03 17:02:01 +0200 | [diff] [blame] | 790 | lockdep_assert_held(&hard_iface->bat_iv.ogm_buff_mutex); |
Antonio Quartulli | f0d9725 | 2016-05-03 01:45:34 +0800 | [diff] [blame] | 791 | |
Sven Eckelmann | 8e8ce08 | 2020-02-16 13:02:06 +0100 | [diff] [blame] | 792 | /* interface already disabled by batadv_iv_ogm_iface_disable */ |
| 793 | if (!*ogm_buff) |
| 794 | return; |
| 795 | |
Antonio Quartulli | f0d9725 | 2016-05-03 01:45:34 +0800 | [diff] [blame] | 796 | /* the interface gets activated here to avoid race conditions between |
| 797 | * the moment of activating the interface in |
| 798 | * hardif_activate_interface() where the originator mac is set and |
| 799 | * outdated packets (especially uninitialized mac addresses) in the |
| 800 | * packet queue |
| 801 | */ |
| 802 | if (hard_iface->if_status == BATADV_IF_TO_BE_ACTIVATED) |
| 803 | hard_iface->if_status = BATADV_IF_ACTIVE; |
| 804 | |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 805 | primary_if = batadv_primary_if_get_selected(bat_priv); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 806 | |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 807 | if (hard_iface == primary_if) { |
| 808 | /* tt changes have to be committed before the tvlv data is |
| 809 | * appended as it may alter the tt tvlv container |
| 810 | */ |
| 811 | batadv_tt_local_commit_changes(bat_priv); |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 812 | tvlv_len = batadv_tvlv_container_ogm_append(bat_priv, ogm_buff, |
| 813 | ogm_buff_len, |
| 814 | BATADV_OGM_HLEN); |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 815 | } |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 816 | |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 817 | batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff); |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 818 | batadv_ogm_packet->tvlv_len = htons(tvlv_len); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 819 | |
| 820 | /* change sequence number to network order */ |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 821 | seqno = (u32)atomic_read(&hard_iface->bat_iv.ogm_seqno); |
Sven Eckelmann | bbb1f90 | 2012-07-08 17:13:15 +0200 | [diff] [blame] | 822 | batadv_ogm_packet->seqno = htonl(seqno); |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 823 | atomic_inc(&hard_iface->bat_iv.ogm_seqno); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 824 | |
Antonio Quartulli | d989661 | 2013-04-17 17:44:43 +0200 | [diff] [blame] | 825 | batadv_iv_ogm_slide_own_bcast_window(hard_iface); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 826 | |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 827 | send_time = batadv_iv_ogm_emit_send_time(bat_priv); |
| 828 | |
| 829 | if (hard_iface != primary_if) { |
| 830 | /* OGMs from secondary interfaces are only scheduled on their |
| 831 | * respective interfaces. |
| 832 | */ |
| 833 | batadv_iv_ogm_queue_add(bat_priv, *ogm_buff, *ogm_buff_len, |
| 834 | hard_iface, hard_iface, 1, send_time); |
| 835 | goto out; |
| 836 | } |
| 837 | |
| 838 | /* OGMs from primary interfaces are scheduled on all |
| 839 | * interfaces. |
| 840 | */ |
| 841 | rcu_read_lock(); |
| 842 | list_for_each_entry_rcu(tmp_hard_iface, &batadv_hardif_list, list) { |
| 843 | if (tmp_hard_iface->soft_iface != hard_iface->soft_iface) |
Sven Eckelmann | 87b40f5 | 2015-07-17 10:03:42 +0200 | [diff] [blame] | 844 | continue; |
Sven Eckelmann | 2735344 | 2016-03-05 16:09:16 +0100 | [diff] [blame] | 845 | |
| 846 | if (!kref_get_unless_zero(&tmp_hard_iface->refcount)) |
| 847 | continue; |
| 848 | |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 849 | batadv_iv_ogm_queue_add(bat_priv, *ogm_buff, |
| 850 | *ogm_buff_len, hard_iface, |
| 851 | tmp_hard_iface, 1, send_time); |
Sven Eckelmann | 2735344 | 2016-03-05 16:09:16 +0100 | [diff] [blame] | 852 | |
| 853 | batadv_hardif_put(tmp_hard_iface); |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 854 | } |
| 855 | rcu_read_unlock(); |
| 856 | |
| 857 | out: |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 858 | if (primary_if) |
Sven Eckelmann | 82047ad | 2016-01-17 11:01:10 +0100 | [diff] [blame] | 859 | batadv_hardif_put(primary_if); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 860 | } |
| 861 | |
Sven Eckelmann | 40e220b | 2019-10-03 17:02:01 +0200 | [diff] [blame] | 862 | static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface) |
| 863 | { |
| 864 | if (hard_iface->if_status == BATADV_IF_NOT_IN_USE || |
| 865 | hard_iface->if_status == BATADV_IF_TO_BE_REMOVED) |
| 866 | return; |
| 867 | |
| 868 | mutex_lock(&hard_iface->bat_iv.ogm_buff_mutex); |
| 869 | batadv_iv_ogm_schedule_buff(hard_iface); |
| 870 | mutex_unlock(&hard_iface->bat_iv.ogm_buff_mutex); |
| 871 | } |
| 872 | |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 873 | /** |
Sven Eckelmann | dee222c7 | 2018-08-16 16:54:45 +0200 | [diff] [blame] | 874 | * batadv_iv_orig_ifinfo_sum() - Get bcast_own sum for originator over iterface |
| 875 | * @orig_node: originator which reproadcasted the OGMs directly |
| 876 | * @if_outgoing: interface which transmitted the original OGM and received the |
| 877 | * direct rebroadcast |
| 878 | * |
| 879 | * Return: Number of replied (rebroadcasted) OGMs which were transmitted by |
| 880 | * an originator and directly (without intermediate hop) received by a specific |
| 881 | * interface |
| 882 | */ |
| 883 | static u8 batadv_iv_orig_ifinfo_sum(struct batadv_orig_node *orig_node, |
| 884 | struct batadv_hard_iface *if_outgoing) |
| 885 | { |
| 886 | struct batadv_orig_ifinfo *orig_ifinfo; |
| 887 | u8 sum; |
| 888 | |
| 889 | orig_ifinfo = batadv_orig_ifinfo_get(orig_node, if_outgoing); |
| 890 | if (!orig_ifinfo) |
| 891 | return 0; |
| 892 | |
| 893 | spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock); |
| 894 | sum = orig_ifinfo->bat_iv.bcast_own_sum; |
| 895 | spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock); |
| 896 | |
| 897 | batadv_orig_ifinfo_put(orig_ifinfo); |
| 898 | |
| 899 | return sum; |
| 900 | } |
| 901 | |
| 902 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 903 | * batadv_iv_ogm_orig_update() - use OGM to update corresponding data in an |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 904 | * originator |
| 905 | * @bat_priv: the bat priv with all the soft interface information |
| 906 | * @orig_node: the orig node who originally emitted the ogm packet |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 907 | * @orig_ifinfo: ifinfo for the outgoing interface of the orig_node |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 908 | * @ethhdr: Ethernet header of the OGM |
| 909 | * @batadv_ogm_packet: the ogm packet |
| 910 | * @if_incoming: interface where the packet was received |
| 911 | * @if_outgoing: interface for which the retransmission should be considered |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 912 | * @dup_status: the duplicate status of this ogm packet. |
| 913 | */ |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 914 | static void |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 915 | batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv, |
| 916 | struct batadv_orig_node *orig_node, |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 917 | struct batadv_orig_ifinfo *orig_ifinfo, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 918 | const struct ethhdr *ethhdr, |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 919 | const struct batadv_ogm_packet *batadv_ogm_packet, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 920 | struct batadv_hard_iface *if_incoming, |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 921 | struct batadv_hard_iface *if_outgoing, |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 922 | enum batadv_dup_status dup_status) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 923 | { |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 924 | struct batadv_neigh_ifinfo *neigh_ifinfo = NULL; |
| 925 | struct batadv_neigh_ifinfo *router_ifinfo = NULL; |
Sven Eckelmann | 4f248cf | 2015-06-09 20:50:49 +0200 | [diff] [blame] | 926 | struct batadv_neigh_node *neigh_node = NULL; |
| 927 | struct batadv_neigh_node *tmp_neigh_node = NULL; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 928 | struct batadv_neigh_node *router = NULL; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 929 | u8 sum_orig, sum_neigh; |
| 930 | u8 *neigh_addr; |
| 931 | u8 tq_avg; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 932 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 933 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 22f0502 | 2017-05-19 13:02:00 +0200 | [diff] [blame] | 934 | "%s(): Searching and updating originator entry of received packet\n", |
| 935 | __func__); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 936 | |
| 937 | rcu_read_lock(); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 938 | hlist_for_each_entry_rcu(tmp_neigh_node, |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 939 | &orig_node->neigh_list, list) { |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 940 | neigh_addr = tmp_neigh_node->addr; |
| 941 | if (batadv_compare_eth(neigh_addr, ethhdr->h_source) && |
| 942 | tmp_neigh_node->if_incoming == if_incoming && |
Sven Eckelmann | 77ae32e | 2016-01-16 10:29:53 +0100 | [diff] [blame] | 943 | kref_get_unless_zero(&tmp_neigh_node->refcount)) { |
Antonio Quartulli | 38dc40e | 2013-03-30 17:22:00 +0100 | [diff] [blame] | 944 | if (WARN(neigh_node, "too many matching neigh_nodes")) |
Sven Eckelmann | 25bb250 | 2016-01-17 11:01:11 +0100 | [diff] [blame] | 945 | batadv_neigh_node_put(neigh_node); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 946 | neigh_node = tmp_neigh_node; |
| 947 | continue; |
| 948 | } |
| 949 | |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 950 | if (dup_status != BATADV_NO_DUP) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 951 | continue; |
| 952 | |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 953 | /* only update the entry for this outgoing interface */ |
| 954 | neigh_ifinfo = batadv_neigh_ifinfo_get(tmp_neigh_node, |
| 955 | if_outgoing); |
| 956 | if (!neigh_ifinfo) |
| 957 | continue; |
| 958 | |
| 959 | spin_lock_bh(&tmp_neigh_node->ifinfo_lock); |
| 960 | batadv_ring_buffer_set(neigh_ifinfo->bat_iv.tq_recv, |
| 961 | &neigh_ifinfo->bat_iv.tq_index, 0); |
| 962 | tq_avg = batadv_ring_buffer_avg(neigh_ifinfo->bat_iv.tq_recv); |
| 963 | neigh_ifinfo->bat_iv.tq_avg = tq_avg; |
| 964 | spin_unlock_bh(&tmp_neigh_node->ifinfo_lock); |
| 965 | |
Sven Eckelmann | 044fa3a | 2016-01-17 11:01:12 +0100 | [diff] [blame] | 966 | batadv_neigh_ifinfo_put(neigh_ifinfo); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 967 | neigh_ifinfo = NULL; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | if (!neigh_node) { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 971 | struct batadv_orig_node *orig_tmp; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 972 | |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 973 | orig_tmp = batadv_iv_ogm_orig_get(bat_priv, ethhdr->h_source); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 974 | if (!orig_tmp) |
| 975 | goto unlock; |
| 976 | |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 977 | neigh_node = batadv_iv_ogm_neigh_new(if_incoming, |
| 978 | ethhdr->h_source, |
Antonio Quartulli | 863dd7a | 2013-03-25 13:49:46 +0100 | [diff] [blame] | 979 | orig_node, orig_tmp); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 980 | |
Sven Eckelmann | 5d96731 | 2016-01-17 11:01:09 +0100 | [diff] [blame] | 981 | batadv_orig_node_put(orig_tmp); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 982 | if (!neigh_node) |
| 983 | goto unlock; |
Markus Pargmann | 23badd6 | 2014-12-26 12:41:33 +0100 | [diff] [blame] | 984 | } else { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 985 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 986 | "Updating existing last-hop neighbor of originator\n"); |
Markus Pargmann | 23badd6 | 2014-12-26 12:41:33 +0100 | [diff] [blame] | 987 | } |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 988 | |
| 989 | rcu_read_unlock(); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 990 | neigh_ifinfo = batadv_neigh_ifinfo_new(neigh_node, if_outgoing); |
| 991 | if (!neigh_ifinfo) |
| 992 | goto out; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 993 | |
Marek Lindner | d7b2a97 | 2012-03-01 15:35:19 +0800 | [diff] [blame] | 994 | neigh_node->last_seen = jiffies; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 995 | |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 996 | spin_lock_bh(&neigh_node->ifinfo_lock); |
| 997 | batadv_ring_buffer_set(neigh_ifinfo->bat_iv.tq_recv, |
| 998 | &neigh_ifinfo->bat_iv.tq_index, |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 999 | batadv_ogm_packet->tq); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1000 | tq_avg = batadv_ring_buffer_avg(neigh_ifinfo->bat_iv.tq_recv); |
| 1001 | neigh_ifinfo->bat_iv.tq_avg = tq_avg; |
| 1002 | spin_unlock_bh(&neigh_node->ifinfo_lock); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1003 | |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1004 | if (dup_status == BATADV_NO_DUP) { |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1005 | orig_ifinfo->last_ttl = batadv_ogm_packet->ttl; |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1006 | neigh_ifinfo->last_ttl = batadv_ogm_packet->ttl; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1007 | } |
| 1008 | |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1009 | /* if this neighbor already is our next hop there is nothing |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1010 | * to change |
| 1011 | */ |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1012 | router = batadv_orig_router_get(orig_node, if_outgoing); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1013 | if (router == neigh_node) |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 1014 | goto out; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1015 | |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1016 | if (router) { |
| 1017 | router_ifinfo = batadv_neigh_ifinfo_get(router, if_outgoing); |
| 1018 | if (!router_ifinfo) |
| 1019 | goto out; |
| 1020 | |
| 1021 | /* if this neighbor does not offer a better TQ we won't |
| 1022 | * consider it |
| 1023 | */ |
| 1024 | if (router_ifinfo->bat_iv.tq_avg > neigh_ifinfo->bat_iv.tq_avg) |
| 1025 | goto out; |
| 1026 | } |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1027 | |
| 1028 | /* if the TQ is the same and the link not more symmetric we |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1029 | * won't consider it either |
| 1030 | */ |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1031 | if (router_ifinfo && |
Markus Pargmann | 01b97a3 | 2014-12-26 12:41:30 +0100 | [diff] [blame] | 1032 | neigh_ifinfo->bat_iv.tq_avg == router_ifinfo->bat_iv.tq_avg) { |
Sven Eckelmann | dee222c7 | 2018-08-16 16:54:45 +0200 | [diff] [blame] | 1033 | sum_orig = batadv_iv_orig_ifinfo_sum(router->orig_node, |
| 1034 | router->if_incoming); |
| 1035 | sum_neigh = batadv_iv_orig_ifinfo_sum(neigh_node->orig_node, |
| 1036 | neigh_node->if_incoming); |
Sven Eckelmann | bbb1f90 | 2012-07-08 17:13:15 +0200 | [diff] [blame] | 1037 | if (sum_orig >= sum_neigh) |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 1038 | goto out; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1039 | } |
| 1040 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1041 | batadv_update_route(bat_priv, orig_node, if_outgoing, neigh_node); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1042 | goto out; |
| 1043 | |
| 1044 | unlock: |
| 1045 | rcu_read_unlock(); |
| 1046 | out: |
| 1047 | if (neigh_node) |
Sven Eckelmann | 25bb250 | 2016-01-17 11:01:11 +0100 | [diff] [blame] | 1048 | batadv_neigh_node_put(neigh_node); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1049 | if (router) |
Sven Eckelmann | 25bb250 | 2016-01-17 11:01:11 +0100 | [diff] [blame] | 1050 | batadv_neigh_node_put(router); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1051 | if (neigh_ifinfo) |
Sven Eckelmann | 044fa3a | 2016-01-17 11:01:12 +0100 | [diff] [blame] | 1052 | batadv_neigh_ifinfo_put(neigh_ifinfo); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1053 | if (router_ifinfo) |
Sven Eckelmann | 044fa3a | 2016-01-17 11:01:12 +0100 | [diff] [blame] | 1054 | batadv_neigh_ifinfo_put(router_ifinfo); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1055 | } |
| 1056 | |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1057 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 1058 | * batadv_iv_ogm_calc_tq() - calculate tq for current received ogm packet |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1059 | * @orig_node: the orig node who originally emitted the ogm packet |
| 1060 | * @orig_neigh_node: the orig node struct of the neighbor who sent the packet |
| 1061 | * @batadv_ogm_packet: the ogm packet |
| 1062 | * @if_incoming: interface where the packet was received |
| 1063 | * @if_outgoing: interface for which the retransmission should be considered |
| 1064 | * |
Sven Eckelmann | 4b426b1 | 2016-02-22 21:02:39 +0100 | [diff] [blame] | 1065 | * Return: true if the link can be considered bidirectional, false otherwise |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1066 | */ |
Sven Eckelmann | 4b426b1 | 2016-02-22 21:02:39 +0100 | [diff] [blame] | 1067 | static bool batadv_iv_ogm_calc_tq(struct batadv_orig_node *orig_node, |
| 1068 | struct batadv_orig_node *orig_neigh_node, |
| 1069 | struct batadv_ogm_packet *batadv_ogm_packet, |
| 1070 | struct batadv_hard_iface *if_incoming, |
| 1071 | struct batadv_hard_iface *if_outgoing) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1072 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1073 | struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface); |
| 1074 | struct batadv_neigh_node *neigh_node = NULL, *tmp_neigh_node; |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1075 | struct batadv_neigh_ifinfo *neigh_ifinfo; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 1076 | u8 total_count; |
| 1077 | u8 orig_eq_count, neigh_rq_count, neigh_rq_inv, tq_own; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 1078 | unsigned int neigh_rq_inv_cube, neigh_rq_max_cube; |
Sven Eckelmann | d285f52 | 2016-02-16 10:47:07 +0100 | [diff] [blame] | 1079 | unsigned int tq_asym_penalty, inv_asym_penalty; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 1080 | unsigned int combined_tq; |
Sven Eckelmann | d285f52 | 2016-02-16 10:47:07 +0100 | [diff] [blame] | 1081 | unsigned int tq_iface_penalty; |
Sven Eckelmann | 4b426b1 | 2016-02-22 21:02:39 +0100 | [diff] [blame] | 1082 | bool ret = false; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1083 | |
| 1084 | /* find corresponding one hop neighbor */ |
| 1085 | rcu_read_lock(); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1086 | hlist_for_each_entry_rcu(tmp_neigh_node, |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1087 | &orig_neigh_node->neigh_list, list) { |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1088 | if (!batadv_compare_eth(tmp_neigh_node->addr, |
| 1089 | orig_neigh_node->orig)) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1090 | continue; |
| 1091 | |
| 1092 | if (tmp_neigh_node->if_incoming != if_incoming) |
| 1093 | continue; |
| 1094 | |
Sven Eckelmann | 77ae32e | 2016-01-16 10:29:53 +0100 | [diff] [blame] | 1095 | if (!kref_get_unless_zero(&tmp_neigh_node->refcount)) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1096 | continue; |
| 1097 | |
| 1098 | neigh_node = tmp_neigh_node; |
| 1099 | break; |
| 1100 | } |
| 1101 | rcu_read_unlock(); |
| 1102 | |
| 1103 | if (!neigh_node) |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 1104 | neigh_node = batadv_iv_ogm_neigh_new(if_incoming, |
| 1105 | orig_neigh_node->orig, |
| 1106 | orig_neigh_node, |
Antonio Quartulli | 863dd7a | 2013-03-25 13:49:46 +0100 | [diff] [blame] | 1107 | orig_neigh_node); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1108 | |
| 1109 | if (!neigh_node) |
| 1110 | goto out; |
| 1111 | |
Marek Lindner | d7b2a97 | 2012-03-01 15:35:19 +0800 | [diff] [blame] | 1112 | /* if orig_node is direct neighbor update neigh_node last_seen */ |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1113 | if (orig_node == orig_neigh_node) |
Marek Lindner | d7b2a97 | 2012-03-01 15:35:19 +0800 | [diff] [blame] | 1114 | neigh_node->last_seen = jiffies; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1115 | |
Marek Lindner | d7b2a97 | 2012-03-01 15:35:19 +0800 | [diff] [blame] | 1116 | orig_node->last_seen = jiffies; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1117 | |
| 1118 | /* find packet count of corresponding one hop neighbor */ |
Sven Eckelmann | dee222c7 | 2018-08-16 16:54:45 +0200 | [diff] [blame] | 1119 | orig_eq_count = batadv_iv_orig_ifinfo_sum(orig_neigh_node, if_incoming); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1120 | neigh_ifinfo = batadv_neigh_ifinfo_new(neigh_node, if_outgoing); |
| 1121 | if (neigh_ifinfo) { |
| 1122 | neigh_rq_count = neigh_ifinfo->bat_iv.real_packet_count; |
Sven Eckelmann | 044fa3a | 2016-01-17 11:01:12 +0100 | [diff] [blame] | 1123 | batadv_neigh_ifinfo_put(neigh_ifinfo); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1124 | } else { |
| 1125 | neigh_rq_count = 0; |
| 1126 | } |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1127 | |
| 1128 | /* pay attention to not get a value bigger than 100 % */ |
Sven Eckelmann | c67893d | 2012-07-08 18:33:51 +0200 | [diff] [blame] | 1129 | if (orig_eq_count > neigh_rq_count) |
| 1130 | total_count = neigh_rq_count; |
| 1131 | else |
| 1132 | total_count = orig_eq_count; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1133 | |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1134 | /* if we have too few packets (too less data) we set tq_own to zero |
| 1135 | * if we receive too few packets it is not considered bidirectional |
| 1136 | */ |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 1137 | if (total_count < BATADV_TQ_LOCAL_BIDRECT_SEND_MINIMUM || |
| 1138 | neigh_rq_count < BATADV_TQ_LOCAL_BIDRECT_RECV_MINIMUM) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1139 | tq_own = 0; |
| 1140 | else |
| 1141 | /* neigh_node->real_packet_count is never zero as we |
| 1142 | * only purge old information when getting new |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1143 | * information |
| 1144 | */ |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 1145 | tq_own = (BATADV_TQ_MAX_VALUE * total_count) / neigh_rq_count; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1146 | |
Sven Eckelmann | 21a1236 | 2012-03-07 09:07:46 +0100 | [diff] [blame] | 1147 | /* 1 - ((1-x) ** 3), normalized to TQ_MAX_VALUE this does |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1148 | * affect the nearly-symmetric links only a little, but |
| 1149 | * punishes asymmetric links more. This will give a value |
| 1150 | * between 0 and TQ_MAX_VALUE |
| 1151 | */ |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 1152 | neigh_rq_inv = BATADV_TQ_LOCAL_WINDOW_SIZE - neigh_rq_count; |
| 1153 | neigh_rq_inv_cube = neigh_rq_inv * neigh_rq_inv * neigh_rq_inv; |
| 1154 | neigh_rq_max_cube = BATADV_TQ_LOCAL_WINDOW_SIZE * |
| 1155 | BATADV_TQ_LOCAL_WINDOW_SIZE * |
| 1156 | BATADV_TQ_LOCAL_WINDOW_SIZE; |
| 1157 | inv_asym_penalty = BATADV_TQ_MAX_VALUE * neigh_rq_inv_cube; |
| 1158 | inv_asym_penalty /= neigh_rq_max_cube; |
| 1159 | tq_asym_penalty = BATADV_TQ_MAX_VALUE - inv_asym_penalty; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1160 | |
Simon Wunderlich | c039876 | 2013-11-13 19:14:48 +0100 | [diff] [blame] | 1161 | /* penalize if the OGM is forwarded on the same interface. WiFi |
| 1162 | * interfaces and other half duplex devices suffer from throughput |
| 1163 | * drops as they can't send and receive at the same time. |
| 1164 | */ |
| 1165 | tq_iface_penalty = BATADV_TQ_MAX_VALUE; |
Sven Eckelmann | 825ffe1 | 2017-08-23 21:52:13 +0200 | [diff] [blame] | 1166 | if (if_outgoing && if_incoming == if_outgoing && |
Sven Eckelmann | 10b1bbb | 2016-09-30 15:21:03 +0200 | [diff] [blame] | 1167 | batadv_is_wifi_hardif(if_outgoing)) |
Simon Wunderlich | c039876 | 2013-11-13 19:14:48 +0100 | [diff] [blame] | 1168 | tq_iface_penalty = batadv_hop_penalty(BATADV_TQ_MAX_VALUE, |
| 1169 | bat_priv); |
| 1170 | |
| 1171 | combined_tq = batadv_ogm_packet->tq * |
| 1172 | tq_own * |
| 1173 | tq_asym_penalty * |
| 1174 | tq_iface_penalty; |
| 1175 | combined_tq /= BATADV_TQ_MAX_VALUE * |
| 1176 | BATADV_TQ_MAX_VALUE * |
| 1177 | BATADV_TQ_MAX_VALUE; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1178 | batadv_ogm_packet->tq = combined_tq; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1179 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1180 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 6a04be8 | 2017-06-18 10:12:30 +0200 | [diff] [blame] | 1181 | "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", |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1182 | orig_node->orig, orig_neigh_node->orig, total_count, |
Simon Wunderlich | c039876 | 2013-11-13 19:14:48 +0100 | [diff] [blame] | 1183 | neigh_rq_count, tq_own, tq_asym_penalty, tq_iface_penalty, |
| 1184 | batadv_ogm_packet->tq, if_incoming->net_dev->name, |
| 1185 | if_outgoing ? if_outgoing->net_dev->name : "DEFAULT"); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1186 | |
| 1187 | /* if link has the minimum required transmission quality |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1188 | * consider it bidirectional |
| 1189 | */ |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1190 | if (batadv_ogm_packet->tq >= BATADV_TQ_TOTAL_BIDRECT_LIMIT) |
Sven Eckelmann | 4b426b1 | 2016-02-22 21:02:39 +0100 | [diff] [blame] | 1191 | ret = true; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1192 | |
| 1193 | out: |
| 1194 | if (neigh_node) |
Sven Eckelmann | 25bb250 | 2016-01-17 11:01:11 +0100 | [diff] [blame] | 1195 | batadv_neigh_node_put(neigh_node); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1196 | return ret; |
| 1197 | } |
| 1198 | |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1199 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 1200 | * batadv_iv_ogm_update_seqnos() - process a batman packet for all interfaces, |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1201 | * adjust the sequence number and find out whether it is a duplicate |
| 1202 | * @ethhdr: ethernet header of the packet |
| 1203 | * @batadv_ogm_packet: OGM packet to be considered |
| 1204 | * @if_incoming: interface on which the OGM packet was received |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1205 | * @if_outgoing: interface for which the retransmission should be considered |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1206 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 1207 | * Return: duplicate status as enum batadv_dup_status |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1208 | */ |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1209 | static enum batadv_dup_status |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 1210 | batadv_iv_ogm_update_seqnos(const struct ethhdr *ethhdr, |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1211 | const struct batadv_ogm_packet *batadv_ogm_packet, |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1212 | const struct batadv_hard_iface *if_incoming, |
| 1213 | struct batadv_hard_iface *if_outgoing) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1214 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1215 | struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface); |
| 1216 | struct batadv_orig_node *orig_node; |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1217 | struct batadv_orig_ifinfo *orig_ifinfo = NULL; |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1218 | struct batadv_neigh_node *neigh_node; |
| 1219 | struct batadv_neigh_ifinfo *neigh_ifinfo; |
Sven Eckelmann | 4b426b1 | 2016-02-22 21:02:39 +0100 | [diff] [blame] | 1220 | bool is_dup; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 1221 | s32 seq_diff; |
Sven Eckelmann | 4b426b1 | 2016-02-22 21:02:39 +0100 | [diff] [blame] | 1222 | bool need_update = false; |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1223 | int set_mark; |
| 1224 | enum batadv_dup_status ret = BATADV_NO_DUP; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 1225 | u32 seqno = ntohl(batadv_ogm_packet->seqno); |
| 1226 | u8 *neigh_addr; |
| 1227 | u8 packet_count; |
Antonio Quartulli | 0538f759 | 2013-09-02 12:15:01 +0200 | [diff] [blame] | 1228 | unsigned long *bitmap; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1229 | |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 1230 | orig_node = batadv_iv_ogm_orig_get(bat_priv, batadv_ogm_packet->orig); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1231 | if (!orig_node) |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1232 | return BATADV_NO_DUP; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1233 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1234 | orig_ifinfo = batadv_orig_ifinfo_new(orig_node, if_outgoing); |
| 1235 | if (WARN_ON(!orig_ifinfo)) { |
Sven Eckelmann | 5d96731 | 2016-01-17 11:01:09 +0100 | [diff] [blame] | 1236 | batadv_orig_node_put(orig_node); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1237 | return 0; |
| 1238 | } |
| 1239 | |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 1240 | spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1241 | seq_diff = seqno - orig_ifinfo->last_real_seqno; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1242 | |
| 1243 | /* signalize caller that the packet is to be dropped. */ |
Antonio Quartulli | 1e5cc26 | 2012-02-26 15:39:42 +0100 | [diff] [blame] | 1244 | if (!hlist_empty(&orig_node->neigh_list) && |
Sven Eckelmann | 30d3c51 | 2012-05-12 02:09:36 +0200 | [diff] [blame] | 1245 | batadv_window_protected(bat_priv, seq_diff, |
Simon Wunderlich | 81f0268 | 2015-11-23 19:57:22 +0100 | [diff] [blame] | 1246 | BATADV_TQ_LOCAL_WINDOW_SIZE, |
| 1247 | &orig_ifinfo->batman_seqno_reset, NULL)) { |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1248 | ret = BATADV_PROTECTED; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1249 | goto out; |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1250 | } |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1251 | |
| 1252 | rcu_read_lock(); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1253 | hlist_for_each_entry_rcu(neigh_node, &orig_node->neigh_list, list) { |
| 1254 | neigh_ifinfo = batadv_neigh_ifinfo_new(neigh_node, |
| 1255 | if_outgoing); |
| 1256 | if (!neigh_ifinfo) |
| 1257 | continue; |
| 1258 | |
| 1259 | neigh_addr = neigh_node->addr; |
| 1260 | is_dup = batadv_test_bit(neigh_ifinfo->bat_iv.real_bits, |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1261 | orig_ifinfo->last_real_seqno, |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1262 | seqno); |
| 1263 | |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1264 | if (batadv_compare_eth(neigh_addr, ethhdr->h_source) && |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1265 | neigh_node->if_incoming == if_incoming) { |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1266 | set_mark = 1; |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1267 | if (is_dup) |
| 1268 | ret = BATADV_NEIGH_DUP; |
| 1269 | } else { |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1270 | set_mark = 0; |
Sven Eckelmann | 825ffe1 | 2017-08-23 21:52:13 +0200 | [diff] [blame] | 1271 | if (is_dup && ret != BATADV_NEIGH_DUP) |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1272 | ret = BATADV_ORIG_DUP; |
| 1273 | } |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1274 | |
| 1275 | /* if the window moved, set the update flag. */ |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1276 | bitmap = neigh_ifinfo->bat_iv.real_bits; |
Antonio Quartulli | 0538f759 | 2013-09-02 12:15:01 +0200 | [diff] [blame] | 1277 | need_update |= batadv_bit_get_packet(bat_priv, bitmap, |
Sven Eckelmann | 0f5f9322 | 2012-05-12 02:09:25 +0200 | [diff] [blame] | 1278 | seq_diff, set_mark); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1279 | |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1280 | packet_count = bitmap_weight(bitmap, |
Sven Eckelmann | bbb1f90 | 2012-07-08 17:13:15 +0200 | [diff] [blame] | 1281 | BATADV_TQ_LOCAL_WINDOW_SIZE); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1282 | neigh_ifinfo->bat_iv.real_packet_count = packet_count; |
Sven Eckelmann | 044fa3a | 2016-01-17 11:01:12 +0100 | [diff] [blame] | 1283 | batadv_neigh_ifinfo_put(neigh_ifinfo); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1284 | } |
| 1285 | rcu_read_unlock(); |
| 1286 | |
| 1287 | if (need_update) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1288 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1289 | "%s updating last_seqno: old %u, new %u\n", |
| 1290 | if_outgoing ? if_outgoing->net_dev->name : "DEFAULT", |
| 1291 | orig_ifinfo->last_real_seqno, seqno); |
| 1292 | orig_ifinfo->last_real_seqno = seqno; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1293 | } |
| 1294 | |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1295 | out: |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 1296 | spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock); |
Sven Eckelmann | 5d96731 | 2016-01-17 11:01:09 +0100 | [diff] [blame] | 1297 | batadv_orig_node_put(orig_node); |
Sven Eckelmann | 35f9477 | 2016-01-17 11:01:13 +0100 | [diff] [blame] | 1298 | batadv_orig_ifinfo_put(orig_ifinfo); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1299 | return ret; |
| 1300 | } |
| 1301 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1302 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 1303 | * batadv_iv_ogm_process_per_outif() - process a batman iv OGM for an outgoing |
| 1304 | * interface |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1305 | * @skb: the skb containing the OGM |
Martin Hundebøll | 95298a9 | 2014-07-15 09:41:05 +0200 | [diff] [blame] | 1306 | * @ogm_offset: offset from skb->data to start of ogm header |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1307 | * @orig_node: the (cached) orig node for the originator of this OGM |
| 1308 | * @if_incoming: the interface where this packet was received |
| 1309 | * @if_outgoing: the interface for which the packet should be considered |
| 1310 | */ |
| 1311 | static void |
| 1312 | batadv_iv_ogm_process_per_outif(const struct sk_buff *skb, int ogm_offset, |
| 1313 | struct batadv_orig_node *orig_node, |
| 1314 | struct batadv_hard_iface *if_incoming, |
| 1315 | struct batadv_hard_iface *if_outgoing) |
| 1316 | { |
| 1317 | struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface); |
Marek Lindner | 4ff1e2a | 2015-08-04 21:09:58 +0800 | [diff] [blame] | 1318 | struct batadv_hardif_neigh_node *hardif_neigh = NULL; |
Sven Eckelmann | 4f248cf | 2015-06-09 20:50:49 +0200 | [diff] [blame] | 1319 | struct batadv_neigh_node *router = NULL; |
| 1320 | struct batadv_neigh_node *router_router = NULL; |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1321 | struct batadv_orig_node *orig_neigh_node; |
| 1322 | struct batadv_orig_ifinfo *orig_ifinfo; |
| 1323 | struct batadv_neigh_node *orig_neigh_router = NULL; |
| 1324 | struct batadv_neigh_ifinfo *router_ifinfo = NULL; |
| 1325 | struct batadv_ogm_packet *ogm_packet; |
| 1326 | enum batadv_dup_status dup_status; |
| 1327 | bool is_from_best_next_hop = false; |
| 1328 | bool is_single_hop_neigh = false; |
| 1329 | bool sameseq, similar_ttl; |
| 1330 | struct sk_buff *skb_priv; |
| 1331 | struct ethhdr *ethhdr; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 1332 | u8 *prev_sender; |
Sven Eckelmann | 4b426b1 | 2016-02-22 21:02:39 +0100 | [diff] [blame] | 1333 | bool is_bidirect; |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1334 | |
| 1335 | /* create a private copy of the skb, as some functions change tq value |
| 1336 | * and/or flags. |
| 1337 | */ |
| 1338 | skb_priv = skb_copy(skb, GFP_ATOMIC); |
| 1339 | if (!skb_priv) |
| 1340 | return; |
| 1341 | |
| 1342 | ethhdr = eth_hdr(skb_priv); |
| 1343 | ogm_packet = (struct batadv_ogm_packet *)(skb_priv->data + ogm_offset); |
| 1344 | |
| 1345 | dup_status = batadv_iv_ogm_update_seqnos(ethhdr, ogm_packet, |
| 1346 | if_incoming, if_outgoing); |
| 1347 | if (batadv_compare_eth(ethhdr->h_source, ogm_packet->orig)) |
| 1348 | is_single_hop_neigh = true; |
| 1349 | |
| 1350 | if (dup_status == BATADV_PROTECTED) { |
| 1351 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
| 1352 | "Drop packet: packet within seqno protection time (sender: %pM)\n", |
| 1353 | ethhdr->h_source); |
| 1354 | goto out; |
| 1355 | } |
| 1356 | |
| 1357 | if (ogm_packet->tq == 0) { |
| 1358 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
| 1359 | "Drop packet: originator packet with tq equal 0\n"); |
| 1360 | goto out; |
| 1361 | } |
| 1362 | |
Marek Lindner | 4ff1e2a | 2015-08-04 21:09:58 +0800 | [diff] [blame] | 1363 | if (is_single_hop_neigh) { |
| 1364 | hardif_neigh = batadv_hardif_neigh_get(if_incoming, |
| 1365 | ethhdr->h_source); |
| 1366 | if (hardif_neigh) |
| 1367 | hardif_neigh->last_seen = jiffies; |
| 1368 | } |
| 1369 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1370 | router = batadv_orig_router_get(orig_node, if_outgoing); |
| 1371 | if (router) { |
| 1372 | router_router = batadv_orig_router_get(router->orig_node, |
| 1373 | if_outgoing); |
| 1374 | router_ifinfo = batadv_neigh_ifinfo_get(router, if_outgoing); |
| 1375 | } |
| 1376 | |
| 1377 | if ((router_ifinfo && router_ifinfo->bat_iv.tq_avg != 0) && |
| 1378 | (batadv_compare_eth(router->addr, ethhdr->h_source))) |
| 1379 | is_from_best_next_hop = true; |
| 1380 | |
| 1381 | prev_sender = ogm_packet->prev_sender; |
| 1382 | /* avoid temporary routing loops */ |
| 1383 | if (router && router_router && |
| 1384 | (batadv_compare_eth(router->addr, prev_sender)) && |
| 1385 | !(batadv_compare_eth(ogm_packet->orig, prev_sender)) && |
| 1386 | (batadv_compare_eth(router->addr, router_router->addr))) { |
| 1387 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
| 1388 | "Drop packet: ignoring all rebroadcast packets that may make me loop (sender: %pM)\n", |
| 1389 | ethhdr->h_source); |
| 1390 | goto out; |
| 1391 | } |
| 1392 | |
| 1393 | if (if_outgoing == BATADV_IF_DEFAULT) |
| 1394 | batadv_tvlv_ogm_receive(bat_priv, ogm_packet, orig_node); |
| 1395 | |
| 1396 | /* if sender is a direct neighbor the sender mac equals |
| 1397 | * originator mac |
| 1398 | */ |
| 1399 | if (is_single_hop_neigh) |
| 1400 | orig_neigh_node = orig_node; |
| 1401 | else |
| 1402 | orig_neigh_node = batadv_iv_ogm_orig_get(bat_priv, |
| 1403 | ethhdr->h_source); |
| 1404 | |
| 1405 | if (!orig_neigh_node) |
| 1406 | goto out; |
| 1407 | |
| 1408 | /* Update nc_nodes of the originator */ |
| 1409 | batadv_nc_update_nc_node(bat_priv, orig_node, orig_neigh_node, |
| 1410 | ogm_packet, is_single_hop_neigh); |
| 1411 | |
| 1412 | orig_neigh_router = batadv_orig_router_get(orig_neigh_node, |
| 1413 | if_outgoing); |
| 1414 | |
| 1415 | /* drop packet if sender is not a direct neighbor and if we |
| 1416 | * don't route towards it |
| 1417 | */ |
Sven Eckelmann | 825ffe1 | 2017-08-23 21:52:13 +0200 | [diff] [blame] | 1418 | if (!is_single_hop_neigh && !orig_neigh_router) { |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1419 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
| 1420 | "Drop packet: OGM via unknown neighbor!\n"); |
| 1421 | goto out_neigh; |
| 1422 | } |
| 1423 | |
| 1424 | is_bidirect = batadv_iv_ogm_calc_tq(orig_node, orig_neigh_node, |
| 1425 | ogm_packet, if_incoming, |
| 1426 | if_outgoing); |
| 1427 | |
| 1428 | /* update ranking if it is not a duplicate or has the same |
| 1429 | * seqno and similar ttl as the non-duplicate |
| 1430 | */ |
| 1431 | orig_ifinfo = batadv_orig_ifinfo_new(orig_node, if_outgoing); |
| 1432 | if (!orig_ifinfo) |
| 1433 | goto out_neigh; |
| 1434 | |
| 1435 | sameseq = orig_ifinfo->last_real_seqno == ntohl(ogm_packet->seqno); |
| 1436 | similar_ttl = (orig_ifinfo->last_ttl - 3) <= ogm_packet->ttl; |
| 1437 | |
Sven Eckelmann | 825ffe1 | 2017-08-23 21:52:13 +0200 | [diff] [blame] | 1438 | if (is_bidirect && (dup_status == BATADV_NO_DUP || |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1439 | (sameseq && similar_ttl))) { |
| 1440 | batadv_iv_ogm_orig_update(bat_priv, orig_node, |
| 1441 | orig_ifinfo, ethhdr, |
| 1442 | ogm_packet, if_incoming, |
| 1443 | if_outgoing, dup_status); |
| 1444 | } |
Sven Eckelmann | 35f9477 | 2016-01-17 11:01:13 +0100 | [diff] [blame] | 1445 | batadv_orig_ifinfo_put(orig_ifinfo); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1446 | |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 1447 | /* only forward for specific interface, not for the default one. */ |
| 1448 | if (if_outgoing == BATADV_IF_DEFAULT) |
| 1449 | goto out_neigh; |
| 1450 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1451 | /* is single hop (direct) neighbor */ |
| 1452 | if (is_single_hop_neigh) { |
| 1453 | /* OGMs from secondary interfaces should only scheduled once |
| 1454 | * per interface where it has been received, not multiple times |
| 1455 | */ |
Sven Eckelmann | 825ffe1 | 2017-08-23 21:52:13 +0200 | [diff] [blame] | 1456 | if (ogm_packet->ttl <= 2 && |
| 1457 | if_incoming != if_outgoing) { |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1458 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
| 1459 | "Drop packet: OGM from secondary interface and wrong outgoing interface\n"); |
| 1460 | goto out_neigh; |
| 1461 | } |
| 1462 | /* mark direct link on incoming interface */ |
| 1463 | batadv_iv_ogm_forward(orig_node, ethhdr, ogm_packet, |
| 1464 | is_single_hop_neigh, |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 1465 | is_from_best_next_hop, if_incoming, |
| 1466 | if_outgoing); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1467 | |
| 1468 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
| 1469 | "Forwarding packet: rebroadcast neighbor packet with direct link flag\n"); |
| 1470 | goto out_neigh; |
| 1471 | } |
| 1472 | |
| 1473 | /* multihop originator */ |
| 1474 | if (!is_bidirect) { |
| 1475 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
| 1476 | "Drop packet: not received via bidirectional link\n"); |
| 1477 | goto out_neigh; |
| 1478 | } |
| 1479 | |
| 1480 | if (dup_status == BATADV_NEIGH_DUP) { |
| 1481 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
| 1482 | "Drop packet: duplicate packet received\n"); |
| 1483 | goto out_neigh; |
| 1484 | } |
| 1485 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1486 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
| 1487 | "Forwarding packet: rebroadcast originator packet\n"); |
| 1488 | batadv_iv_ogm_forward(orig_node, ethhdr, ogm_packet, |
| 1489 | is_single_hop_neigh, is_from_best_next_hop, |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 1490 | if_incoming, if_outgoing); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1491 | |
| 1492 | out_neigh: |
Sven Eckelmann | 825ffe1 | 2017-08-23 21:52:13 +0200 | [diff] [blame] | 1493 | if (orig_neigh_node && !is_single_hop_neigh) |
Sven Eckelmann | 5d96731 | 2016-01-17 11:01:09 +0100 | [diff] [blame] | 1494 | batadv_orig_node_put(orig_neigh_node); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1495 | out: |
Simon Wunderlich | c1e517f | 2014-03-26 15:46:21 +0100 | [diff] [blame] | 1496 | if (router_ifinfo) |
Sven Eckelmann | 044fa3a | 2016-01-17 11:01:12 +0100 | [diff] [blame] | 1497 | batadv_neigh_ifinfo_put(router_ifinfo); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1498 | if (router) |
Sven Eckelmann | 25bb250 | 2016-01-17 11:01:11 +0100 | [diff] [blame] | 1499 | batadv_neigh_node_put(router); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1500 | if (router_router) |
Sven Eckelmann | 25bb250 | 2016-01-17 11:01:11 +0100 | [diff] [blame] | 1501 | batadv_neigh_node_put(router_router); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1502 | if (orig_neigh_router) |
Sven Eckelmann | 25bb250 | 2016-01-17 11:01:11 +0100 | [diff] [blame] | 1503 | batadv_neigh_node_put(orig_neigh_router); |
Marek Lindner | 4ff1e2a | 2015-08-04 21:09:58 +0800 | [diff] [blame] | 1504 | if (hardif_neigh) |
Sven Eckelmann | accadc3 | 2016-01-17 11:01:14 +0100 | [diff] [blame] | 1505 | batadv_hardif_neigh_put(hardif_neigh); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1506 | |
Sven Eckelmann | bd687fe | 2016-07-17 21:04:00 +0200 | [diff] [blame] | 1507 | consume_skb(skb_priv); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1508 | } |
| 1509 | |
| 1510 | /** |
Sven Eckelmann | dee222c7 | 2018-08-16 16:54:45 +0200 | [diff] [blame] | 1511 | * batadv_iv_ogm_process_reply() - Check OGM for direct reply and process it |
| 1512 | * @ogm_packet: rebroadcast OGM packet to process |
| 1513 | * @if_incoming: the interface where this packet was received |
| 1514 | * @orig_node: originator which reproadcasted the OGMs |
| 1515 | * @if_incoming_seqno: OGM sequence number when rebroadcast was received |
| 1516 | */ |
| 1517 | static void batadv_iv_ogm_process_reply(struct batadv_ogm_packet *ogm_packet, |
| 1518 | struct batadv_hard_iface *if_incoming, |
| 1519 | struct batadv_orig_node *orig_node, |
| 1520 | u32 if_incoming_seqno) |
| 1521 | { |
| 1522 | struct batadv_orig_ifinfo *orig_ifinfo; |
| 1523 | s32 bit_pos; |
| 1524 | u8 *weight; |
| 1525 | |
| 1526 | /* neighbor has to indicate direct link and it has to |
| 1527 | * come via the corresponding interface |
| 1528 | */ |
| 1529 | if (!(ogm_packet->flags & BATADV_DIRECTLINK)) |
| 1530 | return; |
| 1531 | |
| 1532 | if (!batadv_compare_eth(if_incoming->net_dev->dev_addr, |
| 1533 | ogm_packet->orig)) |
| 1534 | return; |
| 1535 | |
| 1536 | orig_ifinfo = batadv_orig_ifinfo_get(orig_node, if_incoming); |
| 1537 | if (!orig_ifinfo) |
| 1538 | return; |
| 1539 | |
| 1540 | /* save packet seqno for bidirectional check */ |
| 1541 | spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock); |
| 1542 | bit_pos = if_incoming_seqno - 2; |
| 1543 | bit_pos -= ntohl(ogm_packet->seqno); |
| 1544 | batadv_set_bit(orig_ifinfo->bat_iv.bcast_own, bit_pos); |
| 1545 | weight = &orig_ifinfo->bat_iv.bcast_own_sum; |
| 1546 | *weight = bitmap_weight(orig_ifinfo->bat_iv.bcast_own, |
| 1547 | BATADV_TQ_LOCAL_WINDOW_SIZE); |
| 1548 | spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock); |
| 1549 | |
| 1550 | batadv_orig_ifinfo_put(orig_ifinfo); |
| 1551 | } |
| 1552 | |
| 1553 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 1554 | * batadv_iv_ogm_process() - process an incoming batman iv OGM |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1555 | * @skb: the skb containing the OGM |
| 1556 | * @ogm_offset: offset to the OGM which should be processed (for aggregates) |
| 1557 | * @if_incoming: the interface where this packet was receved |
| 1558 | */ |
| 1559 | static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1560 | struct batadv_hard_iface *if_incoming) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1561 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1562 | struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1563 | struct batadv_orig_node *orig_neigh_node, *orig_node; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1564 | struct batadv_hard_iface *hard_iface; |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1565 | struct batadv_ogm_packet *ogm_packet; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 1566 | u32 if_incoming_seqno; |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1567 | bool has_directlink_flag; |
| 1568 | struct ethhdr *ethhdr; |
| 1569 | bool is_my_oldorig = false; |
| 1570 | bool is_my_addr = false; |
| 1571 | bool is_my_orig = false; |
| 1572 | |
| 1573 | ogm_packet = (struct batadv_ogm_packet *)(skb->data + ogm_offset); |
| 1574 | ethhdr = eth_hdr(skb); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1575 | |
| 1576 | /* Silently drop when the batman packet is actually not a |
| 1577 | * correct packet. |
| 1578 | * |
| 1579 | * This might happen if a packet is padded (e.g. Ethernet has a |
| 1580 | * minimum frame length of 64 byte) and the aggregation interprets |
| 1581 | * it as an additional length. |
| 1582 | * |
| 1583 | * TODO: A more sane solution would be to have a bit in the |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1584 | * batadv_ogm_packet to detect whether the packet is the last |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1585 | * packet in an aggregation. Here we expect that the padding |
| 1586 | * is always zero (or not 0x01) |
| 1587 | */ |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1588 | if (ogm_packet->packet_type != BATADV_IV_OGM) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1589 | return; |
| 1590 | |
| 1591 | /* could be changed by schedule_own_packet() */ |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 1592 | if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1593 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1594 | if (ogm_packet->flags & BATADV_DIRECTLINK) |
| 1595 | has_directlink_flag = true; |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 1596 | else |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1597 | has_directlink_flag = false; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1598 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1599 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 1600 | "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", |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1601 | ethhdr->h_source, if_incoming->net_dev->name, |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1602 | if_incoming->net_dev->dev_addr, ogm_packet->orig, |
| 1603 | ogm_packet->prev_sender, ntohl(ogm_packet->seqno), |
| 1604 | ogm_packet->tq, ogm_packet->ttl, |
| 1605 | ogm_packet->version, has_directlink_flag); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1606 | |
| 1607 | rcu_read_lock(); |
Sven Eckelmann | 3193e8f | 2012-05-12 02:09:42 +0200 | [diff] [blame] | 1608 | list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) { |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 1609 | if (hard_iface->if_status != BATADV_IF_ACTIVE) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1610 | continue; |
| 1611 | |
| 1612 | if (hard_iface->soft_iface != if_incoming->soft_iface) |
| 1613 | continue; |
| 1614 | |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1615 | if (batadv_compare_eth(ethhdr->h_source, |
| 1616 | hard_iface->net_dev->dev_addr)) |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1617 | is_my_addr = true; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1618 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1619 | if (batadv_compare_eth(ogm_packet->orig, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1620 | hard_iface->net_dev->dev_addr)) |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1621 | is_my_orig = true; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1622 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1623 | if (batadv_compare_eth(ogm_packet->prev_sender, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1624 | hard_iface->net_dev->dev_addr)) |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1625 | is_my_oldorig = true; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1626 | } |
| 1627 | rcu_read_unlock(); |
| 1628 | |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1629 | if (is_my_addr) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1630 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1631 | "Drop packet: received my own broadcast (sender: %pM)\n", |
| 1632 | ethhdr->h_source); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1633 | return; |
| 1634 | } |
| 1635 | |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1636 | if (is_my_orig) { |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 1637 | orig_neigh_node = batadv_iv_ogm_orig_get(bat_priv, |
| 1638 | ethhdr->h_source); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1639 | if (!orig_neigh_node) |
| 1640 | return; |
| 1641 | |
Sven Eckelmann | dee222c7 | 2018-08-16 16:54:45 +0200 | [diff] [blame] | 1642 | batadv_iv_ogm_process_reply(ogm_packet, if_incoming, |
| 1643 | orig_neigh_node, if_incoming_seqno); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1644 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1645 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1646 | "Drop packet: originator packet from myself (via neighbor)\n"); |
Sven Eckelmann | 5d96731 | 2016-01-17 11:01:09 +0100 | [diff] [blame] | 1647 | batadv_orig_node_put(orig_neigh_node); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1648 | return; |
| 1649 | } |
| 1650 | |
| 1651 | if (is_my_oldorig) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1652 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1653 | "Drop packet: ignoring all rebroadcast echos (sender: %pM)\n", |
| 1654 | ethhdr->h_source); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1655 | return; |
| 1656 | } |
| 1657 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1658 | if (ogm_packet->flags & BATADV_NOT_BEST_NEXT_HOP) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1659 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1660 | "Drop packet: ignoring all packets not forwarded from the best next hop (sender: %pM)\n", |
| 1661 | ethhdr->h_source); |
Marek Lindner | 13b2541 | 2012-03-11 06:17:53 +0800 | [diff] [blame] | 1662 | return; |
| 1663 | } |
| 1664 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1665 | orig_node = batadv_iv_ogm_orig_get(bat_priv, ogm_packet->orig); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1666 | if (!orig_node) |
| 1667 | return; |
| 1668 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1669 | batadv_iv_ogm_process_per_outif(skb, ogm_offset, orig_node, |
| 1670 | if_incoming, BATADV_IF_DEFAULT); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1671 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1672 | rcu_read_lock(); |
| 1673 | list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) { |
| 1674 | if (hard_iface->if_status != BATADV_IF_ACTIVE) |
| 1675 | continue; |
| 1676 | |
| 1677 | if (hard_iface->soft_iface != bat_priv->soft_iface) |
| 1678 | continue; |
| 1679 | |
Sven Eckelmann | 2735344 | 2016-03-05 16:09:16 +0100 | [diff] [blame] | 1680 | if (!kref_get_unless_zero(&hard_iface->refcount)) |
| 1681 | continue; |
| 1682 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1683 | batadv_iv_ogm_process_per_outif(skb, ogm_offset, orig_node, |
| 1684 | if_incoming, hard_iface); |
Sven Eckelmann | 2735344 | 2016-03-05 16:09:16 +0100 | [diff] [blame] | 1685 | |
| 1686 | batadv_hardif_put(hard_iface); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1687 | } |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1688 | rcu_read_unlock(); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1689 | |
Sven Eckelmann | 5d96731 | 2016-01-17 11:01:09 +0100 | [diff] [blame] | 1690 | batadv_orig_node_put(orig_node); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1691 | } |
| 1692 | |
Antonio Quartulli | f0d9725 | 2016-05-03 01:45:34 +0800 | [diff] [blame] | 1693 | static void batadv_iv_send_outstanding_bat_ogm_packet(struct work_struct *work) |
| 1694 | { |
| 1695 | struct delayed_work *delayed_work; |
| 1696 | struct batadv_forw_packet *forw_packet; |
| 1697 | struct batadv_priv *bat_priv; |
Sven Eckelmann | bd687fe | 2016-07-17 21:04:00 +0200 | [diff] [blame] | 1698 | bool dropped = false; |
Antonio Quartulli | f0d9725 | 2016-05-03 01:45:34 +0800 | [diff] [blame] | 1699 | |
| 1700 | delayed_work = to_delayed_work(work); |
| 1701 | forw_packet = container_of(delayed_work, struct batadv_forw_packet, |
| 1702 | delayed_work); |
| 1703 | bat_priv = netdev_priv(forw_packet->if_incoming->soft_iface); |
Antonio Quartulli | f0d9725 | 2016-05-03 01:45:34 +0800 | [diff] [blame] | 1704 | |
Sven Eckelmann | bd687fe | 2016-07-17 21:04:00 +0200 | [diff] [blame] | 1705 | if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_DEACTIVATING) { |
| 1706 | dropped = true; |
Antonio Quartulli | f0d9725 | 2016-05-03 01:45:34 +0800 | [diff] [blame] | 1707 | goto out; |
Sven Eckelmann | bd687fe | 2016-07-17 21:04:00 +0200 | [diff] [blame] | 1708 | } |
Antonio Quartulli | f0d9725 | 2016-05-03 01:45:34 +0800 | [diff] [blame] | 1709 | |
| 1710 | batadv_iv_ogm_emit(forw_packet); |
| 1711 | |
| 1712 | /* we have to have at least one packet in the queue to determine the |
| 1713 | * queues wake up time unless we are shutting down. |
| 1714 | * |
| 1715 | * only re-schedule if this is the "original" copy, e.g. the OGM of the |
| 1716 | * primary interface should only be rescheduled once per period, but |
| 1717 | * this function will be called for the forw_packet instances of the |
| 1718 | * other secondary interfaces as well. |
| 1719 | */ |
| 1720 | if (forw_packet->own && |
| 1721 | forw_packet->if_incoming == forw_packet->if_outgoing) |
| 1722 | batadv_iv_ogm_schedule(forw_packet->if_incoming); |
| 1723 | |
| 1724 | out: |
Linus LĂĽssing | 9b4aec6 | 2016-11-01 09:44:44 +0100 | [diff] [blame] | 1725 | /* do we get something for free()? */ |
| 1726 | if (batadv_forw_packet_steal(forw_packet, |
| 1727 | &bat_priv->forw_bat_list_lock)) |
| 1728 | batadv_forw_packet_free(forw_packet, dropped); |
Antonio Quartulli | f0d9725 | 2016-05-03 01:45:34 +0800 | [diff] [blame] | 1729 | } |
| 1730 | |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 1731 | static int batadv_iv_ogm_receive(struct sk_buff *skb, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1732 | struct batadv_hard_iface *if_incoming) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1733 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1734 | struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1735 | struct batadv_ogm_packet *ogm_packet; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 1736 | u8 *packet_pos; |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1737 | int ogm_offset; |
Sven Eckelmann | b91a254 | 2016-07-17 21:04:04 +0200 | [diff] [blame] | 1738 | bool res; |
| 1739 | int ret = NET_RX_DROP; |
Marek Lindner | c3e2931 | 2012-03-04 16:56:25 +0800 | [diff] [blame] | 1740 | |
Sven Eckelmann | b91a254 | 2016-07-17 21:04:04 +0200 | [diff] [blame] | 1741 | res = batadv_check_management_packet(skb, if_incoming, BATADV_OGM_HLEN); |
| 1742 | if (!res) |
| 1743 | goto free_skb; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1744 | |
Marek Lindner | edbf12b | 2012-03-11 06:17:49 +0800 | [diff] [blame] | 1745 | /* did we receive a B.A.T.M.A.N. IV OGM packet on an interface |
| 1746 | * that does not have B.A.T.M.A.N. IV enabled ? |
| 1747 | */ |
Antonio Quartulli | 29824a5 | 2016-05-25 23:27:31 +0800 | [diff] [blame] | 1748 | if (bat_priv->algo_ops->iface.enable != batadv_iv_ogm_iface_enable) |
Sven Eckelmann | b91a254 | 2016-07-17 21:04:04 +0200 | [diff] [blame] | 1749 | goto free_skb; |
Marek Lindner | edbf12b | 2012-03-11 06:17:49 +0800 | [diff] [blame] | 1750 | |
Sven Eckelmann | d69909d | 2012-06-03 22:19:20 +0200 | [diff] [blame] | 1751 | batadv_inc_counter(bat_priv, BATADV_CNT_MGMT_RX); |
| 1752 | batadv_add_counter(bat_priv, BATADV_CNT_MGMT_RX_BYTES, |
Martin Hundebøll | f821486 | 2012-04-20 17:02:45 +0200 | [diff] [blame] | 1753 | skb->len + ETH_HLEN); |
| 1754 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1755 | ogm_offset = 0; |
| 1756 | ogm_packet = (struct batadv_ogm_packet *)skb->data; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1757 | |
| 1758 | /* unpack the aggregated packets and process them one by one */ |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1759 | while (batadv_iv_ogm_aggr_packet(ogm_offset, skb_headlen(skb), |
Sven Eckelmann | a15d56a | 2019-08-22 08:55:36 +0200 | [diff] [blame] | 1760 | ogm_packet)) { |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1761 | batadv_iv_ogm_process(skb, ogm_offset, if_incoming); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1762 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1763 | ogm_offset += BATADV_OGM_HLEN; |
| 1764 | ogm_offset += ntohs(ogm_packet->tvlv_len); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1765 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1766 | packet_pos = skb->data + ogm_offset; |
| 1767 | ogm_packet = (struct batadv_ogm_packet *)packet_pos; |
Marek Lindner | b47506d | 2013-03-04 10:39:49 +0800 | [diff] [blame] | 1768 | } |
Marek Lindner | c3e2931 | 2012-03-04 16:56:25 +0800 | [diff] [blame] | 1769 | |
Sven Eckelmann | b91a254 | 2016-07-17 21:04:04 +0200 | [diff] [blame] | 1770 | ret = NET_RX_SUCCESS; |
| 1771 | |
| 1772 | free_skb: |
| 1773 | if (ret == NET_RX_SUCCESS) |
| 1774 | consume_skb(skb); |
| 1775 | else |
| 1776 | kfree_skb(skb); |
| 1777 | |
| 1778 | return ret; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1779 | } |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 1780 | |
Sven Eckelmann | dc1cbd1 | 2016-07-16 09:31:20 +0200 | [diff] [blame] | 1781 | #ifdef CONFIG_BATMAN_ADV_DEBUGFS |
Simon Wunderlich | 1b371d1 | 2014-01-15 21:17:54 +0100 | [diff] [blame] | 1782 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 1783 | * batadv_iv_ogm_orig_print_neigh() - print neighbors for the originator table |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1784 | * @orig_node: the orig_node for which the neighbors are printed |
| 1785 | * @if_outgoing: outgoing interface for these entries |
| 1786 | * @seq: debugfs table seq_file struct |
| 1787 | * |
| 1788 | * Must be called while holding an rcu lock. |
| 1789 | */ |
| 1790 | static void |
| 1791 | batadv_iv_ogm_orig_print_neigh(struct batadv_orig_node *orig_node, |
| 1792 | struct batadv_hard_iface *if_outgoing, |
| 1793 | struct seq_file *seq) |
| 1794 | { |
| 1795 | struct batadv_neigh_node *neigh_node; |
| 1796 | struct batadv_neigh_ifinfo *n_ifinfo; |
| 1797 | |
| 1798 | hlist_for_each_entry_rcu(neigh_node, &orig_node->neigh_list, list) { |
| 1799 | n_ifinfo = batadv_neigh_ifinfo_get(neigh_node, if_outgoing); |
| 1800 | if (!n_ifinfo) |
| 1801 | continue; |
| 1802 | |
| 1803 | seq_printf(seq, " %pM (%3i)", |
| 1804 | neigh_node->addr, |
| 1805 | n_ifinfo->bat_iv.tq_avg); |
| 1806 | |
Sven Eckelmann | 044fa3a | 2016-01-17 11:01:12 +0100 | [diff] [blame] | 1807 | batadv_neigh_ifinfo_put(n_ifinfo); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1808 | } |
| 1809 | } |
| 1810 | |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 1811 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 1812 | * batadv_iv_ogm_orig_print() - print the originator table |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 1813 | * @bat_priv: the bat priv with all the soft interface information |
| 1814 | * @seq: debugfs table seq_file struct |
Simon Wunderlich | cb1c92e | 2013-11-21 11:52:16 +0100 | [diff] [blame] | 1815 | * @if_outgoing: the outgoing interface for which this should be printed |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 1816 | */ |
| 1817 | static void batadv_iv_ogm_orig_print(struct batadv_priv *bat_priv, |
Simon Wunderlich | cb1c92e | 2013-11-21 11:52:16 +0100 | [diff] [blame] | 1818 | struct seq_file *seq, |
| 1819 | struct batadv_hard_iface *if_outgoing) |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 1820 | { |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1821 | struct batadv_neigh_node *neigh_node; |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 1822 | struct batadv_hashtable *hash = bat_priv->orig_hash; |
| 1823 | int last_seen_msecs, last_seen_secs; |
| 1824 | struct batadv_orig_node *orig_node; |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1825 | struct batadv_neigh_ifinfo *n_ifinfo; |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 1826 | unsigned long last_seen_jiffies; |
| 1827 | struct hlist_head *head; |
| 1828 | int batman_count = 0; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 1829 | u32 i; |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 1830 | |
Antonio Quartulli | 925a6f3 | 2016-03-12 10:30:18 +0100 | [diff] [blame] | 1831 | seq_puts(seq, |
| 1832 | " Originator last-seen (#/255) Nexthop [outgoingIF]: Potential nexthops ...\n"); |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 1833 | |
| 1834 | for (i = 0; i < hash->size; i++) { |
| 1835 | head = &hash->table[i]; |
| 1836 | |
| 1837 | rcu_read_lock(); |
| 1838 | hlist_for_each_entry_rcu(orig_node, head, hash_entry) { |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1839 | neigh_node = batadv_orig_router_get(orig_node, |
Simon Wunderlich | cb1c92e | 2013-11-21 11:52:16 +0100 | [diff] [blame] | 1840 | if_outgoing); |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 1841 | if (!neigh_node) |
| 1842 | continue; |
| 1843 | |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1844 | n_ifinfo = batadv_neigh_ifinfo_get(neigh_node, |
Simon Wunderlich | cb1c92e | 2013-11-21 11:52:16 +0100 | [diff] [blame] | 1845 | if_outgoing); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1846 | if (!n_ifinfo) |
| 1847 | goto next; |
| 1848 | |
| 1849 | if (n_ifinfo->bat_iv.tq_avg == 0) |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 1850 | goto next; |
| 1851 | |
| 1852 | last_seen_jiffies = jiffies - orig_node->last_seen; |
| 1853 | last_seen_msecs = jiffies_to_msecs(last_seen_jiffies); |
| 1854 | last_seen_secs = last_seen_msecs / 1000; |
| 1855 | last_seen_msecs = last_seen_msecs % 1000; |
| 1856 | |
| 1857 | seq_printf(seq, "%pM %4i.%03is (%3i) %pM [%10s]:", |
| 1858 | orig_node->orig, last_seen_secs, |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1859 | last_seen_msecs, n_ifinfo->bat_iv.tq_avg, |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 1860 | neigh_node->addr, |
| 1861 | neigh_node->if_incoming->net_dev->name); |
| 1862 | |
Simon Wunderlich | cb1c92e | 2013-11-21 11:52:16 +0100 | [diff] [blame] | 1863 | batadv_iv_ogm_orig_print_neigh(orig_node, if_outgoing, |
| 1864 | seq); |
Markus Elfring | 626caae | 2017-05-06 17:50:13 +0200 | [diff] [blame] | 1865 | seq_putc(seq, '\n'); |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 1866 | batman_count++; |
| 1867 | |
| 1868 | next: |
Sven Eckelmann | 25bb250 | 2016-01-17 11:01:11 +0100 | [diff] [blame] | 1869 | batadv_neigh_node_put(neigh_node); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1870 | if (n_ifinfo) |
Sven Eckelmann | 044fa3a | 2016-01-17 11:01:12 +0100 | [diff] [blame] | 1871 | batadv_neigh_ifinfo_put(n_ifinfo); |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 1872 | } |
| 1873 | rcu_read_unlock(); |
| 1874 | } |
| 1875 | |
| 1876 | if (batman_count == 0) |
| 1877 | seq_puts(seq, "No batman nodes in range ...\n"); |
| 1878 | } |
Sven Eckelmann | dc1cbd1 | 2016-07-16 09:31:20 +0200 | [diff] [blame] | 1879 | #endif |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 1880 | |
Antonio Quartulli | a3285a8 | 2013-09-02 12:15:04 +0200 | [diff] [blame] | 1881 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 1882 | * batadv_iv_ogm_neigh_get_tq_avg() - Get the TQ average for a neighbour on a |
Matthias Schiffer | 024f99c | 2016-07-03 13:31:40 +0200 | [diff] [blame] | 1883 | * given outgoing interface. |
| 1884 | * @neigh_node: Neighbour of interest |
| 1885 | * @if_outgoing: Outgoing interface of interest |
| 1886 | * @tq_avg: Pointer of where to store the TQ average |
| 1887 | * |
| 1888 | * Return: False if no average TQ available, otherwise true. |
| 1889 | */ |
| 1890 | static bool |
| 1891 | batadv_iv_ogm_neigh_get_tq_avg(struct batadv_neigh_node *neigh_node, |
| 1892 | struct batadv_hard_iface *if_outgoing, |
| 1893 | u8 *tq_avg) |
| 1894 | { |
| 1895 | struct batadv_neigh_ifinfo *n_ifinfo; |
| 1896 | |
| 1897 | n_ifinfo = batadv_neigh_ifinfo_get(neigh_node, if_outgoing); |
| 1898 | if (!n_ifinfo) |
| 1899 | return false; |
| 1900 | |
| 1901 | *tq_avg = n_ifinfo->bat_iv.tq_avg; |
| 1902 | batadv_neigh_ifinfo_put(n_ifinfo); |
| 1903 | |
| 1904 | return true; |
| 1905 | } |
| 1906 | |
| 1907 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 1908 | * batadv_iv_ogm_orig_dump_subentry() - Dump an originator subentry into a |
Matthias Schiffer | 024f99c | 2016-07-03 13:31:40 +0200 | [diff] [blame] | 1909 | * message |
| 1910 | * @msg: Netlink message to dump into |
| 1911 | * @portid: Port making netlink request |
| 1912 | * @seq: Sequence number of netlink message |
| 1913 | * @bat_priv: The bat priv with all the soft interface information |
| 1914 | * @if_outgoing: Limit dump to entries with this outgoing interface |
| 1915 | * @orig_node: Originator to dump |
| 1916 | * @neigh_node: Single hops neighbour |
| 1917 | * @best: Is the best originator |
| 1918 | * |
| 1919 | * Return: Error code, or 0 on success |
| 1920 | */ |
| 1921 | static int |
| 1922 | batadv_iv_ogm_orig_dump_subentry(struct sk_buff *msg, u32 portid, u32 seq, |
| 1923 | struct batadv_priv *bat_priv, |
| 1924 | struct batadv_hard_iface *if_outgoing, |
| 1925 | struct batadv_orig_node *orig_node, |
| 1926 | struct batadv_neigh_node *neigh_node, |
| 1927 | bool best) |
| 1928 | { |
| 1929 | void *hdr; |
| 1930 | u8 tq_avg; |
| 1931 | unsigned int last_seen_msecs; |
| 1932 | |
| 1933 | last_seen_msecs = jiffies_to_msecs(jiffies - orig_node->last_seen); |
| 1934 | |
| 1935 | if (!batadv_iv_ogm_neigh_get_tq_avg(neigh_node, if_outgoing, &tq_avg)) |
| 1936 | return 0; |
| 1937 | |
| 1938 | if (if_outgoing != BATADV_IF_DEFAULT && |
| 1939 | if_outgoing != neigh_node->if_incoming) |
| 1940 | return 0; |
| 1941 | |
| 1942 | hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, |
| 1943 | NLM_F_MULTI, BATADV_CMD_GET_ORIGINATORS); |
| 1944 | if (!hdr) |
| 1945 | return -ENOBUFS; |
| 1946 | |
| 1947 | if (nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN, |
| 1948 | orig_node->orig) || |
| 1949 | nla_put(msg, BATADV_ATTR_NEIGH_ADDRESS, ETH_ALEN, |
| 1950 | neigh_node->addr) || |
| 1951 | nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, |
| 1952 | neigh_node->if_incoming->net_dev->ifindex) || |
| 1953 | nla_put_u8(msg, BATADV_ATTR_TQ, tq_avg) || |
| 1954 | nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS, |
| 1955 | last_seen_msecs)) |
| 1956 | goto nla_put_failure; |
| 1957 | |
| 1958 | if (best && nla_put_flag(msg, BATADV_ATTR_FLAG_BEST)) |
| 1959 | goto nla_put_failure; |
| 1960 | |
| 1961 | genlmsg_end(msg, hdr); |
| 1962 | return 0; |
| 1963 | |
| 1964 | nla_put_failure: |
| 1965 | genlmsg_cancel(msg, hdr); |
| 1966 | return -EMSGSIZE; |
| 1967 | } |
| 1968 | |
| 1969 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 1970 | * batadv_iv_ogm_orig_dump_entry() - Dump an originator entry into a message |
Matthias Schiffer | 024f99c | 2016-07-03 13:31:40 +0200 | [diff] [blame] | 1971 | * @msg: Netlink message to dump into |
| 1972 | * @portid: Port making netlink request |
| 1973 | * @seq: Sequence number of netlink message |
| 1974 | * @bat_priv: The bat priv with all the soft interface information |
| 1975 | * @if_outgoing: Limit dump to entries with this outgoing interface |
| 1976 | * @orig_node: Originator to dump |
| 1977 | * @sub_s: Number of sub entries to skip |
| 1978 | * |
| 1979 | * This function assumes the caller holds rcu_read_lock(). |
| 1980 | * |
| 1981 | * Return: Error code, or 0 on success |
| 1982 | */ |
| 1983 | static int |
| 1984 | batadv_iv_ogm_orig_dump_entry(struct sk_buff *msg, u32 portid, u32 seq, |
| 1985 | struct batadv_priv *bat_priv, |
| 1986 | struct batadv_hard_iface *if_outgoing, |
| 1987 | struct batadv_orig_node *orig_node, int *sub_s) |
| 1988 | { |
| 1989 | struct batadv_neigh_node *neigh_node_best; |
| 1990 | struct batadv_neigh_node *neigh_node; |
| 1991 | int sub = 0; |
| 1992 | bool best; |
| 1993 | u8 tq_avg_best; |
| 1994 | |
| 1995 | neigh_node_best = batadv_orig_router_get(orig_node, if_outgoing); |
| 1996 | if (!neigh_node_best) |
| 1997 | goto out; |
| 1998 | |
| 1999 | if (!batadv_iv_ogm_neigh_get_tq_avg(neigh_node_best, if_outgoing, |
| 2000 | &tq_avg_best)) |
| 2001 | goto out; |
| 2002 | |
| 2003 | if (tq_avg_best == 0) |
| 2004 | goto out; |
| 2005 | |
| 2006 | hlist_for_each_entry_rcu(neigh_node, &orig_node->neigh_list, list) { |
| 2007 | if (sub++ < *sub_s) |
| 2008 | continue; |
| 2009 | |
| 2010 | best = (neigh_node == neigh_node_best); |
| 2011 | |
| 2012 | if (batadv_iv_ogm_orig_dump_subentry(msg, portid, seq, |
| 2013 | bat_priv, if_outgoing, |
| 2014 | orig_node, neigh_node, |
| 2015 | best)) { |
| 2016 | batadv_neigh_node_put(neigh_node_best); |
| 2017 | |
| 2018 | *sub_s = sub - 1; |
| 2019 | return -EMSGSIZE; |
| 2020 | } |
| 2021 | } |
| 2022 | |
| 2023 | out: |
| 2024 | if (neigh_node_best) |
| 2025 | batadv_neigh_node_put(neigh_node_best); |
| 2026 | |
| 2027 | *sub_s = 0; |
| 2028 | return 0; |
| 2029 | } |
| 2030 | |
| 2031 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 2032 | * batadv_iv_ogm_orig_dump_bucket() - Dump an originator bucket into a |
Matthias Schiffer | 024f99c | 2016-07-03 13:31:40 +0200 | [diff] [blame] | 2033 | * message |
| 2034 | * @msg: Netlink message to dump into |
| 2035 | * @portid: Port making netlink request |
| 2036 | * @seq: Sequence number of netlink message |
| 2037 | * @bat_priv: The bat priv with all the soft interface information |
| 2038 | * @if_outgoing: Limit dump to entries with this outgoing interface |
| 2039 | * @head: Bucket to be dumped |
| 2040 | * @idx_s: Number of entries to be skipped |
| 2041 | * @sub: Number of sub entries to be skipped |
| 2042 | * |
| 2043 | * Return: Error code, or 0 on success |
| 2044 | */ |
| 2045 | static int |
| 2046 | batadv_iv_ogm_orig_dump_bucket(struct sk_buff *msg, u32 portid, u32 seq, |
| 2047 | struct batadv_priv *bat_priv, |
| 2048 | struct batadv_hard_iface *if_outgoing, |
| 2049 | struct hlist_head *head, int *idx_s, int *sub) |
| 2050 | { |
| 2051 | struct batadv_orig_node *orig_node; |
| 2052 | int idx = 0; |
| 2053 | |
| 2054 | rcu_read_lock(); |
| 2055 | hlist_for_each_entry_rcu(orig_node, head, hash_entry) { |
| 2056 | if (idx++ < *idx_s) |
| 2057 | continue; |
| 2058 | |
| 2059 | if (batadv_iv_ogm_orig_dump_entry(msg, portid, seq, bat_priv, |
| 2060 | if_outgoing, orig_node, |
| 2061 | sub)) { |
| 2062 | rcu_read_unlock(); |
| 2063 | *idx_s = idx - 1; |
| 2064 | return -EMSGSIZE; |
| 2065 | } |
| 2066 | } |
| 2067 | rcu_read_unlock(); |
| 2068 | |
| 2069 | *idx_s = 0; |
| 2070 | *sub = 0; |
| 2071 | return 0; |
| 2072 | } |
| 2073 | |
| 2074 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 2075 | * batadv_iv_ogm_orig_dump() - Dump the originators into a message |
Matthias Schiffer | 024f99c | 2016-07-03 13:31:40 +0200 | [diff] [blame] | 2076 | * @msg: Netlink message to dump into |
| 2077 | * @cb: Control block containing additional options |
| 2078 | * @bat_priv: The bat priv with all the soft interface information |
| 2079 | * @if_outgoing: Limit dump to entries with this outgoing interface |
| 2080 | */ |
| 2081 | static void |
| 2082 | batadv_iv_ogm_orig_dump(struct sk_buff *msg, struct netlink_callback *cb, |
| 2083 | struct batadv_priv *bat_priv, |
| 2084 | struct batadv_hard_iface *if_outgoing) |
| 2085 | { |
| 2086 | struct batadv_hashtable *hash = bat_priv->orig_hash; |
| 2087 | struct hlist_head *head; |
| 2088 | int bucket = cb->args[0]; |
| 2089 | int idx = cb->args[1]; |
| 2090 | int sub = cb->args[2]; |
| 2091 | int portid = NETLINK_CB(cb->skb).portid; |
| 2092 | |
| 2093 | while (bucket < hash->size) { |
| 2094 | head = &hash->table[bucket]; |
| 2095 | |
| 2096 | if (batadv_iv_ogm_orig_dump_bucket(msg, portid, |
| 2097 | cb->nlh->nlmsg_seq, |
| 2098 | bat_priv, if_outgoing, head, |
| 2099 | &idx, &sub)) |
| 2100 | break; |
| 2101 | |
| 2102 | bucket++; |
| 2103 | } |
| 2104 | |
| 2105 | cb->args[0] = bucket; |
| 2106 | cb->args[1] = idx; |
| 2107 | cb->args[2] = sub; |
| 2108 | } |
| 2109 | |
Sven Eckelmann | dc1cbd1 | 2016-07-16 09:31:20 +0200 | [diff] [blame] | 2110 | #ifdef CONFIG_BATMAN_ADV_DEBUGFS |
Matthias Schiffer | 024f99c | 2016-07-03 13:31:40 +0200 | [diff] [blame] | 2111 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 2112 | * batadv_iv_hardif_neigh_print() - print a single hop neighbour node |
Marek Lindner | 7587405 | 2015-08-04 21:09:57 +0800 | [diff] [blame] | 2113 | * @seq: neighbour table seq_file struct |
| 2114 | * @hardif_neigh: hardif neighbour information |
| 2115 | */ |
| 2116 | static void |
| 2117 | batadv_iv_hardif_neigh_print(struct seq_file *seq, |
| 2118 | struct batadv_hardif_neigh_node *hardif_neigh) |
| 2119 | { |
| 2120 | int last_secs, last_msecs; |
| 2121 | |
| 2122 | last_secs = jiffies_to_msecs(jiffies - hardif_neigh->last_seen) / 1000; |
| 2123 | last_msecs = jiffies_to_msecs(jiffies - hardif_neigh->last_seen) % 1000; |
| 2124 | |
| 2125 | seq_printf(seq, " %10s %pM %4i.%03is\n", |
| 2126 | hardif_neigh->if_incoming->net_dev->name, |
| 2127 | hardif_neigh->addr, last_secs, last_msecs); |
| 2128 | } |
| 2129 | |
| 2130 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 2131 | * batadv_iv_ogm_neigh_print() - print the single hop neighbour list |
Marek Lindner | 7587405 | 2015-08-04 21:09:57 +0800 | [diff] [blame] | 2132 | * @bat_priv: the bat priv with all the soft interface information |
| 2133 | * @seq: neighbour table seq_file struct |
| 2134 | */ |
| 2135 | static void batadv_iv_neigh_print(struct batadv_priv *bat_priv, |
| 2136 | struct seq_file *seq) |
| 2137 | { |
| 2138 | struct net_device *net_dev = (struct net_device *)seq->private; |
| 2139 | struct batadv_hardif_neigh_node *hardif_neigh; |
| 2140 | struct batadv_hard_iface *hard_iface; |
| 2141 | int batman_count = 0; |
| 2142 | |
Antonio Quartulli | 925a6f3 | 2016-03-12 10:30:18 +0100 | [diff] [blame] | 2143 | seq_puts(seq, " IF Neighbor last-seen\n"); |
Marek Lindner | 7587405 | 2015-08-04 21:09:57 +0800 | [diff] [blame] | 2144 | |
| 2145 | rcu_read_lock(); |
| 2146 | list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) { |
| 2147 | if (hard_iface->soft_iface != net_dev) |
| 2148 | continue; |
| 2149 | |
| 2150 | hlist_for_each_entry_rcu(hardif_neigh, |
| 2151 | &hard_iface->neigh_list, list) { |
| 2152 | batadv_iv_hardif_neigh_print(seq, hardif_neigh); |
| 2153 | batman_count++; |
| 2154 | } |
| 2155 | } |
| 2156 | rcu_read_unlock(); |
| 2157 | |
| 2158 | if (batman_count == 0) |
| 2159 | seq_puts(seq, "No batman nodes in range ...\n"); |
| 2160 | } |
Sven Eckelmann | dc1cbd1 | 2016-07-16 09:31:20 +0200 | [diff] [blame] | 2161 | #endif |
Marek Lindner | 7587405 | 2015-08-04 21:09:57 +0800 | [diff] [blame] | 2162 | |
| 2163 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 2164 | * batadv_iv_ogm_neigh_diff() - calculate tq difference of two neighbors |
Markus Pargmann | 57b1250 | 2016-07-03 11:07:14 +0200 | [diff] [blame] | 2165 | * @neigh1: the first neighbor object of the comparison |
| 2166 | * @if_outgoing1: outgoing interface for the first neighbor |
| 2167 | * @neigh2: the second neighbor object of the comparison |
| 2168 | * @if_outgoing2: outgoing interface for the second neighbor |
| 2169 | * @diff: pointer to integer receiving the calculated difference |
| 2170 | * |
| 2171 | * The content of *@diff is only valid when this function returns true. |
| 2172 | * It is less, equal to or greater than 0 if the metric via neigh1 is lower, |
| 2173 | * the same as or higher than the metric via neigh2 |
| 2174 | * |
| 2175 | * Return: true when the difference could be calculated, false otherwise |
| 2176 | */ |
| 2177 | static bool batadv_iv_ogm_neigh_diff(struct batadv_neigh_node *neigh1, |
| 2178 | struct batadv_hard_iface *if_outgoing1, |
| 2179 | struct batadv_neigh_node *neigh2, |
| 2180 | struct batadv_hard_iface *if_outgoing2, |
| 2181 | int *diff) |
| 2182 | { |
| 2183 | struct batadv_neigh_ifinfo *neigh1_ifinfo, *neigh2_ifinfo; |
| 2184 | u8 tq1, tq2; |
| 2185 | bool ret = true; |
| 2186 | |
| 2187 | neigh1_ifinfo = batadv_neigh_ifinfo_get(neigh1, if_outgoing1); |
| 2188 | neigh2_ifinfo = batadv_neigh_ifinfo_get(neigh2, if_outgoing2); |
| 2189 | |
| 2190 | if (!neigh1_ifinfo || !neigh2_ifinfo) { |
| 2191 | ret = false; |
| 2192 | goto out; |
| 2193 | } |
| 2194 | |
| 2195 | tq1 = neigh1_ifinfo->bat_iv.tq_avg; |
| 2196 | tq2 = neigh2_ifinfo->bat_iv.tq_avg; |
| 2197 | *diff = (int)tq1 - (int)tq2; |
| 2198 | |
| 2199 | out: |
| 2200 | if (neigh1_ifinfo) |
| 2201 | batadv_neigh_ifinfo_put(neigh1_ifinfo); |
| 2202 | if (neigh2_ifinfo) |
| 2203 | batadv_neigh_ifinfo_put(neigh2_ifinfo); |
| 2204 | |
| 2205 | return ret; |
| 2206 | } |
| 2207 | |
| 2208 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 2209 | * batadv_iv_ogm_neigh_dump_neigh() - Dump a neighbour into a netlink message |
Matthias Schiffer | 024f99c | 2016-07-03 13:31:40 +0200 | [diff] [blame] | 2210 | * @msg: Netlink message to dump into |
| 2211 | * @portid: Port making netlink request |
| 2212 | * @seq: Sequence number of netlink message |
| 2213 | * @hardif_neigh: Neighbour to be dumped |
| 2214 | * |
| 2215 | * Return: Error code, or 0 on success |
| 2216 | */ |
| 2217 | static int |
| 2218 | batadv_iv_ogm_neigh_dump_neigh(struct sk_buff *msg, u32 portid, u32 seq, |
| 2219 | struct batadv_hardif_neigh_node *hardif_neigh) |
| 2220 | { |
| 2221 | void *hdr; |
| 2222 | unsigned int last_seen_msecs; |
| 2223 | |
| 2224 | last_seen_msecs = jiffies_to_msecs(jiffies - hardif_neigh->last_seen); |
| 2225 | |
| 2226 | hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, |
| 2227 | NLM_F_MULTI, BATADV_CMD_GET_NEIGHBORS); |
| 2228 | if (!hdr) |
| 2229 | return -ENOBUFS; |
| 2230 | |
| 2231 | if (nla_put(msg, BATADV_ATTR_NEIGH_ADDRESS, ETH_ALEN, |
| 2232 | hardif_neigh->addr) || |
| 2233 | nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, |
| 2234 | hardif_neigh->if_incoming->net_dev->ifindex) || |
| 2235 | nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS, |
| 2236 | last_seen_msecs)) |
| 2237 | goto nla_put_failure; |
| 2238 | |
| 2239 | genlmsg_end(msg, hdr); |
| 2240 | return 0; |
| 2241 | |
| 2242 | nla_put_failure: |
| 2243 | genlmsg_cancel(msg, hdr); |
| 2244 | return -EMSGSIZE; |
| 2245 | } |
| 2246 | |
| 2247 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 2248 | * batadv_iv_ogm_neigh_dump_hardif() - Dump the neighbours of a hard interface |
Matthias Schiffer | 024f99c | 2016-07-03 13:31:40 +0200 | [diff] [blame] | 2249 | * into a message |
| 2250 | * @msg: Netlink message to dump into |
| 2251 | * @portid: Port making netlink request |
| 2252 | * @seq: Sequence number of netlink message |
| 2253 | * @bat_priv: The bat priv with all the soft interface information |
| 2254 | * @hard_iface: Hard interface to dump the neighbours for |
| 2255 | * @idx_s: Number of entries to skip |
| 2256 | * |
| 2257 | * This function assumes the caller holds rcu_read_lock(). |
| 2258 | * |
| 2259 | * Return: Error code, or 0 on success |
| 2260 | */ |
| 2261 | static int |
| 2262 | batadv_iv_ogm_neigh_dump_hardif(struct sk_buff *msg, u32 portid, u32 seq, |
| 2263 | struct batadv_priv *bat_priv, |
| 2264 | struct batadv_hard_iface *hard_iface, |
| 2265 | int *idx_s) |
| 2266 | { |
| 2267 | struct batadv_hardif_neigh_node *hardif_neigh; |
| 2268 | int idx = 0; |
| 2269 | |
| 2270 | hlist_for_each_entry_rcu(hardif_neigh, |
| 2271 | &hard_iface->neigh_list, list) { |
| 2272 | if (idx++ < *idx_s) |
| 2273 | continue; |
| 2274 | |
| 2275 | if (batadv_iv_ogm_neigh_dump_neigh(msg, portid, seq, |
| 2276 | hardif_neigh)) { |
| 2277 | *idx_s = idx - 1; |
| 2278 | return -EMSGSIZE; |
| 2279 | } |
| 2280 | } |
| 2281 | |
| 2282 | *idx_s = 0; |
| 2283 | return 0; |
| 2284 | } |
| 2285 | |
| 2286 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 2287 | * batadv_iv_ogm_neigh_dump() - Dump the neighbours into a message |
Matthias Schiffer | 024f99c | 2016-07-03 13:31:40 +0200 | [diff] [blame] | 2288 | * @msg: Netlink message to dump into |
| 2289 | * @cb: Control block containing additional options |
| 2290 | * @bat_priv: The bat priv with all the soft interface information |
| 2291 | * @single_hardif: Limit dump to this hard interfaace |
| 2292 | */ |
| 2293 | static void |
| 2294 | batadv_iv_ogm_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb, |
| 2295 | struct batadv_priv *bat_priv, |
| 2296 | struct batadv_hard_iface *single_hardif) |
| 2297 | { |
| 2298 | struct batadv_hard_iface *hard_iface; |
| 2299 | int i_hardif = 0; |
| 2300 | int i_hardif_s = cb->args[0]; |
| 2301 | int idx = cb->args[1]; |
| 2302 | int portid = NETLINK_CB(cb->skb).portid; |
| 2303 | |
| 2304 | rcu_read_lock(); |
| 2305 | if (single_hardif) { |
| 2306 | if (i_hardif_s == 0) { |
| 2307 | if (batadv_iv_ogm_neigh_dump_hardif(msg, portid, |
| 2308 | cb->nlh->nlmsg_seq, |
| 2309 | bat_priv, |
| 2310 | single_hardif, |
| 2311 | &idx) == 0) |
| 2312 | i_hardif++; |
| 2313 | } |
| 2314 | } else { |
| 2315 | list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, |
| 2316 | list) { |
| 2317 | if (hard_iface->soft_iface != bat_priv->soft_iface) |
| 2318 | continue; |
| 2319 | |
| 2320 | if (i_hardif++ < i_hardif_s) |
| 2321 | continue; |
| 2322 | |
| 2323 | if (batadv_iv_ogm_neigh_dump_hardif(msg, portid, |
| 2324 | cb->nlh->nlmsg_seq, |
| 2325 | bat_priv, |
| 2326 | hard_iface, &idx)) { |
| 2327 | i_hardif--; |
| 2328 | break; |
| 2329 | } |
| 2330 | } |
| 2331 | } |
| 2332 | rcu_read_unlock(); |
| 2333 | |
| 2334 | cb->args[0] = i_hardif; |
| 2335 | cb->args[1] = idx; |
| 2336 | } |
| 2337 | |
| 2338 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 2339 | * batadv_iv_ogm_neigh_cmp() - compare the metrics of two neighbors |
Antonio Quartulli | a3285a8 | 2013-09-02 12:15:04 +0200 | [diff] [blame] | 2340 | * @neigh1: the first neighbor object of the comparison |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 2341 | * @if_outgoing1: outgoing interface for the first neighbor |
Antonio Quartulli | a3285a8 | 2013-09-02 12:15:04 +0200 | [diff] [blame] | 2342 | * @neigh2: the second neighbor object of the comparison |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 2343 | * @if_outgoing2: outgoing interface for the second neighbor |
Antonio Quartulli | a3285a8 | 2013-09-02 12:15:04 +0200 | [diff] [blame] | 2344 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 2345 | * Return: a value less, equal to or greater than 0 if the metric via neigh1 is |
Antonio Quartulli | a3285a8 | 2013-09-02 12:15:04 +0200 | [diff] [blame] | 2346 | * lower, the same as or higher than the metric via neigh2 |
| 2347 | */ |
| 2348 | static int batadv_iv_ogm_neigh_cmp(struct batadv_neigh_node *neigh1, |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 2349 | struct batadv_hard_iface *if_outgoing1, |
| 2350 | struct batadv_neigh_node *neigh2, |
| 2351 | struct batadv_hard_iface *if_outgoing2) |
Antonio Quartulli | a3285a8 | 2013-09-02 12:15:04 +0200 | [diff] [blame] | 2352 | { |
Markus Pargmann | 57b1250 | 2016-07-03 11:07:14 +0200 | [diff] [blame] | 2353 | bool ret; |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 2354 | int diff; |
Antonio Quartulli | a3285a8 | 2013-09-02 12:15:04 +0200 | [diff] [blame] | 2355 | |
Markus Pargmann | 57b1250 | 2016-07-03 11:07:14 +0200 | [diff] [blame] | 2356 | ret = batadv_iv_ogm_neigh_diff(neigh1, if_outgoing1, neigh2, |
| 2357 | if_outgoing2, &diff); |
| 2358 | if (!ret) |
| 2359 | return 0; |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 2360 | |
| 2361 | return diff; |
Antonio Quartulli | a3285a8 | 2013-09-02 12:15:04 +0200 | [diff] [blame] | 2362 | } |
| 2363 | |
Antonio Quartulli | c43c981 | 2013-09-02 12:15:05 +0200 | [diff] [blame] | 2364 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 2365 | * batadv_iv_ogm_neigh_is_sob() - check if neigh1 is similarly good or better |
Simon Wunderlich | 18165f6 | 2015-08-08 02:01:50 +0200 | [diff] [blame] | 2366 | * than neigh2 from the metric prospective |
Antonio Quartulli | c43c981 | 2013-09-02 12:15:05 +0200 | [diff] [blame] | 2367 | * @neigh1: the first neighbor object of the comparison |
Martin Hundebøll | 95298a9 | 2014-07-15 09:41:05 +0200 | [diff] [blame] | 2368 | * @if_outgoing1: outgoing interface for the first neighbor |
Antonio Quartulli | c43c981 | 2013-09-02 12:15:05 +0200 | [diff] [blame] | 2369 | * @neigh2: the second neighbor object of the comparison |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 2370 | * @if_outgoing2: outgoing interface for the second neighbor |
Martin Hundebøll | 95298a9 | 2014-07-15 09:41:05 +0200 | [diff] [blame] | 2371 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 2372 | * Return: true if the metric via neigh1 is equally good or better than |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 2373 | * the metric via neigh2, false otherwise. |
| 2374 | */ |
| 2375 | static bool |
Simon Wunderlich | 18165f6 | 2015-08-08 02:01:50 +0200 | [diff] [blame] | 2376 | batadv_iv_ogm_neigh_is_sob(struct batadv_neigh_node *neigh1, |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 2377 | struct batadv_hard_iface *if_outgoing1, |
| 2378 | struct batadv_neigh_node *neigh2, |
| 2379 | struct batadv_hard_iface *if_outgoing2) |
| 2380 | { |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 2381 | bool ret; |
Markus Pargmann | 57b1250 | 2016-07-03 11:07:14 +0200 | [diff] [blame] | 2382 | int diff; |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 2383 | |
Markus Pargmann | 57b1250 | 2016-07-03 11:07:14 +0200 | [diff] [blame] | 2384 | ret = batadv_iv_ogm_neigh_diff(neigh1, if_outgoing1, neigh2, |
| 2385 | if_outgoing2, &diff); |
| 2386 | if (!ret) |
| 2387 | return false; |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 2388 | |
Markus Pargmann | 57b1250 | 2016-07-03 11:07:14 +0200 | [diff] [blame] | 2389 | ret = diff > -BATADV_TQ_SIMILARITY_THRESHOLD; |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 2390 | return ret; |
Antonio Quartulli | c43c981 | 2013-09-02 12:15:05 +0200 | [diff] [blame] | 2391 | } |
| 2392 | |
Sven Eckelmann | 9e6b564 | 2019-06-02 10:57:31 +0200 | [diff] [blame] | 2393 | static void batadv_iv_iface_enabled(struct batadv_hard_iface *hard_iface) |
Antonio Quartulli | f0d9725 | 2016-05-03 01:45:34 +0800 | [diff] [blame] | 2394 | { |
| 2395 | /* begin scheduling originator messages on that interface */ |
| 2396 | batadv_iv_ogm_schedule(hard_iface); |
| 2397 | } |
| 2398 | |
Sven Eckelmann | 1a9070e | 2017-03-04 15:48:50 +0100 | [diff] [blame] | 2399 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 2400 | * batadv_iv_init_sel_class() - initialize GW selection class |
Sven Eckelmann | 1a9070e | 2017-03-04 15:48:50 +0100 | [diff] [blame] | 2401 | * @bat_priv: the bat priv with all the soft interface information |
| 2402 | */ |
| 2403 | static void batadv_iv_init_sel_class(struct batadv_priv *bat_priv) |
| 2404 | { |
| 2405 | /* set default TQ difference threshold to 20 */ |
| 2406 | atomic_set(&bat_priv->gw.sel_class, 20); |
| 2407 | } |
| 2408 | |
Antonio Quartulli | 34d99cf | 2016-07-03 12:46:33 +0200 | [diff] [blame] | 2409 | static struct batadv_gw_node * |
| 2410 | batadv_iv_gw_get_best_gw_node(struct batadv_priv *bat_priv) |
| 2411 | { |
| 2412 | struct batadv_neigh_node *router; |
| 2413 | struct batadv_neigh_ifinfo *router_ifinfo; |
| 2414 | struct batadv_gw_node *gw_node, *curr_gw = NULL; |
| 2415 | u64 max_gw_factor = 0; |
| 2416 | u64 tmp_gw_factor = 0; |
| 2417 | u8 max_tq = 0; |
| 2418 | u8 tq_avg; |
| 2419 | struct batadv_orig_node *orig_node; |
| 2420 | |
| 2421 | rcu_read_lock(); |
Sven Eckelmann | 70ea5ce | 2016-07-27 12:31:08 +0200 | [diff] [blame] | 2422 | hlist_for_each_entry_rcu(gw_node, &bat_priv->gw.gateway_list, list) { |
Antonio Quartulli | 34d99cf | 2016-07-03 12:46:33 +0200 | [diff] [blame] | 2423 | orig_node = gw_node->orig_node; |
| 2424 | router = batadv_orig_router_get(orig_node, BATADV_IF_DEFAULT); |
| 2425 | if (!router) |
| 2426 | continue; |
| 2427 | |
| 2428 | router_ifinfo = batadv_neigh_ifinfo_get(router, |
| 2429 | BATADV_IF_DEFAULT); |
| 2430 | if (!router_ifinfo) |
| 2431 | goto next; |
| 2432 | |
| 2433 | if (!kref_get_unless_zero(&gw_node->refcount)) |
| 2434 | goto next; |
| 2435 | |
| 2436 | tq_avg = router_ifinfo->bat_iv.tq_avg; |
| 2437 | |
| 2438 | switch (atomic_read(&bat_priv->gw.sel_class)) { |
| 2439 | case 1: /* fast connection */ |
| 2440 | tmp_gw_factor = tq_avg * tq_avg; |
| 2441 | tmp_gw_factor *= gw_node->bandwidth_down; |
| 2442 | tmp_gw_factor *= 100 * 100; |
| 2443 | tmp_gw_factor >>= 18; |
| 2444 | |
Sven Eckelmann | 825ffe1 | 2017-08-23 21:52:13 +0200 | [diff] [blame] | 2445 | if (tmp_gw_factor > max_gw_factor || |
| 2446 | (tmp_gw_factor == max_gw_factor && |
| 2447 | tq_avg > max_tq)) { |
Antonio Quartulli | 34d99cf | 2016-07-03 12:46:33 +0200 | [diff] [blame] | 2448 | if (curr_gw) |
| 2449 | batadv_gw_node_put(curr_gw); |
| 2450 | curr_gw = gw_node; |
| 2451 | kref_get(&curr_gw->refcount); |
| 2452 | } |
| 2453 | break; |
| 2454 | |
| 2455 | default: /* 2: stable connection (use best statistic) |
| 2456 | * 3: fast-switch (use best statistic but change as |
| 2457 | * soon as a better gateway appears) |
| 2458 | * XX: late-switch (use best statistic but change as |
| 2459 | * soon as a better gateway appears which has |
| 2460 | * $routing_class more tq points) |
| 2461 | */ |
| 2462 | if (tq_avg > max_tq) { |
| 2463 | if (curr_gw) |
| 2464 | batadv_gw_node_put(curr_gw); |
| 2465 | curr_gw = gw_node; |
| 2466 | kref_get(&curr_gw->refcount); |
| 2467 | } |
| 2468 | break; |
| 2469 | } |
| 2470 | |
| 2471 | if (tq_avg > max_tq) |
| 2472 | max_tq = tq_avg; |
| 2473 | |
| 2474 | if (tmp_gw_factor > max_gw_factor) |
| 2475 | max_gw_factor = tmp_gw_factor; |
| 2476 | |
| 2477 | batadv_gw_node_put(gw_node); |
| 2478 | |
| 2479 | next: |
| 2480 | batadv_neigh_node_put(router); |
| 2481 | if (router_ifinfo) |
| 2482 | batadv_neigh_ifinfo_put(router_ifinfo); |
| 2483 | } |
| 2484 | rcu_read_unlock(); |
| 2485 | |
| 2486 | return curr_gw; |
| 2487 | } |
| 2488 | |
| 2489 | static bool batadv_iv_gw_is_eligible(struct batadv_priv *bat_priv, |
| 2490 | struct batadv_orig_node *curr_gw_orig, |
| 2491 | struct batadv_orig_node *orig_node) |
| 2492 | { |
| 2493 | struct batadv_neigh_ifinfo *router_orig_ifinfo = NULL; |
| 2494 | struct batadv_neigh_ifinfo *router_gw_ifinfo = NULL; |
| 2495 | struct batadv_neigh_node *router_gw = NULL; |
| 2496 | struct batadv_neigh_node *router_orig = NULL; |
| 2497 | u8 gw_tq_avg, orig_tq_avg; |
| 2498 | bool ret = false; |
| 2499 | |
| 2500 | /* dynamic re-election is performed only on fast or late switch */ |
| 2501 | if (atomic_read(&bat_priv->gw.sel_class) <= 2) |
| 2502 | return false; |
| 2503 | |
| 2504 | router_gw = batadv_orig_router_get(curr_gw_orig, BATADV_IF_DEFAULT); |
| 2505 | if (!router_gw) { |
| 2506 | ret = true; |
| 2507 | goto out; |
| 2508 | } |
| 2509 | |
| 2510 | router_gw_ifinfo = batadv_neigh_ifinfo_get(router_gw, |
| 2511 | BATADV_IF_DEFAULT); |
| 2512 | if (!router_gw_ifinfo) { |
| 2513 | ret = true; |
| 2514 | goto out; |
| 2515 | } |
| 2516 | |
| 2517 | router_orig = batadv_orig_router_get(orig_node, BATADV_IF_DEFAULT); |
| 2518 | if (!router_orig) |
| 2519 | goto out; |
| 2520 | |
| 2521 | router_orig_ifinfo = batadv_neigh_ifinfo_get(router_orig, |
| 2522 | BATADV_IF_DEFAULT); |
| 2523 | if (!router_orig_ifinfo) |
| 2524 | goto out; |
| 2525 | |
| 2526 | gw_tq_avg = router_gw_ifinfo->bat_iv.tq_avg; |
| 2527 | orig_tq_avg = router_orig_ifinfo->bat_iv.tq_avg; |
| 2528 | |
| 2529 | /* the TQ value has to be better */ |
| 2530 | if (orig_tq_avg < gw_tq_avg) |
| 2531 | goto out; |
| 2532 | |
| 2533 | /* if the routing class is greater than 3 the value tells us how much |
| 2534 | * greater the TQ value of the new gateway must be |
| 2535 | */ |
| 2536 | if ((atomic_read(&bat_priv->gw.sel_class) > 3) && |
| 2537 | (orig_tq_avg - gw_tq_avg < atomic_read(&bat_priv->gw.sel_class))) |
| 2538 | goto out; |
| 2539 | |
| 2540 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
| 2541 | "Restarting gateway selection: better gateway found (tq curr: %i, tq new: %i)\n", |
| 2542 | gw_tq_avg, orig_tq_avg); |
| 2543 | |
| 2544 | ret = true; |
| 2545 | out: |
| 2546 | if (router_gw_ifinfo) |
| 2547 | batadv_neigh_ifinfo_put(router_gw_ifinfo); |
| 2548 | if (router_orig_ifinfo) |
| 2549 | batadv_neigh_ifinfo_put(router_orig_ifinfo); |
| 2550 | if (router_gw) |
| 2551 | batadv_neigh_node_put(router_gw); |
| 2552 | if (router_orig) |
| 2553 | batadv_neigh_node_put(router_orig); |
| 2554 | |
| 2555 | return ret; |
| 2556 | } |
| 2557 | |
Sven Eckelmann | dc1cbd1 | 2016-07-16 09:31:20 +0200 | [diff] [blame] | 2558 | #ifdef CONFIG_BATMAN_ADV_DEBUGFS |
Antonio Quartulli | 34d99cf | 2016-07-03 12:46:33 +0200 | [diff] [blame] | 2559 | /* fails if orig_node has no router */ |
| 2560 | static int batadv_iv_gw_write_buffer_text(struct batadv_priv *bat_priv, |
| 2561 | struct seq_file *seq, |
| 2562 | const struct batadv_gw_node *gw_node) |
| 2563 | { |
| 2564 | struct batadv_gw_node *curr_gw; |
| 2565 | struct batadv_neigh_node *router; |
| 2566 | struct batadv_neigh_ifinfo *router_ifinfo = NULL; |
| 2567 | int ret = -1; |
| 2568 | |
| 2569 | router = batadv_orig_router_get(gw_node->orig_node, BATADV_IF_DEFAULT); |
| 2570 | if (!router) |
| 2571 | goto out; |
| 2572 | |
| 2573 | router_ifinfo = batadv_neigh_ifinfo_get(router, BATADV_IF_DEFAULT); |
| 2574 | if (!router_ifinfo) |
| 2575 | goto out; |
| 2576 | |
| 2577 | curr_gw = batadv_gw_get_selected_gw_node(bat_priv); |
| 2578 | |
| 2579 | seq_printf(seq, "%s %pM (%3i) %pM [%10s]: %u.%u/%u.%u MBit\n", |
| 2580 | (curr_gw == gw_node ? "=>" : " "), |
| 2581 | gw_node->orig_node->orig, |
| 2582 | router_ifinfo->bat_iv.tq_avg, router->addr, |
| 2583 | router->if_incoming->net_dev->name, |
| 2584 | gw_node->bandwidth_down / 10, |
| 2585 | gw_node->bandwidth_down % 10, |
| 2586 | gw_node->bandwidth_up / 10, |
| 2587 | gw_node->bandwidth_up % 10); |
| 2588 | ret = seq_has_overflowed(seq) ? -1 : 0; |
| 2589 | |
| 2590 | if (curr_gw) |
| 2591 | batadv_gw_node_put(curr_gw); |
| 2592 | out: |
| 2593 | if (router_ifinfo) |
| 2594 | batadv_neigh_ifinfo_put(router_ifinfo); |
| 2595 | if (router) |
| 2596 | batadv_neigh_node_put(router); |
| 2597 | return ret; |
| 2598 | } |
| 2599 | |
| 2600 | static void batadv_iv_gw_print(struct batadv_priv *bat_priv, |
| 2601 | struct seq_file *seq) |
| 2602 | { |
| 2603 | struct batadv_gw_node *gw_node; |
| 2604 | int gw_count = 0; |
| 2605 | |
| 2606 | seq_puts(seq, |
| 2607 | " Gateway (#/255) Nexthop [outgoingIF]: advertised uplink bandwidth\n"); |
| 2608 | |
| 2609 | rcu_read_lock(); |
Sven Eckelmann | 70ea5ce | 2016-07-27 12:31:08 +0200 | [diff] [blame] | 2610 | hlist_for_each_entry_rcu(gw_node, &bat_priv->gw.gateway_list, list) { |
Antonio Quartulli | 34d99cf | 2016-07-03 12:46:33 +0200 | [diff] [blame] | 2611 | /* fails if orig_node has no router */ |
| 2612 | if (batadv_iv_gw_write_buffer_text(bat_priv, seq, gw_node) < 0) |
| 2613 | continue; |
| 2614 | |
| 2615 | gw_count++; |
| 2616 | } |
| 2617 | rcu_read_unlock(); |
| 2618 | |
| 2619 | if (gw_count == 0) |
| 2620 | seq_puts(seq, "No gateways in range ...\n"); |
| 2621 | } |
Sven Eckelmann | dc1cbd1 | 2016-07-16 09:31:20 +0200 | [diff] [blame] | 2622 | #endif |
Antonio Quartulli | 34d99cf | 2016-07-03 12:46:33 +0200 | [diff] [blame] | 2623 | |
Andrew Lunn | efb766a | 2016-07-03 13:31:43 +0200 | [diff] [blame] | 2624 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 2625 | * batadv_iv_gw_dump_entry() - Dump a gateway into a message |
Andrew Lunn | efb766a | 2016-07-03 13:31:43 +0200 | [diff] [blame] | 2626 | * @msg: Netlink message to dump into |
| 2627 | * @portid: Port making netlink request |
Sven Eckelmann | 9264c85 | 2018-10-30 22:01:23 +0100 | [diff] [blame] | 2628 | * @cb: Control block containing additional options |
Andrew Lunn | efb766a | 2016-07-03 13:31:43 +0200 | [diff] [blame] | 2629 | * @bat_priv: The bat priv with all the soft interface information |
| 2630 | * @gw_node: Gateway to be dumped |
| 2631 | * |
| 2632 | * Return: Error code, or 0 on success |
| 2633 | */ |
Sven Eckelmann | 9264c85 | 2018-10-30 22:01:23 +0100 | [diff] [blame] | 2634 | static int batadv_iv_gw_dump_entry(struct sk_buff *msg, u32 portid, |
| 2635 | struct netlink_callback *cb, |
Andrew Lunn | efb766a | 2016-07-03 13:31:43 +0200 | [diff] [blame] | 2636 | struct batadv_priv *bat_priv, |
| 2637 | struct batadv_gw_node *gw_node) |
| 2638 | { |
| 2639 | struct batadv_neigh_ifinfo *router_ifinfo = NULL; |
| 2640 | struct batadv_neigh_node *router; |
Sven Eckelmann | b5685d2 | 2018-06-02 17:26:34 +0200 | [diff] [blame] | 2641 | struct batadv_gw_node *curr_gw = NULL; |
Sven Eckelmann | 10d5702 | 2018-02-19 14:08:52 +0100 | [diff] [blame] | 2642 | int ret = 0; |
Andrew Lunn | efb766a | 2016-07-03 13:31:43 +0200 | [diff] [blame] | 2643 | void *hdr; |
| 2644 | |
| 2645 | router = batadv_orig_router_get(gw_node->orig_node, BATADV_IF_DEFAULT); |
| 2646 | if (!router) |
| 2647 | goto out; |
| 2648 | |
| 2649 | router_ifinfo = batadv_neigh_ifinfo_get(router, BATADV_IF_DEFAULT); |
| 2650 | if (!router_ifinfo) |
| 2651 | goto out; |
| 2652 | |
| 2653 | curr_gw = batadv_gw_get_selected_gw_node(bat_priv); |
| 2654 | |
Sven Eckelmann | 9264c85 | 2018-10-30 22:01:23 +0100 | [diff] [blame] | 2655 | hdr = genlmsg_put(msg, portid, cb->nlh->nlmsg_seq, |
| 2656 | &batadv_netlink_family, NLM_F_MULTI, |
| 2657 | BATADV_CMD_GET_GATEWAYS); |
Andrew Lunn | efb766a | 2016-07-03 13:31:43 +0200 | [diff] [blame] | 2658 | if (!hdr) { |
| 2659 | ret = -ENOBUFS; |
| 2660 | goto out; |
| 2661 | } |
| 2662 | |
Sven Eckelmann | 9264c85 | 2018-10-30 22:01:23 +0100 | [diff] [blame] | 2663 | genl_dump_check_consistent(cb, hdr); |
| 2664 | |
Andrew Lunn | efb766a | 2016-07-03 13:31:43 +0200 | [diff] [blame] | 2665 | ret = -EMSGSIZE; |
| 2666 | |
| 2667 | if (curr_gw == gw_node) |
| 2668 | if (nla_put_flag(msg, BATADV_ATTR_FLAG_BEST)) { |
| 2669 | genlmsg_cancel(msg, hdr); |
| 2670 | goto out; |
| 2671 | } |
| 2672 | |
| 2673 | if (nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN, |
| 2674 | gw_node->orig_node->orig) || |
| 2675 | nla_put_u8(msg, BATADV_ATTR_TQ, router_ifinfo->bat_iv.tq_avg) || |
| 2676 | nla_put(msg, BATADV_ATTR_ROUTER, ETH_ALEN, |
| 2677 | router->addr) || |
| 2678 | nla_put_string(msg, BATADV_ATTR_HARD_IFNAME, |
| 2679 | router->if_incoming->net_dev->name) || |
| 2680 | nla_put_u32(msg, BATADV_ATTR_BANDWIDTH_DOWN, |
| 2681 | gw_node->bandwidth_down) || |
| 2682 | nla_put_u32(msg, BATADV_ATTR_BANDWIDTH_UP, |
| 2683 | gw_node->bandwidth_up)) { |
| 2684 | genlmsg_cancel(msg, hdr); |
| 2685 | goto out; |
| 2686 | } |
| 2687 | |
| 2688 | genlmsg_end(msg, hdr); |
| 2689 | ret = 0; |
| 2690 | |
| 2691 | out: |
Sven Eckelmann | b5685d2 | 2018-06-02 17:26:34 +0200 | [diff] [blame] | 2692 | if (curr_gw) |
| 2693 | batadv_gw_node_put(curr_gw); |
Andrew Lunn | efb766a | 2016-07-03 13:31:43 +0200 | [diff] [blame] | 2694 | if (router_ifinfo) |
| 2695 | batadv_neigh_ifinfo_put(router_ifinfo); |
| 2696 | if (router) |
| 2697 | batadv_neigh_node_put(router); |
| 2698 | return ret; |
| 2699 | } |
| 2700 | |
| 2701 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 2702 | * batadv_iv_gw_dump() - Dump gateways into a message |
Andrew Lunn | efb766a | 2016-07-03 13:31:43 +0200 | [diff] [blame] | 2703 | * @msg: Netlink message to dump into |
| 2704 | * @cb: Control block containing additional options |
| 2705 | * @bat_priv: The bat priv with all the soft interface information |
| 2706 | */ |
| 2707 | static void batadv_iv_gw_dump(struct sk_buff *msg, struct netlink_callback *cb, |
| 2708 | struct batadv_priv *bat_priv) |
| 2709 | { |
| 2710 | int portid = NETLINK_CB(cb->skb).portid; |
| 2711 | struct batadv_gw_node *gw_node; |
| 2712 | int idx_skip = cb->args[0]; |
| 2713 | int idx = 0; |
| 2714 | |
Sven Eckelmann | 9264c85 | 2018-10-30 22:01:23 +0100 | [diff] [blame] | 2715 | spin_lock_bh(&bat_priv->gw.list_lock); |
| 2716 | cb->seq = bat_priv->gw.generation << 1 | 1; |
| 2717 | |
| 2718 | hlist_for_each_entry(gw_node, &bat_priv->gw.gateway_list, list) { |
Andrew Lunn | efb766a | 2016-07-03 13:31:43 +0200 | [diff] [blame] | 2719 | if (idx++ < idx_skip) |
| 2720 | continue; |
| 2721 | |
Sven Eckelmann | 9264c85 | 2018-10-30 22:01:23 +0100 | [diff] [blame] | 2722 | if (batadv_iv_gw_dump_entry(msg, portid, cb, bat_priv, |
| 2723 | gw_node)) { |
Andrew Lunn | efb766a | 2016-07-03 13:31:43 +0200 | [diff] [blame] | 2724 | idx_skip = idx - 1; |
| 2725 | goto unlock; |
| 2726 | } |
| 2727 | } |
| 2728 | |
| 2729 | idx_skip = idx; |
| 2730 | unlock: |
Sven Eckelmann | 9264c85 | 2018-10-30 22:01:23 +0100 | [diff] [blame] | 2731 | spin_unlock_bh(&bat_priv->gw.list_lock); |
Andrew Lunn | efb766a | 2016-07-03 13:31:43 +0200 | [diff] [blame] | 2732 | |
| 2733 | cb->args[0] = idx_skip; |
| 2734 | } |
| 2735 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2736 | static struct batadv_algo_ops batadv_batman_iv __read_mostly = { |
Marek Lindner | 519d349 | 2012-04-18 17:15:57 +0800 | [diff] [blame] | 2737 | .name = "BATMAN_IV", |
Antonio Quartulli | 29824a5 | 2016-05-25 23:27:31 +0800 | [diff] [blame] | 2738 | .iface = { |
Antonio Quartulli | 29824a5 | 2016-05-25 23:27:31 +0800 | [diff] [blame] | 2739 | .enable = batadv_iv_ogm_iface_enable, |
Sven Eckelmann | 9e6b564 | 2019-06-02 10:57:31 +0200 | [diff] [blame] | 2740 | .enabled = batadv_iv_iface_enabled, |
Antonio Quartulli | 29824a5 | 2016-05-25 23:27:31 +0800 | [diff] [blame] | 2741 | .disable = batadv_iv_ogm_iface_disable, |
| 2742 | .update_mac = batadv_iv_ogm_iface_update_mac, |
| 2743 | .primary_set = batadv_iv_ogm_primary_iface_set, |
| 2744 | }, |
| 2745 | .neigh = { |
| 2746 | .cmp = batadv_iv_ogm_neigh_cmp, |
| 2747 | .is_similar_or_better = batadv_iv_ogm_neigh_is_sob, |
Sven Eckelmann | dc1cbd1 | 2016-07-16 09:31:20 +0200 | [diff] [blame] | 2748 | #ifdef CONFIG_BATMAN_ADV_DEBUGFS |
Antonio Quartulli | 29824a5 | 2016-05-25 23:27:31 +0800 | [diff] [blame] | 2749 | .print = batadv_iv_neigh_print, |
Sven Eckelmann | dc1cbd1 | 2016-07-16 09:31:20 +0200 | [diff] [blame] | 2750 | #endif |
Matthias Schiffer | 024f99c | 2016-07-03 13:31:40 +0200 | [diff] [blame] | 2751 | .dump = batadv_iv_ogm_neigh_dump, |
Antonio Quartulli | 29824a5 | 2016-05-25 23:27:31 +0800 | [diff] [blame] | 2752 | }, |
| 2753 | .orig = { |
Sven Eckelmann | dc1cbd1 | 2016-07-16 09:31:20 +0200 | [diff] [blame] | 2754 | #ifdef CONFIG_BATMAN_ADV_DEBUGFS |
Antonio Quartulli | 29824a5 | 2016-05-25 23:27:31 +0800 | [diff] [blame] | 2755 | .print = batadv_iv_ogm_orig_print, |
Sven Eckelmann | dc1cbd1 | 2016-07-16 09:31:20 +0200 | [diff] [blame] | 2756 | #endif |
Matthias Schiffer | 024f99c | 2016-07-03 13:31:40 +0200 | [diff] [blame] | 2757 | .dump = batadv_iv_ogm_orig_dump, |
Antonio Quartulli | 29824a5 | 2016-05-25 23:27:31 +0800 | [diff] [blame] | 2758 | }, |
Antonio Quartulli | 34d99cf | 2016-07-03 12:46:33 +0200 | [diff] [blame] | 2759 | .gw = { |
Sven Eckelmann | 1a9070e | 2017-03-04 15:48:50 +0100 | [diff] [blame] | 2760 | .init_sel_class = batadv_iv_init_sel_class, |
Antonio Quartulli | 34d99cf | 2016-07-03 12:46:33 +0200 | [diff] [blame] | 2761 | .get_best_gw_node = batadv_iv_gw_get_best_gw_node, |
| 2762 | .is_eligible = batadv_iv_gw_is_eligible, |
Sven Eckelmann | dc1cbd1 | 2016-07-16 09:31:20 +0200 | [diff] [blame] | 2763 | #ifdef CONFIG_BATMAN_ADV_DEBUGFS |
Antonio Quartulli | 34d99cf | 2016-07-03 12:46:33 +0200 | [diff] [blame] | 2764 | .print = batadv_iv_gw_print, |
Sven Eckelmann | dc1cbd1 | 2016-07-16 09:31:20 +0200 | [diff] [blame] | 2765 | #endif |
Andrew Lunn | efb766a | 2016-07-03 13:31:43 +0200 | [diff] [blame] | 2766 | .dump = batadv_iv_gw_dump, |
Antonio Quartulli | 34d99cf | 2016-07-03 12:46:33 +0200 | [diff] [blame] | 2767 | }, |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 2768 | }; |
| 2769 | |
Sven Eckelmann | ff15c27 | 2017-12-02 19:51:53 +0100 | [diff] [blame] | 2770 | /** |
| 2771 | * batadv_iv_init() - B.A.T.M.A.N. IV initialization function |
| 2772 | * |
| 2773 | * Return: 0 on success or negative error number in case of failure |
| 2774 | */ |
Sven Eckelmann | 81c524f | 2012-05-12 02:09:22 +0200 | [diff] [blame] | 2775 | int __init batadv_iv_init(void) |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 2776 | { |
Marek Lindner | c3e2931 | 2012-03-04 16:56:25 +0800 | [diff] [blame] | 2777 | int ret; |
| 2778 | |
| 2779 | /* batman originator packet */ |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 2780 | ret = batadv_recv_handler_register(BATADV_IV_OGM, |
| 2781 | batadv_iv_ogm_receive); |
Marek Lindner | c3e2931 | 2012-03-04 16:56:25 +0800 | [diff] [blame] | 2782 | if (ret < 0) |
| 2783 | goto out; |
| 2784 | |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 2785 | ret = batadv_algo_register(&batadv_batman_iv); |
Marek Lindner | c3e2931 | 2012-03-04 16:56:25 +0800 | [diff] [blame] | 2786 | if (ret < 0) |
| 2787 | goto handler_unregister; |
| 2788 | |
| 2789 | goto out; |
| 2790 | |
| 2791 | handler_unregister: |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 2792 | batadv_recv_handler_unregister(BATADV_IV_OGM); |
Marek Lindner | c3e2931 | 2012-03-04 16:56:25 +0800 | [diff] [blame] | 2793 | out: |
| 2794 | return ret; |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 2795 | } |