2019-05-27 09:55:01 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* IPv6 fragment reassembly
|
2007-02-09 17:24:49 +03:00
|
|
|
* Linux INET6 implementation
|
2005-04-17 02:20:36 +04:00
|
|
|
*
|
|
|
|
* Authors:
|
2007-02-09 17:24:49 +03:00
|
|
|
* Pedro Roque <roque@di.fc.ul.pt>
|
2005-04-17 02:20:36 +04:00
|
|
|
*
|
|
|
|
* Based on: net/ipv4/ip_fragment.c
|
|
|
|
*/
|
|
|
|
|
2007-02-09 17:24:49 +03:00
|
|
|
/*
|
|
|
|
* Fixes:
|
2005-04-17 02:20:36 +04:00
|
|
|
* Andi Kleen Make it work with multiple hosts.
|
|
|
|
* More RFC compliance.
|
|
|
|
*
|
|
|
|
* Horst von Brand Add missing #include <linux/string.h>
|
|
|
|
* Alexey Kuznetsov SMP races, threading, cleanup.
|
|
|
|
* Patrick McHardy LRU queue of frag heads for evictor.
|
|
|
|
* Mitsuru KANDA @USAGI Register inet6_protocol{}.
|
|
|
|
* David Stevens and
|
|
|
|
* YOSHIFUJI,H. @USAGI Always remove fragment header to
|
|
|
|
* calculate ICV correctly.
|
|
|
|
*/
|
2013-03-15 15:32:30 +04:00
|
|
|
|
|
|
|
#define pr_fmt(fmt) "IPv6: " fmt
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/socket.h>
|
|
|
|
#include <linux/sockios.h>
|
|
|
|
#include <linux/jiffies.h>
|
|
|
|
#include <linux/net.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/in6.h>
|
|
|
|
#include <linux/ipv6.h>
|
|
|
|
#include <linux/icmpv6.h>
|
|
|
|
#include <linux/random.h>
|
|
|
|
#include <linux/jhash.h>
|
2007-10-15 12:28:47 +04:00
|
|
|
#include <linux/skbuff.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
|
|
|
#include <linux/slab.h>
|
2011-07-15 19:47:34 +04:00
|
|
|
#include <linux/export.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
#include <net/sock.h>
|
|
|
|
#include <net/snmp.h>
|
|
|
|
|
|
|
|
#include <net/ipv6.h>
|
2006-11-04 14:11:37 +03:00
|
|
|
#include <net/ip6_route.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <net/protocol.h>
|
|
|
|
#include <net/transp_v6.h>
|
|
|
|
#include <net/rawv6.h>
|
|
|
|
#include <net/ndisc.h>
|
|
|
|
#include <net/addrconf.h>
|
2018-07-14 02:14:01 +03:00
|
|
|
#include <net/ipv6_frag.h>
|
2013-03-22 12:24:44 +04:00
|
|
|
#include <net/inet_ecn.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2014-08-01 14:29:48 +04:00
|
|
|
static const char ip6_frag_cache_name[] = "ip6-frags";
|
|
|
|
|
2014-10-29 13:38:17 +03:00
|
|
|
static u8 ip6_frag_ecn(const struct ipv6hdr *ipv6h)
|
2013-03-22 12:24:44 +04:00
|
|
|
{
|
|
|
|
return 1 << (ipv6_get_dsfield(ipv6h) & INET_ECN_MASK);
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2007-10-15 13:31:52 +04:00
|
|
|
static struct inet_frags ip6_frags;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2019-01-22 21:02:51 +03:00
|
|
|
static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *skb,
|
|
|
|
struct sk_buff *prev_tail, struct net_device *dev);
|
2007-10-15 12:28:47 +04:00
|
|
|
|
2017-10-17 03:29:20 +03:00
|
|
|
static void ip6_frag_expire(struct timer_list *t)
|
2012-09-18 20:50:09 +04:00
|
|
|
{
|
2017-10-17 03:29:20 +03:00
|
|
|
struct inet_frag_queue *frag = from_timer(frag, t, timer);
|
2012-09-18 20:50:09 +04:00
|
|
|
struct frag_queue *fq;
|
|
|
|
|
2017-10-17 03:29:20 +03:00
|
|
|
fq = container_of(frag, struct frag_queue, q);
|
2012-09-18 20:50:09 +04:00
|
|
|
|
2019-05-24 19:03:38 +03:00
|
|
|
ip6frag_expire_frag_queue(fq->q.fqdir->net, fq);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2014-10-29 13:38:17 +03:00
|
|
|
static struct frag_queue *
|
inet: frags: use rhashtables for reassembly units
Some applications still rely on IP fragmentation, and to be fair linux
reassembly unit is not working under any serious load.
It uses static hash tables of 1024 buckets, and up to 128 items per bucket (!!!)
A work queue is supposed to garbage collect items when host is under memory
pressure, and doing a hash rebuild, changing seed used in hash computations.
This work queue blocks softirqs for up to 25 ms when doing a hash rebuild,
occurring every 5 seconds if host is under fire.
Then there is the problem of sharing this hash table for all netns.
It is time to switch to rhashtables, and allocate one of them per netns
to speedup netns dismantle, since this is a critical metric these days.
Lookup is now using RCU. A followup patch will even remove
the refcount hold/release left from prior implementation and save
a couple of atomic operations.
Before this patch, 16 cpus (16 RX queue NIC) could not handle more
than 1 Mpps frags DDOS.
After the patch, I reach 9 Mpps without any tuning, and can use up to 2GB
of storage for the fragments (exact number depends on frags being evicted
after timeout)
$ grep FRAG /proc/net/sockstat
FRAG: inuse 1966916 memory 2140004608
A followup patch will change the limits for 64bit arches.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Florian Westphal <fw@strlen.de>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Stefan Schmidt <stefan@osg.samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-31 22:58:49 +03:00
|
|
|
fq_find(struct net *net, __be32 id, const struct ipv6hdr *hdr, int iif)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
inet: frags: use rhashtables for reassembly units
Some applications still rely on IP fragmentation, and to be fair linux
reassembly unit is not working under any serious load.
It uses static hash tables of 1024 buckets, and up to 128 items per bucket (!!!)
A work queue is supposed to garbage collect items when host is under memory
pressure, and doing a hash rebuild, changing seed used in hash computations.
This work queue blocks softirqs for up to 25 ms when doing a hash rebuild,
occurring every 5 seconds if host is under fire.
Then there is the problem of sharing this hash table for all netns.
It is time to switch to rhashtables, and allocate one of them per netns
to speedup netns dismantle, since this is a critical metric these days.
Lookup is now using RCU. A followup patch will even remove
the refcount hold/release left from prior implementation and save
a couple of atomic operations.
Before this patch, 16 cpus (16 RX queue NIC) could not handle more
than 1 Mpps frags DDOS.
After the patch, I reach 9 Mpps without any tuning, and can use up to 2GB
of storage for the fragments (exact number depends on frags being evicted
after timeout)
$ grep FRAG /proc/net/sockstat
FRAG: inuse 1966916 memory 2140004608
A followup patch will change the limits for 64bit arches.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Florian Westphal <fw@strlen.de>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Stefan Schmidt <stefan@osg.samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-31 22:58:49 +03:00
|
|
|
struct frag_v6_compare_key key = {
|
|
|
|
.id = id,
|
|
|
|
.saddr = hdr->saddr,
|
|
|
|
.daddr = hdr->daddr,
|
|
|
|
.user = IP6_DEFRAG_LOCAL_DELIVER,
|
|
|
|
.iif = iif,
|
|
|
|
};
|
2007-10-18 06:46:47 +04:00
|
|
|
struct inet_frag_queue *q;
|
2008-06-28 07:06:08 +04:00
|
|
|
|
inet: frags: use rhashtables for reassembly units
Some applications still rely on IP fragmentation, and to be fair linux
reassembly unit is not working under any serious load.
It uses static hash tables of 1024 buckets, and up to 128 items per bucket (!!!)
A work queue is supposed to garbage collect items when host is under memory
pressure, and doing a hash rebuild, changing seed used in hash computations.
This work queue blocks softirqs for up to 25 ms when doing a hash rebuild,
occurring every 5 seconds if host is under fire.
Then there is the problem of sharing this hash table for all netns.
It is time to switch to rhashtables, and allocate one of them per netns
to speedup netns dismantle, since this is a critical metric these days.
Lookup is now using RCU. A followup patch will even remove
the refcount hold/release left from prior implementation and save
a couple of atomic operations.
Before this patch, 16 cpus (16 RX queue NIC) could not handle more
than 1 Mpps frags DDOS.
After the patch, I reach 9 Mpps without any tuning, and can use up to 2GB
of storage for the fragments (exact number depends on frags being evicted
after timeout)
$ grep FRAG /proc/net/sockstat
FRAG: inuse 1966916 memory 2140004608
A followup patch will change the limits for 64bit arches.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Florian Westphal <fw@strlen.de>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Stefan Schmidt <stefan@osg.samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-31 22:58:49 +03:00
|
|
|
if (!(ipv6_addr_type(&hdr->daddr) & (IPV6_ADDR_MULTICAST |
|
|
|
|
IPV6_ADDR_LINKLOCAL)))
|
|
|
|
key.iif = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2019-05-24 19:03:39 +03:00
|
|
|
q = inet_frag_find(net->ipv6.fqdir, &key);
|
2018-03-31 22:58:52 +03:00
|
|
|
if (!q)
|
2010-02-11 03:12:45 +03:00
|
|
|
return NULL;
|
2018-03-31 22:58:52 +03:00
|
|
|
|
2007-10-18 06:46:47 +04:00
|
|
|
return container_of(q, struct frag_queue, q);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2007-10-15 12:28:47 +04:00
|
|
|
static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb,
|
2018-04-18 04:11:44 +03:00
|
|
|
struct frag_hdr *fhdr, int nhoff,
|
|
|
|
u32 *prob_offset)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2009-06-02 09:19:30 +04:00
|
|
|
struct net *net = dev_net(skb_dst(skb)->dev);
|
2019-01-22 21:02:51 +03:00
|
|
|
int offset, end, fragsize;
|
|
|
|
struct sk_buff *prev_tail;
|
|
|
|
struct net_device *dev;
|
|
|
|
int err = -ENOENT;
|
2013-03-22 12:24:44 +04:00
|
|
|
u8 ecn;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2014-08-01 14:29:44 +04:00
|
|
|
if (fq->q.flags & INET_FRAG_COMPLETE)
|
2005-04-17 02:20:36 +04:00
|
|
|
goto err;
|
|
|
|
|
2019-01-22 21:02:51 +03:00
|
|
|
err = -EINVAL;
|
2005-04-17 02:20:36 +04:00
|
|
|
offset = ntohs(fhdr->frag_off) & ~0x7;
|
2007-04-26 04:54:47 +04:00
|
|
|
end = offset + (ntohs(ipv6_hdr(skb)->payload_len) -
|
|
|
|
((u8 *)(fhdr + 1) - (u8 *)(ipv6_hdr(skb) + 1)));
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if ((unsigned int)end > IPV6_MAXPLEN) {
|
2018-04-18 04:11:44 +03:00
|
|
|
*prob_offset = (u8 *)&fhdr->frag_off - skb_network_header(skb);
|
2019-01-22 21:02:51 +03:00
|
|
|
/* note that if prob_offset is set, the skb is freed elsewhere,
|
|
|
|
* we do not free it here.
|
|
|
|
*/
|
2007-10-15 12:28:47 +04:00
|
|
|
return -1;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2013-03-22 12:24:44 +04:00
|
|
|
ecn = ip6_frag_ecn(ipv6_hdr(skb));
|
|
|
|
|
2007-04-11 07:50:43 +04:00
|
|
|
if (skb->ip_summed == CHECKSUM_COMPLETE) {
|
|
|
|
const unsigned char *nh = skb_network_header(skb);
|
2007-02-09 17:24:49 +03:00
|
|
|
skb->csum = csum_sub(skb->csum,
|
2007-04-11 07:50:43 +04:00
|
|
|
csum_partial(nh, (u8 *)(fhdr + 1) - nh,
|
|
|
|
0));
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Is this the final fragment? */
|
|
|
|
if (!(fhdr->frag_off & htons(IP6_MF))) {
|
|
|
|
/* If we already have some bits beyond end
|
|
|
|
* or have different end, the segment is corrupted.
|
|
|
|
*/
|
2007-10-15 13:24:19 +04:00
|
|
|
if (end < fq->q.len ||
|
2014-08-01 14:29:44 +04:00
|
|
|
((fq->q.flags & INET_FRAG_LAST_IN) && end != fq->q.len))
|
2018-09-21 21:17:15 +03:00
|
|
|
goto discard_fq;
|
2014-08-01 14:29:44 +04:00
|
|
|
fq->q.flags |= INET_FRAG_LAST_IN;
|
2007-10-15 13:24:19 +04:00
|
|
|
fq->q.len = end;
|
2005-04-17 02:20:36 +04:00
|
|
|
} else {
|
|
|
|
/* Check if the fragment is rounded to 8 bytes.
|
|
|
|
* Required by the RFC.
|
|
|
|
*/
|
|
|
|
if (end & 0x7) {
|
|
|
|
/* RFC2460 says always send parameter problem in
|
|
|
|
* this case. -DaveM
|
|
|
|
*/
|
2018-04-18 04:11:44 +03:00
|
|
|
*prob_offset = offsetof(struct ipv6hdr, payload_len);
|
2007-10-15 12:28:47 +04:00
|
|
|
return -1;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2007-10-15 13:24:19 +04:00
|
|
|
if (end > fq->q.len) {
|
2005-04-17 02:20:36 +04:00
|
|
|
/* Some bits beyond end -> corruption. */
|
2014-08-01 14:29:44 +04:00
|
|
|
if (fq->q.flags & INET_FRAG_LAST_IN)
|
2018-09-21 21:17:15 +03:00
|
|
|
goto discard_fq;
|
2007-10-15 13:24:19 +04:00
|
|
|
fq->q.len = end;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (end == offset)
|
2018-09-21 21:17:15 +03:00
|
|
|
goto discard_fq;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2019-01-22 21:02:51 +03:00
|
|
|
err = -ENOMEM;
|
2005-04-17 02:20:36 +04:00
|
|
|
/* Point into the IP datagram 'data' part. */
|
|
|
|
if (!pskb_pull(skb, (u8 *) (fhdr + 1) - skb->data))
|
2018-09-21 21:17:15 +03:00
|
|
|
goto discard_fq;
|
2007-02-09 17:24:49 +03:00
|
|
|
|
2019-01-22 21:02:51 +03:00
|
|
|
err = pskb_trim_rcsum(skb, end - offset);
|
|
|
|
if (err)
|
2010-09-03 09:13:05 +04:00
|
|
|
goto discard_fq;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2019-01-22 21:02:51 +03:00
|
|
|
/* Note : skb->rbnode and skb->dev share the same location. */
|
2018-03-31 22:58:59 +03:00
|
|
|
dev = skb->dev;
|
|
|
|
/* Makes sure compiler wont do silly aliasing games */
|
|
|
|
barrier();
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2019-01-22 21:02:51 +03:00
|
|
|
prev_tail = fq->q.fragments_tail;
|
|
|
|
err = inet_frag_queue_insert(&fq->q, skb, offset, end);
|
|
|
|
if (err)
|
|
|
|
goto insert_error;
|
|
|
|
|
|
|
|
if (dev)
|
|
|
|
fq->iif = dev->ifindex;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2007-10-15 13:24:19 +04:00
|
|
|
fq->q.stamp = skb->tstamp;
|
|
|
|
fq->q.meat += skb->len;
|
2013-03-22 12:24:44 +04:00
|
|
|
fq->ecn |= ecn;
|
2019-05-24 19:03:30 +03:00
|
|
|
add_frag_mem_limit(fq->q.fqdir, skb->truesize);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2016-11-02 18:02:18 +03:00
|
|
|
fragsize = -skb_network_offset(skb) + skb->len;
|
|
|
|
if (fragsize > fq->q.max_size)
|
|
|
|
fq->q.max_size = fragsize;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* The first fragment.
|
|
|
|
* nhoffset is obtained from the first fragment, of course.
|
|
|
|
*/
|
|
|
|
if (offset == 0) {
|
|
|
|
fq->nhoffset = nhoff;
|
2014-08-01 14:29:44 +04:00
|
|
|
fq->q.flags |= INET_FRAG_FIRST_IN;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2007-10-15 12:28:47 +04:00
|
|
|
|
2014-08-01 14:29:44 +04:00
|
|
|
if (fq->q.flags == (INET_FRAG_FIRST_IN | INET_FRAG_LAST_IN) &&
|
2013-04-16 16:55:41 +04:00
|
|
|
fq->q.meat == fq->q.len) {
|
|
|
|
unsigned long orefdst = skb->_skb_refdst;
|
|
|
|
|
|
|
|
skb->_skb_refdst = 0UL;
|
2019-01-22 21:02:51 +03:00
|
|
|
err = ip6_frag_reasm(fq, skb, prev_tail, dev);
|
2013-04-16 16:55:41 +04:00
|
|
|
skb->_skb_refdst = orefdst;
|
2019-01-22 21:02:51 +03:00
|
|
|
return err;
|
2013-04-16 16:55:41 +04:00
|
|
|
}
|
2007-10-15 12:28:47 +04:00
|
|
|
|
2013-04-16 16:55:41 +04:00
|
|
|
skb_dst_drop(skb);
|
2019-01-22 21:02:51 +03:00
|
|
|
return -EINPROGRESS;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2019-01-22 21:02:51 +03:00
|
|
|
insert_error:
|
|
|
|
if (err == IPFRAG_DUP) {
|
|
|
|
kfree_skb(skb);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
err = -EINVAL;
|
|
|
|
__IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)),
|
|
|
|
IPSTATS_MIB_REASM_OVERLAPS);
|
2010-09-03 09:13:05 +04:00
|
|
|
discard_fq:
|
2018-03-31 22:58:44 +03:00
|
|
|
inet_frag_kill(&fq->q);
|
2016-04-28 02:44:40 +03:00
|
|
|
__IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)),
|
|
|
|
IPSTATS_MIB_REASMFAILS);
|
2019-01-22 21:02:51 +03:00
|
|
|
err:
|
2005-04-17 02:20:36 +04:00
|
|
|
kfree_skb(skb);
|
2019-01-22 21:02:51 +03:00
|
|
|
return err;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if this packet is complete.
|
|
|
|
*
|
|
|
|
* It is called with locked fq, and caller must check that
|
|
|
|
* queue is eligible for reassembly i.e. it is not COMPLETE,
|
|
|
|
* the last and the first frames arrived and all the bits are here.
|
|
|
|
*/
|
2019-01-22 21:02:51 +03:00
|
|
|
static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *skb,
|
|
|
|
struct sk_buff *prev_tail, struct net_device *dev)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2019-05-24 19:03:38 +03:00
|
|
|
struct net *net = fq->q.fqdir->net;
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned int nhoff;
|
2019-01-22 21:02:51 +03:00
|
|
|
void *reasm_data;
|
|
|
|
int payload_len;
|
2013-03-22 12:24:44 +04:00
|
|
|
u8 ecn;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2018-03-31 22:58:44 +03:00
|
|
|
inet_frag_kill(&fq->q);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2013-03-22 12:24:44 +04:00
|
|
|
ecn = ip_frag_ecn_table[fq->ecn];
|
|
|
|
if (unlikely(ecn == 0xff))
|
|
|
|
goto out_fail;
|
|
|
|
|
2019-01-22 21:02:51 +03:00
|
|
|
reasm_data = inet_frag_reasm_prepare(&fq->q, skb, prev_tail);
|
|
|
|
if (!reasm_data)
|
|
|
|
goto out_oom;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2019-01-22 21:02:51 +03:00
|
|
|
payload_len = ((skb->data - skb_network_header(skb)) -
|
2007-10-15 13:24:19 +04:00
|
|
|
sizeof(struct ipv6hdr) + fq->q.len -
|
2007-04-11 07:50:43 +04:00
|
|
|
sizeof(struct frag_hdr));
|
2005-04-17 02:20:36 +04:00
|
|
|
if (payload_len > IPV6_MAXPLEN)
|
|
|
|
goto out_oversize;
|
|
|
|
|
|
|
|
/* We have to remove fragment header from datagram and to relocate
|
|
|
|
* header in order to calculate ICV correctly. */
|
|
|
|
nhoff = fq->nhoffset;
|
2019-01-22 21:02:51 +03:00
|
|
|
skb_network_header(skb)[nhoff] = skb_transport_header(skb)[0];
|
|
|
|
memmove(skb->head + sizeof(struct frag_hdr), skb->head,
|
|
|
|
(skb->data - skb->head) - sizeof(struct frag_hdr));
|
|
|
|
if (skb_mac_header_was_set(skb))
|
|
|
|
skb->mac_header += sizeof(struct frag_hdr);
|
|
|
|
skb->network_header += sizeof(struct frag_hdr);
|
|
|
|
|
|
|
|
skb_reset_transport_header(skb);
|
|
|
|
|
inet: frags: re-introduce skb coalescing for local delivery
Before commit d4289fcc9b16 ("net: IP6 defrag: use rbtrees for IPv6
defrag"), a netperf UDP_STREAM test[0] using big IPv6 datagrams (thus
generating many fragments) and running over an IPsec tunnel, reported
more than 6Gbps throughput. After that patch, the same test gets only
9Mbps when receiving on a be2net nic (driver can make a big difference
here, for example, ixgbe doesn't seem to be affected).
By reusing the IPv4 defragmentation code, IPv6 lost fragment coalescing
(IPv4 fragment coalescing was dropped by commit 14fe22e33462 ("Revert
"ipv4: use skb coalescing in defragmentation"")).
Without fragment coalescing, be2net runs out of Rx ring entries and
starts to drop frames (ethtool reports rx_drops_no_frags errors). Since
the netperf traffic is only composed of UDP fragments, any lost packet
prevents reassembly of the full datagram. Therefore, fragments which
have no possibility to ever get reassembled pile up in the reassembly
queue, until the memory accounting exeeds the threshold. At that point
no fragment is accepted anymore, which effectively discards all
netperf traffic.
When reassembly timeout expires, some stale fragments are removed from
the reassembly queue, so a few packets can be received, reassembled
and delivered to the netperf receiver. But the nic still drops frames
and soon the reassembly queue gets filled again with stale fragments.
These long time frames where no datagram can be received explain why
the performance drop is so significant.
Re-introducing fragment coalescing is enough to get the initial
performances again (6.6Gbps with be2net): driver doesn't drop frames
anymore (no more rx_drops_no_frags errors) and the reassembly engine
works at full speed.
This patch is quite conservative and only coalesces skbs for local
IPv4 and IPv6 delivery (in order to avoid changing skb geometry when
forwarding). Coalescing could be extended in the future if need be, as
more scenarios would probably benefit from it.
[0]: Test configuration
Sender:
ip xfrm policy flush
ip xfrm state flush
ip xfrm state add src fc00:1::1 dst fc00:2::1 proto esp spi 0x1000 aead 'rfc4106(gcm(aes))' 0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b 96 mode transport sel src fc00:1::1 dst fc00:2::1
ip xfrm policy add src fc00:1::1 dst fc00:2::1 dir in tmpl src fc00:1::1 dst fc00:2::1 proto esp mode transport action allow
ip xfrm state add src fc00:2::1 dst fc00:1::1 proto esp spi 0x1001 aead 'rfc4106(gcm(aes))' 0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b 96 mode transport sel src fc00:2::1 dst fc00:1::1
ip xfrm policy add src fc00:2::1 dst fc00:1::1 dir out tmpl src fc00:2::1 dst fc00:1::1 proto esp mode transport action allow
netserver -D -L fc00:2::1
Receiver:
ip xfrm policy flush
ip xfrm state flush
ip xfrm state add src fc00:2::1 dst fc00:1::1 proto esp spi 0x1001 aead 'rfc4106(gcm(aes))' 0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b 96 mode transport sel src fc00:2::1 dst fc00:1::1
ip xfrm policy add src fc00:2::1 dst fc00:1::1 dir in tmpl src fc00:2::1 dst fc00:1::1 proto esp mode transport action allow
ip xfrm state add src fc00:1::1 dst fc00:2::1 proto esp spi 0x1000 aead 'rfc4106(gcm(aes))' 0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b 96 mode transport sel src fc00:1::1 dst fc00:2::1
ip xfrm policy add src fc00:1::1 dst fc00:2::1 dir out tmpl src fc00:1::1 dst fc00:2::1 proto esp mode transport action allow
netperf -H fc00:2::1 -f k -P 0 -L fc00:1::1 -l 60 -t UDP_STREAM -I 99,5 -i 5,5 -T5,5 -6
Signed-off-by: Guillaume Nault <gnault@redhat.com>
Acked-by: Florian Westphal <fw@strlen.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-08-02 18:15:03 +03:00
|
|
|
inet_frag_reasm_finish(&fq->q, skb, reasm_data, true);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2019-01-22 21:02:51 +03:00
|
|
|
skb->dev = dev;
|
|
|
|
ipv6_hdr(skb)->payload_len = htons(payload_len);
|
|
|
|
ipv6_change_dsfield(ipv6_hdr(skb), 0xff, ecn);
|
|
|
|
IP6CB(skb)->nhoff = nhoff;
|
|
|
|
IP6CB(skb)->flags |= IP6SKB_FRAGMENTED;
|
|
|
|
IP6CB(skb)->frag_max_size = fq->q.max_size;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Yes, and fold redundant checksum back. 8) */
|
2019-01-22 21:02:51 +03:00
|
|
|
skb_postpush_rcsum(skb, skb_network_header(skb),
|
|
|
|
skb_network_header_len(skb));
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-11-04 14:11:37 +03:00
|
|
|
rcu_read_lock();
|
2019-06-10 17:32:50 +03:00
|
|
|
__IP6_INC_STATS(net, __in6_dev_stats_get(dev, skb), IPSTATS_MIB_REASMOKS);
|
2006-11-04 14:11:37 +03:00
|
|
|
rcu_read_unlock();
|
2018-08-03 02:34:39 +03:00
|
|
|
fq->q.rb_fragments = RB_ROOT;
|
2010-06-29 08:39:37 +04:00
|
|
|
fq->q.fragments_tail = NULL;
|
2019-01-22 21:02:51 +03:00
|
|
|
fq->q.last_run_head = NULL;
|
2005-04-17 02:20:36 +04:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
out_oversize:
|
2012-05-14 01:56:26 +04:00
|
|
|
net_dbg_ratelimited("ip6_frag_reasm: payload len = %d\n", payload_len);
|
2005-04-17 02:20:36 +04:00
|
|
|
goto out_fail;
|
|
|
|
out_oom:
|
2012-05-14 01:56:26 +04:00
|
|
|
net_dbg_ratelimited("ip6_frag_reasm: no memory for reassembly\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
out_fail:
|
2006-11-04 14:11:37 +03:00
|
|
|
rcu_read_lock();
|
2019-06-10 17:32:50 +03:00
|
|
|
__IP6_INC_STATS(net, __in6_dev_stats_get(dev, skb), IPSTATS_MIB_REASMFAILS);
|
2006-11-04 14:11:37 +03:00
|
|
|
rcu_read_unlock();
|
2018-09-21 21:17:15 +03:00
|
|
|
inet_frag_kill(&fq->q);
|
2005-04-17 02:20:36 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-10-15 23:50:28 +04:00
|
|
|
static int ipv6_frag_rcv(struct sk_buff *skb)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct frag_hdr *fhdr;
|
|
|
|
struct frag_queue *fq;
|
2011-04-22 08:53:02 +04:00
|
|
|
const struct ipv6hdr *hdr = ipv6_hdr(skb);
|
2009-06-02 09:19:30 +04:00
|
|
|
struct net *net = dev_net(skb_dst(skb)->dev);
|
inet: frags: use rhashtables for reassembly units
Some applications still rely on IP fragmentation, and to be fair linux
reassembly unit is not working under any serious load.
It uses static hash tables of 1024 buckets, and up to 128 items per bucket (!!!)
A work queue is supposed to garbage collect items when host is under memory
pressure, and doing a hash rebuild, changing seed used in hash computations.
This work queue blocks softirqs for up to 25 ms when doing a hash rebuild,
occurring every 5 seconds if host is under fire.
Then there is the problem of sharing this hash table for all netns.
It is time to switch to rhashtables, and allocate one of them per netns
to speedup netns dismantle, since this is a critical metric these days.
Lookup is now using RCU. A followup patch will even remove
the refcount hold/release left from prior implementation and save
a couple of atomic operations.
Before this patch, 16 cpus (16 RX queue NIC) could not handle more
than 1 Mpps frags DDOS.
After the patch, I reach 9 Mpps without any tuning, and can use up to 2GB
of storage for the fragments (exact number depends on frags being evicted
after timeout)
$ grep FRAG /proc/net/sockstat
FRAG: inuse 1966916 memory 2140004608
A followup patch will change the limits for 64bit arches.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Florian Westphal <fw@strlen.de>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Stefan Schmidt <stefan@osg.samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-31 22:58:49 +03:00
|
|
|
int iif;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2013-08-16 15:30:07 +04:00
|
|
|
if (IP6CB(skb)->flags & IP6SKB_FRAGMENTED)
|
|
|
|
goto fail_hdr;
|
|
|
|
|
2016-04-28 02:44:40 +03:00
|
|
|
__IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_REASMREQDS);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Jumbo payload inhibits frag. header */
|
2014-08-25 00:53:10 +04:00
|
|
|
if (hdr->payload_len == 0)
|
2008-10-08 21:31:44 +04:00
|
|
|
goto fail_hdr;
|
|
|
|
|
2007-04-26 04:55:53 +04:00
|
|
|
if (!pskb_may_pull(skb, (skb_transport_offset(skb) +
|
2008-10-08 21:31:44 +04:00
|
|
|
sizeof(struct frag_hdr))))
|
|
|
|
goto fail_hdr;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2007-04-26 04:54:47 +04:00
|
|
|
hdr = ipv6_hdr(skb);
|
2007-04-26 05:04:18 +04:00
|
|
|
fhdr = (struct frag_hdr *)skb_transport_header(skb);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (!(fhdr->frag_off & htons(0xFFF9))) {
|
|
|
|
/* It is not a fragmented frame */
|
2007-04-11 08:21:55 +04:00
|
|
|
skb->transport_header += sizeof(struct frag_hdr);
|
2016-04-28 02:44:40 +03:00
|
|
|
__IP6_INC_STATS(net,
|
|
|
|
ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_REASMOKS);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2007-04-11 07:50:43 +04:00
|
|
|
IP6CB(skb)->nhoff = (u8 *)fhdr - skb_network_header(skb);
|
2013-08-16 15:30:07 +04:00
|
|
|
IP6CB(skb)->flags |= IP6SKB_FRAGMENTED;
|
2005-04-17 02:20:36 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
inet: frags: use rhashtables for reassembly units
Some applications still rely on IP fragmentation, and to be fair linux
reassembly unit is not working under any serious load.
It uses static hash tables of 1024 buckets, and up to 128 items per bucket (!!!)
A work queue is supposed to garbage collect items when host is under memory
pressure, and doing a hash rebuild, changing seed used in hash computations.
This work queue blocks softirqs for up to 25 ms when doing a hash rebuild,
occurring every 5 seconds if host is under fire.
Then there is the problem of sharing this hash table for all netns.
It is time to switch to rhashtables, and allocate one of them per netns
to speedup netns dismantle, since this is a critical metric these days.
Lookup is now using RCU. A followup patch will even remove
the refcount hold/release left from prior implementation and save
a couple of atomic operations.
Before this patch, 16 cpus (16 RX queue NIC) could not handle more
than 1 Mpps frags DDOS.
After the patch, I reach 9 Mpps without any tuning, and can use up to 2GB
of storage for the fragments (exact number depends on frags being evicted
after timeout)
$ grep FRAG /proc/net/sockstat
FRAG: inuse 1966916 memory 2140004608
A followup patch will change the limits for 64bit arches.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Florian Westphal <fw@strlen.de>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Stefan Schmidt <stefan@osg.samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-31 22:58:49 +03:00
|
|
|
iif = skb->dev ? skb->dev->ifindex : 0;
|
|
|
|
fq = fq_find(net, fhdr->identification, hdr, iif);
|
2015-03-29 16:00:05 +03:00
|
|
|
if (fq) {
|
2018-04-18 04:11:44 +03:00
|
|
|
u32 prob_offset = 0;
|
2007-10-15 12:28:47 +04:00
|
|
|
int ret;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2007-10-15 13:24:19 +04:00
|
|
|
spin_lock(&fq->q.lock);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
inet: frags: use rhashtables for reassembly units
Some applications still rely on IP fragmentation, and to be fair linux
reassembly unit is not working under any serious load.
It uses static hash tables of 1024 buckets, and up to 128 items per bucket (!!!)
A work queue is supposed to garbage collect items when host is under memory
pressure, and doing a hash rebuild, changing seed used in hash computations.
This work queue blocks softirqs for up to 25 ms when doing a hash rebuild,
occurring every 5 seconds if host is under fire.
Then there is the problem of sharing this hash table for all netns.
It is time to switch to rhashtables, and allocate one of them per netns
to speedup netns dismantle, since this is a critical metric these days.
Lookup is now using RCU. A followup patch will even remove
the refcount hold/release left from prior implementation and save
a couple of atomic operations.
Before this patch, 16 cpus (16 RX queue NIC) could not handle more
than 1 Mpps frags DDOS.
After the patch, I reach 9 Mpps without any tuning, and can use up to 2GB
of storage for the fragments (exact number depends on frags being evicted
after timeout)
$ grep FRAG /proc/net/sockstat
FRAG: inuse 1966916 memory 2140004608
A followup patch will change the limits for 64bit arches.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Florian Westphal <fw@strlen.de>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Stefan Schmidt <stefan@osg.samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-31 22:58:49 +03:00
|
|
|
fq->iif = iif;
|
2018-04-18 04:11:44 +03:00
|
|
|
ret = ip6_frag_queue(fq, skb, fhdr, IP6CB(skb)->nhoff,
|
|
|
|
&prob_offset);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2007-10-15 13:24:19 +04:00
|
|
|
spin_unlock(&fq->q.lock);
|
2018-03-31 22:58:44 +03:00
|
|
|
inet_frag_put(&fq->q);
|
2018-04-18 04:11:44 +03:00
|
|
|
if (prob_offset) {
|
|
|
|
__IP6_INC_STATS(net, __in6_dev_get_safely(skb->dev),
|
|
|
|
IPSTATS_MIB_INHDRERRORS);
|
2019-01-22 21:02:51 +03:00
|
|
|
/* icmpv6_param_prob() calls kfree_skb(skb) */
|
2018-04-18 04:11:44 +03:00
|
|
|
icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, prob_offset);
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-04-28 02:44:40 +03:00
|
|
|
__IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_REASMFAILS);
|
2005-04-17 02:20:36 +04:00
|
|
|
kfree_skb(skb);
|
|
|
|
return -1;
|
2008-10-08 21:31:44 +04:00
|
|
|
|
|
|
|
fail_hdr:
|
2018-04-16 20:42:16 +03:00
|
|
|
__IP6_INC_STATS(net, __in6_dev_get_safely(skb->dev),
|
2016-04-28 02:44:40 +03:00
|
|
|
IPSTATS_MIB_INHDRERRORS);
|
2008-10-08 21:31:44 +04:00
|
|
|
icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, skb_network_header_len(skb));
|
|
|
|
return -1;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2014-08-25 00:53:11 +04:00
|
|
|
static const struct inet6_protocol frag_protocol = {
|
2005-04-17 02:20:36 +04:00
|
|
|
.handler = ipv6_frag_rcv,
|
|
|
|
.flags = INET6_PROTO_NOPOLICY,
|
|
|
|
};
|
|
|
|
|
2008-01-22 16:58:31 +03:00
|
|
|
#ifdef CONFIG_SYSCTL
|
2014-07-24 18:50:37 +04:00
|
|
|
|
2008-05-20 00:51:29 +04:00
|
|
|
static struct ctl_table ip6_frags_ns_ctl_table[] = {
|
2008-01-22 16:58:31 +03:00
|
|
|
{
|
|
|
|
.procname = "ip6frag_high_thresh",
|
2018-03-31 22:58:53 +03:00
|
|
|
.maxlen = sizeof(unsigned long),
|
2008-01-22 16:58:31 +03:00
|
|
|
.mode = 0644,
|
2018-03-31 22:58:53 +03:00
|
|
|
.proc_handler = proc_doulongvec_minmax,
|
2008-01-22 16:58:31 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.procname = "ip6frag_low_thresh",
|
2018-03-31 22:58:53 +03:00
|
|
|
.maxlen = sizeof(unsigned long),
|
2008-01-22 16:58:31 +03:00
|
|
|
.mode = 0644,
|
2018-04-02 07:57:59 +03:00
|
|
|
.proc_handler = proc_doulongvec_minmax,
|
2008-01-22 16:58:31 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.procname = "ip6frag_time",
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
2008-11-04 05:21:05 +03:00
|
|
|
.proc_handler = proc_dointvec_jiffies,
|
2008-01-22 16:58:31 +03:00
|
|
|
},
|
2008-05-20 00:53:02 +04:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2014-07-24 18:50:35 +04:00
|
|
|
/* secret interval has been deprecated */
|
|
|
|
static int ip6_frags_secret_interval_unused;
|
2008-05-20 00:53:02 +04:00
|
|
|
static struct ctl_table ip6_frags_ctl_table[] = {
|
2008-01-22 16:58:31 +03:00
|
|
|
{
|
|
|
|
.procname = "ip6frag_secret_interval",
|
2014-07-24 18:50:35 +04:00
|
|
|
.data = &ip6_frags_secret_interval_unused,
|
2008-01-22 16:58:31 +03:00
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
2008-11-04 05:21:05 +03:00
|
|
|
.proc_handler = proc_dointvec_jiffies,
|
2008-01-22 16:58:31 +03:00
|
|
|
},
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2010-01-17 06:35:32 +03:00
|
|
|
static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
|
2008-01-22 16:58:31 +03:00
|
|
|
{
|
2008-01-22 17:08:36 +03:00
|
|
|
struct ctl_table *table;
|
2008-01-22 16:58:31 +03:00
|
|
|
struct ctl_table_header *hdr;
|
|
|
|
|
2008-05-20 00:51:29 +04:00
|
|
|
table = ip6_frags_ns_ctl_table;
|
2009-11-26 02:14:13 +03:00
|
|
|
if (!net_eq(net, &init_net)) {
|
2008-05-20 00:51:29 +04:00
|
|
|
table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
|
2015-03-29 16:00:04 +03:00
|
|
|
if (!table)
|
2008-01-22 17:08:36 +03:00
|
|
|
goto err_alloc;
|
|
|
|
|
|
|
|
}
|
2019-05-24 19:03:39 +03:00
|
|
|
table[0].data = &net->ipv6.fqdir->high_thresh;
|
|
|
|
table[0].extra1 = &net->ipv6.fqdir->low_thresh;
|
|
|
|
table[1].data = &net->ipv6.fqdir->low_thresh;
|
|
|
|
table[1].extra2 = &net->ipv6.fqdir->high_thresh;
|
|
|
|
table[2].data = &net->ipv6.fqdir->timeout;
|
2008-01-22 17:08:36 +03:00
|
|
|
|
2012-04-19 17:44:49 +04:00
|
|
|
hdr = register_net_sysctl(net, "net/ipv6", table);
|
2015-03-29 16:00:04 +03:00
|
|
|
if (!hdr)
|
2008-01-22 17:08:36 +03:00
|
|
|
goto err_reg;
|
|
|
|
|
|
|
|
net->ipv6.sysctl.frags_hdr = hdr;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_reg:
|
2009-11-26 02:14:13 +03:00
|
|
|
if (!net_eq(net, &init_net))
|
2008-01-22 17:08:36 +03:00
|
|
|
kfree(table);
|
|
|
|
err_alloc:
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2010-01-17 06:35:32 +03:00
|
|
|
static void __net_exit ip6_frags_ns_sysctl_unregister(struct net *net)
|
2008-01-22 17:08:36 +03:00
|
|
|
{
|
|
|
|
struct ctl_table *table;
|
|
|
|
|
|
|
|
table = net->ipv6.sysctl.frags_hdr->ctl_table_arg;
|
|
|
|
unregister_net_sysctl_table(net->ipv6.sysctl.frags_hdr);
|
2009-12-19 07:25:13 +03:00
|
|
|
if (!net_eq(net, &init_net))
|
|
|
|
kfree(table);
|
2008-01-22 16:58:31 +03:00
|
|
|
}
|
2008-05-20 00:53:02 +04:00
|
|
|
|
|
|
|
static struct ctl_table_header *ip6_ctl_header;
|
|
|
|
|
|
|
|
static int ip6_frags_sysctl_register(void)
|
|
|
|
{
|
2012-04-19 17:22:55 +04:00
|
|
|
ip6_ctl_header = register_net_sysctl(&init_net, "net/ipv6",
|
2008-05-20 00:53:02 +04:00
|
|
|
ip6_frags_ctl_table);
|
|
|
|
return ip6_ctl_header == NULL ? -ENOMEM : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ip6_frags_sysctl_unregister(void)
|
|
|
|
{
|
|
|
|
unregister_net_sysctl_table(ip6_ctl_header);
|
|
|
|
}
|
2008-01-22 16:58:31 +03:00
|
|
|
#else
|
2014-10-29 13:38:17 +03:00
|
|
|
static int ip6_frags_ns_sysctl_register(struct net *net)
|
2008-01-10 13:56:03 +03:00
|
|
|
{
|
2008-01-22 16:58:31 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2008-01-22 17:08:36 +03:00
|
|
|
|
2014-10-29 13:38:17 +03:00
|
|
|
static void ip6_frags_ns_sysctl_unregister(struct net *net)
|
2008-01-22 17:08:36 +03:00
|
|
|
{
|
|
|
|
}
|
2008-05-20 00:53:02 +04:00
|
|
|
|
2014-10-29 13:38:17 +03:00
|
|
|
static int ip6_frags_sysctl_register(void)
|
2008-05-20 00:53:02 +04:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-29 13:38:17 +03:00
|
|
|
static void ip6_frags_sysctl_unregister(void)
|
2008-05-20 00:53:02 +04:00
|
|
|
{
|
|
|
|
}
|
2008-01-22 16:58:31 +03:00
|
|
|
#endif
|
2008-01-19 10:52:35 +03:00
|
|
|
|
2010-01-17 06:35:32 +03:00
|
|
|
static int __net_init ipv6_frags_init_net(struct net *net)
|
2008-01-22 16:58:31 +03:00
|
|
|
{
|
2018-03-31 22:58:43 +03:00
|
|
|
int res;
|
|
|
|
|
2019-05-24 19:03:38 +03:00
|
|
|
res = fqdir_init(&net->ipv6.fqdir, &ip6_frags, net);
|
2018-03-31 22:58:43 +03:00
|
|
|
if (res < 0)
|
|
|
|
return res;
|
2017-09-01 12:26:13 +03:00
|
|
|
|
2019-05-24 19:03:39 +03:00
|
|
|
net->ipv6.fqdir->high_thresh = IPV6_FRAG_HIGH_THRESH;
|
|
|
|
net->ipv6.fqdir->low_thresh = IPV6_FRAG_LOW_THRESH;
|
|
|
|
net->ipv6.fqdir->timeout = IPV6_FRAG_TIMEOUT;
|
|
|
|
|
2018-03-31 22:58:43 +03:00
|
|
|
res = ip6_frags_ns_sysctl_register(net);
|
|
|
|
if (res < 0)
|
2019-05-24 19:03:39 +03:00
|
|
|
fqdir_exit(net->ipv6.fqdir);
|
2018-03-31 22:58:43 +03:00
|
|
|
return res;
|
2008-01-10 13:56:03 +03:00
|
|
|
}
|
|
|
|
|
2019-06-18 21:09:00 +03:00
|
|
|
static void __net_exit ipv6_frags_pre_exit_net(struct net *net)
|
|
|
|
{
|
|
|
|
fqdir_pre_exit(net->ipv6.fqdir);
|
|
|
|
}
|
|
|
|
|
2010-01-17 06:35:32 +03:00
|
|
|
static void __net_exit ipv6_frags_exit_net(struct net *net)
|
2008-01-22 17:12:39 +03:00
|
|
|
{
|
2008-05-20 00:51:29 +04:00
|
|
|
ip6_frags_ns_sysctl_unregister(net);
|
2019-05-24 19:03:39 +03:00
|
|
|
fqdir_exit(net->ipv6.fqdir);
|
2008-01-22 17:12:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct pernet_operations ip6_frags_ops = {
|
2019-06-18 21:09:00 +03:00
|
|
|
.init = ipv6_frags_init_net,
|
|
|
|
.pre_exit = ipv6_frags_pre_exit_net,
|
|
|
|
.exit = ipv6_frags_exit_net,
|
2008-01-22 17:12:39 +03:00
|
|
|
};
|
|
|
|
|
2018-07-14 02:14:01 +03:00
|
|
|
static const struct rhashtable_params ip6_rhash_params = {
|
inet: frags: use rhashtables for reassembly units
Some applications still rely on IP fragmentation, and to be fair linux
reassembly unit is not working under any serious load.
It uses static hash tables of 1024 buckets, and up to 128 items per bucket (!!!)
A work queue is supposed to garbage collect items when host is under memory
pressure, and doing a hash rebuild, changing seed used in hash computations.
This work queue blocks softirqs for up to 25 ms when doing a hash rebuild,
occurring every 5 seconds if host is under fire.
Then there is the problem of sharing this hash table for all netns.
It is time to switch to rhashtables, and allocate one of them per netns
to speedup netns dismantle, since this is a critical metric these days.
Lookup is now using RCU. A followup patch will even remove
the refcount hold/release left from prior implementation and save
a couple of atomic operations.
Before this patch, 16 cpus (16 RX queue NIC) could not handle more
than 1 Mpps frags DDOS.
After the patch, I reach 9 Mpps without any tuning, and can use up to 2GB
of storage for the fragments (exact number depends on frags being evicted
after timeout)
$ grep FRAG /proc/net/sockstat
FRAG: inuse 1966916 memory 2140004608
A followup patch will change the limits for 64bit arches.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Florian Westphal <fw@strlen.de>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Stefan Schmidt <stefan@osg.samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-31 22:58:49 +03:00
|
|
|
.head_offset = offsetof(struct inet_frag_queue, node),
|
2018-07-14 02:14:01 +03:00
|
|
|
.hashfn = ip6frag_key_hashfn,
|
|
|
|
.obj_hashfn = ip6frag_obj_hashfn,
|
|
|
|
.obj_cmpfn = ip6frag_obj_cmpfn,
|
inet: frags: use rhashtables for reassembly units
Some applications still rely on IP fragmentation, and to be fair linux
reassembly unit is not working under any serious load.
It uses static hash tables of 1024 buckets, and up to 128 items per bucket (!!!)
A work queue is supposed to garbage collect items when host is under memory
pressure, and doing a hash rebuild, changing seed used in hash computations.
This work queue blocks softirqs for up to 25 ms when doing a hash rebuild,
occurring every 5 seconds if host is under fire.
Then there is the problem of sharing this hash table for all netns.
It is time to switch to rhashtables, and allocate one of them per netns
to speedup netns dismantle, since this is a critical metric these days.
Lookup is now using RCU. A followup patch will even remove
the refcount hold/release left from prior implementation and save
a couple of atomic operations.
Before this patch, 16 cpus (16 RX queue NIC) could not handle more
than 1 Mpps frags DDOS.
After the patch, I reach 9 Mpps without any tuning, and can use up to 2GB
of storage for the fragments (exact number depends on frags being evicted
after timeout)
$ grep FRAG /proc/net/sockstat
FRAG: inuse 1966916 memory 2140004608
A followup patch will change the limits for 64bit arches.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Florian Westphal <fw@strlen.de>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Stefan Schmidt <stefan@osg.samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-31 22:58:49 +03:00
|
|
|
.automatic_shrinking = true,
|
|
|
|
};
|
|
|
|
|
2007-12-11 13:24:29 +03:00
|
|
|
int __init ipv6_frag_init(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2007-12-11 13:24:29 +03:00
|
|
|
int ret;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2018-07-14 02:14:01 +03:00
|
|
|
ip6_frags.constructor = ip6frag_init;
|
2018-03-31 22:58:45 +03:00
|
|
|
ip6_frags.destructor = NULL;
|
|
|
|
ip6_frags.qsize = sizeof(struct frag_queue);
|
|
|
|
ip6_frags.frag_expire = ip6_frag_expire;
|
|
|
|
ip6_frags.frags_cache_name = ip6_frag_cache_name;
|
inet: frags: use rhashtables for reassembly units
Some applications still rely on IP fragmentation, and to be fair linux
reassembly unit is not working under any serious load.
It uses static hash tables of 1024 buckets, and up to 128 items per bucket (!!!)
A work queue is supposed to garbage collect items when host is under memory
pressure, and doing a hash rebuild, changing seed used in hash computations.
This work queue blocks softirqs for up to 25 ms when doing a hash rebuild,
occurring every 5 seconds if host is under fire.
Then there is the problem of sharing this hash table for all netns.
It is time to switch to rhashtables, and allocate one of them per netns
to speedup netns dismantle, since this is a critical metric these days.
Lookup is now using RCU. A followup patch will even remove
the refcount hold/release left from prior implementation and save
a couple of atomic operations.
Before this patch, 16 cpus (16 RX queue NIC) could not handle more
than 1 Mpps frags DDOS.
After the patch, I reach 9 Mpps without any tuning, and can use up to 2GB
of storage for the fragments (exact number depends on frags being evicted
after timeout)
$ grep FRAG /proc/net/sockstat
FRAG: inuse 1966916 memory 2140004608
A followup patch will change the limits for 64bit arches.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Florian Westphal <fw@strlen.de>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Stefan Schmidt <stefan@osg.samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-31 22:58:49 +03:00
|
|
|
ip6_frags.rhash_params = ip6_rhash_params;
|
2018-03-31 22:58:45 +03:00
|
|
|
ret = inet_frags_init(&ip6_frags);
|
2007-12-11 13:24:29 +03:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
2008-01-10 13:56:03 +03:00
|
|
|
|
2018-03-31 22:58:45 +03:00
|
|
|
ret = inet6_add_protocol(&frag_protocol, IPPROTO_FRAGMENT);
|
|
|
|
if (ret)
|
|
|
|
goto err_protocol;
|
|
|
|
|
2008-05-20 00:53:02 +04:00
|
|
|
ret = ip6_frags_sysctl_register();
|
|
|
|
if (ret)
|
|
|
|
goto err_sysctl;
|
|
|
|
|
2008-05-20 00:52:28 +04:00
|
|
|
ret = register_pernet_subsys(&ip6_frags_ops);
|
|
|
|
if (ret)
|
|
|
|
goto err_pernet;
|
2008-01-22 16:58:31 +03:00
|
|
|
|
2007-12-11 13:24:29 +03:00
|
|
|
out:
|
|
|
|
return ret;
|
2008-05-20 00:52:28 +04:00
|
|
|
|
|
|
|
err_pernet:
|
2008-05-20 00:53:02 +04:00
|
|
|
ip6_frags_sysctl_unregister();
|
|
|
|
err_sysctl:
|
2008-05-20 00:52:28 +04:00
|
|
|
inet6_del_protocol(&frag_protocol, IPPROTO_FRAGMENT);
|
2018-03-31 22:58:45 +03:00
|
|
|
err_protocol:
|
|
|
|
inet_frags_fini(&ip6_frags);
|
2008-05-20 00:52:28 +04:00
|
|
|
goto out;
|
2007-12-11 13:24:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ipv6_frag_exit(void)
|
|
|
|
{
|
2008-05-20 00:53:02 +04:00
|
|
|
ip6_frags_sysctl_unregister();
|
2008-01-22 17:12:39 +03:00
|
|
|
unregister_pernet_subsys(&ip6_frags_ops);
|
2007-12-11 13:24:29 +03:00
|
|
|
inet6_del_protocol(&frag_protocol, IPPROTO_FRAGMENT);
|
2019-05-28 02:56:48 +03:00
|
|
|
inet_frags_fini(&ip6_frags);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|