fuse: no abort on interrupt
[linux-2.6/openmoko-kernel/knife-kernel.git] / net / ipv4 / xfrm4_output.c
bloba4edd666318b0f85bb9efb166df3512f78bce8d5
1 /*
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.
9 */
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>
16 #include <net/ip.h>
17 #include <net/xfrm.h>
18 #include <net/icmp.h>
20 static int xfrm4_tunnel_check_size(struct sk_buff *skb)
22 int mtu, ret = 0;
23 struct dst_entry *dst;
25 if (IPCB(skb)->flags & IPSKB_XFRM_TUNNEL_SIZE)
26 goto out;
28 IPCB(skb)->flags |= IPSKB_XFRM_TUNNEL_SIZE;
30 if (!(ip_hdr(skb)->frag_off & htons(IP_DF)) || skb->local_df)
31 goto out;
33 dst = skb->dst;
34 mtu = dst_mtu(dst);
35 if (skb->len > mtu) {
36 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(mtu));
37 ret = -EMSGSIZE;
39 out:
40 return ret;
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;
47 struct iphdr *iph;
48 int err;
50 if (x->props.mode == XFRM_MODE_TUNNEL) {
51 err = xfrm4_tunnel_check_size(skb);
52 if (err)
53 goto error_nolock;
56 err = xfrm_output(skb);
57 if (err)
58 goto error_nolock;
60 iph = ip_hdr(skb);
61 iph->tot_len = htons(skb->len);
62 ip_send_check(iph);
64 IPCB(skb)->flags |= IPSKB_XFRM_TRANSFORMED;
65 err = 0;
67 out_exit:
68 return err;
69 error_nolock:
70 kfree_skb(skb);
71 goto out_exit;
74 static int xfrm4_output_finish2(struct sk_buff *skb)
76 int err;
78 while (likely((err = xfrm4_output_one(skb)) == 0)) {
79 nf_reset(skb);
81 err = nf_hook(PF_INET, NF_IP_LOCAL_OUT, skb, NULL,
82 skb->dst->dev, dst_output);
83 if (unlikely(err != 1))
84 break;
86 if (!skb->dst->xfrm)
87 return dst_output(skb);
89 err = nf_hook(PF_INET, NF_IP_POST_ROUTING, skb, NULL,
90 skb->dst->dev, xfrm4_output_finish2);
91 if (unlikely(err != 1))
92 break;
95 return err;
98 static int xfrm4_output_finish(struct sk_buff *skb)
100 struct sk_buff *segs;
102 #ifdef CONFIG_NETFILTER
103 if (!skb->dst->xfrm) {
104 IPCB(skb)->flags |= IPSKB_REROUTED;
105 return dst_output(skb);
107 #endif
109 if (!skb_is_gso(skb))
110 return xfrm4_output_finish2(skb);
112 skb->protocol = htons(ETH_P_IP);
113 segs = skb_gso_segment(skb, 0);
114 kfree_skb(skb);
115 if (unlikely(IS_ERR(segs)))
116 return PTR_ERR(segs);
118 do {
119 struct sk_buff *nskb = segs->next;
120 int err;
122 segs->next = NULL;
123 err = xfrm4_output_finish2(segs);
125 if (unlikely(err)) {
126 while ((segs = nskb)) {
127 nskb = segs->next;
128 segs->next = NULL;
129 kfree_skb(segs);
131 return err;
134 segs = nskb;
135 } while (segs);
137 return 0;
140 int xfrm4_output(struct sk_buff *skb)
142 return NF_HOOK_COND(PF_INET, NF_IP_POST_ROUTING, skb, NULL, skb->dst->dev,
143 xfrm4_output_finish,
144 !(IPCB(skb)->flags & IPSKB_REROUTED));