Blame view
net/ipv4/xfrm4_output.c
2.58 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 |
static int xfrm4_tunnel_check_size(struct sk_buff *skb) { int mtu, ret = 0; |
1da177e4c Linux-2.6.12-rc2 |
22 23 24 |
if (IPCB(skb)->flags & IPSKB_XFRM_TUNNEL_SIZE) goto out; |
60ff74673 net: rename local... |
25 |
if (!(ip_hdr(skb)->frag_off & htons(IP_DF)) || skb->ignore_df) |
1da177e4c Linux-2.6.12-rc2 |
26 |
goto out; |
5a25cf1e3 xfrm: revert ipv4... |
27 |
mtu = dst_mtu(skb_dst(skb)); |
1da177e4c Linux-2.6.12-rc2 |
28 |
if (skb->len > mtu) { |
ca064bd89 xfrm: Fix pmtu di... |
29 |
skb->protocol = htons(ETH_P_IP); |
b00897b88 xfrm4: Don't call... |
30 |
if (skb->sk) |
628e341f3 xfrm: make local ... |
31 |
xfrm_local_error(skb, mtu); |
b00897b88 xfrm4: Don't call... |
32 33 34 |
else icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(mtu)); |
1da177e4c Linux-2.6.12-rc2 |
35 36 37 38 39 |
ret = -EMSGSIZE; } out: return ret; } |
36cf9acf9 [IPSEC]: Separate... |
40 41 42 43 44 45 46 |
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... |
47 |
XFRM_MODE_SKB_CB(skb)->protocol = ip_hdr(skb)->protocol; |
36cf9acf9 [IPSEC]: Separate... |
48 49 50 51 52 53 |
return xfrm4_extract_header(skb); } int xfrm4_prepare_output(struct xfrm_state *x, struct sk_buff *skb) { int err; |
df9dcb458 [IPSEC]: Fix inte... |
54 |
err = xfrm_inner_extract_output(x, skb); |
36cf9acf9 [IPSEC]: Separate... |
55 56 |
if (err) return err; |
5596732fa xfrm: Fix crash w... |
57 |
IPCB(skb)->flags |= IPSKB_XFRM_TUNNEL_SIZE; |
044a832a7 xfrm: Fix local e... |
58 |
skb->protocol = htons(ETH_P_IP); |
36cf9acf9 [IPSEC]: Separate... |
59 60 61 62 |
return x->outer_mode->output2(x, skb); } EXPORT_SYMBOL(xfrm4_prepare_output); |
7026b1ddb netfilter: Pass s... |
63 |
int xfrm4_output_finish(struct sock *sk, struct sk_buff *skb) |
09b8f7a93 [IPSEC]: Handle G... |
64 |
{ |
5596732fa xfrm: Fix crash w... |
65 |
memset(IPCB(skb), 0, sizeof(*IPCB(skb))); |
5596732fa xfrm: Fix crash w... |
66 67 68 69 |
#ifdef CONFIG_NETFILTER IPCB(skb)->flags |= IPSKB_XFRM_TRANSFORMED; #endif |
7026b1ddb netfilter: Pass s... |
70 |
return xfrm_output(sk, skb); |
5596732fa xfrm: Fix crash w... |
71 |
} |
0c4b51f00 netfilter: Pass n... |
72 |
static int __xfrm4_output(struct net *net, struct sock *sk, struct sk_buff *skb) |
5596732fa xfrm: Fix crash w... |
73 74 |
{ struct xfrm_state *x = skb_dst(skb)->xfrm; |
09b8f7a93 [IPSEC]: Handle G... |
75 |
#ifdef CONFIG_NETFILTER |
5596732fa xfrm: Fix crash w... |
76 |
if (!x) { |
09b8f7a93 [IPSEC]: Handle G... |
77 |
IPCB(skb)->flags |= IPSKB_REROUTED; |
13206b6bf net: Pass net int... |
78 |
return dst_output(net, sk, skb); |
09b8f7a93 [IPSEC]: Handle G... |
79 |
} |
862b82c6f [IPSEC]: Merge mo... |
80 |
#endif |
09b8f7a93 [IPSEC]: Handle G... |
81 |
|
7026b1ddb netfilter: Pass s... |
82 |
return x->outer_mode->afinfo->output_finish(sk, skb); |
09b8f7a93 [IPSEC]: Handle G... |
83 |
} |
ede2059db dst: Pass net int... |
84 |
int xfrm4_output(struct net *net, struct sock *sk, struct sk_buff *skb) |
16a6677fd [XFRM]: Netfilter... |
85 |
{ |
29a26a568 netfilter: Pass s... |
86 87 88 |
return NF_HOOK_COND(NFPROTO_IPV4, NF_INET_POST_ROUTING, net, sk, skb, NULL, skb_dst(skb)->dev, __xfrm4_output, |
48d5cad87 [XFRM]: Fix SNAT-... |
89 |
!(IPCB(skb)->flags & IPSKB_REROUTED)); |
16a6677fd [XFRM]: Netfilter... |
90 |
} |
628e341f3 xfrm: make local ... |
91 92 93 94 95 96 97 98 99 |
void xfrm4_local_error(struct sk_buff *skb, u32 mtu) { struct iphdr *hdr; hdr = skb->encapsulation ? inner_ip_hdr(skb) : ip_hdr(skb); ip_local_error(skb->sk, EMSGSIZE, hdr->daddr, inet_sk(skb->sk)->inet_dport, mtu); } |