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 int xfrm6_find_1stfragopt(struct xfrm_state *x, struct sk_buff *skb,
23 return ip6_find_1stfragopt(skb, prevhdr);
26 static int xfrm6_tunnel_check_size(struct sk_buff *skb)
29 struct dst_entry *dst = skb->dst;
32 if (mtu < IPV6_MIN_MTU)
37 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, skb->dev);
44 static int xfrm6_output_one(struct sk_buff *skb)
46 struct dst_entry *dst = skb->dst;
47 struct xfrm_state *x = dst->xfrm;
50 if (skb->ip_summed == CHECKSUM_PARTIAL) {
51 err = skb_checksum_help(skb);
56 if (x->props.mode == XFRM_MODE_TUNNEL) {
57 err = xfrm6_tunnel_check_size(skb);
63 spin_lock_bh(&x->lock);
64 err = xfrm_state_check(x, skb);
68 err = x->mode->output(x, skb);
72 err = x->type->output(x, skb);
76 x->curlft.bytes += skb->len;
78 if (x->props.mode == XFRM_MODE_ROUTEOPTIMIZATION)
79 x->lastused = (u64)xtime.tv_sec;
81 spin_unlock_bh(&x->lock);
83 skb->nh.raw = skb->data;
85 if (!(skb->dst = dst_pop(dst))) {
91 } while (x && (x->props.mode != XFRM_MODE_TUNNEL));
93 IP6CB(skb)->flags |= IP6SKB_XFRM_TRANSFORMED;
99 spin_unlock_bh(&x->lock);
105 static int xfrm6_output_finish2(struct sk_buff *skb)
109 while (likely((err = xfrm6_output_one(skb)) == 0)) {
112 err = nf_hook(PF_INET6, NF_IP6_LOCAL_OUT, &skb, NULL,
113 skb->dst->dev, dst_output);
114 if (unlikely(err != 1))
118 return dst_output(skb);
120 err = nf_hook(PF_INET6, NF_IP6_POST_ROUTING, &skb, NULL,
121 skb->dst->dev, xfrm6_output_finish2);
122 if (unlikely(err != 1))
129 static int xfrm6_output_finish(struct sk_buff *skb)
131 struct sk_buff *segs;
133 if (!skb_is_gso(skb))
134 return xfrm6_output_finish2(skb);
136 skb->protocol = htons(ETH_P_IPV6);
137 segs = skb_gso_segment(skb, 0);
139 if (unlikely(IS_ERR(segs)))
140 return PTR_ERR(segs);
143 struct sk_buff *nskb = segs->next;
147 err = xfrm6_output_finish2(segs);
150 while ((segs = nskb)) {
164 int xfrm6_output(struct sk_buff *skb)
166 return NF_HOOK(PF_INET6, NF_IP6_POST_ROUTING, skb, NULL, skb->dst->dev,
167 xfrm6_output_finish);