[PATCH 24/25] nwfilter: use standard label names when reasonable

Laine Stump laine at redhat.com
Thu Jun 25 03:34:13 UTC 2020


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 <laine at redhat.com>
---
 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       | 22 +++++++-------
 4 files changed, 51 insertions(+), 51 deletions(-)

diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c
index e41062feca..efb3257e92 100644
--- a/src/nwfilter/nwfilter_dhcpsnoop.c
+++ b/src/nwfilter/nwfilter_dhcpsnoop.c
@@ -454,11 +454,11 @@ virNWFilterSnoopIPLeaseInstallRule(virNWFilterSnoopIPLeasePtr ipl,
     virNWFilterSnoopReqLock(req);
 
     if (virNWFilterIPAddrMapAddIPAddr(req->binding->portdevname, ipaddr) < 0)
-        goto exit_snooprequnlock;
+        goto cleanup;
 
     if (!instantiate) {
         rc = 0;
-        goto exit_snooprequnlock;
+        goto cleanup;
     }
 
     /* instantiate the filters */
@@ -469,7 +469,7 @@ virNWFilterSnoopIPLeaseInstallRule(virNWFilterSnoopIPLeasePtr ipl,
                                               req->ifindex);
     }
 
- exit_snooprequnlock:
+ cleanup:
     virNWFilterSnoopReqUnlock(req);
     return rc;
 }
@@ -718,7 +718,7 @@ virNWFilterSnoopReqLeaseAdd(virNWFilterSnoopReqPtr req,
 
         virNWFilterSnoopReqUnlock(req);
 
-        goto exit;
+        goto cleanup;
     }
 
     virNWFilterSnoopReqUnlock(req);
@@ -742,7 +742,7 @@ virNWFilterSnoopReqLeaseAdd(virNWFilterSnoopReqPtr req,
 
     g_atomic_int_add(&virNWFilterSnoopState.nLeases, 1);
 
- exit:
+ cleanup:
     if (update_leasefile)
         virNWFilterSnoopLeaseFileSave(pl);
 
@@ -885,7 +885,7 @@ virNWFilterSnoopDHCPGetOpt(virNWFilterSnoopDHCPHdrPtr pd, 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));
@@ -893,7 +893,7 @@ virNWFilterSnoopDHCPGetOpt(virNWFilterSnoopDHCPHdrPtr pd, int len,
             break;
         case DHCPO_MTYPE:
             if (olen - oind < 3)
-                goto malformed;
+                goto error;
             if (*pmtype)
                 return -1;  /* duplicate message type */
             *pmtype = pd->d_opts[oind + 2];
@@ -905,12 +905,12 @@ virNWFilterSnoopDHCPGetOpt(virNWFilterSnoopDHCPHdrPtr pd, int len,
             return 0;
         default:
             if (olen - oind < 2)
-                goto malformed;
+                goto error;
         }
         oind += pd->d_opts[oind + 1] + 2;
     }
     return 0;
- malformed:
+ error:
     VIR_WARN("got lost in the options!");
     return -1;
 }
@@ -1362,7 +1362,7 @@ virNWFilterDHCPSnoopThread(void *req0)
     virNWFilterSnoopReqUnlock(req);
 
     if (req->threadStatus != THREAD_STATUS_OK)
