diff options
Diffstat (limited to 'net/batman-adv/routing.c')
-rw-r--r-- | net/batman-adv/routing.c | 689 |
1 files changed, 373 insertions, 316 deletions
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c index 015471d801b4..bc2b88bbea1f 100644 --- a/net/batman-adv/routing.c +++ b/net/batman-adv/routing.c | |||
@@ -1,5 +1,4 @@ | |||
1 | /* | 1 | /* Copyright (C) 2007-2012 B.A.T.M.A.N. contributors: |
2 | * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors: | ||
3 | * | 2 | * |
4 | * Marek Lindner, Simon Wunderlich | 3 | * Marek Lindner, Simon Wunderlich |
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" |
@@ -31,19 +29,20 @@ | |||
31 | #include "unicast.h" | 29 | #include "unicast.h" |
32 | #include "bridge_loop_avoidance.h" | 30 | #include "bridge_loop_avoidance.h" |
33 | 31 | ||
34 | static int route_unicast_packet(struct sk_buff *skb, | 32 | static int batadv_route_unicast_packet(struct sk_buff *skb, |
35 | struct hard_iface *recv_if); | 33 | struct batadv_hard_iface *recv_if); |
36 | 34 | ||
37 | void slide_own_bcast_window(struct hard_iface *hard_iface) | 35 | void batadv_slide_own_bcast_window(struct batadv_hard_iface *hard_iface) |
38 | { | 36 | { |
39 | struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface); | 37 | struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); |
40 | struct hashtable_t *hash = bat_priv->orig_hash; | 38 | struct batadv_hashtable *hash = bat_priv->orig_hash; |
41 | struct hlist_node *node; | 39 | struct hlist_node *node; |
42 | struct hlist_head *head; | 40 | struct hlist_head *head; |
43 | struct orig_node *orig_node; | 41 | struct batadv_orig_node *orig_node; |
44 | unsigned long *word; | 42 | unsigned long *word; |
45 | uint32_t i; | 43 | uint32_t i; |
46 | size_t word_index; | 44 | size_t word_index; |
45 | uint8_t *w; | ||
47 | 46 | ||
48 | for (i = 0; i < hash->size; i++) { | 47 | for (i = 0; i < hash->size; i++) { |
49 | head = &hash->table[i]; | 48 | head = &hash->table[i]; |
@@ -51,49 +50,49 @@ void slide_own_bcast_window(struct hard_iface *hard_iface) | |||
51 | rcu_read_lock(); | 50 | rcu_read_lock(); |
52 | hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) { | 51 | hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) { |
53 | spin_lock_bh(&orig_node->ogm_cnt_lock); | 52 | spin_lock_bh(&orig_node->ogm_cnt_lock); |
54 | word_index = hard_iface->if_num * NUM_WORDS; | 53 | word_index = hard_iface->if_num * BATADV_NUM_WORDS; |
55 | word = &(orig_node->bcast_own[word_index]); | 54 | word = &(orig_node->bcast_own[word_index]); |
56 | 55 | ||
57 | bit_get_packet(bat_priv, word, 1, 0); | 56 | batadv_bit_get_packet(bat_priv, word, 1, 0); |
58 | orig_node->bcast_own_sum[hard_iface->if_num] = | 57 | w = &orig_node->bcast_own_sum[hard_iface->if_num]; |
59 | bitmap_weight(word, TQ_LOCAL_WINDOW_SIZE); | 58 | *w = bitmap_weight(word, BATADV_TQ_LOCAL_WINDOW_SIZE); |
60 | spin_unlock_bh(&orig_node->ogm_cnt_lock); | 59 | spin_unlock_bh(&orig_node->ogm_cnt_lock); |
61 | } | 60 | } |
62 | rcu_read_unlock(); | 61 | rcu_read_unlock(); |
63 | } | 62 | } |
64 | } | 63 | } |
65 | 64 | ||
66 | static void _update_route(struct bat_priv *bat_priv, | 65 | static void _batadv_update_route(struct batadv_priv *bat_priv, |
67 | struct orig_node *orig_node, | 66 | struct batadv_orig_node *orig_node, |
68 | struct neigh_node *neigh_node) | 67 | struct batadv_neigh_node *neigh_node) |
69 | { | 68 | { |
70 | struct neigh_node *curr_router; | 69 | struct batadv_neigh_node *curr_router; |
71 | 70 | ||
72 | curr_router = orig_node_get_router(orig_node); | 71 | curr_router = batadv_orig_node_get_router(orig_node); |
73 | 72 | ||
74 | /* route deleted */ | 73 | /* route deleted */ |
75 | if ((curr_router) && (!neigh_node)) { | 74 | if ((curr_router) && (!neigh_node)) { |
76 | bat_dbg(DBG_ROUTES, bat_priv, "Deleting route towards: %pM\n", | 75 | batadv_dbg(BATADV_DBG_ROUTES, bat_priv, |
77 | orig_node->orig); | 76 | "Deleting route towards: %pM\n", orig_node->orig); |
78 | tt_global_del_orig(bat_priv, orig_node, | 77 | batadv_tt_global_del_orig(bat_priv, orig_node, |
79 | "Deleted route towards originator"); | 78 | "Deleted route towards originator"); |
80 | 79 | ||
81 | /* route added */ | 80 | /* route added */ |
82 | } else if ((!curr_router) && (neigh_node)) { | 81 | } else if ((!curr_router) && (neigh_node)) { |
83 | 82 | ||
84 | bat_dbg(DBG_ROUTES, bat_priv, | 83 | batadv_dbg(BATADV_DBG_ROUTES, bat_priv, |
85 | "Adding route towards: %pM (via %pM)\n", | 84 | "Adding route towards: %pM (via %pM)\n", |
86 | orig_node->orig, neigh_node->addr); | 85 | orig_node->orig, neigh_node->addr); |
87 | /* route changed */ | 86 | /* route changed */ |
88 | } else if (neigh_node && curr_router) { | 87 | } else if (neigh_node && curr_router) { |
89 | bat_dbg(DBG_ROUTES, bat_priv, | 88 | batadv_dbg(BATADV_DBG_ROUTES, bat_priv, |
90 | "Changing route towards: %pM (now via %pM - was via %pM)\n", | 89 | "Changing route towards: %pM (now via %pM - was via %pM)\n", |
91 | orig_node->orig, neigh_node->addr, | 90 | orig_node->orig, neigh_node->addr, |
92 | curr_router->addr); | 91 | curr_router->addr); |
93 | } | 92 | } |
94 | 93 | ||
95 | if (curr_router) | 94 | if (curr_router) |
96 | neigh_node_free_ref(curr_router); | 95 | batadv_neigh_node_free_ref(curr_router); |
97 | 96 | ||
98 | /* increase refcount of new best neighbor */ | 97 | /* increase refcount of new best neighbor */ |
99 | if (neigh_node && !atomic_inc_not_zero(&neigh_node->refcount)) | 98 | if (neigh_node && !atomic_inc_not_zero(&neigh_node->refcount)) |
@@ -105,30 +104,31 @@ static void _update_route(struct bat_priv *bat_priv, | |||
105 | 104 | ||
106 | /* decrease refcount of previous best neighbor */ | 105 | /* decrease refcount of previous best neighbor */ |
107 | if (curr_router) | 106 | if (curr_router) |
108 | neigh_node_free_ref(curr_router); | 107 | batadv_neigh_node_free_ref(curr_router); |
109 | } | 108 | } |
110 | 109 | ||
111 | void update_route(struct bat_priv *bat_priv, struct orig_node *orig_node, | 110 | void batadv_update_route(struct batadv_priv *bat_priv, |
112 | struct neigh_node *neigh_node) | 111 | struct batadv_orig_node *orig_node, |
112 | struct batadv_neigh_node *neigh_node) | ||
113 | { | 113 | { |
114 | struct neigh_node *router = NULL; | 114 | struct batadv_neigh_node *router = NULL; |
115 | 115 | ||
116 | if (!orig_node) | 116 | if (!orig_node) |
117 | goto out; | 117 | goto out; |
118 | 118 | ||
119 | router = orig_node_get_router(orig_node); | 119 | router = batadv_orig_node_get_router(orig_node); |
120 | 120 | ||
121 | if (router != neigh_node) | 121 | if (router != neigh_node) |
122 | _update_route(bat_priv, orig_node, neigh_node); | 122 | _batadv_update_route(bat_priv, orig_node, neigh_node); |
123 | 123 | ||
124 | out: | 124 | out: |
125 | if (router) | 125 | if (router) |
126 | neigh_node_free_ref(router); | 126 | batadv_neigh_node_free_ref(router); |
127 | } | 127 | } |
128 | 128 | ||
129 | /* caller must hold the neigh_list_lock */ | 129 | /* caller must hold the neigh_list_lock */ |
130 | void bonding_candidate_del(struct orig_node *orig_node, | 130 | void batadv_bonding_candidate_del(struct batadv_orig_node *orig_node, |
131 | struct neigh_node *neigh_node) | 131 | struct batadv_neigh_node *neigh_node) |
132 | { | 132 | { |
133 | /* this neighbor is not part of our candidate list */ | 133 | /* this neighbor is not part of our candidate list */ |
134 | if (list_empty(&neigh_node->bonding_list)) | 134 | if (list_empty(&neigh_node->bonding_list)) |
@@ -136,37 +136,36 @@ void bonding_candidate_del(struct orig_node *orig_node, | |||
136 | 136 | ||
137 | list_del_rcu(&neigh_node->bonding_list); | 137 | list_del_rcu(&neigh_node->bonding_list); |
138 | INIT_LIST_HEAD(&neigh_node->bonding_list); | 138 | INIT_LIST_HEAD(&neigh_node->bonding_list); |
139 | neigh_node_free_ref(neigh_node); | 139 | batadv_neigh_node_free_ref(neigh_node); |
140 | atomic_dec(&orig_node->bond_candidates); | 140 | atomic_dec(&orig_node->bond_candidates); |
141 | 141 | ||
142 | out: | 142 | out: |
143 | return; | 143 | return; |
144 | } | 144 | } |
145 | 145 | ||
146 | void bonding_candidate_add(struct orig_node *orig_node, | 146 | void batadv_bonding_candidate_add(struct batadv_orig_node *orig_node, |
147 | struct neigh_node *neigh_node) | 147 | struct batadv_neigh_node *neigh_node) |
148 | { | 148 | { |
149 | struct hlist_node *node; | 149 | struct hlist_node *node; |
150 | struct neigh_node *tmp_neigh_node, *router = NULL; | 150 | struct batadv_neigh_node *tmp_neigh_node, *router = NULL; |
151 | uint8_t interference_candidate = 0; | 151 | uint8_t interference_candidate = 0; |
152 | 152 | ||
153 | spin_lock_bh(&orig_node->neigh_list_lock); | 153 | spin_lock_bh(&orig_node->neigh_list_lock); |
154 | 154 | ||
155 | /* only consider if it has the same primary address ... */ | 155 | /* only consider if it has the same primary address ... */ |
156 | if (!compare_eth(orig_node->orig, | 156 | if (!batadv_compare_eth(orig_node->orig, |
157 | neigh_node->orig_node->primary_addr)) | 157 | neigh_node->orig_node->primary_addr)) |
158 | goto candidate_del; | 158 | goto candidate_del; |
159 | 159 | ||
160 | router = orig_node_get_router(orig_node); | 160 | router = batadv_orig_node_get_router(orig_node); |
161 | if (!router) | 161 | if (!router) |
162 | goto candidate_del; | 162 | goto candidate_del; |
163 | 163 | ||
164 | /* ... and is good enough to be considered */ | 164 | /* ... and is good enough to be considered */ |
165 | if (neigh_node->tq_avg < router->tq_avg - BONDING_TQ_THRESHOLD) | 165 | if (neigh_node->tq_avg < router->tq_avg - BATADV_BONDING_TQ_THRESHOLD) |
166 | goto candidate_del; | 166 | goto candidate_del; |
167 | 167 | ||
168 | /** | 168 | /* check if we have another candidate with the same mac address or |
169 | * check if we have another candidate with the same mac address or | ||
170 | * interface. If we do, we won't select this candidate because of | 169 | * interface. If we do, we won't select this candidate because of |
171 | * possible interference. | 170 | * possible interference. |
172 | */ | 171 | */ |
@@ -177,12 +176,14 @@ void bonding_candidate_add(struct orig_node *orig_node, | |||
177 | continue; | 176 | continue; |
178 | 177 | ||
179 | /* we only care if the other candidate is even | 178 | /* we only care if the other candidate is even |
180 | * considered as candidate. */ | 179 | * considered as candidate. |
180 | */ | ||
181 | if (list_empty(&tmp_neigh_node->bonding_list)) | 181 | if (list_empty(&tmp_neigh_node->bonding_list)) |
182 | continue; | 182 | continue; |
183 | 183 | ||
184 | if ((neigh_node->if_incoming == tmp_neigh_node->if_incoming) || | 184 | if ((neigh_node->if_incoming == tmp_neigh_node->if_incoming) || |
185 | (compare_eth(neigh_node->addr, tmp_neigh_node->addr))) { | 185 | (batadv_compare_eth(neigh_node->addr, |
186 | tmp_neigh_node->addr))) { | ||
186 | interference_candidate = 1; | 187 | interference_candidate = 1; |
187 | break; | 188 | break; |
188 | } | 189 | } |
@@ -204,21 +205,22 @@ void bonding_candidate_add(struct orig_node *orig_node, | |||
204 | goto out; | 205 | goto out; |
205 | 206 | ||
206 | candidate_del: | 207 | candidate_del: |
207 | bonding_candidate_del(orig_node, neigh_node); | 208 | batadv_bonding_candidate_del(orig_node, neigh_node); |
208 | 209 | ||
209 | out: | 210 | out: |
210 | spin_unlock_bh(&orig_node->neigh_list_lock); | 211 | spin_unlock_bh(&orig_node->neigh_list_lock); |
211 | 212 | ||
212 | if (router) | 213 | if (router) |
213 | neigh_node_free_ref(router); | 214 | batadv_neigh_node_free_ref(router); |
214 | } | 215 | } |
215 | 216 | ||
216 | /* copy primary address for bonding */ | 217 | /* copy primary address for bonding */ |
217 | void bonding_save_primary(const struct orig_node *orig_node, | 218 | void |
218 | struct orig_node *orig_neigh_node, | 219 | batadv_bonding_save_primary(const struct batadv_orig_node *orig_node, |
219 | const struct batman_ogm_packet *batman_ogm_packet) | 220 | struct batadv_orig_node *orig_neigh_node, |
221 | const struct batadv_ogm_packet *batman_ogm_packet) | ||
220 | { | 222 | { |
221 | if (!(batman_ogm_packet->flags & PRIMARIES_FIRST_HOP)) | 223 | if (!(batman_ogm_packet->flags & BATADV_PRIMARIES_FIRST_HOP)) |
222 | return; | 224 | return; |
223 | 225 | ||
224 | memcpy(orig_neigh_node->primary_addr, orig_node->orig, ETH_ALEN); | 226 | memcpy(orig_neigh_node->primary_addr, orig_node->orig, ETH_ALEN); |
@@ -229,25 +231,26 @@ void bonding_save_primary(const struct orig_node *orig_node, | |||
229 | * 0 if the packet is to be accepted | 231 | * 0 if the packet is to be accepted |
230 | * 1 if the packet is to be ignored. | 232 | * 1 if the packet is to be ignored. |
231 | */ | 233 | */ |
232 | int window_protected(struct bat_priv *bat_priv, int32_t seq_num_diff, | 234 | int batadv_window_protected(struct batadv_priv *bat_priv, int32_t seq_num_diff, |
233 | unsigned long *last_reset) | 235 | unsigned long *last_reset) |
234 | { | 236 | { |
235 | if ((seq_num_diff <= -TQ_LOCAL_WINDOW_SIZE) || | 237 | if (seq_num_diff <= -BATADV_TQ_LOCAL_WINDOW_SIZE || |
236 | (seq_num_diff >= EXPECTED_SEQNO_RANGE)) { | 238 | seq_num_diff >= BATADV_EXPECTED_SEQNO_RANGE) { |
237 | if (!has_timed_out(*last_reset, RESET_PROTECTION_MS)) | 239 | if (!batadv_has_timed_out(*last_reset, |
240 | BATADV_RESET_PROTECTION_MS)) | ||
238 | return 1; | 241 | return 1; |
239 | 242 | ||
240 | *last_reset = jiffies; | 243 | *last_reset = jiffies; |
241 | bat_dbg(DBG_BATMAN, bat_priv, | 244 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
242 | "old packet received, start protection\n"); | 245 | "old packet received, start protection\n"); |
243 | } | 246 | } |
244 | 247 | ||
245 | return 0; | 248 | return 0; |
246 | } | 249 | } |
247 | 250 | ||
248 | bool check_management_packet(struct sk_buff *skb, | 251 | bool batadv_check_management_packet(struct sk_buff *skb, |
249 | struct hard_iface *hard_iface, | 252 | struct batadv_hard_iface *hard_iface, |
250 | int header_len) | 253 | int header_len) |
251 | { | 254 | { |
252 | struct ethhdr *ethhdr; | 255 | struct ethhdr *ethhdr; |
253 | 256 | ||
@@ -276,34 +279,34 @@ bool check_management_packet(struct sk_buff *skb, | |||
276 | return true; | 279 | return true; |
277 | } | 280 | } |
278 | 281 | ||
279 | static int recv_my_icmp_packet(struct bat_priv *bat_priv, | 282 | static int batadv_recv_my_icmp_packet(struct batadv_priv *bat_priv, |
280 | struct sk_buff *skb, size_t icmp_len) | 283 | struct sk_buff *skb, size_t icmp_len) |
281 | { | 284 | { |
282 | struct hard_iface *primary_if = NULL; | 285 | struct batadv_hard_iface *primary_if = NULL; |
283 | struct orig_node *orig_node = NULL; | 286 | struct batadv_orig_node *orig_node = NULL; |
284 | struct neigh_node *router = NULL; | 287 | struct batadv_neigh_node *router = NULL; |
285 | struct icmp_packet_rr *icmp_packet; | 288 | struct batadv_icmp_packet_rr *icmp_packet; |
286 | int ret = NET_RX_DROP; | 289 | int ret = NET_RX_DROP; |
287 | 290 | ||
288 | icmp_packet = (struct icmp_packet_rr *)skb->data; | 291 | icmp_packet = (struct batadv_icmp_packet_rr *)skb->data; |
289 | 292 | ||
290 | /* add data to device queue */ | 293 | /* add data to device queue */ |
291 | if (icmp_packet->msg_type != ECHO_REQUEST) { | 294 | if (icmp_packet->msg_type != BATADV_ECHO_REQUEST) { |
292 | bat_socket_receive_packet(icmp_packet, icmp_len); | 295 | batadv_socket_receive_packet(icmp_packet, icmp_len); |
293 | goto out; | 296 | goto out; |
294 | } | 297 | } |
295 | 298 | ||
296 | primary_if = primary_if_get_selected(bat_priv); | 299 | primary_if = batadv_primary_if_get_selected(bat_priv); |
297 | if (!primary_if) | 300 | if (!primary_if) |
298 | goto out; | 301 | goto out; |
299 | 302 | ||
300 | /* answer echo request (ping) */ | 303 | /* answer echo request (ping) */ |
301 | /* get routing information */ | 304 | /* get routing information */ |
302 | orig_node = orig_hash_find(bat_priv, icmp_packet->orig); | 305 | orig_node = batadv_orig_hash_find(bat_priv, icmp_packet->orig); |
303 | if (!orig_node) | 306 | if (!orig_node) |
304 | goto out; | 307 | goto out; |
305 | 308 | ||
306 | router = orig_node_get_router(orig_node); | 309 | router = batadv_orig_node_get_router(orig_node); |
307 | if (!router) | 310 | if (!router) |
308 | goto out; | 311 | goto out; |
309 | 312 | ||
@@ -311,54 +314,54 @@ static int recv_my_icmp_packet(struct bat_priv *bat_priv, | |||
311 | if (skb_cow(skb, ETH_HLEN) < 0) | 314 | if (skb_cow(skb, ETH_HLEN) < 0) |
312 | goto out; | 315 | goto out; |
313 | 316 | ||
314 | icmp_packet = (struct icmp_packet_rr *)skb->data; | 317 | icmp_packet = (struct batadv_icmp_packet_rr *)skb->data; |
315 | 318 | ||
316 | memcpy(icmp_packet->dst, icmp_packet->orig, ETH_ALEN); | 319 | memcpy(icmp_packet->dst, icmp_packet->orig, ETH_ALEN); |
317 | memcpy(icmp_packet->orig, primary_if->net_dev->dev_addr, ETH_ALEN); | 320 | memcpy(icmp_packet->orig, primary_if->net_dev->dev_addr, ETH_ALEN); |
318 | icmp_packet->msg_type = ECHO_REPLY; | 321 | icmp_packet->msg_type = BATADV_ECHO_REPLY; |
319 | icmp_packet->header.ttl = TTL; | 322 | icmp_packet->header.ttl = BATADV_TTL; |
320 | 323 | ||
321 | send_skb_packet(skb, router->if_incoming, router->addr); | 324 | batadv_send_skb_packet(skb, router->if_incoming, router->addr); |
322 | ret = NET_RX_SUCCESS; | 325 | ret = NET_RX_SUCCESS; |
323 | 326 | ||
324 | out: | 327 | out: |
325 | if (primary_if) | 328 | if (primary_if) |
326 | hardif_free_ref(primary_if); | 329 | batadv_hardif_free_ref(primary_if); |
327 | if (router) | 330 | if (router) |
328 | neigh_node_free_ref(router); | 331 | batadv_neigh_node_free_ref(router); |
329 | if (orig_node) | 332 | if (orig_node) |
330 | orig_node_free_ref(orig_node); | 333 | batadv_orig_node_free_ref(orig_node); |
331 | return ret; | 334 | return ret; |
332 | } | 335 | } |
333 | 336 | ||
334 | static int recv_icmp_ttl_exceeded(struct bat_priv *bat_priv, | 337 | static int batadv_recv_icmp_ttl_exceeded(struct batadv_priv *bat_priv, |
335 | struct sk_buff *skb) | 338 | struct sk_buff *skb) |
336 | { | 339 | { |
337 | struct hard_iface *primary_if = NULL; | 340 | struct batadv_hard_iface *primary_if = NULL; |
338 | struct orig_node *orig_node = NULL; | 341 | struct batadv_orig_node *orig_node = NULL; |
339 | struct neigh_node *router = NULL; | 342 | struct batadv_neigh_node *router = NULL; |
340 | struct icmp_packet *icmp_packet; | 343 | struct batadv_icmp_packet *icmp_packet; |
341 | int ret = NET_RX_DROP; | 344 | int ret = NET_RX_DROP; |
342 | 345 | ||
343 | icmp_packet = (struct icmp_packet *)skb->data; | 346 | icmp_packet = (struct batadv_icmp_packet *)skb->data; |
344 | 347 | ||
345 | /* send TTL exceeded if packet is an echo request (traceroute) */ | 348 | /* send TTL exceeded if packet is an echo request (traceroute) */ |
346 | if (icmp_packet->msg_type != ECHO_REQUEST) { | 349 | if (icmp_packet->msg_type != BATADV_ECHO_REQUEST) { |
347 | pr_debug("Warning - can't forward icmp packet from %pM to %pM: ttl exceeded\n", | 350 | pr_debug("Warning - can't forward icmp packet from %pM to %pM: ttl exceeded\n", |
348 | icmp_packet->orig, icmp_packet->dst); | 351 | icmp_packet->orig, icmp_packet->dst); |
349 | goto out; | 352 | goto out; |
350 | } | 353 | } |
351 | 354 | ||
352 | primary_if = primary_if_get_selected(bat_priv); | 355 | primary_if = batadv_primary_if_get_selected(bat_priv); |
353 | if (!primary_if) | 356 | if (!primary_if) |
354 | goto out; | 357 | goto out; |
355 | 358 | ||
356 | /* get routing information */ | 359 | /* get routing information */ |
357 | orig_node = orig_hash_find(bat_priv, icmp_packet->orig); | 360 | orig_node = batadv_orig_hash_find(bat_priv, icmp_packet->orig); |
358 | if (!orig_node) | 361 | if (!orig_node) |
359 | goto out; | 362 | goto out; |
360 | 363 | ||
361 | router = orig_node_get_router(orig_node); | 364 | router = batadv_orig_node_get_router(orig_node); |
362 | if (!router) | 365 | if (!router) |
363 | goto out; | 366 | goto out; |
364 | 367 | ||
@@ -366,42 +369,41 @@ static int recv_icmp_ttl_exceeded(struct bat_priv *bat_priv, | |||
366 | if (skb_cow(skb, ETH_HLEN) < 0) | 369 | if (skb_cow(skb, ETH_HLEN) < 0) |
367 | goto out; | 370 | goto out; |
368 | 371 | ||
369 | icmp_packet = (struct icmp_packet *)skb->data; | 372 | icmp_packet = (struct batadv_icmp_packet *)skb->data; |
370 | 373 | ||
371 | memcpy(icmp_packet->dst, icmp_packet->orig, ETH_ALEN); | 374 | memcpy(icmp_packet->dst, icmp_packet->orig, ETH_ALEN); |
372 | memcpy(icmp_packet->orig, primary_if->net_dev->dev_addr, ETH_ALEN); | 375 | memcpy(icmp_packet->orig, primary_if->net_dev->dev_addr, ETH_ALEN); |
373 | icmp_packet->msg_type = TTL_EXCEEDED; | 376 | icmp_packet->msg_type = BATADV_TTL_EXCEEDED; |
374 | icmp_packet->header.ttl = TTL; | 377 | icmp_packet->header.ttl = BATADV_TTL; |
375 | 378 | ||
376 | send_skb_packet(skb, router->if_incoming, router->addr); | 379 | batadv_send_skb_packet(skb, router->if_incoming, router->addr); |
377 | ret = NET_RX_SUCCESS; | 380 | ret = NET_RX_SUCCESS; |
378 | 381 | ||
379 | out: | 382 | out: |
380 | if (primary_if) | 383 | if (primary_if) |
381 | hardif_free_ref(primary_if); | 384 | batadv_hardif_free_ref(primary_if); |
382 | if (router) | 385 | if (router) |
383 | neigh_node_free_ref(router); | 386 | batadv_neigh_node_free_ref(router); |
384 | if (orig_node) | 387 | if (orig_node) |
385 | orig_node_free_ref(orig_node); | 388 | batadv_orig_node_free_ref(orig_node); |
386 | return ret; | 389 | return ret; |
387 | } | 390 | } |
388 | 391 | ||
389 | 392 | ||
390 | int recv_icmp_packet(struct sk_buff *skb, struct hard_iface *recv_if) | 393 | int batadv_recv_icmp_packet(struct sk_buff *skb, |
394 | struct batadv_hard_iface *recv_if) | ||
391 | { | 395 | { |
392 | struct bat_priv *bat_priv = netdev_priv(recv_if->soft_iface); | 396 | struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface); |
393 | struct icmp_packet_rr *icmp_packet; | 397 | struct batadv_icmp_packet_rr *icmp_packet; |
394 | struct ethhdr *ethhdr; | 398 | struct ethhdr *ethhdr; |
395 | struct orig_node *orig_node = NULL; | 399 | struct batadv_orig_node *orig_node = NULL; |
396 | struct neigh_node *router = NULL; | 400 | struct batadv_neigh_node *router = NULL; |
397 | int hdr_size = sizeof(struct icmp_packet); | 401 | int hdr_size = sizeof(struct batadv_icmp_packet); |
398 | int ret = NET_RX_DROP; | 402 | int ret = NET_RX_DROP; |
399 | 403 | ||
400 | /** | 404 | /* we truncate all incoming icmp packets if they don't match our size */ |
401 | * we truncate all incoming icmp packets if they don't match our size | 405 | if (skb->len >= sizeof(struct batadv_icmp_packet_rr)) |
402 | */ | 406 | hdr_size = sizeof(struct batadv_icmp_packet_rr); |
403 | if (skb->len >= sizeof(struct icmp_packet_rr)) | ||
404 | hdr_size = sizeof(struct icmp_packet_rr); | ||
405 | 407 | ||
406 | /* drop packet if it has not necessary minimum size */ | 408 | /* drop packet if it has not necessary minimum size */ |
407 | if (unlikely(!pskb_may_pull(skb, hdr_size))) | 409 | if (unlikely(!pskb_may_pull(skb, hdr_size))) |
@@ -418,33 +420,33 @@ int recv_icmp_packet(struct sk_buff *skb, struct hard_iface *recv_if) | |||
418 | goto out; | 420 | goto out; |
419 | 421 | ||
420 | /* not for me */ | 422 | /* not for me */ |
421 | if (!is_my_mac(ethhdr->h_dest)) | 423 | if (!batadv_is_my_mac(ethhdr->h_dest)) |
422 | goto out; | 424 | goto out; |
423 | 425 | ||
424 | icmp_packet = (struct icmp_packet_rr *)skb->data; | 426 | icmp_packet = (struct batadv_icmp_packet_rr *)skb->data; |
425 | 427 | ||
426 | /* add record route information if not full */ | 428 | /* add record route information if not full */ |
427 | if ((hdr_size == sizeof(struct icmp_packet_rr)) && | 429 | if ((hdr_size == sizeof(struct batadv_icmp_packet_rr)) && |
428 | (icmp_packet->rr_cur < BAT_RR_LEN)) { | 430 | (icmp_packet->rr_cur < BATADV_RR_LEN)) { |
429 | memcpy(&(icmp_packet->rr[icmp_packet->rr_cur]), | 431 | memcpy(&(icmp_packet->rr[icmp_packet->rr_cur]), |
430 | ethhdr->h_dest, ETH_ALEN); | 432 | ethhdr->h_dest, ETH_ALEN); |
431 | icmp_packet->rr_cur++; | 433 | icmp_packet->rr_cur++; |
432 | } | 434 | } |
433 | 435 | ||
434 | /* packet for me */ | 436 | /* packet for me */ |
435 | if (is_my_mac(icmp_packet->dst)) | 437 | if (batadv_is_my_mac(icmp_packet->dst)) |
436 | return recv_my_icmp_packet(bat_priv, skb, hdr_size); | 438 | return batadv_recv_my_icmp_packet(bat_priv, skb, hdr_size); |
437 | 439 | ||
438 | /* TTL exceeded */ | 440 | /* TTL exceeded */ |
439 | if (icmp_packet->header.ttl < 2) | 441 | if (icmp_packet->header.ttl < 2) |
440 | return recv_icmp_ttl_exceeded(bat_priv, skb); | 442 | return batadv_recv_icmp_ttl_exceeded(bat_priv, skb); |
441 | 443 | ||
442 | /* get routing information */ | 444 | /* get routing information */ |
443 | orig_node = orig_hash_find(bat_priv, icmp_packet->dst); | 445 | orig_node = batadv_orig_hash_find(bat_priv, icmp_packet->dst); |
444 | if (!orig_node) | 446 | if (!orig_node) |
445 | goto out; | 447 | goto out; |
446 | 448 | ||
447 | router = orig_node_get_router(orig_node); | 449 | router = batadv_orig_node_get_router(orig_node); |
448 | if (!router) | 450 | if (!router) |
449 | goto out; | 451 | goto out; |
450 | 452 | ||
@@ -452,20 +454,20 @@ int recv_icmp_packet(struct sk_buff *skb, struct hard_iface *recv_if) | |||
452 | if (skb_cow(skb, ETH_HLEN) < 0) | 454 | if (skb_cow(skb, ETH_HLEN) < 0) |
453 | goto out; | 455 | goto out; |
454 | 456 | ||
455 | icmp_packet = (struct icmp_packet_rr *)skb->data; | 457 | icmp_packet = (struct batadv_icmp_packet_rr *)skb->data; |
456 | 458 | ||
457 | /* decrement ttl */ | 459 | /* decrement ttl */ |
458 | icmp_packet->header.ttl--; | 460 | icmp_packet->header.ttl--; |
459 | 461 | ||
460 | /* route it */ | 462 | /* route it */ |
461 | send_skb_packet(skb, router->if_incoming, router->addr); | 463 | batadv_send_skb_packet(skb, router->if_incoming, router->addr); |
462 | ret = NET_RX_SUCCESS; | 464 | ret = NET_RX_SUCCESS; |
463 | 465 | ||
464 | out: | 466 | out: |
465 | if (router) | 467 | if (router) |
466 | neigh_node_free_ref(router); | 468 | batadv_neigh_node_free_ref(router); |
467 | if (orig_node) | 469 | if (orig_node) |
468 | orig_node_free_ref(orig_node); | 470 | batadv_orig_node_free_ref(orig_node); |
469 | return ret; | 471 | return ret; |
470 | } | 472 | } |
471 | 473 | ||
@@ -473,12 +475,14 @@ out: | |||
473 | * robin fashion over the remaining interfaces. | 475 | * robin fashion over the remaining interfaces. |
474 | * | 476 | * |
475 | * This method rotates the bonding list and increases the | 477 | * This method rotates the bonding list and increases the |
476 | * returned router's refcount. */ | 478 | * returned router's refcount. |
477 | static struct neigh_node *find_bond_router(struct orig_node *primary_orig, | 479 | */ |
478 | const struct hard_iface *recv_if) | 480 | static struct batadv_neigh_node * |
481 | batadv_find_bond_router(struct batadv_orig_node *primary_orig, | ||
482 | const struct batadv_hard_iface *recv_if) | ||
479 | { | 483 | { |
480 | struct neigh_node *tmp_neigh_node; | 484 | struct batadv_neigh_node *tmp_neigh_node; |
481 | struct neigh_node *router = NULL, *first_candidate = NULL; | 485 | struct batadv_neigh_node *router = NULL, *first_candidate = NULL; |
482 | 486 | ||
483 | rcu_read_lock(); | 487 | rcu_read_lock(); |
484 | list_for_each_entry_rcu(tmp_neigh_node, &primary_orig->bond_list, | 488 | list_for_each_entry_rcu(tmp_neigh_node, &primary_orig->bond_list, |
@@ -506,10 +510,12 @@ static struct neigh_node *find_bond_router(struct orig_node *primary_orig, | |||
506 | goto out; | 510 | goto out; |
507 | 511 | ||
508 | /* selected should point to the next element | 512 | /* selected should point to the next element |
509 | * after the current router */ | 513 | * after the current router |
514 | */ | ||
510 | spin_lock_bh(&primary_orig->neigh_list_lock); | 515 | spin_lock_bh(&primary_orig->neigh_list_lock); |
511 | /* this is a list_move(), which unfortunately | 516 | /* this is a list_move(), which unfortunately |
512 | * does not exist as rcu version */ | 517 | * does not exist as rcu version |
518 | */ | ||
513 | list_del_rcu(&primary_orig->bond_list); | 519 | list_del_rcu(&primary_orig->bond_list); |
514 | list_add_rcu(&primary_orig->bond_list, | 520 | list_add_rcu(&primary_orig->bond_list, |
515 | &router->bonding_list); | 521 | &router->bonding_list); |
@@ -524,12 +530,14 @@ out: | |||
524 | * remaining candidates which are not using | 530 | * remaining candidates which are not using |
525 | * this interface. | 531 | * this interface. |
526 | * | 532 | * |
527 | * Increases the returned router's refcount */ | 533 | * Increases the returned router's refcount |
528 | static struct neigh_node *find_ifalter_router(struct orig_node *primary_orig, | 534 | */ |
529 | const struct hard_iface *recv_if) | 535 | static struct batadv_neigh_node * |
536 | batadv_find_ifalter_router(struct batadv_orig_node *primary_orig, | ||
537 | const struct batadv_hard_iface *recv_if) | ||
530 | { | 538 | { |
531 | struct neigh_node *tmp_neigh_node; | 539 | struct batadv_neigh_node *tmp_neigh_node; |
532 | struct neigh_node *router = NULL, *first_candidate = NULL; | 540 | struct batadv_neigh_node *router = NULL, *first_candidate = NULL; |
533 | 541 | ||
534 | rcu_read_lock(); | 542 | rcu_read_lock(); |
535 | list_for_each_entry_rcu(tmp_neigh_node, &primary_orig->bond_list, | 543 | list_for_each_entry_rcu(tmp_neigh_node, &primary_orig->bond_list, |
@@ -545,19 +553,21 @@ static struct neigh_node *find_ifalter_router(struct orig_node *primary_orig, | |||
545 | continue; | 553 | continue; |
546 | 554 | ||
547 | /* if we don't have a router yet | 555 | /* if we don't have a router yet |
548 | * or this one is better, choose it. */ | 556 | * or this one is better, choose it. |
557 | */ | ||
549 | if ((!router) || | 558 | if ((!router) || |
550 | (tmp_neigh_node->tq_avg > router->tq_avg)) { | 559 | (tmp_neigh_node->tq_avg > router->tq_avg)) { |
551 | /* decrement refcount of | 560 | /* decrement refcount of |
552 | * previously selected router */ | 561 | * previously selected router |
562 | */ | ||
553 | if (router) | 563 | if (router) |
554 | neigh_node_free_ref(router); | 564 | batadv_neigh_node_free_ref(router); |
555 | 565 | ||
556 | router = tmp_neigh_node; | 566 | router = tmp_neigh_node; |
557 | atomic_inc_not_zero(&router->refcount); | 567 | atomic_inc_not_zero(&router->refcount); |
558 | } | 568 | } |
559 | 569 | ||
560 | neigh_node_free_ref(tmp_neigh_node); | 570 | batadv_neigh_node_free_ref(tmp_neigh_node); |
561 | } | 571 | } |
562 | 572 | ||
563 | /* use the first candidate if nothing was found. */ | 573 | /* use the first candidate if nothing was found. */ |
@@ -569,19 +579,22 @@ static struct neigh_node *find_ifalter_router(struct orig_node *primary_orig, | |||
569 | return router; | 579 | return router; |
570 | } | 580 | } |
571 | 581 | ||
572 | int recv_tt_query(struct sk_buff *skb, struct hard_iface *recv_if) | 582 | int batadv_recv_tt_query(struct sk_buff *skb, struct batadv_hard_iface *recv_if) |
573 | { | 583 | { |
574 | struct bat_priv *bat_priv = netdev_priv(recv_if->soft_iface); | 584 | struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface); |
575 | struct tt_query_packet *tt_query; | 585 | struct batadv_tt_query_packet *tt_query; |
576 | uint16_t tt_len; | 586 | uint16_t tt_size; |
577 | struct ethhdr *ethhdr; | 587 | struct ethhdr *ethhdr; |
588 | char tt_flag; | ||
589 | size_t packet_size; | ||
578 | 590 | ||
579 | /* drop packet if it has not necessary minimum size */ | 591 | /* drop packet if it has not necessary minimum size */ |
580 | if (unlikely(!pskb_may_pull(skb, sizeof(struct tt_query_packet)))) | 592 | if (unlikely(!pskb_may_pull(skb, |
593 | sizeof(struct batadv_tt_query_packet)))) | ||
581 | goto out; | 594 | goto out; |
582 | 595 | ||
583 | /* I could need to modify it */ | 596 | /* I could need to modify it */ |
584 | if (skb_cow(skb, sizeof(struct tt_query_packet)) < 0) | 597 | if (skb_cow(skb, sizeof(struct batadv_tt_query_packet)) < 0) |
585 | goto out; | 598 | goto out; |
586 | 599 | ||
587 | ethhdr = (struct ethhdr *)skb_mac_header(skb); | 600 | ethhdr = (struct ethhdr *)skb_mac_header(skb); |
@@ -594,47 +607,59 @@ int recv_tt_query(struct sk_buff *skb, struct hard_iface *recv_if) | |||
594 | if (is_broadcast_ether_addr(ethhdr->h_source)) | 607 | if (is_broadcast_ether_addr(ethhdr->h_source)) |
595 | goto out; | 608 | goto out; |
596 | 609 | ||
597 | tt_query = (struct tt_query_packet *)skb->data; | 610 | tt_query = (struct batadv_tt_query_packet *)skb->data; |
598 | 611 | ||
599 | tt_query->tt_data = ntohs(tt_query->tt_data); | 612 | switch (tt_query->flags & BATADV_TT_QUERY_TYPE_MASK) { |
613 | case BATADV_TT_REQUEST: | ||
614 | batadv_inc_counter(bat_priv, BATADV_CNT_TT_REQUEST_RX); | ||
600 | 615 | ||
601 | switch (tt_query->flags & TT_QUERY_TYPE_MASK) { | ||
602 | case TT_REQUEST: | ||
603 | /* If we cannot provide an answer the tt_request is | 616 | /* If we cannot provide an answer the tt_request is |
604 | * forwarded */ | 617 | * forwarded |
605 | if (!send_tt_response(bat_priv, tt_query)) { | 618 | */ |
606 | bat_dbg(DBG_TT, bat_priv, | 619 | if (!batadv_send_tt_response(bat_priv, tt_query)) { |
607 | "Routing TT_REQUEST to %pM [%c]\n", | 620 | if (tt_query->flags & BATADV_TT_FULL_TABLE) |
608 | tt_query->dst, | 621 | tt_flag = 'F'; |
609 | (tt_query->flags & TT_FULL_TABLE ? 'F' : '.')); | 622 | else |
610 | tt_query->tt_data = htons(tt_query->tt_data); | 623 | tt_flag = '.'; |
611 | return route_unicast_packet(skb, recv_if); | 624 | |
625 | batadv_dbg(BATADV_DBG_TT, bat_priv, | ||
626 | "Routing TT_REQUEST to %pM [%c]\n", | ||
627 | tt_query->dst, | ||
628 | tt_flag); | ||
629 | return batadv_route_unicast_packet(skb, recv_if); | ||
612 | } | 630 | } |
613 | break; | 631 | break; |
614 | case TT_RESPONSE: | 632 | case BATADV_TT_RESPONSE: |
615 | if (is_my_mac(tt_query->dst)) { | 633 | batadv_inc_counter(bat_priv, BATADV_CNT_TT_RESPONSE_RX); |
634 | |||
635 | if (batadv_is_my_mac(tt_query->dst)) { | ||
616 | /* packet needs to be linearized to access the TT | 636 | /* packet needs to be linearized to access the TT |
617 | * changes */ | 637 | * changes |
638 | */ | ||
618 | if (skb_linearize(skb) < 0) | 639 | if (skb_linearize(skb) < 0) |
619 | goto out; | 640 | goto out; |
620 | /* skb_linearize() possibly changed skb->data */ | 641 | /* skb_linearize() possibly changed skb->data */ |
621 | tt_query = (struct tt_query_packet *)skb->data; | 642 | tt_query = (struct batadv_tt_query_packet *)skb->data; |
622 | 643 | ||
623 | tt_len = tt_query->tt_data * sizeof(struct tt_change); | 644 | tt_size = batadv_tt_len(ntohs(tt_query->tt_data)); |
624 | 645 | ||
625 | /* Ensure we have all the claimed data */ | 646 | /* Ensure we have all the claimed data */ |
626 | if (unlikely(skb_headlen(skb) < | 647 | packet_size = sizeof(struct batadv_tt_query_packet); |
627 | sizeof(struct tt_query_packet) + tt_len)) | 648 | packet_size += tt_size; |
649 | if (unlikely(skb_headlen(skb) < packet_size)) | ||
628 | goto out; | 650 | goto out; |
629 | 651 | ||
630 | handle_tt_response(bat_priv, tt_query); | 652 | batadv_handle_tt_response(bat_priv, tt_query); |
631 | } else { | 653 | } else { |
632 | bat_dbg(DBG_TT, bat_priv, | 654 | if (tt_query->flags & BATADV_TT_FULL_TABLE) |
633 | "Routing TT_RESPONSE to %pM [%c]\n", | 655 | tt_flag = 'F'; |
634 | tt_query->dst, | 656 | else |
635 | (tt_query->flags & TT_FULL_TABLE ? 'F' : '.')); | 657 | tt_flag = '.'; |
636 | tt_query->tt_data = htons(tt_query->tt_data); | 658 | batadv_dbg(BATADV_DBG_TT, bat_priv, |
637 | return route_unicast_packet(skb, recv_if); | 659 | "Routing TT_RESPONSE to %pM [%c]\n", |
660 | tt_query->dst, | ||
661 | tt_flag); | ||
662 | return batadv_route_unicast_packet(skb, recv_if); | ||
638 | } | 663 | } |
639 | break; | 664 | break; |
640 | } | 665 | } |
@@ -644,15 +669,16 @@ out: | |||
644 | return NET_RX_DROP; | 669 | return NET_RX_DROP; |
645 | } | 670 | } |
646 | 671 | ||
647 | int recv_roam_adv(struct sk_buff *skb, struct hard_iface *recv_if) | 672 | int batadv_recv_roam_adv(struct sk_buff *skb, struct batadv_hard_iface *recv_if) |
648 | { | 673 | { |
649 | struct bat_priv *bat_priv = netdev_priv(recv_if->soft_iface); | 674 | struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface); |
650 | struct roam_adv_packet *roam_adv_packet; | 675 | struct batadv_roam_adv_packet *roam_adv_packet; |
651 | struct orig_node *orig_node; | 676 | struct batadv_orig_node *orig_node; |
652 | struct ethhdr *ethhdr; | 677 | struct ethhdr *ethhdr; |
653 | 678 | ||
654 | /* drop packet if it has not necessary minimum size */ | 679 | /* drop packet if it has not necessary minimum size */ |
655 | if (unlikely(!pskb_may_pull(skb, sizeof(struct roam_adv_packet)))) | 680 | if (unlikely(!pskb_may_pull(skb, |
681 | sizeof(struct batadv_roam_adv_packet)))) | ||
656 | goto out; | 682 | goto out; |
657 | 683 | ||
658 | ethhdr = (struct ethhdr *)skb_mac_header(skb); | 684 | ethhdr = (struct ethhdr *)skb_mac_header(skb); |
@@ -665,35 +691,39 @@ int recv_roam_adv(struct sk_buff *skb, struct hard_iface *recv_if) | |||
665 | if (is_broadcast_ether_addr(ethhdr->h_source)) | 691 | if (is_broadcast_ether_addr(ethhdr->h_source)) |
666 | goto out; | 692 | goto out; |
667 | 693 | ||
668 | roam_adv_packet = (struct roam_adv_packet *)skb->data; | 694 | batadv_inc_counter(bat_priv, BATADV_CNT_TT_ROAM_ADV_RX); |
695 | |||
696 | roam_adv_packet = (struct batadv_roam_adv_packet *)skb->data; | ||
669 | 697 | ||
670 | if (!is_my_mac(roam_adv_packet->dst)) | 698 | if (!batadv_is_my_mac(roam_adv_packet->dst)) |
671 | return route_unicast_packet(skb, recv_if); | 699 | return batadv_route_unicast_packet(skb, recv_if); |
672 | 700 | ||
673 | /* check if it is a backbone gateway. we don't accept | 701 | /* check if it is a backbone gateway. we don't accept |
674 | * roaming advertisement from it, as it has the same | 702 | * roaming advertisement from it, as it has the same |
675 | * entries as we have. | 703 | * entries as we have. |
676 | */ | 704 | */ |
677 | if (bla_is_backbone_gw_orig(bat_priv, roam_adv_packet->src)) | 705 | if (batadv_bla_is_backbone_gw_orig(bat_priv, roam_adv_packet->src)) |
678 | goto out; | 706 | goto out; |
679 | 707 | ||
680 | orig_node = orig_hash_find(bat_priv, roam_adv_packet->src); | 708 | orig_node = batadv_orig_hash_find(bat_priv, roam_adv_packet->src); |
681 | if (!orig_node) | 709 | if (!orig_node) |
682 | goto out; | 710 | goto out; |
683 | 711 | ||
684 | bat_dbg(DBG_TT, bat_priv, | 712 | batadv_dbg(BATADV_DBG_TT, bat_priv, |
685 | "Received ROAMING_ADV from %pM (client %pM)\n", | 713 | "Received ROAMING_ADV from %pM (client %pM)\n", |
686 | roam_adv_packet->src, roam_adv_packet->client); | 714 | roam_adv_packet->src, roam_adv_packet->client); |
687 | 715 | ||
688 | tt_global_add(bat_priv, orig_node, roam_adv_packet->client, | 716 | batadv_tt_global_add(bat_priv, orig_node, roam_adv_packet->client, |
689 | atomic_read(&orig_node->last_ttvn) + 1, true, false); | 717 | BATADV_TT_CLIENT_ROAM, |
718 | atomic_read(&orig_node->last_ttvn) + 1); | ||
690 | 719 | ||
691 | /* Roaming phase starts: I have new information but the ttvn has not | 720 | /* Roaming phase starts: I have new information but the ttvn has not |
692 | * been incremented yet. This flag will make me check all the incoming | 721 | * been incremented yet. This flag will make me check all the incoming |
693 | * packets for the correct destination. */ | 722 | * packets for the correct destination. |
723 | */ | ||
694 | bat_priv->tt_poss_change = true; | 724 | bat_priv->tt_poss_change = true; |
695 | 725 | ||
696 | orig_node_free_ref(orig_node); | 726 | batadv_orig_node_free_ref(orig_node); |
697 | out: | 727 | out: |
698 | /* returning NET_RX_DROP will make the caller function kfree the skb */ | 728 | /* returning NET_RX_DROP will make the caller function kfree the skb */ |
699 | return NET_RX_DROP; | 729 | return NET_RX_DROP; |
@@ -701,26 +731,30 @@ out: | |||
701 | 731 | ||
702 | /* find a suitable router for this originator, and use | 732 | /* find a suitable router for this originator, and use |
703 | * bonding if possible. increases the found neighbors | 733 | * bonding if possible. increases the found neighbors |
704 | * refcount.*/ | 734 | * refcount. |
705 | struct neigh_node *find_router(struct bat_priv *bat_priv, | 735 | */ |
706 | struct orig_node *orig_node, | 736 | struct batadv_neigh_node * |
707 | const struct hard_iface *recv_if) | 737 | batadv_find_router(struct batadv_priv *bat_priv, |
738 | struct batadv_orig_node *orig_node, | ||
739 | const struct batadv_hard_iface *recv_if) | ||
708 | { | 740 | { |
709 | struct orig_node *primary_orig_node; | 741 | struct batadv_orig_node *primary_orig_node; |
710 | struct orig_node *router_orig; | 742 | struct batadv_orig_node *router_orig; |
711 | struct neigh_node *router; | 743 | struct batadv_neigh_node *router; |
712 | static uint8_t zero_mac[ETH_ALEN] = {0, 0, 0, 0, 0, 0}; | 744 | static uint8_t zero_mac[ETH_ALEN] = {0, 0, 0, 0, 0, 0}; |
713 | int bonding_enabled; | 745 | int bonding_enabled; |
746 | uint8_t *primary_addr; | ||
714 | 747 | ||
715 | if (!orig_node) | 748 | if (!orig_node) |
716 | return NULL; | 749 | return NULL; |
717 | 750 | ||
718 | router = orig_node_get_router(orig_node); | 751 | router = batadv_orig_node_get_router(orig_node); |
719 | if (!router) | 752 | if (!router) |
720 | goto err; | 753 | goto err; |
721 | 754 | ||
722 | /* without bonding, the first node should | 755 | /* without bonding, the first node should |
723 | * always choose the default router. */ | 756 | * always choose the default router. |
757 | */ | ||
724 | bonding_enabled = atomic_read(&bat_priv->bonding); | 758 | bonding_enabled = atomic_read(&bat_priv->bonding); |
725 | 759 | ||
726 | rcu_read_lock(); | 760 | rcu_read_lock(); |
@@ -732,43 +766,47 @@ struct neigh_node *find_router(struct bat_priv *bat_priv, | |||
732 | if ((!recv_if) && (!bonding_enabled)) | 766 | if ((!recv_if) && (!bonding_enabled)) |
733 | goto return_router; | 767 | goto return_router; |
734 | 768 | ||
769 | primary_addr = router_orig->primary_addr; | ||
770 | |||
735 | /* if we have something in the primary_addr, we can search | 771 | /* if we have something in the primary_addr, we can search |
736 | * for a potential bonding candidate. */ | 772 | * for a potential bonding candidate. |
737 | if (compare_eth(router_orig->primary_addr, zero_mac)) | 773 | */ |
774 | if (batadv_compare_eth(primary_addr, zero_mac)) | ||
738 | goto return_router; | 775 | goto return_router; |
739 | 776 | ||
740 | /* find the orig_node which has the primary interface. might | 777 | /* find the orig_node which has the primary interface. might |
741 | * even be the same as our router_orig in many cases */ | 778 | * even be the same as our router_orig in many cases |
742 | 779 | */ | |
743 | if (compare_eth(router_orig->primary_addr, router_orig->orig)) { | 780 | if (batadv_compare_eth(primary_addr, router_orig->orig)) { |
744 | primary_orig_node = router_orig; | 781 | primary_orig_node = router_orig; |
745 | } else { | 782 | } else { |
746 | primary_orig_node = orig_hash_find(bat_priv, | 783 | primary_orig_node = batadv_orig_hash_find(bat_priv, |
747 | router_orig->primary_addr); | 784 | primary_addr); |
748 | if (!primary_orig_node) | 785 | if (!primary_orig_node) |
749 | goto return_router; | 786 | goto return_router; |
750 | 787 | ||
751 | orig_node_free_ref(primary_orig_node); | 788 | batadv_orig_node_free_ref(primary_orig_node); |
752 | } | 789 | } |
753 | 790 | ||
754 | /* with less than 2 candidates, we can't do any | 791 | /* with less than 2 candidates, we can't do any |
755 | * bonding and prefer the original router. */ | 792 | * bonding and prefer the original router. |
793 | */ | ||
756 | if (atomic_read(&primary_orig_node->bond_candidates) < 2) | 794 | if (atomic_read(&primary_orig_node->bond_candidates) < 2) |
757 | goto return_router; | 795 | goto return_router; |
758 | 796 | ||
759 | /* all nodes between should choose a candidate which | 797 | /* all nodes between should choose a candidate which |
760 | * is is not on the interface where the packet came | 798 | * is is not on the interface where the packet came |
761 | * in. */ | 799 | * in. |
762 | 800 | */ | |
763 | neigh_node_free_ref(router); | 801 | batadv_neigh_node_free_ref(router); |
764 | 802 | ||
765 | if (bonding_enabled) | 803 | if (bonding_enabled) |
766 | router = find_bond_router(primary_orig_node, recv_if); | 804 | router = batadv_find_bond_router(primary_orig_node, recv_if); |
767 | else | 805 | else |
768 | router = find_ifalter_router(primary_orig_node, recv_if); | 806 | router = batadv_find_ifalter_router(primary_orig_node, recv_if); |
769 | 807 | ||
770 | return_router: | 808 | return_router: |
771 | if (router && router->if_incoming->if_status != IF_ACTIVE) | 809 | if (router && router->if_incoming->if_status != BATADV_IF_ACTIVE) |
772 | goto err_unlock; | 810 | goto err_unlock; |
773 | 811 | ||
774 | rcu_read_unlock(); | 812 | rcu_read_unlock(); |
@@ -777,11 +815,11 @@ err_unlock: | |||
777 | rcu_read_unlock(); | 815 | rcu_read_unlock(); |
778 | err: | 816 | err: |
779 | if (router) | 817 | if (router) |
780 | neigh_node_free_ref(router); | 818 | batadv_neigh_node_free_ref(router); |
781 | return NULL; | 819 | return NULL; |
782 | } | 820 | } |
783 | 821 | ||
784 | static int check_unicast_packet(struct sk_buff *skb, int hdr_size) | 822 | static int batadv_check_unicast_packet(struct sk_buff *skb, int hdr_size) |
785 | { | 823 | { |
786 | struct ethhdr *ethhdr; | 824 | struct ethhdr *ethhdr; |
787 | 825 | ||
@@ -800,23 +838,24 @@ static int check_unicast_packet(struct sk_buff *skb, int hdr_size) | |||
800 | return -1; | 838 | return -1; |
801 | 839 | ||
802 | /* not for me */ | 840 | /* not for me */ |
803 | if (!is_my_mac(ethhdr->h_dest)) | 841 | if (!batadv_is_my_mac(ethhdr->h_dest)) |
804 | return -1; | 842 | return -1; |
805 | 843 | ||
806 | return 0; | 844 | return 0; |
807 | } | 845 | } |
808 | 846 | ||
809 | static int route_unicast_packet(struct sk_buff *skb, struct hard_iface *recv_if) | 847 | static int batadv_route_unicast_packet(struct sk_buff *skb, |
848 | struct batadv_hard_iface *recv_if) | ||
810 | { | 849 | { |
811 | struct bat_priv *bat_priv = netdev_priv(recv_if->soft_iface); | 850 | struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface); |
812 | struct orig_node *orig_node = NULL; | 851 | struct batadv_orig_node *orig_node = NULL; |
813 | struct neigh_node *neigh_node = NULL; | 852 | struct batadv_neigh_node *neigh_node = NULL; |
814 | struct unicast_packet *unicast_packet; | 853 | struct batadv_unicast_packet *unicast_packet; |
815 | struct ethhdr *ethhdr = (struct ethhdr *)skb_mac_header(skb); | 854 | struct ethhdr *ethhdr = (struct ethhdr *)skb_mac_header(skb); |
816 | int ret = NET_RX_DROP; | 855 | int ret = NET_RX_DROP; |
817 | struct sk_buff *new_skb; | 856 | struct sk_buff *new_skb; |
818 | 857 | ||
819 | unicast_packet = (struct unicast_packet *)skb->data; | 858 | unicast_packet = (struct batadv_unicast_packet *)skb->data; |
820 | 859 | ||
821 | /* TTL exceeded */ | 860 | /* TTL exceeded */ |
822 | if (unicast_packet->header.ttl < 2) { | 861 | if (unicast_packet->header.ttl < 2) { |
@@ -826,13 +865,13 @@ static int route_unicast_packet(struct sk_buff *skb, struct hard_iface *recv_if) | |||
826 | } | 865 | } |
827 | 866 | ||
828 | /* get routing information */ | 867 | /* get routing information */ |
829 | orig_node = orig_hash_find(bat_priv, unicast_packet->dest); | 868 | orig_node = batadv_orig_hash_find(bat_priv, unicast_packet->dest); |
830 | 869 | ||
831 | if (!orig_node) | 870 | if (!orig_node) |
832 | goto out; | 871 | goto out; |
833 | 872 | ||
834 | /* find_router() increases neigh_nodes refcount if found. */ | 873 | /* find_router() increases neigh_nodes refcount if found. */ |
835 | neigh_node = find_router(bat_priv, orig_node, recv_if); | 874 | neigh_node = batadv_find_router(bat_priv, orig_node, recv_if); |
836 | 875 | ||
837 | if (!neigh_node) | 876 | if (!neigh_node) |
838 | goto out; | 877 | goto out; |
@@ -841,20 +880,22 @@ static int route_unicast_packet(struct sk_buff *skb, struct hard_iface *recv_if) | |||
841 | if (skb_cow(skb, ETH_HLEN) < 0) | 880 | if (skb_cow(skb, ETH_HLEN) < 0) |
842 | goto out; | 881 | goto out; |
843 | 882 | ||
844 | unicast_packet = (struct unicast_packet *)skb->data; | 883 | unicast_packet = (struct batadv_unicast_packet *)skb->data; |
845 | 884 | ||
846 | if (unicast_packet->header.packet_type == BAT_UNICAST && | 885 | if (unicast_packet->header.packet_type == BATADV_UNICAST && |
847 | atomic_read(&bat_priv->fragmentation) && | 886 | atomic_read(&bat_priv->fragmentation) && |
848 | skb->len > neigh_node->if_incoming->net_dev->mtu) { | 887 | skb->len > neigh_node->if_incoming->net_dev->mtu) { |
849 | ret = frag_send_skb(skb, bat_priv, | 888 | ret = batadv_frag_send_skb(skb, bat_priv, |
850 | neigh_node->if_incoming, neigh_node->addr); | 889 | neigh_node->if_incoming, |
890 | neigh_node->addr); | ||
851 | goto out; | 891 | goto out; |
852 | } | 892 | } |
853 | 893 | ||
854 | if (unicast_packet->header.packet_type == BAT_UNICAST_FRAG && | 894 | if (unicast_packet->header.packet_type == BATADV_UNICAST_FRAG && |
855 | frag_can_reassemble(skb, neigh_node->if_incoming->net_dev->mtu)) { | 895 | batadv_frag_can_reassemble(skb, |
896 | neigh_node->if_incoming->net_dev->mtu)) { | ||
856 | 897 | ||
857 | ret = frag_reassemble_skb(skb, bat_priv, &new_skb); | 898 | ret = batadv_frag_reassemble_skb(skb, bat_priv, &new_skb); |
858 | 899 | ||
859 | if (ret == NET_RX_DROP) | 900 | if (ret == NET_RX_DROP) |
860 | goto out; | 901 | goto out; |
@@ -866,141 +907,153 @@ static int route_unicast_packet(struct sk_buff *skb, struct hard_iface *recv_if) | |||
866 | } | 907 | } |
867 | 908 | ||
868 | skb = new_skb; | 909 | skb = new_skb; |
869 | unicast_packet = (struct unicast_packet *)skb->data; | 910 | unicast_packet = (struct batadv_unicast_packet *)skb->data; |
870 | } | 911 | } |
871 | 912 | ||
872 | /* decrement ttl */ | 913 | /* decrement ttl */ |
873 | unicast_packet->header.ttl--; | 914 | unicast_packet->header.ttl--; |
874 | 915 | ||
916 | /* Update stats counter */ | ||
917 | batadv_inc_counter(bat_priv, BATADV_CNT_FORWARD); | ||
918 | batadv_add_counter(bat_priv, BATADV_CNT_FORWARD_BYTES, | ||
919 | skb->len + ETH_HLEN); | ||
920 | |||
875 | /* route it */ | 921 | /* route it */ |
876 | send_skb_packet(skb, neigh_node->if_incoming, neigh_node->addr); | 922 | batadv_send_skb_packet(skb, neigh_node->if_incoming, neigh_node->addr); |
877 | ret = NET_RX_SUCCESS; | 923 | ret = NET_RX_SUCCESS; |
878 | 924 | ||
879 | out: | 925 | out: |
880 | if (neigh_node) | 926 | if (neigh_node) |
881 | neigh_node_free_ref(neigh_node); | 927 | batadv_neigh_node_free_ref(neigh_node); |
882 | if (orig_node) | 928 | if (orig_node) |
883 | orig_node_free_ref(orig_node); | 929 | batadv_orig_node_free_ref(orig_node); |
884 | return ret; | 930 | return ret; |
885 | } | 931 | } |
886 | 932 | ||
887 | static int check_unicast_ttvn(struct bat_priv *bat_priv, | 933 | static int batadv_check_unicast_ttvn(struct batadv_priv *bat_priv, |
888 | struct sk_buff *skb) { | 934 | struct sk_buff *skb) { |
889 | uint8_t curr_ttvn; | 935 | uint8_t curr_ttvn; |
890 | struct orig_node *orig_node; | 936 | struct batadv_orig_node *orig_node; |
891 | struct ethhdr *ethhdr; | 937 | struct ethhdr *ethhdr; |
892 | struct hard_iface *primary_if; | 938 | struct batadv_hard_iface *primary_if; |
893 | struct unicast_packet *unicast_packet; | 939 | struct batadv_unicast_packet *unicast_packet; |
894 | bool tt_poss_change; | 940 | bool tt_poss_change; |
941 | int is_old_ttvn; | ||
895 | 942 | ||
896 | /* I could need to modify it */ | 943 | /* I could need to modify it */ |
897 | if (skb_cow(skb, sizeof(struct unicast_packet)) < 0) | 944 | if (skb_cow(skb, sizeof(struct batadv_unicast_packet)) < 0) |
898 | return 0; | 945 | return 0; |
899 | 946 | ||
900 | unicast_packet = (struct unicast_packet *)skb->data; | 947 | unicast_packet = (struct batadv_unicast_packet *)skb->data; |
901 | 948 | ||
902 | if (is_my_mac(unicast_packet->dest)) { | 949 | if (batadv_is_my_mac(unicast_packet->dest)) { |
903 | tt_poss_change = bat_priv->tt_poss_change; | 950 | tt_poss_change = bat_priv->tt_poss_change; |
904 | curr_ttvn = (uint8_t)atomic_read(&bat_priv->ttvn); | 951 | curr_ttvn = (uint8_t)atomic_read(&bat_priv->ttvn); |
905 | } else { | 952 | } else { |
906 | orig_node = orig_hash_find(bat_priv, unicast_packet->dest); | 953 | orig_node = batadv_orig_hash_find(bat_priv, |
954 | unicast_packet->dest); | ||
907 | 955 | ||
908 | if (!orig_node) | 956 | if (!orig_node) |
909 | return 0; | 957 | return 0; |
910 | 958 | ||
911 | curr_ttvn = (uint8_t)atomic_read(&orig_node->last_ttvn); | 959 | curr_ttvn = (uint8_t)atomic_read(&orig_node->last_ttvn); |
912 | tt_poss_change = orig_node->tt_poss_change; | 960 | tt_poss_change = orig_node->tt_poss_change; |
913 | orig_node_free_ref(orig_node); | 961 | batadv_orig_node_free_ref(orig_node); |
914 | } | 962 | } |
915 | 963 | ||
916 | /* Check whether I have to reroute the packet */ | 964 | /* Check whether I have to reroute the packet */ |
917 | if (seq_before(unicast_packet->ttvn, curr_ttvn) || tt_poss_change) { | 965 | is_old_ttvn = batadv_seq_before(unicast_packet->ttvn, curr_ttvn); |
966 | if (is_old_ttvn || tt_poss_change) { | ||
918 | /* check if there is enough data before accessing it */ | 967 | /* check if there is enough data before accessing it */ |
919 | if (pskb_may_pull(skb, sizeof(struct unicast_packet) + | 968 | if (pskb_may_pull(skb, sizeof(struct batadv_unicast_packet) + |
920 | ETH_HLEN) < 0) | 969 | ETH_HLEN) < 0) |
921 | return 0; | 970 | return 0; |
922 | 971 | ||
923 | ethhdr = (struct ethhdr *)(skb->data + | 972 | ethhdr = (struct ethhdr *)(skb->data + sizeof(*unicast_packet)); |
924 | sizeof(struct unicast_packet)); | ||
925 | 973 | ||
926 | /* we don't have an updated route for this client, so we should | 974 | /* we don't have an updated route for this client, so we should |
927 | * not try to reroute the packet!! | 975 | * not try to reroute the packet!! |
928 | */ | 976 | */ |
929 | if (tt_global_client_is_roaming(bat_priv, ethhdr->h_dest)) | 977 | if (batadv_tt_global_client_is_roaming(bat_priv, |
978 | ethhdr->h_dest)) | ||
930 | return 1; | 979 | return 1; |
931 | 980 | ||
932 | orig_node = transtable_search(bat_priv, NULL, ethhdr->h_dest); | 981 | orig_node = batadv_transtable_search(bat_priv, NULL, |
982 | ethhdr->h_dest); | ||
933 | 983 | ||
934 | if (!orig_node) { | 984 | if (!orig_node) { |
935 | if (!is_my_client(bat_priv, ethhdr->h_dest)) | 985 | if (!batadv_is_my_client(bat_priv, ethhdr->h_dest)) |
936 | return 0; | 986 | return 0; |
937 | primary_if = primary_if_get_selected(bat_priv); | 987 | primary_if = batadv_primary_if_get_selected(bat_priv); |
938 | if (!primary_if) | 988 | if (!primary_if) |
939 | return 0; | 989 | return 0; |
940 | memcpy(unicast_packet->dest, | 990 | memcpy(unicast_packet->dest, |
941 | primary_if->net_dev->dev_addr, ETH_ALEN); | 991 | primary_if->net_dev->dev_addr, ETH_ALEN); |
942 | hardif_free_ref(primary_if); | 992 | batadv_hardif_free_ref(primary_if); |
943 | } else { | 993 | } else { |
944 | memcpy(unicast_packet->dest, orig_node->orig, | 994 | memcpy(unicast_packet->dest, orig_node->orig, |
945 | ETH_ALEN); | 995 | ETH_ALEN); |
946 | curr_ttvn = (uint8_t) | 996 | curr_ttvn = (uint8_t) |
947 | atomic_read(&orig_node->last_ttvn); | 997 | atomic_read(&orig_node->last_ttvn); |
948 | orig_node_free_ref(orig_node); | 998 | batadv_orig_node_free_ref(orig_node); |
949 | } | 999 | } |
950 | 1000 | ||
951 | bat_dbg(DBG_ROUTES, bat_priv, | 1001 | batadv_dbg(BATADV_DBG_ROUTES, bat_priv, |
952 | "TTVN mismatch (old_ttvn %u new_ttvn %u)! Rerouting unicast packet (for %pM) to %pM\n", | 1002 | "TTVN mismatch (old_ttvn %u new_ttvn %u)! Rerouting unicast packet (for %pM) to %pM\n", |
953 | unicast_packet->ttvn, curr_ttvn, ethhdr->h_dest, | 1003 | unicast_packet->ttvn, curr_ttvn, ethhdr->h_dest, |
954 | unicast_packet->dest); | 1004 | unicast_packet->dest); |
955 | 1005 | ||
956 | unicast_packet->ttvn = curr_ttvn; | 1006 | unicast_packet->ttvn = curr_ttvn; |
957 | } | 1007 | } |
958 | return 1; | 1008 | return 1; |
959 | } | 1009 | } |
960 | 1010 | ||
961 | int recv_unicast_packet(struct sk_buff *skb, struct hard_iface *recv_if) | 1011 | int batadv_recv_unicast_packet(struct sk_buff *skb, |
1012 | struct batadv_hard_iface *recv_if) | ||
962 | { | 1013 | { |
963 | struct bat_priv *bat_priv = netdev_priv(recv_if->soft_iface); | 1014 | struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface); |
964 | struct unicast_packet *unicast_packet; | 1015 | struct batadv_unicast_packet *unicast_packet; |
965 | int hdr_size = sizeof(*unicast_packet); | 1016 | int hdr_size = sizeof(*unicast_packet); |
966 | 1017 | ||
967 | if (check_unicast_packet(skb, hdr_size) < 0) | 1018 | if (batadv_check_unicast_packet(skb, hdr_size) < 0) |
968 | return NET_RX_DROP; | 1019 | return NET_RX_DROP; |
969 | 1020 | ||
970 | if (!check_unicast_ttvn(bat_priv, skb)) | 1021 | if (!batadv_check_unicast_ttvn(bat_priv, skb)) |
971 | return NET_RX_DROP; | 1022 | return NET_RX_DROP; |
972 | 1023 | ||
973 | unicast_packet = (struct unicast_packet *)skb->data; | 1024 | unicast_packet = (struct batadv_unicast_packet *)skb->data; |
974 | 1025 | ||
975 | /* packet for me */ | 1026 | /* packet for me */ |
976 | if (is_my_mac(unicast_packet->dest)) { | 1027 | if (batadv_is_my_mac(unicast_packet->dest)) { |
977 | interface_rx(recv_if->soft_iface, skb, recv_if, hdr_size); | 1028 | batadv_interface_rx(recv_if->soft_iface, skb, recv_if, |
1029 | hdr_size); | ||
978 | return NET_RX_SUCCESS; | 1030 | return NET_RX_SUCCESS; |
979 | } | 1031 | } |
980 | 1032 | ||
981 | return route_unicast_packet(skb, recv_if); | 1033 | return batadv_route_unicast_packet(skb, recv_if); |
982 | } | 1034 | } |
983 | 1035 | ||
984 | int recv_ucast_frag_packet(struct sk_buff *skb, struct hard_iface *recv_if) | 1036 | int batadv_recv_ucast_frag_packet(struct sk_buff *skb, |
1037 | struct batadv_hard_iface *recv_if) | ||
985 | { | 1038 | { |
986 | struct bat_priv *bat_priv = netdev_priv(recv_if->soft_iface); | 1039 | struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface); |
987 | struct unicast_frag_packet *unicast_packet; | 1040 | struct batadv_unicast_frag_packet *unicast_packet; |
988 | int hdr_size = sizeof(*unicast_packet); | 1041 | int hdr_size = sizeof(*unicast_packet); |
989 | struct sk_buff *new_skb = NULL; | 1042 | struct sk_buff *new_skb = NULL; |
990 | int ret; | 1043 | int ret; |
991 | 1044 | ||
992 | if (check_unicast_packet(skb, hdr_size) < 0) | 1045 | if (batadv_check_unicast_packet(skb, hdr_size) < 0) |
993 | return NET_RX_DROP; | 1046 | return NET_RX_DROP; |
994 | 1047 | ||
995 | if (!check_unicast_ttvn(bat_priv, skb)) | 1048 | if (!batadv_check_unicast_ttvn(bat_priv, skb)) |
996 | return NET_RX_DROP; | 1049 | return NET_RX_DROP; |
997 | 1050 | ||
998 | unicast_packet = (struct unicast_frag_packet *)skb->data; | 1051 | unicast_packet = (struct batadv_unicast_frag_packet *)skb->data; |
999 | 1052 | ||
1000 | /* packet for me */ | 1053 | /* packet for me */ |
1001 | if (is_my_mac(unicast_packet->dest)) { | 1054 | if (batadv_is_my_mac(unicast_packet->dest)) { |
1002 | 1055 | ||
1003 | ret = frag_reassemble_skb(skb, bat_priv, &new_skb); | 1056 | ret = batadv_frag_reassemble_skb(skb, bat_priv, &new_skb); |
1004 | 1057 | ||
1005 | if (ret == NET_RX_DROP) | 1058 | if (ret == NET_RX_DROP) |
1006 | return NET_RX_DROP; | 1059 | return NET_RX_DROP; |
@@ -1009,20 +1062,21 @@ int recv_ucast_frag_packet(struct sk_buff *skb, struct hard_iface *recv_if) | |||
1009 | if (!new_skb) | 1062 | if (!new_skb) |
1010 | return NET_RX_SUCCESS; | 1063 | return NET_RX_SUCCESS; |
1011 | 1064 | ||
1012 | interface_rx(recv_if->soft_iface, new_skb, recv_if, | 1065 | batadv_interface_rx(recv_if->soft_iface, new_skb, recv_if, |
1013 | sizeof(struct unicast_packet)); | 1066 | sizeof(struct batadv_unicast_packet)); |
1014 | return NET_RX_SUCCESS; | 1067 | return NET_RX_SUCCESS; |
1015 | } | 1068 | } |
1016 | 1069 | ||
1017 | return route_unicast_packet(skb, recv_if); | 1070 | return batadv_route_unicast_packet(skb, recv_if); |
1018 | } | 1071 | } |
1019 | 1072 | ||
1020 | 1073 | ||
1021 | int recv_bcast_packet(struct sk_buff *skb, struct hard_iface *recv_if) | 1074 | int batadv_recv_bcast_packet(struct sk_buff *skb, |
1075 | struct batadv_hard_iface *recv_if) | ||
1022 | { | 1076 | { |
1023 | struct bat_priv *bat_priv = netdev_priv(recv_if->soft_iface); | 1077 | struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface); |
1024 | struct orig_node *orig_node = NULL; | 1078 | struct batadv_orig_node *orig_node = NULL; |
1025 | struct bcast_packet *bcast_packet; | 1079 | struct batadv_bcast_packet *bcast_packet; |
1026 | struct ethhdr *ethhdr; | 1080 | struct ethhdr *ethhdr; |
1027 | int hdr_size = sizeof(*bcast_packet); | 1081 | int hdr_size = sizeof(*bcast_packet); |
1028 | int ret = NET_RX_DROP; | 1082 | int ret = NET_RX_DROP; |
@@ -1043,19 +1097,19 @@ int recv_bcast_packet(struct sk_buff *skb, struct hard_iface *recv_if) | |||
1043 | goto out; | 1097 | goto out; |
1044 | 1098 | ||
1045 | /* ignore broadcasts sent by myself */ | 1099 | /* ignore broadcasts sent by myself */ |
1046 | if (is_my_mac(ethhdr->h_source)) | 1100 | if (batadv_is_my_mac(ethhdr->h_source)) |
1047 | goto out; | 1101 | goto out; |
1048 | 1102 | ||
1049 | bcast_packet = (struct bcast_packet *)skb->data; | 1103 | bcast_packet = (struct batadv_bcast_packet *)skb->data; |
1050 | 1104 | ||
1051 | /* ignore broadcasts originated by myself */ | 1105 | /* ignore broadcasts originated by myself */ |
1052 | if (is_my_mac(bcast_packet->orig)) | 1106 | if (batadv_is_my_mac(bcast_packet->orig)) |
1053 | goto out; | 1107 | goto out; |
1054 | 1108 | ||
1055 | if (bcast_packet->header.ttl < 2) | 1109 | if (bcast_packet->header.ttl < 2) |
1056 | goto out; | 1110 | goto out; |
1057 | 1111 | ||
1058 | orig_node = orig_hash_find(bat_priv, bcast_packet->orig); | 1112 | orig_node = batadv_orig_hash_find(bat_priv, bcast_packet->orig); |
1059 | 1113 | ||
1060 | if (!orig_node) | 1114 | if (!orig_node) |
1061 | goto out; | 1115 | goto out; |
@@ -1063,39 +1117,40 @@ int recv_bcast_packet(struct sk_buff *skb, struct hard_iface *recv_if) | |||
1063 | spin_lock_bh(&orig_node->bcast_seqno_lock); | 1117 | spin_lock_bh(&orig_node->bcast_seqno_lock); |
1064 | 1118 | ||
1065 | /* check whether the packet is a duplicate */ | 1119 | /* check whether the packet is a duplicate */ |
1066 | if (bat_test_bit(orig_node->bcast_bits, orig_node->last_bcast_seqno, | 1120 | if (batadv_test_bit(orig_node->bcast_bits, orig_node->last_bcast_seqno, |
1067 | ntohl(bcast_packet->seqno))) | 1121 | ntohl(bcast_packet->seqno))) |
1068 | goto spin_unlock; | 1122 | goto spin_unlock; |
1069 | 1123 | ||
1070 | seq_diff = ntohl(bcast_packet->seqno) - orig_node->last_bcast_seqno; | 1124 | seq_diff = ntohl(bcast_packet->seqno) - orig_node->last_bcast_seqno; |
1071 | 1125 | ||
1072 | /* check whether the packet is old and the host just restarted. */ | 1126 | /* check whether the packet is old and the host just restarted. */ |
1073 | if (window_protected(bat_priv, seq_diff, | 1127 | if (batadv_window_protected(bat_priv, seq_diff, |
1074 | &orig_node->bcast_seqno_reset)) | 1128 | &orig_node->bcast_seqno_reset)) |
1075 | goto spin_unlock; | 1129 | goto spin_unlock; |
1076 | 1130 | ||
1077 | /* mark broadcast in flood history, update window position | 1131 | /* mark broadcast in flood history, update window position |
1078 | * if required. */ | 1132 | * if required. |
1079 | if (bit_get_packet(bat_priv, orig_node->bcast_bits, seq_diff, 1)) | 1133 | */ |
1134 | if (batadv_bit_get_packet(bat_priv, orig_node->bcast_bits, seq_diff, 1)) | ||
1080 | orig_node->last_bcast_seqno = ntohl(bcast_packet->seqno); | 1135 | orig_node->last_bcast_seqno = ntohl(bcast_packet->seqno); |
1081 | 1136 | ||
1082 | spin_unlock_bh(&orig_node->bcast_seqno_lock); | 1137 | spin_unlock_bh(&orig_node->bcast_seqno_lock); |
1083 | 1138 | ||
1084 | /* check whether this has been sent by another originator before */ | 1139 | /* check whether this has been sent by another originator before */ |
1085 | if (bla_check_bcast_duplist(bat_priv, bcast_packet, hdr_size)) | 1140 | if (batadv_bla_check_bcast_duplist(bat_priv, bcast_packet, hdr_size)) |
1086 | goto out; | 1141 | goto out; |
1087 | 1142 | ||
1088 | /* rebroadcast packet */ | 1143 | /* rebroadcast packet */ |
1089 | add_bcast_packet_to_list(bat_priv, skb, 1); | 1144 | batadv_add_bcast_packet_to_list(bat_priv, skb, 1); |
1090 | 1145 | ||
1091 | /* don't hand the broadcast up if it is from an originator | 1146 | /* don't hand the broadcast up if it is from an originator |
1092 | * from the same backbone. | 1147 | * from the same backbone. |
1093 | */ | 1148 | */ |
1094 | if (bla_is_backbone_gw(skb, orig_node, hdr_size)) | 1149 | if (batadv_bla_is_backbone_gw(skb, orig_node, hdr_size)) |
1095 | goto out; | 1150 | goto out; |
1096 | 1151 | ||
1097 | /* broadcast for me */ | 1152 | /* broadcast for me */ |
1098 | interface_rx(recv_if->soft_iface, skb, recv_if, hdr_size); | 1153 | batadv_interface_rx(recv_if->soft_iface, skb, recv_if, hdr_size); |
1099 | ret = NET_RX_SUCCESS; | 1154 | ret = NET_RX_SUCCESS; |
1100 | goto out; | 1155 | goto out; |
1101 | 1156 | ||
@@ -1103,15 +1158,16 @@ spin_unlock: | |||
1103 | spin_unlock_bh(&orig_node->bcast_seqno_lock); | 1158 | spin_unlock_bh(&orig_node->bcast_seqno_lock); |
1104 | out: | 1159 | out: |
1105 | if (orig_node) | 1160 | if (orig_node) |
1106 | orig_node_free_ref(orig_node); | 1161 | batadv_orig_node_free_ref(orig_node); |
1107 | return ret; | 1162 | return ret; |
1108 | } | 1163 | } |
1109 | 1164 | ||
1110 | int recv_vis_packet(struct sk_buff *skb, struct hard_iface *recv_if) | 1165 | int batadv_recv_vis_packet(struct sk_buff *skb, |
1166 | struct batadv_hard_iface *recv_if) | ||
1111 | { | 1167 | { |
1112 | struct vis_packet *vis_packet; | 1168 | struct batadv_vis_packet *vis_packet; |
1113 | struct ethhdr *ethhdr; | 1169 | struct ethhdr *ethhdr; |
1114 | struct bat_priv *bat_priv = netdev_priv(recv_if->soft_iface); | 1170 | struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface); |
1115 | int hdr_size = sizeof(*vis_packet); | 1171 | int hdr_size = sizeof(*vis_packet); |
1116 | 1172 | ||
1117 | /* keep skb linear */ | 1173 | /* keep skb linear */ |
@@ -1121,29 +1177,29 @@ int recv_vis_packet(struct sk_buff *skb, struct hard_iface *recv_if) | |||
1121 | if (unlikely(!pskb_may_pull(skb, hdr_size))) | 1177 | if (unlikely(!pskb_may_pull(skb, hdr_size))) |
1122 | return NET_RX_DROP; | 1178 | return NET_RX_DROP; |
1123 | 1179 | ||
1124 | vis_packet = (struct vis_packet *)skb->data; | 1180 | vis_packet = (struct batadv_vis_packet *)skb->data; |
1125 | ethhdr = (struct ethhdr *)skb_mac_header(skb); | 1181 | ethhdr = (struct ethhdr *)skb_mac_header(skb); |
1126 | 1182 | ||
1127 | /* not for me */ | 1183 | /* not for me */ |
1128 | if (!is_my_mac(ethhdr->h_dest)) | 1184 | if (!batadv_is_my_mac(ethhdr->h_dest)) |
1129 | return NET_RX_DROP; | 1185 | return NET_RX_DROP; |
1130 | 1186 | ||
1131 | /* ignore own packets */ | 1187 | /* ignore own packets */ |
1132 | if (is_my_mac(vis_packet->vis_orig)) | 1188 | if (batadv_is_my_mac(vis_packet->vis_orig)) |
1133 | return NET_RX_DROP; | 1189 | return NET_RX_DROP; |
1134 | 1190 | ||
1135 | if (is_my_mac(vis_packet->sender_orig)) | 1191 | if (batadv_is_my_mac(vis_packet->sender_orig)) |
1136 | return NET_RX_DROP; | 1192 | return NET_RX_DROP; |
1137 | 1193 | ||
1138 | switch (vis_packet->vis_type) { | 1194 | switch (vis_packet->vis_type) { |
1139 | case VIS_TYPE_SERVER_SYNC: | 1195 | case BATADV_VIS_TYPE_SERVER_SYNC: |
1140 | receive_server_sync_packet(bat_priv, vis_packet, | 1196 | batadv_receive_server_sync_packet(bat_priv, vis_packet, |
1141 | skb_headlen(skb)); | 1197 | skb_headlen(skb)); |
1142 | break; | 1198 | break; |
1143 | 1199 | ||
1144 | case VIS_TYPE_CLIENT_UPDATE: | 1200 | case BATADV_VIS_TYPE_CLIENT_UPDATE: |
1145 | receive_client_update_packet(bat_priv, vis_packet, | 1201 | batadv_receive_client_update_packet(bat_priv, vis_packet, |
1146 | skb_headlen(skb)); | 1202 | skb_headlen(skb)); |
1147 | break; | 1203 | break; |
1148 | 1204 | ||
1149 | default: /* ignore unknown packet */ | 1205 | default: /* ignore unknown packet */ |
@@ -1151,6 +1207,7 @@ int recv_vis_packet(struct sk_buff *skb, struct hard_iface *recv_if) | |||
1151 | } | 1207 | } |
1152 | 1208 | ||
1153 | /* We take a copy of the data in the packet, so we should | 1209 | /* We take a copy of the data in the packet, so we should |
1154 | always free the skbuf. */ | 1210 | * always free the skbuf. |
1211 | */ | ||
1155 | return NET_RX_DROP; | 1212 | return NET_RX_DROP; |
1156 | } | 1213 | } |