]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
eloop: Fix kqueue event deletion filter
authorJouni Malinen <j@w1.fi>
Wed, 2 Jan 2019 10:11:52 +0000 (12:11 +0200)
committerJouni Malinen <j@w1.fi>
Wed, 2 Jan 2019 10:11:52 +0000 (12:11 +0200)
EV_SET() for EV_ADD used a specific filter type, but that same filter
type was not provided to the matching EV_DELETE case. This resulted in
the kernel rejecting the deletion with "Invalid argument". Fix this by
setting the same filter type for both operations.

Fixes: f9982b321222 ("Implement kqueue(2) support via CONFIG_ELOOP_KQUEUE")
Signed-off-by: Jouni Malinen <j@w1.fi>
src/utils/eloop.c

index fb90d17a79d020f44d1af24452f978550a8409e6..bb375be1095e6a95d9e9c808342fd4e34bf2806f 100644 (file)
@@ -224,22 +224,25 @@ static int eloop_sock_queue(int sock, eloop_event_type type)
 
 
 #ifdef CONFIG_ELOOP_KQUEUE
-static int eloop_sock_queue(int sock, eloop_event_type type)
-{
-       int filter;
-       struct kevent ke;
 
+static short event_type_kevent_filter(eloop_event_type type)
+{
        switch (type) {
        case EVENT_TYPE_READ:
-               filter = EVFILT_READ;
-               break;
+               return EVFILT_READ;
        case EVENT_TYPE_WRITE:
-               filter = EVFILT_WRITE;
-               break;
+               return EVFILT_WRITE;
        default:
-               filter = 0;
+               return 0;
        }
-       EV_SET(&ke, sock, filter, EV_ADD, 0, 0, 0);
+}
+
+
+static int eloop_sock_queue(int sock, eloop_event_type type)
+{
+       struct kevent ke;
+
+       EV_SET(&ke, sock, event_type_kevent_filter(type), EV_ADD, 0, 0, 0);
        if (kevent(eloop.kqueuefd, &ke, 1, NULL, 0, NULL) == -1) {
                wpa_printf(MSG_ERROR, "%s: kevent(ADD) for fd=%d failed: %s",
                           __func__, sock, strerror(errno));
@@ -247,6 +250,7 @@ static int eloop_sock_queue(int sock, eloop_event_type type)
        }
        return 0;
 }
+
 #endif /* CONFIG_ELOOP_KQUEUE */
 
 
@@ -411,7 +415,8 @@ static void eloop_sock_table_remove_sock(struct eloop_sock_table *table,
        os_memset(&eloop.fd_table[sock], 0, sizeof(struct eloop_sock));
 #endif /* CONFIG_ELOOP_EPOLL */
 #ifdef CONFIG_ELOOP_KQUEUE
-       EV_SET(&ke, sock, 0, EV_DELETE, 0, 0, 0);
+       EV_SET(&ke, sock, event_type_kevent_filter(table->type), EV_DELETE, 0,
+              0, 0);
        if (kevent(eloop.kqueuefd, &ke, 1, NULL, 0, NULL) < 0) {
                wpa_printf(MSG_ERROR, "%s: kevent(DEL) for fd=%d failed: %s",
                           __func__, sock, strerror(errno));