Skip to content

Commit

Permalink
Fix more possible clang-tidy issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
abeltrano committed Feb 22, 2024
1 parent a85c335 commit 703a4b5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
4 changes: 4 additions & 0 deletions src/linux/libnl-helpers/Netlink80211Interface.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

using namespace Microsoft::Net::Netlink::Nl80211;

// NOLINTBEGIN(concurrency-mt-unsafe)

Nl80211Interface::Nl80211Interface(std::string_view name, nl80211_iftype type, uint32_t index, uint32_t wiphyIndex) noexcept :
Name(name),
Type(type),
Expand Down Expand Up @@ -177,3 +179,5 @@ Nl80211Interface::IsAccessPoint() const noexcept
{
return (Type == nl80211_iftype::NL80211_IFTYPE_AP);
}

// NOLINTEND(concurrency-mt-unsafe)
4 changes: 2 additions & 2 deletions src/linux/libnl-helpers/Netlink80211ProtocolState.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ Nl80211ProtocolState::Nl80211ProtocolState()
auto netlinkSocket{ NetlinkSocket::Allocate() };

// Connect the socket to the generic netlink family.
int ret = genl_connect(netlinkSocket);
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));
LOGE << std::format("Failed to connect netlink socket for nl control with error {} ({})", err, strerror(err)); // NOLINT(concurrency-mt-unsafe)
throw err;
}

Expand Down
24 changes: 12 additions & 12 deletions src/linux/libnl-helpers/Netlink80211Wiphy.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ HandleNl80211GetWiphyResponse(struct nl_msg *nl80211Message, void *context) noex

/* static */
std::optional<Nl80211Wiphy>
Nl80211Wiphy::FromId(std::function<void(Microsoft::Net::Netlink::NetlinkMessage &)> addWiphyIdentifier)
Nl80211Wiphy::FromId(const std::function<void(Microsoft::Net::Netlink::NetlinkMessage &)> &addWiphyIdentifier)
{
// Allocate a new netlink socket.
auto nl80211SocketOpt{ CreateNl80211Socket() };
Expand Down Expand Up @@ -178,7 +178,7 @@ Nl80211Wiphy::Parse(struct nl_msg *nl80211Message) noexcept
std::array<struct nlattr *, NL80211_ATTR_MAX + 1> wiphyAttributes{};
int ret = nla_parse(std::data(wiphyAttributes), std::size(wiphyAttributes), genlmsg_attrdata(genl80211MessageHeader, 0), genlmsg_attrlen(genl80211MessageHeader, 0), nullptr);
if (ret < 0) {
LOGE << std::format("Failed to parse netlink message attributes with error {} ({})", ret, strerror(-ret));
LOGE << std::format("Failed to parse netlink message attributes with error {} ({})", ret, strerror(-ret)); // NOLINT(concurrency-mt-unsafe)
return std::nullopt;
}

Expand All @@ -189,14 +189,14 @@ Nl80211Wiphy::Parse(struct nl_msg *nl80211Message) noexcept
}

auto wiphyIndex = static_cast<uint32_t>(nla_get_u32(wiphyAttributes[NL80211_ATTR_WIPHY]));
auto wiphyName = static_cast<const char *>(nla_data(wiphyAttributes[NL80211_ATTR_WIPHY_NAME]));
const auto *wiphyName = static_cast<const char *>(nla_data(wiphyAttributes[NL80211_ATTR_WIPHY_NAME]));

