linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / net / ipv4 / xfrm4_input.c
index b045c87..850d919 100644 (file)
@@ -9,7 +9,10 @@
  *     
  */
 
+#include <linux/module.h>
 #include <linux/string.h>
+#include <linux/netfilter.h>
+#include <linux/netfilter_ipv4.h>
 #include <net/inet_ecn.h>
 #include <net/ip.h>
 #include <net/xfrm.h>
@@ -19,13 +22,14 @@ int xfrm4_rcv(struct sk_buff *skb)
        return xfrm4_rcv_encap(skb, 0);
 }
 
+EXPORT_SYMBOL(xfrm4_rcv);
+
 static inline void ipip_ecn_decapsulate(struct sk_buff *skb)
 {
        struct iphdr *outer_iph = skb->nh.iph;
        struct iphdr *inner_iph = skb->h.ipiph;
 
-       if (INET_ECN_is_ce(outer_iph->tos) &&
-           INET_ECN_is_not_ce(inner_iph->tos))
+       if (INET_ECN_is_ce(outer_iph->tos))
                IP_ECN_set_ce(inner_iph);
 }
 
@@ -43,6 +47,23 @@ static int xfrm4_parse_spi(struct sk_buff *skb, u8 nexthdr, u32 *spi, u32 *seq)
        return xfrm_parse_spi(skb, nexthdr, spi, seq);
 }
 
+#ifdef CONFIG_NETFILTER
+static inline int xfrm4_rcv_encap_finish(struct sk_buff *skb)
+{
+       struct iphdr *iph = skb->nh.iph;
+
+       if (skb->dst == NULL) {
+               if (ip_route_input(skb, iph->daddr, iph->saddr, iph->tos,
+                                  skb->dev))
+                       goto drop;
+       }
+       return dst_input(skb);
+drop:
+       kfree_skb(skb);
+       return NET_RX_DROP;
+}
+#endif
+
 int xfrm4_rcv_encap(struct sk_buff *skb, __u16 encap_type)
 {
        int err;
@@ -102,6 +123,8 @@ int xfrm4_rcv_encap(struct sk_buff *skb, __u16 encap_type)
                        if (skb_cloned(skb) &&
                            pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
                                goto drop;
+                       if (x->props.flags & XFRM_STATE_DECAP_DSCP)
+                               ipv4_copy_dscp(iph, skb->h.ipiph);
                        if (!(x->props.flags & XFRM_STATE_NOECN))
                                ipip_ecn_decapsulate(skb);
                        skb->mac.raw = memmove(skb->data - skb->mac_len,
@@ -133,6 +156,8 @@ int xfrm4_rcv_encap(struct sk_buff *skb, __u16 encap_type)
        memcpy(skb->sp->x+skb->sp->len, xfrm_vec, xfrm_nr*sizeof(struct sec_decap_state));
        skb->sp->len += xfrm_nr;
 
+       nf_reset(skb);
+
        if (decaps) {
                if (!(skb->dev->flags&IFF_LOOPBACK)) {
                        dst_release(skb->dst);
@@ -141,7 +166,17 @@ int xfrm4_rcv_encap(struct sk_buff *skb, __u16 encap_type)
                netif_rx(skb);
                return 0;
        } else {
+#ifdef CONFIG_NETFILTER
+               __skb_push(skb, skb->data - skb->nh.raw);
+               skb->nh.iph->tot_len = htons(skb->len);
+               ip_send_check(skb->nh.iph);
+
+               NF_HOOK(PF_INET, NF_IP_PRE_ROUTING, skb, skb->dev, NULL,
+                       xfrm4_rcv_encap_finish);
+               return 0;
+#else
                return -skb->nh.iph->protocol;
+#endif
        }
 
 drop_unlock: