aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv/unicast.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/batman-adv/unicast.c')
-rw-r--r--net/batman-adv/unicast.c179
1 files changed, 93 insertions, 86 deletions
diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
index 74175c210858..00164645b3f7 100644
--- a/net/batman-adv/unicast.c
+++ b/net/batman-adv/unicast.c
@@ -1,5 +1,4 @@
1/* 1/* Copyright (C) 2010-2012 B.A.T.M.A.N. contributors:
2 * Copyright (C) 2010-2012 B.A.T.M.A.N. contributors:
3 * 2 *
4 * Andreas Langer 3 * Andreas Langer
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 "hard-interface.h" 29#include "hard-interface.h"
32 30
33 31
34static struct sk_buff *frag_merge_packet(struct list_head *head, 32static struct sk_buff *
35 struct frag_packet_list_entry *tfp, 33batadv_frag_merge_packet(struct list_head *head,
36 struct sk_buff *skb) 34 struct batadv_frag_packet_list_entry *tfp,
35 struct sk_buff *skb)
37{ 36{
38 struct unicast_frag_packet *up = 37 struct batadv_unicast_frag_packet *up;
39 (struct unicast_frag_packet *)skb->data;
40 struct sk_buff *tmp_skb; 38 struct sk_buff *tmp_skb;
41 struct unicast_packet *unicast_packet; 39 struct batadv_unicast_packet *unicast_packet;
42 int hdr_len = sizeof(*unicast_packet); 40 int hdr_len = sizeof(*unicast_packet);
43 int uni_diff = sizeof(*up) - hdr_len; 41 int uni_diff = sizeof(*up) - hdr_len;
44 42
43 up = (struct batadv_unicast_frag_packet *)skb->data;
45 /* set skb to the first part and tmp_skb to the second part */ 44 /* set skb to the first part and tmp_skb to the second part */
46 if (up->flags & UNI_FRAG_HEAD) { 45 if (up->flags & BATADV_UNI_FRAG_HEAD) {
47 tmp_skb = tfp->skb; 46 tmp_skb = tfp->skb;
48 } else { 47 } else {
49 tmp_skb = skb; 48 tmp_skb = skb;
@@ -66,8 +65,9 @@ static struct sk_buff *frag_merge_packet(struct list_head *head,
66 kfree_skb(tmp_skb); 65 kfree_skb(tmp_skb);
67 66
68 memmove(skb->data + uni_diff, skb->data, hdr_len); 67 memmove(skb->data + uni_diff, skb->data, hdr_len);
69 unicast_packet = (struct unicast_packet *)skb_pull(skb, uni_diff); 68 unicast_packet = (struct batadv_unicast_packet *)skb_pull(skb,
70 unicast_packet->header.packet_type = BAT_UNICAST; 69 uni_diff);
70 unicast_packet->header.packet_type = BATADV_UNICAST;
71 71
72 return skb; 72 return skb;
73 73
@@ -77,11 +77,13 @@ err:
77 return NULL; 77 return NULL;
78} 78}
79 79
80static void frag_create_entry(struct list_head *head, struct sk_buff *skb) 80static void batadv_frag_create_entry(struct list_head *head,
81 struct sk_buff *skb)
81{ 82{
82 struct frag_packet_list_entry *tfp; 83 struct batadv_frag_packet_list_entry *tfp;
83 struct unicast_frag_packet *up = 84 struct batadv_unicast_frag_packet *up;
84 (struct unicast_frag_packet *)skb->data; 85
86 up = (struct batadv_unicast_frag_packet *)skb->data;
85 87
86 /* free and oldest packets stand at the end */ 88 /* free and oldest packets stand at the end */
87 tfp = list_entry((head)->prev, typeof(*tfp), list); 89 tfp = list_entry((head)->prev, typeof(*tfp), list);
@@ -93,15 +95,15 @@ static void frag_create_entry(struct list_head *head, struct sk_buff *skb)
93 return; 95 return;
94} 96}
95 97
96static int frag_create_buffer(struct list_head *head) 98static int batadv_frag_create_buffer(struct list_head *head)
97{ 99{
98 int i; 100 int i;
99 struct frag_packet_list_entry *tfp; 101 struct batadv_frag_packet_list_entry *tfp;
100 102
101 for (i = 0; i < FRAG_BUFFER_SIZE; i++) { 103 for (i = 0; i < BATADV_FRAG_BUFFER_SIZE; i++) {
102 tfp = kmalloc(sizeof(*tfp), GFP_ATOMIC); 104 tfp = kmalloc(sizeof(*tfp), GFP_ATOMIC);
103 if (!tfp) { 105 if (!tfp) {
104 frag_list_free(head); 106 batadv_frag_list_free(head);
105 return -ENOMEM; 107 return -ENOMEM;
106 } 108 }
107 tfp->skb = NULL; 109 tfp->skb = NULL;
@@ -113,14 +115,15 @@ static int frag_create_buffer(struct list_head *head)
113 return 0; 115 return 0;
114} 116}
115 117
116static struct frag_packet_list_entry *frag_search_packet(struct list_head *head, 118static struct batadv_frag_packet_list_entry *
117 const struct unicast_frag_packet *up) 119batadv_frag_search_packet(struct list_head *head,
120 const struct batadv_unicast_frag_packet *up)
118{ 121{
119 struct frag_packet_list_entry *tfp; 122 struct batadv_frag_packet_list_entry *tfp;
120 struct unicast_frag_packet *tmp_up = NULL; 123 struct batadv_unicast_frag_packet *tmp_up = NULL;
121 uint16_t search_seqno; 124 uint16_t search_seqno;
122 125
123 if (up->flags & UNI_FRAG_HEAD) 126 if (up->flags & BATADV_UNI_FRAG_HEAD)
124 search_seqno = ntohs(up->seqno)+1; 127 search_seqno = ntohs(up->seqno)+1;
125 else 128 else
126 search_seqno = ntohs(up->seqno)-1; 129 search_seqno = ntohs(up->seqno)-1;
@@ -133,12 +136,12 @@ static struct frag_packet_list_entry *frag_search_packet(struct list_head *head,
133 if (tfp->seqno == ntohs(up->seqno)) 136 if (tfp->seqno == ntohs(up->seqno))
134 goto mov_tail; 137 goto mov_tail;
135 138
136 tmp_up = (struct unicast_frag_packet *)tfp->skb->data; 139 tmp_up = (struct batadv_unicast_frag_packet *)tfp->skb->data;
137 140
138 if (tfp->seqno == search_seqno) { 141 if (tfp->seqno == search_seqno) {
139 142
140 if ((tmp_up->flags & UNI_FRAG_HEAD) != 143 if ((tmp_up->flags & BATADV_UNI_FRAG_HEAD) !=
141 (up->flags & UNI_FRAG_HEAD)) 144 (up->flags & BATADV_UNI_FRAG_HEAD))
142 return tfp; 145 return tfp;
143 else 146 else
144 goto mov_tail; 147 goto mov_tail;
@@ -151,9 +154,9 @@ mov_tail:
151 return NULL; 154 return NULL;
152} 155}
153 156
154void frag_list_free(struct list_head *head) 157void batadv_frag_list_free(struct list_head *head)
155{ 158{
156 struct frag_packet_list_entry *pf, *tmp_pf; 159 struct batadv_frag_packet_list_entry *pf, *tmp_pf;
157 160
158 if (!list_empty(head)) { 161 if (!list_empty(head)) {
159 162
@@ -172,64 +175,66 @@ void frag_list_free(struct list_head *head)
172 * or the skb could be reassembled (skb_new will point to the new packet and 175 * or the skb could be reassembled (skb_new will point to the new packet and
173 * skb was freed) 176 * skb was freed)
174 */ 177 */
175int frag_reassemble_skb(struct sk_buff *skb, struct bat_priv *bat_priv, 178int batadv_frag_reassemble_skb(struct sk_buff *skb,
176 struct sk_buff **new_skb) 179 struct batadv_priv *bat_priv,
180 struct sk_buff **new_skb)
177{ 181{
178 struct orig_node *orig_node; 182 struct batadv_orig_node *orig_node;
179 struct frag_packet_list_entry *tmp_frag_entry; 183 struct batadv_frag_packet_list_entry *tmp_frag_entry;
180 int ret = NET_RX_DROP; 184 int ret = NET_RX_DROP;
181 struct unicast_frag_packet *unicast_packet = 185 struct batadv_unicast_frag_packet *unicast_packet;
182 (struct unicast_frag_packet *)skb->data;
183 186
187 unicast_packet = (struct batadv_unicast_frag_packet *)skb->data;
184 *new_skb = NULL; 188 *new_skb = NULL;
185 189
186 orig_node = orig_hash_find(bat_priv, unicast_packet->orig); 190 orig_node = batadv_orig_hash_find(bat_priv, unicast_packet->orig);
187 if (!orig_node) 191 if (!orig_node)
188 goto out; 192 goto out;
189 193
190 orig_node->last_frag_packet = jiffies; 194 orig_node->last_frag_packet = jiffies;
191 195
192 if (list_empty(&orig_node->frag_list) && 196 if (list_empty(&orig_node->frag_list) &&
193 frag_create_buffer(&orig_node->frag_list)) { 197 batadv_frag_create_buffer(&orig_node->frag_list)) {
194 pr_debug("couldn't create frag buffer\n"); 198 pr_debug("couldn't create frag buffer\n");
195 goto out; 199 goto out;
196 } 200 }
197 201
198 tmp_frag_entry = frag_search_packet(&orig_node->frag_list, 202 tmp_frag_entry = batadv_frag_search_packet(&orig_node->frag_list,
199 unicast_packet); 203 unicast_packet);
200 204
201 if (!tmp_frag_entry) { 205 if (!tmp_frag_entry) {
202 frag_create_entry(&orig_node->frag_list, skb); 206 batadv_frag_create_entry(&orig_node->frag_list, skb);
203 ret = NET_RX_SUCCESS; 207 ret = NET_RX_SUCCESS;
204 goto out; 208 goto out;
205 } 209 }
206 210
207 *new_skb = frag_merge_packet(&orig_node->frag_list, tmp_frag_entry, 211 *new_skb = batadv_frag_merge_packet(&orig_node->frag_list,
208 skb); 212 tmp_frag_entry, skb);
209 /* if not, merge failed */ 213 /* if not, merge failed */
210 if (*new_skb) 214 if (*new_skb)
211 ret = NET_RX_SUCCESS; 215 ret = NET_RX_SUCCESS;
212 216
213out: 217out:
214 if (orig_node) 218 if (orig_node)
215 orig_node_free_ref(orig_node); 219 batadv_orig_node_free_ref(orig_node);
216 return ret; 220 return ret;
217} 221}
218 222
219int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv, 223int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
220 struct hard_iface *hard_iface, const uint8_t dstaddr[]) 224 struct batadv_hard_iface *hard_iface,
225 const uint8_t dstaddr[])
221{ 226{
222 struct unicast_packet tmp_uc, *unicast_packet; 227 struct batadv_unicast_packet tmp_uc, *unicast_packet;
223 struct hard_iface *primary_if; 228 struct batadv_hard_iface *primary_if;
224 struct sk_buff *frag_skb; 229 struct sk_buff *frag_skb;
225 struct unicast_frag_packet *frag1, *frag2; 230 struct batadv_unicast_frag_packet *frag1, *frag2;
226 int uc_hdr_len = sizeof(*unicast_packet); 231 int uc_hdr_len = sizeof(*unicast_packet);
227 int ucf_hdr_len = sizeof(*frag1); 232 int ucf_hdr_len = sizeof(*frag1);
228 int data_len = skb->len - uc_hdr_len; 233 int data_len = skb->len - uc_hdr_len;
229 int large_tail = 0, ret = NET_RX_DROP; 234 int large_tail = 0, ret = NET_RX_DROP;
230 uint16_t seqno; 235 uint16_t seqno;
231 236
232 primary_if = primary_if_get_selected(bat_priv); 237 primary_if = batadv_primary_if_get_selected(bat_priv);
233 if (!primary_if) 238 if (!primary_if)
234 goto dropped; 239 goto dropped;
235 240
@@ -238,38 +243,38 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
238 goto dropped; 243 goto dropped;
239 skb_reserve(frag_skb, ucf_hdr_len); 244 skb_reserve(frag_skb, ucf_hdr_len);
240 245
241 unicast_packet = (struct unicast_packet *)skb->data; 246 unicast_packet = (struct batadv_unicast_packet *)skb->data;
242 memcpy(&tmp_uc, unicast_packet, uc_hdr_len); 247 memcpy(&tmp_uc, unicast_packet, uc_hdr_len);
243 skb_split(skb, frag_skb, data_len / 2 + uc_hdr_len); 248 skb_split(skb, frag_skb, data_len / 2 + uc_hdr_len);
244 249
245 if (my_skb_head_push(skb, ucf_hdr_len - uc_hdr_len) < 0 || 250 if (batadv_skb_head_push(skb, ucf_hdr_len - uc_hdr_len) < 0 ||
246 my_skb_head_push(frag_skb, ucf_hdr_len) < 0) 251 batadv_skb_head_push(frag_skb, ucf_hdr_len) < 0)
247 goto drop_frag; 252 goto drop_frag;
248 253
249 frag1 = (struct unicast_frag_packet *)skb->data; 254 frag1 = (struct batadv_unicast_frag_packet *)skb->data;
250 frag2 = (struct unicast_frag_packet *)frag_skb->data; 255 frag2 = (struct batadv_unicast_frag_packet *)frag_skb->data;
251 256
252 memcpy(frag1, &tmp_uc, sizeof(tmp_uc)); 257 memcpy(frag1, &tmp_uc, sizeof(tmp_uc));
253 258
254 frag1->header.ttl--; 259 frag1->header.ttl--;
255 frag1->header.version = COMPAT_VERSION; 260 frag1->header.version = BATADV_COMPAT_VERSION;
256 frag1->header.packet_type = BAT_UNICAST_FRAG; 261 frag1->header.packet_type = BATADV_UNICAST_FRAG;
257 262
258 memcpy(frag1->orig, primary_if->net_dev->dev_addr, ETH_ALEN); 263 memcpy(frag1->orig, primary_if->net_dev->dev_addr, ETH_ALEN);
259 memcpy(frag2, frag1, sizeof(*frag2)); 264 memcpy(frag2, frag1, sizeof(*frag2));
260 265
261 if (data_len & 1) 266 if (data_len & 1)
262 large_tail = UNI_FRAG_LARGETAIL; 267 large_tail = BATADV_UNI_FRAG_LARGETAIL;
263 268
264 frag1->flags = UNI_FRAG_HEAD | large_tail; 269 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
265 frag2->flags = large_tail; 270 frag2->flags = large_tail;
266 271
267 seqno = atomic_add_return(2, &hard_iface->frag_seqno); 272 seqno = atomic_add_return(2, &hard_iface->frag_seqno);
268 frag1->seqno = htons(seqno - 1); 273 frag1->seqno = htons(seqno - 1);
269 frag2->seqno = htons(seqno); 274 frag2->seqno = htons(seqno);
270 275
271 send_skb_packet(skb, hard_iface, dstaddr); 276 batadv_send_skb_packet(skb, hard_iface, dstaddr);
272 send_skb_packet(frag_skb, hard_iface, dstaddr); 277 batadv_send_skb_packet(frag_skb, hard_iface, dstaddr);
273 ret = NET_RX_SUCCESS; 278 ret = NET_RX_SUCCESS;
274 goto out; 279 goto out;
275 280
@@ -279,52 +284,53 @@ dropped:
279 kfree_skb(skb); 284 kfree_skb(skb);
280out: 285out:
281 if (primary_if) 286 if (primary_if)
282 hardif_free_ref(primary_if); 287 batadv_hardif_free_ref(primary_if);
283 return ret; 288 return ret;
284} 289}
285 290
286int unicast_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv) 291int batadv_unicast_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv)
287{ 292{
288 struct ethhdr *ethhdr = (struct ethhdr *)skb->data; 293 struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
289 struct unicast_packet *unicast_packet; 294 struct batadv_unicast_packet *unicast_packet;
290 struct orig_node *orig_node; 295 struct batadv_orig_node *orig_node;
291 struct neigh_node *neigh_node; 296 struct batadv_neigh_node *neigh_node;
292 int data_len = skb->len; 297 int data_len = skb->len;
293 int ret = 1; 298 int ret = 1;
299 unsigned int dev_mtu;
294 300
295 /* get routing information */ 301 /* get routing information */
296 if (is_multicast_ether_addr(ethhdr->h_dest)) { 302 if (is_multicast_ether_addr(ethhdr->h_dest)) {
297 orig_node = gw_get_selected_orig(bat_priv); 303 orig_node = batadv_gw_get_selected_orig(bat_priv);
298 if (orig_node) 304 if (orig_node)
299 goto find_router; 305 goto find_router;
300 } 306 }
301 307
302 /* check for tt host - increases orig_node refcount. 308 /* check for tt host - increases orig_node refcount.
303 * returns NULL in case of AP isolation */ 309 * returns NULL in case of AP isolation
304 orig_node = transtable_search(bat_priv, ethhdr->h_source, 310 */
305 ethhdr->h_dest); 311 orig_node = batadv_transtable_search(bat_priv, ethhdr->h_source,
312 ethhdr->h_dest);
306 313
307find_router: 314find_router:
308 /** 315 /* find_router():
309 * find_router():
310 * - if orig_node is NULL it returns NULL 316 * - if orig_node is NULL it returns NULL
311 * - increases neigh_nodes refcount if found. 317 * - increases neigh_nodes refcount if found.
312 */ 318 */
313 neigh_node = find_router(bat_priv, orig_node, NULL); 319 neigh_node = batadv_find_router(bat_priv, orig_node, NULL);
314 320
315 if (!neigh_node) 321 if (!neigh_node)
316 goto out; 322 goto out;
317 323
318 if (my_skb_head_push(skb, sizeof(*unicast_packet)) < 0) 324 if (batadv_skb_head_push(skb, sizeof(*unicast_packet)) < 0)
319 goto out; 325 goto out;
320 326
321 unicast_packet = (struct unicast_packet *)skb->data; 327 unicast_packet = (struct batadv_unicast_packet *)skb->data;
322 328
323 unicast_packet->header.version = COMPAT_VERSION; 329 unicast_packet->header.version = BATADV_COMPAT_VERSION;
324 /* batman packet type: unicast */ 330 /* batman packet type: unicast */
325 unicast_packet->header.packet_type = BAT_UNICAST; 331 unicast_packet->header.packet_type = BATADV_UNICAST;
326 /* set unicast ttl */ 332 /* set unicast ttl */
327 unicast_packet->header.ttl = TTL; 333 unicast_packet->header.ttl = BATADV_TTL;
328 /* copy the destination for faster routing */ 334 /* copy the destination for faster routing */
329 memcpy(unicast_packet->dest, orig_node->orig, ETH_ALEN); 335 memcpy(unicast_packet->dest, orig_node->orig, ETH_ALEN);
330 /* set the destination tt version number */ 336 /* set the destination tt version number */
@@ -336,28 +342,29 @@ find_router:
336 * try to reroute it because the ttvn contained in the header is less 342 * try to reroute it because the ttvn contained in the header is less
337 * than the current one 343 * than the current one
338 */ 344 */
339 if (tt_global_client_is_roaming(bat_priv, ethhdr->h_dest)) 345 if (batadv_tt_global_client_is_roaming(bat_priv, ethhdr->h_dest))
340 unicast_packet->ttvn = unicast_packet->ttvn - 1; 346 unicast_packet->ttvn = unicast_packet->ttvn - 1;
341 347
348 dev_mtu = neigh_node->if_incoming->net_dev->mtu;
342 if (atomic_read(&bat_priv->fragmentation) && 349 if (atomic_read(&bat_priv->fragmentation) &&
343 data_len + sizeof(*unicast_packet) > 350 data_len + sizeof(*unicast_packet) > dev_mtu) {
344 neigh_node->if_incoming->net_dev->mtu) {
345 /* send frag skb decreases ttl */ 351 /* send frag skb decreases ttl */
346 unicast_packet->header.ttl++; 352 unicast_packet->header.ttl++;
347 ret = frag_send_skb(skb, bat_priv, 353 ret = batadv_frag_send_skb(skb, bat_priv,
348 neigh_node->if_incoming, neigh_node->addr); 354 neigh_node->if_incoming,
355 neigh_node->addr);
349 goto out; 356 goto out;
350 } 357 }
351 358
352 send_skb_packet(skb, neigh_node->if_incoming, neigh_node->addr); 359 batadv_send_skb_packet(skb, neigh_node->if_incoming, neigh_node->addr);
353 ret = 0; 360 ret = 0;
354 goto out; 361 goto out;
355 362
356out: 363out:
357 if (neigh_node) 364 if (neigh_node)
358 neigh_node_free_ref(neigh_node); 365 batadv_neigh_node_free_ref(neigh_node);
359 if (orig_node) 366 if (orig_node)
360 orig_node_free_ref(orig_node); 367 batadv_orig_node_free_ref(orig_node);
361 if (ret == 1) 368 if (ret == 1)
362 kfree_skb(skb); 369 kfree_skb(skb);
363 return ret; 370 return ret;