From 4ae2b2c1c4c345d0cb5f5a6b0f20fd6afb4a6962 Mon Sep 17 00:00:00 2001 From: Pravin B Shelar Date: Fri, 3 Oct 2014 05:26:42 -0700 Subject: [PATCH] datapath: Add support for RHEL-7 / CentOS-7 kernel. This patch mostly is related to tunnel API where RHEL 7 kernel API are not in-sync with newer linux kernel API. So extra checks are required to check for parameters of API. Signed-off-by: Pravin B Shelar Acked-by: Jiri Benc --- acinclude.m4 | 7 +++++++ datapath/datapath.c | 2 +- datapath/linux/compat/gre.c | 3 +++ datapath/linux/compat/include/linux/hash.h | 7 +++---- datapath/linux/compat/include/linux/skbuff.h | 4 ++++ datapath/linux/compat/include/net/genetlink.h | 2 +- datapath/linux/compat/include/net/gre.h | 2 +- datapath/linux/compat/include/net/ip_tunnels.h | 10 +++++++++- datapath/linux/compat/include/net/vxlan.h | 10 +++++++--- datapath/linux/compat/ip_tunnels_core.c | 6 +++--- datapath/linux/compat/skbuff-openvswitch.c | 2 ++ datapath/linux/compat/vxlan.c | 3 ++- 12 files changed, 43 insertions(+), 15 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index fa1de8668..c1dd90b9a 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -242,6 +242,7 @@ AC_DEFUN([OVS_CHECK_LINUX_COMPAT], [ [OVS_DEFINE([HAVE_CSUM_COPY_DBG])]) OVS_GREP_IFELSE([$KSRC/include/linux/err.h], [ERR_CAST]) + OVS_GREP_IFELSE([$KSRC/include/linux/hash.h], [fast_hash_ops]) OVS_GREP_IFELSE([$KSRC/include/linux/etherdevice.h], [eth_hw_addr_random]) OVS_GREP_IFELSE([$KSRC/include/linux/etherdevice.h], [ether_addr_copy]) @@ -299,6 +300,8 @@ AC_DEFUN([OVS_CHECK_LINUX_COMPAT], [ OVS_GREP_IFELSE([$KSRC/include/linux/skbuff.h], [skb_orphan_frags]) OVS_GREP_IFELSE([$KSRC/include/linux/skbuff.h], [skb_get_hash]) OVS_GREP_IFELSE([$KSRC/include/linux/skbuff.h], [skb_clear_hash]) + OVS_GREP_IFELSE([$KSRC/include/linux/skbuff.h], [int.skb_zerocopy(], + [OVS_DEFINE([HAVE_SKB_ZEROCOPY])]) OVS_GREP_IFELSE([$KSRC/include/linux/skbuff.h], [l4_rxhash]) OVS_GREP_IFELSE([$KSRC/include/linux/types.h], [bool], @@ -312,7 +315,11 @@ AC_DEFUN([OVS_CHECK_LINUX_COMPAT], [ OVS_GREP_IFELSE([$KSRC/include/net/checksum.h], [csum_unfold]) OVS_GREP_IFELSE([$KSRC/include/net/genetlink.h], [parallel_ops]) + OVS_GREP_IFELSE([$KSRC/include/net/genetlink.h], [genlmsg_new_unicast]) OVS_GREP_IFELSE([$KSRC/include/net/gre.h], [gre_cisco_register]) + OVS_GREP_IFELSE([$KSRC/include/net/gre.h], [gre_handle_offloads]) + OVS_GREP_IFELSE([$KSRC/include/net/ip_tunnels.h], [iptunnel_xmit.*net], + [OVS_DEFINE([HAVE_IPTUNNEL_XMIT_NET])]) OVS_GREP_IFELSE([$KSRC/include/net/netlink.h], [nla_get_be16]) OVS_GREP_IFELSE([$KSRC/include/net/netlink.h], [nla_put_be16]) OVS_GREP_IFELSE([$KSRC/include/net/netlink.h], [nla_put_be32]) diff --git a/datapath/datapath.c b/datapath/datapath.c index 95ba520a0..b0de67206 100644 --- a/datapath/datapath.c +++ b/datapath/datapath.c @@ -433,7 +433,7 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb, struct sk_buff *user_skb; /* to be queued to userspace */ struct nlattr *nla; struct genl_info info = { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0) +#ifdef HAVE_GENLMSG_NEW_UNICAST .dst_sk = ovs_dp_get_net(dp)->genl_sock, #endif .snd_portid = upcall_info->portid, diff --git a/datapath/linux/compat/gre.c b/datapath/linux/compat/gre.c index 8c133dee4..de3d6eb7c 100644 --- a/datapath/linux/compat/gre.c +++ b/datapath/linux/compat/gre.c @@ -268,6 +268,8 @@ int gre_cisco_unregister(struct gre_cisco_protocol *proto) #endif /* !HAVE_GRE_CISCO_REGISTER */ +#ifndef GRE_USE_KERNEL_GRE_HANDLE_OFFLOADS + /* GRE TX side. */ static void gre_csum_fix(struct sk_buff *skb) { @@ -343,6 +345,7 @@ void gre_build_header(struct sk_buff *skb, const struct tnl_ptk_info *tpi, } } } +#endif #endif /* CONFIG_NET_IPGRE_DEMUX */ diff --git a/datapath/linux/compat/include/linux/hash.h b/datapath/linux/compat/include/linux/hash.h index ac8531b3a..1d70dcb22 100644 --- a/datapath/linux/compat/include/linux/hash.h +++ b/datapath/linux/compat/include/linux/hash.h @@ -2,11 +2,10 @@ #define _LINUX_HASH_WRAPPER_H #include_next - -#include -#if LINUX_VERSION_CODE < KERNEL_VERSION(3,14,0) #include +#ifndef HAVE_FAST_HASH_OPS + struct fast_hash_ops { u32 (*hash)(const void *data, u32 len, u32 seed); u32 (*hash2)(const u32 *data, u32 len, u32 seed); @@ -40,6 +39,6 @@ extern u32 arch_fast_hash(const void *data, u32 len, u32 seed); * Returns 32bit hash. */ extern u32 arch_fast_hash2(const u32 *data, u32 len, u32 seed); -#endif /* < 3.14 */ +#endif /* !HASH_FAST_HASH_OPS */ #endif /* _LINUX_HASH_WRAPPER_H */ diff --git a/datapath/linux/compat/include/linux/skbuff.h b/datapath/linux/compat/include/linux/skbuff.h index 9abd58224..a01621343 100644 --- a/datapath/linux/compat/include/linux/skbuff.h +++ b/datapath/linux/compat/include/linux/skbuff.h @@ -284,6 +284,10 @@ static inline void skb_tx_error(struct sk_buff *skb) #if LINUX_VERSION_CODE < KERNEL_VERSION(3,14,0) unsigned int skb_zerocopy_headlen(const struct sk_buff *from); +#endif + +#ifndef HAVE_SKB_ZEROCOPY +#define skb_zerocopy rpl_skb_zerocopy int skb_zerocopy(struct sk_buff *to, struct sk_buff *from, int len, int hlen); #endif diff --git a/datapath/linux/compat/include/net/genetlink.h b/datapath/linux/compat/include/net/genetlink.h index 9f425e5ff..9b2aa5b65 100644 --- a/datapath/linux/compat/include/net/genetlink.h +++ b/datapath/linux/compat/include/net/genetlink.h @@ -96,7 +96,7 @@ static inline int rpl_genl_register_family(struct genl_family *family) #endif -#if LINUX_VERSION_CODE < KERNEL_VERSION(3,14,0) +#ifndef HAVE_GENLMSG_NEW_UNICAST static inline struct sk_buff *genlmsg_new_unicast(size_t payload, struct genl_info *info, gfp_t flags) diff --git a/datapath/linux/compat/include/net/gre.h b/datapath/linux/compat/include/net/gre.h index 3c69e38e8..f091b327a 100644 --- a/datapath/linux/compat/include/net/gre.h +++ b/datapath/linux/compat/include/net/gre.h @@ -81,7 +81,7 @@ static inline __be16 tnl_flags_to_gre_flags(__be16 tflags) #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0) */ #endif /* HAVE_GRE_CISCO_REGISTER */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(3,12,0) +#ifndef GRE_USE_KERNEL_GRE_HANDLE_OFFLOADS #define gre_build_header rpl_gre_build_header void gre_build_header(struct sk_buff *skb, const struct tnl_ptk_info *tpi, diff --git a/datapath/linux/compat/include/net/ip_tunnels.h b/datapath/linux/compat/include/net/ip_tunnels.h index e59f9f356..130c2d6c6 100644 --- a/datapath/linux/compat/include/net/ip_tunnels.h +++ b/datapath/linux/compat/include/net/ip_tunnels.h @@ -2,7 +2,15 @@ #define __NET_IP_TUNNELS_WRAPPER_H 1 #include -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,12,0) +#if defined(HAVE_GRE_HANDLE_OFFLOADS) && \ + LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0) +/* RHEL6 and RHEL7 both has backported tunnel API but RHEL6 has + * older version, so avoid using RHEL6 backports. + */ +#define GRE_USE_KERNEL_GRE_HANDLE_OFFLOADS +#endif + +#ifdef GRE_USE_KERNEL_GRE_HANDLE_OFFLOADS #include_next #else diff --git a/datapath/linux/compat/include/net/vxlan.h b/datapath/linux/compat/include/net/vxlan.h index d64630b45..0f0ff16c5 100644 --- a/datapath/linux/compat/include/net/vxlan.h +++ b/datapath/linux/compat/include/net/vxlan.h @@ -4,9 +4,10 @@ #include #include #include +#include #include -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,12,0) +#ifdef GRE_USE_KERNEL_GRE_HANDLE_OFFLOADS #include_next static inline int rpl_vxlan_xmit_skb(struct vxlan_sock *vs, @@ -18,11 +19,14 @@ static inline int rpl_vxlan_xmit_skb(struct vxlan_sock *vs, kfree_skb(skb); return -ENOSYS; } - +#ifndef HAVE_IPTUNNEL_XMIT_NET return vxlan_xmit_skb(vs, rt, skb, src, dst, tos, ttl, df, src_port, dst_port, vni); +#else + return vxlan_xmit_skb(NULL, vs, rt, skb, src, dst, tos, ttl, df, + src_port, dst_port, vni); +#endif } - #define vxlan_xmit_skb rpl_vxlan_xmit_skb #else diff --git a/datapath/linux/compat/ip_tunnels_core.c b/datapath/linux/compat/ip_tunnels_core.c index a70aefc6a..eb0380ee6 100644 --- a/datapath/linux/compat/ip_tunnels_core.c +++ b/datapath/linux/compat/ip_tunnels_core.c @@ -16,8 +16,6 @@ * 02110-1301, USA */ -#include -#if LINUX_VERSION_CODE < KERNEL_VERSION(3,12,0) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt @@ -30,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -37,6 +36,7 @@ #include "compat.h" #include "gso.h" +#ifndef GRE_USE_KERNEL_GRE_HANDLE_OFFLOADS int iptunnel_xmit(struct rtable *rt, struct sk_buff *skb, __be32 src, __be32 dst, __u8 proto, @@ -117,4 +117,4 @@ int iptunnel_pull_header(struct sk_buff *skb, int hdr_len, __be16 inner_proto) return 0; } -#endif /* 3.12 */ +#endif diff --git a/datapath/linux/compat/skbuff-openvswitch.c b/datapath/linux/compat/skbuff-openvswitch.c index 96c27d006..65ea74726 100644 --- a/datapath/linux/compat/skbuff-openvswitch.c +++ b/datapath/linux/compat/skbuff-openvswitch.c @@ -49,6 +49,7 @@ skb_zerocopy_headlen(const struct sk_buff *from) return hlen; } +#ifndef HAVE_SKB_ZEROCOPY /** * skb_zerocopy - Zero copy skb to skb * @to: destination buffer @@ -122,3 +123,4 @@ skb_zerocopy(struct sk_buff *to, struct sk_buff *from, int len, int hlen) return 0; } #endif +#endif diff --git a/datapath/linux/compat/vxlan.c b/datapath/linux/compat/vxlan.c index b8b8fa762..5f2c0b365 100644 --- a/datapath/linux/compat/vxlan.c +++ b/datapath/linux/compat/vxlan.c @@ -19,7 +19,6 @@ */ #include -#if LINUX_VERSION_CODE < KERNEL_VERSION(3,12,0) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt @@ -43,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -58,6 +58,7 @@ #include "datapath.h" #include "gso.h" #include "vlan.h" +#ifndef GRE_USE_KERNEL_GRE_HANDLE_OFFLOADS #define VXLAN_HLEN (sizeof(struct udphdr) + sizeof(struct vxlanhdr)) -- 2.20.1