summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/net/pfkeyv2.c9
-rw-r--r--sys/netinet/ip_ipsp.c59
-rw-r--r--sys/netinet/ip_ipsp.h3
3 files changed, 37 insertions, 34 deletions
diff --git a/sys/net/pfkeyv2.c b/sys/net/pfkeyv2.c
index 0189dfaa5da..543faa42898 100644
--- a/sys/net/pfkeyv2.c
+++ b/sys/net/pfkeyv2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfkeyv2.c,v 1.56 2001/03/15 06:30:57 mickey Exp $ */
+/* $OpenBSD: pfkeyv2.c,v 1.57 2001/03/27 14:45:21 art Exp $ */
/*
%%% copyright-nrl-97
This software is Copyright 1997-1998 by Randall Atkinson, Ronald Lee,
@@ -1321,9 +1321,7 @@ pfkeyv2_send(struct socket *socket, void *message, int len)
int alg;
/* Create new TDB */
- MALLOC(freeme, struct tdb *, sizeof(struct tdb),
- M_TDB, M_WAITOK);
- bzero(freeme, sizeof(struct tdb));
+ freeme = tdb_alloc();
bzero(&ii, sizeof(struct ipsecinit));
newsa = (struct tdb *) freeme;
@@ -1431,8 +1429,7 @@ pfkeyv2_send(struct socket *socket, void *message, int len)
}
/* Allocate and initialize new TDB */
- MALLOC(freeme, struct tdb *, sizeof(struct tdb), M_TDB, M_WAITOK);
- bzero(freeme, sizeof(struct tdb));
+ freeme = tdb_alloc();
{
struct tdb *newsa = (struct tdb *) freeme;
diff --git a/sys/netinet/ip_ipsp.c b/sys/netinet/ip_ipsp.c
index 135f36048bd..c4b83425334 100644
--- a/sys/netinet/ip_ipsp.c
+++ b/sys/netinet/ip_ipsp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip_ipsp.c,v 1.109 2001/03/15 06:30:59 mickey Exp $ */
+/* $OpenBSD: ip_ipsp.c,v 1.110 2001/03/27 14:45:22 art Exp $ */
/*
* The authors of this code are John Ioannidis (ji@tla.org),
@@ -238,8 +238,7 @@ reserve_spi(u_int32_t sspi, u_int32_t tspi, union sockaddr_union *src,
if (tdbp != (struct tdb *) NULL)
continue;
- MALLOC(tdbp, struct tdb *, sizeof(struct tdb), M_TDB, M_WAITOK);
- bzero((caddr_t) tdbp, sizeof(struct tdb));
+ tdbp = tdb_alloc();
tdbp->tdb_spi = spi;
bcopy(&dst->sa, &tdbp->tdb_dst.sa, SA_LEN(&dst->sa));
@@ -247,16 +246,8 @@ reserve_spi(u_int32_t sspi, u_int32_t tspi, union sockaddr_union *src,
tdbp->tdb_sproto = sproto;
tdbp->tdb_flags |= TDBF_INVALID; /* Mark SA as invalid for now */
tdbp->tdb_satype = SADB_SATYPE_UNSPEC;
- tdbp->tdb_established = time.tv_sec;
- tdbp->tdb_epoch = kernfs_epoch - 1;
puttdb(tdbp);
- /* Initialize timeouts */
- timeout_set(&tdbp->tdb_timer_tmo, tdb_timeout, tdbp);
- timeout_set(&tdbp->tdb_first_tmo, tdb_firstuse, tdbp);
- timeout_set(&tdbp->tdb_stimer_tmo, tdb_soft_timeout, tdbp);
- timeout_set(&tdbp->tdb_sfirst_tmo, tdb_soft_firstuse, tdbp);
-
/* Setup a "silent" expiration (since TDBF_INVALID's set) */
if (ipsec_keep_invalid > 0)
{
@@ -749,28 +740,42 @@ tdb_delete(struct tdb *tdbp)
}
/*
- * Initialize a TDB structure.
+ * Allocate a TDB and initialize a few basic fields.
*/
-int
-tdb_init(struct tdb *tdbp, u_int16_t alg, struct ipsecinit *ii)
+struct tdb *
+tdb_alloc(void)
{
- struct xformsw *xsp;
- int err;
+ struct tdb *tdbp;
- /* Record establishment time */
- tdbp->tdb_established = time.tv_sec;
- tdbp->tdb_epoch = kernfs_epoch - 1;
+ MALLOC(tdbp, struct tdb *, sizeof(struct tdb), M_TDB, M_WAITOK);
+ bzero((caddr_t) tdbp, sizeof(struct tdb));
- /* Initialize timeouts */
- timeout_set(&tdbp->tdb_timer_tmo, tdb_timeout, tdbp);
- timeout_set(&tdbp->tdb_first_tmo, tdb_firstuse, tdbp);
- timeout_set(&tdbp->tdb_stimer_tmo, tdb_soft_timeout, tdbp);
- timeout_set(&tdbp->tdb_sfirst_tmo, tdb_soft_firstuse, tdbp);
+ /* Init Incoming SA-Binding Queues */
+ TAILQ_INIT(&tdbp->tdb_inp);
- /* Init Incoming SA-Binding Queues */
- TAILQ_INIT(&tdbp->tdb_inp);
+ TAILQ_INIT(&tdbp->tdb_policy_head);
- TAILQ_INIT(&tdbp->tdb_policy_head);
+ /* Record establishment time */
+ tdbp->tdb_established = time.tv_sec;
+ tdbp->tdb_epoch = kernfs_epoch - 1;
+
+ /* Initialize timeouts */
+ timeout_set(&tdbp->tdb_timer_tmo, tdb_timeout, tdbp);
+ timeout_set(&tdbp->tdb_first_tmo, tdb_firstuse, tdbp);
+ timeout_set(&tdbp->tdb_stimer_tmo, tdb_soft_timeout, tdbp);
+ timeout_set(&tdbp->tdb_sfirst_tmo, tdb_soft_firstuse, tdbp);
+
+ return tdbp;
+}
+
+/*
+ * Do further initializations of a TDB.
+ */
+int
+tdb_init(struct tdb *tdbp, u_int16_t alg, struct ipsecinit *ii)
+{
+ struct xformsw *xsp;
+ int err;
for (xsp = xformsw; xsp < xformswNXFORMSW; xsp++)
if (xsp->xf_type == alg)
diff --git a/sys/netinet/ip_ipsp.h b/sys/netinet/ip_ipsp.h
index 7f834d72728..78f4298868f 100644
--- a/sys/netinet/ip_ipsp.h
+++ b/sys/netinet/ip_ipsp.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip_ipsp.h,v 1.80 2001/03/15 06:31:00 mickey Exp $ */
+/* $OpenBSD: ip_ipsp.h,v 1.81 2001/03/27 14:45:22 art Exp $ */
/*
* The authors of this code are John Ioannidis (ji@tla.org),
@@ -479,6 +479,7 @@ extern struct tdb *gettdbbysrc(union sockaddr_union *, u_int8_t,
struct mbuf *, int);
extern void puttdb(struct tdb *);
extern void tdb_delete(struct tdb *);
+extern struct tdb *tdb_alloc(void);
extern int tdb_init(struct tdb *, u_int16_t, struct ipsecinit *);
extern int tdb_walk(int (*)(struct tdb *, void *, int), void *);