Sven Eckelmann | 0046b04 | 2016-01-01 00:01:03 +0100 | [diff] [blame] | 1 | /* Copyright (C) 2009-2016 B.A.T.M.A.N. contributors: |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 2 | * |
| 3 | * Marek Lindner |
| 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 "gateway_client.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/byteorder/generic.h> |
Sven Eckelmann | d7129da | 2016-07-03 13:31:42 +0200 | [diff] [blame] | 23 | #include <linux/errno.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 24 | #include <linux/etherdevice.h> |
| 25 | #include <linux/fs.h> |
| 26 | #include <linux/if_ether.h> |
| 27 | #include <linux/if_vlan.h> |
| 28 | #include <linux/in.h> |
| 29 | #include <linux/ip.h> |
| 30 | #include <linux/ipv6.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 31 | #include <linux/kernel.h> |
Sven Eckelmann | e7aed32 | 2016-01-16 10:29:41 +0100 | [diff] [blame] | 32 | #include <linux/kref.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 33 | #include <linux/list.h> |
| 34 | #include <linux/netdevice.h> |
Sven Eckelmann | d7129da | 2016-07-03 13:31:42 +0200 | [diff] [blame] | 35 | #include <linux/netlink.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 36 | #include <linux/rculist.h> |
| 37 | #include <linux/rcupdate.h> |
| 38 | #include <linux/seq_file.h> |
| 39 | #include <linux/skbuff.h> |
| 40 | #include <linux/slab.h> |
| 41 | #include <linux/spinlock.h> |
| 42 | #include <linux/stddef.h> |
| 43 | #include <linux/udp.h> |
Sven Eckelmann | d7129da | 2016-07-03 13:31:42 +0200 | [diff] [blame] | 44 | #include <net/sock.h> |
| 45 | #include <uapi/linux/batman_adv.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 46 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 47 | #include "gateway_common.h" |
| 48 | #include "hard-interface.h" |
Sven Eckelmann | ba41208 | 2016-05-15 23:48:31 +0200 | [diff] [blame] | 49 | #include "log.h" |
Sven Eckelmann | d7129da | 2016-07-03 13:31:42 +0200 | [diff] [blame] | 50 | #include "netlink.h" |
Linus Lüssing | 57f0c07 | 2011-03-14 22:43:33 +0000 | [diff] [blame] | 51 | #include "originator.h" |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 52 | #include "packet.h" |
Antonio Quartulli | 43676ab5 | 2011-04-26 21:31:45 +0200 | [diff] [blame] | 53 | #include "routing.h" |
Sven Eckelmann | d7129da | 2016-07-03 13:31:42 +0200 | [diff] [blame] | 54 | #include "soft-interface.h" |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 55 | #include "sysfs.h" |
| 56 | #include "translation-table.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 57 | |
Antonio Quartulli | 6c413b1 | 2013-11-05 19:31:08 +0100 | [diff] [blame] | 58 | /* These are the offsets of the "hw type" and "hw address length" in the dhcp |
| 59 | * packet starting at the beginning of the dhcp header |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 60 | */ |
Antonio Quartulli | 6c413b1 | 2013-11-05 19:31:08 +0100 | [diff] [blame] | 61 | #define BATADV_DHCP_HTYPE_OFFSET 1 |
| 62 | #define BATADV_DHCP_HLEN_OFFSET 2 |
| 63 | /* Value of htype representing Ethernet */ |
| 64 | #define BATADV_DHCP_HTYPE_ETHERNET 0x01 |
| 65 | /* This is the offset of the "chaddr" field in the dhcp packet starting at the |
| 66 | * beginning of the dhcp header |
| 67 | */ |
| 68 | #define BATADV_DHCP_CHADDR_OFFSET 28 |
Antonio Quartulli | 43676ab5 | 2011-04-26 21:31:45 +0200 | [diff] [blame] | 69 | |
Sven Eckelmann | e7aed32 | 2016-01-16 10:29:41 +0100 | [diff] [blame] | 70 | /** |
| 71 | * batadv_gw_node_release - release gw_node from lists and queue for free after |
| 72 | * rcu grace period |
| 73 | * @ref: kref pointer of the gw_node |
| 74 | */ |
| 75 | static void batadv_gw_node_release(struct kref *ref) |
| 76 | { |
| 77 | struct batadv_gw_node *gw_node; |
| 78 | |
| 79 | gw_node = container_of(ref, struct batadv_gw_node, refcount); |
| 80 | |
Sven Eckelmann | 5d96731 | 2016-01-17 11:01:09 +0100 | [diff] [blame] | 81 | batadv_orig_node_put(gw_node->orig_node); |
Sven Eckelmann | e7aed32 | 2016-01-16 10:29:41 +0100 | [diff] [blame] | 82 | kfree_rcu(gw_node, rcu); |
| 83 | } |
| 84 | |
| 85 | /** |
Sven Eckelmann | 3a01743 | 2016-01-17 11:01:18 +0100 | [diff] [blame] | 86 | * batadv_gw_node_put - decrement the gw_node refcounter and possibly release it |
Sven Eckelmann | e7aed32 | 2016-01-16 10:29:41 +0100 | [diff] [blame] | 87 | * @gw_node: gateway node to free |
| 88 | */ |
Antonio Quartulli | 34d99cf | 2016-07-03 12:46:33 +0200 | [diff] [blame] | 89 | void batadv_gw_node_put(struct batadv_gw_node *gw_node) |
Marek Lindner | 25b6d3c | 2011-02-10 14:33:49 +0000 | [diff] [blame] | 90 | { |
Sven Eckelmann | e7aed32 | 2016-01-16 10:29:41 +0100 | [diff] [blame] | 91 | kref_put(&gw_node->refcount, batadv_gw_node_release); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Antonio Quartulli | 34d99cf | 2016-07-03 12:46:33 +0200 | [diff] [blame] | 94 | struct batadv_gw_node * |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 95 | batadv_gw_get_selected_gw_node(struct batadv_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 96 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 97 | struct batadv_gw_node *gw_node; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 98 | |
Linus Lüssing | 5d02b3c | 2011-02-13 21:13:02 +0000 | [diff] [blame] | 99 | rcu_read_lock(); |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 100 | gw_node = rcu_dereference(bat_priv->gw.curr_gw); |
Marek Lindner | c4aac1a | 2011-03-23 11:24:34 +0100 | [diff] [blame] | 101 | if (!gw_node) |
Linus Lüssing | 5d02b3c | 2011-02-13 21:13:02 +0000 | [diff] [blame] | 102 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 103 | |
Sven Eckelmann | e7aed32 | 2016-01-16 10:29:41 +0100 | [diff] [blame] | 104 | if (!kref_get_unless_zero(&gw_node->refcount)) |
Marek Lindner | c4aac1a | 2011-03-23 11:24:34 +0100 | [diff] [blame] | 105 | gw_node = NULL; |
| 106 | |
| 107 | out: |
| 108 | rcu_read_unlock(); |
| 109 | return gw_node; |
| 110 | } |
| 111 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 112 | struct batadv_orig_node * |
| 113 | batadv_gw_get_selected_orig(struct batadv_priv *bat_priv) |
Marek Lindner | c4aac1a | 2011-03-23 11:24:34 +0100 | [diff] [blame] | 114 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 115 | struct batadv_gw_node *gw_node; |
| 116 | struct batadv_orig_node *orig_node = NULL; |
Marek Lindner | c4aac1a | 2011-03-23 11:24:34 +0100 | [diff] [blame] | 117 | |
Sven Eckelmann | 1409a83 | 2012-05-12 18:33:55 +0200 | [diff] [blame] | 118 | gw_node = batadv_gw_get_selected_gw_node(bat_priv); |
Marek Lindner | c4aac1a | 2011-03-23 11:24:34 +0100 | [diff] [blame] | 119 | if (!gw_node) |
Marek Lindner | 7b36e8e | 2011-02-18 12:28:10 +0000 | [diff] [blame] | 120 | goto out; |
Linus Lüssing | 5d02b3c | 2011-02-13 21:13:02 +0000 | [diff] [blame] | 121 | |
Marek Lindner | c4aac1a | 2011-03-23 11:24:34 +0100 | [diff] [blame] | 122 | rcu_read_lock(); |
| 123 | orig_node = gw_node->orig_node; |
| 124 | if (!orig_node) |
| 125 | goto unlock; |
| 126 | |
Sven Eckelmann | 7c12439 | 2016-01-16 10:29:56 +0100 | [diff] [blame] | 127 | if (!kref_get_unless_zero(&orig_node->refcount)) |
Marek Lindner | 7b36e8e | 2011-02-18 12:28:10 +0000 | [diff] [blame] | 128 | orig_node = NULL; |
Linus Lüssing | 43c70ad | 2011-02-13 21:13:04 +0000 | [diff] [blame] | 129 | |
Marek Lindner | c4aac1a | 2011-03-23 11:24:34 +0100 | [diff] [blame] | 130 | unlock: |
Linus Lüssing | 5d02b3c | 2011-02-13 21:13:02 +0000 | [diff] [blame] | 131 | rcu_read_unlock(); |
Marek Lindner | c4aac1a | 2011-03-23 11:24:34 +0100 | [diff] [blame] | 132 | out: |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 133 | if (gw_node) |
Sven Eckelmann | 3a01743 | 2016-01-17 11:01:18 +0100 | [diff] [blame] | 134 | batadv_gw_node_put(gw_node); |
Marek Lindner | c4aac1a | 2011-03-23 11:24:34 +0100 | [diff] [blame] | 135 | return orig_node; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 138 | static void batadv_gw_select(struct batadv_priv *bat_priv, |
| 139 | struct batadv_gw_node *new_gw_node) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 140 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 141 | struct batadv_gw_node *curr_gw_node; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 142 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 143 | spin_lock_bh(&bat_priv->gw.list_lock); |
Marek Lindner | c4aac1a | 2011-03-23 11:24:34 +0100 | [diff] [blame] | 144 | |
Sven Eckelmann | a08d497 | 2016-03-05 16:09:22 +0100 | [diff] [blame] | 145 | if (new_gw_node) |
| 146 | kref_get(&new_gw_node->refcount); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 147 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 148 | curr_gw_node = rcu_dereference_protected(bat_priv->gw.curr_gw, 1); |
| 149 | rcu_assign_pointer(bat_priv->gw.curr_gw, new_gw_node); |
Marek Lindner | 25b6d3c | 2011-02-10 14:33:49 +0000 | [diff] [blame] | 150 | |
| 151 | if (curr_gw_node) |
Sven Eckelmann | 3a01743 | 2016-01-17 11:01:18 +0100 | [diff] [blame] | 152 | batadv_gw_node_put(curr_gw_node); |
Marek Lindner | c4aac1a | 2011-03-23 11:24:34 +0100 | [diff] [blame] | 153 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 154 | spin_unlock_bh(&bat_priv->gw.list_lock); |
Marek Lindner | c4aac1a | 2011-03-23 11:24:34 +0100 | [diff] [blame] | 155 | } |
| 156 | |
Antonio Quartulli | 4e820e7 | 2013-11-04 20:59:41 +0100 | [diff] [blame] | 157 | /** |
| 158 | * batadv_gw_reselect - force a gateway reselection |
| 159 | * @bat_priv: the bat priv with all the soft interface information |
| 160 | * |
| 161 | * Set a flag to remind the GW component to perform a new gateway reselection. |
| 162 | * However this function does not ensure that the current gateway is going to be |
| 163 | * deselected. The reselection mechanism may elect the same gateway once again. |
| 164 | * |
| 165 | * This means that invoking batadv_gw_reselect() does not guarantee a gateway |
| 166 | * change and therefore a uevent is not necessarily expected. |
| 167 | */ |
| 168 | void batadv_gw_reselect(struct batadv_priv *bat_priv) |
Marek Lindner | c4aac1a | 2011-03-23 11:24:34 +0100 | [diff] [blame] | 169 | { |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 170 | atomic_set(&bat_priv->gw.reselect, 1); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Antonio Quartulli | c6eaa3f | 2013-07-13 00:06:00 +0200 | [diff] [blame] | 173 | /** |
| 174 | * batadv_gw_check_client_stop - check if client mode has been switched off |
| 175 | * @bat_priv: the bat priv with all the soft interface information |
| 176 | * |
| 177 | * This function assumes the caller has checked that the gw state *is actually |
| 178 | * changing*. This function is not supposed to be called when there is no state |
| 179 | * change. |
| 180 | */ |
| 181 | void batadv_gw_check_client_stop(struct batadv_priv *bat_priv) |
| 182 | { |
| 183 | struct batadv_gw_node *curr_gw; |
| 184 | |
Antonio Quartulli | 3a24a63 | 2016-05-06 02:46:38 +0800 | [diff] [blame] | 185 | if (atomic_read(&bat_priv->gw.mode) != BATADV_GW_MODE_CLIENT) |
Antonio Quartulli | c6eaa3f | 2013-07-13 00:06:00 +0200 | [diff] [blame] | 186 | return; |
| 187 | |
| 188 | curr_gw = batadv_gw_get_selected_gw_node(bat_priv); |
| 189 | if (!curr_gw) |
| 190 | return; |
| 191 | |
Antonio Quartulli | f316318 | 2013-11-04 20:59:40 +0100 | [diff] [blame] | 192 | /* deselect the current gateway so that next time that client mode is |
| 193 | * enabled a proper GW_ADD event can be sent |
| 194 | */ |
| 195 | batadv_gw_select(bat_priv, NULL); |
| 196 | |
Antonio Quartulli | c6eaa3f | 2013-07-13 00:06:00 +0200 | [diff] [blame] | 197 | /* if batman-adv is switching the gw client mode off and a gateway was |
| 198 | * already selected, send a DEL uevent |
| 199 | */ |
| 200 | batadv_throw_uevent(bat_priv, BATADV_UEV_GW, BATADV_UEV_DEL, NULL); |
| 201 | |
Sven Eckelmann | 3a01743 | 2016-01-17 11:01:18 +0100 | [diff] [blame] | 202 | batadv_gw_node_put(curr_gw); |
Antonio Quartulli | c6eaa3f | 2013-07-13 00:06:00 +0200 | [diff] [blame] | 203 | } |
| 204 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 205 | void batadv_gw_election(struct batadv_priv *bat_priv) |
Antonio Quartulli | 2265c14 | 2011-04-27 00:22:00 +0200 | [diff] [blame] | 206 | { |
Sven Eckelmann | 4f248cf | 2015-06-09 20:50:49 +0200 | [diff] [blame] | 207 | struct batadv_gw_node *curr_gw = NULL; |
| 208 | struct batadv_gw_node *next_gw = NULL; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 209 | struct batadv_neigh_node *router = NULL; |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 210 | struct batadv_neigh_ifinfo *router_ifinfo = NULL; |
Antonio Quartulli | 19595e0 | 2011-06-12 11:58:58 +0200 | [diff] [blame] | 211 | char gw_addr[18] = { '\0' }; |
Antonio Quartulli | 2265c14 | 2011-04-27 00:22:00 +0200 | [diff] [blame] | 212 | |
Antonio Quartulli | 3a24a63 | 2016-05-06 02:46:38 +0800 | [diff] [blame] | 213 | if (atomic_read(&bat_priv->gw.mode) != BATADV_GW_MODE_CLIENT) |
Antonio Quartulli | 2265c14 | 2011-04-27 00:22:00 +0200 | [diff] [blame] | 214 | goto out; |
| 215 | |
Antonio Quartulli | 34d99cf | 2016-07-03 12:46:33 +0200 | [diff] [blame] | 216 | if (!bat_priv->algo_ops->gw.get_best_gw_node) |
| 217 | goto out; |
| 218 | |
Sven Eckelmann | 1409a83 | 2012-05-12 18:33:55 +0200 | [diff] [blame] | 219 | curr_gw = batadv_gw_get_selected_gw_node(bat_priv); |
Antonio Quartulli | 2265c14 | 2011-04-27 00:22:00 +0200 | [diff] [blame] | 220 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 221 | if (!batadv_atomic_dec_not_zero(&bat_priv->gw.reselect) && curr_gw) |
Marek Lindner | caa0bf6 | 2012-08-04 04:13:26 +0000 | [diff] [blame] | 222 | goto out; |
| 223 | |
Antonio Quartulli | 34d99cf | 2016-07-03 12:46:33 +0200 | [diff] [blame] | 224 | /* if gw.reselect is set to 1 it means that a previous call to |
| 225 | * gw.is_eligible() said that we have a new best GW, therefore it can |
| 226 | * now be picked from the list and selected |
| 227 | */ |
| 228 | next_gw = bat_priv->algo_ops->gw.get_best_gw_node(bat_priv); |
Antonio Quartulli | 2265c14 | 2011-04-27 00:22:00 +0200 | [diff] [blame] | 229 | |
| 230 | if (curr_gw == next_gw) |
| 231 | goto out; |
| 232 | |
| 233 | if (next_gw) { |
Antonio Quartulli | 19595e0 | 2011-06-12 11:58:58 +0200 | [diff] [blame] | 234 | sprintf(gw_addr, "%pM", next_gw->orig_node->orig); |
| 235 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 236 | router = batadv_orig_router_get(next_gw->orig_node, |
| 237 | BATADV_IF_DEFAULT); |
Antonio Quartulli | 2265c14 | 2011-04-27 00:22:00 +0200 | [diff] [blame] | 238 | if (!router) { |
Antonio Quartulli | 4e820e7 | 2013-11-04 20:59:41 +0100 | [diff] [blame] | 239 | batadv_gw_reselect(bat_priv); |
Antonio Quartulli | 2265c14 | 2011-04-27 00:22:00 +0200 | [diff] [blame] | 240 | goto out; |
| 241 | } |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 242 | |
| 243 | router_ifinfo = batadv_neigh_ifinfo_get(router, |
| 244 | BATADV_IF_DEFAULT); |
| 245 | if (!router_ifinfo) { |
| 246 | batadv_gw_reselect(bat_priv); |
| 247 | goto out; |
| 248 | } |
Antonio Quartulli | 2265c14 | 2011-04-27 00:22:00 +0200 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | if ((curr_gw) && (!next_gw)) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 252 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 253 | "Removing selected gateway - no gateway in range\n"); |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 254 | batadv_throw_uevent(bat_priv, BATADV_UEV_GW, BATADV_UEV_DEL, |
| 255 | NULL); |
Antonio Quartulli | 2265c14 | 2011-04-27 00:22:00 +0200 | [diff] [blame] | 256 | } else if ((!curr_gw) && (next_gw)) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 257 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 258 | "Adding route to gateway %pM (bandwidth: %u.%u/%u.%u MBit, tq: %i)\n", |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 259 | next_gw->orig_node->orig, |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 260 | next_gw->bandwidth_down / 10, |
| 261 | next_gw->bandwidth_down % 10, |
| 262 | next_gw->bandwidth_up / 10, |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 263 | next_gw->bandwidth_up % 10, |
| 264 | router_ifinfo->bat_iv.tq_avg); |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 265 | batadv_throw_uevent(bat_priv, BATADV_UEV_GW, BATADV_UEV_ADD, |
| 266 | gw_addr); |
Antonio Quartulli | 2265c14 | 2011-04-27 00:22:00 +0200 | [diff] [blame] | 267 | } else { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 268 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 269 | "Changing route to gateway %pM (bandwidth: %u.%u/%u.%u MBit, tq: %i)\n", |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 270 | next_gw->orig_node->orig, |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 271 | next_gw->bandwidth_down / 10, |
| 272 | next_gw->bandwidth_down % 10, |
| 273 | next_gw->bandwidth_up / 10, |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 274 | next_gw->bandwidth_up % 10, |
| 275 | router_ifinfo->bat_iv.tq_avg); |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 276 | batadv_throw_uevent(bat_priv, BATADV_UEV_GW, BATADV_UEV_CHANGE, |
| 277 | gw_addr); |
Antonio Quartulli | 2265c14 | 2011-04-27 00:22:00 +0200 | [diff] [blame] | 278 | } |
| 279 | |
Sven Eckelmann | 1409a83 | 2012-05-12 18:33:55 +0200 | [diff] [blame] | 280 | batadv_gw_select(bat_priv, next_gw); |
Antonio Quartulli | 2265c14 | 2011-04-27 00:22:00 +0200 | [diff] [blame] | 281 | |
Marek Lindner | c4aac1a | 2011-03-23 11:24:34 +0100 | [diff] [blame] | 282 | out: |
| 283 | if (curr_gw) |
Sven Eckelmann | 3a01743 | 2016-01-17 11:01:18 +0100 | [diff] [blame] | 284 | batadv_gw_node_put(curr_gw); |
Antonio Quartulli | 2265c14 | 2011-04-27 00:22:00 +0200 | [diff] [blame] | 285 | if (next_gw) |
Sven Eckelmann | 3a01743 | 2016-01-17 11:01:18 +0100 | [diff] [blame] | 286 | batadv_gw_node_put(next_gw); |
Antonio Quartulli | 2265c14 | 2011-04-27 00:22:00 +0200 | [diff] [blame] | 287 | if (router) |
Sven Eckelmann | 25bb250 | 2016-01-17 11:01:11 +0100 | [diff] [blame] | 288 | batadv_neigh_node_put(router); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 289 | if (router_ifinfo) |
Sven Eckelmann | 044fa3a | 2016-01-17 11:01:12 +0100 | [diff] [blame] | 290 | batadv_neigh_ifinfo_put(router_ifinfo); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 291 | } |
| 292 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 293 | void batadv_gw_check_election(struct batadv_priv *bat_priv, |
| 294 | struct batadv_orig_node *orig_node) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 295 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 296 | struct batadv_orig_node *curr_gw_orig; |
Antonio Quartulli | 34d99cf | 2016-07-03 12:46:33 +0200 | [diff] [blame] | 297 | |
| 298 | /* abort immediately if the routing algorithm does not support gateway |
| 299 | * election |
| 300 | */ |
| 301 | if (!bat_priv->algo_ops->gw.is_eligible) |
| 302 | return; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 303 | |
Sven Eckelmann | 7cf06bc | 2012-05-12 02:09:29 +0200 | [diff] [blame] | 304 | curr_gw_orig = batadv_gw_get_selected_orig(bat_priv); |
Linus Lüssing | 57f0c07 | 2011-03-14 22:43:33 +0000 | [diff] [blame] | 305 | if (!curr_gw_orig) |
Antonio Quartulli | 4e820e7 | 2013-11-04 20:59:41 +0100 | [diff] [blame] | 306 | goto reselect; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 307 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 308 | /* this node already is the gateway */ |
Linus Lüssing | 57f0c07 | 2011-03-14 22:43:33 +0000 | [diff] [blame] | 309 | if (curr_gw_orig == orig_node) |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 310 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 311 | |
Antonio Quartulli | 34d99cf | 2016-07-03 12:46:33 +0200 | [diff] [blame] | 312 | if (!bat_priv->algo_ops->gw.is_eligible(bat_priv, curr_gw_orig, |
| 313 | orig_node)) |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 314 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 315 | |
Antonio Quartulli | 4e820e7 | 2013-11-04 20:59:41 +0100 | [diff] [blame] | 316 | reselect: |
| 317 | batadv_gw_reselect(bat_priv); |
Linus Lüssing | 5d02b3c | 2011-02-13 21:13:02 +0000 | [diff] [blame] | 318 | out: |
Linus Lüssing | 57f0c07 | 2011-03-14 22:43:33 +0000 | [diff] [blame] | 319 | if (curr_gw_orig) |
Sven Eckelmann | 5d96731 | 2016-01-17 11:01:09 +0100 | [diff] [blame] | 320 | batadv_orig_node_put(curr_gw_orig); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 321 | } |
| 322 | |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 323 | /** |
| 324 | * batadv_gw_node_add - add gateway node to list of available gateways |
| 325 | * @bat_priv: the bat priv with all the soft interface information |
| 326 | * @orig_node: originator announcing gateway capabilities |
| 327 | * @gateway: announced bandwidth information |
| 328 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 329 | static void batadv_gw_node_add(struct batadv_priv *bat_priv, |
| 330 | struct batadv_orig_node *orig_node, |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 331 | struct batadv_tvlv_gateway_data *gateway) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 332 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 333 | struct batadv_gw_node *gw_node; |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 334 | |
| 335 | if (gateway->bandwidth_down == 0) |
| 336 | return; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 337 | |
Antonio Quartulli | 377fe0f | 2014-05-02 01:35:13 +0200 | [diff] [blame] | 338 | gw_node = kzalloc(sizeof(*gw_node), GFP_ATOMIC); |
Sven Eckelmann | c3ba37a7 | 2016-03-05 16:09:23 +0100 | [diff] [blame] | 339 | if (!gw_node) |
Antonio Quartulli | 377fe0f | 2014-05-02 01:35:13 +0200 | [diff] [blame] | 340 | return; |
Antonio Quartulli | 377fe0f | 2014-05-02 01:35:13 +0200 | [diff] [blame] | 341 | |
Sven Eckelmann | f665fa7 | 2016-07-15 17:39:27 +0200 | [diff] [blame] | 342 | kref_init(&gw_node->refcount); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 343 | INIT_HLIST_NODE(&gw_node->list); |
Sven Eckelmann | 55db2d5 | 2016-07-15 17:39:21 +0200 | [diff] [blame] | 344 | kref_get(&orig_node->refcount); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 345 | gw_node->orig_node = orig_node; |
Simon Wunderlich | 27a4d5e | 2015-06-24 14:50:19 +0200 | [diff] [blame] | 346 | gw_node->bandwidth_down = ntohl(gateway->bandwidth_down); |
| 347 | gw_node->bandwidth_up = ntohl(gateway->bandwidth_up); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 348 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 349 | spin_lock_bh(&bat_priv->gw.list_lock); |
Sven Eckelmann | f665fa7 | 2016-07-15 17:39:27 +0200 | [diff] [blame] | 350 | kref_get(&gw_node->refcount); |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 351 | hlist_add_head_rcu(&gw_node->list, &bat_priv->gw.list); |
| 352 | spin_unlock_bh(&bat_priv->gw.list_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 353 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 354 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 355 | "Found new gateway %pM -> gw bandwidth: %u.%u/%u.%u MBit\n", |
| 356 | orig_node->orig, |
| 357 | ntohl(gateway->bandwidth_down) / 10, |
| 358 | ntohl(gateway->bandwidth_down) % 10, |
| 359 | ntohl(gateway->bandwidth_up) / 10, |
| 360 | ntohl(gateway->bandwidth_up) % 10); |
Sven Eckelmann | f665fa7 | 2016-07-15 17:39:27 +0200 | [diff] [blame] | 361 | |
| 362 | /* don't return reference to new gw_node */ |
| 363 | batadv_gw_node_put(gw_node); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 364 | } |
| 365 | |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 366 | /** |
| 367 | * batadv_gw_node_get - retrieve gateway node from list of available gateways |
| 368 | * @bat_priv: the bat priv with all the soft interface information |
| 369 | * @orig_node: originator announcing gateway capabilities |
| 370 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 371 | * Return: gateway node if found or NULL otherwise. |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 372 | */ |
Antonio Quartulli | 50164d8 | 2016-07-03 12:46:34 +0200 | [diff] [blame] | 373 | struct batadv_gw_node *batadv_gw_node_get(struct batadv_priv *bat_priv, |
| 374 | struct batadv_orig_node *orig_node) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 375 | { |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 376 | struct batadv_gw_node *gw_node_tmp, *gw_node = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 377 | |
| 378 | rcu_read_lock(); |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 379 | hlist_for_each_entry_rcu(gw_node_tmp, &bat_priv->gw.list, list) { |
| 380 | if (gw_node_tmp->orig_node != orig_node) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 381 | continue; |
| 382 | |
Sven Eckelmann | e7aed32 | 2016-01-16 10:29:41 +0100 | [diff] [blame] | 383 | if (!kref_get_unless_zero(&gw_node_tmp->refcount)) |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 384 | continue; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 385 | |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 386 | gw_node = gw_node_tmp; |
| 387 | break; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 388 | } |
Marek Lindner | c4aac1a | 2011-03-23 11:24:34 +0100 | [diff] [blame] | 389 | rcu_read_unlock(); |
Antonio Quartulli | 71e4aa9 | 2011-04-25 22:44:32 +0200 | [diff] [blame] | 390 | |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 391 | return gw_node; |
| 392 | } |
| 393 | |
| 394 | /** |
| 395 | * batadv_gw_node_update - update list of available gateways with changed |
| 396 | * bandwidth information |
| 397 | * @bat_priv: the bat priv with all the soft interface information |
| 398 | * @orig_node: originator announcing gateway capabilities |
| 399 | * @gateway: announced bandwidth information |
| 400 | */ |
| 401 | void batadv_gw_node_update(struct batadv_priv *bat_priv, |
| 402 | struct batadv_orig_node *orig_node, |
| 403 | struct batadv_tvlv_gateway_data *gateway) |
| 404 | { |
| 405 | struct batadv_gw_node *gw_node, *curr_gw = NULL; |
| 406 | |
| 407 | gw_node = batadv_gw_node_get(bat_priv, orig_node); |
| 408 | if (!gw_node) { |
| 409 | batadv_gw_node_add(bat_priv, orig_node, gateway); |
| 410 | goto out; |
| 411 | } |
| 412 | |
| 413 | if ((gw_node->bandwidth_down == ntohl(gateway->bandwidth_down)) && |
| 414 | (gw_node->bandwidth_up == ntohl(gateway->bandwidth_up))) |
| 415 | goto out; |
| 416 | |
| 417 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
| 418 | "Gateway bandwidth of originator %pM changed from %u.%u/%u.%u MBit to %u.%u/%u.%u MBit\n", |
| 419 | orig_node->orig, |
| 420 | gw_node->bandwidth_down / 10, |
| 421 | gw_node->bandwidth_down % 10, |
| 422 | gw_node->bandwidth_up / 10, |
| 423 | gw_node->bandwidth_up % 10, |
| 424 | ntohl(gateway->bandwidth_down) / 10, |
| 425 | ntohl(gateway->bandwidth_down) % 10, |
| 426 | ntohl(gateway->bandwidth_up) / 10, |
| 427 | ntohl(gateway->bandwidth_up) % 10); |
| 428 | |
| 429 | gw_node->bandwidth_down = ntohl(gateway->bandwidth_down); |
| 430 | gw_node->bandwidth_up = ntohl(gateway->bandwidth_up); |
| 431 | |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 432 | if (ntohl(gateway->bandwidth_down) == 0) { |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 433 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
| 434 | "Gateway %pM removed from gateway list\n", |
| 435 | orig_node->orig); |
| 436 | |
| 437 | /* Note: We don't need a NULL check here, since curr_gw never |
| 438 | * gets dereferenced. |
| 439 | */ |
Simon Wunderlich | bd3524c | 2015-08-03 19:13:58 +0200 | [diff] [blame] | 440 | spin_lock_bh(&bat_priv->gw.list_lock); |
Sven Eckelmann | c18bdd0 | 2016-01-31 13:27:59 +0100 | [diff] [blame] | 441 | if (!hlist_unhashed(&gw_node->list)) { |
| 442 | hlist_del_init_rcu(&gw_node->list); |
Sven Eckelmann | 3a01743 | 2016-01-17 11:01:18 +0100 | [diff] [blame] | 443 | batadv_gw_node_put(gw_node); |
Sven Eckelmann | c18bdd0 | 2016-01-31 13:27:59 +0100 | [diff] [blame] | 444 | } |
Simon Wunderlich | bd3524c | 2015-08-03 19:13:58 +0200 | [diff] [blame] | 445 | spin_unlock_bh(&bat_priv->gw.list_lock); |
| 446 | |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 447 | curr_gw = batadv_gw_get_selected_gw_node(bat_priv); |
| 448 | if (gw_node == curr_gw) |
Antonio Quartulli | 4e820e7 | 2013-11-04 20:59:41 +0100 | [diff] [blame] | 449 | batadv_gw_reselect(bat_priv); |
Simon Wunderlich | bd3524c | 2015-08-03 19:13:58 +0200 | [diff] [blame] | 450 | |
| 451 | if (curr_gw) |
Sven Eckelmann | 3a01743 | 2016-01-17 11:01:18 +0100 | [diff] [blame] | 452 | batadv_gw_node_put(curr_gw); |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | out: |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 456 | if (gw_node) |
Sven Eckelmann | 3a01743 | 2016-01-17 11:01:18 +0100 | [diff] [blame] | 457 | batadv_gw_node_put(gw_node); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 458 | } |
| 459 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 460 | void batadv_gw_node_delete(struct batadv_priv *bat_priv, |
| 461 | struct batadv_orig_node *orig_node) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 462 | { |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 463 | struct batadv_tvlv_gateway_data gateway; |
| 464 | |
| 465 | gateway.bandwidth_down = 0; |
| 466 | gateway.bandwidth_up = 0; |
| 467 | |
| 468 | batadv_gw_node_update(bat_priv, orig_node, &gateway); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 469 | } |
| 470 | |
Simon Wunderlich | bd3524c | 2015-08-03 19:13:58 +0200 | [diff] [blame] | 471 | void batadv_gw_node_free(struct batadv_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 472 | { |
Simon Wunderlich | bd3524c | 2015-08-03 19:13:58 +0200 | [diff] [blame] | 473 | struct batadv_gw_node *gw_node; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 474 | struct hlist_node *node_tmp; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 475 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 476 | spin_lock_bh(&bat_priv->gw.list_lock); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 477 | hlist_for_each_entry_safe(gw_node, node_tmp, |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 478 | &bat_priv->gw.list, list) { |
Simon Wunderlich | bd3524c | 2015-08-03 19:13:58 +0200 | [diff] [blame] | 479 | hlist_del_init_rcu(&gw_node->list); |
Sven Eckelmann | 3a01743 | 2016-01-17 11:01:18 +0100 | [diff] [blame] | 480 | batadv_gw_node_put(gw_node); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 481 | } |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 482 | spin_unlock_bh(&bat_priv->gw.list_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 483 | } |
| 484 | |
Sven Eckelmann | dc1cbd1 | 2016-07-16 09:31:20 +0200 | [diff] [blame] | 485 | #ifdef CONFIG_BATMAN_ADV_DEBUGFS |
Sven Eckelmann | 7cf06bc | 2012-05-12 02:09:29 +0200 | [diff] [blame] | 486 | int batadv_gw_client_seq_print_text(struct seq_file *seq, void *offset) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 487 | { |
| 488 | struct net_device *net_dev = (struct net_device *)seq->private; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 489 | struct batadv_priv *bat_priv = netdev_priv(net_dev); |
| 490 | struct batadv_hard_iface *primary_if; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 491 | |
Marek Lindner | 30da63a | 2012-08-03 17:15:46 +0200 | [diff] [blame] | 492 | primary_if = batadv_seq_print_text_primary_if_get(seq); |
| 493 | if (!primary_if) |
Antonio Quartulli | 34d99cf | 2016-07-03 12:46:33 +0200 | [diff] [blame] | 494 | return 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 495 | |
Antonio Quartulli | 34d99cf | 2016-07-03 12:46:33 +0200 | [diff] [blame] | 496 | 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] | 497 | BATADV_SOURCE_VERSION, primary_if->net_dev->name, |
Antonio Quartulli | 34d99cf | 2016-07-03 12:46:33 +0200 | [diff] [blame] | 498 | primary_if->net_dev->dev_addr, net_dev->name, |
| 499 | bat_priv->algo_ops->name); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 500 | |
Antonio Quartulli | 34d99cf | 2016-07-03 12:46:33 +0200 | [diff] [blame] | 501 | batadv_hardif_put(primary_if); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 502 | |
Antonio Quartulli | 34d99cf | 2016-07-03 12:46:33 +0200 | [diff] [blame] | 503 | if (!bat_priv->algo_ops->gw.print) { |
| 504 | seq_puts(seq, |
| 505 | "No printing function for this routing protocol\n"); |
| 506 | return 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 507 | } |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 508 | |
Antonio Quartulli | 34d99cf | 2016-07-03 12:46:33 +0200 | [diff] [blame] | 509 | bat_priv->algo_ops->gw.print(bat_priv, seq); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 510 | |
Marek Lindner | 30da63a | 2012-08-03 17:15:46 +0200 | [diff] [blame] | 511 | return 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 512 | } |
Sven Eckelmann | dc1cbd1 | 2016-07-16 09:31:20 +0200 | [diff] [blame] | 513 | #endif |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 514 | |
Antonio Quartulli | 6c413b1 | 2013-11-05 19:31:08 +0100 | [diff] [blame] | 515 | /** |
Sven Eckelmann | d7129da | 2016-07-03 13:31:42 +0200 | [diff] [blame] | 516 | * batadv_gw_dump - Dump gateways into a message |
| 517 | * @msg: Netlink message to dump into |
| 518 | * @cb: Control block containing additional options |
| 519 | * |
| 520 | * Return: Error code, or length of message |
| 521 | */ |
| 522 | int batadv_gw_dump(struct sk_buff *msg, struct netlink_callback *cb) |
| 523 | { |
| 524 | struct batadv_hard_iface *primary_if = NULL; |
| 525 | struct net *net = sock_net(cb->skb->sk); |
| 526 | struct net_device *soft_iface; |
| 527 | struct batadv_priv *bat_priv; |
| 528 | int ifindex; |
| 529 | int ret; |
| 530 | |
| 531 | ifindex = batadv_netlink_get_ifindex(cb->nlh, |
| 532 | BATADV_ATTR_MESH_IFINDEX); |
| 533 | if (!ifindex) |
| 534 | return -EINVAL; |
| 535 | |
| 536 | soft_iface = dev_get_by_index(net, ifindex); |
| 537 | if (!soft_iface || !batadv_softif_is_valid(soft_iface)) { |
| 538 | ret = -ENODEV; |
| 539 | goto out; |
| 540 | } |
| 541 | |
| 542 | bat_priv = netdev_priv(soft_iface); |
| 543 | |
| 544 | primary_if = batadv_primary_if_get_selected(bat_priv); |
| 545 | if (!primary_if || primary_if->if_status != BATADV_IF_ACTIVE) { |
| 546 | ret = -ENOENT; |
| 547 | goto out; |
| 548 | } |
| 549 | |
| 550 | if (!bat_priv->algo_ops->gw.dump) { |
| 551 | ret = -EOPNOTSUPP; |
| 552 | goto out; |
| 553 | } |
| 554 | |
| 555 | bat_priv->algo_ops->gw.dump(msg, cb, bat_priv); |
| 556 | |
| 557 | ret = msg->len; |
| 558 | |
| 559 | out: |
| 560 | if (primary_if) |
| 561 | batadv_hardif_put(primary_if); |
| 562 | if (soft_iface) |
| 563 | dev_put(soft_iface); |
| 564 | |
| 565 | return ret; |
| 566 | } |
| 567 | |
| 568 | /** |
Antonio Quartulli | 6c413b1 | 2013-11-05 19:31:08 +0100 | [diff] [blame] | 569 | * batadv_gw_dhcp_recipient_get - check if a packet is a DHCP message |
| 570 | * @skb: the packet to check |
| 571 | * @header_len: a pointer to the batman-adv header size |
| 572 | * @chaddr: buffer where the client address will be stored. Valid |
| 573 | * only if the function returns BATADV_DHCP_TO_CLIENT |
| 574 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 575 | * This function may re-allocate the data buffer of the skb passed as argument. |
| 576 | * |
| 577 | * Return: |
Antonio Quartulli | 6c413b1 | 2013-11-05 19:31:08 +0100 | [diff] [blame] | 578 | * - BATADV_DHCP_NO if the packet is not a dhcp message or if there was an error |
| 579 | * while parsing it |
| 580 | * - BATADV_DHCP_TO_SERVER if this is a message going to the DHCP server |
| 581 | * - BATADV_DHCP_TO_CLIENT if this is a message going to a DHCP client |
Antonio Quartulli | 6c413b1 | 2013-11-05 19:31:08 +0100 | [diff] [blame] | 582 | */ |
| 583 | enum batadv_dhcp_recipient |
| 584 | batadv_gw_dhcp_recipient_get(struct sk_buff *skb, unsigned int *header_len, |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 585 | u8 *chaddr) |
Antonio Quartulli | 43676ab5 | 2011-04-26 21:31:45 +0200 | [diff] [blame] | 586 | { |
Antonio Quartulli | 6c413b1 | 2013-11-05 19:31:08 +0100 | [diff] [blame] | 587 | enum batadv_dhcp_recipient ret = BATADV_DHCP_NO; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 588 | struct ethhdr *ethhdr; |
| 589 | struct iphdr *iphdr; |
| 590 | struct ipv6hdr *ipv6hdr; |
| 591 | struct udphdr *udphdr; |
Antonio Quartulli | f7f8ed5 | 2013-05-12 21:51:15 +0200 | [diff] [blame] | 592 | struct vlan_ethhdr *vhdr; |
Antonio Quartulli | 6c413b1 | 2013-11-05 19:31:08 +0100 | [diff] [blame] | 593 | int chaddr_offset; |
Antonio Quartulli | f7f8ed5 | 2013-05-12 21:51:15 +0200 | [diff] [blame] | 594 | __be16 proto; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 595 | u8 *p; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 596 | |
| 597 | /* check for ethernet header */ |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 598 | if (!pskb_may_pull(skb, *header_len + ETH_HLEN)) |
Antonio Quartulli | 6c413b1 | 2013-11-05 19:31:08 +0100 | [diff] [blame] | 599 | return BATADV_DHCP_NO; |
| 600 | |
Linus Lüssing | 927c2ed | 2014-01-19 22:22:45 +0100 | [diff] [blame] | 601 | ethhdr = eth_hdr(skb); |
Antonio Quartulli | f7f8ed5 | 2013-05-12 21:51:15 +0200 | [diff] [blame] | 602 | proto = ethhdr->h_proto; |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 603 | *header_len += ETH_HLEN; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 604 | |
| 605 | /* check for initial vlan header */ |
Antonio Quartulli | f7f8ed5 | 2013-05-12 21:51:15 +0200 | [diff] [blame] | 606 | if (proto == htons(ETH_P_8021Q)) { |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 607 | if (!pskb_may_pull(skb, *header_len + VLAN_HLEN)) |
Antonio Quartulli | 6c413b1 | 2013-11-05 19:31:08 +0100 | [diff] [blame] | 608 | return BATADV_DHCP_NO; |
Antonio Quartulli | f7f8ed5 | 2013-05-12 21:51:15 +0200 | [diff] [blame] | 609 | |
Linus Lüssing | 927c2ed | 2014-01-19 22:22:45 +0100 | [diff] [blame] | 610 | vhdr = vlan_eth_hdr(skb); |
Antonio Quartulli | f7f8ed5 | 2013-05-12 21:51:15 +0200 | [diff] [blame] | 611 | proto = vhdr->h_vlan_encapsulated_proto; |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 612 | *header_len += VLAN_HLEN; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | /* check for ip header */ |
Antonio Quartulli | f7f8ed5 | 2013-05-12 21:51:15 +0200 | [diff] [blame] | 616 | switch (proto) { |
| 617 | case htons(ETH_P_IP): |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 618 | if (!pskb_may_pull(skb, *header_len + sizeof(*iphdr))) |
Antonio Quartulli | 6c413b1 | 2013-11-05 19:31:08 +0100 | [diff] [blame] | 619 | return BATADV_DHCP_NO; |
| 620 | |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 621 | iphdr = (struct iphdr *)(skb->data + *header_len); |
| 622 | *header_len += iphdr->ihl * 4; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 623 | |
| 624 | /* check for udp header */ |
| 625 | if (iphdr->protocol != IPPROTO_UDP) |
Antonio Quartulli | 6c413b1 | 2013-11-05 19:31:08 +0100 | [diff] [blame] | 626 | return BATADV_DHCP_NO; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 627 | |
| 628 | break; |
Antonio Quartulli | f7f8ed5 | 2013-05-12 21:51:15 +0200 | [diff] [blame] | 629 | case htons(ETH_P_IPV6): |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 630 | if (!pskb_may_pull(skb, *header_len + sizeof(*ipv6hdr))) |
Antonio Quartulli | 6c413b1 | 2013-11-05 19:31:08 +0100 | [diff] [blame] | 631 | return BATADV_DHCP_NO; |
| 632 | |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 633 | ipv6hdr = (struct ipv6hdr *)(skb->data + *header_len); |
| 634 | *header_len += sizeof(*ipv6hdr); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 635 | |
| 636 | /* check for udp header */ |
| 637 | if (ipv6hdr->nexthdr != IPPROTO_UDP) |
Antonio Quartulli | 6c413b1 | 2013-11-05 19:31:08 +0100 | [diff] [blame] | 638 | return BATADV_DHCP_NO; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 639 | |
| 640 | break; |
| 641 | default: |
Antonio Quartulli | 6c413b1 | 2013-11-05 19:31:08 +0100 | [diff] [blame] | 642 | return BATADV_DHCP_NO; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 643 | } |
| 644 | |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 645 | if (!pskb_may_pull(skb, *header_len + sizeof(*udphdr))) |
Antonio Quartulli | 6c413b1 | 2013-11-05 19:31:08 +0100 | [diff] [blame] | 646 | return BATADV_DHCP_NO; |
Linus Lüssing | 9d2c948 | 2013-08-06 20:21:15 +0200 | [diff] [blame] | 647 | |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 648 | udphdr = (struct udphdr *)(skb->data + *header_len); |
| 649 | *header_len += sizeof(*udphdr); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 650 | |
| 651 | /* check for bootp port */ |
Antonio Quartulli | 6c413b1 | 2013-11-05 19:31:08 +0100 | [diff] [blame] | 652 | switch (proto) { |
| 653 | case htons(ETH_P_IP): |
| 654 | if (udphdr->dest == htons(67)) |
| 655 | ret = BATADV_DHCP_TO_SERVER; |
| 656 | else if (udphdr->source == htons(67)) |
| 657 | ret = BATADV_DHCP_TO_CLIENT; |
| 658 | break; |
| 659 | case htons(ETH_P_IPV6): |
| 660 | if (udphdr->dest == htons(547)) |
| 661 | ret = BATADV_DHCP_TO_SERVER; |
| 662 | else if (udphdr->source == htons(547)) |
| 663 | ret = BATADV_DHCP_TO_CLIENT; |
| 664 | break; |
| 665 | } |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 666 | |
Antonio Quartulli | 6c413b1 | 2013-11-05 19:31:08 +0100 | [diff] [blame] | 667 | chaddr_offset = *header_len + BATADV_DHCP_CHADDR_OFFSET; |
| 668 | /* store the client address if the message is going to a client */ |
| 669 | if (ret == BATADV_DHCP_TO_CLIENT && |
| 670 | pskb_may_pull(skb, chaddr_offset + ETH_ALEN)) { |
| 671 | /* check if the DHCP packet carries an Ethernet DHCP */ |
| 672 | p = skb->data + *header_len + BATADV_DHCP_HTYPE_OFFSET; |
| 673 | if (*p != BATADV_DHCP_HTYPE_ETHERNET) |
| 674 | return BATADV_DHCP_NO; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 675 | |
Antonio Quartulli | 6c413b1 | 2013-11-05 19:31:08 +0100 | [diff] [blame] | 676 | /* check if the DHCP packet carries a valid Ethernet address */ |
| 677 | p = skb->data + *header_len + BATADV_DHCP_HLEN_OFFSET; |
| 678 | if (*p != ETH_ALEN) |
| 679 | return BATADV_DHCP_NO; |
| 680 | |
Antonio Quartulli | 8fdd015 | 2014-01-22 00:42:11 +0100 | [diff] [blame] | 681 | ether_addr_copy(chaddr, skb->data + chaddr_offset); |
Antonio Quartulli | 6c413b1 | 2013-11-05 19:31:08 +0100 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | return ret; |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 685 | } |
Antonio Quartulli | aa143d2 | 2014-09-01 14:37:27 +0200 | [diff] [blame] | 686 | |
Antonio Quartulli | bbb877e | 2013-06-04 12:11:42 +0200 | [diff] [blame] | 687 | /** |
| 688 | * batadv_gw_out_of_range - check if the dhcp request destination is the best gw |
| 689 | * @bat_priv: the bat priv with all the soft interface information |
| 690 | * @skb: the outgoing packet |
| 691 | * |
| 692 | * Check if the skb is a DHCP request and if it is sent to the current best GW |
| 693 | * server. Due to topology changes it may be the case that the GW server |
| 694 | * previously selected is not the best one anymore. |
| 695 | * |
Antonio Quartulli | bbb877e | 2013-06-04 12:11:42 +0200 | [diff] [blame] | 696 | * This call might reallocate skb data. |
Antonio Quartulli | 6c413b1 | 2013-11-05 19:31:08 +0100 | [diff] [blame] | 697 | * Must be invoked only when the DHCP packet is going TO a DHCP SERVER. |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 698 | * |
| 699 | * Return: true if the packet destination is unicast and it is not the best gw, |
| 700 | * false otherwise. |
Antonio Quartulli | bbb877e | 2013-06-04 12:11:42 +0200 | [diff] [blame] | 701 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 702 | bool batadv_gw_out_of_range(struct batadv_priv *bat_priv, |
Linus Lüssing | 9d2c948 | 2013-08-06 20:21:15 +0200 | [diff] [blame] | 703 | struct sk_buff *skb) |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 704 | { |
Sven Eckelmann | 4f248cf | 2015-06-09 20:50:49 +0200 | [diff] [blame] | 705 | struct batadv_neigh_node *neigh_curr = NULL; |
| 706 | struct batadv_neigh_node *neigh_old = NULL; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 707 | struct batadv_orig_node *orig_dst_node = NULL; |
Sven Eckelmann | 4f248cf | 2015-06-09 20:50:49 +0200 | [diff] [blame] | 708 | struct batadv_gw_node *gw_node = NULL; |
| 709 | struct batadv_gw_node *curr_gw = NULL; |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 710 | struct batadv_neigh_ifinfo *curr_ifinfo, *old_ifinfo; |
Antonio Quartulli | 6c413b1 | 2013-11-05 19:31:08 +0100 | [diff] [blame] | 711 | struct ethhdr *ethhdr = (struct ethhdr *)skb->data; |
| 712 | bool out_of_range = false; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 713 | u8 curr_tq_avg; |
Antonio Quartulli | bbb877e | 2013-06-04 12:11:42 +0200 | [diff] [blame] | 714 | unsigned short vid; |
| 715 | |
| 716 | vid = batadv_get_vid(skb, 0); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 717 | |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 718 | orig_dst_node = batadv_transtable_search(bat_priv, ethhdr->h_source, |
Antonio Quartulli | bbb877e | 2013-06-04 12:11:42 +0200 | [diff] [blame] | 719 | ethhdr->h_dest, vid); |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 720 | if (!orig_dst_node) |
| 721 | goto out; |
| 722 | |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 723 | gw_node = batadv_gw_node_get(bat_priv, orig_dst_node); |
Antonio Quartulli | 0d16449 | 2014-12-20 13:48:57 +0100 | [diff] [blame] | 724 | if (!gw_node) |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 725 | goto out; |
| 726 | |
Antonio Quartulli | 3a24a63 | 2016-05-06 02:46:38 +0800 | [diff] [blame] | 727 | switch (atomic_read(&bat_priv->gw.mode)) { |
Sven Eckelmann | cd646ab | 2012-06-03 22:19:18 +0200 | [diff] [blame] | 728 | case BATADV_GW_MODE_SERVER: |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 729 | /* If we are a GW then we are our best GW. We can artificially |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 730 | * set the tq towards ourself as the maximum value |
| 731 | */ |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 732 | curr_tq_avg = BATADV_TQ_MAX_VALUE; |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 733 | break; |
Sven Eckelmann | cd646ab | 2012-06-03 22:19:18 +0200 | [diff] [blame] | 734 | case BATADV_GW_MODE_CLIENT: |
Sven Eckelmann | 1409a83 | 2012-05-12 18:33:55 +0200 | [diff] [blame] | 735 | curr_gw = batadv_gw_get_selected_gw_node(bat_priv); |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 736 | if (!curr_gw) |
| 737 | goto out; |
| 738 | |
| 739 | /* packet is going to our gateway */ |
| 740 | if (curr_gw->orig_node == orig_dst_node) |
| 741 | goto out; |
| 742 | |
| 743 | /* If the dhcp packet has been sent to a different gw, |
| 744 | * we have to evaluate whether the old gw is still |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 745 | * reliable enough |
| 746 | */ |
Sven Eckelmann | 30d3c51 | 2012-05-12 02:09:36 +0200 | [diff] [blame] | 747 | neigh_curr = batadv_find_router(bat_priv, curr_gw->orig_node, |
| 748 | NULL); |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 749 | if (!neigh_curr) |
| 750 | goto out; |
| 751 | |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 752 | curr_ifinfo = batadv_neigh_ifinfo_get(neigh_curr, |
| 753 | BATADV_IF_DEFAULT); |
| 754 | if (!curr_ifinfo) |
| 755 | goto out; |
| 756 | |
| 757 | curr_tq_avg = curr_ifinfo->bat_iv.tq_avg; |
Sven Eckelmann | 044fa3a | 2016-01-17 11:01:12 +0100 | [diff] [blame] | 758 | batadv_neigh_ifinfo_put(curr_ifinfo); |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 759 | |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 760 | break; |
Sven Eckelmann | cd646ab | 2012-06-03 22:19:18 +0200 | [diff] [blame] | 761 | case BATADV_GW_MODE_OFF: |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 762 | default: |
| 763 | goto out; |
Antonio Quartulli | 43676ab5 | 2011-04-26 21:31:45 +0200 | [diff] [blame] | 764 | } |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 765 | |
Sven Eckelmann | 30d3c51 | 2012-05-12 02:09:36 +0200 | [diff] [blame] | 766 | neigh_old = batadv_find_router(bat_priv, orig_dst_node, NULL); |
Dan Carpenter | 2ef04f4 | 2011-11-29 09:09:09 +0300 | [diff] [blame] | 767 | if (!neigh_old) |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 768 | goto out; |
| 769 | |
Simon Wunderlich | 8965233 | 2013-11-13 19:14:46 +0100 | [diff] [blame] | 770 | old_ifinfo = batadv_neigh_ifinfo_get(neigh_old, BATADV_IF_DEFAULT); |
| 771 | if (!old_ifinfo) |
| 772 | goto out; |
| 773 | |
| 774 | if ((curr_tq_avg - old_ifinfo->bat_iv.tq_avg) > BATADV_GW_THRESHOLD) |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 775 | out_of_range = true; |
Sven Eckelmann | 044fa3a | 2016-01-17 11:01:12 +0100 | [diff] [blame] | 776 | batadv_neigh_ifinfo_put(old_ifinfo); |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 777 | |
| 778 | out: |
| 779 | if (orig_dst_node) |
Sven Eckelmann | 5d96731 | 2016-01-17 11:01:09 +0100 | [diff] [blame] | 780 | batadv_orig_node_put(orig_dst_node); |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 781 | if (curr_gw) |
Sven Eckelmann | 3a01743 | 2016-01-17 11:01:18 +0100 | [diff] [blame] | 782 | batadv_gw_node_put(curr_gw); |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 783 | if (gw_node) |
Sven Eckelmann | 3a01743 | 2016-01-17 11:01:18 +0100 | [diff] [blame] | 784 | batadv_gw_node_put(gw_node); |
Antonio Quartulli | 43676ab5 | 2011-04-26 21:31:45 +0200 | [diff] [blame] | 785 | if (neigh_old) |
Sven Eckelmann | 25bb250 | 2016-01-17 11:01:11 +0100 | [diff] [blame] | 786 | batadv_neigh_node_put(neigh_old); |
Antonio Quartulli | 43676ab5 | 2011-04-26 21:31:45 +0200 | [diff] [blame] | 787 | if (neigh_curr) |
Sven Eckelmann | 25bb250 | 2016-01-17 11:01:11 +0100 | [diff] [blame] | 788 | batadv_neigh_node_put(neigh_curr); |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 789 | return out_of_range; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 790 | } |