ip_fragment.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. /*
  2. * INET An implementation of the TCP/IP protocol suite for the LINUX
  3. * operating system. INET is implemented using the BSD Socket
  4. * interface as the means of communication with the user level.
  5. *
  6. * The IP fragmentation functionality.
  7. *
  8. * Version: $Id: ip_fragment.c,v 1.59 2002/01/12 07:54:56 davem Exp $
  9. *
  10. * Authors: Fred N. van Kempen <waltje@uWalt.NL.Mugnet.ORG>
  11. * Alan Cox <Alan.Cox@linux.org>
  12. *
  13. * Fixes:
  14. * Alan Cox : Split from ip.c , see ip_input.c for history.
  15. * David S. Miller : Begin massive cleanup...
  16. * Andi Kleen : Add sysctls.
  17. * xxxx : Overlapfrag bug.
  18. * Ultima : ip_expire() kernel panic.
  19. * Bill Hawes : Frag accounting and evictor fixes.
  20. * John McDonald : 0 length frag bug.
  21. * Alexey Kuznetsov: SMP races, threading, cleanup.
  22. * Patrick McHardy : LRU queue of frag heads for evictor.
  23. */
  24. #include <linux/config.h>
  25. #include <linux/module.h>
  26. #include <linux/types.h>
  27. #include <linux/mm.h>
  28. #include <linux/jiffies.h>
  29. #include <linux/skbuff.h>
  30. #include <linux/list.h>
  31. #include <linux/ip.h>
  32. #include <linux/icmp.h>
  33. #include <linux/netdevice.h>
  34. #include <linux/jhash.h>
  35. #include <linux/random.h>
  36. #include <net/sock.h>
  37. #include <net/ip.h>
  38. #include <net/icmp.h>
  39. #include <net/checksum.h>
  40. #include <linux/tcp.h>
  41. #include <linux/udp.h>
  42. #include <linux/inet.h>
  43. #include <linux/netfilter_ipv4.h>
  44. /* NOTE. Logic of IP defragmentation is parallel to corresponding IPv6
  45. * code now. If you change something here, _PLEASE_ update ipv6/reassembly.c
  46. * as well. Or notify me, at least. --ANK
  47. */
  48. /* Fragment cache limits. We will commit 256K at one time. Should we
  49. * cross that limit we will prune down to 192K. This should cope with
  50. * even the most extreme cases without allowing an attacker to measurably
  51. * harm machine performance.
  52. */
  53. int sysctl_ipfrag_high_thresh = 256*1024;
  54. int sysctl_ipfrag_low_thresh = 192*1024;
  55. /* Important NOTE! Fragment queue must be destroyed before MSL expires.
  56. * RFC791 is wrong proposing to prolongate timer each fragment arrival by TTL.
  57. */
  58. int sysctl_ipfrag_time = IP_FRAG_TIME;
  59. struct ipfrag_skb_cb
  60. {
  61. struct inet_skb_parm h;
  62. int offset;
  63. };
  64. #define FRAG_CB(skb) ((struct ipfrag_skb_cb*)((skb)->cb))
  65. /* Describe an entry in the "incomplete datagrams" queue. */
  66. struct ipq {
  67. struct hlist_node list;
  68. struct list_head lru_list; /* lru list member */
  69. u32 user;
  70. u32 saddr;
  71. u32 daddr;
  72. u16 id;
  73. u8 protocol;
  74. u8 last_in;
  75. #define COMPLETE 4
  76. #define FIRST_IN 2
  77. #define LAST_IN 1
  78. struct sk_buff *fragments; /* linked list of received fragments */
  79. int len; /* total length of original datagram */
  80. int meat;
  81. spinlock_t lock;
  82. atomic_t refcnt;
  83. struct timer_list timer; /* when will this queue expire? */
  84. int iif;
  85. struct timeval stamp;
  86. };
  87. /* Hash table. */
  88. #define IPQ_HASHSZ 64
  89. /* Per-bucket lock is easy to add now. */
  90. static struct hlist_head ipq_hash[IPQ_HASHSZ];
  91. static DEFINE_RWLOCK(ipfrag_lock);
  92. static u32 ipfrag_hash_rnd;
  93. static LIST_HEAD(ipq_lru_list);
  94. int ip_frag_nqueues = 0;
  95. static __inline__ void __ipq_unlink(struct ipq *qp)
  96. {
  97. hlist_del(&qp->list);
  98. list_del(&qp->lru_list);
  99. ip_frag_nqueues--;
  100. }
  101. static __inline__ void ipq_unlink(struct ipq *ipq)
  102. {
  103. write_lock(&ipfrag_lock);
  104. __ipq_unlink(ipq);
  105. write_unlock(&ipfrag_lock);
  106. }
  107. static unsigned int ipqhashfn(u16 id, u32 saddr, u32 daddr, u8 prot)
  108. {
  109. return jhash_3words((u32)id << 16 | prot, saddr, daddr,
  110. ipfrag_hash_rnd) & (IPQ_HASHSZ - 1);
  111. }
  112. static struct timer_list ipfrag_secret_timer;
  113. int sysctl_ipfrag_secret_interval = 10 * 60 * HZ;
  114. static void ipfrag_secret_rebuild(unsigned long dummy)
  115. {
  116. unsigned long now = jiffies;
  117. int i;
  118. write_lock(&ipfrag_lock);
  119. get_random_bytes(&ipfrag_hash_rnd, sizeof(u32));
  120. for (i = 0; i < IPQ_HASHSZ; i++) {
  121. struct ipq *q;
  122. struct hlist_node *p, *n;
  123. hlist_for_each_entry_safe(q, p, n, &ipq_hash[i], list) {
  124. unsigned int hval = ipqhashfn(q->id, q->saddr,
  125. q->daddr, q->protocol);
  126. if (hval != i) {
  127. hlist_del(&q->list);
  128. /* Relink to new hash chain. */
  129. hlist_add_head(&q->list, &ipq_hash[hval]);
  130. }
  131. }
  132. }
  133. write_unlock(&ipfrag_lock);
  134. mod_timer(&ipfrag_secret_timer, now + sysctl_ipfrag_secret_interval);
  135. }
  136. atomic_t ip_frag_mem = ATOMIC_INIT(0); /* Memory used for fragments */
  137. /* Memory Tracking Functions. */
  138. static __inline__ void frag_kfree_skb(struct sk_buff *skb, int *work)
  139. {
  140. if (work)
  141. *work -= skb->truesize;
  142. atomic_sub(skb->truesize, &ip_frag_mem);
  143. kfree_skb(skb);
  144. }
  145. static __inline__ void frag_free_queue(struct ipq *qp, int *work)
  146. {
  147. if (work)
  148. *work -= sizeof(struct ipq);
  149. atomic_sub(sizeof(struct ipq), &ip_frag_mem);
  150. kfree(qp);
  151. }
  152. static __inline__ struct ipq *frag_alloc_queue(void)
  153. {
  154. struct ipq *qp = kmalloc(sizeof(struct ipq), GFP_ATOMIC);
  155. if(!qp)
  156. return NULL;
  157. atomic_add(sizeof(struct ipq), &ip_frag_mem);
  158. return qp;
  159. }
  160. /* Destruction primitives. */
  161. /* Complete destruction of ipq. */
  162. static void ip_frag_destroy(struct ipq *qp, int *work)
  163. {
  164. struct sk_buff *fp;
  165. BUG_TRAP(qp->last_in&COMPLETE);
  166. BUG_TRAP(del_timer(&qp->timer) == 0);
  167. /* Release all fragment data. */
  168. fp = qp->fragments;
  169. while (fp) {
  170. struct sk_buff *xp = fp->next;
  171. frag_kfree_skb(fp, work);
  172. fp = xp;
  173. }
  174. /* Finally, release the queue descriptor itself. */
  175. frag_free_queue(qp, work);
  176. }
  177. static __inline__ void ipq_put(struct ipq *ipq, int *work)
  178. {
  179. if (atomic_dec_and_test(&ipq->refcnt))
  180. ip_frag_destroy(ipq, work);
  181. }
  182. /* Kill ipq entry. It is not destroyed immediately,
  183. * because caller (and someone more) holds reference count.
  184. */
  185. static void ipq_kill(struct ipq *ipq)
  186. {
  187. if (del_timer(&ipq->timer))
  188. atomic_dec(&ipq->refcnt);
  189. if (!(ipq->last_in & COMPLETE)) {
  190. ipq_unlink(ipq);
  191. atomic_dec(&ipq->refcnt);
  192. ipq->last_in |= COMPLETE;
  193. }
  194. }
  195. /* Memory limiting on fragments. Evictor trashes the oldest
  196. * fragment queue until we are back under the threshold.
  197. */
  198. static void ip_evictor(void)
  199. {
  200. struct ipq *qp;
  201. struct list_head *tmp;
  202. int work;
  203. work = atomic_read(&ip_frag_mem) - sysctl_ipfrag_low_thresh;
  204. if (work <= 0)
  205. return;
  206. while (work > 0) {
  207. read_lock(&ipfrag_lock);
  208. if (list_empty(&ipq_lru_list)) {
  209. read_unlock(&ipfrag_lock);
  210. return;
  211. }
  212. tmp = ipq_lru_list.next;
  213. qp = list_entry(tmp, struct ipq, lru_list);
  214. atomic_inc(&qp->refcnt);
  215. read_unlock(&ipfrag_lock);
  216. spin_lock(&qp->lock);
  217. if (!(qp->last_in&COMPLETE))
  218. ipq_kill(qp);
  219. spin_unlock(&qp->lock);
  220. ipq_put(qp, &work);
  221. IP_INC_STATS_BH(IPSTATS_MIB_REASMFAILS);
  222. }
  223. }
  224. /*
  225. * Oops, a fragment queue timed out. Kill it and send an ICMP reply.
  226. */
  227. static void ip_expire(unsigned long arg)
  228. {
  229. struct ipq *qp = (struct ipq *) arg;
  230. spin_lock(&qp->lock);
  231. if (qp->last_in & COMPLETE)
  232. goto out;
  233. ipq_kill(qp);
  234. IP_INC_STATS_BH(IPSTATS_MIB_REASMTIMEOUT);
  235. IP_INC_STATS_BH(IPSTATS_MIB_REASMFAILS);
  236. if ((qp->last_in&FIRST_IN) && qp->fragments != NULL) {
  237. struct sk_buff *head = qp->fragments;
  238. /* Send an ICMP "Fragment Reassembly Timeout" message. */
  239. if ((head->dev = dev_get_by_index(qp->iif)) != NULL) {
  240. icmp_send(head, ICMP_TIME_EXCEEDED, ICMP_EXC_FRAGTIME, 0);
  241. dev_put(head->dev);
  242. }
  243. }
  244. out:
  245. spin_unlock(&qp->lock);
  246. ipq_put(qp, NULL);
  247. }
  248. /* Creation primitives. */
  249. static struct ipq *ip_frag_intern(unsigned int hash, struct ipq *qp_in)
  250. {
  251. struct ipq *qp;
  252. #ifdef CONFIG_SMP
  253. struct hlist_node *n;
  254. #endif
  255. write_lock(&ipfrag_lock);
  256. #ifdef CONFIG_SMP
  257. /* With SMP race we have to recheck hash table, because
  258. * such entry could be created on other cpu, while we
  259. * promoted read lock to write lock.
  260. */
  261. hlist_for_each_entry(qp, n, &ipq_hash[hash], list) {
  262. if(qp->id == qp_in->id &&
  263. qp->saddr == qp_in->saddr &&
  264. qp->daddr == qp_in->daddr &&
  265. qp->protocol == qp_in->protocol &&
  266. qp->user == qp_in->user) {
  267. atomic_inc(&qp->refcnt);
  268. write_unlock(&ipfrag_lock);
  269. qp_in->last_in |= COMPLETE;
  270. ipq_put(qp_in, NULL);
  271. return qp;
  272. }
  273. }
  274. #endif
  275. qp = qp_in;
  276. if (!mod_timer(&qp->timer, jiffies + sysctl_ipfrag_time))
  277. atomic_inc(&qp->refcnt);
  278. atomic_inc(&qp->refcnt);
  279. hlist_add_head(&qp->list, &ipq_hash[hash]);
  280. INIT_LIST_HEAD(&qp->lru_list);
  281. list_add_tail(&qp->lru_list, &ipq_lru_list);
  282. ip_frag_nqueues++;
  283. write_unlock(&ipfrag_lock);
  284. return qp;
  285. }
  286. /* Add an entry to the 'ipq' queue for a newly received IP datagram. */
  287. static struct ipq *ip_frag_create(unsigned hash, struct iphdr *iph, u32 user)
  288. {
  289. struct ipq *qp;
  290. if ((qp = frag_alloc_queue()) == NULL)
  291. goto out_nomem;
  292. qp->protocol = iph->protocol;
  293. qp->last_in = 0;
  294. qp->id = iph->id;
  295. qp->saddr = iph->saddr;
  296. qp->daddr = iph->daddr;
  297. qp->user = user;
  298. qp->len = 0;
  299. qp->meat = 0;
  300. qp->fragments = NULL;
  301. qp->iif = 0;
  302. /* Initialize a timer for this entry. */
  303. init_timer(&qp->timer);
  304. qp->timer.data = (unsigned long) qp; /* pointer to queue */
  305. qp->timer.function = ip_expire; /* expire function */
  306. spin_lock_init(&qp->lock);
  307. atomic_set(&qp->refcnt, 1);
  308. return ip_frag_intern(hash, qp);
  309. out_nomem:
  310. LIMIT_NETDEBUG(KERN_ERR "ip_frag_create: no memory left !\n");
  311. return NULL;
  312. }
  313. /* Find the correct entry in the "incomplete datagrams" queue for
  314. * this IP datagram, and create new one, if nothing is found.
  315. */
  316. static inline struct ipq *ip_find(struct iphdr *iph, u32 user)
  317. {
  318. __u16 id = iph->id;
  319. __u32 saddr = iph->saddr;
  320. __u32 daddr = iph->daddr;
  321. __u8 protocol = iph->protocol;
  322. unsigned int hash = ipqhashfn(id, saddr, daddr, protocol);
  323. struct ipq *qp;
  324. struct hlist_node *n;
  325. read_lock(&ipfrag_lock);
  326. hlist_for_each_entry(qp, n, &ipq_hash[hash], list) {
  327. if(qp->id == id &&
  328. qp->saddr == saddr &&
  329. qp->daddr == daddr &&
  330. qp->protocol == protocol &&
  331. qp->user == user) {
  332. atomic_inc(&qp->refcnt);
  333. read_unlock(&ipfrag_lock);
  334. return qp;
  335. }
  336. }
  337. read_unlock(&ipfrag_lock);
  338. return ip_frag_create(hash, iph, user);
  339. }
  340. /* Add new segment to existing queue. */
  341. static void ip_frag_queue(struct ipq *qp, struct sk_buff *skb)
  342. {
  343. struct sk_buff *prev, *next;
  344. int flags, offset;
  345. int ihl, end;
  346. if (qp->last_in & COMPLETE)
  347. goto err;
  348. offset = ntohs(skb->nh.iph->frag_off);
  349. flags = offset & ~IP_OFFSET;
  350. offset &= IP_OFFSET;
  351. offset <<= 3; /* offset is in 8-byte chunks */
  352. ihl = skb->nh.iph->ihl * 4;
  353. /* Determine the position of this fragment. */
  354. end = offset + skb->len - ihl;
  355. /* Is this the final fragment? */
  356. if ((flags & IP_MF) == 0) {
  357. /* If we already have some bits beyond end
  358. * or have different end, the segment is corrrupted.
  359. */
  360. if (end < qp->len ||
  361. ((qp->last_in & LAST_IN) && end != qp->len))
  362. goto err;
  363. qp->last_in |= LAST_IN;
  364. qp->len = end;
  365. } else {
  366. if (end&7) {
  367. end &= ~7;
  368. if (skb->ip_summed != CHECKSUM_UNNECESSARY)
  369. skb->ip_summed = CHECKSUM_NONE;
  370. }
  371. if (end > qp->len) {
  372. /* Some bits beyond end -> corruption. */
  373. if (qp->last_in & LAST_IN)
  374. goto err;
  375. qp->len = end;
  376. }
  377. }
  378. if (end == offset)
  379. goto err;
  380. if (pskb_pull(skb, ihl) == NULL)
  381. goto err;
  382. if (pskb_trim_rcsum(skb, end-offset))
  383. goto err;
  384. /* Find out which fragments are in front and at the back of us
  385. * in the chain of fragments so far. We must know where to put
  386. * this fragment, right?
  387. */
  388. prev = NULL;
  389. for(next = qp->fragments; next != NULL; next = next->next) {
  390. if (FRAG_CB(next)->offset >= offset)
  391. break; /* bingo! */
  392. prev = next;
  393. }
  394. /* We found where to put this one. Check for overlap with
  395. * preceding fragment, and, if needed, align things so that
  396. * any overlaps are eliminated.
  397. */
  398. if (prev) {
  399. int i = (FRAG_CB(prev)->offset + prev->len) - offset;
  400. if (i > 0) {
  401. offset += i;
  402. if (end <= offset)
  403. goto err;
  404. if (!pskb_pull(skb, i))
  405. goto err;
  406. if (skb->ip_summed != CHECKSUM_UNNECESSARY)
  407. skb->ip_summed = CHECKSUM_NONE;
  408. }
  409. }
  410. while (next && FRAG_CB(next)->offset < end) {
  411. int i = end - FRAG_CB(next)->offset; /* overlap is 'i' bytes */
  412. if (i < next->len) {
  413. /* Eat head of the next overlapped fragment
  414. * and leave the loop. The next ones cannot overlap.
  415. */
  416. if (!pskb_pull(next, i))
  417. goto err;
  418. FRAG_CB(next)->offset += i;
  419. qp->meat -= i;
  420. if (next->ip_summed != CHECKSUM_UNNECESSARY)
  421. next->ip_summed = CHECKSUM_NONE;
  422. break;
  423. } else {
  424. struct sk_buff *free_it = next;
  425. /* Old fragmnet is completely overridden with
  426. * new one drop it.
  427. */
  428. next = next->next;
  429. if (prev)
  430. prev->next = next;
  431. else
  432. qp->fragments = next;
  433. qp->meat -= free_it->len;
  434. frag_kfree_skb(free_it, NULL);
  435. }
  436. }
  437. FRAG_CB(skb)->offset = offset;
  438. /* Insert this fragment in the chain of fragments. */
  439. skb->next = next;
  440. if (prev)
  441. prev->next = skb;
  442. else
  443. qp->fragments = skb;
  444. if (skb->dev)
  445. qp->iif = skb->dev->ifindex;
  446. skb->dev = NULL;
  447. skb_get_timestamp(skb, &qp->stamp);
  448. qp->meat += skb->len;
  449. atomic_add(skb->truesize, &ip_frag_mem);
  450. if (offset == 0)
  451. qp->last_in |= FIRST_IN;
  452. write_lock(&ipfrag_lock);
  453. list_move_tail(&qp->lru_list, &ipq_lru_list);
  454. write_unlock(&ipfrag_lock);
  455. return;
  456. err:
  457. kfree_skb(skb);
  458. }
  459. /* Build a new IP datagram from all its fragments. */
  460. static struct sk_buff *ip_frag_reasm(struct ipq *qp, struct net_device *dev)
  461. {
  462. struct iphdr *iph;
  463. struct sk_buff *fp, *head = qp->fragments;
  464. int len;
  465. int ihlen;
  466. ipq_kill(qp);
  467. BUG_TRAP(head != NULL);
  468. BUG_TRAP(FRAG_CB(head)->offset == 0);
  469. /* Allocate a new buffer for the datagram. */
  470. ihlen = head->nh.iph->ihl*4;
  471. len = ihlen + qp->len;
  472. if(len > 65535)
  473. goto out_oversize;
  474. /* Head of list must not be cloned. */
  475. if (skb_cloned(head) && pskb_expand_head(head, 0, 0, GFP_ATOMIC))
  476. goto out_nomem;
  477. /* If the first fragment is fragmented itself, we split
  478. * it to two chunks: the first with data and paged part
  479. * and the second, holding only fragments. */
  480. if (skb_shinfo(head)->frag_list) {
  481. struct sk_buff *clone;
  482. int i, plen = 0;
  483. if ((clone = alloc_skb(0, GFP_ATOMIC)) == NULL)
  484. goto out_nomem;
  485. clone->next = head->next;
  486. head->next = clone;
  487. skb_shinfo(clone)->frag_list = skb_shinfo(head)->frag_list;
  488. skb_shinfo(head)->frag_list = NULL;
  489. for (i=0; i<skb_shinfo(head)->nr_frags; i++)
  490. plen += skb_shinfo(head)->frags[i].size;
  491. clone->len = clone->data_len = head->data_len - plen;
  492. head->data_len -= clone->len;
  493. head->len -= clone->len;
  494. clone->csum = 0;
  495. clone->ip_summed = head->ip_summed;
  496. atomic_add(clone->truesize, &ip_frag_mem);
  497. }
  498. skb_shinfo(head)->frag_list = head->next;
  499. skb_push(head, head->data - head->nh.raw);
  500. atomic_sub(head->truesize, &ip_frag_mem);
  501. for (fp=head->next; fp; fp = fp->next) {
  502. head->data_len += fp->len;
  503. head->len += fp->len;
  504. if (head->ip_summed != fp->ip_summed)
  505. head->ip_summed = CHECKSUM_NONE;
  506. else if (head->ip_summed == CHECKSUM_HW)
  507. head->csum = csum_add(head->csum, fp->csum);
  508. head->truesize += fp->truesize;
  509. atomic_sub(fp->truesize, &ip_frag_mem);
  510. }
  511. head->next = NULL;
  512. head->dev = dev;
  513. skb_set_timestamp(head, &qp->stamp);
  514. iph = head->nh.iph;
  515. iph->frag_off = 0;
  516. iph->tot_len = htons(len);
  517. IP_INC_STATS_BH(IPSTATS_MIB_REASMOKS);
  518. qp->fragments = NULL;
  519. return head;
  520. out_nomem:
  521. LIMIT_NETDEBUG(KERN_ERR "IP: queue_glue: no memory for gluing "
  522. "queue %p\n", qp);
  523. goto out_fail;
  524. out_oversize:
  525. if (net_ratelimit())
  526. printk(KERN_INFO
  527. "Oversized IP packet from %d.%d.%d.%d.\n",
  528. NIPQUAD(qp->saddr));
  529. out_fail:
  530. IP_INC_STATS_BH(IPSTATS_MIB_REASMFAILS);
  531. return NULL;
  532. }
  533. /* Process an incoming IP datagram fragment. */
  534. struct sk_buff *ip_defrag(struct sk_buff *skb, u32 user)
  535. {
  536. struct iphdr *iph = skb->nh.iph;
  537. struct ipq *qp;
  538. struct net_device *dev;
  539. IP_INC_STATS_BH(IPSTATS_MIB_REASMREQDS);
  540. /* Start by cleaning up the memory. */
  541. if (atomic_read(&ip_frag_mem) > sysctl_ipfrag_high_thresh)
  542. ip_evictor();
  543. dev = skb->dev;
  544. /* Lookup (or create) queue header */
  545. if ((qp = ip_find(iph, user)) != NULL) {
  546. struct sk_buff *ret = NULL;
  547. spin_lock(&qp->lock);
  548. ip_frag_queue(qp, skb);
  549. if (qp->last_in == (FIRST_IN|LAST_IN) &&
  550. qp->meat == qp->len)
  551. ret = ip_frag_reasm(qp, dev);
  552. spin_unlock(&qp->lock);
  553. ipq_put(qp, NULL);
  554. return ret;
  555. }
  556. IP_INC_STATS_BH(IPSTATS_MIB_REASMFAILS);
  557. kfree_skb(skb);
  558. return NULL;
  559. }
  560. void ipfrag_init(void)
  561. {
  562. ipfrag_hash_rnd = (u32) ((num_physpages ^ (num_physpages>>7)) ^
  563. (jiffies ^ (jiffies >> 6)));
  564. init_timer(&ipfrag_secret_timer);
  565. ipfrag_secret_timer.function = ipfrag_secret_rebuild;
  566. ipfrag_secret_timer.expires = jiffies + sysctl_ipfrag_secret_interval;
  567. add_timer(&ipfrag_secret_timer);
  568. }
  569. EXPORT_SYMBOL(ip_defrag);