[ovs-dev] [PATCH 6/6] datapath: Add support for 4.1 kernel.

Joe Stringer joestringer at nicira.com
Wed Jul 29 19:53:08 UTC 2015


Signed-off-by: Joe Stringer <joestringer at nicira.com>
---
 .travis.yml                                       |  1 +
 acinclude.m4                                      |  4 ++--
 datapath/datapath.h                               |  9 ++++---
 datapath/flow.c                                   |  4 +++-
 datapath/linux/compat/geneve.c                    |  2 +-
 datapath/linux/compat/include/net/net_namespace.h | 29 +++++++++++++++++++++++
 datapath/linux/compat/include/net/udp_tunnel.h    |  5 ++--
 datapath/linux/compat/include/net/vxlan.h         | 14 ++++++-----
 datapath/linux/compat/stt.c                       | 16 +++++++------
 datapath/linux/compat/udp_tunnel.c                | 10 ++++----
 datapath/linux/compat/vxlan.c                     |  7 +++---
 datapath/vport-lisp.c                             |  3 ++-
 datapath/vport-vxlan.c                            |  2 +-
 13 files changed, 71 insertions(+), 35 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 70cc14b..f3236db 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -12,6 +12,7 @@ env:
   - TESTSUITE=1 KERNEL=3.18.1
   - TESTSUITE=1 OPTS="--enable-shared"
   - BUILD_ENV="-m32" OPTS="--disable-ssl"
+  - KERNEL=4.1.3
   - KERNEL=4.0.2
   - KERNEL=3.17.7 DPDK=1
   - KERNEL=3.17.7 DPDK=1 OPTS="--enable-shared"
