From patchwork Sat Aug 4 08:31:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wenxu X-Patchwork-Id: 953417 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ucloud.cn Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41jHFj5Fkwz9sXb for ; Sat, 4 Aug 2018 18:31:52 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id A6040B9E; Sat, 4 Aug 2018 08:31:49 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id D45488E2 for ; Sat, 4 Aug 2018 08:31:45 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from m6561.mail.qiye.163.com (m6561.mail.qiye.163.com [123.126.65.61]) by smtp1.linuxfoundation.org (Postfix) with ESMTP id C9007701 for ; Sat, 4 Aug 2018 08:31:43 +0000 (UTC) Received: from localhost.localdomain (unknown [123.59.132.129]) by smtp11 (Coremail) with SMTP id WdOowADH0_VrZGVbgLCnAA--.11286S2; Sat, 04 Aug 2018 16:31:39 +0800 (CST) From: wenxu@ucloud.cn To: dev@openvswitch.org Date: Sat, 4 Aug 2018 16:31:36 +0800 Message-Id: <1533371496-26588-1-git-send-email-wenxu@ucloud.cn> X-Mailer: git-send-email 1.8.3.1 X-CM-TRANSID: WdOowADH0_VrZGVbgLCnAA--.11286S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxuFW3AF1DAF4xGw47Gr45Jrb_yoW3JF43pF 4UAanxtFWDGrnrZF4SqF1UGF15try8ArWxGry5K34YvF1jqwn3Was0grWS93sYgFWfZay3 XFW8Ga1UKw1xWFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07U9FxbUUUUU= X-Originating-IP: [123.59.132.129] X-CM-SenderInfo: xzhq53w6xfz0lxgou0/1tbieguYKFqrhG6T1QAAsc X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: iaas_nad@ucloud.cn Subject: [ovs-dev] [PATCH v3] datapath: support upstream ndo_udp_tunnel_add in net_device_ops X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org From: wenxu It makes datapath can support both ndo_add_udp_tunnel_port and ndo_add_vxlan/geneve_port. The newer kernels don't support vxlan/geneve specific NDO's anymore Signed-off-by: wenxu Reviewed-by: Greg Rose Tested-by: Greg Rose --- acinclude.m4 | 1 + datapath/linux/compat/geneve.c | 41 ++++++++++++++++++-- datapath/linux/compat/include/net/udp_tunnel.h | 14 +++++++ datapath/linux/compat/vxlan.c | 52 ++++++++++++++++++++++++-- 4 files changed, 102 insertions(+), 6 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index d6e0d33..7899307 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -553,6 +553,7 @@ AC_DEFUN([OVS_CHECK_LINUX_COMPAT], [ [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..5b5bbae 100644 --- a/datapath/linux/compat/geneve.c +++ b/datapath/linux/compat/geneve.c @@ -432,6 +432,14 @@ static void geneve_notify_add_rx_port(struct geneve_sock *gs) if (dev->netdev_ops->ndo_add_geneve_port) dev->netdev_ops->ndo_add_geneve_port(dev, sa_family, port); +#elif defined(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(); @@ -452,6 +460,14 @@ static void geneve_notify_del_rx_port(struct geneve_sock *gs) if (dev->netdev_ops->ndo_del_geneve_port) dev->netdev_ops->ndo_del_geneve_port(dev, sa_family, port); +#elif defined(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,9 +1317,9 @@ static struct device_type geneve_type = { .name = "geneve", }; -/* Calls the ndo_add_geneve_port of the caller in order to - * supply the listening GENEVE udp ports. Callers are expected - * to implement the ndo_add_geneve_port. +/* Calls the ndo_add_geneve_port or 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. */ static void geneve_push_rx_ports(struct net_device *dev) { @@ -1326,6 +1342,25 @@ static void geneve_push_rx_ports(struct net_device *dev) dev->netdev_ops->ndo_add_geneve_port(dev, sa_family, port); } rcu_read_unlock(); +#elif defined(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; + struct sock *sk; + + 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; + 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..6e40633 100644 --- a/datapath/linux/compat/include/net/udp_tunnel.h +++ b/datapath/linux/compat/include/net/udp_tunnel.h @@ -43,6 +43,20 @@ struct udp_port_cfg { ipv6_v6only:1; }; +#ifdef HAVE_NDO_UDP_TUNNEL_ADD +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; +}; +#endif + #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..57b7866 100644 --- a/datapath/linux/compat/vxlan.c +++ b/datapath/linux/compat/vxlan.c @@ -396,6 +396,17 @@ static void vxlan_notify_add_rx_port(struct vxlan_sock *vs) if (dev->netdev_ops->ndo_add_vxlan_port) dev->netdev_ops->ndo_add_vxlan_port(dev, sa_family, port); +#elif defined(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(); @@ -417,6 +428,17 @@ static void vxlan_notify_del_rx_port(struct vxlan_sock *vs) if (dev->netdev_ops->ndo_del_vxlan_port) dev->netdev_ops->ndo_del_vxlan_port(dev, sa_family, port); +#elif defined(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,9 +1540,9 @@ static struct device_type vxlan_type = { .name = "vxlan", }; -/* Calls the ndo_add_vxlan_port of the caller in order to - * supply the listening VXLAN udp ports. Callers are expected - * to implement the ndo_add_vxlan_port. +/* Calls the ndo_add_vxlan_port or 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. */ static void vxlan_push_rx_ports(struct net_device *dev) { @@ -1545,6 +1567,30 @@ static void vxlan_push_rx_ports(struct net_device *dev) } } spin_unlock(&vn->sock_lock); +#elif defined(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); + unsigned int i; + + 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) { + 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); #endif }