From: Willy Tarreau Date: Wed, 17 Jul 2019 08:38:45 +0000 (+0200) Subject: BUG/MINOR: dns: remove irrelevant dependency on a client connection X-Git-Tag: v2.1-dev2~397 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=45726fd4588d9075632cb09c9cd093d7a67c1159;p=thirdparty%2Fhaproxy.git BUG/MINOR: dns: remove irrelevant dependency on a client connection The do-resolve action tests for a client connection to the stream and tries to get the client's address, otherwise it refrains from performing the resolution. This really makes no sense at all and looks like an earlier attempt at resolving the client's address to test that the code was working. Further, it prevents the action from being used from other places such as an autonomous applet for example, even if at the moment this use case does not exist. This patch simply removes the irrelevant test. This can be backported to 2.0. --- diff --git a/src/dns.c b/src/dns.c index 30fc93c673..503eb674bc 100644 --- a/src/dns.c +++ b/src/dns.c @@ -2147,8 +2147,9 @@ static int action_prepare_for_resolution(struct stream *stream, const char *host enum act_return dns_action_do_resolve(struct act_rule *rule, struct proxy *px, struct session *sess, struct stream *s, int flags) { - struct connection *cli_conn; struct dns_resolution *resolution; + struct sample *smp; + char *fqdn; /* we have a response to our DNS resolution */ if (s->dns_ctx.dns_requester && s->dns_ctx.dns_requester->resolution != NULL) { @@ -2197,26 +2198,17 @@ enum act_return dns_action_do_resolve(struct act_rule *rule, struct proxy *px, } /* need to configure and start a new DNS resolution */ - cli_conn = objt_conn(sess->origin); - if (cli_conn && conn_ctrl_ready(cli_conn)) { - struct sample *smp; - char *fqdn; - - conn_get_from_addr(cli_conn); + smp = sample_fetch_as_type(px, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->arg.dns.expr, SMP_T_STR); + if (smp == NULL) + return ACT_RET_CONT; - smp = sample_fetch_as_type(px, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->arg.dns.expr, SMP_T_STR); - if (smp == NULL) - return ACT_RET_CONT; + fqdn = smp->data.u.str.area; + if (action_prepare_for_resolution(s, fqdn) == -1) + return ACT_RET_ERR; - fqdn = smp->data.u.str.area; - if (action_prepare_for_resolution(s, fqdn) == -1) { - return ACT_RET_ERR; - } - - s->dns_ctx.parent = rule; - dns_link_resolution(s, OBJ_TYPE_STREAM, 0); - dns_trigger_resolution(s->dns_ctx.dns_requester); - } + s->dns_ctx.parent = rule; + dns_link_resolution(s, OBJ_TYPE_STREAM, 0); + dns_trigger_resolution(s->dns_ctx.dns_requester); return ACT_RET_YIELD; }