mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-21 13:51:26 +02:00
MINOR: sample: Refactor fc_pp_authority by wrapping the generic TLV fetch
We already have a call that can retreive an TLV with any value. Therefore, the fetch logic is redundant and can be simplified by simply calling the generic fetch with the correct TLV ID set as an argument.
This commit is contained in:
parent
f773ef721c
commit
ece0d1ab49
@ -729,6 +729,20 @@ static inline struct listener *conn_active_reverse_listener(const struct connect
|
|||||||
__objt_listener(conn->target);
|
__objt_listener(conn->target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Prepare TLV argument for redirecting fetches.
|
||||||
|
* Note that it is not possible to use an argument check function
|
||||||
|
* as that would require us to allow arguments for functions
|
||||||
|
* that do not need it. Alternatively, the sample logic could be
|
||||||
|
* adjusted to perform checks for no arguments and allocate
|
||||||
|
* in the check function. However, this does not seem worth the trouble.
|
||||||
|
*/
|
||||||
|
static inline void set_tlv_arg(int tlv_type, struct arg *tlv_arg)
|
||||||
|
{
|
||||||
|
tlv_arg->type = ARGT_SINT;
|
||||||
|
tlv_arg->data.sint = tlv_type;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* _HAPROXY_CONNECTION_H */
|
#endif /* _HAPROXY_CONNECTION_H */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -2328,33 +2328,13 @@ int smp_fetch_fc_pp_tlv(const struct arg *args, struct sample *smp, const char *
|
|||||||
/* fetch the authority TLV from a PROXY protocol header */
|
/* fetch the authority TLV from a PROXY protocol header */
|
||||||
int smp_fetch_fc_pp_authority(const struct arg *args, struct sample *smp, const char *kw, void *private)
|
int smp_fetch_fc_pp_authority(const struct arg *args, struct sample *smp, const char *kw, void *private)
|
||||||
{
|
{
|
||||||
struct connection *conn = NULL;
|
struct arg tlv_arg;
|
||||||
struct conn_tlv_list *conn_tlv = NULL;
|
int ret;
|
||||||
|
|
||||||
conn = objt_conn(smp->sess->origin);
|
set_tlv_arg(PP2_TYPE_AUTHORITY, &tlv_arg);
|
||||||
if (!conn)
|
ret = smp_fetch_fc_pp_tlv(&tlv_arg, smp, kw, private);
|
||||||
return 0;
|
smp->flags &= ~SMP_F_NOT_LAST; // return only the first authority
|
||||||
|
return ret;
|
||||||
if (conn->flags & CO_FL_WAIT_XPRT) {
|
|
||||||
smp->flags |= SMP_F_MAY_CHANGE;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
conn_tlv = smp->ctx.p ? smp->ctx.p : LIST_ELEM(conn->tlv_list.n, struct conn_tlv_list *, list);
|
|
||||||
list_for_each_entry_from(conn_tlv, &conn->tlv_list, list) {
|
|
||||||
if (conn_tlv->type == PP2_TYPE_AUTHORITY) {
|
|
||||||
smp->data.type = SMP_T_STR;
|
|
||||||
smp->data.u.str.area = conn_tlv->value;
|
|
||||||
smp->data.u.str.data = conn_tlv->len;
|
|
||||||
smp->ctx.p = conn_tlv;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
smp->flags &= ~SMP_F_NOT_LAST;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fetch the unique ID TLV from a PROXY protocol header */
|
/* fetch the unique ID TLV from a PROXY protocol header */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user