Hi Wataru,
On Mon, Mar 09, 2020 at 08:09:24PM +0900, Wataru Ashihara wrote:
> to improve readability.
>
> This is the first time of my commit to OpenBSD, so if I went something
> wrong, let me know that.
Thanks for sharing, committed!
>
> Index: sbin/iked/config.c
> ===================================================================
> RCS file: /cvs/src/sbin/iked/config.c,v
> retrieving revision 1.53
> diff -u -r1.53 config.c
> --- sbin/iked/config.c 16 Jan 2020 20:05:00 -0000 1.53
> +++ sbin/iked/config.c 9 Mar 2020 11:05:37 -0000
> @@ -258,11 +258,9 @@
> 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 @@
> 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 @@
> 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 @@
>
> 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);
> }
> }
> Index: sbin/iked/ikev2.c
> ===================================================================
> RCS file: /cvs/src/sbin/iked/ikev2.c,v
> retrieving revision 1.190
> diff -u -r1.190 ikev2.c
> --- sbin/iked/ikev2.c 1 Mar 2020 19:17:58 -0000 1.190
> +++ sbin/iked/ikev2.c 9 Mar 2020 11:05:37 -0000
> @@ -3701,9 +3701,9 @@
> 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 @@
> 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 @@
> 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 @@
> }
> }
> /* 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 @@
> 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)) ||
> Index: sbin/iked/policy.c
> ===================================================================
> RCS file: /cvs/src/sbin/iked/policy.c,v
> retrieving revision 1.55
> diff -u -r1.55 policy.c
> --- sbin/iked/policy.c 1 Mar 2020 19:17:58 -0000 1.55
> +++ sbin/iked/policy.c 9 Mar 2020 11:05:38 -0000
> @@ -512,11 +512,9 @@
> 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)
>