Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src-draft/trunk]: src/sys/net80211 Do not use malloc(9) directly, abstract v...
details: https://anonhg.NetBSD.org/src-all/rev/78e02a9939ae
branches: trunk
changeset: 949103:78e02a9939ae
user: Martin Husemann <martin%NetBSD.org@localhost>
date: Thu Dec 10 18:26:08 2020 +0100
description:
Do not use malloc(9) directly, abstract various uses.
In the process of removing all malloc(9) calls, separate the various
different uses and map them via macros to different functions depending
on context.
Move a few more calls to thread context by changing timeout processing
from a callout to a taskqueue.
diffstat:
sys/net80211/ieee80211.c | 7 +--
sys/net80211/ieee80211_acl.c | 19 ++++----
sys/net80211/ieee80211_action.c | 1 -
sys/net80211/ieee80211_adhoc.c | 1 -
sys/net80211/ieee80211_ageq.c | 1 -
sys/net80211/ieee80211_alq.c | 1 -
sys/net80211/ieee80211_amrr.c | 16 ++++---
sys/net80211/ieee80211_crypto.c | 6 ++-
sys/net80211/ieee80211_crypto.h | 6 ++
sys/net80211/ieee80211_crypto_ccmp.c | 35 +++++++++++++-
sys/net80211/ieee80211_crypto_none.c | 1 -
sys/net80211/ieee80211_crypto_tkip.c | 35 +++++++++++++-
sys/net80211/ieee80211_crypto_wep.c | 35 +++++++++++++-
sys/net80211/ieee80211_ddb.c | 1 -
sys/net80211/ieee80211_dfs.c | 1 -
sys/net80211/ieee80211_hostap.c | 7 +-
sys/net80211/ieee80211_ht.c | 1 -
sys/net80211/ieee80211_hwmp.c | 35 ++++++++------
sys/net80211/ieee80211_input.c | 3 +-
sys/net80211/ieee80211_ioctl.c | 78 ++++++++++++++++++----------------
sys/net80211/ieee80211_mesh.c | 29 ++++++------
sys/net80211/ieee80211_monitor.c | 1 -
sys/net80211/ieee80211_netbsd.c | 6 +--
sys/net80211/ieee80211_netbsd.h | 57 +++++++++++++++++++++----
sys/net80211/ieee80211_node.c | 61 ++++++++++++++-------------
sys/net80211/ieee80211_node.h | 2 +-
sys/net80211/ieee80211_output.c | 4 +-
sys/net80211/ieee80211_phy.c | 1 -
sys/net80211/ieee80211_power.c | 8 +-
sys/net80211/ieee80211_proto.c | 4 +-
sys/net80211/ieee80211_radiotap.c | 1 -
sys/net80211/ieee80211_ratectl.c | 1 -
sys/net80211/ieee80211_ratectl_none.c | 5 +-
sys/net80211/ieee80211_regdomain.c | 11 ++--
sys/net80211/ieee80211_rssadapt.c | 15 +++---
sys/net80211/ieee80211_scan.c | 1 -
sys/net80211/ieee80211_scan_sta.c | 47 +++++++++++++++++----
sys/net80211/ieee80211_scan_sw.c | 20 +++-----
sys/net80211/ieee80211_sta.c | 4 +-
sys/net80211/ieee80211_superg.c | 6 +-
sys/net80211/ieee80211_tdma.c | 7 +-
sys/net80211/ieee80211_var.h | 4 +-
sys/net80211/ieee80211_vht.c | 1 -
sys/net80211/ieee80211_wds.c | 1 -
sys/net80211/ieee80211_xauth.c | 1 -
45 files changed, 369 insertions(+), 219 deletions(-)
diffs (truncated from 1960 to 300 lines):
diff -r 50b3e6fc37bd -r 78e02a9939ae sys/net80211/ieee80211.c
--- a/sys/net80211/ieee80211.c Thu Dec 10 18:22:42 2020 +0100
+++ b/sys/net80211/ieee80211.c Thu Dec 10 18:26:08 2020 +0100
@@ -46,7 +46,6 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
-#include <sys/malloc.h>
#include <sys/socket.h>
#include <sys/sbuf.h>
#include <sys/cprng.h>
@@ -489,9 +488,7 @@
LIST_REMOVE(ic, ic_next);
mtx_unlock(&ic_list_mtx);
-#if __FreeBSD__
- taskqueue_drain(taskqueue_thread, &ic->ic_restart_task);
-#endif
+ taskqueue_drain(ic->ic_tq, &ic->ic_restart_task);
/*
* The VAP is responsible for setting and clearing
@@ -518,7 +515,7 @@
ieee80211_power_detach(ic);
ieee80211_node_detach(ic);
-#if __FreeBSD__
+#if __FreeBSD__
counter_u64_free(ic->ic_ierrors);
counter_u64_free(ic->ic_oerrors);
#endif
diff -r 50b3e6fc37bd -r 78e02a9939ae sys/net80211/ieee80211_acl.c
--- a/sys/net80211/ieee80211_acl.c Thu Dec 10 18:22:42 2020 +0100
+++ b/sys/net80211/ieee80211_acl.c Thu Dec 10 18:26:08 2020 +0100
@@ -53,7 +53,6 @@
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/systm.h>
-#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/module.h>
#include <sys/queue.h>
@@ -117,8 +116,8 @@
{
struct aclstate *as;
- as = (struct aclstate *) IEEE80211_MALLOC(sizeof(struct aclstate),
- M_80211_ACL, IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
+ as = (struct aclstate *) IEEE80211_ZALLOC(sizeof(struct aclstate),
+ M_80211_ACL, IEEE80211_M_NOWAIT);
if (as == NULL)
return 0;
ACL_LOCK_INIT(as, "acl");
@@ -141,7 +140,7 @@
acl_free_all(vap);
vap->iv_as = NULL;
ACL_LOCK_DESTROY(as);
- IEEE80211_FREE(as, M_80211_ACL);
+ IEEE80211_FREE(as, M_80211_ACL, sizeof(*as));
}
static __inline struct acl *
@@ -165,7 +164,7 @@
TAILQ_REMOVE(&as->as_list, acl, acl_list);
LIST_REMOVE(acl, acl_hash);
- IEEE80211_FREE(acl, M_80211_ACL);
+ IEEE80211_FREE(acl, M_80211_ACL, sizeof(*acl));
as->as_nacls--;
}
@@ -193,8 +192,8 @@
struct acl *acl, *new;
int hash;
- new = (struct acl *) IEEE80211_MALLOC(sizeof(struct acl),
- M_80211_ACL, IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
+ new = (struct acl *) IEEE80211_ZALLOC(sizeof(struct acl),
+ M_80211_ACL, IEEE80211_M_NOWAIT);
if (new == NULL) {
IEEE80211_DPRINTF(vap, IEEE80211_MSG_ACL,
"ACL: add %s failed, no memory\n", ether_sprintf(mac));
@@ -207,7 +206,7 @@
LIST_FOREACH(acl, &as->as_hash[hash], acl_hash) {
if (IEEE80211_ADDR_EQ(acl->acl_macaddr, mac)) {
ACL_UNLOCK(as);
- IEEE80211_FREE(new, M_80211_ACL);
+ IEEE80211_FREE(new, M_80211_ACL, sizeof(*new));
IEEE80211_DPRINTF(vap, IEEE80211_MSG_ACL,
"ACL: add %s failed, already present\n",
ether_sprintf(mac));
@@ -321,7 +320,7 @@
ireq->i_len = space; /* return required space */
return 0; /* NB: must not error */
}
- ap = (struct ieee80211req_maclist *) IEEE80211_MALLOC(space,
+ ap = (struct ieee80211req_maclist *) IEEE80211_ALLOC(space,
M_TEMP, IEEE80211_M_NOWAIT);
if (ap == NULL)
return ENOMEM;
@@ -337,7 +336,7 @@
ireq->i_len = space;
} else
error = copyout(ap, ireq->i_data, ireq->i_len);
- IEEE80211_FREE(ap, M_TEMP);
+ IEEE80211_FREE(ap, M_TEMP, space);
return error;
}
return EINVAL;
diff -r 50b3e6fc37bd -r 78e02a9939ae sys/net80211/ieee80211_action.c
--- a/sys/net80211/ieee80211_action.c Thu Dec 10 18:22:42 2020 +0100
+++ b/sys/net80211/ieee80211_action.c Thu Dec 10 18:26:08 2020 +0100
@@ -46,7 +46,6 @@
#include <sys/param.h>
#include <sys/kernel.h>
-#include <sys/malloc.h>
#include <sys/systm.h>
#include <sys/socket.h>
diff -r 50b3e6fc37bd -r 78e02a9939ae sys/net80211/ieee80211_adhoc.c
--- a/sys/net80211/ieee80211_adhoc.c Thu Dec 10 18:22:42 2020 +0100
+++ b/sys/net80211/ieee80211_adhoc.c Thu Dec 10 18:26:08 2020 +0100
@@ -46,7 +46,6 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/mbuf.h>
-#include <sys/malloc.h>
#include <sys/kernel.h>
#include <sys/socket.h>
diff -r 50b3e6fc37bd -r 78e02a9939ae sys/net80211/ieee80211_ageq.c
--- a/sys/net80211/ieee80211_ageq.c Thu Dec 10 18:22:42 2020 +0100
+++ b/sys/net80211/ieee80211_ageq.c Thu Dec 10 18:26:08 2020 +0100
@@ -45,7 +45,6 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
-#include <sys/malloc.h>
#ifdef __NetBSD__
#include <sys/mbuf.h>
#endif
diff -r 50b3e6fc37bd -r 78e02a9939ae sys/net80211/ieee80211_alq.c
--- a/sys/net80211/ieee80211_alq.c Thu Dec 10 18:22:42 2020 +0100
+++ b/sys/net80211/ieee80211_alq.c Thu Dec 10 18:26:08 2020 +0100
@@ -49,7 +49,6 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/mbuf.h>
-#include <sys/malloc.h>
#include <sys/endian.h>
#include <sys/kernel.h>
#include <sys/sysctl.h>
diff -r 50b3e6fc37bd -r 78e02a9939ae sys/net80211/ieee80211_amrr.c
--- a/sys/net80211/ieee80211_amrr.c Thu Dec 10 18:22:42 2020 +0100
+++ b/sys/net80211/ieee80211_amrr.c Thu Dec 10 18:26:08 2020 +0100
@@ -43,7 +43,6 @@
#include <sys/param.h>
#include <sys/kernel.h>
-#include <sys/malloc.h>
#include <sys/module.h>
#include <sys/sbuf.h>
#include <sys/socket.h>
@@ -147,8 +146,8 @@
KASSERTMSG(vap->iv_rs == NULL, "%s called multiple times", __func__);
nrefs++; /* XXX locking */
- amrr = vap->iv_rs = IEEE80211_MALLOC(sizeof(struct ieee80211_amrr),
- M_80211_RATECTL, IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
+ amrr = vap->iv_rs = IEEE80211_ZALLOC(sizeof(struct ieee80211_amrr),
+ M_80211_RATECTL, IEEE80211_M_NOWAIT);
if (amrr == NULL) {
if_printf(vap->iv_ifp, "couldn't alloc ratectl structure\n");
return;
@@ -164,7 +163,8 @@
static void
amrr_deinit(struct ieee80211vap *vap)
{
- IEEE80211_FREE(vap->iv_rs, M_80211_RATECTL);
+ IEEE80211_FREE(vap->iv_rs, M_80211_RATECTL,
+ sizeof(struct ieee80211_amrr));
KASSERTMSG(nrefs > 0, "imbalanced attach/detach");
nrefs--; /* XXX locking */
}
@@ -204,8 +204,9 @@
}
if (ni->ni_rctls == NULL) {
- ni->ni_rctls = amn = IEEE80211_MALLOC(sizeof(struct ieee80211_amrr_node),
- M_80211_RATECTL, IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
+ ni->ni_rctls = amn = IEEE80211_ZALLOC(
+ sizeof(struct ieee80211_amrr_node),
+ M_80211_RATECTL, IEEE80211_M_NOWAIT);
if (amn == NULL) {
if_printf(vap->iv_ifp, "couldn't alloc per-node ratectl "
"structure\n");
@@ -272,7 +273,8 @@
static void
amrr_node_deinit(struct ieee80211_node *ni)
{
- IEEE80211_FREE(ni->ni_rctls, M_80211_RATECTL);
+ IEEE80211_FREE(ni->ni_rctls, M_80211_RATECTL,
+ sizeof(struct ieee80211_amrr_node));
}
static int
diff -r 50b3e6fc37bd -r 78e02a9939ae sys/net80211/ieee80211_crypto.c
--- a/sys/net80211/ieee80211_crypto.c Thu Dec 10 18:22:42 2020 +0100
+++ b/sys/net80211/ieee80211_crypto.c Thu Dec 10 18:26:08 2020 +0100
@@ -46,7 +46,6 @@
*/
#include <sys/param.h>
#include <sys/kernel.h>
-#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/socket.h>
@@ -63,7 +62,9 @@
#include <net80211/ieee80211_var.h>
+#if __FreeBSD__
MALLOC_DEFINE(M_80211_CRYPTO, "80211crypto", "802.11 crypto state");
+#endif
static int _ieee80211_crypto_delkey(struct ieee80211vap *,
struct ieee80211_key *);
@@ -122,11 +123,13 @@
key->wk_cipher->ic_detach(key);
}
+#if 0
static __inline void *
cipher_attach(struct ieee80211vap *vap, struct ieee80211_key *key)
{
return key->wk_cipher->ic_attach(vap, key);
}
+#endif
/*
* Wrappers for driver key management methods.
@@ -291,6 +294,7 @@
void *keyctx;
int oflags;
+ KASSERT(!cpu_intr_p());
IEEE80211_DPRINTF(vap, IEEE80211_MSG_CRYPTO,
"%s: cipher %u flags 0x%x keyix %u\n",
__func__, cipher, flags, key->wk_keyix);
diff -r 50b3e6fc37bd -r 78e02a9939ae sys/net80211/ieee80211_crypto.h
--- a/sys/net80211/ieee80211_crypto.h Thu Dec 10 18:22:42 2020 +0100
+++ b/sys/net80211/ieee80211_crypto.h Thu Dec 10 18:26:08 2020 +0100
@@ -162,7 +162,13 @@
struct ieee80211_node;
struct mbuf;
+#if __FreeBSD__
+#include <net80211/ieee80211_freebsd.h>
MALLOC_DECLARE(M_80211_CRYPTO);
+#define M_80211_CRYPTO_CCMP M_80211_CRYPTO
+#define M_80211_CRYPTO_TKIP M_80211_CRYPTO
+#define M_80211_CRYPTO_WEP M_80211_CRYPTO
+#endif
void ieee80211_crypto_attach(struct ieee80211com *);
void ieee80211_crypto_detach(struct ieee80211com *);
diff -r 50b3e6fc37bd -r 78e02a9939ae sys/net80211/ieee80211_crypto_ccmp.c
--- a/sys/net80211/ieee80211_crypto_ccmp.c Thu Dec 10 18:22:42 2020 +0100
+++ b/sys/net80211/ieee80211_crypto_ccmp.c Thu Dec 10 18:26:08 2020 +0100
@@ -49,7 +49,6 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/mbuf.h>
-#include <sys/malloc.h>
#include <sys/kernel.h>
#include <sys/module.h>
@@ -63,6 +62,8 @@
#ifdef __NetBSD__
#include <net/route.h>
#include <net/if_ether.h>
+#include <sys/once.h>
+#include <sys/cpu.h>
#endif
#include <net80211/ieee80211_var.h>
@@ -73,6 +74,11 @@
#define AES_BLOCK_LEN 16
+#if 0 // __NetBSD__
+static pool_cache_t ieee80211_ccmp_ctx_pool;
+#define M_80211_CRYPTO_CCMP ieee80211_ccmp_ctx_pool
+#endif
+
struct ccmp_ctx {
struct aesenc cc_aes;
struct ieee80211vap *cc_vap; /* for diagnostics+statistics */
@@ -112,13 +118,34 @@
Home |
Main Index |
Thread Index |
Old Index