[ovs-dev] [PATCH V2 2/3] compat: Clean up gre_calc_hlen

Greg Rose gvrose8192 at gmail.com
Wed Jul 3 17:04:54 UTC 2019


It's proliferated throughout three .c files so let's pull them all
together in gre.h where the inline function belongs. This requires
some adjustments to the compat layer so that the various iterations
of gre_calc_hlen and ip_gre_calc_hlen since the 3.10 kernel are
handled correctly.

Signed-off-by: Greg Rose <gvrose8192 at gmail.com>
Acked-by: William Tu <u9012063 at gmail.com>
---
 acinclude.m4                            |  4 ++++
 datapath/linux/compat/gre.c             | 15 ---------------
 datapath/linux/compat/include/net/gre.h | 21 +++++++++++++++++++++
 datapath/linux/compat/ip6_gre.c         | 14 --------------
 datapath/linux/compat/ip_gre.c          | 18 ++++--------------
 5 files changed, 29 insertions(+), 43 deletions(-)

diff --git a/acinclude.m4 b/acinclude.m4
index 321a741..b8c9d6c 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -966,6 +966,10 @@ AC_DEFUN([OVS_CHECK_LINUX_COMPAT], [
   OVS_FIND_PARAM_IFELSE([$KSRC/include/net/netfilter/nf_conntrack_helper.h],
                         [nf_ct_helper_ext_add], [nf_conntrack_helper],
                         [OVS_DEFINE([HAVE_NF_CT_HELPER_EXT_ADD_TAKES_HELPER])])
+  OVS_GREP_IFELSE([$KSRC/include/net/gre.h], [gre_calc_hlen],
+                  [OVS_DEFINE([HAVE_GRE_CALC_HLEN])])
+  OVS_GREP_IFELSE([$KSRC/include/net/gre.h], [ip_gre_calc_hlen],
+                  [OVS_DEFINE([HAVE_IP_GRE_CALC_HLEN])])
 
   if cmp -s datapath/linux/kcompat.h.new \
             datapath/linux/kcompat.h >/dev/null 2>&1; then
diff --git a/datapath/linux/compat/gre.c b/datapath/linux/compat/gre.c
index 2b14c5a..e57528f 100644
--- a/datapath/linux/compat/gre.c
+++ b/datapath/linux/compat/gre.c
@@ -139,21 +139,6 @@ void rpl_gre_exit(void)
 }
 EXPORT_SYMBOL_GPL(rpl_gre_exit);
 
-#define ip_gre_calc_hlen rpl_ip_gre_calc_hlen
-#define gre_calc_hlen rpl_ip_gre_calc_hlen
-static int rpl_ip_gre_calc_hlen(__be16 o_flags)
-{
-	int addend = 4;
-
-	if (o_flags & TUNNEL_CSUM)
-		addend += 4;
-	if (o_flags & TUNNEL_KEY)
-		addend += 4;
-	if (o_flags & TUNNEL_SEQ)
-		addend += 4;
-	return addend;
-}
-
 void rpl_gre_build_header(struct sk_buff *skb, const struct tnl_ptk_info *tpi,
 			  int hdr_len)
 {
diff --git a/datapath/linux/compat/include/net/gre.h b/datapath/linux/compat/include/net/gre.h
index 58fa97a..57293b6 100644
--- a/datapath/linux/compat/include/net/gre.h
+++ b/datapath/linux/compat/include/net/gre.h
@@ -56,6 +56,27 @@ static inline struct net_device *rpl_gretap_fb_dev_create(
 #else
 #include_next <net/gre.h>
 
+#ifndef HAVE_GRE_CALC_HLEN
+static inline int gre_calc_hlen(__be16 o_flags)
+{
+	int addend = 4;
+
+	if (o_flags & TUNNEL_CSUM)
+		addend += 4;
+	if (o_flags & TUNNEL_KEY)
+		addend += 4;
+	if (o_flags & TUNNEL_SEQ)
+		addend += 4;
+	return addend;
+}
+
+#define ip_gre_calc_hlen gre_calc_hlen
+#else
+#ifdef HAVE_IP_GRE_CALC_HLEN
+#define gre_calc_hlen ip_gre_calc_hlen
+#endif
+#endif
+
 #define tnl_flags_to_gre_flags rpl_tnl_flags_to_gre_flags
 static inline __be16 rpl_tnl_flags_to_gre_flags(__be16 tflags)
 {
diff --git a/datapath/linux/compat/ip6_gre.c b/datapath/linux/compat/ip6_gre.c
index 850e703..a95c5f8 100644
--- a/datapath/linux/compat/ip6_gre.c
+++ b/datapath/linux/compat/ip6_gre.c
@@ -83,20 +83,6 @@ static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
 static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu);
 static void ip6erspan_tnl_link_config(struct ip6_tnl *t, int set_mtu);
 
-#define gre_calc_hlen rpl_ip_gre_calc_hlen
-static int rpl_ip_gre_calc_hlen(__be16 o_flags)
-{
-	int addend = 4;
-
-	if (o_flags & TUNNEL_CSUM)
-		addend += 4;
-	if (o_flags & TUNNEL_KEY)
-		addend += 4;
-	if (o_flags & TUNNEL_SEQ)
-		addend += 4;
-	return addend;
-}
-
 /* Tunnel hash table */
 
 /*
diff --git a/datapath/linux/compat/ip_gre.c b/datapath/linux/compat/ip_gre.c
index 77c5b47..6766661 100644
--- a/datapath/linux/compat/ip_gre.c
+++ b/datapath/linux/compat/ip_gre.c
@@ -71,20 +71,6 @@ static void erspan_build_header(struct sk_buff *skb,
 
 static bool ip_gre_loaded = false;
 
-#define ip_gre_calc_hlen rpl_ip_gre_calc_hlen
-static int ip_gre_calc_hlen(__be16 o_flags)
-{
-	int addend = 4;
-
-	if (o_flags & TUNNEL_CSUM)
-		addend += 4;
-	if (o_flags & TUNNEL_KEY)
-		addend += 4;
-	if (o_flags & TUNNEL_SEQ)
-		addend += 4;
-	return addend;
-}
-
 /* Returns the least-significant 32 bits of a __be64. */
 static __be32 tunnel_id_to_key(__be64 x)
 {
@@ -100,6 +86,10 @@ struct dst_ops md_dst_ops = {
 	.family =		AF_UNSPEC,
 };
 
+#ifndef ip_gre_calc_hlen
+#define ip_gre_calc_hlen gre_calc_hlen
+#endif
+
 static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi,
 		      int gre_hdr_len)
 {
-- 
1.8.3.1



More information about the dev mailing list