aboutsummaryrefslogtreecommitdiffstats
path: root/net/xfrm
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2007-10-08 20:16:30 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-10-10 19:54:53 -0400
commit406ef77c893ebd882209be4e393d64b01fe72054 (patch)
tree815d753889769b355fba7e648abef7ad1422559e /net/xfrm
parentbc31d3b2c7d7f2a03721a05cb3c9a3ce8b1e2e5a (diff)
[IPSEC]: Move common output code to xfrm_output
Most of the code in xfrm4_output_one and xfrm6_output_one are identical so this patch moves them into a common xfrm_output function which will live in net/xfrm. In fact this would seem to fix a bug as on IPv4 we never reset the network header after a transform which may upset netfilter later on. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/xfrm')
-rw-r--r--net/xfrm/Makefile2
-rw-r--r--net/xfrm/xfrm_output.c73
2 files changed, 74 insertions, 1 deletions
diff --git a/net/xfrm/Makefile b/net/xfrm/Makefile
index de3c1a625a46..45744a3d3a51 100644
--- a/net/xfrm/Makefile
+++ b/net/xfrm/Makefile
@@ -3,6 +3,6 @@
3# 3#
4 4
5obj-$(CONFIG_XFRM) := xfrm_policy.o xfrm_state.o xfrm_hash.o \ 5obj-$(CONFIG_XFRM) := xfrm_policy.o xfrm_state.o xfrm_hash.o \
6 xfrm_input.o xfrm_algo.o 6 xfrm_input.o xfrm_output.o xfrm_algo.o
7obj-$(CONFIG_XFRM_USER) += xfrm_user.o 7obj-$(CONFIG_XFRM_USER) += xfrm_user.o
8 8
diff --git a/net/xfrm/xfrm_output.c b/net/xfrm/xfrm_output.c
new file mode 100644
index 000000000000..75f289b488a7
--- /dev/null
+++ b/net/xfrm/xfrm_output.c
@@ -0,0 +1,73 @@
1/*
2 * xfrm_output.c - Common IPsec encapsulation code.
3 *
4 * Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#include <linux/errno.h>
13#include <linux/module.h>
14#include <linux/netdevice.h>
15#include <linux/skbuff.h>
16#include <linux/spinlock.h>
17#include <linux/time.h>
18#include <net/dst.h>
19#include <net/xfrm.h>
20
21int xfrm_output(struct sk_buff *skb)
22{
23 struct dst_entry *dst = skb->dst;
24 struct xfrm_state *x = dst->xfrm;
25 int err;
26
27 if (skb->ip_summed == CHECKSUM_PARTIAL) {
28 err = skb_checksum_help(skb);
29 if (err)
30 goto error_nolock;
31 }
32
33 do {
34 spin_lock_bh(&x->lock);
35 err = xfrm_state_check(x, skb);
36 if (err)
37 goto error;
38
39 err = x->mode->output(x, skb);
40 if (err)
41 goto error;
42
43 err = x->type->output(x, skb);
44 if (err)
45 goto error;
46
47 x->curlft.bytes += skb->len;
48 x->curlft.packets++;
49
50 if (x->props.mode == XFRM_MODE_ROUTEOPTIMIZATION)
51 x->lastused = get_seconds();
52
53 spin_unlock_bh(&x->lock);
54
55 skb_reset_network_header(skb);
56
57 if (!(skb->dst = dst_pop(dst))) {
58 err = -EHOSTUNREACH;
59 goto error_nolock;
60 }
61 dst = skb->dst;
62 x = dst->xfrm;
63 } while (x && (x->props.mode != XFRM_MODE_TUNNEL));
64
65 err = 0;
66
67error_nolock:
68 return err;
69error:
70 spin_unlock_bh(&x->lock);
71 goto error_nolock;
72}
73EXPORT_SYMBOL_GPL(xfrm_output);