reassembly.c (f61944efdf0d2569721ed6d7b0445e9f1214b295) | reassembly.c (5ab11c98d3a950faf6922b6166e5f8fc874590e7) |
---|---|
1/* 2 * IPv6 fragment reassembly 3 * Linux INET6 implementation 4 * 5 * Authors: 6 * Pedro Roque <roque@di.fc.ul.pt> 7 * 8 * $Id: reassembly.c,v 1.26 2001/03/07 22:00:57 davem Exp $ --- 40 unchanged lines hidden (view full) --- 49 50#include <net/ipv6.h> 51#include <net/ip6_route.h> 52#include <net/protocol.h> 53#include <net/transp_v6.h> 54#include <net/rawv6.h> 55#include <net/ndisc.h> 56#include <net/addrconf.h> | 1/* 2 * IPv6 fragment reassembly 3 * Linux INET6 implementation 4 * 5 * Authors: 6 * Pedro Roque <roque@di.fc.ul.pt> 7 * 8 * $Id: reassembly.c,v 1.26 2001/03/07 22:00:57 davem Exp $ --- 40 unchanged lines hidden (view full) --- 49 50#include <net/ipv6.h> 51#include <net/ip6_route.h> 52#include <net/protocol.h> 53#include <net/transp_v6.h> 54#include <net/rawv6.h> 55#include <net/ndisc.h> 56#include <net/addrconf.h> |
57#include <net/inet_frag.h> |
|
57 58int sysctl_ip6frag_high_thresh __read_mostly = 256*1024; 59int sysctl_ip6frag_low_thresh __read_mostly = 192*1024; 60 61int sysctl_ip6frag_time __read_mostly = IPV6_FRAG_TIMEOUT; 62 63struct ip6frag_skb_cb 64{ --- 5 unchanged lines hidden (view full) --- 70 71 72/* 73 * Equivalent of ipv4 struct ipq 74 */ 75 76struct frag_queue 77{ | 58 59int sysctl_ip6frag_high_thresh __read_mostly = 256*1024; 60int sysctl_ip6frag_low_thresh __read_mostly = 192*1024; 61 62int sysctl_ip6frag_time __read_mostly = IPV6_FRAG_TIMEOUT; 63 64struct ip6frag_skb_cb 65{ --- 5 unchanged lines hidden (view full) --- 71 72 73/* 74 * Equivalent of ipv4 struct ipq 75 */ 76 77struct frag_queue 78{ |
78 struct hlist_node list; 79 struct list_head lru_list; /* lru list member */ | 79 struct inet_frag_queue q; |
80 81 __be32 id; /* fragment id */ 82 struct in6_addr saddr; 83 struct in6_addr daddr; 84 | 80 81 __be32 id; /* fragment id */ 82 struct in6_addr saddr; 83 struct in6_addr daddr; 84 |
85 spinlock_t lock; 86 atomic_t refcnt; 87 struct timer_list timer; /* expire timer */ 88 struct sk_buff *fragments; 89 int len; 90 int meat; | |
91 int iif; | 85 int iif; |
92 ktime_t stamp; | |
93 unsigned int csum; | 86 unsigned int csum; |
94 __u8 last_in; /* has first/last segment arrived? */ 95#define COMPLETE 4 96#define FIRST_IN 2 97#define LAST_IN 1 | |
98 __u16 nhoffset; 99}; 100 101/* Hash table. */ 102 103#define IP6Q_HASHSZ 64 104 105static struct hlist_head ip6_frag_hash[IP6Q_HASHSZ]; 106static DEFINE_RWLOCK(ip6_frag_lock); 107static u32 ip6_frag_hash_rnd; 108static LIST_HEAD(ip6_frag_lru_list); 109int ip6_frag_nqueues = 0; 110 111static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *prev, 112 struct net_device *dev); 113 114static __inline__ void __fq_unlink(struct frag_queue *fq) 115{ | 87 __u16 nhoffset; 88}; 89 90/* Hash table. */ 91 92#define IP6Q_HASHSZ 64 93 94static struct hlist_head ip6_frag_hash[IP6Q_HASHSZ]; 95static DEFINE_RWLOCK(ip6_frag_lock); 96static u32 ip6_frag_hash_rnd; 97static LIST_HEAD(ip6_frag_lru_list); 98int ip6_frag_nqueues = 0; 99 100static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *prev, 101 struct net_device *dev); 102 103static __inline__ void __fq_unlink(struct frag_queue *fq) 104{ |
116 hlist_del(&fq->list); 117 list_del(&fq->lru_list); | 105 hlist_del(&fq->q.list); 106 list_del(&fq->q.lru_list); |
118 ip6_frag_nqueues--; 119} 120 121static __inline__ void fq_unlink(struct frag_queue *fq) 122{ 123 write_lock(&ip6_frag_lock); 124 __fq_unlink(fq); 125 write_unlock(&ip6_frag_lock); --- 39 unchanged lines hidden (view full) --- 165 int i; 166 167 write_lock(&ip6_frag_lock); 168 get_random_bytes(&ip6_frag_hash_rnd, sizeof(u32)); 169 for (i = 0; i < IP6Q_HASHSZ; i++) { 170 struct frag_queue *q; 171 struct hlist_node *p, *n; 172 | 107 ip6_frag_nqueues--; 108} 109 110static __inline__ void fq_unlink(struct frag_queue *fq) 111{ 112 write_lock(&ip6_frag_lock); 113 __fq_unlink(fq); 114 write_unlock(&ip6_frag_lock); --- 39 unchanged lines hidden (view full) --- 154 int i; 155 156 write_lock(&ip6_frag_lock); 157 get_random_bytes(&ip6_frag_hash_rnd, sizeof(u32)); 158 for (i = 0; i < IP6Q_HASHSZ; i++) { 159 struct frag_queue *q; 160 struct hlist_node *p, *n; 161 |
173 hlist_for_each_entry_safe(q, p, n, &ip6_frag_hash[i], list) { | 162 hlist_for_each_entry_safe(q, p, n, &ip6_frag_hash[i], q.list) { |
174 unsigned int hval = ip6qhashfn(q->id, 175 &q->saddr, 176 &q->daddr); 177 178 if (hval != i) { | 163 unsigned int hval = ip6qhashfn(q->id, 164 &q->saddr, 165 &q->daddr); 166 167 if (hval != i) { |
179 hlist_del(&q->list); | 168 hlist_del(&q->q.list); |
180 181 /* Relink to new hash chain. */ | 169 170 /* Relink to new hash chain. */ |
182 hlist_add_head(&q->list, | 171 hlist_add_head(&q->q.list, |
183 &ip6_frag_hash[hval]); 184 185 } 186 } 187 } 188 write_unlock(&ip6_frag_lock); 189 190 mod_timer(&ip6_frag_secret_timer, now + sysctl_ip6frag_secret_interval); --- 30 unchanged lines hidden (view full) --- 221 222/* Destruction primitives. */ 223 224/* Complete destruction of fq. */ 225static void ip6_frag_destroy(struct frag_queue *fq, int *work) 226{ 227 struct sk_buff *fp; 228 | 172 &ip6_frag_hash[hval]); 173 174 } 175 } 176 } 177 write_unlock(&ip6_frag_lock); 178 179 mod_timer(&ip6_frag_secret_timer, now + sysctl_ip6frag_secret_interval); --- 30 unchanged lines hidden (view full) --- 210 211/* Destruction primitives. */ 212 213/* Complete destruction of fq. */ 214static void ip6_frag_destroy(struct frag_queue *fq, int *work) 215{ 216 struct sk_buff *fp; 217 |
229 BUG_TRAP(fq->last_in&COMPLETE); 230 BUG_TRAP(del_timer(&fq->timer) == 0); | 218 BUG_TRAP(fq->q.last_in&COMPLETE); 219 BUG_TRAP(del_timer(&fq->q.timer) == 0); |
231 232 /* Release all fragment data. */ | 220 221 /* Release all fragment data. */ |
233 fp = fq->fragments; | 222 fp = fq->q.fragments; |
234 while (fp) { 235 struct sk_buff *xp = fp->next; 236 237 frag_kfree_skb(fp, work); 238 fp = xp; 239 } 240 241 frag_free_queue(fq, work); 242} 243 244static __inline__ void fq_put(struct frag_queue *fq, int *work) 245{ | 223 while (fp) { 224 struct sk_buff *xp = fp->next; 225 226 frag_kfree_skb(fp, work); 227 fp = xp; 228 } 229 230 frag_free_queue(fq, work); 231} 232 233static __inline__ void fq_put(struct frag_queue *fq, int *work) 234{ |
246 if (atomic_dec_and_test(&fq->refcnt)) | 235 if (atomic_dec_and_test(&fq->q.refcnt)) |
247 ip6_frag_destroy(fq, work); 248} 249 250/* Kill fq entry. It is not destroyed immediately, 251 * because caller (and someone more) holds reference count. 252 */ 253static __inline__ void fq_kill(struct frag_queue *fq) 254{ | 236 ip6_frag_destroy(fq, work); 237} 238 239/* Kill fq entry. It is not destroyed immediately, 240 * because caller (and someone more) holds reference count. 241 */ 242static __inline__ void fq_kill(struct frag_queue *fq) 243{ |
255 if (del_timer(&fq->timer)) 256 atomic_dec(&fq->refcnt); | 244 if (del_timer(&fq->q.timer)) 245 atomic_dec(&fq->q.refcnt); |
257 | 246 |
258 if (!(fq->last_in & COMPLETE)) { | 247 if (!(fq->q.last_in & COMPLETE)) { |
259 fq_unlink(fq); | 248 fq_unlink(fq); |
260 atomic_dec(&fq->refcnt); 261 fq->last_in |= COMPLETE; | 249 atomic_dec(&fq->q.refcnt); 250 fq->q.last_in |= COMPLETE; |
262 } 263} 264 265static void ip6_evictor(struct inet6_dev *idev) 266{ 267 struct frag_queue *fq; 268 struct list_head *tmp; 269 int work; --- 4 unchanged lines hidden (view full) --- 274 275 while(work > 0) { 276 read_lock(&ip6_frag_lock); 277 if (list_empty(&ip6_frag_lru_list)) { 278 read_unlock(&ip6_frag_lock); 279 return; 280 } 281 tmp = ip6_frag_lru_list.next; | 251 } 252} 253 254static void ip6_evictor(struct inet6_dev *idev) 255{ 256 struct frag_queue *fq; 257 struct list_head *tmp; 258 int work; --- 4 unchanged lines hidden (view full) --- 263 264 while(work > 0) { 265 read_lock(&ip6_frag_lock); 266 if (list_empty(&ip6_frag_lru_list)) { 267 read_unlock(&ip6_frag_lock); 268 return; 269 } 270 tmp = ip6_frag_lru_list.next; |
282 fq = list_entry(tmp, struct frag_queue, lru_list); 283 atomic_inc(&fq->refcnt); | 271 fq = list_entry(tmp, struct frag_queue, q.lru_list); 272 atomic_inc(&fq->q.refcnt); |
284 read_unlock(&ip6_frag_lock); 285 | 273 read_unlock(&ip6_frag_lock); 274 |
286 spin_lock(&fq->lock); 287 if (!(fq->last_in&COMPLETE)) | 275 spin_lock(&fq->q.lock); 276 if (!(fq->q.last_in&COMPLETE)) |
288 fq_kill(fq); | 277 fq_kill(fq); |
289 spin_unlock(&fq->lock); | 278 spin_unlock(&fq->q.lock); |
290 291 fq_put(fq, &work); 292 IP6_INC_STATS_BH(idev, IPSTATS_MIB_REASMFAILS); 293 } 294} 295 296static void ip6_frag_expire(unsigned long data) 297{ 298 struct frag_queue *fq = (struct frag_queue *) data; 299 struct net_device *dev = NULL; 300 | 279 280 fq_put(fq, &work); 281 IP6_INC_STATS_BH(idev, IPSTATS_MIB_REASMFAILS); 282 } 283} 284 285static void ip6_frag_expire(unsigned long data) 286{ 287 struct frag_queue *fq = (struct frag_queue *) data; 288 struct net_device *dev = NULL; 289 |
301 spin_lock(&fq->lock); | 290 spin_lock(&fq->q.lock); |
302 | 291 |
303 if (fq->last_in & COMPLETE) | 292 if (fq->q.last_in & COMPLETE) |
304 goto out; 305 306 fq_kill(fq); 307 308 dev = dev_get_by_index(&init_net, fq->iif); 309 if (!dev) 310 goto out; 311 312 rcu_read_lock(); 313 IP6_INC_STATS_BH(__in6_dev_get(dev), IPSTATS_MIB_REASMTIMEOUT); 314 IP6_INC_STATS_BH(__in6_dev_get(dev), IPSTATS_MIB_REASMFAILS); 315 rcu_read_unlock(); 316 317 /* Don't send error if the first segment did not arrive. */ | 293 goto out; 294 295 fq_kill(fq); 296 297 dev = dev_get_by_index(&init_net, fq->iif); 298 if (!dev) 299 goto out; 300 301 rcu_read_lock(); 302 IP6_INC_STATS_BH(__in6_dev_get(dev), IPSTATS_MIB_REASMTIMEOUT); 303 IP6_INC_STATS_BH(__in6_dev_get(dev), IPSTATS_MIB_REASMFAILS); 304 rcu_read_unlock(); 305 306 /* Don't send error if the first segment did not arrive. */ |
318 if (!(fq->last_in&FIRST_IN) || !fq->fragments) | 307 if (!(fq->q.last_in&FIRST_IN) || !fq->q.fragments) |
319 goto out; 320 321 /* 322 But use as source device on which LAST ARRIVED 323 segment was received. And do not use fq->dev 324 pointer directly, device might already disappeared. 325 */ | 308 goto out; 309 310 /* 311 But use as source device on which LAST ARRIVED 312 segment was received. And do not use fq->dev 313 pointer directly, device might already disappeared. 314 */ |
326 fq->fragments->dev = dev; 327 icmpv6_send(fq->fragments, ICMPV6_TIME_EXCEED, ICMPV6_EXC_FRAGTIME, 0, dev); | 315 fq->q.fragments->dev = dev; 316 icmpv6_send(fq->q.fragments, ICMPV6_TIME_EXCEED, ICMPV6_EXC_FRAGTIME, 0, dev); |
328out: 329 if (dev) 330 dev_put(dev); | 317out: 318 if (dev) 319 dev_put(dev); |
331 spin_unlock(&fq->lock); | 320 spin_unlock(&fq->q.lock); |
332 fq_put(fq, NULL); 333} 334 335/* Creation primitives. */ 336 337 338static struct frag_queue *ip6_frag_intern(struct frag_queue *fq_in) 339{ 340 struct frag_queue *fq; 341 unsigned int hash; 342#ifdef CONFIG_SMP 343 struct hlist_node *n; 344#endif 345 346 write_lock(&ip6_frag_lock); 347 hash = ip6qhashfn(fq_in->id, &fq_in->saddr, &fq_in->daddr); 348#ifdef CONFIG_SMP | 321 fq_put(fq, NULL); 322} 323 324/* Creation primitives. */ 325 326 327static struct frag_queue *ip6_frag_intern(struct frag_queue *fq_in) 328{ 329 struct frag_queue *fq; 330 unsigned int hash; 331#ifdef CONFIG_SMP 332 struct hlist_node *n; 333#endif 334 335 write_lock(&ip6_frag_lock); 336 hash = ip6qhashfn(fq_in->id, &fq_in->saddr, &fq_in->daddr); 337#ifdef CONFIG_SMP |
349 hlist_for_each_entry(fq, n, &ip6_frag_hash[hash], list) { | 338 hlist_for_each_entry(fq, n, &ip6_frag_hash[hash], q.list) { |
350 if (fq->id == fq_in->id && 351 ipv6_addr_equal(&fq_in->saddr, &fq->saddr) && 352 ipv6_addr_equal(&fq_in->daddr, &fq->daddr)) { | 339 if (fq->id == fq_in->id && 340 ipv6_addr_equal(&fq_in->saddr, &fq->saddr) && 341 ipv6_addr_equal(&fq_in->daddr, &fq->daddr)) { |
353 atomic_inc(&fq->refcnt); | 342 atomic_inc(&fq->q.refcnt); |
354 write_unlock(&ip6_frag_lock); | 343 write_unlock(&ip6_frag_lock); |
355 fq_in->last_in |= COMPLETE; | 344 fq_in->q.last_in |= COMPLETE; |
356 fq_put(fq_in, NULL); 357 return fq; 358 } 359 } 360#endif 361 fq = fq_in; 362 | 345 fq_put(fq_in, NULL); 346 return fq; 347 } 348 } 349#endif 350 fq = fq_in; 351 |
363 if (!mod_timer(&fq->timer, jiffies + sysctl_ip6frag_time)) 364 atomic_inc(&fq->refcnt); | 352 if (!mod_timer(&fq->q.timer, jiffies + sysctl_ip6frag_time)) 353 atomic_inc(&fq->q.refcnt); |
365 | 354 |
366 atomic_inc(&fq->refcnt); 367 hlist_add_head(&fq->list, &ip6_frag_hash[hash]); 368 INIT_LIST_HEAD(&fq->lru_list); 369 list_add_tail(&fq->lru_list, &ip6_frag_lru_list); | 355 atomic_inc(&fq->q.refcnt); 356 hlist_add_head(&fq->q.list, &ip6_frag_hash[hash]); 357 INIT_LIST_HEAD(&fq->q.lru_list); 358 list_add_tail(&fq->q.lru_list, &ip6_frag_lru_list); |
370 ip6_frag_nqueues++; 371 write_unlock(&ip6_frag_lock); 372 return fq; 373} 374 375 376static struct frag_queue * 377ip6_frag_create(__be32 id, struct in6_addr *src, struct in6_addr *dst, 378 struct inet6_dev *idev) 379{ 380 struct frag_queue *fq; 381 382 if ((fq = frag_alloc_queue()) == NULL) 383 goto oom; 384 385 fq->id = id; 386 ipv6_addr_copy(&fq->saddr, src); 387 ipv6_addr_copy(&fq->daddr, dst); 388 | 359 ip6_frag_nqueues++; 360 write_unlock(&ip6_frag_lock); 361 return fq; 362} 363 364 365static struct frag_queue * 366ip6_frag_create(__be32 id, struct in6_addr *src, struct in6_addr *dst, 367 struct inet6_dev *idev) 368{ 369 struct frag_queue *fq; 370 371 if ((fq = frag_alloc_queue()) == NULL) 372 goto oom; 373 374 fq->id = id; 375 ipv6_addr_copy(&fq->saddr, src); 376 ipv6_addr_copy(&fq->daddr, dst); 377 |
389 init_timer(&fq->timer); 390 fq->timer.function = ip6_frag_expire; 391 fq->timer.data = (long) fq; 392 spin_lock_init(&fq->lock); 393 atomic_set(&fq->refcnt, 1); | 378 init_timer(&fq->q.timer); 379 fq->q.timer.function = ip6_frag_expire; 380 fq->q.timer.data = (long) fq; 381 spin_lock_init(&fq->q.lock); 382 atomic_set(&fq->q.refcnt, 1); |
394 395 return ip6_frag_intern(fq); 396 397oom: 398 IP6_INC_STATS_BH(idev, IPSTATS_MIB_REASMFAILS); 399 return NULL; 400} 401 402static __inline__ struct frag_queue * 403fq_find(__be32 id, struct in6_addr *src, struct in6_addr *dst, 404 struct inet6_dev *idev) 405{ 406 struct frag_queue *fq; 407 struct hlist_node *n; 408 unsigned int hash; 409 410 read_lock(&ip6_frag_lock); 411 hash = ip6qhashfn(id, src, dst); | 383 384 return ip6_frag_intern(fq); 385 386oom: 387 IP6_INC_STATS_BH(idev, IPSTATS_MIB_REASMFAILS); 388 return NULL; 389} 390 391static __inline__ struct frag_queue * 392fq_find(__be32 id, struct in6_addr *src, struct in6_addr *dst, 393 struct inet6_dev *idev) 394{ 395 struct frag_queue *fq; 396 struct hlist_node *n; 397 unsigned int hash; 398 399 read_lock(&ip6_frag_lock); 400 hash = ip6qhashfn(id, src, dst); |
412 hlist_for_each_entry(fq, n, &ip6_frag_hash[hash], list) { | 401 hlist_for_each_entry(fq, n, &ip6_frag_hash[hash], q.list) { |
413 if (fq->id == id && 414 ipv6_addr_equal(src, &fq->saddr) && 415 ipv6_addr_equal(dst, &fq->daddr)) { | 402 if (fq->id == id && 403 ipv6_addr_equal(src, &fq->saddr) && 404 ipv6_addr_equal(dst, &fq->daddr)) { |
416 atomic_inc(&fq->refcnt); | 405 atomic_inc(&fq->q.refcnt); |
417 read_unlock(&ip6_frag_lock); 418 return fq; 419 } 420 } 421 read_unlock(&ip6_frag_lock); 422 423 return ip6_frag_create(id, src, dst, idev); 424} 425 426 427static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb, 428 struct frag_hdr *fhdr, int nhoff) 429{ 430 struct sk_buff *prev, *next; 431 struct net_device *dev; 432 int offset, end; 433 | 406 read_unlock(&ip6_frag_lock); 407 return fq; 408 } 409 } 410 read_unlock(&ip6_frag_lock); 411 412 return ip6_frag_create(id, src, dst, idev); 413} 414 415 416static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb, 417 struct frag_hdr *fhdr, int nhoff) 418{ 419 struct sk_buff *prev, *next; 420 struct net_device *dev; 421 int offset, end; 422 |
434 if (fq->last_in & COMPLETE) | 423 if (fq->q.last_in & COMPLETE) |
435 goto err; 436 437 offset = ntohs(fhdr->frag_off) & ~0x7; 438 end = offset + (ntohs(ipv6_hdr(skb)->payload_len) - 439 ((u8 *)(fhdr + 1) - (u8 *)(ipv6_hdr(skb) + 1))); 440 441 if ((unsigned int)end > IPV6_MAXPLEN) { 442 IP6_INC_STATS_BH(ip6_dst_idev(skb->dst), --- 11 unchanged lines hidden (view full) --- 454 0)); 455 } 456 457 /* Is this the final fragment? */ 458 if (!(fhdr->frag_off & htons(IP6_MF))) { 459 /* If we already have some bits beyond end 460 * or have different end, the segment is corrupted. 461 */ | 424 goto err; 425 426 offset = ntohs(fhdr->frag_off) & ~0x7; 427 end = offset + (ntohs(ipv6_hdr(skb)->payload_len) - 428 ((u8 *)(fhdr + 1) - (u8 *)(ipv6_hdr(skb) + 1))); 429 430 if ((unsigned int)end > IPV6_MAXPLEN) { 431 IP6_INC_STATS_BH(ip6_dst_idev(skb->dst), --- 11 unchanged lines hidden (view full) --- 443 0)); 444 } 445 446 /* Is this the final fragment? */ 447 if (!(fhdr->frag_off & htons(IP6_MF))) { 448 /* If we already have some bits beyond end 449 * or have different end, the segment is corrupted. 450 */ |
462 if (end < fq->len || 463 ((fq->last_in & LAST_IN) && end != fq->len)) | 451 if (end < fq->q.len || 452 ((fq->q.last_in & LAST_IN) && end != fq->q.len)) |
464 goto err; | 453 goto err; |
465 fq->last_in |= LAST_IN; 466 fq->len = end; | 454 fq->q.last_in |= LAST_IN; 455 fq->q.len = end; |
467 } else { 468 /* Check if the fragment is rounded to 8 bytes. 469 * Required by the RFC. 470 */ 471 if (end & 0x7) { 472 /* RFC2460 says always send parameter problem in 473 * this case. -DaveM 474 */ 475 IP6_INC_STATS_BH(ip6_dst_idev(skb->dst), 476 IPSTATS_MIB_INHDRERRORS); 477 icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, 478 offsetof(struct ipv6hdr, payload_len)); 479 return -1; 480 } | 456 } else { 457 /* Check if the fragment is rounded to 8 bytes. 458 * Required by the RFC. 459 */ 460 if (end & 0x7) { 461 /* RFC2460 says always send parameter problem in 462 * this case. -DaveM 463 */ 464 IP6_INC_STATS_BH(ip6_dst_idev(skb->dst), 465 IPSTATS_MIB_INHDRERRORS); 466 icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, 467 offsetof(struct ipv6hdr, payload_len)); 468 return -1; 469 } |
481 if (end > fq->len) { | 470 if (end > fq->q.len) { |
482 /* Some bits beyond end -> corruption. */ | 471 /* Some bits beyond end -> corruption. */ |
483 if (fq->last_in & LAST_IN) | 472 if (fq->q.last_in & LAST_IN) |
484 goto err; | 473 goto err; |
485 fq->len = end; | 474 fq->q.len = end; |
486 } 487 } 488 489 if (end == offset) 490 goto err; 491 492 /* Point into the IP datagram 'data' part. */ 493 if (!pskb_pull(skb, (u8 *) (fhdr + 1) - skb->data)) 494 goto err; 495 496 if (pskb_trim_rcsum(skb, end - offset)) 497 goto err; 498 499 /* Find out which fragments are in front and at the back of us 500 * in the chain of fragments so far. We must know where to put 501 * this fragment, right? 502 */ 503 prev = NULL; | 475 } 476 } 477 478 if (end == offset) 479 goto err; 480 481 /* Point into the IP datagram 'data' part. */ 482 if (!pskb_pull(skb, (u8 *) (fhdr + 1) - skb->data)) 483 goto err; 484 485 if (pskb_trim_rcsum(skb, end - offset)) 486 goto err; 487 488 /* Find out which fragments are in front and at the back of us 489 * in the chain of fragments so far. We must know where to put 490 * this fragment, right? 491 */ 492 prev = NULL; |
504 for(next = fq->fragments; next != NULL; next = next->next) { | 493 for(next = fq->q.fragments; next != NULL; next = next->next) { |
505 if (FRAG6_CB(next)->offset >= offset) 506 break; /* bingo! */ 507 prev = next; 508 } 509 510 /* We found where to put this one. Check for overlap with 511 * preceding fragment, and, if needed, align things so that 512 * any overlaps are eliminated. --- 20 unchanged lines hidden (view full) --- 533 534 if (i < next->len) { 535 /* Eat head of the next overlapped fragment 536 * and leave the loop. The next ones cannot overlap. 537 */ 538 if (!pskb_pull(next, i)) 539 goto err; 540 FRAG6_CB(next)->offset += i; /* next fragment */ | 494 if (FRAG6_CB(next)->offset >= offset) 495 break; /* bingo! */ 496 prev = next; 497 } 498 499 /* We found where to put this one. Check for overlap with 500 * preceding fragment, and, if needed, align things so that 501 * any overlaps are eliminated. --- 20 unchanged lines hidden (view full) --- 522 523 if (i < next->len) { 524 /* Eat head of the next overlapped fragment 525 * and leave the loop. The next ones cannot overlap. 526 */ 527 if (!pskb_pull(next, i)) 528 goto err; 529 FRAG6_CB(next)->offset += i; /* next fragment */ |
541 fq->meat -= i; | 530 fq->q.meat -= i; |
542 if (next->ip_summed != CHECKSUM_UNNECESSARY) 543 next->ip_summed = CHECKSUM_NONE; 544 break; 545 } else { 546 struct sk_buff *free_it = next; 547 548 /* Old fragment is completely overridden with 549 * new one drop it. 550 */ 551 next = next->next; 552 553 if (prev) 554 prev->next = next; 555 else | 531 if (next->ip_summed != CHECKSUM_UNNECESSARY) 532 next->ip_summed = CHECKSUM_NONE; 533 break; 534 } else { 535 struct sk_buff *free_it = next; 536 537 /* Old fragment is completely overridden with 538 * new one drop it. 539 */ 540 next = next->next; 541 542 if (prev) 543 prev->next = next; 544 else |
556 fq->fragments = next; | 545 fq->q.fragments = next; |
557 | 546 |
558 fq->meat -= free_it->len; | 547 fq->q.meat -= free_it->len; |
559 frag_kfree_skb(free_it, NULL); 560 } 561 } 562 563 FRAG6_CB(skb)->offset = offset; 564 565 /* Insert this fragment in the chain of fragments. */ 566 skb->next = next; 567 if (prev) 568 prev->next = skb; 569 else | 548 frag_kfree_skb(free_it, NULL); 549 } 550 } 551 552 FRAG6_CB(skb)->offset = offset; 553 554 /* Insert this fragment in the chain of fragments. */ 555 skb->next = next; 556 if (prev) 557 prev->next = skb; 558 else |
570 fq->fragments = skb; | 559 fq->q.fragments = skb; |
571 572 dev = skb->dev; 573 if (dev) { 574 fq->iif = dev->ifindex; 575 skb->dev = NULL; 576 } | 560 561 dev = skb->dev; 562 if (dev) { 563 fq->iif = dev->ifindex; 564 skb->dev = NULL; 565 } |
577 fq->stamp = skb->tstamp; 578 fq->meat += skb->len; | 566 fq->q.stamp = skb->tstamp; 567 fq->q.meat += skb->len; |
579 atomic_add(skb->truesize, &ip6_frag_mem); 580 581 /* The first fragment. 582 * nhoffset is obtained from the first fragment, of course. 583 */ 584 if (offset == 0) { 585 fq->nhoffset = nhoff; | 568 atomic_add(skb->truesize, &ip6_frag_mem); 569 570 /* The first fragment. 571 * nhoffset is obtained from the first fragment, of course. 572 */ 573 if (offset == 0) { 574 fq->nhoffset = nhoff; |
586 fq->last_in |= FIRST_IN; | 575 fq->q.last_in |= FIRST_IN; |
587 } 588 | 576 } 577 |
589 if (fq->last_in == (FIRST_IN | LAST_IN) && fq->meat == fq->len) | 578 if (fq->q.last_in == (FIRST_IN | LAST_IN) && fq->q.meat == fq->q.len) |
590 return ip6_frag_reasm(fq, prev, dev); 591 592 write_lock(&ip6_frag_lock); | 579 return ip6_frag_reasm(fq, prev, dev); 580 581 write_lock(&ip6_frag_lock); |
593 list_move_tail(&fq->lru_list, &ip6_frag_lru_list); | 582 list_move_tail(&fq->q.lru_list, &ip6_frag_lru_list); |
594 write_unlock(&ip6_frag_lock); 595 return -1; 596 597err: 598 IP6_INC_STATS(ip6_dst_idev(skb->dst), IPSTATS_MIB_REASMFAILS); 599 kfree_skb(skb); 600 return -1; 601} --- 5 unchanged lines hidden (view full) --- 607 * 608 * It is called with locked fq, and caller must check that 609 * queue is eligible for reassembly i.e. it is not COMPLETE, 610 * the last and the first frames arrived and all the bits are here. 611 */ 612static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *prev, 613 struct net_device *dev) 614{ | 583 write_unlock(&ip6_frag_lock); 584 return -1; 585 586err: 587 IP6_INC_STATS(ip6_dst_idev(skb->dst), IPSTATS_MIB_REASMFAILS); 588 kfree_skb(skb); 589 return -1; 590} --- 5 unchanged lines hidden (view full) --- 596 * 597 * It is called with locked fq, and caller must check that 598 * queue is eligible for reassembly i.e. it is not COMPLETE, 599 * the last and the first frames arrived and all the bits are here. 600 */ 601static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *prev, 602 struct net_device *dev) 603{ |
615 struct sk_buff *fp, *head = fq->fragments; | 604 struct sk_buff *fp, *head = fq->q.fragments; |
616 int payload_len; 617 unsigned int nhoff; 618 619 fq_kill(fq); 620 621 /* Make the one we just received the head. */ 622 if (prev) { 623 head = prev->next; 624 fp = skb_clone(head, GFP_ATOMIC); 625 626 if (!fp) 627 goto out_oom; 628 629 fp->next = head->next; 630 prev->next = fp; 631 | 605 int payload_len; 606 unsigned int nhoff; 607 608 fq_kill(fq); 609 610 /* Make the one we just received the head. */ 611 if (prev) { 612 head = prev->next; 613 fp = skb_clone(head, GFP_ATOMIC); 614 615 if (!fp) 616 goto out_oom; 617 618 fp->next = head->next; 619 prev->next = fp; 620 |
632 skb_morph(head, fq->fragments); 633 head->next = fq->fragments->next; | 621 skb_morph(head, fq->q.fragments); 622 head->next = fq->q.fragments->next; |
634 | 623 |
635 kfree_skb(fq->fragments); 636 fq->fragments = head; | 624 kfree_skb(fq->q.fragments); 625 fq->q.fragments = head; |
637 } 638 639 BUG_TRAP(head != NULL); 640 BUG_TRAP(FRAG6_CB(head)->offset == 0); 641 642 /* Unfragmented part is taken from the first segment. */ 643 payload_len = ((head->data - skb_network_header(head)) - | 626 } 627 628 BUG_TRAP(head != NULL); 629 BUG_TRAP(FRAG6_CB(head)->offset == 0); 630 631 /* Unfragmented part is taken from the first segment. */ 632 payload_len = ((head->data - skb_network_header(head)) - |
644 sizeof(struct ipv6hdr) + fq->len - | 633 sizeof(struct ipv6hdr) + fq->q.len - |
645 sizeof(struct frag_hdr)); 646 if (payload_len > IPV6_MAXPLEN) 647 goto out_oversize; 648 649 /* Head of list must not be cloned. */ 650 if (skb_cloned(head) && pskb_expand_head(head, 0, 0, GFP_ATOMIC)) 651 goto out_oom; 652 --- 42 unchanged lines hidden (view full) --- 695 else if (head->ip_summed == CHECKSUM_COMPLETE) 696 head->csum = csum_add(head->csum, fp->csum); 697 head->truesize += fp->truesize; 698 atomic_sub(fp->truesize, &ip6_frag_mem); 699 } 700 701 head->next = NULL; 702 head->dev = dev; | 634 sizeof(struct frag_hdr)); 635 if (payload_len > IPV6_MAXPLEN) 636 goto out_oversize; 637 638 /* Head of list must not be cloned. */ 639 if (skb_cloned(head) && pskb_expand_head(head, 0, 0, GFP_ATOMIC)) 640 goto out_oom; 641 --- 42 unchanged lines hidden (view full) --- 684 else if (head->ip_summed == CHECKSUM_COMPLETE) 685 head->csum = csum_add(head->csum, fp->csum); 686 head->truesize += fp->truesize; 687 atomic_sub(fp->truesize, &ip6_frag_mem); 688 } 689 690 head->next = NULL; 691 head->dev = dev; |
703 head->tstamp = fq->stamp; | 692 head->tstamp = fq->q.stamp; |
704 ipv6_hdr(head)->payload_len = htons(payload_len); 705 IP6CB(head)->nhoff = nhoff; 706 707 /* Yes, and fold redundant checksum back. 8) */ 708 if (head->ip_summed == CHECKSUM_COMPLETE) 709 head->csum = csum_partial(skb_network_header(head), 710 skb_network_header_len(head), 711 head->csum); 712 713 rcu_read_lock(); 714 IP6_INC_STATS_BH(__in6_dev_get(dev), IPSTATS_MIB_REASMOKS); 715 rcu_read_unlock(); | 693 ipv6_hdr(head)->payload_len = htons(payload_len); 694 IP6CB(head)->nhoff = nhoff; 695 696 /* Yes, and fold redundant checksum back. 8) */ 697 if (head->ip_summed == CHECKSUM_COMPLETE) 698 head->csum = csum_partial(skb_network_header(head), 699 skb_network_header_len(head), 700 head->csum); 701 702 rcu_read_lock(); 703 IP6_INC_STATS_BH(__in6_dev_get(dev), IPSTATS_MIB_REASMOKS); 704 rcu_read_unlock(); |
716 fq->fragments = NULL; | 705 fq->q.fragments = NULL; |
717 return 1; 718 719out_oversize: 720 if (net_ratelimit()) 721 printk(KERN_DEBUG "ip6_frag_reasm: payload len = %d\n", payload_len); 722 goto out_fail; 723out_oom: 724 if (net_ratelimit()) --- 43 unchanged lines hidden (view full) --- 768 769 if (atomic_read(&ip6_frag_mem) > sysctl_ip6frag_high_thresh) 770 ip6_evictor(ip6_dst_idev(skb->dst)); 771 772 if ((fq = fq_find(fhdr->identification, &hdr->saddr, &hdr->daddr, 773 ip6_dst_idev(skb->dst))) != NULL) { 774 int ret; 775 | 706 return 1; 707 708out_oversize: 709 if (net_ratelimit()) 710 printk(KERN_DEBUG "ip6_frag_reasm: payload len = %d\n", payload_len); 711 goto out_fail; 712out_oom: 713 if (net_ratelimit()) --- 43 unchanged lines hidden (view full) --- 757 758 if (atomic_read(&ip6_frag_mem) > sysctl_ip6frag_high_thresh) 759 ip6_evictor(ip6_dst_idev(skb->dst)); 760 761 if ((fq = fq_find(fhdr->identification, &hdr->saddr, &hdr->daddr, 762 ip6_dst_idev(skb->dst))) != NULL) { 763 int ret; 764 |
776 spin_lock(&fq->lock); | 765 spin_lock(&fq->q.lock); |
777 778 ret = ip6_frag_queue(fq, skb, fhdr, IP6CB(skb)->nhoff); 779 | 766 767 ret = ip6_frag_queue(fq, skb, fhdr, IP6CB(skb)->nhoff); 768 |
780 spin_unlock(&fq->lock); | 769 spin_unlock(&fq->q.lock); |
781 fq_put(fq, NULL); 782 return ret; 783 } 784 785 IP6_INC_STATS_BH(ip6_dst_idev(skb->dst), IPSTATS_MIB_REASMFAILS); 786 kfree_skb(skb); 787 return -1; 788} --- 20 unchanged lines hidden --- | 770 fq_put(fq, NULL); 771 return ret; 772 } 773 774 IP6_INC_STATS_BH(ip6_dst_idev(skb->dst), IPSTATS_MIB_REASMFAILS); 775 kfree_skb(skb); 776 return -1; 777} --- 20 unchanged lines hidden --- |