Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/netipsec Provide foreach macros for SA states (NFCI)
details: https://anonhg.NetBSD.org/src/rev/ceaa0bffaa04
branches: trunk
changeset: 353483:ceaa0bffaa04
user: ozaki-r <ozaki-r%NetBSD.org@localhost>
date: Tue May 09 04:18:51 2017 +0000
description:
Provide foreach macros for SA states (NFCI)
diffstat:
sys/netipsec/key.c | 66 +++++++++++++++++++----------------------------------
1 files changed, 24 insertions(+), 42 deletions(-)
diffs (180 lines):
diff -r c64e6a5845a1 -r ceaa0bffaa04 sys/netipsec/key.c
--- a/sys/netipsec/key.c Tue May 09 04:17:13 2017 +0000
+++ b/sys/netipsec/key.c Tue May 09 04:18:51 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: key.c,v 1.119 2017/05/09 04:17:13 ozaki-r Exp $ */
+/* $NetBSD: key.c,v 1.120 2017/05/09 04:18:51 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.119 2017/05/09 04:17:13 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.120 2017/05/09 04:18:51 ozaki-r Exp $");
/*
* This code is referd to RFC 2367
@@ -171,6 +171,17 @@
SADB_SASTATE_LARVAL, SADB_SASTATE_DEAD
};
+#define SASTATE_ALIVE_FOREACH(s) \
+ for (int _i = 0; \
+ _i < __arraycount(saorder_state_alive) ? \
+ (s) = saorder_state_alive[_i], true : false; \
+ _i++)
+#define SASTATE_ANY_FOREACH(s) \
+ for (int _i = 0; \
+ _i < __arraycount(saorder_state_any) ? \
+ (s) = saorder_state_any[_i], true : false; \
+ _i++)
+
static const int minsize[] = {
sizeof(struct sadb_msg), /* SADB_EXT_RESERVED */
sizeof(struct sadb_sa), /* SADB_EXT_SA */
@@ -2852,7 +2863,7 @@
key_delsah(struct secashead *sah)
{
struct secasvar *sav, *nextsav;
- u_int stateidx, state;
+ u_int state;
int s;
int zombie = 0;
@@ -2861,11 +2872,7 @@
s = splsoftnet(); /*called from softclock()*/
/* searching all SA registerd in the secindex. */
- for (stateidx = 0;
- stateidx < _ARRAYLEN(saorder_state_any);
- stateidx++) {
-
- state = saorder_state_any[stateidx];
+ SASTATE_ANY_FOREACH(state) {
LIST_FOREACH_SAFE(sav, &sah->savtree[state], chain, nextsav) {
if (sav->refcnt == 0) {
/* sanity check */
@@ -3109,14 +3116,10 @@
key_getsavbyspi(struct secashead *sah, u_int32_t spi)
{
struct secasvar *sav;
- u_int stateidx, state;
+ u_int state;
/* search all status */
- for (stateidx = 0;
- stateidx < _ARRAYLEN(saorder_state_alive);
- stateidx++) {
-
- state = saorder_state_alive[stateidx];
+ SASTATE_ALIVE_FOREACH(state) {
LIST_FOREACH(sav, &sah->savtree[state], chain) {
/* sanity check */
@@ -5757,7 +5760,7 @@
struct secasindex saidx;
struct secashead *sah;
struct secasvar *sav, *nextsav;
- u_int stateidx, state;
+ u_int state;
int error;
src0 = (struct sadb_address *)(mhp->ext[SADB_EXT_ADDRESS_SRC]);
@@ -5777,10 +5780,7 @@
continue;
/* Delete all non-LARVAL SAs. */
- for (stateidx = 0;
- stateidx < _ARRAYLEN(saorder_state_alive);
- stateidx++) {
- state = saorder_state_alive[stateidx];
+ SASTATE_ALIVE_FOREACH(state) {
if (state == SADB_SASTATE_LARVAL)
continue;
LIST_FOREACH_SAFE(sav, &sah->savtree[state], chain,
@@ -6921,7 +6921,6 @@
struct secasvar *sav, *nextsav;
u_int16_t proto;
u_int8_t state;
- u_int stateidx;
KASSERT(so != NULL);
KASSERT(mhp != NULL);
@@ -6939,10 +6938,7 @@
&& proto != sah->saidx.proto)
continue;
- for (stateidx = 0;
- stateidx < _ARRAYLEN(saorder_state_alive);
- stateidx++) {
- state = saorder_state_any[stateidx];
+ SASTATE_ALIVE_FOREACH(state) {
LIST_FOREACH_SAFE(sav, &sah->savtree[state], chain,
nextsav) {
key_sa_chgstate(sav, SADB_SASTATE_DEAD);
@@ -6977,7 +6973,6 @@
struct secashead *sah;
struct secasvar *sav;
u_int16_t proto;
- u_int stateidx;
u_int8_t satype;
u_int8_t state;
int cnt;
@@ -6998,10 +6993,7 @@
proto != sah->saidx.proto)
continue;
- for (stateidx = 0;
- stateidx < _ARRAYLEN(saorder_state_any);
- stateidx++) {
- state = saorder_state_any[stateidx];
+ SASTATE_ANY_FOREACH(state) {
LIST_FOREACH(sav, &sah->savtree[state], chain) {
cnt++;
}
@@ -7028,10 +7020,7 @@
return (NULL);
}
- for (stateidx = 0;
- stateidx < _ARRAYLEN(saorder_state_any);
- stateidx++) {
- state = saorder_state_any[stateidx];
+ SASTATE_ANY_FOREACH(state) {
LIST_FOREACH(sav, &sah->savtree[state], chain) {
n = key_setdumpsa(sav, SADB_DUMP, satype,
--cnt, pid);
@@ -7940,7 +7929,6 @@
struct secashead *sah;
struct secasvar *sav;
u_int16_t proto;
- u_int stateidx;
u_int8_t satype;
u_int8_t state;
int cnt;
@@ -7959,10 +7947,7 @@
proto != sah->saidx.proto)
continue;
- for (stateidx = 0;
- stateidx < _ARRAYLEN(saorder_state_any);
- stateidx++) {
- state = saorder_state_any[stateidx];
+ SASTATE_ANY_FOREACH(state) {
LIST_FOREACH(sav, &sah->savtree[state], chain) {
cnt++;
}
@@ -7988,10 +7973,7 @@
return (NULL);
}
- for (stateidx = 0;
- stateidx < _ARRAYLEN(saorder_state_any);
- stateidx++) {
- state = saorder_state_any[stateidx];
+ SASTATE_ANY_FOREACH(state) {
LIST_FOREACH(sav, &sah->savtree[state], chain) {
n = key_setdumpsa(sav, SADB_DUMP, satype,
--cnt, pid);
Home |
Main Index |
Thread Index |
Old Index