11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * IPv6 fragment reassembly 31da177e4SLinus Torvalds * Linux INET6 implementation 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * Authors: 61da177e4SLinus Torvalds * Pedro Roque <roque@di.fc.ul.pt> 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * $Id: reassembly.c,v 1.26 2001/03/07 22:00:57 davem Exp $ 91da177e4SLinus Torvalds * 101da177e4SLinus Torvalds * Based on: net/ipv4/ip_fragment.c 111da177e4SLinus Torvalds * 121da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or 131da177e4SLinus Torvalds * modify it under the terms of the GNU General Public License 141da177e4SLinus Torvalds * as published by the Free Software Foundation; either version 151da177e4SLinus Torvalds * 2 of the License, or (at your option) any later version. 161da177e4SLinus Torvalds */ 171da177e4SLinus Torvalds 181da177e4SLinus Torvalds /* 191da177e4SLinus Torvalds * Fixes: 201da177e4SLinus Torvalds * Andi Kleen Make it work with multiple hosts. 211da177e4SLinus Torvalds * More RFC compliance. 221da177e4SLinus Torvalds * 231da177e4SLinus Torvalds * Horst von Brand Add missing #include <linux/string.h> 241da177e4SLinus Torvalds * Alexey Kuznetsov SMP races, threading, cleanup. 251da177e4SLinus Torvalds * Patrick McHardy LRU queue of frag heads for evictor. 261da177e4SLinus Torvalds * Mitsuru KANDA @USAGI Register inet6_protocol{}. 271da177e4SLinus Torvalds * David Stevens and 281da177e4SLinus Torvalds * YOSHIFUJI,H. @USAGI Always remove fragment header to 291da177e4SLinus Torvalds * calculate ICV correctly. 301da177e4SLinus Torvalds */ 311da177e4SLinus Torvalds #include <linux/errno.h> 321da177e4SLinus Torvalds #include <linux/types.h> 331da177e4SLinus Torvalds #include <linux/string.h> 341da177e4SLinus Torvalds #include <linux/socket.h> 351da177e4SLinus Torvalds #include <linux/sockios.h> 361da177e4SLinus Torvalds #include <linux/jiffies.h> 371da177e4SLinus Torvalds #include <linux/net.h> 381da177e4SLinus Torvalds #include <linux/list.h> 391da177e4SLinus Torvalds #include <linux/netdevice.h> 401da177e4SLinus Torvalds #include <linux/in6.h> 411da177e4SLinus Torvalds #include <linux/ipv6.h> 421da177e4SLinus Torvalds #include <linux/icmpv6.h> 431da177e4SLinus Torvalds #include <linux/random.h> 441da177e4SLinus Torvalds #include <linux/jhash.h> 45f61944efSHerbert Xu #include <linux/skbuff.h> 461da177e4SLinus Torvalds 471da177e4SLinus Torvalds #include <net/sock.h> 481da177e4SLinus Torvalds #include <net/snmp.h> 491da177e4SLinus Torvalds 501da177e4SLinus Torvalds #include <net/ipv6.h> 51a11d206dSYOSHIFUJI Hideaki #include <net/ip6_route.h> 521da177e4SLinus Torvalds #include <net/protocol.h> 531da177e4SLinus Torvalds #include <net/transp_v6.h> 541da177e4SLinus Torvalds #include <net/rawv6.h> 551da177e4SLinus Torvalds #include <net/ndisc.h> 561da177e4SLinus Torvalds #include <net/addrconf.h> 575ab11c98SPavel Emelyanov #include <net/inet_frag.h> 581da177e4SLinus Torvalds 591da177e4SLinus Torvalds struct ip6frag_skb_cb 601da177e4SLinus Torvalds { 611da177e4SLinus Torvalds struct inet6_skb_parm h; 621da177e4SLinus Torvalds int offset; 631da177e4SLinus Torvalds }; 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds #define FRAG6_CB(skb) ((struct ip6frag_skb_cb*)((skb)->cb)) 661da177e4SLinus Torvalds 671da177e4SLinus Torvalds 681da177e4SLinus Torvalds /* 691da177e4SLinus Torvalds * Equivalent of ipv4 struct ipq 701da177e4SLinus Torvalds */ 711da177e4SLinus Torvalds 721da177e4SLinus Torvalds struct frag_queue 731da177e4SLinus Torvalds { 745ab11c98SPavel Emelyanov struct inet_frag_queue q; 751da177e4SLinus Torvalds 76e69a4adcSAl Viro __be32 id; /* fragment id */ 771da177e4SLinus Torvalds struct in6_addr saddr; 781da177e4SLinus Torvalds struct in6_addr daddr; 791da177e4SLinus Torvalds 801da177e4SLinus Torvalds int iif; 811da177e4SLinus Torvalds unsigned int csum; 821da177e4SLinus Torvalds __u16 nhoffset; 831da177e4SLinus Torvalds }; 841da177e4SLinus Torvalds 8504128f23SPavel Emelyanov struct inet_frags_ctl ip6_frags_ctl __read_mostly = { 8604128f23SPavel Emelyanov .high_thresh = 256 * 1024, 8704128f23SPavel Emelyanov .low_thresh = 192 * 1024, 8804128f23SPavel Emelyanov .timeout = IPV6_FRAG_TIMEOUT, 8904128f23SPavel Emelyanov .secret_interval = 10 * 60 * HZ, 9004128f23SPavel Emelyanov }; 9104128f23SPavel Emelyanov 927eb95156SPavel Emelyanov static struct inet_frags ip6_frags; 931da177e4SLinus Torvalds 947eb95156SPavel Emelyanov int ip6_frag_nqueues(void) 957eb95156SPavel Emelyanov { 967eb95156SPavel Emelyanov return ip6_frags.nqueues; 977eb95156SPavel Emelyanov } 981da177e4SLinus Torvalds 997eb95156SPavel Emelyanov int ip6_frag_mem(void) 1007eb95156SPavel Emelyanov { 1017eb95156SPavel Emelyanov return atomic_read(&ip6_frags.mem); 1027eb95156SPavel Emelyanov } 1031da177e4SLinus Torvalds 104f61944efSHerbert Xu static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *prev, 105f61944efSHerbert Xu struct net_device *dev); 106f61944efSHerbert Xu 107f6596f9dSZach Brown /* 108f6596f9dSZach Brown * callers should be careful not to use the hash value outside the ipfrag_lock 109f6596f9dSZach Brown * as doing so could race with ipfrag_hash_rnd being recalculated. 110f6596f9dSZach Brown */ 111e69a4adcSAl Viro static unsigned int ip6qhashfn(__be32 id, struct in6_addr *saddr, 1121da177e4SLinus Torvalds struct in6_addr *daddr) 1131da177e4SLinus Torvalds { 1141da177e4SLinus Torvalds u32 a, b, c; 1151da177e4SLinus Torvalds 116e69a4adcSAl Viro a = (__force u32)saddr->s6_addr32[0]; 117e69a4adcSAl Viro b = (__force u32)saddr->s6_addr32[1]; 118e69a4adcSAl Viro c = (__force u32)saddr->s6_addr32[2]; 1191da177e4SLinus Torvalds 1201da177e4SLinus Torvalds a += JHASH_GOLDEN_RATIO; 1211da177e4SLinus Torvalds b += JHASH_GOLDEN_RATIO; 1227eb95156SPavel Emelyanov c += ip6_frags.rnd; 1231da177e4SLinus Torvalds __jhash_mix(a, b, c); 1241da177e4SLinus Torvalds 125e69a4adcSAl Viro a += (__force u32)saddr->s6_addr32[3]; 126e69a4adcSAl Viro b += (__force u32)daddr->s6_addr32[0]; 127e69a4adcSAl Viro c += (__force u32)daddr->s6_addr32[1]; 1281da177e4SLinus Torvalds __jhash_mix(a, b, c); 1291da177e4SLinus Torvalds 130e69a4adcSAl Viro a += (__force u32)daddr->s6_addr32[2]; 131e69a4adcSAl Viro b += (__force u32)daddr->s6_addr32[3]; 132e69a4adcSAl Viro c += (__force u32)id; 1331da177e4SLinus Torvalds __jhash_mix(a, b, c); 1341da177e4SLinus Torvalds 1357eb95156SPavel Emelyanov return c & (INETFRAGS_HASHSZ - 1); 1361da177e4SLinus Torvalds } 1371da177e4SLinus Torvalds 138321a3a99SPavel Emelyanov static unsigned int ip6_hashfn(struct inet_frag_queue *q) 1391da177e4SLinus Torvalds { 140321a3a99SPavel Emelyanov struct frag_queue *fq; 1411da177e4SLinus Torvalds 142321a3a99SPavel Emelyanov fq = container_of(q, struct frag_queue, q); 143321a3a99SPavel Emelyanov return ip6qhashfn(fq->id, &fq->saddr, &fq->daddr); 1441da177e4SLinus Torvalds } 1451da177e4SLinus Torvalds 1461da177e4SLinus Torvalds /* Memory Tracking Functions. */ 1471da177e4SLinus Torvalds static inline void frag_kfree_skb(struct sk_buff *skb, int *work) 1481da177e4SLinus Torvalds { 1491da177e4SLinus Torvalds if (work) 1501da177e4SLinus Torvalds *work -= skb->truesize; 1517eb95156SPavel Emelyanov atomic_sub(skb->truesize, &ip6_frags.mem); 1521da177e4SLinus Torvalds kfree_skb(skb); 1531da177e4SLinus Torvalds } 1541da177e4SLinus Torvalds 1551e4b8287SPavel Emelyanov static void ip6_frag_free(struct inet_frag_queue *fq) 1561da177e4SLinus Torvalds { 1571e4b8287SPavel Emelyanov kfree(container_of(fq, struct frag_queue, q)); 1581da177e4SLinus Torvalds } 1591da177e4SLinus Torvalds 1601da177e4SLinus Torvalds static inline struct frag_queue *frag_alloc_queue(void) 1611da177e4SLinus Torvalds { 16278c784c4SIngo Oeser struct frag_queue *fq = kzalloc(sizeof(struct frag_queue), GFP_ATOMIC); 1631da177e4SLinus Torvalds 1641da177e4SLinus Torvalds if(!fq) 1651da177e4SLinus Torvalds return NULL; 1667eb95156SPavel Emelyanov atomic_add(sizeof(struct frag_queue), &ip6_frags.mem); 1671da177e4SLinus Torvalds return fq; 1681da177e4SLinus Torvalds } 1691da177e4SLinus Torvalds 1701da177e4SLinus Torvalds /* Destruction primitives. */ 1711da177e4SLinus Torvalds 1721da177e4SLinus Torvalds static __inline__ void fq_put(struct frag_queue *fq, int *work) 1731da177e4SLinus Torvalds { 1745ab11c98SPavel Emelyanov if (atomic_dec_and_test(&fq->q.refcnt)) 1751e4b8287SPavel Emelyanov inet_frag_destroy(&fq->q, &ip6_frags, work); 1761da177e4SLinus Torvalds } 1771da177e4SLinus Torvalds 1781da177e4SLinus Torvalds /* Kill fq entry. It is not destroyed immediately, 1791da177e4SLinus Torvalds * because caller (and someone more) holds reference count. 1801da177e4SLinus Torvalds */ 1811da177e4SLinus Torvalds static __inline__ void fq_kill(struct frag_queue *fq) 1821da177e4SLinus Torvalds { 183277e650dSPavel Emelyanov inet_frag_kill(&fq->q, &ip6_frags); 1841da177e4SLinus Torvalds } 1851da177e4SLinus Torvalds 186a11d206dSYOSHIFUJI Hideaki static void ip6_evictor(struct inet6_dev *idev) 1871da177e4SLinus Torvalds { 1881da177e4SLinus Torvalds struct frag_queue *fq; 1891da177e4SLinus Torvalds struct list_head *tmp; 1901da177e4SLinus Torvalds int work; 1911da177e4SLinus Torvalds 19204128f23SPavel Emelyanov work = atomic_read(&ip6_frags.mem) - ip6_frags_ctl.low_thresh; 1931da177e4SLinus Torvalds if (work <= 0) 1941da177e4SLinus Torvalds return; 1951da177e4SLinus Torvalds 1961da177e4SLinus Torvalds while(work > 0) { 1977eb95156SPavel Emelyanov read_lock(&ip6_frags.lock); 1987eb95156SPavel Emelyanov if (list_empty(&ip6_frags.lru_list)) { 1997eb95156SPavel Emelyanov read_unlock(&ip6_frags.lock); 2001da177e4SLinus Torvalds return; 2011da177e4SLinus Torvalds } 2027eb95156SPavel Emelyanov tmp = ip6_frags.lru_list.next; 2035ab11c98SPavel Emelyanov fq = list_entry(tmp, struct frag_queue, q.lru_list); 2045ab11c98SPavel Emelyanov atomic_inc(&fq->q.refcnt); 2057eb95156SPavel Emelyanov read_unlock(&ip6_frags.lock); 2061da177e4SLinus Torvalds 2075ab11c98SPavel Emelyanov spin_lock(&fq->q.lock); 2085ab11c98SPavel Emelyanov if (!(fq->q.last_in&COMPLETE)) 2091da177e4SLinus Torvalds fq_kill(fq); 2105ab11c98SPavel Emelyanov spin_unlock(&fq->q.lock); 2111da177e4SLinus Torvalds 2121da177e4SLinus Torvalds fq_put(fq, &work); 213a11d206dSYOSHIFUJI Hideaki IP6_INC_STATS_BH(idev, IPSTATS_MIB_REASMFAILS); 2141da177e4SLinus Torvalds } 2151da177e4SLinus Torvalds } 2161da177e4SLinus Torvalds 2171da177e4SLinus Torvalds static void ip6_frag_expire(unsigned long data) 2181da177e4SLinus Torvalds { 2191da177e4SLinus Torvalds struct frag_queue *fq = (struct frag_queue *) data; 220a11d206dSYOSHIFUJI Hideaki struct net_device *dev = NULL; 2211da177e4SLinus Torvalds 2225ab11c98SPavel Emelyanov spin_lock(&fq->q.lock); 2231da177e4SLinus Torvalds 2245ab11c98SPavel Emelyanov if (fq->q.last_in & COMPLETE) 2251da177e4SLinus Torvalds goto out; 2261da177e4SLinus Torvalds 2271da177e4SLinus Torvalds fq_kill(fq); 2281da177e4SLinus Torvalds 229881d966bSEric W. Biederman dev = dev_get_by_index(&init_net, fq->iif); 230a11d206dSYOSHIFUJI Hideaki if (!dev) 231a11d206dSYOSHIFUJI Hideaki goto out; 232a11d206dSYOSHIFUJI Hideaki 233a11d206dSYOSHIFUJI Hideaki rcu_read_lock(); 234a11d206dSYOSHIFUJI Hideaki IP6_INC_STATS_BH(__in6_dev_get(dev), IPSTATS_MIB_REASMTIMEOUT); 235a11d206dSYOSHIFUJI Hideaki IP6_INC_STATS_BH(__in6_dev_get(dev), IPSTATS_MIB_REASMFAILS); 236a11d206dSYOSHIFUJI Hideaki rcu_read_unlock(); 2371da177e4SLinus Torvalds 23878c784c4SIngo Oeser /* Don't send error if the first segment did not arrive. */ 2395ab11c98SPavel Emelyanov if (!(fq->q.last_in&FIRST_IN) || !fq->q.fragments) 24078c784c4SIngo Oeser goto out; 24178c784c4SIngo Oeser 2421da177e4SLinus Torvalds /* 2431da177e4SLinus Torvalds But use as source device on which LAST ARRIVED 2441da177e4SLinus Torvalds segment was received. And do not use fq->dev 2451da177e4SLinus Torvalds pointer directly, device might already disappeared. 2461da177e4SLinus Torvalds */ 2475ab11c98SPavel Emelyanov fq->q.fragments->dev = dev; 2485ab11c98SPavel Emelyanov icmpv6_send(fq->q.fragments, ICMPV6_TIME_EXCEED, ICMPV6_EXC_FRAGTIME, 0, dev); 2491da177e4SLinus Torvalds out: 250a11d206dSYOSHIFUJI Hideaki if (dev) 251a11d206dSYOSHIFUJI Hideaki dev_put(dev); 2525ab11c98SPavel Emelyanov spin_unlock(&fq->q.lock); 2531da177e4SLinus Torvalds fq_put(fq, NULL); 2541da177e4SLinus Torvalds } 2551da177e4SLinus Torvalds 2561da177e4SLinus Torvalds /* Creation primitives. */ 2571da177e4SLinus Torvalds 2581da177e4SLinus Torvalds 259f6596f9dSZach Brown static struct frag_queue *ip6_frag_intern(struct frag_queue *fq_in) 2601da177e4SLinus Torvalds { 2611da177e4SLinus Torvalds struct frag_queue *fq; 262f6596f9dSZach Brown unsigned int hash; 263e7c8a41eSYasuyuki Kozakai #ifdef CONFIG_SMP 264e7c8a41eSYasuyuki Kozakai struct hlist_node *n; 265e7c8a41eSYasuyuki Kozakai #endif 2661da177e4SLinus Torvalds 2677eb95156SPavel Emelyanov write_lock(&ip6_frags.lock); 268f6596f9dSZach Brown hash = ip6qhashfn(fq_in->id, &fq_in->saddr, &fq_in->daddr); 2691da177e4SLinus Torvalds #ifdef CONFIG_SMP 2707eb95156SPavel Emelyanov hlist_for_each_entry(fq, n, &ip6_frags.hash[hash], q.list) { 2711da177e4SLinus Torvalds if (fq->id == fq_in->id && 2721da177e4SLinus Torvalds ipv6_addr_equal(&fq_in->saddr, &fq->saddr) && 2731da177e4SLinus Torvalds ipv6_addr_equal(&fq_in->daddr, &fq->daddr)) { 2745ab11c98SPavel Emelyanov atomic_inc(&fq->q.refcnt); 2757eb95156SPavel Emelyanov write_unlock(&ip6_frags.lock); 2765ab11c98SPavel Emelyanov fq_in->q.last_in |= COMPLETE; 2771da177e4SLinus Torvalds fq_put(fq_in, NULL); 2781da177e4SLinus Torvalds return fq; 2791da177e4SLinus Torvalds } 2801da177e4SLinus Torvalds } 2811da177e4SLinus Torvalds #endif 2821da177e4SLinus Torvalds fq = fq_in; 2831da177e4SLinus Torvalds 28404128f23SPavel Emelyanov if (!mod_timer(&fq->q.timer, jiffies + ip6_frags_ctl.timeout)) 2855ab11c98SPavel Emelyanov atomic_inc(&fq->q.refcnt); 2861da177e4SLinus Torvalds 2875ab11c98SPavel Emelyanov atomic_inc(&fq->q.refcnt); 2887eb95156SPavel Emelyanov hlist_add_head(&fq->q.list, &ip6_frags.hash[hash]); 2895ab11c98SPavel Emelyanov INIT_LIST_HEAD(&fq->q.lru_list); 2907eb95156SPavel Emelyanov list_add_tail(&fq->q.lru_list, &ip6_frags.lru_list); 2917eb95156SPavel Emelyanov ip6_frags.nqueues++; 2927eb95156SPavel Emelyanov write_unlock(&ip6_frags.lock); 2931da177e4SLinus Torvalds return fq; 2941da177e4SLinus Torvalds } 2951da177e4SLinus Torvalds 2961da177e4SLinus Torvalds 2971da177e4SLinus Torvalds static struct frag_queue * 298e69a4adcSAl Viro ip6_frag_create(__be32 id, struct in6_addr *src, struct in6_addr *dst, 299a11d206dSYOSHIFUJI Hideaki struct inet6_dev *idev) 3001da177e4SLinus Torvalds { 3011da177e4SLinus Torvalds struct frag_queue *fq; 3021da177e4SLinus Torvalds 3031da177e4SLinus Torvalds if ((fq = frag_alloc_queue()) == NULL) 3041da177e4SLinus Torvalds goto oom; 3051da177e4SLinus Torvalds 3061da177e4SLinus Torvalds fq->id = id; 3071da177e4SLinus Torvalds ipv6_addr_copy(&fq->saddr, src); 3081da177e4SLinus Torvalds ipv6_addr_copy(&fq->daddr, dst); 3091da177e4SLinus Torvalds 3105ab11c98SPavel Emelyanov init_timer(&fq->q.timer); 3115ab11c98SPavel Emelyanov fq->q.timer.function = ip6_frag_expire; 3125ab11c98SPavel Emelyanov fq->q.timer.data = (long) fq; 3135ab11c98SPavel Emelyanov spin_lock_init(&fq->q.lock); 3145ab11c98SPavel Emelyanov atomic_set(&fq->q.refcnt, 1); 3151da177e4SLinus Torvalds 316f6596f9dSZach Brown return ip6_frag_intern(fq); 3171da177e4SLinus Torvalds 3181da177e4SLinus Torvalds oom: 319a11d206dSYOSHIFUJI Hideaki IP6_INC_STATS_BH(idev, IPSTATS_MIB_REASMFAILS); 3201da177e4SLinus Torvalds return NULL; 3211da177e4SLinus Torvalds } 3221da177e4SLinus Torvalds 3231da177e4SLinus Torvalds static __inline__ struct frag_queue * 324e69a4adcSAl Viro fq_find(__be32 id, struct in6_addr *src, struct in6_addr *dst, 325a11d206dSYOSHIFUJI Hideaki struct inet6_dev *idev) 3261da177e4SLinus Torvalds { 3271da177e4SLinus Torvalds struct frag_queue *fq; 328e7c8a41eSYasuyuki Kozakai struct hlist_node *n; 329f6596f9dSZach Brown unsigned int hash; 3301da177e4SLinus Torvalds 3317eb95156SPavel Emelyanov read_lock(&ip6_frags.lock); 332f6596f9dSZach Brown hash = ip6qhashfn(id, src, dst); 3337eb95156SPavel Emelyanov hlist_for_each_entry(fq, n, &ip6_frags.hash[hash], q.list) { 3341da177e4SLinus Torvalds if (fq->id == id && 3351da177e4SLinus Torvalds ipv6_addr_equal(src, &fq->saddr) && 3361da177e4SLinus Torvalds ipv6_addr_equal(dst, &fq->daddr)) { 3375ab11c98SPavel Emelyanov atomic_inc(&fq->q.refcnt); 3387eb95156SPavel Emelyanov read_unlock(&ip6_frags.lock); 3391da177e4SLinus Torvalds return fq; 3401da177e4SLinus Torvalds } 3411da177e4SLinus Torvalds } 3427eb95156SPavel Emelyanov read_unlock(&ip6_frags.lock); 3431da177e4SLinus Torvalds 344a11d206dSYOSHIFUJI Hideaki return ip6_frag_create(id, src, dst, idev); 3451da177e4SLinus Torvalds } 3461da177e4SLinus Torvalds 3471da177e4SLinus Torvalds 348f61944efSHerbert Xu static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb, 3491da177e4SLinus Torvalds struct frag_hdr *fhdr, int nhoff) 3501da177e4SLinus Torvalds { 3511da177e4SLinus Torvalds struct sk_buff *prev, *next; 352f61944efSHerbert Xu struct net_device *dev; 3531da177e4SLinus Torvalds int offset, end; 3541da177e4SLinus Torvalds 3555ab11c98SPavel Emelyanov if (fq->q.last_in & COMPLETE) 3561da177e4SLinus Torvalds goto err; 3571da177e4SLinus Torvalds 3581da177e4SLinus Torvalds offset = ntohs(fhdr->frag_off) & ~0x7; 3590660e03fSArnaldo Carvalho de Melo end = offset + (ntohs(ipv6_hdr(skb)->payload_len) - 3600660e03fSArnaldo Carvalho de Melo ((u8 *)(fhdr + 1) - (u8 *)(ipv6_hdr(skb) + 1))); 3611da177e4SLinus Torvalds 3621da177e4SLinus Torvalds if ((unsigned int)end > IPV6_MAXPLEN) { 363a11d206dSYOSHIFUJI Hideaki IP6_INC_STATS_BH(ip6_dst_idev(skb->dst), 364a11d206dSYOSHIFUJI Hideaki IPSTATS_MIB_INHDRERRORS); 365d56f90a7SArnaldo Carvalho de Melo icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, 366d56f90a7SArnaldo Carvalho de Melo ((u8 *)&fhdr->frag_off - 367d56f90a7SArnaldo Carvalho de Melo skb_network_header(skb))); 368f61944efSHerbert Xu return -1; 3691da177e4SLinus Torvalds } 3701da177e4SLinus Torvalds 371d56f90a7SArnaldo Carvalho de Melo if (skb->ip_summed == CHECKSUM_COMPLETE) { 372d56f90a7SArnaldo Carvalho de Melo const unsigned char *nh = skb_network_header(skb); 3731da177e4SLinus Torvalds skb->csum = csum_sub(skb->csum, 374d56f90a7SArnaldo Carvalho de Melo csum_partial(nh, (u8 *)(fhdr + 1) - nh, 375d56f90a7SArnaldo Carvalho de Melo 0)); 376d56f90a7SArnaldo Carvalho de Melo } 3771da177e4SLinus Torvalds 3781da177e4SLinus Torvalds /* Is this the final fragment? */ 3791da177e4SLinus Torvalds if (!(fhdr->frag_off & htons(IP6_MF))) { 3801da177e4SLinus Torvalds /* If we already have some bits beyond end 3811da177e4SLinus Torvalds * or have different end, the segment is corrupted. 3821da177e4SLinus Torvalds */ 3835ab11c98SPavel Emelyanov if (end < fq->q.len || 3845ab11c98SPavel Emelyanov ((fq->q.last_in & LAST_IN) && end != fq->q.len)) 3851da177e4SLinus Torvalds goto err; 3865ab11c98SPavel Emelyanov fq->q.last_in |= LAST_IN; 3875ab11c98SPavel Emelyanov fq->q.len = end; 3881da177e4SLinus Torvalds } else { 3891da177e4SLinus Torvalds /* Check if the fragment is rounded to 8 bytes. 3901da177e4SLinus Torvalds * Required by the RFC. 3911da177e4SLinus Torvalds */ 3921da177e4SLinus Torvalds if (end & 0x7) { 3931da177e4SLinus Torvalds /* RFC2460 says always send parameter problem in 3941da177e4SLinus Torvalds * this case. -DaveM 3951da177e4SLinus Torvalds */ 396a11d206dSYOSHIFUJI Hideaki IP6_INC_STATS_BH(ip6_dst_idev(skb->dst), 397a11d206dSYOSHIFUJI Hideaki IPSTATS_MIB_INHDRERRORS); 3981da177e4SLinus Torvalds icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, 3991da177e4SLinus Torvalds offsetof(struct ipv6hdr, payload_len)); 400f61944efSHerbert Xu return -1; 4011da177e4SLinus Torvalds } 4025ab11c98SPavel Emelyanov if (end > fq->q.len) { 4031da177e4SLinus Torvalds /* Some bits beyond end -> corruption. */ 4045ab11c98SPavel Emelyanov if (fq->q.last_in & LAST_IN) 4051da177e4SLinus Torvalds goto err; 4065ab11c98SPavel Emelyanov fq->q.len = end; 4071da177e4SLinus Torvalds } 4081da177e4SLinus Torvalds } 4091da177e4SLinus Torvalds 4101da177e4SLinus Torvalds if (end == offset) 4111da177e4SLinus Torvalds goto err; 4121da177e4SLinus Torvalds 4131da177e4SLinus Torvalds /* Point into the IP datagram 'data' part. */ 4141da177e4SLinus Torvalds if (!pskb_pull(skb, (u8 *) (fhdr + 1) - skb->data)) 4151da177e4SLinus Torvalds goto err; 41642ca89c1SStephen Hemminger 41742ca89c1SStephen Hemminger if (pskb_trim_rcsum(skb, end - offset)) 4181da177e4SLinus Torvalds goto err; 4191da177e4SLinus Torvalds 4201da177e4SLinus Torvalds /* Find out which fragments are in front and at the back of us 4211da177e4SLinus Torvalds * in the chain of fragments so far. We must know where to put 4221da177e4SLinus Torvalds * this fragment, right? 4231da177e4SLinus Torvalds */ 4241da177e4SLinus Torvalds prev = NULL; 4255ab11c98SPavel Emelyanov for(next = fq->q.fragments; next != NULL; next = next->next) { 4261da177e4SLinus Torvalds if (FRAG6_CB(next)->offset >= offset) 4271da177e4SLinus Torvalds break; /* bingo! */ 4281da177e4SLinus Torvalds prev = next; 4291da177e4SLinus Torvalds } 4301da177e4SLinus Torvalds 4311da177e4SLinus Torvalds /* We found where to put this one. Check for overlap with 4321da177e4SLinus Torvalds * preceding fragment, and, if needed, align things so that 4331da177e4SLinus Torvalds * any overlaps are eliminated. 4341da177e4SLinus Torvalds */ 4351da177e4SLinus Torvalds if (prev) { 4361da177e4SLinus Torvalds int i = (FRAG6_CB(prev)->offset + prev->len) - offset; 4371da177e4SLinus Torvalds 4381da177e4SLinus Torvalds if (i > 0) { 4391da177e4SLinus Torvalds offset += i; 4401da177e4SLinus Torvalds if (end <= offset) 4411da177e4SLinus Torvalds goto err; 4421da177e4SLinus Torvalds if (!pskb_pull(skb, i)) 4431da177e4SLinus Torvalds goto err; 4441da177e4SLinus Torvalds if (skb->ip_summed != CHECKSUM_UNNECESSARY) 4451da177e4SLinus Torvalds skb->ip_summed = CHECKSUM_NONE; 4461da177e4SLinus Torvalds } 4471da177e4SLinus Torvalds } 4481da177e4SLinus Torvalds 4491da177e4SLinus Torvalds /* Look for overlap with succeeding segments. 4501da177e4SLinus Torvalds * If we can merge fragments, do it. 4511da177e4SLinus Torvalds */ 4521da177e4SLinus Torvalds while (next && FRAG6_CB(next)->offset < end) { 4531da177e4SLinus Torvalds int i = end - FRAG6_CB(next)->offset; /* overlap is 'i' bytes */ 4541da177e4SLinus Torvalds 4551da177e4SLinus Torvalds if (i < next->len) { 4561da177e4SLinus Torvalds /* Eat head of the next overlapped fragment 4571da177e4SLinus Torvalds * and leave the loop. The next ones cannot overlap. 4581da177e4SLinus Torvalds */ 4591da177e4SLinus Torvalds if (!pskb_pull(next, i)) 4601da177e4SLinus Torvalds goto err; 4611da177e4SLinus Torvalds FRAG6_CB(next)->offset += i; /* next fragment */ 4625ab11c98SPavel Emelyanov fq->q.meat -= i; 4631da177e4SLinus Torvalds if (next->ip_summed != CHECKSUM_UNNECESSARY) 4641da177e4SLinus Torvalds next->ip_summed = CHECKSUM_NONE; 4651da177e4SLinus Torvalds break; 4661da177e4SLinus Torvalds } else { 4671da177e4SLinus Torvalds struct sk_buff *free_it = next; 4681da177e4SLinus Torvalds 4691da177e4SLinus Torvalds /* Old fragment is completely overridden with 4701da177e4SLinus Torvalds * new one drop it. 4711da177e4SLinus Torvalds */ 4721da177e4SLinus Torvalds next = next->next; 4731da177e4SLinus Torvalds 4741da177e4SLinus Torvalds if (prev) 4751da177e4SLinus Torvalds prev->next = next; 4761da177e4SLinus Torvalds else 4775ab11c98SPavel Emelyanov fq->q.fragments = next; 4781da177e4SLinus Torvalds 4795ab11c98SPavel Emelyanov fq->q.meat -= free_it->len; 4801da177e4SLinus Torvalds frag_kfree_skb(free_it, NULL); 4811da177e4SLinus Torvalds } 4821da177e4SLinus Torvalds } 4831da177e4SLinus Torvalds 4841da177e4SLinus Torvalds FRAG6_CB(skb)->offset = offset; 4851da177e4SLinus Torvalds 4861da177e4SLinus Torvalds /* Insert this fragment in the chain of fragments. */ 4871da177e4SLinus Torvalds skb->next = next; 4881da177e4SLinus Torvalds if (prev) 4891da177e4SLinus Torvalds prev->next = skb; 4901da177e4SLinus Torvalds else 4915ab11c98SPavel Emelyanov fq->q.fragments = skb; 4921da177e4SLinus Torvalds 493f61944efSHerbert Xu dev = skb->dev; 494f61944efSHerbert Xu if (dev) { 495f61944efSHerbert Xu fq->iif = dev->ifindex; 4961da177e4SLinus Torvalds skb->dev = NULL; 497f61944efSHerbert Xu } 4985ab11c98SPavel Emelyanov fq->q.stamp = skb->tstamp; 4995ab11c98SPavel Emelyanov fq->q.meat += skb->len; 5007eb95156SPavel Emelyanov atomic_add(skb->truesize, &ip6_frags.mem); 5011da177e4SLinus Torvalds 5021da177e4SLinus Torvalds /* The first fragment. 5031da177e4SLinus Torvalds * nhoffset is obtained from the first fragment, of course. 5041da177e4SLinus Torvalds */ 5051da177e4SLinus Torvalds if (offset == 0) { 5061da177e4SLinus Torvalds fq->nhoffset = nhoff; 5075ab11c98SPavel Emelyanov fq->q.last_in |= FIRST_IN; 5081da177e4SLinus Torvalds } 509f61944efSHerbert Xu 5105ab11c98SPavel Emelyanov if (fq->q.last_in == (FIRST_IN | LAST_IN) && fq->q.meat == fq->q.len) 511f61944efSHerbert Xu return ip6_frag_reasm(fq, prev, dev); 512f61944efSHerbert Xu 5137eb95156SPavel Emelyanov write_lock(&ip6_frags.lock); 5147eb95156SPavel Emelyanov list_move_tail(&fq->q.lru_list, &ip6_frags.lru_list); 5157eb95156SPavel Emelyanov write_unlock(&ip6_frags.lock); 516f61944efSHerbert Xu return -1; 5171da177e4SLinus Torvalds 5181da177e4SLinus Torvalds err: 519a11d206dSYOSHIFUJI Hideaki IP6_INC_STATS(ip6_dst_idev(skb->dst), IPSTATS_MIB_REASMFAILS); 5201da177e4SLinus Torvalds kfree_skb(skb); 521f61944efSHerbert Xu return -1; 5221da177e4SLinus Torvalds } 5231da177e4SLinus Torvalds 5241da177e4SLinus Torvalds /* 5251da177e4SLinus Torvalds * Check if this packet is complete. 5261da177e4SLinus Torvalds * Returns NULL on failure by any reason, and pointer 5271da177e4SLinus Torvalds * to current nexthdr field in reassembled frame. 5281da177e4SLinus Torvalds * 5291da177e4SLinus Torvalds * It is called with locked fq, and caller must check that 5301da177e4SLinus Torvalds * queue is eligible for reassembly i.e. it is not COMPLETE, 5311da177e4SLinus Torvalds * the last and the first frames arrived and all the bits are here. 5321da177e4SLinus Torvalds */ 533f61944efSHerbert Xu static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *prev, 5341da177e4SLinus Torvalds struct net_device *dev) 5351da177e4SLinus Torvalds { 5365ab11c98SPavel Emelyanov struct sk_buff *fp, *head = fq->q.fragments; 5371da177e4SLinus Torvalds int payload_len; 5381da177e4SLinus Torvalds unsigned int nhoff; 5391da177e4SLinus Torvalds 5401da177e4SLinus Torvalds fq_kill(fq); 5411da177e4SLinus Torvalds 542f61944efSHerbert Xu /* Make the one we just received the head. */ 543f61944efSHerbert Xu if (prev) { 544f61944efSHerbert Xu head = prev->next; 545f61944efSHerbert Xu fp = skb_clone(head, GFP_ATOMIC); 546f61944efSHerbert Xu 547f61944efSHerbert Xu if (!fp) 548f61944efSHerbert Xu goto out_oom; 549f61944efSHerbert Xu 550f61944efSHerbert Xu fp->next = head->next; 551f61944efSHerbert Xu prev->next = fp; 552f61944efSHerbert Xu 5535ab11c98SPavel Emelyanov skb_morph(head, fq->q.fragments); 5545ab11c98SPavel Emelyanov head->next = fq->q.fragments->next; 555f61944efSHerbert Xu 5565ab11c98SPavel Emelyanov kfree_skb(fq->q.fragments); 5575ab11c98SPavel Emelyanov fq->q.fragments = head; 558f61944efSHerbert Xu } 559f61944efSHerbert Xu 5601da177e4SLinus Torvalds BUG_TRAP(head != NULL); 5611da177e4SLinus Torvalds BUG_TRAP(FRAG6_CB(head)->offset == 0); 5621da177e4SLinus Torvalds 5631da177e4SLinus Torvalds /* Unfragmented part is taken from the first segment. */ 564d56f90a7SArnaldo Carvalho de Melo payload_len = ((head->data - skb_network_header(head)) - 5655ab11c98SPavel Emelyanov sizeof(struct ipv6hdr) + fq->q.len - 566d56f90a7SArnaldo Carvalho de Melo sizeof(struct frag_hdr)); 5671da177e4SLinus Torvalds if (payload_len > IPV6_MAXPLEN) 5681da177e4SLinus Torvalds goto out_oversize; 5691da177e4SLinus Torvalds 5701da177e4SLinus Torvalds /* Head of list must not be cloned. */ 5711da177e4SLinus Torvalds if (skb_cloned(head) && pskb_expand_head(head, 0, 0, GFP_ATOMIC)) 5721da177e4SLinus Torvalds goto out_oom; 5731da177e4SLinus Torvalds 5741da177e4SLinus Torvalds /* If the first fragment is fragmented itself, we split 5751da177e4SLinus Torvalds * it to two chunks: the first with data and paged part 5761da177e4SLinus Torvalds * and the second, holding only fragments. */ 5771da177e4SLinus Torvalds if (skb_shinfo(head)->frag_list) { 5781da177e4SLinus Torvalds struct sk_buff *clone; 5791da177e4SLinus Torvalds int i, plen = 0; 5801da177e4SLinus Torvalds 5811da177e4SLinus Torvalds if ((clone = alloc_skb(0, GFP_ATOMIC)) == NULL) 5821da177e4SLinus Torvalds goto out_oom; 5831da177e4SLinus Torvalds clone->next = head->next; 5841da177e4SLinus Torvalds head->next = clone; 5851da177e4SLinus Torvalds skb_shinfo(clone)->frag_list = skb_shinfo(head)->frag_list; 5861da177e4SLinus Torvalds skb_shinfo(head)->frag_list = NULL; 5871da177e4SLinus Torvalds for (i=0; i<skb_shinfo(head)->nr_frags; i++) 5881da177e4SLinus Torvalds plen += skb_shinfo(head)->frags[i].size; 5891da177e4SLinus Torvalds clone->len = clone->data_len = head->data_len - plen; 5901da177e4SLinus Torvalds head->data_len -= clone->len; 5911da177e4SLinus Torvalds head->len -= clone->len; 5921da177e4SLinus Torvalds clone->csum = 0; 5931da177e4SLinus Torvalds clone->ip_summed = head->ip_summed; 5947eb95156SPavel Emelyanov atomic_add(clone->truesize, &ip6_frags.mem); 5951da177e4SLinus Torvalds } 5961da177e4SLinus Torvalds 5971da177e4SLinus Torvalds /* We have to remove fragment header from datagram and to relocate 5981da177e4SLinus Torvalds * header in order to calculate ICV correctly. */ 5991da177e4SLinus Torvalds nhoff = fq->nhoffset; 600b0e380b1SArnaldo Carvalho de Melo skb_network_header(head)[nhoff] = skb_transport_header(head)[0]; 6011da177e4SLinus Torvalds memmove(head->head + sizeof(struct frag_hdr), head->head, 6021da177e4SLinus Torvalds (head->data - head->head) - sizeof(struct frag_hdr)); 603b0e380b1SArnaldo Carvalho de Melo head->mac_header += sizeof(struct frag_hdr); 604b0e380b1SArnaldo Carvalho de Melo head->network_header += sizeof(struct frag_hdr); 6051da177e4SLinus Torvalds 6061da177e4SLinus Torvalds skb_shinfo(head)->frag_list = head->next; 607badff6d0SArnaldo Carvalho de Melo skb_reset_transport_header(head); 608d56f90a7SArnaldo Carvalho de Melo skb_push(head, head->data - skb_network_header(head)); 6097eb95156SPavel Emelyanov atomic_sub(head->truesize, &ip6_frags.mem); 6101da177e4SLinus Torvalds 6111da177e4SLinus Torvalds for (fp=head->next; fp; fp = fp->next) { 6121da177e4SLinus Torvalds head->data_len += fp->len; 6131da177e4SLinus Torvalds head->len += fp->len; 6141da177e4SLinus Torvalds if (head->ip_summed != fp->ip_summed) 6151da177e4SLinus Torvalds head->ip_summed = CHECKSUM_NONE; 61684fa7933SPatrick McHardy else if (head->ip_summed == CHECKSUM_COMPLETE) 6171da177e4SLinus Torvalds head->csum = csum_add(head->csum, fp->csum); 6181da177e4SLinus Torvalds head->truesize += fp->truesize; 6197eb95156SPavel Emelyanov atomic_sub(fp->truesize, &ip6_frags.mem); 6201da177e4SLinus Torvalds } 6211da177e4SLinus Torvalds 6221da177e4SLinus Torvalds head->next = NULL; 6231da177e4SLinus Torvalds head->dev = dev; 6245ab11c98SPavel Emelyanov head->tstamp = fq->q.stamp; 6250660e03fSArnaldo Carvalho de Melo ipv6_hdr(head)->payload_len = htons(payload_len); 626951dbc8aSPatrick McHardy IP6CB(head)->nhoff = nhoff; 6271da177e4SLinus Torvalds 6281da177e4SLinus Torvalds /* Yes, and fold redundant checksum back. 8) */ 62984fa7933SPatrick McHardy if (head->ip_summed == CHECKSUM_COMPLETE) 630d56f90a7SArnaldo Carvalho de Melo head->csum = csum_partial(skb_network_header(head), 631cfe1fc77SArnaldo Carvalho de Melo skb_network_header_len(head), 632d56f90a7SArnaldo Carvalho de Melo head->csum); 6331da177e4SLinus Torvalds 634a11d206dSYOSHIFUJI Hideaki rcu_read_lock(); 635a11d206dSYOSHIFUJI Hideaki IP6_INC_STATS_BH(__in6_dev_get(dev), IPSTATS_MIB_REASMOKS); 636a11d206dSYOSHIFUJI Hideaki rcu_read_unlock(); 6375ab11c98SPavel Emelyanov fq->q.fragments = NULL; 6381da177e4SLinus Torvalds return 1; 6391da177e4SLinus Torvalds 6401da177e4SLinus Torvalds out_oversize: 6411da177e4SLinus Torvalds if (net_ratelimit()) 6421da177e4SLinus Torvalds printk(KERN_DEBUG "ip6_frag_reasm: payload len = %d\n", payload_len); 6431da177e4SLinus Torvalds goto out_fail; 6441da177e4SLinus Torvalds out_oom: 6451da177e4SLinus Torvalds if (net_ratelimit()) 6461da177e4SLinus Torvalds printk(KERN_DEBUG "ip6_frag_reasm: no memory for reassembly\n"); 6471da177e4SLinus Torvalds out_fail: 648a11d206dSYOSHIFUJI Hideaki rcu_read_lock(); 649a11d206dSYOSHIFUJI Hideaki IP6_INC_STATS_BH(__in6_dev_get(dev), IPSTATS_MIB_REASMFAILS); 650a11d206dSYOSHIFUJI Hideaki rcu_read_unlock(); 6511da177e4SLinus Torvalds return -1; 6521da177e4SLinus Torvalds } 6531da177e4SLinus Torvalds 654951dbc8aSPatrick McHardy static int ipv6_frag_rcv(struct sk_buff **skbp) 6551da177e4SLinus Torvalds { 6561da177e4SLinus Torvalds struct sk_buff *skb = *skbp; 6571da177e4SLinus Torvalds struct frag_hdr *fhdr; 6581da177e4SLinus Torvalds struct frag_queue *fq; 6590660e03fSArnaldo Carvalho de Melo struct ipv6hdr *hdr = ipv6_hdr(skb); 6601da177e4SLinus Torvalds 661a11d206dSYOSHIFUJI Hideaki IP6_INC_STATS_BH(ip6_dst_idev(skb->dst), IPSTATS_MIB_REASMREQDS); 6621da177e4SLinus Torvalds 6631da177e4SLinus Torvalds /* Jumbo payload inhibits frag. header */ 6641da177e4SLinus Torvalds if (hdr->payload_len==0) { 665a11d206dSYOSHIFUJI Hideaki IP6_INC_STATS(ip6_dst_idev(skb->dst), IPSTATS_MIB_INHDRERRORS); 666cfe1fc77SArnaldo Carvalho de Melo icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, 667cfe1fc77SArnaldo Carvalho de Melo skb_network_header_len(skb)); 6681da177e4SLinus Torvalds return -1; 6691da177e4SLinus Torvalds } 670ea2ae17dSArnaldo Carvalho de Melo if (!pskb_may_pull(skb, (skb_transport_offset(skb) + 671ea2ae17dSArnaldo Carvalho de Melo sizeof(struct frag_hdr)))) { 672a11d206dSYOSHIFUJI Hideaki IP6_INC_STATS(ip6_dst_idev(skb->dst), IPSTATS_MIB_INHDRERRORS); 673cfe1fc77SArnaldo Carvalho de Melo icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, 674cfe1fc77SArnaldo Carvalho de Melo skb_network_header_len(skb)); 6751da177e4SLinus Torvalds return -1; 6761da177e4SLinus Torvalds } 6771da177e4SLinus Torvalds 6780660e03fSArnaldo Carvalho de Melo hdr = ipv6_hdr(skb); 6799c70220bSArnaldo Carvalho de Melo fhdr = (struct frag_hdr *)skb_transport_header(skb); 6801da177e4SLinus Torvalds 6811da177e4SLinus Torvalds if (!(fhdr->frag_off & htons(0xFFF9))) { 6821da177e4SLinus Torvalds /* It is not a fragmented frame */ 683b0e380b1SArnaldo Carvalho de Melo skb->transport_header += sizeof(struct frag_hdr); 684a11d206dSYOSHIFUJI Hideaki IP6_INC_STATS_BH(ip6_dst_idev(skb->dst), IPSTATS_MIB_REASMOKS); 6851da177e4SLinus Torvalds 686d56f90a7SArnaldo Carvalho de Melo IP6CB(skb)->nhoff = (u8 *)fhdr - skb_network_header(skb); 6871da177e4SLinus Torvalds return 1; 6881da177e4SLinus Torvalds } 6891da177e4SLinus Torvalds 69004128f23SPavel Emelyanov if (atomic_read(&ip6_frags.mem) > ip6_frags_ctl.high_thresh) 691a11d206dSYOSHIFUJI Hideaki ip6_evictor(ip6_dst_idev(skb->dst)); 6921da177e4SLinus Torvalds 693a11d206dSYOSHIFUJI Hideaki if ((fq = fq_find(fhdr->identification, &hdr->saddr, &hdr->daddr, 694a11d206dSYOSHIFUJI Hideaki ip6_dst_idev(skb->dst))) != NULL) { 695f61944efSHerbert Xu int ret; 6961da177e4SLinus Torvalds 6975ab11c98SPavel Emelyanov spin_lock(&fq->q.lock); 6981da177e4SLinus Torvalds 699f61944efSHerbert Xu ret = ip6_frag_queue(fq, skb, fhdr, IP6CB(skb)->nhoff); 7001da177e4SLinus Torvalds 7015ab11c98SPavel Emelyanov spin_unlock(&fq->q.lock); 7021da177e4SLinus Torvalds fq_put(fq, NULL); 7031da177e4SLinus Torvalds return ret; 7041da177e4SLinus Torvalds } 7051da177e4SLinus Torvalds 706a11d206dSYOSHIFUJI Hideaki IP6_INC_STATS_BH(ip6_dst_idev(skb->dst), IPSTATS_MIB_REASMFAILS); 7071da177e4SLinus Torvalds kfree_skb(skb); 7081da177e4SLinus Torvalds return -1; 7091da177e4SLinus Torvalds } 7101da177e4SLinus Torvalds 7111da177e4SLinus Torvalds static struct inet6_protocol frag_protocol = 7121da177e4SLinus Torvalds { 7131da177e4SLinus Torvalds .handler = ipv6_frag_rcv, 7141da177e4SLinus Torvalds .flags = INET6_PROTO_NOPOLICY, 7151da177e4SLinus Torvalds }; 7161da177e4SLinus Torvalds 7171da177e4SLinus Torvalds void __init ipv6_frag_init(void) 7181da177e4SLinus Torvalds { 7191da177e4SLinus Torvalds if (inet6_add_protocol(&frag_protocol, IPPROTO_FRAGMENT) < 0) 7201da177e4SLinus Torvalds printk(KERN_ERR "ipv6_frag_init: Could not register protocol\n"); 7211da177e4SLinus Torvalds 72204128f23SPavel Emelyanov ip6_frags.ctl = &ip6_frags_ctl; 723321a3a99SPavel Emelyanov ip6_frags.hashfn = ip6_hashfn; 7241e4b8287SPavel Emelyanov ip6_frags.destructor = ip6_frag_free; 7251e4b8287SPavel Emelyanov ip6_frags.skb_free = NULL; 7261e4b8287SPavel Emelyanov ip6_frags.qsize = sizeof(struct frag_queue); 7277eb95156SPavel Emelyanov inet_frags_init(&ip6_frags); 7281da177e4SLinus Torvalds } 729