From patchwork Thu Feb 16 22:25:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Garver X-Patchwork-Id: 728939 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3vPW5m2Yfjz9s3s for ; Fri, 17 Feb 2017 09:28:44 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id B674FBE0; Thu, 16 Feb 2017 22:25:45 +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 0BDE0BB3 for ; Thu, 16 Feb 2017 22:25:40 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 913F910A for ; Thu, 16 Feb 2017 22:25:39 +0000 (UTC) Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 238D02EF170; Thu, 16 Feb 2017 22:25:40 +0000 (UTC) Received: from wsfd-netdev-buildsys.ntdv.lab.eng.bos.redhat.com (wsfd-netdev-buildsys.ntdv.lab.eng.bos.redhat.com [10.19.17.61]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1GMPYgB006109; Thu, 16 Feb 2017 17:25:39 -0500 From: Eric Garver To: dev@openvswitch.org Date: Thu, 16 Feb 2017 17:25:32 -0500 Message-Id: <20170216222533.11027-8-e@erig.me> In-Reply-To: <20170216222533.11027-1-e@erig.me> References: <20170216222533.11027-1-e@erig.me> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 16 Feb 2017 22:25:40 +0000 (UTC) X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Jiri Benc Subject: [ovs-dev] [PATCH RFC v5 7/8] dpif-netlink: Probe for out-of-tree datapath. 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 For out-of-tree datapath, only try genetlink/compat. For in-tree kernel datapath, try rtnetlink then genetlink. Signed-off-by: Eric Garver --- lib/dpif-netlink.c | 16 +++++++++++++--- lib/dpif-rtnetlink.c | 39 +++++++++++++++++++++++++++++++++++++++ lib/dpif-rtnetlink.h | 7 +++++++ 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c index ae8204ffe6e1..991004491ec2 100644 --- a/lib/dpif-netlink.c +++ b/lib/dpif-netlink.c @@ -211,6 +211,12 @@ static int ovs_packet_family; * Initialized by dpif_netlink_init(). */ static unsigned int ovs_vport_mcgroup; +/* If true, tunnel devices are created using OVS compat/genetlink. + * If false, tunnel devices are created with rtnetlink and using light weight + * tunnels. If we fail to create the tunnel the rtnetlink+LWT, then we fallback + * to using the compat interface. */ +static bool ovs_tunnels_out_of_tree = true; + static int dpif_netlink_init(void); static int open_dpif(const struct dpif_netlink_dp *, struct dpif **); static uint32_t dpif_netlink_port_get_pid(const struct dpif *, @@ -979,11 +985,13 @@ dpif_netlink_port_add(struct dpif *dpif_, struct netdev *netdev, odp_port_t *port_nop) { struct dpif_netlink *dpif = dpif_netlink_cast(dpif_); - int error; + int error = EOPNOTSUPP; fat_rwlock_wrlock(&dpif->upcall_lock); - error = dpif_rtnetlink_port_create_and_add(dpif, netdev, port_nop); - if (error == EOPNOTSUPP) { + if (!ovs_tunnels_out_of_tree) { + error = dpif_rtnetlink_port_create_and_add(dpif, netdev, port_nop); + } + if (error) { error = dpif_netlink_port_add_compat(dpif, netdev, port_nop); } fat_rwlock_unlock(&dpif->upcall_lock); @@ -2495,6 +2503,8 @@ dpif_netlink_init(void) &ovs_vport_mcgroup); } + ovs_tunnels_out_of_tree = dpif_rtnetlink_probe_oot_tunnels(); + ovsthread_once_done(&once); } diff --git a/lib/dpif-rtnetlink.c b/lib/dpif-rtnetlink.c index 60a5003b88ca..853de6b764e8 100644 --- a/lib/dpif-rtnetlink.c +++ b/lib/dpif-rtnetlink.c @@ -474,3 +474,42 @@ dpif_rtnetlink_port_destroy(const char *name, const char *type) } return 0; } + +/** + * This is to probe for whether the modules are out-of-tree (openvswitch) or + * in-tree (upstream kernel). + * + * We probe for "ovs_geneve" via rtnetlink. As long as this returns something + * other than EOPNOTSUPP we know that the module in use is the out-of-tree one. + * This will be used to determine what netlink interface to use when creating + * ports; rtnetlink or compat/genetlink. + * + * See ovs_tunnels_out_of_tree + */ +bool +dpif_rtnetlink_probe_oot_tunnels(void) +{ + struct netdev *netdev = NULL; + bool out_of_tree = false; + int error; + + error = netdev_open("ovs-system-probe", "geneve", &netdev); + if (!error) { + error = dpif_rtnetlink_geneve_create_kind(netdev, "ovs_geneve"); + if (error != EOPNOTSUPP) { + if (!error) { + char namebuf[NETDEV_VPORT_NAME_BUFSIZE]; + const char *dp_port; + + dp_port = netdev_vport_get_dpif_port(netdev, namebuf, + sizeof namebuf); + dpif_rtnetlink_geneve_destroy(dp_port); + } + out_of_tree = true; + } + netdev_close(netdev); + error = 0; + } + + return out_of_tree; +} diff --git a/lib/dpif-rtnetlink.h b/lib/dpif-rtnetlink.h index 515820f02e66..5bb578c4ac65 100644 --- a/lib/dpif-rtnetlink.h +++ b/lib/dpif-rtnetlink.h @@ -24,6 +24,8 @@ int dpif_rtnetlink_port_create(struct netdev *netdev); int dpif_rtnetlink_port_destroy(const char *name, const char *type); +bool dpif_rtnetlink_probe_oot_tunnels(void); + #ifndef __linux__ /* Dummy implementations for non Linux builds. * @@ -41,6 +43,11 @@ static inline int dpif_rtnetlink_port_destroy(const char *name OVS_UNUSED, return EOPNOTSUPP; } +static inline bool dpif_rtnetlink_probe_oot_tunnels(void) +{ + return true; +} + #endif #endif /* DPIF_RTNETLINK_H */