Use LIST_* functions (NFC)
This commit is contained in:
parent
504ff72d98
commit
d9a74b87d3
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: key.c,v 1.118 2017/04/26 08:36:32 ozaki-r Exp $ */
|
||||
/* $NetBSD: key.c,v 1.119 2017/05/09 04:17:13 ozaki-r Exp $ */
|
||||
/* $FreeBSD: src/sys/netipsec/key.c,v 1.3.2.3 2004/02/14 22:23:23 bms Exp $ */
|
||||
/* $KAME: key.c,v 1.191 2001/06/27 10:46:49 sakane Exp $ */
|
||||
|
||||
@ -32,7 +32,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.118 2017/04/26 08:36:32 ozaki-r Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.119 2017/05/09 04:17:13 ozaki-r Exp $");
|
||||
|
||||
/*
|
||||
* This code is referd to RFC 2367
|
||||
@ -573,7 +573,7 @@ int
|
||||
key_havesp(u_int dir)
|
||||
{
|
||||
return (dir == IPSEC_DIR_INBOUND || dir == IPSEC_DIR_OUTBOUND ?
|
||||
LIST_FIRST(&sptree[dir]) != NULL : 1);
|
||||
!LIST_EMPTY(&sptree[dir]) : 1);
|
||||
}
|
||||
|
||||
/* %%% IPsec policy management */
|
||||
@ -927,17 +927,12 @@ key_allocsa_policy(const struct secasindex *saidx)
|
||||
static struct secasvar *
|
||||
key_do_allocsa_policy(struct secashead *sah, u_int state)
|
||||
{
|
||||
struct secasvar *sav, *nextsav, *candidate, *d;
|
||||
struct secasvar *sav, *candidate, *d;
|
||||
|
||||
/* initilize */
|
||||
candidate = NULL;
|
||||
|
||||
for (sav = LIST_FIRST(&sah->savtree[state]);
|
||||
sav != NULL;
|
||||
sav = nextsav) {
|
||||
|
||||
nextsav = LIST_NEXT(sav, chain);
|
||||
|
||||
LIST_FOREACH(sav, &sah->savtree[state], chain) {
|
||||
/* sanity check */
|
||||
KEY_CHKSASTATE(sav->state, state, "key_do_allocsa_policy");
|
||||
|
||||
@ -2395,11 +2390,7 @@ key_spdflush(struct socket *so, struct mbuf *m,
|
||||
|
||||
for (dir = 0; dir < IPSEC_DIR_MAX; dir++) {
|
||||
struct secpolicy * nextsp;
|
||||
for (sp = LIST_FIRST(&sptree[dir]);
|
||||
sp != NULL;
|
||||
sp = nextsp) {
|
||||
|
||||
nextsp = LIST_NEXT(sp, chain);
|
||||
LIST_FOREACH_SAFE(sp, &sptree[dir], chain, nextsp) {
|
||||
if (sp->state == IPSEC_SPSTATE_DEAD)
|
||||
continue;
|
||||
key_sp_dead(sp);
|
||||
@ -2875,12 +2866,7 @@ key_delsah(struct secashead *sah)
|
||||
stateidx++) {
|
||||
|
||||
state = saorder_state_any[stateidx];
|
||||
for (sav = (struct secasvar *)LIST_FIRST(&sah->savtree[state]);
|
||||
sav != NULL;
|
||||
sav = nextsav) {
|
||||
|
||||
nextsav = LIST_NEXT(sav, chain);
|
||||
|
||||
LIST_FOREACH_SAFE(sav, &sah->savtree[state], chain, nextsav) {
|
||||
if (sav->refcnt == 0) {
|
||||
/* sanity check */
|
||||
KEY_CHKSASTATE(state, sav->state, "key_delsah");
|
||||
@ -4542,12 +4528,7 @@ key_timehandler(void* arg)
|
||||
struct secpolicy *sp, *nextsp;
|
||||
|
||||
for (dir = 0; dir < IPSEC_DIR_MAX; dir++) {
|
||||
for (sp = LIST_FIRST(&sptree[dir]);
|
||||
sp != NULL;
|
||||
sp = nextsp) {
|
||||
|
||||
nextsp = LIST_NEXT(sp, chain);
|
||||
|
||||
LIST_FOREACH_SAFE(sp, &sptree[dir], chain, nextsp) {
|
||||
if (sp->state == IPSEC_SPSTATE_DEAD) {
|
||||
key_sp_unlink(sp); /*XXX*/
|
||||
|
||||
@ -4576,12 +4557,7 @@ key_timehandler(void* arg)
|
||||
struct secashead *sah, *nextsah;
|
||||
struct secasvar *sav, *nextsav;
|
||||
|
||||
for (sah = LIST_FIRST(&sahtree);
|
||||
sah != NULL;
|
||||
sah = nextsah) {
|
||||
|
||||
nextsah = LIST_NEXT(sah, chain);
|
||||
|
||||
LIST_FOREACH_SAFE(sah, &sahtree, chain, nextsah) {
|
||||
/* if sah has been dead, then delete it and process next sah. */
|
||||
if (sah->state == SADB_SASTATE_DEAD) {
|
||||
key_delsah(sah);
|
||||
@ -4589,12 +4565,8 @@ key_timehandler(void* arg)
|
||||
}
|
||||
|
||||
/* if LARVAL entry doesn't become MATURE, delete it. */
|
||||
for (sav = LIST_FIRST(&sah->savtree[SADB_SASTATE_LARVAL]);
|
||||
sav != NULL;
|
||||
sav = nextsav) {
|
||||
|
||||
nextsav = LIST_NEXT(sav, chain);
|
||||
|
||||
LIST_FOREACH_SAFE(sav, &sah->savtree[SADB_SASTATE_LARVAL],
|
||||
chain, nextsav) {
|
||||
if (now - sav->created > key_larval_lifetime) {
|
||||
KEY_FREESAV(&sav);
|
||||
}
|
||||
@ -4604,12 +4576,8 @@ key_timehandler(void* arg)
|
||||
* check MATURE entry to start to send expire message
|
||||
* whether or not.
|
||||
*/
|
||||
for (sav = LIST_FIRST(&sah->savtree[SADB_SASTATE_MATURE]);
|
||||
sav != NULL;
|
||||
sav = nextsav) {
|
||||
|
||||
nextsav = LIST_NEXT(sav, chain);
|
||||
|
||||
LIST_FOREACH_SAFE(sav, &sah->savtree[SADB_SASTATE_MATURE],
|
||||
chain, nextsav) {
|
||||
/* we don't need to check. */
|
||||
if (sav->lft_s == NULL)
|
||||
continue;
|
||||
@ -4661,12 +4629,8 @@ key_timehandler(void* arg)
|
||||
}
|
||||
|
||||
/* check DYING entry to change status to DEAD. */
|
||||
for (sav = LIST_FIRST(&sah->savtree[SADB_SASTATE_DYING]);
|
||||
sav != NULL;
|
||||
sav = nextsav) {
|
||||
|
||||
nextsav = LIST_NEXT(sav, chain);
|
||||
|
||||
LIST_FOREACH_SAFE(sav, &sah->savtree[SADB_SASTATE_DYING],
|
||||
chain, nextsav) {
|
||||
/* we don't need to check. */
|
||||
if (sav->lft_h == NULL)
|
||||
continue;
|
||||
@ -4708,12 +4672,8 @@ key_timehandler(void* arg)
|
||||
}
|
||||
|
||||
/* delete entry in DEAD */
|
||||
for (sav = LIST_FIRST(&sah->savtree[SADB_SASTATE_DEAD]);
|
||||
sav != NULL;
|
||||
sav = nextsav) {
|
||||
|
||||
nextsav = LIST_NEXT(sav, chain);
|
||||
|
||||
LIST_FOREACH_SAFE(sav, &sah->savtree[SADB_SASTATE_DEAD],
|
||||
chain, nextsav) {
|
||||
/* sanity check */
|
||||
if (sav->state != SADB_SASTATE_DEAD) {
|
||||
ipseclog((LOG_DEBUG, "key_timehandler: "
|
||||
@ -4738,12 +4698,7 @@ key_timehandler(void* arg)
|
||||
{
|
||||
struct secacq *acq, *nextacq;
|
||||
|
||||
for (acq = LIST_FIRST(&acqtree);
|
||||
acq != NULL;
|
||||
acq = nextacq) {
|
||||
|
||||
nextacq = LIST_NEXT(acq, chain);
|
||||
|
||||
LIST_FOREACH_SAFE(acq, &acqtree, chain, nextacq) {
|
||||
if (now - acq->created > key_blockacq_lifetime
|
||||
&& __LIST_CHAINED(acq)) {
|
||||
LIST_REMOVE(acq, chain);
|
||||
@ -4757,12 +4712,7 @@ key_timehandler(void* arg)
|
||||
{
|
||||
struct secspacq *acq, *nextacq;
|
||||
|
||||
for (acq = LIST_FIRST(&spacqtree);
|
||||
acq != NULL;
|
||||
acq = nextacq) {
|
||||
|
||||
nextacq = LIST_NEXT(acq, chain);
|
||||
|
||||
LIST_FOREACH_SAFE(acq, &spacqtree, chain, nextacq) {
|
||||
if (now - acq->created > key_blockacq_lifetime
|
||||
&& __LIST_CHAINED(acq)) {
|
||||
LIST_REMOVE(acq, chain);
|
||||
@ -5833,9 +5783,8 @@ key_delete_all(struct socket *so, struct mbuf *m,
|
||||
state = saorder_state_alive[stateidx];
|
||||
if (state == SADB_SASTATE_LARVAL)
|
||||
continue;
|
||||
for (sav = LIST_FIRST(&sah->savtree[state]);
|
||||
sav != NULL; sav = nextsav) {
|
||||
nextsav = LIST_NEXT(sav, chain);
|
||||
LIST_FOREACH_SAFE(sav, &sah->savtree[state], chain,
|
||||
nextsav) {
|
||||
/* sanity check */
|
||||
if (sav->state != state) {
|
||||
ipseclog((LOG_DEBUG, "key_delete_all: "
|
||||
@ -6968,7 +6917,7 @@ key_flush(struct socket *so, struct mbuf *m,
|
||||
const struct sadb_msghdr *mhp)
|
||||
{
|
||||
struct sadb_msg *newmsg;
|
||||
struct secashead *sah, *nextsah;
|
||||
struct secashead *sah;
|
||||
struct secasvar *sav, *nextsav;
|
||||
u_int16_t proto;
|
||||
u_int8_t state;
|
||||
@ -6985,11 +6934,7 @@ key_flush(struct socket *so, struct mbuf *m,
|
||||
}
|
||||
|
||||
/* no SATYPE specified, i.e. flushing all SA. */
|
||||
for (sah = LIST_FIRST(&sahtree);
|
||||
sah != NULL;
|
||||
sah = nextsah) {
|
||||
nextsah = LIST_NEXT(sah, chain);
|
||||
|
||||
LIST_FOREACH(sah, &sahtree, chain) {
|
||||
if (mhp->msg->sadb_msg_satype != SADB_SATYPE_UNSPEC
|
||||
&& proto != sah->saidx.proto)
|
||||
continue;
|
||||
@ -6998,12 +6943,8 @@ key_flush(struct socket *so, struct mbuf *m,
|
||||
stateidx < _ARRAYLEN(saorder_state_alive);
|
||||
stateidx++) {
|
||||
state = saorder_state_any[stateidx];
|
||||
for (sav = LIST_FIRST(&sah->savtree[state]);
|
||||
sav != NULL;
|
||||
sav = nextsav) {
|
||||
|
||||
nextsav = LIST_NEXT(sav, chain);
|
||||
|
||||
LIST_FOREACH_SAFE(sav, &sah->savtree[state], chain,
|
||||
nextsav) {
|
||||
key_sa_chgstate(sav, SADB_SASTATE_DEAD);
|
||||
KEY_FREESAV(&sav);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user