MINOR: tcp: replace tcp_src_to_stktable_key with addr_to_stktable_key

Make it more obvious that this function does not depend on any knowledge
of the session. This is important to plan for TCP rules that can run on
connection without any initialized session yet.
This commit is contained in:
Willy Tarreau 2012-08-30 22:59:48 +02:00 committed by Willy Tarreau
parent 14f8e86da5
commit 64ee491309
3 changed files with 26 additions and 26 deletions

View File

@ -39,19 +39,19 @@ int tcp_inspect_response(struct session *s, struct channel *rep, int an_bit);
int tcp_exec_req_rules(struct session *s);
int smp_fetch_rdp_cookie(struct proxy *px, struct session *l4, void *l7, unsigned int opt, const struct arg *args, struct sample *smp);
/* Converts the TCP source address to a stick_table key usable for table
/* Converts the INET/INET6 source address to a stick_table key usable for table
* lookups. Returns either NULL if the source cannot be converted (eg: not
* IPv4) or a pointer to the converted result in static_table_key in the
* appropriate format (IP).
*/
static inline struct stktable_key *tcp_src_to_stktable_key(struct session *s)
static inline struct stktable_key *addr_to_stktable_key(struct sockaddr_storage *addr)
{
switch (s->si[0].conn.addr.from.ss_family) {
switch (addr->ss_family) {
case AF_INET:
static_table_key.key = (void *)&((struct sockaddr_in *)&s->si[0].conn.addr.from)->sin_addr;
static_table_key.key = (void *)&((struct sockaddr_in *)addr)->sin_addr;
break;
case AF_INET6:
static_table_key.key = (void *)&((struct sockaddr_in6 *)&s->si[0].conn.addr.from)->sin6_addr;
static_table_key.key = (void *)&((struct sockaddr_in6 *)addr)->sin6_addr;
break;
default:
return NULL;

View File

@ -839,7 +839,7 @@ int tcp_inspect_request(struct session *s, struct channel *req, int an_bit)
* to consider rule->act_prm->trk_ctr.type.
*/
t = rule->act_prm.trk_ctr.table.t;
ts = stktable_get_entry(t, tcp_src_to_stktable_key(s));
ts = stktable_get_entry(t, addr_to_stktable_key(&s->si[0].conn.addr.from));
if (ts) {
session_track_stkctr1(s, t, ts);
if (s->fe != s->be)
@ -855,7 +855,7 @@ int tcp_inspect_request(struct session *s, struct channel *req, int an_bit)
* to consider rule->act_prm->trk_ctr.type.
*/
t = rule->act_prm.trk_ctr.table.t;
ts = stktable_get_entry(t, tcp_src_to_stktable_key(s));
ts = stktable_get_entry(t, addr_to_stktable_key(&s->si[0].conn.addr.from));
if (ts) {
session_track_stkctr2(s, t, ts);
if (s->fe != s->be)
@ -1009,7 +1009,7 @@ int tcp_exec_req_rules(struct session *s)
* to consider rule->act_prm->trk_ctr.type.
*/
t = rule->act_prm.trk_ctr.table.t;
ts = stktable_get_entry(t, tcp_src_to_stktable_key(s));
ts = stktable_get_entry(t, addr_to_stktable_key(&s->si[0].conn.addr.from));
if (ts)
session_track_stkctr1(s, t, ts);
}
@ -1022,7 +1022,7 @@ int tcp_exec_req_rules(struct session *s)
* to consider rule->act_prm->trk_ctr.type.
*/
t = rule->act_prm.trk_ctr.table.t;
ts = stktable_get_entry(t, tcp_src_to_stktable_key(s));
ts = stktable_get_entry(t, addr_to_stktable_key(&s->si[0].conn.addr.from));
if (ts)
session_track_stkctr2(s, t, ts);
}

View File

@ -2369,7 +2369,7 @@ acl_fetch_src_get_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned
{
struct stktable_key *key;
key = tcp_src_to_stktable_key(l4);
key = addr_to_stktable_key(&l4->si[0].conn.addr.from);
if (!key)
return 0;
@ -2429,7 +2429,7 @@ acl_fetch_src_inc_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned
{
struct stktable_key *key;
key = tcp_src_to_stktable_key(l4);
key = addr_to_stktable_key(&l4->si[0].conn.addr.from);
if (!key)
return 0;
@ -2490,7 +2490,7 @@ acl_fetch_src_clr_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned
{
struct stktable_key *key;
key = tcp_src_to_stktable_key(l4);
key = addr_to_stktable_key(&l4->si[0].conn.addr.from);
if (!key)
return 0;
@ -2546,7 +2546,7 @@ acl_fetch_src_conn_cnt(struct proxy *px, struct session *l4, void *l7, unsigned
{
struct stktable_key *key;
key = tcp_src_to_stktable_key(l4);
key = addr_to_stktable_key(&l4->si[0].conn.addr.from);
if (!key)
return 0;
@ -2607,7 +2607,7 @@ acl_fetch_src_conn_rate(struct proxy *px, struct session *l4, void *l7, unsigned
{
struct stktable_key *key;
key = tcp_src_to_stktable_key(l4);
key = addr_to_stktable_key(&l4->si[0].conn.addr.from);
if (!key)
return 0;
@ -2627,7 +2627,7 @@ acl_fetch_src_updt_conn_cnt(struct proxy *px, struct session *l4, void *l7, unsi
struct stktable_key *key;
void *ptr;
key = tcp_src_to_stktable_key(l4);
key = addr_to_stktable_key(&l4->si[0].conn.addr.from);
if (!key)
return 0;
@ -2696,7 +2696,7 @@ acl_fetch_src_conn_cur(struct proxy *px, struct session *l4, void *l7, unsigned
{
struct stktable_key *key;
key = tcp_src_to_stktable_key(l4);
key = addr_to_stktable_key(&l4->si[0].conn.addr.from);
if (!key)
return 0;
@ -2752,7 +2752,7 @@ acl_fetch_src_sess_cnt(struct proxy *px, struct session *l4, void *l7, unsigned
{
struct stktable_key *key;
key = tcp_src_to_stktable_key(l4);
key = addr_to_stktable_key(&l4->si[0].conn.addr.from);
if (!key)
return 0;
@ -2813,7 +2813,7 @@ acl_fetch_src_sess_rate(struct proxy *px, struct session *l4, void *l7, unsigned
{
struct stktable_key *key;
key = tcp_src_to_stktable_key(l4);
key = addr_to_stktable_key(&l4->si[0].conn.addr.from);
if (!key)
return 0;
@ -2869,7 +2869,7 @@ acl_fetch_src_http_req_cnt(struct proxy *px, struct session *l4, void *l7, unsig
{
struct stktable_key *key;
key = tcp_src_to_stktable_key(l4);
key = addr_to_stktable_key(&l4->si[0].conn.addr.from);
if (!key)
return 0;
@ -2930,7 +2930,7 @@ acl_fetch_src_http_req_rate(struct proxy *px, struct session *l4, void *l7, unsi
{
struct stktable_key *key;
key = tcp_src_to_stktable_key(l4);
key = addr_to_stktable_key(&l4->si[0].conn.addr.from);
if (!key)
return 0;
@ -2986,7 +2986,7 @@ acl_fetch_src_http_err_cnt(struct proxy *px, struct session *l4, void *l7, unsig
{
struct stktable_key *key;
key = tcp_src_to_stktable_key(l4);
key = addr_to_stktable_key(&l4->si[0].conn.addr.from);
if (!key)
return 0;
@ -3047,7 +3047,7 @@ acl_fetch_src_http_err_rate(struct proxy *px, struct session *l4, void *l7, unsi
{
struct stktable_key *key;
key = tcp_src_to_stktable_key(l4);
key = addr_to_stktable_key(&l4->si[0].conn.addr.from);
if (!key)
return 0;
@ -3108,7 +3108,7 @@ acl_fetch_src_kbytes_in(struct proxy *px, struct session *l4, void *l7, unsigned
{
struct stktable_key *key;
key = tcp_src_to_stktable_key(l4);
key = addr_to_stktable_key(&l4->si[0].conn.addr.from);
if (!key)
return 0;
@ -3171,7 +3171,7 @@ acl_fetch_src_bytes_in_rate(struct proxy *px, struct session *l4, void *l7, unsi
{
struct stktable_key *key;
key = tcp_src_to_stktable_key(l4);
key = addr_to_stktable_key(&l4->si[0].conn.addr.from);
if (!key)
return 0;
@ -3232,7 +3232,7 @@ acl_fetch_src_kbytes_out(struct proxy *px, struct session *l4, void *l7, unsigne
{
struct stktable_key *key;
key = tcp_src_to_stktable_key(l4);
key = addr_to_stktable_key(&l4->si[0].conn.addr.from);
if (!key)
return 0;
@ -3295,7 +3295,7 @@ acl_fetch_src_bytes_out_rate(struct proxy *px, struct session *l4, void *l7, uns
{
struct stktable_key *key;
key = tcp_src_to_stktable_key(l4);
key = addr_to_stktable_key(&l4->si[0].conn.addr.from);
if (!key)
return 0;