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