From patchwork Mon Jul 18 17:00:25 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: 649648 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 3rtTwW1THwz9s6r for ; Tue, 19 Jul 2016 03:01:31 +1000 (AEST) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 96A81109A2; Mon, 18 Jul 2016 10:00:51 -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 56E3E1098F for ; Mon, 18 Jul 2016 10:00:49 -0700 (PDT) Received: from bar5.cudamail.com (localhost [127.0.0.1]) by mx1e3.cudamail.com (Postfix) with ESMTPS id D400F420AA0 for ; Mon, 18 Jul 2016 11:00:48 -0600 (MDT) X-ASG-Debug-ID: 1468861248-09eadd26a749790001-byXFYA Received: from mx1-pf1.cudamail.com ([192.168.24.1]) by bar5.cudamail.com with ESMTP id Wa96Zp1lFDjum4gi (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Mon, 18 Jul 2016 11:00:48 -0600 (MDT) X-Barracuda-Envelope-From: cascardo@redhat.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.1 Received: from unknown (HELO mx1.redhat.com) (209.132.183.28) by mx1-pf1.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 18 Jul 2016 17:00:48 -0000 Received-SPF: pass (mx1-pf1.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-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (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 AEB5967AC0 for ; Mon, 18 Jul 2016 17:00:46 +0000 (UTC) Received: from indiana.gru.redhat.com (ovpn-116-31.phx2.redhat.com [10.3.116.31]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6IH0YQE005099 for ; Mon, 18 Jul 2016 13:00:46 -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-E1-717040626 X-CudaMail-DTE: 071816 X-CudaMail-Originating-IP: 209.132.183.28 Date: Mon, 18 Jul 2016 14:00:25 -0300 X-ASG-Orig-Subj: [##CM-E1-717040626##][RFC 5/5] netdev: do not allow devices to be opened with conflicting types Message-Id: <1468861225-8569-6-git-send-email-cascardo@redhat.com> In-Reply-To: <1468861225-8569-1-git-send-email-cascardo@redhat.com> References: <1468861225-8569-1-git-send-email-cascardo@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 18 Jul 2016 17:00:46 +0000 (UTC) X-Barracuda-Connect: UNKNOWN[192.168.24.1] X-Barracuda-Start-Time: 1468861248 X-Barracuda-Encrypted: ECDHE-RSA-AES256-GCM-SHA384 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] [RFC 5/5] netdev: do not allow devices to be opened with conflicting types 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" When a device is already opened, netdev_open should verify that the types match, or else return an error. Otherwise, users might expect to open a device with a certain type and get a handle belonging to a different type. This also prevents certain conflicting configurations that would have a port of a certain type in the database and one of a different type on the system. --- lib/netdev.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/netdev.c b/lib/netdev.c index 6651173..ab7386a 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -339,7 +339,8 @@ netdev_open(const char *name, const char *type, struct netdev **netdevp) if (!netdev) { struct netdev_registered_class *rc; - rc = netdev_lookup_class(type && type[0] ? type : "system"); + type = type && type[0] ? type : "system"; + rc = netdev_lookup_class(type); if (rc && ovs_refcount_try_ref_rcu(&rc->refcnt)) { netdev = rc->class->alloc(); if (netdev) { @@ -376,6 +377,11 @@ netdev_open(const char *name, const char *type, struct netdev **netdevp) name, type); error = EAFNOSUPPORT; } + } else if (type && strcmp(type, netdev_get_type(netdev))) { + VLOG_WARN("trying to create netdev %s of different type %s," + " already is %s\n", + name, type, netdev_get_type(netdev)); + error = EEXIST; } else { error = 0; }