From 767a2621f07a4ba9a59a9d383581ed5558f667db Mon Sep 17 00:00:00 2001 From: bz Date: Sun, 2 Mar 2008 17:12:28 +0000 Subject: 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 --- sys/netipsec/key.c | 9 +++++++-- sys/netipsec/key_debug.c | 26 ++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) (limited to 'sys') 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 #include +#ifdef _KERNEL +#include +#endif #ifndef _KERNEL #include @@ -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] ? */ -- cgit v1.1