Protobuf export to a server is enabled using the `protobufServer()` directive:
```
-protobufServer("192.0.2.1:4242" [[[[[[, timeout], maxQueuedEntries], reconnectWaitTime], maskV4], maskV6], asynConnect])
+protobufServer("192.0.2.1:4242" [[[[[[[, timeout], maxQueuedEntries], reconnectWaitTime], maskV4], maskV6], asynConnect], taggedOnly])
```
The optional parameters are:
* reconnectWaitTime = how long to wait, in seconds, between two reconnection attempts, default to 1
* maskV4 = network mask to apply to the client IPv4 addresses, for anonymization purpose. The default of 32 means no anonymization
* maskV6 = same as maskV4, but for IPv6. Default to 128
+* taggedOnly = only entries with a policy or a policy tag set will be sent
* asyncConnect = if set to false (default) the first connection to the server during startup will block up to `timeout` seconds,
otherwise the connection is done in a separate thread.
g_rs.submitResponse(dc->d_mdp.d_qtype, packet.size(), !dc->d_tcp);
updateResponseStats(res, dc->d_remote, packet.size(), &dc->d_mdp.d_qname, dc->d_mdp.d_qtype);
#ifdef HAVE_PROTOBUF
- if (luaconfsLocal->protobufServer) {
+ if (luaconfsLocal->protobufServer && (!luaconfsLocal->protobufTaggedOnly || (appliedPolicy.d_name && !appliedPolicy.d_name->empty()) || !dc->d_policyTags.empty())) {
pbMessage.setBytes(packet.size());
pbMessage.setResponseCode(pw.getHeader()->rcode);
if (appliedPolicy.d_name) {
const struct dnsheader* dh = (const struct dnsheader*) conn->data;
dc->d_ednssubnet = ednssubnet;
- protobufLogQuery(luaconfsLocal->protobufServer, luaconfsLocal->protobufMaskV4, luaconfsLocal->protobufMaskV6, dc->d_uuid, dest, conn->d_remote, ednssubnet, true, dh->id, conn->qlen, qname, qtype, qclass, dc->d_policyTags);
+ if (!luaconfsLocal->protobufTaggedOnly) {
+ protobufLogQuery(luaconfsLocal->protobufServer, luaconfsLocal->protobufMaskV4, luaconfsLocal->protobufMaskV6, dc->d_uuid, dest, conn->d_remote, ednssubnet, true, dh->id, conn->qlen, qname, qtype, qclass, dc->d_policyTags);
+ }
}
catch(std::exception& e) {
if(g_logCommonErrors)
RecProtoBufMessage pbMessage(DNSProtoBufMessage::DNSProtoBufMessageType::Response);
#ifdef HAVE_PROTOBUF
if(luaconfsLocal->protobufServer) {
- protobufLogQuery(luaconfsLocal->protobufServer, luaconfsLocal->protobufMaskV4, luaconfsLocal->protobufMaskV6, uniqueId, fromaddr, destaddr, ednssubnet, false, dh->id, question.size(), qname, qtype, qclass, policyTags);
+ if (!luaconfsLocal->protobufTaggedOnly || !policyTags.empty()) {
+ protobufLogQuery(luaconfsLocal->protobufServer, luaconfsLocal->protobufMaskV4, luaconfsLocal->protobufMaskV6, uniqueId, fromaddr, destaddr, ednssubnet, false, dh->id, question.size(), qname, qtype, qclass, policyTags);
+ }
}
#endif /* HAVE_PROTOBUF */
cacheHit = (!SyncRes::s_nopacketcache && t_packetCache->getResponsePacket(ctag, question, g_now.tv_sec, &response, &age, &pbMessage));
if (cacheHit) {
#ifdef HAVE_PROTOBUF
- if(luaconfsLocal->protobufServer) {
+ if(luaconfsLocal->protobufServer && (!luaconfsLocal->protobufTaggedOnly || !pbMessage.getAppliedPolicy().empty() || !pbMessage.getPolicyTags().empty())) {
Netmask requestorNM(fromaddr, fromaddr.sin4.sin_family == AF_INET ? luaconfsLocal->protobufMaskV4 : luaconfsLocal->protobufMaskV6);
const ComboAddress& requestor = requestorNM.getMaskedNetwork();
pbMessage.update(uniqueId, &requestor, &destaddr, false, dh->id);
});
#if HAVE_PROTOBUF
- Lua.writeFunction("protobufServer", [&lci](const string& server_, const boost::optional<uint16_t> timeout, const boost::optional<uint64_t> maxQueuedEntries, const boost::optional<uint8_t> reconnectWaitTime, const boost::optional<uint8_t> maskV4, boost::optional<uint8_t> maskV6, boost::optional<bool> asyncConnect) {
+ Lua.writeFunction("protobufServer", [&lci](const string& server_, const boost::optional<uint16_t> timeout, const boost::optional<uint64_t> maxQueuedEntries, const boost::optional<uint8_t> reconnectWaitTime, const boost::optional<uint8_t> maskV4, boost::optional<uint8_t> maskV6, boost::optional<bool> asyncConnect, boost::optional<bool> taggedOnly) {
try {
ComboAddress server(server_);
if (!lci.protobufServer) {
if (maskV6) {
lci.protobufMaskV6 = *maskV6;
}
+ if (taggedOnly) {
+ lci.protobufTaggedOnly = *taggedOnly;
+ }
}
else {
theL()<<Logger::Error<<"Only one protobuf server can be configured, we already have "<<lci.protobufServer->toString()<<endl;
}
#endif /* HAVE_PROTOBUF */
}
+
+std::string RecProtoBufMessage::getAppliedPolicy() const
+{
+ std::string result;
+#ifdef HAVE_PROTOBUF
+ const PBDNSMessage_DNSResponse& response = d_message.response();
+ result = response.appliedpolicy();
+#endif /* HAVE_PROTOBUF */
+ return result;
+}
+
+std::vector<std::string> RecProtoBufMessage::getPolicyTags() const
+{
+ std::vector<std::string> result;
+#ifdef HAVE_PROTOBUF
+ const PBDNSMessage_DNSResponse& response = d_message.response();
+ const int count = response.tags_size();
+ for (int idx = 0; idx < count; idx++) {
+ result.push_back(response.tags(idx));
+ }
+#endif /* HAVE_PROTOBUF */
+ return result;
+}