Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pawsten committed Oct 5, 2023
1 parent aa968b8 commit cc94656
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
8 changes: 4 additions & 4 deletions libebpfdiscovery/headers/ebpfdiscovery/IpAddressChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

namespace ebpfdiscovery {

using IPv4 = uint32_t;
using IPv4int = uint32_t;

struct IpIfce {
std::vector<IPv4> ip;
std::vector<IPv4> broadcast;
std::vector<IPv4int> ip;
std::vector<IPv4int> broadcast;
uint32_t mask;
int index;
bool isLocalBridge;
Expand All @@ -32,7 +32,7 @@ class IpAddressChecker {
public:
IpAddressChecker(const NetlinkCalls &calls);
IpAddressChecker(std::initializer_list<IpIfce> config, const NetlinkCalls &calls);
bool isAddressExternalLocal(IPv4 addr);
bool isAddressExternalLocal(IPv4int addr);
bool readNetworks();
};
} // namespace ebpfdiscovery
Expand Down
10 changes: 4 additions & 6 deletions libebpfdiscovery/src/IpAddressChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <string_view>
#include <unistd.h>

static constexpr uint32_t BUFFLEN{4096};
static constexpr uint32_t BUFLEN{4096};
static constexpr uint32_t IP_CLASS_C{0x0000a8c0}; // 192.168.*.*
static constexpr uint32_t MASK_CLASS_C{0x0000ffff};
static constexpr uint32_t IP_CLASS_B{0x000010ac}; // 172.16-31.*.*
Expand All @@ -29,7 +29,6 @@ static void logErrorFromErrno(std::string_view prefix) {
std::cout << prefix << ": " << strerror(errno) << "\n";
}


static ebpfdiscovery::IpIfce parseIfceIPv4(void* data, size_t len) {
ebpfdiscovery::IpIfce ifce{};
ifaddrmsg* ifa = reinterpret_cast<ifaddrmsg*>(data);
Expand Down Expand Up @@ -67,7 +66,6 @@ static int getIfIndex(void* data) {

namespace ebpfdiscovery {


IpAddressChecker::IpAddressChecker(std::initializer_list<IpIfce> config, const NetlinkCalls &calls) :netlink(calls) {
interfaces.insert(interfaces.end(), config.begin(), config.end());
}
Expand Down Expand Up @@ -128,8 +126,8 @@ static bool handleNetlink(S send, R receive, P parse, int domain) {

uint32_t nlMsgType;
do {
std::array<char, BUFFLEN> buf{};
len = receive(fd, &sa, buf.data(), BUFFLEN);
std::array<char, BUFLEN> buf{};
len = receive(fd, &sa, buf.data(), BUFLEN);
if (len <= 0) {
logErrorFromErrno("receive");
break;
Expand Down Expand Up @@ -177,7 +175,7 @@ bool IpAddressChecker::isLoopback(const IpIfce& ifce) {
});
}

bool IpAddressChecker::isAddressExternalLocal(IPv4 addr) {
bool IpAddressChecker::isAddressExternalLocal(IPv4int addr) {
const bool isPublic = ((addr & MASK_CLASS_A) != IP_CLASS_A) && ((addr & MASK_CLASS_B) != IP_CLASS_B) && ((addr & MASK_CLASS_C) != IP_CLASS_C);

if (isPublic) {
Expand Down

0 comments on commit cc94656

Please sign in to comment.