summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorbz <bz@FreeBSD.org>2008-03-02 17:12:28 +0000
committerbz <bz@FreeBSD.org>2008-03-02 17:12:28 +0000
commit767a2621f07a4ba9a59a9d383581ed5558f667db (patch)
tree9e4f7f34605a0e72d8b6dd6e4df767cbae80a7aa /sys
parent3dea77f93cd358a469b5ae398a5e67d559db283a (diff)
downloadFreeBSD-src-767a2621f07a4ba9a59a9d383581ed5558f667db.zip
FreeBSD-src-767a2621f07a4ba9a59a9d383581ed5558f667db.tar.gz
Fix bugs when allocating and passing information of current lifetime and
soft lifetime [1] introduced in rev. 1.21 of key.c. Along with that, fix a related problem in key_debug printing the correct data. While there replace a printf by panic in a sanity check. PR: 120751 Submitted by: Kazuaki ODA (kazuaki aliceblue.jp) [1] MFC after: 5 days
Diffstat (limited to 'sys')
-rw-r--r--sys/netipsec/key.c9
-rw-r--r--sys/netipsec/key_debug.c26
2 files changed, 29 insertions, 6 deletions
diff --git a/sys/netipsec/key.c b/sys/netipsec/key.c
index 5dfc32f..5ce367d 100644
--- a/sys/netipsec/key.c
+++ b/sys/netipsec/key.c
@@ -3137,7 +3137,7 @@ key_setsaval(sav, m, mhp)
sav->created = time_second;
/* make lifetime for CURRENT */
- sav->lft_c = malloc(sizeof(struct sadb_lifetime), M_IPSEC_MISC, M_NOWAIT);
+ sav->lft_c = malloc(sizeof(struct seclifetime), M_IPSEC_MISC, M_NOWAIT);
if (sav->lft_c == NULL) {
ipseclog((LOG_DEBUG, "%s: No more memory.\n", __func__));
error = ENOBUFS;
@@ -6323,7 +6323,12 @@ key_expire(struct secasvar *sav)
lt->sadb_lifetime_addtime = sav->lft_c->addtime;
lt->sadb_lifetime_usetime = sav->lft_c->usetime;
lt = (struct sadb_lifetime *)(mtod(m, caddr_t) + len / 2);
- bcopy(sav->lft_s, lt, sizeof(*lt));
+ lt->sadb_lifetime_len = PFKEY_UNIT64(sizeof(struct sadb_lifetime));
+ lt->sadb_lifetime_exttype = SADB_EXT_LIFETIME_SOFT;
+ lt->sadb_lifetime_allocations = sav->lft_s->allocations;
+ lt->sadb_lifetime_bytes = sav->lft_s->bytes;
+ lt->sadb_lifetime_addtime = sav->lft_s->addtime;
+ lt->sadb_lifetime_usetime = sav->lft_s->usetime;
m_cat(result, m);
/* set sadb_address for source */
diff --git a/sys/netipsec/key_debug.c b/sys/netipsec/key_debug.c
index 7252ea0..7acc266 100644
--- a/sys/netipsec/key_debug.c
+++ b/sys/netipsec/key_debug.c
@@ -52,6 +52,9 @@
#include <netinet/in.h>
#include <netipsec/ipsec.h>
+#ifdef _KERNEL
+#include <netipsec/keydb.h>
+#endif
#ifndef _KERNEL
#include <ctype.h>
@@ -296,7 +299,7 @@ kdebug_sadb_lifetime(ext)
/* sanity check */
if (ext == NULL)
- printf("%s: NULL pointer was passed.\n", __func__);
+ panic("%s: NULL pointer was passed.\n", __func__);
printf("sadb_lifetime{ alloc=%u, bytes=%u\n",
lft->sadb_lifetime_allocations,
@@ -553,6 +556,21 @@ kdebug_secasindex(saidx)
return;
}
+static void
+kdebug_sec_lifetime(struct seclifetime *lft)
+{
+ /* sanity check */
+ if (lft == NULL)
+ panic("%s: NULL pointer was passed.\n", __func__);
+
+ printf("sec_lifetime{ alloc=%u, bytes=%u\n",
+ lft->allocations, (u_int32_t)lft->bytes);
+ printf(" addtime=%u, usetime=%u }\n",
+ (u_int32_t)lft->addtime, (u_int32_t)lft->usetime);
+
+ return;
+}
+
void
kdebug_secasv(sav)
struct secasvar *sav;
@@ -582,11 +600,11 @@ kdebug_secasv(sav)
if (sav->replay != NULL)
kdebug_secreplay(sav->replay);
if (sav->lft_c != NULL)
- kdebug_sadb_lifetime((struct sadb_ext *)sav->lft_c);
+ kdebug_sec_lifetime(sav->lft_c);
if (sav->lft_h != NULL)
- kdebug_sadb_lifetime((struct sadb_ext *)sav->lft_h);
+ kdebug_sec_lifetime(sav->lft_h);
if (sav->lft_s != NULL)
- kdebug_sadb_lifetime((struct sadb_ext *)sav->lft_s);
+ kdebug_sec_lifetime(sav->lft_s);
#ifdef notyet
/* XXX: misc[123] ? */
OpenPOWER on IntegriCloud