From nobody Thu Nov 28 08:28:40 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 1524843092961893.6821698089476; Fri, 27 Apr 2018 08:31:32 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 952F33150080; Fri, 27 Apr 2018 15:31:31 +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 3CCFE65B54; Fri, 27 Apr 2018 15:31:31 +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 B963E180596E; Fri, 27 Apr 2018 15:31:30 +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 w3RFPIMj032244 for ; Fri, 27 Apr 2018 11:25:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6B57083B71; Fri, 27 Apr 2018 15:25:18 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id D17E583B76; Fri, 27 Apr 2018 15:25:17 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 27 Apr 2018 16:25:00 +0100 Message-Id: <20180427152513.28928-2-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 01/14] nwfilter: remove pointless virNWFilterHashTable struct 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 27 Apr 2018 15:31:32 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 The virNWFilterHashTable struct only contains a single virHashTable member since commit 293d4fe2f11db98c91175525056c8883725d4b22 Author: Daniel P. Berrange Date: Mon Mar 24 16:35:23 2014 +0000 Remove pointless storage of var names in virNWFilterHashTable Thus, this struct wrapper adds no real value over just using the virHashTable directly, but brings the complexity of needing to derefence the hashtable to call virHash* APIs, and adds extra memory allocation step. To minimize code churn this just turns virNWFilterHashTable into a typedef aliases virHashTable. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Jiri Denemark --- src/conf/nwfilter_ipaddrmap.c | 6 ++--- src/conf/nwfilter_params.c | 49 +++++++++++-------------------= ---- src/conf/nwfilter_params.h | 8 ++---- src/nwfilter/nwfilter_dhcpsnoop.c | 4 +-- src/nwfilter/nwfilter_gentech_driver.c | 14 +++++----- tests/nwfilterxml2firewalltest.c | 2 +- 6 files changed, 31 insertions(+), 52 deletions(-) diff --git a/src/conf/nwfilter_ipaddrmap.c b/src/conf/nwfilter_ipaddrmap.c index 54e6d0f0f4..680667bac9 100644 --- a/src/conf/nwfilter_ipaddrmap.c +++ b/src/conf/nwfilter_ipaddrmap.c @@ -61,7 +61,7 @@ virNWFilterIPAddrMapAddIPAddr(const char *ifname, char *a= ddr) =20 virMutexLock(&ipAddressMapLock); =20 - val =3D virHashLookup(ipAddressMap->hashTable, ifname); + val =3D virHashLookup(ipAddressMap, ifname); if (!val) { val =3D virNWFilterVarValueCreateSimple(addrCopy); if (!val) @@ -109,7 +109,7 @@ virNWFilterIPAddrMapDelIPAddr(const char *ifname, const= char *ipaddr) virMutexLock(&ipAddressMapLock); =20 if (ipaddr !=3D NULL) { - val =3D virHashLookup(ipAddressMap->hashTable, ifname); + val =3D virHashLookup(ipAddressMap, ifname); if (val) { if (virNWFilterVarValueGetCardinality(val) =3D=3D 1 && STREQ(ipaddr, @@ -144,7 +144,7 @@ virNWFilterIPAddrMapGetIPAddr(const char *ifname) =20 virMutexLock(&ipAddressMapLock); =20 - res =3D virHashLookup(ipAddressMap->hashTable, ifname); + res =3D virHashLookup(ipAddressMap, ifname); =20 virMutexUnlock(&ipAddressMapLock); =20 diff --git a/src/conf/nwfilter_params.c b/src/conf/nwfilter_params.c index 3a01049182..e833c8cb5d 100644 --- a/src/conf/nwfilter_params.c +++ b/src/conf/nwfilter_params.c @@ -355,7 +355,7 @@ virNWFilterVarCombIterAddVariable(virNWFilterVarCombIte= rEntryPtr cie, unsigned int maxValue =3D 0, minValue =3D 0; const char *varName =3D virNWFilterVarAccessGetVarName(varAccess); =20 - varValue =3D virHashLookup(hash->hashTable, varName); + varValue =3D virHashLookup(hash, varName); if (varValue =3D=3D NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not find value for variable '%s'"), @@ -421,7 +421,7 @@ virNWFilterVarCombIterEntryAreUniqueEntries(virNWFilter= VarCombIterEntryPtr cie, virNWFilterVarValuePtr varValue, tmp; const char *value; =20 - varValue =3D virHashLookup(hash->hashTable, cie->varNames[0]); + varValue =3D virHashLookup(hash, cie->varNames[0]); if (!varValue) { /* caller's error */ VIR_ERROR(_("hash lookup resulted in NULL pointer")); @@ -439,7 +439,7 @@ virNWFilterVarCombIterEntryAreUniqueEntries(virNWFilter= VarCombIterEntryPtr cie, if (STREQ(value, virNWFilterVarValueGetNthValue(varValue, i))) { bool isSame =3D true; for (j =3D 1; j < cie->nVarNames; j++) { - tmp =3D virHashLookup(hash->hashTable, cie->varNames[j]); + tmp =3D virHashLookup(hash, cie->varNames[j]); if (!tmp) { /* should never occur to step on a NULL here */ return true; @@ -604,7 +604,7 @@ virNWFilterVarCombIterGetVarValue(virNWFilterVarCombIte= rPtr ci, return NULL; } =20 - value =3D virHashLookup(ci->hashTable->hashTable, varName); + value =3D virHashLookup(ci->hashTable, varName); if (!value) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not find value for variable '%s'"), @@ -648,11 +648,11 @@ virNWFilterHashTablePut(virNWFilterHashTablePtr table, const char *name, virNWFilterVarValuePtr val) { - if (!virHashLookup(table->hashTable, name)) { - if (virHashAddEntry(table->hashTable, name, val) < 0) + if (!virHashLookup(table, name)) { + if (virHashAddEntry(table, name, val) < 0) return -1; } else { - if (virHashUpdateEntry(table->hashTable, name, val) < 0) + if (virHashUpdateEntry(table, name, val) < 0) return -1; } return 0; @@ -671,27 +671,14 @@ virNWFilterHashTablePut(virNWFilterHashTablePtr table, void virNWFilterHashTableFree(virNWFilterHashTablePtr table) { - if (!table) - return; - virHashFree(table->hashTable); - - VIR_FREE(table); + virHashFree(table); } =20 =20 virNWFilterHashTablePtr virNWFilterHashTableCreate(int n) { - virNWFilterHashTablePtr ret; - - if (VIR_ALLOC(ret) < 0) - return NULL; - ret->hashTable =3D virHashCreate(n, hashDataFree); - if (!ret->hashTable) { - VIR_FREE(ret); - return NULL; - } - return ret; + return virHashCreate(n, hashDataFree); } =20 =20 @@ -699,7 +686,7 @@ void * virNWFilterHashTableRemoveEntry(virNWFilterHashTablePtr ht, const char *entry) { - return virHashSteal(ht->hashTable, entry); + return virHashSteal(ht, entry); } =20 =20 @@ -745,7 +732,7 @@ virNWFilterHashTablePutAll(virNWFilterHashTablePtr src, .errOccurred =3D 0, }; =20 - virHashForEach(src->hashTable, addToTable, &atts); + virHashForEach(src, addToTable, &atts); if (atts.errOccurred) goto err_exit; =20 @@ -770,11 +757,7 @@ bool virNWFilterHashTableEqual(virNWFilterHashTablePtr a, virNWFilterHashTablePtr b) { - if (!(a || b)) - return true; - if (!(a && b)) - return false; - return virHashEqual(a->hashTable, b->hashTable, virNWFilterVarValueCom= pare); + return virHashEqual(a, b, virNWFilterVarValueCompare); } =20 static bool @@ -819,7 +802,7 @@ virNWFilterParseParamAttributes(xmlNodePtr cur) goto skip_entry; if (!isValidVarValue(val)) goto skip_entry; - value =3D virHashLookup(table->hashTable, nam); + value =3D virHashLookup(table, nam); if (value) { /* add value to existing value -> list */ if (virNWFilterVarValueAddValue(value, val) < 0) { @@ -871,7 +854,7 @@ virNWFilterFormatParamAttributes(virBufferPtr buf, size_t i, j; int card, numKeys; =20 - numKeys =3D virHashSize(table->hashTable); + numKeys =3D virHashSize(table); =20 if (numKeys < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -879,7 +862,7 @@ virNWFilterFormatParamAttributes(virBufferPtr buf, return -1; } =20 - items =3D virHashGetItems(table->hashTable, + items =3D virHashGetItems(table, virNWFilterFormatParameterNameSorter); if (!items) return -1; @@ -1103,7 +1086,7 @@ virNWFilterVarAccessIsAvailable(const virNWFilterVarA= ccess *varAccess, unsigned int idx; virNWFilterVarValuePtr varValue; =20 - varValue =3D virHashLookup(hash->hashTable, varName); + varValue =3D virHashLookup(hash, varName); if (!varValue) return false; =20 diff --git a/src/conf/nwfilter_params.h b/src/conf/nwfilter_params.h index abd5b85fec..b3ed3e6418 100644 --- a/src/conf/nwfilter_params.h +++ b/src/conf/nwfilter_params.h @@ -63,12 +63,8 @@ int virNWFilterVarValueAddValue(virNWFilterVarValuePtr v= al, char *value); int virNWFilterVarValueAddValueCopy(virNWFilterVarValuePtr val, const char= *value); int virNWFilterVarValueDelValue(virNWFilterVarValuePtr val, const char *va= lue); =20 -typedef struct _virNWFilterHashTable virNWFilterHashTable; -typedef virNWFilterHashTable *virNWFilterHashTablePtr; -struct _virNWFilterHashTable { - virHashTablePtr hashTable; -}; - +typedef virHashTable virNWFilterHashTable; +typedef virHashTable *virNWFilterHashTablePtr; =20 virNWFilterHashTablePtr virNWFilterParseParamAttributes(xmlNodePtr cur); int virNWFilterFormatParamAttributes(virBufferPtr buf, diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcp= snoop.c index 6069e70460..d1e3f836a1 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -883,7 +883,7 @@ virNWFilterSnoopReqLeaseDel(virNWFilterSnoopReqPtr req, req->vars); } else { virNWFilterVarValuePtr dhcpsrvrs =3D - virHashLookup(req->vars->hashTable, NWFILTER_VARNAME_DHCPSERVE= R); + virHashLookup(req->vars, NWFILTER_VARNAME_DHCPSERVER); =20 if (req->techdriver && req->techdriver->applyDHCPOnlyRules(req->ifname, &req->macaddr, @@ -1648,7 +1648,7 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr tech= driver, goto exit_snoopreqput; } =20 - dhcpsrvrs =3D virHashLookup(filterparams->hashTable, + dhcpsrvrs =3D virHashLookup(filterparams, NWFILTER_VARNAME_DHCPSERVER); =20 if (techdriver->applyDHCPOnlyRules(req->ifname, &req->macaddr, diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter= _gentech_driver.c index 5ef26b6afb..4706f1f1da 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -153,7 +153,7 @@ virNWFilterVarHashmapAddStdValues(virNWFilterHashTableP= tr table, if (!val) return -1; =20 - if (virHashAddEntry(table->hashTable, + if (virHashAddEntry(table, NWFILTER_STD_VAR_MAC, val) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -167,7 +167,7 @@ virNWFilterVarHashmapAddStdValues(virNWFilterHashTableP= tr table, if (!val) return -1; =20 - if (virHashAddEntry(table->hashTable, + if (virHashAddEntry(table, NWFILTER_STD_VAR_IP, val) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -633,7 +633,7 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid, if (rc < 0) goto err_exit; =20 - lv =3D virHashLookup(vars->hashTable, NWFILTER_VARNAME_CTRL_IP_LEARNIN= G); + lv =3D virHashLookup(vars, NWFILTER_VARNAME_CTRL_IP_LEARNING); if (lv) learning =3D virNWFilterVarValueGetNthValue(lv, 0); else @@ -642,8 +642,8 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid, if (learning =3D=3D NULL) learning =3D NWFILTER_DFLT_LEARN; =20 - if (virHashSize(missing_vars->hashTable) =3D=3D 1) { - if (virHashLookup(missing_vars->hashTable, + if (virHashSize(missing_vars) =3D=3D 1) { + if (virHashLookup(missing_vars, NWFILTER_STD_VAR_IP) !=3D NULL) { if (STRCASEEQ(learning, "none")) { /* no learning */ reportIP =3D true; @@ -677,7 +677,7 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid, } else { goto err_unresolvable_vars; } - } else if (virHashSize(missing_vars->hashTable) > 1) { + } else if (virHashSize(missing_vars) > 1) { goto err_unresolvable_vars; } else if (!forceWithPendingReq && virNWFilterLookupLearnReq(ifindex) !=3D NULL) { @@ -729,7 +729,7 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid, =20 err_unresolvable_vars: =20 - buf =3D virNWFilterPrintVars(missing_vars->hashTable, ", ", false, rep= ortIP); + buf =3D virNWFilterPrintVars(missing_vars, ", ", false, reportIP); if (buf) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot instantiate filter due to unresolvable " diff --git a/tests/nwfilterxml2firewalltest.c b/tests/nwfilterxml2firewallt= est.c index b5eec538c4..bf1400d2d0 100644 --- a/tests/nwfilterxml2firewalltest.c +++ b/tests/nwfilterxml2firewalltest.c @@ -333,7 +333,7 @@ static int testSetOneParameter(virNWFilterHashTablePtr = vars, int ret =3D -1; virNWFilterVarValuePtr val; =20 - if ((val =3D virHashLookup(vars->hashTable, name)) =3D=3D NULL) { + if ((val =3D virHashLookup(vars, name)) =3D=3D NULL) { val =3D virNWFilterVarValueCreateSimpleCopyValue(value); if (!val) goto cleanup; --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Nov 28 08:28:40 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 1524842879898141.62114030729106; Fri, 27 Apr 2018 08:27:59 -0700 (PDT) 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 195354E918; Fri, 27 Apr 2018 15:27:58 +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 547E617D7C; Fri, 27 Apr 2018 15:27:57 +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 0EA17180215F; Fri, 27 Apr 2018 15:27:56 +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 w3RFPJf2032250 for ; Fri, 27 Apr 2018 11:25:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id 208BD83B76; Fri, 27 Apr 2018 15:25:19 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E3BA83B77; Fri, 27 Apr 2018 15:25:18 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 27 Apr 2018 16:25:01 +0100 Message-Id: <20180427152513.28928-3-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 02/14] nwfilter: remove methods that are trivial wrappers for virHash APIs 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.38]); Fri, 27 Apr 2018 15:27:58 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 This removes the virNWFilterHashTableFree, virNWFilterHashTablePut and virNWFilterHashTableRemove methods, in favour of just calling the virHash APIs directly. The virNWFilterHashTablePut method was unreasonably complex because the virHashUpdateEntry already knows how to create the entry if it does not currently exist. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Jiri Denemark --- src/conf/domain_conf.c | 6 ++-- src/conf/nwfilter_conf.c | 2 +- src/conf/nwfilter_ipaddrmap.c | 7 ++-- src/conf/nwfilter_params.c | 62 ++----------------------------= ---- src/conf/nwfilter_params.h | 6 ---- src/libvirt_private.syms | 3 -- src/nwfilter/nwfilter_dhcpsnoop.c | 4 +-- src/nwfilter/nwfilter_gentech_driver.c | 18 +++++----- src/nwfilter/nwfilter_learnipaddr.c | 4 +-- tests/nwfilterxml2firewalltest.c | 10 +++--- 10 files changed, 28 insertions(+), 94 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b0257068da..627058a144 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2093,7 +2093,7 @@ virDomainNetDefClear(virDomainNetDefPtr def) virDomainDeviceInfoClear(&def->info); =20 VIR_FREE(def->filter); - virNWFilterHashTableFree(def->filterparams); + virHashFree(def->filterparams); def->filterparams =3D NULL; =20 virNetDevBandwidthFree(def->bandwidth); @@ -11046,7 +11046,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlop= t, goto error; } filter =3D virXMLPropString(cur, "filter"); - virNWFilterHashTableFree(filterparams); + virHashFree(filterparams); filterparams =3D virNWFilterParseParamAttributes(cur); } else if ((flags & VIR_DOMAIN_DEF_PARSE_STATUS) && virXMLNodeNameEqual(cur, "state")) { @@ -11679,7 +11679,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlop= t, VIR_FREE(vhost_path); VIR_FREE(localaddr); VIR_FREE(localport); - virNWFilterHashTableFree(filterparams); + virHashFree(filterparams); =20 return def; =20 diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index fd42d58c2c..5d04f2a93c 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -312,7 +312,7 @@ virNWFilterIncludeDefFree(virNWFilterIncludeDefPtr inc) { if (!inc) return; - virNWFilterHashTableFree(inc->params); + virHashFree(inc->params); VIR_FREE(inc->filterref); VIR_FREE(inc); } diff --git a/src/conf/nwfilter_ipaddrmap.c b/src/conf/nwfilter_ipaddrmap.c index 680667bac9..a921d7cfd6 100644 --- a/src/conf/nwfilter_ipaddrmap.c +++ b/src/conf/nwfilter_ipaddrmap.c @@ -67,7 +67,7 @@ virNWFilterIPAddrMapAddIPAddr(const char *ifname, char *a= ddr) if (!val) goto cleanup; addrCopy =3D NULL; - ret =3D virNWFilterHashTablePut(ipAddressMap, ifname, val); + ret =3D virHashUpdateEntry(ipAddressMap, ifname, val); if (ret < 0) virNWFilterVarValueFree(val); goto cleanup; @@ -121,8 +121,7 @@ virNWFilterIPAddrMapDelIPAddr(const char *ifname, const= char *ipaddr) } else { remove_entry: /* remove whole entry */ - val =3D virNWFilterHashTableRemoveEntry(ipAddressMap, ifname); - virNWFilterVarValueFree(val); + virHashRemoveEntry(ipAddressMap, ifname); ret =3D 0; } =20 @@ -164,6 +163,6 @@ virNWFilterIPAddrMapInit(void) void virNWFilterIPAddrMapShutdown(void) { - virNWFilterHashTableFree(ipAddressMap); + virHashFree(ipAddressMap); ipAddressMap =3D NULL; } diff --git a/src/conf/nwfilter_params.c b/src/conf/nwfilter_params.c index e833c8cb5d..ee9c063941 100644 --- a/src/conf/nwfilter_params.c +++ b/src/conf/nwfilter_params.c @@ -631,65 +631,12 @@ hashDataFree(void *payload, const void *name ATTRIBUT= E_UNUSED) } =20 =20 -/** - * virNWFilterHashTablePut: - * @table: Pointer to a virNWFilterHashTable - * @name: name of the key to enter - * @val: The value associated with the key - * @freeName: Whether the name must be freed on table destruction - * - * Returns 0 on success, -1 on failure. - * - * Put an entry into the hashmap replacing and freeing an existing entry - * if one existed. - */ -int -virNWFilterHashTablePut(virNWFilterHashTablePtr table, - const char *name, - virNWFilterVarValuePtr val) -{ - if (!virHashLookup(table, name)) { - if (virHashAddEntry(table, name, val) < 0) - return -1; - } else { - if (virHashUpdateEntry(table, name, val) < 0) - return -1; - } - return 0; -} - - -/** - * virNWFilterHashTableFree: - * @table: Pointer to virNWFilterHashTable - * - * Free a hashtable de-allocating memory for all its entries. - * - * All hash tables within the NWFilter driver must use this - * function to deallocate and free their content. - */ -void -virNWFilterHashTableFree(virNWFilterHashTablePtr table) -{ - virHashFree(table); -} - - virNWFilterHashTablePtr virNWFilterHashTableCreate(int n) { return virHashCreate(n, hashDataFree); } =20 - -void * -virNWFilterHashTableRemoveEntry(virNWFilterHashTablePtr ht, - const char *entry) -{ - return virHashSteal(ht, entry); -} - - struct addToTableStruct { virNWFilterHashTablePtr target; int errOccurred; @@ -711,10 +658,7 @@ addToTable(void *payload, const void *name, void *data) return 0; } =20 - if (virNWFilterHashTablePut(atts->target, (const char *)name, val) < 0= ) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Could not put variable '%s' into hashmap"), - (const char *)name); + if (virHashUpdateEntry(atts->target, (const char *)name, val) < 0) { atts->errOccurred =3D 1; virNWFilterVarValueFree(val); } @@ -814,7 +758,7 @@ virNWFilterParseParamAttributes(xmlNodePtr cur) value =3D virNWFilterParseVarValue(val); if (!value) goto skip_entry; - if (virNWFilterHashTablePut(table, nam, value) < 0) + if (virHashUpdateEntry(table, nam, value) < 0) goto err_exit; } value =3D NULL; @@ -833,7 +777,7 @@ virNWFilterParseParamAttributes(xmlNodePtr cur) VIR_FREE(nam); VIR_FREE(val); virNWFilterVarValueFree(value); - virNWFilterHashTableFree(table); + virHashFree(table); return NULL; } =20 diff --git a/src/conf/nwfilter_params.h b/src/conf/nwfilter_params.h index b3ed3e6418..b24f023633 100644 --- a/src/conf/nwfilter_params.h +++ b/src/conf/nwfilter_params.h @@ -72,12 +72,6 @@ int virNWFilterFormatParamAttributes(virBufferPtr buf, const char *filterref); =20 virNWFilterHashTablePtr virNWFilterHashTableCreate(int n); -void virNWFilterHashTableFree(virNWFilterHashTablePtr table); -int virNWFilterHashTablePut(virNWFilterHashTablePtr table, - const char *name, - virNWFilterVarValuePtr val); -void *virNWFilterHashTableRemoveEntry(virNWFilterHashTablePtr table, - const char *name); int virNWFilterHashTablePutAll(virNWFilterHashTablePtr src, virNWFilterHashTablePtr dest); bool virNWFilterHashTableEqual(virNWFilterHashTablePtr a, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d2728749fb..bf17d17777 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -820,10 +820,7 @@ virNWFilterIPAddrMapShutdown; # conf/nwfilter_params.h virNWFilterHashTableCreate; virNWFilterHashTableEqual; -virNWFilterHashTableFree; -virNWFilterHashTablePut; virNWFilterHashTablePutAll; -virNWFilterHashTableRemoveEntry; virNWFilterVarAccessGetVarName; virNWFilterVarAccessIsAvailable; virNWFilterVarAccessPrint; diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcp= snoop.c index d1e3f836a1..d23cad3b75 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -636,7 +636,7 @@ virNWFilterSnoopReqFree(virNWFilterSnoopReqPtr req) VIR_FREE(req->ifname); VIR_FREE(req->linkdev); VIR_FREE(req->filtername); - virNWFilterHashTableFree(req->vars); + virHashFree(req->vars); =20 virMutexDestroy(&req->lock); virCondDestroy(&req->threadStatusCond); @@ -1617,7 +1617,7 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr tech= driver, } /* a recycled req may still have filtername and vars */ VIR_FREE(req->filtername); - virNWFilterHashTableFree(req->vars); + virHashFree(req->vars); } else { req =3D virNWFilterSnoopReqNew(ifkey); if (!req) diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter= _gentech_driver.c index 4706f1f1da..130a366d67 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -123,7 +123,7 @@ virNWFilterRuleInstFree(virNWFilterRuleInstPtr inst) if (!inst) return; =20 - virNWFilterHashTableFree(inst->vars); + virHashFree(inst->vars); VIR_FREE(inst); } =20 @@ -200,7 +200,7 @@ virNWFilterCreateVarHashmap(char *macaddr, return NULL; =20 if (virNWFilterVarHashmapAddStdValues(table, macaddr, ipaddr) < 0) { - virNWFilterHashTableFree(table); + virHashFree(table); return NULL; } return table; @@ -295,7 +295,7 @@ virNWFilterCreateVarsFrom(virNWFilterHashTablePtr vars1, return res; =20 err_exit: - virNWFilterHashTableFree(res); + virHashFree(res); return NULL; } =20 @@ -424,7 +424,7 @@ virNWFilterIncludeDefToRuleInst(virNWFilterDriverStateP= tr driver, cleanup: if (ret < 0) virNWFilterInstReset(inst); - virNWFilterHashTableFree(tmpvars); + virHashFree(tmpvars); if (obj) virNWFilterObjUnlock(obj); return ret; @@ -524,7 +524,7 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr fi= lter, } =20 varAccess =3D virBufferContentAndReset(&buf); - rc =3D virNWFilterHashTablePut(missing_vars, varAccess= , val); + rc =3D virHashUpdateEntry(missing_vars, varAccess, val= ); VIR_FREE(varAccess); if (rc < 0) { virNWFilterVarValueFree(val); @@ -562,7 +562,7 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr fi= lter, useNewFilter, driver); =20 - virNWFilterHashTableFree(tmpvars); + virHashFree(tmpvars); =20 virNWFilterObjUnlock(obj); if (rc < 0) @@ -723,7 +723,7 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid, =20 err_exit: virNWFilterInstReset(&inst); - virNWFilterHashTableFree(missing_vars); + virHashFree(missing_vars); =20 return rc; =20 @@ -832,10 +832,10 @@ virNWFilterInstantiateFilterUpdate(virNWFilterDriverS= tatePtr driver, teardownOld, macaddr, driver, forceWithPendingReq); =20 - virNWFilterHashTableFree(vars); + virHashFree(vars); =20 err_exit_vars1: - virNWFilterHashTableFree(vars1); + virHashFree(vars1); =20 err_exit: virNWFilterObjUnlock(obj); diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_le= arnipaddr.c index 9ca0639576..f5b94cf27d 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -216,7 +216,7 @@ virNWFilterIPAddrLearnReqFree(virNWFilterIPAddrLearnReq= Ptr req) return; =20 VIR_FREE(req->filtername); - virNWFilterHashTableFree(req->filterparams); + virHashFree(req->filterparams); =20 VIR_FREE(req); } @@ -765,7 +765,7 @@ virNWFilterLearnIPAddress(virNWFilterTechDriverPtr tech= driver, err_dereg_req: virNWFilterDeregisterLearnReq(ifindex); err_free_ht: - virNWFilterHashTableFree(ht); + virHashFree(ht); err_free_req: virNWFilterIPAddrLearnReqFree(req); err_no_req: diff --git a/tests/nwfilterxml2firewalltest.c b/tests/nwfilterxml2firewallt= est.c index bf1400d2d0..a51ad9412a 100644 --- a/tests/nwfilterxml2firewalltest.c +++ b/tests/nwfilterxml2firewalltest.c @@ -164,7 +164,7 @@ virNWFilterCreateVarsFrom(virNWFilterHashTablePtr vars1, return res; =20 err_exit: - virNWFilterHashTableFree(res); + virHashFree(res); return NULL; } =20 @@ -175,7 +175,7 @@ virNWFilterRuleInstFree(virNWFilterRuleInstPtr inst) if (!inst) return; =20 - virNWFilterHashTableFree(inst->vars); + virHashFree(inst->vars); VIR_FREE(inst); } =20 @@ -263,7 +263,7 @@ virNWFilterIncludeDefToRuleInst(virNWFilterIncludeDefPt= r inc, cleanup: if (ret < 0) virNWFilterInstReset(inst); - virNWFilterHashTableFree(tmpvars); + virHashFree(tmpvars); VIR_FREE(xml); return ret; } @@ -337,7 +337,7 @@ static int testSetOneParameter(virNWFilterHashTablePtr = vars, val =3D virNWFilterVarValueCreateSimpleCopyValue(value); if (!val) goto cleanup; - if (virNWFilterHashTablePut(vars, name, val) < 0) { + if (virHashUpdateEntry(vars, name, val) < 0) { virNWFilterVarValueFree(val); goto cleanup; } @@ -414,7 +414,7 @@ static int testCompareXMLToArgvFiles(const char *xml, virBufferFreeAndReset(&buf); VIR_FREE(actualargv); virNWFilterInstReset(&inst); - virNWFilterHashTableFree(vars); + virHashFree(vars); return ret; } =20 --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Nov 28 08:28:40 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 152484289855080.09866436062634; Fri, 27 Apr 2018 08:28:18 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F336E7B123; Fri, 27 Apr 2018 15:28:16 +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 B0AB316D2D; Fri, 27 Apr 2018 15:28:16 +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 27DA6180BAD3; Fri, 27 Apr 2018 15:28:16 +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 w3RFPKjs032258 for ; Fri, 27 Apr 2018 11:25:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id E8FCE83B77; Fri, 27 Apr 2018 15:25:19 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 563C5AB583; Fri, 27 Apr 2018 15:25:19 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 27 Apr 2018 16:25:02 +0100 Message-Id: <20180427152513.28928-4-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 03/14] nwfilter: remove virNWFilterHashTable typedefs entirely 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 27 Apr 2018 15:28:17 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 All the code now just uses the virHashTablePtr type directly. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Jiri Denemark --- src/conf/domain_conf.c | 2 +- src/conf/domain_conf.h | 2 +- src/conf/nwfilter_conf.h | 2 +- src/conf/nwfilter_ipaddrmap.c | 2 +- src/conf/nwfilter_params.c | 26 ++++++++++----------- src/conf/nwfilter_params.h | 23 ++++++++----------- src/nwfilter/nwfilter_dhcpsnoop.c | 6 ++--- src/nwfilter/nwfilter_dhcpsnoop.h | 2 +- src/nwfilter/nwfilter_gentech_driver.c | 42 +++++++++++++++++-------------= ---- src/nwfilter/nwfilter_gentech_driver.h | 4 ++-- src/nwfilter/nwfilter_learnipaddr.c | 6 ++--- src/nwfilter/nwfilter_learnipaddr.h | 4 ++-- src/nwfilter/nwfilter_tech_driver.h | 2 +- tests/nwfilterxml2firewalltest.c | 24 +++++++++---------- 14 files changed, 72 insertions(+), 75 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 627058a144..bdda11c599 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10868,7 +10868,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlop= t, char *vhostuser_type =3D NULL; char *trustGuestRxFilters =3D NULL; char *vhost_path =3D NULL; - virNWFilterHashTablePtr filterparams =3D NULL; + virHashTablePtr filterparams =3D NULL; virDomainActualNetDefPtr actual =3D NULL; xmlNodePtr oldnode =3D ctxt->node; virDomainChrSourceReconnectDef reconnect =3D {0}; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 3c7eccb8ca..b954f4d462 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1057,7 +1057,7 @@ struct _virDomainNetDef { virNetDevIPInfo guestIP; virDomainDeviceInfo info; char *filter; - virNWFilterHashTablePtr filterparams; + virHashTablePtr filterparams; virNetDevBandwidthPtr bandwidth; virNetDevVlan vlan; int trustGuestRxFilters; /* enum virTristateBool */ diff --git a/src/conf/nwfilter_conf.h b/src/conf/nwfilter_conf.h index f960bf3d56..a31db6d3ff 100644 --- a/src/conf/nwfilter_conf.h +++ b/src/conf/nwfilter_conf.h @@ -501,7 +501,7 @@ typedef struct _virNWFilterIncludeDef virNWFilterInclud= eDef; typedef virNWFilterIncludeDef *virNWFilterIncludeDefPtr; struct _virNWFilterIncludeDef { char *filterref; - virNWFilterHashTablePtr params; + virHashTablePtr params; }; =20 =20 diff --git a/src/conf/nwfilter_ipaddrmap.c b/src/conf/nwfilter_ipaddrmap.c index a921d7cfd6..14a62c1a74 100644 --- a/src/conf/nwfilter_ipaddrmap.c +++ b/src/conf/nwfilter_ipaddrmap.c @@ -36,7 +36,7 @@ #define VIR_FROM_THIS VIR_FROM_NWFILTER =20 static virMutex ipAddressMapLock =3D VIR_MUTEX_INITIALIZER; -static virNWFilterHashTablePtr ipAddressMap; +static virHashTablePtr ipAddressMap; =20 =20 /* Add an IP address to the list of IP addresses an interface is diff --git a/src/conf/nwfilter_params.c b/src/conf/nwfilter_params.c index ee9c063941..ffffc6bae8 100644 --- a/src/conf/nwfilter_params.c +++ b/src/conf/nwfilter_params.c @@ -348,7 +348,7 @@ virNWFilterVarCombIterEntryInit(virNWFilterVarCombIterE= ntryPtr cie, =20 static int virNWFilterVarCombIterAddVariable(virNWFilterVarCombIterEntryPtr cie, - virNWFilterHashTablePtr hash, + virHashTablePtr hash, const virNWFilterVarAccess *varAccess) { virNWFilterVarValuePtr varValue; @@ -415,7 +415,7 @@ virNWFilterVarCombIterAddVariable(virNWFilterVarCombIte= rEntryPtr cie, */ static bool virNWFilterVarCombIterEntryAreUniqueEntries(virNWFilterVarCombIterEntryPtr= cie, - virNWFilterHashTablePtr hash) + virHashTablePtr hash) { size_t i, j; virNWFilterVarValuePtr varValue, tmp; @@ -473,7 +473,7 @@ virNWFilterVarCombIterEntryAreUniqueEntries(virNWFilter= VarCombIterEntryPtr cie, * be created. */ virNWFilterVarCombIterPtr -virNWFilterVarCombIterCreate(virNWFilterHashTablePtr hash, +virNWFilterVarCombIterCreate(virHashTablePtr hash, virNWFilterVarAccessPtr *varAccess, size_t nVarAccess) { @@ -631,14 +631,14 @@ hashDataFree(void *payload, const void *name ATTRIBUT= E_UNUSED) } =20 =20 -virNWFilterHashTablePtr +virHashTablePtr virNWFilterHashTableCreate(int n) { return virHashCreate(n, hashDataFree); } =20 struct addToTableStruct { - virNWFilterHashTablePtr target; + virHashTablePtr target; int errOccurred; }; =20 @@ -668,8 +668,8 @@ addToTable(void *payload, const void *name, void *data) =20 =20 int -virNWFilterHashTablePutAll(virNWFilterHashTablePtr src, - virNWFilterHashTablePtr dest) +virNWFilterHashTablePutAll(virHashTablePtr src, + virHashTablePtr dest) { struct addToTableStruct atts =3D { .target =3D dest, @@ -698,8 +698,8 @@ virNWFilterVarValueCompare(const void *a, const void *b) } =20 bool -virNWFilterHashTableEqual(virNWFilterHashTablePtr a, - virNWFilterHashTablePtr b) +virNWFilterHashTableEqual(virHashTablePtr a, + virHashTablePtr b) { return virHashEqual(a, b, virNWFilterVarValueCompare); } @@ -723,13 +723,13 @@ virNWFilterParseVarValue(const char *val) return virNWFilterVarValueCreateSimpleCopyValue(val); } =20 -virNWFilterHashTablePtr +virHashTablePtr virNWFilterParseParamAttributes(xmlNodePtr cur) { char *nam, *val; virNWFilterVarValuePtr value; =20 - virNWFilterHashTablePtr table =3D virNWFilterHashTableCreate(0); + virHashTablePtr table =3D virNWFilterHashTableCreate(0); if (!table) return NULL; =20 @@ -791,7 +791,7 @@ virNWFilterFormatParameterNameSorter(const virHashKeyVa= luePair *a, =20 int virNWFilterFormatParamAttributes(virBufferPtr buf, - virNWFilterHashTablePtr table, + virHashTablePtr table, const char *filterref) { virHashKeyValuePairPtr items; @@ -1023,7 +1023,7 @@ virNWFilterVarAccessGetIntIterId(const virNWFilterVar= Access *vap) =20 bool virNWFilterVarAccessIsAvailable(const virNWFilterVarAccess *varAccess, - const virNWFilterHashTable *hash) + const virHashTable *hash) { const char *varName =3D virNWFilterVarAccessGetVarName(varAccess); const char *res; diff --git a/src/conf/nwfilter_params.h b/src/conf/nwfilter_params.h index b24f023633..9bdf65c033 100644 --- a/src/conf/nwfilter_params.h +++ b/src/conf/nwfilter_params.h @@ -63,19 +63,16 @@ int virNWFilterVarValueAddValue(virNWFilterVarValuePtr = val, char *value); int virNWFilterVarValueAddValueCopy(virNWFilterVarValuePtr val, const char= *value); int virNWFilterVarValueDelValue(virNWFilterVarValuePtr val, const char *va= lue); =20 -typedef virHashTable virNWFilterHashTable; -typedef virHashTable *virNWFilterHashTablePtr; - -virNWFilterHashTablePtr virNWFilterParseParamAttributes(xmlNodePtr cur); +virHashTablePtr virNWFilterParseParamAttributes(xmlNodePtr cur); int virNWFilterFormatParamAttributes(virBufferPtr buf, - virNWFilterHashTablePtr table, + virHashTablePtr table, const char *filterref); =20 -virNWFilterHashTablePtr virNWFilterHashTableCreate(int n); -int virNWFilterHashTablePutAll(virNWFilterHashTablePtr src, - virNWFilterHashTablePtr dest); -bool virNWFilterHashTableEqual(virNWFilterHashTablePtr a, - virNWFilterHashTablePtr b); +virHashTablePtr virNWFilterHashTableCreate(int n); +int virNWFilterHashTablePutAll(virHashTablePtr src, + virHashTablePtr dest); +bool virNWFilterHashTableEqual(virHashTablePtr a, + virHashTablePtr b); =20 # define VALID_VARNAME \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_" @@ -123,7 +120,7 @@ virNWFilterVarAccessType virNWFilterVarAccessGetType( unsigned int virNWFilterVarAccessGetIterId(const virNWFilterVarAccess *vap= ); unsigned int virNWFilterVarAccessGetIndex(const virNWFilterVarAccess *vap); bool virNWFilterVarAccessIsAvailable(const virNWFilterVarAccess *vap, - const virNWFilterHashTable *hash); + const virHashTable *hash); =20 typedef struct _virNWFilterVarCombIterEntry virNWFilterVarCombIterEntry; typedef virNWFilterVarCombIterEntry *virNWFilterVarCombIterEntryPtr; @@ -139,12 +136,12 @@ struct _virNWFilterVarCombIterEntry { typedef struct _virNWFilterVarCombIter virNWFilterVarCombIter; typedef virNWFilterVarCombIter *virNWFilterVarCombIterPtr; struct _virNWFilterVarCombIter { - virNWFilterHashTablePtr hashTable; + virHashTablePtr hashTable; size_t nIter; virNWFilterVarCombIterEntry iter[0]; }; virNWFilterVarCombIterPtr virNWFilterVarCombIterCreate( - virNWFilterHashTablePtr hash, + virHashTablePtr hash, virNWFilterVarAccessPtr *vars, size_t nVars); =20 diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcp= snoop.c index d23cad3b75..aec68ab847 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -141,7 +141,7 @@ struct _virNWFilterSnoopReq { char ifkey[VIR_IFKEY_LEN]; virMacAddr macaddr; char *filtername; - virNWFilterHashTablePtr vars; + virHashTablePtr vars; virNWFilterDriverStatePtr driver; /* start and end of lease list, ordered by lease time */ virNWFilterSnoopIPLeasePtr start; @@ -1595,7 +1595,7 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr tech= driver, const unsigned char *vmuuid, const virMacAddr *macaddr, const char *filtername, - virNWFilterHashTablePtr filterparams, + virHashTablePtr filterparams, virNWFilterDriverStatePtr driver) { virNWFilterSnoopReqPtr req; @@ -2239,7 +2239,7 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr tech= driver ATTRIBUTE_UNUSED, const unsigned char *vmuuid ATTRIBUTE_UNUSED, const virMacAddr *macaddr ATTRIBUTE_UNUSED, const char *filtername ATTRIBUTE_UNUSED, - virNWFilterHashTablePtr filterparams ATTRIBUTE_UNU= SED, + virHashTablePtr filterparams ATTRIBUTE_UNUSED, virNWFilterDriverStatePtr driver ATTRIBUTE_UNUSED) { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/nwfilter/nwfilter_dhcpsnoop.h b/src/nwfilter/nwfilter_dhcp= snoop.h index 3ef96fa4e1..a5925de40a 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.h +++ b/src/nwfilter/nwfilter_dhcpsnoop.h @@ -35,7 +35,7 @@ int virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr tech= driver, const unsigned char *vmuuid, const virMacAddr *macaddr, const char *filtername, - virNWFilterHashTablePtr filterparams, + virHashTablePtr filterparams, virNWFilterDriverStatePtr driver); void virNWFilterDHCPSnoopEnd(const char *ifname); #endif /* __NWFILTER_DHCPSNOOP_H */ diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter= _gentech_driver.c index 130a366d67..0735426734 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -142,7 +142,7 @@ virNWFilterRuleInstFree(virNWFilterRuleInstPtr inst) * Adds a couple of standard keys (MAC, IP) to the hash table. */ static int -virNWFilterVarHashmapAddStdValues(virNWFilterHashTablePtr table, +virNWFilterVarHashmapAddStdValues(virHashTablePtr table, char *macaddr, const virNWFilterVarValue *ipaddr) { @@ -191,11 +191,11 @@ virNWFilterVarHashmapAddStdValues(virNWFilterHashTabl= ePtr table, * * Returns pointer to hashmap, NULL if an error occurred. */ -virNWFilterHashTablePtr +virHashTablePtr virNWFilterCreateVarHashmap(char *macaddr, const virNWFilterVarValue *ipaddr) { - virNWFilterHashTablePtr table =3D virNWFilterHashTableCreate(0); + virHashTablePtr table =3D virNWFilterHashTableCreate(0); if (!table) return NULL; =20 @@ -208,7 +208,7 @@ virNWFilterCreateVarHashmap(char *macaddr, =20 =20 /** - * Convert a virNWFilterHashTable into a string of comma-separated + * Convert a virHashTable into a string of comma-separated * variable names. */ struct printString @@ -278,11 +278,11 @@ virNWFilterPrintVars(virHashTablePtr vars, * Creates a new hash table with contents of var1 and var2 added where * contents of var2 will overwrite those of var1. */ -static virNWFilterHashTablePtr -virNWFilterCreateVarsFrom(virNWFilterHashTablePtr vars1, - virNWFilterHashTablePtr vars2) +static virHashTablePtr +virNWFilterCreateVarsFrom(virHashTablePtr vars1, + virHashTablePtr vars2) { - virNWFilterHashTablePtr res =3D virNWFilterHashTableCreate(0); + virHashTablePtr res =3D virNWFilterHashTableCreate(0); if (!res) return NULL; =20 @@ -330,7 +330,7 @@ virNWFilterInstReset(virNWFilterInstPtr inst) static int virNWFilterDefToInst(virNWFilterDriverStatePtr driver, virNWFilterDefPtr def, - virNWFilterHashTablePtr vars, + virHashTablePtr vars, enum instCase useNewFilter, bool *foundNewFilter, virNWFilterInstPtr inst); @@ -338,7 +338,7 @@ virNWFilterDefToInst(virNWFilterDriverStatePtr driver, static int virNWFilterRuleDefToRuleInst(virNWFilterDefPtr def, virNWFilterRuleDefPtr rule, - virNWFilterHashTablePtr vars, + virHashTablePtr vars, virNWFilterInstPtr inst) { virNWFilterRuleInstPtr ruleinst; @@ -371,13 +371,13 @@ virNWFilterRuleDefToRuleInst(virNWFilterDefPtr def, static int virNWFilterIncludeDefToRuleInst(virNWFilterDriverStatePtr driver, virNWFilterIncludeDefPtr inc, - virNWFilterHashTablePtr vars, + virHashTablePtr vars, enum instCase useNewFilter, bool *foundNewFilter, virNWFilterInstPtr inst) { virNWFilterObjPtr obj; - virNWFilterHashTablePtr tmpvars =3D NULL; + virHashTablePtr tmpvars =3D NULL; virNWFilterDefPtr childdef; virNWFilterDefPtr newChilddef; int ret =3D -1; @@ -452,7 +452,7 @@ virNWFilterIncludeDefToRuleInst(virNWFilterDriverStateP= tr driver, static int virNWFilterDefToInst(virNWFilterDriverStatePtr driver, virNWFilterDefPtr def, - virNWFilterHashTablePtr vars, + virHashTablePtr vars, enum instCase useNewFilter, bool *foundNewFilter, virNWFilterInstPtr inst) @@ -487,8 +487,8 @@ virNWFilterDefToInst(virNWFilterDriverStatePtr driver, =20 static int virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr filter, - virNWFilterHashTablePtr vars, - virNWFilterHashTablePtr missing_vars, + virHashTablePtr vars, + virHashTablePtr missing_vars, int useNewFilter, virNWFilterDriverStatePtr driver) { @@ -498,7 +498,7 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr fi= lter, virNWFilterDefPtr next_filter; virNWFilterDefPtr newNext_filter; virNWFilterVarValuePtr val; - virNWFilterHashTablePtr tmpvars; + virHashTablePtr tmpvars; =20 for (i =3D 0; i < filter->nentries; i++) { virNWFilterRuleDefPtr rule =3D filter->filterEntries[i]->rule; @@ -600,7 +600,7 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid, const char *ifname, int ifindex, const char *linkdev, - virNWFilterHashTablePtr vars, + virHashTablePtr vars, enum instCase useNewFilter, bool *foundNewFilter, bool teardownOld, @@ -616,7 +616,7 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid, const char *learning; bool reportIP =3D false; =20 - virNWFilterHashTablePtr missing_vars =3D virNWFilterHashTableCreate(0); + virHashTablePtr missing_vars =3D virNWFilterHashTableCreate(0); =20 memset(&inst, 0, sizeof(inst)); =20 @@ -754,7 +754,7 @@ virNWFilterInstantiateFilterUpdate(virNWFilterDriverSta= tePtr driver, const char *linkdev, const virMacAddr *macaddr, const char *filtername, - virNWFilterHashTablePtr filterparams, + virHashTablePtr filterparams, enum instCase useNewFilter, bool forceWithPendingReq, bool *foundNewFilter) @@ -763,7 +763,7 @@ virNWFilterInstantiateFilterUpdate(virNWFilterDriverSta= tePtr driver, const char *drvname =3D EBIPTABLES_DRIVER_ID; virNWFilterTechDriverPtr techdriver; virNWFilterObjPtr obj; - virNWFilterHashTablePtr vars, vars1; + virHashTablePtr vars, vars1; virNWFilterDefPtr filter; virNWFilterDefPtr newFilter; char vmmacaddr[VIR_MAC_STRING_BUFLEN] =3D {0}; @@ -896,7 +896,7 @@ virNWFilterInstantiateFilterLate(virNWFilterDriverState= Ptr driver, const char *linkdev, const virMacAddr *macaddr, const char *filtername, - virNWFilterHashTablePtr filterparams) + virHashTablePtr filterparams) { int rc; bool foundNewFilter =3D false; diff --git a/src/nwfilter/nwfilter_gentech_driver.h b/src/nwfilter/nwfilter= _gentech_driver.h index 71924879a2..67092157b8 100644 --- a/src/nwfilter/nwfilter_gentech_driver.h +++ b/src/nwfilter/nwfilter_gentech_driver.h @@ -53,11 +53,11 @@ int virNWFilterInstantiateFilterLate(virNWFilterDriverS= tatePtr driver, const char *linkdev, const virMacAddr *macaddr, const char *filtername, - virNWFilterHashTablePtr filterparams); + virHashTablePtr filterparams); =20 int virNWFilterTeardownFilter(const virDomainNetDef *net); =20 -virNWFilterHashTablePtr virNWFilterCreateVarHashmap(char *macaddr, +virHashTablePtr virNWFilterCreateVarHashmap(char *macaddr, const virNWFilterVarValue *value); =20 int virNWFilterDomainFWUpdateCB(virDomainObjPtr vm, diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_le= arnipaddr.c index f5b94cf27d..2401857ddb 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -692,14 +692,14 @@ virNWFilterLearnIPAddress(virNWFilterTechDriverPtr te= chdriver, const char *linkdev, const virMacAddr *macaddr, const char *filtername, - virNWFilterHashTablePtr filterparams, + virHashTablePtr filterparams, virNWFilterDriverStatePtr driver, enum howDetect howDetect) { int rc; virThread thread; virNWFilterIPAddrLearnReqPtr req =3D NULL; - virNWFilterHashTablePtr ht =3D NULL; + virHashTablePtr ht =3D NULL; =20 if (howDetect =3D=3D 0) return -1; @@ -781,7 +781,7 @@ virNWFilterLearnIPAddress(virNWFilterTechDriverPtr tech= driver ATTRIBUTE_UNUSED, const char *linkdev ATTRIBUTE_UNUSED, const virMacAddr *macaddr ATTRIBUTE_UNUSED, const char *filtername ATTRIBUTE_UNUSED, - virNWFilterHashTablePtr filterparams ATTRIBUTE_U= NUSED, + virHashTablePtr filterparams ATTRIBUTE_UNUSED, virNWFilterDriverStatePtr driver ATTRIBUTE_UNUSE= D, enum howDetect howDetect ATTRIBUTE_UNUSED) { diff --git a/src/nwfilter/nwfilter_learnipaddr.h b/src/nwfilter/nwfilter_le= arnipaddr.h index b93ed38cff..dc4c0d110f 100644 --- a/src/nwfilter/nwfilter_learnipaddr.h +++ b/src/nwfilter/nwfilter_learnipaddr.h @@ -44,7 +44,7 @@ struct _virNWFilterIPAddrLearnReq { char linkdev[IF_NAMESIZE]; virMacAddr macaddr; char *filtername; - virNWFilterHashTablePtr filterparams; + virHashTablePtr filterparams; virNWFilterDriverStatePtr driver; enum howDetect howDetect; =20 @@ -58,7 +58,7 @@ int virNWFilterLearnIPAddress(virNWFilterTechDriverPtr te= chdriver, const char *linkdev, const virMacAddr *macaddr, const char *filtername, - virNWFilterHashTablePtr filterparams, + virHashTablePtr filterparams, virNWFilterDriverStatePtr driver, enum howDetect howDetect); =20 diff --git a/src/nwfilter/nwfilter_tech_driver.h b/src/nwfilter/nwfilter_te= ch_driver.h index bc30496644..d2ac0077db 100644 --- a/src/nwfilter/nwfilter_tech_driver.h +++ b/src/nwfilter/nwfilter_tech_driver.h @@ -39,7 +39,7 @@ struct _virNWFilterRuleInst { virNWFilterChainPriority chainPriority; virNWFilterRuleDefPtr def; virNWFilterRulePriority priority; - virNWFilterHashTablePtr vars; + virHashTablePtr vars; }; =20 =20 diff --git a/tests/nwfilterxml2firewalltest.c b/tests/nwfilterxml2firewallt= est.c index a51ad9412a..043b7d170e 100644 --- a/tests/nwfilterxml2firewalltest.c +++ b/tests/nwfilterxml2firewalltest.c @@ -147,11 +147,11 @@ static const char *commonRules[] =3D { }; =20 =20 -static virNWFilterHashTablePtr -virNWFilterCreateVarsFrom(virNWFilterHashTablePtr vars1, - virNWFilterHashTablePtr vars2) +static virHashTablePtr +virNWFilterCreateVarsFrom(virHashTablePtr vars1, + virHashTablePtr vars2) { - virNWFilterHashTablePtr res =3D virNWFilterHashTableCreate(0); + virHashTablePtr res =3D virNWFilterHashTableCreate(0); if (!res) return NULL; =20 @@ -199,13 +199,13 @@ virNWFilterInstReset(virNWFilterInstPtr inst) =20 static int virNWFilterDefToInst(const char *xml, - virNWFilterHashTablePtr vars, + virHashTablePtr vars, virNWFilterInstPtr inst); =20 static int virNWFilterRuleDefToRuleInst(virNWFilterDefPtr def, virNWFilterRuleDefPtr rule, - virNWFilterHashTablePtr vars, + virHashTablePtr vars, virNWFilterInstPtr inst) { virNWFilterRuleInstPtr ruleinst; @@ -238,10 +238,10 @@ virNWFilterRuleDefToRuleInst(virNWFilterDefPtr def, =20 static int virNWFilterIncludeDefToRuleInst(virNWFilterIncludeDefPtr inc, - virNWFilterHashTablePtr vars, + virHashTablePtr vars, virNWFilterInstPtr inst) { - virNWFilterHashTablePtr tmpvars =3D NULL; + virHashTablePtr tmpvars =3D NULL; int ret =3D -1; char *xml; =20 @@ -270,7 +270,7 @@ virNWFilterIncludeDefToRuleInst(virNWFilterIncludeDefPt= r inc, =20 static int virNWFilterDefToInst(const char *xml, - virNWFilterHashTablePtr vars, + virHashTablePtr vars, virNWFilterInstPtr inst) { size_t i; @@ -326,7 +326,7 @@ static void testRemoveCommonRules(char *rules) } =20 =20 -static int testSetOneParameter(virNWFilterHashTablePtr vars, +static int testSetOneParameter(virHashTablePtr vars, const char *name, const char *value) { @@ -350,7 +350,7 @@ static int testSetOneParameter(virNWFilterHashTablePtr = vars, return ret; } =20 -static int testSetDefaultParameters(virNWFilterHashTablePtr vars) +static int testSetDefaultParameters(virHashTablePtr vars) { if (testSetOneParameter(vars, "IPSETNAME", "tck_test") < 0 || testSetOneParameter(vars, "A", "1.1.1.1") || @@ -374,7 +374,7 @@ static int testCompareXMLToArgvFiles(const char *xml, { char *actualargv =3D NULL; virBuffer buf =3D VIR_BUFFER_INITIALIZER; - virNWFilterHashTablePtr vars =3D virNWFilterHashTableCreate(0); + virHashTablePtr vars =3D virNWFilterHashTableCreate(0); virNWFilterInst inst; int ret =3D -1; =20 --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Nov 28 08:28:40 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 1524843377201764.2767498744379; Fri, 27 Apr 2018 08:36:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7DFF04E90A; Fri, 27 Apr 2018 15:36:14 +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 0ADF216D2E; Fri, 27 Apr 2018 15:36:14 +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 0465418033EB; Fri, 27 Apr 2018 15:36:13 +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 w3RFPKOm032268 for ; Fri, 27 Apr 2018 11:25:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9339A83B77; Fri, 27 Apr 2018 15:25:20 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2A8E1AB3EF; Fri, 27 Apr 2018 15:25:20 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 27 Apr 2018 16:25:03 +0100 Message-Id: <20180427152513.28928-5-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 04/14] nwfilter: make virNWFilterIPAddrLearnReq type private 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.84 on 10.5.11.23 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:36:15 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 The virNWFilterIPAddrLearnReq type should only be used by the IP address learning code, so can live in the implementation file instead of header file. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Jiri Denemark --- src/nwfilter/nwfilter_gentech_driver.c | 8 ++++---- src/nwfilter/nwfilter_learnipaddr.c | 23 ++++++++++++++++++++--- src/nwfilter/nwfilter_learnipaddr.h | 19 +------------------ 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter= _gentech_driver.c index 0735426734..91794dd3ad 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -655,7 +655,7 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid, filter->name, vars, driver); goto err_exit; } else if (STRCASEEQ(learning, "any")) { - if (virNWFilterLookupLearnReq(ifindex) =3D=3D NULL) { + if (!virNWFilterHasLearnReq(ifindex)) { rc =3D virNWFilterLearnIPAddress(techdriver, ifname, ifindex, @@ -680,7 +680,7 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid, } else if (virHashSize(missing_vars) > 1) { goto err_unresolvable_vars; } else if (!forceWithPendingReq && - virNWFilterLookupLearnReq(ifindex) !=3D NULL) { + virNWFilterHasLearnReq(ifindex)) { goto err_exit; } =20 @@ -976,7 +976,7 @@ virNWFilterRollbackUpdateFilter(const virDomainNetDef *= net) /* don't tear anything while the address is being learned */ if (virNetDevGetIndex(net->ifname, &ifindex) < 0) virResetLastError(); - else if (virNWFilterLookupLearnReq(ifindex) !=3D NULL) + else if (virNWFilterHasLearnReq(ifindex)) return 0; =20 return techdriver->tearNewRules(net->ifname); @@ -1002,7 +1002,7 @@ virNWFilterTearOldFilter(virDomainNetDefPtr net) /* don't tear anything while the address is being learned */ if (virNetDevGetIndex(net->ifname, &ifindex) < 0) virResetLastError(); - else if (virNWFilterLookupLearnReq(ifindex) !=3D NULL) + else if (virNWFilterHasLearnReq(ifindex)) return 0; =20 return techdriver->tearOldRules(net->ifname); diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_le= arnipaddr.c index 2401857ddb..cc3bfd971c 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -133,6 +133,23 @@ struct _virNWFilterIfaceLock { int refctr; }; =20 +typedef struct _virNWFilterIPAddrLearnReq virNWFilterIPAddrLearnReq; +typedef virNWFilterIPAddrLearnReq *virNWFilterIPAddrLearnReqPtr; +struct _virNWFilterIPAddrLearnReq { + virNWFilterTechDriverPtr techdriver; + char ifname[IF_NAMESIZE]; + int ifindex; + char linkdev[IF_NAMESIZE]; + virMacAddr macaddr; + char *filtername; + virHashTablePtr filterparams; + virNWFilterDriverStatePtr driver; + enum howDetect howDetect; + + int status; + volatile bool terminate; +}; + =20 static bool threadsTerminate; =20 @@ -279,8 +296,8 @@ virNWFilterTerminateLearnReq(const char *ifname) } =20 =20 -virNWFilterIPAddrLearnReqPtr -virNWFilterLookupLearnReq(int ifindex) +bool +virNWFilterHasLearnReq(int ifindex) { void *res; IFINDEX2STR(ifindex_str, ifindex); @@ -291,7 +308,7 @@ virNWFilterLookupLearnReq(int ifindex) =20 virMutexUnlock(&pendingLearnReqLock); =20 - return res; + return res !=3D NULL; } =20 =20 diff --git a/src/nwfilter/nwfilter_learnipaddr.h b/src/nwfilter/nwfilter_le= arnipaddr.h index dc4c0d110f..06fea5bff8 100644 --- a/src/nwfilter/nwfilter_learnipaddr.h +++ b/src/nwfilter/nwfilter_learnipaddr.h @@ -35,23 +35,6 @@ enum howDetect { DETECT_STATIC =3D 2, }; =20 -typedef struct _virNWFilterIPAddrLearnReq virNWFilterIPAddrLearnReq; -typedef virNWFilterIPAddrLearnReq *virNWFilterIPAddrLearnReqPtr; -struct _virNWFilterIPAddrLearnReq { - virNWFilterTechDriverPtr techdriver; - char ifname[IF_NAMESIZE]; - int ifindex; - char linkdev[IF_NAMESIZE]; - virMacAddr macaddr; - char *filtername; - virHashTablePtr filterparams; - virNWFilterDriverStatePtr driver; - enum howDetect howDetect; - - int status; - volatile bool terminate; -}; - int virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver, const char *ifname, int ifindex, @@ -62,7 +45,7 @@ int virNWFilterLearnIPAddress(virNWFilterTechDriverPtr te= chdriver, virNWFilterDriverStatePtr driver, enum howDetect howDetect); =20 -virNWFilterIPAddrLearnReqPtr virNWFilterLookupLearnReq(int ifindex); +bool virNWFilterHasLearnReq(int ifindex); int virNWFilterTerminateLearnReq(const char *ifname); =20 int virNWFilterLockIface(const char *ifname) ATTRIBUTE_RETURN_CHECK; --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Nov 28 08:28:40 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 1524842908437408.02946240327026; Fri, 27 Apr 2018 08:28:28 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D8F097D4E3; Fri, 27 Apr 2018 15:28:26 +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 A2C8D314EE61; Fri, 27 Apr 2018 15:28:26 +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 52FF44CA9F; Fri, 27 Apr 2018 15:28:26 +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 w3RFPLC5032278 for ; Fri, 27 Apr 2018 11:25:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3AC8783B77; Fri, 27 Apr 2018 15:25:21 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id C67CC83B76; Fri, 27 Apr 2018 15:25:20 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 27 Apr 2018 16:25:04 +0100 Message-Id: <20180427152513.28928-6-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 05/14] nwfilter: remove obsolete code related to firewalld 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.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 27 Apr 2018 15:28:27 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 There is a bunch of left over code in the nwfilter driver related to monitoring firewalld over dbus, that is no longer used since the conversion to use virFirewall APIs. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Jiri Denemark --- src/conf/virnwfilterobj.h | 1 - src/nwfilter/nwfilter_driver.c | 18 ------------------ src/nwfilter/nwfilter_driver.h | 2 -- 3 files changed, 21 deletions(-) diff --git a/src/conf/virnwfilterobj.h b/src/conf/virnwfilterobj.h index 8e79518ed3..433b0402d0 100644 --- a/src/conf/virnwfilterobj.h +++ b/src/conf/virnwfilterobj.h @@ -38,7 +38,6 @@ struct _virNWFilterDriverState { virNWFilterObjListPtr nwfilters; =20 char *configDir; - bool watchingFirewallD; }; =20 virNWFilterDefPtr diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index 542de03596..fef3aa272b 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -186,8 +186,6 @@ nwfilterStateInitialize(bool privileged, if (virMutexInit(&driver->lock) < 0) goto err_free_driverstate; =20 - /* remember that we are going to use firewalld */ - driver->watchingFirewallD =3D (sysbus !=3D NULL); driver->privileged =3D privileged; if (!(driver->nwfilters =3D virNWFilterObjListNew())) goto error; @@ -311,22 +309,6 @@ nwfilterStateReload(void) } =20 =20 -/** - * virNWFilterIsWatchingFirewallD: - * - * Checks if the nwfilter has the DBus watches for FirewallD installed. - * - * Returns true if it is watching firewalld, false otherwise - */ -bool -virNWFilterDriverIsWatchingFirewallD(void) -{ - if (!driver) - return false; - - return driver->watchingFirewallD; -} - /** * nwfilterStateCleanup: * diff --git a/src/nwfilter/nwfilter_driver.h b/src/nwfilter/nwfilter_driver.h index 06d7572d21..ad56e7bb2f 100644 --- a/src/nwfilter/nwfilter_driver.h +++ b/src/nwfilter/nwfilter_driver.h @@ -33,6 +33,4 @@ =20 int nwfilterRegister(void); =20 -bool virNWFilterDriverIsWatchingFirewallD(void); - #endif /* __VIR_NWFILTER_DRIVER_H__ */ --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Nov 28 08:28:40 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 1524842914620711.4237594367798; Fri, 27 Apr 2018 08:28:34 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 17B8481DFE; Fri, 27 Apr 2018 15:28:33 +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 B353E16D36; Fri, 27 Apr 2018 15:28: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 5D4A9180215F; Fri, 27 Apr 2018 15:28:32 +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 w3RFPLBW032283 for ; Fri, 27 Apr 2018 11:25:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id D39C2AB3EF; Fri, 27 Apr 2018 15:25:21 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6BCFB83B71; Fri, 27 Apr 2018 15:25:21 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 27 Apr 2018 16:25:05 +0100 Message-Id: <20180427152513.28928-7-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 06/14] nwfilter: fix leaking of filter parameters upon error 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 27 Apr 2018 15:28:33 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 The filter parameters were not correctly free'd when an error hits while adding to the hash table. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Jiri Denemark --- src/nwfilter/nwfilter_gentech_driver.c | 22 ++++++---------------- src/nwfilter/nwfilter_gentech_driver.h | 2 +- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter= _gentech_driver.c index 91794dd3ad..af4411d4db 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -143,19 +143,20 @@ virNWFilterRuleInstFree(virNWFilterRuleInstPtr inst) */ static int virNWFilterVarHashmapAddStdValues(virHashTablePtr table, - char *macaddr, + const char *macaddr, const virNWFilterVarValue *ipaddr) { virNWFilterVarValue *val; =20 if (macaddr) { - val =3D virNWFilterVarValueCreateSimple(macaddr); + val =3D virNWFilterVarValueCreateSimpleCopyValue(macaddr); if (!val) return -1; =20 if (virHashAddEntry(table, NWFILTER_STD_VAR_MAC, val) < 0) { + virNWFilterVarValueFree(val); virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not add variable 'MAC' to hashma= p")); return -1; @@ -170,6 +171,7 @@ virNWFilterVarHashmapAddStdValues(virHashTablePtr table, if (virHashAddEntry(table, NWFILTER_STD_VAR_IP, val) < 0) { + virNWFilterVarValueFree(val); virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not add variable 'IP' to hashmap= ")); return -1; @@ -192,7 +194,7 @@ virNWFilterVarHashmapAddStdValues(virHashTablePtr table, * Returns pointer to hashmap, NULL if an error occurred. */ virHashTablePtr -virNWFilterCreateVarHashmap(char *macaddr, +virNWFilterCreateVarHashmap(const char *macaddr, const virNWFilterVarValue *ipaddr) { virHashTablePtr table =3D virNWFilterHashTableCreate(0); @@ -767,9 +769,7 @@ virNWFilterInstantiateFilterUpdate(virNWFilterDriverSta= tePtr driver, virNWFilterDefPtr filter; virNWFilterDefPtr newFilter; char vmmacaddr[VIR_MAC_STRING_BUFLEN] =3D {0}; - char *str_macaddr =3D NULL; virNWFilterVarValuePtr ipaddr; - char *str_ipaddr =3D NULL; =20 techdriver =3D virNWFilterTechDriverForName(drvname); =20 @@ -788,22 +788,15 @@ virNWFilterInstantiateFilterUpdate(virNWFilterDriverS= tatePtr driver, return -1; =20 virMacAddrFormat(macaddr, vmmacaddr); - if (VIR_STRDUP(str_macaddr, vmmacaddr) < 0) { - rc =3D -1; - goto err_exit; - } =20 ipaddr =3D virNWFilterIPAddrMapGetIPAddr(ifname); =20 - vars1 =3D virNWFilterCreateVarHashmap(str_macaddr, ipaddr); + vars1 =3D virNWFilterCreateVarHashmap(vmmacaddr, ipaddr); if (!vars1) { rc =3D -1; goto err_exit; } =20 - str_macaddr =3D NULL; - str_ipaddr =3D NULL; - vars =3D virNWFilterCreateVarsFrom(vars1, filterparams); if (!vars) { @@ -840,9 +833,6 @@ virNWFilterInstantiateFilterUpdate(virNWFilterDriverSta= tePtr driver, err_exit: virNWFilterObjUnlock(obj); =20 - VIR_FREE(str_ipaddr); - VIR_FREE(str_macaddr); - return rc; } =20 diff --git a/src/nwfilter/nwfilter_gentech_driver.h b/src/nwfilter/nwfilter= _gentech_driver.h index 67092157b8..86cc677e79 100644 --- a/src/nwfilter/nwfilter_gentech_driver.h +++ b/src/nwfilter/nwfilter_gentech_driver.h @@ -57,7 +57,7 @@ int virNWFilterInstantiateFilterLate(virNWFilterDriverSta= tePtr driver, =20 int virNWFilterTeardownFilter(const virDomainNetDef *net); =20 -virHashTablePtr virNWFilterCreateVarHashmap(char *macaddr, +virHashTablePtr virNWFilterCreateVarHashmap(const char *macaddr, const virNWFilterVarValue *value); =20 int virNWFilterDomainFWUpdateCB(virDomainObjPtr vm, --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Nov 28 08:28:40 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 1524843102332706.8693487035687; Fri, 27 Apr 2018 08:31:42 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C29385F7AF; Fri, 27 Apr 2018 15:31:40 +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 8C67C16D2F; Fri, 27 Apr 2018 15:31:40 +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 EC03D180596F; Fri, 27 Apr 2018 15:31: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 w3RFPMUT032290 for ; Fri, 27 Apr 2018 11:25:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id CD17DAB3EF; Fri, 27 Apr 2018 15:25:22 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 42D8883B77; Fri, 27 Apr 2018 15:25:22 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 27 Apr 2018 16:25:06 +0100 Message-Id: <20180427152513.28928-8-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 07/14] nwfilter: introduce virNWFilterBinding to decouple from virDomainNet 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 27 Apr 2018 15:31:41 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 The virDomainNet struct contains everything related to configuring a guest network device. Out of all of this info, only 5 fields are relevant to configuring network filters. It will be more convenient for future changes to the nwfilter driver if the relevant fields are kept in a dedicated struct. Thus the virNWFilterBinding struct is created to track this information. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Jiri Denemark --- src/conf/nwfilter_conf.c | 53 ++++++++++++++++++++++++++++++++++++++++++++= +++- src/conf/nwfilter_conf.h | 18 +++++++++++++++- src/libvirt_private.syms | 2 ++ 3 files changed, 71 insertions(+), 2 deletions(-) diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index 5d04f2a93c..3d2ae9d0f3 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -2,7 +2,7 @@ * nwfilter_conf.c: network filter XML processing * (derived from storage_conf.c) * - * Copyright (C) 2006-2014 Red Hat, Inc. + * Copyright (C) 2006-2018 Red Hat, Inc. * Copyright (C) 2006-2008 Daniel P. Berrange * * Copyright (C) 2010-2011 IBM Corporation @@ -3265,3 +3265,54 @@ virNWFilterRuleIsProtocolEthernet(virNWFilterRuleDef= Ptr rule) return true; return false; } + +void virNWFilterBindingFree(virNWFilterBindingPtr binding) +{ + if (!binding) + return; + + VIR_FREE(binding->ownername); + VIR_FREE(binding->portdevname); + VIR_FREE(binding->linkdevname); + VIR_FREE(binding->filter); + virHashFree(binding->filterparams); + + VIR_FREE(binding); +} + +virNWFilterBindingPtr virNWFilterBindingCopy(virNWFilterBindingPtr src) +{ + virNWFilterBindingPtr ret; + + if (VIR_ALLOC(ret) < 0) + return NULL; + + if (VIR_STRDUP(ret->ownername, src->ownername) < 0) + goto error; + + memcpy(ret->owneruuid, src->owneruuid, sizeof(ret->owneruuid)); + + if (VIR_STRDUP(ret->portdevname, src->portdevname) < 0) + goto error; + + if (src->linkdevname && + VIR_STRDUP(ret->linkdevname, src->linkdevname) < 0) + goto error; + + ret->mac =3D src->mac; + + if (VIR_STRDUP(ret->filter, src->filter) < 0) + goto error; + + if (!(ret->filterparams =3D virNWFilterHashTableCreate(0))) + goto error; + + if (virNWFilterHashTablePutAll(src->filterparams, ret->filterparams) <= 0) + goto error; + + return ret; + + error: + virNWFilterBindingFree(ret); + return NULL; +} diff --git a/src/conf/nwfilter_conf.h b/src/conf/nwfilter_conf.h index a31db6d3ff..8c5421ee62 100644 --- a/src/conf/nwfilter_conf.h +++ b/src/conf/nwfilter_conf.h @@ -2,7 +2,7 @@ * nwfilter_conf.h: network filter XML processing * (derived from storage_conf.h) * - * Copyright (C) 2006-2010, 2012-2014 Red Hat, Inc. + * Copyright (C) 2006-2010, 2012-2018 Red Hat, Inc. * Copyright (C) 2006-2008 Daniel P. Berrange * * Copyright (C) 2010 IBM Corporation @@ -545,6 +545,19 @@ struct _virNWFilterDef { virNWFilterEntryPtr *filterEntries; }; =20 +typedef struct virNWFilterBinding virNWFilterBinding; +typedef virNWFilterBinding *virNWFilterBindingPtr; + +struct virNWFilterBinding { + char *ownername; + unsigned char owneruuid[VIR_UUID_BUFLEN]; + char *portdevname; + char *linkdevname; + virMacAddr mac; + char *filter; + virHashTablePtr filterparams; +}; + =20 typedef enum { STEP_APPLY_NEW, @@ -650,6 +663,9 @@ virNWFilterRuleIsProtocolIPv6(virNWFilterRuleDefPtr rul= e); bool virNWFilterRuleIsProtocolEthernet(virNWFilterRuleDefPtr rule); =20 +void virNWFilterBindingFree(virNWFilterBindingPtr binding); +virNWFilterBindingPtr virNWFilterBindingCopy(virNWFilterBindingPtr src); + VIR_ENUM_DECL(virNWFilterRuleAction); VIR_ENUM_DECL(virNWFilterRuleDirection); VIR_ENUM_DECL(virNWFilterRuleProtocol); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index bf17d17777..9fc0aa470d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -780,6 +780,8 @@ virDomainNumatuneSpecifiedMaxNode; =20 =20 # conf/nwfilter_conf.h +virNWFilterBindingCopy; +virNWFilterBindingFree; virNWFilterCallbackDriversLock; virNWFilterCallbackDriversUnlock; virNWFilterChainSuffixTypeToString; --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Nov 28 08:28:40 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 1524843391013721.1207442247231; Fri, 27 Apr 2018 08:36:31 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8EC5E300440C; Fri, 27 Apr 2018 15:36:28 +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 34CEB314EE64; Fri, 27 Apr 2018 15:36:28 +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 71F12180BAD4; Fri, 27 Apr 2018 15:36:27 +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 w3RFPOri032298 for ; Fri, 27 Apr 2018 11:25:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id ED887AB3EF; Fri, 27 Apr 2018 15:25:23 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 33E5583B76; Fri, 27 Apr 2018 15:25:23 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 27 Apr 2018 16:25:07 +0100 Message-Id: <20180427152513.28928-9-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 08/14] nwfilter: pass vm name in when instantiating filters 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.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Fri, 27 Apr 2018 15:36:30 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 The vm name is not needed for any functional requirement, but it will be useful when debugging problems to identify which VM is associated with a filter, since UUID is not human friendly. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Jiri Denemark --- src/conf/domain_nwfilter.c | 5 +++-- src/conf/domain_nwfilter.h | 6 ++++-- src/lxc/lxc_process.c | 2 +- src/nwfilter/nwfilter_driver.c | 3 ++- src/qemu/qemu_hotplug.c | 6 ++++-- src/qemu/qemu_interface.c | 4 ++-- src/qemu/qemu_process.c | 2 +- src/uml/uml_conf.c | 2 +- 8 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/conf/domain_nwfilter.c b/src/conf/domain_nwfilter.c index 176e7e6734..e360aceeba 100644 --- a/src/conf/domain_nwfilter.c +++ b/src/conf/domain_nwfilter.c @@ -38,11 +38,12 @@ virDomainConfNWFilterRegister(virDomainConfNWFilterDriv= erPtr driver) } =20 int -virDomainConfNWFilterInstantiate(const unsigned char *vmuuid, +virDomainConfNWFilterInstantiate(const char *vmname, + const unsigned char *vmuuid, virDomainNetDefPtr net) { if (nwfilterDriver !=3D NULL) - return nwfilterDriver->instantiateFilter(vmuuid, net); + return nwfilterDriver->instantiateFilter(vmname, vmuuid, net); /* driver module not available -- don't indicate failure */ return 0; } diff --git a/src/conf/domain_nwfilter.h b/src/conf/domain_nwfilter.h index af047c745a..857cac6c2a 100644 --- a/src/conf/domain_nwfilter.h +++ b/src/conf/domain_nwfilter.h @@ -23,7 +23,8 @@ #ifndef DOMAIN_NWFILTER_H # define DOMAIN_NWFILTER_H =20 -typedef int (*virDomainConfInstantiateNWFilter)(const unsigned char *vmuui= d, +typedef int (*virDomainConfInstantiateNWFilter)(const char *vmname, + const unsigned char *vmuui= d, virDomainNetDefPtr net); typedef void (*virDomainConfTeardownNWFilter)(virDomainNetDefPtr net); =20 @@ -35,7 +36,8 @@ typedef virDomainConfNWFilterDriver *virDomainConfNWFilte= rDriverPtr; =20 void virDomainConfNWFilterRegister(virDomainConfNWFilterDriverPtr driver); =20 -int virDomainConfNWFilterInstantiate(const unsigned char *vmuuid, +int virDomainConfNWFilterInstantiate(const char *vmname, + const unsigned char *vmuuid, virDomainNetDefPtr net); void virDomainConfNWFilterTeardown(virDomainNetDefPtr net); void virDomainConfVMNWFilterTeardown(virDomainObjPtr vm); diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index e911d88b56..3610523c06 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -304,7 +304,7 @@ virLXCProcessSetupInterfaceTap(virDomainDefPtr vm, } =20 if (net->filter && - virDomainConfNWFilterInstantiate(vm->uuid, net) < 0) + virDomainConfNWFilterInstantiate(vm->name, vm->uuid, net) < 0) goto cleanup; =20 ret =3D containerVeth; diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index fef3aa272b..d17a8ec00b 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -642,7 +642,8 @@ nwfilterGetXMLDesc(virNWFilterPtr nwfilter, =20 =20 static int -nwfilterInstantiateFilter(const unsigned char *vmuuid, +nwfilterInstantiateFilter(const char *vmname ATTRIBUTE_UNUSED, + const unsigned char *vmuuid, virDomainNetDefPtr net) { return virNWFilterInstantiateFilter(driver, vmuuid, net); diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index df9e8aa716..3bb0c72257 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -3016,7 +3016,8 @@ qemuDomainChangeNetFilter(virDomainObjPtr vm, virDomainConfNWFilterTeardown(olddev); =20 if (newdev->filter && - virDomainConfNWFilterInstantiate(vm->def->uuid, newdev) < 0) { + virDomainConfNWFilterInstantiate(vm->def->name, + vm->def->uuid, newdev) < 0) { virErrorPtr errobj; =20 virReportError(VIR_ERR_OPERATION_FAILED, @@ -3024,7 +3025,8 @@ qemuDomainChangeNetFilter(virDomainObjPtr vm, "- attempting to restore old rules"), olddev->ifname); virErrorPreserveLast(&errobj); - ignore_value(virDomainConfNWFilterInstantiate(vm->def->uuid, oldde= v)); + ignore_value(virDomainConfNWFilterInstantiate(vm->def->name, + vm->def->uuid, oldde= v)); virErrorRestore(&errobj); return -1; } diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c index ffa4b875c0..5d54a85c53 100644 --- a/src/qemu/qemu_interface.c +++ b/src/qemu/qemu_interface.c @@ -467,7 +467,7 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def, goto cleanup; =20 if (net->filter && - virDomainConfNWFilterInstantiate(def->uuid, net) < 0) { + virDomainConfNWFilterInstantiate(def->name, def->uuid, net) < 0) { goto cleanup; } =20 @@ -586,7 +586,7 @@ qemuInterfaceBridgeConnect(virDomainDefPtr def, goto cleanup; =20 if (net->filter && - virDomainConfNWFilterInstantiate(def->uuid, net) < 0) { + virDomainConfNWFilterInstantiate(def->name, def->uuid, net) < 0) { goto cleanup; } =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 6a5262ae46..9233d26948 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2952,7 +2952,7 @@ qemuProcessFiltersInstantiate(virDomainDefPtr def) for (i =3D 0; i < def->nnets; i++) { virDomainNetDefPtr net =3D def->nets[i]; if ((net->filter) && (net->ifname)) { - if (virDomainConfNWFilterInstantiate(def->uuid, net) < 0) + if (virDomainConfNWFilterInstantiate(def->name, def->uuid, net= ) < 0) return 1; } } diff --git a/src/uml/uml_conf.c b/src/uml/uml_conf.c index 49589b33c9..9c548f0e80 100644 --- a/src/uml/uml_conf.c +++ b/src/uml/uml_conf.c @@ -137,7 +137,7 @@ umlConnectTapDevice(virDomainDefPtr vm, } =20 if (net->filter) { - if (virDomainConfNWFilterInstantiate(vm->uuid, net) < 0) { + if (virDomainConfNWFilterInstantiate(vm->name, vm->uuid, net) < 0)= { if (template_ifname) VIR_FREE(net->ifname); goto error; --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Nov 28 08:28:40 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 1524843112065132.09674956266986; Fri, 27 Apr 2018 08:31:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ADD221764E1; Fri, 27 Apr 2018 15:31:49 +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 2BE811C06A; Fri, 27 Apr 2018 15:31:49 +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 C26A94CA9F; Fri, 27 Apr 2018 15:31:48 +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 w3RFPPir032304 for ; Fri, 27 Apr 2018 11:25:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id E21BDAB3EF; Fri, 27 Apr 2018 15:25:24 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4B69C83B71; Fri, 27 Apr 2018 15:25:24 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 27 Apr 2018 16:25:08 +0100 Message-Id: <20180427152513.28928-10-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 09/14] nwfilter: convert the gentech driver code to use virNWFilterBinding 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.84 on 10.5.11.27 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:31:51 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Use the virNWFilterBinding struct in the gentech driver code directly. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/nwfilter/nwfilter_dhcpsnoop.c | 35 +++--- src/nwfilter/nwfilter_driver.c | 21 +++- src/nwfilter/nwfilter_gentech_driver.c | 211 +++++++++++++++++------------= ---- src/nwfilter/nwfilter_gentech_driver.h | 22 ++-- src/nwfilter/nwfilter_learnipaddr.c | 16 +-- 5 files changed, 168 insertions(+), 137 deletions(-) diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcp= snoop.c index aec68ab847..dc4e3cb834 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -486,15 +486,18 @@ virNWFilterSnoopIPLeaseInstallRule(virNWFilterSnoopIP= LeasePtr ipl, =20 /* instantiate the filters */ =20 - if (req->ifname) + if (req->ifname) { + virNWFilterBinding binding =3D { + .portdevname =3D req->ifname, + .linkdevname =3D req->linkdev, + .mac =3D req->macaddr, + .filter =3D req->filtername, + .filterparams =3D req->vars, + }; rc =3D virNWFilterInstantiateFilterLate(req->driver, - NULL, - req->ifname, - req->ifindex, - req->linkdev, - &req->macaddr, - req->filtername, - req->vars); + &binding, + req->ifindex); + } =20 exit_snooprequnlock: virNWFilterSnoopReqUnlock(req); @@ -873,14 +876,16 @@ virNWFilterSnoopReqLeaseDel(virNWFilterSnoopReqPtr re= q, goto skip_instantiate; =20 if (ipAddrLeft) { + virNWFilterBinding binding =3D { + .portdevname =3D req->ifname, + .linkdevname =3D req->linkdev, + .mac =3D req->macaddr, + .filter =3D req->filtername, + .filterparams =3D req->vars, + }; ret =3D virNWFilterInstantiateFilterLate(req->driver, - NULL, - req->ifname, - req->ifindex, - req->linkdev, - &req->macaddr, - req->filtername, - req->vars); + &binding, + req->ifindex); } else { virNWFilterVarValuePtr dhcpsrvrs =3D virHashLookup(req->vars, NWFILTER_VARNAME_DHCPSERVER); diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index d17a8ec00b..a375e9bda8 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -642,19 +642,34 @@ nwfilterGetXMLDesc(virNWFilterPtr nwfilter, =20 =20 static int -nwfilterInstantiateFilter(const char *vmname ATTRIBUTE_UNUSED, +nwfilterInstantiateFilter(const char *vmname, const unsigned char *vmuuid, virDomainNetDefPtr net) { - return virNWFilterInstantiateFilter(driver, vmuuid, net); + virNWFilterBindingPtr binding; + int ret; + + if (!(binding =3D virNWFilterBindingForNet(vmname, vmuuid, net))) + return -1; + ret =3D virNWFilterInstantiateFilter(driver, binding); + virNWFilterBindingFree(binding); + return ret; } =20 =20 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(net); + virNWFilterTeardownFilter(&binding); } =20 =20 diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter= _gentech_driver.c index af4411d4db..c755350586 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -577,12 +577,9 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr f= ilter, =20 /** * virNWFilterDoInstantiate: - * @vmuuid: The UUID of the VM * @techdriver: The driver to use for instantiation + * @binding: description of port to bind the filter to * @filter: The filter to instantiate - * @ifname: The name of the interface to apply the rules to - * @vars: A map holding variable names and values used for instantiating - * the filter and its subfilters. * @forceWithPendingReq: Ignore the check whether a pending learn request * is active; 'true' only when the rules are applied late * @@ -596,17 +593,13 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr = filter, * Call this function while holding the NWFilter filter update lock */ static int -virNWFilterDoInstantiate(const unsigned char *vmuuid, - virNWFilterTechDriverPtr techdriver, +virNWFilterDoInstantiate(virNWFilterTechDriverPtr techdriver, + virNWFilterBindingPtr binding, virNWFilterDefPtr filter, - const char *ifname, int ifindex, - const char *linkdev, - virHashTablePtr vars, enum instCase useNewFilter, bool *foundNewFilter, bool teardownOld, - const virMacAddr *macaddr, virNWFilterDriverStatePtr driver, bool forceWithPendingReq) { @@ -628,14 +621,14 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid, } =20 rc =3D virNWFilterDetermineMissingVarsRec(filter, - vars, + binding->filterparams, missing_vars, useNewFilter, driver); if (rc < 0) goto err_exit; =20 - lv =3D virHashLookup(vars, NWFILTER_VARNAME_CTRL_IP_LEARNING); + lv =3D virHashLookup(binding->filterparams, NWFILTER_VARNAME_CTRL_IP_L= EARNING); if (lv) learning =3D virNWFilterVarValueGetNthValue(lv, 0); else @@ -652,19 +645,20 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid, goto err_unresolvable_vars; } if (STRCASEEQ(learning, "dhcp")) { - rc =3D virNWFilterDHCPSnoopReq(techdriver, ifname, linkdev, - vmuuid, macaddr, - filter->name, vars, driver); + rc =3D virNWFilterDHCPSnoopReq(techdriver, binding->portde= vname, + binding->linkdevname, + binding->owneruuid, &binding-= >mac, + filter->name, binding->filter= params, driver); goto err_exit; } else if (STRCASEEQ(learning, "any")) { if (!virNWFilterHasLearnReq(ifindex)) { rc =3D virNWFilterLearnIPAddress(techdriver, - ifname, + binding->portdevname, ifindex, - linkdev, - macaddr, + binding->linkdevname, + &binding->mac, filter->name, - vars, driver, + binding->filterparams, = driver, DETECT_DHCP|DETECT_STAT= IC); } goto err_exit; @@ -688,7 +682,7 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid, =20 rc =3D virNWFilterDefToInst(driver, filter, - vars, + binding->filterparams, useNewFilter, foundNewFilter, &inst); =20 @@ -705,22 +699,22 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid, } =20 if (instantiate) { - if (virNWFilterLockIface(ifname) < 0) + if (virNWFilterLockIface(binding->portdevname) < 0) goto err_exit; =20 - rc =3D techdriver->applyNewRules(ifname, inst.rules, inst.nrules); + rc =3D techdriver->applyNewRules(binding->portdevname, inst.rules,= inst.nrules); =20 if (teardownOld && rc =3D=3D 0) - techdriver->tearOldRules(ifname); + techdriver->tearOldRules(binding->portdevname); =20 - if (rc =3D=3D 0 && (virNetDevValidateConfig(ifname, NULL, ifindex)= <=3D 0)) { + if (rc =3D=3D 0 && (virNetDevValidateConfig(binding->portdevname, = NULL, ifindex) <=3D 0)) { virResetLastError(); /* interface changed/disppeared */ - techdriver->allTeardown(ifname); + techdriver->allTeardown(binding->portdevname); rc =3D -1; } =20 - virNWFilterUnlockIface(ifname); + virNWFilterUnlockIface(binding->portdevname); } =20 err_exit: @@ -749,14 +743,9 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid, */ static int virNWFilterInstantiateFilterUpdate(virNWFilterDriverStatePtr driver, - const unsigned char *vmuuid, bool teardownOld, - const char *ifname, + virNWFilterBindingPtr binding, int ifindex, - const char *linkdev, - const virMacAddr *macaddr, - const char *filtername, - virHashTablePtr filterparams, enum instCase useNewFilter, bool forceWithPendingReq, bool *foundNewFilter) @@ -765,7 +754,6 @@ virNWFilterInstantiateFilterUpdate(virNWFilterDriverSta= tePtr driver, const char *drvname =3D EBIPTABLES_DRIVER_ID; virNWFilterTechDriverPtr techdriver; virNWFilterObjPtr obj; - virHashTablePtr vars, vars1; virNWFilterDefPtr filter; virNWFilterDefPtr newFilter; char vmmacaddr[VIR_MAC_STRING_BUFLEN] =3D {0}; @@ -781,29 +769,22 @@ virNWFilterInstantiateFilterUpdate(virNWFilterDriverS= tatePtr driver, return -1; } =20 - VIR_DEBUG("filter name: %s", filtername); + VIR_DEBUG("filter name: %s", binding->filter); =20 if (!(obj =3D virNWFilterObjListFindInstantiateFilter(driver->nwfilter= s, - filtername))) + binding->filter))) return -1; =20 - virMacAddrFormat(macaddr, vmmacaddr); + virMacAddrFormat(&binding->mac, vmmacaddr); =20 - ipaddr =3D virNWFilterIPAddrMapGetIPAddr(ifname); + ipaddr =3D virNWFilterIPAddrMapGetIPAddr(binding->portdevname); =20 - vars1 =3D virNWFilterCreateVarHashmap(vmmacaddr, ipaddr); - if (!vars1) { + if (virNWFilterVarHashmapAddStdValues(binding->filterparams, + vmmacaddr, ipaddr) < 0) { rc =3D -1; goto err_exit; } =20 - vars =3D virNWFilterCreateVarsFrom(vars1, - filterparams); - if (!vars) { - rc =3D -1; - goto err_exit_vars1; - } - filter =3D virNWFilterObjGetDef(obj); =20 switch (useNewFilter) { @@ -819,17 +800,11 @@ virNWFilterInstantiateFilterUpdate(virNWFilterDriverS= tatePtr driver, break; } =20 - rc =3D virNWFilterDoInstantiate(vmuuid, techdriver, filter, - ifname, ifindex, linkdev, - vars, useNewFilter, foundNewFilter, - teardownOld, macaddr, driver, + rc =3D virNWFilterDoInstantiate(techdriver, binding, filter, + ifindex, useNewFilter, foundNewFilter, + teardownOld, driver, forceWithPendingReq); =20 - virHashFree(vars); - - err_exit_vars1: - virHashFree(vars1); - err_exit: virNWFilterObjUnlock(obj); =20 @@ -839,15 +814,11 @@ virNWFilterInstantiateFilterUpdate(virNWFilterDriverS= tatePtr driver, =20 static int virNWFilterInstantiateFilterInternal(virNWFilterDriverStatePtr driver, - const unsigned char *vmuuid, - const virDomainNetDef *net, + virNWFilterBindingPtr binding, bool teardownOld, enum instCase useNewFilter, bool *foundNewFilter) { - const char *linkdev =3D (net->type =3D=3D VIR_DOMAIN_NET_TYPE_DIRECT) - ? net->data.direct.linkdev - : NULL; int ifindex; int rc; =20 @@ -856,8 +827,8 @@ virNWFilterInstantiateFilterInternal(virNWFilterDriverS= tatePtr driver, /* after grabbing the filter update lock check for the interface; if it's not there anymore its filters will be or are being removed (while holding the lock) and we don't want to build new ones */ - if (virNetDevExists(net->ifname) !=3D 1 || - virNetDevGetIndex(net->ifname, &ifindex) < 0) { + if (virNetDevExists(binding->portdevname) !=3D 1 || + virNetDevGetIndex(binding->portdevname, &ifindex) < 0) { /* interfaces / VMs can disappear during filter instantiation; don't mark it as an error */ virResetLastError(); @@ -865,10 +836,10 @@ virNWFilterInstantiateFilterInternal(virNWFilterDrive= rStatePtr driver, goto cleanup; } =20 - rc =3D virNWFilterInstantiateFilterUpdate(driver, vmuuid, teardownOld, - net->ifname, ifindex, linkdev, - &net->mac, net->filter, - net->filterparams, useNewFilte= r, + rc =3D virNWFilterInstantiateFilterUpdate(driver, teardownOld, + binding, + ifindex, + useNewFilter, false, foundNewFilter); =20 cleanup: @@ -880,13 +851,8 @@ virNWFilterInstantiateFilterInternal(virNWFilterDriver= StatePtr driver, =20 int virNWFilterInstantiateFilterLate(virNWFilterDriverStatePtr driver, - const unsigned char *vmuuid, - const char *ifname, - int ifindex, - const char *linkdev, - const virMacAddr *macaddr, - const char *filtername, - virHashTablePtr filterparams) + virNWFilterBindingPtr binding, + int ifindex) { int rc; bool foundNewFilter =3D false; @@ -894,18 +860,17 @@ virNWFilterInstantiateFilterLate(virNWFilterDriverSta= tePtr driver, virNWFilterReadLockFilterUpdates(); virMutexLock(&updateMutex); =20 - rc =3D virNWFilterInstantiateFilterUpdate(driver, vmuuid, true, - ifname, ifindex, linkdev, - macaddr, filtername, filterpar= ams, + rc =3D virNWFilterInstantiateFilterUpdate(driver, true, + binding, ifindex, INSTANTIATE_ALWAYS, true, &foundNewFilter); if (rc < 0) { /* something went wrong... 'DOWN' the interface */ - if ((virNetDevValidateConfig(ifname, NULL, ifindex) <=3D 0) || - (virNetDevSetOnline(ifname, false) < 0)) { + if ((virNetDevValidateConfig(binding->portdevname, NULL, ifindex) = <=3D 0) || + (virNetDevSetOnline(binding->portdevname, false) < 0)) { virResetLastError(); /* assuming interface disappeared... */ - _virNWFilterTeardownFilter(ifname); + _virNWFilterTeardownFilter(binding->portdevname); } } =20 @@ -918,12 +883,11 @@ virNWFilterInstantiateFilterLate(virNWFilterDriverSta= tePtr driver, =20 int virNWFilterInstantiateFilter(virNWFilterDriverStatePtr driver, - const unsigned char *vmuuid, - const virDomainNetDef *net) + virNWFilterBindingPtr binding) { bool foundNewFilter =3D false; =20 - return virNWFilterInstantiateFilterInternal(driver, vmuuid, net, + return virNWFilterInstantiateFilterInternal(driver, binding, 1, INSTANTIATE_ALWAYS, &foundNewFilter); @@ -932,13 +896,12 @@ virNWFilterInstantiateFilter(virNWFilterDriverStatePt= r driver, =20 int virNWFilterUpdateInstantiateFilter(virNWFilterDriverStatePtr driver, - const unsigned char *vmuuid, - const virDomainNetDef *net, + virNWFilterBindingPtr binding, bool *skipIface) { bool foundNewFilter =3D false; =20 - int rc =3D virNWFilterInstantiateFilterInternal(driver, vmuuid, net, + int rc =3D virNWFilterInstantiateFilterInternal(driver, binding, 0, INSTANTIATE_FOLLOW_NEWFI= LTER, &foundNewFilter); @@ -948,7 +911,7 @@ virNWFilterUpdateInstantiateFilter(virNWFilterDriverSta= tePtr driver, } =20 static int -virNWFilterRollbackUpdateFilter(const virDomainNetDef *net) +virNWFilterRollbackUpdateFilter(virNWFilterBindingPtr binding) { const char *drvname =3D EBIPTABLES_DRIVER_ID; int ifindex; @@ -964,17 +927,17 @@ virNWFilterRollbackUpdateFilter(const virDomainNetDef= *net) } =20 /* don't tear anything while the address is being learned */ - if (virNetDevGetIndex(net->ifname, &ifindex) < 0) + if (virNetDevGetIndex(binding->portdevname, &ifindex) < 0) virResetLastError(); else if (virNWFilterHasLearnReq(ifindex)) return 0; =20 - return techdriver->tearNewRules(net->ifname); + return techdriver->tearNewRules(binding->portdevname); } =20 =20 static int -virNWFilterTearOldFilter(virDomainNetDefPtr net) +virNWFilterTearOldFilter(virNWFilterBindingPtr binding) { const char *drvname =3D EBIPTABLES_DRIVER_ID; int ifindex; @@ -990,12 +953,12 @@ virNWFilterTearOldFilter(virDomainNetDefPtr net) } =20 /* don't tear anything while the address is being learned */ - if (virNetDevGetIndex(net->ifname, &ifindex) < 0) + if (virNetDevGetIndex(binding->portdevname, &ifindex) < 0) virResetLastError(); else if (virNWFilterHasLearnReq(ifindex)) return 0; =20 - return techdriver->tearOldRules(net->ifname); + return techdriver->tearOldRules(binding->portdevname); } =20 =20 @@ -1032,11 +995,11 @@ _virNWFilterTeardownFilter(const char *ifname) =20 =20 int -virNWFilterTeardownFilter(const virDomainNetDef *net) +virNWFilterTeardownFilter(virNWFilterBindingPtr binding) { int ret; virMutexLock(&updateMutex); - ret =3D _virNWFilterTeardownFilter(net->ifname); + ret =3D _virNWFilterTeardownFilter(binding->portdevname); virMutexUnlock(&updateMutex); return ret; } @@ -1057,12 +1020,21 @@ virNWFilterDomainFWUpdateCB(virDomainObjPtr obj, if (virDomainObjIsActive(obj)) { for (i =3D 0; i < vm->nnets; i++) { virDomainNetDefPtr net =3D vm->nets[i]; + virNWFilterBinding binding =3D { + .ownername =3D vm->name, + .portdevname =3D net->ifname, + .linkdevname =3D (net->type =3D=3D VIR_DOMAIN_NET_TYPE_DIR= ECT ? + net->data.direct.linkdev : NULL), + .mac =3D net->mac, + .filter =3D net->filter, + .filterparams =3D net->filterparams, + }; + memcpy(binding.owneruuid, vm->uuid, sizeof(binding.owneruuid)); if ((net->filter) && (net->ifname)) { switch (cb->step) { case STEP_APPLY_NEW: ret =3D virNWFilterUpdateInstantiateFilter(cb->opaque, - vm->uuid, - net, + &binding, &skipIface); if (ret =3D=3D 0 && skipIface) { /* filter tree unchanged -- no update needed */ @@ -1074,18 +1046,17 @@ virNWFilterDomainFWUpdateCB(virDomainObjPtr obj, =20 case STEP_TEAR_NEW: if (!virHashLookup(cb->skipInterfaces, net->ifname)) - ret =3D virNWFilterRollbackUpdateFilter(net); + ret =3D virNWFilterRollbackUpdateFilter(&binding); break; =20 case STEP_TEAR_OLD: if (!virHashLookup(cb->skipInterfaces, net->ifname)) - ret =3D virNWFilterTearOldFilter(net); + ret =3D virNWFilterTearOldFilter(&binding); break; =20 case STEP_APPLY_CURRENT: ret =3D virNWFilterInstantiateFilter(cb->opaque, - vm->uuid, - net); + &binding); if (ret) virReportError(VIR_ERR_INTERNAL_ERROR, _("Failure while applying current f= ilter on " @@ -1101,3 +1072,45 @@ virNWFilterDomainFWUpdateCB(virDomainObjPtr obj, virObjectUnlock(obj); return ret; } + + +virNWFilterBindingPtr virNWFilterBindingForNet(const char *vmname, + const unsigned char *vmuuid, + virDomainNetDefPtr net) +{ + virNWFilterBindingPtr ret; + + if (VIR_ALLOC(ret) < 0) + return NULL; + + if (VIR_STRDUP(ret->ownername, vmname) < 0) + goto error; + + memcpy(ret->owneruuid, vmuuid, sizeof(ret->owneruuid)); + + if (VIR_STRDUP(ret->portdevname, net->ifname) < 0) + goto error; + + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_DIRECT && + net->data.direct.linkdev && + VIR_STRDUP(ret->linkdevname, net->data.direct.linkdev) < 0) + goto error; + + ret->mac =3D net->mac; + + if (VIR_STRDUP(ret->filter, net->filter) < 0) + goto error; + + if (!(ret->filterparams =3D virNWFilterHashTableCreate(0))) + goto error; + + if (net->filterparams && + virNWFilterHashTablePutAll(net->filterparams, ret->filterparams) <= 0) + goto error; + + return ret; + + error: + virNWFilterBindingFree(ret); + return NULL; +} diff --git a/src/nwfilter/nwfilter_gentech_driver.h b/src/nwfilter/nwfilter= _gentech_driver.h index 86cc677e79..0d846dc92f 100644 --- a/src/nwfilter/nwfilter_gentech_driver.h +++ b/src/nwfilter/nwfilter_gentech_driver.h @@ -37,25 +37,17 @@ enum instCase { INSTANTIATE_FOLLOW_NEWFILTER, }; =20 - int virNWFilterInstantiateFilter(virNWFilterDriverStatePtr driver, - const unsigned char *vmuuid, - const virDomainNetDef *net); + virNWFilterBindingPtr binding); int virNWFilterUpdateInstantiateFilter(virNWFilterDriverStatePtr driver, - const unsigned char *vmuuid, - const virDomainNetDef *net, + virNWFilterBindingPtr binding, bool *skipIface); =20 int virNWFilterInstantiateFilterLate(virNWFilterDriverStatePtr driver, - const unsigned char *vmuuid, - const char *ifname, - int ifindex, - const char *linkdev, - const virMacAddr *macaddr, - const char *filtername, - virHashTablePtr filterparams); + virNWFilterBindingPtr binding, + int ifindex); =20 -int virNWFilterTeardownFilter(const virDomainNetDef *net); +int virNWFilterTeardownFilter(virNWFilterBindingPtr binding); =20 virHashTablePtr virNWFilterCreateVarHashmap(const char *macaddr, const virNWFilterVarValue *value); @@ -63,4 +55,8 @@ virHashTablePtr virNWFilterCreateVarHashmap(const char *m= acaddr, int virNWFilterDomainFWUpdateCB(virDomainObjPtr vm, void *data); =20 +virNWFilterBindingPtr virNWFilterBindingForNet(const char *vmname, + const unsigned char *vmuuid, + virDomainNetDefPtr net); + #endif diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_le= arnipaddr.c index cc3bfd971c..4b13370661 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -643,19 +643,21 @@ learnIPAddressThread(void *arg) virNWFilterUnlockIface(req->ifname); =20 if ((inetaddr =3D virSocketAddrFormat(&sa)) !=3D NULL) { + virNWFilterBinding binding =3D { + .portdevname =3D req->ifname, + .linkdevname =3D req->linkdev, + .mac =3D req->macaddr, + .filter =3D req->filtername, + .filterparams =3D req->filterparams, + }; if (virNWFilterIPAddrMapAddIPAddr(req->ifname, inetaddr) < 0) { VIR_ERROR(_("Failed to add IP address %s to IP address " "cache for interface %s"), inetaddr, req->ifname= ); } =20 ret =3D virNWFilterInstantiateFilterLate(req->driver, - NULL, - req->ifname, - req->ifindex, - req->linkdev, - &req->macaddr, - req->filtername, - req->filterparams); + &binding, + req->ifindex); VIR_DEBUG("Result from applying firewall rules on " "%s with IP addr %s : %d", req->ifname, inetaddr, re= t); VIR_FREE(inetaddr); --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Nov 28 08:28:40 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 1524843121288771.1721707611107; Fri, 27 Apr 2018 08:32:01 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2E3CB30FA042; Fri, 27 Apr 2018 15:31:58 +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 E3032314EE72; Fri, 27 Apr 2018 15:31:57 +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 77BD2180BAD5; Fri, 27 Apr 2018 15:31:57 +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 w3RFPPHR032314 for ; Fri, 27 Apr 2018 11:25:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id D196483B77; Fri, 27 Apr 2018 15:25:25 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3714F83B71; Fri, 27 Apr 2018 15:25:25 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 27 Apr 2018 16:25:09 +0100 Message-Id: <20180427152513.28928-11-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 10/14] nwfilter: convert IP address learning code to virNWFilterBinding 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.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 27 Apr 2018 15:32:00 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Use the virNWFilterBinding struct i nthe IP address learning code directly. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/nwfilter/nwfilter_gentech_driver.c | 7 +-- src/nwfilter/nwfilter_learnipaddr.c | 98 ++++++++++--------------------= ---- src/nwfilter/nwfilter_learnipaddr.h | 6 +-- 3 files changed, 30 insertions(+), 81 deletions(-) diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter= _gentech_driver.c index c755350586..514315f781 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -653,12 +653,9 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr tech= driver, } else if (STRCASEEQ(learning, "any")) { if (!virNWFilterHasLearnReq(ifindex)) { rc =3D virNWFilterLearnIPAddress(techdriver, - binding->portdevname, + binding, ifindex, - binding->linkdevname, - &binding->mac, - filter->name, - binding->filterparams, = driver, + driver, DETECT_DHCP|DETECT_STAT= IC); } goto err_exit; diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_le= arnipaddr.c index 4b13370661..0e76921648 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -137,12 +137,8 @@ typedef struct _virNWFilterIPAddrLearnReq virNWFilterI= PAddrLearnReq; typedef virNWFilterIPAddrLearnReq *virNWFilterIPAddrLearnReqPtr; struct _virNWFilterIPAddrLearnReq { virNWFilterTechDriverPtr techdriver; - char ifname[IF_NAMESIZE]; int ifindex; - char linkdev[IF_NAMESIZE]; - virMacAddr macaddr; - char *filtername; - virHashTablePtr filterparams; + virNWFilterBindingPtr binding; virNWFilterDriverStatePtr driver; enum howDetect howDetect; =20 @@ -232,8 +228,7 @@ virNWFilterIPAddrLearnReqFree(virNWFilterIPAddrLearnReq= Ptr req) if (!req) return; =20 - VIR_FREE(req->filtername); - virHashFree(req->filterparams); + virNWFilterBindingFree(req->binding); =20 VIR_FREE(req); } @@ -404,8 +399,9 @@ learnIPAddressThread(void *arg) virNWFilterIPAddrLearnReqPtr req =3D arg; uint32_t vmaddr =3D 0, bcastaddr =3D 0; unsigned int ethHdrSize; - char *listen_if =3D (strlen(req->linkdev) !=3D 0) ? req->linkdev - : req->ifname; + char *listen_if =3D (req->binding->linkdevname ? + req->binding->linkdevname : + req->binding->portdevname); int dhcp_opts_len; char macaddr[VIR_MAC_STRING_BUFLEN]; virBuffer buf =3D VIR_BUFFER_INITIALIZER; @@ -415,13 +411,13 @@ learnIPAddressThread(void *arg) enum howDetect howDetected =3D 0; virNWFilterTechDriverPtr techdriver =3D req->techdriver; =20 - if (virNWFilterLockIface(req->ifname) < 0) + if (virNWFilterLockIface(req->binding->portdevname) < 0) goto err_no_lock; =20 req->status =3D 0; =20 /* anything change to the VM's interface -- check at least once */ - if (virNetDevValidateConfig(req->ifname, NULL, req->ifindex) <=3D 0) { + if (virNetDevValidateConfig(req->binding->portdevname, NULL, req->ifin= dex) <=3D 0) { virResetLastError(); req->status =3D ENODEV; goto done; @@ -435,12 +431,12 @@ learnIPAddressThread(void *arg) goto done; } =20 - virMacAddrFormat(&req->macaddr, macaddr); + virMacAddrFormat(&req->binding->mac, macaddr); =20 switch (req->howDetect) { case DETECT_DHCP: - if (techdriver->applyDHCPOnlyRules(req->ifname, - &req->macaddr, + if (techdriver->applyDHCPOnlyRules(req->binding->portdevname, + &req->binding->mac, NULL, false) < 0) { req->status =3D EINVAL; goto done; @@ -448,8 +444,8 @@ learnIPAddressThread(void *arg) virBufferAddLit(&buf, "src port 67 and dst port 68"); break; case DETECT_STATIC: - if (techdriver->applyBasicRules(req->ifname, - &req->macaddr) < 0) { + if (techdriver->applyBasicRules(req->binding->portdevname, + &req->binding->mac) < 0) { req->status =3D EINVAL; goto done; } @@ -495,7 +491,7 @@ learnIPAddressThread(void *arg) } =20 /* check whether VM's dev is still there */ - if (virNetDevValidateConfig(req->ifname, NULL, req->ifindex) <= =3D 0) { + if (virNetDevValidateConfig(req->binding->portdevname, NULL, r= eq->ifindex) <=3D 0) { virResetLastError(); req->status =3D ENODEV; showError =3D false; @@ -527,7 +523,7 @@ learnIPAddressThread(void *arg) continue; } =20 - if (virMacAddrCmpRaw(&req->macaddr, ether_hdr->ether_shost) = =3D=3D 0) { + if (virMacAddrCmpRaw(&req->binding->mac, ether_hdr->ether_shos= t) =3D=3D 0) { /* packets from the VM */ =20 if (etherType =3D=3D ETHERTYPE_IP && @@ -566,7 +562,7 @@ learnIPAddressThread(void *arg) break; } } - } else if (virMacAddrCmpRaw(&req->macaddr, + } else if (virMacAddrCmpRaw(&req->binding->mac, ether_hdr->ether_dhost) =3D=3D 0 || /* allow Broadcast replies from DHCP server */ virMacAddrIsBroadcastRaw(ether_hdr->ether_dhost)) { @@ -596,7 +592,7 @@ learnIPAddressThread(void *arg) ((char *)udphdr + sizeof(udphdr)); if (dhcp->op =3D=3D 2 /* BOOTREPLY */ && virMacAddrCmpRaw( - &req->macaddr, + &req->binding->mac, &dhcp->chaddr[0]) =3D=3D 0) { dhcp_opts_len =3D header.len - (ethHdrSize + iphdr->ihl * 4 + @@ -640,26 +636,19 @@ learnIPAddressThread(void *arg) * Also it is safe to unlock interface here because we stopped * capturing and applied necessary rules on the interface, while * instantiating a new filter doesn't require a locked interface.*/ - virNWFilterUnlockIface(req->ifname); + virNWFilterUnlockIface(req->binding->portdevname); =20 if ((inetaddr =3D virSocketAddrFormat(&sa)) !=3D NULL) { - virNWFilterBinding binding =3D { - .portdevname =3D req->ifname, - .linkdevname =3D req->linkdev, - .mac =3D req->macaddr, - .filter =3D req->filtername, - .filterparams =3D req->filterparams, - }; - if (virNWFilterIPAddrMapAddIPAddr(req->ifname, inetaddr) < 0) { + if (virNWFilterIPAddrMapAddIPAddr(req->binding->portdevname, i= netaddr) < 0) { VIR_ERROR(_("Failed to add IP address %s to IP address " - "cache for interface %s"), inetaddr, req->ifname= ); + "cache for interface %s"), inetaddr, req->bindin= g->portdevname); } =20 ret =3D virNWFilterInstantiateFilterLate(req->driver, - &binding, + req->binding, req->ifindex); VIR_DEBUG("Result from applying firewall rules on " - "%s with IP addr %s : %d", req->ifname, inetaddr, re= t); + "%s with IP addr %s : %d", req->binding->portdevname= , inetaddr, ret); VIR_FREE(inetaddr); } } else { @@ -667,13 +656,13 @@ learnIPAddressThread(void *arg) virReportSystemError(req->status, _("encountered an error on interface %s " "index %d"), - req->ifname, req->ifindex); + req->binding->portdevname, req->ifindex); =20 - techdriver->applyDropAllRules(req->ifname); - virNWFilterUnlockIface(req->ifname); + techdriver->applyDropAllRules(req->binding->portdevname); + virNWFilterUnlockIface(req->binding->portdevname); } =20 - VIR_DEBUG("pcap thread terminating for interface %s", req->ifname); + VIR_DEBUG("pcap thread terminating for interface %s", req->binding->po= rtdevname); =20 =20 err_no_lock: @@ -706,19 +695,14 @@ learnIPAddressThread(void *arg) */ int virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver, - const char *ifname, + virNWFilterBindingPtr binding, int ifindex, - const char *linkdev, - const virMacAddr *macaddr, - const char *filtername, - virHashTablePtr filterparams, virNWFilterDriverStatePtr driver, enum howDetect howDetect) { int rc; virThread thread; virNWFilterIPAddrLearnReqPtr req =3D NULL; - virHashTablePtr ht =3D NULL; =20 if (howDetect =3D=3D 0) return -1; @@ -734,37 +718,11 @@ virNWFilterLearnIPAddress(virNWFilterTechDriverPtr te= chdriver, if (VIR_ALLOC(req) < 0) goto err_no_req; =20 - ht =3D virNWFilterHashTableCreate(0); - if (ht =3D=3D NULL) + if (!(req->binding =3D virNWFilterBindingCopy(binding))) goto err_free_req; =20 - if (virNWFilterHashTablePutAll(filterparams, ht) < 0) - goto err_free_ht; - - if (VIR_STRDUP(req->filtername, filtername) < 0) - goto err_free_ht; - - if (virStrcpyStatic(req->ifname, ifname) =3D=3D NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Destination buffer for ifname ('%s') " - "not large enough"), ifname); - goto err_free_ht; - } - - if (linkdev) { - if (virStrcpyStatic(req->linkdev, linkdev) =3D=3D NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Destination buffer for linkdev ('%s') " - "not large enough"), linkdev); - goto err_free_ht; - } - } - req->ifindex =3D ifindex; - virMacAddrSet(&req->macaddr, macaddr); req->driver =3D driver; - req->filterparams =3D ht; - ht =3D NULL; req->howDetect =3D howDetect; req->techdriver =3D techdriver; =20 @@ -783,8 +741,6 @@ virNWFilterLearnIPAddress(virNWFilterTechDriverPtr tech= driver, =20 err_dereg_req: virNWFilterDeregisterLearnReq(ifindex); - err_free_ht: - virHashFree(ht); err_free_req: virNWFilterIPAddrLearnReqFree(req); err_no_req: diff --git a/src/nwfilter/nwfilter_learnipaddr.h b/src/nwfilter/nwfilter_le= arnipaddr.h index 06fea5bff8..2646019ade 100644 --- a/src/nwfilter/nwfilter_learnipaddr.h +++ b/src/nwfilter/nwfilter_learnipaddr.h @@ -36,12 +36,8 @@ enum howDetect { }; =20 int virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver, - const char *ifname, + virNWFilterBindingPtr binding, int ifindex, - const char *linkdev, - const virMacAddr *macaddr, - const char *filtername, - virHashTablePtr filterparams, virNWFilterDriverStatePtr driver, enum howDetect howDetect); =20 --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Nov 28 08:28:40 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 15248431308421023.0124902684227; Fri, 27 Apr 2018 08:32:10 -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 5D05932D7446; Fri, 27 Apr 2018 15:32:07 +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 03FCD7E4D8; Fri, 27 Apr 2018 15:32:07 +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 2D3EF4CAA3; Fri, 27 Apr 2018 15:32:06 +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 w3RFPQFg032319 for ; Fri, 27 Apr 2018 11:25:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9368783B71; Fri, 27 Apr 2018 15:25:26 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 27BF7AB583; Fri, 27 Apr 2018 15:25:26 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 27 Apr 2018 16:25:10 +0100 Message-Id: <20180427152513.28928-12-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 11/14] nwfilter: convert DHCP address snooping code to virNWFilterBinding 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.40]); Fri, 27 Apr 2018 15:32:09 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Use the virNWFilterBinding struct in the DHCP address snooping code directly. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/nwfilter/nwfilter_dhcpsnoop.c | 150 +++++++++++++----------------= ---- src/nwfilter/nwfilter_dhcpsnoop.h | 7 +- src/nwfilter/nwfilter_gentech_driver.c | 7 +- 3 files changed, 61 insertions(+), 103 deletions(-) diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcp= snoop.c index dc4e3cb834..e67cea40ab 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -135,13 +135,9 @@ struct _virNWFilterSnoopReq { int refctr; =20 virNWFilterTechDriverPtr techdriver; - char *ifname; + virNWFilterBindingPtr binding; int ifindex; - char *linkdev; char ifkey[VIR_IFKEY_LEN]; - virMacAddr macaddr; - char *filtername; - virHashTablePtr vars; virNWFilterDriverStatePtr driver; /* start and end of lease list, ordered by lease time */ virNWFilterSnoopIPLeasePtr start; @@ -473,10 +469,10 @@ virNWFilterSnoopIPLeaseInstallRule(virNWFilterSnoopIP= LeasePtr ipl, =20 req =3D ipl->snoopReq; =20 - /* protect req->ifname */ + /* protect req->binding->portdevname */ virNWFilterSnoopReqLock(req); =20 - if (virNWFilterIPAddrMapAddIPAddr(req->ifname, ipaddr) < 0) + if (virNWFilterIPAddrMapAddIPAddr(req->binding->portdevname, ipaddr) <= 0) goto exit_snooprequnlock; =20 if (!instantiate) { @@ -486,16 +482,9 @@ virNWFilterSnoopIPLeaseInstallRule(virNWFilterSnoopIPL= easePtr ipl, =20 /* instantiate the filters */ =20 - if (req->ifname) { - virNWFilterBinding binding =3D { - .portdevname =3D req->ifname, - .linkdevname =3D req->linkdev, - .mac =3D req->macaddr, - .filter =3D req->filtername, - .filterparams =3D req->vars, - }; + if (req->binding->portdevname) { rc =3D virNWFilterInstantiateFilterLate(req->driver, - &binding, + req->binding, req->ifindex); } =20 @@ -636,10 +625,7 @@ virNWFilterSnoopReqFree(virNWFilterSnoopReqPtr req) virNWFilterSnoopReqLeaseDel(req, &ipl->ipAddress, false, false); =20 /* free all req data */ - VIR_FREE(req->ifname); - VIR_FREE(req->linkdev); - VIR_FREE(req->filtername); - virHashFree(req->vars); + virNWFilterBindingFree(req->binding); =20 virMutexDestroy(&req->lock); virCondDestroy(&req->threadStatusCond); @@ -870,28 +856,23 @@ virNWFilterSnoopReqLeaseDel(virNWFilterSnoopReqPtr re= q, if (update_leasefile) virNWFilterSnoopLeaseFileSave(ipl); =20 - ipAddrLeft =3D virNWFilterIPAddrMapDelIPAddr(req->ifname, ipstr); + ipAddrLeft =3D virNWFilterIPAddrMapDelIPAddr(req->binding->portdevname= , ipstr); =20 if (!req->threadkey || !instantiate) goto skip_instantiate; =20 if (ipAddrLeft) { - virNWFilterBinding binding =3D { - .portdevname =3D req->ifname, - .linkdevname =3D req->linkdev, - .mac =3D req->macaddr, - .filter =3D req->filtername, - .filterparams =3D req->vars, - }; ret =3D virNWFilterInstantiateFilterLate(req->driver, - &binding, + req->binding, req->ifindex); } else { virNWFilterVarValuePtr dhcpsrvrs =3D - virHashLookup(req->vars, NWFILTER_VARNAME_DHCPSERVER); + virHashLookup(req->binding->filterparams, + NWFILTER_VARNAME_DHCPSERVER); =20 if (req->techdriver && - req->techdriver->applyDHCPOnlyRules(req->ifname, &req->macaddr, + req->techdriver->applyDHCPOnlyRules(req->binding->portdevname, + &req->binding->mac, dhcpsrvrs, false) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("virNWFilterSnoopListDel failed")); @@ -1021,7 +1002,7 @@ virNWFilterSnoopDHCPDecode(virNWFilterSnoopReqPtr req, * inside the DHCP response */ if (!fromVM) { - if (virMacAddrCmpRaw(&req->macaddr, + if (virMacAddrCmpRaw(&req->binding->mac, (unsigned char *)&pd->d_chaddr) !=3D 0) return -2; } @@ -1178,7 +1159,7 @@ static void virNWFilterDHCPDecodeWorker(void *jobdata= , void *opaque) =20 virReportError(VIR_ERR_INTERNAL_ERROR, _("Instantiation of rules failed on " - "interface '%s'"), req->ifname); + "interface '%s'"), req->binding->portdevname); } virAtomicIntDecAndTest(job->qCtr); VIR_FREE(job); @@ -1387,13 +1368,14 @@ virNWFilterDHCPSnoopThread(void *req0) =20 /* whoever started us increased the reference counter for the req for = us */ =20 - /* protect req->ifname & req->threadkey */ + /* protect req->binding->portdevname & req->threadkey */ virNWFilterSnoopReqLock(req); =20 - if (req->ifname && req->threadkey) { + if (req->binding->portdevname && req->threadkey) { for (i =3D 0; i < ARRAY_CARDINALITY(pcapConf); i++) { pcapConf[i].handle =3D - virNWFilterSnoopDHCPOpen(req->ifname, &req->macaddr, + virNWFilterSnoopDHCPOpen(req->binding->portdevname, + &req->binding->mac, pcapConf[i].filter, pcapConf[i].dir); if (!pcapConf[i].handle) { @@ -1402,7 +1384,7 @@ virNWFilterDHCPSnoopThread(void *req0) } fds[i].fd =3D pcap_fileno(pcapConf[i].handle); } - tmp =3D virNetDevGetIndex(req->ifname, &ifindex); + tmp =3D virNetDevGetIndex(req->binding->portdevname, &ifindex); ignore_value(VIR_STRDUP(threadkey, req->threadkey)); worker =3D virThreadPoolNew(1, 1, 0, virNWFilterDHCPDecodeWorker, @@ -1467,11 +1449,11 @@ virNWFilterDHCPSnoopThread(void *req0) /* error reading from socket */ tmp =3D -1; =20 - /* protect req->ifname */ + /* protect req->binding->portdevname */ virNWFilterSnoopReqLock(req); =20 - if (req->ifname) - tmp =3D virNetDevValidateConfig(req->ifname, NULL, ifi= ndex); + if (req->binding->portdevname) + tmp =3D virNetDevValidateConfig(req->binding->portdevn= ame, NULL, ifindex); =20 virNWFilterSnoopReqUnlock(req); =20 @@ -1484,16 +1466,17 @@ virNWFilterDHCPSnoopThread(void *req0) pcap_close(pcapConf[i].handle); pcapConf[i].handle =3D NULL; =20 - /* protect req->ifname */ + /* protect req->binding->portdevname */ virNWFilterSnoopReqLock(req); =20 virReportError(VIR_ERR_INTERNAL_ERROR, _("interface '%s' failing; " "reopening"), - req->ifname); - if (req->ifname) + req->binding->portdevname); + if (req->binding->portdevname) pcapConf[i].handle =3D - virNWFilterSnoopDHCPOpen(req->ifname, &req->ma= caddr, + virNWFilterSnoopDHCPOpen(req->binding->portdev= name, + &req->binding->mac, pcapConf[i].filter, pcapConf[i].dir); =20 @@ -1519,7 +1502,7 @@ virNWFilterDHCPSnoopThread(void *req0) last_displayed_queue =3D time(0); VIR_WARN("Worker thread for interface '%s' has a " "job queue that is too long", - req->ifname); + req->binding->portdevname); } continue; } @@ -1532,7 +1515,7 @@ virNWFilterDHCPSnoopThread(void *req0) if (time(0) - last_displayed > 10) { last_displayed =3D time(0); VIR_WARN("Too many DHCP packets on interface '%s'= ", - req->ifname); + req->binding->portdevname); } continue; } @@ -1543,7 +1526,7 @@ virNWFilterDHCPSnoopThread(void *req0) &pcapConf[i].qCtr) <= 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Job submission failed on " - "interface '%s'"), req->ifname); + "interface '%s'"), req->binding->port= devname); error =3D true; break; } @@ -1554,15 +1537,15 @@ virNWFilterDHCPSnoopThread(void *req0) /* protect IfNameToKey */ virNWFilterSnoopLock(); =20 - /* protect req->ifname & req->threadkey */ + /* protect req->binding->portdevname & req->threadkey */ virNWFilterSnoopReqLock(req); =20 virNWFilterSnoopCancel(&req->threadkey); =20 ignore_value(virHashRemoveEntry(virNWFilterSnoopState.ifnameToKey, - req->ifname)); + req->binding->portdevname)); =20 - VIR_FREE(req->ifname); + VIR_FREE(req->binding->portdevname); =20 virNWFilterSnoopReqUnlock(req); virNWFilterSnoopUnlock(); @@ -1595,12 +1578,7 @@ virNWFilterSnoopIFKeyFMT(char *ifkey, const unsigned= char *vmuuid, =20 int virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr techdriver, - const char *ifname, - const char *linkdev, - const unsigned char *vmuuid, - const virMacAddr *macaddr, - const char *filtername, - virHashTablePtr filterparams, + virNWFilterBindingPtr binding, virNWFilterDriverStatePtr driver) { virNWFilterSnoopReqPtr req; @@ -1611,7 +1589,7 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr tech= driver, virNWFilterVarValuePtr dhcpsrvrs; bool threadPuts =3D false; =20 - virNWFilterSnoopIFKeyFMT(ifkey, vmuuid, macaddr); + virNWFilterSnoopIFKeyFMT(ifkey, binding->owneruuid, &binding->mac); =20 req =3D virNWFilterSnoopReqGetByIFKey(ifkey); isnewreq =3D (req =3D=3D NULL); @@ -1620,9 +1598,8 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr tech= driver, virNWFilterSnoopReqPut(req); return 0; } - /* a recycled req may still have filtername and vars */ - VIR_FREE(req->filtername); - virHashFree(req->vars); + virNWFilterBindingFree(req->binding); + req->binding =3D NULL; } else { req =3D virNWFilterSnoopReqNew(ifkey); if (!req) @@ -1631,17 +1608,9 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr tec= hdriver, =20 req->driver =3D driver; req->techdriver =3D techdriver; - tmp =3D virNetDevGetIndex(ifname, &req->ifindex); - virMacAddrSet(&req->macaddr, macaddr); - req->vars =3D virNWFilterHashTableCreate(0); - req->linkdev =3D NULL; - - if (VIR_STRDUP(req->ifname, ifname) < 0 || - VIR_STRDUP(req->filtername, filtername) < 0 || - VIR_STRDUP(req->linkdev, linkdev) < 0) + if ((tmp =3D virNetDevGetIndex(binding->portdevname, &req->ifindex)) <= 0) goto exit_snoopreqput; - - if (!req->vars || tmp < 0) + if (!(req->binding =3D virNWFilterBindingCopy(binding))) goto exit_snoopreqput; =20 /* check that all tools are available for applying the filters (late) = */ @@ -1653,10 +1622,11 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr te= chdriver, goto exit_snoopreqput; } =20 - dhcpsrvrs =3D virHashLookup(filterparams, + dhcpsrvrs =3D virHashLookup(binding->filterparams, NWFILTER_VARNAME_DHCPSERVER); =20 - if (techdriver->applyDHCPOnlyRules(req->ifname, &req->macaddr, + if (techdriver->applyDHCPOnlyRules(req->binding->portdevname, + &req->binding->mac, dhcpsrvrs, false) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("applyDHCPOnlyRules " @@ -1664,20 +1634,14 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr te= chdriver, goto exit_snoopreqput; } =20 - if (virNWFilterHashTablePutAll(filterparams, req->vars) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("virNWFilterDHCPSnoopReq: can't copy variables" - " on if %s"), ifkey); - goto exit_snoopreqput; - } - virNWFilterSnoopLock(); =20 - if (virHashAddEntry(virNWFilterSnoopState.ifnameToKey, ifname, + if (virHashAddEntry(virNWFilterSnoopState.ifnameToKey, + req->binding->portdevname, req->ifkey) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("virNWFilterDHCPSnoopReq ifname map failed" - " on interface \"%s\" key \"%s\""), ifname, + " on interface \"%s\" key \"%s\""), binding->port= devname, ifkey); goto exit_snoopunlock; } @@ -1686,7 +1650,7 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr tech= driver, virHashAddEntry(virNWFilterSnoopState.snoopReqs, ifkey, req) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("virNWFilterDHCPSnoopReq req add failed on" - " interface \"%s\" ifkey \"%s\""), ifname, + " interface \"%s\" ifkey \"%s\""), binding->portd= evname, ifkey); goto exit_rem_ifnametokey; } @@ -1698,7 +1662,7 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr tech= driver, req) !=3D 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("virNWFilterDHCPSnoopReq virThreadCreate " - "failed on interface '%s'"), ifname); + "failed on interface '%s'"), binding->portdevname= ); goto exit_snoopreq_unlock; } =20 @@ -1710,14 +1674,14 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr te= chdriver, if (!req->threadkey) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Activation of snoop request failed on " - "interface '%s'"), req->ifname); + "interface '%s'"), req->binding->portdevname); goto exit_snoopreq_unlock; } =20 if (virNWFilterSnoopReqRestore(req) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Restoring of leases failed on " - "interface '%s'"), req->ifname); + "interface '%s'"), req->binding->portdevname); goto exit_snoop_cancel; } =20 @@ -1746,7 +1710,7 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr tech= driver, exit_snoopreq_unlock: virNWFilterSnoopReqUnlock(req); exit_rem_ifnametokey: - virHashRemoveEntry(virNWFilterSnoopState.ifnameToKey, ifname); + virHashRemoveEntry(virNWFilterSnoopState.ifnameToKey, binding->portdev= name); exit_snoopunlock: virNWFilterSnoopUnlock(); exit_snoopreqput: @@ -2054,21 +2018,21 @@ virNWFilterSnoopRemAllReqIter(const void *payload, { virNWFilterSnoopReqPtr req =3D (virNWFilterSnoopReqPtr)payload; =20 - /* protect req->ifname */ + /* protect req->binding->portdevname */ virNWFilterSnoopReqLock(req); =20 - if (req->ifname) { + if (req->binding->portdevname) { ignore_value(virHashRemoveEntry(virNWFilterSnoopState.ifnameToKey, - req->ifname)); + req->binding->portdevname)); =20 /* * Remove all IP addresses known to be associated with this * interface so that a new thread will be started on this * interface */ - virNWFilterIPAddrMapDelIPAddr(req->ifname, NULL); + virNWFilterIPAddrMapDelIPAddr(req->binding->portdevname, NULL); =20 - VIR_FREE(req->ifname); + VIR_FREE(req->binding->portdevname); } =20 virNWFilterSnoopReqUnlock(req); @@ -2171,13 +2135,13 @@ virNWFilterDHCPSnoopEnd(const char *ifname) goto cleanup; } =20 - /* protect req->ifname & req->threadkey */ + /* protect req->binding->portdevname & req->threadkey */ virNWFilterSnoopReqLock(req); =20 /* keep valid lease req; drop interface association */ virNWFilterSnoopCancel(&req->threadkey); =20 - VIR_FREE(req->ifname); + VIR_FREE(req->binding->portdevname); =20 virNWFilterSnoopReqUnlock(req); =20 diff --git a/src/nwfilter/nwfilter_dhcpsnoop.h b/src/nwfilter/nwfilter_dhcp= snoop.h index a5925de40a..0c047fd5a1 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.h +++ b/src/nwfilter/nwfilter_dhcpsnoop.h @@ -30,12 +30,7 @@ int virNWFilterDHCPSnoopInit(void); void virNWFilterDHCPSnoopShutdown(void); int virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr techdriver, - const char *ifname, - const char *linkdev, - const unsigned char *vmuuid, - const virMacAddr *macaddr, - const char *filtername, - virHashTablePtr filterparams, + virNWFilterBindingPtr binding, virNWFilterDriverStatePtr driver); void virNWFilterDHCPSnoopEnd(const char *ifname); #endif /* __NWFILTER_DHCPSNOOP_H */ diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter= _gentech_driver.c index 514315f781..0dc51d16c5 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -645,10 +645,9 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr tech= driver, goto err_unresolvable_vars; } if (STRCASEEQ(learning, "dhcp")) { - rc =3D virNWFilterDHCPSnoopReq(techdriver, binding->portde= vname, - binding->linkdevname, - binding->owneruuid, &binding-= >mac, - filter->name, binding->filter= params, driver); + rc =3D virNWFilterDHCPSnoopReq(techdriver, + binding, + driver); goto err_exit; } else if (STRCASEEQ(learning, "any")) { if (!virNWFilterHasLearnReq(ifindex)) { --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Nov 28 08:28:40 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 152484313776345.7290614233068; Fri, 27 Apr 2018 08:32:17 -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 3CCBC30C808F; Fri, 27 Apr 2018 15:32:16 +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 E655C5FC20; Fri, 27 Apr 2018 15:32:15 +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 6BD324CA9F; Fri, 27 Apr 2018 15:32:15 +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 w3RFPRaP032332 for ; Fri, 27 Apr 2018 11:25:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3411983B71; 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 C3D03AB3EF; Fri, 27 Apr 2018 15:25:26 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 27 Apr 2018 16:25:11 +0100 Message-Id: <20180427152513.28928-13-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 12/14] nwfilter: report an error if nic needs filtering by no driver is present 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.46]); Fri, 27 Apr 2018 15:32:16 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 If a includes a filter name but the nwfilter driver is not present we silently do nothing. This is very bad, because an application that thinks it is protected by malicious guest traffic will in fact be vulnerable. Reporting an error gives the administrator the ability to know there is a problem and fix it. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/conf/domain_nwfilter.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/conf/domain_nwfilter.c b/src/conf/domain_nwfilter.c index e360aceeba..7570e0ae83 100644 --- a/src/conf/domain_nwfilter.c +++ b/src/conf/domain_nwfilter.c @@ -28,6 +28,9 @@ #include "datatypes.h" #include "domain_conf.h" #include "domain_nwfilter.h" +#include "virerror.h" + +#define VIR_FROM_THIS VIR_FROM_NWFILTER =20 static virDomainConfNWFilterDriverPtr nwfilterDriver; =20 @@ -44,8 +47,10 @@ virDomainConfNWFilterInstantiate(const char *vmname, { if (nwfilterDriver !=3D NULL) return nwfilterDriver->instantiateFilter(vmname, vmuuid, net); - /* driver module not available -- don't indicate failure */ - return 0; + + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("No network filter driver available")); + return -1; } =20 void --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Nov 28 08:28:40 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 From nobody Thu Nov 28 08:28:40 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 1524842927973445.8333115910582; Fri, 27 Apr 2018 08:28:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 72DBFC03D472; Fri, 27 Apr 2018 15:28:46 +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 4569231327A1; Fri, 27 Apr 2018 15:28:46 +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 B71314CAA2; Fri, 27 Apr 2018 15:28:45 +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 w3RFPSiM032345 for ; Fri, 27 Apr 2018 11:25:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8B3F7AB3EF; Fri, 27 Apr 2018 15:25:28 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 252CC83B71; Fri, 27 Apr 2018 15:25:28 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 27 Apr 2018 16:25:13 +0100 Message-Id: <20180427152513.28928-15-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 WIP 14/14] nwfilter: remove virt driver callback layer for rebuilding filters 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.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 27 Apr 2018 15:28:47 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Now that the nwfilter driver keeps a list of bindings that it has created, there is no need for the complex virt driver callbacks. It is possible to simply iterate of the list of recorded filter bindings. This means that rebuilding filters no longer has to acquire any locks on the virDomainObj objects, as they're never touched. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/conf/nwfilter_conf.c | 169 ++++++++++-------------------= ---- src/conf/nwfilter_conf.h | 51 +--------- src/conf/virnwfilterobj.c | 4 +- src/libvirt_private.syms | 3 +- src/lxc/lxc_driver.c | 28 ------ src/nwfilter/nwfilter_driver.c | 22 +++-- src/nwfilter/nwfilter_gentech_driver.c | 169 ++++++++++++++++++++---------= ---- src/nwfilter/nwfilter_gentech_driver.h | 4 +- src/qemu/qemu_driver.c | 25 ----- src/uml/uml_driver.c | 29 ------ 10 files changed, 175 insertions(+), 329 deletions(-) diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index 3d2ae9d0f3..83c9ff920f 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -2819,121 +2819,6 @@ virNWFilterSaveConfig(const char *configDir, } =20 =20 -int nCallbackDriver; -#define MAX_CALLBACK_DRIVER 10 -static virNWFilterCallbackDriverPtr callbackDrvArray[MAX_CALLBACK_DRIVER]; - -void -virNWFilterRegisterCallbackDriver(virNWFilterCallbackDriverPtr cbd) -{ - if (nCallbackDriver < MAX_CALLBACK_DRIVER) - callbackDrvArray[nCallbackDriver++] =3D cbd; -} - - -void -virNWFilterUnRegisterCallbackDriver(virNWFilterCallbackDriverPtr cbd) -{ - size_t i =3D 0; - - while (i < nCallbackDriver && callbackDrvArray[i] !=3D cbd) - i++; - - if (i < nCallbackDriver) { - memmove(&callbackDrvArray[i], &callbackDrvArray[i+1], - (nCallbackDriver - i - 1) * sizeof(callbackDrvArray[i])); - callbackDrvArray[i] =3D 0; - nCallbackDriver--; - } -} - - -void -virNWFilterCallbackDriversLock(void) -{ - size_t i; - - for (i =3D 0; i < nCallbackDriver; i++) - callbackDrvArray[i]->vmDriverLock(); -} - - -void -virNWFilterCallbackDriversUnlock(void) -{ - size_t i; - - for (i =3D 0; i < nCallbackDriver; i++) - callbackDrvArray[i]->vmDriverUnlock(); -} - - -static virDomainObjListIterator virNWFilterDomainFWUpdateCB; -static void *virNWFilterDomainFWUpdateOpaque; - -/** - * virNWFilterInstFiltersOnAllVMs: - * Apply all filters on all running VMs. Don't terminate in case of an - * error. This should be called upon reloading of the driver. - */ -int -virNWFilterInstFiltersOnAllVMs(void) -{ - size_t i; - struct domUpdateCBStruct cb =3D { - .opaque =3D virNWFilterDomainFWUpdateOpaque, - .step =3D STEP_APPLY_CURRENT, - .skipInterfaces =3D NULL, /* not needed */ - }; - - for (i =3D 0; i < nCallbackDriver; i++) - callbackDrvArray[i]->vmFilterRebuild(virNWFilterDomainFWUpdateCB, - &cb); - - return 0; -} - - -int -virNWFilterTriggerVMFilterRebuild(void) -{ - size_t i; - int ret =3D 0; - struct domUpdateCBStruct cb =3D { - .opaque =3D virNWFilterDomainFWUpdateOpaque, - .step =3D STEP_APPLY_NEW, - .skipInterfaces =3D virHashCreate(0, NULL), - }; - - if (!cb.skipInterfaces) - return -1; - - for (i =3D 0; i < nCallbackDriver; i++) { - if (callbackDrvArray[i]->vmFilterRebuild(virNWFilterDomainFWUpdate= CB, - &cb) < 0) - ret =3D -1; - } - - if (ret < 0) { - cb.step =3D STEP_TEAR_NEW; /* rollback */ - - for (i =3D 0; i < nCallbackDriver; i++) - callbackDrvArray[i]->vmFilterRebuild(virNWFilterDomainFWUpdate= CB, - &cb); - } else { - cb.step =3D STEP_TEAR_OLD; /* switch over */ - - for (i =3D 0; i < nCallbackDriver; i++) - callbackDrvArray[i]->vmFilterRebuild(virNWFilterDomainFWUpdate= CB, - &cb); - } - - virHashFree(cb.skipInterfaces); - - return ret; -} - - int virNWFilterDeleteDef(const char *configDir, virNWFilterDefPtr def) @@ -3204,16 +3089,18 @@ virNWFilterDefFormat(const virNWFilterDef *def) return NULL; } =20 +static virNWFilterTriggerRebuildCallback rebuildCallback; +static void *rebuildOpaque; =20 int -virNWFilterConfLayerInit(virDomainObjListIterator domUpdateCB, +virNWFilterConfLayerInit(virNWFilterTriggerRebuildCallback cb, void *opaque) { if (initialized) return -1; =20 - virNWFilterDomainFWUpdateCB =3D domUpdateCB; - virNWFilterDomainFWUpdateOpaque =3D opaque; + rebuildCallback =3D cb; + rebuildOpaque =3D opaque; =20 initialized =3D true; =20 @@ -3233,8 +3120,50 @@ virNWFilterConfLayerShutdown(void) virRWLockDestroy(&updateLock); =20 initialized =3D false; - virNWFilterDomainFWUpdateOpaque =3D NULL; - virNWFilterDomainFWUpdateCB =3D NULL; + rebuildCallback =3D NULL; + rebuildOpaque =3D NULL; +} + +int +virNWFilterTriggerRebuild(void) +{ +#if 0 + size_t i; + int ret =3D 0; + struct domUpdateCBStruct cb =3D { + .opaque =3D virNWFilterDomainFWUpdateOpaque, + .step =3D STEP_APPLY_NEW, + .skipInterfaces =3D virHashCreate(0, NULL), + }; + + if (!cb.skipInterfaces) + return -1; + + for (i =3D 0; i < nCallbackDriver; i++) { + if (callbackDrvArray[i]->vmFilterRebuild(virNWFilterDomainFWUpdate= CB, + &cb) < 0) + ret =3D -1; + } + + if (ret < 0) { + cb.step =3D STEP_TEAR_NEW; /* rollback */ + + for (i =3D 0; i < nCallbackDriver; i++) + callbackDrvArray[i]->vmFilterRebuild(virNWFilterDomainFWUpdate= CB, + &cb); + } else { + cb.step =3D STEP_TEAR_OLD; /* switch over */ + + for (i =3D 0; i < nCallbackDriver; i++) + callbackDrvArray[i]->vmFilterRebuild(virNWFilterDomainFWUpdate= CB, + &cb); + } + + virHashFree(cb.skipInterfaces); + + return ret; +#endif + return rebuildCallback(rebuildOpaque); } =20 =20 diff --git a/src/conf/nwfilter_conf.h b/src/conf/nwfilter_conf.h index 8c5421ee62..3b36a02a78 100644 --- a/src/conf/nwfilter_conf.h +++ b/src/conf/nwfilter_conf.h @@ -559,20 +559,6 @@ struct virNWFilterBinding { }; =20 =20 -typedef enum { - STEP_APPLY_NEW, - STEP_TEAR_NEW, - STEP_TEAR_OLD, - STEP_APPLY_CURRENT, -} UpdateStep; - -struct domUpdateCBStruct { - void *opaque; - UpdateStep step; - virHashTablePtr skipInterfaces; -}; - - void virNWFilterRuleDefFree(virNWFilterRuleDefPtr def); =20 @@ -580,7 +566,7 @@ void virNWFilterDefFree(virNWFilterDefPtr def); =20 int -virNWFilterTriggerVMFilterRebuild(void); +virNWFilterTriggerRebuild(void); =20 int virNWFilterDeleteDef(const char *configDir, @@ -612,44 +598,15 @@ virNWFilterReadLockFilterUpdates(void); void virNWFilterUnlockFilterUpdates(void); =20 +typedef int (*virNWFilterTriggerRebuildCallback)(void *opaque); + int -virNWFilterConfLayerInit(virDomainObjListIterator domUpdateCB, +virNWFilterConfLayerInit(virNWFilterTriggerRebuildCallback cb, void *opaque); =20 void virNWFilterConfLayerShutdown(void); =20 -int -virNWFilterInstFiltersOnAllVMs(void); - -typedef int -(*virNWFilterRebuild)(virDomainObjListIterator domUpdateCB, - void *data); - -typedef void -(*virNWFilterVoidCall)(void); - -typedef struct _virNWFilterCallbackDriver virNWFilterCallbackDriver; -typedef virNWFilterCallbackDriver *virNWFilterCallbackDriverPtr; -struct _virNWFilterCallbackDriver { - const char *name; - - virNWFilterRebuild vmFilterRebuild; - virNWFilterVoidCall vmDriverLock; - virNWFilterVoidCall vmDriverUnlock; -}; - -void -virNWFilterRegisterCallbackDriver(virNWFilterCallbackDriverPtr); - -void -virNWFilterUnRegisterCallbackDriver(virNWFilterCallbackDriverPtr); - -void -virNWFilterCallbackDriversLock(void); - -void -virNWFilterCallbackDriversUnlock(void); =20 char * virNWFilterPrintTCPFlags(uint8_t flags); diff --git a/src/conf/virnwfilterobj.c b/src/conf/virnwfilterobj.c index 87d7e72703..0136a0d56c 100644 --- a/src/conf/virnwfilterobj.c +++ b/src/conf/virnwfilterobj.c @@ -276,7 +276,7 @@ virNWFilterObjTestUnassignDef(virNWFilterObjPtr obj) =20 obj->wantRemoved =3D true; /* trigger the update on VMs referencing the filter */ - if (virNWFilterTriggerVMFilterRebuild() < 0) + if (virNWFilterTriggerRebuild() < 0) rc =3D -1; =20 obj->wantRemoved =3D false; @@ -358,7 +358,7 @@ virNWFilterObjListAssignDef(virNWFilterObjListPtr nwfil= ters, =20 obj->newDef =3D def; /* trigger the update on VMs referencing the filter */ - if (virNWFilterTriggerVMFilterRebuild() < 0) { + if (virNWFilterTriggerRebuild() < 0) { obj->newDef =3D NULL; virNWFilterObjUnlock(obj); return NULL; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 9fc0aa470d..fd5edc86ad 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -792,7 +792,6 @@ virNWFilterDefFree; virNWFilterDefParseFile; virNWFilterDefParseString; virNWFilterDeleteDef; -virNWFilterInstFiltersOnAllVMs; virNWFilterJumpTargetTypeToString; virNWFilterPrintStateMatchFlags; virNWFilterPrintTCPFlags; @@ -805,7 +804,7 @@ virNWFilterRuleIsProtocolIPv4; virNWFilterRuleIsProtocolIPv6; virNWFilterRuleProtocolTypeToString; virNWFilterSaveConfig; -virNWFilterTriggerVMFilterRebuild; +virNWFilterTriggerRebuild; virNWFilterUnlockFilterUpdates; virNWFilterUnRegisterCallbackDriver; virNWFilterWriteLockFilterUpdates; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index ca01d369d5..a6b689aef0 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -66,7 +66,6 @@ #include "virfdstream.h" #include "domain_audit.h" #include "domain_nwfilter.h" -#include "nwfilter_conf.h" #include "virinitctl.h" #include "virnetdev.h" #include "virnetdevtap.h" @@ -95,31 +94,6 @@ static int lxcStateInitialize(bool privileged, static int lxcStateCleanup(void); virLXCDriverPtr lxc_driver =3D NULL; =20 -/* callbacks for nwfilter */ -static int -lxcVMFilterRebuild(virDomainObjListIterator iter, void *data) -{ - return virDomainObjListForEach(lxc_driver->domains, iter, data); -} - -static void -lxcVMDriverLock(void) -{ - lxcDriverLock(lxc_driver); -} - -static void -lxcVMDriverUnlock(void) -{ - lxcDriverUnlock(lxc_driver); -} - -static virNWFilterCallbackDriver lxcCallbackDriver =3D { - .name =3D "LXC", - .vmFilterRebuild =3D lxcVMFilterRebuild, - .vmDriverLock =3D lxcVMDriverLock, - .vmDriverUnlock =3D lxcVMDriverUnlock, -}; =20 /** * lxcDomObjFromDomain: @@ -1691,7 +1665,6 @@ static int lxcStateInitialize(bool privileged, NULL, NULL) < 0) goto cleanup; =20 - virNWFilterRegisterCallbackDriver(&lxcCallbackDriver); virObjectUnref(caps); return 0; =20 @@ -1764,7 +1737,6 @@ static int lxcStateCleanup(void) if (lxc_driver =3D=3D NULL) return -1; =20 - virNWFilterUnRegisterCallbackDriver(&lxcCallbackDriver); virObjectUnref(lxc_driver->domains); virObjectUnref(lxc_driver->domainEventState); =20 diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index ccbcfbbf67..92389840fd 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -170,6 +170,15 @@ static void virNWFilterBindingDataFree(void *payload, = const void *name ATTRIBUTE virNWFilterBindingFree(binding); } =20 + +static int virNWFilterTriggerRebuildImpl(void *opaque) +{ + virNWFilterDriverStatePtr nwdriver =3D opaque; + + return virNWFilterBuildAll(nwdriver, true); +} + + /** * nwfilterStateInitialize: * @@ -216,7 +225,7 @@ nwfilterStateInitialize(bool privileged, if (virNWFilterTechDriversInit(privileged) < 0) goto err_dhcpsnoop_shutdown; =20 - if (virNWFilterConfLayerInit(virNWFilterDomainFWUpdateCB, + if (virNWFilterConfLayerInit(virNWFilterTriggerRebuildImpl, driver) < 0) goto err_techdrivers_shutdown; =20 @@ -306,15 +315,14 @@ nwfilterStateReload(void) =20 nwfilterDriverLock(); virNWFilterWriteLockFilterUpdates(); - virNWFilterCallbackDriversLock(); =20 virNWFilterObjListLoadAllConfigs(driver->nwfilters, driver->configDir); =20 - virNWFilterCallbackDriversUnlock(); virNWFilterUnlockFilterUpdates(); - nwfilterDriverUnlock(); =20 - virNWFilterInstFiltersOnAllVMs(); + virNWFilterBuildAll(driver, false); + + nwfilterDriverUnlock(); =20 return 0; } @@ -550,7 +558,6 @@ nwfilterDefineXML(virConnectPtr conn, =20 nwfilterDriverLock(); virNWFilterWriteLockFilterUpdates(); - virNWFilterCallbackDriversLock(); =20 if (!(def =3D virNWFilterDefParseString(xml))) goto cleanup; @@ -575,7 +582,6 @@ nwfilterDefineXML(virConnectPtr conn, if (obj) virNWFilterObjUnlock(obj); =20 - virNWFilterCallbackDriversUnlock(); virNWFilterUnlockFilterUpdates(); nwfilterDriverUnlock(); return nwfilter; @@ -591,7 +597,6 @@ nwfilterUndefine(virNWFilterPtr nwfilter) =20 nwfilterDriverLock(); virNWFilterWriteLockFilterUpdates(); - virNWFilterCallbackDriversLock(); =20 if (!(obj =3D nwfilterObjFromNWFilter(nwfilter->uuid))) goto cleanup; @@ -618,7 +623,6 @@ nwfilterUndefine(virNWFilterPtr nwfilter) if (obj) virNWFilterObjUnlock(obj); =20 - virNWFilterCallbackDriversUnlock(); virNWFilterUnlockFilterUpdates(); nwfilterDriverUnlock(); return ret; diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter= _gentech_driver.c index 0dc51d16c5..5c83b06504 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -153,9 +153,9 @@ virNWFilterVarHashmapAddStdValues(virHashTablePtr table, if (!val) return -1; =20 - if (virHashAddEntry(table, - NWFILTER_STD_VAR_MAC, - val) < 0) { + if (virHashUpdateEntry(table, + NWFILTER_STD_VAR_MAC, + val) < 0) { virNWFilterVarValueFree(val); virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not add variable 'MAC' to hashma= p")); @@ -168,9 +168,9 @@ virNWFilterVarHashmapAddStdValues(virHashTablePtr table, if (!val) return -1; =20 - if (virHashAddEntry(table, - NWFILTER_STD_VAR_IP, - val) < 0) { + if (virHashUpdateEntry(table, + NWFILTER_STD_VAR_IP, + val) < 0) { virNWFilterVarValueFree(val); virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not add variable 'IP' to hashmap= ")); @@ -1000,72 +1000,111 @@ virNWFilterTeardownFilter(virNWFilterBindingPtr bi= nding) return ret; } =20 +enum { + STEP_APPLY_NEW, + STEP_TEAR_NEW, + STEP_TEAR_OLD, + STEP_APPLY_CURRENT, +}; =20 -int -virNWFilterDomainFWUpdateCB(virDomainObjPtr obj, - void *data) +static int +virNWFilterBuildOne(virNWFilterDriverStatePtr driver, + virNWFilterBindingPtr binding, + virHashTablePtr skipInterfaces, + int step) { - virDomainDefPtr vm =3D obj->def; - struct domUpdateCBStruct *cb =3D data; - size_t i; bool skipIface; int ret =3D 0; - - virObjectLock(obj); - - if (virDomainObjIsActive(obj)) { - for (i =3D 0; i < vm->nnets; i++) { - virDomainNetDefPtr net =3D vm->nets[i]; - virNWFilterBinding binding =3D { - .ownername =3D vm->name, - .portdevname =3D net->ifname, - .linkdevname =3D (net->type =3D=3D VIR_DOMAIN_NET_TYPE_DIR= ECT ? - net->data.direct.linkdev : NULL), - .mac =3D net->mac, - .filter =3D net->filter, - .filterparams =3D net->filterparams, - }; - memcpy(binding.owneruuid, vm->uuid, sizeof(binding.owneruuid)); - if ((net->filter) && (net->ifname)) { - switch (cb->step) { - case STEP_APPLY_NEW: - ret =3D virNWFilterUpdateInstantiateFilter(cb->opaque, - &binding, - &skipIface); - if (ret =3D=3D 0 && skipIface) { - /* filter tree unchanged -- no update needed */ - ret =3D virHashAddEntry(cb->skipInterfaces, - net->ifname, - (void *)~0); - } - break; - - case STEP_TEAR_NEW: - if (!virHashLookup(cb->skipInterfaces, net->ifname)) - ret =3D virNWFilterRollbackUpdateFilter(&binding); - break; - - case STEP_TEAR_OLD: - if (!virHashLookup(cb->skipInterfaces, net->ifname)) - ret =3D virNWFilterTearOldFilter(&binding); - break; - - case STEP_APPLY_CURRENT: - ret =3D virNWFilterInstantiateFilter(cb->opaque, - &binding); - if (ret) - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failure while applying current f= ilter on " - "VM %s"), vm->name); - break; - } - if (ret) - break; - } + VIR_DEBUG("Building filter for portdev=3D%s step=3D%d", binding->portd= evname, step); + + switch (step) { + case STEP_APPLY_NEW: + ret =3D virNWFilterUpdateInstantiateFilter(driver, + binding, + &skipIface); + if (ret =3D=3D 0 && skipIface) { + /* filter tree unchanged -- no update needed */ + ret =3D virHashAddEntry(skipInterfaces, + binding->portdevname, + (void *)~0); } + break; + + case STEP_TEAR_NEW: + if (!virHashLookup(skipInterfaces, binding->portdevname)) + ret =3D virNWFilterRollbackUpdateFilter(binding); + break; + + case STEP_TEAR_OLD: + if (!virHashLookup(skipInterfaces, binding->portdevname)) + ret =3D virNWFilterTearOldFilter(binding); + break; + + case STEP_APPLY_CURRENT: + ret =3D virNWFilterInstantiateFilter(driver, + binding); + break; } =20 - virObjectUnlock(obj); + return ret; +} + + +struct virNWFilterBuildData { + virNWFilterDriverStatePtr driver; + virHashTablePtr skipInterfaces; + int step; +}; + +static int +virNWFilterBuildIter(void *payload, const void *name ATTRIBUTE_UNUSED, voi= d *opaque) +{ + virNWFilterBindingPtr binding =3D payload; + struct virNWFilterBuildData *data =3D opaque; + + return virNWFilterBuildOne(data->driver, binding, + data->skipInterfaces, data->step); +} + +int +virNWFilterBuildAll(virNWFilterDriverStatePtr driver, + bool newFilters) +{ + struct virNWFilterBuildData data =3D { + .driver =3D driver, + }; + int ret =3D 0; + + VIR_DEBUG("Build all filters newFilters=3D%d", newFilters); + + if (newFilters) { + if (!(data.skipInterfaces =3D virHashCreate(0, NULL))) + return -1; + + data.step =3D STEP_APPLY_NEW; + if (virHashForEach(driver->bindings, + virNWFilterBuildIter, + &data) < 0) + ret =3D -1; + + if (ret =3D=3D -1) { + data.step =3D STEP_TEAR_NEW; + virHashForEach(driver->bindings, + virNWFilterBuildIter, + &data); + } else { + data.step =3D STEP_TEAR_OLD; + virHashForEach(driver->bindings, + virNWFilterBuildIter, + &data); + } + } else { + data.step =3D STEP_APPLY_CURRENT; + if (virHashForEach(driver->bindings, + virNWFilterBuildIter, + &data) < 0) + ret =3D -1; + } return ret; } =20 diff --git a/src/nwfilter/nwfilter_gentech_driver.h b/src/nwfilter/nwfilter= _gentech_driver.h index 0d846dc92f..8bfc323808 100644 --- a/src/nwfilter/nwfilter_gentech_driver.h +++ b/src/nwfilter/nwfilter_gentech_driver.h @@ -52,8 +52,8 @@ int virNWFilterTeardownFilter(virNWFilterBindingPtr bindi= ng); virHashTablePtr virNWFilterCreateVarHashmap(const char *macaddr, const virNWFilterVarValue *value); =20 -int virNWFilterDomainFWUpdateCB(virDomainObjPtr vm, - void *data); +int virNWFilterBuildAll(virNWFilterDriverStatePtr driver, + bool newFilters); =20 virNWFilterBindingPtr virNWFilterBindingForNet(const char *vmname, const unsigned char *vmuuid, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 7484b00e23..668891a119 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -84,7 +84,6 @@ #include "cpu/cpu.h" #include "virsysinfo.h" #include "domain_nwfilter.h" -#include "nwfilter_conf.h" #include "virhook.h" #include "virstoragefile.h" #include "virfile.h" @@ -164,28 +163,6 @@ static int qemuARPGetInterfaces(virDomainObjPtr vm, =20 static virQEMUDriverPtr qemu_driver; =20 - -static void -qemuVMDriverLock(void) -{} -static void -qemuVMDriverUnlock(void) -{} - -static int -qemuVMFilterRebuild(virDomainObjListIterator iter, void *data) -{ - return virDomainObjListForEach(qemu_driver->domains, iter, data); -} - -static virNWFilterCallbackDriver qemuCallbackDriver =3D { - .name =3D QEMU_DRIVER_NAME, - .vmFilterRebuild =3D qemuVMFilterRebuild, - .vmDriverLock =3D qemuVMDriverLock, - .vmDriverUnlock =3D qemuVMDriverUnlock, -}; - - /** * qemuDomObjFromDomain: * @domain: Domain pointer that has to be looked up @@ -938,7 +915,6 @@ qemuStateInitialize(bool privileged, if (!qemu_driver->workerPool) goto error; =20 - virNWFilterRegisterCallbackDriver(&qemuCallbackDriver); return 0; =20 error: @@ -1078,7 +1054,6 @@ qemuStateCleanup(void) if (!qemu_driver) return -1; =20 - virNWFilterUnRegisterCallbackDriver(&qemuCallbackDriver); virThreadPoolFree(qemu_driver->workerPool); virObjectUnref(qemu_driver->config); virObjectUnref(qemu_driver->hostdevMgr); diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index b50ba1ba64..4da8fdf473 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -55,7 +55,6 @@ #include "datatypes.h" #include "virlog.h" #include "domain_nwfilter.h" -#include "nwfilter_conf.h" #include "virfile.h" #include "virfdstream.h" #include "configmake.h" @@ -145,25 +144,6 @@ static int umlMonitorCommand(const struct uml_driver *= driver, =20 static struct uml_driver *uml_driver; =20 -static int -umlVMFilterRebuild(virDomainObjListIterator iter, void *data) -{ - return virDomainObjListForEach(uml_driver->domains, iter, data); -} - -static void -umlVMDriverLock(void) -{ - umlDriverLock(uml_driver); -} - -static void -umlVMDriverUnlock(void) -{ - umlDriverUnlock(uml_driver); -} - - static virDomainObjPtr umlDomObjFromDomainLocked(struct uml_driver *driver, const unsigned char *uuid) @@ -196,13 +176,6 @@ umlDomObjFromDomain(struct uml_driver *driver, } =20 =20 -static virNWFilterCallbackDriver umlCallbackDriver =3D { - .name =3D "UML", - .vmFilterRebuild =3D umlVMFilterRebuild, - .vmDriverLock =3D umlVMDriverLock, - .vmDriverUnlock =3D umlVMDriverUnlock, -}; - struct umlAutostartData { struct uml_driver *driver; virConnectPtr conn; @@ -615,7 +588,6 @@ umlStateInitialize(bool privileged, =20 VIR_FREE(userdir); =20 - virNWFilterRegisterCallbackDriver(¨CallbackDriver); return 0; =20 out_of_memory: @@ -709,7 +681,6 @@ umlStateCleanup(void) return -1; =20 umlDriverLock(uml_driver); - virNWFilterRegisterCallbackDriver(¨CallbackDriver); if (uml_driver->inotifyWatch !=3D -1) virEventRemoveHandle(uml_driver->inotifyWatch); VIR_FORCE_CLOSE(uml_driver->inotifyFD); --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list