gre: Unify IPTUNNEL_XMIT across kernel versions.
authorJesse Gross <jesse@nicira.com>
Tue, 2 Feb 2010 21:44:44 +0000 (16:44 -0500)
committerJesse Gross <jesse@nicira.com>
Thu, 4 Feb 2010 20:44:40 +0000 (15:44 -0500)
The IPTUNNEL_XMIT macro was split into different versions based on
the kernel.  This adds the compatibility code to allow a single
copy to work on all kernel versions, making it easier to maintain.

datapath/linux-2.6/Modules.mk
datapath/linux-2.6/compat-2.6/include/linux/netdevice.h
datapath/linux-2.6/compat-2.6/include/net/ip.h [new file with mode: 0644]
datapath/linux-2.6/compat-2.6/include/net/ipip.h
datapath/linux-2.6/compat-2.6/ip_output-ip_gre.c [new file with mode: 0644]

index 8d2f969..dafbcad 100644 (file)
@@ -52,6 +52,7 @@ dist_modules += ip_gre
 build_modules += $(if $(BUILD_GRE),ip_gre)
 ip_gre_sources = \
        linux-2.6/compat-2.6/ip_gre.c \
+       linux-2.6/compat-2.6/ip_output-ip_gre.c \
        linux-2.6/compat-2.6/net_namespace-ip_gre.c
 ip_gre_headers = \
        linux-2.6/compat-2.6/compat26.h \
@@ -66,6 +67,7 @@ ip_gre_headers = \
        linux-2.6/compat-2.6/include/linux/tcp.h \
        linux-2.6/compat-2.6/include/linux/types.h \
        linux-2.6/compat-2.6/include/net/dst.h \
+       linux-2.6/compat-2.6/include/net/ip.h \
        linux-2.6/compat-2.6/include/net/ipip.h \
        linux-2.6/compat-2.6/include/net/netns/generic.h \
        linux-2.6/compat-2.6/include/net/net_namespace.h \
index c25f2bd..0a0e47a 100644 (file)
@@ -63,6 +63,8 @@ typedef int netdev_tx_t;
 #define for_each_netdev(net,d) list_for_each_entry(d, &dev_base_head, dev_list)
 #endif
 
-
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
+#define net_xmit_eval(e)       ((e) == NET_XMIT_CN? 0 : (e))
+#endif
 
 #endif
diff --git a/datapath/linux-2.6/compat-2.6/include/net/ip.h b/datapath/linux-2.6/compat-2.6/include/net/ip.h
new file mode 100644 (file)
index 0000000..b18b968
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef __NET_IP_WRAPPER_H
+#define __NET_IP_WRAPPER_H 1
+
+#include_next <net/ip.h>
+
+#include <linux/version.h>
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
+
+extern int             __ip_local_out(struct sk_buff *skb);
+extern int             ip_local_out(struct sk_buff *skb);
+
+#endif /* linux kernel < 2.6.25 */
+
+#endif
index 2eca5f8..604ece2 100644 (file)
@@ -48,31 +48,11 @@ struct ip_tunnel_prl_entry
        spinlock_t                      lock;
 };
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
 #define IPTUNNEL_XMIT() do {                                           \
        int err;                                                        \
        int pkt_len = skb->len - skb_transport_offset(skb);             \
                                                                        \
        skb->ip_summed = CHECKSUM_NONE;                                 \
-       iph->tot_len = htons(skb->len);                                 \
-       ip_select_ident(iph, &rt->u.dst, NULL);                         \
-       ip_send_check(iph);                                             \
-                                                                       \
-       err = NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev, dst_output);\
-       if (err == NET_XMIT_SUCCESS || err == NET_XMIT_CN) {            \
-               stats->tx_bytes += pkt_len;                             \
-               stats->tx_packets++;                                    \
-       } else {                                                        \
-               stats->tx_errors++;                                     \
-               stats->tx_aborted_errors++;                             \
-       }                                                               \
-} while (0)
-#else
-#define IPTUNNEL_XMIT() do {                                           \
-       int err;                                                        \
-       int pkt_len = skb->len;                                         \
-                                                                       \
-       skb->ip_summed = CHECKSUM_NONE;                                 \
        ip_select_ident(iph, &rt->u.dst, NULL);                         \
                                                                        \
        err = ip_local_out(skb);                                        \
@@ -84,7 +64,6 @@ struct ip_tunnel_prl_entry
                stats->tx_aborted_errors++;                             \
        }                                                               \
 } while (0)
-#endif
 
 #else
 #include_next <net/ipip.h>
diff --git a/datapath/linux-2.6/compat-2.6/ip_output-ip_gre.c b/datapath/linux-2.6/compat-2.6/ip_output-ip_gre.c
new file mode 100644 (file)
index 0000000..a09fcbc
--- /dev/null
@@ -0,0 +1,33 @@
+#include <linux/version.h>
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
+
+#include <linux/netfilter_ipv4.h>
+#include <net/ip.h>
+
+int __ip_local_out(struct sk_buff *skb)
+{
+       struct iphdr *iph = ip_hdr(skb);
+
+       iph->tot_len = htons(skb->len);
+       ip_send_check(iph);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
+       return nf_hook(PF_INET, NF_IP_LOCAL_OUT, &skb, NULL, skb->dst->dev,
+                      dst_output);
+#else
+       return nf_hook(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, skb->dst->dev,
+                      dst_output);
+#endif /* kernel < 2.6.24 */
+}
+
+int ip_local_out(struct sk_buff *skb)
+{
+       int err;
+
+       err = __ip_local_out(skb);
+       if (likely(err == 1))
+               err = dst_output(skb);
+
+       return err;
+}
+
+#endif /* kernel < 2.6.25 */