MINOR: dns: Dynamically allocate dns options to reduce the act_rule size
<.arg.dns.dns_opts> field in the act_rule structure is now dynamically allocated
when a do-resolve rule is parsed. This drastically reduces the structure size.
diff --git a/include/types/action.h b/include/types/action.h
index 6ec3f01..293e1d8 100644
--- a/include/types/action.h
+++ b/include/types/action.h
@@ -115,7 +115,7 @@
char *varname;
char *resolvers_id;
struct dns_resolvers *resolvers;
- struct dns_options dns_opts;
+ struct dns_options *dns_opts;
} dns; /* dns resolution */
struct {
int i; /* integer param (status, nice, loglevel, ..) */
diff --git a/src/dns.c b/src/dns.c
index 28d47d2..bd2c963 100644
--- a/src/dns.c
+++ b/src/dns.c
@@ -1629,7 +1629,7 @@
hostname_dn = &stream->dns_ctx.hostname_dn;
hostname_dn_len = stream->dns_ctx.hostname_dn_len;
resolvers = stream->dns_ctx.parent->arg.dns.resolvers;
- query_type = ((stream->dns_ctx.parent->arg.dns.dns_opts.family_prio == AF_INET)
+ query_type = ((stream->dns_ctx.parent->arg.dns.dns_opts->family_prio == AF_INET)
? DNS_RTYPE_A
: DNS_RTYPE_AAAA);
break;
@@ -2415,7 +2415,7 @@
short ip_sin_family = 0;
void *ip = NULL;
- dns_get_ip_from_response(&resolution->response, &rule->arg.dns.dns_opts, NULL,
+ dns_get_ip_from_response(&resolution->response, rule->arg.dns.dns_opts, NULL,
0, &ip, &ip_sin_family, NULL);
switch (ip_sin_family) {
@@ -2533,8 +2533,12 @@
goto do_resolve_parse_error;
+ rule->arg.dns.dns_opts = calloc(1, sizeof(*rule->arg.dns.dns_opts));
+ if (rule->arg.dns.dns_opts == NULL)
+ goto do_resolve_parse_error;
+
/* Default priority is ipv6 */
- rule->arg.dns.dns_opts.family_prio = AF_INET6;
+ rule->arg.dns.dns_opts->family_prio = AF_INET6;
/* optional arguments accepted for now:
* ipv4 or ipv6
@@ -2548,10 +2552,10 @@
goto do_resolve_parse_error;
if (strncmp(beg, "ipv4", end - beg) == 0) {
- rule->arg.dns.dns_opts.family_prio = AF_INET;
+ rule->arg.dns.dns_opts->family_prio = AF_INET;
}
else if (strncmp(beg, "ipv6", end - beg) == 0) {
- rule->arg.dns.dns_opts.family_prio = AF_INET6;
+ rule->arg.dns.dns_opts->family_prio = AF_INET6;
}
else {
goto do_resolve_parse_error;