Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * INET An implementation of the TCP/IP protocol suite for the LINUX |
| 4 | * operating system. INET is implemented using the BSD Socket |
| 5 | * interface as the means of communication with the user level. |
| 6 | * |
| 7 | * The IP fragmentation functionality. |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 8 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * Authors: Fred N. van Kempen <waltje@uWalt.NL.Mugnet.ORG> |
Alan Cox | 113aa83 | 2008-10-13 19:01:08 -0700 | [diff] [blame] | 10 | * Alan Cox <alan@lxorguk.ukuu.org.uk> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * |
| 12 | * Fixes: |
| 13 | * Alan Cox : Split from ip.c , see ip_input.c for history. |
| 14 | * David S. Miller : Begin massive cleanup... |
| 15 | * Andi Kleen : Add sysctls. |
| 16 | * xxxx : Overlapfrag bug. |
| 17 | * Ultima : ip_expire() kernel panic. |
| 18 | * Bill Hawes : Frag accounting and evictor fixes. |
| 19 | * John McDonald : 0 length frag bug. |
| 20 | * Alexey Kuznetsov: SMP races, threading, cleanup. |
| 21 | * Patrick McHardy : LRU queue of frag heads for evictor. |
| 22 | */ |
| 23 | |
Joe Perches | afd46503 | 2012-03-12 07:03:32 +0000 | [diff] [blame] | 24 | #define pr_fmt(fmt) "IPv4: " fmt |
| 25 | |
Herbert Xu | 89cee8b | 2005-12-13 23:14:27 -0800 | [diff] [blame] | 26 | #include <linux/compiler.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/module.h> |
| 28 | #include <linux/types.h> |
| 29 | #include <linux/mm.h> |
| 30 | #include <linux/jiffies.h> |
| 31 | #include <linux/skbuff.h> |
| 32 | #include <linux/list.h> |
| 33 | #include <linux/ip.h> |
| 34 | #include <linux/icmp.h> |
| 35 | #include <linux/netdevice.h> |
| 36 | #include <linux/jhash.h> |
| 37 | #include <linux/random.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 38 | #include <linux/slab.h> |
Shan Wei | e9017b5 | 2010-01-23 01:57:42 -0800 | [diff] [blame] | 39 | #include <net/route.h> |
| 40 | #include <net/dst.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <net/sock.h> |
| 42 | #include <net/ip.h> |
| 43 | #include <net/icmp.h> |
| 44 | #include <net/checksum.h> |
Herbert Xu | 89cee8b | 2005-12-13 23:14:27 -0800 | [diff] [blame] | 45 | #include <net/inetpeer.h> |
Pavel Emelyanov | 5ab11c9 | 2007-10-15 02:24:19 -0700 | [diff] [blame] | 46 | #include <net/inet_frag.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <linux/tcp.h> |
| 48 | #include <linux/udp.h> |
| 49 | #include <linux/inet.h> |
| 50 | #include <linux/netfilter_ipv4.h> |
Eric Dumazet | 6623e3b | 2011-01-05 07:52:55 +0000 | [diff] [blame] | 51 | #include <net/inet_ecn.h> |
David Ahern | 385add9 | 2015-09-29 20:07:13 -0700 | [diff] [blame] | 52 | #include <net/l3mdev.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | /* NOTE. Logic of IP defragmentation is parallel to corresponding IPv6 |
| 55 | * code now. If you change something here, _PLEASE_ update ipv6/reassembly.c |
| 56 | * as well. Or notify me, at least. --ANK |
| 57 | */ |
Nikolay Aleksandrov | d4ad4d2 | 2014-08-01 12:29:48 +0200 | [diff] [blame] | 58 | static const char ip_frag_cache_name[] = "ip4-frags"; |
Herbert Xu | 89cee8b | 2005-12-13 23:14:27 -0800 | [diff] [blame] | 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | /* Describe an entry in the "incomplete datagrams" queue. */ |
| 61 | struct ipq { |
Pavel Emelyanov | 5ab11c9 | 2007-10-15 02:24:19 -0700 | [diff] [blame] | 62 | struct inet_frag_queue q; |
| 63 | |
Eric Dumazet | 6623e3b | 2011-01-05 07:52:55 +0000 | [diff] [blame] | 64 | u8 ecn; /* RFC3168 support */ |
Florian Westphal | d6b915e | 2015-05-22 16:32:51 +0200 | [diff] [blame] | 65 | u16 max_df_size; /* largest frag with DF set seen */ |
Herbert Xu | 89cee8b | 2005-12-13 23:14:27 -0800 | [diff] [blame] | 66 | int iif; |
| 67 | unsigned int rid; |
| 68 | struct inet_peer *peer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | }; |
| 70 | |
Fabian Frederick | aa1f731 | 2014-11-04 20:44:04 +0100 | [diff] [blame] | 71 | static u8 ip4_frag_ecn(u8 tos) |
Eric Dumazet | 6623e3b | 2011-01-05 07:52:55 +0000 | [diff] [blame] | 72 | { |
Eric Dumazet | 5173cc0 | 2011-05-16 08:37:37 +0000 | [diff] [blame] | 73 | return 1 << (tos & INET_ECN_MASK); |
Eric Dumazet | 6623e3b | 2011-01-05 07:52:55 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Pavel Emelyanov | 7eb9515 | 2007-10-15 02:31:52 -0700 | [diff] [blame] | 76 | static struct inet_frags ip4_frags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
Peter Oskolkov | a4fd284 | 2018-08-11 20:27:25 +0000 | [diff] [blame] | 78 | static int ip_frag_reasm(struct ipq *qp, struct sk_buff *skb, |
| 79 | struct sk_buff *prev_tail, struct net_device *dev); |
Herbert Xu | 1706d58 | 2007-10-14 00:38:15 -0700 | [diff] [blame] | 80 | |
Pavel Emelyanov | abd6523 | 2007-10-17 19:47:21 -0700 | [diff] [blame] | 81 | |
Florian Westphal | 36c7778 | 2014-07-24 16:50:29 +0200 | [diff] [blame] | 82 | static void ip4_frag_init(struct inet_frag_queue *q, const void *a) |
Pavel Emelyanov | c6fda28 | 2007-10-17 19:46:47 -0700 | [diff] [blame] | 83 | { |
| 84 | struct ipq *qp = container_of(q, struct ipq, q); |
Eric Dumazet | a39aca6 | 2019-05-24 09:03:38 -0700 | [diff] [blame^] | 85 | struct net *net = q->fqdir->net; |
Gao feng | 54db0cc | 2012-06-08 01:21:40 +0000 | [diff] [blame] | 86 | |
Eric Dumazet | 648700f | 2018-03-31 12:58:49 -0700 | [diff] [blame] | 87 | const struct frag_v4_compare_key *key = a; |
Pavel Emelyanov | c6fda28 | 2007-10-17 19:46:47 -0700 | [diff] [blame] | 88 | |
Eric Dumazet | 648700f | 2018-03-31 12:58:49 -0700 | [diff] [blame] | 89 | q->key.v4 = *key; |
| 90 | qp->ecn = 0; |
Eric Dumazet | 6ce3b4d | 2019-05-24 09:03:30 -0700 | [diff] [blame] | 91 | qp->peer = q->fqdir->max_dist ? |
Eric Dumazet | 648700f | 2018-03-31 12:58:49 -0700 | [diff] [blame] | 92 | inet_getpeer_v4(net->ipv4.peers, key->saddr, key->vif, 1) : |
David Ahern | 192132b | 2015-08-27 16:07:03 -0700 | [diff] [blame] | 93 | NULL; |
Pavel Emelyanov | c6fda28 | 2007-10-17 19:46:47 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Fabian Frederick | aa1f731 | 2014-11-04 20:44:04 +0100 | [diff] [blame] | 96 | static void ip4_frag_free(struct inet_frag_queue *q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | { |
Pavel Emelyanov | 1e4b828 | 2007-10-15 02:39:14 -0700 | [diff] [blame] | 98 | struct ipq *qp; |
| 99 | |
| 100 | qp = container_of(q, struct ipq, q); |
| 101 | if (qp->peer) |
| 102 | inet_putpeer(qp->peer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | /* Destruction primitives. */ |
| 107 | |
Fabian Frederick | aa1f731 | 2014-11-04 20:44:04 +0100 | [diff] [blame] | 108 | static void ipq_put(struct ipq *ipq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | { |
Eric Dumazet | 093ba72 | 2018-03-31 12:58:44 -0700 | [diff] [blame] | 110 | inet_frag_put(&ipq->q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | /* Kill ipq entry. It is not destroyed immediately, |
| 114 | * because caller (and someone more) holds reference count. |
| 115 | */ |
| 116 | static void ipq_kill(struct ipq *ipq) |
| 117 | { |
Eric Dumazet | 093ba72 | 2018-03-31 12:58:44 -0700 | [diff] [blame] | 118 | inet_frag_kill(&ipq->q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Andy Zhou | 5cf4228 | 2015-05-15 14:15:35 -0700 | [diff] [blame] | 121 | static bool frag_expire_skip_icmp(u32 user) |
| 122 | { |
| 123 | return user == IP_DEFRAG_AF_PACKET || |
| 124 | ip_defrag_user_in_between(user, IP_DEFRAG_CONNTRACK_IN, |
Andy Zhou | 8bc0486 | 2015-05-15 14:15:36 -0700 | [diff] [blame] | 125 | __IP_DEFRAG_CONNTRACK_IN_END) || |
| 126 | ip_defrag_user_in_between(user, IP_DEFRAG_CONNTRACK_BRIDGE_IN, |
| 127 | __IP_DEFRAG_CONNTRACK_BRIDGE_IN); |
Andy Zhou | 5cf4228 | 2015-05-15 14:15:35 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | /* |
| 131 | * Oops, a fragment queue timed out. Kill it and send an ICMP reply. |
| 132 | */ |
Kees Cook | 7880201 | 2017-10-16 17:29:20 -0700 | [diff] [blame] | 133 | static void ip_expire(struct timer_list *t) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | { |
Kees Cook | 7880201 | 2017-10-16 17:29:20 -0700 | [diff] [blame] | 135 | struct inet_frag_queue *frag = from_timer(frag, t, timer); |
Eric Dumazet | 399d140 | 2018-03-31 12:58:51 -0700 | [diff] [blame] | 136 | const struct iphdr *iph; |
Peter Oskolkov | fa0f527 | 2018-08-02 23:34:39 +0000 | [diff] [blame] | 137 | struct sk_buff *head = NULL; |
Pavel Emelyanov | 84a3aa0 | 2008-07-16 20:19:08 -0700 | [diff] [blame] | 138 | struct net *net; |
Eric Dumazet | 399d140 | 2018-03-31 12:58:51 -0700 | [diff] [blame] | 139 | struct ipq *qp; |
| 140 | int err; |
Pavel Emelyanov | e521db9 | 2007-10-17 19:45:23 -0700 | [diff] [blame] | 141 | |
Kees Cook | 7880201 | 2017-10-16 17:29:20 -0700 | [diff] [blame] | 142 | qp = container_of(frag, struct ipq, q); |
Eric Dumazet | a39aca6 | 2019-05-24 09:03:38 -0700 | [diff] [blame^] | 143 | net = qp->q.fqdir->net; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
Eric Dumazet | ec4fbd6 | 2017-03-22 08:57:15 -0700 | [diff] [blame] | 145 | rcu_read_lock(); |
Pavel Emelyanov | 5ab11c9 | 2007-10-15 02:24:19 -0700 | [diff] [blame] | 146 | spin_lock(&qp->q.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
Nikolay Aleksandrov | 06aa8b8 | 2014-08-01 12:29:44 +0200 | [diff] [blame] | 148 | if (qp->q.flags & INET_FRAG_COMPLETE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | goto out; |
| 150 | |
| 151 | ipq_kill(qp); |
Eric Dumazet | b45386e | 2016-04-27 16:44:35 -0700 | [diff] [blame] | 152 | __IP_INC_STATS(net, IPSTATS_MIB_REASMFAILS); |
Eric Dumazet | 399d140 | 2018-03-31 12:58:51 -0700 | [diff] [blame] | 153 | __IP_INC_STATS(net, IPSTATS_MIB_REASMTIMEOUT); |
Nikolay Aleksandrov | 2e404f6 | 2014-08-01 12:29:47 +0200 | [diff] [blame] | 154 | |
Dan Carpenter | 70837ff | 2018-08-06 22:17:35 +0300 | [diff] [blame] | 155 | if (!(qp->q.flags & INET_FRAG_FIRST_IN)) |
Eric Dumazet | 399d140 | 2018-03-31 12:58:51 -0700 | [diff] [blame] | 156 | goto out; |
Nikolay Aleksandrov | 2e404f6 | 2014-08-01 12:29:47 +0200 | [diff] [blame] | 157 | |
Peter Oskolkov | fa0f527 | 2018-08-02 23:34:39 +0000 | [diff] [blame] | 158 | /* sk_buff::dev and sk_buff::rbnode are unionized. So we |
| 159 | * pull the head out of the tree in order to be able to |
| 160 | * deal with head->dev. |
| 161 | */ |
Peter Oskolkov | c23f35d | 2019-01-22 10:02:50 -0800 | [diff] [blame] | 162 | head = inet_frag_pull_head(&qp->q); |
| 163 | if (!head) |
| 164 | goto out; |
Eric Dumazet | 399d140 | 2018-03-31 12:58:51 -0700 | [diff] [blame] | 165 | head->dev = dev_get_by_index_rcu(net, qp->iif); |
| 166 | if (!head->dev) |
| 167 | goto out; |
Eric Dumazet | ec4fbd6 | 2017-03-22 08:57:15 -0700 | [diff] [blame] | 168 | |
Shan Wei | e9017b5 | 2010-01-23 01:57:42 -0800 | [diff] [blame] | 169 | |
Eric Dumazet | 399d140 | 2018-03-31 12:58:51 -0700 | [diff] [blame] | 170 | /* skb has no dst, perform route lookup again */ |
| 171 | iph = ip_hdr(head); |
| 172 | err = ip_route_input_noref(head, iph->daddr, iph->saddr, |
David S. Miller | c6cffba | 2012-07-26 11:14:38 +0000 | [diff] [blame] | 173 | iph->tos, head->dev); |
Eric Dumazet | 399d140 | 2018-03-31 12:58:51 -0700 | [diff] [blame] | 174 | if (err) |
| 175 | goto out; |
Eric Dumazet | 64f3b9e | 2011-05-04 10:02:26 +0000 | [diff] [blame] | 176 | |
Eric Dumazet | 399d140 | 2018-03-31 12:58:51 -0700 | [diff] [blame] | 177 | /* Only an end host needs to send an ICMP |
| 178 | * "Fragment Reassembly Timeout" message, per RFC792. |
| 179 | */ |
| 180 | if (frag_expire_skip_icmp(qp->q.key.v4.user) && |
| 181 | (skb_rtable(head)->rt_type != RTN_LOCAL)) |
| 182 | goto out; |
Eric Dumazet | ec4fbd6 | 2017-03-22 08:57:15 -0700 | [diff] [blame] | 183 | |
Eric Dumazet | 1eec5d5 | 2018-03-31 12:58:54 -0700 | [diff] [blame] | 184 | spin_unlock(&qp->q.lock); |
| 185 | icmp_send(head, ICMP_TIME_EXCEEDED, ICMP_EXC_FRAGTIME, 0); |
Eric Dumazet | 1eec5d5 | 2018-03-31 12:58:54 -0700 | [diff] [blame] | 186 | goto out_rcu_unlock; |
Shan Wei | e9017b5 | 2010-01-23 01:57:42 -0800 | [diff] [blame] | 187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | out: |
Pavel Emelyanov | 5ab11c9 | 2007-10-15 02:24:19 -0700 | [diff] [blame] | 189 | spin_unlock(&qp->q.lock); |
Eric Dumazet | ec4fbd6 | 2017-03-22 08:57:15 -0700 | [diff] [blame] | 190 | out_rcu_unlock: |
| 191 | rcu_read_unlock(); |
zhong jiang | 1d08962 | 2018-09-20 17:37:43 +0800 | [diff] [blame] | 192 | kfree_skb(head); |
Pavel Emelyanov | 4b6cb5d | 2007-10-15 02:41:09 -0700 | [diff] [blame] | 193 | ipq_put(qp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Pavel Emelyanov | abd6523 | 2007-10-17 19:47:21 -0700 | [diff] [blame] | 196 | /* Find the correct entry in the "incomplete datagrams" queue for |
| 197 | * this IP datagram, and create new one, if nothing is found. |
| 198 | */ |
David Ahern | 9972f13 | 2015-08-13 14:59:09 -0600 | [diff] [blame] | 199 | static struct ipq *ip_find(struct net *net, struct iphdr *iph, |
| 200 | u32 user, int vif) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | { |
Eric Dumazet | 648700f | 2018-03-31 12:58:49 -0700 | [diff] [blame] | 202 | struct frag_v4_compare_key key = { |
| 203 | .saddr = iph->saddr, |
| 204 | .daddr = iph->daddr, |
| 205 | .user = user, |
| 206 | .vif = vif, |
| 207 | .id = iph->id, |
| 208 | .protocol = iph->protocol, |
| 209 | }; |
Pavel Emelyanov | c6fda28 | 2007-10-17 19:46:47 -0700 | [diff] [blame] | 210 | struct inet_frag_queue *q; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
Eric Dumazet | 803fdd9 | 2019-05-24 09:03:32 -0700 | [diff] [blame] | 212 | q = inet_frag_find(&net->ipv4.fqdir, &key); |
Eric Dumazet | 2d44ed2 | 2018-03-31 12:58:52 -0700 | [diff] [blame] | 213 | if (!q) |
Hannes Frederic Sowa | 5a3da1f | 2013-03-15 11:32:30 +0000 | [diff] [blame] | 214 | return NULL; |
Eric Dumazet | 2d44ed2 | 2018-03-31 12:58:52 -0700 | [diff] [blame] | 215 | |
Pavel Emelyanov | c6fda28 | 2007-10-17 19:46:47 -0700 | [diff] [blame] | 216 | return container_of(q, struct ipq, q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Herbert Xu | 89cee8b | 2005-12-13 23:14:27 -0800 | [diff] [blame] | 219 | /* Is the fragment too far ahead to be part of ipq? */ |
Fabian Frederick | aa1f731 | 2014-11-04 20:44:04 +0100 | [diff] [blame] | 220 | static int ip_frag_too_far(struct ipq *qp) |
Herbert Xu | 89cee8b | 2005-12-13 23:14:27 -0800 | [diff] [blame] | 221 | { |
| 222 | struct inet_peer *peer = qp->peer; |
Eric Dumazet | 6ce3b4d | 2019-05-24 09:03:30 -0700 | [diff] [blame] | 223 | unsigned int max = qp->q.fqdir->max_dist; |
Herbert Xu | 89cee8b | 2005-12-13 23:14:27 -0800 | [diff] [blame] | 224 | unsigned int start, end; |
| 225 | |
| 226 | int rc; |
| 227 | |
| 228 | if (!peer || !max) |
| 229 | return 0; |
| 230 | |
| 231 | start = qp->rid; |
| 232 | end = atomic_inc_return(&peer->rid); |
| 233 | qp->rid = end; |
| 234 | |
Peter Oskolkov | fa0f527 | 2018-08-02 23:34:39 +0000 | [diff] [blame] | 235 | rc = qp->q.fragments_tail && (end - start) > max; |
Herbert Xu | 89cee8b | 2005-12-13 23:14:27 -0800 | [diff] [blame] | 236 | |
Eric Dumazet | a39aca6 | 2019-05-24 09:03:38 -0700 | [diff] [blame^] | 237 | if (rc) |
| 238 | __IP_INC_STATS(qp->q.fqdir->net, IPSTATS_MIB_REASMFAILS); |
Herbert Xu | 89cee8b | 2005-12-13 23:14:27 -0800 | [diff] [blame] | 239 | |
| 240 | return rc; |
| 241 | } |
| 242 | |
| 243 | static int ip_frag_reinit(struct ipq *qp) |
| 244 | { |
Jesper Dangaard Brouer | d433673 | 2013-01-28 23:45:12 +0000 | [diff] [blame] | 245 | unsigned int sum_truesize = 0; |
Herbert Xu | 89cee8b | 2005-12-13 23:14:27 -0800 | [diff] [blame] | 246 | |
Eric Dumazet | 6ce3b4d | 2019-05-24 09:03:30 -0700 | [diff] [blame] | 247 | if (!mod_timer(&qp->q.timer, jiffies + qp->q.fqdir->timeout)) { |
Reshetova, Elena | edcb691 | 2017-06-30 13:08:07 +0300 | [diff] [blame] | 248 | refcount_inc(&qp->q.refcnt); |
Herbert Xu | 89cee8b | 2005-12-13 23:14:27 -0800 | [diff] [blame] | 249 | return -ETIMEDOUT; |
| 250 | } |
| 251 | |
Peter Oskolkov | a4fd284 | 2018-08-11 20:27:25 +0000 | [diff] [blame] | 252 | sum_truesize = inet_frag_rbtree_purge(&qp->q.rb_fragments); |
Eric Dumazet | 6ce3b4d | 2019-05-24 09:03:30 -0700 | [diff] [blame] | 253 | sub_frag_mem_limit(qp->q.fqdir, sum_truesize); |
Herbert Xu | 89cee8b | 2005-12-13 23:14:27 -0800 | [diff] [blame] | 254 | |
Nikolay Aleksandrov | 06aa8b8 | 2014-08-01 12:29:44 +0200 | [diff] [blame] | 255 | qp->q.flags = 0; |
Pavel Emelyanov | 5ab11c9 | 2007-10-15 02:24:19 -0700 | [diff] [blame] | 256 | qp->q.len = 0; |
| 257 | qp->q.meat = 0; |
Peter Oskolkov | fa0f527 | 2018-08-02 23:34:39 +0000 | [diff] [blame] | 258 | qp->q.rb_fragments = RB_ROOT; |
Changli Gao | d6bebca | 2010-06-29 04:39:37 +0000 | [diff] [blame] | 259 | qp->q.fragments_tail = NULL; |
Peter Oskolkov | a4fd284 | 2018-08-11 20:27:25 +0000 | [diff] [blame] | 260 | qp->q.last_run_head = NULL; |
Herbert Xu | 89cee8b | 2005-12-13 23:14:27 -0800 | [diff] [blame] | 261 | qp->iif = 0; |
Eric Dumazet | 6623e3b | 2011-01-05 07:52:55 +0000 | [diff] [blame] | 262 | qp->ecn = 0; |
Herbert Xu | 89cee8b | 2005-12-13 23:14:27 -0800 | [diff] [blame] | 263 | |
| 264 | return 0; |
| 265 | } |
| 266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | /* Add new segment to existing queue. */ |
Herbert Xu | 1706d58 | 2007-10-14 00:38:15 -0700 | [diff] [blame] | 268 | static int ip_frag_queue(struct ipq *qp, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | { |
Eric Dumazet | a39aca6 | 2019-05-24 09:03:38 -0700 | [diff] [blame^] | 270 | struct net *net = qp->q.fqdir->net; |
Peter Oskolkov | c23f35d | 2019-01-22 10:02:50 -0800 | [diff] [blame] | 271 | int ihl, end, flags, offset; |
| 272 | struct sk_buff *prev_tail; |
Herbert Xu | 1706d58 | 2007-10-14 00:38:15 -0700 | [diff] [blame] | 273 | struct net_device *dev; |
Florian Westphal | d6b915e | 2015-05-22 16:32:51 +0200 | [diff] [blame] | 274 | unsigned int fragsize; |
Herbert Xu | 1706d58 | 2007-10-14 00:38:15 -0700 | [diff] [blame] | 275 | int err = -ENOENT; |
Eric Dumazet | 6623e3b | 2011-01-05 07:52:55 +0000 | [diff] [blame] | 276 | u8 ecn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
Nikolay Aleksandrov | 06aa8b8 | 2014-08-01 12:29:44 +0200 | [diff] [blame] | 278 | if (qp->q.flags & INET_FRAG_COMPLETE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | goto err; |
| 280 | |
Herbert Xu | 89cee8b | 2005-12-13 23:14:27 -0800 | [diff] [blame] | 281 | if (!(IPCB(skb)->flags & IPSKB_FRAG_COMPLETE) && |
Herbert Xu | 1706d58 | 2007-10-14 00:38:15 -0700 | [diff] [blame] | 282 | unlikely(ip_frag_too_far(qp)) && |
| 283 | unlikely(err = ip_frag_reinit(qp))) { |
Herbert Xu | 89cee8b | 2005-12-13 23:14:27 -0800 | [diff] [blame] | 284 | ipq_kill(qp); |
| 285 | goto err; |
| 286 | } |
| 287 | |
Eric Dumazet | 6623e3b | 2011-01-05 07:52:55 +0000 | [diff] [blame] | 288 | ecn = ip4_frag_ecn(ip_hdr(skb)->tos); |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 289 | offset = ntohs(ip_hdr(skb)->frag_off); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | flags = offset & ~IP_OFFSET; |
| 291 | offset &= IP_OFFSET; |
| 292 | offset <<= 3; /* offset is in 8-byte chunks */ |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 293 | ihl = ip_hdrlen(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | |
| 295 | /* Determine the position of this fragment. */ |
Edward Hyunkoo Jee | 0848f64 | 2015-07-21 09:43:59 +0200 | [diff] [blame] | 296 | end = offset + skb->len - skb_network_offset(skb) - ihl; |
Herbert Xu | 1706d58 | 2007-10-14 00:38:15 -0700 | [diff] [blame] | 297 | err = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
| 299 | /* Is this the final fragment? */ |
| 300 | if ((flags & IP_MF) == 0) { |
| 301 | /* If we already have some bits beyond end |
Justin P. Mattock | 42b2aa8 | 2011-11-28 20:31:00 -0800 | [diff] [blame] | 302 | * or have different end, the segment is corrupted. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | */ |
Pavel Emelyanov | 5ab11c9 | 2007-10-15 02:24:19 -0700 | [diff] [blame] | 304 | if (end < qp->q.len || |
Nikolay Aleksandrov | 06aa8b8 | 2014-08-01 12:29:44 +0200 | [diff] [blame] | 305 | ((qp->q.flags & INET_FRAG_LAST_IN) && end != qp->q.len)) |
Peter Oskolkov | 0ff89ef | 2018-08-28 11:36:19 -0700 | [diff] [blame] | 306 | goto discard_qp; |
Nikolay Aleksandrov | 06aa8b8 | 2014-08-01 12:29:44 +0200 | [diff] [blame] | 307 | qp->q.flags |= INET_FRAG_LAST_IN; |
Pavel Emelyanov | 5ab11c9 | 2007-10-15 02:24:19 -0700 | [diff] [blame] | 308 | qp->q.len = end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | } else { |
| 310 | if (end&7) { |
| 311 | end &= ~7; |
| 312 | if (skb->ip_summed != CHECKSUM_UNNECESSARY) |
| 313 | skb->ip_summed = CHECKSUM_NONE; |
| 314 | } |
Pavel Emelyanov | 5ab11c9 | 2007-10-15 02:24:19 -0700 | [diff] [blame] | 315 | if (end > qp->q.len) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | /* Some bits beyond end -> corruption. */ |
Nikolay Aleksandrov | 06aa8b8 | 2014-08-01 12:29:44 +0200 | [diff] [blame] | 317 | if (qp->q.flags & INET_FRAG_LAST_IN) |
Peter Oskolkov | 0ff89ef | 2018-08-28 11:36:19 -0700 | [diff] [blame] | 318 | goto discard_qp; |
Pavel Emelyanov | 5ab11c9 | 2007-10-15 02:24:19 -0700 | [diff] [blame] | 319 | qp->q.len = end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | if (end == offset) |
Peter Oskolkov | 0ff89ef | 2018-08-28 11:36:19 -0700 | [diff] [blame] | 323 | goto discard_qp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
Herbert Xu | 1706d58 | 2007-10-14 00:38:15 -0700 | [diff] [blame] | 325 | err = -ENOMEM; |
Edward Hyunkoo Jee | 0848f64 | 2015-07-21 09:43:59 +0200 | [diff] [blame] | 326 | if (!pskb_pull(skb, skb_network_offset(skb) + ihl)) |
Peter Oskolkov | 0ff89ef | 2018-08-28 11:36:19 -0700 | [diff] [blame] | 327 | goto discard_qp; |
Herbert Xu | 1706d58 | 2007-10-14 00:38:15 -0700 | [diff] [blame] | 328 | |
| 329 | err = pskb_trim_rcsum(skb, end - offset); |
| 330 | if (err) |
Peter Oskolkov | 0ff89ef | 2018-08-28 11:36:19 -0700 | [diff] [blame] | 331 | goto discard_qp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
Peter Oskolkov | fa0f527 | 2018-08-02 23:34:39 +0000 | [diff] [blame] | 333 | /* Note : skb->rbnode and skb->dev share the same location. */ |
| 334 | dev = skb->dev; |
| 335 | /* Makes sure compiler wont do silly aliasing games */ |
| 336 | barrier(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | |
Peter Oskolkov | a4fd284 | 2018-08-11 20:27:25 +0000 | [diff] [blame] | 338 | prev_tail = qp->q.fragments_tail; |
Peter Oskolkov | c23f35d | 2019-01-22 10:02:50 -0800 | [diff] [blame] | 339 | err = inet_frag_queue_insert(&qp->q, skb, offset, end); |
| 340 | if (err) |
| 341 | goto insert_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
Eric Dumazet | bf66337 | 2018-03-31 12:58:58 -0700 | [diff] [blame] | 343 | if (dev) |
| 344 | qp->iif = dev->ifindex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
Pavel Emelyanov | 5ab11c9 | 2007-10-15 02:24:19 -0700 | [diff] [blame] | 346 | qp->q.stamp = skb->tstamp; |
| 347 | qp->q.meat += skb->len; |
Eric Dumazet | 6623e3b | 2011-01-05 07:52:55 +0000 | [diff] [blame] | 348 | qp->ecn |= ecn; |
Eric Dumazet | 6ce3b4d | 2019-05-24 09:03:30 -0700 | [diff] [blame] | 349 | add_frag_mem_limit(qp->q.fqdir, skb->truesize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | if (offset == 0) |
Nikolay Aleksandrov | 06aa8b8 | 2014-08-01 12:29:44 +0200 | [diff] [blame] | 351 | qp->q.flags |= INET_FRAG_FIRST_IN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | |
Florian Westphal | d6b915e | 2015-05-22 16:32:51 +0200 | [diff] [blame] | 353 | fragsize = skb->len + ihl; |
| 354 | |
| 355 | if (fragsize > qp->q.max_size) |
| 356 | qp->q.max_size = fragsize; |
| 357 | |
Patrick McHardy | 5f2d04f | 2012-08-26 19:13:55 +0200 | [diff] [blame] | 358 | if (ip_hdr(skb)->frag_off & htons(IP_DF) && |
Florian Westphal | d6b915e | 2015-05-22 16:32:51 +0200 | [diff] [blame] | 359 | fragsize > qp->max_df_size) |
| 360 | qp->max_df_size = fragsize; |
Patrick McHardy | 5f2d04f | 2012-08-26 19:13:55 +0200 | [diff] [blame] | 361 | |
Nikolay Aleksandrov | 06aa8b8 | 2014-08-01 12:29:44 +0200 | [diff] [blame] | 362 | if (qp->q.flags == (INET_FRAG_FIRST_IN | INET_FRAG_LAST_IN) && |
Eric Dumazet | 97599dc | 2013-04-16 12:55:41 +0000 | [diff] [blame] | 363 | qp->q.meat == qp->q.len) { |
| 364 | unsigned long orefdst = skb->_skb_refdst; |
Herbert Xu | 1706d58 | 2007-10-14 00:38:15 -0700 | [diff] [blame] | 365 | |
Eric Dumazet | 97599dc | 2013-04-16 12:55:41 +0000 | [diff] [blame] | 366 | skb->_skb_refdst = 0UL; |
Peter Oskolkov | a4fd284 | 2018-08-11 20:27:25 +0000 | [diff] [blame] | 367 | err = ip_frag_reasm(qp, skb, prev_tail, dev); |
Eric Dumazet | 97599dc | 2013-04-16 12:55:41 +0000 | [diff] [blame] | 368 | skb->_skb_refdst = orefdst; |
Peter Oskolkov | 0ff89ef | 2018-08-28 11:36:19 -0700 | [diff] [blame] | 369 | if (err) |
| 370 | inet_frag_kill(&qp->q); |
Eric Dumazet | 97599dc | 2013-04-16 12:55:41 +0000 | [diff] [blame] | 371 | return err; |
| 372 | } |
| 373 | |
| 374 | skb_dst_drop(skb); |
Herbert Xu | 1706d58 | 2007-10-14 00:38:15 -0700 | [diff] [blame] | 375 | return -EINPROGRESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | |
Peter Oskolkov | c23f35d | 2019-01-22 10:02:50 -0800 | [diff] [blame] | 377 | insert_error: |
| 378 | if (err == IPFRAG_DUP) { |
| 379 | kfree_skb(skb); |
| 380 | return -EINVAL; |
| 381 | } |
| 382 | err = -EINVAL; |
Peter Oskolkov | 0ff89ef | 2018-08-28 11:36:19 -0700 | [diff] [blame] | 383 | __IP_INC_STATS(net, IPSTATS_MIB_REASM_OVERLAPS); |
Peter Oskolkov | 7969e5c | 2018-08-02 23:34:37 +0000 | [diff] [blame] | 384 | discard_qp: |
| 385 | inet_frag_kill(&qp->q); |
Peter Oskolkov | c23f35d | 2019-01-22 10:02:50 -0800 | [diff] [blame] | 386 | __IP_INC_STATS(net, IPSTATS_MIB_REASMFAILS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | err: |
| 388 | kfree_skb(skb); |
Herbert Xu | 1706d58 | 2007-10-14 00:38:15 -0700 | [diff] [blame] | 389 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | /* Build a new IP datagram from all its fragments. */ |
Peter Oskolkov | fa0f527 | 2018-08-02 23:34:39 +0000 | [diff] [blame] | 393 | static int ip_frag_reasm(struct ipq *qp, struct sk_buff *skb, |
Peter Oskolkov | a4fd284 | 2018-08-11 20:27:25 +0000 | [diff] [blame] | 394 | struct sk_buff *prev_tail, struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | { |
Eric Dumazet | a39aca6 | 2019-05-24 09:03:38 -0700 | [diff] [blame^] | 396 | struct net *net = qp->q.fqdir->net; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | struct iphdr *iph; |
Peter Oskolkov | c23f35d | 2019-01-22 10:02:50 -0800 | [diff] [blame] | 398 | void *reasm_data; |
| 399 | int len, err; |
Eric Dumazet | 5173cc0 | 2011-05-16 08:37:37 +0000 | [diff] [blame] | 400 | u8 ecn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | |
| 402 | ipq_kill(qp); |
| 403 | |
Hannes Frederic Sowa | be99197 | 2013-03-22 08:24:37 +0000 | [diff] [blame] | 404 | ecn = ip_frag_ecn_table[qp->ecn]; |
Eric Dumazet | 5173cc0 | 2011-05-16 08:37:37 +0000 | [diff] [blame] | 405 | if (unlikely(ecn == 0xff)) { |
| 406 | err = -EINVAL; |
| 407 | goto out_fail; |
| 408 | } |
Peter Oskolkov | c23f35d | 2019-01-22 10:02:50 -0800 | [diff] [blame] | 409 | |
Herbert Xu | 1706d58 | 2007-10-14 00:38:15 -0700 | [diff] [blame] | 410 | /* Make the one we just received the head. */ |
Peter Oskolkov | c23f35d | 2019-01-22 10:02:50 -0800 | [diff] [blame] | 411 | reasm_data = inet_frag_reasm_prepare(&qp->q, skb, prev_tail); |
| 412 | if (!reasm_data) |
| 413 | goto out_nomem; |
Herbert Xu | 1706d58 | 2007-10-14 00:38:15 -0700 | [diff] [blame] | 414 | |
Peter Oskolkov | c23f35d | 2019-01-22 10:02:50 -0800 | [diff] [blame] | 415 | len = ip_hdrlen(skb) + qp->q.len; |
Herbert Xu | 1706d58 | 2007-10-14 00:38:15 -0700 | [diff] [blame] | 416 | err = -E2BIG; |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 417 | if (len > 65535) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | goto out_oversize; |
| 419 | |
Peter Oskolkov | c23f35d | 2019-01-22 10:02:50 -0800 | [diff] [blame] | 420 | inet_frag_reasm_finish(&qp->q, skb, reasm_data); |
Jiri Wiesner | ebaf39e | 2018-12-05 16:55:29 +0100 | [diff] [blame] | 421 | |
Peter Oskolkov | c23f35d | 2019-01-22 10:02:50 -0800 | [diff] [blame] | 422 | skb->dev = dev; |
| 423 | IPCB(skb)->frag_max_size = max(qp->max_df_size, qp->q.max_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | |
Peter Oskolkov | c23f35d | 2019-01-22 10:02:50 -0800 | [diff] [blame] | 425 | iph = ip_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | iph->tot_len = htons(len); |
Eric Dumazet | 5173cc0 | 2011-05-16 08:37:37 +0000 | [diff] [blame] | 427 | iph->tos |= ecn; |
Florian Westphal | d6b915e | 2015-05-22 16:32:51 +0200 | [diff] [blame] | 428 | |
| 429 | /* When we set IP_DF on a refragmented skb we must also force a |
| 430 | * call to ip_fragment to avoid forwarding a DF-skb of size s while |
| 431 | * original sender only sent fragments of size f (where f < s). |
| 432 | * |
| 433 | * We only set DF/IPSKB_FRAG_PMTU if such DF fragment was the largest |
| 434 | * frag seen to avoid sending tiny DF-fragments in case skb was built |
| 435 | * from one very small df-fragment and one large non-df frag. |
| 436 | */ |
| 437 | if (qp->max_df_size == qp->q.max_size) { |
Peter Oskolkov | c23f35d | 2019-01-22 10:02:50 -0800 | [diff] [blame] | 438 | IPCB(skb)->flags |= IPSKB_FRAG_PMTU; |
Florian Westphal | d6b915e | 2015-05-22 16:32:51 +0200 | [diff] [blame] | 439 | iph->frag_off = htons(IP_DF); |
| 440 | } else { |
| 441 | iph->frag_off = 0; |
| 442 | } |
| 443 | |
Edward Hyunkoo Jee | 0848f64 | 2015-07-21 09:43:59 +0200 | [diff] [blame] | 444 | ip_send_check(iph); |
| 445 | |
Eric Dumazet | b45386e | 2016-04-27 16:44:35 -0700 | [diff] [blame] | 446 | __IP_INC_STATS(net, IPSTATS_MIB_REASMOKS); |
Peter Oskolkov | fa0f527 | 2018-08-02 23:34:39 +0000 | [diff] [blame] | 447 | qp->q.rb_fragments = RB_ROOT; |
Changli Gao | d6bebca | 2010-06-29 04:39:37 +0000 | [diff] [blame] | 448 | qp->q.fragments_tail = NULL; |
Peter Oskolkov | a4fd284 | 2018-08-11 20:27:25 +0000 | [diff] [blame] | 449 | qp->q.last_run_head = NULL; |
Herbert Xu | 1706d58 | 2007-10-14 00:38:15 -0700 | [diff] [blame] | 450 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
| 452 | out_nomem: |
Joe Perches | ba7a46f | 2014-11-11 10:59:17 -0800 | [diff] [blame] | 453 | net_dbg_ratelimited("queue_glue: no memory for gluing queue %p\n", qp); |
David Howells | 4554247 | 2007-10-17 21:37:22 -0700 | [diff] [blame] | 454 | err = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | goto out_fail; |
| 456 | out_oversize: |
Eric Dumazet | 648700f | 2018-03-31 12:58:49 -0700 | [diff] [blame] | 457 | net_info_ratelimited("Oversized IP packet from %pI4\n", &qp->q.key.v4.saddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | out_fail: |
Eric Dumazet | b45386e | 2016-04-27 16:44:35 -0700 | [diff] [blame] | 459 | __IP_INC_STATS(net, IPSTATS_MIB_REASMFAILS); |
Herbert Xu | 1706d58 | 2007-10-14 00:38:15 -0700 | [diff] [blame] | 460 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | /* Process an incoming IP datagram fragment. */ |
Eric W. Biederman | 19bcf9f | 2015-10-09 13:44:54 -0500 | [diff] [blame] | 464 | int ip_defrag(struct net *net, struct sk_buff *skb, u32 user) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | { |
David Ahern | 9972f13 | 2015-08-13 14:59:09 -0600 | [diff] [blame] | 466 | struct net_device *dev = skb->dev ? : skb_dst(skb)->dev; |
David Ahern | 385add9 | 2015-09-29 20:07:13 -0700 | [diff] [blame] | 467 | int vif = l3mdev_master_ifindex_rcu(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | struct ipq *qp; |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 469 | |
Eric Dumazet | b45386e | 2016-04-27 16:44:35 -0700 | [diff] [blame] | 470 | __IP_INC_STATS(net, IPSTATS_MIB_REASMREQDS); |
Joe Stringer | 8282f27 | 2016-01-22 15:49:12 -0800 | [diff] [blame] | 471 | skb_orphan(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | /* Lookup (or create) queue header */ |
David Ahern | 9972f13 | 2015-08-13 14:59:09 -0600 | [diff] [blame] | 474 | qp = ip_find(net, ip_hdr(skb), user, vif); |
Ian Morris | 00db412 | 2015-04-03 09:17:27 +0100 | [diff] [blame] | 475 | if (qp) { |
Herbert Xu | 1706d58 | 2007-10-14 00:38:15 -0700 | [diff] [blame] | 476 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | |
Pavel Emelyanov | 5ab11c9 | 2007-10-15 02:24:19 -0700 | [diff] [blame] | 478 | spin_lock(&qp->q.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | |
Herbert Xu | 1706d58 | 2007-10-14 00:38:15 -0700 | [diff] [blame] | 480 | ret = ip_frag_queue(qp, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | |
Pavel Emelyanov | 5ab11c9 | 2007-10-15 02:24:19 -0700 | [diff] [blame] | 482 | spin_unlock(&qp->q.lock); |
Pavel Emelyanov | 4b6cb5d | 2007-10-15 02:41:09 -0700 | [diff] [blame] | 483 | ipq_put(qp); |
Herbert Xu | 776c729 | 2007-10-14 00:38:32 -0700 | [diff] [blame] | 484 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | } |
| 486 | |
Eric Dumazet | b45386e | 2016-04-27 16:44:35 -0700 | [diff] [blame] | 487 | __IP_INC_STATS(net, IPSTATS_MIB_REASMFAILS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | kfree_skb(skb); |
Herbert Xu | 776c729 | 2007-10-14 00:38:32 -0700 | [diff] [blame] | 489 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | } |
Eric Dumazet | 4bc2f18 | 2010-07-09 21:22:10 +0000 | [diff] [blame] | 491 | EXPORT_SYMBOL(ip_defrag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | |
Eric W. Biederman | 19bcf9f | 2015-10-09 13:44:54 -0500 | [diff] [blame] | 493 | struct sk_buff *ip_check_defrag(struct net *net, struct sk_buff *skb, u32 user) |
Eric Dumazet | bc416d9 | 2011-10-06 10:28:31 +0000 | [diff] [blame] | 494 | { |
Johannes Berg | 1bf3751 | 2012-12-09 23:41:06 +0000 | [diff] [blame] | 495 | struct iphdr iph; |
Alexander Drozdov | 3e32e73 | 2015-03-05 10:29:39 +0300 | [diff] [blame] | 496 | int netoff; |
Eric Dumazet | bc416d9 | 2011-10-06 10:28:31 +0000 | [diff] [blame] | 497 | u32 len; |
| 498 | |
| 499 | if (skb->protocol != htons(ETH_P_IP)) |
| 500 | return skb; |
| 501 | |
Alexander Drozdov | 3e32e73 | 2015-03-05 10:29:39 +0300 | [diff] [blame] | 502 | netoff = skb_network_offset(skb); |
| 503 | |
| 504 | if (skb_copy_bits(skb, netoff, &iph, sizeof(iph)) < 0) |
Eric Dumazet | bc416d9 | 2011-10-06 10:28:31 +0000 | [diff] [blame] | 505 | return skb; |
| 506 | |
Johannes Berg | 1bf3751 | 2012-12-09 23:41:06 +0000 | [diff] [blame] | 507 | if (iph.ihl < 5 || iph.version != 4) |
Eric Dumazet | bc416d9 | 2011-10-06 10:28:31 +0000 | [diff] [blame] | 508 | return skb; |
| 509 | |
Johannes Berg | 1bf3751 | 2012-12-09 23:41:06 +0000 | [diff] [blame] | 510 | len = ntohs(iph.tot_len); |
Alexander Drozdov | 3e32e73 | 2015-03-05 10:29:39 +0300 | [diff] [blame] | 511 | if (skb->len < netoff + len || len < (iph.ihl * 4)) |
Johannes Berg | 1bf3751 | 2012-12-09 23:41:06 +0000 | [diff] [blame] | 512 | return skb; |
| 513 | |
| 514 | if (ip_is_fragment(&iph)) { |
Eric Dumazet | bc416d9 | 2011-10-06 10:28:31 +0000 | [diff] [blame] | 515 | skb = skb_share_check(skb, GFP_ATOMIC); |
| 516 | if (skb) { |
Cong Wang | 7de414a | 2018-11-01 12:02:37 -0700 | [diff] [blame] | 517 | if (!pskb_may_pull(skb, netoff + iph.ihl * 4)) { |
| 518 | kfree_skb(skb); |
| 519 | return NULL; |
| 520 | } |
| 521 | if (pskb_trim_rcsum(skb, netoff + len)) { |
| 522 | kfree_skb(skb); |
| 523 | return NULL; |
| 524 | } |
Eric Dumazet | bc416d9 | 2011-10-06 10:28:31 +0000 | [diff] [blame] | 525 | memset(IPCB(skb), 0, sizeof(struct inet_skb_parm)); |
Eric W. Biederman | 19bcf9f | 2015-10-09 13:44:54 -0500 | [diff] [blame] | 526 | if (ip_defrag(net, skb, user)) |
Eric Dumazet | bc416d9 | 2011-10-06 10:28:31 +0000 | [diff] [blame] | 527 | return NULL; |
Tom Herbert | 7539fad | 2013-12-15 22:12:18 -0800 | [diff] [blame] | 528 | skb_clear_hash(skb); |
Eric Dumazet | bc416d9 | 2011-10-06 10:28:31 +0000 | [diff] [blame] | 529 | } |
| 530 | } |
| 531 | return skb; |
| 532 | } |
| 533 | EXPORT_SYMBOL(ip_check_defrag); |
| 534 | |
Pavel Emelyanov | 8d8354d | 2008-01-22 05:58:31 -0800 | [diff] [blame] | 535 | #ifdef CONFIG_SYSCTL |
Eric Dumazet | 3d23401 | 2018-04-04 08:35:10 -0700 | [diff] [blame] | 536 | static int dist_min; |
Pavel Emelyanov | 8d8354d | 2008-01-22 05:58:31 -0800 | [diff] [blame] | 537 | |
Pavel Emelyanov | 0a64b4b | 2008-05-19 13:51:29 -0700 | [diff] [blame] | 538 | static struct ctl_table ip4_frags_ns_ctl_table[] = { |
Pavel Emelyanov | 8d8354d | 2008-01-22 05:58:31 -0800 | [diff] [blame] | 539 | { |
Pavel Emelyanov | 8d8354d | 2008-01-22 05:58:31 -0800 | [diff] [blame] | 540 | .procname = "ipfrag_high_thresh", |
Eric Dumazet | 3e67f10 | 2018-03-31 12:58:53 -0700 | [diff] [blame] | 541 | .maxlen = sizeof(unsigned long), |
Pavel Emelyanov | 8d8354d | 2008-01-22 05:58:31 -0800 | [diff] [blame] | 542 | .mode = 0644, |
Eric Dumazet | 3e67f10 | 2018-03-31 12:58:53 -0700 | [diff] [blame] | 543 | .proc_handler = proc_doulongvec_minmax, |
Pavel Emelyanov | 8d8354d | 2008-01-22 05:58:31 -0800 | [diff] [blame] | 544 | }, |
| 545 | { |
Pavel Emelyanov | 8d8354d | 2008-01-22 05:58:31 -0800 | [diff] [blame] | 546 | .procname = "ipfrag_low_thresh", |
Eric Dumazet | 3e67f10 | 2018-03-31 12:58:53 -0700 | [diff] [blame] | 547 | .maxlen = sizeof(unsigned long), |
Pavel Emelyanov | 8d8354d | 2008-01-22 05:58:31 -0800 | [diff] [blame] | 548 | .mode = 0644, |
Eric Dumazet | 3e67f10 | 2018-03-31 12:58:53 -0700 | [diff] [blame] | 549 | .proc_handler = proc_doulongvec_minmax, |
Pavel Emelyanov | 8d8354d | 2008-01-22 05:58:31 -0800 | [diff] [blame] | 550 | }, |
| 551 | { |
Pavel Emelyanov | 8d8354d | 2008-01-22 05:58:31 -0800 | [diff] [blame] | 552 | .procname = "ipfrag_time", |
Pavel Emelyanov | 8d8354d | 2008-01-22 05:58:31 -0800 | [diff] [blame] | 553 | .maxlen = sizeof(int), |
| 554 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 555 | .proc_handler = proc_dointvec_jiffies, |
Pavel Emelyanov | 8d8354d | 2008-01-22 05:58:31 -0800 | [diff] [blame] | 556 | }, |
Nikolay Borisov | 0fbf4cb | 2016-02-15 12:11:31 +0200 | [diff] [blame] | 557 | { |
| 558 | .procname = "ipfrag_max_dist", |
Nikolay Borisov | 0fbf4cb | 2016-02-15 12:11:31 +0200 | [diff] [blame] | 559 | .maxlen = sizeof(int), |
| 560 | .mode = 0644, |
| 561 | .proc_handler = proc_dointvec_minmax, |
Eric Dumazet | 3d23401 | 2018-04-04 08:35:10 -0700 | [diff] [blame] | 562 | .extra1 = &dist_min, |
Nikolay Borisov | 0fbf4cb | 2016-02-15 12:11:31 +0200 | [diff] [blame] | 563 | }, |
Pavel Emelyanov | 7d291eb | 2008-05-19 13:53:02 -0700 | [diff] [blame] | 564 | { } |
| 565 | }; |
| 566 | |
Florian Westphal | e3a57d1 | 2014-07-24 16:50:35 +0200 | [diff] [blame] | 567 | /* secret interval has been deprecated */ |
| 568 | static int ip4_frags_secret_interval_unused; |
Pavel Emelyanov | 7d291eb | 2008-05-19 13:53:02 -0700 | [diff] [blame] | 569 | static struct ctl_table ip4_frags_ctl_table[] = { |
Pavel Emelyanov | 8d8354d | 2008-01-22 05:58:31 -0800 | [diff] [blame] | 570 | { |
Pavel Emelyanov | 8d8354d | 2008-01-22 05:58:31 -0800 | [diff] [blame] | 571 | .procname = "ipfrag_secret_interval", |
Florian Westphal | e3a57d1 | 2014-07-24 16:50:35 +0200 | [diff] [blame] | 572 | .data = &ip4_frags_secret_interval_unused, |
Pavel Emelyanov | 8d8354d | 2008-01-22 05:58:31 -0800 | [diff] [blame] | 573 | .maxlen = sizeof(int), |
| 574 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 575 | .proc_handler = proc_dointvec_jiffies, |
Pavel Emelyanov | 8d8354d | 2008-01-22 05:58:31 -0800 | [diff] [blame] | 576 | }, |
Pavel Emelyanov | 8d8354d | 2008-01-22 05:58:31 -0800 | [diff] [blame] | 577 | { } |
| 578 | }; |
| 579 | |
Alexey Dobriyan | 2c8c1e7 | 2010-01-17 03:35:32 +0000 | [diff] [blame] | 580 | static int __net_init ip4_frags_ns_ctl_register(struct net *net) |
Pavel Emelyanov | 8d8354d | 2008-01-22 05:58:31 -0800 | [diff] [blame] | 581 | { |
Pavel Emelyanov | e4a2d5c | 2008-01-22 06:08:36 -0800 | [diff] [blame] | 582 | struct ctl_table *table; |
Pavel Emelyanov | 8d8354d | 2008-01-22 05:58:31 -0800 | [diff] [blame] | 583 | struct ctl_table_header *hdr; |
| 584 | |
Pavel Emelyanov | 0a64b4b | 2008-05-19 13:51:29 -0700 | [diff] [blame] | 585 | table = ip4_frags_ns_ctl_table; |
Octavian Purdila | 09ad9bc | 2009-11-25 15:14:13 -0800 | [diff] [blame] | 586 | if (!net_eq(net, &init_net)) { |
Pavel Emelyanov | 0a64b4b | 2008-05-19 13:51:29 -0700 | [diff] [blame] | 587 | table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL); |
Ian Morris | 51456b2 | 2015-04-03 09:17:26 +0100 | [diff] [blame] | 588 | if (!table) |
Pavel Emelyanov | e4a2d5c | 2008-01-22 06:08:36 -0800 | [diff] [blame] | 589 | goto err_alloc; |
| 590 | |
Pavel Emelyanov | e4a2d5c | 2008-01-22 06:08:36 -0800 | [diff] [blame] | 591 | } |
Eric Dumazet | 8dfdb31 | 2019-05-24 09:03:33 -0700 | [diff] [blame] | 592 | table[0].data = &net->ipv4.fqdir.high_thresh; |
| 593 | table[0].extra1 = &net->ipv4.fqdir.low_thresh; |
| 594 | table[1].data = &net->ipv4.fqdir.low_thresh; |
| 595 | table[1].extra2 = &net->ipv4.fqdir.high_thresh; |
| 596 | table[2].data = &net->ipv4.fqdir.timeout; |
| 597 | table[3].data = &net->ipv4.fqdir.max_dist; |
Pavel Emelyanov | e4a2d5c | 2008-01-22 06:08:36 -0800 | [diff] [blame] | 598 | |
Eric W. Biederman | ec8f23c | 2012-04-19 13:44:49 +0000 | [diff] [blame] | 599 | hdr = register_net_sysctl(net, "net/ipv4", table); |
Ian Morris | 51456b2 | 2015-04-03 09:17:26 +0100 | [diff] [blame] | 600 | if (!hdr) |
Pavel Emelyanov | e4a2d5c | 2008-01-22 06:08:36 -0800 | [diff] [blame] | 601 | goto err_reg; |
| 602 | |
| 603 | net->ipv4.frags_hdr = hdr; |
| 604 | return 0; |
| 605 | |
| 606 | err_reg: |
Octavian Purdila | 09ad9bc | 2009-11-25 15:14:13 -0800 | [diff] [blame] | 607 | if (!net_eq(net, &init_net)) |
Pavel Emelyanov | e4a2d5c | 2008-01-22 06:08:36 -0800 | [diff] [blame] | 608 | kfree(table); |
| 609 | err_alloc: |
| 610 | return -ENOMEM; |
| 611 | } |
| 612 | |
Alexey Dobriyan | 2c8c1e7 | 2010-01-17 03:35:32 +0000 | [diff] [blame] | 613 | static void __net_exit ip4_frags_ns_ctl_unregister(struct net *net) |
Pavel Emelyanov | e4a2d5c | 2008-01-22 06:08:36 -0800 | [diff] [blame] | 614 | { |
| 615 | struct ctl_table *table; |
| 616 | |
| 617 | table = net->ipv4.frags_hdr->ctl_table_arg; |
| 618 | unregister_net_sysctl_table(net->ipv4.frags_hdr); |
| 619 | kfree(table); |
Pavel Emelyanov | 8d8354d | 2008-01-22 05:58:31 -0800 | [diff] [blame] | 620 | } |
Pavel Emelyanov | 7d291eb | 2008-05-19 13:53:02 -0700 | [diff] [blame] | 621 | |
Fabian Frederick | 57a02c3 | 2014-10-01 19:18:57 +0200 | [diff] [blame] | 622 | static void __init ip4_frags_ctl_register(void) |
Pavel Emelyanov | 7d291eb | 2008-05-19 13:53:02 -0700 | [diff] [blame] | 623 | { |
Eric W. Biederman | 4344475 | 2012-04-19 13:22:55 +0000 | [diff] [blame] | 624 | register_net_sysctl(&init_net, "net/ipv4", ip4_frags_ctl_table); |
Pavel Emelyanov | 7d291eb | 2008-05-19 13:53:02 -0700 | [diff] [blame] | 625 | } |
Pavel Emelyanov | 8d8354d | 2008-01-22 05:58:31 -0800 | [diff] [blame] | 626 | #else |
Fabian Frederick | aa1f731 | 2014-11-04 20:44:04 +0100 | [diff] [blame] | 627 | static int ip4_frags_ns_ctl_register(struct net *net) |
Pavel Emelyanov | 8d8354d | 2008-01-22 05:58:31 -0800 | [diff] [blame] | 628 | { |
| 629 | return 0; |
| 630 | } |
Pavel Emelyanov | e4a2d5c | 2008-01-22 06:08:36 -0800 | [diff] [blame] | 631 | |
Fabian Frederick | aa1f731 | 2014-11-04 20:44:04 +0100 | [diff] [blame] | 632 | static void ip4_frags_ns_ctl_unregister(struct net *net) |
Pavel Emelyanov | e4a2d5c | 2008-01-22 06:08:36 -0800 | [diff] [blame] | 633 | { |
| 634 | } |
Pavel Emelyanov | 7d291eb | 2008-05-19 13:53:02 -0700 | [diff] [blame] | 635 | |
Fabian Frederick | aa1f731 | 2014-11-04 20:44:04 +0100 | [diff] [blame] | 636 | static void __init ip4_frags_ctl_register(void) |
Pavel Emelyanov | 7d291eb | 2008-05-19 13:53:02 -0700 | [diff] [blame] | 637 | { |
| 638 | } |
Pavel Emelyanov | 8d8354d | 2008-01-22 05:58:31 -0800 | [diff] [blame] | 639 | #endif |
| 640 | |
Alexey Dobriyan | 2c8c1e7 | 2010-01-17 03:35:32 +0000 | [diff] [blame] | 641 | static int __net_init ipv4_frags_init_net(struct net *net) |
Pavel Emelyanov | 8d8354d | 2008-01-22 05:58:31 -0800 | [diff] [blame] | 642 | { |
Eric Dumazet | 787bea7 | 2018-03-31 12:58:43 -0700 | [diff] [blame] | 643 | int res; |
| 644 | |
Jesper Dangaard Brouer | c2a9366 | 2013-01-15 07:16:35 +0000 | [diff] [blame] | 645 | /* Fragment cache limits. |
| 646 | * |
| 647 | * The fragment memory accounting code, (tries to) account for |
| 648 | * the real memory usage, by measuring both the size of frag |
| 649 | * queue struct (inet_frag_queue (ipv4:ipq/ipv6:frag_queue)) |
| 650 | * and the SKB's truesize. |
| 651 | * |
| 652 | * A 64K fragment consumes 129736 bytes (44*2944)+200 |
| 653 | * (1500 truesize == 2944, sizeof(struct ipq) == 200) |
| 654 | * |
| 655 | * We will commit 4MB at one time. Should we cross that limit |
| 656 | * we will prune down to 3MB, making room for approx 8 big 64K |
| 657 | * fragments 8x128k. |
Pavel Emelyanov | e31e0bdc7 | 2008-01-22 06:10:13 -0800 | [diff] [blame] | 658 | */ |
Eric Dumazet | 803fdd9 | 2019-05-24 09:03:32 -0700 | [diff] [blame] | 659 | net->ipv4.fqdir.high_thresh = 4 * 1024 * 1024; |
| 660 | net->ipv4.fqdir.low_thresh = 3 * 1024 * 1024; |
Pavel Emelyanov | e31e0bdc7 | 2008-01-22 06:10:13 -0800 | [diff] [blame] | 661 | /* |
Pavel Emelyanov | b2fd532 | 2008-01-22 06:09:37 -0800 | [diff] [blame] | 662 | * Important NOTE! Fragment queue must be destroyed before MSL expires. |
| 663 | * RFC791 is wrong proposing to prolongate timer each fragment arrival |
| 664 | * by TTL. |
| 665 | */ |
Eric Dumazet | 803fdd9 | 2019-05-24 09:03:32 -0700 | [diff] [blame] | 666 | net->ipv4.fqdir.timeout = IP_FRAG_TIME; |
Pavel Emelyanov | b2fd532 | 2008-01-22 06:09:37 -0800 | [diff] [blame] | 667 | |
Eric Dumazet | 803fdd9 | 2019-05-24 09:03:32 -0700 | [diff] [blame] | 668 | net->ipv4.fqdir.max_dist = 64; |
Nikolay Borisov | 0fbf4cb | 2016-02-15 12:11:31 +0200 | [diff] [blame] | 669 | |
Eric Dumazet | a39aca6 | 2019-05-24 09:03:38 -0700 | [diff] [blame^] | 670 | res = fqdir_init(&net->ipv4.fqdir, &ip4_frags, net); |
Eric Dumazet | 787bea7 | 2018-03-31 12:58:43 -0700 | [diff] [blame] | 671 | if (res < 0) |
| 672 | return res; |
| 673 | res = ip4_frags_ns_ctl_register(net); |
| 674 | if (res < 0) |
Eric Dumazet | 803fdd9 | 2019-05-24 09:03:32 -0700 | [diff] [blame] | 675 | fqdir_exit(&net->ipv4.fqdir); |
Eric Dumazet | 787bea7 | 2018-03-31 12:58:43 -0700 | [diff] [blame] | 676 | return res; |
Pavel Emelyanov | 8d8354d | 2008-01-22 05:58:31 -0800 | [diff] [blame] | 677 | } |
| 678 | |
Alexey Dobriyan | 2c8c1e7 | 2010-01-17 03:35:32 +0000 | [diff] [blame] | 679 | static void __net_exit ipv4_frags_exit_net(struct net *net) |
Pavel Emelyanov | 81566e8 | 2008-01-22 06:12:39 -0800 | [diff] [blame] | 680 | { |
Pavel Emelyanov | 0a64b4b | 2008-05-19 13:51:29 -0700 | [diff] [blame] | 681 | ip4_frags_ns_ctl_unregister(net); |
Eric Dumazet | 803fdd9 | 2019-05-24 09:03:32 -0700 | [diff] [blame] | 682 | fqdir_exit(&net->ipv4.fqdir); |
Pavel Emelyanov | 81566e8 | 2008-01-22 06:12:39 -0800 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | static struct pernet_operations ip4_frags_ops = { |
| 686 | .init = ipv4_frags_init_net, |
| 687 | .exit = ipv4_frags_exit_net, |
| 688 | }; |
| 689 | |
Eric Dumazet | 648700f | 2018-03-31 12:58:49 -0700 | [diff] [blame] | 690 | |
| 691 | static u32 ip4_key_hashfn(const void *data, u32 len, u32 seed) |
| 692 | { |
| 693 | return jhash2(data, |
| 694 | sizeof(struct frag_v4_compare_key) / sizeof(u32), seed); |
| 695 | } |
| 696 | |
| 697 | static u32 ip4_obj_hashfn(const void *data, u32 len, u32 seed) |
| 698 | { |
| 699 | const struct inet_frag_queue *fq = data; |
| 700 | |
| 701 | return jhash2((const u32 *)&fq->key.v4, |
| 702 | sizeof(struct frag_v4_compare_key) / sizeof(u32), seed); |
| 703 | } |
| 704 | |
| 705 | static int ip4_obj_cmpfn(struct rhashtable_compare_arg *arg, const void *ptr) |
| 706 | { |
| 707 | const struct frag_v4_compare_key *key = arg->key; |
| 708 | const struct inet_frag_queue *fq = ptr; |
| 709 | |
| 710 | return !!memcmp(&fq->key, key, sizeof(*key)); |
| 711 | } |
| 712 | |
| 713 | static const struct rhashtable_params ip4_rhash_params = { |
| 714 | .head_offset = offsetof(struct inet_frag_queue, node), |
| 715 | .key_offset = offsetof(struct inet_frag_queue, key), |
| 716 | .key_len = sizeof(struct frag_v4_compare_key), |
| 717 | .hashfn = ip4_key_hashfn, |
| 718 | .obj_hashfn = ip4_obj_hashfn, |
| 719 | .obj_cmpfn = ip4_obj_cmpfn, |
| 720 | .automatic_shrinking = true, |
| 721 | }; |
| 722 | |
Eric Dumazet | b7aa0bf | 2007-04-19 16:16:32 -0700 | [diff] [blame] | 723 | void __init ipfrag_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | { |
Pavel Emelyanov | c6fda28 | 2007-10-17 19:46:47 -0700 | [diff] [blame] | 725 | ip4_frags.constructor = ip4_frag_init; |
Pavel Emelyanov | 1e4b828 | 2007-10-15 02:39:14 -0700 | [diff] [blame] | 726 | ip4_frags.destructor = ip4_frag_free; |
Pavel Emelyanov | 1e4b828 | 2007-10-15 02:39:14 -0700 | [diff] [blame] | 727 | ip4_frags.qsize = sizeof(struct ipq); |
Pavel Emelyanov | e521db9 | 2007-10-17 19:45:23 -0700 | [diff] [blame] | 728 | ip4_frags.frag_expire = ip_expire; |
Nikolay Aleksandrov | d4ad4d2 | 2014-08-01 12:29:48 +0200 | [diff] [blame] | 729 | ip4_frags.frags_cache_name = ip_frag_cache_name; |
Eric Dumazet | 648700f | 2018-03-31 12:58:49 -0700 | [diff] [blame] | 730 | ip4_frags.rhash_params = ip4_rhash_params; |
Nikolay Aleksandrov | d4ad4d2 | 2014-08-01 12:29:48 +0200 | [diff] [blame] | 731 | if (inet_frags_init(&ip4_frags)) |
| 732 | panic("IP: failed to allocate ip4_frags cache\n"); |
Eric Dumazet | 483a6e4 | 2018-03-31 12:58:47 -0700 | [diff] [blame] | 733 | ip4_frags_ctl_register(); |
| 734 | register_pernet_subsys(&ip4_frags_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | } |