2 * xfrm6_output.c - Common IPsec encapsulation code for IPv6.
3 * Copyright (C) 2002 USAGI/WIDE Project
4 * Copyright (c) 2004 Herbert Xu <herbert@gondor.apana.org.au>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #include <linux/compiler.h>
13 #include <linux/skbuff.h>
14 #include <linux/spinlock.h>
15 #include <linux/icmpv6.h>
16 #include <linux/netfilter_ipv6.h>
20 static int xfrm6_tunnel_check_size(struct sk_buff *skb)
23 struct dst_entry *dst = skb->dst;
26 if (mtu < IPV6_MIN_MTU)
31 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, skb->dev);
38 static int xfrm6_output_one(struct sk_buff *skb)
40 struct dst_entry *dst = skb->dst;
41 struct xfrm_state *x = dst->xfrm;
44 if (skb->ip_summed == CHECKSUM_HW) {
45 err = skb_checksum_help(skb, 0);
51 err = xfrm6_tunnel_check_size(skb);
57 spin_lock_bh(&x->lock);
58 err = xfrm_state_check(x, skb);
62 err = x->mode->output(skb);
66 err = x->type->output(x, skb);
70 x->curlft.bytes += skb->len;
73 spin_unlock_bh(&x->lock);
75 skb->nh.raw = skb->data;
77 if (!(skb->dst = dst_pop(dst))) {
83 } while (x && !x->props.mode);
85 IP6CB(skb)->flags |= IP6SKB_XFRM_TRANSFORMED;
91 spin_unlock_bh(&x->lock);
97 static int xfrm6_output_finish2(struct sk_buff *skb)
101 while (likely((err = xfrm6_output_one(skb)) == 0)) {
104 err = nf_hook(PF_INET6, NF_IP6_LOCAL_OUT, &skb, NULL,
105 skb->dst->dev, dst_output);
106 if (unlikely(err != 1))
110 return dst_output(skb);
112 err = nf_hook(PF_INET6, NF_IP6_POST_ROUTING, &skb, NULL,
113 skb->dst->dev, xfrm6_output_finish2);
114 if (unlikely(err != 1))
121 static int xfrm6_output_finish(struct sk_buff *skb)
123 struct sk_buff *segs;
125 if (!skb_is_gso(skb))
126 return xfrm6_output_finish2(skb);
128 skb->protocol = htons(ETH_P_IP);
129 segs = skb_gso_segment(skb, 0);
131 if (unlikely(IS_ERR(segs)))
132 return PTR_ERR(segs);
135 struct sk_buff *nskb = segs->next;
139 err = xfrm6_output_finish2(segs);
142 while ((segs = nskb)) {
156 int xfrm6_output(struct sk_buff *skb)
158 return NF_HOOK(PF_INET6, NF_IP6_POST_ROUTING, skb, NULL, skb->dst->dev,
159 xfrm6_output_finish);