From patchwork Wed Jun 22 15:47:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thadeu Lima de Souza Cascardo X-Patchwork-Id: 639248 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (archives.nicira.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 3rZTWp52H4z9t1C for ; Thu, 23 Jun 2016 01:48:06 +1000 (AEST) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id EBA7C108DD; Wed, 22 Jun 2016 08:48:01 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx1e3.cudamail.com (mx1.cudamail.com [69.90.118.67]) by archives.nicira.com (Postfix) with ESMTPS id 22126108D8 for ; Wed, 22 Jun 2016 08:48:00 -0700 (PDT) Received: from bar5.cudamail.com (localhost [127.0.0.1]) by mx1e3.cudamail.com (Postfix) with ESMTPS id 5FCB8420430 for ; Wed, 22 Jun 2016 09:47:59 -0600 (MDT) X-ASG-Debug-ID: 1466610477-09eadd08b213b20001-byXFYA Received: from mx3-pf2.cudamail.com ([192.168.14.1]) by bar5.cudamail.com with ESMTP id sFikj526ofTxeYr3 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 22 Jun 2016 09:47:57 -0600 (MDT) X-Barracuda-Envelope-From: cascardo@redhat.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.14.1 Received: from unknown (HELO mx1.redhat.com) (209.132.183.28) by mx3-pf2.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 22 Jun 2016 15:47:57 -0000 Received-SPF: pass (mx3-pf2.cudamail.com: SPF record at _spf1.redhat.com designates 209.132.183.28 as permitted sender) X-Barracuda-Apparent-Source-IP: 209.132.183.28 X-Barracuda-RBL-IP: 209.132.183.28 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 820A4C05B1DE for ; Wed, 22 Jun 2016 15:47:56 +0000 (UTC) Received: from indiana.gru.redhat.com (ovpn-116-114.phx2.redhat.com [10.3.116.114]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5MFlrdH014082 for ; Wed, 22 Jun 2016 11:47:55 -0400 X-CudaMail-Envelope-Sender: cascardo@redhat.com From: Thadeu Lima de Souza Cascardo To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-V2-621025156 X-CudaMail-DTE: 062216 X-CudaMail-Originating-IP: 209.132.183.28 Date: Wed, 22 Jun 2016 12:47:38 -0300 X-ASG-Orig-Subj: [##CM-V2-621025156##][PATCH v3 1/5] netdev: get device type from vport prefix if it uses one Message-Id: <1466610462-32116-2-git-send-email-cascardo@redhat.com> In-Reply-To: <1466610462-32116-1-git-send-email-cascardo@redhat.com> References: <1466610462-32116-1-git-send-email-cascardo@redhat.com> 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.32]); Wed, 22 Jun 2016 15:47:56 +0000 (UTC) X-Barracuda-Connect: UNKNOWN[192.168.14.1] X-Barracuda-Start-Time: 1466610477 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 Subject: [ovs-dev] [PATCH v3 1/5] netdev: get device type from vport prefix if it uses one X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" 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 4be806d..8ff7882 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -281,6 +281,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). @@ -1759,9 +1774,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; }