diff options
author | tobhe <tobhe@cvs.openbsd.org> | 2020-03-09 11:50:44 +0000 |
---|---|---|
committer | tobhe <tobhe@cvs.openbsd.org> | 2020-03-09 11:50:44 +0000 |
commit | 8809a3d0d3a00b23e7e68438809b3e4561b02dfd (patch) | |
tree | ce17ad86a0e1f310936a88a94cf15dfab8a2a918 /sbin | |
parent | ab2399ae576acee0248fd18f61232c9b75ec39d4 (diff) |
Use TAILQ_FOREACH_SAFE instead of hand rolled loops.
From Wataru <wataash at wataash dot com>
ok patrick@
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/iked/config.c | 20 | ||||
-rw-r--r-- | sbin/iked/ikev2.c | 26 | ||||
-rw-r--r-- | sbin/iked/policy.c | 8 |
3 files changed, 19 insertions, 35 deletions
diff --git a/sbin/iked/config.c b/sbin/iked/config.c index 71f01cb5d54..13bf476f26f 100644 --- a/sbin/iked/config.c +++ b/sbin/iked/config.c @@ -1,4 +1,4 @@ -/* $OpenBSD: config.c,v 1.53 2020/01/16 20:05:00 tobhe Exp $ */ +/* $OpenBSD: config.c,v 1.54 2020/03/09 11:50:43 tobhe Exp $ */ /* * Copyright (c) 2019 Tobias Heider <tobias.heider@stusta.de> @@ -258,11 +258,9 @@ config_add_proposal(struct iked_proposals *head, unsigned int id, void config_free_proposals(struct iked_proposals *head, unsigned int proto) { - struct iked_proposal *prop, *next; - - for (prop = TAILQ_FIRST(head); prop != NULL; prop = next) { - next = TAILQ_NEXT(prop, prop_entry); + struct iked_proposal *prop, *proptmp; + TAILQ_FOREACH_SAFE(prop, head, prop_entry, proptmp) { /* Free any proposal or only selected SA proto */ if (proto != 0 && prop->prop_protoid != proto) continue; @@ -293,14 +291,12 @@ void config_free_childsas(struct iked *env, struct iked_childsas *head, struct iked_spi *peerspi, struct iked_spi *localspi) { - struct iked_childsa *csa, *nextcsa, *ipcomp; + struct iked_childsa *csa, *csatmp, *ipcomp; if (localspi != NULL) bzero(localspi, sizeof(*localspi)); - for (csa = TAILQ_FIRST(head); csa != NULL; csa = nextcsa) { - nextcsa = TAILQ_NEXT(csa, csa_entry); - + TAILQ_FOREACH_SAFE(csa, head, csa_entry, csatmp) { if (peerspi != NULL) { /* Only delete matching peer SPIs */ if (peerspi->spi != csa->csa_peerspi) @@ -511,7 +507,7 @@ config_setreset(struct iked *env, unsigned int mode, enum privsep_procid id) int config_getreset(struct iked *env, struct imsg *imsg) { - struct iked_policy *pol, *nextpol; + struct iked_policy *pol, *poltmp; struct iked_sa *sa, *nextsa; struct iked_user *usr, *nextusr; unsigned int mode; @@ -521,9 +517,7 @@ config_getreset(struct iked *env, struct imsg *imsg) if (mode == RESET_ALL || mode == RESET_POLICY) { log_debug("%s: flushing policies", __func__); - for (pol = TAILQ_FIRST(&env->sc_policies); - pol != NULL; pol = nextpol) { - nextpol = TAILQ_NEXT(pol, pol_entry); + TAILQ_FOREACH_SAFE(pol, &env->sc_policies, pol_entry, poltmp) { config_free_policy(env, pol); } } diff --git a/sbin/iked/ikev2.c b/sbin/iked/ikev2.c index f0b93ec71b2..39b111a25c0 100644 --- a/sbin/iked/ikev2.c +++ b/sbin/iked/ikev2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ikev2.c,v 1.190 2020/03/01 19:17:58 tobhe Exp $ */ +/* $OpenBSD: ikev2.c,v 1.191 2020/03/09 11:50:43 tobhe Exp $ */ /* * Copyright (c) 2019 Tobias Heider <tobias.heider@stusta.de> @@ -3701,9 +3701,9 @@ done: int ikev2_ikesa_enable(struct iked *env, struct iked_sa *sa, struct iked_sa *nsa) { - struct iked_childsa *csa, *nextcsa, *ipcomp; - struct iked_flow *flow, *nextflow; - struct iked_proposal *prop, *nextprop; + struct iked_childsa *csa, *csatmp, *ipcomp; + struct iked_flow *flow, *flowtmp; + struct iked_proposal *prop, *proptmp; log_debug("%s: IKE SA %p ispi %s rspi %s replaced" " by SA %p ispi %s rspi %s ", @@ -3729,9 +3729,7 @@ ikev2_ikesa_enable(struct iked *env, struct iked_sa *sa, struct iked_sa *nsa) sizeof(nsa->sa_peer_loaded)); /* Transfer all Child SAs and flows from the old IKE SA */ - for (flow = TAILQ_FIRST(&sa->sa_flows); flow != NULL; - flow = nextflow) { - nextflow = TAILQ_NEXT(flow, flow_entry); + TAILQ_FOREACH_SAFE(flow, &sa->sa_flows, flow_entry, flowtmp) { TAILQ_REMOVE(&sa->sa_flows, flow, flow_entry); TAILQ_INSERT_TAIL(&nsa->sa_flows, flow, flow_entry); @@ -3739,9 +3737,7 @@ ikev2_ikesa_enable(struct iked *env, struct iked_sa *sa, struct iked_sa *nsa) flow->flow_local = &nsa->sa_local; flow->flow_peer = &nsa->sa_peer; } - for (csa = TAILQ_FIRST(&sa->sa_childsas); csa != NULL; - csa = nextcsa) { - nextcsa = TAILQ_NEXT(csa, csa_entry); + TAILQ_FOREACH_SAFE(csa, &sa->sa_childsas, csa_entry, csatmp) { TAILQ_REMOVE(&sa->sa_childsas, csa, csa_entry); TAILQ_INSERT_TAIL(&nsa->sa_childsas, csa, csa_entry); @@ -3760,9 +3756,7 @@ ikev2_ikesa_enable(struct iked *env, struct iked_sa *sa, struct iked_sa *nsa) } } /* Transfer all non-IKE proposals */ - for (prop = TAILQ_FIRST(&sa->sa_proposals); prop != NULL; - prop = nextprop) { - nextprop = TAILQ_NEXT(prop, prop_entry); + TAILQ_FOREACH_SAFE(prop, &sa->sa_proposals, prop_entry, proptmp) { if (prop->prop_protoid == IKEV2_SAPROTO_IKE) continue; TAILQ_REMOVE(&sa->sa_proposals, prop, prop_entry); @@ -5599,13 +5593,11 @@ int ikev2_childsa_delete(struct iked *env, struct iked_sa *sa, uint8_t saproto, uint64_t spi, uint64_t *spiptr, int cleanup) { - struct iked_childsa *csa, *nextcsa = NULL, *ipcomp; + struct iked_childsa *csa, *csatmp = NULL, *ipcomp; uint64_t peerspi = 0; int found = 0; - for (csa = TAILQ_FIRST(&sa->sa_childsas); csa != NULL; csa = nextcsa) { - nextcsa = TAILQ_NEXT(csa, csa_entry); - + TAILQ_FOREACH_SAFE(csa, &sa->sa_childsas, csa_entry, csatmp) { if ((saproto && csa->csa_saproto != saproto) || (spi && (csa->csa_spi.spi != spi && csa->csa_peerspi != spi)) || diff --git a/sbin/iked/policy.c b/sbin/iked/policy.c index 96070e50566..6c9baa9b619 100644 --- a/sbin/iked/policy.c +++ b/sbin/iked/policy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: policy.c,v 1.55 2020/03/01 19:17:58 tobhe Exp $ */ +/* $OpenBSD: policy.c,v 1.56 2020/03/09 11:50:43 tobhe Exp $ */ /* * Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org> @@ -512,11 +512,9 @@ sa_free(struct iked *env, struct iked_sa *sa) void sa_free_flows(struct iked *env, struct iked_saflows *head) { - struct iked_flow *flow, *next; - - for (flow = TAILQ_FIRST(head); flow != NULL; flow = next) { - next = TAILQ_NEXT(flow, flow_entry); + struct iked_flow *flow, *flowtmp; + TAILQ_FOREACH_SAFE(flow, head, flow_entry, flowtmp) { log_debug("%s: free %p", __func__, flow); if (flow->flow_loaded) |