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/compiler.h>
12 #include <linux/if_ether.h>
13 #include <linux/kernel.h>
14 #include <linux/skbuff.h>
15 #include <linux/netfilter_ipv4.h>
20 static int xfrm4_tunnel_check_size(struct sk_buff *skb)
23 struct dst_entry *dst;
25 if (IPCB(skb)->flags & IPSKB_XFRM_TUNNEL_SIZE)
28 IPCB(skb)->flags |= IPSKB_XFRM_TUNNEL_SIZE;
30 if (!(ip_hdr(skb)->frag_off & htons(IP_DF)) || skb->local_df)
36 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(mtu));
43 static inline int xfrm4_output_one(struct sk_buff *skb)
45 struct dst_entry *dst = skb->dst;
46 struct xfrm_state *x = dst->xfrm;
49 if (x->props.mode == XFRM_MODE_TUNNEL) {
50 err = xfrm4_tunnel_check_size(skb);
55 err = xfrm_output(skb);
59 IPCB(skb)->flags |= IPSKB_XFRM_TRANSFORMED;
69 static int xfrm4_output_finish2(struct sk_buff *skb)
73 while (likely((err = xfrm4_output_one(skb)) == 0)) {
76 err = nf_hook(PF_INET, NF_IP_LOCAL_OUT, &skb, NULL,
77 skb->dst->dev, dst_output);
78 if (unlikely(err != 1))
82 return dst_output(skb);
84 err = nf_hook(PF_INET, NF_IP_POST_ROUTING, &skb, NULL,
85 skb->dst->dev, xfrm4_output_finish2);
86 if (unlikely(err != 1))
93 static int xfrm4_output_finish(struct sk_buff *skb)
97 #ifdef CONFIG_NETFILTER
98 if (!skb->dst->xfrm) {
99 IPCB(skb)->flags |= IPSKB_REROUTED;
100 return dst_output(skb);
104 if (!skb_is_gso(skb))
105 return xfrm4_output_finish2(skb);
107 skb->protocol = htons(ETH_P_IP);
108 segs = skb_gso_segment(skb, 0);
110 if (unlikely(IS_ERR(segs)))
111 return PTR_ERR(segs);
114 struct sk_buff *nskb = segs->next;
118 err = xfrm4_output_finish2(segs);
121 while ((segs = nskb)) {
135 int xfrm4_output(struct sk_buff *skb)
137 return NF_HOOK_COND(PF_INET, NF_IP_POST_ROUTING, skb, NULL, skb->dst->dev,
139 !(IPCB(skb)->flags & IPSKB_REROUTED));