| .. | .. |
|---|
| 1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
|---|
| 2 | | -/* Copyright (C) 2009-2018 B.A.T.M.A.N. contributors: |
|---|
| 2 | +/* Copyright (C) 2009-2020 B.A.T.M.A.N. contributors: |
|---|
| 3 | 3 | * |
|---|
| 4 | 4 | * Marek Lindner |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or |
|---|
| 7 | | - * modify it under the terms of version 2 of the GNU General Public |
|---|
| 8 | | - * License as published by the Free Software Foundation. |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is distributed in the hope that it will be useful, but |
|---|
| 11 | | - * WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 13 | | - * General Public License for more details. |
|---|
| 14 | | - * |
|---|
| 15 | | - * You should have received a copy of the GNU General Public License |
|---|
| 16 | | - * along with this program; if not, see <http://www.gnu.org/licenses/>. |
|---|
| 17 | 5 | */ |
|---|
| 18 | 6 | |
|---|
| 19 | 7 | #include "gateway_client.h" |
|---|
| .. | .. |
|---|
| 47 | 35 | #include <uapi/linux/batadv_packet.h> |
|---|
| 48 | 36 | #include <uapi/linux/batman_adv.h> |
|---|
| 49 | 37 | |
|---|
| 50 | | -#include "gateway_common.h" |
|---|
| 51 | 38 | #include "hard-interface.h" |
|---|
| 52 | 39 | #include "log.h" |
|---|
| 53 | 40 | #include "netlink.h" |
|---|
| 54 | 41 | #include "originator.h" |
|---|
| 55 | 42 | #include "routing.h" |
|---|
| 56 | 43 | #include "soft-interface.h" |
|---|
| 57 | | -#include "sysfs.h" |
|---|
| 58 | 44 | #include "translation-table.h" |
|---|
| 59 | 45 | |
|---|
| 60 | 46 | /* These are the offsets of the "hw type" and "hw address length" in the dhcp |
|---|
| .. | .. |
|---|
| 74 | 60 | * after rcu grace period |
|---|
| 75 | 61 | * @ref: kref pointer of the gw_node |
|---|
| 76 | 62 | */ |
|---|
| 77 | | -static void batadv_gw_node_release(struct kref *ref) |
|---|
| 63 | +void batadv_gw_node_release(struct kref *ref) |
|---|
| 78 | 64 | { |
|---|
| 79 | 65 | struct batadv_gw_node *gw_node; |
|---|
| 80 | 66 | |
|---|
| .. | .. |
|---|
| 82 | 68 | |
|---|
| 83 | 69 | batadv_orig_node_put(gw_node->orig_node); |
|---|
| 84 | 70 | kfree_rcu(gw_node, rcu); |
|---|
| 85 | | -} |
|---|
| 86 | | - |
|---|
| 87 | | -/** |
|---|
| 88 | | - * batadv_gw_node_put() - decrement the gw_node refcounter and possibly release |
|---|
| 89 | | - * it |
|---|
| 90 | | - * @gw_node: gateway node to free |
|---|
| 91 | | - */ |
|---|
| 92 | | -void batadv_gw_node_put(struct batadv_gw_node *gw_node) |
|---|
| 93 | | -{ |
|---|
| 94 | | - kref_put(&gw_node->refcount, batadv_gw_node_release); |
|---|
| 95 | 71 | } |
|---|
| 96 | 72 | |
|---|
| 97 | 73 | /** |
|---|
| .. | .. |
|---|
| 160 | 136 | if (new_gw_node) |
|---|
| 161 | 137 | kref_get(&new_gw_node->refcount); |
|---|
| 162 | 138 | |
|---|
| 163 | | - curr_gw_node = rcu_dereference_protected(bat_priv->gw.curr_gw, 1); |
|---|
| 164 | | - rcu_assign_pointer(bat_priv->gw.curr_gw, new_gw_node); |
|---|
| 139 | + curr_gw_node = rcu_replace_pointer(bat_priv->gw.curr_gw, new_gw_node, |
|---|
| 140 | + true); |
|---|
| 165 | 141 | |
|---|
| 166 | 142 | if (curr_gw_node) |
|---|
| 167 | 143 | batadv_gw_node_put(curr_gw_node); |
|---|
| .. | .. |
|---|
| 377 | 353 | |
|---|
| 378 | 354 | kref_get(&gw_node->refcount); |
|---|
| 379 | 355 | hlist_add_head_rcu(&gw_node->list, &bat_priv->gw.gateway_list); |
|---|
| 356 | + bat_priv->gw.generation++; |
|---|
| 380 | 357 | |
|---|
| 381 | 358 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
|---|
| 382 | 359 | "Found new gateway %pM -> gw bandwidth: %u.%u/%u.%u MBit\n", |
|---|
| .. | .. |
|---|
| 472 | 449 | if (!hlist_unhashed(&gw_node->list)) { |
|---|
| 473 | 450 | hlist_del_init_rcu(&gw_node->list); |
|---|
| 474 | 451 | batadv_gw_node_put(gw_node); |
|---|
| 452 | + bat_priv->gw.generation++; |
|---|
| 475 | 453 | } |
|---|
| 476 | 454 | spin_unlock_bh(&bat_priv->gw.list_lock); |
|---|
| 477 | 455 | |
|---|
| .. | .. |
|---|
| 518 | 496 | &bat_priv->gw.gateway_list, list) { |
|---|
| 519 | 497 | hlist_del_init_rcu(&gw_node->list); |
|---|
| 520 | 498 | batadv_gw_node_put(gw_node); |
|---|
| 499 | + bat_priv->gw.generation++; |
|---|
| 521 | 500 | } |
|---|
| 522 | 501 | spin_unlock_bh(&bat_priv->gw.list_lock); |
|---|
| 523 | 502 | } |
|---|