diff options
Diffstat (limited to 'net/batman-adv/gateway_client.c')
-rw-r--r-- | net/batman-adv/gateway_client.c | 291 |
1 files changed, 148 insertions, 143 deletions
diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c index 47f7186dcefc..5fc162c8425a 100644 --- a/net/batman-adv/gateway_client.c +++ b/net/batman-adv/gateway_client.c | |||
@@ -1,5 +1,4 @@ | |||
1 | /* | 1 | /* Copyright (C) 2009-2012 B.A.T.M.A.N. contributors: |
2 | * Copyright (C) 2009-2012 B.A.T.M.A.N. contributors: | ||
3 | * | 2 | * |
4 | * Marek Lindner | 3 | * Marek Lindner |
5 | * | 4 | * |
@@ -16,7 +15,6 @@ | |||
16 | * along with this program; if not, write to the Free Software | 15 | * along with this program; if not, write to the Free Software |
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
18 | * 02110-1301, USA | 17 | * 02110-1301, USA |
19 | * | ||
20 | */ | 18 | */ |
21 | 19 | ||
22 | #include "main.h" | 20 | #include "main.h" |
@@ -33,17 +31,18 @@ | |||
33 | #include <linux/if_vlan.h> | 31 | #include <linux/if_vlan.h> |
34 | 32 | ||
35 | /* This is the offset of the options field in a dhcp packet starting at | 33 | /* This is the offset of the options field in a dhcp packet starting at |
36 | * the beginning of the dhcp header */ | 34 | * the beginning of the dhcp header |
37 | #define DHCP_OPTIONS_OFFSET 240 | 35 | */ |
38 | #define DHCP_REQUEST 3 | 36 | #define BATADV_DHCP_OPTIONS_OFFSET 240 |
37 | #define BATADV_DHCP_REQUEST 3 | ||
39 | 38 | ||
40 | static void gw_node_free_ref(struct gw_node *gw_node) | 39 | static void batadv_gw_node_free_ref(struct gw_node *gw_node) |
41 | { | 40 | { |
42 | if (atomic_dec_and_test(&gw_node->refcount)) | 41 | if (atomic_dec_and_test(&gw_node->refcount)) |
43 | kfree_rcu(gw_node, rcu); | 42 | kfree_rcu(gw_node, rcu); |
44 | } | 43 | } |
45 | 44 | ||
46 | static struct gw_node *gw_get_selected_gw_node(struct bat_priv *bat_priv) | 45 | static struct gw_node *batadv_gw_get_selected_gw_node(struct bat_priv *bat_priv) |
47 | { | 46 | { |
48 | struct gw_node *gw_node; | 47 | struct gw_node *gw_node; |
49 | 48 | ||
@@ -60,12 +59,12 @@ out: | |||
60 | return gw_node; | 59 | return gw_node; |
61 | } | 60 | } |
62 | 61 | ||
63 | struct orig_node *gw_get_selected_orig(struct bat_priv *bat_priv) | 62 | struct orig_node *batadv_gw_get_selected_orig(struct bat_priv *bat_priv) |
64 | { | 63 | { |
65 | struct gw_node *gw_node; | 64 | struct gw_node *gw_node; |
66 | struct orig_node *orig_node = NULL; | 65 | struct orig_node *orig_node = NULL; |
67 | 66 | ||
68 | gw_node = gw_get_selected_gw_node(bat_priv); | 67 | gw_node = batadv_gw_get_selected_gw_node(bat_priv); |
69 | if (!gw_node) | 68 | if (!gw_node) |
70 | goto out; | 69 | goto out; |
71 | 70 | ||
@@ -81,11 +80,12 @@ unlock: | |||
81 | rcu_read_unlock(); | 80 | rcu_read_unlock(); |
82 | out: | 81 | out: |
83 | if (gw_node) | 82 | if (gw_node) |
84 | gw_node_free_ref(gw_node); | 83 | batadv_gw_node_free_ref(gw_node); |
85 | return orig_node; | 84 | return orig_node; |
86 | } | 85 | } |
87 | 86 | ||
88 | static void gw_select(struct bat_priv *bat_priv, struct gw_node *new_gw_node) | 87 | static void batadv_gw_select(struct bat_priv *bat_priv, |
88 | struct gw_node *new_gw_node) | ||
89 | { | 89 | { |
90 | struct gw_node *curr_gw_node; | 90 | struct gw_node *curr_gw_node; |
91 | 91 | ||
@@ -98,17 +98,17 @@ static void gw_select(struct bat_priv *bat_priv, struct gw_node *new_gw_node) | |||
98 | rcu_assign_pointer(bat_priv->curr_gw, new_gw_node); | 98 | rcu_assign_pointer(bat_priv->curr_gw, new_gw_node); |
99 | 99 | ||
100 | if (curr_gw_node) | 100 | if (curr_gw_node) |
101 | gw_node_free_ref(curr_gw_node); | 101 | batadv_gw_node_free_ref(curr_gw_node); |
102 | 102 | ||
103 | spin_unlock_bh(&bat_priv->gw_list_lock); | 103 | spin_unlock_bh(&bat_priv->gw_list_lock); |
104 | } | 104 | } |
105 | 105 | ||
106 | void gw_deselect(struct bat_priv *bat_priv) | 106 | void batadv_gw_deselect(struct bat_priv *bat_priv) |
107 | { | 107 | { |
108 | atomic_set(&bat_priv->gw_reselect, 1); | 108 | atomic_set(&bat_priv->gw_reselect, 1); |
109 | } | 109 | } |
110 | 110 | ||
111 | static struct gw_node *gw_get_best_gw_node(struct bat_priv *bat_priv) | 111 | static struct gw_node *batadv_gw_get_best_gw_node(struct bat_priv *bat_priv) |
112 | { | 112 | { |
113 | struct neigh_node *router; | 113 | struct neigh_node *router; |
114 | struct hlist_node *node; | 114 | struct hlist_node *node; |
@@ -116,13 +116,15 @@ static struct gw_node *gw_get_best_gw_node(struct bat_priv *bat_priv) | |||
116 | uint32_t max_gw_factor = 0, tmp_gw_factor = 0; | 116 | uint32_t max_gw_factor = 0, tmp_gw_factor = 0; |
117 | uint8_t max_tq = 0; | 117 | uint8_t max_tq = 0; |
118 | int down, up; | 118 | int down, up; |
119 | struct orig_node *orig_node; | ||
119 | 120 | ||
120 | rcu_read_lock(); | 121 | rcu_read_lock(); |
121 | hlist_for_each_entry_rcu(gw_node, node, &bat_priv->gw_list, list) { | 122 | hlist_for_each_entry_rcu(gw_node, node, &bat_priv->gw_list, list) { |
122 | if (gw_node->deleted) | 123 | if (gw_node->deleted) |
123 | continue; | 124 | continue; |
124 | 125 | ||
125 | router = orig_node_get_router(gw_node->orig_node); | 126 | orig_node = gw_node->orig_node; |
127 | router = batadv_orig_node_get_router(orig_node); | ||
126 | if (!router) | 128 | if (!router) |
127 | continue; | 129 | continue; |
128 | 130 | ||
@@ -131,35 +133,34 @@ static struct gw_node *gw_get_best_gw_node(struct bat_priv *bat_priv) | |||
131 | 133 | ||
132 | switch (atomic_read(&bat_priv->gw_sel_class)) { | 134 | switch (atomic_read(&bat_priv->gw_sel_class)) { |
133 | case 1: /* fast connection */ | 135 | case 1: /* fast connection */ |
134 | gw_bandwidth_to_kbit(gw_node->orig_node->gw_flags, | 136 | batadv_gw_bandwidth_to_kbit(orig_node->gw_flags, |
135 | &down, &up); | 137 | &down, &up); |
136 | 138 | ||
137 | tmp_gw_factor = (router->tq_avg * router->tq_avg * | 139 | tmp_gw_factor = (router->tq_avg * router->tq_avg * |
138 | down * 100 * 100) / | 140 | down * 100 * 100) / |
139 | (TQ_LOCAL_WINDOW_SIZE * | 141 | (BATADV_TQ_LOCAL_WINDOW_SIZE * |
140 | TQ_LOCAL_WINDOW_SIZE * 64); | 142 | BATADV_TQ_LOCAL_WINDOW_SIZE * 64); |
141 | 143 | ||
142 | if ((tmp_gw_factor > max_gw_factor) || | 144 | if ((tmp_gw_factor > max_gw_factor) || |
143 | ((tmp_gw_factor == max_gw_factor) && | 145 | ((tmp_gw_factor == max_gw_factor) && |
144 | (router->tq_avg > max_tq))) { | 146 | (router->tq_avg > max_tq))) { |
145 | if (curr_gw) | 147 | if (curr_gw) |
146 | gw_node_free_ref(curr_gw); | 148 | batadv_gw_node_free_ref(curr_gw); |
147 | curr_gw = gw_node; | 149 | curr_gw = gw_node; |
148 | atomic_inc(&curr_gw->refcount); | 150 | atomic_inc(&curr_gw->refcount); |
149 | } | 151 | } |
150 | break; | 152 | break; |
151 | 153 | ||
152 | default: /** | 154 | default: /* 2: stable connection (use best statistic) |
153 | * 2: stable connection (use best statistic) | ||
154 | * 3: fast-switch (use best statistic but change as | 155 | * 3: fast-switch (use best statistic but change as |
155 | * soon as a better gateway appears) | 156 | * soon as a better gateway appears) |
156 | * XX: late-switch (use best statistic but change as | 157 | * XX: late-switch (use best statistic but change as |
157 | * soon as a better gateway appears which has | 158 | * soon as a better gateway appears which has |
158 | * $routing_class more tq points) | 159 | * $routing_class more tq points) |
159 | **/ | 160 | */ |
160 | if (router->tq_avg > max_tq) { | 161 | if (router->tq_avg > max_tq) { |
161 | if (curr_gw) | 162 | if (curr_gw) |
162 | gw_node_free_ref(curr_gw); | 163 | batadv_gw_node_free_ref(curr_gw); |
163 | curr_gw = gw_node; | 164 | curr_gw = gw_node; |
164 | atomic_inc(&curr_gw->refcount); | 165 | atomic_inc(&curr_gw->refcount); |
165 | } | 166 | } |
@@ -172,37 +173,36 @@ static struct gw_node *gw_get_best_gw_node(struct bat_priv *bat_priv) | |||
172 | if (tmp_gw_factor > max_gw_factor) | 173 | if (tmp_gw_factor > max_gw_factor) |
173 | max_gw_factor = tmp_gw_factor; | 174 | max_gw_factor = tmp_gw_factor; |
174 | 175 | ||
175 | gw_node_free_ref(gw_node); | 176 | batadv_gw_node_free_ref(gw_node); |
176 | 177 | ||
177 | next: | 178 | next: |
178 | neigh_node_free_ref(router); | 179 | batadv_neigh_node_free_ref(router); |
179 | } | 180 | } |
180 | rcu_read_unlock(); | 181 | rcu_read_unlock(); |
181 | 182 | ||
182 | return curr_gw; | 183 | return curr_gw; |
183 | } | 184 | } |
184 | 185 | ||
185 | void gw_election(struct bat_priv *bat_priv) | 186 | void batadv_gw_election(struct bat_priv *bat_priv) |
186 | { | 187 | { |
187 | struct gw_node *curr_gw = NULL, *next_gw = NULL; | 188 | struct gw_node *curr_gw = NULL, *next_gw = NULL; |
188 | struct neigh_node *router = NULL; | 189 | struct neigh_node *router = NULL; |
189 | char gw_addr[18] = { '\0' }; | 190 | char gw_addr[18] = { '\0' }; |
190 | 191 | ||
191 | /** | 192 | /* The batman daemon checks here if we already passed a full originator |
192 | * The batman daemon checks here if we already passed a full originator | ||
193 | * cycle in order to make sure we don't choose the first gateway we | 193 | * cycle in order to make sure we don't choose the first gateway we |
194 | * hear about. This check is based on the daemon's uptime which we | 194 | * hear about. This check is based on the daemon's uptime which we |
195 | * don't have. | 195 | * don't have. |
196 | **/ | 196 | */ |
197 | if (atomic_read(&bat_priv->gw_mode) != GW_MODE_CLIENT) | 197 | if (atomic_read(&bat_priv->gw_mode) != GW_MODE_CLIENT) |
198 | goto out; | 198 | goto out; |
199 | 199 | ||
200 | if (!atomic_dec_not_zero(&bat_priv->gw_reselect)) | 200 | if (!batadv_atomic_dec_not_zero(&bat_priv->gw_reselect)) |
201 | goto out; | 201 | goto out; |
202 | 202 | ||
203 | curr_gw = gw_get_selected_gw_node(bat_priv); | 203 | curr_gw = batadv_gw_get_selected_gw_node(bat_priv); |
204 | 204 | ||
205 | next_gw = gw_get_best_gw_node(bat_priv); | 205 | next_gw = batadv_gw_get_best_gw_node(bat_priv); |
206 | 206 | ||
207 | if (curr_gw == next_gw) | 207 | if (curr_gw == next_gw) |
208 | goto out; | 208 | goto out; |
@@ -210,53 +210,54 @@ void gw_election(struct bat_priv *bat_priv) | |||
210 | if (next_gw) { | 210 | if (next_gw) { |
211 | sprintf(gw_addr, "%pM", next_gw->orig_node->orig); | 211 | sprintf(gw_addr, "%pM", next_gw->orig_node->orig); |
212 | 212 | ||
213 | router = orig_node_get_router(next_gw->orig_node); | 213 | router = batadv_orig_node_get_router(next_gw->orig_node); |
214 | if (!router) { | 214 | if (!router) { |
215 | gw_deselect(bat_priv); | 215 | batadv_gw_deselect(bat_priv); |
216 | goto out; | 216 | goto out; |
217 | } | 217 | } |
218 | } | 218 | } |
219 | 219 | ||
220 | if ((curr_gw) && (!next_gw)) { | 220 | if ((curr_gw) && (!next_gw)) { |
221 | bat_dbg(DBG_BATMAN, bat_priv, | 221 | batadv_dbg(DBG_BATMAN, bat_priv, |
222 | "Removing selected gateway - no gateway in range\n"); | 222 | "Removing selected gateway - no gateway in range\n"); |
223 | throw_uevent(bat_priv, UEV_GW, UEV_DEL, NULL); | 223 | batadv_throw_uevent(bat_priv, UEV_GW, UEV_DEL, NULL); |
224 | } else if ((!curr_gw) && (next_gw)) { | 224 | } else if ((!curr_gw) && (next_gw)) { |
225 | bat_dbg(DBG_BATMAN, bat_priv, | 225 | batadv_dbg(DBG_BATMAN, bat_priv, |
226 | "Adding route to gateway %pM (gw_flags: %i, tq: %i)\n", | 226 | "Adding route to gateway %pM (gw_flags: %i, tq: %i)\n", |
227 | next_gw->orig_node->orig, next_gw->orig_node->gw_flags, | 227 | next_gw->orig_node->orig, |
228 | router->tq_avg); | 228 | next_gw->orig_node->gw_flags, router->tq_avg); |
229 | throw_uevent(bat_priv, UEV_GW, UEV_ADD, gw_addr); | 229 | batadv_throw_uevent(bat_priv, UEV_GW, UEV_ADD, gw_addr); |
230 | } else { | 230 | } else { |
231 | bat_dbg(DBG_BATMAN, bat_priv, | 231 | batadv_dbg(DBG_BATMAN, bat_priv, |
232 | "Changing route to gateway %pM (gw_flags: %i, tq: %i)\n", | 232 | "Changing route to gateway %pM (gw_flags: %i, tq: %i)\n", |
233 | next_gw->orig_node->orig, next_gw->orig_node->gw_flags, | 233 | next_gw->orig_node->orig, |
234 | router->tq_avg); | 234 | next_gw->orig_node->gw_flags, router->tq_avg); |
235 | throw_uevent(bat_priv, UEV_GW, UEV_CHANGE, gw_addr); | 235 | batadv_throw_uevent(bat_priv, UEV_GW, UEV_CHANGE, gw_addr); |
236 | } | 236 | } |
237 | 237 | ||
238 | gw_select(bat_priv, next_gw); | 238 | batadv_gw_select(bat_priv, next_gw); |
239 | 239 | ||
240 | out: | 240 | out: |
241 | if (curr_gw) | 241 | if (curr_gw) |
242 | gw_node_free_ref(curr_gw); | 242 | batadv_gw_node_free_ref(curr_gw); |
243 | if (next_gw) | 243 | if (next_gw) |
244 | gw_node_free_ref(next_gw); | 244 | batadv_gw_node_free_ref(next_gw); |
245 | if (router) | 245 | if (router) |
246 | neigh_node_free_ref(router); | 246 | batadv_neigh_node_free_ref(router); |
247 | } | 247 | } |
248 | 248 | ||
249 | void gw_check_election(struct bat_priv *bat_priv, struct orig_node *orig_node) | 249 | void batadv_gw_check_election(struct bat_priv *bat_priv, |
250 | struct orig_node *orig_node) | ||
250 | { | 251 | { |
251 | struct orig_node *curr_gw_orig; | 252 | struct orig_node *curr_gw_orig; |
252 | struct neigh_node *router_gw = NULL, *router_orig = NULL; | 253 | struct neigh_node *router_gw = NULL, *router_orig = NULL; |
253 | uint8_t gw_tq_avg, orig_tq_avg; | 254 | uint8_t gw_tq_avg, orig_tq_avg; |
254 | 255 | ||
255 | curr_gw_orig = gw_get_selected_orig(bat_priv); | 256 | curr_gw_orig = batadv_gw_get_selected_orig(bat_priv); |
256 | if (!curr_gw_orig) | 257 | if (!curr_gw_orig) |
257 | goto deselect; | 258 | goto deselect; |
258 | 259 | ||
259 | router_gw = orig_node_get_router(curr_gw_orig); | 260 | router_gw = batadv_orig_node_get_router(curr_gw_orig); |
260 | if (!router_gw) | 261 | if (!router_gw) |
261 | goto deselect; | 262 | goto deselect; |
262 | 263 | ||
@@ -264,7 +265,7 @@ void gw_check_election(struct bat_priv *bat_priv, struct orig_node *orig_node) | |||
264 | if (curr_gw_orig == orig_node) | 265 | if (curr_gw_orig == orig_node) |
265 | goto out; | 266 | goto out; |
266 | 267 | ||
267 | router_orig = orig_node_get_router(orig_node); | 268 | router_orig = batadv_orig_node_get_router(orig_node); |
268 | if (!router_orig) | 269 | if (!router_orig) |
269 | goto out; | 270 | goto out; |
270 | 271 | ||
@@ -275,33 +276,33 @@ void gw_check_election(struct bat_priv *bat_priv, struct orig_node *orig_node) | |||
275 | if (orig_tq_avg < gw_tq_avg) | 276 | if (orig_tq_avg < gw_tq_avg) |
276 | goto out; | 277 | goto out; |
277 | 278 | ||
278 | /** | 279 | /* if the routing class is greater than 3 the value tells us how much |
279 | * if the routing class is greater than 3 the value tells us how much | ||
280 | * greater the TQ value of the new gateway must be | 280 | * greater the TQ value of the new gateway must be |
281 | **/ | 281 | */ |
282 | if ((atomic_read(&bat_priv->gw_sel_class) > 3) && | 282 | if ((atomic_read(&bat_priv->gw_sel_class) > 3) && |
283 | (orig_tq_avg - gw_tq_avg < atomic_read(&bat_priv->gw_sel_class))) | 283 | (orig_tq_avg - gw_tq_avg < atomic_read(&bat_priv->gw_sel_class))) |
284 | goto out; | 284 | goto out; |
285 | 285 | ||
286 | bat_dbg(DBG_BATMAN, bat_priv, | 286 | batadv_dbg(DBG_BATMAN, bat_priv, |
287 | "Restarting gateway selection: better gateway found (tq curr: %i, tq new: %i)\n", | 287 | "Restarting gateway selection: better gateway found (tq curr: %i, tq new: %i)\n", |
288 | gw_tq_avg, orig_tq_avg); | 288 | gw_tq_avg, orig_tq_avg); |
289 | 289 | ||
290 | deselect: | 290 | deselect: |
291 | gw_deselect(bat_priv); | 291 | batadv_gw_deselect(bat_priv); |
292 | out: | 292 | out: |
293 | if (curr_gw_orig) | 293 | if (curr_gw_orig) |
294 | orig_node_free_ref(curr_gw_orig); | 294 | batadv_orig_node_free_ref(curr_gw_orig); |
295 | if (router_gw) | 295 | if (router_gw) |
296 | neigh_node_free_ref(router_gw); | 296 | batadv_neigh_node_free_ref(router_gw); |
297 | if (router_orig) | 297 | if (router_orig) |
298 | neigh_node_free_ref(router_orig); | 298 | batadv_neigh_node_free_ref(router_orig); |
299 | 299 | ||
300 | return; | 300 | return; |
301 | } | 301 | } |
302 | 302 | ||
303 | static void gw_node_add(struct bat_priv *bat_priv, | 303 | static void batadv_gw_node_add(struct bat_priv *bat_priv, |
304 | struct orig_node *orig_node, uint8_t new_gwflags) | 304 | struct orig_node *orig_node, |
305 | uint8_t new_gwflags) | ||
305 | { | 306 | { |
306 | struct gw_node *gw_node; | 307 | struct gw_node *gw_node; |
307 | int down, up; | 308 | int down, up; |
@@ -318,47 +319,46 @@ static void gw_node_add(struct bat_priv *bat_priv, | |||
318 | hlist_add_head_rcu(&gw_node->list, &bat_priv->gw_list); | 319 | hlist_add_head_rcu(&gw_node->list, &bat_priv->gw_list); |
319 | spin_unlock_bh(&bat_priv->gw_list_lock); | 320 | spin_unlock_bh(&bat_priv->gw_list_lock); |
320 | 321 | ||
321 | gw_bandwidth_to_kbit(new_gwflags, &down, &up); | 322 | batadv_gw_bandwidth_to_kbit(new_gwflags, &down, &up); |
322 | bat_dbg(DBG_BATMAN, bat_priv, | 323 | batadv_dbg(DBG_BATMAN, bat_priv, |
323 | "Found new gateway %pM -> gw_class: %i - %i%s/%i%s\n", | 324 | "Found new gateway %pM -> gw_class: %i - %i%s/%i%s\n", |
324 | orig_node->orig, new_gwflags, | 325 | orig_node->orig, new_gwflags, |
325 | (down > 2048 ? down / 1024 : down), | 326 | (down > 2048 ? down / 1024 : down), |
326 | (down > 2048 ? "MBit" : "KBit"), | 327 | (down > 2048 ? "MBit" : "KBit"), |
327 | (up > 2048 ? up / 1024 : up), | 328 | (up > 2048 ? up / 1024 : up), |
328 | (up > 2048 ? "MBit" : "KBit")); | 329 | (up > 2048 ? "MBit" : "KBit")); |
329 | } | 330 | } |
330 | 331 | ||
331 | void gw_node_update(struct bat_priv *bat_priv, | 332 | void batadv_gw_node_update(struct bat_priv *bat_priv, |
332 | struct orig_node *orig_node, uint8_t new_gwflags) | 333 | struct orig_node *orig_node, uint8_t new_gwflags) |
333 | { | 334 | { |
334 | struct hlist_node *node; | 335 | struct hlist_node *node; |
335 | struct gw_node *gw_node, *curr_gw; | 336 | struct gw_node *gw_node, *curr_gw; |
336 | 337 | ||
337 | /** | 338 | /* Note: We don't need a NULL check here, since curr_gw never gets |
338 | * Note: We don't need a NULL check here, since curr_gw never gets | ||
339 | * dereferenced. If curr_gw is NULL we also should not exit as we may | 339 | * dereferenced. If curr_gw is NULL we also should not exit as we may |
340 | * have this gateway in our list (duplication check!) even though we | 340 | * have this gateway in our list (duplication check!) even though we |
341 | * have no currently selected gateway. | 341 | * have no currently selected gateway. |
342 | */ | 342 | */ |
343 | curr_gw = gw_get_selected_gw_node(bat_priv); | 343 | curr_gw = batadv_gw_get_selected_gw_node(bat_priv); |
344 | 344 | ||
345 | rcu_read_lock(); | 345 | rcu_read_lock(); |
346 | hlist_for_each_entry_rcu(gw_node, node, &bat_priv->gw_list, list) { | 346 | hlist_for_each_entry_rcu(gw_node, node, &bat_priv->gw_list, list) { |
347 | if (gw_node->orig_node != orig_node) | 347 | if (gw_node->orig_node != orig_node) |
348 | continue; | 348 | continue; |
349 | 349 | ||
350 | bat_dbg(DBG_BATMAN, bat_priv, | 350 | batadv_dbg(DBG_BATMAN, bat_priv, |
351 | "Gateway class of originator %pM changed from %i to %i\n", | 351 | "Gateway class of originator %pM changed from %i to %i\n", |
352 | orig_node->orig, gw_node->orig_node->gw_flags, | 352 | orig_node->orig, gw_node->orig_node->gw_flags, |
353 | new_gwflags); | 353 | new_gwflags); |
354 | 354 | ||
355 | gw_node->deleted = 0; | 355 | gw_node->deleted = 0; |
356 | 356 | ||
357 | if (new_gwflags == NO_FLAGS) { | 357 | if (new_gwflags == BATADV_NO_FLAGS) { |
358 | gw_node->deleted = jiffies; | 358 | gw_node->deleted = jiffies; |
359 | bat_dbg(DBG_BATMAN, bat_priv, | 359 | batadv_dbg(DBG_BATMAN, bat_priv, |
360 | "Gateway %pM removed from gateway list\n", | 360 | "Gateway %pM removed from gateway list\n", |
361 | orig_node->orig); | 361 | orig_node->orig); |
362 | 362 | ||
363 | if (gw_node == curr_gw) | 363 | if (gw_node == curr_gw) |
364 | goto deselect; | 364 | goto deselect; |
@@ -367,34 +367,35 @@ void gw_node_update(struct bat_priv *bat_priv, | |||
367 | goto unlock; | 367 | goto unlock; |
368 | } | 368 | } |
369 | 369 | ||
370 | if (new_gwflags == NO_FLAGS) | 370 | if (new_gwflags == BATADV_NO_FLAGS) |
371 | goto unlock; | 371 | goto unlock; |
372 | 372 | ||
373 | gw_node_add(bat_priv, orig_node, new_gwflags); | 373 | batadv_gw_node_add(bat_priv, orig_node, new_gwflags); |
374 | goto unlock; | 374 | goto unlock; |
375 | 375 | ||
376 | deselect: | 376 | deselect: |
377 | gw_deselect(bat_priv); | 377 | batadv_gw_deselect(bat_priv); |
378 | unlock: | 378 | unlock: |
379 | rcu_read_unlock(); | 379 | rcu_read_unlock(); |
380 | 380 | ||
381 | if (curr_gw) | 381 | if (curr_gw) |
382 | gw_node_free_ref(curr_gw); | 382 | batadv_gw_node_free_ref(curr_gw); |
383 | } | 383 | } |
384 | 384 | ||
385 | void gw_node_delete(struct bat_priv *bat_priv, struct orig_node *orig_node) | 385 | void batadv_gw_node_delete(struct bat_priv *bat_priv, |
386 | struct orig_node *orig_node) | ||
386 | { | 387 | { |
387 | gw_node_update(bat_priv, orig_node, 0); | 388 | batadv_gw_node_update(bat_priv, orig_node, 0); |
388 | } | 389 | } |
389 | 390 | ||
390 | void gw_node_purge(struct bat_priv *bat_priv) | 391 | void batadv_gw_node_purge(struct bat_priv *bat_priv) |
391 | { | 392 | { |
392 | struct gw_node *gw_node, *curr_gw; | 393 | struct gw_node *gw_node, *curr_gw; |
393 | struct hlist_node *node, *node_tmp; | 394 | struct hlist_node *node, *node_tmp; |
394 | unsigned long timeout = msecs_to_jiffies(2 * PURGE_TIMEOUT); | 395 | unsigned long timeout = msecs_to_jiffies(2 * BATADV_PURGE_TIMEOUT); |
395 | int do_deselect = 0; | 396 | int do_deselect = 0; |
396 | 397 | ||
397 | curr_gw = gw_get_selected_gw_node(bat_priv); | 398 | curr_gw = batadv_gw_get_selected_gw_node(bat_priv); |
398 | 399 | ||
399 | spin_lock_bh(&bat_priv->gw_list_lock); | 400 | spin_lock_bh(&bat_priv->gw_list_lock); |
400 | 401 | ||
@@ -409,36 +410,35 @@ void gw_node_purge(struct bat_priv *bat_priv) | |||
409 | do_deselect = 1; | 410 | do_deselect = 1; |
410 | 411 | ||
411 | hlist_del_rcu(&gw_node->list); | 412 | hlist_del_rcu(&gw_node->list); |
412 | gw_node_free_ref(gw_node); | 413 | batadv_gw_node_free_ref(gw_node); |
413 | } | 414 | } |
414 | 415 | ||
415 | spin_unlock_bh(&bat_priv->gw_list_lock); | 416 | spin_unlock_bh(&bat_priv->gw_list_lock); |
416 | 417 | ||
417 | /* gw_deselect() needs to acquire the gw_list_lock */ | 418 | /* gw_deselect() needs to acquire the gw_list_lock */ |
418 | if (do_deselect) | 419 | if (do_deselect) |
419 | gw_deselect(bat_priv); | 420 | batadv_gw_deselect(bat_priv); |
420 | 421 | ||
421 | if (curr_gw) | 422 | if (curr_gw) |
422 | gw_node_free_ref(curr_gw); | 423 | batadv_gw_node_free_ref(curr_gw); |
423 | } | 424 | } |
424 | 425 | ||
425 | /** | 426 | /* fails if orig_node has no router */ |
426 | * fails if orig_node has no router | 427 | static int batadv_write_buffer_text(struct bat_priv *bat_priv, |
427 | */ | 428 | struct seq_file *seq, |
428 | static int _write_buffer_text(struct bat_priv *bat_priv, struct seq_file *seq, | 429 | const struct gw_node *gw_node) |
429 | const struct gw_node *gw_node) | ||
430 | { | 430 | { |
431 | struct gw_node *curr_gw; | 431 | struct gw_node *curr_gw; |
432 | struct neigh_node *router; | 432 | struct neigh_node *router; |
433 | int down, up, ret = -1; | 433 | int down, up, ret = -1; |
434 | 434 | ||
435 | gw_bandwidth_to_kbit(gw_node->orig_node->gw_flags, &down, &up); | 435 | batadv_gw_bandwidth_to_kbit(gw_node->orig_node->gw_flags, &down, &up); |
436 | 436 | ||
437 | router = orig_node_get_router(gw_node->orig_node); | 437 | router = batadv_orig_node_get_router(gw_node->orig_node); |
438 | if (!router) | 438 | if (!router) |
439 | goto out; | 439 | goto out; |
440 | 440 | ||
441 | curr_gw = gw_get_selected_gw_node(bat_priv); | 441 | curr_gw = batadv_gw_get_selected_gw_node(bat_priv); |
442 | 442 | ||
443 | ret = seq_printf(seq, "%s %pM (%3i) %pM [%10s]: %3i - %i%s/%i%s\n", | 443 | ret = seq_printf(seq, "%s %pM (%3i) %pM [%10s]: %3i - %i%s/%i%s\n", |
444 | (curr_gw == gw_node ? "=>" : " "), | 444 | (curr_gw == gw_node ? "=>" : " "), |
@@ -451,14 +451,14 @@ static int _write_buffer_text(struct bat_priv *bat_priv, struct seq_file *seq, | |||
451 | (up > 2048 ? up / 1024 : up), | 451 | (up > 2048 ? up / 1024 : up), |
452 | (up > 2048 ? "MBit" : "KBit")); | 452 | (up > 2048 ? "MBit" : "KBit")); |
453 | 453 | ||
454 | neigh_node_free_ref(router); | 454 | batadv_neigh_node_free_ref(router); |
455 | if (curr_gw) | 455 | if (curr_gw) |
456 | gw_node_free_ref(curr_gw); | 456 | batadv_gw_node_free_ref(curr_gw); |
457 | out: | 457 | out: |
458 | return ret; | 458 | return ret; |
459 | } | 459 | } |
460 | 460 | ||
461 | int gw_client_seq_print_text(struct seq_file *seq, void *offset) | 461 | int batadv_gw_client_seq_print_text(struct seq_file *seq, void *offset) |
462 | { | 462 | { |
463 | struct net_device *net_dev = (struct net_device *)seq->private; | 463 | struct net_device *net_dev = (struct net_device *)seq->private; |
464 | struct bat_priv *bat_priv = netdev_priv(net_dev); | 464 | struct bat_priv *bat_priv = netdev_priv(net_dev); |
@@ -467,7 +467,7 @@ int gw_client_seq_print_text(struct seq_file *seq, void *offset) | |||
467 | struct hlist_node *node; | 467 | struct hlist_node *node; |
468 | int gw_count = 0, ret = 0; | 468 | int gw_count = 0, ret = 0; |
469 | 469 | ||
470 | primary_if = primary_if_get_selected(bat_priv); | 470 | primary_if = batadv_primary_if_get_selected(bat_priv); |
471 | if (!primary_if) { | 471 | if (!primary_if) { |
472 | ret = seq_printf(seq, | 472 | ret = seq_printf(seq, |
473 | "BATMAN mesh %s disabled - please specify interfaces to enable it\n", | 473 | "BATMAN mesh %s disabled - please specify interfaces to enable it\n", |
@@ -484,8 +484,8 @@ int gw_client_seq_print_text(struct seq_file *seq, void *offset) | |||
484 | 484 | ||
485 | seq_printf(seq, | 485 | seq_printf(seq, |
486 | " %-12s (%s/%i) %17s [%10s]: gw_class ... [B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s)]\n", | 486 | " %-12s (%s/%i) %17s [%10s]: gw_class ... [B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s)]\n", |
487 | "Gateway", "#", TQ_MAX_VALUE, "Nexthop", "outgoingIF", | 487 | "Gateway", "#", BATADV_TQ_MAX_VALUE, "Nexthop", "outgoingIF", |
488 | SOURCE_VERSION, primary_if->net_dev->name, | 488 | BATADV_SOURCE_VERSION, primary_if->net_dev->name, |
489 | primary_if->net_dev->dev_addr, net_dev->name); | 489 | primary_if->net_dev->dev_addr, net_dev->name); |
490 | 490 | ||
491 | rcu_read_lock(); | 491 | rcu_read_lock(); |
@@ -494,7 +494,7 @@ int gw_client_seq_print_text(struct seq_file *seq, void *offset) | |||
494 | continue; | 494 | continue; |
495 | 495 | ||
496 | /* fails if orig_node has no router */ | 496 | /* fails if orig_node has no router */ |
497 | if (_write_buffer_text(bat_priv, seq, gw_node) < 0) | 497 | if (batadv_write_buffer_text(bat_priv, seq, gw_node) < 0) |
498 | continue; | 498 | continue; |
499 | 499 | ||
500 | gw_count++; | 500 | gw_count++; |
@@ -506,11 +506,11 @@ int gw_client_seq_print_text(struct seq_file *seq, void *offset) | |||
506 | 506 | ||
507 | out: | 507 | out: |
508 | if (primary_if) | 508 | if (primary_if) |
509 | hardif_free_ref(primary_if); | 509 | batadv_hardif_free_ref(primary_if); |
510 | return ret; | 510 | return ret; |
511 | } | 511 | } |
512 | 512 | ||
513 | static bool is_type_dhcprequest(struct sk_buff *skb, int header_len) | 513 | static bool batadv_is_type_dhcprequest(struct sk_buff *skb, int header_len) |
514 | { | 514 | { |
515 | int ret = false; | 515 | int ret = false; |
516 | unsigned char *p; | 516 | unsigned char *p; |
@@ -521,27 +521,29 @@ static bool is_type_dhcprequest(struct sk_buff *skb, int header_len) | |||
521 | 521 | ||
522 | pkt_len = skb_headlen(skb); | 522 | pkt_len = skb_headlen(skb); |
523 | 523 | ||
524 | if (pkt_len < header_len + DHCP_OPTIONS_OFFSET + 1) | 524 | if (pkt_len < header_len + BATADV_DHCP_OPTIONS_OFFSET + 1) |
525 | goto out; | 525 | goto out; |
526 | 526 | ||
527 | p = skb->data + header_len + DHCP_OPTIONS_OFFSET; | 527 | p = skb->data + header_len + BATADV_DHCP_OPTIONS_OFFSET; |
528 | pkt_len -= header_len + DHCP_OPTIONS_OFFSET + 1; | 528 | pkt_len -= header_len + BATADV_DHCP_OPTIONS_OFFSET + 1; |
529 | 529 | ||
530 | /* Access the dhcp option lists. Each entry is made up by: | 530 | /* Access the dhcp option lists. Each entry is made up by: |
531 | * - octet 1: option type | 531 | * - octet 1: option type |
532 | * - octet 2: option data len (only if type != 255 and 0) | 532 | * - octet 2: option data len (only if type != 255 and 0) |
533 | * - octet 3: option data */ | 533 | * - octet 3: option data |
534 | */ | ||
534 | while (*p != 255 && !ret) { | 535 | while (*p != 255 && !ret) { |
535 | /* p now points to the first octet: option type */ | 536 | /* p now points to the first octet: option type */ |
536 | if (*p == 53) { | 537 | if (*p == 53) { |
537 | /* type 53 is the message type option. | 538 | /* type 53 is the message type option. |
538 | * Jump the len octet and go to the data octet */ | 539 | * Jump the len octet and go to the data octet |
540 | */ | ||
539 | if (pkt_len < 2) | 541 | if (pkt_len < 2) |
540 | goto out; | 542 | goto out; |
541 | p += 2; | 543 | p += 2; |
542 | 544 | ||
543 | /* check if the message type is what we need */ | 545 | /* check if the message type is what we need */ |
544 | if (*p == DHCP_REQUEST) | 546 | if (*p == BATADV_DHCP_REQUEST) |
545 | ret = true; | 547 | ret = true; |
546 | break; | 548 | break; |
547 | } else if (*p == 0) { | 549 | } else if (*p == 0) { |
@@ -568,7 +570,7 @@ out: | |||
568 | return ret; | 570 | return ret; |
569 | } | 571 | } |
570 | 572 | ||
571 | bool gw_is_dhcp_target(struct sk_buff *skb, unsigned int *header_len) | 573 | bool batadv_gw_is_dhcp_target(struct sk_buff *skb, unsigned int *header_len) |
572 | { | 574 | { |
573 | struct ethhdr *ethhdr; | 575 | struct ethhdr *ethhdr; |
574 | struct iphdr *iphdr; | 576 | struct iphdr *iphdr; |
@@ -634,8 +636,8 @@ bool gw_is_dhcp_target(struct sk_buff *skb, unsigned int *header_len) | |||
634 | return true; | 636 | return true; |
635 | } | 637 | } |
636 | 638 | ||
637 | bool gw_out_of_range(struct bat_priv *bat_priv, | 639 | bool batadv_gw_out_of_range(struct bat_priv *bat_priv, |
638 | struct sk_buff *skb, struct ethhdr *ethhdr) | 640 | struct sk_buff *skb, struct ethhdr *ethhdr) |
639 | { | 641 | { |
640 | struct neigh_node *neigh_curr = NULL, *neigh_old = NULL; | 642 | struct neigh_node *neigh_curr = NULL, *neigh_old = NULL; |
641 | struct orig_node *orig_dst_node = NULL; | 643 | struct orig_node *orig_dst_node = NULL; |
@@ -644,30 +646,31 @@ bool gw_out_of_range(struct bat_priv *bat_priv, | |||
644 | unsigned int header_len = 0; | 646 | unsigned int header_len = 0; |
645 | uint8_t curr_tq_avg; | 647 | uint8_t curr_tq_avg; |
646 | 648 | ||
647 | ret = gw_is_dhcp_target(skb, &header_len); | 649 | ret = batadv_gw_is_dhcp_target(skb, &header_len); |
648 | if (!ret) | 650 | if (!ret) |
649 | goto out; | 651 | goto out; |
650 | 652 | ||
651 | orig_dst_node = transtable_search(bat_priv, ethhdr->h_source, | 653 | orig_dst_node = batadv_transtable_search(bat_priv, ethhdr->h_source, |
652 | ethhdr->h_dest); | 654 | ethhdr->h_dest); |
653 | if (!orig_dst_node) | 655 | if (!orig_dst_node) |
654 | goto out; | 656 | goto out; |
655 | 657 | ||
656 | if (!orig_dst_node->gw_flags) | 658 | if (!orig_dst_node->gw_flags) |
657 | goto out; | 659 | goto out; |
658 | 660 | ||
659 | ret = is_type_dhcprequest(skb, header_len); | 661 | ret = batadv_is_type_dhcprequest(skb, header_len); |
660 | if (!ret) | 662 | if (!ret) |
661 | goto out; | 663 | goto out; |
662 | 664 | ||
663 | switch (atomic_read(&bat_priv->gw_mode)) { | 665 | switch (atomic_read(&bat_priv->gw_mode)) { |
664 | case GW_MODE_SERVER: | 666 | case GW_MODE_SERVER: |
665 | /* If we are a GW then we are our best GW. We can artificially | 667 | /* If we are a GW then we are our best GW. We can artificially |
666 | * set the tq towards ourself as the maximum value */ | 668 | * set the tq towards ourself as the maximum value |
667 | curr_tq_avg = TQ_MAX_VALUE; | 669 | */ |
670 | curr_tq_avg = BATADV_TQ_MAX_VALUE; | ||
668 | break; | 671 | break; |
669 | case GW_MODE_CLIENT: | 672 | case GW_MODE_CLIENT: |
670 | curr_gw = gw_get_selected_gw_node(bat_priv); | 673 | curr_gw = batadv_gw_get_selected_gw_node(bat_priv); |
671 | if (!curr_gw) | 674 | if (!curr_gw) |
672 | goto out; | 675 | goto out; |
673 | 676 | ||
@@ -677,8 +680,10 @@ bool gw_out_of_range(struct bat_priv *bat_priv, | |||
677 | 680 | ||
678 | /* If the dhcp packet has been sent to a different gw, | 681 | /* If the dhcp packet has been sent to a different gw, |
679 | * we have to evaluate whether the old gw is still | 682 | * we have to evaluate whether the old gw is still |
680 | * reliable enough */ | 683 | * reliable enough |
681 | neigh_curr = find_router(bat_priv, curr_gw->orig_node, NULL); | 684 | */ |
685 | neigh_curr = batadv_find_router(bat_priv, curr_gw->orig_node, | ||
686 | NULL); | ||
682 | if (!neigh_curr) | 687 | if (!neigh_curr) |
683 | goto out; | 688 | goto out; |
684 | 689 | ||
@@ -689,21 +694,21 @@ bool gw_out_of_range(struct bat_priv *bat_priv, | |||
689 | goto out; | 694 | goto out; |
690 | } | 695 | } |
691 | 696 | ||
692 | neigh_old = find_router(bat_priv, orig_dst_node, NULL); | 697 | neigh_old = batadv_find_router(bat_priv, orig_dst_node, NULL); |
693 | if (!neigh_old) | 698 | if (!neigh_old) |
694 | goto out; | 699 | goto out; |
695 | 700 | ||
696 | if (curr_tq_avg - neigh_old->tq_avg > GW_THRESHOLD) | 701 | if (curr_tq_avg - neigh_old->tq_avg > BATADV_GW_THRESHOLD) |
697 | out_of_range = true; | 702 | out_of_range = true; |
698 | 703 | ||
699 | out: | 704 | out: |
700 | if (orig_dst_node) | 705 | if (orig_dst_node) |
701 | orig_node_free_ref(orig_dst_node); | 706 | batadv_orig_node_free_ref(orig_dst_node); |
702 | if (curr_gw) | 707 | if (curr_gw) |
703 | gw_node_free_ref(curr_gw); | 708 | batadv_gw_node_free_ref(curr_gw); |
704 | if (neigh_old) | 709 | if (neigh_old) |
705 | neigh_node_free_ref(neigh_old); | 710 | batadv_neigh_node_free_ref(neigh_old); |
706 | if (neigh_curr) | 711 | if (neigh_curr) |
707 | neigh_node_free_ref(neigh_curr); | 712 | batadv_neigh_node_free_ref(neigh_curr); |
708 | return out_of_range; | 713 | return out_of_range; |
709 | } | 714 | } |