diff --git a/src/common/shared/notstd/CMakeLists.txt b/src/common/shared/notstd/CMakeLists.txt index 1ecf3e8c..3b2d7fe9 100644 --- a/src/common/shared/notstd/CMakeLists.txt +++ b/src/common/shared/notstd/CMakeLists.txt @@ -13,7 +13,6 @@ target_sources(notstd ${NOTSTD_PUBLIC_INCLUDE_PREFIX}/Exceptions.hxx ${NOTSTD_PUBLIC_INCLUDE_PREFIX}/Memory.hxx ${NOTSTD_PUBLIC_INCLUDE_PREFIX}/Scope.hxx - ${NOTSTD_PUBLIC_INCLUDE_PREFIX}/Utility.hxx ) install( diff --git a/src/common/shared/notstd/include/notstd/Utility.hxx b/src/common/shared/notstd/include/notstd/Utility.hxx deleted file mode 100644 index 87894611..00000000 --- a/src/common/shared/notstd/include/notstd/Utility.hxx +++ /dev/null @@ -1,32 +0,0 @@ - -#ifndef NOTSTD_UTILITY_HXX -#define NOTSTD_UTILITY_HXX - -#include -#include - -namespace notstd -{ -/** - * @brief Converts a enumeration value to its underlying type. - * - * The function prototype matches the C++23 function so can be used in its - * place. - * - * @tparam Enum The enumeration class type to convert. - * @param e The enumeration class value. - * @return constexpr std::underlying_type_t - */ -// clang-format off -template -requires std::is_enum_v -constexpr std::underlying_type_t -// clang-format on -to_underlying(EnumT e) noexcept -{ - return static_cast>(e); -} - -} // namespace notstd - -#endif // NOTSTD_UTILITY_HXX diff --git a/src/linux/libnl-helpers/CMakeLists.txt b/src/linux/libnl-helpers/CMakeLists.txt index c5a51c63..872535ad 100644 --- a/src/linux/libnl-helpers/CMakeLists.txt +++ b/src/linux/libnl-helpers/CMakeLists.txt @@ -9,18 +9,22 @@ target_sources(libnl-helpers PRIVATE Netlink80211.cxx Netlink80211Interface.cxx + NetlinkException.cxx Netlink80211ProtocolState.cxx Netlink80211Wiphy.cxx - NetlinkMessage.cxx - NetlinkSocket.cxx Netlink80211WiphyBand.cxx Netlink80211WiphyBandFrequency.cxx + NetlinkErrorCategory.cxx + NetlinkMessage.cxx + NetlinkSocket.cxx PUBLIC FILE_SET HEADERS BASE_DIRS ${LIBNL_HELPERS_PUBLIC_INCLUDE} FILES + ${LIBNL_HELPERS_PUBLIC_INCLUDE_PREFIX}/NetlinkErrorCategory.hxx ${LIBNL_HELPERS_PUBLIC_INCLUDE_PREFIX}/NetlinkMessage.hxx ${LIBNL_HELPERS_PUBLIC_INCLUDE_PREFIX}/NetlinkSocket.hxx + ${LIBNL_HELPERS_PUBLIC_INCLUDE_PREFIX}/NetlinkException.hxx ${LIBNL_HELPERS_PUBLIC_INCLUDE_PREFIX}/nl80211/Netlink80211.hxx ${LIBNL_HELPERS_PUBLIC_INCLUDE_PREFIX}/nl80211/Netlink80211Interface.hxx ${LIBNL_HELPERS_PUBLIC_INCLUDE_PREFIX}/nl80211/Netlink80211ProtocolState.hxx diff --git a/src/linux/libnl-helpers/Netlink80211.cxx b/src/linux/libnl-helpers/Netlink80211.cxx index 8a89a143..887f842f 100644 --- a/src/linux/libnl-helpers/Netlink80211.cxx +++ b/src/linux/libnl-helpers/Netlink80211.cxx @@ -1,14 +1,13 @@ #include #include -#include #include -#include +#include #include +#include #include #include -#include #include #include @@ -506,24 +505,22 @@ Nl80211CipherSuiteToString(uint32_t cipherSuite) noexcept using Microsoft::Net::Netlink::NetlinkSocket; -std::optional +NetlinkSocket CreateNl80211Socket() { // Allocate a new netlink socket. auto netlinkSocket{ NetlinkSocket::Allocate() }; - if (netlinkSocket == nullptr) { - LOGE << "Failed to allocate new netlink socket for nl control"; - return std::nullopt; - } // Connect the socket to the generic netlink family. - int ret = genl_connect(netlinkSocket); + const int ret = genl_connect(netlinkSocket); if (ret < 0) { - LOGE << std::format("Failed to connect netlink socket for nl control with error {} ({})", ret, nl_geterror(ret)); - return std::nullopt; + const auto errorCode = MakeNetlinkErrorCode(-ret); + const auto message = std::format("Failed to connect netlink socket for nl control with error {}", errorCode.value()); + LOGE << message; + throw std::system_error(errorCode, message); } - return std::move(netlinkSocket); + return netlinkSocket; } } // namespace Microsoft::Net::Netlink::Nl80211 diff --git a/src/linux/libnl-helpers/Netlink80211Interface.cxx b/src/linux/libnl-helpers/Netlink80211Interface.cxx index 25b2f4f0..30eacf81 100644 --- a/src/linux/libnl-helpers/Netlink80211Interface.cxx +++ b/src/linux/libnl-helpers/Netlink80211Interface.cxx @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -108,7 +107,7 @@ HandleNl80211InterfaceDumpResponse(struct nl_msg *nl80211Message, void *context) LOGW << "Failed to parse nl80211 interface dump response"; return NL_SKIP; } - + LOGD << std::format("Parsed nl80211 interface dump response: {}", nl80211Interface->ToString()); nl80211Interfaces.push_back(std::move(nl80211Interface.value())); @@ -120,15 +119,7 @@ HandleNl80211InterfaceDumpResponse(struct nl_msg *nl80211Message, void *context) std::vector Nl80211Interface::Enumerate() { - // Allocate a new netlink socket. - auto nl80211SocketOpt{ CreateNl80211Socket() }; - if (!nl80211SocketOpt.has_value()) { - LOGE << "Failed to create nl80211 socket"; - return {}; - } - // Allocate a new nl80211 message for sending the dump request for all interfaces. - auto nl80211Socket{ std::move(nl80211SocketOpt.value()) }; auto nl80211MessageGetInterfaces{ NetlinkMessage::Allocate() }; if (nl80211MessageGetInterfaces == nullptr) { LOGE << "Failed to allocate nl80211 message for interface dump request"; @@ -144,6 +135,7 @@ Nl80211Interface::Enumerate() } // Modify the socket callback to handle the response, providing a pointer to the vector to populate with interfaces. + auto nl80211Socket{ CreateNl80211Socket() }; std::vector nl80211Interfaces{}; int ret = nl_socket_modify_cb(nl80211Socket, NL_CB_VALID, NL_CB_CUSTOM, detail::HandleNl80211InterfaceDumpResponse, &nl80211Interfaces); if (ret < 0) { diff --git a/src/linux/libnl-helpers/Netlink80211ProtocolState.cxx b/src/linux/libnl-helpers/Netlink80211ProtocolState.cxx index 930e6c38..d56ea840 100644 --- a/src/linux/libnl-helpers/Netlink80211ProtocolState.cxx +++ b/src/linux/libnl-helpers/Netlink80211ProtocolState.cxx @@ -1,17 +1,14 @@ -#include -#include #include #include #include +#include #include #include #include -#include #include #include -#include using namespace Microsoft::Net::Netlink::Nl80211; @@ -25,24 +22,20 @@ Nl80211ProtocolState::Nl80211ProtocolState() // Connect the socket to the generic netlink family. const int ret = genl_connect(netlinkSocket); if (ret < 0) { - const auto err = errno; - LOGE << std::format("Failed to connect netlink socket for nl control with error {} ({})", err, strerror(err)); // NOLINT(concurrency-mt-unsafe) - throw err; + throw NetlinkException::CreateLogged(-ret, "Failed to connect netlink socket for nl control"); } // Look up the nl80211 driver id. DriverId = genl_ctrl_resolve(netlinkSocket, NL80211_GENL_NAME); if (DriverId < 0) { - LOGE << std::format("Failed to resolve nl80211 netlink id with error {} ({})", DriverId, nl_geterror(DriverId)); - throw DriverId; + throw NetlinkException::CreateLogged(-DriverId, "Failed to resolve nl80211 netlink id"); } // Lookup the ids for the nl80211 multicast groups. for (const auto& [multicastGroup, multicastGroupName] : Nl80211MulticastGroupNames) { - int multicastGroupId = genl_ctrl_resolve_grp(netlinkSocket, NL80211_GENL_NAME, std::data(multicastGroupName)); + const int multicastGroupId = genl_ctrl_resolve_grp(netlinkSocket, NL80211_GENL_NAME, std::data(multicastGroupName)); if (multicastGroupId < 0) { - LOGE << std::format("Failed to resolve nl80211 {} multicast group id with error {} ({})", multicastGroupName, multicastGroupId, nl_geterror(multicastGroupId)); - throw multicastGroupId; + throw NetlinkException::CreateLogged(-multicastGroupId, std::format("Failed to resolve nl80211 {} multicast group id", multicastGroupName)); } MulticastGroupId[multicastGroup] = multicastGroupId; } diff --git a/src/linux/libnl-helpers/Netlink80211Wiphy.cxx b/src/linux/libnl-helpers/Netlink80211Wiphy.cxx index 236bfbc1..9d48c09f 100644 --- a/src/linux/libnl-helpers/Netlink80211Wiphy.cxx +++ b/src/linux/libnl-helpers/Netlink80211Wiphy.cxx @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -76,17 +75,9 @@ HandleNl80211GetWiphyResponse(struct nl_msg *nl80211Message, void *context) noex /* static */ std::optional -Nl80211Wiphy::FromId(const std::function &addWiphyIdentifier) +Nl80211Wiphy::FromId(const std::function &addWiphyIdentifier) { - // Allocate a new netlink socket. - auto nl80211SocketOpt{ CreateNl80211Socket() }; - if (!nl80211SocketOpt.has_value()) { - LOGE << "Failed to create nl80211 socket"; - return std::nullopt; - } - // Allocate a new nl80211 message for sending the dump request for all interfaces. - auto nl80211Socket{ std::move(nl80211SocketOpt.value()) }; auto nl80211MessageGetWiphy{ NetlinkMessage::Allocate() }; if (nl80211MessageGetWiphy == nullptr) { LOGE << "Failed to allocate nl80211 message for wiphy request"; @@ -104,6 +95,7 @@ Nl80211Wiphy::FromId(const std::function nl80211Wiphy{}; int ret = nl_socket_modify_cb(nl80211Socket, NL_CB_VALID, NL_CB_CUSTOM, detail::HandleNl80211GetWiphyResponse, &nl80211Wiphy); if (ret < 0) { diff --git a/src/linux/libnl-helpers/Netlink80211WiphyBand.cxx b/src/linux/libnl-helpers/Netlink80211WiphyBand.cxx index d7f83e30..9808ca24 100644 --- a/src/linux/libnl-helpers/Netlink80211WiphyBand.cxx +++ b/src/linux/libnl-helpers/Netlink80211WiphyBand.cxx @@ -24,7 +24,7 @@ Nl80211WiphyBand::Nl80211WiphyBand(std::vector frequencies, Bitrates(std::move(bitRates)), HtCapabilities(htCapabilities), VhtCapabilities(VhtCapabilities), - VhtMcsSet(std::move(vhtMcsSetOpt)) + VhtMcsSet(vhtMcsSetOpt) { } @@ -58,21 +58,21 @@ Nl80211WiphyBand::Parse(struct nlattr *wiphyBand) noexcept std::vector frequencies{}; if (wiphyBandAttributes[NL80211_BAND_ATTR_FREQS] != nullptr) { - struct nlattr *wiphyBandFrequency; - int remainingBandFrequencies; + struct nlattr *wiphyBandFrequency = nullptr; + int remainingBandFrequencies = 0; nla_for_each_nested(wiphyBandFrequency, wiphyBandAttributes[NL80211_BAND_ATTR_FREQS], remainingBandFrequencies) { auto frequency = WiphyBandFrequency::Parse(wiphyBandFrequency); if (frequency.has_value()) { - frequencies.emplace_back(std::move(frequency.value())); + frequencies.emplace_back(frequency.value()); } } } std::vector bitRates{}; if (wiphyBandAttributes[NL80211_BAND_ATTR_RATES] != nullptr) { - int remainingBitRates; - struct nlattr *bitRate; + int remainingBitRates = 0; + struct nlattr *bitRate = nullptr; nla_for_each_nested(bitRate, wiphyBandAttributes[NL80211_BAND_ATTR_RATES], remainingBitRates) { std::array bitRateAttributes{}; @@ -80,7 +80,8 @@ Nl80211WiphyBand::Parse(struct nlattr *wiphyBand) noexcept if (ret < 0) { LOGW << std::format("Failed to parse wiphy band bit rate attributes with error {} ({})", ret, nl_geterror(ret)); return std::nullopt; - } else if (bitRateAttributes[NL80211_BITRATE_ATTR_RATE] == nullptr) { + } + if (bitRateAttributes[NL80211_BITRATE_ATTR_RATE] == nullptr) { continue; } @@ -89,7 +90,7 @@ Nl80211WiphyBand::Parse(struct nlattr *wiphyBand) noexcept } } - return Nl80211WiphyBand(std::move(frequencies), std::move(bitRates), htCapabilities, vhtCapabilities, std::move(vhtMcsSetOpt)); + return Nl80211WiphyBand(std::move(frequencies), std::move(bitRates), htCapabilities, vhtCapabilities, vhtMcsSetOpt); } std::string diff --git a/src/linux/libnl-helpers/NetlinkErrorCategory.cxx b/src/linux/libnl-helpers/NetlinkErrorCategory.cxx new file mode 100644 index 00000000..d50da058 --- /dev/null +++ b/src/linux/libnl-helpers/NetlinkErrorCategory.cxx @@ -0,0 +1,47 @@ + +#include +#include +#include + +#include +#include + +namespace Microsoft::Net::Netlink +{ + +const char* +NetlinkErrorCategory::name() const noexcept +{ + static constexpr const char* Name = "Netlink"; + return Name; +} + +std::string +NetlinkErrorCategory::message(int error) const +{ + return nl_geterror(error); +} + +std::error_condition +NetlinkErrorCategory::default_error_condition(int error) const noexcept +{ + return std::error_condition(error, *this); +} + +std::error_code +make_netlink_error_code(int error) +{ + return std::error_code(error, NetlinkErrorCategory()); +} + +std::error_code +MakeNetlinkErrorCode(int error) +{ + if (error < 0) { + throw std::runtime_error("Netlink error codes must be non-negative; this is a programming error"); + } + + return make_netlink_error_code(error); +} + +} // namespace Microsoft::Net::Netlink diff --git a/src/linux/libnl-helpers/NetlinkException.cxx b/src/linux/libnl-helpers/NetlinkException.cxx new file mode 100644 index 00000000..7152e35f --- /dev/null +++ b/src/linux/libnl-helpers/NetlinkException.cxx @@ -0,0 +1,34 @@ + +#include +#include +#include + +#include +#include +#include + +using namespace Microsoft::Net::Netlink; + +NetlinkException::NetlinkException(int error, const char *what) : + std::system_error(MakeNetlinkErrorCode(error), what) +{} + +NetlinkException::NetlinkException(int error, const std::string &what) : + NetlinkException(error, what.c_str()) +{} + +/* static */ +NetlinkException +NetlinkException::CreateLogged(int error, const char *what) +{ + NetlinkException netlinkException(error, what); + LOGE << std::format("Netlink error ({}): {} ({})", netlinkException.code().value(), netlinkException.what(), netlinkException.code().message()); + return netlinkException; +} + +/* static */ +NetlinkException +NetlinkException::CreateLogged(int error, const std::string &what) +{ + return CreateLogged(error, what.c_str()); +} diff --git a/src/linux/libnl-helpers/NetlinkSocket.cxx b/src/linux/libnl-helpers/NetlinkSocket.cxx index a24ff1a3..d0649c8b 100644 --- a/src/linux/libnl-helpers/NetlinkSocket.cxx +++ b/src/linux/libnl-helpers/NetlinkSocket.cxx @@ -1,5 +1,9 @@ +#include + +#include #include +#include #include #include @@ -10,6 +14,10 @@ NetlinkSocket NetlinkSocket::Allocate() { auto* socket = nl_socket_alloc(); + if (socket == nullptr) { + throw std::system_error(MakeNetlinkErrorCode(NLE_NOMEM), "Failed to allocate netlink socket"); + } + return NetlinkSocket{ socket }; } diff --git a/src/linux/libnl-helpers/include/microsoft/net/netlink/NetlinkErrorCategory.hxx b/src/linux/libnl-helpers/include/microsoft/net/netlink/NetlinkErrorCategory.hxx new file mode 100644 index 00000000..1b0852e9 --- /dev/null +++ b/src/linux/libnl-helpers/include/microsoft/net/netlink/NetlinkErrorCategory.hxx @@ -0,0 +1,67 @@ + +#ifndef NETLINK_ERROR_CATEGORY_HXX +#define NETLINK_ERROR_CATEGORY_HXX + +#include +#include + +namespace Microsoft::Net::Netlink +{ +/** + * @brief Error category for errors originating from the netlink library. + */ +struct NetlinkErrorCategory : + public std::error_category +{ + /** + * @brief The name of this category. + * + * @return const char* "Netlink". + */ + const char* + name() const noexcept override; + + /** + * @brief A string representation of the error code. + * + * @param error The error code to convert to a string. + * @return std::string + */ + std::string + message(int error) const override; + + /** + * @brief The default error condition for the given error code. + * + * @param error The error code to convert to an error condition. + * @return std::error_condition + */ + std::error_condition + default_error_condition(int error) const noexcept override; +}; + +/** + * @brief Constructs a std::error_code from a netlink error code. + * + * This function uses the std naming convention. + * + * @param error The netlink error code. Must be positive. + * @return std::error_code + */ +[[nodiscard]] std::error_code +make_netlink_error_code(int error); + +/** + * @brief Alias for the make_netlink_error_code function. + * + * This function uses the project naming convention. + * + * @param error + * @return std::error_code + */ +[[nodiscard]] std::error_code +MakeNetlinkErrorCode(int error); + +} // namespace Microsoft::Net::Netlink + +#endif // NETLINK_ERROR_CATEGORY_HXX diff --git a/src/linux/libnl-helpers/include/microsoft/net/netlink/NetlinkException.hxx b/src/linux/libnl-helpers/include/microsoft/net/netlink/NetlinkException.hxx new file mode 100644 index 00000000..a2fc9838 --- /dev/null +++ b/src/linux/libnl-helpers/include/microsoft/net/netlink/NetlinkException.hxx @@ -0,0 +1,61 @@ + +#ifndef NETLINK_EXCEPTION_HXX +#define NETLINK_EXCEPTION_HXX + +#include +#include + +namespace Microsoft::Net::Netlink +{ +/** + * @brief std compatible exception for Netlink errors. + */ +struct NetlinkException : + public std::system_error +{ +public: + /** + * @brief Construct a new NetlinkException object. + * + * @param error The netlink error code. This must be one of the NLE_* values from netlink/errno.h. + * @param what The error message. + */ + explicit NetlinkException(int error, const char* what = ""); + + /** + * @brief Construct a new NetlinkException object. Overload accepting a std::string. + * + * @param error The netlink error code. This must be one of the NLE_* values from netlink/errno.h. + * @param what The error message. + */ + NetlinkException(int error, const std::string& what); + + /** + * @brief Create a NetlinkException and log it. + * + * @param error The netlink error code. This must be one of the NLE_* values from netlink/errno.h. + * @param what The error message. + * @return NetlinkException + */ + static NetlinkException + CreateLogged(int error, const char* what = ""); + + /** + * @brief Create a NetlinkException and log it. Overload accepting a std::string. + * + * @param error The netlink error code. This must be one of the NLE_* values from netlink/errno.h. + * @param what The error message. + * @return NetlinkException + */ + static NetlinkException + CreateLogged(int error, const std::string& what); +}; + +/** + * @brief std-style type alias for NetlinkException. + */ +using netlink_exception = NetlinkException; + +} // namespace Microsoft::Net::Netlink + +#endif // NETLINK_EXCEPTION_HXX diff --git a/src/linux/libnl-helpers/include/microsoft/net/netlink/nl80211/Netlink80211.hxx b/src/linux/libnl-helpers/include/microsoft/net/netlink/nl80211/Netlink80211.hxx index da2462cc..11d414a3 100644 --- a/src/linux/libnl-helpers/include/microsoft/net/netlink/nl80211/Netlink80211.hxx +++ b/src/linux/libnl-helpers/include/microsoft/net/netlink/nl80211/Netlink80211.hxx @@ -3,7 +3,6 @@ #define NETLINK_82011_HXX #include -#include #include #include @@ -20,16 +19,18 @@ enum class Nl80211MulticastGroup { Nan, }; +// NOLINTBEGIN(cert-err58-cpp) /** * @brief Map of multicast group enum values to names. */ -static const std::unordered_map Nl80211MulticastGroupNames{ // NOLINT(cert-err58-cpp) +static const std::unordered_map Nl80211MulticastGroupNames{ { Nl80211MulticastGroup::Configuration, NL80211_MULTICAST_GROUP_CONFIG }, { Nl80211MulticastGroup::Scan, NL80211_MULTICAST_GROUP_SCAN }, { Nl80211MulticastGroup::Regulatory, NL80211_MULTICAST_GROUP_REG }, { Nl80211MulticastGroup::Mlme, NL80211_MULTICAST_GROUP_MLME }, { Nl80211MulticastGroup::Nan, NL80211_MULTICAST_GROUP_NAN }, }; +// NOLINTEND(cert-err58-cpp) /** * @brief Convert an nl80211_commands enum value to a string. @@ -62,9 +63,9 @@ Nl80211CipherSuiteToString(uint32_t cipherSuite) noexcept; * * This creates a netlink socket and connects it to the nl80211 generic netlink family. * - * @return std::optional + * @return Microsoft::Net::Netlink::NetlinkSocket */ -std::optional +Microsoft::Net::Netlink::NetlinkSocket CreateNl80211Socket(); } // namespace Microsoft::Net::Netlink::Nl80211 diff --git a/src/linux/libnl-helpers/include/microsoft/net/netlink/nl80211/Netlink80211Interface.hxx b/src/linux/libnl-helpers/include/microsoft/net/netlink/nl80211/Netlink80211Interface.hxx index cd9d99df..175fbf69 100644 --- a/src/linux/libnl-helpers/include/microsoft/net/netlink/nl80211/Netlink80211Interface.hxx +++ b/src/linux/libnl-helpers/include/microsoft/net/netlink/nl80211/Netlink80211Interface.hxx @@ -29,7 +29,7 @@ struct Nl80211Interface Nl80211Interface() = default; auto - operator <=>(const Nl80211Interface&) const = default; + operator<=>(const Nl80211Interface&) const = default; /** * @brief Construct a new Nl80211Interface object with the specified attributes. @@ -79,9 +79,9 @@ struct Nl80211Interface /** * @brief Indicates if the interface is an access point. - * - * @return true - * @return false + * + * @return true + * @return false */ bool IsAccessPoint() const noexcept; diff --git a/src/linux/wifi/apmanager/AccessPointDiscoveryAgentOperationsNetlink.cxx b/src/linux/wifi/apmanager/AccessPointDiscoveryAgentOperationsNetlink.cxx index 35d594ac..f2bb33a7 100644 --- a/src/linux/wifi/apmanager/AccessPointDiscoveryAgentOperationsNetlink.cxx +++ b/src/linux/wifi/apmanager/AccessPointDiscoveryAgentOperationsNetlink.cxx @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -40,6 +41,7 @@ #include using namespace Microsoft::Net::Wifi; +using namespace Microsoft::Net::Netlink; using namespace Microsoft::Net::Netlink::Nl80211; using Microsoft::Net::Netlink::NetlinkSocket; @@ -96,24 +98,12 @@ AccessPointDiscoveryAgentOperationsNetlink::Start(AccessPointPresenceEventCallba Stop(); } - // TODO: This function needs to signal errors either through its return type, or an exception. - - // Allocate a new netlink socket for use with nl80211. - auto nl80211SocketOpt{ CreateNl80211Socket() }; - if (nl80211SocketOpt == nullptr) { - LOGE << "Failed to allocate new netlink socket for nl control"; - return; - } - - auto nl80211Socket{ std::move(nl80211SocketOpt.value()) }; - // Subscribe to configuration messages. + auto nl80211Socket{ CreateNl80211Socket() }; const int nl80211MulticastGroupIdConfig = m_netlink80211ProtocolState.MulticastGroupId[Nl80211MulticastGroup::Configuration]; const int ret = nl_socket_add_membership(nl80211Socket, nl80211MulticastGroupIdConfig); if (ret < 0) { - const auto err = errno; - LOGE << std::format("Failed to add netlink socket membership for '" NL80211_MULTICAST_GROUP_CONFIG "' group with error {} ({})", err, strerror(err)); - return; + throw NetlinkException::CreateLogged(-ret, "Failed to add netlink socket membership for 'NL80211_MULTICAST_GROUP_CONFIG'"); } // Update the access point presence callback for the netlink message handler to use. @@ -214,6 +204,7 @@ AccessPointDiscoveryAgentOperationsNetlink::ProcessNetlinkMessage(struct nl_msg genlMessageHeader->cmd != NL80211_CMD_DEL_INTERFACE && genlMessageHeader->cmd != NL80211_CMD_SET_INTERFACE) { LOGD << std::format("Ignoring {} nl80211 command message", nl80211CommandName); + return NL_SKIP; } LOGD << std::format("Received {} nl80211 command message", nl80211CommandName);