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