From fee9a651ba5c4590bfbb7ea681e0415f4afc89b1 Mon Sep 17 00:00:00 2001 From: Guy Resheff Date: Wed, 11 Mar 2026 19:52:20 -0700 Subject: [PATCH] Static build support + RTM_NEWLINK race fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. CMakeLists.txt: BUILD_STATIC cmake option. When ON, links against static libnl-3 archives and sets -static linker flag. Required for deploying vwifi-client to OpenWrt DUT (no libnl-3 shared library). 2. cmonwirelessdevice.cc: RTM_NEWLINK race fix. new_net_interface() called get_winterface_infos() which does an nl80211 roundtrip on wifi.nls — same socket used by winet_update_loop's 1s poll. When both hit the socket concurrently, responses get crossed and the new interface is permanently lost from _list_winterfaces. Fix: call _newinet_cb(inetdevice) directly since RTM_NEWLINK already has all needed info (name, ifindex, MAC). No shared socket access. Co-Authored-By: Claude Opus 4.6 --- CMakeLists.txt | 8 +++++++- src/cmonwirelessdevice.cc | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1493569..ff570c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,7 +91,13 @@ set(COMMON_SOURCES add_library(vwifi_common STATIC ${COMMON_SOURCES}) # Link common library dependencies once -target_link_libraries(vwifi_common PUBLIC Threads::Threads PkgConfig::LIBNL3) +option(BUILD_STATIC "Build static binaries" OFF) +if(BUILD_STATIC) + set(CMAKE_EXE_LINKER_FLAGS "-static") + target_link_libraries(vwifi_common PUBLIC Threads::Threads /usr/lib/x86_64-linux-gnu/libnl-genl-3.a /usr/lib/x86_64-linux-gnu/libnl-3.a) +else() + target_link_libraries(vwifi_common PUBLIC Threads::Threads PkgConfig::LIBNL3) +endif() # --- Executables --- diff --git a/src/cmonwirelessdevice.cc b/src/cmonwirelessdevice.cc index 0fdf666..1d41684 100644 --- a/src/cmonwirelessdevice.cc +++ b/src/cmonwirelessdevice.cc @@ -323,7 +323,7 @@ void MonitorWirelessDevice::new_net_interface(struct nlmsghdr *h) if(inetdevice.checkif_wireless_device()){ - get_winterface_infos(ifi->ifi_index); // we can call a callback here, instead calling it in recv_winterface_infos, to reduce cpu + _newinet_cb(inetdevice); // Fix: call directly, skip nl80211 roundtrip (races with winet_update_loop) } }