From nobody Thu Nov 28 10:40:09 2024 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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1524842921980884.6449237583861; Fri, 27 Apr 2018 08:28:41 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F0A8C4902F; Fri, 27 Apr 2018 15:28:39 +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 B81A15F72C; Fri, 27 Apr 2018 15:28:39 +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 576894CAA2; Fri, 27 Apr 2018 15:28:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w3RFPRUH032340 for ; Fri, 27 Apr 2018 11:25:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id D777B83B76; Fri, 27 Apr 2018 15:25:27 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6B16383B77; Fri, 27 Apr 2018 15:25:27 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 27 Apr 2018 16:25:12 +0100 Message-Id: <20180427152513.28928-14-berrange@redhat.com> In-Reply-To: <20180427152513.28928-1-berrange@redhat.com> References: <20180427152513.28928-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 13/14] nwfilter: keep track of active filter bindings 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 27 Apr 2018 15:28:40 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Currently the nwfilter driver does not keep any record of what filter bindings it has active. This means that when it needs to recreate filters, it has to rely on triggering callbacks provided by the virt drivers. This introduces a hash table recording the virNWFilterBinding objects so the driver has a record of all active filters. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/conf/virnwfilterobj.h | 3 +++ src/nwfilter/nwfilter_driver.c | 57 +++++++++++++++++++++++++++++++++-----= ---- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/conf/virnwfilterobj.h b/src/conf/virnwfilterobj.h index 433b0402d0..5e69313476 100644 --- a/src/conf/virnwfilterobj.h +++ b/src/conf/virnwfilterobj.h @@ -37,6 +37,9 @@ struct _virNWFilterDriverState { =20 virNWFilterObjListPtr nwfilters; =20 + /* ifname -> virNWFilterBindingPtr */ + virHashTablePtr bindings; + char *configDir; }; =20 diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index a375e9bda8..ccbcfbbf67 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -163,6 +163,13 @@ nwfilterDriverInstallDBusMatches(DBusConnection *sysbu= s ATTRIBUTE_UNUSED) =20 #endif /* HAVE_FIREWALLD */ =20 +static void virNWFilterBindingDataFree(void *payload, const void *name ATT= RIBUTE_UNUSED) +{ + virNWFilterBindingPtr binding =3D payload; + + virNWFilterBindingFree(binding); +} + /** * nwfilterStateInitialize: * @@ -190,6 +197,10 @@ nwfilterStateInitialize(bool privileged, if (!(driver->nwfilters =3D virNWFilterObjListNew())) goto error; =20 + if (!(driver->bindings =3D virHashCreate(0, + virNWFilterBindingDataFree))) + goto error; + if (!privileged) return 0; =20 @@ -335,6 +346,8 @@ nwfilterStateCleanup(void) nwfilterDriverUnlock(); } =20 + virHashFree(driver->bindings); + /* free inactive nwfilters */ virNWFilterObjListFree(driver->nwfilters); =20 @@ -649,10 +662,28 @@ nwfilterInstantiateFilter(const char *vmname, virNWFilterBindingPtr binding; int ret; =20 - if (!(binding =3D virNWFilterBindingForNet(vmname, vmuuid, net))) + nwfilterDriverLock(); + binding =3D virHashLookup(driver->bindings, net->ifname); + if (binding) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Filter already present for NIC %s"), net->ifname= ); + nwfilterDriverUnlock(); + return -1; + } + if (!(binding =3D virNWFilterBindingForNet(vmname, vmuuid, net))) { + nwfilterDriverUnlock(); return -1; + } + virHashAddEntry(driver->bindings, net->ifname, binding); + nwfilterDriverUnlock(); + ret =3D virNWFilterInstantiateFilter(driver, binding); - virNWFilterBindingFree(binding); + + if (ret < 0) { + nwfilterDriverLock(); + virHashRemoveEntry(driver->bindings, net->ifname); + nwfilterDriverUnlock(); + } return ret; } =20 @@ -660,16 +691,18 @@ nwfilterInstantiateFilter(const char *vmname, static void nwfilterTeardownFilter(virDomainNetDefPtr net) { - virNWFilterBinding binding =3D { - .portdevname =3D net->ifname, - .linkdevname =3D (net->type =3D=3D VIR_DOMAIN_NET_TYPE_DIRECT ? - net->data.direct.linkdev : NULL), - .mac =3D net->mac, - .filter =3D net->filter, - .filterparams =3D net->filterparams, - }; - if ((net->ifname) && (net->filter)) - virNWFilterTeardownFilter(&binding); + virNWFilterBindingPtr binding; + if (!net->ifname) + return; + + nwfilterDriverLock(); + binding =3D virHashSteal(driver->bindings, net->ifname); + nwfilterDriverUnlock(); + if (!binding) + return; + + virNWFilterTeardownFilter(binding); + virNWFilterBindingFree(binding); } =20 =20 --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list