Blame view
net/ipv4/xfrm4_output.c
2.3 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 |
/* * xfrm4_output.c - Common IPsec encapsulation code for IPv4. * Copyright (c) 2004 Herbert Xu <herbert@gondor.apana.org.au> |
e905a9eda [NET] IPV4: Fix w... |
4 |
* |
1da177e4c Linux-2.6.12-rc2 |
5 6 7 8 9 |
* This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ |
09b8f7a93 [IPSEC]: Handle G... |
10 11 |
#include <linux/if_ether.h> #include <linux/kernel.h> |
36cf9acf9 [IPSEC]: Separate... |
12 |
#include <linux/module.h> |
1da177e4c Linux-2.6.12-rc2 |
13 |
#include <linux/skbuff.h> |
16a6677fd [XFRM]: Netfilter... |
14 |
#include <linux/netfilter_ipv4.h> |
36cf9acf9 [IPSEC]: Separate... |
15 |
#include <net/dst.h> |
1da177e4c Linux-2.6.12-rc2 |
16 17 18 |
#include <net/ip.h> #include <net/xfrm.h> #include <net/icmp.h> |
1da177e4c Linux-2.6.12-rc2 |
19 20 21 22 |
static int xfrm4_tunnel_check_size(struct sk_buff *skb) { int mtu, ret = 0; struct dst_entry *dst; |
1da177e4c Linux-2.6.12-rc2 |
23 24 25 |
if (IPCB(skb)->flags & IPSKB_XFRM_TUNNEL_SIZE) goto out; |
eddc9ec53 [SK_BUFF]: Introd... |
26 |
if (!(ip_hdr(skb)->frag_off & htons(IP_DF)) || skb->local_df) |
1da177e4c Linux-2.6.12-rc2 |
27 |
goto out; |
adf30907d net: skb->dst acc... |
28 |
dst = skb_dst(skb); |
1da177e4c Linux-2.6.12-rc2 |
29 30 |
mtu = dst_mtu(dst); if (skb->len > mtu) { |
b00897b88 xfrm4: Don't call... |
31 32 33 34 35 36 |
if (skb->sk) ip_local_error(skb->sk, EMSGSIZE, ip_hdr(skb)->daddr, inet_sk(skb->sk)->inet_dport, mtu); else icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(mtu)); |
1da177e4c Linux-2.6.12-rc2 |
37 38 39 40 41 |
ret = -EMSGSIZE; } out: return ret; } |
36cf9acf9 [IPSEC]: Separate... |
42 43 44 45 46 47 48 |
int xfrm4_extract_output(struct xfrm_state *x, struct sk_buff *skb) { int err; err = xfrm4_tunnel_check_size(skb); if (err) return err; |
60d5fcfb1 [IPSEC]: Remove n... |
49 |
XFRM_MODE_SKB_CB(skb)->protocol = ip_hdr(skb)->protocol; |
36cf9acf9 [IPSEC]: Separate... |
50 51 52 53 54 55 |
return xfrm4_extract_header(skb); } int xfrm4_prepare_output(struct xfrm_state *x, struct sk_buff *skb) { int err; |
df9dcb458 [IPSEC]: Fix inte... |
56 |
err = xfrm_inner_extract_output(x, skb); |
36cf9acf9 [IPSEC]: Separate... |
57 58 59 60 |
if (err) return err; memset(IPCB(skb), 0, sizeof(*IPCB(skb))); |
862b82c6f [IPSEC]: Merge mo... |
61 |
IPCB(skb)->flags |= IPSKB_XFRM_TUNNEL_SIZE | IPSKB_XFRM_TRANSFORMED; |
36cf9acf9 [IPSEC]: Separate... |
62 63 64 65 66 67 |
skb->protocol = htons(ETH_P_IP); return x->outer_mode->output2(x, skb); } EXPORT_SYMBOL(xfrm4_prepare_output); |
43a4dea4c xfrm: Assign the ... |
68 |
int xfrm4_output_finish(struct sk_buff *skb) |
09b8f7a93 [IPSEC]: Handle G... |
69 |
{ |
09b8f7a93 [IPSEC]: Handle G... |
70 |
#ifdef CONFIG_NETFILTER |
adf30907d net: skb->dst acc... |
71 |
if (!skb_dst(skb)->xfrm) { |
09b8f7a93 [IPSEC]: Handle G... |
72 73 74 |
IPCB(skb)->flags |= IPSKB_REROUTED; return dst_output(skb); } |
09b8f7a93 [IPSEC]: Handle G... |
75 |
|
862b82c6f [IPSEC]: Merge mo... |
76 77 |
IPCB(skb)->flags |= IPSKB_XFRM_TRANSFORMED; #endif |
09b8f7a93 [IPSEC]: Handle G... |
78 79 |
skb->protocol = htons(ETH_P_IP); |
862b82c6f [IPSEC]: Merge mo... |
80 |
return xfrm_output(skb); |
09b8f7a93 [IPSEC]: Handle G... |
81 |
} |
16a6677fd [XFRM]: Netfilter... |
82 83 |
int xfrm4_output(struct sk_buff *skb) { |
43a4dea4c xfrm: Assign the ... |
84 85 |
struct dst_entry *dst = skb_dst(skb); struct xfrm_state *x = dst->xfrm; |
9bbc768aa netfilter: ipv4: ... |
86 |
return NF_HOOK_COND(NFPROTO_IPV4, NF_INET_POST_ROUTING, skb, |
43a4dea4c xfrm: Assign the ... |
87 88 |
NULL, dst->dev, x->outer_mode->afinfo->output_finish, |
48d5cad87 [XFRM]: Fix SNAT-... |
89 |
!(IPCB(skb)->flags & IPSKB_REROUTED)); |
16a6677fd [XFRM]: Netfilter... |
90 |
} |