From nobody Mon Feb 9 01:21:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608082061; cv=none; d=zohomail.com; s=zohoarc; b=LfiurbyyyFqxs4CehNZm1+pJ2Cr48J8RriHK+jvJicZRd9EF/ix0V1rktnuhOj7AkPmhl/BFHuyiT6UpPLnyxkIoKfPwrb02pFmfC3YT+JJJqKZ+jDzDentNQu0/2Oqg1AtSd0YnLxnQ55yewWW6Pk9atST1zz47U6W0Gen7SJw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608082061; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JYdNf084V/ByGacp2Khy/VUtB90A604dTs2+d166jA8=; b=nAvEhL3qGOfWoSNye5JEzcaUchHJRIyInK7ku2DlDTZsSLbWaTR6AKXa6nCjrp5JYiI4iwwpPXiFgU3P6dLL3w0Vp3CaQ923Gxmqk/dSMMprt2lwU3K4lI47+sDSwyo1t9OfQQB6AusvnU/nwnL7UDRdKLC5h2J7O+AFKDdTgYY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1608082061950759.2761501182093; Tue, 15 Dec 2020 17:27:41 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-196--GTWK-OUNPCmhx01kspdAw-1; Tue, 15 Dec 2020 20:27:38 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6CEA1107ACE8; Wed, 16 Dec 2020 01:27:33 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 312AF60939; Wed, 16 Dec 2020 01:27:32 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 954B44BB7B; Wed, 16 Dec 2020 01:27:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BG1RTdZ026588 for ; Tue, 15 Dec 2020 20:27:29 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0905A5D9E3; Wed, 16 Dec 2020 01:27:29 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-38.phx2.redhat.com [10.3.112.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id A405B5D9D7; Wed, 16 Dec 2020 01:27:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608082060; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=JYdNf084V/ByGacp2Khy/VUtB90A604dTs2+d166jA8=; b=VG6bdYfl8NCxXwia/b8Hyzr2PN0uD3MXvx1DRr6aAJz8YxdTNh1kjXD06T+boKzbEk6eI5 YzhjX5fbxWBt+b/oj3lEdquAtq0/fjOZCY6n0nq9QmMpvz8urwXSoR/Z2FVz9SDpWrDDvY fyNEQhHUkyuAUfW0F/vw0CN5OQhMYbg= X-MC-Unique: -GTWK-OUNPCmhx01kspdAw-1 From: Laine Stump To: libvir-list@redhat.com Subject: [PATCH 1/5] util: fix tap device name auto-generation for FreeBSD Date: Tue, 15 Dec 2020 20:27:19 -0500 Message-Id: <20201216012723.176100-2-laine@redhat.com> In-Reply-To: <20201216012723.176100-1-laine@redhat.com> References: <20201216012723.176100-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: Roman Bogorodskiy , Shi Lei X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The Linux implementation of virNetDevCreate() no longer requires a template ifname (e.g. "vnet%d") when it is called, but just generates a new name if ifname is empty. The FreeBSD implementation requires that the caller actually fill in a template ifname, and will fail if ifname is empty. Since we want to eliminate all the special code in callers that is setting the template name, we need to make the behavior of the FreeBSD virNetDevCreate() match the behavior of the Linux virNetDevCreate(). The simplest way to do this is to use the new virNetDevGenerateName() function - if ifname is empty it generates a new name with the proper prefix, and if it's not empty, it leaves it alone. Signed-off-by: Laine Stump --- src/util/virnetdevtap.c | 35 ++++++----------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c index 88ad321627..cca2f614fe 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -308,7 +308,6 @@ int virNetDevTapCreate(char **ifname, int s; struct ifreq ifr; int ret =3D -1; - char *newifname =3D NULL; =20 if (tapfdSize > 1) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", @@ -316,6 +315,12 @@ int virNetDevTapCreate(char **ifname, goto cleanup; } =20 + /* auto-generate an unused name for the new device (this + * is NOP if a name has been provided) + */ + if (virNetDevGenerateName(ifname, VIR_NET_DEV_GEN_NAME_VNET) < 0) + return -1; + =20 /* As FreeBSD determines interface type by name, * we have to create 'tap' interface first and * then rename it to 'vnet' @@ -329,34 +334,6 @@ int virNetDevTapCreate(char **ifname, goto cleanup; } =20 - /* In case we were given exact interface name (e.g. 'vnetN'), - * we just rename to it. If we have format string like - * 'vnet%d', we need to find the first available name that - * matches this pattern - */ - if (strstr(*ifname, "%d") !=3D NULL) { - size_t i; - for (i =3D 0; i <=3D IF_MAXUNIT; i++) { - g_autofree char *newname =3D NULL; - - newname =3D g_strdup_printf(*ifname, i); - - if (virNetDevExists(newname) =3D=3D 0) { - newifname =3D g_steal_pointer(&newname); - break; - } - } - if (newifname) { - VIR_FREE(*ifname); - *ifname =3D newifname; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to generate new name for interface %s= "), - ifr.ifr_name); - goto cleanup; - } - } - if (tapfd) { g_autofree char *dev_path =3D NULL; dev_path =3D g_strdup_printf("/dev/%s", ifr.ifr_name); --=20 2.28.0