MINOR: filters: Extract proxy stuff from the struct filter

Now, filter's configuration (.id, .conf and .ops fields) is stored in the
structure 'flt_conf'. So proxies own a flt_conf list instead of a filter
list. When a filter is attached to a stream, it gets a pointer on its
configuration. This avoids mixing the filter's context (owns by a stream) and
its configuration (owns by a proxy). It also saves 2 pointers per filter
instance.
This commit is contained in:
Christopher Faulet 2016-02-04 13:40:26 +01:00 committed by Willy Tarreau
parent e6c3b69be0
commit 443ea1a242
8 changed files with 124 additions and 118 deletions

View File

@ -29,6 +29,10 @@
#include <proto/channel.h> #include <proto/channel.h>
#define FLT_ID(flt) (flt)->config->id
#define FLT_CONF(flt) (flt)->config->conf
#define FLT_OPS(flt) (flt)->config->ops
/* Useful macros to access per-channel values. It can be safely used inside /* Useful macros to access per-channel values. It can be safely used inside
* filters. */ * filters. */
#define CHN_IDX(chn) (((chn)->flags & CF_ISRESP) == CF_ISRESP) #define CHN_IDX(chn) (((chn)->flags & CF_ISRESP) == CF_ISRESP)

View File

@ -28,6 +28,7 @@ struct http_msg;
struct proxy; struct proxy;
struct stream; struct stream;
struct channel; struct channel;
struct flt_conf;
struct filter; struct filter;
/* Descriptor for a "filter" keyword. The ->parse() function returns 0 in case /* Descriptor for a "filter" keyword. The ->parse() function returns 0 in case
@ -40,7 +41,7 @@ struct filter;
struct flt_kw { struct flt_kw {
const char *kw; const char *kw;
int (*parse)(char **args, int *cur_arg, struct proxy *px, int (*parse)(char **args, int *cur_arg, struct proxy *px,
struct filter *filter, char **err); struct flt_conf *fconf, char **err);
}; };
/* /*
@ -123,9 +124,9 @@ struct flt_ops {
/* /*
* Callbacks to manage the filter lifecycle * Callbacks to manage the filter lifecycle
*/ */
int (*init) (struct proxy *p, struct filter *f); int (*init) (struct proxy *p, struct flt_conf *fconf);
void (*deinit)(struct proxy *p, struct filter *f); void (*deinit)(struct proxy *p, struct flt_conf *fconf);
int (*check) (struct proxy *p, struct filter *f); int (*check) (struct proxy *p, struct flt_conf *fconf);
/* /*
* Stream callbacks * Stream callbacks
@ -171,9 +172,18 @@ struct flt_ops {
#define STRM_FLT_FL_HAS_FILTERS 0x0001 /* The stream has at least one filter */ #define STRM_FLT_FL_HAS_FILTERS 0x0001 /* The stream has at least one filter */
/* /*
* Structure representing the state of a filter. When attached to a proxy, only * Structure representing the filter configuration, attached to a proxy and
* <ops> and <conf> field (and optionnaly <id>) are set. All other fields are * accessible from a filter when instantiated in a stream
* used when the filter is attached to a stream. */
struct flt_conf {
const char *id; /* The filter id */
struct flt_ops *ops; /* The filter callbacks */
void *conf; /* The filter configuration */
struct list list; /* Next filter for the same proxy */
};
/*
* Structure reprensenting a filter instance attached to a stream
* *
* 2D-Array fields are used to store info per channel. The first index stands * 2D-Array fields are used to store info per channel. The first index stands
* for the request channel, and the second one for the response channel. * for the request channel, and the second one for the response channel.
@ -182,9 +192,7 @@ struct flt_ops {
* access these values using FLT_NXT and FLT_FWD macros. * access these values using FLT_NXT and FLT_FWD macros.
*/ */
struct filter { struct filter {
const char *id; /* The filter id */ struct flt_conf *config; /* the filter's configuration */
struct flt_ops *ops; /* The filter callbacks */
void *conf; /* The filter configuration */
void *ctx; /* The filter context (opaque) */ void *ctx; /* The filter context (opaque) */
unsigned short flags; /* FLT_FL_* */ unsigned short flags; /* FLT_FL_* */
unsigned int next[2]; /* Offset, relative to buf->p, to the next byte to parse for a specific channel unsigned int next[2]; /* Offset, relative to buf->p, to the next byte to parse for a specific channel

View File

@ -432,8 +432,7 @@ struct proxy {
* this backend. If not specified or void, then the backend * this backend. If not specified or void, then the backend
* name is used * name is used
*/ */
struct list filter_configs; /* list of the filters that are declared on this proxy */
struct list filters;
}; };
struct switching_rule { struct switching_rule {

View File

@ -8435,7 +8435,7 @@ out_uri_auth_compat:
curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES;
/* Add filters analyzers if needed */ /* Add filters analyzers if needed */
if (!LIST_ISEMPTY(&curproxy->filters)) { if (!LIST_ISEMPTY(&curproxy->filter_configs)) {
curproxy->fe_req_ana |= AN_FLT_ALL_FE; curproxy->fe_req_ana |= AN_FLT_ALL_FE;
curproxy->fe_rsp_ana |= AN_FLT_ALL_FE; curproxy->fe_rsp_ana |= AN_FLT_ALL_FE;
if (curproxy->mode == PR_MODE_HTTP) { if (curproxy->mode == PR_MODE_HTTP) {
@ -8465,7 +8465,7 @@ out_uri_auth_compat:
curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE;
/* Add filters analyzers if needed */ /* Add filters analyzers if needed */
if (!LIST_ISEMPTY(&curproxy->filters)) { if (!LIST_ISEMPTY(&curproxy->filter_configs)) {
curproxy->be_req_ana |= AN_FLT_ALL_BE; curproxy->be_req_ana |= AN_FLT_ALL_BE;
curproxy->be_rsp_ana |= AN_FLT_ALL_BE; curproxy->be_rsp_ana |= AN_FLT_ALL_BE;
if (curproxy->mode == PR_MODE_HTTP) { if (curproxy->mode == PR_MODE_HTTP) {

View File

@ -158,7 +158,7 @@ static int
parse_filter(char **args, int section_type, struct proxy *curpx, parse_filter(char **args, int section_type, struct proxy *curpx,
struct proxy *defpx, const char *file, int line, char **err) struct proxy *defpx, const char *file, int line, char **err)
{ {
struct filter *filter = NULL; struct flt_conf *fconf = NULL;
/* Filter cannot be defined on a default proxy */ /* Filter cannot be defined on a default proxy */
if (curpx == defpx) { if (curpx == defpx) {
@ -176,12 +176,11 @@ parse_filter(char **args, int section_type, struct proxy *curpx,
file, line, args[0], proxy_type_str(curpx), curpx->id); file, line, args[0], proxy_type_str(curpx), curpx->id);
goto error; goto error;
} }
filter = pool_alloc2(pool2_filter); fconf = calloc(1, sizeof(*fconf));
if (!filter) { if (!fconf) {
memprintf(err, "'%s' : out of memory", args[0]); memprintf(err, "'%s' : out of memory", args[0]);
goto error; goto error;
} }
memset(filter, 0, sizeof(*filter));
cur_arg = 1; cur_arg = 1;
kw = flt_find_kw(args[cur_arg]); kw = flt_find_kw(args[cur_arg]);
@ -192,7 +191,7 @@ parse_filter(char **args, int section_type, struct proxy *curpx,
file, line, args[0], args[cur_arg]); file, line, args[0], args[cur_arg]);
goto error; goto error;
} }
if (kw->parse(args, &cur_arg, curpx, filter, err) != 0) { if (kw->parse(args, &cur_arg, curpx, fconf, err) != 0) {
if (err && *err) if (err && *err)
memprintf(err, "'%s' : '%s'", memprintf(err, "'%s' : '%s'",
args[0], *err); args[0], *err);
@ -216,13 +215,12 @@ parse_filter(char **args, int section_type, struct proxy *curpx,
goto error; goto error;
} }
LIST_ADDQ(&curpx->filters, &filter->list); LIST_ADDQ(&curpx->filter_configs, &fconf->list);
} }
return 0; return 0;
error: error:
if (filter) free(fconf);
pool_free2(pool2_filter, filter);
return -1; return -1;
@ -236,10 +234,10 @@ parse_filter(char **args, int section_type, struct proxy *curpx,
int int
flt_init(struct proxy *proxy) flt_init(struct proxy *proxy)
{ {
struct filter *filter; struct flt_conf *fconf;
list_for_each_entry(filter, &proxy->filters, list) { list_for_each_entry(fconf, &proxy->filter_configs, list) {
if (filter->ops->init && filter->ops->init(proxy, filter) < 0) if (fconf->ops->init && fconf->ops->init(proxy, fconf) < 0)
return ERR_ALERT|ERR_FATAL; return ERR_ALERT|ERR_FATAL;
} }
return 0; return 0;
@ -253,12 +251,12 @@ flt_init(struct proxy *proxy)
int int
flt_check(struct proxy *proxy) flt_check(struct proxy *proxy)
{ {
struct filter *filter; struct flt_conf *fconf;
int err = 0; int err = 0;
list_for_each_entry(filter, &proxy->filters, list) { list_for_each_entry(fconf, &proxy->filter_configs, list) {
if (filter->ops->check) if (fconf->ops->check)
err += filter->ops->check(proxy, filter); err += fconf->ops->check(proxy, fconf);
} }
err += check_legacy_http_comp_flt(proxy); err += check_legacy_http_comp_flt(proxy);
return err; return err;
@ -271,27 +269,25 @@ flt_check(struct proxy *proxy)
void void
flt_deinit(struct proxy *proxy) flt_deinit(struct proxy *proxy)
{ {
struct filter *filter, *back; struct flt_conf *fconf, *back;
list_for_each_entry_safe(filter, back, &proxy->filters, list) { list_for_each_entry_safe(fconf, back, &proxy->filter_configs, list) {
if (filter->ops->deinit) if (fconf->ops->deinit)
filter->ops->deinit(proxy, filter); fconf->ops->deinit(proxy, fconf);
LIST_DEL(&filter->list); LIST_DEL(&fconf->list);
pool_free2(pool2_filter, filter); free(fconf);
} }
} }
/* Attaches a filter to a stream. Returns -1 if an error occurs, 0 otherwise. */ /* Attaches a filter to a stream. Returns -1 if an error occurs, 0 otherwise. */
static int static int
flt_stream_add_filter(struct stream *s, struct filter *filter, unsigned int flags) flt_stream_add_filter(struct stream *s, struct flt_conf *fconf, unsigned int flags)
{ {
struct filter *f = pool_alloc2(pool2_filter); struct filter *f = pool_alloc2(pool2_filter);
if (!f) /* not enough memory */ if (!f) /* not enough memory */
return -1; return -1;
memset(f, 0, sizeof(*f)); memset(f, 0, sizeof(*f));
f->id = filter->id; f->config = fconf;
f->ops = filter->ops;
f->conf = filter->conf;
f->flags |= flags; f->flags |= flags;
LIST_ADDQ(&strm_flt(s)->filters, &f->list); LIST_ADDQ(&strm_flt(s)->filters, &f->list);
strm_flt(s)->flags |= STRM_FLT_FL_HAS_FILTERS; strm_flt(s)->flags |= STRM_FLT_FL_HAS_FILTERS;
@ -305,12 +301,12 @@ flt_stream_add_filter(struct stream *s, struct filter *filter, unsigned int flag
int int
flt_stream_init(struct stream *s) flt_stream_init(struct stream *s)
{ {
struct filter *filter; struct flt_conf *fconf;
memset(strm_flt(s), 0, sizeof(*strm_flt(s))); memset(strm_flt(s), 0, sizeof(*strm_flt(s)));
LIST_INIT(&strm_flt(s)->filters); LIST_INIT(&strm_flt(s)->filters);
list_for_each_entry(filter, &strm_fe(s)->filters, list) { list_for_each_entry(fconf, &strm_fe(s)->filter_configs, list) {
if (flt_stream_add_filter(s, filter, 0) < 0) if (flt_stream_add_filter(s, fconf, 0) < 0)
return -1; return -1;
} }
return 0; return 0;
@ -348,7 +344,7 @@ flt_stream_start(struct stream *s)
struct filter *filter; struct filter *filter;
list_for_each_entry(filter, &strm_flt(s)->filters, list) { list_for_each_entry(filter, &strm_flt(s)->filters, list) {
if (filter->ops->stream_start && filter->ops->stream_start(s, filter) < 0) if (FLT_OPS(filter)->stream_start && FLT_OPS(filter)->stream_start(s, filter) < 0)
return -1; return -1;
} }
return 0; return 0;
@ -364,8 +360,8 @@ flt_stream_stop(struct stream *s)
struct filter *filter; struct filter *filter;
list_for_each_entry(filter, &strm_flt(s)->filters, list) { list_for_each_entry(filter, &strm_flt(s)->filters, list) {
if (filter->ops->stream_stop) if (FLT_OPS(filter)->stream_stop)
filter->ops->stream_stop(s, filter); FLT_OPS(filter)->stream_stop(s, filter);
} }
} }
@ -377,13 +373,13 @@ flt_stream_stop(struct stream *s)
int int
flt_set_stream_backend(struct stream *s, struct proxy *be) flt_set_stream_backend(struct stream *s, struct proxy *be)
{ {
struct filter *filter; struct flt_conf *fconf;
if (strm_fe(s) == be) if (strm_fe(s) == be)
return 0; return 0;
list_for_each_entry(filter, &be->filters, list) { list_for_each_entry(fconf, &be->filter_configs, list) {
if (flt_stream_add_filter(s, filter, FLT_FL_IS_BACKEND_FILTER) < 0) if (flt_stream_add_filter(s, fconf, FLT_FL_IS_BACKEND_FILTER) < 0)
return -1; return -1;
} }
return 0; return 0;
@ -423,8 +419,8 @@ flt_http_data(struct stream *s, struct http_msg *msg)
if (msg->next > *nxt) if (msg->next > *nxt)
*nxt = msg->next; *nxt = msg->next;
if (filter->ops->http_data) { if (FLT_OPS(filter)->http_data) {
ret = filter->ops->http_data(s, filter, msg); ret = FLT_OPS(filter)->http_data(s, filter, msg);
if (ret < 0) if (ret < 0)
break; break;
@ -477,8 +473,8 @@ flt_http_chunk_trailers(struct stream *s, struct http_msg *msg)
nxt = &FLT_NXT(filter, msg->chn); nxt = &FLT_NXT(filter, msg->chn);
*nxt = msg->next; *nxt = msg->next;
if (filter->ops->http_chunk_trailers) { if (FLT_OPS(filter)->http_chunk_trailers) {
ret = filter->ops->http_chunk_trailers(s, filter, msg); ret = FLT_OPS(filter)->http_chunk_trailers(s, filter, msg);
if (ret < 0) if (ret < 0)
break; break;
} }
@ -502,8 +498,8 @@ flt_http_end(struct stream *s, struct http_msg *msg)
int ret = 1; int ret = 1;
RESUME_FILTER_LOOP(s, msg->chn) { RESUME_FILTER_LOOP(s, msg->chn) {
if (filter->ops->http_end) { if (FLT_OPS(filter)->http_end) {
ret = filter->ops->http_end(s, filter, msg); ret = FLT_OPS(filter)->http_end(s, filter, msg);
if (ret <= 0) if (ret <= 0)
BREAK_EXECUTION(s, msg->chn, end); BREAK_EXECUTION(s, msg->chn, end);
} }
@ -522,8 +518,8 @@ flt_http_reset(struct stream *s, struct http_msg *msg)
struct filter *filter; struct filter *filter;
list_for_each_entry(filter, &strm_flt(s)->filters, list) { list_for_each_entry(filter, &strm_flt(s)->filters, list) {
if (filter->ops->http_reset) if (FLT_OPS(filter)->http_reset)
filter->ops->http_reset(s, filter, msg); FLT_OPS(filter)->http_reset(s, filter, msg);
} }
} }
@ -537,8 +533,8 @@ flt_http_reply(struct stream *s, short status, const struct chunk *msg)
struct filter *filter; struct filter *filter;
list_for_each_entry(filter, &strm_flt(s)->filters, list) { list_for_each_entry(filter, &strm_flt(s)->filters, list) {
if (filter->ops->http_reply) if (FLT_OPS(filter)->http_reply)
filter->ops->http_reply(s, filter, status, msg); FLT_OPS(filter)->http_reply(s, filter, status, msg);
} }
} }
@ -572,10 +568,10 @@ flt_http_forward_data(struct stream *s, struct http_msg *msg, unsigned int len)
if (msg->next > *nxt) if (msg->next > *nxt)
*nxt = msg->next; *nxt = msg->next;
if (filter->ops->http_forward_data) { if (FLT_OPS(filter)->http_forward_data) {
/* Remove bytes that the current filter considered as /* Remove bytes that the current filter considered as
* forwarded */ * forwarded */
ret = filter->ops->http_forward_data(s, filter, msg, ret - *fwd); ret = FLT_OPS(filter)->http_forward_data(s, filter, msg, ret - *fwd);
if (ret < 0) if (ret < 0)
goto end; goto end;
} }
@ -628,8 +624,8 @@ flt_start_analyze(struct stream *s, struct channel *chn, unsigned int an_bit)
FLT_NXT(filter, chn) = 0; FLT_NXT(filter, chn) = 0;
FLT_FWD(filter, chn) = 0; FLT_FWD(filter, chn) = 0;
if (filter->ops->channel_start_analyze) { if (FLT_OPS(filter)->channel_start_analyze) {
ret = filter->ops->channel_start_analyze(s, filter, chn); ret = FLT_OPS(filter)->channel_start_analyze(s, filter, chn);
if (ret <= 0) if (ret <= 0)
BREAK_EXECUTION(s, chn, end); BREAK_EXECUTION(s, chn, end);
} }
@ -652,8 +648,8 @@ flt_analyze(struct stream *s, struct channel *chn, unsigned int an_bit)
int ret = 1; int ret = 1;
RESUME_FILTER_LOOP(s, chn) { RESUME_FILTER_LOOP(s, chn) {
if (filter->ops->channel_analyze) { if (FLT_OPS(filter)->channel_analyze) {
ret = filter->ops->channel_analyze(s, filter, chn, an_bit); ret = FLT_OPS(filter)->channel_analyze(s, filter, chn, an_bit);
if (ret <= 0) if (ret <= 0)
BREAK_EXECUTION(s, chn, check_result); BREAK_EXECUTION(s, chn, check_result);
} }
@ -676,8 +672,8 @@ flt_analyze_http_headers(struct stream *s, struct channel *chn, unsigned int an_
int ret = 1; int ret = 1;
RESUME_FILTER_LOOP(s, chn) { RESUME_FILTER_LOOP(s, chn) {
if (filter->ops->channel_analyze) { if (FLT_OPS(filter)->channel_analyze) {
ret = filter->ops->channel_analyze(s, filter, chn, an_bit); ret = FLT_OPS(filter)->channel_analyze(s, filter, chn, an_bit);
if (ret <= 0) if (ret <= 0)
BREAK_EXECUTION(s, chn, check_result); BREAK_EXECUTION(s, chn, check_result);
} }
@ -717,8 +713,8 @@ flt_end_analyze(struct stream *s, struct channel *chn, unsigned int an_bit)
FLT_FWD(filter, chn) = 0; FLT_FWD(filter, chn) = 0;
unregister_data_filter(s, chn, filter); unregister_data_filter(s, chn, filter);
if (filter->ops->channel_end_analyze) { if (FLT_OPS(filter)->channel_end_analyze) {
ret = filter->ops->channel_end_analyze(s, filter, chn); ret = FLT_OPS(filter)->channel_end_analyze(s, filter, chn);
if (ret <= 0) if (ret <= 0)
BREAK_EXECUTION(s, chn, end); BREAK_EXECUTION(s, chn, end);
} }
@ -778,8 +774,8 @@ flt_data(struct stream *s, struct channel *chn)
continue; continue;
nxt = &FLT_NXT(filter, chn); nxt = &FLT_NXT(filter, chn);
if (filter->ops->tcp_data) { if (FLT_OPS(filter)->tcp_data) {
ret = filter->ops->tcp_data(s, filter, chn); ret = FLT_OPS(filter)->tcp_data(s, filter, chn);
if (ret < 0) if (ret < 0)
break; break;
@ -830,10 +826,10 @@ flt_forward_data(struct stream *s, struct channel *chn, unsigned int len)
continue; continue;
fwd = &FLT_FWD(filter, chn); fwd = &FLT_FWD(filter, chn);
if (filter->ops->tcp_forward_data) { if (FLT_OPS(filter)->tcp_forward_data) {
/* Remove bytes that the current filter considered as /* Remove bytes that the current filter considered as
* forwarded */ * forwarded */
ret = filter->ops->tcp_forward_data(s, filter, chn, ret - *fwd); ret = FLT_OPS(filter)->tcp_forward_data(s, filter, chn, ret - *fwd);
if (ret < 0) if (ret < 0)
goto end; goto end;
} }

View File

@ -62,7 +62,7 @@ static int http_compression_buffer_end(struct comp_state *st, struct stream *s,
/***********************************************************************/ /***********************************************************************/
static int static int
comp_flt_init(struct proxy *px, struct filter *filter) comp_flt_init(struct proxy *px, struct flt_conf *fconf)
{ {
if (!tmpbuf->size && b_alloc(&tmpbuf) == NULL) if (!tmpbuf->size && b_alloc(&tmpbuf) == NULL)
@ -73,7 +73,7 @@ comp_flt_init(struct proxy *px, struct filter *filter)
} }
static void static void
comp_flt_deinit(struct proxy *px, struct filter *filter) comp_flt_deinit(struct proxy *px, struct flt_conf *fconf)
{ {
if (tmpbuf->size) if (tmpbuf->size)
b_free(&tmpbuf); b_free(&tmpbuf);
@ -830,20 +830,20 @@ parse_compression_options(char **args, int section, struct proxy *proxy,
static int static int
parse_http_comp_flt(char **args, int *cur_arg, struct proxy *px, parse_http_comp_flt(char **args, int *cur_arg, struct proxy *px,
struct filter *filter, char **err) struct flt_conf *fconf, char **err)
{ {
struct filter *flt, *back; struct flt_conf *fc, *back;
list_for_each_entry_safe(flt, back, &px->filters, list) { list_for_each_entry_safe(fc, back, &px->filter_configs, list) {
if (flt->id == http_comp_flt_id) { if (fc->id == http_comp_flt_id) {
memprintf(err, "%s: Proxy supports only one compression filter\n", px->id); memprintf(err, "%s: Proxy supports only one compression filter\n", px->id);
return -1; return -1;
} }
} }
filter->id = http_comp_flt_id; fconf->id = http_comp_flt_id;
filter->conf = NULL; fconf->conf = NULL;
filter->ops = &comp_ops; fconf->ops = &comp_ops;
(*cur_arg)++; (*cur_arg)++;
return 0; return 0;
@ -853,14 +853,14 @@ parse_http_comp_flt(char **args, int *cur_arg, struct proxy *px,
int int
check_legacy_http_comp_flt(struct proxy *proxy) check_legacy_http_comp_flt(struct proxy *proxy)
{ {
struct filter *filter; struct flt_conf *fconf;
int err = 0; int err = 0;
if (proxy->comp == NULL) if (proxy->comp == NULL)
goto end; goto end;
if (!LIST_ISEMPTY(&proxy->filters)) { if (!LIST_ISEMPTY(&proxy->filter_configs)) {
list_for_each_entry(filter, &proxy->filters, list) { list_for_each_entry(fconf, &proxy->filter_configs, list) {
if (filter->id == http_comp_flt_id) if (fconf->id == http_comp_flt_id)
goto end; goto end;
} }
Alert("config: %s '%s': require an explicit filter declaration to use HTTP compression\n", Alert("config: %s '%s': require an explicit filter declaration to use HTTP compression\n",
@ -869,18 +869,17 @@ check_legacy_http_comp_flt(struct proxy *proxy)
goto end; goto end;
} }
filter = pool_alloc2(pool2_filter); fconf = calloc(1, sizeof(*fconf));
if (!filter) { if (!fconf) {
Alert("config: %s '%s': out of memory\n", Alert("config: %s '%s': out of memory\n",
proxy_type_str(proxy), proxy->id); proxy_type_str(proxy), proxy->id);
err++; err++;
goto end; goto end;
} }
memset(filter, 0, sizeof(*filter)); fconf->id = http_comp_flt_id;
filter->id = http_comp_flt_id; fconf->conf = NULL;
filter->conf = NULL; fconf->ops = &comp_ops;
filter->ops = &comp_ops; LIST_ADDQ(&proxy->filter_configs, &fconf->list);
LIST_ADDQ(&proxy->filters, &filter->list);
end: end:
return err; return err;
@ -916,7 +915,7 @@ smp_fetch_res_comp_algo(const struct arg *args, struct sample *smp,
return 0; return 0;
list_for_each_entry(filter, &strm_flt(smp->strm)->filters, list) { list_for_each_entry(filter, &strm_flt(smp->strm)->filters, list) {
if (filter->id != http_comp_flt_id) if (FLT_ID(filter) != http_comp_flt_id)
continue; continue;
if (!(st = filter->ctx)) if (!(st = filter->ctx))

View File

@ -70,15 +70,15 @@ stream_pos(const struct stream *s)
**************************************************************************/ **************************************************************************/
/* Initialize the filter. Returns -1 on error, else 0. */ /* Initialize the filter. Returns -1 on error, else 0. */
static int static int
trace_init(struct proxy *px, struct filter *filter) trace_init(struct proxy *px, struct flt_conf *fconf)
{ {
struct trace_config *conf = filter->conf; struct trace_config *conf = fconf->conf;
if (conf->name) if (conf->name)
memprintf(&conf->name, "%s/%s", conf->name, px->id); memprintf(&conf->name, "%s/%s", conf->name, px->id);
else else
memprintf(&conf->name, "TRACE/%s", px->id); memprintf(&conf->name, "TRACE/%s", px->id);
filter->conf = conf; fconf->conf = conf;
TRACE(conf, "filter initialized [read random=%s - fwd random=%s]", TRACE(conf, "filter initialized [read random=%s - fwd random=%s]",
(conf->rand_parsing ? "true" : "false"), (conf->rand_parsing ? "true" : "false"),
(conf->rand_forwarding ? "true" : "false")); (conf->rand_forwarding ? "true" : "false"));
@ -87,22 +87,22 @@ trace_init(struct proxy *px, struct filter *filter)
/* Free ressources allocated by the trace filter. */ /* Free ressources allocated by the trace filter. */
static void static void
trace_deinit(struct proxy *px, struct filter *filter) trace_deinit(struct proxy *px, struct flt_conf *fconf)
{ {
struct trace_config *conf = filter->conf; struct trace_config *conf = fconf->conf;
if (conf) { if (conf) {
TRACE(conf, "filter deinitialized"); TRACE(conf, "filter deinitialized");
free(conf->name); free(conf->name);
free(conf); free(conf);
} }
filter->conf = NULL; fconf->conf = NULL;
} }
/* Check configuration of a trace filter for a specified proxy. /* Check configuration of a trace filter for a specified proxy.
* Return 1 on error, else 0. */ * Return 1 on error, else 0. */
static int static int
trace_check(struct proxy *px, struct filter *filter) trace_check(struct proxy *px, struct flt_conf *fconf)
{ {
return 0; return 0;
} }
@ -114,7 +114,7 @@ trace_check(struct proxy *px, struct filter *filter)
static int static int
trace_stream_start(struct stream *s, struct filter *filter) trace_stream_start(struct stream *s, struct filter *filter)
{ {
struct trace_config *conf = filter->conf; struct trace_config *conf = FLT_CONF(filter);
STRM_TRACE(conf, s, "%-25s", STRM_TRACE(conf, s, "%-25s",
__FUNCTION__); __FUNCTION__);
@ -125,7 +125,7 @@ trace_stream_start(struct stream *s, struct filter *filter)
static void static void
trace_stream_stop(struct stream *s, struct filter *filter) trace_stream_stop(struct stream *s, struct filter *filter)
{ {
struct trace_config *conf = filter->conf; struct trace_config *conf = FLT_CONF(filter);
STRM_TRACE(conf, s, "%-25s", STRM_TRACE(conf, s, "%-25s",
__FUNCTION__); __FUNCTION__);
@ -139,7 +139,7 @@ static int
trace_chn_start_analyze(struct stream *s, struct filter *filter, trace_chn_start_analyze(struct stream *s, struct filter *filter,
struct channel *chn) struct channel *chn)
{ {
struct trace_config *conf = filter->conf; struct trace_config *conf = FLT_CONF(filter);
STRM_TRACE(conf, s, "%-25s: channel=%-10s - mode=%-5s (%s)", STRM_TRACE(conf, s, "%-25s: channel=%-10s - mode=%-5s (%s)",
__FUNCTION__, __FUNCTION__,
@ -153,7 +153,7 @@ static int
trace_chn_analyze(struct stream *s, struct filter *filter, trace_chn_analyze(struct stream *s, struct filter *filter,
struct channel *chn, unsigned an_bit) struct channel *chn, unsigned an_bit)
{ {
struct trace_config *conf = filter->conf; struct trace_config *conf = FLT_CONF(filter);
char *ana; char *ana;
switch (an_bit) { switch (an_bit) {
@ -236,7 +236,7 @@ static int
trace_chn_end_analyze(struct stream *s, struct filter *filter, trace_chn_end_analyze(struct stream *s, struct filter *filter,
struct channel *chn) struct channel *chn)
{ {
struct trace_config *conf = filter->conf; struct trace_config *conf = FLT_CONF(filter);
STRM_TRACE(conf, s, "%-25s: channel=%-10s - mode=%-5s (%s)", STRM_TRACE(conf, s, "%-25s: channel=%-10s - mode=%-5s (%s)",
__FUNCTION__, __FUNCTION__,
@ -251,7 +251,7 @@ static int
trace_http_data(struct stream *s, struct filter *filter, trace_http_data(struct stream *s, struct filter *filter,
struct http_msg *msg) struct http_msg *msg)
{ {
struct trace_config *conf = filter->conf; struct trace_config *conf = FLT_CONF(filter);
int avail = MIN(msg->chunk_len + msg->next, msg->chn->buf->i) - FLT_NXT(filter, msg->chn); int avail = MIN(msg->chunk_len + msg->next, msg->chn->buf->i) - FLT_NXT(filter, msg->chn);
int ret = avail; int ret = avail;
@ -273,7 +273,7 @@ static int
trace_http_chunk_trailers(struct stream *s, struct filter *filter, trace_http_chunk_trailers(struct stream *s, struct filter *filter,
struct http_msg *msg) struct http_msg *msg)
{ {
struct trace_config *conf = filter->conf; struct trace_config *conf = FLT_CONF(filter);
STRM_TRACE(conf, s, "%-25s: channel=%-10s - mode=%-5s (%s)", STRM_TRACE(conf, s, "%-25s: channel=%-10s - mode=%-5s (%s)",
__FUNCTION__, __FUNCTION__,
@ -285,7 +285,7 @@ static int
trace_http_end(struct stream *s, struct filter *filter, trace_http_end(struct stream *s, struct filter *filter,
struct http_msg *msg) struct http_msg *msg)
{ {
struct trace_config *conf = filter->conf; struct trace_config *conf = FLT_CONF(filter);
STRM_TRACE(conf, s, "%-25s: channel=%-10s - mode=%-5s (%s)", STRM_TRACE(conf, s, "%-25s: channel=%-10s - mode=%-5s (%s)",
__FUNCTION__, __FUNCTION__,
@ -297,7 +297,7 @@ static void
trace_http_reset(struct stream *s, struct filter *filter, trace_http_reset(struct stream *s, struct filter *filter,
struct http_msg *msg) struct http_msg *msg)
{ {
struct trace_config *conf = filter->conf; struct trace_config *conf = FLT_CONF(filter);
STRM_TRACE(conf, s, "%-25s: channel=%-10s - mode=%-5s (%s)", STRM_TRACE(conf, s, "%-25s: channel=%-10s - mode=%-5s (%s)",
__FUNCTION__, __FUNCTION__,
@ -308,7 +308,7 @@ static void
trace_http_reply(struct stream *s, struct filter *filter, short status, trace_http_reply(struct stream *s, struct filter *filter, short status,
const struct chunk *msg) const struct chunk *msg)
{ {
struct trace_config *conf = filter->conf; struct trace_config *conf = FLT_CONF(filter);
STRM_TRACE(conf, s, "%-25s: channel=%-10s - mode=%-5s (%s)", STRM_TRACE(conf, s, "%-25s: channel=%-10s - mode=%-5s (%s)",
__FUNCTION__, "-", proxy_mode(s), stream_pos(s)); __FUNCTION__, "-", proxy_mode(s), stream_pos(s));
@ -318,7 +318,7 @@ static int
trace_http_forward_data(struct stream *s, struct filter *filter, trace_http_forward_data(struct stream *s, struct filter *filter,
struct http_msg *msg, unsigned int len) struct http_msg *msg, unsigned int len)
{ {
struct trace_config *conf = filter->conf; struct trace_config *conf = FLT_CONF(filter);
int ret = len; int ret = len;
if (ret && conf->rand_forwarding) if (ret && conf->rand_forwarding)
@ -342,7 +342,7 @@ trace_http_forward_data(struct stream *s, struct filter *filter,
static int static int
trace_tcp_data(struct stream *s, struct filter *filter, struct channel *chn) trace_tcp_data(struct stream *s, struct filter *filter, struct channel *chn)
{ {
struct trace_config *conf = filter->conf; struct trace_config *conf = FLT_CONF(filter);
int avail = chn->buf->i - FLT_NXT(filter, chn); int avail = chn->buf->i - FLT_NXT(filter, chn);
int ret = avail; int ret = avail;
@ -363,7 +363,7 @@ static int
trace_tcp_forward_data(struct stream *s, struct filter *filter, struct channel *chn, trace_tcp_forward_data(struct stream *s, struct filter *filter, struct channel *chn,
unsigned int len) unsigned int len)
{ {
struct trace_config *conf = filter->conf; struct trace_config *conf = FLT_CONF(filter);
int ret = len; int ret = len;
if (ret && conf->rand_forwarding) if (ret && conf->rand_forwarding)
@ -414,7 +414,7 @@ struct flt_ops trace_ops = {
/* Return -1 on error, else 0 */ /* Return -1 on error, else 0 */
static int static int
parse_trace_flt(char **args, int *cur_arg, struct proxy *px, parse_trace_flt(char **args, int *cur_arg, struct proxy *px,
struct filter *filter, char **err) struct flt_conf *fconf, char **err)
{ {
struct trace_config *conf; struct trace_config *conf;
int pos = *cur_arg; int pos = *cur_arg;
@ -452,10 +452,10 @@ parse_trace_flt(char **args, int *cur_arg, struct proxy *px,
pos++; pos++;
} }
*cur_arg = pos; *cur_arg = pos;
filter->ops = &trace_ops; fconf->ops = &trace_ops;
} }
filter->conf = conf; fconf->conf = conf;
return 0; return 0;
error: error:

View File

@ -748,7 +748,7 @@ void init_new_proxy(struct proxy *p)
LIST_INIT(&p->conf.listeners); LIST_INIT(&p->conf.listeners);
LIST_INIT(&p->conf.args.list); LIST_INIT(&p->conf.args.list);
LIST_INIT(&p->tcpcheck_rules); LIST_INIT(&p->tcpcheck_rules);
LIST_INIT(&p->filters); LIST_INIT(&p->filter_configs);
/* Timeouts are defined as -1 */ /* Timeouts are defined as -1 */
proxy_reset_timeouts(p); proxy_reset_timeouts(p);