From 02059c09d4d7bc4860db9aee7f4daae43b6eab68 Mon Sep 17 00:00:00 2001 From: Jesse Gross Date: Tue, 2 Feb 2010 16:44:44 -0500 Subject: [PATCH] gre: Unify IPTUNNEL_XMIT across kernel versions. 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 | 2 ++ .../compat-2.6/include/linux/netdevice.h | 4 ++- .../linux-2.6/compat-2.6/include/net/ip.h | 14 ++++++++ .../linux-2.6/compat-2.6/include/net/ipip.h | 21 ------------ .../linux-2.6/compat-2.6/ip_output-ip_gre.c | 33 +++++++++++++++++++ 5 files changed, 52 insertions(+), 22 deletions(-) create mode 100644 datapath/linux-2.6/compat-2.6/include/net/ip.h create mode 100644 datapath/linux-2.6/compat-2.6/ip_output-ip_gre.c diff --git a/datapath/linux-2.6/Modules.mk b/datapath/linux-2.6/Modules.mk index 8d2f96966..dafbcad77 100644 --- a/datapath/linux-2.6/Modules.mk +++ b/datapath/linux-2.6/Modules.mk @@ -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 \ diff --git a/datapath/linux-2.6/compat-2.6/include/linux/netdevice.h b/datapath/linux-2.6/compat-2.6/include/linux/netdevice.h index c25f2bd04..0a0e47abd 100644 --- a/datapath/linux-2.6/compat-2.6/include/linux/netdevice.h +++ b/datapath/linux-2.6/compat-2.6/include/linux/netdevice.h @@ -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 index 000000000..b18b968b6 --- /dev/null +++ b/datapath/linux-2.6/compat-2.6/include/net/ip.h @@ -0,0 +1,14 @@ +#ifndef __NET_IP_WRAPPER_H +#define __NET_IP_WRAPPER_H 1 + +#include_next + +#include +#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 diff --git a/datapath/linux-2.6/compat-2.6/include/net/ipip.h b/datapath/linux-2.6/compat-2.6/include/net/ipip.h index 2eca5f8bc..604ece2dc 100644 --- a/datapath/linux-2.6/compat-2.6/include/net/ipip.h +++ b/datapath/linux-2.6/compat-2.6/include/net/ipip.h @@ -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 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 index 000000000..a09fcbce4 --- /dev/null +++ b/datapath/linux-2.6/compat-2.6/ip_output-ip_gre.c @@ -0,0 +1,33 @@ +#include +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25) + +#include +#include + +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 */ -- 2.43.0