blob: ecf340047cdee596e728ceb4363918e920e9c8a8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * IPv6 fragment reassembly
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +09003 * Linux INET6 implementation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 * Authors:
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +09006 * Pedro Roque <roque@di.fc.ul.pt>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
8 * $Id: reassembly.c,v 1.26 2001/03/07 22:00:57 davem Exp $
9 *
10 * Based on: net/ipv4/ip_fragment.c
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version
15 * 2 of the License, or (at your option) any later version.
16 */
17
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +090018/*
19 * Fixes:
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 * Andi Kleen Make it work with multiple hosts.
21 * More RFC compliance.
22 *
23 * Horst von Brand Add missing #include <linux/string.h>
24 * Alexey Kuznetsov SMP races, threading, cleanup.
25 * Patrick McHardy LRU queue of frag heads for evictor.
26 * Mitsuru KANDA @USAGI Register inet6_protocol{}.
27 * David Stevens and
28 * YOSHIFUJI,H. @USAGI Always remove fragment header to
29 * calculate ICV correctly.
30 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/errno.h>
32#include <linux/types.h>
33#include <linux/string.h>
34#include <linux/socket.h>
35#include <linux/sockios.h>
36#include <linux/jiffies.h>
37#include <linux/net.h>
38#include <linux/list.h>
39#include <linux/netdevice.h>
40#include <linux/in6.h>
41#include <linux/ipv6.h>
42#include <linux/icmpv6.h>
43#include <linux/random.h>
44#include <linux/jhash.h>
Herbert Xuf61944e2007-10-15 01:28:47 -070045#include <linux/skbuff.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47#include <net/sock.h>
48#include <net/snmp.h>
49
50#include <net/ipv6.h>
YOSHIFUJI Hideakia11d2062006-11-04 20:11:37 +090051#include <net/ip6_route.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#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>
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -070057#include <net/inet_frag.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Brian Haleyab32ea52006-09-22 14:15:41 -070059int sysctl_ip6frag_high_thresh __read_mostly = 256*1024;
60int sysctl_ip6frag_low_thresh __read_mostly = 192*1024;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Brian Haleyab32ea52006-09-22 14:15:41 -070062int sysctl_ip6frag_time __read_mostly = IPV6_FRAG_TIMEOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64struct ip6frag_skb_cb
65{
66 struct inet6_skb_parm h;
67 int offset;
68};
69
70#define FRAG6_CB(skb) ((struct ip6frag_skb_cb*)((skb)->cb))
71
72
73/*
74 * Equivalent of ipv4 struct ipq
75 */
76
77struct frag_queue
78{
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -070079 struct inet_frag_queue q;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Al Viroe69a4ad2006-11-14 20:56:00 -080081 __be32 id; /* fragment id */
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 struct in6_addr saddr;
83 struct in6_addr daddr;
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 int iif;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 unsigned int csum;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 __u16 nhoffset;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088};
89
Pavel Emelyanov7eb95152007-10-15 02:31:52 -070090static struct inet_frags ip6_frags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Pavel Emelyanov7eb95152007-10-15 02:31:52 -070092int ip6_frag_nqueues(void)
93{
94 return ip6_frags.nqueues;
95}
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Pavel Emelyanov7eb95152007-10-15 02:31:52 -070097int ip6_frag_mem(void)
98{
99 return atomic_read(&ip6_frags.mem);
100}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Herbert Xuf61944e2007-10-15 01:28:47 -0700102static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *prev,
103 struct net_device *dev);
104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105static __inline__ void __fq_unlink(struct frag_queue *fq)
106{
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700107 hlist_del(&fq->q.list);
108 list_del(&fq->q.lru_list);
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700109 ip6_frags.nqueues--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110}
111
112static __inline__ void fq_unlink(struct frag_queue *fq)
113{
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700114 write_lock(&ip6_frags.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 __fq_unlink(fq);
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700116 write_unlock(&ip6_frags.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117}
118
Zach Brownf6596f92006-04-10 16:05:34 -0700119/*
120 * callers should be careful not to use the hash value outside the ipfrag_lock
121 * as doing so could race with ipfrag_hash_rnd being recalculated.
122 */
Al Viroe69a4ad2006-11-14 20:56:00 -0800123static unsigned int ip6qhashfn(__be32 id, struct in6_addr *saddr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 struct in6_addr *daddr)
125{
126 u32 a, b, c;
127
Al Viroe69a4ad2006-11-14 20:56:00 -0800128 a = (__force u32)saddr->s6_addr32[0];
129 b = (__force u32)saddr->s6_addr32[1];
130 c = (__force u32)saddr->s6_addr32[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132 a += JHASH_GOLDEN_RATIO;
133 b += JHASH_GOLDEN_RATIO;
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700134 c += ip6_frags.rnd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 __jhash_mix(a, b, c);
136
Al Viroe69a4ad2006-11-14 20:56:00 -0800137 a += (__force u32)saddr->s6_addr32[3];
138 b += (__force u32)daddr->s6_addr32[0];
139 c += (__force u32)daddr->s6_addr32[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 __jhash_mix(a, b, c);
141
Al Viroe69a4ad2006-11-14 20:56:00 -0800142 a += (__force u32)daddr->s6_addr32[2];
143 b += (__force u32)daddr->s6_addr32[3];
144 c += (__force u32)id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 __jhash_mix(a, b, c);
146
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700147 return c & (INETFRAGS_HASHSZ - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148}
149
Brian Haleyab32ea52006-09-22 14:15:41 -0700150int sysctl_ip6frag_secret_interval __read_mostly = 10 * 60 * HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
152static void ip6_frag_secret_rebuild(unsigned long dummy)
153{
154 unsigned long now = jiffies;
155 int i;
156
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700157 write_lock(&ip6_frags.lock);
158 get_random_bytes(&ip6_frags.rnd, sizeof(u32));
159 for (i = 0; i < INETFRAGS_HASHSZ; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 struct frag_queue *q;
Yasuyuki Kozakaie7c8a412005-11-16 12:55:37 -0800161 struct hlist_node *p, *n;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700163 hlist_for_each_entry_safe(q, p, n, &ip6_frags.hash[i], q.list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 unsigned int hval = ip6qhashfn(q->id,
165 &q->saddr,
166 &q->daddr);
167
168 if (hval != i) {
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700169 hlist_del(&q->q.list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
171 /* Relink to new hash chain. */
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700172 hlist_add_head(&q->q.list,
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700173 &ip6_frags.hash[hval]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Yasuyuki Kozakaie7c8a412005-11-16 12:55:37 -0800175 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 }
177 }
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700178 write_unlock(&ip6_frags.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700180 mod_timer(&ip6_frags.secret_timer, now + sysctl_ip6frag_secret_interval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181}
182
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183/* Memory Tracking Functions. */
184static inline void frag_kfree_skb(struct sk_buff *skb, int *work)
185{
186 if (work)
187 *work -= skb->truesize;
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700188 atomic_sub(skb->truesize, &ip6_frags.mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 kfree_skb(skb);
190}
191
192static inline void frag_free_queue(struct frag_queue *fq, int *work)
193{
194 if (work)
195 *work -= sizeof(struct frag_queue);
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700196 atomic_sub(sizeof(struct frag_queue), &ip6_frags.mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 kfree(fq);
198}
199
200static inline struct frag_queue *frag_alloc_queue(void)
201{
Ingo Oeser78c784c2006-03-20 23:01:17 -0800202 struct frag_queue *fq = kzalloc(sizeof(struct frag_queue), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
204 if(!fq)
205 return NULL;
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700206 atomic_add(sizeof(struct frag_queue), &ip6_frags.mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 return fq;
208}
209
210/* Destruction primitives. */
211
212/* Complete destruction of fq. */
213static void ip6_frag_destroy(struct frag_queue *fq, int *work)
214{
215 struct sk_buff *fp;
216
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700217 BUG_TRAP(fq->q.last_in&COMPLETE);
218 BUG_TRAP(del_timer(&fq->q.timer) == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220 /* Release all fragment data. */
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700221 fp = fq->q.fragments;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 while (fp) {
223 struct sk_buff *xp = fp->next;
224
225 frag_kfree_skb(fp, work);
226 fp = xp;
227 }
228
229 frag_free_queue(fq, work);
230}
231
232static __inline__ void fq_put(struct frag_queue *fq, int *work)
233{
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700234 if (atomic_dec_and_test(&fq->q.refcnt))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 ip6_frag_destroy(fq, work);
236}
237
238/* Kill fq entry. It is not destroyed immediately,
239 * because caller (and someone more) holds reference count.
240 */
241static __inline__ void fq_kill(struct frag_queue *fq)
242{
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700243 if (del_timer(&fq->q.timer))
244 atomic_dec(&fq->q.refcnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700246 if (!(fq->q.last_in & COMPLETE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 fq_unlink(fq);
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700248 atomic_dec(&fq->q.refcnt);
249 fq->q.last_in |= COMPLETE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 }
251}
252
YOSHIFUJI Hideakia11d2062006-11-04 20:11:37 +0900253static void ip6_evictor(struct inet6_dev *idev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
255 struct frag_queue *fq;
256 struct list_head *tmp;
257 int work;
258
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700259 work = atomic_read(&ip6_frags.mem) - sysctl_ip6frag_low_thresh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 if (work <= 0)
261 return;
262
263 while(work > 0) {
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700264 read_lock(&ip6_frags.lock);
265 if (list_empty(&ip6_frags.lru_list)) {
266 read_unlock(&ip6_frags.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 return;
268 }
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700269 tmp = ip6_frags.lru_list.next;
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700270 fq = list_entry(tmp, struct frag_queue, q.lru_list);
271 atomic_inc(&fq->q.refcnt);
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700272 read_unlock(&ip6_frags.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700274 spin_lock(&fq->q.lock);
275 if (!(fq->q.last_in&COMPLETE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 fq_kill(fq);
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700277 spin_unlock(&fq->q.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
279 fq_put(fq, &work);
YOSHIFUJI Hideakia11d2062006-11-04 20:11:37 +0900280 IP6_INC_STATS_BH(idev, IPSTATS_MIB_REASMFAILS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 }
282}
283
284static void ip6_frag_expire(unsigned long data)
285{
286 struct frag_queue *fq = (struct frag_queue *) data;
YOSHIFUJI Hideakia11d2062006-11-04 20:11:37 +0900287 struct net_device *dev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700289 spin_lock(&fq->q.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700291 if (fq->q.last_in & COMPLETE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 goto out;
293
294 fq_kill(fq);
295
Eric W. Biederman881d9662007-09-17 11:56:21 -0700296 dev = dev_get_by_index(&init_net, fq->iif);
YOSHIFUJI Hideakia11d2062006-11-04 20:11:37 +0900297 if (!dev)
298 goto out;
299
300 rcu_read_lock();
301 IP6_INC_STATS_BH(__in6_dev_get(dev), IPSTATS_MIB_REASMTIMEOUT);
302 IP6_INC_STATS_BH(__in6_dev_get(dev), IPSTATS_MIB_REASMFAILS);
303 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
Ingo Oeser78c784c2006-03-20 23:01:17 -0800305 /* Don't send error if the first segment did not arrive. */
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700306 if (!(fq->q.last_in&FIRST_IN) || !fq->q.fragments)
Ingo Oeser78c784c2006-03-20 23:01:17 -0800307 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Ingo Oeser78c784c2006-03-20 23:01:17 -0800309 /*
310 But use as source device on which LAST ARRIVED
311 segment was received. And do not use fq->dev
312 pointer directly, device might already disappeared.
313 */
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700314 fq->q.fragments->dev = dev;
315 icmpv6_send(fq->q.fragments, ICMPV6_TIME_EXCEED, ICMPV6_EXC_FRAGTIME, 0, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316out:
YOSHIFUJI Hideakia11d2062006-11-04 20:11:37 +0900317 if (dev)
318 dev_put(dev);
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700319 spin_unlock(&fq->q.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 fq_put(fq, NULL);
321}
322
323/* Creation primitives. */
324
325
Zach Brownf6596f92006-04-10 16:05:34 -0700326static struct frag_queue *ip6_frag_intern(struct frag_queue *fq_in)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327{
328 struct frag_queue *fq;
Zach Brownf6596f92006-04-10 16:05:34 -0700329 unsigned int hash;
Yasuyuki Kozakaie7c8a412005-11-16 12:55:37 -0800330#ifdef CONFIG_SMP
331 struct hlist_node *n;
332#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700334 write_lock(&ip6_frags.lock);
Zach Brownf6596f92006-04-10 16:05:34 -0700335 hash = ip6qhashfn(fq_in->id, &fq_in->saddr, &fq_in->daddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336#ifdef CONFIG_SMP
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700337 hlist_for_each_entry(fq, n, &ip6_frags.hash[hash], q.list) {
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +0900338 if (fq->id == fq_in->id &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 ipv6_addr_equal(&fq_in->saddr, &fq->saddr) &&
340 ipv6_addr_equal(&fq_in->daddr, &fq->daddr)) {
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700341 atomic_inc(&fq->q.refcnt);
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700342 write_unlock(&ip6_frags.lock);
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700343 fq_in->q.last_in |= COMPLETE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 fq_put(fq_in, NULL);
345 return fq;
346 }
347 }
348#endif
349 fq = fq_in;
350
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700351 if (!mod_timer(&fq->q.timer, jiffies + sysctl_ip6frag_time))
352 atomic_inc(&fq->q.refcnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700354 atomic_inc(&fq->q.refcnt);
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700355 hlist_add_head(&fq->q.list, &ip6_frags.hash[hash]);
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700356 INIT_LIST_HEAD(&fq->q.lru_list);
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700357 list_add_tail(&fq->q.lru_list, &ip6_frags.lru_list);
358 ip6_frags.nqueues++;
359 write_unlock(&ip6_frags.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 return fq;
361}
362
363
364static struct frag_queue *
Al Viroe69a4ad2006-11-14 20:56:00 -0800365ip6_frag_create(__be32 id, struct in6_addr *src, struct in6_addr *dst,
YOSHIFUJI Hideakia11d2062006-11-04 20:11:37 +0900366 struct inet6_dev *idev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367{
368 struct frag_queue *fq;
369
370 if ((fq = frag_alloc_queue()) == NULL)
371 goto oom;
372
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 fq->id = id;
374 ipv6_addr_copy(&fq->saddr, src);
375 ipv6_addr_copy(&fq->daddr, dst);
376
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700377 init_timer(&fq->q.timer);
378 fq->q.timer.function = ip6_frag_expire;
379 fq->q.timer.data = (long) fq;
380 spin_lock_init(&fq->q.lock);
381 atomic_set(&fq->q.refcnt, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
Zach Brownf6596f92006-04-10 16:05:34 -0700383 return ip6_frag_intern(fq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
385oom:
YOSHIFUJI Hideakia11d2062006-11-04 20:11:37 +0900386 IP6_INC_STATS_BH(idev, IPSTATS_MIB_REASMFAILS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 return NULL;
388}
389
390static __inline__ struct frag_queue *
Al Viroe69a4ad2006-11-14 20:56:00 -0800391fq_find(__be32 id, struct in6_addr *src, struct in6_addr *dst,
YOSHIFUJI Hideakia11d2062006-11-04 20:11:37 +0900392 struct inet6_dev *idev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393{
394 struct frag_queue *fq;
Yasuyuki Kozakaie7c8a412005-11-16 12:55:37 -0800395 struct hlist_node *n;
Zach Brownf6596f92006-04-10 16:05:34 -0700396 unsigned int hash;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700398 read_lock(&ip6_frags.lock);
Zach Brownf6596f92006-04-10 16:05:34 -0700399 hash = ip6qhashfn(id, src, dst);
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700400 hlist_for_each_entry(fq, n, &ip6_frags.hash[hash], q.list) {
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +0900401 if (fq->id == id &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 ipv6_addr_equal(src, &fq->saddr) &&
403 ipv6_addr_equal(dst, &fq->daddr)) {
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700404 atomic_inc(&fq->q.refcnt);
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700405 read_unlock(&ip6_frags.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 return fq;
407 }
408 }
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700409 read_unlock(&ip6_frags.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
YOSHIFUJI Hideakia11d2062006-11-04 20:11:37 +0900411 return ip6_frag_create(id, src, dst, idev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412}
413
414
Herbert Xuf61944e2007-10-15 01:28:47 -0700415static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 struct frag_hdr *fhdr, int nhoff)
417{
418 struct sk_buff *prev, *next;
Herbert Xuf61944e2007-10-15 01:28:47 -0700419 struct net_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 int offset, end;
421
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700422 if (fq->q.last_in & COMPLETE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 goto err;
424
425 offset = ntohs(fhdr->frag_off) & ~0x7;
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -0700426 end = offset + (ntohs(ipv6_hdr(skb)->payload_len) -
427 ((u8 *)(fhdr + 1) - (u8 *)(ipv6_hdr(skb) + 1)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
429 if ((unsigned int)end > IPV6_MAXPLEN) {
YOSHIFUJI Hideakia11d2062006-11-04 20:11:37 +0900430 IP6_INC_STATS_BH(ip6_dst_idev(skb->dst),
431 IPSTATS_MIB_INHDRERRORS);
Arnaldo Carvalho de Melod56f90a2007-04-10 20:50:43 -0700432 icmpv6_param_prob(skb, ICMPV6_HDR_FIELD,
433 ((u8 *)&fhdr->frag_off -
434 skb_network_header(skb)));
Herbert Xuf61944e2007-10-15 01:28:47 -0700435 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 }
437
Arnaldo Carvalho de Melod56f90a2007-04-10 20:50:43 -0700438 if (skb->ip_summed == CHECKSUM_COMPLETE) {
439 const unsigned char *nh = skb_network_header(skb);
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +0900440 skb->csum = csum_sub(skb->csum,
Arnaldo Carvalho de Melod56f90a2007-04-10 20:50:43 -0700441 csum_partial(nh, (u8 *)(fhdr + 1) - nh,
442 0));
443 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
445 /* Is this the final fragment? */
446 if (!(fhdr->frag_off & htons(IP6_MF))) {
447 /* If we already have some bits beyond end
448 * or have different end, the segment is corrupted.
449 */
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700450 if (end < fq->q.len ||
451 ((fq->q.last_in & LAST_IN) && end != fq->q.len))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 goto err;
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700453 fq->q.last_in |= LAST_IN;
454 fq->q.len = end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 } else {
456 /* Check if the fragment is rounded to 8 bytes.
457 * Required by the RFC.
458 */
459 if (end & 0x7) {
460 /* RFC2460 says always send parameter problem in
461 * this case. -DaveM
462 */
YOSHIFUJI Hideakia11d2062006-11-04 20:11:37 +0900463 IP6_INC_STATS_BH(ip6_dst_idev(skb->dst),
464 IPSTATS_MIB_INHDRERRORS);
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +0900465 icmpv6_param_prob(skb, ICMPV6_HDR_FIELD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 offsetof(struct ipv6hdr, payload_len));
Herbert Xuf61944e2007-10-15 01:28:47 -0700467 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 }
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700469 if (end > fq->q.len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 /* Some bits beyond end -> corruption. */
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700471 if (fq->q.last_in & LAST_IN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 goto err;
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700473 fq->q.len = end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 }
475 }
476
477 if (end == offset)
478 goto err;
479
480 /* Point into the IP datagram 'data' part. */
481 if (!pskb_pull(skb, (u8 *) (fhdr + 1) - skb->data))
482 goto err;
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +0900483
Stephen Hemminger42ca89c2005-09-08 12:57:43 -0700484 if (pskb_trim_rcsum(skb, end - offset))
485 goto err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
487 /* Find out which fragments are in front and at the back of us
488 * in the chain of fragments so far. We must know where to put
489 * this fragment, right?
490 */
491 prev = NULL;
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700492 for(next = fq->q.fragments; next != NULL; next = next->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 if (FRAG6_CB(next)->offset >= offset)
494 break; /* bingo! */
495 prev = next;
496 }
497
498 /* We found where to put this one. Check for overlap with
499 * preceding fragment, and, if needed, align things so that
500 * any overlaps are eliminated.
501 */
502 if (prev) {
503 int i = (FRAG6_CB(prev)->offset + prev->len) - offset;
504
505 if (i > 0) {
506 offset += i;
507 if (end <= offset)
508 goto err;
509 if (!pskb_pull(skb, i))
510 goto err;
511 if (skb->ip_summed != CHECKSUM_UNNECESSARY)
512 skb->ip_summed = CHECKSUM_NONE;
513 }
514 }
515
516 /* Look for overlap with succeeding segments.
517 * If we can merge fragments, do it.
518 */
519 while (next && FRAG6_CB(next)->offset < end) {
520 int i = end - FRAG6_CB(next)->offset; /* overlap is 'i' bytes */
521
522 if (i < next->len) {
523 /* Eat head of the next overlapped fragment
524 * and leave the loop. The next ones cannot overlap.
525 */
526 if (!pskb_pull(next, i))
527 goto err;
528 FRAG6_CB(next)->offset += i; /* next fragment */
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700529 fq->q.meat -= i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 if (next->ip_summed != CHECKSUM_UNNECESSARY)
531 next->ip_summed = CHECKSUM_NONE;
532 break;
533 } else {
534 struct sk_buff *free_it = next;
535
536 /* Old fragment is completely overridden with
537 * new one drop it.
538 */
539 next = next->next;
540
541 if (prev)
542 prev->next = next;
543 else
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700544 fq->q.fragments = next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700546 fq->q.meat -= free_it->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 frag_kfree_skb(free_it, NULL);
548 }
549 }
550
551 FRAG6_CB(skb)->offset = offset;
552
553 /* Insert this fragment in the chain of fragments. */
554 skb->next = next;
555 if (prev)
556 prev->next = skb;
557 else
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700558 fq->q.fragments = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
Herbert Xuf61944e2007-10-15 01:28:47 -0700560 dev = skb->dev;
561 if (dev) {
562 fq->iif = dev->ifindex;
563 skb->dev = NULL;
564 }
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700565 fq->q.stamp = skb->tstamp;
566 fq->q.meat += skb->len;
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700567 atomic_add(skb->truesize, &ip6_frags.mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
569 /* The first fragment.
570 * nhoffset is obtained from the first fragment, of course.
571 */
572 if (offset == 0) {
573 fq->nhoffset = nhoff;
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700574 fq->q.last_in |= FIRST_IN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 }
Herbert Xuf61944e2007-10-15 01:28:47 -0700576
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700577 if (fq->q.last_in == (FIRST_IN | LAST_IN) && fq->q.meat == fq->q.len)
Herbert Xuf61944e2007-10-15 01:28:47 -0700578 return ip6_frag_reasm(fq, prev, dev);
579
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700580 write_lock(&ip6_frags.lock);
581 list_move_tail(&fq->q.lru_list, &ip6_frags.lru_list);
582 write_unlock(&ip6_frags.lock);
Herbert Xuf61944e2007-10-15 01:28:47 -0700583 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
585err:
YOSHIFUJI Hideakia11d2062006-11-04 20:11:37 +0900586 IP6_INC_STATS(ip6_dst_idev(skb->dst), IPSTATS_MIB_REASMFAILS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 kfree_skb(skb);
Herbert Xuf61944e2007-10-15 01:28:47 -0700588 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589}
590
591/*
592 * Check if this packet is complete.
593 * Returns NULL on failure by any reason, and pointer
594 * to current nexthdr field in reassembled frame.
595 *
596 * It is called with locked fq, and caller must check that
597 * queue is eligible for reassembly i.e. it is not COMPLETE,
598 * the last and the first frames arrived and all the bits are here.
599 */
Herbert Xuf61944e2007-10-15 01:28:47 -0700600static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *prev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 struct net_device *dev)
602{
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700603 struct sk_buff *fp, *head = fq->q.fragments;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 int payload_len;
605 unsigned int nhoff;
606
607 fq_kill(fq);
608
Herbert Xuf61944e2007-10-15 01:28:47 -0700609 /* Make the one we just received the head. */
610 if (prev) {
611 head = prev->next;
612 fp = skb_clone(head, GFP_ATOMIC);
613
614 if (!fp)
615 goto out_oom;
616
617 fp->next = head->next;
618 prev->next = fp;
619
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700620 skb_morph(head, fq->q.fragments);
621 head->next = fq->q.fragments->next;
Herbert Xuf61944e2007-10-15 01:28:47 -0700622
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700623 kfree_skb(fq->q.fragments);
624 fq->q.fragments = head;
Herbert Xuf61944e2007-10-15 01:28:47 -0700625 }
626
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 BUG_TRAP(head != NULL);
628 BUG_TRAP(FRAG6_CB(head)->offset == 0);
629
630 /* Unfragmented part is taken from the first segment. */
Arnaldo Carvalho de Melod56f90a2007-04-10 20:50:43 -0700631 payload_len = ((head->data - skb_network_header(head)) -
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700632 sizeof(struct ipv6hdr) + fq->q.len -
Arnaldo Carvalho de Melod56f90a2007-04-10 20:50:43 -0700633 sizeof(struct frag_hdr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 if (payload_len > IPV6_MAXPLEN)
635 goto out_oversize;
636
637 /* Head of list must not be cloned. */
638 if (skb_cloned(head) && pskb_expand_head(head, 0, 0, GFP_ATOMIC))
639 goto out_oom;
640
641 /* If the first fragment is fragmented itself, we split
642 * it to two chunks: the first with data and paged part
643 * and the second, holding only fragments. */
644 if (skb_shinfo(head)->frag_list) {
645 struct sk_buff *clone;
646 int i, plen = 0;
647
648 if ((clone = alloc_skb(0, GFP_ATOMIC)) == NULL)
649 goto out_oom;
650 clone->next = head->next;
651 head->next = clone;
652 skb_shinfo(clone)->frag_list = skb_shinfo(head)->frag_list;
653 skb_shinfo(head)->frag_list = NULL;
654 for (i=0; i<skb_shinfo(head)->nr_frags; i++)
655 plen += skb_shinfo(head)->frags[i].size;
656 clone->len = clone->data_len = head->data_len - plen;
657 head->data_len -= clone->len;
658 head->len -= clone->len;
659 clone->csum = 0;
660 clone->ip_summed = head->ip_summed;
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700661 atomic_add(clone->truesize, &ip6_frags.mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 }
663
664 /* We have to remove fragment header from datagram and to relocate
665 * header in order to calculate ICV correctly. */
666 nhoff = fq->nhoffset;
Arnaldo Carvalho de Melob0e380b2007-04-10 21:21:55 -0700667 skb_network_header(head)[nhoff] = skb_transport_header(head)[0];
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +0900668 memmove(head->head + sizeof(struct frag_hdr), head->head,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 (head->data - head->head) - sizeof(struct frag_hdr));
Arnaldo Carvalho de Melob0e380b2007-04-10 21:21:55 -0700670 head->mac_header += sizeof(struct frag_hdr);
671 head->network_header += sizeof(struct frag_hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
673 skb_shinfo(head)->frag_list = head->next;
Arnaldo Carvalho de Melobadff6d2007-03-13 13:06:52 -0300674 skb_reset_transport_header(head);
Arnaldo Carvalho de Melod56f90a2007-04-10 20:50:43 -0700675 skb_push(head, head->data - skb_network_header(head));
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700676 atomic_sub(head->truesize, &ip6_frags.mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
678 for (fp=head->next; fp; fp = fp->next) {
679 head->data_len += fp->len;
680 head->len += fp->len;
681 if (head->ip_summed != fp->ip_summed)
682 head->ip_summed = CHECKSUM_NONE;
Patrick McHardy84fa7932006-08-29 16:44:56 -0700683 else if (head->ip_summed == CHECKSUM_COMPLETE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 head->csum = csum_add(head->csum, fp->csum);
685 head->truesize += fp->truesize;
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700686 atomic_sub(fp->truesize, &ip6_frags.mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 }
688
689 head->next = NULL;
690 head->dev = dev;
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700691 head->tstamp = fq->q.stamp;
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -0700692 ipv6_hdr(head)->payload_len = htons(payload_len);
Patrick McHardy951dbc82006-01-06 23:02:34 -0800693 IP6CB(head)->nhoff = nhoff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 /* Yes, and fold redundant checksum back. 8) */
Patrick McHardy84fa7932006-08-29 16:44:56 -0700696 if (head->ip_summed == CHECKSUM_COMPLETE)
Arnaldo Carvalho de Melod56f90a2007-04-10 20:50:43 -0700697 head->csum = csum_partial(skb_network_header(head),
Arnaldo Carvalho de Melocfe1fc72007-03-16 17:26:39 -0300698 skb_network_header_len(head),
Arnaldo Carvalho de Melod56f90a2007-04-10 20:50:43 -0700699 head->csum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700
YOSHIFUJI Hideakia11d2062006-11-04 20:11:37 +0900701 rcu_read_lock();
702 IP6_INC_STATS_BH(__in6_dev_get(dev), IPSTATS_MIB_REASMOKS);
703 rcu_read_unlock();
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700704 fq->q.fragments = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 return 1;
706
707out_oversize:
708 if (net_ratelimit())
709 printk(KERN_DEBUG "ip6_frag_reasm: payload len = %d\n", payload_len);
710 goto out_fail;
711out_oom:
712 if (net_ratelimit())
713 printk(KERN_DEBUG "ip6_frag_reasm: no memory for reassembly\n");
714out_fail:
YOSHIFUJI Hideakia11d2062006-11-04 20:11:37 +0900715 rcu_read_lock();
716 IP6_INC_STATS_BH(__in6_dev_get(dev), IPSTATS_MIB_REASMFAILS);
717 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 return -1;
719}
720
Patrick McHardy951dbc82006-01-06 23:02:34 -0800721static int ipv6_frag_rcv(struct sk_buff **skbp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722{
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +0900723 struct sk_buff *skb = *skbp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 struct frag_hdr *fhdr;
725 struct frag_queue *fq;
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -0700726 struct ipv6hdr *hdr = ipv6_hdr(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
YOSHIFUJI Hideakia11d2062006-11-04 20:11:37 +0900728 IP6_INC_STATS_BH(ip6_dst_idev(skb->dst), IPSTATS_MIB_REASMREQDS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
730 /* Jumbo payload inhibits frag. header */
731 if (hdr->payload_len==0) {
YOSHIFUJI Hideakia11d2062006-11-04 20:11:37 +0900732 IP6_INC_STATS(ip6_dst_idev(skb->dst), IPSTATS_MIB_INHDRERRORS);
Arnaldo Carvalho de Melocfe1fc72007-03-16 17:26:39 -0300733 icmpv6_param_prob(skb, ICMPV6_HDR_FIELD,
734 skb_network_header_len(skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 return -1;
736 }
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -0700737 if (!pskb_may_pull(skb, (skb_transport_offset(skb) +
738 sizeof(struct frag_hdr)))) {
YOSHIFUJI Hideakia11d2062006-11-04 20:11:37 +0900739 IP6_INC_STATS(ip6_dst_idev(skb->dst), IPSTATS_MIB_INHDRERRORS);
Arnaldo Carvalho de Melocfe1fc72007-03-16 17:26:39 -0300740 icmpv6_param_prob(skb, ICMPV6_HDR_FIELD,
741 skb_network_header_len(skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 return -1;
743 }
744
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -0700745 hdr = ipv6_hdr(skb);
Arnaldo Carvalho de Melo9c702202007-04-25 18:04:18 -0700746 fhdr = (struct frag_hdr *)skb_transport_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
748 if (!(fhdr->frag_off & htons(0xFFF9))) {
749 /* It is not a fragmented frame */
Arnaldo Carvalho de Melob0e380b2007-04-10 21:21:55 -0700750 skb->transport_header += sizeof(struct frag_hdr);
YOSHIFUJI Hideakia11d2062006-11-04 20:11:37 +0900751 IP6_INC_STATS_BH(ip6_dst_idev(skb->dst), IPSTATS_MIB_REASMOKS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
Arnaldo Carvalho de Melod56f90a2007-04-10 20:50:43 -0700753 IP6CB(skb)->nhoff = (u8 *)fhdr - skb_network_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 return 1;
755 }
756
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700757 if (atomic_read(&ip6_frags.mem) > sysctl_ip6frag_high_thresh)
YOSHIFUJI Hideakia11d2062006-11-04 20:11:37 +0900758 ip6_evictor(ip6_dst_idev(skb->dst));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759
YOSHIFUJI Hideakia11d2062006-11-04 20:11:37 +0900760 if ((fq = fq_find(fhdr->identification, &hdr->saddr, &hdr->daddr,
761 ip6_dst_idev(skb->dst))) != NULL) {
Herbert Xuf61944e2007-10-15 01:28:47 -0700762 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700764 spin_lock(&fq->q.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765
Herbert Xuf61944e2007-10-15 01:28:47 -0700766 ret = ip6_frag_queue(fq, skb, fhdr, IP6CB(skb)->nhoff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -0700768 spin_unlock(&fq->q.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 fq_put(fq, NULL);
770 return ret;
771 }
772
YOSHIFUJI Hideakia11d2062006-11-04 20:11:37 +0900773 IP6_INC_STATS_BH(ip6_dst_idev(skb->dst), IPSTATS_MIB_REASMFAILS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 kfree_skb(skb);
775 return -1;
776}
777
778static struct inet6_protocol frag_protocol =
779{
780 .handler = ipv6_frag_rcv,
781 .flags = INET6_PROTO_NOPOLICY,
782};
783
784void __init ipv6_frag_init(void)
785{
786 if (inet6_add_protocol(&frag_protocol, IPPROTO_FRAGMENT) < 0)
787 printk(KERN_ERR "ipv6_frag_init: Could not register protocol\n");
788
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700789 init_timer(&ip6_frags.secret_timer);
790 ip6_frags.secret_timer.function = ip6_frag_secret_rebuild;
791 ip6_frags.secret_timer.expires = jiffies + sysctl_ip6frag_secret_interval;
792 add_timer(&ip6_frags.secret_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
Pavel Emelyanov7eb95152007-10-15 02:31:52 -0700794 inet_frags_init(&ip6_frags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795}