From patchwork Thu Mar 16 22:10:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Garver X-Patchwork-Id: 740040 X-Patchwork-Delegate: joestringer@nicira.com 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 3vkjNG1df3z9ryQ for ; Fri, 17 Mar 2017 09:10:54 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id DB8F5C21; Thu, 16 Mar 2017 22:10:25 +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 81BDCBD5 for ; Thu, 16 Mar 2017 22:10:23 +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 325652A2 for ; Thu, 16 Mar 2017 22:10:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A83943DBE2 for ; Thu, 16 Mar 2017 22:10:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A83943DBE2 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=erig.me Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=none smtp.mailfrom=e@erig.me DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A83943DBE2 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 smtp.corp.redhat.com (Postfix) with ESMTP id 64E8B183C3 for ; Thu, 16 Mar 2017 22:10:23 +0000 (UTC) From: Eric Garver To: dev@openvswitch.org Date: Thu, 16 Mar 2017 18:10:15 -0400 Message-Id: <20170316221021.11149-2-e@erig.me> In-Reply-To: <20170316221021.11149-1-e@erig.me> References: <20170316221021.11149-1-e@erig.me> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 16 Mar 2017 22:10:23 +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 Subject: [ovs-dev] [PATCH v2 1/7] netdev: get device type from vport prefix if it uses one 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: Thadeu Lima de Souza Cascardo If the device name uses a vport prefix, then use that vport type. Since these names are reserved, we can assume this is the right type. This is important when we are querying the datapath right after vswitch has started and using the right type will be even more important when we add support to creating tunnel ports with rtnetlink. Signed-off-by: Thadeu Lima de Souza Cascardo --- lib/netdev.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/netdev.c b/lib/netdev.c index a8d8edad7243..26c413601550 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -288,6 +288,21 @@ netdev_enumerate_types(struct sset *types) } } +static const char * +netdev_vport_type_from_name(const char *name) +{ + struct netdev_registered_class *rc; + const char *type; + CMAP_FOR_EACH (rc, cmap_node, &netdev_classes) { + const char *dpif_port = netdev_vport_class_get_dpif_port(rc->class); + if (dpif_port && !strncmp(name, dpif_port, strlen(dpif_port))) { + type = rc->class->type; + return type; + } + } + return NULL; +} + /* Check that the network device name is not the same as any of the registered * vport providers' dpif_port name (dpif_port is NULL if the vport provider * does not define it) or the datapath internal port name (e.g. ovs-system). @@ -1811,9 +1826,14 @@ netdev_get_vports(size_t *size) const char * netdev_get_type_from_name(const char *name) { - struct netdev *dev = netdev_from_name(name); - const char *type = dev ? netdev_get_type(dev) : NULL; - netdev_close(dev); + struct netdev *dev; + const char *type; + type = netdev_vport_type_from_name(name); + if (type == NULL) { + dev = netdev_from_name(name); + type = dev ? netdev_get_type(dev) : NULL; + netdev_close(dev); + } return type; }