From nobody Wed May 14 21:48:03 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1516973852619356.9775841679018; Fri, 26 Jan 2018 05:37:32 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 64AE320273; Fri, 26 Jan 2018 13:37:30 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 20E965D730; Fri, 26 Jan 2018 13:37:30 +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 CED3D18033DC; Fri, 26 Jan 2018 13:37:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0QDZn0U025189 for ; Fri, 26 Jan 2018 08:35:49 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6016875A1B; Fri, 26 Jan 2018 13:35:49 +0000 (UTC) Received: from t460.redhat.com (unknown [10.33.36.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA2B275A0E; Fri, 26 Jan 2018 13:35:47 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 26 Jan 2018 13:35:32 +0000 Message-Id: <20180126133537.31883-6-berrange@redhat.com> In-Reply-To: <20180126133537.31883-1-berrange@redhat.com> References: <20180126133537.31883-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 05/10] nwfilter: allow opening with nwfilter:///system URI 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: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 26 Jan 2018 13:37:31 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Allow the possibility of opening a connection to only the storage driver, by defining a nwfilter:///system URI and registering a fake hypervisor driver that supports it. The hypervisor drivers can now directly open a nwfilter driver connection at time of need, instead of having to pass around a virConnectPtr through many functions. This will facilitate the later change to support separate daemons for each driver. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/nwfilter/nwfilter_driver.c | 83 ++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 83 insertions(+) diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index 885dbcc282..5787152adc 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -363,6 +363,71 @@ nwfilterStateCleanup(void) } =20 =20 +static virDrvOpenStatus nwfilterConnectOpen(virConnectPtr conn, + virConnectAuthPtr auth ATTRIBU= TE_UNUSED, + virConfPtr conf ATTRIBUTE_UNUS= ED, + unsigned int flags) +{ + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + + /* Verify uri was specified */ + if (conn->uri =3D=3D NULL) { + /* Only hypervisor drivers are permitted to auto-open on NULL uri = */ + return VIR_DRV_OPEN_DECLINED; + } else { + if (STRNEQ_NULLABLE(conn->uri->scheme, "nwfilter")) + return VIR_DRV_OPEN_DECLINED; + + /* Leave for remote driver */ + if (conn->uri->server !=3D NULL) + return VIR_DRV_OPEN_DECLINED; + + if (driver =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("nwfilter state driver is not active")); + return VIR_DRV_OPEN_ERROR; + } + + if (STRNEQ(conn->uri->path, "/system")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected nwfilter URI path '%s', try nwfil= ter:///system"), + conn->uri->path); + return VIR_DRV_OPEN_ERROR; + } + } + + if (virConnectOpenEnsureACL(conn) < 0) + return VIR_DRV_OPEN_ERROR; + + return VIR_DRV_OPEN_SUCCESS; +} + +static int nwfilterConnectClose(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + return 0; +} + + +static int nwfilterConnectIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + /* Trivially secure, since always inside the daemon */ + return 1; +} + + +static int nwfilterConnectIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + /* Not encrypted, but remote driver takes care of that */ + return 0; +} + + +static int nwfilterConnectIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + return 1; +} + + static virNWFilterObjPtr nwfilterObjFromNWFilter(const unsigned char *uuid) { @@ -635,6 +700,22 @@ static virNWFilterDriver nwfilterDriver =3D { }; =20 =20 +static virHypervisorDriver nwfilterHypervisorDriver =3D { + .name =3D "nwfilter", + .connectOpen =3D nwfilterConnectOpen, /* 4.1.0 */ + .connectClose =3D nwfilterConnectClose, /* 4.1.0 */ + .connectIsEncrypted =3D nwfilterConnectIsEncrypted, /* 4.1.0 */ + .connectIsSecure =3D nwfilterConnectIsSecure, /* 4.1.0 */ + .connectIsAlive =3D nwfilterConnectIsAlive, /* 4.1.0 */ +}; + + +static virConnectDriver nwfilterConnectDriver =3D { + .hypervisorDriver =3D &nwfilterHypervisorDriver, + .nwfilterDriver =3D &nwfilterDriver, +}; + + static virStateDriver stateDriver =3D { .name =3D "NWFilter", .stateInitialize =3D nwfilterStateInitialize, @@ -651,6 +732,8 @@ static virDomainConfNWFilterDriver domainNWFilterDriver= =3D { =20 int nwfilterRegister(void) { + if (virRegisterConnectDriver(&nwfilterConnectDriver, false) < 0) + return -1; if (virSetSharedNWFilterDriver(&nwfilterDriver) < 0) return -1; if (virRegisterStateDriver(&stateDriver) < 0) --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list