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 | |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 18 | #include "bat_algo.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> |
| 33 | #include <linux/list.h> |
Sven Eckelmann | 77ae32e | 2016-01-16 10:29:53 +0100 | [diff] [blame] | 34 | #include <linux/kref.h> |
Sven Eckelmann | 64ae7445 | 2016-02-22 22:56:34 +0100 | [diff] [blame] | 35 | #include <linux/lockdep.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 36 | #include <linux/netdevice.h> |
| 37 | #include <linux/pkt_sched.h> |
| 38 | #include <linux/printk.h> |
| 39 | #include <linux/random.h> |
| 40 | #include <linux/rculist.h> |
| 41 | #include <linux/rcupdate.h> |
| 42 | #include <linux/seq_file.h> |
| 43 | #include <linux/skbuff.h> |
| 44 | #include <linux/slab.h> |
| 45 | #include <linux/spinlock.h> |
| 46 | #include <linux/stddef.h> |
| 47 | #include <linux/string.h> |
| 48 | #include <linux/types.h> |
| 49 | #include <linux/workqueue.h> |
| 50 | |
| 51 | #include "bitarray.h" |
| 52 | #include "hard-interface.h" |
| 53 | #include "hash.h" |
Martin Hundebøll | d56b170 | 2013-01-25 11:12:39 +0100 | [diff] [blame] | 54 | #include "network-coding.h" |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 55 | #include "originator.h" |
| 56 | #include "packet.h" |
| 57 | #include "routing.h" |
| 58 | #include "send.h" |
| 59 | #include "translation-table.h" |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 60 | |
Antonio Quartulli | 791c2a2 | 2013-08-17 12:44:44 +0200 | [diff] [blame] | 61 | /** |
Martin Hundebøll | 95298a9 | 2014-07-15 09:41:05 +0200 | [diff] [blame] | 62 | * enum batadv_dup_status - duplicate status |
Markus Pargmann | 9f52ee1 | 2014-12-26 12:41:34 +0100 | [diff] [blame] | 63 | * @BATADV_NO_DUP: the packet is no duplicate |
Antonio Quartulli | 791c2a2 | 2013-08-17 12:44:44 +0200 | [diff] [blame] | 64 | * @BATADV_ORIG_DUP: OGM is a duplicate in the originator (but not for the |
| 65 | * neighbor) |
| 66 | * @BATADV_NEIGH_DUP: OGM is a duplicate for the neighbor |
| 67 | * @BATADV_PROTECTED: originator is currently protected (after reboot) |
| 68 | */ |
| 69 | enum batadv_dup_status { |
| 70 | BATADV_NO_DUP = 0, |
| 71 | BATADV_ORIG_DUP, |
| 72 | BATADV_NEIGH_DUP, |
| 73 | BATADV_PROTECTED, |
| 74 | }; |
| 75 | |
Antonio Quartulli | 24a5dee | 2013-04-08 09:38:12 +0200 | [diff] [blame] | 76 | /** |
| 77 | * batadv_ring_buffer_set - update the ring buffer with the given value |
| 78 | * @lq_recv: pointer to the ring buffer |
| 79 | * @lq_index: index to store the value at |
| 80 | * @value: value to store in the ring buffer |
| 81 | */ |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 82 | 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] | 83 | { |
| 84 | lq_recv[*lq_index] = value; |
| 85 | *lq_index = (*lq_index + 1) % BATADV_TQ_GLOBAL_WINDOW_SIZE; |
| 86 | } |
| 87 | |
| 88 | /** |
Markus Pargmann | d491dbb | 2014-12-26 12:41:36 +0100 | [diff] [blame] | 89 | * 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] | 90 | * in the given ring buffer |
| 91 | * @lq_recv: pointer to the ring buffer |
| 92 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 93 | * Return: computed average value. |
Antonio Quartulli | 24a5dee | 2013-04-08 09:38:12 +0200 | [diff] [blame] | 94 | */ |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 95 | static u8 batadv_ring_buffer_avg(const u8 lq_recv[]) |
Antonio Quartulli | 24a5dee | 2013-04-08 09:38:12 +0200 | [diff] [blame] | 96 | { |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 97 | const u8 *ptr; |
| 98 | u16 count = 0; |
| 99 | u16 i = 0; |
| 100 | u16 sum = 0; |
Antonio Quartulli | 24a5dee | 2013-04-08 09:38:12 +0200 | [diff] [blame] | 101 | |
| 102 | ptr = lq_recv; |
| 103 | |
| 104 | while (i < BATADV_TQ_GLOBAL_WINDOW_SIZE) { |
| 105 | if (*ptr != 0) { |
| 106 | count++; |
| 107 | sum += *ptr; |
| 108 | } |
| 109 | |
| 110 | i++; |
| 111 | ptr++; |
| 112 | } |
| 113 | |
| 114 | if (count == 0) |
| 115 | return 0; |
| 116 | |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 117 | return (u8)(sum / count); |
Antonio Quartulli | 24a5dee | 2013-04-08 09:38:12 +0200 | [diff] [blame] | 118 | } |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 119 | |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 120 | /** |
Antonio Quartulli | d0015fd | 2013-09-03 11:10:23 +0200 | [diff] [blame] | 121 | * batadv_iv_ogm_orig_free - free the private resources allocated for this |
| 122 | * orig_node |
| 123 | * @orig_node: the orig_node for which the resources have to be free'd |
| 124 | */ |
| 125 | static void batadv_iv_ogm_orig_free(struct batadv_orig_node *orig_node) |
| 126 | { |
| 127 | kfree(orig_node->bat_iv.bcast_own); |
| 128 | kfree(orig_node->bat_iv.bcast_own_sum); |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * batadv_iv_ogm_orig_add_if - change the private structures of the orig_node to |
| 133 | * include the new hard-interface |
| 134 | * @orig_node: the orig_node that has to be changed |
| 135 | * @max_if_num: the current amount of interfaces |
| 136 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 137 | * Return: 0 on success, a negative error code otherwise. |
Antonio Quartulli | d0015fd | 2013-09-03 11:10:23 +0200 | [diff] [blame] | 138 | */ |
| 139 | static int batadv_iv_ogm_orig_add_if(struct batadv_orig_node *orig_node, |
| 140 | int max_if_num) |
| 141 | { |
| 142 | void *data_ptr; |
Antonio Quartulli | 0185dda | 2014-05-24 06:43:47 +0200 | [diff] [blame] | 143 | size_t old_size; |
Antonio Quartulli | d0015fd | 2013-09-03 11:10:23 +0200 | [diff] [blame] | 144 | int ret = -ENOMEM; |
| 145 | |
| 146 | spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock); |
| 147 | |
Antonio Quartulli | d0015fd | 2013-09-03 11:10:23 +0200 | [diff] [blame] | 148 | old_size = (max_if_num - 1) * sizeof(unsigned long) * BATADV_NUM_WORDS; |
Antonio Quartulli | 0185dda | 2014-05-24 06:43:47 +0200 | [diff] [blame] | 149 | data_ptr = kmalloc_array(max_if_num, |
| 150 | BATADV_NUM_WORDS * sizeof(unsigned long), |
| 151 | GFP_ATOMIC); |
Antonio Quartulli | d0015fd | 2013-09-03 11:10:23 +0200 | [diff] [blame] | 152 | if (!data_ptr) |
| 153 | goto unlock; |
| 154 | |
| 155 | memcpy(data_ptr, orig_node->bat_iv.bcast_own, old_size); |
| 156 | kfree(orig_node->bat_iv.bcast_own); |
| 157 | orig_node->bat_iv.bcast_own = data_ptr; |
| 158 | |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 159 | data_ptr = kmalloc_array(max_if_num, sizeof(u8), GFP_ATOMIC); |
Sven Eckelmann | f7dcdf5 | 2016-02-22 22:56:33 +0100 | [diff] [blame] | 160 | if (!data_ptr) |
Antonio Quartulli | d0015fd | 2013-09-03 11:10:23 +0200 | [diff] [blame] | 161 | goto unlock; |
Antonio Quartulli | d0015fd | 2013-09-03 11:10:23 +0200 | [diff] [blame] | 162 | |
| 163 | memcpy(data_ptr, orig_node->bat_iv.bcast_own_sum, |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 164 | (max_if_num - 1) * sizeof(u8)); |
Antonio Quartulli | d0015fd | 2013-09-03 11:10:23 +0200 | [diff] [blame] | 165 | kfree(orig_node->bat_iv.bcast_own_sum); |
| 166 | orig_node->bat_iv.bcast_own_sum = data_ptr; |
| 167 | |
| 168 | ret = 0; |
| 169 | |
| 170 | unlock: |
| 171 | spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock); |
| 172 | |
| 173 | return ret; |
| 174 | } |
| 175 | |
| 176 | /** |
Sven Eckelmann | 64ae7445 | 2016-02-22 22:56:34 +0100 | [diff] [blame] | 177 | * batadv_iv_ogm_drop_bcast_own_entry - drop section of bcast_own |
| 178 | * @orig_node: the orig_node that has to be changed |
| 179 | * @max_if_num: the current amount of interfaces |
| 180 | * @del_if_num: the index of the interface being removed |
| 181 | */ |
| 182 | static void |
| 183 | batadv_iv_ogm_drop_bcast_own_entry(struct batadv_orig_node *orig_node, |
| 184 | int max_if_num, int del_if_num) |
| 185 | { |
| 186 | size_t chunk_size; |
| 187 | size_t if_offset; |
| 188 | void *data_ptr; |
| 189 | |
| 190 | lockdep_assert_held(&orig_node->bat_iv.ogm_cnt_lock); |
| 191 | |
| 192 | chunk_size = sizeof(unsigned long) * BATADV_NUM_WORDS; |
| 193 | data_ptr = kmalloc_array(max_if_num, chunk_size, GFP_ATOMIC); |
| 194 | if (!data_ptr) |
| 195 | /* use old buffer when new one could not be allocated */ |
| 196 | data_ptr = orig_node->bat_iv.bcast_own; |
| 197 | |
| 198 | /* copy first part */ |
| 199 | memmove(data_ptr, orig_node->bat_iv.bcast_own, del_if_num * chunk_size); |
| 200 | |
| 201 | /* copy second part */ |
| 202 | if_offset = (del_if_num + 1) * chunk_size; |
| 203 | memmove((char *)data_ptr + del_if_num * chunk_size, |
| 204 | (uint8_t *)orig_node->bat_iv.bcast_own + if_offset, |
| 205 | (max_if_num - del_if_num) * chunk_size); |
| 206 | |
| 207 | /* bcast_own was shrunk down in new buffer; free old one */ |
| 208 | if (orig_node->bat_iv.bcast_own != data_ptr) { |
| 209 | kfree(orig_node->bat_iv.bcast_own); |
| 210 | orig_node->bat_iv.bcast_own = data_ptr; |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * batadv_iv_ogm_drop_bcast_own_sum_entry - drop section of bcast_own_sum |
| 216 | * @orig_node: the orig_node that has to be changed |
| 217 | * @max_if_num: the current amount of interfaces |
| 218 | * @del_if_num: the index of the interface being removed |
| 219 | */ |
| 220 | static void |
| 221 | batadv_iv_ogm_drop_bcast_own_sum_entry(struct batadv_orig_node *orig_node, |
| 222 | int max_if_num, int del_if_num) |
| 223 | { |
| 224 | size_t if_offset; |
| 225 | void *data_ptr; |
| 226 | |
| 227 | lockdep_assert_held(&orig_node->bat_iv.ogm_cnt_lock); |
| 228 | |
| 229 | data_ptr = kmalloc_array(max_if_num, sizeof(u8), GFP_ATOMIC); |
| 230 | if (!data_ptr) |
| 231 | /* use old buffer when new one could not be allocated */ |
| 232 | data_ptr = orig_node->bat_iv.bcast_own_sum; |
| 233 | |
| 234 | memmove(data_ptr, orig_node->bat_iv.bcast_own_sum, |
| 235 | del_if_num * sizeof(u8)); |
| 236 | |
| 237 | if_offset = (del_if_num + 1) * sizeof(u8); |
| 238 | memmove((char *)data_ptr + del_if_num * sizeof(u8), |
| 239 | orig_node->bat_iv.bcast_own_sum + if_offset, |
| 240 | (max_if_num - del_if_num) * sizeof(u8)); |
| 241 | |
| 242 | /* bcast_own_sum was shrunk down in new buffer; free old one */ |
| 243 | if (orig_node->bat_iv.bcast_own_sum != data_ptr) { |
| 244 | kfree(orig_node->bat_iv.bcast_own_sum); |
| 245 | orig_node->bat_iv.bcast_own_sum = data_ptr; |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | /** |
Antonio Quartulli | d0015fd | 2013-09-03 11:10:23 +0200 | [diff] [blame] | 250 | * batadv_iv_ogm_orig_del_if - change the private structures of the orig_node to |
| 251 | * exclude the removed interface |
| 252 | * @orig_node: the orig_node that has to be changed |
| 253 | * @max_if_num: the current amount of interfaces |
| 254 | * @del_if_num: the index of the interface being removed |
| 255 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 256 | * Return: 0 on success, a negative error code otherwise. |
Antonio Quartulli | d0015fd | 2013-09-03 11:10:23 +0200 | [diff] [blame] | 257 | */ |
| 258 | static int batadv_iv_ogm_orig_del_if(struct batadv_orig_node *orig_node, |
| 259 | int max_if_num, int del_if_num) |
| 260 | { |
Antonio Quartulli | d0015fd | 2013-09-03 11:10:23 +0200 | [diff] [blame] | 261 | spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock); |
| 262 | |
Sven Eckelmann | 64ae7445 | 2016-02-22 22:56:34 +0100 | [diff] [blame] | 263 | if (max_if_num == 0) { |
Antonio Quartulli | d0015fd | 2013-09-03 11:10:23 +0200 | [diff] [blame] | 264 | kfree(orig_node->bat_iv.bcast_own); |
Sven Eckelmann | 64ae7445 | 2016-02-22 22:56:34 +0100 | [diff] [blame] | 265 | kfree(orig_node->bat_iv.bcast_own_sum); |
| 266 | orig_node->bat_iv.bcast_own = NULL; |
| 267 | orig_node->bat_iv.bcast_own_sum = NULL; |
| 268 | } else { |
| 269 | batadv_iv_ogm_drop_bcast_own_entry(orig_node, max_if_num, |
| 270 | del_if_num); |
| 271 | batadv_iv_ogm_drop_bcast_own_sum_entry(orig_node, max_if_num, |
| 272 | del_if_num); |
Antonio Quartulli | d0015fd | 2013-09-03 11:10:23 +0200 | [diff] [blame] | 273 | } |
| 274 | |
Antonio Quartulli | d0015fd | 2013-09-03 11:10:23 +0200 | [diff] [blame] | 275 | spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock); |
| 276 | |
Sven Eckelmann | 64ae7445 | 2016-02-22 22:56:34 +0100 | [diff] [blame] | 277 | return 0; |
Antonio Quartulli | d0015fd | 2013-09-03 11:10:23 +0200 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | /** |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 281 | * batadv_iv_ogm_orig_get - retrieve or create (if does not exist) an originator |
| 282 | * @bat_priv: the bat priv with all the soft interface information |
| 283 | * @addr: mac address of the originator |
| 284 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 285 | * Return: the originator object corresponding to the passed mac address or NULL |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 286 | * on failure. |
| 287 | * If the object does not exists it is created an initialised. |
| 288 | */ |
| 289 | static struct batadv_orig_node * |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 290 | 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] | 291 | { |
| 292 | struct batadv_orig_node *orig_node; |
| 293 | int size, hash_added; |
| 294 | |
| 295 | orig_node = batadv_orig_hash_find(bat_priv, addr); |
| 296 | if (orig_node) |
| 297 | return orig_node; |
| 298 | |
| 299 | orig_node = batadv_orig_node_new(bat_priv, addr); |
| 300 | if (!orig_node) |
| 301 | return NULL; |
| 302 | |
| 303 | spin_lock_init(&orig_node->bat_iv.ogm_cnt_lock); |
| 304 | |
| 305 | size = bat_priv->num_ifaces * sizeof(unsigned long) * BATADV_NUM_WORDS; |
| 306 | orig_node->bat_iv.bcast_own = kzalloc(size, GFP_ATOMIC); |
| 307 | if (!orig_node->bat_iv.bcast_own) |
| 308 | goto free_orig_node; |
| 309 | |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 310 | size = bat_priv->num_ifaces * sizeof(u8); |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 311 | orig_node->bat_iv.bcast_own_sum = kzalloc(size, GFP_ATOMIC); |
| 312 | if (!orig_node->bat_iv.bcast_own_sum) |
Antonio Quartulli | a5a5cb8 | 2014-02-15 02:17:20 +0100 | [diff] [blame] | 313 | goto free_orig_node; |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 314 | |
| 315 | hash_added = batadv_hash_add(bat_priv->orig_hash, batadv_compare_orig, |
| 316 | batadv_choose_orig, orig_node, |
| 317 | &orig_node->hash_entry); |
| 318 | if (hash_added != 0) |
Antonio Quartulli | a5a5cb8 | 2014-02-15 02:17:20 +0100 | [diff] [blame] | 319 | goto free_orig_node; |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 320 | |
| 321 | return orig_node; |
| 322 | |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 323 | free_orig_node: |
Simon Wunderlich | b2262df | 2014-02-08 16:45:06 +0100 | [diff] [blame] | 324 | /* free twice, as batadv_orig_node_new sets refcount to 2 */ |
Sven Eckelmann | 5d96731 | 2016-01-17 11:01:09 +0100 | [diff] [blame] | 325 | batadv_orig_node_put(orig_node); |
| 326 | batadv_orig_node_put(orig_node); |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 327 | |
| 328 | return NULL; |
| 329 | } |
| 330 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 331 | static struct batadv_neigh_node * |
| 332 | batadv_iv_ogm_neigh_new(struct batadv_hard_iface *hard_iface, |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 333 | const u8 *neigh_addr, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 334 | struct batadv_orig_node *orig_node, |
Antonio Quartulli | 863dd7a | 2013-03-25 13:49:46 +0100 | [diff] [blame] | 335 | struct batadv_orig_node *orig_neigh) |
Marek Lindner | 7ae8b28 | 2012-03-01 15:35:21 +0800 | [diff] [blame] | 336 | { |
Marek Lindner | 741aa06 | 2015-07-26 04:57:43 +0800 | [diff] [blame] | 337 | struct batadv_neigh_node *neigh_node; |
Marek Lindner | 7ae8b28 | 2012-03-01 15:35:21 +0800 | [diff] [blame] | 338 | |
Marek Lindner | 3f32f8a | 2015-07-26 04:59:15 +0800 | [diff] [blame] | 339 | neigh_node = batadv_neigh_node_new(orig_node, hard_iface, neigh_addr); |
Marek Lindner | 7ae8b28 | 2012-03-01 15:35:21 +0800 | [diff] [blame] | 340 | if (!neigh_node) |
| 341 | goto out; |
| 342 | |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 343 | neigh_node->orig_node = orig_neigh; |
Marek Lindner | 7ae8b28 | 2012-03-01 15:35:21 +0800 | [diff] [blame] | 344 | |
Marek Lindner | 7ae8b28 | 2012-03-01 15:35:21 +0800 | [diff] [blame] | 345 | out: |
| 346 | return neigh_node; |
| 347 | } |
| 348 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 349 | 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] | 350 | { |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 351 | struct batadv_ogm_packet *batadv_ogm_packet; |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 352 | unsigned char *ogm_buff; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 353 | u32 random_seqno; |
Marek Lindner | d7d32ec | 2012-02-07 17:20:46 +0800 | [diff] [blame] | 354 | |
| 355 | /* randomize initial seqno to avoid collision */ |
| 356 | get_random_bytes(&random_seqno, sizeof(random_seqno)); |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 357 | atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno); |
Marek Lindner | d0b9fd8 | 2011-07-30 12:33:33 +0200 | [diff] [blame] | 358 | |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 359 | hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN; |
| 360 | ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC); |
| 361 | if (!ogm_buff) |
Markus Pargmann | 42d9f2c | 2014-12-26 12:41:26 +0100 | [diff] [blame] | 362 | return -ENOMEM; |
Marek Lindner | 77af757 | 2012-02-07 17:20:48 +0800 | [diff] [blame] | 363 | |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 364 | hard_iface->bat_iv.ogm_buff = ogm_buff; |
| 365 | |
| 366 | batadv_ogm_packet = (struct batadv_ogm_packet *)ogm_buff; |
Simon Wunderlich | a40d9b0 | 2013-12-02 20:38:31 +0100 | [diff] [blame] | 367 | batadv_ogm_packet->packet_type = BATADV_IV_OGM; |
| 368 | batadv_ogm_packet->version = BATADV_COMPAT_VERSION; |
| 369 | batadv_ogm_packet->ttl = 2; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 370 | batadv_ogm_packet->flags = BATADV_NO_FLAGS; |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 371 | batadv_ogm_packet->reserved = 0; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 372 | batadv_ogm_packet->tq = BATADV_TQ_MAX_VALUE; |
Marek Lindner | 77af757 | 2012-02-07 17:20:48 +0800 | [diff] [blame] | 373 | |
Markus Pargmann | 42d9f2c | 2014-12-26 12:41:26 +0100 | [diff] [blame] | 374 | return 0; |
Marek Lindner | d0b9fd8 | 2011-07-30 12:33:33 +0200 | [diff] [blame] | 375 | } |
| 376 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 377 | 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] | 378 | { |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 379 | kfree(hard_iface->bat_iv.ogm_buff); |
| 380 | hard_iface->bat_iv.ogm_buff = NULL; |
Marek Lindner | 00a5007 | 2012-02-07 17:20:47 +0800 | [diff] [blame] | 381 | } |
| 382 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 383 | 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] | 384 | { |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 385 | struct batadv_ogm_packet *batadv_ogm_packet; |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 386 | unsigned char *ogm_buff = hard_iface->bat_iv.ogm_buff; |
Marek Lindner | d0b9fd8 | 2011-07-30 12:33:33 +0200 | [diff] [blame] | 387 | |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 388 | batadv_ogm_packet = (struct batadv_ogm_packet *)ogm_buff; |
Antonio Quartulli | 8fdd015 | 2014-01-22 00:42:11 +0100 | [diff] [blame] | 389 | ether_addr_copy(batadv_ogm_packet->orig, |
| 390 | hard_iface->net_dev->dev_addr); |
| 391 | ether_addr_copy(batadv_ogm_packet->prev_sender, |
| 392 | hard_iface->net_dev->dev_addr); |
Marek Lindner | d0b9fd8 | 2011-07-30 12:33:33 +0200 | [diff] [blame] | 393 | } |
| 394 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 395 | static void |
| 396 | batadv_iv_ogm_primary_iface_set(struct batadv_hard_iface *hard_iface) |
Marek Lindner | c322939 | 2012-03-11 06:17:50 +0800 | [diff] [blame] | 397 | { |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 398 | struct batadv_ogm_packet *batadv_ogm_packet; |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 399 | unsigned char *ogm_buff = hard_iface->bat_iv.ogm_buff; |
Marek Lindner | c322939 | 2012-03-11 06:17:50 +0800 | [diff] [blame] | 400 | |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 401 | batadv_ogm_packet = (struct batadv_ogm_packet *)ogm_buff; |
Simon Wunderlich | a40d9b0 | 2013-12-02 20:38:31 +0100 | [diff] [blame] | 402 | batadv_ogm_packet->ttl = BATADV_TTL; |
Marek Lindner | c322939 | 2012-03-11 06:17:50 +0800 | [diff] [blame] | 403 | } |
| 404 | |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 405 | /* when do we schedule our own ogm to be sent */ |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 406 | static unsigned long |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 407 | batadv_iv_ogm_emit_send_time(const struct batadv_priv *bat_priv) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 408 | { |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 409 | unsigned int msecs; |
| 410 | |
| 411 | msecs = atomic_read(&bat_priv->orig_interval) - BATADV_JITTER; |
Akinobu Mita | e76e432 | 2012-12-24 11:14:07 +0900 | [diff] [blame] | 412 | msecs += prandom_u32() % (2 * BATADV_JITTER); |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 413 | |
| 414 | return jiffies + msecs_to_jiffies(msecs); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | /* when do we schedule a ogm packet to be sent */ |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 418 | static unsigned long batadv_iv_ogm_fwd_send_time(void) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 419 | { |
Akinobu Mita | e76e432 | 2012-12-24 11:14:07 +0900 | [diff] [blame] | 420 | return jiffies + msecs_to_jiffies(prandom_u32() % (BATADV_JITTER / 2)); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | /* apply hop penalty for a normal link */ |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 424 | 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] | 425 | { |
| 426 | int hop_penalty = atomic_read(&bat_priv->hop_penalty); |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 427 | int new_tq; |
| 428 | |
| 429 | new_tq = tq * (BATADV_TQ_MAX_VALUE - hop_penalty); |
| 430 | new_tq /= BATADV_TQ_MAX_VALUE; |
| 431 | |
| 432 | return new_tq; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 433 | } |
| 434 | |
Simon Wunderlich | 600184b | 2015-11-23 19:57:21 +0100 | [diff] [blame] | 435 | /** |
| 436 | * batadv_iv_ogm_aggr_packet - checks if there is another OGM attached |
| 437 | * @buff_pos: current position in the skb |
| 438 | * @packet_len: total length of the skb |
| 439 | * @tvlv_len: tvlv length of the previously considered OGM |
| 440 | * |
| 441 | * Return: true if there is enough space for another OGM, false otherwise. |
| 442 | */ |
Markus Pargmann | 9fd9b19 | 2014-12-26 12:41:27 +0100 | [diff] [blame] | 443 | static bool batadv_iv_ogm_aggr_packet(int buff_pos, int packet_len, |
| 444 | __be16 tvlv_len) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 445 | { |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 446 | int next_buff_pos = 0; |
| 447 | |
Sven Eckelmann | 7e071c7 | 2012-06-03 22:19:13 +0200 | [diff] [blame] | 448 | next_buff_pos += buff_pos + BATADV_OGM_HLEN; |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 449 | next_buff_pos += ntohs(tvlv_len); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 450 | |
| 451 | return (next_buff_pos <= packet_len) && |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 452 | (next_buff_pos <= BATADV_MAX_AGGREGATION_BYTES); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 453 | } |
| 454 | |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 455 | /* send a batman ogm to a given interface */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 456 | static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet, |
| 457 | struct batadv_hard_iface *hard_iface) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 458 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 459 | struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); |
Markus Pargmann | de12bae | 2014-12-26 12:41:28 +0100 | [diff] [blame] | 460 | const char *fwd_str; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 461 | u8 packet_num; |
| 462 | s16 buff_pos; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 463 | struct batadv_ogm_packet *batadv_ogm_packet; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 464 | struct sk_buff *skb; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 465 | u8 *packet_pos; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 466 | |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 467 | if (hard_iface->if_status != BATADV_IF_ACTIVE) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 468 | return; |
| 469 | |
| 470 | packet_num = 0; |
| 471 | buff_pos = 0; |
Sven Eckelmann | c67893d | 2012-07-08 18:33:51 +0200 | [diff] [blame] | 472 | packet_pos = forw_packet->skb->data; |
| 473 | batadv_ogm_packet = (struct batadv_ogm_packet *)packet_pos; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 474 | |
| 475 | /* adjust all flags and log packets */ |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 476 | while (batadv_iv_ogm_aggr_packet(buff_pos, forw_packet->packet_len, |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 477 | batadv_ogm_packet->tvlv_len)) { |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 478 | /* we might have aggregated direct link packets with an |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 479 | * ordinary base packet |
| 480 | */ |
Sven Eckelmann | 8de47de | 2012-07-08 16:32:09 +0200 | [diff] [blame] | 481 | if (forw_packet->direct_link_flags & BIT(packet_num) && |
| 482 | forw_packet->if_incoming == hard_iface) |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 483 | batadv_ogm_packet->flags |= BATADV_DIRECTLINK; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 484 | else |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 485 | batadv_ogm_packet->flags &= ~BATADV_DIRECTLINK; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 486 | |
Sven Eckelmann | c67893d | 2012-07-08 18:33:51 +0200 | [diff] [blame] | 487 | if (packet_num > 0 || !forw_packet->own) |
| 488 | fwd_str = "Forwarding"; |
| 489 | else |
| 490 | fwd_str = "Sending own"; |
| 491 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 492 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 493 | "%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] | 494 | fwd_str, (packet_num > 0 ? "aggregated " : ""), |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 495 | batadv_ogm_packet->orig, |
| 496 | ntohl(batadv_ogm_packet->seqno), |
Simon Wunderlich | a40d9b0 | 2013-12-02 20:38:31 +0100 | [diff] [blame] | 497 | batadv_ogm_packet->tq, batadv_ogm_packet->ttl, |
Sven Eckelmann | a2f2b6c | 2015-04-23 18:22:24 +0200 | [diff] [blame] | 498 | ((batadv_ogm_packet->flags & BATADV_DIRECTLINK) ? |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 499 | "on" : "off"), |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 500 | hard_iface->net_dev->name, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 501 | hard_iface->net_dev->dev_addr); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 502 | |
Sven Eckelmann | 7e071c7 | 2012-06-03 22:19:13 +0200 | [diff] [blame] | 503 | buff_pos += BATADV_OGM_HLEN; |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 504 | buff_pos += ntohs(batadv_ogm_packet->tvlv_len); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 505 | packet_num++; |
Sven Eckelmann | c67893d | 2012-07-08 18:33:51 +0200 | [diff] [blame] | 506 | packet_pos = forw_packet->skb->data + buff_pos; |
| 507 | batadv_ogm_packet = (struct batadv_ogm_packet *)packet_pos; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | /* create clone because function is called more than once */ |
| 511 | skb = skb_clone(forw_packet->skb, GFP_ATOMIC); |
Martin Hundebøll | f821486 | 2012-04-20 17:02:45 +0200 | [diff] [blame] | 512 | if (skb) { |
Sven Eckelmann | d69909d | 2012-06-03 22:19:20 +0200 | [diff] [blame] | 513 | batadv_inc_counter(bat_priv, BATADV_CNT_MGMT_TX); |
| 514 | batadv_add_counter(bat_priv, BATADV_CNT_MGMT_TX_BYTES, |
Martin Hundebøll | f821486 | 2012-04-20 17:02:45 +0200 | [diff] [blame] | 515 | skb->len + ETH_HLEN); |
Antonio Quartulli | 95d3927 | 2016-01-16 16:40:15 +0800 | [diff] [blame] | 516 | batadv_send_broadcast_skb(skb, hard_iface); |
Martin Hundebøll | f821486 | 2012-04-20 17:02:45 +0200 | [diff] [blame] | 517 | } |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | /* send a batman ogm packet */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 521 | static void batadv_iv_ogm_emit(struct batadv_forw_packet *forw_packet) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 522 | { |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 523 | struct net_device *soft_iface; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 524 | struct batadv_priv *bat_priv; |
| 525 | struct batadv_hard_iface *primary_if = NULL; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 526 | |
| 527 | if (!forw_packet->if_incoming) { |
Sven Eckelmann | 86ceb36 | 2012-03-07 09:07:45 +0100 | [diff] [blame] | 528 | pr_err("Error - can't forward packet: incoming iface not specified\n"); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 529 | goto out; |
| 530 | } |
| 531 | |
| 532 | soft_iface = forw_packet->if_incoming->soft_iface; |
| 533 | bat_priv = netdev_priv(soft_iface); |
| 534 | |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 535 | if (WARN_ON(!forw_packet->if_outgoing)) |
| 536 | goto out; |
| 537 | |
| 538 | if (WARN_ON(forw_packet->if_outgoing->soft_iface != soft_iface)) |
| 539 | goto out; |
| 540 | |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 541 | if (forw_packet->if_incoming->if_status != BATADV_IF_ACTIVE) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 542 | goto out; |
| 543 | |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 544 | primary_if = batadv_primary_if_get_selected(bat_priv); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 545 | if (!primary_if) |
| 546 | goto out; |
| 547 | |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 548 | /* only for one specific outgoing interface */ |
| 549 | batadv_iv_ogm_send_to_if(forw_packet, forw_packet->if_outgoing); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 550 | |
| 551 | out: |
| 552 | if (primary_if) |
Sven Eckelmann | 82047ad | 2016-01-17 11:01:10 +0100 | [diff] [blame] | 553 | batadv_hardif_put(primary_if); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 554 | } |
| 555 | |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 556 | /** |
| 557 | * batadv_iv_ogm_can_aggregate - find out if an OGM can be aggregated on an |
| 558 | * existing forward packet |
| 559 | * @new_bat_ogm_packet: OGM packet to be aggregated |
| 560 | * @bat_priv: the bat priv with all the soft interface information |
| 561 | * @packet_len: (total) length of the OGM |
| 562 | * @send_time: timestamp (jiffies) when the packet is to be sent |
Martin Hundebøll | 95298a9 | 2014-07-15 09:41:05 +0200 | [diff] [blame] | 563 | * @directlink: true if this is a direct link packet |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 564 | * @if_incoming: interface where the packet was received |
| 565 | * @if_outgoing: interface for which the retransmission should be considered |
| 566 | * @forw_packet: the forwarded packet which should be checked |
| 567 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 568 | * Return: true if new_packet can be aggregated with forw_packet |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 569 | */ |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 570 | static bool |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 571 | 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] | 572 | struct batadv_priv *bat_priv, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 573 | int packet_len, unsigned long send_time, |
| 574 | bool directlink, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 575 | const struct batadv_hard_iface *if_incoming, |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 576 | const struct batadv_hard_iface *if_outgoing, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 577 | const struct batadv_forw_packet *forw_packet) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 578 | { |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 579 | struct batadv_ogm_packet *batadv_ogm_packet; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 580 | int aggregated_bytes = forw_packet->packet_len + packet_len; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 581 | struct batadv_hard_iface *primary_if = NULL; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 582 | bool res = false; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 583 | unsigned long aggregation_end_time; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 584 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 585 | batadv_ogm_packet = (struct batadv_ogm_packet *)forw_packet->skb->data; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 586 | aggregation_end_time = send_time; |
| 587 | aggregation_end_time += msecs_to_jiffies(BATADV_MAX_AGGREGATION_MS); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 588 | |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 589 | /* we can aggregate the current packet to this aggregated packet |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 590 | * if: |
| 591 | * |
| 592 | * - the send time is within our MAX_AGGREGATION_MS time |
| 593 | * - the resulting packet wont be bigger than |
| 594 | * MAX_AGGREGATION_BYTES |
Markus Pargmann | 8f34b38 | 2014-12-26 12:41:29 +0100 | [diff] [blame] | 595 | * otherwise aggregation is not possible |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 596 | */ |
Markus Pargmann | 8f34b38 | 2014-12-26 12:41:29 +0100 | [diff] [blame] | 597 | if (!time_before(send_time, forw_packet->send_time) || |
| 598 | !time_after_eq(aggregation_end_time, forw_packet->send_time)) |
| 599 | return false; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 600 | |
Markus Pargmann | 8f34b38 | 2014-12-26 12:41:29 +0100 | [diff] [blame] | 601 | if (aggregated_bytes > BATADV_MAX_AGGREGATION_BYTES) |
| 602 | return false; |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 603 | |
Markus Pargmann | 8f34b38 | 2014-12-26 12:41:29 +0100 | [diff] [blame] | 604 | /* packet is not leaving on the same interface. */ |
| 605 | if (forw_packet->if_outgoing != if_outgoing) |
| 606 | return false; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 607 | |
Markus Pargmann | 8f34b38 | 2014-12-26 12:41:29 +0100 | [diff] [blame] | 608 | /* check aggregation compatibility |
| 609 | * -> direct link packets are broadcasted on |
| 610 | * their interface only |
| 611 | * -> aggregate packet if the current packet is |
| 612 | * a "global" packet as well as the base |
| 613 | * packet |
| 614 | */ |
| 615 | primary_if = batadv_primary_if_get_selected(bat_priv); |
| 616 | if (!primary_if) |
| 617 | return false; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 618 | |
Markus Pargmann | 8f34b38 | 2014-12-26 12:41:29 +0100 | [diff] [blame] | 619 | /* packets without direct link flag and high TTL |
| 620 | * are flooded through the net |
| 621 | */ |
| 622 | if (!directlink && |
| 623 | !(batadv_ogm_packet->flags & BATADV_DIRECTLINK) && |
| 624 | batadv_ogm_packet->ttl != 1 && |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 625 | |
Markus Pargmann | 8f34b38 | 2014-12-26 12:41:29 +0100 | [diff] [blame] | 626 | /* own packets originating non-primary |
| 627 | * interfaces leave only that interface |
| 628 | */ |
| 629 | (!forw_packet->own || |
| 630 | forw_packet->if_incoming == primary_if)) { |
| 631 | res = true; |
| 632 | goto out; |
| 633 | } |
| 634 | |
| 635 | /* if the incoming packet is sent via this one |
| 636 | * interface only - we still can aggregate |
| 637 | */ |
| 638 | if (directlink && |
| 639 | new_bat_ogm_packet->ttl == 1 && |
| 640 | forw_packet->if_incoming == if_incoming && |
| 641 | |
| 642 | /* packets from direct neighbors or |
| 643 | * own secondary interface packets |
| 644 | * (= secondary interface packets in general) |
| 645 | */ |
| 646 | (batadv_ogm_packet->flags & BATADV_DIRECTLINK || |
| 647 | (forw_packet->own && |
| 648 | forw_packet->if_incoming != primary_if))) { |
| 649 | res = true; |
| 650 | goto out; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | out: |
| 654 | if (primary_if) |
Sven Eckelmann | 82047ad | 2016-01-17 11:01:10 +0100 | [diff] [blame] | 655 | batadv_hardif_put(primary_if); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 656 | return res; |
| 657 | } |
| 658 | |
Simon Wunderlich | 1b371d1 | 2014-01-15 21:17:54 +0100 | [diff] [blame] | 659 | /** |
| 660 | * 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] | 661 | * packet to it. |
| 662 | * @packet_buff: pointer to the OGM |
| 663 | * @packet_len: (total) length of the OGM |
| 664 | * @send_time: timestamp (jiffies) when the packet is to be sent |
| 665 | * @direct_link: whether this OGM has direct link status |
| 666 | * @if_incoming: interface where the packet was received |
| 667 | * @if_outgoing: interface for which the retransmission should be considered |
| 668 | * @own_packet: true if it is a self-generated ogm |
| 669 | */ |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 670 | static void batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff, |
| 671 | int packet_len, unsigned long send_time, |
| 672 | bool direct_link, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 673 | struct batadv_hard_iface *if_incoming, |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 674 | struct batadv_hard_iface *if_outgoing, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 675 | int own_packet) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 676 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 677 | struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface); |
| 678 | struct batadv_forw_packet *forw_packet_aggr; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 679 | unsigned char *skb_buff; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 680 | unsigned int skb_size; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 681 | |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 682 | /* own packet should always be scheduled */ |
| 683 | if (!own_packet) { |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 684 | if (!batadv_atomic_dec_not_zero(&bat_priv->batman_queue_left)) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 685 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 686 | "batman packet queue full\n"); |
Sven Eckelmann | 17a8691 | 2016-04-11 13:06:40 +0200 | [diff] [blame] | 687 | return; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 688 | } |
| 689 | } |
| 690 | |
| 691 | forw_packet_aggr = kmalloc(sizeof(*forw_packet_aggr), GFP_ATOMIC); |
Markus Pargmann | 940d156 | 2014-12-26 12:41:31 +0100 | [diff] [blame] | 692 | if (!forw_packet_aggr) |
| 693 | goto out_nomem; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 694 | |
Markus Pargmann | 940d156 | 2014-12-26 12:41:31 +0100 | [diff] [blame] | 695 | if (atomic_read(&bat_priv->aggregated_ogms) && |
| 696 | packet_len < BATADV_MAX_AGGREGATION_BYTES) |
Sven Eckelmann | 5b24657 | 2012-11-04 17:11:45 +0100 | [diff] [blame] | 697 | skb_size = BATADV_MAX_AGGREGATION_BYTES; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 698 | else |
Sven Eckelmann | 5b24657 | 2012-11-04 17:11:45 +0100 | [diff] [blame] | 699 | skb_size = packet_len; |
| 700 | |
Antonio Quartulli | 41ab6c4 | 2013-04-02 22:28:44 +0200 | [diff] [blame] | 701 | skb_size += ETH_HLEN; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 702 | |
Antonio Quartulli | 41ab6c4 | 2013-04-02 22:28:44 +0200 | [diff] [blame] | 703 | forw_packet_aggr->skb = netdev_alloc_skb_ip_align(NULL, skb_size); |
Markus Pargmann | 940d156 | 2014-12-26 12:41:31 +0100 | [diff] [blame] | 704 | if (!forw_packet_aggr->skb) |
| 705 | goto out_free_forw_packet; |
Simon Wunderlich | c54f38c | 2013-07-29 17:56:44 +0200 | [diff] [blame] | 706 | forw_packet_aggr->skb->priority = TC_PRIO_CONTROL; |
Antonio Quartulli | 41ab6c4 | 2013-04-02 22:28:44 +0200 | [diff] [blame] | 707 | skb_reserve(forw_packet_aggr->skb, ETH_HLEN); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 708 | |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 709 | skb_buff = skb_put(forw_packet_aggr->skb, packet_len); |
| 710 | forw_packet_aggr->packet_len = packet_len; |
| 711 | memcpy(skb_buff, packet_buff, packet_len); |
| 712 | |
Sven Eckelmann | 17a8691 | 2016-04-11 13:06:40 +0200 | [diff] [blame] | 713 | kref_get(&if_incoming->refcount); |
| 714 | kref_get(&if_outgoing->refcount); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 715 | forw_packet_aggr->own = own_packet; |
| 716 | forw_packet_aggr->if_incoming = if_incoming; |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 717 | forw_packet_aggr->if_outgoing = if_outgoing; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 718 | forw_packet_aggr->num_packets = 0; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 719 | forw_packet_aggr->direct_link_flags = BATADV_NO_FLAGS; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 720 | forw_packet_aggr->send_time = send_time; |
| 721 | |
| 722 | /* save packet direct link flag status */ |
| 723 | if (direct_link) |
| 724 | forw_packet_aggr->direct_link_flags |= 1; |
| 725 | |
| 726 | /* add new packet to packet list */ |
| 727 | spin_lock_bh(&bat_priv->forw_bat_list_lock); |
| 728 | hlist_add_head(&forw_packet_aggr->list, &bat_priv->forw_bat_list); |
| 729 | spin_unlock_bh(&bat_priv->forw_bat_list_lock); |
| 730 | |
| 731 | /* start timer for this packet */ |
| 732 | INIT_DELAYED_WORK(&forw_packet_aggr->delayed_work, |
Sven Eckelmann | 9455e34 | 2012-05-12 02:09:37 +0200 | [diff] [blame] | 733 | batadv_send_outstanding_bat_ogm_packet); |
Sven Eckelmann | 3193e8f | 2012-05-12 02:09:42 +0200 | [diff] [blame] | 734 | queue_delayed_work(batadv_event_workqueue, |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 735 | &forw_packet_aggr->delayed_work, |
| 736 | send_time - jiffies); |
| 737 | |
| 738 | return; |
Markus Pargmann | 940d156 | 2014-12-26 12:41:31 +0100 | [diff] [blame] | 739 | out_free_forw_packet: |
| 740 | kfree(forw_packet_aggr); |
| 741 | out_nomem: |
| 742 | if (!own_packet) |
| 743 | atomic_inc(&bat_priv->batman_queue_left); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | /* aggregate a new packet into the existing ogm packet */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 747 | 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] | 748 | const unsigned char *packet_buff, |
| 749 | int packet_len, bool direct_link) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 750 | { |
| 751 | unsigned char *skb_buff; |
Sven Eckelmann | 8de47de | 2012-07-08 16:32:09 +0200 | [diff] [blame] | 752 | unsigned long new_direct_link_flag; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 753 | |
| 754 | skb_buff = skb_put(forw_packet_aggr->skb, packet_len); |
| 755 | memcpy(skb_buff, packet_buff, packet_len); |
| 756 | forw_packet_aggr->packet_len += packet_len; |
| 757 | forw_packet_aggr->num_packets++; |
| 758 | |
| 759 | /* save packet direct link flag status */ |
Sven Eckelmann | 8de47de | 2012-07-08 16:32:09 +0200 | [diff] [blame] | 760 | if (direct_link) { |
| 761 | new_direct_link_flag = BIT(forw_packet_aggr->num_packets); |
| 762 | forw_packet_aggr->direct_link_flags |= new_direct_link_flag; |
| 763 | } |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 764 | } |
| 765 | |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 766 | /** |
| 767 | * batadv_iv_ogm_queue_add - queue up an OGM for transmission |
| 768 | * @bat_priv: the bat priv with all the soft interface information |
| 769 | * @packet_buff: pointer to the OGM |
| 770 | * @packet_len: (total) length of the OGM |
| 771 | * @if_incoming: interface where the packet was received |
| 772 | * @if_outgoing: interface for which the retransmission should be considered |
| 773 | * @own_packet: true if it is a self-generated ogm |
| 774 | * @send_time: timestamp (jiffies) when the packet is to be sent |
| 775 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 776 | static void batadv_iv_ogm_queue_add(struct batadv_priv *bat_priv, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 777 | unsigned char *packet_buff, |
| 778 | int packet_len, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 779 | struct batadv_hard_iface *if_incoming, |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 780 | struct batadv_hard_iface *if_outgoing, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 781 | int own_packet, unsigned long send_time) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 782 | { |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 783 | /* _aggr -> pointer to the packet we want to aggregate with |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 784 | * _pos -> pointer to the position in the queue |
| 785 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 786 | struct batadv_forw_packet *forw_packet_aggr = NULL; |
| 787 | struct batadv_forw_packet *forw_packet_pos = NULL; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 788 | struct batadv_ogm_packet *batadv_ogm_packet; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 789 | bool direct_link; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 790 | unsigned long max_aggregation_jiffies; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 791 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 792 | batadv_ogm_packet = (struct batadv_ogm_packet *)packet_buff; |
Markus Pargmann | 5648915 | 2014-12-26 12:41:32 +0100 | [diff] [blame] | 793 | direct_link = !!(batadv_ogm_packet->flags & BATADV_DIRECTLINK); |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 794 | max_aggregation_jiffies = msecs_to_jiffies(BATADV_MAX_AGGREGATION_MS); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 795 | |
| 796 | /* find position for the packet in the forward queue */ |
| 797 | spin_lock_bh(&bat_priv->forw_bat_list_lock); |
| 798 | /* own packets are not to be aggregated */ |
Markus Pargmann | 5648915 | 2014-12-26 12:41:32 +0100 | [diff] [blame] | 799 | if (atomic_read(&bat_priv->aggregated_ogms) && !own_packet) { |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 800 | hlist_for_each_entry(forw_packet_pos, |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 801 | &bat_priv->forw_bat_list, list) { |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 802 | if (batadv_iv_ogm_can_aggregate(batadv_ogm_packet, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 803 | bat_priv, packet_len, |
| 804 | send_time, direct_link, |
| 805 | if_incoming, |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 806 | if_outgoing, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 807 | forw_packet_pos)) { |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 808 | forw_packet_aggr = forw_packet_pos; |
| 809 | break; |
| 810 | } |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | /* nothing to aggregate with - either aggregation disabled or no |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 815 | * suitable aggregation packet found |
| 816 | */ |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 817 | if (!forw_packet_aggr) { |
| 818 | /* the following section can run without the lock */ |
| 819 | spin_unlock_bh(&bat_priv->forw_bat_list_lock); |
| 820 | |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 821 | /* if we could not aggregate this packet with one of the others |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 822 | * we hold it back for a while, so that it might be aggregated |
| 823 | * later on |
| 824 | */ |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 825 | if (!own_packet && atomic_read(&bat_priv->aggregated_ogms)) |
| 826 | send_time += max_aggregation_jiffies; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 827 | |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 828 | batadv_iv_ogm_aggregate_new(packet_buff, packet_len, |
| 829 | send_time, direct_link, |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 830 | if_incoming, if_outgoing, |
| 831 | own_packet); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 832 | } else { |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 833 | batadv_iv_ogm_aggregate(forw_packet_aggr, packet_buff, |
| 834 | packet_len, direct_link); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 835 | spin_unlock_bh(&bat_priv->forw_bat_list_lock); |
| 836 | } |
| 837 | } |
| 838 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 839 | static void batadv_iv_ogm_forward(struct batadv_orig_node *orig_node, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 840 | const struct ethhdr *ethhdr, |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 841 | struct batadv_ogm_packet *batadv_ogm_packet, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 842 | bool is_single_hop_neigh, |
| 843 | bool is_from_best_next_hop, |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 844 | struct batadv_hard_iface *if_incoming, |
| 845 | struct batadv_hard_iface *if_outgoing) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 846 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 847 | struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface); |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 848 | u16 tvlv_len; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 849 | |
Simon Wunderlich | a40d9b0 | 2013-12-02 20:38:31 +0100 | [diff] [blame] | 850 | if (batadv_ogm_packet->ttl <= 1) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 851 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, "ttl exceeded\n"); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 852 | return; |
| 853 | } |
| 854 | |
Marek Lindner | 13b2541 | 2012-03-11 06:17:53 +0800 | [diff] [blame] | 855 | if (!is_from_best_next_hop) { |
| 856 | /* Mark the forwarded packet when it is not coming from our |
| 857 | * best next hop. We still need to forward the packet for our |
| 858 | * neighbor link quality detection to work in case the packet |
| 859 | * originated from a single hop neighbor. Otherwise we can |
| 860 | * simply drop the ogm. |
| 861 | */ |
| 862 | if (is_single_hop_neigh) |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 863 | batadv_ogm_packet->flags |= BATADV_NOT_BEST_NEXT_HOP; |
Marek Lindner | 13b2541 | 2012-03-11 06:17:53 +0800 | [diff] [blame] | 864 | else |
| 865 | return; |
| 866 | } |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 867 | |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 868 | tvlv_len = ntohs(batadv_ogm_packet->tvlv_len); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 869 | |
Simon Wunderlich | a40d9b0 | 2013-12-02 20:38:31 +0100 | [diff] [blame] | 870 | batadv_ogm_packet->ttl--; |
Antonio Quartulli | 8fdd015 | 2014-01-22 00:42:11 +0100 | [diff] [blame] | 871 | ether_addr_copy(batadv_ogm_packet->prev_sender, ethhdr->h_source); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 872 | |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 873 | /* apply hop penalty */ |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 874 | batadv_ogm_packet->tq = batadv_hop_penalty(batadv_ogm_packet->tq, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 875 | bat_priv); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 876 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 877 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 878 | "Forwarding packet: tq: %i, ttl: %i\n", |
Simon Wunderlich | a40d9b0 | 2013-12-02 20:38:31 +0100 | [diff] [blame] | 879 | batadv_ogm_packet->tq, batadv_ogm_packet->ttl); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 880 | |
Marek Lindner | 75cd33f | 2012-03-01 15:35:16 +0800 | [diff] [blame] | 881 | if (is_single_hop_neigh) |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 882 | batadv_ogm_packet->flags |= BATADV_DIRECTLINK; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 883 | else |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 884 | batadv_ogm_packet->flags &= ~BATADV_DIRECTLINK; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 885 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 886 | batadv_iv_ogm_queue_add(bat_priv, (unsigned char *)batadv_ogm_packet, |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 887 | BATADV_OGM_HLEN + tvlv_len, |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 888 | if_incoming, if_outgoing, 0, |
| 889 | batadv_iv_ogm_fwd_send_time()); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 890 | } |
| 891 | |
Antonio Quartulli | d989661 | 2013-04-17 17:44:43 +0200 | [diff] [blame] | 892 | /** |
| 893 | * batadv_iv_ogm_slide_own_bcast_window - bitshift own OGM broadcast windows for |
| 894 | * the given interface |
| 895 | * @hard_iface: the interface for which the windows have to be shifted |
| 896 | */ |
| 897 | static void |
| 898 | batadv_iv_ogm_slide_own_bcast_window(struct batadv_hard_iface *hard_iface) |
| 899 | { |
| 900 | struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); |
| 901 | struct batadv_hashtable *hash = bat_priv->orig_hash; |
| 902 | struct hlist_head *head; |
| 903 | struct batadv_orig_node *orig_node; |
| 904 | unsigned long *word; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 905 | u32 i; |
Antonio Quartulli | d989661 | 2013-04-17 17:44:43 +0200 | [diff] [blame] | 906 | size_t word_index; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 907 | u8 *w; |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 908 | int if_num; |
Antonio Quartulli | d989661 | 2013-04-17 17:44:43 +0200 | [diff] [blame] | 909 | |
| 910 | for (i = 0; i < hash->size; i++) { |
| 911 | head = &hash->table[i]; |
| 912 | |
| 913 | rcu_read_lock(); |
| 914 | hlist_for_each_entry_rcu(orig_node, head, hash_entry) { |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 915 | spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock); |
Antonio Quartulli | d989661 | 2013-04-17 17:44:43 +0200 | [diff] [blame] | 916 | word_index = hard_iface->if_num * BATADV_NUM_WORDS; |
Antonio Quartulli | 32db6aa | 2014-09-01 14:37:29 +0200 | [diff] [blame] | 917 | word = &orig_node->bat_iv.bcast_own[word_index]; |
Antonio Quartulli | d989661 | 2013-04-17 17:44:43 +0200 | [diff] [blame] | 918 | |
| 919 | batadv_bit_get_packet(bat_priv, word, 1, 0); |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 920 | if_num = hard_iface->if_num; |
| 921 | w = &orig_node->bat_iv.bcast_own_sum[if_num]; |
Antonio Quartulli | d989661 | 2013-04-17 17:44:43 +0200 | [diff] [blame] | 922 | *w = bitmap_weight(word, BATADV_TQ_LOCAL_WINDOW_SIZE); |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 923 | spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock); |
Antonio Quartulli | d989661 | 2013-04-17 17:44:43 +0200 | [diff] [blame] | 924 | } |
| 925 | rcu_read_unlock(); |
| 926 | } |
| 927 | } |
| 928 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 929 | static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 930 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 931 | struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 932 | unsigned char **ogm_buff = &hard_iface->bat_iv.ogm_buff; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 933 | struct batadv_ogm_packet *batadv_ogm_packet; |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 934 | struct batadv_hard_iface *primary_if, *tmp_hard_iface; |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 935 | int *ogm_buff_len = &hard_iface->bat_iv.ogm_buff_len; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 936 | u32 seqno; |
| 937 | u16 tvlv_len = 0; |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 938 | unsigned long send_time; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 939 | |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 940 | primary_if = batadv_primary_if_get_selected(bat_priv); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 941 | |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 942 | if (hard_iface == primary_if) { |
| 943 | /* tt changes have to be committed before the tvlv data is |
| 944 | * appended as it may alter the tt tvlv container |
| 945 | */ |
| 946 | batadv_tt_local_commit_changes(bat_priv); |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 947 | tvlv_len = batadv_tvlv_container_ogm_append(bat_priv, ogm_buff, |
| 948 | ogm_buff_len, |
| 949 | BATADV_OGM_HLEN); |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 950 | } |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 951 | |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 952 | batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff); |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 953 | batadv_ogm_packet->tvlv_len = htons(tvlv_len); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 954 | |
| 955 | /* change sequence number to network order */ |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 956 | seqno = (u32)atomic_read(&hard_iface->bat_iv.ogm_seqno); |
Sven Eckelmann | bbb1f90 | 2012-07-08 17:13:15 +0200 | [diff] [blame] | 957 | batadv_ogm_packet->seqno = htonl(seqno); |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 958 | atomic_inc(&hard_iface->bat_iv.ogm_seqno); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 959 | |
Antonio Quartulli | d989661 | 2013-04-17 17:44:43 +0200 | [diff] [blame] | 960 | batadv_iv_ogm_slide_own_bcast_window(hard_iface); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 961 | |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 962 | send_time = batadv_iv_ogm_emit_send_time(bat_priv); |
| 963 | |
| 964 | if (hard_iface != primary_if) { |
| 965 | /* OGMs from secondary interfaces are only scheduled on their |
| 966 | * respective interfaces. |
| 967 | */ |
| 968 | batadv_iv_ogm_queue_add(bat_priv, *ogm_buff, *ogm_buff_len, |
| 969 | hard_iface, hard_iface, 1, send_time); |
| 970 | goto out; |
| 971 | } |
| 972 | |
| 973 | /* OGMs from primary interfaces are scheduled on all |
| 974 | * interfaces. |
| 975 | */ |
| 976 | rcu_read_lock(); |
| 977 | list_for_each_entry_rcu(tmp_hard_iface, &batadv_hardif_list, list) { |
| 978 | if (tmp_hard_iface->soft_iface != hard_iface->soft_iface) |
Sven Eckelmann | 87b40f5 | 2015-07-17 10:03:42 +0200 | [diff] [blame] | 979 | continue; |
Sven Eckelmann | 2735344 | 2016-03-05 16:09:16 +0100 | [diff] [blame] | 980 | |
| 981 | if (!kref_get_unless_zero(&tmp_hard_iface->refcount)) |
| 982 | continue; |
| 983 | |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 984 | batadv_iv_ogm_queue_add(bat_priv, *ogm_buff, |
| 985 | *ogm_buff_len, hard_iface, |
| 986 | tmp_hard_iface, 1, send_time); |
Sven Eckelmann | 2735344 | 2016-03-05 16:09:16 +0100 | [diff] [blame] | 987 | |
| 988 | batadv_hardif_put(tmp_hard_iface); |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 989 | } |
| 990 | rcu_read_unlock(); |
| 991 | |
| 992 | out: |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 993 | if (primary_if) |
Sven Eckelmann | 82047ad | 2016-01-17 11:01:10 +0100 | [diff] [blame] | 994 | batadv_hardif_put(primary_if); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 995 | } |
| 996 | |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 997 | /** |
| 998 | * batadv_iv_ogm_orig_update - use OGM to update corresponding data in an |
| 999 | * originator |
| 1000 | * @bat_priv: the bat priv with all the soft interface information |
| 1001 | * @orig_node: the orig node who originally emitted the ogm packet |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1002 | * @orig_ifinfo: ifinfo for the outgoing interface of the orig_node |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1003 | * @ethhdr: Ethernet header of the OGM |
| 1004 | * @batadv_ogm_packet: the ogm packet |
| 1005 | * @if_incoming: interface where the packet was received |
| 1006 | * @if_outgoing: interface for which the retransmission should be considered |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1007 | * @dup_status: the duplicate status of this ogm packet. |
| 1008 | */ |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 1009 | static void |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1010 | batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv, |
| 1011 | struct batadv_orig_node *orig_node, |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1012 | struct batadv_orig_ifinfo *orig_ifinfo, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 1013 | const struct ethhdr *ethhdr, |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1014 | const struct batadv_ogm_packet *batadv_ogm_packet, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1015 | struct batadv_hard_iface *if_incoming, |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1016 | struct batadv_hard_iface *if_outgoing, |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1017 | enum batadv_dup_status dup_status) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1018 | { |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1019 | struct batadv_neigh_ifinfo *neigh_ifinfo = NULL; |
| 1020 | struct batadv_neigh_ifinfo *router_ifinfo = NULL; |
Sven Eckelmann | 4f248cf | 2015-06-09 20:50:49 +0200 | [diff] [blame] | 1021 | struct batadv_neigh_node *neigh_node = NULL; |
| 1022 | struct batadv_neigh_node *tmp_neigh_node = NULL; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1023 | struct batadv_neigh_node *router = NULL; |
| 1024 | struct batadv_orig_node *orig_node_tmp; |
Linus Lüssing | 7caf69f | 2012-09-18 03:01:08 +0200 | [diff] [blame] | 1025 | int if_num; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 1026 | u8 sum_orig, sum_neigh; |
| 1027 | u8 *neigh_addr; |
| 1028 | u8 tq_avg; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1029 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1030 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1031 | "update_originator(): Searching and updating originator entry of received packet\n"); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1032 | |
| 1033 | rcu_read_lock(); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1034 | hlist_for_each_entry_rcu(tmp_neigh_node, |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1035 | &orig_node->neigh_list, list) { |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1036 | neigh_addr = tmp_neigh_node->addr; |
| 1037 | if (batadv_compare_eth(neigh_addr, ethhdr->h_source) && |
| 1038 | tmp_neigh_node->if_incoming == if_incoming && |
Sven Eckelmann | 77ae32e | 2016-01-16 10:29:53 +0100 | [diff] [blame] | 1039 | kref_get_unless_zero(&tmp_neigh_node->refcount)) { |
Antonio Quartulli | 38dc40e | 2013-03-30 17:22:00 +0100 | [diff] [blame] | 1040 | if (WARN(neigh_node, "too many matching neigh_nodes")) |
Sven Eckelmann | 25bb250 | 2016-01-17 11:01:11 +0100 | [diff] [blame] | 1041 | batadv_neigh_node_put(neigh_node); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1042 | neigh_node = tmp_neigh_node; |
| 1043 | continue; |
| 1044 | } |
| 1045 | |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1046 | if (dup_status != BATADV_NO_DUP) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1047 | continue; |
| 1048 | |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1049 | /* only update the entry for this outgoing interface */ |
| 1050 | neigh_ifinfo = batadv_neigh_ifinfo_get(tmp_neigh_node, |
| 1051 | if_outgoing); |
| 1052 | if (!neigh_ifinfo) |
| 1053 | continue; |
| 1054 | |
| 1055 | spin_lock_bh(&tmp_neigh_node->ifinfo_lock); |
| 1056 | batadv_ring_buffer_set(neigh_ifinfo->bat_iv.tq_recv, |
| 1057 | &neigh_ifinfo->bat_iv.tq_index, 0); |
| 1058 | tq_avg = batadv_ring_buffer_avg(neigh_ifinfo->bat_iv.tq_recv); |
| 1059 | neigh_ifinfo->bat_iv.tq_avg = tq_avg; |
| 1060 | spin_unlock_bh(&tmp_neigh_node->ifinfo_lock); |
| 1061 | |
Sven Eckelmann | 044fa3a | 2016-01-17 11:01:12 +0100 | [diff] [blame] | 1062 | batadv_neigh_ifinfo_put(neigh_ifinfo); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1063 | neigh_ifinfo = NULL; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1064 | } |
| 1065 | |
| 1066 | if (!neigh_node) { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1067 | struct batadv_orig_node *orig_tmp; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1068 | |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 1069 | orig_tmp = batadv_iv_ogm_orig_get(bat_priv, ethhdr->h_source); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1070 | if (!orig_tmp) |
| 1071 | goto unlock; |
| 1072 | |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 1073 | neigh_node = batadv_iv_ogm_neigh_new(if_incoming, |
| 1074 | ethhdr->h_source, |
Antonio Quartulli | 863dd7a | 2013-03-25 13:49:46 +0100 | [diff] [blame] | 1075 | orig_node, orig_tmp); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1076 | |
Sven Eckelmann | 5d96731 | 2016-01-17 11:01:09 +0100 | [diff] [blame] | 1077 | batadv_orig_node_put(orig_tmp); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1078 | if (!neigh_node) |
| 1079 | goto unlock; |
Markus Pargmann | 23badd6 | 2014-12-26 12:41:33 +0100 | [diff] [blame] | 1080 | } else { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1081 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1082 | "Updating existing last-hop neighbor of originator\n"); |
Markus Pargmann | 23badd6 | 2014-12-26 12:41:33 +0100 | [diff] [blame] | 1083 | } |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1084 | |
| 1085 | rcu_read_unlock(); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1086 | neigh_ifinfo = batadv_neigh_ifinfo_new(neigh_node, if_outgoing); |
| 1087 | if (!neigh_ifinfo) |
| 1088 | goto out; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1089 | |
Marek Lindner | d7b2a97 | 2012-03-01 15:35:19 +0800 | [diff] [blame] | 1090 | neigh_node->last_seen = jiffies; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1091 | |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1092 | spin_lock_bh(&neigh_node->ifinfo_lock); |
| 1093 | batadv_ring_buffer_set(neigh_ifinfo->bat_iv.tq_recv, |
| 1094 | &neigh_ifinfo->bat_iv.tq_index, |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1095 | batadv_ogm_packet->tq); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1096 | tq_avg = batadv_ring_buffer_avg(neigh_ifinfo->bat_iv.tq_recv); |
| 1097 | neigh_ifinfo->bat_iv.tq_avg = tq_avg; |
| 1098 | spin_unlock_bh(&neigh_node->ifinfo_lock); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1099 | |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1100 | if (dup_status == BATADV_NO_DUP) { |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1101 | orig_ifinfo->last_ttl = batadv_ogm_packet->ttl; |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1102 | neigh_ifinfo->last_ttl = batadv_ogm_packet->ttl; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1103 | } |
| 1104 | |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1105 | /* if this neighbor already is our next hop there is nothing |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1106 | * to change |
| 1107 | */ |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1108 | router = batadv_orig_router_get(orig_node, if_outgoing); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1109 | if (router == neigh_node) |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 1110 | goto out; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1111 | |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1112 | if (router) { |
| 1113 | router_ifinfo = batadv_neigh_ifinfo_get(router, if_outgoing); |
| 1114 | if (!router_ifinfo) |
| 1115 | goto out; |
| 1116 | |
| 1117 | /* if this neighbor does not offer a better TQ we won't |
| 1118 | * consider it |
| 1119 | */ |
| 1120 | if (router_ifinfo->bat_iv.tq_avg > neigh_ifinfo->bat_iv.tq_avg) |
| 1121 | goto out; |
| 1122 | } |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1123 | |
| 1124 | /* 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] | 1125 | * won't consider it either |
| 1126 | */ |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1127 | if (router_ifinfo && |
Markus Pargmann | 01b97a3 | 2014-12-26 12:41:30 +0100 | [diff] [blame] | 1128 | neigh_ifinfo->bat_iv.tq_avg == router_ifinfo->bat_iv.tq_avg) { |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1129 | orig_node_tmp = router->orig_node; |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 1130 | spin_lock_bh(&orig_node_tmp->bat_iv.ogm_cnt_lock); |
Linus Lüssing | 7caf69f | 2012-09-18 03:01:08 +0200 | [diff] [blame] | 1131 | if_num = router->if_incoming->if_num; |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 1132 | sum_orig = orig_node_tmp->bat_iv.bcast_own_sum[if_num]; |
| 1133 | spin_unlock_bh(&orig_node_tmp->bat_iv.ogm_cnt_lock); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1134 | |
| 1135 | orig_node_tmp = neigh_node->orig_node; |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 1136 | spin_lock_bh(&orig_node_tmp->bat_iv.ogm_cnt_lock); |
Linus Lüssing | 7caf69f | 2012-09-18 03:01:08 +0200 | [diff] [blame] | 1137 | if_num = neigh_node->if_incoming->if_num; |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 1138 | sum_neigh = orig_node_tmp->bat_iv.bcast_own_sum[if_num]; |
| 1139 | spin_unlock_bh(&orig_node_tmp->bat_iv.ogm_cnt_lock); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1140 | |
Sven Eckelmann | bbb1f90 | 2012-07-08 17:13:15 +0200 | [diff] [blame] | 1141 | if (sum_orig >= sum_neigh) |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 1142 | goto out; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1143 | } |
| 1144 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1145 | batadv_update_route(bat_priv, orig_node, if_outgoing, neigh_node); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1146 | goto out; |
| 1147 | |
| 1148 | unlock: |
| 1149 | rcu_read_unlock(); |
| 1150 | out: |
| 1151 | if (neigh_node) |
Sven Eckelmann | 25bb250 | 2016-01-17 11:01:11 +0100 | [diff] [blame] | 1152 | batadv_neigh_node_put(neigh_node); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1153 | if (router) |
Sven Eckelmann | 25bb250 | 2016-01-17 11:01:11 +0100 | [diff] [blame] | 1154 | batadv_neigh_node_put(router); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1155 | if (neigh_ifinfo) |
Sven Eckelmann | 044fa3a | 2016-01-17 11:01:12 +0100 | [diff] [blame] | 1156 | batadv_neigh_ifinfo_put(neigh_ifinfo); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1157 | if (router_ifinfo) |
Sven Eckelmann | 044fa3a | 2016-01-17 11:01:12 +0100 | [diff] [blame] | 1158 | batadv_neigh_ifinfo_put(router_ifinfo); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1159 | } |
| 1160 | |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1161 | /** |
| 1162 | * batadv_iv_ogm_calc_tq - calculate tq for current received ogm packet |
| 1163 | * @orig_node: the orig node who originally emitted the ogm packet |
| 1164 | * @orig_neigh_node: the orig node struct of the neighbor who sent the packet |
| 1165 | * @batadv_ogm_packet: the ogm packet |
| 1166 | * @if_incoming: interface where the packet was received |
| 1167 | * @if_outgoing: interface for which the retransmission should be considered |
| 1168 | * |
Sven Eckelmann | 4b426b1 | 2016-02-22 21:02:39 +0100 | [diff] [blame] | 1169 | * Return: true if the link can be considered bidirectional, false otherwise |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1170 | */ |
Sven Eckelmann | 4b426b1 | 2016-02-22 21:02:39 +0100 | [diff] [blame] | 1171 | static bool batadv_iv_ogm_calc_tq(struct batadv_orig_node *orig_node, |
| 1172 | struct batadv_orig_node *orig_neigh_node, |
| 1173 | struct batadv_ogm_packet *batadv_ogm_packet, |
| 1174 | struct batadv_hard_iface *if_incoming, |
| 1175 | struct batadv_hard_iface *if_outgoing) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1176 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1177 | struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface); |
| 1178 | struct batadv_neigh_node *neigh_node = NULL, *tmp_neigh_node; |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1179 | struct batadv_neigh_ifinfo *neigh_ifinfo; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 1180 | u8 total_count; |
| 1181 | u8 orig_eq_count, neigh_rq_count, neigh_rq_inv, tq_own; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 1182 | unsigned int neigh_rq_inv_cube, neigh_rq_max_cube; |
Sven Eckelmann | d285f52 | 2016-02-16 10:47:07 +0100 | [diff] [blame] | 1183 | int if_num; |
| 1184 | unsigned int tq_asym_penalty, inv_asym_penalty; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 1185 | unsigned int combined_tq; |
Sven Eckelmann | d285f52 | 2016-02-16 10:47:07 +0100 | [diff] [blame] | 1186 | unsigned int tq_iface_penalty; |
Sven Eckelmann | 4b426b1 | 2016-02-22 21:02:39 +0100 | [diff] [blame] | 1187 | bool ret = false; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1188 | |
| 1189 | /* find corresponding one hop neighbor */ |
| 1190 | rcu_read_lock(); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1191 | hlist_for_each_entry_rcu(tmp_neigh_node, |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1192 | &orig_neigh_node->neigh_list, list) { |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1193 | if (!batadv_compare_eth(tmp_neigh_node->addr, |
| 1194 | orig_neigh_node->orig)) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1195 | continue; |
| 1196 | |
| 1197 | if (tmp_neigh_node->if_incoming != if_incoming) |
| 1198 | continue; |
| 1199 | |
Sven Eckelmann | 77ae32e | 2016-01-16 10:29:53 +0100 | [diff] [blame] | 1200 | if (!kref_get_unless_zero(&tmp_neigh_node->refcount)) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1201 | continue; |
| 1202 | |
| 1203 | neigh_node = tmp_neigh_node; |
| 1204 | break; |
| 1205 | } |
| 1206 | rcu_read_unlock(); |
| 1207 | |
| 1208 | if (!neigh_node) |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 1209 | neigh_node = batadv_iv_ogm_neigh_new(if_incoming, |
| 1210 | orig_neigh_node->orig, |
| 1211 | orig_neigh_node, |
Antonio Quartulli | 863dd7a | 2013-03-25 13:49:46 +0100 | [diff] [blame] | 1212 | orig_neigh_node); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1213 | |
| 1214 | if (!neigh_node) |
| 1215 | goto out; |
| 1216 | |
Marek Lindner | d7b2a97 | 2012-03-01 15:35:19 +0800 | [diff] [blame] | 1217 | /* if orig_node is direct neighbor update neigh_node last_seen */ |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1218 | if (orig_node == orig_neigh_node) |
Marek Lindner | d7b2a97 | 2012-03-01 15:35:19 +0800 | [diff] [blame] | 1219 | neigh_node->last_seen = jiffies; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1220 | |
Marek Lindner | d7b2a97 | 2012-03-01 15:35:19 +0800 | [diff] [blame] | 1221 | orig_node->last_seen = jiffies; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1222 | |
| 1223 | /* find packet count of corresponding one hop neighbor */ |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 1224 | spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock); |
| 1225 | if_num = if_incoming->if_num; |
| 1226 | 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] | 1227 | neigh_ifinfo = batadv_neigh_ifinfo_new(neigh_node, if_outgoing); |
| 1228 | if (neigh_ifinfo) { |
| 1229 | neigh_rq_count = neigh_ifinfo->bat_iv.real_packet_count; |
Sven Eckelmann | 044fa3a | 2016-01-17 11:01:12 +0100 | [diff] [blame] | 1230 | batadv_neigh_ifinfo_put(neigh_ifinfo); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1231 | } else { |
| 1232 | neigh_rq_count = 0; |
| 1233 | } |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 1234 | spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1235 | |
| 1236 | /* pay attention to not get a value bigger than 100 % */ |
Sven Eckelmann | c67893d | 2012-07-08 18:33:51 +0200 | [diff] [blame] | 1237 | if (orig_eq_count > neigh_rq_count) |
| 1238 | total_count = neigh_rq_count; |
| 1239 | else |
| 1240 | total_count = orig_eq_count; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1241 | |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1242 | /* if we have too few packets (too less data) we set tq_own to zero |
| 1243 | * if we receive too few packets it is not considered bidirectional |
| 1244 | */ |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 1245 | if (total_count < BATADV_TQ_LOCAL_BIDRECT_SEND_MINIMUM || |
| 1246 | neigh_rq_count < BATADV_TQ_LOCAL_BIDRECT_RECV_MINIMUM) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1247 | tq_own = 0; |
| 1248 | else |
| 1249 | /* neigh_node->real_packet_count is never zero as we |
| 1250 | * only purge old information when getting new |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1251 | * information |
| 1252 | */ |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 1253 | tq_own = (BATADV_TQ_MAX_VALUE * total_count) / neigh_rq_count; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1254 | |
Sven Eckelmann | 21a1236 | 2012-03-07 09:07:46 +0100 | [diff] [blame] | 1255 | /* 1 - ((1-x) ** 3), normalized to TQ_MAX_VALUE this does |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1256 | * affect the nearly-symmetric links only a little, but |
| 1257 | * punishes asymmetric links more. This will give a value |
| 1258 | * between 0 and TQ_MAX_VALUE |
| 1259 | */ |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 1260 | neigh_rq_inv = BATADV_TQ_LOCAL_WINDOW_SIZE - neigh_rq_count; |
| 1261 | neigh_rq_inv_cube = neigh_rq_inv * neigh_rq_inv * neigh_rq_inv; |
| 1262 | neigh_rq_max_cube = BATADV_TQ_LOCAL_WINDOW_SIZE * |
| 1263 | BATADV_TQ_LOCAL_WINDOW_SIZE * |
| 1264 | BATADV_TQ_LOCAL_WINDOW_SIZE; |
| 1265 | inv_asym_penalty = BATADV_TQ_MAX_VALUE * neigh_rq_inv_cube; |
| 1266 | inv_asym_penalty /= neigh_rq_max_cube; |
| 1267 | tq_asym_penalty = BATADV_TQ_MAX_VALUE - inv_asym_penalty; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1268 | |
Simon Wunderlich | c039876 | 2013-11-13 19:14:48 +0100 | [diff] [blame] | 1269 | /* penalize if the OGM is forwarded on the same interface. WiFi |
| 1270 | * interfaces and other half duplex devices suffer from throughput |
| 1271 | * drops as they can't send and receive at the same time. |
| 1272 | */ |
| 1273 | tq_iface_penalty = BATADV_TQ_MAX_VALUE; |
| 1274 | if (if_outgoing && (if_incoming == if_outgoing) && |
| 1275 | batadv_is_wifi_netdev(if_outgoing->net_dev)) |
| 1276 | tq_iface_penalty = batadv_hop_penalty(BATADV_TQ_MAX_VALUE, |
| 1277 | bat_priv); |
| 1278 | |
| 1279 | combined_tq = batadv_ogm_packet->tq * |
| 1280 | tq_own * |
| 1281 | tq_asym_penalty * |
| 1282 | tq_iface_penalty; |
| 1283 | combined_tq /= BATADV_TQ_MAX_VALUE * |
| 1284 | BATADV_TQ_MAX_VALUE * |
| 1285 | BATADV_TQ_MAX_VALUE; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1286 | batadv_ogm_packet->tq = combined_tq; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1287 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1288 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Simon Wunderlich | c039876 | 2013-11-13 19:14:48 +0100 | [diff] [blame] | 1289 | "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] | 1290 | orig_node->orig, orig_neigh_node->orig, total_count, |
Simon Wunderlich | c039876 | 2013-11-13 19:14:48 +0100 | [diff] [blame] | 1291 | neigh_rq_count, tq_own, tq_asym_penalty, tq_iface_penalty, |
| 1292 | batadv_ogm_packet->tq, if_incoming->net_dev->name, |
| 1293 | if_outgoing ? if_outgoing->net_dev->name : "DEFAULT"); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1294 | |
| 1295 | /* if link has the minimum required transmission quality |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1296 | * consider it bidirectional |
| 1297 | */ |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1298 | if (batadv_ogm_packet->tq >= BATADV_TQ_TOTAL_BIDRECT_LIMIT) |
Sven Eckelmann | 4b426b1 | 2016-02-22 21:02:39 +0100 | [diff] [blame] | 1299 | ret = true; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1300 | |
| 1301 | out: |
| 1302 | if (neigh_node) |
Sven Eckelmann | 25bb250 | 2016-01-17 11:01:11 +0100 | [diff] [blame] | 1303 | batadv_neigh_node_put(neigh_node); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1304 | return ret; |
| 1305 | } |
| 1306 | |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1307 | /** |
| 1308 | * batadv_iv_ogm_update_seqnos - process a batman packet for all interfaces, |
| 1309 | * adjust the sequence number and find out whether it is a duplicate |
| 1310 | * @ethhdr: ethernet header of the packet |
| 1311 | * @batadv_ogm_packet: OGM packet to be considered |
| 1312 | * @if_incoming: interface on which the OGM packet was received |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1313 | * @if_outgoing: interface for which the retransmission should be considered |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1314 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 1315 | * Return: duplicate status as enum batadv_dup_status |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1316 | */ |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1317 | static enum batadv_dup_status |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 1318 | batadv_iv_ogm_update_seqnos(const struct ethhdr *ethhdr, |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1319 | const struct batadv_ogm_packet *batadv_ogm_packet, |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1320 | const struct batadv_hard_iface *if_incoming, |
| 1321 | struct batadv_hard_iface *if_outgoing) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1322 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1323 | struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface); |
| 1324 | struct batadv_orig_node *orig_node; |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1325 | struct batadv_orig_ifinfo *orig_ifinfo = NULL; |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1326 | struct batadv_neigh_node *neigh_node; |
| 1327 | struct batadv_neigh_ifinfo *neigh_ifinfo; |
Sven Eckelmann | 4b426b1 | 2016-02-22 21:02:39 +0100 | [diff] [blame] | 1328 | bool is_dup; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 1329 | s32 seq_diff; |
Sven Eckelmann | 4b426b1 | 2016-02-22 21:02:39 +0100 | [diff] [blame] | 1330 | bool need_update = false; |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1331 | int set_mark; |
| 1332 | enum batadv_dup_status ret = BATADV_NO_DUP; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 1333 | u32 seqno = ntohl(batadv_ogm_packet->seqno); |
| 1334 | u8 *neigh_addr; |
| 1335 | u8 packet_count; |
Antonio Quartulli | 0538f75 | 2013-09-02 12:15:01 +0200 | [diff] [blame] | 1336 | unsigned long *bitmap; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1337 | |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 1338 | 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] | 1339 | if (!orig_node) |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1340 | return BATADV_NO_DUP; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1341 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1342 | orig_ifinfo = batadv_orig_ifinfo_new(orig_node, if_outgoing); |
| 1343 | if (WARN_ON(!orig_ifinfo)) { |
Sven Eckelmann | 5d96731 | 2016-01-17 11:01:09 +0100 | [diff] [blame] | 1344 | batadv_orig_node_put(orig_node); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1345 | return 0; |
| 1346 | } |
| 1347 | |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 1348 | spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1349 | seq_diff = seqno - orig_ifinfo->last_real_seqno; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1350 | |
| 1351 | /* signalize caller that the packet is to be dropped. */ |
Antonio Quartulli | 1e5cc26 | 2012-02-26 15:39:42 +0100 | [diff] [blame] | 1352 | if (!hlist_empty(&orig_node->neigh_list) && |
Sven Eckelmann | 30d3c51 | 2012-05-12 02:09:36 +0200 | [diff] [blame] | 1353 | batadv_window_protected(bat_priv, seq_diff, |
Simon Wunderlich | 81f0268 | 2015-11-23 19:57:22 +0100 | [diff] [blame] | 1354 | BATADV_TQ_LOCAL_WINDOW_SIZE, |
| 1355 | &orig_ifinfo->batman_seqno_reset, NULL)) { |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1356 | ret = BATADV_PROTECTED; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1357 | goto out; |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1358 | } |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1359 | |
| 1360 | rcu_read_lock(); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1361 | hlist_for_each_entry_rcu(neigh_node, &orig_node->neigh_list, list) { |
| 1362 | neigh_ifinfo = batadv_neigh_ifinfo_new(neigh_node, |
| 1363 | if_outgoing); |
| 1364 | if (!neigh_ifinfo) |
| 1365 | continue; |
| 1366 | |
| 1367 | neigh_addr = neigh_node->addr; |
| 1368 | is_dup = batadv_test_bit(neigh_ifinfo->bat_iv.real_bits, |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1369 | orig_ifinfo->last_real_seqno, |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1370 | seqno); |
| 1371 | |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1372 | if (batadv_compare_eth(neigh_addr, ethhdr->h_source) && |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1373 | neigh_node->if_incoming == if_incoming) { |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1374 | set_mark = 1; |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1375 | if (is_dup) |
| 1376 | ret = BATADV_NEIGH_DUP; |
| 1377 | } else { |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1378 | set_mark = 0; |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1379 | if (is_dup && (ret != BATADV_NEIGH_DUP)) |
| 1380 | ret = BATADV_ORIG_DUP; |
| 1381 | } |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1382 | |
| 1383 | /* if the window moved, set the update flag. */ |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1384 | bitmap = neigh_ifinfo->bat_iv.real_bits; |
Antonio Quartulli | 0538f75 | 2013-09-02 12:15:01 +0200 | [diff] [blame] | 1385 | need_update |= batadv_bit_get_packet(bat_priv, bitmap, |
Sven Eckelmann | 0f5f932 | 2012-05-12 02:09:25 +0200 | [diff] [blame] | 1386 | seq_diff, set_mark); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1387 | |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1388 | packet_count = bitmap_weight(bitmap, |
Sven Eckelmann | bbb1f90 | 2012-07-08 17:13:15 +0200 | [diff] [blame] | 1389 | BATADV_TQ_LOCAL_WINDOW_SIZE); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1390 | neigh_ifinfo->bat_iv.real_packet_count = packet_count; |
Sven Eckelmann | 044fa3a | 2016-01-17 11:01:12 +0100 | [diff] [blame] | 1391 | batadv_neigh_ifinfo_put(neigh_ifinfo); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1392 | } |
| 1393 | rcu_read_unlock(); |
| 1394 | |
| 1395 | if (need_update) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1396 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1397 | "%s updating last_seqno: old %u, new %u\n", |
| 1398 | if_outgoing ? if_outgoing->net_dev->name : "DEFAULT", |
| 1399 | orig_ifinfo->last_real_seqno, seqno); |
| 1400 | orig_ifinfo->last_real_seqno = seqno; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1401 | } |
| 1402 | |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1403 | out: |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 1404 | spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock); |
Sven Eckelmann | 5d96731 | 2016-01-17 11:01:09 +0100 | [diff] [blame] | 1405 | batadv_orig_node_put(orig_node); |
Sven Eckelmann | 35f9477 | 2016-01-17 11:01:13 +0100 | [diff] [blame] | 1406 | batadv_orig_ifinfo_put(orig_ifinfo); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1407 | return ret; |
| 1408 | } |
| 1409 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1410 | /** |
| 1411 | * batadv_iv_ogm_process_per_outif - process a batman iv OGM for an outgoing if |
| 1412 | * @skb: the skb containing the OGM |
Martin Hundebøll | 95298a9 | 2014-07-15 09:41:05 +0200 | [diff] [blame] | 1413 | * @ogm_offset: offset from skb->data to start of ogm header |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1414 | * @orig_node: the (cached) orig node for the originator of this OGM |
| 1415 | * @if_incoming: the interface where this packet was received |
| 1416 | * @if_outgoing: the interface for which the packet should be considered |
| 1417 | */ |
| 1418 | static void |
| 1419 | batadv_iv_ogm_process_per_outif(const struct sk_buff *skb, int ogm_offset, |
| 1420 | struct batadv_orig_node *orig_node, |
| 1421 | struct batadv_hard_iface *if_incoming, |
| 1422 | struct batadv_hard_iface *if_outgoing) |
| 1423 | { |
| 1424 | struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface); |
Marek Lindner | 4ff1e2a | 2015-08-04 21:09:58 +0800 | [diff] [blame] | 1425 | struct batadv_hardif_neigh_node *hardif_neigh = NULL; |
Sven Eckelmann | 4f248cf | 2015-06-09 20:50:49 +0200 | [diff] [blame] | 1426 | struct batadv_neigh_node *router = NULL; |
| 1427 | struct batadv_neigh_node *router_router = NULL; |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1428 | struct batadv_orig_node *orig_neigh_node; |
| 1429 | struct batadv_orig_ifinfo *orig_ifinfo; |
| 1430 | struct batadv_neigh_node *orig_neigh_router = NULL; |
| 1431 | struct batadv_neigh_ifinfo *router_ifinfo = NULL; |
| 1432 | struct batadv_ogm_packet *ogm_packet; |
| 1433 | enum batadv_dup_status dup_status; |
| 1434 | bool is_from_best_next_hop = false; |
| 1435 | bool is_single_hop_neigh = false; |
| 1436 | bool sameseq, similar_ttl; |
| 1437 | struct sk_buff *skb_priv; |
| 1438 | struct ethhdr *ethhdr; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 1439 | u8 *prev_sender; |
Sven Eckelmann | 4b426b1 | 2016-02-22 21:02:39 +0100 | [diff] [blame] | 1440 | bool is_bidirect; |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1441 | |
| 1442 | /* create a private copy of the skb, as some functions change tq value |
| 1443 | * and/or flags. |
| 1444 | */ |
| 1445 | skb_priv = skb_copy(skb, GFP_ATOMIC); |
| 1446 | if (!skb_priv) |
| 1447 | return; |
| 1448 | |
| 1449 | ethhdr = eth_hdr(skb_priv); |
| 1450 | ogm_packet = (struct batadv_ogm_packet *)(skb_priv->data + ogm_offset); |
| 1451 | |
| 1452 | dup_status = batadv_iv_ogm_update_seqnos(ethhdr, ogm_packet, |
| 1453 | if_incoming, if_outgoing); |
| 1454 | if (batadv_compare_eth(ethhdr->h_source, ogm_packet->orig)) |
| 1455 | is_single_hop_neigh = true; |
| 1456 | |
| 1457 | if (dup_status == BATADV_PROTECTED) { |
| 1458 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
| 1459 | "Drop packet: packet within seqno protection time (sender: %pM)\n", |
| 1460 | ethhdr->h_source); |
| 1461 | goto out; |
| 1462 | } |
| 1463 | |
| 1464 | if (ogm_packet->tq == 0) { |
| 1465 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
| 1466 | "Drop packet: originator packet with tq equal 0\n"); |
| 1467 | goto out; |
| 1468 | } |
| 1469 | |
Marek Lindner | 4ff1e2a | 2015-08-04 21:09:58 +0800 | [diff] [blame] | 1470 | if (is_single_hop_neigh) { |
| 1471 | hardif_neigh = batadv_hardif_neigh_get(if_incoming, |
| 1472 | ethhdr->h_source); |
| 1473 | if (hardif_neigh) |
| 1474 | hardif_neigh->last_seen = jiffies; |
| 1475 | } |
| 1476 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1477 | router = batadv_orig_router_get(orig_node, if_outgoing); |
| 1478 | if (router) { |
| 1479 | router_router = batadv_orig_router_get(router->orig_node, |
| 1480 | if_outgoing); |
| 1481 | router_ifinfo = batadv_neigh_ifinfo_get(router, if_outgoing); |
| 1482 | } |
| 1483 | |
| 1484 | if ((router_ifinfo && router_ifinfo->bat_iv.tq_avg != 0) && |
| 1485 | (batadv_compare_eth(router->addr, ethhdr->h_source))) |
| 1486 | is_from_best_next_hop = true; |
| 1487 | |
| 1488 | prev_sender = ogm_packet->prev_sender; |
| 1489 | /* avoid temporary routing loops */ |
| 1490 | if (router && router_router && |
| 1491 | (batadv_compare_eth(router->addr, prev_sender)) && |
| 1492 | !(batadv_compare_eth(ogm_packet->orig, prev_sender)) && |
| 1493 | (batadv_compare_eth(router->addr, router_router->addr))) { |
| 1494 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
| 1495 | "Drop packet: ignoring all rebroadcast packets that may make me loop (sender: %pM)\n", |
| 1496 | ethhdr->h_source); |
| 1497 | goto out; |
| 1498 | } |
| 1499 | |
| 1500 | if (if_outgoing == BATADV_IF_DEFAULT) |
| 1501 | batadv_tvlv_ogm_receive(bat_priv, ogm_packet, orig_node); |
| 1502 | |
| 1503 | /* if sender is a direct neighbor the sender mac equals |
| 1504 | * originator mac |
| 1505 | */ |
| 1506 | if (is_single_hop_neigh) |
| 1507 | orig_neigh_node = orig_node; |
| 1508 | else |
| 1509 | orig_neigh_node = batadv_iv_ogm_orig_get(bat_priv, |
| 1510 | ethhdr->h_source); |
| 1511 | |
| 1512 | if (!orig_neigh_node) |
| 1513 | goto out; |
| 1514 | |
| 1515 | /* Update nc_nodes of the originator */ |
| 1516 | batadv_nc_update_nc_node(bat_priv, orig_node, orig_neigh_node, |
| 1517 | ogm_packet, is_single_hop_neigh); |
| 1518 | |
| 1519 | orig_neigh_router = batadv_orig_router_get(orig_neigh_node, |
| 1520 | if_outgoing); |
| 1521 | |
| 1522 | /* drop packet if sender is not a direct neighbor and if we |
| 1523 | * don't route towards it |
| 1524 | */ |
| 1525 | if (!is_single_hop_neigh && (!orig_neigh_router)) { |
| 1526 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
| 1527 | "Drop packet: OGM via unknown neighbor!\n"); |
| 1528 | goto out_neigh; |
| 1529 | } |
| 1530 | |
| 1531 | is_bidirect = batadv_iv_ogm_calc_tq(orig_node, orig_neigh_node, |
| 1532 | ogm_packet, if_incoming, |
| 1533 | if_outgoing); |
| 1534 | |
| 1535 | /* update ranking if it is not a duplicate or has the same |
| 1536 | * seqno and similar ttl as the non-duplicate |
| 1537 | */ |
| 1538 | orig_ifinfo = batadv_orig_ifinfo_new(orig_node, if_outgoing); |
| 1539 | if (!orig_ifinfo) |
| 1540 | goto out_neigh; |
| 1541 | |
| 1542 | sameseq = orig_ifinfo->last_real_seqno == ntohl(ogm_packet->seqno); |
| 1543 | similar_ttl = (orig_ifinfo->last_ttl - 3) <= ogm_packet->ttl; |
| 1544 | |
| 1545 | if (is_bidirect && ((dup_status == BATADV_NO_DUP) || |
| 1546 | (sameseq && similar_ttl))) { |
| 1547 | batadv_iv_ogm_orig_update(bat_priv, orig_node, |
| 1548 | orig_ifinfo, ethhdr, |
| 1549 | ogm_packet, if_incoming, |
| 1550 | if_outgoing, dup_status); |
| 1551 | } |
Sven Eckelmann | 35f9477 | 2016-01-17 11:01:13 +0100 | [diff] [blame] | 1552 | batadv_orig_ifinfo_put(orig_ifinfo); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1553 | |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 1554 | /* only forward for specific interface, not for the default one. */ |
| 1555 | if (if_outgoing == BATADV_IF_DEFAULT) |
| 1556 | goto out_neigh; |
| 1557 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1558 | /* is single hop (direct) neighbor */ |
| 1559 | if (is_single_hop_neigh) { |
| 1560 | /* OGMs from secondary interfaces should only scheduled once |
| 1561 | * per interface where it has been received, not multiple times |
| 1562 | */ |
| 1563 | if ((ogm_packet->ttl <= 2) && |
| 1564 | (if_incoming != if_outgoing)) { |
| 1565 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
| 1566 | "Drop packet: OGM from secondary interface and wrong outgoing interface\n"); |
| 1567 | goto out_neigh; |
| 1568 | } |
| 1569 | /* mark direct link on incoming interface */ |
| 1570 | batadv_iv_ogm_forward(orig_node, ethhdr, ogm_packet, |
| 1571 | is_single_hop_neigh, |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 1572 | is_from_best_next_hop, if_incoming, |
| 1573 | if_outgoing); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1574 | |
| 1575 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
| 1576 | "Forwarding packet: rebroadcast neighbor packet with direct link flag\n"); |
| 1577 | goto out_neigh; |
| 1578 | } |
| 1579 | |
| 1580 | /* multihop originator */ |
| 1581 | if (!is_bidirect) { |
| 1582 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
| 1583 | "Drop packet: not received via bidirectional link\n"); |
| 1584 | goto out_neigh; |
| 1585 | } |
| 1586 | |
| 1587 | if (dup_status == BATADV_NEIGH_DUP) { |
| 1588 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
| 1589 | "Drop packet: duplicate packet received\n"); |
| 1590 | goto out_neigh; |
| 1591 | } |
| 1592 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1593 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
| 1594 | "Forwarding packet: rebroadcast originator packet\n"); |
| 1595 | batadv_iv_ogm_forward(orig_node, ethhdr, ogm_packet, |
| 1596 | is_single_hop_neigh, is_from_best_next_hop, |
Simon Wunderlich | ef0a937 | 2013-11-13 19:14:49 +0100 | [diff] [blame] | 1597 | if_incoming, if_outgoing); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1598 | |
| 1599 | out_neigh: |
| 1600 | if ((orig_neigh_node) && (!is_single_hop_neigh)) |
Sven Eckelmann | 5d96731 | 2016-01-17 11:01:09 +0100 | [diff] [blame] | 1601 | batadv_orig_node_put(orig_neigh_node); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1602 | out: |
Simon Wunderlich | c1e517f | 2014-03-26 15:46:21 +0100 | [diff] [blame] | 1603 | if (router_ifinfo) |
Sven Eckelmann | 044fa3a | 2016-01-17 11:01:12 +0100 | [diff] [blame] | 1604 | batadv_neigh_ifinfo_put(router_ifinfo); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1605 | if (router) |
Sven Eckelmann | 25bb250 | 2016-01-17 11:01:11 +0100 | [diff] [blame] | 1606 | batadv_neigh_node_put(router); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1607 | if (router_router) |
Sven Eckelmann | 25bb250 | 2016-01-17 11:01:11 +0100 | [diff] [blame] | 1608 | batadv_neigh_node_put(router_router); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1609 | if (orig_neigh_router) |
Sven Eckelmann | 25bb250 | 2016-01-17 11:01:11 +0100 | [diff] [blame] | 1610 | batadv_neigh_node_put(orig_neigh_router); |
Marek Lindner | 4ff1e2a | 2015-08-04 21:09:58 +0800 | [diff] [blame] | 1611 | if (hardif_neigh) |
Sven Eckelmann | accadc3 | 2016-01-17 11:01:14 +0100 | [diff] [blame] | 1612 | batadv_hardif_neigh_put(hardif_neigh); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1613 | |
| 1614 | kfree_skb(skb_priv); |
| 1615 | } |
| 1616 | |
| 1617 | /** |
| 1618 | * batadv_iv_ogm_process - process an incoming batman iv OGM |
| 1619 | * @skb: the skb containing the OGM |
| 1620 | * @ogm_offset: offset to the OGM which should be processed (for aggregates) |
| 1621 | * @if_incoming: the interface where this packet was receved |
| 1622 | */ |
| 1623 | 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] | 1624 | struct batadv_hard_iface *if_incoming) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1625 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1626 | struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1627 | struct batadv_orig_node *orig_neigh_node, *orig_node; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1628 | struct batadv_hard_iface *hard_iface; |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1629 | struct batadv_ogm_packet *ogm_packet; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 1630 | u32 if_incoming_seqno; |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1631 | bool has_directlink_flag; |
| 1632 | struct ethhdr *ethhdr; |
| 1633 | bool is_my_oldorig = false; |
| 1634 | bool is_my_addr = false; |
| 1635 | bool is_my_orig = false; |
| 1636 | |
| 1637 | ogm_packet = (struct batadv_ogm_packet *)(skb->data + ogm_offset); |
| 1638 | ethhdr = eth_hdr(skb); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1639 | |
| 1640 | /* Silently drop when the batman packet is actually not a |
| 1641 | * correct packet. |
| 1642 | * |
| 1643 | * This might happen if a packet is padded (e.g. Ethernet has a |
| 1644 | * minimum frame length of 64 byte) and the aggregation interprets |
| 1645 | * it as an additional length. |
| 1646 | * |
| 1647 | * 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] | 1648 | * batadv_ogm_packet to detect whether the packet is the last |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1649 | * packet in an aggregation. Here we expect that the padding |
| 1650 | * is always zero (or not 0x01) |
| 1651 | */ |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1652 | if (ogm_packet->packet_type != BATADV_IV_OGM) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1653 | return; |
| 1654 | |
| 1655 | /* could be changed by schedule_own_packet() */ |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 1656 | if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1657 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1658 | if (ogm_packet->flags & BATADV_DIRECTLINK) |
| 1659 | has_directlink_flag = true; |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 1660 | else |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1661 | has_directlink_flag = false; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1662 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1663 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 1664 | "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] | 1665 | ethhdr->h_source, if_incoming->net_dev->name, |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1666 | if_incoming->net_dev->dev_addr, ogm_packet->orig, |
| 1667 | ogm_packet->prev_sender, ntohl(ogm_packet->seqno), |
| 1668 | ogm_packet->tq, ogm_packet->ttl, |
| 1669 | ogm_packet->version, has_directlink_flag); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1670 | |
| 1671 | rcu_read_lock(); |
Sven Eckelmann | 3193e8f | 2012-05-12 02:09:42 +0200 | [diff] [blame] | 1672 | list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) { |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 1673 | if (hard_iface->if_status != BATADV_IF_ACTIVE) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1674 | continue; |
| 1675 | |
| 1676 | if (hard_iface->soft_iface != if_incoming->soft_iface) |
| 1677 | continue; |
| 1678 | |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1679 | if (batadv_compare_eth(ethhdr->h_source, |
| 1680 | hard_iface->net_dev->dev_addr)) |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1681 | is_my_addr = true; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1682 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1683 | if (batadv_compare_eth(ogm_packet->orig, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1684 | hard_iface->net_dev->dev_addr)) |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1685 | is_my_orig = true; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1686 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1687 | if (batadv_compare_eth(ogm_packet->prev_sender, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1688 | hard_iface->net_dev->dev_addr)) |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1689 | is_my_oldorig = true; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1690 | } |
| 1691 | rcu_read_unlock(); |
| 1692 | |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1693 | if (is_my_addr) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1694 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1695 | "Drop packet: received my own broadcast (sender: %pM)\n", |
| 1696 | ethhdr->h_source); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1697 | return; |
| 1698 | } |
| 1699 | |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1700 | if (is_my_orig) { |
| 1701 | unsigned long *word; |
| 1702 | int offset; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 1703 | s32 bit_pos; |
| 1704 | s16 if_num; |
| 1705 | u8 *weight; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1706 | |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 1707 | orig_neigh_node = batadv_iv_ogm_orig_get(bat_priv, |
| 1708 | ethhdr->h_source); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1709 | if (!orig_neigh_node) |
| 1710 | return; |
| 1711 | |
| 1712 | /* neighbor has to indicate direct link and it has to |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1713 | * come via the corresponding interface |
| 1714 | * save packet seqno for bidirectional check |
| 1715 | */ |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1716 | if (has_directlink_flag && |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1717 | batadv_compare_eth(if_incoming->net_dev->dev_addr, |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1718 | ogm_packet->orig)) { |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 1719 | if_num = if_incoming->if_num; |
| 1720 | offset = if_num * BATADV_NUM_WORDS; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1721 | |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 1722 | spin_lock_bh(&orig_neigh_node->bat_iv.ogm_cnt_lock); |
Antonio Quartulli | 32db6aa | 2014-09-01 14:37:29 +0200 | [diff] [blame] | 1723 | word = &orig_neigh_node->bat_iv.bcast_own[offset]; |
Sven Eckelmann | 9b4a115 | 2012-05-12 13:48:53 +0200 | [diff] [blame] | 1724 | bit_pos = if_incoming_seqno - 2; |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1725 | bit_pos -= ntohl(ogm_packet->seqno); |
Sven Eckelmann | 9b4a115 | 2012-05-12 13:48:53 +0200 | [diff] [blame] | 1726 | batadv_set_bit(word, bit_pos); |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 1727 | weight = &orig_neigh_node->bat_iv.bcast_own_sum[if_num]; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 1728 | *weight = bitmap_weight(word, |
| 1729 | BATADV_TQ_LOCAL_WINDOW_SIZE); |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 1730 | spin_unlock_bh(&orig_neigh_node->bat_iv.ogm_cnt_lock); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1731 | } |
| 1732 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1733 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1734 | "Drop packet: originator packet from myself (via neighbor)\n"); |
Sven Eckelmann | 5d96731 | 2016-01-17 11:01:09 +0100 | [diff] [blame] | 1735 | batadv_orig_node_put(orig_neigh_node); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1736 | return; |
| 1737 | } |
| 1738 | |
| 1739 | if (is_my_oldorig) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1740 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1741 | "Drop packet: ignoring all rebroadcast echos (sender: %pM)\n", |
| 1742 | ethhdr->h_source); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1743 | return; |
| 1744 | } |
| 1745 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1746 | if (ogm_packet->flags & BATADV_NOT_BEST_NEXT_HOP) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1747 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1748 | "Drop packet: ignoring all packets not forwarded from the best next hop (sender: %pM)\n", |
| 1749 | ethhdr->h_source); |
Marek Lindner | 13b2541 | 2012-03-11 06:17:53 +0800 | [diff] [blame] | 1750 | return; |
| 1751 | } |
| 1752 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1753 | orig_node = batadv_iv_ogm_orig_get(bat_priv, ogm_packet->orig); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1754 | if (!orig_node) |
| 1755 | return; |
| 1756 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1757 | batadv_iv_ogm_process_per_outif(skb, ogm_offset, orig_node, |
| 1758 | if_incoming, BATADV_IF_DEFAULT); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1759 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1760 | rcu_read_lock(); |
| 1761 | list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) { |
| 1762 | if (hard_iface->if_status != BATADV_IF_ACTIVE) |
| 1763 | continue; |
| 1764 | |
| 1765 | if (hard_iface->soft_iface != bat_priv->soft_iface) |
| 1766 | continue; |
| 1767 | |
Sven Eckelmann | 2735344 | 2016-03-05 16:09:16 +0100 | [diff] [blame] | 1768 | if (!kref_get_unless_zero(&hard_iface->refcount)) |
| 1769 | continue; |
| 1770 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1771 | batadv_iv_ogm_process_per_outif(skb, ogm_offset, orig_node, |
| 1772 | if_incoming, hard_iface); |
Sven Eckelmann | 2735344 | 2016-03-05 16:09:16 +0100 | [diff] [blame] | 1773 | |
| 1774 | batadv_hardif_put(hard_iface); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1775 | } |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1776 | rcu_read_unlock(); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1777 | |
Sven Eckelmann | 5d96731 | 2016-01-17 11:01:09 +0100 | [diff] [blame] | 1778 | batadv_orig_node_put(orig_node); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1779 | } |
| 1780 | |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 1781 | static int batadv_iv_ogm_receive(struct sk_buff *skb, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1782 | struct batadv_hard_iface *if_incoming) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1783 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1784 | struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1785 | struct batadv_ogm_packet *ogm_packet; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 1786 | u8 *packet_pos; |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1787 | int ogm_offset; |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 1788 | bool ret; |
Marek Lindner | c3e2931 | 2012-03-04 16:56:25 +0800 | [diff] [blame] | 1789 | |
Sven Eckelmann | 7e071c7 | 2012-06-03 22:19:13 +0200 | [diff] [blame] | 1790 | ret = batadv_check_management_packet(skb, if_incoming, BATADV_OGM_HLEN); |
Marek Lindner | c3e2931 | 2012-03-04 16:56:25 +0800 | [diff] [blame] | 1791 | if (!ret) |
| 1792 | return NET_RX_DROP; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1793 | |
Marek Lindner | edbf12b | 2012-03-11 06:17:49 +0800 | [diff] [blame] | 1794 | /* did we receive a B.A.T.M.A.N. IV OGM packet on an interface |
| 1795 | * that does not have B.A.T.M.A.N. IV enabled ? |
| 1796 | */ |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 1797 | if (bat_priv->bat_algo_ops->bat_ogm_emit != batadv_iv_ogm_emit) |
Marek Lindner | edbf12b | 2012-03-11 06:17:49 +0800 | [diff] [blame] | 1798 | return NET_RX_DROP; |
| 1799 | |
Sven Eckelmann | d69909d | 2012-06-03 22:19:20 +0200 | [diff] [blame] | 1800 | batadv_inc_counter(bat_priv, BATADV_CNT_MGMT_RX); |
| 1801 | batadv_add_counter(bat_priv, BATADV_CNT_MGMT_RX_BYTES, |
Martin Hundebøll | f821486 | 2012-04-20 17:02:45 +0200 | [diff] [blame] | 1802 | skb->len + ETH_HLEN); |
| 1803 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1804 | ogm_offset = 0; |
| 1805 | ogm_packet = (struct batadv_ogm_packet *)skb->data; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1806 | |
| 1807 | /* unpack the aggregated packets and process them one by one */ |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1808 | while (batadv_iv_ogm_aggr_packet(ogm_offset, skb_headlen(skb), |
| 1809 | ogm_packet->tvlv_len)) { |
| 1810 | batadv_iv_ogm_process(skb, ogm_offset, if_incoming); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1811 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1812 | ogm_offset += BATADV_OGM_HLEN; |
| 1813 | ogm_offset += ntohs(ogm_packet->tvlv_len); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1814 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1815 | packet_pos = skb->data + ogm_offset; |
| 1816 | ogm_packet = (struct batadv_ogm_packet *)packet_pos; |
Marek Lindner | b47506d | 2013-03-04 10:39:49 +0800 | [diff] [blame] | 1817 | } |
Marek Lindner | c3e2931 | 2012-03-04 16:56:25 +0800 | [diff] [blame] | 1818 | |
| 1819 | kfree_skb(skb); |
| 1820 | return NET_RX_SUCCESS; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1821 | } |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 1822 | |
Simon Wunderlich | 1b371d1 | 2014-01-15 21:17:54 +0100 | [diff] [blame] | 1823 | /** |
| 1824 | * batadv_iv_ogm_orig_print_neigh - print neighbors for the originator table |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1825 | * @orig_node: the orig_node for which the neighbors are printed |
| 1826 | * @if_outgoing: outgoing interface for these entries |
| 1827 | * @seq: debugfs table seq_file struct |
| 1828 | * |
| 1829 | * Must be called while holding an rcu lock. |
| 1830 | */ |
| 1831 | static void |
| 1832 | batadv_iv_ogm_orig_print_neigh(struct batadv_orig_node *orig_node, |
| 1833 | struct batadv_hard_iface *if_outgoing, |
| 1834 | struct seq_file *seq) |
| 1835 | { |
| 1836 | struct batadv_neigh_node *neigh_node; |
| 1837 | struct batadv_neigh_ifinfo *n_ifinfo; |
| 1838 | |
| 1839 | hlist_for_each_entry_rcu(neigh_node, &orig_node->neigh_list, list) { |
| 1840 | n_ifinfo = batadv_neigh_ifinfo_get(neigh_node, if_outgoing); |
| 1841 | if (!n_ifinfo) |
| 1842 | continue; |
| 1843 | |
| 1844 | seq_printf(seq, " %pM (%3i)", |
| 1845 | neigh_node->addr, |
| 1846 | n_ifinfo->bat_iv.tq_avg); |
| 1847 | |
Sven Eckelmann | 044fa3a | 2016-01-17 11:01:12 +0100 | [diff] [blame] | 1848 | batadv_neigh_ifinfo_put(n_ifinfo); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1849 | } |
| 1850 | } |
| 1851 | |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 1852 | /** |
| 1853 | * batadv_iv_ogm_orig_print - print the originator table |
| 1854 | * @bat_priv: the bat priv with all the soft interface information |
| 1855 | * @seq: debugfs table seq_file struct |
Simon Wunderlich | cb1c92e | 2013-11-21 11:52:16 +0100 | [diff] [blame] | 1856 | * @if_outgoing: the outgoing interface for which this should be printed |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 1857 | */ |
| 1858 | static void batadv_iv_ogm_orig_print(struct batadv_priv *bat_priv, |
Simon Wunderlich | cb1c92e | 2013-11-21 11:52:16 +0100 | [diff] [blame] | 1859 | struct seq_file *seq, |
| 1860 | struct batadv_hard_iface *if_outgoing) |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 1861 | { |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1862 | struct batadv_neigh_node *neigh_node; |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 1863 | struct batadv_hashtable *hash = bat_priv->orig_hash; |
| 1864 | int last_seen_msecs, last_seen_secs; |
| 1865 | struct batadv_orig_node *orig_node; |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1866 | struct batadv_neigh_ifinfo *n_ifinfo; |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 1867 | unsigned long last_seen_jiffies; |
| 1868 | struct hlist_head *head; |
| 1869 | int batman_count = 0; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 1870 | u32 i; |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 1871 | |
Antonio Quartulli | 925a6f3 | 2016-03-12 10:30:18 +0100 | [diff] [blame] | 1872 | seq_puts(seq, |
| 1873 | " Originator last-seen (#/255) Nexthop [outgoingIF]: Potential nexthops ...\n"); |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 1874 | |
| 1875 | for (i = 0; i < hash->size; i++) { |
| 1876 | head = &hash->table[i]; |
| 1877 | |
| 1878 | rcu_read_lock(); |
| 1879 | hlist_for_each_entry_rcu(orig_node, head, hash_entry) { |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 1880 | neigh_node = batadv_orig_router_get(orig_node, |
Simon Wunderlich | cb1c92e | 2013-11-21 11:52:16 +0100 | [diff] [blame] | 1881 | if_outgoing); |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 1882 | if (!neigh_node) |
| 1883 | continue; |
| 1884 | |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1885 | n_ifinfo = batadv_neigh_ifinfo_get(neigh_node, |
Simon Wunderlich | cb1c92e | 2013-11-21 11:52:16 +0100 | [diff] [blame] | 1886 | if_outgoing); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1887 | if (!n_ifinfo) |
| 1888 | goto next; |
| 1889 | |
| 1890 | if (n_ifinfo->bat_iv.tq_avg == 0) |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 1891 | goto next; |
| 1892 | |
| 1893 | last_seen_jiffies = jiffies - orig_node->last_seen; |
| 1894 | last_seen_msecs = jiffies_to_msecs(last_seen_jiffies); |
| 1895 | last_seen_secs = last_seen_msecs / 1000; |
| 1896 | last_seen_msecs = last_seen_msecs % 1000; |
| 1897 | |
| 1898 | seq_printf(seq, "%pM %4i.%03is (%3i) %pM [%10s]:", |
| 1899 | orig_node->orig, last_seen_secs, |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1900 | last_seen_msecs, n_ifinfo->bat_iv.tq_avg, |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 1901 | neigh_node->addr, |
| 1902 | neigh_node->if_incoming->net_dev->name); |
| 1903 | |
Simon Wunderlich | cb1c92e | 2013-11-21 11:52:16 +0100 | [diff] [blame] | 1904 | batadv_iv_ogm_orig_print_neigh(orig_node, if_outgoing, |
| 1905 | seq); |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 1906 | seq_puts(seq, "\n"); |
| 1907 | batman_count++; |
| 1908 | |
| 1909 | next: |
Sven Eckelmann | 25bb250 | 2016-01-17 11:01:11 +0100 | [diff] [blame] | 1910 | batadv_neigh_node_put(neigh_node); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1911 | if (n_ifinfo) |
Sven Eckelmann | 044fa3a | 2016-01-17 11:01:12 +0100 | [diff] [blame] | 1912 | batadv_neigh_ifinfo_put(n_ifinfo); |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 1913 | } |
| 1914 | rcu_read_unlock(); |
| 1915 | } |
| 1916 | |
| 1917 | if (batman_count == 0) |
| 1918 | seq_puts(seq, "No batman nodes in range ...\n"); |
| 1919 | } |
| 1920 | |
Antonio Quartulli | a3285a8 | 2013-09-02 12:15:04 +0200 | [diff] [blame] | 1921 | /** |
Marek Lindner | 7587405 | 2015-08-04 21:09:57 +0800 | [diff] [blame] | 1922 | * batadv_iv_hardif_neigh_print - print a single hop neighbour node |
| 1923 | * @seq: neighbour table seq_file struct |
| 1924 | * @hardif_neigh: hardif neighbour information |
| 1925 | */ |
| 1926 | static void |
| 1927 | batadv_iv_hardif_neigh_print(struct seq_file *seq, |
| 1928 | struct batadv_hardif_neigh_node *hardif_neigh) |
| 1929 | { |
| 1930 | int last_secs, last_msecs; |
| 1931 | |
| 1932 | last_secs = jiffies_to_msecs(jiffies - hardif_neigh->last_seen) / 1000; |
| 1933 | last_msecs = jiffies_to_msecs(jiffies - hardif_neigh->last_seen) % 1000; |
| 1934 | |
| 1935 | seq_printf(seq, " %10s %pM %4i.%03is\n", |
| 1936 | hardif_neigh->if_incoming->net_dev->name, |
| 1937 | hardif_neigh->addr, last_secs, last_msecs); |
| 1938 | } |
| 1939 | |
| 1940 | /** |
| 1941 | * batadv_iv_ogm_neigh_print - print the single hop neighbour list |
| 1942 | * @bat_priv: the bat priv with all the soft interface information |
| 1943 | * @seq: neighbour table seq_file struct |
| 1944 | */ |
| 1945 | static void batadv_iv_neigh_print(struct batadv_priv *bat_priv, |
| 1946 | struct seq_file *seq) |
| 1947 | { |
| 1948 | struct net_device *net_dev = (struct net_device *)seq->private; |
| 1949 | struct batadv_hardif_neigh_node *hardif_neigh; |
| 1950 | struct batadv_hard_iface *hard_iface; |
| 1951 | int batman_count = 0; |
| 1952 | |
Antonio Quartulli | 925a6f3 | 2016-03-12 10:30:18 +0100 | [diff] [blame] | 1953 | seq_puts(seq, " IF Neighbor last-seen\n"); |
Marek Lindner | 7587405 | 2015-08-04 21:09:57 +0800 | [diff] [blame] | 1954 | |
| 1955 | rcu_read_lock(); |
| 1956 | list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) { |
| 1957 | if (hard_iface->soft_iface != net_dev) |
| 1958 | continue; |
| 1959 | |
| 1960 | hlist_for_each_entry_rcu(hardif_neigh, |
| 1961 | &hard_iface->neigh_list, list) { |
| 1962 | batadv_iv_hardif_neigh_print(seq, hardif_neigh); |
| 1963 | batman_count++; |
| 1964 | } |
| 1965 | } |
| 1966 | rcu_read_unlock(); |
| 1967 | |
| 1968 | if (batman_count == 0) |
| 1969 | seq_puts(seq, "No batman nodes in range ...\n"); |
| 1970 | } |
| 1971 | |
| 1972 | /** |
Antonio Quartulli | a3285a8 | 2013-09-02 12:15:04 +0200 | [diff] [blame] | 1973 | * batadv_iv_ogm_neigh_cmp - compare the metrics of two neighbors |
| 1974 | * @neigh1: the first neighbor object of the comparison |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1975 | * @if_outgoing1: outgoing interface for the first neighbor |
Antonio Quartulli | a3285a8 | 2013-09-02 12:15:04 +0200 | [diff] [blame] | 1976 | * @neigh2: the second neighbor object of the comparison |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1977 | * @if_outgoing2: outgoing interface for the second neighbor |
Antonio Quartulli | a3285a8 | 2013-09-02 12:15:04 +0200 | [diff] [blame] | 1978 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 1979 | * 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] | 1980 | * lower, the same as or higher than the metric via neigh2 |
| 1981 | */ |
| 1982 | static int batadv_iv_ogm_neigh_cmp(struct batadv_neigh_node *neigh1, |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1983 | struct batadv_hard_iface *if_outgoing1, |
| 1984 | struct batadv_neigh_node *neigh2, |
| 1985 | struct batadv_hard_iface *if_outgoing2) |
Antonio Quartulli | a3285a8 | 2013-09-02 12:15:04 +0200 | [diff] [blame] | 1986 | { |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1987 | struct batadv_neigh_ifinfo *neigh1_ifinfo, *neigh2_ifinfo; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 1988 | u8 tq1, tq2; |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1989 | int diff; |
Antonio Quartulli | a3285a8 | 2013-09-02 12:15:04 +0200 | [diff] [blame] | 1990 | |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1991 | neigh1_ifinfo = batadv_neigh_ifinfo_get(neigh1, if_outgoing1); |
| 1992 | neigh2_ifinfo = batadv_neigh_ifinfo_get(neigh2, if_outgoing2); |
Antonio Quartulli | a3285a8 | 2013-09-02 12:15:04 +0200 | [diff] [blame] | 1993 | |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 1994 | if (!neigh1_ifinfo || !neigh2_ifinfo) { |
| 1995 | diff = 0; |
| 1996 | goto out; |
| 1997 | } |
| 1998 | |
| 1999 | tq1 = neigh1_ifinfo->bat_iv.tq_avg; |
| 2000 | tq2 = neigh2_ifinfo->bat_iv.tq_avg; |
| 2001 | diff = tq1 - tq2; |
| 2002 | |
| 2003 | out: |
| 2004 | if (neigh1_ifinfo) |
Sven Eckelmann | 044fa3a | 2016-01-17 11:01:12 +0100 | [diff] [blame] | 2005 | batadv_neigh_ifinfo_put(neigh1_ifinfo); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 2006 | if (neigh2_ifinfo) |
Sven Eckelmann | 044fa3a | 2016-01-17 11:01:12 +0100 | [diff] [blame] | 2007 | batadv_neigh_ifinfo_put(neigh2_ifinfo); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 2008 | |
| 2009 | return diff; |
Antonio Quartulli | a3285a8 | 2013-09-02 12:15:04 +0200 | [diff] [blame] | 2010 | } |
| 2011 | |
Antonio Quartulli | c43c981 | 2013-09-02 12:15:05 +0200 | [diff] [blame] | 2012 | /** |
Simon Wunderlich | 18165f6 | 2015-08-08 02:01:50 +0200 | [diff] [blame] | 2013 | * batadv_iv_ogm_neigh_is_sob - check if neigh1 is similarly good or better |
| 2014 | * than neigh2 from the metric prospective |
Antonio Quartulli | c43c981 | 2013-09-02 12:15:05 +0200 | [diff] [blame] | 2015 | * @neigh1: the first neighbor object of the comparison |
Martin Hundebøll | 95298a9 | 2014-07-15 09:41:05 +0200 | [diff] [blame] | 2016 | * @if_outgoing1: outgoing interface for the first neighbor |
Antonio Quartulli | c43c981 | 2013-09-02 12:15:05 +0200 | [diff] [blame] | 2017 | * @neigh2: the second neighbor object of the comparison |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 2018 | * @if_outgoing2: outgoing interface for the second neighbor |
Martin Hundebøll | 95298a9 | 2014-07-15 09:41:05 +0200 | [diff] [blame] | 2019 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 2020 | * 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] | 2021 | * the metric via neigh2, false otherwise. |
| 2022 | */ |
| 2023 | static bool |
Simon Wunderlich | 18165f6 | 2015-08-08 02:01:50 +0200 | [diff] [blame] | 2024 | batadv_iv_ogm_neigh_is_sob(struct batadv_neigh_node *neigh1, |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 2025 | struct batadv_hard_iface *if_outgoing1, |
| 2026 | struct batadv_neigh_node *neigh2, |
| 2027 | struct batadv_hard_iface *if_outgoing2) |
| 2028 | { |
| 2029 | struct batadv_neigh_ifinfo *neigh1_ifinfo, *neigh2_ifinfo; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 2030 | u8 tq1, tq2; |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 2031 | bool ret; |
| 2032 | |
| 2033 | neigh1_ifinfo = batadv_neigh_ifinfo_get(neigh1, if_outgoing1); |
| 2034 | neigh2_ifinfo = batadv_neigh_ifinfo_get(neigh2, if_outgoing2); |
| 2035 | |
| 2036 | /* we can't say that the metric is better */ |
| 2037 | if (!neigh1_ifinfo || !neigh2_ifinfo) { |
| 2038 | ret = false; |
| 2039 | goto out; |
| 2040 | } |
| 2041 | |
| 2042 | tq1 = neigh1_ifinfo->bat_iv.tq_avg; |
| 2043 | tq2 = neigh2_ifinfo->bat_iv.tq_avg; |
| 2044 | ret = (tq1 - tq2) > -BATADV_TQ_SIMILARITY_THRESHOLD; |
| 2045 | |
| 2046 | out: |
| 2047 | if (neigh1_ifinfo) |
Sven Eckelmann | 044fa3a | 2016-01-17 11:01:12 +0100 | [diff] [blame] | 2048 | batadv_neigh_ifinfo_put(neigh1_ifinfo); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 2049 | if (neigh2_ifinfo) |
Sven Eckelmann | 044fa3a | 2016-01-17 11:01:12 +0100 | [diff] [blame] | 2050 | batadv_neigh_ifinfo_put(neigh2_ifinfo); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 2051 | |
| 2052 | return ret; |
Antonio Quartulli | c43c981 | 2013-09-02 12:15:05 +0200 | [diff] [blame] | 2053 | } |
| 2054 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2055 | static struct batadv_algo_ops batadv_batman_iv __read_mostly = { |
Marek Lindner | 519d349 | 2012-04-18 17:15:57 +0800 | [diff] [blame] | 2056 | .name = "BATMAN_IV", |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 2057 | .bat_iface_enable = batadv_iv_ogm_iface_enable, |
| 2058 | .bat_iface_disable = batadv_iv_ogm_iface_disable, |
| 2059 | .bat_iface_update_mac = batadv_iv_ogm_iface_update_mac, |
| 2060 | .bat_primary_iface_set = batadv_iv_ogm_primary_iface_set, |
| 2061 | .bat_ogm_schedule = batadv_iv_ogm_schedule, |
| 2062 | .bat_ogm_emit = batadv_iv_ogm_emit, |
Antonio Quartulli | a3285a8 | 2013-09-02 12:15:04 +0200 | [diff] [blame] | 2063 | .bat_neigh_cmp = batadv_iv_ogm_neigh_cmp, |
Simon Wunderlich | 18165f6 | 2015-08-08 02:01:50 +0200 | [diff] [blame] | 2064 | .bat_neigh_is_similar_or_better = batadv_iv_ogm_neigh_is_sob, |
Marek Lindner | 7587405 | 2015-08-04 21:09:57 +0800 | [diff] [blame] | 2065 | .bat_neigh_print = batadv_iv_neigh_print, |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 2066 | .bat_orig_print = batadv_iv_ogm_orig_print, |
Antonio Quartulli | d0015fd | 2013-09-03 11:10:23 +0200 | [diff] [blame] | 2067 | .bat_orig_free = batadv_iv_ogm_orig_free, |
| 2068 | .bat_orig_add_if = batadv_iv_ogm_orig_add_if, |
| 2069 | .bat_orig_del_if = batadv_iv_ogm_orig_del_if, |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 2070 | }; |
| 2071 | |
Sven Eckelmann | 81c524f | 2012-05-12 02:09:22 +0200 | [diff] [blame] | 2072 | int __init batadv_iv_init(void) |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 2073 | { |
Marek Lindner | c3e2931 | 2012-03-04 16:56:25 +0800 | [diff] [blame] | 2074 | int ret; |
| 2075 | |
| 2076 | /* batman originator packet */ |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 2077 | ret = batadv_recv_handler_register(BATADV_IV_OGM, |
| 2078 | batadv_iv_ogm_receive); |
Marek Lindner | c3e2931 | 2012-03-04 16:56:25 +0800 | [diff] [blame] | 2079 | if (ret < 0) |
| 2080 | goto out; |
| 2081 | |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 2082 | ret = batadv_algo_register(&batadv_batman_iv); |
Marek Lindner | c3e2931 | 2012-03-04 16:56:25 +0800 | [diff] [blame] | 2083 | if (ret < 0) |
| 2084 | goto handler_unregister; |
| 2085 | |
| 2086 | goto out; |
| 2087 | |
| 2088 | handler_unregister: |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 2089 | batadv_recv_handler_unregister(BATADV_IV_OGM); |
Marek Lindner | c3e2931 | 2012-03-04 16:56:25 +0800 | [diff] [blame] | 2090 | out: |
| 2091 | return ret; |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 2092 | } |