-/* $OpenBSD: pfkeyv2.c,v 1.223 2021/11/26 16:16:35 tobhe Exp $ */
+/* $OpenBSD: pfkeyv2.c,v 1.224 2021/11/29 15:39:59 bluhm Exp $ */
/*
* @(#)COPYRIGHT 1.1 (NRL) 17 January 1995
int alg;
/* Create new TDB */
- freeme_sz = 0;
- freeme = tdb_alloc(rdomain);
- bzero(&ii, sizeof(struct ipsecinit));
-
- newsa = (struct tdb *) freeme;
+ newsa = tdb_alloc(rdomain);
newsa->tdb_satype = smsg->sadb_msg_satype;
if ((rval = pfkeyv2_get_proto_alg(newsa->tdb_satype,
&newsa->tdb_sproto, &alg))) {
- tdb_unref(freeme);
- freeme = NULL;
+ tdb_unref(newsa);
NET_UNLOCK();
goto ret;
}
/* Initialize SA */
+ bzero(&ii, sizeof(struct ipsecinit));
import_sa(newsa, headers[SADB_EXT_SA], &ii);
import_address(&newsa->tdb_src.sa,
headers[SADB_EXT_ADDRESS_SRC]);
headers[SADB_X_EXT_DST_MASK],
headers[SADB_X_EXT_PROTOCOL],
headers[SADB_X_EXT_FLOW_TYPE]))) {
- tdb_unref(freeme);
- freeme = NULL;
+ tdb_unref(newsa);
NET_UNLOCK();
goto ret;
}
rval = tdb_init(newsa, alg, &ii);
if (rval) {
rval = EINVAL;
- tdb_unref(freeme);
- freeme = NULL;
+ tdb_unref(newsa);
NET_UNLOCK();
goto ret;
}
/* Delete old version of the SA, insert new one */
tdb_delete(sa2);
- puttdb((struct tdb *) freeme);
- freeme = NULL;
+ puttdb(newsa);
} else {
/*
* The SA is already initialized, so we're only allowed to
goto ret;
}
- /* Allocate and initialize new TDB */
- freeme_sz = 0;
- freeme = tdb_alloc(rdomain);
-
{
- struct tdb *newsa = (struct tdb *) freeme;
+ struct tdb *newsa;
struct ipsecinit ii;
int alg;
- bzero(&ii, sizeof(struct ipsecinit));
-
+ /* Create new TDB */
+ newsa = tdb_alloc(rdomain);
newsa->tdb_satype = smsg->sadb_msg_satype;
+
if ((rval = pfkeyv2_get_proto_alg(newsa->tdb_satype,
&newsa->tdb_sproto, &alg))) {
- tdb_unref(freeme);
- freeme = NULL;
+ tdb_unref(newsa);
NET_UNLOCK();
goto ret;
}
+ /* Initialize SA */
+ bzero(&ii, sizeof(struct ipsecinit));
import_sa(newsa, headers[SADB_EXT_SA], &ii);
import_address(&newsa->tdb_src.sa,
headers[SADB_EXT_ADDRESS_SRC]);
headers[SADB_X_EXT_DST_MASK],
headers[SADB_X_EXT_PROTOCOL],
headers[SADB_X_EXT_FLOW_TYPE]))) {
- tdb_unref(freeme);
- freeme = NULL;
+ tdb_unref(newsa);
NET_UNLOCK();
goto ret;
}
rval = tdb_init(newsa, alg, &ii);
if (rval) {
rval = EINVAL;
- tdb_unref(freeme);
- freeme = NULL;
+ tdb_unref(newsa);
NET_UNLOCK();
goto ret;
}
- }
- /* Add TDB in table */
- puttdb((struct tdb *) freeme);
+ /* Add TDB in table */
+ puttdb(newsa);
+ }
NET_UNLOCK();
- freeme = NULL;
break;
case SADB_DELETE: