2006-05-28 13:05:54 +07: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 15:04:11 +07:00
|
|
|
#include <linux/gfp.h>
|
2006-05-28 13:05:54 +07: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 08:02:22 +07:00
|
|
|
struct iphdr *inner_iph = ipip_hdr(skb);
|
2006-05-28 13:05:54 +07:00
|
|
|
|
2007-11-14 12:41:28 +07:00
|
|
|
if (INET_ECN_is_ce(XFRM_MODE_SKB_CB(skb)->tos))
|
2006-05-28 13:05:54 +07:00
|
|
|
IP_ECN_set_ce(inner_iph);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add encapsulation header.
|
|
|
|
*
|
2007-10-11 05:45:52 +07:00
|
|
|
* The top IP header will be constructed per RFC 2401.
|
2006-05-28 13:05:54 +07:00
|
|
|
*/
|
2007-12-21 04:53:40 +07:00
|
|
|
static int xfrm4_mode_tunnel_output(struct xfrm_state *x, struct sk_buff *skb)
|
2006-05-28 13:05:54 +07:00
|
|
|
{
|
2009-06-02 12:19:30 +07:00
|
|
|
struct dst_entry *dst = skb_dst(skb);
|
2007-11-14 12:40:52 +07:00
|
|
|
struct iphdr *top_iph;
|
2006-05-28 13:05:54 +07:00
|
|
|
int flags;
|
|
|
|
|
2007-10-11 05:44:06 +07:00
|
|
|
skb_set_network_header(skb, -x->props.header_len);
|
2007-10-11 05:44:44 +07:00
|
|
|
skb->mac_header = skb->network_header +
|
|
|
|
offsetof(struct iphdr, protocol);
|
2007-11-14 12:40:52 +07:00
|
|
|
skb->transport_header = skb->network_header + sizeof(*top_iph);
|
2007-04-21 12:47:35 +07:00
|
|
|
top_iph = ip_hdr(skb);
|
2006-05-28 13:05:54 +07:00
|
|
|
|
|
|
|
top_iph->ihl = 5;
|
|
|
|
top_iph->version = 4;
|
|
|
|
|
2009-06-02 12:19:30 +07:00
|
|
|
top_iph->protocol = xfrm_af2proto(skb_dst(skb)->ops->family);
|
2007-02-07 05:27:02 +07:00
|
|
|
|
2013-02-22 16:54:54 +07: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 12:40:52 +07:00
|
|
|
XFRM_MODE_SKB_CB(skb)->tos);
|
2006-05-28 13:05:54 +07:00
|
|
|
|
2007-11-14 12:40:52 +07:00
|
|
|
flags = x->props.flags;
|
2006-05-28 13:05:54 +07:00
|
|
|
if (flags & XFRM_STATE_NOECN)
|
|
|
|
IP_ECN_clear(top_iph);
|
|
|
|
|
2007-11-14 12:40:52 +07:00
|
|
|
top_iph->frag_off = (flags & XFRM_STATE_NOPMTUDISC) ?
|
2008-06-18 06:37:13 +07:00
|
|
|
0 : (XFRM_MODE_SKB_CB(skb)->frag_off & htons(IP_DF));
|
2006-05-28 13:05:54 +07:00
|
|
|
|
2010-12-13 12:55:08 +07:00
|
|
|
top_iph->ttl = ip4_dst_hoplimit(dst->child);
|
2006-05-28 13:05:54 +07: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 19:26:03 +07:00
|
|
|
ip_select_ident(skb, NULL);
|
2006-05-28 13:05:54 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-12-21 04:53:40 +07:00
|
|
|
static int xfrm4_mode_tunnel_input(struct xfrm_state *x, struct sk_buff *skb)
|
2006-05-28 13:05:54 +07:00
|
|
|
{
|
|
|
|
int err = -EINVAL;
|
|
|
|
|
2007-11-14 12:41:28 +07:00
|
|
|
if (XFRM_MODE_SKB_CB(skb)->protocol != IPPROTO_IPIP)
|
|
|
|
goto out;
|
2007-02-07 05:27:02 +07:00
|
|
|
|
2006-05-28 13:05:54 +07:00
|
|
|
if (!pskb_may_pull(skb, sizeof(struct iphdr)))
|
|
|
|
goto out;
|
|
|
|
|
2013-02-16 14:40:29 +07:00
|
|
|
err = skb_unclone(skb, GFP_ATOMIC);
|
|
|
|
if (err)
|
2006-05-28 13:05:54 +07:00
|
|
|
goto out;
|
|
|
|
|
2007-11-14 12:41:28 +07: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 10:45:18 +07:00
|
|
|
skb_reset_network_header(skb);
|
2012-02-23 17:55:02 +07:00
|
|
|
skb_mac_header_rebuild(skb);
|
|
|
|
|
2006-05-28 13:05:54 +07:00
|
|
|
err = 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct xfrm_mode xfrm4_tunnel_mode = {
|
2007-12-21 04:53:40 +07:00
|
|
|
.input2 = xfrm4_mode_tunnel_input,
|
2007-11-14 12:41:28 +07:00
|
|
|
.input = xfrm_prepare_input,
|
2007-12-21 04:53:40 +07:00
|
|
|
.output2 = xfrm4_mode_tunnel_output,
|
2007-11-14 12:40:52 +07:00
|
|
|
.output = xfrm4_prepare_output,
|
2006-05-28 13:05:54 +07:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.encap = XFRM_MODE_TUNNEL,
|
2007-10-18 11:31:50 +07:00
|
|
|
.flags = XFRM_MODE_FLAG_TUNNEL,
|
2006-05-28 13:05:54 +07:00
|
|
|
};
|
|
|
|
|
2007-12-21 04:53:40 +07:00
|
|
|
static int __init xfrm4_mode_tunnel_init(void)
|
2006-05-28 13:05:54 +07:00
|
|
|
{
|
|
|
|
return xfrm_register_mode(&xfrm4_tunnel_mode, AF_INET);
|
|
|
|
}
|
|
|
|
|
2007-12-21 04:53:40 +07:00
|
|
|
static void __exit xfrm4_mode_tunnel_exit(void)
|
2006-05-28 13:05:54 +07:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = xfrm_unregister_mode(&xfrm4_tunnel_mode, AF_INET);
|
|
|
|
BUG_ON(err);
|
|
|
|
}
|
|
|
|
|
2007-12-21 04:53:40 +07:00
|
|
|
module_init(xfrm4_mode_tunnel_init);
|
|
|
|
module_exit(xfrm4_mode_tunnel_exit);
|
2006-05-28 13:05:54 +07:00
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS_XFRM_MODE(AF_INET, XFRM_MODE_TUNNEL);
|