]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tcp: replace tcp_src_to_stktable_key with addr_to_stktable_key
authorWilly Tarreau <wtarreau@exceliance.fr>
Thu, 30 Aug 2012 20:59:48 +0000 (22:59 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 3 Sep 2012 18:47:34 +0000 (20:47 +0200)
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.

include/proto/proto_tcp.h
src/proto_tcp.c
src/session.c

index 5b6bf4499daaf008abf3c28373a05a1020cc6990..1a1dcfab51fc1023c9d0df19313490293caef872 100644 (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;
index b61d87e6c09a9513975deff6d22c4efa810711aa..af9dbf95b0e7ce590b7b8ac8090933d7278fdda2 100644 (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);
                                }
index 774a8a319683d8a8fefe56d80acf84f7b359d892..db13fc632540569d74b1ae8fcb2d7d0319b73991 100644 (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;