// Process bands.
auto wiphyBands = wiphyAttributes[NL80211_ATTR_WIPHY_BANDS];
auto *wiphyBands = wiphyAttributes[NL80211_ATTR_WIPHY_BANDS];
std::unordered_map<nl80211_band, Nl80211WiphyBand> wiphyBandMap{};
if (wiphyBands != nullptr) {
int remainingBands;
struct nlattr *wiphyBand;
int remainingBands = 0;
struct nlattr *wiphyBand = nullptr;

nla_for_each_nested(wiphyBand, wiphyBands, remainingBands)
{
Expand All @@ -214,13 +214,13 @@ Nl80211Wiphy::Parse(struct nl_msg *nl80211Message) noexcept

// Process AKM suites.
// Note: NL80211_ATTR_AKM_SUITES describes the AKMs supported by the PHY (wiphy) and is not specific to an interface.
uint32_t *wiphyAkmSuites;
uint32_t *wiphyAkmSuites = nullptr;
std::size_t wiphyNumAkmSuites = 0;
std::vector<uint32_t> akmSuites{};
if (wiphyAttributes[NL80211_ATTR_AKM_SUITES] != nullptr) {
wiphyAkmSuites = static_cast<uint32_t *>(nla_data(wiphyAttributes[NL80211_ATTR_AKM_SUITES]));
wiphyNumAkmSuites = static_cast<std::size_t>(nla_len(wiphyAttributes[NL80211_ATTR_AKM_SUITES])) / sizeof(*wiphyAkmSuites);
akmSuites = std::vector<uint32_t>(wiphyAkmSuites, wiphyAkmSuites + wiphyNumAkmSuites);
akmSuites = std::vector<uint32_t>(wiphyAkmSuites, wiphyAkmSuites + wiphyNumAkmSuites); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
} else {
// Per nl80211 documentation, if this attribute is not present, userspace should assume all AKMs are supported.
akmSuites = Microsoft::Net::Wifi::AllIeee80211Akms;
Expand All @@ -230,17 +230,17 @@ Nl80211Wiphy::Parse(struct nl_msg *nl80211Message) noexcept
std::size_t wiphyNumCipherSuites = 0;
std::vector<uint32_t> cipherSuites{};
if (wiphyAttributes[NL80211_ATTR_CIPHER_SUITES] != nullptr) {
uint32_t *wiphyCipherSuites;
uint32_t *wiphyCipherSuites = nullptr;
wiphyNumCipherSuites = static_cast<std::size_t>(nla_len(wiphyAttributes[NL80211_ATTR_CIPHER_SUITES])) / sizeof(*wiphyCipherSuites);
wiphyCipherSuites = static_cast<uint32_t *>(nla_data(wiphyAttributes[NL80211_ATTR_CIPHER_SUITES]));
cipherSuites = std::vector<uint32_t>(wiphyCipherSuites, wiphyCipherSuites + wiphyNumCipherSuites);
cipherSuites = std::vector<uint32_t>(wiphyCipherSuites, wiphyCipherSuites + wiphyNumCipherSuites); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
}

// Process supported interface types.
std::vector<nl80211_iftype> supportedInterfaceTypes{};
if (wiphyAttributes[NL80211_ATTR_SUPPORTED_IFTYPES] != nullptr) {
int remainingSupportedInterfaceTypes;
struct nlattr *supportedInterfaceType;
int remainingSupportedInterfaceTypes = 0;
struct nlattr *supportedInterfaceType = nullptr;
nla_for_each_nested(supportedInterfaceType, wiphyAttributes[NL80211_ATTR_SUPPORTED_IFTYPES], remainingSupportedInterfaceTypes)
{
auto interfaceType = static_cast<nl80211_iftype>(supportedInterfaceType->nla_type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private:
* @return std::optional<Nl80211Wiphy>
*/
static std::optional<Nl80211Wiphy>
FromId(std::function<void(Microsoft::Net::Netlink::NetlinkMessage&)> addWiphyIdentifier);
FromId(const std::function<void(Microsoft::Net::Netlink::NetlinkMessage&)>& addWiphyIdentifier);
};

} // namespace Microsoft::Net::Netlink::Nl80211
Expand Down
13 changes: 10 additions & 3 deletions src/linux/tools/apmonitor/Main.cxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@

#include <csignal> // NOLINT(misc-include-cleaner)
// NOLINTBEGIN(misc-include-cleaner, concurrency-mt-unsafe)
// clang-tidy can't seem to figure out that sig/SIG* stuff is indirectly included by <csignal>. While we could include
// the actual headers directly, this goes against the std library's convention of including the top-level header.

#include <csignal>
#include <format>
#include <memory>
#include <utility>
Expand Down Expand Up @@ -37,7 +41,7 @@ main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
accessPointDiscoveryAgent->Start();

// Mask SIGTERM and SIGINT so they can be explicitly waited on from the main thread.
int signal;
int signal = 0;
sigset_t mask;
sigemptyset(&mask);
sigaddset(&mask, SIGTERM);
Expand All @@ -49,11 +53,14 @@ main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
}

// Wait for the process to be signaled to exit.
while (sigwait(&mask, &signal) != 0)
while (sigwait(&mask, &signal) != 0) {
;
}

// Received interrupt or terminate signal, so shut down.
accessPointDiscoveryAgent->Stop();

return 0;
}

// NOLINTEND(misc-include-cleaner, concurrency-mt-unsafe)

0 comments on commit 703a4b5

Please sign in to comment.