From: Willy Tarreau Date: Wed, 17 Jul 2019 09:37:29 +0000 (+0200) Subject: MINOR: tcp: replace various calls to conn_get_{from,to}_addr with conn_get_{src,dst} X-Git-Tag: v2.1-dev2~325 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dddd2b422f6559ce53e4a956b17914c0174972ad;p=thirdparty%2Fhaproxy.git MINOR: tcp: replace various calls to conn_get_{from,to}_addr with conn_get_{src,dst} These calls include the operation's status. When the check was already present, it was merged with the call. when it was not present, it was added. --- diff --git a/src/proto_tcp.c b/src/proto_tcp.c index a99febf429..d999188ec9 100644 --- a/src/proto_tcp.c +++ b/src/proto_tcp.c @@ -1172,7 +1172,7 @@ enum act_return tcp_action_req_set_src(struct act_rule *rule, struct proxy *px, { struct connection *cli_conn; - if ((cli_conn = objt_conn(sess->origin)) && conn_ctrl_ready(cli_conn)) { + if ((cli_conn = objt_conn(sess->origin)) && conn_get_src(cli_conn)) { struct sample *smp; smp = sample_fetch_as_type(px, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->arg.expr, SMP_T_ADDR); @@ -1204,7 +1204,7 @@ enum act_return tcp_action_req_set_dst(struct act_rule *rule, struct proxy *px, { struct connection *cli_conn; - if ((cli_conn = objt_conn(sess->origin)) && conn_ctrl_ready(cli_conn)) { + if ((cli_conn = objt_conn(sess->origin)) && conn_get_dst(cli_conn)) { struct sample *smp; smp = sample_fetch_as_type(px, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->arg.expr, SMP_T_ADDR); @@ -1236,11 +1236,9 @@ enum act_return tcp_action_req_set_src_port(struct act_rule *rule, struct proxy { struct connection *cli_conn; - if ((cli_conn = objt_conn(sess->origin)) && conn_ctrl_ready(cli_conn)) { + if ((cli_conn = objt_conn(sess->origin)) && conn_get_src(cli_conn)) { struct sample *smp; - conn_get_from_addr(cli_conn); - smp = sample_fetch_as_type(px, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->arg.expr, SMP_T_SINT); if (smp) { if (cli_conn->addr.from.ss_family == AF_INET6) { @@ -1268,11 +1266,9 @@ enum act_return tcp_action_req_set_dst_port(struct act_rule *rule, struct proxy { struct connection *cli_conn; - if ((cli_conn = objt_conn(sess->origin)) && conn_ctrl_ready(cli_conn)) { + if ((cli_conn = objt_conn(sess->origin)) && conn_get_dst(cli_conn)) { struct sample *smp; - conn_get_to_addr(cli_conn); - smp = sample_fetch_as_type(px, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->arg.expr, SMP_T_SINT); if (smp) { if (cli_conn->addr.to.ss_family == AF_INET6) { @@ -1425,6 +1421,9 @@ int smp_fetch_src(const struct arg *args, struct sample *smp, const char *kw, vo if (!cli_conn) return 0; + if (!conn_get_src(cli_conn)) + return 0; + switch (cli_conn->addr.from.ss_family) { case AF_INET: smp->data.u.ipv4 = ((struct sockaddr_in *)&cli_conn->addr.from)->sin_addr; @@ -1451,6 +1450,9 @@ smp_fetch_sport(const struct arg *args, struct sample *smp, const char *k, void if (!cli_conn) return 0; + if (!conn_get_src(cli_conn)) + return 0; + smp->data.type = SMP_T_SINT; if (!(smp->data.u.sint = get_host_port(&cli_conn->addr.from))) return 0; @@ -1468,7 +1470,8 @@ smp_fetch_dst(const struct arg *args, struct sample *smp, const char *kw, void * if (!cli_conn) return 0; - conn_get_to_addr(cli_conn); + if (!conn_get_dst(cli_conn)) + return 0; switch (cli_conn->addr.to.ss_family) { case AF_INET: @@ -1498,8 +1501,7 @@ int smp_fetch_dst_is_local(const struct arg *args, struct sample *smp, const cha if (!conn) return 0; - conn_get_to_addr(conn); - if (!(conn->flags & CO_FL_ADDR_TO_SET)) + if (!conn_get_dst(conn)) return 0; smp->data.type = SMP_T_BOOL; @@ -1519,8 +1521,7 @@ int smp_fetch_src_is_local(const struct arg *args, struct sample *smp, const cha if (!conn) return 0; - conn_get_from_addr(conn); - if (!(conn->flags & CO_FL_ADDR_FROM_SET)) + if (!conn_get_src(conn)) return 0; smp->data.type = SMP_T_BOOL; @@ -1538,7 +1539,8 @@ smp_fetch_dport(const struct arg *args, struct sample *smp, const char *kw, void if (!cli_conn) return 0; - conn_get_to_addr(cli_conn); + if (!conn_get_dst(cli_conn)) + return 0; smp->data.type = SMP_T_SINT; if (!(smp->data.u.sint = get_host_port(&cli_conn->addr.to)))