Skip to content

Commit

Permalink
fix(ua2f.c): possible deadlock in the queue (#127)
Browse files Browse the repository at this point in the history
* fix ua2f.c: possible deadlock in the queue, causing network disconnection

在不支持内核上运行会造成队列死锁。当返回Operation not supported错误的时候,如果继续执行,就会死锁。

Signed-off-by: miny1233 <[email protected]>

* fix: exit while met IO_ERROR

* fix: should set exit for unknown return value

---------

Signed-off-by: miny1233 <[email protected]>
Co-authored-by: Zxilly <[email protected]>
  • Loading branch information
miny1233 and Zxilly committed Jun 30, 2024
1 parent 448c047 commit 6133d71
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/ua2f.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,27 @@ int main(const int argc, char *argv[]) {

while (!should_exit) {
if (nfqueue_receive(queue, buf, 0) == IO_READY) {
struct nf_packet packet[1];
while (nfqueue_next(buf, packet) == IO_READY) {
handle_packet(queue, packet);
while (!should_exit) {
struct nf_packet packet[1];
switch (nfqueue_next(buf, packet)) {
case IO_ERROR:
should_exit = true;
case IO_READY:
handle_packet(queue, packet);
case IO_NOTREADY:
continue;
default:
syslog(LOG_ERR, "Unknown return value [%s:%d]", __FILE__, __LINE__);
should_exit = true;
}
}
}
}

free(buf->data);
nfqueue_close(queue);

return EXIT_SUCCESS;
}

#pragma clang diagnostic pop

0 comments on commit 6133d71

Please sign in to comment.