uint16_t qtype;
// incoming protocol
dnsdist::Protocol protocol;
+#if defined(DNSDIST_RINGS_WITH_MACADDRESS)
+ char macaddress[6];
+ bool hasmac{false};
+#endif
};
struct Response
{
void insertQuery(const struct timespec& when, const ComboAddress& requestor, const DNSName& name, uint16_t qtype, uint16_t size, const struct dnsheader& dh, dnsdist::Protocol protocol)
{
+#if defined(DNSDIST_RINGS_WITH_MACADDRESS)
+ char macaddress[6];
+ bool hasmac{false};
+ if (getMACAddress(requestor, macaddress, sizeof(macaddress)) == 0) {
+ hasmac = true;
+ }
+#endif
for (size_t idx = 0; idx < d_nbLockTries; idx++) {
auto& shard = getOneShard();
auto lock = shard->queryRing.try_lock();
if (lock.owns_lock()) {
+#if defined(DNSDIST_RINGS_WITH_MACADDRESS)
+ insertQueryLocked(*lock, when, requestor, name, qtype, size, dh, protocol, macaddress, sizeof(macaddress), hasmac);
+#else
insertQueryLocked(*lock, when, requestor, name, qtype, size, dh, protocol);
+#endif
return;
}
if (d_keepLockingStats) {
}
auto& shard = getOneShard();
auto lock = shard->queryRing.lock();
+#if defined(DNSDIST_RINGS_WITH_MACADDRESS)
+ insertQueryLocked(*lock, when, requestor, name, qtype, size, dh, protocol, macaddress, sizeof(macaddress), hasmac);
+#else
insertQueryLocked(*lock, when, requestor, name, qtype, size, dh, protocol);
+#endif
}
void insertResponse(const struct timespec& when, const ComboAddress& requestor, const DNSName& name, uint16_t qtype, unsigned int usec, unsigned int size, const struct dnsheader& dh, const ComboAddress& backend, dnsdist::Protocol protocol)
return d_shards[getShardId()];
}
+#if defined(DNSDIST_RINGS_WITH_MACADDRESS)
+ void insertQueryLocked(boost::circular_buffer<Query>& ring, const struct timespec& when, const ComboAddress& requestor, const DNSName& name, uint16_t qtype, uint16_t size, const struct dnsheader& dh, dnsdist::Protocol protocol, const char* macaddress, size_t maclen, const bool hasmac)
+#else
void insertQueryLocked(boost::circular_buffer<Query>& ring, const struct timespec& when, const ComboAddress& requestor, const DNSName& name, uint16_t qtype, uint16_t size, const struct dnsheader& dh, dnsdist::Protocol protocol)
+#endif
{
if (!ring.full()) {
d_nbQueryEntries++;
}
+#if defined(DNSDIST_RINGS_WITH_MACADDRESS)
+ Rings::Query query({requestor, name, when, dh, size, qtype, protocol, "", hasmac});
+ if (hasmac) {
+ memcpy(query.macaddress, macaddress, maclen);
+ }
+ ring.push_back(std::move(query));
+#else
ring.push_back({requestor, name, when, dh, size, qtype, protocol});
+#endif
}
void insertResponseLocked(boost::circular_buffer<Response>& ring, const struct timespec& when, const ComboAddress& requestor, const DNSName& name, uint16_t qtype, unsigned int usec, unsigned int size, const struct dnsheader& dh, const ComboAddress& backend, dnsdist::Protocol protocol)
dnsdist::Protocol outgoingProtocol = dnsdist::Protocol::DoUDP;
Rings rings(numberOfEntries, numberOfShards, lockAttempts, true);
+#if defined(DNSDIST_RINGS_WITH_MACADDRESS)
+ Rings::Query query({requestor, qname, now, dh, size, qtype, protocol, "", false});
+#else
Rings::Query query({requestor, qname, now, dh, size, qtype, protocol});
+#endif
Rings::Response response({requestor, server, qname, now, dh, latency, size, qtype, outgoingProtocol});
std::atomic<bool> done(false);
return true;
}
-string getMACAddress(const ComboAddress& ca)
+int getMACAddress(const ComboAddress& ca, char* dest, size_t len)
{
- string ret;
#ifdef __linux__
ifstream ifs("/proc/net/arp");
- if(!ifs)
- return ret;
+ if (len < 6) {
+ return EINVAL;
+ }
+ if (!ifs) {
+ return EIO;
+ }
string line;
- string match=ca.toString()+' ';
+ string match = ca.toString() + ' ';
while(getline(ifs, line)) {
if(boost::starts_with(line, match)) {
vector<string> parts;
stringtok(parts, line, " \n\t\r");
- if(parts.size() < 4)
- return ret;
- unsigned int tmp[6];
- if (sscanf(parts[3].c_str(), "%02x:%02x:%02x:%02x:%02x:%02x", tmp, tmp+1, tmp+2, tmp+3, tmp+4, tmp+5) != 6) {
- return ret;
+ if (parts.size() < 4)
+ return ENOENT;
+ if (sscanf(parts[3].c_str(), "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", dest, dest+1, dest+2, dest+3, dest+4, dest+5) != 6) {
+ return ENOENT;
}
- for(unsigned int i : tmp)
- ret.append(1, (char)i);
- return ret;
+ return 0;
}
}
#endif
+ return ENOENT;
+}
+string getMACAddress(const ComboAddress& ca)
+{
+ string ret;
+ char tmp[6];
+ if (getMACAddress(ca, tmp, sizeof(tmp)) == 0) {
+ ret.append(tmp, sizeof(tmp));
+ }
return ret;
}