eloop: Fix kqueue event deletion filter

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: f9982b3212 ("Implement kqueue(2) support via CONFIG_ELOOP_KQUEUE")
Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2019-01-02 12:11:52 +02:00
parent 7153bd4674
commit 7814838f92

View 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));