2006-05-28 10:05:54 +04:00
|
|
|
/*
|
|
|
|
* xfrm4_mode_tunnel.c - Tunnel mode encapsulation for IPv4.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004-2006 Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
*/
|
|
|
|
|
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/gfp.h>
|
2006-05-28 10:05:54 +04:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/stringify.h>
|
|
|
|
#include <net/dst.h>
|
|
|
|
#include <net/inet_ecn.h>
|
|
|
|
#include <net/ip.h>
|
|
|
|
#include <net/xfrm.h>
|
|
|
|
|
|
|
|
static inline void ipip_ecn_decapsulate(struct sk_buff *skb)
|
|
|
|
{
|
2007-04-26 05:02:22 +04:00
|
|
|
struct iphdr *inner_iph = ipip_hdr(skb);
|
2006-05-28 10:05:54 +04:00
|
|
|
|
2007-11-14 08:41:28 +03:00
|
|
|
if (INET_ECN_is_ce(XFRM_MODE_SKB_CB(skb)->tos))
|
2006-05-28 10:05:54 +04:00
|
|
|
IP_ECN_set_ce(inner_iph);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add encapsulation header.
|
|
|
|
*
|
2007-10-11 02:45:52 +04:00
|
|
|
* The top IP header will be constructed per RFC 2401.
|
2006-05-28 10:05:54 +04:00
|
|
|
*/
|
2007-12-21 00:53:40 +03:00
|
|
|
static int xfrm4_mode_tunnel_output(struct xfrm_state *x, struct sk_buff *skb)
|
2006-05-28 10:05:54 +04:00
|
|
|
{
|
2009-06-02 09:19:30 +04:00
|
|
|
struct dst_entry *dst = skb_dst(skb);
|
2007-11-14 08:40:52 +03:00
|
|
|
struct iphdr *top_iph;
|
2006-05-28 10:05:54 +04:00
|
|
|
int flags;
|
|
|
|
|
2007-10-11 02:44:06 +04:00
|
|
|
skb_set_network_header(skb, -x->props.header_len);
|
2007-10-11 02:44:44 +04:00
|
|
|
skb->mac_header = skb->network_header +
|
|
|
|
offsetof(struct iphdr, protocol);
|
2007-11-14 08:40:52 +03:00
|
|
|
skb->transport_header = skb->network_header + sizeof(*top_iph);
|
2007-04-21 09:47:35 +04:00
|
|
|
top_iph = ip_hdr(skb);
|
2006-05-28 10:05:54 +04:00
|
|
|
|
|
|
|
top_iph->ihl = 5;
|
|
|
|
top_iph->version = 4;
|
|
|
|
|
2009-06-02 09:19:30 +04:00
|
|
|
top_iph->protocol = xfrm_af2proto(skb_dst(skb)->ops->family);
|
2007-02-07 01:27:02 +03:00
|
|
|
|
2013-02-22 13:54:54 +04:00
|
|
|
/* DS disclosing depends on XFRM_SA_XFLAG_DONT_ENCAP_DSCP */
|
|
|
|
if (x->props.extra_flags & XFRM_SA_XFLAG_DONT_ENCAP_DSCP)
|
|
|
|
top_iph->tos = 0;
|
|
|
|
else
|
|
|
|
top_iph->tos = XFRM_MODE_SKB_CB(skb)->tos;
|
|
|
|
top_iph->tos = INET_ECN_encapsulate(top_iph->tos,
|
2007-11-14 08:40:52 +03:00
|
|
|
XFRM_MODE_SKB_CB(skb)->tos);
|
2006-05-28 10:05:54 +04:00
|
|
|
|
2007-11-14 08:40:52 +03:00
|
|
|
flags = x->props.flags;
|
2006-05-28 10:05:54 +04:00
|
|
|
if (flags & XFRM_STATE_NOECN)
|
|
|
|
IP_ECN_clear(top_iph);
|
|
|
|
|
2007-11-14 08:40:52 +03:00
|
|
|
top_iph->frag_off = (flags & XFRM_STATE_NOPMTUDISC) ?
|
2008-06-18 03:37:13 +04:00
|
|
|
0 : (XFRM_MODE_SKB_CB(skb)->frag_off & htons(IP_DF));
|
2006-05-28 10:05:54 +04:00
|
|
|
|
2010-12-13 08:55:08 +03:00
|
|
|
top_iph->ttl = ip4_dst_hoplimit(dst->child);
|
2006-05-28 10:05:54 +04:00
|
|
|
|
|
|
|
top_iph->saddr = x->props.saddr.a4;
|
|
|
|
top_iph->daddr = x->id.daddr.a4;
|
inetpeer: get rid of ip_id_count
Ideally, we would need to generate IP ID using a per destination IP
generator.
linux kernels used inet_peer cache for this purpose, but this had a huge
cost on servers disabling MTU discovery.
1) each inet_peer struct consumes 192 bytes
2) inetpeer cache uses a binary tree of inet_peer structs,
with a nominal size of ~66000 elements under load.
3) lookups in this tree are hitting a lot of cache lines, as tree depth
is about 20.
4) If server deals with many tcp flows, we have a high probability of
not finding the inet_peer, allocating a fresh one, inserting it in
the tree with same initial ip_id_count, (cf secure_ip_id())
5) We garbage collect inet_peer aggressively.
IP ID generation do not have to be 'perfect'
Goal is trying to avoid duplicates in a short period of time,
so that reassembly units have a chance to complete reassembly of
fragments belonging to one message before receiving other fragments
with a recycled ID.
We simply use an array of generators, and a Jenkin hash using the dst IP
as a key.
ipv6_select_ident() is put back into net/ipv6/ip6_output.c where it
belongs (it is only used from this file)
secure_ip_id() and secure_ipv6_id() no longer are needed.
Rename ip_select_ident_more() to ip_select_ident_segs() to avoid
unnecessary decrement/increment of the number of segments.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-06-02 16:26:03 +04:00
|
|
|
ip_select_ident(skb, NULL);
|
2006-05-28 10:05:54 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-12-21 00:53:40 +03:00
|
|
|
static int xfrm4_mode_tunnel_input(struct xfrm_state *x, struct sk_buff *skb)
|
2006-05-28 10:05:54 +04:00
|
|
|
{
|
|
|
|
int err = -EINVAL;
|
|
|
|
|
2007-11-14 08:41:28 +03:00
|
|
|
if (XFRM_MODE_SKB_CB(skb)->protocol != IPPROTO_IPIP)
|
|
|
|
goto out;
|
2007-02-07 01:27:02 +03:00
|
|
|
|
2006-05-28 10:05:54 +04:00
|
|
|
if (!pskb_may_pull(skb, sizeof(struct iphdr)))
|
|
|
|
goto out;
|
|
|
|
|
2013-02-16 11:40:29 +04:00
|
|
|
err = skb_unclone(skb, GFP_ATOMIC);
|
|
|
|
if (err)
|
2006-05-28 10:05:54 +04:00
|
|
|
goto out;
|
|
|
|
|
2007-11-14 08:41:28 +03:00
|
|
|
if (x->props.flags & XFRM_STATE_DECAP_DSCP)
|
|
|
|
ipv4_copy_dscp(XFRM_MODE_SKB_CB(skb)->tos, ipip_hdr(skb));
|
|
|
|
if (!(x->props.flags & XFRM_STATE_NOECN))
|
|
|
|
ipip_ecn_decapsulate(skb);
|
|
|
|
|
2007-04-11 07:45:18 +04:00
|
|
|
skb_reset_network_header(skb);
|
2012-02-23 14:55:02 +04:00
|
|
|
skb_mac_header_rebuild(skb);
|
|
|
|
|
2006-05-28 10:05:54 +04:00
|
|
|
err = 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct xfrm_mode xfrm4_tunnel_mode = {
|
2007-12-21 00:53:40 +03:00
|
|
|
.input2 = xfrm4_mode_tunnel_input,
|
2007-11-14 08:41:28 +03:00
|
|
|
.input = xfrm_prepare_input,
|
2007-12-21 00:53:40 +03:00
|
|
|
.output2 = xfrm4_mode_tunnel_output,
|
2007-11-14 08:40:52 +03:00
|
|
|
.output = xfrm4_prepare_output,
|
2006-05-28 10:05:54 +04:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.encap = XFRM_MODE_TUNNEL,
|
2007-10-18 08:31:50 +04:00
|
|
|
.flags = XFRM_MODE_FLAG_TUNNEL,
|
2006-05-28 10:05:54 +04:00
|
|
|
};
|
|
|
|
|
2007-12-21 00:53:40 +03:00
|
|
|
static int __init xfrm4_mode_tunnel_init(void)
|
2006-05-28 10:05:54 +04:00
|
|
|
{
|
|
|
|
return xfrm_register_mode(&xfrm4_tunnel_mode, AF_INET);
|
|
|
|
}
|
|
|
|
|
2007-12-21 00:53:40 +03:00
|
|
|
static void __exit xfrm4_mode_tunnel_exit(void)
|
2006-05-28 10:05:54 +04:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = xfrm_unregister_mode(&xfrm4_tunnel_mode, AF_INET);
|
|
|
|
BUG_ON(err);
|
|
|
|
}
|
|
|
|
|
2007-12-21 00:53:40 +03:00
|
|
|
module_init(xfrm4_mode_tunnel_init);
|
|
|
|
module_exit(xfrm4_mode_tunnel_exit);
|
2006-05-28 10:05:54 +04:00
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS_XFRM_MODE(AF_INET, XFRM_MODE_TUNNEL);
|