This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / net / ipv6 / xfrm6_tunnel.c
index 5766a13..f5a0654 100644 (file)
@@ -27,8 +27,8 @@
 #include <linux/list.h>
 #include <net/ip.h>
 #include <net/xfrm.h>
+#include <net/icmp.h>
 #include <net/ipv6.h>
-#include <net/protocol.h>
 #include <linux/ipv6.h>
 #include <linux/icmpv6.h>
 
@@ -343,15 +343,68 @@ void xfrm6_tunnel_free_spi(xfrm_address_t *saddr)
 
 EXPORT_SYMBOL(xfrm6_tunnel_free_spi);
 
+int xfrm6_tunnel_check_size(struct sk_buff *skb)
+{
+       int mtu, ret = 0;
+       struct dst_entry *dst = skb->dst;
+
+       mtu = dst_pmtu(dst) - sizeof(struct ipv6hdr);
+       if (mtu < IPV6_MIN_MTU)
+               mtu = IPV6_MIN_MTU;
+
+       if (skb->len > mtu) {
+               icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, skb->dev);
+               ret = -EMSGSIZE;
+       }
+
+       return ret;
+}
+
+EXPORT_SYMBOL(xfrm6_tunnel_check_size);
+
 static int xfrm6_tunnel_output(struct sk_buff **pskb)
 {
        struct sk_buff *skb = *pskb;
-       struct ipv6hdr *top_iph;
-
-       top_iph = (struct ipv6hdr *)skb->data;
+       struct dst_entry *dst = skb->dst;
+       struct xfrm_state *x = dst->xfrm;
+       struct ipv6hdr *iph, *top_iph;
+       int err;
+
+       if ((err = xfrm6_tunnel_check_size(skb)) != 0)
+               goto error_nolock;
+
+       iph = skb->nh.ipv6h;
+
+       top_iph = (struct ipv6hdr *)skb_push(skb, x->props.header_len);
+       top_iph->version = 6;
+       top_iph->priority = iph->priority;
+       top_iph->flow_lbl[0] = iph->flow_lbl[0];
+       top_iph->flow_lbl[1] = iph->flow_lbl[1];
+       top_iph->flow_lbl[2] = iph->flow_lbl[2];
+       top_iph->nexthdr = IPPROTO_IPV6; 
        top_iph->payload_len = htons(skb->len - sizeof(struct ipv6hdr));
+       top_iph->hop_limit = iph->hop_limit;
+       memcpy(&top_iph->saddr, (struct in6_addr *)&x->props.saddr, sizeof(struct in6_addr));
+       memcpy(&top_iph->daddr, (struct in6_addr *)&x->id.daddr, sizeof(struct in6_addr));
+       skb->nh.raw = skb->data;
+       skb->h.raw = skb->nh.raw + sizeof(struct ipv6hdr);
 
-       return 0;
+       x->curlft.bytes += skb->len;
+       x->curlft.packets++;
+
+       spin_unlock_bh(&x->lock);
+
+       if ((skb->dst = dst_pop(dst)) == NULL) { 
+               kfree_skb(skb);
+               err = -EHOSTUNREACH;
+               goto error_nolock;
+       }
+
+       return NET_XMIT_BYPASS;
+
+error_nolock:
+       kfree_skb(skb);
+       return err;
 }
 
 static int xfrm6_tunnel_input(struct xfrm_state *x, struct xfrm_decap_state *decap, struct sk_buff *skb)