diff --git a/acinclude.m4 b/acinclude.m4
index 45cfaf6..42866de 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -134,10 +134,10 @@ AC_DEFUN([OVS_CHECK_LINUX], [
     AC_MSG_RESULT([$kversion])
 
     if test "$version" -ge 4; then
-       if test "$version" = 4 && test "$patchlevel" -le 0; then
+       if test "$version" = 4 && test "$patchlevel" -le 1; then
           : # Linux 4.x
        else
-          AC_ERROR([Linux kernel in $KBUILD is version $kversion, but version newer than 4.0.x is not supported (please refer to the FAQ for advice)])
+          AC_ERROR([Linux kernel in $KBUILD is version $kversion, but version newer than 4.1.x is not supported (please refer to the FAQ for advice)])
        fi
     elif test "$version" = 3; then
        : # Linux 3.x
diff --git a/datapath/datapath.h b/datapath/datapath.h
index 152d70c..4d1f5af 100644
--- a/datapath/datapath.h
+++ b/datapath/datapath.h
@@ -25,6 +25,7 @@
 #include <linux/netdevice.h>
 #include <linux/skbuff.h>
 #include <linux/u64_stats_sync.h>
+#include <net/net_namespace.h>
 
 #include "compat.h"
 #include "flow.h"
@@ -86,10 +87,8 @@ struct datapath {
 	/* Stats. */
 	struct dp_stats_percpu __percpu *stats_percpu;
 
-#ifdef CONFIG_NET_NS
 	/* Network namespace ref. */
-	struct net *net;
-#endif
+	possible_net_t net;
 
 	u32 user_features;
 };
@@ -156,12 +155,12 @@ int lockdep_ovsl_is_held(void);
 
 static inline struct net *ovs_dp_get_net(const struct datapath *dp)
 {
-	return read_pnet(&dp->net);
+	return rpl_read_pnet(&dp->net);
 }
 
 static inline void ovs_dp_set_net(struct datapath *dp, struct net *net)
 {
-	write_pnet(&dp->net, net);
+	rpl_write_pnet(&dp->net, net);
 }
 
 struct vport *ovs_lookup_vport(const struct datapath *dp, u16 port_no);
diff --git a/datapath/flow.c b/datapath/flow.c
index a7a2063..8ef60d1 100644
--- a/datapath/flow.c
+++ b/datapath/flow.c
@@ -101,7 +101,9 @@ void ovs_flow_stats_update(struct sw_flow *flow, __be16 tcp_flags,
 
 				new_stats =
 					kmem_cache_alloc_node(flow_stats_cache,
-							      GFP_THISNODE |
+                                                              GFP_NOWAIT |
+                                                              __GFP_THISNODE |
+                                                              __GFP_NOWARN |
 							      __GFP_NOMEMALLOC,
 							      node);
 				if (likely(new_stats)) {
diff --git a/datapath/linux/compat/geneve.c b/datapath/linux/compat/geneve.c
index 78d3395..8e80180 100644
--- a/datapath/linux/compat/geneve.c
+++ b/datapath/linux/compat/geneve.c
@@ -117,7 +117,7 @@ int rpl_geneve_xmit_skb(struct geneve_sock *gs, struct rtable *rt,
 
 	ovs_skb_set_inner_protocol(skb, htons(ETH_P_TEB));
 
-	return udp_tunnel_xmit_skb(rt, skb, src, dst,
+	return udp_tunnel_xmit_skb(rt, gs->sock->sk, skb, src, dst,
 				   tos, ttl, df, src_port, dst_port, xnet,
 				   !csum);
 }
diff --git a/datapath/linux/compat/include/net/net_namespace.h b/datapath/linux/compat/include/net/net_namespace.h
index b7dbfe3..05c48f4 100644
--- a/datapath/linux/compat/include/net/net_namespace.h
+++ b/datapath/linux/compat/include/net/net_namespace.h
@@ -51,4 +51,33 @@ static void rpl_unregister_pernet_gen_##TYPE(struct rpl_pernet_operations *rpl_p
 #define DEFINE_COMPAT_PNET_REG_FUNC(TYPE)
 #endif /* 2.6.33 */
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,1,0)
+typedef struct {
+#ifdef CONFIG_NET_NS
+	struct net *net;
+#endif
+} possible_net_t;
+
+static inline void rpl_write_pnet(possible_net_t *pnet, struct net *net)
+{
+#ifdef CONFIG_NET_NS
+	pnet->net = net;
+#endif
+}
+
+static inline struct net *rpl_read_pnet(const possible_net_t *pnet)
+{
+#ifdef CONFIG_NET_NS
+	return pnet->net;
+#else
+	return &init_net;
+#endif
+}
+#else /* Linux >= 4.1 */
+#define hold_net(x) (x)
+#define release_net(x) (x)
+#define rpl_read_pnet read_pnet
+#define rpl_write_pnet write_pnet
+#endif /* Linux >= 4.1 */
+
 #endif /* net/net_namespace.h wrapper */
diff --git a/datapath/linux/compat/include/net/udp_tunnel.h b/datapath/linux/compat/include/net/udp_tunnel.h
index 81cb3df..221639a 100644
--- a/datapath/linux/compat/include/net/udp_tunnel.h
+++ b/datapath/linux/compat/include/net/udp_tunnel.h
@@ -4,7 +4,7 @@
 #include <linux/version.h>
 #include <linux/kconfig.h>
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,0,0)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,1,0)
 #include_next <net/udp_tunnel.h>
 
 static inline struct sk_buff *
@@ -71,7 +71,8 @@ void rpl_setup_udp_tunnel_sock(struct net *net, struct socket *sock,
 
 /* Transmit the skb using UDP encapsulation. */
 #define udp_tunnel_xmit_skb rpl_udp_tunnel_xmit_skb
-int rpl_udp_tunnel_xmit_skb(struct rtable *rt, struct sk_buff *skb,
+int rpl_udp_tunnel_xmit_skb(struct rtable *rt,
+			    struct sock *sk, struct sk_buff *skb,
 			    __be32 src, __be32 dst, __u8 tos, __u8 ttl,
 			    __be16 df, __be16 src_port, __be16 dst_port,
 			    bool xnet, bool nocheck);
diff --git a/datapath/linux/compat/include/net/vxlan.h b/datapath/linux/compat/include/net/vxlan.h
index 0d60c18..cafff79 100644
--- a/datapath/linux/compat/include/net/vxlan.h
+++ b/datapath/linux/compat/include/net/vxlan.h
@@ -88,10 +88,9 @@ struct vxlanhdr_gbp {
 #endif
 
 #ifdef USE_UPSTREAM_VXLAN
-static inline int rpl_vxlan_xmit_skb(struct vxlan_sock *vs,
-                   struct rtable *rt, struct sk_buff *skb,
-                   __be32 src, __be32 dst, __u8 tos, __u8 ttl, __be16 df,
-                   __be16 src_port, __be16 dst_port,
+static inline int rpl_vxlan_xmit_skb(struct rtable *rt, struct sock *sk,
+		   struct sk_buff *skb, __be32 src, __be32 dst, __u8 tos,
+		   __u8 ttl, __be16 df, __be16 src_port, __be16 dst_port,
 		   struct vxlan_metadata *md, bool xnet, u32 vxflags)
 {
 	if (skb_is_gso(skb) && skb_is_encapsulated(skb)) {
@@ -99,7 +98,11 @@ static inline int rpl_vxlan_xmit_skb(struct vxlan_sock *vs,
 		return -ENOSYS;
 	}
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,1,0)
 	return vxlan_xmit_skb(rt, skb, src, dst, tos, ttl, df,
+#else
+	return vxlan_xmit_skb(rt, sk, skb, src, dst, tos, ttl, df,
+#endif
 			      src_port, dst_port, md, xnet, vxflags);
 }
 
@@ -138,8 +141,7 @@ struct vxlan_sock *rpl_vxlan_sock_add(struct net *net, __be16 port,
 void rpl_vxlan_sock_release(struct vxlan_sock *vs);
 
 #define vxlan_xmit_skb rpl_vxlan_xmit_skb
-int rpl_vxlan_xmit_skb(struct vxlan_sock *vs,
-		       struct rtable *rt, struct sk_buff *skb,
+int rpl_vxlan_xmit_skb(struct rtable *rt, struct sock *sk, struct sk_buff *skb,
 		       __be32 src, __be32 dst, __u8 tos, __u8 ttl, __be16 df,
 		       __be16 src_port, __be16 dst_port,
 		       struct vxlan_metadata *md, bool xnet, u32 vxflags);
diff --git a/datapath/linux/compat/stt.c b/datapath/linux/compat/stt.c
index b44f470..8fbbdfa 100644
--- a/datapath/linux/compat/stt.c
+++ b/datapath/linux/compat/stt.c
@@ -1319,16 +1319,18 @@ static void clean_percpu(struct work_struct *work)
 }
 
 #ifdef HAVE_NF_HOOKFN_ARG_OPS
-#define FIRST_PARAM const struct nf_hook_ops *ops,
+#define FIRST_PARAM const struct nf_hook_ops *ops
 #else
-#define FIRST_PARAM unsigned int hooknum,
+#define FIRST_PARAM unsigned int hooknum
 #endif
 
-static unsigned int nf_ip_hook(FIRST_PARAM
-			       struct sk_buff *skb,
-			       const struct net_device *in,
-			       const struct net_device *out,
-			       int (*okfn)(struct sk_buff *))
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,1,0)
+#define LAST_PARAM const struct nf_hook_state *state
+#else
+#define LAST_PARAM const struct net_device *in, const struct net_device *out, int (*okfn)(struct sk_buff *)
+#endif
+
+static unsigned int nf_ip_hook(FIRST_PARAM, struct sk_buff *skb, LAST_PARAM)
 {
 	struct stt_sock *stt_sock;
 	int ip_hdr_len;
diff --git a/datapath/linux/compat/udp_tunnel.c b/datapath/linux/compat/udp_tunnel.c
index c84113b..680fd83 100644
--- a/datapath/linux/compat/udp_tunnel.c
+++ b/datapath/linux/compat/udp_tunnel.c
@@ -142,10 +142,10 @@ void ovs_udp_csum_gso(struct sk_buff *skb)
 }
 EXPORT_SYMBOL_GPL(ovs_udp_csum_gso);
 
-int rpl_udp_tunnel_xmit_skb(struct rtable *rt, struct sk_buff *skb,
-			    __be32 src, __be32 dst, __u8 tos, __u8 ttl,
-			    __be16 df, __be16 src_port, __be16 dst_port,
-			    bool xnet, bool nocheck)
+int rpl_udp_tunnel_xmit_skb(struct rtable *rt, struct sock *sk,
+			    struct sk_buff *skb, __be32 src, __be32 dst,
+			    __u8 tos, __u8 ttl, __be16 df, __be16 src_port,
+			    __be16 dst_port, bool xnet, bool nocheck)
 {
 	struct udphdr *uh;
 
@@ -159,7 +159,7 @@ int rpl_udp_tunnel_xmit_skb(struct rtable *rt, struct sk_buff *skb,
 
 	udp_set_csum(nocheck, skb, src, dst, skb->len);
 
-	return iptunnel_xmit(skb->sk, rt, skb, src, dst, IPPROTO_UDP,
+	return iptunnel_xmit(sk, rt, skb, src, dst, IPPROTO_UDP,
 			     tos, ttl, df, xnet);
 }
 EXPORT_SYMBOL_GPL(rpl_udp_tunnel_xmit_skb);
diff --git a/datapath/linux/compat/vxlan.c b/datapath/linux/compat/vxlan.c
index 129f171..fd454ae 100644
--- a/datapath/linux/compat/vxlan.c
+++ b/datapath/linux/compat/vxlan.c
@@ -180,8 +180,7 @@ static void vxlan_build_gbp_hdr(struct vxlanhdr *vxh, u32 vxflags,
 	gbp->policy_id = htons(md->gbp & VXLAN_GBP_ID_MASK);
 }
 
-int rpl_vxlan_xmit_skb(struct vxlan_sock *vs,
-		       struct rtable *rt, struct sk_buff *skb,
+int rpl_vxlan_xmit_skb(struct rtable *rt, struct sock *sk, struct sk_buff *skb,
 		       __be32 src, __be32 dst, __u8 tos, __u8 ttl, __be16 df,
 		       __be16 src_port, __be16 dst_port,
 		       struct vxlan_metadata *md, bool xnet, u32 vxflags)
@@ -217,11 +216,11 @@ int rpl_vxlan_xmit_skb(struct vxlan_sock *vs,
 	if (vxflags & VXLAN_F_GBP)
 		vxlan_build_gbp_hdr(vxh, vxflags, md);
 
-	vxlan_set_owner(vs->sock->sk, skb);
+	vxlan_set_owner(sk, skb);
 
 	ovs_skb_set_inner_protocol(skb, htons(ETH_P_TEB));
 
-	return udp_tunnel_xmit_skb(rt, skb, src, dst, tos,
+	return udp_tunnel_xmit_skb(rt, sk, skb, src, dst, tos,
 				   ttl, df, src_port, dst_port, xnet,
 				   !udp_sum);
 }
diff --git a/datapath/vport-lisp.c b/datapath/vport-lisp.c
index 0024eb4..104a21d 100644
--- a/datapath/vport-lisp.c
+++ b/datapath/vport-lisp.c
@@ -455,7 +455,8 @@ static int lisp_send(struct vport *vport, struct sk_buff *skb)
 	ovs_skb_set_inner_protocol(skb, skb->protocol);
 
 	df = tun_key->tun_flags & TUNNEL_DONT_FRAGMENT ? htons(IP_DF) : 0;
-	sent_len = udp_tunnel_xmit_skb(rt, skb, saddr, tun_key->ipv4_dst,
+	sent_len = udp_tunnel_xmit_skb(rt, lisp_port->lisp_rcv_socket->sk, skb,
+				       saddr, tun_key->ipv4_dst,
 				       tun_key->ipv4_tos, tun_key->ipv4_ttl,
 				       df, src_port, dst_port, false, true);
 
diff --git a/datapath/vport-vxlan.c b/datapath/vport-vxlan.c
index eff7ca2..fc9f350 100644
--- a/datapath/vport-vxlan.c
+++ b/datapath/vport-vxlan.c
@@ -260,7 +260,7 @@ static int vxlan_tnl_send(struct vport *vport, struct sk_buff *skb)
 	vxflags = vxlan_port->exts |
 		      (tun_key->tun_flags & TUNNEL_CSUM ? VXLAN_F_UDP_CSUM : 0);
 
-	err = vxlan_xmit_skb(vxlan_port->vs, rt, skb,
+	err = vxlan_xmit_skb(rt, vxlan_port->vs->sock->sk, skb,
 			     saddr, tun_key->ipv4_dst,
 			     tun_key->ipv4_tos,
 			     tun_key->ipv4_ttl, df,
-- 
2.1.4




More information about the dev mailing list