int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_size,
int max_entries)
{
- union bpf_attr attr = { 0 };
+ union bpf_attr attr;
+ memset(&attr, 0, sizeof(attr));
attr.map_type = map_type;
attr.key_size = key_size;
attr.value_size = value_size;
int bpf_update_elem(int fd, void *key, void *value, unsigned long long flags)
{
- union bpf_attr attr = { 0 };
+ union bpf_attr attr;
+ memset(&attr, 0, sizeof(attr));
attr.map_fd = fd;
attr.key = ptr_to_u64(key);
attr.value = ptr_to_u64(value);
int bpf_lookup_elem(int fd, void *key, void *value)
{
- union bpf_attr attr = { 0 };
+ union bpf_attr attr;
+ memset(&attr, 0, sizeof(attr));
attr.map_fd = fd;
attr.key = ptr_to_u64(key);
attr.value = ptr_to_u64(value);
int bpf_delete_elem(int fd, void *key)
{
- union bpf_attr attr = { 0 };
+ union bpf_attr attr;
+ memset(&attr, 0, sizeof(attr));
attr.map_fd = fd;
attr.key = ptr_to_u64(key);
return syscall(SYS_bpf, BPF_MAP_DELETE_ELEM, &attr, sizeof(attr));
int bpf_get_next_key(int fd, void *key, void *next_key)
{
- union bpf_attr attr = { 0 };
+ union bpf_attr attr;
+ memset(&attr, 0, sizeof(attr));
attr.map_fd = fd;
attr.key = ptr_to_u64(key);
attr.next_key = ptr_to_u64(next_key);
const char *license, int kern_version)
{
char log_buf[65535];
- union bpf_attr attr = { 0 };
+ union bpf_attr attr;
+ memset(&attr, 0, sizeof(attr));
attr.prog_type = prog_type;
attr.insns = ptr_to_u64((void *) insns);
attr.insn_cnt = prog_len / sizeof(struct bpf_insn);
uint32_t nextV4Key;
uint64_t value;
int res = bpf_get_next_key(d_v4map.fd, &v4Key, &nextV4Key);
- sockaddr_in v4Addr = { 0 };
- v4Addr.sin_port = 0;
+ sockaddr_in v4Addr;
+ memset(&v4Addr, 0, sizeof(v4Addr));
v4Addr.sin_family = AF_INET;
while (res == 0) {
uint8_t v6Key[16];
uint8_t nextV6Key[16];
- sockaddr_in6 v6Addr = { 0 };
+ sockaddr_in6 v6Addr;
+ memset(&v6Addr, 0, sizeof(v6Addr));
v6Addr.sin6_family = AF_INET6;
- v6Addr.sin6_port = 0;
+
static_assert(sizeof(v6Addr.sin6_addr.s6_addr) == sizeof(v6Key), "POSIX mandates s6_addr to be an array of 16 uint8_t");
for (size_t idx = 0; idx < sizeof(v6Key); idx++) {
v6Key[idx] = 0;
}
pos += 1;
- uint16_t qtype = (const unsigned char)packet[pos]*256 + (const unsigned char)packet[pos+1];
+ uint16_t qtype = (reinterpret_cast<const unsigned char*>(packet)[pos])*256 + reinterpret_cast<const unsigned char*>(packet)[pos+1];
pos += DNS_TYPE_SIZE;
pos += DNS_CLASS_SIZE;
char* optRDLen = reinterpret_cast<char*>(dq.dh) + optRDPosition;
char * optPtr = (optRDLen - (/* root */ 1 + DNS_TYPE_SIZE + DNS_CLASS_SIZE + EDNS_EXTENDED_RCODE_SIZE + EDNS_VERSION_SIZE + /* Z */ 2));
- const uint8_t* zPtr = (const uint8_t*) optPtr + /* root */ 1 + DNS_TYPE_SIZE + DNS_CLASS_SIZE + EDNS_EXTENDED_RCODE_SIZE + EDNS_VERSION_SIZE;
+ const uint8_t* zPtr = reinterpret_cast<const uint8_t*>(optPtr) + /* root */ 1 + DNS_TYPE_SIZE + DNS_CLASS_SIZE + EDNS_EXTENDED_RCODE_SIZE + EDNS_VERSION_SIZE;
uint16_t z = 0x100 * (*zPtr) + *(zPtr + 1);
bool dnssecOK = z & EDNS_HEADER_FLAG_DO;
pos++;
- uint16_t qtype = (const unsigned char)packet[pos]*256 + (const unsigned char)packet[pos+1];
+ uint16_t qtype = (reinterpret_cast<const unsigned char*>(packet)[pos])*256 + reinterpret_cast<const unsigned char*>(packet)[pos+1];
pos += DNS_TYPE_SIZE;
pos += DNS_CLASS_SIZE;
return 0;
}
- const uint8_t* z = (const uint8_t*) packet + pos + EDNS_EXTENDED_RCODE_SIZE + EDNS_VERSION_SIZE;
+ const uint8_t* z = reinterpret_cast<const uint8_t*>(packet) + pos + EDNS_EXTENDED_RCODE_SIZE + EDNS_VERSION_SIZE;
return 0x100 * (*z) + *(z+1);
}
catch(...)
boost::optional<uint16_t> qtype,
boost::optional<bool> suffixMatch) {
if (cache) {
- cache->expungeByName(dname, qtype ? *qtype : QType::ANY, suffixMatch ? *suffixMatch : false);
+ cache->expungeByName(dname, qtype ? *qtype : QType(QType::ANY).getCode(), suffixMatch ? *suffixMatch : false);
}
});
g_lua.registerFunction<void(std::shared_ptr<DNSDistPacketCache>::*)()>("printStats", [](const std::shared_ptr<DNSDistPacketCache> cache) {
bool DNSPacket::s_doEDNSSubnetProcessing;
uint16_t DNSPacket::s_udpTruncationThreshold;
-DNSPacket::DNSPacket(bool isQuery)
+DNSPacket::DNSPacket(bool isQuery): d_isQuery(isQuery)
{
- d_wrapped=false;
- d_compress=true;
- d_tcp=false;
- d_wantsnsid=false;
- d_haveednssubnet = false;
- d_dnssecOk=false;
- d_ednsversion=0;
- d_ednsrcode=0;
memset(&d, 0, sizeof(d));
- qclass = QClass::IN;
- d_tsig_algo = TSIG_MD5;
- d_havetsig = false;
- d_socket = -1;
- d_maxreplylen = 0;
- d_tsigtimersonly = false;
- d_haveednssection = false;
- d_isQuery = isQuery;
}
const string& DNSPacket::getString()
}
DNSPacket::DNSPacket(const DNSPacket &orig) :
- d_socket(orig.d_socket),
- d_remote(orig.d_remote),
+ d_anyLocal(orig.d_anyLocal),
d_dt(orig.d_dt),
- d_compress(orig.d_compress),
- d_tcp(orig.d_tcp),
- qtype(orig.qtype),
- qclass(orig.qclass),
qdomain(orig.qdomain),
qdomainwild(orig.qdomainwild),
qdomainzone(orig.qdomainzone),
- d_maxreplylen(orig.d_maxreplylen),
- d_wantsnsid(orig.d_wantsnsid),
- d_anyLocal(orig.d_anyLocal),
- d_eso(orig.d_eso),
- d_haveednssubnet(orig.d_haveednssubnet),
- d_haveednssection(orig.d_haveednssection),
- d_ednsversion(orig.d_ednsversion),
- d_ednsrcode(orig.d_ednsrcode),
- d_dnssecOk(orig.d_dnssecOk),
- d_rrs(orig.d_rrs),
- d_tsigkeyname(orig.d_tsigkeyname),
- d_tsigprevious(orig.d_tsigprevious),
- d_tsigtimersonly(orig.d_tsigtimersonly),
+ d(orig.d),
d_trc(orig.d_trc),
- d_tsigsecret(orig.d_tsigsecret),
+ d_remote(orig.d_remote),
+ d_tsig_algo(orig.d_tsig_algo),
+
d_ednsRawPacketSizeLimit(orig.d_ednsRawPacketSizeLimit),
+ qclass(orig.qclass),
+ qtype(orig.qtype),
+ d_tcp(orig.d_tcp),
+ d_dnssecOk(orig.d_dnssecOk),
d_havetsig(orig.d_havetsig),
- d_wrapped(orig.d_wrapped),
+ d_tsigsecret(orig.d_tsigsecret),
+ d_tsigkeyname(orig.d_tsigkeyname),
+ d_tsigprevious(orig.d_tsigprevious),
+ d_rrs(orig.d_rrs),
d_rawpacket(orig.d_rawpacket),
- d_tsig_algo(orig.d_tsig_algo),
- d(orig.d),
+ d_eso(orig.d_eso),
+ d_maxreplylen(orig.d_maxreplylen),
+ d_socket(orig.d_socket),
+ d_hash(orig.d_hash),
+ d_ednsrcode(orig.d_ednsrcode),
+ d_ednsversion(orig.d_ednsversion),
+
+ d_wrapped(orig.d_wrapped),
+ d_compress(orig.d_compress),
+ d_tsigtimersonly(orig.d_tsigtimersonly),
+ d_wantsnsid(orig.d_wantsnsid),
+ d_haveednssubnet(orig.d_haveednssubnet),
+ d_haveednssection(orig.d_haveednssection),
- d_isQuery(orig.d_isQuery),
- d_hash(orig.d_hash)
+ d_isQuery(orig.d_isQuery)
{
DLOG(g_log<<"DNSPacket copy constructor called!"<<endl);
}
string d_peer_principal;
const DNSName& getTSIGKeyname() const;
- uint16_t qclass; //!< class of the question - should always be INternet 2
struct dnsheader d; //!< dnsheader at the start of the databuffer 12
- QType qtype; //!< type of the question 2
-
TSIGRecordContent d_trc; //72
ComboAddress d_remote; //28
- TSIGHashEnum d_tsig_algo; //4
+ TSIGHashEnum d_tsig_algo{TSIG_MD5}; //4
- bool d_tcp;
- bool d_dnssecOk;
- bool d_havetsig;
+ int d_ednsRawPacketSizeLimit; // only used for Lua record
+ uint16_t qclass{QClass::IN}; //!< class of the question - should always be INternet 2
+ QType qtype; //!< type of the question 2
+
+ bool d_tcp{false};
+ bool d_dnssecOk{false};
+ bool d_havetsig{false};
bool getTSIGDetails(TSIGRecordContent* tr, DNSName* keyname, uint16_t* tsigPos=nullptr) const;
void setTSIGDetails(const TSIGRecordContent& tr, const DNSName& keyname, const string& secret, const string& previous, bool timersonly=false);
vector<DNSZoneRecord>& getRRS() { return d_rrs; }
bool checkForCorrectTSIG(UeberBackend* B, DNSName* keyname, string* secret, TSIGRecordContent* trc) const;
- static bool s_doEDNSSubnetProcessing;
static uint16_t s_udpTruncationThreshold;
- int d_ednsRawPacketSizeLimit; // only used for Lua record
+ static bool s_doEDNSSubnetProcessing;
+
private:
void pasteQ(const char *question, int length); //!< set the question of this packet, useful for crafting replies
- bool d_wrapped; // 1
- int d_socket; // 4
-
string d_tsigsecret;
DNSName d_tsigkeyname;
string d_tsigprevious;
string d_rawpacket; // this is where everything lives 8
EDNSSubnetOpts d_eso;
- int d_maxreplylen;
-
- uint8_t d_ednsversion;
- // WARNING! This is really 12 bits
- uint16_t d_ednsrcode;
-
+ int d_maxreplylen{0};
+ int d_socket{-1}; // 4
uint32_t d_hash{0};
-
- bool d_compress; // 1
- bool d_tsigtimersonly;
- bool d_wantsnsid;
- bool d_haveednssubnet;
- bool d_haveednssection;
+ // WARNING! This is really 12 bits
+ uint16_t d_ednsrcode{0};
+ uint8_t d_ednsversion{0};
+
+ bool d_wrapped{false}; // 1
+ bool d_compress{true}; // 1
+ bool d_tsigtimersonly{false};
+ bool d_wantsnsid{false};
+ bool d_haveednssubnet{false};
+ bool d_haveednssection{false};
bool d_isQuery;
};
case QType::MX:
if (content.size() >= 2 && *(content.rbegin()+1) == ' ')
return;
+ /* Falls through. */
case QType::CNAME:
case QType::DNAME:
case QType::NS:
// cout<<"Clearing state for "<<qi<<endl<<endl;
statmap.erase(qi);
}
- else
- ;// cout<<"State for qi remains open, qcount="<<qd.d_qcount<<", answercount="<<qd.d_answercount<<endl;
-
+ else {
+ // cout<<"State for qi remains open, qcount="<<qd.d_qcount<<", answercount="<<qd.d_answercount<<endl;
+ }
}
}
catch(std::exception& e) {
DynListener::DynListener(const ComboAddress& local) :
- d_tcp(true),
- d_client(-1),
- d_tid(0),
- d_ppid(0)
+ d_tcp(true)
{
listenOnTCP(local);
}
-DynListener::DynListener(const string &progname) :
- d_client(-1),
- d_tid(0),
- d_ppid(0),
- d_s(-1)
+DynListener::DynListener(const string &progname)
{
if(!progname.empty()) {
}
else
d_nonlocal=false; // we listen on stdin!
- d_tcp=false;
}
void DynListener::go()
void createSocketAndBind(int family, struct sockaddr*local, size_t len);
NetmaskGroup d_tcprange;
- int d_s;
- int d_client;
- pthread_t d_tid;
+ int d_s{-1};
+ int d_client{-1};
+ pthread_t d_tid{0};
bool d_nonlocal;
- bool d_tcp;
- pid_t d_ppid;
+ bool d_tcp{false};
+ pid_t d_ppid{0};
string d_socketname;
ComboAddress d_socketaddress;
fd_set rfds;
FD_ZERO(&rfds);
FD_SET(sock, &rfds);
+ fd_set errfds;
+ FD_ZERO(&errfds);
+ FD_SET(sock, &errfds);
int len;
struct timeval tv;
bool timeout = true;
for(int tries=0; tries<60; tries++) {
tv.tv_sec = 1;
tv.tv_usec = 0;
- if ((len = select(sock+1, &rfds, NULL, &rfds, &tv)) > 0) {
+ if ((len = select(sock+1, &rfds, nullptr, &errfds, &tv)) > 0) {
len = recv(sock, buffer, sizeof(buffer), 0);
timeout = false;
break;
{
public:
SSQLite3Statement(SSQLite3 *db, bool dolog, const string& query) :
- d_prepared(false),
d_query(query),
- d_dolog(dolog),
- d_stmt(nullptr),
- d_rc(0),
- d_db(db)
+ d_db(db),
+ d_dolog(dolog)
{
}
const string& getQuery() { return d_query; };
private:
string d_query;
- sqlite3_stmt* d_stmt;
- SSQLite3* d_db;
- int d_rc;
- bool d_dolog;
- bool d_prepared;
DTime d_dtime;
+ sqlite3_stmt* d_stmt{nullptr};
+ SSQLite3* d_db{nullptr};
+ int d_rc{0};
+ bool d_dolog;
+ bool d_prepared{false};
+
void prepareStatement() {
const char *pTail;
void releaseStatement() {
if (d_stmt)
sqlite3_finalize(d_stmt);
- d_stmt = NULL;
+ d_stmt = nullptr;
d_prepared = false;
}
};
{
private:
//! Pointer to the SQLite database instance.
- sqlite3 *m_pDB;
+ sqlite3 *m_pDB{nullptr};
bool m_dolog;
bool m_in_transaction;
static void makePtr(const DNSResourceRecord& rr, DNSResourceRecord* ptr);
AuthWebServer::AuthWebServer() :
- d_start(time(0)),
+ d_tid(0),
+ d_start(time(nullptr)),
d_min10(0),
d_min5(0),
- d_min1(0),
- d_ws(nullptr),
- d_tid(0)
+ d_min1(0)
{
if(arg().mustDo("webserver") || arg().mustDo("api")) {
d_ws = new WebServer(arg()["webserver-address"], arg().asNum("webserver-port"));
double d_min10, d_min5, d_min1;
Ewma d_queries, d_cachehits, d_cachemisses;
Ewma d_qcachehits, d_qcachemisses;
- WebServer *d_ws;
+ WebServer *d_ws{nullptr};
};
#endif