]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
dnstap: Add optional identity and version fields
authorPavel Dolezal <pavel.dolezal@nic.cz>
Mon, 14 Dec 2020 12:59:50 +0000 (13:59 +0100)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 12 Jan 2021 10:55:03 +0000 (11:55 +0100)
modules/dnstap/README.rst
modules/dnstap/dnstap.c

index 5a218dd19cb729978d2fdfd9d6e486bb8fdc0e91..3bd022dbbd40576888d36584f799f3c97d44b921 100644 (file)
@@ -14,6 +14,8 @@ The unix socket and the socket reader must be present before starting resolver i
 Tunables:
 
 * ``socket_path``: the the unix socket file where dnstap messages will be sent
+* ``identity``: identity string as typically returned by an "NSID" (RFC 5001) query, empty by default
+* ``version``: version string of the resolver, defaulting to "Knot Resolver major.minor.patch"
 * ``client.log_requests``: if ``true`` requests from downstream in wire format will be logged
 * ``client.log_responses``: if ``true`` responses to downstream in wire format will be logged
 
@@ -22,6 +24,8 @@ Tunables:
     modules = {
         dnstap = {
             socket_path = "/tmp/dnstap.sock",
+            identity = nsid.name() or "",
+            version = "My Custom Knot Resolver " .. package_version(),
             client = {
                 log_requests = true,
                 log_responses = true,
index 14214660311c7713569871d9bf5d1f66553b3ea6..25d7160136aa679d92a703afe48ef2fe92bb8015 100644 (file)
@@ -16,6 +16,8 @@
 
 #define DEBUG_MSG(fmt, ...) kr_log_verbose("[dnstap] " fmt, ##__VA_ARGS__);
 #define CFG_SOCK_PATH "socket_path"
+#define CFG_IDENTITY_STRING "identity"
+#define CFG_VERSION_STRING "version"
 #define CFG_LOG_CLIENT_PKT "client"
 #define CFG_LOG_REQ_PKT "log_requests"
 #define CFG_LOG_RESP_PKT "log_responses"
 
 /* Internal data structure */
 struct dnstap_data {
+       char *identity;
+       size_t identity_len;
+       char *version;
+       size_t version_len;
        bool log_req_pkt;
        bool log_resp_pkt;
        struct fstrm_iothr *iothread;
@@ -200,6 +206,18 @@ static int dnstap_log(kr_layer_t *ctx) {
        dnstap.type = DNSTAP__DNSTAP__TYPE__MESSAGE;
        dnstap.message = (Dnstap__Message *)&m;
 
+       if (dnstap_dt->identity) {
+               dnstap.identity.data = (uint8_t*)dnstap_dt->identity;
+               dnstap.identity.len = dnstap_dt->identity_len;
+               dnstap.has_identity = true;
+       }
+
+       if (dnstap_dt->version) {
+               dnstap.version.data = (uint8_t*)dnstap_dt->version;
+               dnstap.version.len = dnstap_dt->version_len;
+               dnstap.has_version = true;
+       }
+
        /* Pack the message */
        uint8_t *frame = NULL;
        size_t size = 0;
@@ -246,6 +264,9 @@ int dnstap_deinit(struct kr_module *module) {
        struct dnstap_data *data = module->data;
        /* Free allocated memory */
        if (data) {
+               free(data->identity);
+               free(data->version);
+
                fstrm_iothr_destroy(&data->iothread);
                DEBUG_MSG("fstrm iothread destroyed\n");
                free(data);
@@ -338,6 +359,26 @@ int dnstap_config(struct kr_module *module, const char *conf) {
                        sock_path = strndup(DEFAULT_SOCK_PATH, PATH_MAX);
                }
 
+               /* identity string key */
+               node = json_find_member(root_node, CFG_IDENTITY_STRING);
+               if (!node || find_string(node, &data->identity, KR_EDNS_PAYLOAD) != kr_ok()) {
+                       data->identity = NULL;
+                       data->identity_len = 0;
+               } else {
+                       data->identity_len = strlen(data->identity);
+               }
+
+               /* version string key */
+               node = json_find_member(root_node, CFG_VERSION_STRING);
+               if (!node || find_string(node, &data->version, KR_EDNS_PAYLOAD) != kr_ok()) {
+                       data->version = strdup("Knot Resolver " PACKAGE_VERSION);
+                       if (data->version) {
+                               data->version_len = strlen(data->version);
+                       }
+               } else {
+                       data->version_len = strlen(data->version);
+               }
+
                node = json_find_member(root_node, CFG_LOG_CLIENT_PKT);
                if (node) {
                        JsonNode *subnode;