]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: dns: Dynamically allocate dns options to reduce the act_rule size
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 24 Jan 2020 17:08:42 +0000 (18:08 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 6 Feb 2020 13:55:34 +0000 (14:55 +0100)
<.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.

include/types/action.h
src/dns.c

index 6ec3f018d0a206883598f94b938067a8fbe9d7a7..293e1d87f0edfcc695ab7144ab733f0f52fc1f7f 100644 (file)
@@ -115,7 +115,7 @@ struct act_rule {
                        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, ..) */
index 28d47d26c503fd22fa06b119faf0d4f5a9a5df33..bd2c9638ea0d930bf3c943d75aa7bd3b2fbf9675 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
@@ -1629,7 +1629,7 @@ int dns_link_resolution(void *requester, int requester_type, int requester_locke
                        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 @@ enum act_return dns_action_do_resolve(struct act_rule *rule, struct proxy *px,
                                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 @@ enum act_parse_ret dns_parse_do_resolve(const char **args, int *orig_arg, struct
                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 @@ enum act_parse_ret dns_parse_do_resolve(const char **args, int *orig_arg, struct
                        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;