Simon Wunderlich | e19f975 | 2014-01-04 18:04:25 +0100 | [diff] [blame] | 1 | /* Copyright (C) 2009-2014 B.A.T.M.A.N. contributors: |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [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/>. |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 16 | */ |
| 17 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 18 | #include "main.h" |
Antonio Quartulli | 785ea11 | 2011-11-23 11:35:44 +0100 | [diff] [blame] | 19 | #include "distributed-arp-table.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 20 | #include "originator.h" |
| 21 | #include "hash.h" |
| 22 | #include "translation-table.h" |
| 23 | #include "routing.h" |
| 24 | #include "gateway_client.h" |
| 25 | #include "hard-interface.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 26 | #include "soft-interface.h" |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 27 | #include "bridge_loop_avoidance.h" |
Martin Hundebøll | d56b170 | 2013-01-25 11:12:39 +0100 | [diff] [blame] | 28 | #include "network-coding.h" |
Martin Hundebøll | 610bfc6bc | 2013-05-23 16:53:02 +0200 | [diff] [blame] | 29 | #include "fragmentation.h" |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame^] | 30 | #include "multicast.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 31 | |
Antonio Quartulli | dec0507 | 2012-11-10 11:00:32 +0100 | [diff] [blame] | 32 | /* hash class keys */ |
| 33 | static struct lock_class_key batadv_orig_hash_lock_class_key; |
| 34 | |
Sven Eckelmann | 03fc7f8 | 2012-05-12 18:34:00 +0200 | [diff] [blame] | 35 | static void batadv_purge_orig(struct work_struct *work); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 36 | |
Sven Eckelmann | b8e2dd1 | 2011-06-15 15:08:59 +0200 | [diff] [blame] | 37 | /* returns 1 if they are the same originator */ |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 38 | int batadv_compare_orig(const struct hlist_node *node, const void *data2) |
Sven Eckelmann | b8e2dd1 | 2011-06-15 15:08:59 +0200 | [diff] [blame] | 39 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 40 | const void *data1 = container_of(node, struct batadv_orig_node, |
| 41 | hash_entry); |
Sven Eckelmann | b8e2dd1 | 2011-06-15 15:08:59 +0200 | [diff] [blame] | 42 | |
dingtianhong | 323813e | 2013-12-26 19:40:39 +0800 | [diff] [blame] | 43 | return batadv_compare_eth(data1, data2); |
Sven Eckelmann | b8e2dd1 | 2011-06-15 15:08:59 +0200 | [diff] [blame] | 44 | } |
| 45 | |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 46 | /** |
| 47 | * batadv_orig_node_vlan_get - get an orig_node_vlan object |
| 48 | * @orig_node: the originator serving the VLAN |
| 49 | * @vid: the VLAN identifier |
| 50 | * |
| 51 | * Returns the vlan object identified by vid and belonging to orig_node or NULL |
| 52 | * if it does not exist. |
| 53 | */ |
| 54 | struct batadv_orig_node_vlan * |
| 55 | batadv_orig_node_vlan_get(struct batadv_orig_node *orig_node, |
| 56 | unsigned short vid) |
| 57 | { |
| 58 | struct batadv_orig_node_vlan *vlan = NULL, *tmp; |
| 59 | |
| 60 | rcu_read_lock(); |
| 61 | list_for_each_entry_rcu(tmp, &orig_node->vlan_list, list) { |
| 62 | if (tmp->vid != vid) |
| 63 | continue; |
| 64 | |
| 65 | if (!atomic_inc_not_zero(&tmp->refcount)) |
| 66 | continue; |
| 67 | |
| 68 | vlan = tmp; |
| 69 | |
| 70 | break; |
| 71 | } |
| 72 | rcu_read_unlock(); |
| 73 | |
| 74 | return vlan; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * batadv_orig_node_vlan_new - search and possibly create an orig_node_vlan |
| 79 | * object |
| 80 | * @orig_node: the originator serving the VLAN |
| 81 | * @vid: the VLAN identifier |
| 82 | * |
| 83 | * Returns NULL in case of failure or the vlan object identified by vid and |
| 84 | * belonging to orig_node otherwise. The object is created and added to the list |
| 85 | * if it does not exist. |
| 86 | * |
| 87 | * The object is returned with refcounter increased by 1. |
| 88 | */ |
| 89 | struct batadv_orig_node_vlan * |
| 90 | batadv_orig_node_vlan_new(struct batadv_orig_node *orig_node, |
| 91 | unsigned short vid) |
| 92 | { |
| 93 | struct batadv_orig_node_vlan *vlan; |
| 94 | |
| 95 | spin_lock_bh(&orig_node->vlan_list_lock); |
| 96 | |
| 97 | /* first look if an object for this vid already exists */ |
| 98 | vlan = batadv_orig_node_vlan_get(orig_node, vid); |
| 99 | if (vlan) |
| 100 | goto out; |
| 101 | |
| 102 | vlan = kzalloc(sizeof(*vlan), GFP_ATOMIC); |
| 103 | if (!vlan) |
| 104 | goto out; |
| 105 | |
| 106 | atomic_set(&vlan->refcount, 2); |
| 107 | vlan->vid = vid; |
| 108 | |
| 109 | list_add_rcu(&vlan->list, &orig_node->vlan_list); |
| 110 | |
| 111 | out: |
| 112 | spin_unlock_bh(&orig_node->vlan_list_lock); |
| 113 | |
| 114 | return vlan; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * batadv_orig_node_vlan_free_ref - decrement the refcounter and possibly free |
| 119 | * the originator-vlan object |
| 120 | * @orig_vlan: the originator-vlan object to release |
| 121 | */ |
| 122 | void batadv_orig_node_vlan_free_ref(struct batadv_orig_node_vlan *orig_vlan) |
| 123 | { |
| 124 | if (atomic_dec_and_test(&orig_vlan->refcount)) |
| 125 | kfree_rcu(orig_vlan, rcu); |
| 126 | } |
| 127 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 128 | int batadv_originator_init(struct batadv_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 129 | { |
| 130 | if (bat_priv->orig_hash) |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 131 | return 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 132 | |
Sven Eckelmann | 1a8eaf0 | 2012-05-12 02:09:32 +0200 | [diff] [blame] | 133 | bat_priv->orig_hash = batadv_hash_new(1024); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 134 | |
| 135 | if (!bat_priv->orig_hash) |
| 136 | goto err; |
| 137 | |
Antonio Quartulli | dec0507 | 2012-11-10 11:00:32 +0100 | [diff] [blame] | 138 | batadv_hash_set_lock_class(bat_priv->orig_hash, |
| 139 | &batadv_orig_hash_lock_class_key); |
| 140 | |
Antonio Quartulli | 7241444 | 2012-12-25 13:14:37 +0100 | [diff] [blame] | 141 | INIT_DELAYED_WORK(&bat_priv->orig_work, batadv_purge_orig); |
| 142 | queue_delayed_work(batadv_event_workqueue, |
| 143 | &bat_priv->orig_work, |
| 144 | msecs_to_jiffies(BATADV_ORIG_WORK_PERIOD)); |
| 145 | |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 146 | return 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 147 | |
| 148 | err: |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 149 | return -ENOMEM; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 152 | /** |
| 153 | * batadv_neigh_ifinfo_free_rcu - free the neigh_ifinfo object |
| 154 | * @rcu: rcu pointer of the neigh_ifinfo object |
| 155 | */ |
| 156 | static void batadv_neigh_ifinfo_free_rcu(struct rcu_head *rcu) |
| 157 | { |
| 158 | struct batadv_neigh_ifinfo *neigh_ifinfo; |
| 159 | |
| 160 | neigh_ifinfo = container_of(rcu, struct batadv_neigh_ifinfo, rcu); |
| 161 | |
| 162 | if (neigh_ifinfo->if_outgoing != BATADV_IF_DEFAULT) |
| 163 | batadv_hardif_free_ref_now(neigh_ifinfo->if_outgoing); |
| 164 | |
| 165 | kfree(neigh_ifinfo); |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * batadv_neigh_ifinfo_free_now - decrement the refcounter and possibly free |
| 170 | * the neigh_ifinfo (without rcu callback) |
| 171 | * @neigh_ifinfo: the neigh_ifinfo object to release |
| 172 | */ |
| 173 | static void |
| 174 | batadv_neigh_ifinfo_free_ref_now(struct batadv_neigh_ifinfo *neigh_ifinfo) |
| 175 | { |
| 176 | if (atomic_dec_and_test(&neigh_ifinfo->refcount)) |
| 177 | batadv_neigh_ifinfo_free_rcu(&neigh_ifinfo->rcu); |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * batadv_neigh_ifinfo_free_ref - decrement the refcounter and possibly free |
| 182 | * the neigh_ifinfo |
| 183 | * @neigh_ifinfo: the neigh_ifinfo object to release |
| 184 | */ |
| 185 | void batadv_neigh_ifinfo_free_ref(struct batadv_neigh_ifinfo *neigh_ifinfo) |
| 186 | { |
| 187 | if (atomic_dec_and_test(&neigh_ifinfo->refcount)) |
| 188 | call_rcu(&neigh_ifinfo->rcu, batadv_neigh_ifinfo_free_rcu); |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * batadv_neigh_node_free_rcu - free the neigh_node |
| 193 | * @rcu: rcu pointer of the neigh_node |
| 194 | */ |
| 195 | static void batadv_neigh_node_free_rcu(struct rcu_head *rcu) |
| 196 | { |
| 197 | struct hlist_node *node_tmp; |
| 198 | struct batadv_neigh_node *neigh_node; |
| 199 | struct batadv_neigh_ifinfo *neigh_ifinfo; |
| 200 | |
| 201 | neigh_node = container_of(rcu, struct batadv_neigh_node, rcu); |
| 202 | |
| 203 | hlist_for_each_entry_safe(neigh_ifinfo, node_tmp, |
| 204 | &neigh_node->ifinfo_list, list) { |
| 205 | batadv_neigh_ifinfo_free_ref_now(neigh_ifinfo); |
| 206 | } |
| 207 | batadv_hardif_free_ref_now(neigh_node->if_incoming); |
| 208 | |
| 209 | kfree(neigh_node); |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * batadv_neigh_node_free_ref_now - decrement the neighbors refcounter |
| 214 | * and possibly free it (without rcu callback) |
| 215 | * @neigh_node: neigh neighbor to free |
| 216 | */ |
| 217 | static void |
| 218 | batadv_neigh_node_free_ref_now(struct batadv_neigh_node *neigh_node) |
| 219 | { |
| 220 | if (atomic_dec_and_test(&neigh_node->refcount)) |
| 221 | batadv_neigh_node_free_rcu(&neigh_node->rcu); |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * batadv_neigh_node_free_ref - decrement the neighbors refcounter |
| 226 | * and possibly free it |
| 227 | * @neigh_node: neigh neighbor to free |
| 228 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 229 | void batadv_neigh_node_free_ref(struct batadv_neigh_node *neigh_node) |
Simon Wunderlich | a4c135c | 2011-01-19 20:01:43 +0000 | [diff] [blame] | 230 | { |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 231 | if (atomic_dec_and_test(&neigh_node->refcount)) |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 232 | call_rcu(&neigh_node->rcu, batadv_neigh_node_free_rcu); |
Simon Wunderlich | a4c135c | 2011-01-19 20:01:43 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 235 | /** |
| 236 | * batadv_orig_node_get_router - router to the originator depending on iface |
| 237 | * @orig_node: the orig node for the router |
| 238 | * @if_outgoing: the interface where the payload packet has been received or |
| 239 | * the OGM should be sent to |
| 240 | * |
| 241 | * Returns the neighbor which should be router for this orig_node/iface. |
| 242 | * |
| 243 | * The object is returned with refcounter increased by 1. |
| 244 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 245 | struct batadv_neigh_node * |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 246 | batadv_orig_router_get(struct batadv_orig_node *orig_node, |
| 247 | const struct batadv_hard_iface *if_outgoing) |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 248 | { |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 249 | struct batadv_orig_ifinfo *orig_ifinfo; |
| 250 | struct batadv_neigh_node *router = NULL; |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 251 | |
| 252 | rcu_read_lock(); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 253 | hlist_for_each_entry_rcu(orig_ifinfo, &orig_node->ifinfo_list, list) { |
| 254 | if (orig_ifinfo->if_outgoing != if_outgoing) |
| 255 | continue; |
| 256 | |
| 257 | router = rcu_dereference(orig_ifinfo->router); |
| 258 | break; |
| 259 | } |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 260 | |
| 261 | if (router && !atomic_inc_not_zero(&router->refcount)) |
| 262 | router = NULL; |
| 263 | |
| 264 | rcu_read_unlock(); |
| 265 | return router; |
| 266 | } |
| 267 | |
Antonio Quartulli | 0538f75 | 2013-09-02 12:15:01 +0200 | [diff] [blame] | 268 | /** |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 269 | * batadv_orig_ifinfo_get - find the ifinfo from an orig_node |
| 270 | * @orig_node: the orig node to be queried |
| 271 | * @if_outgoing: the interface for which the ifinfo should be acquired |
| 272 | * |
| 273 | * Returns the requested orig_ifinfo or NULL if not found. |
| 274 | * |
| 275 | * The object is returned with refcounter increased by 1. |
| 276 | */ |
| 277 | struct batadv_orig_ifinfo * |
| 278 | batadv_orig_ifinfo_get(struct batadv_orig_node *orig_node, |
| 279 | struct batadv_hard_iface *if_outgoing) |
| 280 | { |
| 281 | struct batadv_orig_ifinfo *tmp, *orig_ifinfo = NULL; |
| 282 | |
| 283 | rcu_read_lock(); |
| 284 | hlist_for_each_entry_rcu(tmp, &orig_node->ifinfo_list, |
| 285 | list) { |
| 286 | if (tmp->if_outgoing != if_outgoing) |
| 287 | continue; |
| 288 | |
| 289 | if (!atomic_inc_not_zero(&tmp->refcount)) |
| 290 | continue; |
| 291 | |
| 292 | orig_ifinfo = tmp; |
| 293 | break; |
| 294 | } |
| 295 | rcu_read_unlock(); |
| 296 | |
| 297 | return orig_ifinfo; |
| 298 | } |
| 299 | |
| 300 | /** |
| 301 | * batadv_orig_ifinfo_new - search and possibly create an orig_ifinfo object |
| 302 | * @orig_node: the orig node to be queried |
| 303 | * @if_outgoing: the interface for which the ifinfo should be acquired |
| 304 | * |
| 305 | * Returns NULL in case of failure or the orig_ifinfo object for the if_outgoing |
| 306 | * interface otherwise. The object is created and added to the list |
| 307 | * if it does not exist. |
| 308 | * |
| 309 | * The object is returned with refcounter increased by 1. |
| 310 | */ |
| 311 | struct batadv_orig_ifinfo * |
| 312 | batadv_orig_ifinfo_new(struct batadv_orig_node *orig_node, |
| 313 | struct batadv_hard_iface *if_outgoing) |
| 314 | { |
| 315 | struct batadv_orig_ifinfo *orig_ifinfo = NULL; |
| 316 | unsigned long reset_time; |
| 317 | |
| 318 | spin_lock_bh(&orig_node->neigh_list_lock); |
| 319 | |
| 320 | orig_ifinfo = batadv_orig_ifinfo_get(orig_node, if_outgoing); |
| 321 | if (orig_ifinfo) |
| 322 | goto out; |
| 323 | |
| 324 | orig_ifinfo = kzalloc(sizeof(*orig_ifinfo), GFP_ATOMIC); |
| 325 | if (!orig_ifinfo) |
| 326 | goto out; |
| 327 | |
| 328 | if (if_outgoing != BATADV_IF_DEFAULT && |
| 329 | !atomic_inc_not_zero(&if_outgoing->refcount)) { |
| 330 | kfree(orig_ifinfo); |
| 331 | orig_ifinfo = NULL; |
| 332 | goto out; |
| 333 | } |
| 334 | |
| 335 | reset_time = jiffies - 1; |
| 336 | reset_time -= msecs_to_jiffies(BATADV_RESET_PROTECTION_MS); |
| 337 | orig_ifinfo->batman_seqno_reset = reset_time; |
| 338 | orig_ifinfo->if_outgoing = if_outgoing; |
| 339 | INIT_HLIST_NODE(&orig_ifinfo->list); |
| 340 | atomic_set(&orig_ifinfo->refcount, 2); |
| 341 | hlist_add_head_rcu(&orig_ifinfo->list, |
| 342 | &orig_node->ifinfo_list); |
| 343 | out: |
| 344 | spin_unlock_bh(&orig_node->neigh_list_lock); |
| 345 | return orig_ifinfo; |
| 346 | } |
| 347 | |
| 348 | /** |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 349 | * batadv_neigh_ifinfo_get - find the ifinfo from an neigh_node |
| 350 | * @neigh_node: the neigh node to be queried |
| 351 | * @if_outgoing: the interface for which the ifinfo should be acquired |
| 352 | * |
| 353 | * The object is returned with refcounter increased by 1. |
| 354 | * |
| 355 | * Returns the requested neigh_ifinfo or NULL if not found |
| 356 | */ |
| 357 | struct batadv_neigh_ifinfo * |
| 358 | batadv_neigh_ifinfo_get(struct batadv_neigh_node *neigh, |
| 359 | struct batadv_hard_iface *if_outgoing) |
| 360 | { |
| 361 | struct batadv_neigh_ifinfo *neigh_ifinfo = NULL, |
| 362 | *tmp_neigh_ifinfo; |
| 363 | |
| 364 | rcu_read_lock(); |
| 365 | hlist_for_each_entry_rcu(tmp_neigh_ifinfo, &neigh->ifinfo_list, |
| 366 | list) { |
| 367 | if (tmp_neigh_ifinfo->if_outgoing != if_outgoing) |
| 368 | continue; |
| 369 | |
| 370 | if (!atomic_inc_not_zero(&tmp_neigh_ifinfo->refcount)) |
| 371 | continue; |
| 372 | |
| 373 | neigh_ifinfo = tmp_neigh_ifinfo; |
| 374 | break; |
| 375 | } |
| 376 | rcu_read_unlock(); |
| 377 | |
| 378 | return neigh_ifinfo; |
| 379 | } |
| 380 | |
| 381 | /** |
| 382 | * batadv_neigh_ifinfo_new - search and possibly create an neigh_ifinfo object |
| 383 | * @neigh_node: the neigh node to be queried |
| 384 | * @if_outgoing: the interface for which the ifinfo should be acquired |
| 385 | * |
| 386 | * Returns NULL in case of failure or the neigh_ifinfo object for the |
| 387 | * if_outgoing interface otherwise. The object is created and added to the list |
| 388 | * if it does not exist. |
| 389 | * |
| 390 | * The object is returned with refcounter increased by 1. |
| 391 | */ |
| 392 | struct batadv_neigh_ifinfo * |
| 393 | batadv_neigh_ifinfo_new(struct batadv_neigh_node *neigh, |
| 394 | struct batadv_hard_iface *if_outgoing) |
| 395 | { |
| 396 | struct batadv_neigh_ifinfo *neigh_ifinfo; |
| 397 | |
| 398 | spin_lock_bh(&neigh->ifinfo_lock); |
| 399 | |
| 400 | neigh_ifinfo = batadv_neigh_ifinfo_get(neigh, if_outgoing); |
| 401 | if (neigh_ifinfo) |
| 402 | goto out; |
| 403 | |
| 404 | neigh_ifinfo = kzalloc(sizeof(*neigh_ifinfo), GFP_ATOMIC); |
| 405 | if (!neigh_ifinfo) |
| 406 | goto out; |
| 407 | |
| 408 | if (if_outgoing && !atomic_inc_not_zero(&if_outgoing->refcount)) { |
| 409 | kfree(neigh_ifinfo); |
| 410 | neigh_ifinfo = NULL; |
| 411 | goto out; |
| 412 | } |
| 413 | |
| 414 | INIT_HLIST_NODE(&neigh_ifinfo->list); |
| 415 | atomic_set(&neigh_ifinfo->refcount, 2); |
| 416 | neigh_ifinfo->if_outgoing = if_outgoing; |
| 417 | |
| 418 | hlist_add_head_rcu(&neigh_ifinfo->list, &neigh->ifinfo_list); |
| 419 | |
| 420 | out: |
| 421 | spin_unlock_bh(&neigh->ifinfo_lock); |
| 422 | |
| 423 | return neigh_ifinfo; |
| 424 | } |
| 425 | |
| 426 | /** |
Antonio Quartulli | 0538f75 | 2013-09-02 12:15:01 +0200 | [diff] [blame] | 427 | * batadv_neigh_node_new - create and init a new neigh_node object |
| 428 | * @hard_iface: the interface where the neighbour is connected to |
| 429 | * @neigh_addr: the mac address of the neighbour interface |
| 430 | * @orig_node: originator object representing the neighbour |
| 431 | * |
| 432 | * Allocates a new neigh_node object and initialises all the generic fields. |
| 433 | * Returns the new object or NULL on failure. |
| 434 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 435 | struct batadv_neigh_node * |
| 436 | batadv_neigh_node_new(struct batadv_hard_iface *hard_iface, |
Antonio Quartulli | 0538f75 | 2013-09-02 12:15:01 +0200 | [diff] [blame] | 437 | const uint8_t *neigh_addr, |
| 438 | struct batadv_orig_node *orig_node) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 439 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 440 | struct batadv_neigh_node *neigh_node; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 441 | |
Sven Eckelmann | 704509b | 2011-05-14 23:14:54 +0200 | [diff] [blame] | 442 | neigh_node = kzalloc(sizeof(*neigh_node), GFP_ATOMIC); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 443 | if (!neigh_node) |
Marek Lindner | 7ae8b28 | 2012-03-01 15:35:21 +0800 | [diff] [blame] | 444 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 445 | |
Marek Lindner | 9591a79 | 2010-12-12 21:57:11 +0000 | [diff] [blame] | 446 | INIT_HLIST_NODE(&neigh_node->list); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 447 | INIT_HLIST_HEAD(&neigh_node->ifinfo_list); |
| 448 | spin_lock_init(&neigh_node->ifinfo_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 449 | |
Antonio Quartulli | 8fdd015 | 2014-01-22 00:42:11 +0100 | [diff] [blame] | 450 | ether_addr_copy(neigh_node->addr, neigh_addr); |
Antonio Quartulli | 0538f75 | 2013-09-02 12:15:01 +0200 | [diff] [blame] | 451 | neigh_node->if_incoming = hard_iface; |
| 452 | neigh_node->orig_node = orig_node; |
| 453 | |
Marek Lindner | 1605d0d | 2011-02-18 12:28:11 +0000 | [diff] [blame] | 454 | /* extra reference for return */ |
| 455 | atomic_set(&neigh_node->refcount, 2); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 456 | |
Marek Lindner | 7ae8b28 | 2012-03-01 15:35:21 +0800 | [diff] [blame] | 457 | out: |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 458 | return neigh_node; |
| 459 | } |
| 460 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 461 | /** |
Antonio Quartulli | 08bf0ed | 2014-01-29 11:25:12 +0100 | [diff] [blame] | 462 | * batadv_neigh_node_get - retrieve a neighbour from the list |
| 463 | * @orig_node: originator which the neighbour belongs to |
| 464 | * @hard_iface: the interface where this neighbour is connected to |
| 465 | * @addr: the address of the neighbour |
| 466 | * |
| 467 | * Looks for and possibly returns a neighbour belonging to this originator list |
| 468 | * which is connected through the provided hard interface. |
| 469 | * Returns NULL if the neighbour is not found. |
| 470 | */ |
| 471 | struct batadv_neigh_node * |
| 472 | batadv_neigh_node_get(const struct batadv_orig_node *orig_node, |
| 473 | const struct batadv_hard_iface *hard_iface, |
| 474 | const uint8_t *addr) |
| 475 | { |
| 476 | struct batadv_neigh_node *tmp_neigh_node, *res = NULL; |
| 477 | |
| 478 | rcu_read_lock(); |
| 479 | hlist_for_each_entry_rcu(tmp_neigh_node, &orig_node->neigh_list, list) { |
| 480 | if (!batadv_compare_eth(tmp_neigh_node->addr, addr)) |
| 481 | continue; |
| 482 | |
| 483 | if (tmp_neigh_node->if_incoming != hard_iface) |
| 484 | continue; |
| 485 | |
| 486 | if (!atomic_inc_not_zero(&tmp_neigh_node->refcount)) |
| 487 | continue; |
| 488 | |
| 489 | res = tmp_neigh_node; |
| 490 | break; |
| 491 | } |
| 492 | rcu_read_unlock(); |
| 493 | |
| 494 | return res; |
| 495 | } |
| 496 | |
| 497 | /** |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 498 | * batadv_orig_ifinfo_free_rcu - free the orig_ifinfo object |
| 499 | * @rcu: rcu pointer of the orig_ifinfo object |
| 500 | */ |
| 501 | static void batadv_orig_ifinfo_free_rcu(struct rcu_head *rcu) |
| 502 | { |
| 503 | struct batadv_orig_ifinfo *orig_ifinfo; |
| 504 | |
| 505 | orig_ifinfo = container_of(rcu, struct batadv_orig_ifinfo, rcu); |
| 506 | |
| 507 | if (orig_ifinfo->if_outgoing != BATADV_IF_DEFAULT) |
| 508 | batadv_hardif_free_ref_now(orig_ifinfo->if_outgoing); |
| 509 | |
| 510 | kfree(orig_ifinfo); |
| 511 | } |
| 512 | |
| 513 | /** |
| 514 | * batadv_orig_ifinfo_free_ref - decrement the refcounter and possibly free |
| 515 | * the orig_ifinfo (without rcu callback) |
| 516 | * @orig_ifinfo: the orig_ifinfo object to release |
| 517 | */ |
| 518 | static void |
| 519 | batadv_orig_ifinfo_free_ref_now(struct batadv_orig_ifinfo *orig_ifinfo) |
| 520 | { |
| 521 | if (atomic_dec_and_test(&orig_ifinfo->refcount)) |
| 522 | batadv_orig_ifinfo_free_rcu(&orig_ifinfo->rcu); |
| 523 | } |
| 524 | |
| 525 | /** |
| 526 | * batadv_orig_ifinfo_free_ref - decrement the refcounter and possibly free |
| 527 | * the orig_ifinfo |
| 528 | * @orig_ifinfo: the orig_ifinfo object to release |
| 529 | */ |
| 530 | void batadv_orig_ifinfo_free_ref(struct batadv_orig_ifinfo *orig_ifinfo) |
| 531 | { |
| 532 | if (atomic_dec_and_test(&orig_ifinfo->refcount)) |
| 533 | call_rcu(&orig_ifinfo->rcu, batadv_orig_ifinfo_free_rcu); |
| 534 | } |
| 535 | |
Sven Eckelmann | 03fc7f8 | 2012-05-12 18:34:00 +0200 | [diff] [blame] | 536 | static void batadv_orig_node_free_rcu(struct rcu_head *rcu) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 537 | { |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 538 | struct hlist_node *node_tmp; |
Simon Wunderlich | f6c8b71 | 2013-11-13 19:14:45 +0100 | [diff] [blame] | 539 | struct batadv_neigh_node *neigh_node; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 540 | struct batadv_orig_node *orig_node; |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 541 | struct batadv_orig_ifinfo *orig_ifinfo; |
Marek Lindner | 16b1aba | 2011-01-19 20:01:42 +0000 | [diff] [blame] | 542 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 543 | orig_node = container_of(rcu, struct batadv_orig_node, rcu); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 544 | |
Marek Lindner | f987ed6 | 2010-12-12 21:57:12 +0000 | [diff] [blame] | 545 | spin_lock_bh(&orig_node->neigh_list_lock); |
| 546 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 547 | /* for all neighbors towards this originator ... */ |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 548 | hlist_for_each_entry_safe(neigh_node, node_tmp, |
Marek Lindner | 9591a79 | 2010-12-12 21:57:11 +0000 | [diff] [blame] | 549 | &orig_node->neigh_list, list) { |
Marek Lindner | f987ed6 | 2010-12-12 21:57:12 +0000 | [diff] [blame] | 550 | hlist_del_rcu(&neigh_node->list); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 551 | batadv_neigh_node_free_ref_now(neigh_node); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 552 | } |
| 553 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 554 | hlist_for_each_entry_safe(orig_ifinfo, node_tmp, |
| 555 | &orig_node->ifinfo_list, list) { |
| 556 | hlist_del_rcu(&orig_ifinfo->list); |
| 557 | batadv_orig_ifinfo_free_ref_now(orig_ifinfo); |
| 558 | } |
Marek Lindner | f987ed6 | 2010-12-12 21:57:12 +0000 | [diff] [blame] | 559 | spin_unlock_bh(&orig_node->neigh_list_lock); |
| 560 | |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame^] | 561 | batadv_mcast_purge_orig(orig_node); |
| 562 | |
Martin Hundebøll | d56b170 | 2013-01-25 11:12:39 +0100 | [diff] [blame] | 563 | /* Free nc_nodes */ |
| 564 | batadv_nc_purge_orig(orig_node->bat_priv, orig_node, NULL); |
| 565 | |
Martin Hundebøll | 610bfc6bc | 2013-05-23 16:53:02 +0200 | [diff] [blame] | 566 | batadv_frag_purge_orig(orig_node, NULL); |
| 567 | |
Antonio Quartulli | 95fb130 | 2013-08-07 18:28:55 +0200 | [diff] [blame] | 568 | batadv_tt_global_del_orig(orig_node->bat_priv, orig_node, -1, |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 569 | "originator timed out"); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 570 | |
Antonio Quartulli | d0015fd | 2013-09-03 11:10:23 +0200 | [diff] [blame] | 571 | if (orig_node->bat_priv->bat_algo_ops->bat_orig_free) |
| 572 | orig_node->bat_priv->bat_algo_ops->bat_orig_free(orig_node); |
| 573 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 574 | kfree(orig_node->tt_buff); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 575 | kfree(orig_node); |
| 576 | } |
| 577 | |
Linus Lüssing | 7282222 | 2013-04-15 21:43:29 +0800 | [diff] [blame] | 578 | /** |
| 579 | * batadv_orig_node_free_ref - decrement the orig node refcounter and possibly |
| 580 | * schedule an rcu callback for freeing it |
| 581 | * @orig_node: the orig node to free |
| 582 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 583 | void batadv_orig_node_free_ref(struct batadv_orig_node *orig_node) |
Marek Lindner | 7b36e8e | 2011-02-18 12:28:10 +0000 | [diff] [blame] | 584 | { |
| 585 | if (atomic_dec_and_test(&orig_node->refcount)) |
Sven Eckelmann | 03fc7f8 | 2012-05-12 18:34:00 +0200 | [diff] [blame] | 586 | call_rcu(&orig_node->rcu, batadv_orig_node_free_rcu); |
Marek Lindner | 7b36e8e | 2011-02-18 12:28:10 +0000 | [diff] [blame] | 587 | } |
| 588 | |
Linus Lüssing | 7282222 | 2013-04-15 21:43:29 +0800 | [diff] [blame] | 589 | /** |
| 590 | * batadv_orig_node_free_ref_now - decrement the orig node refcounter and |
| 591 | * possibly free it (without rcu callback) |
| 592 | * @orig_node: the orig node to free |
| 593 | */ |
| 594 | void batadv_orig_node_free_ref_now(struct batadv_orig_node *orig_node) |
| 595 | { |
| 596 | if (atomic_dec_and_test(&orig_node->refcount)) |
| 597 | batadv_orig_node_free_rcu(&orig_node->rcu); |
| 598 | } |
| 599 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 600 | void batadv_originator_free(struct batadv_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 601 | { |
Sven Eckelmann | 5bf74e9 | 2012-06-05 22:31:28 +0200 | [diff] [blame] | 602 | struct batadv_hashtable *hash = bat_priv->orig_hash; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 603 | struct hlist_node *node_tmp; |
Marek Lindner | 16b1aba | 2011-01-19 20:01:42 +0000 | [diff] [blame] | 604 | struct hlist_head *head; |
Marek Lindner | 16b1aba | 2011-01-19 20:01:42 +0000 | [diff] [blame] | 605 | spinlock_t *list_lock; /* spinlock to protect write access */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 606 | struct batadv_orig_node *orig_node; |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 607 | uint32_t i; |
Marek Lindner | 16b1aba | 2011-01-19 20:01:42 +0000 | [diff] [blame] | 608 | |
| 609 | if (!hash) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 610 | return; |
| 611 | |
| 612 | cancel_delayed_work_sync(&bat_priv->orig_work); |
| 613 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 614 | bat_priv->orig_hash = NULL; |
Marek Lindner | 16b1aba | 2011-01-19 20:01:42 +0000 | [diff] [blame] | 615 | |
| 616 | for (i = 0; i < hash->size; i++) { |
| 617 | head = &hash->table[i]; |
| 618 | list_lock = &hash->list_locks[i]; |
| 619 | |
| 620 | spin_lock_bh(list_lock); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 621 | hlist_for_each_entry_safe(orig_node, node_tmp, |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 622 | head, hash_entry) { |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 623 | hlist_del_rcu(&orig_node->hash_entry); |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 624 | batadv_orig_node_free_ref(orig_node); |
Marek Lindner | 16b1aba | 2011-01-19 20:01:42 +0000 | [diff] [blame] | 625 | } |
| 626 | spin_unlock_bh(list_lock); |
| 627 | } |
| 628 | |
Sven Eckelmann | 1a8eaf0 | 2012-05-12 02:09:32 +0200 | [diff] [blame] | 629 | batadv_hash_destroy(hash); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 630 | } |
| 631 | |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 632 | /** |
| 633 | * batadv_orig_node_new - creates a new orig_node |
| 634 | * @bat_priv: the bat priv with all the soft interface information |
| 635 | * @addr: the mac address of the originator |
| 636 | * |
| 637 | * Creates a new originator object and initialise all the generic fields. |
| 638 | * The new object is not added to the originator list. |
| 639 | * Returns the newly created object or NULL on failure. |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 640 | */ |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 641 | struct batadv_orig_node *batadv_orig_node_new(struct batadv_priv *bat_priv, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 642 | const uint8_t *addr) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 643 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 644 | struct batadv_orig_node *orig_node; |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 645 | struct batadv_orig_node_vlan *vlan; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 646 | unsigned long reset_time; |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 647 | int i; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 648 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 649 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
| 650 | "Creating new originator: %pM\n", addr); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 651 | |
Sven Eckelmann | 704509b | 2011-05-14 23:14:54 +0200 | [diff] [blame] | 652 | orig_node = kzalloc(sizeof(*orig_node), GFP_ATOMIC); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 653 | if (!orig_node) |
| 654 | return NULL; |
| 655 | |
Marek Lindner | 9591a79 | 2010-12-12 21:57:11 +0000 | [diff] [blame] | 656 | INIT_HLIST_HEAD(&orig_node->neigh_list); |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 657 | INIT_LIST_HEAD(&orig_node->vlan_list); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 658 | INIT_HLIST_HEAD(&orig_node->ifinfo_list); |
Marek Lindner | f3e0008 | 2011-01-25 21:52:11 +0000 | [diff] [blame] | 659 | spin_lock_init(&orig_node->bcast_seqno_lock); |
Marek Lindner | f987ed6 | 2010-12-12 21:57:12 +0000 | [diff] [blame] | 660 | spin_lock_init(&orig_node->neigh_list_lock); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 661 | spin_lock_init(&orig_node->tt_buff_lock); |
Antonio Quartulli | a70a9aa | 2013-07-30 22:16:24 +0200 | [diff] [blame] | 662 | spin_lock_init(&orig_node->tt_lock); |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 663 | spin_lock_init(&orig_node->vlan_list_lock); |
Marek Lindner | 7b36e8e | 2011-02-18 12:28:10 +0000 | [diff] [blame] | 664 | |
Martin Hundebøll | d56b170 | 2013-01-25 11:12:39 +0100 | [diff] [blame] | 665 | batadv_nc_init_orig(orig_node); |
| 666 | |
Marek Lindner | 7b36e8e | 2011-02-18 12:28:10 +0000 | [diff] [blame] | 667 | /* extra reference for return */ |
| 668 | atomic_set(&orig_node->refcount, 2); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 669 | |
Marek Lindner | 16b1aba | 2011-01-19 20:01:42 +0000 | [diff] [blame] | 670 | orig_node->bat_priv = bat_priv; |
Antonio Quartulli | 8fdd015 | 2014-01-22 00:42:11 +0100 | [diff] [blame] | 671 | ether_addr_copy(orig_node->orig, addr); |
Antonio Quartulli | 785ea11 | 2011-11-23 11:35:44 +0100 | [diff] [blame] | 672 | batadv_dat_init_orig_node_addr(orig_node); |
Antonio Quartulli | c8c991b | 2011-07-07 01:40:57 +0200 | [diff] [blame] | 673 | atomic_set(&orig_node->last_ttvn, 0); |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 674 | orig_node->tt_buff = NULL; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 675 | orig_node->tt_buff_len = 0; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 676 | reset_time = jiffies - 1 - msecs_to_jiffies(BATADV_RESET_PROTECTION_MS); |
| 677 | orig_node->bcast_seqno_reset = reset_time; |
Linus Lüssing | 60432d7 | 2014-02-15 17:47:51 +0100 | [diff] [blame^] | 678 | #ifdef CONFIG_BATMAN_ADV_MCAST |
| 679 | orig_node->mcast_flags = BATADV_NO_FLAGS; |
| 680 | #endif |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 681 | |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 682 | /* create a vlan object for the "untagged" LAN */ |
| 683 | vlan = batadv_orig_node_vlan_new(orig_node, BATADV_NO_FLAGS); |
| 684 | if (!vlan) |
| 685 | goto free_orig_node; |
| 686 | /* batadv_orig_node_vlan_new() increases the refcounter. |
| 687 | * Immediately release vlan since it is not needed anymore in this |
| 688 | * context |
| 689 | */ |
| 690 | batadv_orig_node_vlan_free_ref(vlan); |
| 691 | |
Martin Hundebøll | 610bfc6bc | 2013-05-23 16:53:02 +0200 | [diff] [blame] | 692 | for (i = 0; i < BATADV_FRAG_BUFFER_COUNT; i++) { |
| 693 | INIT_HLIST_HEAD(&orig_node->fragments[i].head); |
| 694 | spin_lock_init(&orig_node->fragments[i].lock); |
| 695 | orig_node->fragments[i].size = 0; |
| 696 | } |
| 697 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 698 | return orig_node; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 699 | free_orig_node: |
| 700 | kfree(orig_node); |
| 701 | return NULL; |
| 702 | } |
| 703 | |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 704 | /** |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 705 | * batadv_purge_orig_ifinfo - purge obsolete ifinfo entries from originator |
| 706 | * @bat_priv: the bat priv with all the soft interface information |
| 707 | * @orig_node: orig node which is to be checked |
| 708 | * |
| 709 | * Returns true if any ifinfo entry was purged, false otherwise. |
| 710 | */ |
| 711 | static bool |
| 712 | batadv_purge_orig_ifinfo(struct batadv_priv *bat_priv, |
| 713 | struct batadv_orig_node *orig_node) |
| 714 | { |
| 715 | struct batadv_orig_ifinfo *orig_ifinfo; |
| 716 | struct batadv_hard_iface *if_outgoing; |
| 717 | struct hlist_node *node_tmp; |
| 718 | bool ifinfo_purged = false; |
| 719 | |
| 720 | spin_lock_bh(&orig_node->neigh_list_lock); |
| 721 | |
| 722 | /* for all ifinfo objects for this originator */ |
| 723 | hlist_for_each_entry_safe(orig_ifinfo, node_tmp, |
| 724 | &orig_node->ifinfo_list, list) { |
| 725 | if_outgoing = orig_ifinfo->if_outgoing; |
| 726 | |
| 727 | /* always keep the default interface */ |
| 728 | if (if_outgoing == BATADV_IF_DEFAULT) |
| 729 | continue; |
| 730 | |
| 731 | /* don't purge if the interface is not (going) down */ |
| 732 | if ((if_outgoing->if_status != BATADV_IF_INACTIVE) && |
| 733 | (if_outgoing->if_status != BATADV_IF_NOT_IN_USE) && |
| 734 | (if_outgoing->if_status != BATADV_IF_TO_BE_REMOVED)) |
| 735 | continue; |
| 736 | |
| 737 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
| 738 | "router/ifinfo purge: originator %pM, iface: %s\n", |
| 739 | orig_node->orig, if_outgoing->net_dev->name); |
| 740 | |
| 741 | ifinfo_purged = true; |
| 742 | |
| 743 | hlist_del_rcu(&orig_ifinfo->list); |
| 744 | batadv_orig_ifinfo_free_ref(orig_ifinfo); |
Simon Wunderlich | f3b3d90 | 2013-11-13 19:14:50 +0100 | [diff] [blame] | 745 | if (orig_node->last_bonding_candidate == orig_ifinfo) { |
| 746 | orig_node->last_bonding_candidate = NULL; |
| 747 | batadv_orig_ifinfo_free_ref(orig_ifinfo); |
| 748 | } |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | spin_unlock_bh(&orig_node->neigh_list_lock); |
| 752 | |
| 753 | return ifinfo_purged; |
| 754 | } |
| 755 | |
| 756 | |
| 757 | /** |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 758 | * batadv_purge_orig_neighbors - purges neighbors from originator |
| 759 | * @bat_priv: the bat priv with all the soft interface information |
| 760 | * @orig_node: orig node which is to be checked |
| 761 | * |
| 762 | * Returns true if any neighbor was purged, false otherwise |
| 763 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 764 | static bool |
| 765 | batadv_purge_orig_neighbors(struct batadv_priv *bat_priv, |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 766 | struct batadv_orig_node *orig_node) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 767 | { |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 768 | struct hlist_node *node_tmp; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 769 | struct batadv_neigh_node *neigh_node; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 770 | bool neigh_purged = false; |
Marek Lindner | 0b0094e | 2012-03-01 15:35:20 +0800 | [diff] [blame] | 771 | unsigned long last_seen; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 772 | struct batadv_hard_iface *if_incoming; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 773 | |
Marek Lindner | f987ed6 | 2010-12-12 21:57:12 +0000 | [diff] [blame] | 774 | spin_lock_bh(&orig_node->neigh_list_lock); |
| 775 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 776 | /* for all neighbors towards this originator ... */ |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 777 | hlist_for_each_entry_safe(neigh_node, node_tmp, |
Marek Lindner | 9591a79 | 2010-12-12 21:57:11 +0000 | [diff] [blame] | 778 | &orig_node->neigh_list, list) { |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 779 | last_seen = neigh_node->last_seen; |
| 780 | if_incoming = neigh_node->if_incoming; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 781 | |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 782 | if ((batadv_has_timed_out(last_seen, BATADV_PURGE_TIMEOUT)) || |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 783 | (if_incoming->if_status == BATADV_IF_INACTIVE) || |
| 784 | (if_incoming->if_status == BATADV_IF_NOT_IN_USE) || |
| 785 | (if_incoming->if_status == BATADV_IF_TO_BE_REMOVED)) { |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 786 | if ((if_incoming->if_status == BATADV_IF_INACTIVE) || |
| 787 | (if_incoming->if_status == BATADV_IF_NOT_IN_USE) || |
| 788 | (if_incoming->if_status == BATADV_IF_TO_BE_REMOVED)) |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 789 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 790 | "neighbor purge: originator %pM, neighbor: %pM, iface: %s\n", |
| 791 | orig_node->orig, neigh_node->addr, |
| 792 | if_incoming->net_dev->name); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 793 | else |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 794 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 795 | "neighbor timeout: originator %pM, neighbor: %pM, last_seen: %u\n", |
| 796 | orig_node->orig, neigh_node->addr, |
| 797 | jiffies_to_msecs(last_seen)); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 798 | |
| 799 | neigh_purged = true; |
Marek Lindner | 9591a79 | 2010-12-12 21:57:11 +0000 | [diff] [blame] | 800 | |
Marek Lindner | f987ed6 | 2010-12-12 21:57:12 +0000 | [diff] [blame] | 801 | hlist_del_rcu(&neigh_node->list); |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 802 | batadv_neigh_node_free_ref(neigh_node); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 803 | } |
| 804 | } |
Marek Lindner | f987ed6 | 2010-12-12 21:57:12 +0000 | [diff] [blame] | 805 | |
| 806 | spin_unlock_bh(&orig_node->neigh_list_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 807 | return neigh_purged; |
| 808 | } |
| 809 | |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 810 | /** |
| 811 | * batadv_find_best_neighbor - finds the best neighbor after purging |
| 812 | * @bat_priv: the bat priv with all the soft interface information |
| 813 | * @orig_node: orig node which is to be checked |
| 814 | * @if_outgoing: the interface for which the metric should be compared |
| 815 | * |
| 816 | * Returns the current best neighbor, with refcount increased. |
| 817 | */ |
| 818 | static struct batadv_neigh_node * |
| 819 | batadv_find_best_neighbor(struct batadv_priv *bat_priv, |
| 820 | struct batadv_orig_node *orig_node, |
| 821 | struct batadv_hard_iface *if_outgoing) |
| 822 | { |
| 823 | struct batadv_neigh_node *best = NULL, *neigh; |
| 824 | struct batadv_algo_ops *bao = bat_priv->bat_algo_ops; |
| 825 | |
| 826 | rcu_read_lock(); |
| 827 | hlist_for_each_entry_rcu(neigh, &orig_node->neigh_list, list) { |
| 828 | if (best && (bao->bat_neigh_cmp(neigh, if_outgoing, |
| 829 | best, if_outgoing) <= 0)) |
| 830 | continue; |
| 831 | |
| 832 | if (!atomic_inc_not_zero(&neigh->refcount)) |
| 833 | continue; |
| 834 | |
| 835 | if (best) |
| 836 | batadv_neigh_node_free_ref(best); |
| 837 | |
| 838 | best = neigh; |
| 839 | } |
| 840 | rcu_read_unlock(); |
| 841 | |
| 842 | return best; |
| 843 | } |
| 844 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 845 | /** |
| 846 | * batadv_purge_orig_node - purges obsolete information from an orig_node |
| 847 | * @bat_priv: the bat priv with all the soft interface information |
| 848 | * @orig_node: orig node which is to be checked |
| 849 | * |
| 850 | * This function checks if the orig_node or substructures of it have become |
| 851 | * obsolete, and purges this information if that's the case. |
| 852 | * |
| 853 | * Returns true if the orig_node is to be removed, false otherwise. |
| 854 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 855 | static bool batadv_purge_orig_node(struct batadv_priv *bat_priv, |
| 856 | struct batadv_orig_node *orig_node) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 857 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 858 | struct batadv_neigh_node *best_neigh_node; |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 859 | struct batadv_hard_iface *hard_iface; |
| 860 | bool changed; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 861 | |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 862 | if (batadv_has_timed_out(orig_node->last_seen, |
| 863 | 2 * BATADV_PURGE_TIMEOUT)) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 864 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 865 | "Originator timeout: originator %pM, last_seen %u\n", |
| 866 | orig_node->orig, |
| 867 | jiffies_to_msecs(orig_node->last_seen)); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 868 | return true; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 869 | } |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 870 | changed = batadv_purge_orig_ifinfo(bat_priv, orig_node); |
| 871 | changed = changed || batadv_purge_orig_neighbors(bat_priv, orig_node); |
| 872 | |
| 873 | if (!changed) |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 874 | return false; |
| 875 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 876 | /* first for NULL ... */ |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 877 | best_neigh_node = batadv_find_best_neighbor(bat_priv, orig_node, |
| 878 | BATADV_IF_DEFAULT); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 879 | batadv_update_route(bat_priv, orig_node, BATADV_IF_DEFAULT, |
| 880 | best_neigh_node); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 881 | if (best_neigh_node) |
| 882 | batadv_neigh_node_free_ref(best_neigh_node); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 883 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 884 | /* ... then for all other interfaces. */ |
| 885 | rcu_read_lock(); |
| 886 | list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) { |
| 887 | if (hard_iface->if_status != BATADV_IF_ACTIVE) |
| 888 | continue; |
| 889 | |
| 890 | if (hard_iface->soft_iface != bat_priv->soft_iface) |
| 891 | continue; |
| 892 | |
| 893 | best_neigh_node = batadv_find_best_neighbor(bat_priv, |
| 894 | orig_node, |
| 895 | hard_iface); |
| 896 | batadv_update_route(bat_priv, orig_node, hard_iface, |
| 897 | best_neigh_node); |
| 898 | if (best_neigh_node) |
| 899 | batadv_neigh_node_free_ref(best_neigh_node); |
| 900 | } |
| 901 | rcu_read_unlock(); |
| 902 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 903 | return false; |
| 904 | } |
| 905 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 906 | static void _batadv_purge_orig(struct batadv_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 907 | { |
Sven Eckelmann | 5bf74e9 | 2012-06-05 22:31:28 +0200 | [diff] [blame] | 908 | struct batadv_hashtable *hash = bat_priv->orig_hash; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 909 | struct hlist_node *node_tmp; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 910 | struct hlist_head *head; |
Marek Lindner | fb778ea | 2011-01-19 20:01:40 +0000 | [diff] [blame] | 911 | spinlock_t *list_lock; /* spinlock to protect write access */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 912 | struct batadv_orig_node *orig_node; |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 913 | uint32_t i; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 914 | |
| 915 | if (!hash) |
| 916 | return; |
| 917 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 918 | /* for all origins... */ |
| 919 | for (i = 0; i < hash->size; i++) { |
| 920 | head = &hash->table[i]; |
Marek Lindner | fb778ea | 2011-01-19 20:01:40 +0000 | [diff] [blame] | 921 | list_lock = &hash->list_locks[i]; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 922 | |
Marek Lindner | fb778ea | 2011-01-19 20:01:40 +0000 | [diff] [blame] | 923 | spin_lock_bh(list_lock); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 924 | hlist_for_each_entry_safe(orig_node, node_tmp, |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 925 | head, hash_entry) { |
Sven Eckelmann | 03fc7f8 | 2012-05-12 18:34:00 +0200 | [diff] [blame] | 926 | if (batadv_purge_orig_node(bat_priv, orig_node)) { |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 927 | batadv_gw_node_delete(bat_priv, orig_node); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 928 | hlist_del_rcu(&orig_node->hash_entry); |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 929 | batadv_orig_node_free_ref(orig_node); |
Marek Lindner | fb778ea | 2011-01-19 20:01:40 +0000 | [diff] [blame] | 930 | continue; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 931 | } |
Martin Hundebøll | 610bfc6bc | 2013-05-23 16:53:02 +0200 | [diff] [blame] | 932 | |
| 933 | batadv_frag_purge_orig(orig_node, |
| 934 | batadv_frag_check_entry); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 935 | } |
Marek Lindner | fb778ea | 2011-01-19 20:01:40 +0000 | [diff] [blame] | 936 | spin_unlock_bh(list_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 937 | } |
| 938 | |
Sven Eckelmann | 7cf06bc | 2012-05-12 02:09:29 +0200 | [diff] [blame] | 939 | batadv_gw_node_purge(bat_priv); |
| 940 | batadv_gw_election(bat_priv); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 941 | } |
| 942 | |
Sven Eckelmann | 03fc7f8 | 2012-05-12 18:34:00 +0200 | [diff] [blame] | 943 | static void batadv_purge_orig(struct work_struct *work) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 944 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 945 | struct delayed_work *delayed_work; |
| 946 | struct batadv_priv *bat_priv; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 947 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 948 | delayed_work = container_of(work, struct delayed_work, work); |
| 949 | bat_priv = container_of(delayed_work, struct batadv_priv, orig_work); |
Sven Eckelmann | 03fc7f8 | 2012-05-12 18:34:00 +0200 | [diff] [blame] | 950 | _batadv_purge_orig(bat_priv); |
Antonio Quartulli | 7241444 | 2012-12-25 13:14:37 +0100 | [diff] [blame] | 951 | queue_delayed_work(batadv_event_workqueue, |
| 952 | &bat_priv->orig_work, |
| 953 | msecs_to_jiffies(BATADV_ORIG_WORK_PERIOD)); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 954 | } |
| 955 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 956 | void batadv_purge_orig_ref(struct batadv_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 957 | { |
Sven Eckelmann | 03fc7f8 | 2012-05-12 18:34:00 +0200 | [diff] [blame] | 958 | _batadv_purge_orig(bat_priv); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 959 | } |
| 960 | |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 961 | int batadv_orig_seq_print_text(struct seq_file *seq, void *offset) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 962 | { |
| 963 | struct net_device *net_dev = (struct net_device *)seq->private; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 964 | struct batadv_priv *bat_priv = netdev_priv(net_dev); |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 965 | struct batadv_hard_iface *primary_if; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 966 | |
Marek Lindner | 30da63a | 2012-08-03 17:15:46 +0200 | [diff] [blame] | 967 | primary_if = batadv_seq_print_text_primary_if_get(seq); |
| 968 | if (!primary_if) |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 969 | return 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 970 | |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 971 | seq_printf(seq, "[B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s %s)]\n", |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 972 | BATADV_SOURCE_VERSION, primary_if->net_dev->name, |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 973 | primary_if->net_dev->dev_addr, net_dev->name, |
| 974 | bat_priv->bat_algo_ops->name); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 975 | |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 976 | batadv_hardif_free_ref(primary_if); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 977 | |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame] | 978 | if (!bat_priv->bat_algo_ops->bat_orig_print) { |
| 979 | seq_puts(seq, |
| 980 | "No printing function for this routing protocol\n"); |
| 981 | return 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 982 | } |
| 983 | |
Simon Wunderlich | cb1c92e | 2013-11-21 11:52:16 +0100 | [diff] [blame] | 984 | bat_priv->bat_algo_ops->bat_orig_print(bat_priv, seq, |
| 985 | BATADV_IF_DEFAULT); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 986 | |
Marek Lindner | 30da63a | 2012-08-03 17:15:46 +0200 | [diff] [blame] | 987 | return 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 988 | } |
| 989 | |
Simon Wunderlich | cb1c92e | 2013-11-21 11:52:16 +0100 | [diff] [blame] | 990 | /** |
| 991 | * batadv_orig_hardif_seq_print_text - writes originator infos for a specific |
| 992 | * outgoing interface |
| 993 | * @seq: debugfs table seq_file struct |
| 994 | * @offset: not used |
| 995 | * |
| 996 | * Returns 0 |
| 997 | */ |
| 998 | int batadv_orig_hardif_seq_print_text(struct seq_file *seq, void *offset) |
| 999 | { |
| 1000 | struct net_device *net_dev = (struct net_device *)seq->private; |
| 1001 | struct batadv_hard_iface *hard_iface; |
| 1002 | struct batadv_priv *bat_priv; |
| 1003 | |
| 1004 | hard_iface = batadv_hardif_get_by_netdev(net_dev); |
| 1005 | |
| 1006 | if (!hard_iface || !hard_iface->soft_iface) { |
| 1007 | seq_puts(seq, "Interface not known to B.A.T.M.A.N.\n"); |
| 1008 | goto out; |
| 1009 | } |
| 1010 | |
| 1011 | bat_priv = netdev_priv(hard_iface->soft_iface); |
| 1012 | if (!bat_priv->bat_algo_ops->bat_orig_print) { |
| 1013 | seq_puts(seq, |
| 1014 | "No printing function for this routing protocol\n"); |
| 1015 | goto out; |
| 1016 | } |
| 1017 | |
| 1018 | if (hard_iface->if_status != BATADV_IF_ACTIVE) { |
| 1019 | seq_puts(seq, "Interface not active\n"); |
| 1020 | goto out; |
| 1021 | } |
| 1022 | |
| 1023 | seq_printf(seq, "[B.A.T.M.A.N. adv %s, IF/MAC: %s/%pM (%s %s)]\n", |
| 1024 | BATADV_SOURCE_VERSION, hard_iface->net_dev->name, |
| 1025 | hard_iface->net_dev->dev_addr, |
| 1026 | hard_iface->soft_iface->name, bat_priv->bat_algo_ops->name); |
| 1027 | |
| 1028 | bat_priv->bat_algo_ops->bat_orig_print(bat_priv, seq, hard_iface); |
| 1029 | |
| 1030 | out: |
| 1031 | batadv_hardif_free_ref(hard_iface); |
| 1032 | return 0; |
| 1033 | } |
| 1034 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1035 | int batadv_orig_hash_add_if(struct batadv_hard_iface *hard_iface, |
| 1036 | int max_if_num) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1037 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1038 | struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); |
Antonio Quartulli | d0015fd | 2013-09-03 11:10:23 +0200 | [diff] [blame] | 1039 | struct batadv_algo_ops *bao = bat_priv->bat_algo_ops; |
Sven Eckelmann | 5bf74e9 | 2012-06-05 22:31:28 +0200 | [diff] [blame] | 1040 | struct batadv_hashtable *hash = bat_priv->orig_hash; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1041 | struct hlist_head *head; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1042 | struct batadv_orig_node *orig_node; |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 1043 | uint32_t i; |
| 1044 | int ret; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1045 | |
| 1046 | /* resize all orig nodes because orig_node->bcast_own(_sum) depend on |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1047 | * if_num |
| 1048 | */ |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1049 | for (i = 0; i < hash->size; i++) { |
| 1050 | head = &hash->table[i]; |
| 1051 | |
Marek Lindner | fb778ea | 2011-01-19 20:01:40 +0000 | [diff] [blame] | 1052 | rcu_read_lock(); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1053 | hlist_for_each_entry_rcu(orig_node, head, hash_entry) { |
Antonio Quartulli | d0015fd | 2013-09-03 11:10:23 +0200 | [diff] [blame] | 1054 | ret = 0; |
| 1055 | if (bao->bat_orig_add_if) |
| 1056 | ret = bao->bat_orig_add_if(orig_node, |
| 1057 | max_if_num); |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 1058 | if (ret == -ENOMEM) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1059 | goto err; |
| 1060 | } |
Marek Lindner | fb778ea | 2011-01-19 20:01:40 +0000 | [diff] [blame] | 1061 | rcu_read_unlock(); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1064 | return 0; |
| 1065 | |
| 1066 | err: |
Marek Lindner | fb778ea | 2011-01-19 20:01:40 +0000 | [diff] [blame] | 1067 | rcu_read_unlock(); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1068 | return -ENOMEM; |
| 1069 | } |
| 1070 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1071 | int batadv_orig_hash_del_if(struct batadv_hard_iface *hard_iface, |
| 1072 | int max_if_num) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1073 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1074 | struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); |
Sven Eckelmann | 5bf74e9 | 2012-06-05 22:31:28 +0200 | [diff] [blame] | 1075 | struct batadv_hashtable *hash = bat_priv->orig_hash; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1076 | struct hlist_head *head; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1077 | struct batadv_hard_iface *hard_iface_tmp; |
| 1078 | struct batadv_orig_node *orig_node; |
Antonio Quartulli | d0015fd | 2013-09-03 11:10:23 +0200 | [diff] [blame] | 1079 | struct batadv_algo_ops *bao = bat_priv->bat_algo_ops; |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 1080 | uint32_t i; |
| 1081 | int ret; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1082 | |
| 1083 | /* resize all orig nodes because orig_node->bcast_own(_sum) depend on |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1084 | * if_num |
| 1085 | */ |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1086 | for (i = 0; i < hash->size; i++) { |
| 1087 | head = &hash->table[i]; |
| 1088 | |
Marek Lindner | fb778ea | 2011-01-19 20:01:40 +0000 | [diff] [blame] | 1089 | rcu_read_lock(); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1090 | hlist_for_each_entry_rcu(orig_node, head, hash_entry) { |
Antonio Quartulli | d0015fd | 2013-09-03 11:10:23 +0200 | [diff] [blame] | 1091 | ret = 0; |
| 1092 | if (bao->bat_orig_del_if) |
| 1093 | ret = bao->bat_orig_del_if(orig_node, |
| 1094 | max_if_num, |
| 1095 | hard_iface->if_num); |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 1096 | if (ret == -ENOMEM) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1097 | goto err; |
| 1098 | } |
Marek Lindner | fb778ea | 2011-01-19 20:01:40 +0000 | [diff] [blame] | 1099 | rcu_read_unlock(); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | /* renumber remaining batman interfaces _inside_ of orig_hash_lock */ |
| 1103 | rcu_read_lock(); |
Sven Eckelmann | 3193e8f | 2012-05-12 02:09:42 +0200 | [diff] [blame] | 1104 | list_for_each_entry_rcu(hard_iface_tmp, &batadv_hardif_list, list) { |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 1105 | if (hard_iface_tmp->if_status == BATADV_IF_NOT_IN_USE) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1106 | continue; |
| 1107 | |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 1108 | if (hard_iface == hard_iface_tmp) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1109 | continue; |
| 1110 | |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 1111 | if (hard_iface->soft_iface != hard_iface_tmp->soft_iface) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1112 | continue; |
| 1113 | |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 1114 | if (hard_iface_tmp->if_num > hard_iface->if_num) |
| 1115 | hard_iface_tmp->if_num--; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1116 | } |
| 1117 | rcu_read_unlock(); |
| 1118 | |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 1119 | hard_iface->if_num = -1; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1120 | return 0; |
| 1121 | |
| 1122 | err: |
Marek Lindner | fb778ea | 2011-01-19 20:01:40 +0000 | [diff] [blame] | 1123 | rcu_read_unlock(); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1124 | return -ENOMEM; |
| 1125 | } |