Make hostapd_for_each_interface() take context pointer as argument

This removes need for using eloop_get_user_data().
This commit is contained in:
Jouni Malinen 2009-12-19 19:07:31 +02:00
parent 2988796257
commit 9969e5a46a
5 changed files with 29 additions and 11 deletions

View file

@ -69,7 +69,8 @@ static void hostapd_prune_associations(struct hostapd_data *hapd,
struct prune_data data; struct prune_data data;
data.hapd = hapd; data.hapd = hapd;
data.addr = sta->addr; data.addr = sta->addr;
hostapd_for_each_interface(prune_associations, &data); hostapd_for_each_interface(hapd->iface->interfaces,
prune_associations, &data);
} }

View file

@ -660,10 +660,12 @@ static int hostapd_wpa_auth_for_each_auth(
void *ctx, int (*cb)(struct wpa_authenticator *sm, void *ctx), void *ctx, int (*cb)(struct wpa_authenticator *sm, void *ctx),
void *cb_ctx) void *cb_ctx)
{ {
struct hostapd_data *hapd = ctx;
struct wpa_auth_iface_iter_data data; struct wpa_auth_iface_iter_data data;
data.cb = cb; data.cb = cb;
data.cb_ctx = cb_ctx; data.cb_ctx = cb_ctx;
return hostapd_for_each_interface(wpa_auth_iface_iter, &data); return hostapd_for_each_interface(hapd->iface->interfaces,
wpa_auth_iface_iter, &data);
} }

View file

@ -21,6 +21,7 @@ struct wpa_driver_ops;
struct wpa_ctrl_dst; struct wpa_ctrl_dst;
struct radius_server_data; struct radius_server_data;
struct upnp_wps_device_sm; struct upnp_wps_device_sm;
struct hapd_interfaces;
#ifdef CONFIG_FULL_DYNAMIC_VLAN #ifdef CONFIG_FULL_DYNAMIC_VLAN
struct full_dynamic_vlan; struct full_dynamic_vlan;
@ -119,6 +120,7 @@ struct hostapd_data {
* struct hostapd_iface - hostapd per-interface data structure * struct hostapd_iface - hostapd per-interface data structure
*/ */
struct hostapd_iface { struct hostapd_iface {
struct hapd_interfaces *interfaces;
void *owner; void *owner;
char *config_fname; char *config_fname;
struct hostapd_config *conf; struct hostapd_config *conf;
@ -180,7 +182,8 @@ void hostapd_interface_deinit(struct hostapd_iface *iface);
int handle_reload_iface(struct hostapd_iface *iface, void *ctx); int handle_reload_iface(struct hostapd_iface *iface, void *ctx);
int handle_dump_state_iface(struct hostapd_iface *iface, void *ctx); int handle_dump_state_iface(struct hostapd_iface *iface, void *ctx);
int hostapd_for_each_interface(int (*cb)(struct hostapd_iface *iface, int hostapd_for_each_interface(struct hapd_interfaces *interfaces,
int (*cb)(struct hostapd_iface *iface,
void *ctx), void *ctx); void *ctx), void *ctx);
int hostapd_register_probereq_cb(struct hostapd_data *hapd, int hostapd_register_probereq_cb(struct hostapd_data *hapd,

View file

@ -38,10 +38,10 @@ struct hapd_interfaces {
}; };
int hostapd_for_each_interface(int (*cb)(struct hostapd_iface *iface, int hostapd_for_each_interface(struct hapd_interfaces *interfaces,
int (*cb)(struct hostapd_iface *iface,
void *ctx), void *ctx) void *ctx), void *ctx)
{ {
struct hapd_interfaces *interfaces = eloop_get_user_data();
size_t i; size_t i;
int ret; int ret;
@ -221,8 +221,9 @@ fail:
} }
static struct hostapd_iface * hostapd_interface_init(const char *config_fname, static struct hostapd_iface *
int debug) hostapd_interface_init(struct hapd_interfaces *interfaces,
const char *config_fname, int debug)
{ {
struct hostapd_iface *iface; struct hostapd_iface *iface;
int k; int k;
@ -231,6 +232,7 @@ static struct hostapd_iface * hostapd_interface_init(const char *config_fname,
iface = hostapd_init(config_fname); iface = hostapd_init(config_fname);
if (!iface) if (!iface)
return NULL; return NULL;
iface->interfaces = interfaces;
for (k = 0; k < debug; k++) { for (k = 0; k < debug; k++) {
if (iface->bss[0]->conf->logger_stdout_level > 0) if (iface->bss[0]->conf->logger_stdout_level > 0)
@ -262,16 +264,18 @@ static void handle_term(int sig, void *eloop_ctx, void *signal_ctx)
*/ */
static void handle_reload(int sig, void *eloop_ctx, void *signal_ctx) static void handle_reload(int sig, void *eloop_ctx, void *signal_ctx)
{ {
struct hapd_interfaces *interfaces = eloop_ctx;
wpa_printf(MSG_DEBUG, "Signal %d received - reloading configuration", wpa_printf(MSG_DEBUG, "Signal %d received - reloading configuration",
sig); sig);
hostapd_for_each_interface(handle_reload_iface, NULL); hostapd_for_each_interface(interfaces, handle_reload_iface, NULL);
} }
static void handle_dump_state(int sig, void *eloop_ctx, void *signal_ctx) static void handle_dump_state(int sig, void *eloop_ctx, void *signal_ctx)
{ {
#ifdef HOSTAPD_DUMP_STATE #ifdef HOSTAPD_DUMP_STATE
hostapd_for_each_interface(handle_dump_state_iface, NULL); struct hapd_interfaces *interfaces = eloop_ctx;
hostapd_for_each_interface(interfaces, handle_dump_state_iface, NULL);
#endif /* HOSTAPD_DUMP_STATE */ #endif /* HOSTAPD_DUMP_STATE */
} }
#endif /* CONFIG_NATIVE_WINDOWS */ #endif /* CONFIG_NATIVE_WINDOWS */
@ -449,7 +453,8 @@ int main(int argc, char *argv[])
/* Initialize interfaces */ /* Initialize interfaces */
for (i = 0; i < interfaces.count; i++) { for (i = 0; i < interfaces.count; i++) {
interfaces.iface[i] = hostapd_interface_init(argv[optind + i], interfaces.iface[i] = hostapd_interface_init(&interfaces,
argv[optind + i],
debug); debug);
if (!interfaces.iface[i]) if (!interfaces.iface[i])
goto out; goto out;

View file

@ -33,7 +33,14 @@
#include "ap.h" #include "ap.h"
int hostapd_for_each_interface(int (*cb)(struct hostapd_iface *iface, struct hapd_interfaces {
size_t count;
struct hostapd_iface **iface;
};
int hostapd_for_each_interface(struct hapd_interfaces *interfaces,
int (*cb)(struct hostapd_iface *iface,
void *ctx), void *ctx) void *ctx), void *ctx)
{ {
/* TODO */ /* TODO */