2 * xfrm4_output.c - Common IPsec encapsulation code for IPv4.
3 * Copyright (c) 2004 Herbert Xu <herbert@gondor.apana.org.au>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version
8 * 2 of the License, or (at your option) any later version.
11 #include <linux/if_ether.h>
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/skbuff.h>
15 #include <linux/netfilter_ipv4.h>
21 static int xfrm4_tunnel_check_size(struct sk_buff
*skb
)
24 struct dst_entry
*dst
;
26 if (IPCB(skb
)->flags
& IPSKB_XFRM_TUNNEL_SIZE
)
29 if (!(ip_hdr(skb
)->frag_off
& htons(IP_DF
)) || skb
->local_df
)
35 icmp_send(skb
, ICMP_DEST_UNREACH
, ICMP_FRAG_NEEDED
, htonl(mtu
));
42 int xfrm4_extract_output(struct xfrm_state
*x
, struct sk_buff
*skb
)
46 err
= xfrm4_tunnel_check_size(skb
);
50 return xfrm4_extract_header(skb
);
53 int xfrm4_prepare_output(struct xfrm_state
*x
, struct sk_buff
*skb
)
57 err
= x
->inner_mode
->afinfo
->extract_output(x
, skb
);
61 memset(IPCB(skb
), 0, sizeof(*IPCB(skb
)));
62 IPCB(skb
)->flags
|= IPSKB_XFRM_TUNNEL_SIZE
;
64 skb
->protocol
= htons(ETH_P_IP
);
66 return x
->outer_mode
->output2(x
, skb
);
68 EXPORT_SYMBOL(xfrm4_prepare_output
);
70 static inline int xfrm4_output_one(struct sk_buff
*skb
)
74 err
= xfrm_output(skb
);
78 IPCB(skb
)->flags
|= IPSKB_XFRM_TRANSFORMED
;
88 static int xfrm4_output_finish2(struct sk_buff
*skb
)
92 while (likely((err
= xfrm4_output_one(skb
)) == 0)) {
95 err
= __ip_local_out(skb
);
96 if (unlikely(err
!= 1))
100 return dst_output(skb
);
102 err
= nf_hook(PF_INET
, NF_IP_POST_ROUTING
, skb
, NULL
,
103 skb
->dst
->dev
, xfrm4_output_finish2
);
104 if (unlikely(err
!= 1))
111 static int xfrm4_output_finish(struct sk_buff
*skb
)
113 struct sk_buff
*segs
;
115 #ifdef CONFIG_NETFILTER
116 if (!skb
->dst
->xfrm
) {
117 IPCB(skb
)->flags
|= IPSKB_REROUTED
;
118 return dst_output(skb
);
122 if (!skb_is_gso(skb
))
123 return xfrm4_output_finish2(skb
);
125 skb
->protocol
= htons(ETH_P_IP
);
126 segs
= skb_gso_segment(skb
, 0);
128 if (unlikely(IS_ERR(segs
)))
129 return PTR_ERR(segs
);
132 struct sk_buff
*nskb
= segs
->next
;
136 err
= xfrm4_output_finish2(segs
);
139 while ((segs
= nskb
)) {
153 int xfrm4_output(struct sk_buff
*skb
)
155 return NF_HOOK_COND(PF_INET
, NF_IP_POST_ROUTING
, skb
, NULL
, skb
->dst
->dev
,
157 !(IPCB(skb
)->flags
& IPSKB_REROUTED
));
This page took 0.033045 seconds and 5 git commands to generate.