From: Willy Tarreau Date: Fri, 20 Apr 2012 18:49:27 +0000 (+0200) Subject: MEDIUM: pattern: add new sample types to replace pattern types X-Git-Tag: v1.5-dev9~51 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=422aa0792d8a214e4d67806a5e2d66ebe7091bc1;p=thirdparty%2Fhaproxy.git MEDIUM: pattern: add new sample types to replace pattern types The new sample types are necessary for the acl-pattern convergence. These types are boolean and signed int. Some types were renamed for less ambiguity (ip->ipv4, integer->uint). --- diff --git a/include/types/pattern.h b/include/types/pattern.h index 16a2e78b49..c37959564b 100644 --- a/include/types/pattern.h +++ b/include/types/pattern.h @@ -27,16 +27,18 @@ #include #include -/* pattern in and out types */ +/* input and output sample types */ enum { - PATTERN_TYPE_IP = 0, /* ipv4 type */ - PATTERN_TYPE_IPV6, /* ipv6 type */ - PATTERN_TYPE_INTEGER, /* unsigned 32bits integer type */ - PATTERN_TYPE_STRING, /* char string type */ - PATTERN_TYPE_DATA, /* buffer type */ - PATTERN_TYPE_CONSTSTRING, /* constant char string type, data need dup before conversion */ - PATTERN_TYPE_CONSTDATA, /* constant buffer type, data need dup before conversion */ - PATTERN_TYPES /* number of types, must always be last */ + SMP_T_BOOL = 0, /* boolean */ + SMP_T_UINT, /* unsigned 32bits integer type */ + SMP_T_SINT, /* signed 32bits integer type */ + SMP_T_IPV4, /* ipv4 type */ + SMP_T_IPV6, /* ipv6 type */ + SMP_T_STR, /* char string type */ + SMP_T_BIN, /* buffer type */ + SMP_T_CSTR, /* constant char string type, data need dup before conversion */ + SMP_T_CBIN, /* constant buffer type, data need dup before conversion */ + SMP_TYPES /* number of types, must always be last */ }; /* Flags used to describe fetched samples. MAY_CHANGE indicates that the result @@ -70,10 +72,11 @@ enum { /* pattern result data */ union pattern_data { - struct in_addr ip; /* used for ipv4 type */ - struct in6_addr ipv6; /* used for ipv6 type */ - int integer; /* used for unsigned 32bits integer type */ - struct chunk str; /* used for char string type or buffers*/ + unsigned int uint; /* used for unsigned 32bits integers and booleans */ + int sint; /* used for signed 32bits integers */ + struct in_addr ipv4; /* used for ipv4 addresses */ + struct in6_addr ipv6; /* used for ipv6 addresses */ + struct chunk str; /* used for char strings or buffers */ }; /* pattern result */ @@ -100,7 +103,7 @@ union smp_ctx { */ struct sample { unsigned int flags; /* SMP_F_* */ - int type; /* PATTERN_TYPE_* */ + int type; /* SMP_T_* */ union pattern_data data; union smp_ctx ctx; }; diff --git a/src/acl.c b/src/acl.c index 673ca03a42..b5422d655f 100644 --- a/src/acl.c +++ b/src/acl.c @@ -104,7 +104,7 @@ acl_fetch_req_len(struct proxy *px, struct session *l4, void *l7, int dir, if (!l4 || !l4->req) return 0; - temp_pattern.data.integer = l4->req->i; + temp_pattern.data.uint = l4->req->i; test->flags = ACL_TEST_F_VOLATILE | ACL_TEST_F_MAY_CHANGE; return 1; } @@ -157,7 +157,7 @@ acl_fetch_ssl_hello_type(struct proxy *px, struct session *l4, void *l7, int dir goto not_ssl_hello; } - temp_pattern.data.integer = hs_type; + temp_pattern.data.uint = hs_type; test->flags = ACL_TEST_F_VOLATILE; return 1; @@ -270,7 +270,7 @@ acl_fetch_req_ssl_ver(struct proxy *px, struct session *l4, void *l7, int dir, /* OK that's enough. We have at least the whole message, and we have * the protocol version. */ - temp_pattern.data.integer = version; + temp_pattern.data.uint = version; test->flags = ACL_TEST_F_VOLATILE; return 1; @@ -553,7 +553,7 @@ acl_fetch_rdp_cookie_cnt(struct proxy *px, struct session *l4, void *l7, int dir return 0; test->flags = ACL_TEST_F_VOLATILE; - temp_pattern.data.integer = ret; + temp_pattern.data.uint = ret; return 1; } @@ -814,8 +814,8 @@ int acl_match_dom(struct acl_test *test, struct acl_pattern *pattern) /* Checks that the integer in is included between min and max */ int acl_match_int(struct acl_test *test, struct acl_pattern *pattern) { - if ((!pattern->val.range.min_set || pattern->val.range.min <= temp_pattern.data.integer) && - (!pattern->val.range.max_set || temp_pattern.data.integer <= pattern->val.range.max)) + if ((!pattern->val.range.min_set || pattern->val.range.min <= temp_pattern.data.uint) && + (!pattern->val.range.max_set || temp_pattern.data.uint <= pattern->val.range.max)) return ACL_PAT_PASS; return ACL_PAT_FAIL; } @@ -833,10 +833,10 @@ int acl_match_ip(struct acl_test *test, struct acl_pattern *pattern) { struct in_addr *s; - if (temp_pattern.type != PATTERN_TYPE_IP) + if (temp_pattern.type != SMP_T_IPV4) return ACL_PAT_FAIL; - s = &temp_pattern.data.ip; + s = &temp_pattern.data.ipv4; if (((s->s_addr ^ pattern->val.ipv4.addr.s_addr) & pattern->val.ipv4.mask.s_addr) == 0) return ACL_PAT_PASS; return ACL_PAT_FAIL; @@ -849,10 +849,10 @@ void *acl_lookup_ip(struct acl_test *test, struct acl_expr *expr) { struct in_addr *s; - if (temp_pattern.type != PATTERN_TYPE_IP) + if (temp_pattern.type != SMP_T_IPV4) return ACL_PAT_FAIL; - s = &temp_pattern.data.ip; + s = &temp_pattern.data.ipv4; return ebmb_lookup_longest(&expr->pattern_tree, &s->s_addr); } diff --git a/src/backend.c b/src/backend.c index 742e87edf5..291201e55b 100644 --- a/src/backend.c +++ b/src/backend.c @@ -1389,11 +1389,11 @@ acl_fetch_nbsrv(struct proxy *px, struct session *l4, void *l7, int dir, px = expr->args->data.prx; if (px->srv_act) - temp_pattern.data.integer = px->srv_act; + temp_pattern.data.uint = px->srv_act; else if (px->lbprm.fbck) - temp_pattern.data.integer = 1; + temp_pattern.data.uint = 1; else - temp_pattern.data.integer = px->srv_bck; + temp_pattern.data.uint = px->srv_bck; return 1; } @@ -1429,7 +1429,7 @@ acl_fetch_connslots(struct proxy *px, struct session *l4, void *l7, int dir, struct server *iterator; test->flags = ACL_TEST_F_VOL_TEST; - temp_pattern.data.integer = 0; + temp_pattern.data.uint = 0; for (iterator = expr->args->data.prx->srv; iterator; iterator = iterator->next) { if ((iterator->state & SRV_RUNNING) == 0) @@ -1437,12 +1437,12 @@ acl_fetch_connslots(struct proxy *px, struct session *l4, void *l7, int dir, if (iterator->maxconn == 0 || iterator->maxqueue == 0) { /* configuration is stupid */ - temp_pattern.data.integer = -1; + temp_pattern.data.uint = -1; /* FIXME: stupid value! */ return 1; } - temp_pattern.data.integer += (iterator->maxconn - iterator->cur_sess) - + (iterator->maxqueue - iterator->nbpend); + temp_pattern.data.uint += (iterator->maxconn - iterator->cur_sess) + + (iterator->maxqueue - iterator->nbpend); } return 1; @@ -1454,7 +1454,7 @@ acl_fetch_be_id(struct proxy *px, struct session *l4, void *l7, int dir, struct acl_expr *expr, struct acl_test *test) { test->flags = ACL_TEST_F_READ_ONLY; - temp_pattern.data.integer = l4->be->uuid; + temp_pattern.data.uint = l4->be->uuid; return 1; } @@ -1468,7 +1468,7 @@ acl_fetch_srv_id(struct proxy *px, struct session *l4, void *l7, int dir, return 0; test->flags = ACL_TEST_F_READ_ONLY; - temp_pattern.data.integer = target_srv(&l4->target)->puid; + temp_pattern.data.uint = target_srv(&l4->target)->puid; return 1; } @@ -1482,7 +1482,7 @@ acl_fetch_be_sess_rate(struct proxy *px, struct session *l4, void *l7, int dir, struct acl_expr *expr, struct acl_test *test) { test->flags = ACL_TEST_F_VOL_TEST; - temp_pattern.data.integer = read_freq_ctr(&expr->args->data.prx->be_sess_per_sec); + temp_pattern.data.uint = read_freq_ctr(&expr->args->data.prx->be_sess_per_sec); return 1; } @@ -1495,7 +1495,7 @@ acl_fetch_be_conn(struct proxy *px, struct session *l4, void *l7, int dir, struct acl_expr *expr, struct acl_test *test) { test->flags = ACL_TEST_F_VOL_TEST; - temp_pattern.data.integer = expr->args->data.prx->beconn; + temp_pattern.data.uint = expr->args->data.prx->beconn; return 1; } @@ -1508,7 +1508,7 @@ acl_fetch_queue_size(struct proxy *px, struct session *l4, void *l7, int dir, struct acl_expr *expr, struct acl_test *test) { test->flags = ACL_TEST_F_VOL_TEST; - temp_pattern.data.integer = expr->args->data.prx->totpend; + temp_pattern.data.uint = expr->args->data.prx->totpend; return 1; } @@ -1537,9 +1537,9 @@ acl_fetch_avg_queue_size(struct proxy *px, struct session *l4, void *l7, int dir nbsrv = px->srv_bck; if (nbsrv > 0) - temp_pattern.data.integer = (px->totpend + nbsrv - 1) / nbsrv; + temp_pattern.data.uint = (px->totpend + nbsrv - 1) / nbsrv; else - temp_pattern.data.integer = px->totpend * 2; + temp_pattern.data.uint = px->totpend * 2; return 1; } @@ -1552,7 +1552,7 @@ static int acl_fetch_srv_conn(struct proxy *px, struct session *l4, void *l7, int dir, struct acl_expr *expr, struct acl_test *test) { - temp_pattern.data.integer = expr->args->data.srv->cur_sess; + temp_pattern.data.uint = expr->args->data.srv->cur_sess; return 1; } diff --git a/src/frontend.c b/src/frontend.c index 685b172990..00a461e36d 100644 --- a/src/frontend.c +++ b/src/frontend.c @@ -503,7 +503,7 @@ acl_fetch_fe_id(struct proxy *px, struct session *l4, void *l7, int dir, struct acl_expr *expr, struct acl_test *test) { test->flags = ACL_TEST_F_READ_ONLY; - temp_pattern.data.integer = l4->fe->uuid; + temp_pattern.data.uint = l4->fe->uuid; return 1; } @@ -516,7 +516,7 @@ acl_fetch_fe_sess_rate(struct proxy *px, struct session *l4, void *l7, int dir, struct acl_expr *expr, struct acl_test *test) { test->flags = ACL_TEST_F_VOL_TEST; - temp_pattern.data.integer = read_freq_ctr(&expr->args->data.prx->fe_sess_per_sec); + temp_pattern.data.uint = read_freq_ctr(&expr->args->data.prx->fe_sess_per_sec); return 1; } @@ -529,7 +529,7 @@ acl_fetch_fe_conn(struct proxy *px, struct session *l4, void *l7, int dir, struct acl_expr *expr, struct acl_test *test) { test->flags = ACL_TEST_F_VOL_TEST; - temp_pattern.data.integer = expr->args->data.prx->feconn; + temp_pattern.data.uint = expr->args->data.prx->feconn; return 1; } diff --git a/src/pattern.c b/src/pattern.c index 0c568efa0a..fac145fbd6 100644 --- a/src/pattern.c +++ b/src/pattern.c @@ -122,7 +122,7 @@ static struct chunk *get_trash_chunk(void) static int c_ip2int(union pattern_data *data) { - data->integer = ntohl(data->ip.s_addr); + data->uint = ntohl(data->ipv4.s_addr); return 1; } @@ -130,7 +130,7 @@ static int c_ip2str(union pattern_data *data) { struct chunk *trash = get_trash_chunk(); - if (!inet_ntop(AF_INET, (void *)&data->ip, trash->str, trash->size)) + if (!inet_ntop(AF_INET, (void *)&data->ipv4, trash->str, trash->size)) return 0; trash->len = strlen(trash->str); @@ -141,7 +141,7 @@ static int c_ip2str(union pattern_data *data) static int c_ip2ipv6(union pattern_data *data) { - v4tov6(&data->ipv6, &data->ip); + v4tov6(&data->ipv6, &data->ipv4); return 1; } @@ -160,19 +160,19 @@ static int c_ipv62str(union pattern_data *data) /* static int c_ipv62ip(union pattern_data *data) { - return v6tov4(&data->ip, &data->ipv6); + return v6tov4(&data->ipv4, &data->ipv6); } */ static int c_int2ip(union pattern_data *data) { - data->ip.s_addr = htonl(data->integer); + data->ipv4.s_addr = htonl(data->uint); return 1; } static int c_str2ip(union pattern_data *data) { - if (!buf2ip(data->str.str, data->str.len, &data->ip)) + if (!buf2ip(data->str.str, data->str.len, &data->ipv4)) return 0; return 1; } @@ -187,7 +187,7 @@ static int c_int2str(union pattern_data *data) struct chunk *trash = get_trash_chunk(); char *pos; - pos = ultoa_r(data->integer, trash->str, trash->size); + pos = ultoa_r(data->uint, trash->str, trash->size); if (!pos) return 0; @@ -210,7 +210,7 @@ static int c_datadup(union pattern_data *data) } -static int c_donothing(union pattern_data *data) +static int c_none(union pattern_data *data) { return 1; } @@ -229,7 +229,7 @@ static int c_str2int(union pattern_data *data) ret = ret * 10 + val; } - data->integer = ret; + data->uint = ret; return 1; } @@ -240,18 +240,19 @@ static int c_str2int(union pattern_data *data) /*****************************************************************/ typedef int (*pattern_cast_fct)(union pattern_data *data); -static pattern_cast_fct pattern_casts[PATTERN_TYPES][PATTERN_TYPES] = { -/* to: IP IPV6 INTEGER STRING DATA CONSTSTRING CONSTDATA */ -/* from: IP */ { c_donothing, c_ip2ipv6, c_ip2int, c_ip2str, NULL, c_ip2str, NULL }, -/* IPV6 */ { NULL, c_donothing, NULL, c_ipv62str, NULL, c_ipv62str, NULL }, -/* INTEGER */ { c_int2ip, NULL, c_donothing, c_int2str, NULL, c_int2str, NULL }, -/* STRING */ { c_str2ip, c_str2ipv6, c_str2int, c_donothing, c_donothing, c_donothing, c_donothing }, -/* DATA */ { NULL, NULL, NULL, NULL, c_donothing, NULL, c_donothing }, -/* CONSTSTRING */ { c_str2ip, c_str2ipv6, c_str2int, c_datadup, c_datadup, c_donothing, c_donothing }, -/* CONSTDATA */ { NULL, NULL, NULL, NULL, c_datadup, NULL, c_donothing }, +static pattern_cast_fct pattern_casts[SMP_TYPES][SMP_TYPES] = { +/* to: BOOL UINT SINT IPV4 IPV6 STR BIN CSTR CBIN */ +/* from: BOOL */ { c_none, c_none, c_none, NULL, NULL, NULL, NULL, NULL, NULL }, +/* UINT */ { c_none, c_none, c_none, c_int2ip, NULL, c_int2str, NULL, c_int2str, NULL }, +/* SINT */ { c_none, c_none, c_none, c_int2ip, NULL, c_int2str, NULL, c_int2str, NULL }, +/* IPV4 */ { NULL, c_ip2int, c_ip2int, c_none, c_ip2ipv6, c_ip2str, NULL, c_ip2str, NULL }, +/* IPV6 */ { NULL, NULL, NULL, NULL, c_none, c_ipv62str, NULL, c_ipv62str, NULL }, +/* STR */ { c_str2int, c_str2int, c_str2int, c_str2ip, c_str2ipv6, c_none, c_none, c_none, c_none }, +/* BIN */ { NULL, NULL, NULL, NULL, NULL, NULL, c_none, NULL, c_none }, +/* CSTR */ { c_str2int, c_str2int, c_str2int, c_str2ip, c_str2ipv6, c_datadup, c_datadup, c_none, c_none }, +/* CBIN */ { NULL, NULL, NULL, NULL, NULL, NULL, c_datadup, NULL, c_none }, }; - /* * Parse a pattern expression configuration: * fetch keyword followed by format conversion keywords. @@ -297,7 +298,7 @@ struct pattern_expr *pattern_parse_expr(char **str, int *idx, char *err, int err } goto out_error; } - if (fetch->out_type >= PATTERN_TYPES) { + if (fetch->out_type >= SMP_TYPES) { p = my_strndup(str[*idx], endw - str[*idx]); if (p) { @@ -378,8 +379,8 @@ struct pattern_expr *pattern_parse_expr(char **str, int *idx, char *err, int err if (!conv) break; - if (conv->in_type >= PATTERN_TYPES || - conv->out_type >= PATTERN_TYPES) { + if (conv->in_type >= SMP_TYPES || + conv->out_type >= SMP_TYPES) { p = my_strndup(str[*idx], endw - str[*idx]); if (p) { snprintf(err, err_size, "returns type of conv method '%s' is unknown.", p); @@ -527,15 +528,15 @@ static int pattern_conv_str2upper(const struct arg *arg_p, union pattern_data *d /* takes the netmask in arg_p */ static int pattern_conv_ipmask(const struct arg *arg_p, union pattern_data *data) { - data->ip.s_addr &= arg_p->data.ipv4.s_addr; + data->ipv4.s_addr &= arg_p->data.ipv4.s_addr; return 1; } /* Note: must not be declared as its list will be overwritten */ static struct pattern_conv_kw_list pattern_conv_kws = {{ },{ - { "upper", pattern_conv_str2upper, 0, NULL, PATTERN_TYPE_STRING, PATTERN_TYPE_STRING }, - { "lower", pattern_conv_str2lower, 0, NULL, PATTERN_TYPE_STRING, PATTERN_TYPE_STRING }, - { "ipmask", pattern_conv_ipmask, ARG1(1,MSK4), NULL, PATTERN_TYPE_IP, PATTERN_TYPE_IP }, + { "upper", pattern_conv_str2upper, 0, NULL, SMP_T_STR, SMP_T_STR }, + { "lower", pattern_conv_str2lower, 0, NULL, SMP_T_STR, SMP_T_STR }, + { "ipmask", pattern_conv_ipmask, ARG1(1,MSK4), NULL, SMP_T_IPV4, SMP_T_IPV4 }, { NULL, NULL, 0, 0, 0 }, }}; diff --git a/src/proto_http.c b/src/proto_http.c index 82aa241727..b2b4c06404 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -7769,7 +7769,7 @@ acl_fetch_stcode(struct proxy *px, struct session *l4, void *l7, int dir, len = txn->rsp.sl.st.c_l; ptr = txn->rsp.buf->p + txn->rsp.sol + txn->rsp.sl.st.c; - temp_pattern.data.integer = __strl2ui(ptr, len); + temp_pattern.data.uint = __strl2ui(ptr, len); test->flags = ACL_TEST_F_VOL_1ST; return 1; } @@ -7803,8 +7803,8 @@ acl_fetch_url_ip(struct proxy *px, struct session *l4, void *l7, int dir, url2sa(txn->req.buf->p + txn->req.sol + txn->req.sl.rq.u, txn->req.sl.rq.u_l, &l4->req->cons->addr.to); if (((struct sockaddr_in *)&l4->req->cons->addr.to)->sin_family != AF_INET) return 0; - temp_pattern.type = PATTERN_TYPE_IP; - temp_pattern.data.ip = ((struct sockaddr_in *)&l4->req->cons->addr.to)->sin_addr; + temp_pattern.type = SMP_T_IPV4; + temp_pattern.data.ipv4 = ((struct sockaddr_in *)&l4->req->cons->addr.to)->sin_addr; /* * If we are parsing url in frontend space, we prepare backend stage @@ -7827,7 +7827,7 @@ acl_fetch_url_port(struct proxy *px, struct session *l4, void *l7, int dir, /* Same optimization as url_ip */ url2sa(txn->req.buf->p + txn->req.sol + txn->req.sl.rq.u, txn->req.sl.rq.u_l, &l4->req->cons->addr.to); - temp_pattern.data.integer = ntohs(((struct sockaddr_in *)&l4->req->cons->addr.to)->sin_port); + temp_pattern.data.uint = ntohs(((struct sockaddr_in *)&l4->req->cons->addr.to)->sin_port); if (px->options & PR_O_HTTP_PROXY) l4->flags |= SN_ADDR_SET; @@ -7894,7 +7894,7 @@ acl_fetch_hdr_cnt(struct proxy *px, struct session *l4, void *l7, int dir, while (http_find_header2(expr->args->data.str.str, expr->args->data.str.len, msg->buf->p + msg->sol, idx, &ctx)) cnt++; - temp_pattern.data.integer = cnt; + temp_pattern.data.uint = cnt; test->flags = ACL_TEST_F_VOL_HDR; return 1; } @@ -7909,7 +7909,7 @@ acl_fetch_hdr_val(struct proxy *px, struct session *l4, void *l7, int dir, int ret = acl_fetch_hdr(px, l4, l7, dir, expr, test); if (ret > 0) - temp_pattern.data.integer = strl2ic(temp_pattern.data.str.str, temp_pattern.data.str.len); + temp_pattern.data.uint = strl2ic(temp_pattern.data.str.str, temp_pattern.data.str.len); return ret; } @@ -7923,8 +7923,8 @@ acl_fetch_hdr_ip(struct proxy *px, struct session *l4, void *l7, int dir, int ret; while ((ret = acl_fetch_hdr(px, l4, l7, dir, expr, test)) > 0) { - temp_pattern.type = PATTERN_TYPE_IP; - if (url2ipv4((char *)temp_pattern.data.str.str, &temp_pattern.data.ip)) + temp_pattern.type = SMP_T_IPV4; + if (url2ipv4((char *)temp_pattern.data.str.str, &temp_pattern.data.ipv4)) break; /* if the header doesn't match an IP address, fetch next one */ } @@ -8244,7 +8244,7 @@ acl_fetch_cookie_cnt(struct proxy *px, struct session *l4, void *l7, int dir, } } - temp_pattern.data.integer = cnt; + temp_pattern.data.uint = cnt; test->flags |= ACL_TEST_F_VOL_HDR; return 1; } @@ -8537,10 +8537,10 @@ pattern_fetch_set_cookie(struct proxy *px, struct session *l4, void *l7, int dir /************************************************************************/ /* Note: must not be declared as its list will be overwritten */ static struct pattern_fetch_kw_list pattern_fetch_keywords = {{ },{ - { "hdr", pattern_fetch_hdr, ARG1(1,STR), NULL, PATTERN_TYPE_STRING, PATTERN_FETCH_REQ }, - { "url_param", pattern_fetch_url_param, ARG1(1,STR), NULL, PATTERN_TYPE_STRING, PATTERN_FETCH_REQ }, - { "cookie", pattern_fetch_cookie, ARG1(1,STR), NULL, PATTERN_TYPE_STRING, PATTERN_FETCH_REQ }, - { "set-cookie", pattern_fetch_set_cookie, ARG1(1,STR), NULL, PATTERN_TYPE_STRING, PATTERN_FETCH_RTR }, + { "hdr", pattern_fetch_hdr, ARG1(1,STR), NULL, SMP_T_CSTR, PATTERN_FETCH_REQ }, + { "url_param", pattern_fetch_url_param, ARG1(1,STR), NULL, SMP_T_CSTR, PATTERN_FETCH_REQ }, + { "cookie", pattern_fetch_cookie, ARG1(1,STR), NULL, SMP_T_CSTR, PATTERN_FETCH_REQ }, + { "set-cookie", pattern_fetch_set_cookie, ARG1(1,STR), NULL, SMP_T_CSTR, PATTERN_FETCH_RTR }, { NULL, NULL, 0, 0, 0 }, }}; diff --git a/src/proto_tcp.c b/src/proto_tcp.c index 715f1e9068..d532cbe4cc 100644 --- a/src/proto_tcp.c +++ b/src/proto_tcp.c @@ -1258,12 +1258,12 @@ acl_fetch_src(struct proxy *px, struct session *l4, void *l7, int dir, { switch (l4->si[0].addr.from.ss_family) { case AF_INET: - temp_pattern.data.ip = ((struct sockaddr_in *)&l4->si[0].addr.from)->sin_addr; - temp_pattern.type = PATTERN_TYPE_IP; + temp_pattern.data.ipv4 = ((struct sockaddr_in *)&l4->si[0].addr.from)->sin_addr; + temp_pattern.type = SMP_T_IPV4; break; case AF_INET6: temp_pattern.data.ipv6 = ((struct sockaddr_in6 *)(&l4->si[0].addr.from))->sin6_addr; - temp_pattern.type = PATTERN_TYPE_IPV6; + temp_pattern.type = SMP_T_IPV6; break; default: return 0; @@ -1281,7 +1281,7 @@ pattern_fetch_src(struct proxy *px, struct session *l4, void *l7, int dir, if (l4->si[0].addr.from.ss_family != AF_INET ) return 0; - data->ip.s_addr = ((struct sockaddr_in *)&l4->si[0].addr.from)->sin_addr.s_addr; + data->ipv4.s_addr = ((struct sockaddr_in *)&l4->si[0].addr.from)->sin_addr.s_addr; return 1; } @@ -1302,7 +1302,7 @@ static int acl_fetch_sport(struct proxy *px, struct session *l4, void *l7, int dir, struct acl_expr *expr, struct acl_test *test) { - if (!(temp_pattern.data.integer = get_host_port(&l4->si[0].addr.from))) + if (!(temp_pattern.data.uint = get_host_port(&l4->si[0].addr.from))) return 0; test->flags = 0; @@ -1319,12 +1319,12 @@ acl_fetch_dst(struct proxy *px, struct session *l4, void *l7, int dir, switch (l4->si[0].addr.to.ss_family) { case AF_INET: - temp_pattern.data.ip = ((struct sockaddr_in *)&l4->si[0].addr.to)->sin_addr; - temp_pattern.type = PATTERN_TYPE_IP; + temp_pattern.data.ipv4 = ((struct sockaddr_in *)&l4->si[0].addr.to)->sin_addr; + temp_pattern.type = SMP_T_IPV4; break; case AF_INET6: temp_pattern.data.ipv6 = ((struct sockaddr_in6 *)(&l4->si[0].addr.to))->sin6_addr; - temp_pattern.type = PATTERN_TYPE_IPV6; + temp_pattern.type = SMP_T_IPV6; break; default: return 0; @@ -1345,7 +1345,7 @@ pattern_fetch_dst(struct proxy *px, struct session *l4, void *l7, int dir, if (l4->si[0].addr.to.ss_family != AF_INET) return 0; - data->ip.s_addr = ((struct sockaddr_in *)&l4->si[0].addr.to)->sin_addr.s_addr; + data->ipv4.s_addr = ((struct sockaddr_in *)&l4->si[0].addr.to)->sin_addr.s_addr; return 1; } @@ -1370,7 +1370,7 @@ acl_fetch_dport(struct proxy *px, struct session *l4, void *l7, int dir, { stream_sock_get_to_addr(&l4->si[0]); - if (!(temp_pattern.data.integer = get_host_port(&l4->si[0].addr.to))) + if (!(temp_pattern.data.uint = get_host_port(&l4->si[0].addr.to))) return 0; test->flags = 0; @@ -1383,7 +1383,7 @@ pattern_fetch_dport(struct proxy *px, struct session *l4, void *l7, int dir, { stream_sock_get_to_addr(&l4->si[0]); - if (!(data->integer = get_host_port(&l4->si[0].addr.to))) + if (!(data->uint = get_host_port(&l4->si[0].addr.to))) return 0; return 1; @@ -1556,14 +1556,14 @@ static struct acl_kw_list acl_kws = {{ },{ /* Note: must not be declared as its list will be overwritten */ static struct pattern_fetch_kw_list pattern_fetch_keywords = {{ },{ - { "src", pattern_fetch_src, 0, NULL, PATTERN_TYPE_IP, PATTERN_FETCH_REQ }, - { "src6", pattern_fetch_src6, 0, NULL, PATTERN_TYPE_IPV6, PATTERN_FETCH_REQ }, - { "dst", pattern_fetch_dst, 0, NULL, PATTERN_TYPE_IP, PATTERN_FETCH_REQ }, - { "dst6", pattern_fetch_dst6, 0, NULL, PATTERN_TYPE_IPV6, PATTERN_FETCH_REQ }, - { "dst_port", pattern_fetch_dport, 0, NULL, PATTERN_TYPE_INTEGER, PATTERN_FETCH_REQ }, - { "payload", pattern_fetch_payload, ARG2(2,UINT,UINT), val_payload, PATTERN_TYPE_CONSTDATA, PATTERN_FETCH_REQ|PATTERN_FETCH_RTR }, - { "payload_lv", pattern_fetch_payloadlv, ARG3(2,UINT,UINT,SINT), val_payload_lv, PATTERN_TYPE_CONSTDATA, PATTERN_FETCH_REQ|PATTERN_FETCH_RTR }, - { "rdp_cookie", pattern_fetch_rdp_cookie, ARG1(1,STR), NULL, PATTERN_TYPE_CONSTSTRING, PATTERN_FETCH_REQ }, + { "src", pattern_fetch_src, 0, NULL, SMP_T_IPV4, PATTERN_FETCH_REQ }, + { "src6", pattern_fetch_src6, 0, NULL, SMP_T_IPV6, PATTERN_FETCH_REQ }, + { "dst", pattern_fetch_dst, 0, NULL, SMP_T_IPV4, PATTERN_FETCH_REQ }, + { "dst6", pattern_fetch_dst6, 0, NULL, SMP_T_IPV6, PATTERN_FETCH_REQ }, + { "dst_port", pattern_fetch_dport, 0, NULL, SMP_T_UINT, PATTERN_FETCH_REQ }, + { "payload", pattern_fetch_payload, ARG2(2,UINT,UINT), val_payload, SMP_T_CBIN, PATTERN_FETCH_REQ|PATTERN_FETCH_RTR }, + { "payload_lv", pattern_fetch_payloadlv, ARG3(2,UINT,UINT,SINT), val_payload_lv, SMP_T_CBIN, PATTERN_FETCH_REQ|PATTERN_FETCH_RTR }, + { "rdp_cookie", pattern_fetch_rdp_cookie, ARG1(1,STR), NULL, SMP_T_CSTR, PATTERN_FETCH_REQ }, { NULL, NULL, 0, 0, 0 }, }}; diff --git a/src/protocols.c b/src/protocols.c index 169a50d254..ebf601b9ca 100644 --- a/src/protocols.c +++ b/src/protocols.c @@ -328,7 +328,7 @@ static int acl_fetch_dconn(struct proxy *px, struct session *l4, void *l7, int dir, struct acl_expr *expr, struct acl_test *test) { - temp_pattern.data.integer = l4->listener->nbconn; + temp_pattern.data.uint = l4->listener->nbconn; return 1; } @@ -338,7 +338,7 @@ acl_fetch_so_id(struct proxy *px, struct session *l4, void *l7, int dir, struct acl_expr *expr, struct acl_test *test) { test->flags = ACL_TEST_F_READ_ONLY; - temp_pattern.data.integer = l4->listener->luid; + temp_pattern.data.uint = l4->listener->luid; return 1; } diff --git a/src/session.c b/src/session.c index e6a23a6962..1dc46a954d 100644 --- a/src/session.c +++ b/src/session.c @@ -2311,12 +2311,12 @@ static int acl_fetch_get_gpc0(struct stktable *table, struct acl_test *test, struct stksess *ts) { test->flags = ACL_TEST_F_VOL_TEST; - temp_pattern.data.integer = 0; + temp_pattern.data.uint = 0; if (ts != NULL) { void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_GPC0); if (!ptr) return 0; /* parameter not stored */ - temp_pattern.data.integer = stktable_data_cast(ptr, gpc0); + temp_pattern.data.uint = stktable_data_cast(ptr, gpc0); } return 1; } @@ -2370,12 +2370,12 @@ static int acl_fetch_inc_gpc0(struct stktable *table, struct acl_test *test, struct stksess *ts) { test->flags = ACL_TEST_F_VOL_TEST; - temp_pattern.data.integer = 0; + temp_pattern.data.uint = 0; if (ts != NULL) { void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_GPC0); if (!ptr) return 0; /* parameter not stored */ - temp_pattern.data.integer = ++stktable_data_cast(ptr, gpc0); + temp_pattern.data.uint = ++stktable_data_cast(ptr, gpc0); } return 1; } @@ -2429,12 +2429,12 @@ static int acl_fetch_clr_gpc0(struct stktable *table, struct acl_test *test, struct stksess *ts) { test->flags = ACL_TEST_F_VOL_TEST; - temp_pattern.data.integer = 0; + temp_pattern.data.uint = 0; if (ts != NULL) { void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_GPC0); if (!ptr) return 0; /* parameter not stored */ - temp_pattern.data.integer = stktable_data_cast(ptr, gpc0); + temp_pattern.data.uint = stktable_data_cast(ptr, gpc0); stktable_data_cast(ptr, gpc0) = 0; } return 1; @@ -2487,12 +2487,12 @@ static int acl_fetch_conn_cnt(struct stktable *table, struct acl_test *test, struct stksess *ts) { test->flags = ACL_TEST_F_VOL_TEST; - temp_pattern.data.integer = 0; + temp_pattern.data.uint = 0; if (ts != NULL) { void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_CONN_CNT); if (!ptr) return 0; /* parameter not stored */ - temp_pattern.data.integer = stktable_data_cast(ptr, conn_cnt); + temp_pattern.data.uint = stktable_data_cast(ptr, conn_cnt); } return 1; } @@ -2542,12 +2542,12 @@ static int acl_fetch_conn_rate(struct stktable *table, struct acl_test *test, struct stksess *ts) { test->flags = ACL_TEST_F_VOL_TEST; - temp_pattern.data.integer = 0; + temp_pattern.data.uint = 0; if (ts != NULL) { void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_CONN_RATE); if (!ptr) return 0; /* parameter not stored */ - temp_pattern.data.integer = read_freq_ctr_period(&stktable_data_cast(ptr, conn_rate), + temp_pattern.data.uint = read_freq_ctr_period(&stktable_data_cast(ptr, conn_rate), table->data_arg[STKTABLE_DT_CONN_RATE].u); } return 1; @@ -2623,7 +2623,7 @@ acl_fetch_src_updt_conn_cnt(struct proxy *px, struct session *l4, void *l7, int if (!ptr) return 0; /* parameter not stored in this table */ - temp_pattern.data.integer = ++stktable_data_cast(ptr, conn_cnt); + temp_pattern.data.uint = ++stktable_data_cast(ptr, conn_cnt); test->flags = ACL_TEST_F_VOL_TEST; return 1; } @@ -2633,13 +2633,13 @@ static int acl_fetch_conn_cur(struct stktable *table, struct acl_test *test, struct stksess *ts) { test->flags = ACL_TEST_F_VOL_TEST; - temp_pattern.data.integer = 0; + temp_pattern.data.uint = 0; if (ts != NULL) { void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_CONN_CUR); if (!ptr) return 0; /* parameter not stored */ - temp_pattern.data.integer = stktable_data_cast(ptr, conn_cur); + temp_pattern.data.uint = stktable_data_cast(ptr, conn_cur); } return 1; } @@ -2689,12 +2689,12 @@ static int acl_fetch_sess_cnt(struct stktable *table, struct acl_test *test, struct stksess *ts) { test->flags = ACL_TEST_F_VOL_TEST; - temp_pattern.data.integer = 0; + temp_pattern.data.uint = 0; if (ts != NULL) { void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_SESS_CNT); if (!ptr) return 0; /* parameter not stored */ - temp_pattern.data.integer = stktable_data_cast(ptr, sess_cnt); + temp_pattern.data.uint = stktable_data_cast(ptr, sess_cnt); } return 1; } @@ -2744,12 +2744,12 @@ static int acl_fetch_sess_rate(struct stktable *table, struct acl_test *test, struct stksess *ts) { test->flags = ACL_TEST_F_VOL_TEST; - temp_pattern.data.integer = 0; + temp_pattern.data.uint = 0; if (ts != NULL) { void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_SESS_RATE); if (!ptr) return 0; /* parameter not stored */ - temp_pattern.data.integer = read_freq_ctr_period(&stktable_data_cast(ptr, sess_rate), + temp_pattern.data.uint = read_freq_ctr_period(&stktable_data_cast(ptr, sess_rate), table->data_arg[STKTABLE_DT_SESS_RATE].u); } return 1; @@ -2804,12 +2804,12 @@ static int acl_fetch_http_req_cnt(struct stktable *table, struct acl_test *test, struct stksess *ts) { test->flags = ACL_TEST_F_VOL_TEST; - temp_pattern.data.integer = 0; + temp_pattern.data.uint = 0; if (ts != NULL) { void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_HTTP_REQ_CNT); if (!ptr) return 0; /* parameter not stored */ - temp_pattern.data.integer = stktable_data_cast(ptr, http_req_cnt); + temp_pattern.data.uint = stktable_data_cast(ptr, http_req_cnt); } return 1; } @@ -2859,12 +2859,12 @@ static int acl_fetch_http_req_rate(struct stktable *table, struct acl_test *test, struct stksess *ts) { test->flags = ACL_TEST_F_VOL_TEST; - temp_pattern.data.integer = 0; + temp_pattern.data.uint = 0; if (ts != NULL) { void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_HTTP_REQ_RATE); if (!ptr) return 0; /* parameter not stored */ - temp_pattern.data.integer = read_freq_ctr_period(&stktable_data_cast(ptr, http_req_rate), + temp_pattern.data.uint = read_freq_ctr_period(&stktable_data_cast(ptr, http_req_rate), table->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u); } return 1; @@ -2919,12 +2919,12 @@ static int acl_fetch_http_err_cnt(struct stktable *table, struct acl_test *test, struct stksess *ts) { test->flags = ACL_TEST_F_VOL_TEST; - temp_pattern.data.integer = 0; + temp_pattern.data.uint = 0; if (ts != NULL) { void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_HTTP_ERR_CNT); if (!ptr) return 0; /* parameter not stored */ - temp_pattern.data.integer = stktable_data_cast(ptr, http_err_cnt); + temp_pattern.data.uint = stktable_data_cast(ptr, http_err_cnt); } return 1; } @@ -2974,12 +2974,12 @@ static int acl_fetch_http_err_rate(struct stktable *table, struct acl_test *test, struct stksess *ts) { test->flags = ACL_TEST_F_VOL_TEST; - temp_pattern.data.integer = 0; + temp_pattern.data.uint = 0; if (ts != NULL) { void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_HTTP_ERR_RATE); if (!ptr) return 0; /* parameter not stored */ - temp_pattern.data.integer = read_freq_ctr_period(&stktable_data_cast(ptr, http_err_rate), + temp_pattern.data.uint = read_freq_ctr_period(&stktable_data_cast(ptr, http_err_rate), table->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u); } return 1; @@ -3034,13 +3034,13 @@ static int acl_fetch_kbytes_in(struct stktable *table, struct acl_test *test, struct stksess *ts) { test->flags = ACL_TEST_F_VOL_TEST; - temp_pattern.data.integer = 0; + temp_pattern.data.uint = 0; if (ts != NULL) { void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_BYTES_IN_CNT); if (!ptr) return 0; /* parameter not stored */ - temp_pattern.data.integer = stktable_data_cast(ptr, bytes_in_cnt) >> 10; + temp_pattern.data.uint = stktable_data_cast(ptr, bytes_in_cnt) >> 10; } return 1; } @@ -3096,12 +3096,12 @@ static int acl_fetch_bytes_in_rate(struct stktable *table, struct acl_test *test, struct stksess *ts) { test->flags = ACL_TEST_F_VOL_TEST; - temp_pattern.data.integer = 0; + temp_pattern.data.uint = 0; if (ts != NULL) { void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_BYTES_IN_RATE); if (!ptr) return 0; /* parameter not stored */ - temp_pattern.data.integer = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_in_rate), + temp_pattern.data.uint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_in_rate), table->data_arg[STKTABLE_DT_BYTES_IN_RATE].u); } return 1; @@ -3156,13 +3156,13 @@ static int acl_fetch_kbytes_out(struct stktable *table, struct acl_test *test, struct stksess *ts) { test->flags = ACL_TEST_F_VOL_TEST; - temp_pattern.data.integer = 0; + temp_pattern.data.uint = 0; if (ts != NULL) { void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_BYTES_OUT_CNT); if (!ptr) return 0; /* parameter not stored */ - temp_pattern.data.integer = stktable_data_cast(ptr, bytes_out_cnt) >> 10; + temp_pattern.data.uint = stktable_data_cast(ptr, bytes_out_cnt) >> 10; } return 1; } @@ -3218,12 +3218,12 @@ static int acl_fetch_bytes_out_rate(struct stktable *table, struct acl_test *test, struct stksess *ts) { test->flags = ACL_TEST_F_VOL_TEST; - temp_pattern.data.integer = 0; + temp_pattern.data.uint = 0; if (ts != NULL) { void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_BYTES_OUT_RATE); if (!ptr) return 0; /* parameter not stored */ - temp_pattern.data.integer = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_out_rate), + temp_pattern.data.uint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_out_rate), table->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u); } return 1; @@ -3281,7 +3281,7 @@ acl_fetch_table_cnt(struct proxy *px, struct session *l4, void *l7, int dir, struct acl_expr *expr, struct acl_test *test) { test->flags = ACL_TEST_F_VOL_TEST; - temp_pattern.data.integer = expr->args->data.prx->table.current; + temp_pattern.data.uint = expr->args->data.prx->table.current; return 1; } @@ -3294,7 +3294,7 @@ acl_fetch_table_avl(struct proxy *px, struct session *l4, void *l7, int dir, { px = expr->args->data.prx; test->flags = ACL_TEST_F_VOL_TEST; - temp_pattern.data.integer = px->table.size - px->table.current; + temp_pattern.data.uint = px->table.size - px->table.current; return 1; } diff --git a/src/stick_table.c b/src/stick_table.c index 8fb10cfe23..433d7d3ec2 100644 --- a/src/stick_table.c +++ b/src/stick_table.c @@ -450,17 +450,17 @@ int stktable_parse_type(char **args, int *myidx, unsigned long *type, size_t *ke static void *k_int2int(union pattern_data *pdata, union stktable_key_data *kdata, size_t *len) { - return (void *)&pdata->integer; + return (void *)&pdata->uint; } static void *k_ip2ip(union pattern_data *pdata, union stktable_key_data *kdata, size_t *len) { - return (void *)&pdata->ip.s_addr; + return (void *)&pdata->ipv4.s_addr; } static void *k_ip2ipv6(union pattern_data *pdata, union stktable_key_data *kdata, size_t *len) { - v4tov6(&kdata->ipv6, &pdata->ip); + v4tov6(&kdata->ipv6, &pdata->ipv4); return (void *)&kdata->ipv6.s6_addr; } @@ -479,13 +479,13 @@ static void *k_ipv62ip(union pattern_data *pdata, union stktable_key_data *kdata static void *k_ip2int(union pattern_data *pdata, union stktable_key_data *kdata, size_t *len) { - kdata->integer = ntohl(pdata->ip.s_addr); + kdata->integer = ntohl(pdata->ipv4.s_addr); return (void *)&kdata->integer; } static void *k_int2ip(union pattern_data *pdata, union stktable_key_data *kdata, size_t *len) { - kdata->ip.s_addr = htonl(pdata->integer); + kdata->ip.s_addr = htonl(pdata->uint); return (void *)&kdata->ip.s_addr; } @@ -497,7 +497,7 @@ static void *k_str2str(union pattern_data *pdata, union stktable_key_data *kdata static void *k_ip2str(union pattern_data *pdata, union stktable_key_data *kdata, size_t *len) { - if (!inet_ntop(AF_INET, &pdata->ip, kdata->buf, sizeof(kdata->buf))) + if (!inet_ntop(AF_INET, &pdata->ipv4, kdata->buf, sizeof(kdata->buf))) return NULL; *len = strlen((const char *)kdata->buf); @@ -517,7 +517,7 @@ static void *k_int2str(union pattern_data *pdata, union stktable_key_data *kdata { void *key; - key = (void *)ultoa_r(pdata->integer, kdata->buf, sizeof(kdata->buf)); + key = (void *)ultoa_r(pdata->uint, kdata->buf, sizeof(kdata->buf)); if (!key) return NULL; @@ -570,16 +570,17 @@ static void *k_str2int(union pattern_data *pdata, union stktable_key_data *kdata */ typedef void *(*pattern_to_key_fct)(union pattern_data *pdata, union stktable_key_data *kdata, size_t *len); -static pattern_to_key_fct pattern_to_key[PATTERN_TYPES][STKTABLE_TYPES] = { +static pattern_to_key_fct pattern_to_key[SMP_TYPES][STKTABLE_TYPES] = { /* table type: IP IPV6 INTEGER STRING BINARY */ -/* pattern type: IP */ { k_ip2ip, k_ip2ipv6, k_ip2int, k_ip2str, NULL }, +/* patt. type: BOOL */ { NULL, NULL, k_int2int, k_int2str, NULL }, +/* UINT */ { k_int2ip, NULL, k_int2int, k_int2str, NULL }, +/* SINT */ { k_int2ip, NULL, k_int2int, k_int2str, NULL }, +/* IPV4 */ { k_ip2ip, k_ip2ipv6, k_ip2int, k_ip2str, NULL }, /* IPV6 */ { NULL, k_ipv62ipv6, NULL, k_ipv62str, NULL }, -/* INTEGER */ { k_int2ip, NULL, k_int2int, k_int2str, NULL }, -/* STRING */ { k_str2ip, k_str2ipv6, k_str2int, k_str2str, k_str2str }, -/* DATA */ { NULL, NULL, NULL, NULL, k_str2str }, -/* CONSTSTRING */ { k_str2ip, k_str2ipv6, k_str2int, k_str2str, k_str2str }, -/* CONSTDATA */ { NULL, NULL, NULL, NULL , k_str2str }, - +/* STR */ { k_str2ip, k_str2ipv6, k_str2int, k_str2str, k_str2str }, +/* BIN */ { NULL, NULL, NULL, NULL, k_str2str }, +/* CSTR */ { k_str2ip, k_str2ipv6, k_str2int, k_str2str, k_str2str }, +/* CBIN */ { NULL, NULL, NULL, NULL , k_str2str }, };