diff --git a/.github/workflows/build-and-test-linux.yaml b/.github/workflows/build-and-test-linux.yaml index b95caddc8..5e54f6f88 100644 --- a/.github/workflows/build-and-test-linux.yaml +++ b/.github/workflows/build-and-test-linux.yaml @@ -96,6 +96,8 @@ jobs: libimlib2-dev \ libircclient-dev \ libiw-dev \ + libnl-3-dev\ + libnl-route-3-dev\ liblua5.3-dev \ libmicrohttpd-dev \ libmysqlclient-dev \ diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index bb0f28d51..fc81852f8 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -44,6 +44,8 @@ jobs: libimlib2-dev \ libircclient-dev \ libiw-dev \ + libnl-3-dev\ + libnl-route-3-dev\ liblua5.3-dev \ libmicrohttpd-dev \ libmysqlclient-dev \ diff --git a/.github/workflows/publish-appimage.yml b/.github/workflows/publish-appimage.yml index 4ef460263..ff4fb3046 100644 --- a/.github/workflows/publish-appimage.yml +++ b/.github/workflows/publish-appimage.yml @@ -50,6 +50,8 @@ jobs: libimlib2-dev \ libircclient-dev \ libiw-dev \ + libnl-3-dev\ + libnl-route-3-dev\ liblua5.3-dev \ libmicrohttpd-dev \ libmysqlclient-dev \ diff --git a/cmake/ConkyPlatformChecks.cmake b/cmake/ConkyPlatformChecks.cmake index d2996ab33..fa2b595bf 100644 --- a/cmake/ConkyPlatformChecks.cmake +++ b/cmake/ConkyPlatformChecks.cmake @@ -290,7 +290,10 @@ if(BUILD_WLAN AND OS_LINUX) if(NOT NL_FOUND) message(FATAL_ERROR "Unable to find netlink library") - endif(NOT NL_FOUND) + endif() + if(NOT HAVE_LIBNL_ROUTE) + message(FATAL_ERROR "Unable to find netlink route library") + endif() set(conky_includes ${conky_includes} ${NL_INCLUDE_DIRS}) set(conky_libs ${conky_libs} ${NL_LIBRARIES}) diff --git a/cmake/FindNL.cmake b/cmake/FindNL.cmake index 761983f7c..0c7263d98 100644 --- a/cmake/FindNL.cmake +++ b/cmake/FindNL.cmake @@ -1,5 +1,3 @@ -# Source: https://github.com/wireshark/wireshark/blob/master/cmake/modules/FindNL.cmake -# # Find the native netlink includes and library # # If they exist, differentiate between versions 1, 2 and 3. @@ -12,6 +10,11 @@ # NL_LIBRARIES - List of libraries when using libnl. # NL_FOUND - True if libnl found. +# Based on wireshark FindNL: +# https://github.com/wireshark/wireshark/blob/master/cmake/modules/FindNL.cmake +# Modified so it doesn't make any hard requirements for libraries used by the +# project. + if(NL_LIBRARIES AND NL_INCLUDE_DIRS) # in cache already SET(NL_FOUND TRUE) @@ -27,6 +30,9 @@ else() pkg_check_modules(NL3 libnl-3.0 libnl-genl-3.0 libnl-route-3.0) if(NOT NL3_FOUND) pkg_search_module(NL2 libnl-2.0) + if (NL2_FOUND) + mark_as_advanced(NL2_INCLUDE_DIR NL2_LIBRARY) + endif() endif() # Try to find NL 2.0, 3.0 or 3.1 (/usr/include/netlink/version.h) or @@ -38,11 +44,12 @@ else() NAMES netlink/version.h HINTS - "${NL3_libnl-3.0_INCLUDEDIR}" - "${NL2_INCLUDEDIR}" + "${NL3_libnl-3.0_includeDIR}" + "${NL2_includeDIR}" PATHS $(SEARCHPATHS) ) + # NL version >= 2 if(NL3_INCLUDE_DIR) find_library(NL3_LIBRARY @@ -56,6 +63,16 @@ else() PATHS $(SEARCHPATHS) ) + + if(NL3_LIBRARY) + set(NL_LIBRARIES ${NL_LIBRARIES} ${NL3_LIBRARY}) + set(NL_INCLUDE_DIRS ${NL_INCLUDE_DIRS} ${NL3_INCLUDE_DIR}) + set(HAVE_LIBNL 1) + mark_as_advanced(NL3_LIBRARY HAVE_LIBNL) + else() + + endif() + find_library(NLGENL_LIBRARY NAMES nl-genl-3 nl-genl @@ -67,6 +84,13 @@ else() PATHS $(SEARCHPATHS) ) + + if(NLGENL_LIBRARY) + mark_as_advanced(NLGENL_LIBRARY) + set(NL_LIBRARIES ${NL_LIBRARIES} ${NLGENL_LIBRARY}) + set(HAVE_LIBNL_GENL 1) + endif() + find_library(NLROUTE_LIBRARY NAMES nl-route-3 nl-route @@ -78,67 +102,22 @@ else() PATHS $(SEARCHPATHS) ) - # - # If we don't have all of those libraries, we can't use libnl. - # - if(NL3_LIBRARY AND NLGENL_LIBRARY AND NLROUTE_LIBRARY) - set(NL_LIBRARY ${NL3_LIBRARY}) - if(NL3_INCLUDE_DIR) - # NL2 and NL3 are similar and just affect how the version is reported in - # the --version output. In cast of doubt, assume NL3 since a library - # without version number could be any of 2.0, 3.0 or 3.1. - if(NOT NL3_FOUND AND NL2_FOUND) - set(HAVE_LIBNL2 1) - else() - set(HAVE_LIBNL3 1) - endif() - endif() + + if(NLROUTE_LIBRARY) + mark_as_advanced(NLROUTE_LIBRARY) + set(NL_LIBRARIES ${NL_LIBRARIES} ${NLROUTE_LIBRARY}) + set(HAVE_LIBNL_ROUTE 1) endif() - set(NL_INCLUDE_DIR ${NL3_INCLUDE_DIR}) - endif() - # libnl-2 and libnl-3 not found, try NL version 1 - if(NOT (NL_LIBRARY AND NL_INCLUDE_DIR)) - pkg_search_module(NL1 libnl-1) - find_path(NL1_INCLUDE_DIR - NAMES - netlink/netlink.h - HINTS - "${NL1_INCLUDEDIR}" - PATHS - $(SEARCHPATHS) - ) - find_library(NL1_LIBRARY - NAMES - nl - PATH_SUFFIXES - lib64 lib - HINTS - "${NL1_LIBDIR}" - PATHS - $(SEARCHPATHS) - ) - set(NL_LIBRARY ${NL1_LIBRARY}) - set(NL_INCLUDE_DIR ${NL1_INCLUDE_DIR}) - if(NL1_LIBRARY AND NL1_INCLUDE_DIR) - set(HAVE_LIBNL1 1) + if(NOT NL3_FOUND AND NL2_FOUND) + set(HAVE_LIBNL2 1) + else() + set(HAVE_LIBNL3 1) endif() endif() endif() -# MESSAGE(STATUS "LIB Found: ${NL_LIBRARY}, Suffix: ${NLSUFFIX}\n 1:${HAVE_LIBNL1}, 2:${HAVE_LIBNL2}, 3:${HAVE_LIBNL3}.") -# handle the QUIETLY and REQUIRED arguments and set NL_FOUND to TRUE if -# all listed variables are TRUE -INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(NL DEFAULT_MSG NL_LIBRARY NL_INCLUDE_DIR) - -IF(NL_FOUND) - set(NL_LIBRARIES ${NLGENL_LIBRARY} ${NLROUTE_LIBRARY} ${NL_LIBRARY}) - set(NL_INCLUDE_DIRS ${NL_INCLUDE_DIR}) - set(HAVE_LIBNL 1) -else() - set(NL_LIBRARIES ) - set(NL_INCLUDE_DIRS) -endif() +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(NL DEFAULT_MSG NL_LIBRARIES NL_INCLUDE_DIRS) +mark_as_advanced(NL_LIBRARIES NL_INCLUDE_DIRS) -MARK_AS_ADVANCED( NL_LIBRARIES NL_INCLUDE_DIRS ) diff --git a/src/linux.cc b/src/linux.cc index d9ab45b01..d9677ee22 100644 --- a/src/linux.cc +++ b/src/linux.cc @@ -87,9 +87,9 @@ #endif #ifdef BUILD_WLAN -#include -#include -#include +#include +#include +#include #include #endif @@ -644,7 +644,7 @@ void update_net_interfaces(FILE *net_dev_fp, bool is_first_update, } nl_link = nullptr; } - if (nl_link == nullptr) { nl_index == -1; } + if (nl_link == nullptr) { nl_index = -1; } } if (nl_link != nullptr) { // See: http://www.infradead.org/~tgr/libnl/doc/route.html#link_object @@ -680,7 +680,7 @@ void update_net_interfaces(FILE *net_dev_fp, bool is_first_update, ns->freq[0] */ - auto modes = rtnl_link_get_flags(struct rtnl_link * link); + auto modes = rtnl_link_get_flags(nl_link); rtnl_link_flags2str(modes, ns->mode, 64); }