mirror of
https://github.com/openwrt/openwrt.git
synced 2025-04-23 18:34:01 +00:00
hostapd: switch to using uloop (integrated with built-in eloop)
Preparation for pulling in more code that uses uloop Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
parent
9769655d1b
commit
33e4ad767e
package/network/services/hostapd
@ -1,11 +1,12 @@
|
||||
--- a/hostapd/Makefile
|
||||
+++ b/hostapd/Makefile
|
||||
@@ -166,6 +166,11 @@ OBJS += ../src/common/hw_features_common
|
||||
@@ -166,6 +166,12 @@ OBJS += ../src/common/hw_features_common
|
||||
|
||||
OBJS += ../src/eapol_auth/eapol_auth_sm.o
|
||||
|
||||
+ifdef CONFIG_UBUS
|
||||
+CFLAGS += -DUBUS_SUPPORT
|
||||
+OBJS += ../src/utils/uloop.o
|
||||
+OBJS += ../src/ap/ubus.o
|
||||
+LIBS += -lubox -lubus
|
||||
+endif
|
||||
@ -330,20 +331,21 @@
|
||||
|
||||
--- a/wpa_supplicant/Makefile
|
||||
+++ b/wpa_supplicant/Makefile
|
||||
@@ -194,6 +194,12 @@ ifdef CONFIG_EAPOL_TEST
|
||||
@@ -194,6 +194,13 @@ ifdef CONFIG_EAPOL_TEST
|
||||
CFLAGS += -Werror -DEAPOL_TEST
|
||||
endif
|
||||
|
||||
+ifdef CONFIG_UBUS
|
||||
+CFLAGS += -DUBUS_SUPPORT
|
||||
+OBJS += ubus.o
|
||||
+OBJS += ../src/utils/uloop.o
|
||||
+LIBS += -lubox -lubus
|
||||
+endif
|
||||
+
|
||||
ifdef CONFIG_CODE_COVERAGE
|
||||
CFLAGS += -O0 -fprofile-arcs -ftest-coverage
|
||||
LIBS += -lgcov
|
||||
@@ -989,6 +995,9 @@ ifdef CONFIG_CTRL_IFACE_MIB
|
||||
@@ -989,6 +996,9 @@ ifdef CONFIG_CTRL_IFACE_MIB
|
||||
CFLAGS += -DCONFIG_CTRL_IFACE_MIB
|
||||
endif
|
||||
OBJS += ../src/ap/ctrl_iface_ap.o
|
||||
@ -623,3 +625,151 @@
|
||||
wpa_hexdump(MSG_DEBUG, "WNM: BSS Transition Candidate List Entries",
|
||||
pos, end - pos);
|
||||
}
|
||||
--- a/src/utils/eloop.c
|
||||
+++ b/src/utils/eloop.c
|
||||
@@ -77,6 +77,9 @@ struct eloop_sock_table {
|
||||
struct eloop_data {
|
||||
int max_sock;
|
||||
|
||||
+ eloop_timeout_poll_handler timeout_poll_cb;
|
||||
+ eloop_poll_handler poll_cb;
|
||||
+
|
||||
size_t count; /* sum of all table counts */
|
||||
#ifdef CONFIG_ELOOP_POLL
|
||||
size_t max_pollfd_map; /* number of pollfds_map currently allocated */
|
||||
@@ -1121,6 +1124,12 @@ void eloop_run(void)
|
||||
os_reltime_sub(&timeout->time, &now, &tv);
|
||||
else
|
||||
tv.sec = tv.usec = 0;
|
||||
+ }
|
||||
+
|
||||
+ if (eloop.timeout_poll_cb && eloop.timeout_poll_cb(&tv, !!timeout))
|
||||
+ timeout = (void *)1;
|
||||
+
|
||||
+ if (timeout) {
|
||||
#if defined(CONFIG_ELOOP_POLL) || defined(CONFIG_ELOOP_EPOLL)
|
||||
timeout_ms = tv.sec * 1000 + tv.usec / 1000;
|
||||
#endif /* defined(CONFIG_ELOOP_POLL) || defined(CONFIG_ELOOP_EPOLL) */
|
||||
@@ -1190,7 +1199,8 @@ void eloop_run(void)
|
||||
eloop.exceptions.changed = 0;
|
||||
|
||||
eloop_process_pending_signals();
|
||||
-
|
||||
+ if (eloop.poll_cb)
|
||||
+ eloop.poll_cb();
|
||||
|
||||
/* check if some registered timeouts have occurred */
|
||||
timeout = dl_list_first(&eloop.timeout, struct eloop_timeout,
|
||||
@@ -1252,6 +1262,14 @@ out:
|
||||
return;
|
||||
}
|
||||
|
||||
+int eloop_register_cb(eloop_poll_handler poll_cb,
|
||||
+ eloop_timeout_poll_handler timeout_cb)
|
||||
+{
|
||||
+ eloop.poll_cb = poll_cb;
|
||||
+ eloop.timeout_poll_cb = timeout_cb;
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
|
||||
void eloop_terminate(void)
|
||||
{
|
||||
--- a/src/utils/eloop.h
|
||||
+++ b/src/utils/eloop.h
|
||||
@@ -65,6 +65,9 @@ typedef void (*eloop_timeout_handler)(vo
|
||||
*/
|
||||
typedef void (*eloop_signal_handler)(int sig, void *signal_ctx);
|
||||
|
||||
+typedef bool (*eloop_timeout_poll_handler)(struct os_reltime *tv, bool tv_set);
|
||||
+typedef void (*eloop_poll_handler)(void);
|
||||
+
|
||||
/**
|
||||
* eloop_init() - Initialize global event loop data
|
||||
* Returns: 0 on success, -1 on failure
|
||||
@@ -73,6 +76,9 @@ typedef void (*eloop_signal_handler)(int
|
||||
*/
|
||||
int eloop_init(void);
|
||||
|
||||
+int eloop_register_cb(eloop_poll_handler poll_cb,
|
||||
+ eloop_timeout_poll_handler timeout_cb);
|
||||
+
|
||||
/**
|
||||
* eloop_register_read_sock - Register handler for read events
|
||||
* @sock: File descriptor number for the socket
|
||||
@@ -320,6 +326,8 @@ int eloop_register_signal_reconfig(eloop
|
||||
*/
|
||||
int eloop_sock_requeue(void);
|
||||
|
||||
+void eloop_add_uloop(void);
|
||||
+
|
||||
/**
|
||||
* eloop_run - Start the event loop
|
||||
*
|
||||
--- /dev/null
|
||||
+++ b/src/utils/uloop.c
|
||||
@@ -0,0 +1,64 @@
|
||||
+#include <libubox/uloop.h>
|
||||
+#include "includes.h"
|
||||
+#include "common.h"
|
||||
+#include "eloop.h"
|
||||
+
|
||||
+static void eloop_uloop_event_cb(int sock, void *eloop_ctx, void *sock_ctx)
|
||||
+{
|
||||
+}
|
||||
+
|
||||
+static void eloop_uloop_fd_cb(struct uloop_fd *fd, unsigned int events)
|
||||
+{
|
||||
+ unsigned int changed = events ^ fd->flags;
|
||||
+
|
||||
+ if (changed & ULOOP_READ) {
|
||||
+ if (events & ULOOP_READ)
|
||||
+ eloop_register_sock(fd->fd, EVENT_TYPE_READ, eloop_uloop_event_cb, fd, fd);
|
||||
+ else
|
||||
+ eloop_unregister_sock(fd->fd, EVENT_TYPE_READ);
|
||||
+ }
|
||||
+
|
||||
+ if (changed & ULOOP_WRITE) {
|
||||
+ if (events & ULOOP_WRITE)
|
||||
+ eloop_register_sock(fd->fd, EVENT_TYPE_WRITE, eloop_uloop_event_cb, fd, fd);
|
||||
+ else
|
||||
+ eloop_unregister_sock(fd->fd, EVENT_TYPE_WRITE);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+static bool uloop_timeout_poll_handler(struct os_reltime *tv, bool tv_set)
|
||||
+{
|
||||
+ struct os_reltime tv_uloop;
|
||||
+ int timeout_ms = uloop_get_next_timeout();
|
||||
+
|
||||
+ if (timeout_ms < 0)
|
||||
+ return false;
|
||||
+
|
||||
+ tv_uloop.sec = timeout_ms / 1000;
|
||||
+ tv_uloop.usec = (timeout_ms % 1000) * 1000;
|
||||
+
|
||||
+ if (!tv_set || os_reltime_before(&tv_uloop, tv)) {
|
||||
+ *tv = tv_uloop;
|
||||
+ return true;
|
||||
+ }
|
||||
+
|
||||
+ return false;
|
||||
+}
|
||||
+
|
||||
+static void uloop_poll_handler(void)
|
||||
+{
|
||||
+ uloop_run_timeout(0);
|
||||
+}
|
||||
+
|
||||
+void eloop_add_uloop(void)
|
||||
+{
|
||||
+ static bool init_done = false;
|
||||
+
|
||||
+ if (!init_done) {
|
||||
+ uloop_init();
|
||||
+ uloop_fd_set_cb = eloop_uloop_fd_cb;
|
||||
+ init_done = true;
|
||||
+ }
|
||||
+
|
||||
+ eloop_register_cb(uloop_poll_handler, uloop_timeout_poll_handler);
|
||||
+}
|
||||
|
@ -44,12 +44,6 @@ struct ubus_banned_client {
|
||||
u8 addr[ETH_ALEN];
|
||||
};
|
||||
|
||||
static void ubus_receive(int sock, void *eloop_ctx, void *sock_ctx)
|
||||
{
|
||||
struct ubus_context *ctx = eloop_ctx;
|
||||
ubus_handle_event(ctx);
|
||||
}
|
||||
|
||||
static void ubus_reconnect_timeout(void *eloop_data, void *user_ctx)
|
||||
{
|
||||
if (ubus_reconnect(ctx, NULL)) {
|
||||
@ -57,12 +51,12 @@ static void ubus_reconnect_timeout(void *eloop_data, void *user_ctx)
|
||||
return;
|
||||
}
|
||||
|
||||
eloop_register_read_sock(ctx->sock.fd, ubus_receive, ctx, NULL);
|
||||
ubus_add_uloop(ctx);
|
||||
}
|
||||
|
||||
static void hostapd_ubus_connection_lost(struct ubus_context *ctx)
|
||||
{
|
||||
eloop_unregister_read_sock(ctx->sock.fd);
|
||||
uloop_fd_delete(&ctx->sock);
|
||||
eloop_register_timeout(1, 0, ubus_reconnect_timeout, ctx, NULL);
|
||||
}
|
||||
|
||||
@ -71,12 +65,14 @@ static bool hostapd_ubus_init(void)
|
||||
if (ctx)
|
||||
return true;
|
||||
|
||||
eloop_add_uloop();
|
||||
ctx = ubus_connect(NULL);
|
||||
if (!ctx)
|
||||
return false;
|
||||
|
||||
ctx->connection_lost = hostapd_ubus_connection_lost;
|
||||
eloop_register_read_sock(ctx->sock.fd, ubus_receive, ctx, NULL);
|
||||
ubus_add_uloop(ctx);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -94,7 +90,7 @@ static void hostapd_ubus_ref_dec(void)
|
||||
if (ctx_ref)
|
||||
return;
|
||||
|
||||
eloop_unregister_read_sock(ctx->sock.fd);
|
||||
uloop_fd_delete(&ctx->sock);
|
||||
ubus_free(ctx);
|
||||
ctx = NULL;
|
||||
}
|
||||
|
@ -30,12 +30,6 @@ static inline struct wpa_supplicant *get_wpas_from_object(struct ubus_object *ob
|
||||
return container_of(obj, struct wpa_supplicant, ubus.obj);
|
||||
}
|
||||
|
||||
static void ubus_receive(int sock, void *eloop_ctx, void *sock_ctx)
|
||||
{
|
||||
struct ubus_context *ctx = eloop_ctx;
|
||||
ubus_handle_event(ctx);
|
||||
}
|
||||
|
||||
static void ubus_reconnect_timeout(void *eloop_data, void *user_ctx)
|
||||
{
|
||||
if (ubus_reconnect(ctx, NULL)) {
|
||||
@ -43,12 +37,12 @@ static void ubus_reconnect_timeout(void *eloop_data, void *user_ctx)
|
||||
return;
|
||||
}
|
||||
|
||||
eloop_register_read_sock(ctx->sock.fd, ubus_receive, ctx, NULL);
|
||||
ubus_add_uloop(ctx);
|
||||
}
|
||||
|
||||
static void wpas_ubus_connection_lost(struct ubus_context *ctx)
|
||||
{
|
||||
eloop_unregister_read_sock(ctx->sock.fd);
|
||||
uloop_fd_delete(&ctx->sock);
|
||||
eloop_register_timeout(1, 0, ubus_reconnect_timeout, ctx, NULL);
|
||||
}
|
||||
|
||||
@ -57,12 +51,14 @@ static bool wpas_ubus_init(void)
|
||||
if (ctx)
|
||||
return true;
|
||||
|
||||
eloop_add_uloop();
|
||||
ctx = ubus_connect(NULL);
|
||||
if (!ctx)
|
||||
return false;
|
||||
|
||||
ctx->connection_lost = wpas_ubus_connection_lost;
|
||||
eloop_register_read_sock(ctx->sock.fd, ubus_receive, ctx, NULL);
|
||||
ubus_add_uloop(ctx);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -80,7 +76,7 @@ static void wpas_ubus_ref_dec(void)
|
||||
if (ctx_ref)
|
||||
return;
|
||||
|
||||
eloop_unregister_read_sock(ctx->sock.fd);
|
||||
uloop_fd_delete(&ctx->sock);
|
||||
ubus_free(ctx);
|
||||
ctx = NULL;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user