From nobody Mon Nov 25 21:45:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1594156507; cv=none; d=zohomail.com; s=zohoarc; b=cPqx7zChgs6IpWnHm/OXXVIuqs7KRX4ThnAGRcyo7BDxnCx2i/5mqo46sxEmasxwqFU5RABFvtUE5oE5sZOrS3h5PTbrUdrIdczKKcS77POqAOwEJ9OZNINHt3e50c9Zx5zerhjHEd5sWzfbMu4wHqQuQdd1BsjJC3gt+bCJ4hY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594156507; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=B53q1TwZXfXS+QBeQuNnw1rlSoknyYusGolxu8JnKCI=; b=g4foKBQGYWk46LkgOBBsZW23pb+ZQHBtU1C+ffhI+z12n+ZOzmvEZQCgDRMf1JXH7ufehxLx4qbBOjpP+v+tNTXQVoTMUXSU4OFSXWO3ynZ3a7qSw7U1DG1kn0pLI0rm+h+MuzPqyXDDwrHpSttwl7XBdidcYyljck0qZpJgDlY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1594156507624914.0270657950582; Tue, 7 Jul 2020 14:15:07 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-444-Z0JTvsNmPIyYk8LeMyUMmA-1; Tue, 07 Jul 2020 17:15:03 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6CF81107ACF7; Tue, 7 Jul 2020 21:14:57 +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 4E1F77846E; Tue, 7 Jul 2020 21:14: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 1F3C51806B0A; Tue, 7 Jul 2020 21:14:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 067L8Swo008022 for ; Tue, 7 Jul 2020 17:08:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id E5C13797E0; Tue, 7 Jul 2020 21:08:28 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-194.phx2.redhat.com [10.3.112.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CEF579220 for ; Tue, 7 Jul 2020 21:08:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594156506; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=B53q1TwZXfXS+QBeQuNnw1rlSoknyYusGolxu8JnKCI=; b=eDzbtdszqqjdwW+PpIL1WX3CK4RzU7QNYU5XtFj5ldc3N24n1FbzUCEPbHFS6dalqJICdh /TO7/jv+x6hKyJpyn2IgMgwpWwvyPn26FJ8N4i5tu1RH4S8HHkuea9HpM3x2RS+oYC0o9b vFd9xJOdErAXLeM+C4XBbgncpfHhKz4= X-MC-Unique: Z0JTvsNmPIyYk8LeMyUMmA-1 From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH v2 12/15] nwfilter: use standard label names when reasonable Date: Tue, 7 Jul 2020 17:08:12 -0400 Message-Id: <20200707210815.1797463-13-laine@redhat.com> In-Reply-To: <20200707210815.1797463-1-laine@redhat.com> References: <20200707210815.1797463-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Rather than having labels named exit, done, exit_snooprequnlock, skip_rename, etc, use the standard "cleanup" label. And instead of err_exit, malformed, tear_down_tmpebchains, use "error". Signed-off-by: Laine Stump Reviewed-by: J=C3=A1n Tomko --- src/nwfilter/nwfilter_dhcpsnoop.c | 36 +++++++++++------------ src/nwfilter/nwfilter_ebiptables_driver.c | 12 ++++---- src/nwfilter/nwfilter_gentech_driver.c | 32 ++++++++++---------- src/nwfilter/nwfilter_learnipaddr.c | 24 +++++++-------- 4 files changed, 52 insertions(+), 52 deletions(-) diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcp= snoop.c index f530341872..6de41ff209 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -456,11 +456,11 @@ virNWFilterSnoopIPLeaseInstallRule(virNWFilterSnoopIP= LeasePtr ipl, virNWFilterSnoopReqLock(req); =20 if (virNWFilterIPAddrMapAddIPAddr(req->binding->portdevname, ipaddr) <= 0) - goto exit_snooprequnlock; + goto cleanup; =20 if (!instantiate) { rc =3D 0; - goto exit_snooprequnlock; + goto cleanup; } =20 /* instantiate the filters */ @@ -471,7 +471,7 @@ virNWFilterSnoopIPLeaseInstallRule(virNWFilterSnoopIPLe= asePtr ipl, req->ifindex); } =20 - exit_snooprequnlock: + cleanup: virNWFilterSnoopReqUnlock(req); =20 VIR_FREE(ipaddr); @@ -732,7 +732,7 @@ virNWFilterSnoopReqLeaseAdd(virNWFilterSnoopReqPtr req, =20 virNWFilterSnoopReqUnlock(req); =20 - goto exit; + goto cleanup; } =20 virNWFilterSnoopReqUnlock(req); @@ -757,7 +757,7 @@ virNWFilterSnoopReqLeaseAdd(virNWFilterSnoopReqPtr req, =20 g_atomic_int_add(&virNWFilterSnoopState.nLeases, 1); =20 - exit: + cleanup: if (update_leasefile) virNWFilterSnoopLeaseFileSave(pl); =20 @@ -902,7 +902,7 @@ virNWFilterSnoopDHCPGetOpt(virNWFilterSnoopDHCPHdrPtr p= d, int len, switch (pd->d_opts[oind]) { case DHCPO_LEASE: if (olen - oind < 6) - goto malformed; + goto error; if (*pleasetime) return -1; /* duplicate lease time */ memcpy(&nwint, (char *)pd->d_opts + oind + 2, sizeof(nwint)); @@ -910,7 +910,7 @@ virNWFilterSnoopDHCPGetOpt(virNWFilterSnoopDHCPHdrPtr p= d, int len, break; case DHCPO_MTYPE: if (olen - oind < 3) - goto malformed; + goto error; if (*pmtype) return -1; /* duplicate message type */ *pmtype =3D pd->d_opts[oind + 2]; @@ -922,12 +922,12 @@ virNWFilterSnoopDHCPGetOpt(virNWFilterSnoopDHCPHdrPtr= pd, int len, return 0; default: if (olen - oind < 2) - goto malformed; + goto error; } oind +=3D pd->d_opts[oind + 1] + 2; } return 0; - malformed: + error: VIR_WARN("got lost in the options!"); return -1; } @@ -1386,7 +1386,7 @@ virNWFilterDHCPSnoopThread(void *req0) virNWFilterSnoopReqUnlock(req); =20 if (req->threadStatus !=3D THREAD_STATUS_OK) - goto exit; + goto cleanup; =20 while (!error) { if (virNWFilterSnoopAdjustPoll(pcapConf, @@ -1414,7 +1414,7 @@ virNWFilterDHCPSnoopThread(void *req0) */ if (!virNWFilterSnoopIsActive(threadkey) || req->jobCompletionStatus !=3D 0) - goto exit; + goto cleanup; =20 for (i =3D 0; n > 0 && i < G_N_ELEMENTS(fds); i++) { if (!fds[i].revents) @@ -1531,7 +1531,7 @@ virNWFilterDHCPSnoopThread(void *req0) virNWFilterSnoopReqUnlock(req); virNWFilterSnoopUnlock(); =20 - exit: + cleanup: virThreadPoolFree(worker); =20 virNWFilterSnoopReqPut(req); @@ -1774,14 +1774,14 @@ virNWFilterSnoopLeaseFileSave(virNWFilterSnoopIPLea= sePtr ipl) virNWFilterSnoopLeaseFileOpen(); if (virNWFilterSnoopLeaseFileWrite(virNWFilterSnoopState.leaseFD, req->ifkey, ipl) < 0) - goto err_exit; + goto error; =20 /* keep dead leases at < ~95% of file size */ if (g_atomic_int_add(&virNWFilterSnoopState.wLeases, 1) >=3D g_atomic_int_get(&virNWFilterSnoopState.nLeases) * 20) virNWFilterSnoopLeaseFileLoad(); /* load & refresh lease file */ =20 - err_exit: + error: virNWFilterSnoopUnlock(); } =20 @@ -1876,7 +1876,7 @@ virNWFilterSnoopLeaseFileRefresh(void) if (VIR_CLOSE(tfd) < 0) { virReportSystemError(errno, _("unable to close %s"), TMPLEASEFILE); /* assuming the old lease file is still better, skip the renaming = */ - goto skip_rename; + goto cleanup; } =20 if (rename(TMPLEASEFILE, LEASEFILE) < 0) { @@ -1886,7 +1886,7 @@ virNWFilterSnoopLeaseFileRefresh(void) } g_atomic_int_set(&virNWFilterSnoopState.wLeases, 0); =20 - skip_rename: + cleanup: virNWFilterSnoopLeaseFileOpen(); } =20 @@ -2051,14 +2051,14 @@ virNWFilterDHCPSnoopInit(void) if (!virNWFilterSnoopState.ifnameToKey || !virNWFilterSnoopState.snoopReqs || !virNWFilterSnoopState.active) - goto err_exit; + goto error; =20 virNWFilterSnoopLeaseFileLoad(); virNWFilterSnoopLeaseFileOpen(); =20 return 0; =20 - err_exit: + error: virHashFree(virNWFilterSnoopState.ifnameToKey); virNWFilterSnoopState.ifnameToKey =3D NULL; =20 diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfil= ter_ebiptables_driver.c index 94eaac927a..8ac3a7271e 100644 --- a/src/nwfilter/nwfilter_ebiptables_driver.c +++ b/src/nwfilter/nwfilter_ebiptables_driver.c @@ -2893,11 +2893,11 @@ ebtablesApplyBasicRules(const char *ifname, ebtablesRenameTmpRootChainFW(fw, true, ifname); =20 if (virFirewallApply(fw) < 0) - goto tear_down_tmpebchains; + goto error; =20 return 0; =20 - tear_down_tmpebchains: + error: ebtablesCleanAll(ifname); return -1; } @@ -3009,11 +3009,11 @@ ebtablesApplyDHCPOnlyRules(const char *ifname, } =20 if (virFirewallApply(fw) < 0) - goto tear_down_tmpebchains; + goto error; =20 return 0; =20 - tear_down_tmpebchains: + error: ebtablesCleanAll(ifname); return -1; } @@ -3060,11 +3060,11 @@ ebtablesApplyDropAllRules(const char *ifname) ebtablesRenameTmpRootChainFW(fw, false, ifname); =20 if (virFirewallApply(fw) < 0) - goto tear_down_tmpebchains; + goto error; =20 return 0; =20 - tear_down_tmpebchains: + error: ebtablesCleanAll(ifname); return -1; } diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter= _gentech_driver.c index aff42cbfb0..400d064724 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -204,14 +204,14 @@ virNWFilterCreateVarsFrom(virHashTablePtr vars1, return NULL; =20 if (virNWFilterHashTablePutAll(vars1, res) < 0) - goto err_exit; + goto error; =20 if (virNWFilterHashTablePutAll(vars2, res) < 0) - goto err_exit; + goto error; =20 return res; =20 - err_exit: + error: virHashFree(res); return NULL; } @@ -527,7 +527,7 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr techd= river, =20 if (!missing_vars) { rc =3D -1; - goto err_exit; + goto error; } =20 rc =3D virNWFilterDetermineMissingVarsRec(filter, @@ -536,7 +536,7 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr techd= river, useNewFilter, driver); if (rc < 0) - goto err_exit; + goto error; =20 lv =3D virHashLookup(binding->filterparams, NWFILTER_VARNAME_CTRL_IP_L= EARNING); if (lv) @@ -558,7 +558,7 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr techd= river, rc =3D virNWFilterDHCPSnoopReq(techdriver, binding, driver); - goto err_exit; + goto error; } else if (STRCASEEQ(learning, "any")) { if (!virNWFilterHasLearnReq(ifindex)) { rc =3D virNWFilterLearnIPAddress(techdriver, @@ -567,14 +567,14 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr tec= hdriver, driver, DETECT_DHCP|DETECT_STAT= IC); } - goto err_exit; + goto error; } else { rc =3D -1; virReportError(VIR_ERR_PARSE_FAILED, _("filter '%s' " "learning value '%s' invalid."), filter->name, learning); - goto err_exit; + goto error; } } else { goto err_unresolvable_vars; @@ -583,7 +583,7 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr techd= river, goto err_unresolvable_vars; } else if (!forceWithPendingReq && virNWFilterHasLearnReq(ifindex)) { - goto err_exit; + goto error; } =20 rc =3D virNWFilterDefToInst(driver, @@ -593,7 +593,7 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr techd= river, &inst); =20 if (rc < 0) - goto err_exit; + goto error; =20 switch (useNewFilter) { case INSTANTIATE_FOLLOW_NEWFILTER: @@ -606,7 +606,7 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr techd= river, =20 if (instantiate) { if (virNWFilterLockIface(binding->portdevname) < 0) - goto err_exit; + goto error; =20 rc =3D techdriver->applyNewRules(binding->portdevname, inst.rules,= inst.nrules); =20 @@ -623,7 +623,7 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr techd= river, virNWFilterUnlockIface(binding->portdevname); } =20 - err_exit: + error: virNWFilterInstReset(&inst); virHashFree(missing_vars); =20 @@ -640,7 +640,7 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr techd= river, } =20 rc =3D -1; - goto err_exit; + goto error; } =20 =20 @@ -707,14 +707,14 @@ virNWFilterInstantiateFilterUpdate(virNWFilterDriverS= tatePtr driver, if (virNWFilterVarHashmapAddStdValue(binding->filterparams, NWFILTER_STD_VAR_MAC, vmmacaddr) < 0) - goto err_exit; + goto error; =20 ipaddr =3D virNWFilterIPAddrMapGetIPAddr(binding->portdevname); if (ipaddr && virNWFilterVarHashmapAddStdValue(binding->filterparams, NWFILTER_STD_VAR_IP, virNWFilterVarValueGetSimple(ipad= dr)) < 0) - goto err_exit; + goto error; =20 =20 filter =3D virNWFilterObjGetDef(obj); @@ -737,7 +737,7 @@ virNWFilterInstantiateFilterUpdate(virNWFilterDriverSta= tePtr driver, teardownOld, driver, forceWithPendingReq); =20 - err_exit: + error: virNWFilterObjUnlock(obj); =20 return rc; diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_le= arnipaddr.c index 14c66cff35..95e21050b4 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -152,13 +152,13 @@ virNWFilterLockIface(const char *ifname) ifaceLock =3D virHashLookup(ifaceLockMap, ifname); if (!ifaceLock) { if (VIR_ALLOC(ifaceLock) < 0) - goto err_exit; + goto error; =20 if (virMutexInitRecursive(&ifaceLock->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("mutex initialization failed")); VIR_FREE(ifaceLock); - goto err_exit; + goto error; } =20 if (virStrcpyStatic(ifaceLock->ifname, ifname) < 0) { @@ -167,12 +167,12 @@ virNWFilterLockIface(const char *ifname) "buffer "), ifaceLock->ifname); VIR_FREE(ifaceLock); - goto err_exit; + goto error; } =20 while (virHashAddEntry(ifaceLockMap, ifname, ifaceLock)) { VIR_FREE(ifaceLock); - goto err_exit; + goto error; } =20 ifaceLock->refctr =3D 0; @@ -186,7 +186,7 @@ virNWFilterLockIface(const char *ifname) =20 return 0; =20 - err_exit: + error: virMutexUnlock(&ifaceMapLock); =20 return -1; @@ -414,7 +414,7 @@ learnIPAddressThread(void *arg) if (virNetDevValidateConfig(req->binding->portdevname, NULL, req->ifin= dex) <=3D 0) { virResetLastError(); req->status =3D ENODEV; - goto done; + goto cleanup; } =20 handle =3D pcap_open_live(listen_if, BUFSIZ, 0, PKT_TIMEOUT_MS, errbuf= ); @@ -422,7 +422,7 @@ learnIPAddressThread(void *arg) if (handle =3D=3D NULL) { VIR_DEBUG("Couldn't open device %s: %s", listen_if, errbuf); req->status =3D ENODEV; - goto done; + goto cleanup; } =20 fds[0].fd =3D pcap_fileno(handle); @@ -436,7 +436,7 @@ learnIPAddressThread(void *arg) NULL, false) < 0) { VIR_DEBUG("Unable to apply DHCP only rules"); req->status =3D EINVAL; - goto done; + goto cleanup; } virBufferAddLit(&buf, "src port 67 and dst port 68"); } else { @@ -444,7 +444,7 @@ learnIPAddressThread(void *arg) &req->binding->mac) < 0) { VIR_DEBUG("Unable to apply basic rules"); req->status =3D EINVAL; - goto done; + goto cleanup; } virBufferAsprintf(&buf, "ether host %s or ether dst ff:ff:ff:ff:ff= :ff", macaddr); @@ -455,14 +455,14 @@ learnIPAddressThread(void *arg) if (pcap_compile(handle, &fp, filter, 1, 0) !=3D 0) { VIR_DEBUG("Couldn't compile filter '%s'", filter); req->status =3D EINVAL; - goto done; + goto cleanup; } =20 if (pcap_setfilter(handle, &fp) !=3D 0) { VIR_DEBUG("Couldn't set filter '%s'", filter); req->status =3D EINVAL; pcap_freecode(&fp); - goto done; + goto cleanup; } =20 pcap_freecode(&fp); @@ -622,7 +622,7 @@ learnIPAddressThread(void *arg) } } /* while */ =20 - done: + cleanup: VIR_FREE(filter); =20 if (handle) --=20 2.25.4