From 7d93365197f3df144ea007a0ce27cff3b59af8d3 Mon Sep 17 00:00:00 2001 From: Jan Friesse Date: Tue, 23 Apr 2024 18:01:02 +0200 Subject: [PATCH] transport: Fix _find_myself for kernel 6.9 Kernel 6.9 seems to have changed AF_NETLINK behavior slightly making booth unable to start. Previously it was expected only first item in the message can be NLMSG_DONE or NLMSG_ERROR type. And it looks this was true for Kernel < 6.9. With kernel 6.9 this is no longer true, so any item can be type NLMSG_DONE or NLMSG_ERROR. Result was loop was never terminated and booth was waiting for more messages from kernel which never arrived. Solution is to change loop a bit so NLMSG_DONE, NLMSG_ERROR and RTM_NEWADDR are handled correctly. Signed-off-by: Jan Friesse --- src/transport.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/transport.c b/src/transport.c index 0d17f18c..817a4dc7 100644 --- a/src/transport.c +++ b/src/transport.c @@ -208,17 +208,16 @@ int _find_myself(int family, struct booth_site **mep, int fuzzy_allowed) return 0; } - h = (struct nlmsghdr *)rcvbuf; - if (h->nlmsg_type == NLMSG_DONE) - break; - - if (h->nlmsg_type == NLMSG_ERROR) { - close(fd); - log_error("netlink socket recvmsg error"); - return 0; - } + for (h = (struct nlmsghdr *)rcvbuf; NLMSG_OK(h, status); h = NLMSG_NEXT(h, status)) { + if (h->nlmsg_type == NLMSG_DONE) + goto out; + + if (h->nlmsg_type == NLMSG_ERROR) { + close(fd); + log_error("netlink socket recvmsg error"); + return 0; + } - while (NLMSG_OK(h, status)) { if (h->nlmsg_type == RTM_NEWADDR) { struct ifaddrmsg *ifa = NLMSG_DATA(h); struct rtattr *tb[IFA_MAX+1]; @@ -271,10 +270,10 @@ int _find_myself(int family, struct booth_site **mep, int fuzzy_allowed) } } } - h = NLMSG_NEXT(h, status); } } +out: close(fd); if (!me)