summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorDamien Bergamini <damien@cvs.openbsd.org>2008-04-17 18:05:34 +0000
committerDamien Bergamini <damien@cvs.openbsd.org>2008-04-17 18:05:34 +0000
commit58bd3d5d1f8766fb6f7af3e51dc4bf9ea504389a (patch)
tree1cadf8d2b7f151678024452de190319bf925f7b9 /sys
parent7d4b1c6f2891eacf9056f14e8d50e8cc4aba0bc0 (diff)
call ieee80211_crc_init() only once, when the first 802.11 device
attaches instead of at every attach. discussed with deraadt@
Diffstat (limited to 'sys')
-rw-r--r--sys/net80211/ieee80211_crypto.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/sys/net80211/ieee80211_crypto.c b/sys/net80211/ieee80211_crypto.c
index 7147980a019..99ecfd68a5f 100644
--- a/sys/net80211/ieee80211_crypto.c
+++ b/sys/net80211/ieee80211_crypto.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ieee80211_crypto.c,v 1.37 2008/04/16 18:32:15 damien Exp $ */
+/* $OpenBSD: ieee80211_crypto.c,v 1.38 2008/04/17 18:05:33 damien Exp $ */
/*-
* Copyright (c) 2008 Damien Bergamini <damien.bergamini@free.fr>
@@ -64,7 +64,7 @@ void ieee80211_derive_gtk(const u_int8_t *, size_t, const u_int8_t *,
void
ieee80211_crypto_attach(struct ifnet *ifp)
{
- ieee80211_crc_init(); /* XXX only once? */
+ ieee80211_crc_init();
}
void
@@ -220,19 +220,24 @@ ieee80211_decrypt(struct ieee80211com *ic, struct mbuf *m0,
}
/*
- * CRC 32 -- routine from RFC 2083
+ * CRC (Cyclic Redundancy Check) (routine from RFC 2083).
*/
-/* Table of CRCs of all 8-bit messages */
+/* Table of CRCs of all 8-bit messages. */
static u_int32_t ieee80211_crc_table[256];
/* Make the table for a fast CRC. */
void
ieee80211_crc_init(void)
{
+ /* Flag: has the table been computed? Initially false. */
+ static int crc_table_computed = 0;
u_int32_t c;
int n, k;
+ if (crc_table_computed)
+ return;
+
for (n = 0; n < 256; n++) {
c = (u_int32_t)n;
for (k = 0; k < 8; k++) {
@@ -243,12 +248,13 @@ ieee80211_crc_init(void)
}
ieee80211_crc_table[n] = c;
}
+ crc_table_computed = 1;
}
/*
* Update a running CRC with the bytes buf[0..len-1]--the CRC
* should be initialized to all 1's, and the transmitted value
- * is the 1's complement of the final running CRC
+ * is the 1's complement of the final running CRC.
*/
u_int32_t
ieee80211_crc_update(u_int32_t crc, const u_int8_t *buf, int len)