mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 07:37:02 +02:00
MEDIUM: pattern: replace type pattern_arg with type arg
arg is more complete than pattern_arg since it also covers ACL args, so let's use this one instead.
This commit is contained in:
parent
0146c2e873
commit
ecfb8e8ff9
@ -34,6 +34,6 @@ struct pattern *pattern_process(struct proxy *px, struct session *l4,
|
||||
void pattern_register_fetches(struct pattern_fetch_kw_list *psl);
|
||||
void pattern_register_convs(struct pattern_conv_kw_list *psl);
|
||||
|
||||
int pattern_arg_ipmask(const char *arg_str, struct pattern_arg **arg_p, int *arg_i);
|
||||
int pattern_arg_str(const char *arg_str, struct pattern_arg **arg_p, int *arg_i);
|
||||
int pattern_arg_ipmask(const char *arg_str, struct arg **arg_p, int *arg_i);
|
||||
int pattern_arg_str(const char *arg_str, struct arg **arg_p, int *arg_i);
|
||||
#endif
|
||||
|
@ -22,9 +22,10 @@
|
||||
#ifndef _TYPES_PATTERN_H
|
||||
#define _TYPES_PATTERN_H
|
||||
|
||||
#include <types/buffers.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <types/arg.h>
|
||||
#include <types/buffers.h>
|
||||
|
||||
/* pattern in and out types */
|
||||
enum {
|
||||
@ -39,33 +40,11 @@ enum {
|
||||
};
|
||||
|
||||
|
||||
/* pattern arg types */
|
||||
enum {
|
||||
PATTERN_ARG_TYPE_IP = 0, /* ipv4 type */
|
||||
PATTERN_ARG_TYPE_IPV6, /* ipv6 type */
|
||||
PATTERN_ARG_TYPE_INTEGER, /* unsigned 32bits integer type */
|
||||
PATTERN_ARG_TYPE_SINTEGER, /* signed 32bits integer type */
|
||||
PATTERN_ARG_TYPE_STRING /* string type */
|
||||
};
|
||||
|
||||
/* pattern fetch direction */
|
||||
#define PATTERN_FETCH_REQ 1
|
||||
#define PATTERN_FETCH_RTR 2
|
||||
|
||||
|
||||
union pattern_arg_data {
|
||||
struct in_addr ip; /* used for ipv4 type */
|
||||
struct in6_addr ipv6; /* used for ipv6 type */
|
||||
uint32_t integer; /* used for unsigned 32bits integer type */
|
||||
int sinteger; /* used for signed 32bits integer type */
|
||||
struct chunk str;
|
||||
};
|
||||
|
||||
struct pattern_arg {
|
||||
int type; /* type of arg */
|
||||
union pattern_arg_data data; /* data */
|
||||
};
|
||||
|
||||
/* pattern result data */
|
||||
union pattern_data {
|
||||
struct in_addr ip; /* used for ipv4 type */
|
||||
@ -83,11 +62,11 @@ struct pattern {
|
||||
/* pattern conversion */
|
||||
struct pattern_conv {
|
||||
const char *kw; /* configuration keyword */
|
||||
int (*process)(const struct pattern_arg *arg_p,
|
||||
int (*process)(const struct arg *arg_p,
|
||||
int arg_i,
|
||||
union pattern_data *data); /* process function */
|
||||
int (*parse_args)(const char *arg_str,
|
||||
struct pattern_arg **arg_p,
|
||||
struct arg **arg_p,
|
||||
int *arg_i); /* argument parser. Can be NULL. */
|
||||
unsigned int in_type; /* input needed pattern type */
|
||||
unsigned int out_type; /* output pattern type */
|
||||
@ -97,7 +76,7 @@ struct pattern_conv {
|
||||
struct pattern_conv_expr {
|
||||
struct list list; /* member of a pattern expression */
|
||||
struct pattern_conv *conv; /* pattern conversion */
|
||||
struct pattern_arg *arg_p; /* pointer on args */
|
||||
struct arg *arg_p; /* pointer on args */
|
||||
int arg_i; /* number of args */
|
||||
};
|
||||
|
||||
@ -107,11 +86,11 @@ struct pattern_fetch {
|
||||
int (*process)(struct proxy *px,
|
||||
struct session *l4,
|
||||
void *l7,
|
||||
int dir, const struct pattern_arg *arg_p,
|
||||
int dir, const struct arg *arg_p,
|
||||
int arg_i,
|
||||
union pattern_data *data); /* fetch processing function */
|
||||
int (*parse_args)(const char *arg_str,
|
||||
struct pattern_arg **arg_p,
|
||||
struct arg **arg_p,
|
||||
int *arg_i); /* argument parser. Can be NULL. */
|
||||
unsigned long out_type; /* output pattern type */
|
||||
int dir; /* usable directions */
|
||||
@ -121,7 +100,7 @@ struct pattern_fetch {
|
||||
struct pattern_expr {
|
||||
struct list list; /* member of list of pattern, currently not used */
|
||||
struct pattern_fetch *fetch; /* pattern fetch */
|
||||
struct pattern_arg *arg_p; /* pointer on args */
|
||||
struct arg *arg_p; /* pointer on args */
|
||||
int arg_i; /* number of args */
|
||||
struct list conv_exprs; /* list of conversion expression to apply */
|
||||
};
|
||||
|
@ -758,14 +758,19 @@ static void deinit_tcp_rules(struct list *rules)
|
||||
}
|
||||
}
|
||||
|
||||
static void deinit_pattern_arg(struct pattern_arg *p, int i)
|
||||
static void deinit_pattern_arg(struct arg *p, int i)
|
||||
{
|
||||
if (!p)
|
||||
return;
|
||||
|
||||
while (i--)
|
||||
if (p[i].type == PATTERN_ARG_TYPE_STRING)
|
||||
while (i--) {
|
||||
if (p[i].type == ARGT_FE || p[i].type == ARGT_BE ||
|
||||
p[i].type == ARGT_TAB || p[i].type == ARGT_SRV ||
|
||||
p[i].type == ARGT_USR || p[i].type == ARGT_STR) {
|
||||
free(p[i].data.str.str);
|
||||
p[i].data.str.str = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
free(p);
|
||||
}
|
||||
|
@ -476,30 +476,30 @@ struct pattern *pattern_process(struct proxy *px, struct session *l4, void *l7,
|
||||
return p;
|
||||
}
|
||||
|
||||
/* Converts an argument string mask to a pattern_arg type IP.
|
||||
/* Converts an argument string mask to a arg type IP.
|
||||
* Returns non-zero in case of success, 0 on error.
|
||||
*/
|
||||
int pattern_arg_ipmask(const char *arg_str, struct pattern_arg **arg_p, int *arg_i)
|
||||
int pattern_arg_ipmask(const char *arg_str, struct arg **arg_p, int *arg_i)
|
||||
{
|
||||
*arg_i = 1;
|
||||
*arg_p = calloc(1, *arg_i*sizeof(struct pattern_arg));
|
||||
(*arg_p)->type = PATTERN_ARG_TYPE_IP;
|
||||
*arg_p = calloc(1, *arg_i*sizeof(struct arg));
|
||||
(*arg_p)->type = ARGT_IPV4;
|
||||
|
||||
if (!str2mask(arg_str, &(*arg_p)->data.ip))
|
||||
if (!str2mask(arg_str, &(*arg_p)->data.ipv4))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Converts an argument string to a pattern_arg type STRING.
|
||||
/* Converts an argument string to a arg type STRING.
|
||||
* Returns non-zero in case of success, 0 on error.
|
||||
*/
|
||||
int pattern_arg_str(const char *arg_str, struct pattern_arg **arg_p, int *arg_i)
|
||||
int pattern_arg_str(const char *arg_str, struct arg **arg_p, int *arg_i)
|
||||
{
|
||||
*arg_i = 1;
|
||||
*arg_p = calloc(1, *arg_i*sizeof(struct pattern_arg));
|
||||
(*arg_p)->type = PATTERN_ARG_TYPE_STRING;
|
||||
*arg_p = calloc(1, *arg_i*sizeof(struct arg));
|
||||
(*arg_p)->type = ARGT_STR;
|
||||
(*arg_p)->data.str.str = strdup(arg_str);
|
||||
(*arg_p)->data.str.len = strlen(arg_str);
|
||||
|
||||
@ -512,7 +512,7 @@ int pattern_arg_str(const char *arg_str, struct pattern_arg **arg_p, int *arg_i)
|
||||
/* Pattern format convert functions */
|
||||
/*****************************************************************/
|
||||
|
||||
static int pattern_conv_str2lower(const struct pattern_arg *arg_p, int arg_i, union pattern_data *data)
|
||||
static int pattern_conv_str2lower(const struct arg *arg_p, int arg_i, union pattern_data *data)
|
||||
{
|
||||
int i;
|
||||
|
||||
@ -526,7 +526,7 @@ static int pattern_conv_str2lower(const struct pattern_arg *arg_p, int arg_i, un
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int pattern_conv_str2upper(const struct pattern_arg *arg_p, int arg_i, union pattern_data *data)
|
||||
static int pattern_conv_str2upper(const struct arg *arg_p, int arg_i, union pattern_data *data)
|
||||
{
|
||||
int i;
|
||||
|
||||
@ -541,9 +541,9 @@ static int pattern_conv_str2upper(const struct pattern_arg *arg_p, int arg_i, un
|
||||
}
|
||||
|
||||
/* takes the netmask in arg_i */
|
||||
static int pattern_conv_ipmask(const struct pattern_arg *arg_p, int arg_i, union pattern_data *data)
|
||||
static int pattern_conv_ipmask(const struct arg *arg_p, int arg_i, union pattern_data *data)
|
||||
{
|
||||
data->ip.s_addr &= arg_p->data.ip.s_addr;
|
||||
data->ip.s_addr &= arg_p->data.ipv4.s_addr;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -8344,7 +8344,7 @@ static struct acl_kw_list acl_kws = {{ },{
|
||||
/* Returns the last occurrence of specified header. */
|
||||
static int
|
||||
pattern_fetch_hdr(struct proxy *px, struct session *l4, void *l7, int dir,
|
||||
const struct pattern_arg *arg_p, int arg_i, union pattern_data *data)
|
||||
const struct arg *arg_p, int arg_i, union pattern_data *data)
|
||||
{
|
||||
struct http_txn *txn = l7;
|
||||
|
||||
@ -8439,7 +8439,7 @@ find_url_param_value(char* path, size_t path_l,
|
||||
|
||||
static int
|
||||
pattern_fetch_url_param(struct proxy *px, struct session *l4, void *l7, int dir,
|
||||
const struct pattern_arg *arg_p, int arg_i, union pattern_data *data)
|
||||
const struct arg *arg_p, int arg_i, union pattern_data *data)
|
||||
{
|
||||
struct http_txn *txn = l7;
|
||||
struct http_msg *msg = &txn->req;
|
||||
@ -8492,7 +8492,7 @@ find_cookie_value(struct http_msg *msg, struct http_txn *txn,
|
||||
|
||||
static int
|
||||
pattern_fetch_cookie(struct proxy *px, struct session *l4, void *l7, int dir,
|
||||
const struct pattern_arg *arg_p, int arg_i, union pattern_data *data)
|
||||
const struct arg *arg_p, int arg_i, union pattern_data *data)
|
||||
{
|
||||
struct http_txn *txn = l7;
|
||||
struct http_msg *msg = &txn->req;
|
||||
@ -8514,7 +8514,7 @@ pattern_fetch_cookie(struct proxy *px, struct session *l4, void *l7, int dir,
|
||||
|
||||
static int
|
||||
pattern_fetch_set_cookie(struct proxy *px, struct session *l4, void *l7, int dir,
|
||||
const struct pattern_arg *arg_p, int arg_i, union pattern_data *data)
|
||||
const struct arg *arg_p, int arg_i, union pattern_data *data)
|
||||
{
|
||||
struct http_txn *txn = l7;
|
||||
struct http_msg *msg = &txn->rsp;
|
||||
|
@ -1275,7 +1275,7 @@ acl_fetch_src(struct proxy *px, struct session *l4, void *l7, int dir,
|
||||
/* extract the connection's source ipv4 address */
|
||||
static int
|
||||
pattern_fetch_src(struct proxy *px, struct session *l4, void *l7, int dir,
|
||||
const struct pattern_arg *arg_p, int arg_i, union pattern_data *data)
|
||||
const struct arg *arg_p, int arg_i, union pattern_data *data)
|
||||
{
|
||||
if (l4->si[0].addr.from.ss_family != AF_INET )
|
||||
return 0;
|
||||
@ -1287,7 +1287,7 @@ pattern_fetch_src(struct proxy *px, struct session *l4, void *l7, int dir,
|
||||
/* extract the connection's source ipv6 address */
|
||||
static int
|
||||
pattern_fetch_src6(struct proxy *px, struct session *l4, void *l7, int dir,
|
||||
const struct pattern_arg *arg_p, int arg_i, union pattern_data *data)
|
||||
const struct arg *arg_p, int arg_i, union pattern_data *data)
|
||||
{
|
||||
if (l4->si[0].addr.from.ss_family != AF_INET6)
|
||||
return 0;
|
||||
@ -1337,7 +1337,7 @@ acl_fetch_dst(struct proxy *px, struct session *l4, void *l7, int dir,
|
||||
/* extract the connection's destination ipv4 address */
|
||||
static int
|
||||
pattern_fetch_dst(struct proxy *px, struct session *l4, void *l7, int dir,
|
||||
const struct pattern_arg *arg_p, int arg_i, union pattern_data *data)
|
||||
const struct arg *arg_p, int arg_i, union pattern_data *data)
|
||||
{
|
||||
stream_sock_get_to_addr(&l4->si[0]);
|
||||
|
||||
@ -1351,7 +1351,7 @@ pattern_fetch_dst(struct proxy *px, struct session *l4, void *l7, int dir,
|
||||
/* extract the connection's destination ipv6 address */
|
||||
static int
|
||||
pattern_fetch_dst6(struct proxy *px, struct session *l4, void *l7, int dir,
|
||||
const struct pattern_arg *arg_p, int arg_i, union pattern_data *data)
|
||||
const struct arg *arg_p, int arg_i, union pattern_data *data)
|
||||
{
|
||||
stream_sock_get_to_addr(&l4->si[0]);
|
||||
|
||||
@ -1378,7 +1378,7 @@ acl_fetch_dport(struct proxy *px, struct session *l4, void *l7, int dir,
|
||||
|
||||
static int
|
||||
pattern_fetch_dport(struct proxy *px, struct session *l4, void *l7, int dir,
|
||||
const struct pattern_arg *arg, int i, union pattern_data *data)
|
||||
const struct arg *arg, int i, union pattern_data *data)
|
||||
{
|
||||
stream_sock_get_to_addr(&l4->si[0]);
|
||||
|
||||
@ -1389,7 +1389,7 @@ pattern_fetch_dport(struct proxy *px, struct session *l4, void *l7, int dir,
|
||||
}
|
||||
|
||||
static int
|
||||
pattern_arg_fetch_payloadlv(const char *arg, struct pattern_arg **arg_p, int *arg_i)
|
||||
pattern_arg_fetch_payloadlv(const char *arg, struct arg **arg_p, int *arg_i)
|
||||
{
|
||||
int member = 0;
|
||||
int len_offset = 0;
|
||||
@ -1446,24 +1446,24 @@ pattern_arg_fetch_payloadlv(const char *arg, struct pattern_arg **arg_p, int *ar
|
||||
}
|
||||
|
||||
*arg_i = 3;
|
||||
*arg_p = calloc(1, *arg_i*sizeof(struct pattern_arg));
|
||||
(*arg_p)[0].type = PATTERN_ARG_TYPE_INTEGER;
|
||||
(*arg_p)[0].data.integer = len_offset;
|
||||
(*arg_p)[1].type = PATTERN_ARG_TYPE_INTEGER;
|
||||
(*arg_p)[1].data.integer = len_size;
|
||||
(*arg_p)[2].type = PATTERN_ARG_TYPE_INTEGER;
|
||||
(*arg_p)[2].data.integer = buf_offset;
|
||||
*arg_p = calloc(1, *arg_i*sizeof(struct arg));
|
||||
(*arg_p)[0].type = ARGT_UINT;
|
||||
(*arg_p)[0].data.uint = len_offset;
|
||||
(*arg_p)[1].type = ARGT_UINT;
|
||||
(*arg_p)[1].data.uint = len_size;
|
||||
(*arg_p)[2].type = ARGT_UINT;
|
||||
(*arg_p)[2].data.uint = buf_offset;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
pattern_fetch_payloadlv(struct proxy *px, struct session *l4, void *l7, int dir,
|
||||
const struct pattern_arg *arg_p, int arg_i, union pattern_data *data)
|
||||
const struct arg *arg_p, int arg_i, union pattern_data *data)
|
||||
{
|
||||
int len_offset = arg_p[0].data.integer;
|
||||
int len_size = arg_p[1].data.integer;
|
||||
int buf_offset = arg_p[2].data.integer;
|
||||
int len_offset = arg_p[0].data.uint;
|
||||
int len_size = arg_p[1].data.uint;
|
||||
int buf_offset = arg_p[2].data.uint;
|
||||
int buf_size = 0;
|
||||
struct buffer *b;
|
||||
int i;
|
||||
@ -1500,7 +1500,7 @@ pattern_fetch_payloadlv(struct proxy *px, struct session *l4, void *l7, int dir,
|
||||
}
|
||||
|
||||
static int
|
||||
pattern_arg_fetch_payload (const char *arg, struct pattern_arg **arg_p, int *arg_i)
|
||||
pattern_arg_fetch_payload (const char *arg, struct arg **arg_p, int *arg_i)
|
||||
{
|
||||
int member = 0;
|
||||
int buf_offset = 0;
|
||||
@ -1528,21 +1528,21 @@ pattern_arg_fetch_payload (const char *arg, struct pattern_arg **arg_p, int *arg
|
||||
return 0;
|
||||
|
||||
*arg_i = 2;
|
||||
*arg_p = calloc(1, *arg_i*sizeof(struct pattern_arg));
|
||||
(*arg_p)[0].type = PATTERN_ARG_TYPE_INTEGER;
|
||||
(*arg_p)[0].data.integer = buf_offset;
|
||||
(*arg_p)[1].type = PATTERN_ARG_TYPE_INTEGER;
|
||||
(*arg_p)[1].data.integer = buf_size;
|
||||
*arg_p = calloc(1, *arg_i*sizeof(struct arg));
|
||||
(*arg_p)[0].type = ARGT_UINT;
|
||||
(*arg_p)[0].data.uint = buf_offset;
|
||||
(*arg_p)[1].type = ARGT_UINT;
|
||||
(*arg_p)[1].data.uint = buf_size;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
pattern_fetch_payload(struct proxy *px, struct session *l4, void *l7, int dir,
|
||||
const struct pattern_arg *arg_p, int arg_i, union pattern_data *data)
|
||||
const struct arg *arg_p, int arg_i, union pattern_data *data)
|
||||
{
|
||||
int buf_offset = arg_p[0].data.integer;
|
||||
int buf_size = arg_p[1].data.integer;
|
||||
int buf_offset = arg_p[0].data.uint;
|
||||
int buf_size = arg_p[1].data.uint;
|
||||
struct buffer *b;
|
||||
|
||||
if (!l4)
|
||||
@ -1564,7 +1564,7 @@ pattern_fetch_payload(struct proxy *px, struct session *l4, void *l7, int dir,
|
||||
|
||||
static int
|
||||
pattern_fetch_rdp_cookie(struct proxy *px, struct session *l4, void *l7, int dir,
|
||||
const struct pattern_arg *arg_p, int arg_i, union pattern_data *data)
|
||||
const struct arg *arg_p, int arg_i, union pattern_data *data)
|
||||
{
|
||||
int ret;
|
||||
struct acl_expr expr;
|
||||
|
Loading…
Reference in New Issue
Block a user