auto lock = s_cookiestore.lock();
auto found = lock->find(address);
if (found != lock->end()) {
- if (found->d_support) {
+ switch (found->getSupport()) {
+ case CookieEntry::Support::Supported:
+ case CookieEntry::Support::Probing:
cookieSentOut = found->d_cookie;
addressToBindTo = found->d_localaddress;
opts.emplace_back(EDNSOptionCode::COOKIE, cookieSentOut->makeOptString());
found->d_lastupdate = now->tv_sec;
cerr << "Sending stored cookie info to " << address.toString() << ": " << found->d_cookie.toDisplayString() << endl;
- }
- else {
- cerr << "This server does not support cookies" << endl;
+ break;
+ case CookieEntry::Support::Unknown:
+ assert(0);
+ case CookieEntry::Support::Unsupported:
+ default:
+ cerr << "This server does not support cookies or we don't know yet:" << endl;
}
}
else {
+ // Server not in table
CookieEntry entry;
entry.d_address = address;
entry.d_cookie.makeClientCookie();
cookieSentOut = entry.d_cookie;
entry.d_lastupdate = now->tv_sec;
- entry.d_support = false;
+ entry.setSupport(CookieEntry::Support::Probing);
lock->emplace(entry);
opts.emplace_back(EDNSOptionCode::COOKIE, cookieSentOut->makeOptString());
cerr << "We're sending new client cookie info from to " << address.toString() << ": " << entry.d_cookie.toDisplayString() << endl;
found->d_localaddress = localip;
found->d_cookie = received;
found->d_lastupdate = now->tv_sec;
- found->d_support = true;
+ found->setSupport(CookieEntry::Support::Supported);
uint16_t ercode = (edo.d_extRCode << 4) | lwr->d_rcode;
if (ercode == ERCode::BADCOOKIE) {
lwr->d_validpacket = true;
}
}
else {
- // We sent a cookie out but forgot it?
+ // We sent a cookie out but it's not in the table?
cerr << "Cookie not found back"<< endl;
lwr->d_validpacket = true;
return LWResult::Result::BadCookie; // XXX
src_dir / 'rec-zonetocache.cc',
src_dir / 'rec_channel.cc',
src_dir / 'rec_channel_rec.cc',
+ src_dir / 'rec-cookiestore.cc',
src_dir / 'rec-xfr.cc',
src_dir / 'rec-xfrtracker.cc',
src_dir / 'recpacketcache.cc',
fprintf(filePtr.get(), "%s\t%s\t%s\t%s\t%s\n",
entry.d_address.toString().c_str(), entry.d_localaddress.toString().c_str(),
entry.d_cookie.toDisplayString().c_str(),
- entry.d_support ? "yes" : "no",
+ CookieEntry::toString(entry.d_support).c_str(),
timestamp(entry.d_lastupdate, tmp));
}
return count;
struct CookieEntry
{
+ enum class Support : uint8_t
+ {
+ Unknown,
+ Unsupported,
+ Supported,
+ Probing
+ };
+
+ static std::string toString(Support support)
+ {
+ static const std::array<std::string, 4> names = {
+ "Unknown",
+ "Unsupported",
+ "Supported",
+ "Probing"};
+ const auto index = static_cast<uint8_t>(support);
+ if (index >= names.size()) {
+ return "?";
+ }
+ return names.at(index);
+ }
+
+ Support getSupport() const
+ {
+ return d_support;
+ }
+
+ void setSupport(Support support) const // modifying mutable field
+ {
+ d_support = support;
+ }
+
+ bool supported() const
+ {
+ return d_support == Support::Supported;
+ }
+
ComboAddress d_address;
mutable ComboAddress d_localaddress; // The address we were bound to, see RFC 9018
mutable EDNSCookiesOpt d_cookie; // Contains both client and server cookie
mutable time_t d_lastupdate{};
- mutable bool d_support;
+ mutable Support d_support{Support::Unknown};
};
class CookieStore : public multi_index_container < CookieEntry,