PERFORCE change 134606 for review

Sam Leffler sam at FreeBSD.org
Fri Feb 1 13:28:35 PST 2008


http://perforce.freebsd.org/chv.cgi?CH=134606

Change 134606 by sam at sam_ebb on 2008/02/01 21:27:39

	add evil linker set hackery to handle files w/ multiple instances:
	o introduce _IEEE80211_PROFILE_MODULE to encapsulate the basic 
	  module glop
	o define other module wrappers in terms of _IEEE80211_PROFILE_MODULE
	  and add wrappers to construct a linker set for sub-instances that
	  the module event handler walks
	o add nrefs counters to modules since _IEEE80211_PROFILE_MODULE
	  uses this to disallow kldunload when dynamic references are
	  present (in the case of wlan_acl this needed to be done and was
	  not but for some other modules there is no way to manage dynamic
	  refs due to the current api's)
	o add stub module wrapper for rate control algorithms so we're ready
	  when sephe bringins in his framework

Affected files ...

.. //depot/projects/vap/sys/net80211/ieee80211_acl.c#8 edit
.. //depot/projects/vap/sys/net80211/ieee80211_amrr.c#6 edit
.. //depot/projects/vap/sys/net80211/ieee80211_freebsd.h#15 edit
.. //depot/projects/vap/sys/net80211/ieee80211_rssadapt.c#2 edit
.. //depot/projects/vap/sys/net80211/ieee80211_scan_sta.c#16 edit
.. //depot/projects/vap/sys/net80211/ieee80211_xauth.c#8 edit

Differences ...

==== //depot/projects/vap/sys/net80211/ieee80211_acl.c#8 (text+ko) ====

@@ -91,6 +91,9 @@
 
 static	int acl_free_all(struct ieee80211vap *);
 
+/* number of references from net80211 layer */
+static	int nrefs = 0;
+
 static int
 acl_attach(struct ieee80211vap *vap)
 {
@@ -105,6 +108,7 @@
 	as->as_policy = ACL_POLICY_OPEN;
 	as->as_vap = vap;
 	vap->iv_as = as;
+	nrefs++;			/* NB: we assume caller locking */
 	return 1;
 }
 
@@ -113,6 +117,9 @@
 {
 	struct aclstate *as = vap->iv_as;
 
+	KASSERT(nrefs > 0, ("imbalanced attach/detach"));
+	nrefs--;			/* NB: we assume caller locking */
+
 	acl_free_all(vap);
 	vap->iv_as = NULL;
 	ACL_LOCK_DESTROY(as);

==== //depot/projects/vap/sys/net80211/ieee80211_amrr.c#6 (text+ko) ====

@@ -64,6 +64,9 @@
 #define reset_cnt(amn)		\
 	do { (amn)->amn_txcnt = (amn)->amn_retrycnt = 0; } while (0)
 
+/* number of references from net80211 layer */
+static	int nrefs = 0;
+
 void
 ieee80211_amrr_init(struct ieee80211_amrr *amrr,
     struct ieee80211vap *vap, int amin, int amax)
@@ -140,25 +143,4 @@
 /*
  * Module glue.
  */
-static int
-amrr_modevent(module_t mod, int type, void *unused)
-{
-	switch (type) {
-	case MOD_LOAD:
-		if (bootverbose)
-			printf("wlan_amrr: <AMRR Transmit Rate Control Algorithm>\n");
-		return 0;
-	case MOD_UNLOAD:
-		return 0;
-	}
-	return EINVAL;
-}
-
-static moduledata_t amrr_mod = {
-	"wlan_amrr",
-	amrr_modevent,
-	0
-};
-DECLARE_MODULE(wlan_amrr, amrr_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
-MODULE_VERSION(wlan_amrr, 1);
-MODULE_DEPEND(wlan_amrr, wlan, 1, 1, 1);
+IEEE80211_RATE_MODULE(amrr, 1);

==== //depot/projects/vap/sys/net80211/ieee80211_freebsd.h#15 (text+ko) ====

@@ -283,13 +283,24 @@
 
 void	ieee80211_load_module(const char *);
 
-#define	IEEE80211_CRYPTO_MODULE(name, version) \
+/*
+ * A "policy module" is an adjunct module to net80211 that provides
+ * functionality that typically includes policy decisions.  This
+ * modularity enables extensibility and vendor-supplied functionality.
+ */
+#define	_IEEE80211_POLICY_MODULE(policy, name, version)			\
+typedef void (*policy##_setup)(int);					\
+SET_DECLARE(policy##_set, policy##_setup);				\
 static int								\
-name##_modevent(module_t mod, int type, void *unused)			\
+wlan_##name##_modevent(module_t mod, int type, void *unused)		\
 {									\
+	policy##_setup * const *iter, f;				\
 	switch (type) {							\
 	case MOD_LOAD:							\
-		ieee80211_crypto_register(&name);			\
+		SET_FOREACH(iter, policy##_set) {			\
+			f = (void*) *iter;				\
+			f(type);					\
+		}							\
 		return 0;						\
 	case MOD_UNLOAD:						\
 	case MOD_QUIESCE:						\
@@ -298,100 +309,100 @@
 				nrefs);					\
 			return EBUSY;					\
 		}							\
-		if (type == MOD_UNLOAD)					\
-			ieee80211_crypto_unregister(&name);		\
+		if (type == MOD_UNLOAD) {				\
+			SET_FOREACH(iter, policy##_set) {		\
+				f = (void*) *iter;			\
+				f(type);				\
+			}						\
+		}							\
 		return 0;						\
 	}								\
 	return EINVAL;							\
 }									\
 static moduledata_t name##_mod = {					\
 	"wlan_" #name,							\
-	name##_modevent,						\
+	wlan_##name##_modevent,						\
 	0								\
 };									\
 DECLARE_MODULE(wlan_##name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);\
 MODULE_VERSION(wlan_##name, version);					\
 MODULE_DEPEND(wlan_##name, wlan, 1, 1, 1)
 
-#define	IEEE80211_SCANNER_MODULE(name, alg, v, version)			\
-static int								\
-name##alg##_modevent(module_t mod, int type, void *unused)		\
+/*
+ * Crypto modules implement cipher support.
+ */
+#define	IEEE80211_CRYPTO_MODULE(name, version)				\
+_IEEE80211_POLICY_MODULE(crypto, name, version);			\
+static void								\
+name##_modevent(int type)						\
+{									\
+	if (type == MOD_LOAD)						\
+		ieee80211_crypto_register(&name);			\
+	else								\
+		ieee80211_crypto_unregister(&name);			\
+}									\
+TEXT_SET(crypto##_set, name##_modevent)
+
+/*
+ * Scanner modules provide scanning policy.
+ */
+#define	IEEE80211_SCANNER_MODULE(name, version)				\
+	_IEEE80211_POLICY_MODULE(scanner, name, version)
+
+#define	IEEE80211_SCANNER_ALG(name, alg, v)				\
+static void								\
+name##_modevent(int type)						\
 {									\
-	switch (type) {							\
-	case MOD_LOAD:							\
+	if (type == MOD_LOAD)						\
 		ieee80211_scanner_register(alg, &v);			\
-		return 0;						\
-	case MOD_UNLOAD:						\
-	case MOD_QUIESCE:						\
-		if (nrefs) {						\
-			printf("wlan_##name: still in use (%u dynamic refs)\n",\
-				nrefs);					\
-			return EBUSY;					\
-		}							\
-		if (type == MOD_UNLOAD)					\
-			ieee80211_scanner_unregister(&name);		\
-		return 0;						\
-	}								\
-	return EINVAL;							\
+	else								\
+		ieee80211_scanner_unregister(alg, &v);			\
 }									\
-static moduledata_t name##_mod = {					\
-	"wlan_" #name,							\
-	name##_modevent,						\
-	0								\
-};									\
-DECLARE_MODULE(wlan_##name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);\
-MODULE_VERSION(wlan_##name, version);					\
-MODULE_DEPEND(wlan_##name, wlan, 1, 1, 1)
+TEXT_SET(scanner_set, name##_modevent);					\
 
+/*
+ * ACL modules implement acl policy.
+ */
 #define	IEEE80211_ACL_MODULE(name, alg, version)			\
-static int								\
-name##_modevent(module_t mod, int type, void *unused)			\
+_IEEE80211_POLICY_MODULE(acl, name, version);				\
+static void								\
+alg##_modevent(int type)						\
 {									\
-	switch (type) {							\
-	case MOD_LOAD:							\
+	if (type == MOD_LOAD)						\
 		ieee80211_aclator_register(&alg);			\
-		return 0;						\
-	case MOD_UNLOAD:						\
-	case MOD_QUIESCE:						\
-		if (type == MOD_UNLOAD)					\
-			ieee80211_aclator_unregister(&alg);		\
-		return 0;						\
-	}								\
-	return EINVAL;							\
+	else								\
+		ieee80211_aclator_unregister(&alg);			\
+}									\
+TEXT_SET(acl_set, alg##_modevent);					\
+
+/*
+ * Authenticator modules handle 802.1x/WPA authentication.
+ */
+#define	IEEE80211_AUTH_MODULE(name, version)				\
+	_IEEE80211_POLICY_MODULE(auth, name, version)
+
+#define	IEEE80211_AUTH_ALG(name, alg, v)				\
+static void								\
+name##_modevent(int type)						\
+{									\
+	if (type == MOD_LOAD)						\
+		ieee80211_authenticator_register(alg, &v);		\
+	else								\
+		ieee80211_authenticator_unregister(alg);		\
 }									\
-static moduledata_t name##_mod = {					\
-	#name,								\
-	name##_modevent,						\
-	0								\
-};									\
-DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);	\
-MODULE_VERSION(name, version);						\
-MODULE_DEPEND(name, wlan, 1, 1, 1)
+TEXT_SET(auth_set, name##_modevent)
 
-#define	IEEE80211_AUTH_MODULE(name, alg, version)			\
-static int								\
-name##_modevent(module_t mod, int type, void *unused)			\
+/*
+ * Rate control modules provide tx rate control support.
+ */
+#define	IEEE80211_RATE_MODULE(alg, version)				\
+_IEEE80211_POLICY_MODULE(rate, alg, version);				\
+static void								\
+alg##_modevent(int type)						\
 {									\
-	switch (type) {							\
-	case MOD_LOAD:							\
-		ieee80211_authenticator_register(alg, &name);		\
-		return 0;						\
-	case MOD_UNLOAD:						\
-	case MOD_QUIESCE:						\
-		if (type == MOD_UNLOAD)					\
-			ieee80211_authenticator_unregister(alg);	\
-		return 0;						\
-	}								\
-	return EINVAL;							\
+	/* XXX nothing to do until the rate control framework arrives */\
 }									\
-static moduledata_t name##_mod = {					\
-	#name,								\
-	name##_modevent,						\
-	0								\
-};									\
-DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);	\
-MODULE_VERSION(name, version);						\
-MODULE_DEPEND(name, wlan, 1, 1, 1)
+TEXT_SET(rate##_set, alg##_modevent)
 #endif /* _KERNEL */
 
 /* XXX this stuff belongs elsewhere */

==== //depot/projects/vap/sys/net80211/ieee80211_rssadapt.c#2 (text+ko) ====

@@ -71,6 +71,9 @@
                                      (parm##_denom - parm##_old) * (new)) / \
 				    parm##_denom)
 
+/* number of references from net80211 layer */
+static	int nrefs = 0;
+
 void
 ieee80211_rssadapt_init(struct ieee80211_rssadapt *rs, struct ieee80211vap *vap)
 {
@@ -220,3 +223,8 @@
 	else
 		rssadapt_lower_rate(rn, pktlen, rate, rssi);
 }
+
+/*
+ * Module glue.
+ */
+IEEE80211_RATE_MODULE(rssadapt, 1);

==== //depot/projects/vap/sys/net80211/ieee80211_scan_sta.c#16 (text+ko) ====

@@ -1646,7 +1646,6 @@
 IEEE80211_SCANNER_MODULE(adhoc, IEEE80211_M_IBSS, adhoc_default, 1);
 IEEE80211_SCANNER_MODULE(adhoc, IEEE80211_M_AHDEMO, adhoc_default, 1);
 IEEE80211_SCANNER_MODULE(ap, IEEE80211_M_HOSTAP, ap_default, 1);
-#else
 static int
 wlan_scan_modevent(module_t mod, int type, void *unused)
 {
@@ -1682,3 +1681,91 @@
 MODULE_VERSION(wlan_scan_sta, 1);
 MODULE_DEPEND(wlan_scan_sta, wlan, 1, 1, 1);
 #endif
+#if 0
+typedef void (*scanner_setup)(int);
+SET_DECLARE(scanner_set, scanner_setup);
+
+static int
+wlan_scan_modevent(module_t mod, int type, void *unused)
+{
+	scanner_setup * const *iter, f;
+
+	switch (type) {
+	case MOD_LOAD:
+		SET_FOREACH(iter, scanner_set) {
+			f = (void*) *iter;
+			f(type);
+		}
+		return 0;
+	case MOD_UNLOAD:
+	case MOD_QUIESCE:
+		if (nrefs) {
+			printf("wlan_scan: still in use (%u dynamic refs)\n",
+				nrefs);
+			return EBUSY;
+		}
+		if (type == MOD_UNLOAD) {
+			SET_FOREACH(iter, scanner_set) {
+				f = (void*) *iter;
+				f(type);
+			}
+		}
+		return 0;
+	}
+	return EINVAL;
+}
+static moduledata_t wlan_scan_mod = {
+	"wlan_scan_sta",
+	wlan_scan_modevent,
+	0
+};
+DECLARE_MODULE(wlan_scan_sta, wlan_scan_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
+MODULE_VERSION(wlan_scan_sta, 1);
+MODULE_DEPEND(wlan_scan_sta, wlan, 1, 1, 1);
+
+static void
+sta_modevent(int type)
+{
+	if (type == MOD_LOAD)
+		ieee80211_scanner_register(IEEE80211_M_STA, &sta_default);
+	else
+		ieee80211_scanner_unregister(IEEE80211_M_STA, &sta_default);
+}
+TEXT_SET(scanner_set, sta_modevent);
+
+static void
+ibss_modevent(int type)
+{
+	if (type == MOD_LOAD)
+		ieee80211_scanner_register(IEEE80211_M_IBSS, &adhoc_default);
+	else
+		ieee80211_scanner_unregister(IEEE80211_M_IBSS, &adhoc_default);
+}
+TEXT_SET(scanner_set, ibss_modevent);
+
+static void
+ahdemo_modevent(int type)
+{
+	if (type == MOD_LOAD)
+		ieee80211_scanner_register(IEEE80211_M_AHDEMO, &adhoc_default);
+	else
+		ieee80211_scanner_unregister(IEEE80211_M_AHDEMO, &adhoc_default);
+}
+TEXT_SET(scanner_set, ahdemo_modevent);
+
+static void
+ap_modevent(int type)
+{
+	if (type == MOD_LOAD)
+		ieee80211_scanner_register(IEEE80211_M_HOSTAP, &ap_default);
+	else
+		ieee80211_scanner_unregister(IEEE80211_M_HOSTAP, &ap_default);
+}
+TEXT_SET(scanner_set, ap_modevent);
+#else
+IEEE80211_SCANNER_MODULE(sta, 1);
+IEEE80211_SCANNER_ALG(sta, IEEE80211_M_STA, sta_default);
+IEEE80211_SCANNER_ALG(ibss, IEEE80211_M_IBSS, adhoc_default);
+IEEE80211_SCANNER_ALG(ahdemo, IEEE80211_M_AHDEMO, adhoc_default);
+IEEE80211_SCANNER_ALG(ap, IEEE80211_M_HOSTAP, ap_default);
+#endif

==== //depot/projects/vap/sys/net80211/ieee80211_xauth.c#8 (text+ko) ====

@@ -56,6 +56,9 @@
 
 #include <net80211/ieee80211_var.h>
 
+/* XXX number of references from net80211 layer; needed for module code */
+static	int nrefs = 0;
+
 /*
  * One module handles everything for now.  May want
  * to split things up for embedded applications.
@@ -68,34 +71,6 @@
 	.ia_node_leave	= NULL,
 };
 
-#if 0
-IEEE80211_AUTH_MODULE(xauth, IEEE80211_AUTH_8021X, 1);
-IEEE80211_AUTH_MODULE(xauth, IEEE80211_AUTH_WPA, 1);
-#else
-static int
-wlan_xauth_modevent(module_t mod, int type, void *unused)
-{
-	switch (type) {
-	case MOD_LOAD:
-		ieee80211_authenticator_register(IEEE80211_AUTH_8021X, &xauth);
-		ieee80211_authenticator_register(IEEE80211_AUTH_WPA, &xauth);
-		return 0;
-	case MOD_UNLOAD:
-	case MOD_QUIESCE:
-		if (type == MOD_UNLOAD) {
-			ieee80211_authenticator_unregister(IEEE80211_AUTH_8021X);
-			ieee80211_authenticator_unregister(IEEE80211_AUTH_WPA);
-		}
-		return 0;
-	}
-	return EINVAL;
-}
-static moduledata_t wlan_xauth_mod = {
-	"wlan_xauth",
-	wlan_xauth_modevent,
-	0
-};
-DECLARE_MODULE(wlan_xauth, wlan_xauth_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
-MODULE_VERSION(wlan_xauth, 1);
-MODULE_DEPEND(wlan_xauth, wlan, 1, 1, 1);
-#endif
+IEEE80211_AUTH_MODULE(xauth, 1);
+IEEE80211_AUTH_ALG(x8021x, IEEE80211_AUTH_8021X, xauth);
+IEEE80211_AUTH_ALG(wpa, IEEE80211_AUTH_WPA, xauth);


More information about the p4-projects mailing list