[ovs-dev] [PATCH] datapath: Rename ndo_add_vxlan/geneve_port to ndo_add_udp_tunnel_port

wenxu at ucloud.cn wenxu at ucloud.cn
Sat Jul 28 08:41:58 UTC 2018


From: wenxu <wenxu at ucloud.cn>

Signed-off-by: wenxu <wenxu at ucloud.cn>
---
 acinclude.m4                                   |  3 +-
 datapath/linux/compat/geneve.c                 | 46 ++++++++++----------
 datapath/linux/compat/include/net/udp_tunnel.h | 12 ++++++
 datapath/linux/compat/vxlan.c                  | 58 ++++++++++++++++----------
 4 files changed, 73 insertions(+), 46 deletions(-)

diff --git a/acinclude.m4 b/acinclude.m4
index d6e0d33..95b46c6 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -551,8 +551,7 @@ AC_DEFUN([OVS_CHECK_LINUX_COMPAT], [
   OVS_GREP_IFELSE([$KSRC/include/linux/netdevice.h], [ndo_get_iflink])
   OVS_GREP_IFELSE([$KSRC/include/linux/netdevice.h], [ndo_features_check],
                   [OVS_DEFINE([USE_UPSTREAM_TUNNEL_GSO])])
-  OVS_GREP_IFELSE([$KSRC/include/linux/netdevice.h], [ndo_add_vxlan_port])
-  OVS_GREP_IFELSE([$KSRC/include/linux/netdevice.h], [ndo_add_geneve_port])
+  OVS_GREP_IFELSE([$KSRC/include/linux/netdevice.h], [ndo_udp_tunnel_add])
   OVS_GREP_IFELSE([$KSRC/include/linux/netdevice.h], [netdev_features_t])
   dnl Ubuntu kernel 3.13 has defined this struct but not used for netdev->tstats.
   dnl So check type of tstats.
diff --git a/datapath/linux/compat/geneve.c b/datapath/linux/compat/geneve.c
index 435a23f..3fdeae9 100644
--- a/datapath/linux/compat/geneve.c
+++ b/datapath/linux/compat/geneve.c
@@ -426,12 +426,14 @@ static void geneve_notify_add_rx_port(struct geneve_sock *gs)
 
 	rcu_read_lock();
 	for_each_netdev_rcu(net, dev) {
-#ifdef HAVE_NDO_ADD_GENEVE_PORT
-		__be16 port = inet_sk(sk)->inet_sport;
-
-		if (dev->netdev_ops->ndo_add_geneve_port)
-			dev->netdev_ops->ndo_add_geneve_port(dev, sa_family,
-					port);
+#ifdef HAVE_NDO_UDP_TUNNEL_ADD
+		struct udp_tunnel_info ti;
+		ti.type = UDP_TUNNEL_TYPE_GENEVE;
+		ti.sa_family = sa_family;
+		ti.port = inet_sk(sk)->inet_sport;
+
+		if (dev->netdev_ops->ndo_udp_tunnel_add)
+			dev->netdev_ops->ndo_udp_tunnel_add(dev, &ti);
 #endif
 	}
 	rcu_read_unlock();
@@ -446,12 +448,14 @@ static void geneve_notify_del_rx_port(struct geneve_sock *gs)
 
 	rcu_read_lock();
 	for_each_netdev_rcu(net, dev) {
-#ifdef HAVE_NDO_ADD_GENEVE_PORT
-		__be16 port = inet_sk(sk)->inet_sport;
-
-		if (dev->netdev_ops->ndo_del_geneve_port)
-			dev->netdev_ops->ndo_del_geneve_port(dev, sa_family,
-					port);
+#ifdef HAVE_NDO_UDP_TUNNEL_ADD
+		struct udp_tunnel_info ti;
+		ti.type = UDP_TUNNEL_TYPE_GENEVE;
+		ti.port = inet_sk(sk)->inet_sport;
+		ti.sa_family = sa_family;
+
+		if (dev->netdev_ops->ndo_udp_tunnel_del)
+			dev->netdev_ops->ndo_udp_tunnel_del(dev, &ti);
 #endif
 	}
 
@@ -1301,29 +1305,29 @@ static struct device_type geneve_type = {
 	.name = "geneve",
 };
 
-/* Calls the ndo_add_geneve_port of the caller in order to
+/* Calls the ndo_udp_tunnel_add of the caller in order to
  * supply the listening GENEVE udp ports. Callers are expected
- * to implement the ndo_add_geneve_port.
+ * to implement the ndo_udp_tunnel_add.
  */
 static void geneve_push_rx_ports(struct net_device *dev)
 {
-#ifdef HAVE_NDO_ADD_GENEVE_PORT
+#ifdef HAVE_NDO_UDP_TUNNEL_ADD
 	struct net *net = dev_net(dev);
 	struct geneve_net *gn = net_generic(net, geneve_net_id);
 	struct geneve_sock *gs;
-	sa_family_t sa_family;
 	struct sock *sk;
-	__be16 port;
 
-	if (!dev->netdev_ops->ndo_add_geneve_port)
+	if (!dev->netdev_ops->ndo_udp_tunnel_add)
 		return;
 
 	rcu_read_lock();
 	list_for_each_entry_rcu(gs, &gn->sock_list, list) {
+		struct udp_tunnel_info ti;
+		ti.type = UDP_TUNNEL_TYPE_GENEVE;
 		sk = gs->sock->sk;
-		sa_family = sk->sk_family;
-		port = inet_sk(sk)->inet_sport;
-		dev->netdev_ops->ndo_add_geneve_port(dev, sa_family, port);
+		ti.port = inet_sk(sk)->inet_sport;
+		ti.sa_family = sk->sk_family;
+		dev->netdev_ops->ndo_udp_tunnel_add(dev, &ti);
 	}
 	rcu_read_unlock();
 #endif
diff --git a/datapath/linux/compat/include/net/udp_tunnel.h b/datapath/linux/compat/include/net/udp_tunnel.h
index 6b5e540..a057ad1 100644
--- a/datapath/linux/compat/include/net/udp_tunnel.h
+++ b/datapath/linux/compat/include/net/udp_tunnel.h
@@ -43,6 +43,18 @@ struct udp_port_cfg {
 				ipv6_v6only:1;
 };
 
+enum udp_parsable_tunnel_type {
+	UDP_TUNNEL_TYPE_VXLAN,      /* RFC 7348 */
+	UDP_TUNNEL_TYPE_GENEVE,     /* draft-ietf-nvo3-geneve */
+	UDP_TUNNEL_TYPE_VXLAN_GPE,  /* draft-ietf-nvo3-vxlan-gpe */
+};
+
+struct udp_tunnel_info {
+	unsigned short type;
+	sa_family_t sa_family;
+	__be16 port;
+};
+
 #define udp_sock_create4 rpl_udp_sock_create4
 int rpl_udp_sock_create4(struct net *net, struct udp_port_cfg *cfg,
 		     struct socket **sockp);
diff --git a/datapath/linux/compat/vxlan.c b/datapath/linux/compat/vxlan.c
index 7f5d5ce..22385ca 100644
--- a/datapath/linux/compat/vxlan.c
+++ b/datapath/linux/compat/vxlan.c
@@ -379,7 +379,6 @@ static void vxlan_notify_add_rx_port(struct vxlan_sock *vs)
 	struct net *net = sock_net(sk);
 	sa_family_t sa_family = vxlan_get_sk_family(vs);
 
-
 	if (sa_family == AF_INET) {
 		int err;
 
@@ -390,12 +389,17 @@ static void vxlan_notify_add_rx_port(struct vxlan_sock *vs)
 
 	rcu_read_lock();
 	for_each_netdev_rcu(net, dev) {
-#ifdef HAVE_NDO_ADD_VXLAN_PORT
-		__be16 port = inet_sk(sk)->inet_sport;
-
-		if (dev->netdev_ops->ndo_add_vxlan_port)
-			dev->netdev_ops->ndo_add_vxlan_port(dev, sa_family,
-					port);
+#ifdef HAVE_NDO_UDP_TUNNEL_ADD
+		struct udp_tunnel_info ti;
+		if (vs->flags & VXLAN_F_GPE)
+			ti.type = UDP_TUNNEL_TYPE_VXLAN_GPE;
+		else 
+			ti.type = UDP_TUNNEL_TYPE_VXLAN;
+		ti.sa_family = sa_family;
+		ti.port = inet_sk(sk)->inet_sport;
+
+		if (dev->netdev_ops->ndo_udp_tunnel_add)
+			dev->netdev_ops->ndo_udp_tunnel_add(dev, &ti);
 #endif
 	}
 	rcu_read_unlock();
@@ -411,12 +415,17 @@ static void vxlan_notify_del_rx_port(struct vxlan_sock *vs)
 
 	rcu_read_lock();
 	for_each_netdev_rcu(net, dev) {
-#ifdef HAVE_NDO_ADD_VXLAN_PORT
-		__be16 port = inet_sk(sk)->inet_sport;
-
-		if (dev->netdev_ops->ndo_del_vxlan_port)
-			dev->netdev_ops->ndo_del_vxlan_port(dev, sa_family,
-					port);
+#ifdef HAVE_NDO_UDP_TUNNEL_ADD
+		struct udp_tunnel_info ti;
+		if (vs->flags & VXLAN_F_GPE)
+			ti.type = UDP_TUNNEL_TYPE_VXLAN_GPE;
+		else 
+			ti.type = UDP_TUNNEL_TYPE_VXLAN;
+		ti.port = inet_sk(sk)->inet_sport;
+		ti.sa_family = sa_family;
+
+		if (dev->netdev_ops->ndo_udp_tunnel_del)
+			dev->netdev_ops->ndo_udp_tunnel_del(dev, &ti);
 #endif
 	}
 	rcu_read_unlock();
@@ -1518,30 +1527,33 @@ static struct device_type vxlan_type = {
 	.name = "vxlan",
 };
 
-/* Calls the ndo_add_vxlan_port of the caller in order to
+/* Calls the ndo_udp_tunnel_add of the caller in order to
  * supply the listening VXLAN udp ports. Callers are expected
- * to implement the ndo_add_vxlan_port.
+ * to implement the ndo_udp_tunnel_add.
  */
 static void vxlan_push_rx_ports(struct net_device *dev)
 {
-#ifdef HAVE_NDO_ADD_VXLAN_PORT
+#ifdef HAVE_NDO_UDP_TUNNEL_ADD
 	struct vxlan_sock *vs;
 	struct net *net = dev_net(dev);
 	struct vxlan_net *vn = net_generic(net, vxlan_net_id);
-	sa_family_t sa_family;
-	__be16 port;
 	unsigned int i;
 
-	if (!dev->netdev_ops->ndo_add_vxlan_port)
+	if (!dev->netdev_ops->ndo_udp_tunnel_add)
 		return;
 
 	spin_lock(&vn->sock_lock);
 	for (i = 0; i < PORT_HASH_SIZE; ++i) {
 		hlist_for_each_entry_rcu(vs, &vn->sock_list[i], hlist) {
-			port = inet_sk(vs->sock->sk)->inet_sport;
-			sa_family = vxlan_get_sk_family(vs);
-			dev->netdev_ops->ndo_add_vxlan_port(dev, sa_family,
-							    port);
+			struct udp_tunnel_info ti;
+			if (vs->flags & VXLAN_F_GPE)
+				ti.type = UDP_TUNNEL_TYPE_VXLAN_GPE;
+			else 
+				ti.type = UDP_TUNNEL_TYPE_VXLAN;
+			ti.port = inet_sk(vs->sock->sk)->inet_sport;
+			ti.sa_family = vxlan_get_sk_family(vs);
+
+			dev->netdev_ops->ndo_udp_tunnel_add(dev, &ti);
 		}
 	}
 	spin_unlock(&vn->sock_lock);
-- 
1.8.3.1




More information about the dev mailing list