-        goto exit;
+        goto cleanup;
 
     while (!error) {
         if (virNWFilterSnoopAdjustPoll(pcapConf,
@@ -1390,7 +1390,7 @@ virNWFilterDHCPSnoopThread(void *req0)
          */
         if (!virNWFilterSnoopIsActive(threadkey) ||
             req->jobCompletionStatus != 0)
-            goto exit;
+            goto cleanup;
 
         for (i = 0; n > 0 && i < G_N_ELEMENTS(fds); i++) {
             if (!fds[i].revents)
@@ -1507,7 +1507,7 @@ virNWFilterDHCPSnoopThread(void *req0)
     virNWFilterSnoopReqUnlock(req);
     virNWFilterSnoopUnlock();
 
- exit:
+ cleanup:
     virThreadPoolFree(worker);
 
     virNWFilterSnoopReqPut(req);
@@ -1736,14 +1736,14 @@ virNWFilterSnoopLeaseFileSave(virNWFilterSnoopIPLeasePtr ipl)
         virNWFilterSnoopLeaseFileOpen();
     if (virNWFilterSnoopLeaseFileWrite(virNWFilterSnoopState.leaseFD,
                                        req->ifkey, ipl) < 0)
-        goto err_exit;
+        goto error;
 
     /* keep dead leases at < ~95% of file size */
     if (g_atomic_int_add(&virNWFilterSnoopState.wLeases, 1) >=
         g_atomic_int_get(&virNWFilterSnoopState.nLeases) * 20)
         virNWFilterSnoopLeaseFileLoad();   /* load & refresh lease file */
 
- err_exit:
+ error:
     virNWFilterSnoopUnlock();
 }
 
@@ -1838,7 +1838,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;
     }
 
     if (rename(TMPLEASEFILE, LEASEFILE) < 0) {
@@ -1848,7 +1848,7 @@ virNWFilterSnoopLeaseFileRefresh(void)
     }
     g_atomic_int_set(&virNWFilterSnoopState.wLeases, 0);
 
- skip_rename:
+ cleanup:
     virNWFilterSnoopLeaseFileOpen();
 }
 
@@ -2013,14 +2013,14 @@ virNWFilterDHCPSnoopInit(void)
     if (!virNWFilterSnoopState.ifnameToKey ||
         !virNWFilterSnoopState.snoopReqs ||
         !virNWFilterSnoopState.active)
-        goto err_exit;
+        goto error;
 
     virNWFilterSnoopLeaseFileLoad();
     virNWFilterSnoopLeaseFileOpen();
 
     return 0;
 
- err_exit:
+ error:
     virHashFree(virNWFilterSnoopState.ifnameToKey);
     virNWFilterSnoopState.ifnameToKey = NULL;
 
diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfilter_ebiptables_driver.c
index 90afbe21f1..6aefbe226b 100644
--- a/src/nwfilter/nwfilter_ebiptables_driver.c
+++ b/src/nwfilter/nwfilter_ebiptables_driver.c
@@ -2881,11 +2881,11 @@ ebtablesApplyBasicRules(const char *ifname,
     ebtablesRenameTmpRootChainFW(fw, true, ifname);
 
     if (virFirewallApply(fw) < 0)
-        goto tear_down_tmpebchains;
+        goto error;
 
     return 0;
 
- tear_down_tmpebchains:
+ error:
     ebtablesCleanAll(ifname);
     return -1;
 }
@@ -2997,11 +2997,11 @@ ebtablesApplyDHCPOnlyRules(const char *ifname,
     }
 
     if (virFirewallApply(fw) < 0)
-        goto tear_down_tmpebchains;
+        goto error;
 
     return 0;
 
- tear_down_tmpebchains:
+ error:
     ebtablesCleanAll(ifname);
     return -1;
 }
@@ -3048,11 +3048,11 @@ ebtablesApplyDropAllRules(const char *ifname)
     ebtablesRenameTmpRootChainFW(fw, false, ifname);
 
     if (virFirewallApply(fw) < 0)
-        goto tear_down_tmpebchains;
+        goto error;
 
     return 0;
 
- 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 183e2f0a91..5433761548 100644
--- a/src/nwfilter/nwfilter_gentech_driver.c
+++ b/src/nwfilter/nwfilter_gentech_driver.c
@@ -204,14 +204,14 @@ virNWFilterCreateVarsFrom(virHashTablePtr vars1,
         return NULL;
 
     if (virNWFilterHashTablePutAll(vars1, res) < 0)
-        goto err_exit;
+        goto error;
 
     if (virNWFilterHashTablePutAll(vars2, res) < 0)
-        goto err_exit;
+        goto error;
 
     return res;
 
- err_exit:
+ error:
     virHashFree(res);
     return NULL;
 }
@@ -521,7 +521,7 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr techdriver,
 
     if (!missing_vars) {
         rc = -1;
-        goto err_exit;
+        goto error;
     }
 
     rc = virNWFilterDetermineMissingVarsRec(filter,
@@ -530,7 +530,7 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr techdriver,
                                             useNewFilter,
                                             driver);
     if (rc < 0)
-        goto err_exit;
+        goto error;
 
     lv = virHashLookup(binding->filterparams, NWFILTER_VARNAME_CTRL_IP_LEARNING);
     if (lv)
@@ -552,7 +552,7 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr techdriver,
                 rc = virNWFilterDHCPSnoopReq(techdriver,
                                              binding,
                                              driver);
-                goto err_exit;
+                goto error;
             } else if (STRCASEEQ(learning, "any")) {
                 if (!virNWFilterHasLearnReq(ifindex)) {
                     rc = virNWFilterLearnIPAddress(techdriver,
@@ -561,14 +561,14 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr techdriver,
                                                    driver,
                                                    DETECT_DHCP|DETECT_STATIC);
                 }
-                goto err_exit;
+                goto error;
             } else {
                 rc = -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;
@@ -577,7 +577,7 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr techdriver,
         goto err_unresolvable_vars;
     } else if (!forceWithPendingReq &&
                virNWFilterHasLearnReq(ifindex)) {
-        goto err_exit;
+        goto error;
     }
 
     rc = virNWFilterDefToInst(driver,
@@ -587,7 +587,7 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr techdriver,
                               &inst);
 
     if (rc < 0)
-        goto err_exit;
+        goto error;
 
     switch (useNewFilter) {
     case INSTANTIATE_FOLLOW_NEWFILTER:
@@ -600,7 +600,7 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr techdriver,
 
     if (instantiate) {
         if (virNWFilterLockIface(binding->portdevname) < 0)
-            goto err_exit;
+            goto error;
 
         rc = techdriver->applyNewRules(binding->portdevname, inst.rules, inst.nrules);
 
@@ -617,7 +617,7 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr techdriver,
         virNWFilterUnlockIface(binding->portdevname);
     }
 
- err_exit:
+ error:
     virNWFilterInstReset(&inst);
     virHashFree(missing_vars);
 
@@ -633,7 +633,7 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr techdriver,
     }
 
     rc = -1;
-    goto err_exit;
+    goto error;
 }
 
 
@@ -700,14 +700,14 @@ virNWFilterInstantiateFilterUpdate(virNWFilterDriverStatePtr driver,
     if (virNWFilterVarHashmapAddStdValue(binding->filterparams,
                                          NWFILTER_STD_VAR_MAC,
                                          vmmacaddr) < 0)
-        goto err_exit;
+        goto error;
 
     ipaddr = virNWFilterIPAddrMapGetIPAddr(binding->portdevname);
     if (ipaddr &&
         virNWFilterVarHashmapAddStdValue(binding->filterparams,
                                          NWFILTER_STD_VAR_IP,
                                          virNWFilterVarValueGetSimple(ipaddr)) < 0)
-        goto err_exit;
+        goto error;
 
 
     filter = virNWFilterObjGetDef(obj);
@@ -730,7 +730,7 @@ virNWFilterInstantiateFilterUpdate(virNWFilterDriverStatePtr driver,
                                   teardownOld, driver,
                                   forceWithPendingReq);
 
- err_exit:
+ error:
     virNWFilterObjUnlock(obj);
 
     return rc;
diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_learnipaddr.c
index c72ae23e4c..c6497450eb 100644
--- a/src/nwfilter/nwfilter_learnipaddr.c
+++ b/src/nwfilter/nwfilter_learnipaddr.c
@@ -157,7 +157,7 @@ virNWFilterLockIface(const char *ifname)
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("mutex initialization failed"));
             g_free(ifaceLock);
-            goto err_exit;
+            goto error;
         }
 
         if (virStrcpyStatic(ifaceLock->ifname, ifname) < 0) {
@@ -166,12 +166,12 @@ virNWFilterLockIface(const char *ifname)
                              "buffer "),
                            ifaceLock->ifname);
             g_free(ifaceLock);
-            goto err_exit;
+            goto error;
         }
 
         while (virHashAddEntry(ifaceLockMap, ifname, ifaceLock)) {
             g_free(ifaceLock);
-            goto err_exit;
+            goto error;
         }
 
         ifaceLock->refctr = 0;
@@ -185,7 +185,7 @@ virNWFilterLockIface(const char *ifname)
 
     return 0;
 
- err_exit:
+ error:
     virMutexUnlock(&ifaceMapLock);
 
     return -1;
@@ -413,7 +413,7 @@ learnIPAddressThread(void *arg)
     if (virNetDevValidateConfig(req->binding->portdevname, NULL, req->ifindex) <= 0) {
         virResetLastError();
         req->status = ENODEV;
-        goto done;
+        goto cleanup;
     }
 
     handle = pcap_open_live(listen_if, BUFSIZ, 0, PKT_TIMEOUT_MS, errbuf);
@@ -421,7 +421,7 @@ learnIPAddressThread(void *arg)
     if (handle == NULL) {
         VIR_DEBUG("Couldn't open device %s: %s", listen_if, errbuf);
         req->status = ENODEV;
-        goto done;
+        goto cleanup;
     }
 
     fds[0].fd = pcap_fileno(handle);
@@ -435,7 +435,7 @@ learnIPAddressThread(void *arg)
                                            NULL, false) < 0) {
             VIR_DEBUG("Unable to apply DHCP only rules");
             req->status = EINVAL;
-            goto done;
+            goto cleanup;
         }
         virBufferAddLit(&buf, "src port 67 and dst port 68");
     } else {
@@ -443,7 +443,7 @@ learnIPAddressThread(void *arg)
                                         &req->binding->mac) < 0) {
             VIR_DEBUG("Unable to apply basic rules");
             req->status = EINVAL;
-            goto done;
+            goto cleanup;
         }
         virBufferAsprintf(&buf, "ether host %s or ether dst ff:ff:ff:ff:ff:ff",
                           macaddr);
@@ -454,14 +454,14 @@ learnIPAddressThread(void *arg)
     if (pcap_compile(handle, &fp, filter, 1, 0) != 0) {
         VIR_DEBUG("Couldn't compile filter '%s'", filter);
         req->status = EINVAL;
-        goto done;
+        goto cleanup;
     }
 
     if (pcap_setfilter(handle, &fp) != 0) {
         VIR_DEBUG("Couldn't set filter '%s'", filter);
         req->status = EINVAL;
         pcap_freecode(&fp);
-        goto done;
+        goto cleanup;
     }
 
     pcap_freecode(&fp);
@@ -621,7 +621,7 @@ learnIPAddressThread(void *arg)
         }
     } /* while */
 
- done:
+ cleanup:
     if (handle)
         pcap_close(handle);
 
-- 
2.25.4




More information about the libvir-list mailing list