MINOR: stream: Use an enum to identify last and waiting entities for streams

Instead of using 1 for last/waiting rule and 2 for last/waiting filter, an
enum is used. It is less ambiguous this way.
This commit is contained in:
Christopher Faulet 2024-10-31 13:53:56 +01:00
parent 537f20eb3e
commit c64712b085
5 changed files with 73 additions and 63 deletions

View File

@ -156,6 +156,16 @@ enum {
STRM_ET_DATA_ABRT = 0x0400, /* data phase aborted by external cause */
};
/* Types of entities that may interrupt a processing, teomporarily or not
* depending on the context;
*/
enum {
STRM_ENTITY_NONE = 0x0000,
STRM_ENTITY_RULE = 0x0001,
STRM_ENTITY_FILTER = 0x0002,
};
/* This function is used to report flags in debugging tools. Please reflect
* below any single-bit flag addition above in the same order via the
* __APPEND_FLAG macro. The new end of the buffer is returned.
@ -292,12 +302,12 @@ struct stream {
struct {
void *ptr; /* Pointer on the entity (def: NULL) */
int type; /* entity type (0: undef, 1: rule, 2: filter) */
int type; /* entity type (STRM_ENTITY_*) */
} last_entity; /* last evaluated entity that interrupted processing */
struct {
void *ptr; /* Pointer on the entity (def: NULL) */
int type; /* entity type (0: undef, 1: rule, 2: filter) */
int type; /* entity type (STRM_ENTITY_*) */
} waiting_entity; /* The entity waiting to continue its processing and interrupted by an error/timeout */
unsigned int stream_epoch; /* copy of stream_epoch when the stream was created */

View File

@ -62,7 +62,7 @@ static int handle_analyzer_result(struct stream *s, struct channel *chn, unsigne
strm_flt(strm)->current[CHN_IDX(chn)] = NULL; \
if (!(chn_prod(chn)->flags & SC_FL_ERROR) && \
!(chn->flags & (CF_READ_TIMEOUT|CF_WRITE_TIMEOUT))) { \
(strm)->waiting_entity.type = 0; \
(strm)->waiting_entity.type = STRM_ENTITY_NONE; \
(strm)->waiting_entity.ptr = NULL; \
} \
goto resume_execution; \
@ -78,11 +78,11 @@ static int handle_analyzer_result(struct stream *s, struct channel *chn, unsigne
#define BREAK_EXECUTION(strm, chn, label) \
do { \
if (ret == 0) { \
s->waiting_entity.type = 2; \
s->waiting_entity.type = STRM_ENTITY_FILTER; \
s->waiting_entity.ptr = filter; \
} \
else if (ret < 0) { \
(strm)->last_entity.type = 2; \
(strm)->last_entity.type = STRM_ENTITY_FILTER; \
(strm)->last_entity.ptr = filter; \
} \
strm_flt(strm)->current[CHN_IDX(chn)] = filter; \
@ -570,7 +570,7 @@ flt_set_stream_backend(struct stream *s, struct proxy *be)
if (FLT_OPS(filter)->stream_set_backend) {
filter->calls++;
if (FLT_OPS(filter)->stream_set_backend(s, filter, be) < 0) {
s->last_entity.type = 2;
s->last_entity.type = STRM_ENTITY_FILTER;
s->last_entity.ptr = filter;
return -1;
}
@ -710,7 +710,7 @@ flt_http_payload(struct stream *s, struct http_msg *msg, unsigned int len)
filter->calls++;
ret = FLT_OPS(filter)->http_payload(s, filter, msg, out + offset, data - offset);
if (ret < 0) {
s->last_entity.type = 2;
s->last_entity.type = STRM_ENTITY_FILTER;
s->last_entity.ptr = filter;
goto end;
}
@ -852,7 +852,7 @@ flt_post_analyze(struct stream *s, struct channel *chn, unsigned int an_bit)
filter->calls++;
ret = FLT_OPS(filter)->channel_post_analyze(s, filter, chn, an_bit);
if (ret < 0) {
s->last_entity.type = 2;
s->last_entity.type = STRM_ENTITY_FILTER;
s->last_entity.ptr = filter;
break;
}
@ -1009,7 +1009,7 @@ flt_tcp_payload(struct stream *s, struct channel *chn, unsigned int len)
filter->calls++;
ret = FLT_OPS(filter)->tcp_payload(s, filter, chn, out + offset, data - offset);
if (ret < 0) {
s->last_entity.type = 2;
s->last_entity.type = STRM_ENTITY_FILTER;
s->last_entity.ptr = filter;
goto end;
}

View File

@ -2735,7 +2735,7 @@ static enum rule_result http_req_get_intercept_rule(struct proxy *px, struct lis
act_opts |= ACT_OPT_FINAL;
if (!(s->scf->flags & SC_FL_ERROR) & !(s->req.flags & (CF_READ_TIMEOUT|CF_WRITE_TIMEOUT))) {
s->waiting_entity.type = 0;
s->waiting_entity.type = STRM_ENTITY_NONE;
s->waiting_entity.ptr = NULL;
}
@ -2744,7 +2744,7 @@ static enum rule_result http_req_get_intercept_rule(struct proxy *px, struct lis
break;
case ACT_RET_STOP:
rule_ret = HTTP_RULE_RES_STOP;
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto end;
case ACT_RET_YIELD:
@ -2753,40 +2753,40 @@ static enum rule_result http_req_get_intercept_rule(struct proxy *px, struct lis
send_log(s->be, LOG_WARNING,
"Internal error: action yields while it is no long allowed "
"for the http-request actions.");
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
rule_ret = HTTP_RULE_RES_ERROR;
goto end;
}
s->waiting_entity.type = 1;
s->waiting_entity.type = STRM_ENTITY_RULE;
s->waiting_entity.ptr = rule;
rule_ret = HTTP_RULE_RES_YIELD;
goto end;
case ACT_RET_ERR:
rule_ret = HTTP_RULE_RES_ERROR;
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto end;
case ACT_RET_DONE:
rule_ret = HTTP_RULE_RES_DONE;
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto end;
case ACT_RET_DENY:
if (txn->status == -1)
txn->status = 403;
rule_ret = HTTP_RULE_RES_DENY;
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto end;
case ACT_RET_ABRT:
rule_ret = HTTP_RULE_RES_ABRT;
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto end;
case ACT_RET_INV:
rule_ret = HTTP_RULE_RES_BADREQ;
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto end;
}
@ -2797,7 +2797,7 @@ static enum rule_result http_req_get_intercept_rule(struct proxy *px, struct lis
switch (rule->action) {
case ACT_ACTION_ALLOW:
rule_ret = HTTP_RULE_RES_STOP;
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto end;
@ -2805,7 +2805,7 @@ static enum rule_result http_req_get_intercept_rule(struct proxy *px, struct lis
txn->status = rule->arg.http_reply->status;
txn->http_reply = rule->arg.http_reply;
rule_ret = HTTP_RULE_RES_DENY;
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto end;
@ -2814,7 +2814,7 @@ static enum rule_result http_req_get_intercept_rule(struct proxy *px, struct lis
txn->status = rule->arg.http_reply->status;
txn->http_reply = rule->arg.http_reply;
rule_ret = HTTP_RULE_RES_DENY;
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto end;
@ -2825,7 +2825,7 @@ static enum rule_result http_req_get_intercept_rule(struct proxy *px, struct lis
break;
rule_ret = ret ? HTTP_RULE_RES_ABRT : HTTP_RULE_RES_ERROR;
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto end;
}
@ -2916,7 +2916,7 @@ resume_execution:
act_opts |= ACT_OPT_FINAL;
if (!(s->scb->flags & SC_FL_ERROR) & !(s->res.flags & (CF_READ_TIMEOUT|CF_WRITE_TIMEOUT))) {
s->waiting_entity.type = 0;
s->waiting_entity.type = STRM_ENTITY_NONE;
s->waiting_entity.ptr = NULL;
}
@ -2925,7 +2925,7 @@ resume_execution:
break;
case ACT_RET_STOP:
rule_ret = HTTP_RULE_RES_STOP;
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto end;
case ACT_RET_YIELD:
@ -2934,40 +2934,40 @@ resume_execution:
send_log(s->be, LOG_WARNING,
"Internal error: action yields while it is no long allowed "
"for the http-response/http-after-response actions.");
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
rule_ret = HTTP_RULE_RES_ERROR;
goto end;
}
s->waiting_entity.type = 1;
s->waiting_entity.type = STRM_ENTITY_RULE;
s->waiting_entity.ptr = rule;
rule_ret = HTTP_RULE_RES_YIELD;
goto end;
case ACT_RET_ERR:
rule_ret = HTTP_RULE_RES_ERROR;
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto end;
case ACT_RET_DONE:
rule_ret = HTTP_RULE_RES_DONE;
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto end;
case ACT_RET_DENY:
if (txn->status == -1)
txn->status = 502;
rule_ret = HTTP_RULE_RES_DENY;
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto end;
case ACT_RET_ABRT:
rule_ret = HTTP_RULE_RES_ABRT;
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto end;
case ACT_RET_INV:
rule_ret = HTTP_RULE_RES_BADREQ;
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto end;
}
@ -2978,7 +2978,7 @@ resume_execution:
switch (rule->action) {
case ACT_ACTION_ALLOW:
rule_ret = HTTP_RULE_RES_STOP; /* "allow" rules are OK */
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto end;
@ -2986,7 +2986,7 @@ resume_execution:
txn->status = rule->arg.http_reply->status;
txn->http_reply = rule->arg.http_reply;
rule_ret = HTTP_RULE_RES_DENY;
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto end;
@ -2997,7 +2997,7 @@ resume_execution:
break;
rule_ret = ret ? HTTP_RULE_RES_ABRT : HTTP_RULE_RES_ERROR;
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto end;
}

View File

@ -389,9 +389,9 @@ struct stream *stream_new(struct session *sess, struct stconn *sc, struct buffer
s->current_rule_list = NULL;
s->current_rule = NULL;
s->rules_exp = TICK_ETERNITY;
s->last_entity.type = 0;
s->last_entity.type = STRM_ENTITY_NONE;
s->last_entity.ptr = NULL;
s->waiting_entity.type = 0;
s->waiting_entity.type = STRM_ENTITY_NONE;
s->waiting_entity.ptr = NULL;
s->stkctr = NULL;
@ -4101,7 +4101,7 @@ static int smp_fetch_last_rule_file(const struct arg *args, struct sample *smp,
smp->flags = SMP_F_VOL_TXN;
smp->data.type = SMP_T_STR;
if (!smp->strm || smp->strm->last_entity.type != 1)
if (!smp->strm || smp->strm->last_entity.type != STRM_ENTITY_RULE)
return 0;
rule = smp->strm->last_entity.ptr;
@ -4117,7 +4117,7 @@ static int smp_fetch_last_rule_line(const struct arg *args, struct sample *smp,
smp->flags = SMP_F_VOL_TXN;
smp->data.type = SMP_T_SINT;
if (!smp->strm || smp->strm->last_entity.type != 1)
if (!smp->strm || smp->strm->last_entity.type != STRM_ENTITY_RULE)
return 0;
rule = smp->strm->last_entity.ptr;
@ -4132,14 +4132,14 @@ static int smp_fetch_last_entity(const struct arg *args, struct sample *smp, con
if (!smp->strm)
return 0;
if (smp->strm->last_entity.type == 1) {
if (smp->strm->last_entity.type == STRM_ENTITY_RULE) {
struct act_rule *rule = smp->strm->last_entity.ptr;
struct buffer *trash = get_trash_chunk();
trash->data = snprintf(trash->area, trash->size, "%s:%d", rule->conf.file, rule->conf.line);
smp->data.u.str = *trash;
}
else if (smp->strm->last_entity.type == 2) {
else if (smp->strm->last_entity.type == STRM_ENTITY_FILTER) {
struct filter *filter = smp->strm->last_entity.ptr;
if (FLT_ID(filter)) {
@ -4167,14 +4167,14 @@ static int smp_fetch_waiting_entity(const struct arg *args, struct sample *smp,
if (!smp->strm)
return 0;
if (smp->strm->waiting_entity.type == 1) {
if (smp->strm->waiting_entity.type == STRM_ENTITY_RULE) {
struct act_rule *rule = smp->strm->waiting_entity.ptr;
struct buffer *trash = get_trash_chunk();
trash->data = snprintf(trash->area, trash->size, "%s:%d", rule->conf.file, rule->conf.line);
smp->data.u.str = *trash;
}
else if (smp->strm->waiting_entity.type == 2) {
else if (smp->strm->waiting_entity.type == STRM_ENTITY_FILTER) {
struct filter *filter = smp->strm->waiting_entity.ptr;
if (FLT_ID(filter)) {

View File

@ -138,7 +138,7 @@ int tcp_inspect_request(struct stream *s, struct channel *req, int an_bit)
rule = s->current_rule;
s->current_rule = NULL;
if (!(req->flags & SC_FL_ERROR) && !(req->flags & (CF_READ_TIMEOUT|CF_WRITE_TIMEOUT))) {
s->waiting_entity.type = 0;
s->waiting_entity.type = STRM_ENTITY_NONE;
s->waiting_entity.ptr = NULL;
}
if ((def_rules && s->current_rule_list == def_rules) || s->current_rule_list == rules)
@ -170,7 +170,7 @@ resume_execution:
break;
case ACT_RET_STOP:
case ACT_RET_DONE:
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto end;
case ACT_RET_YIELD:
@ -179,27 +179,27 @@ resume_execution:
send_log(s->be, LOG_WARNING,
"Internal error: yield not allowed if the inspect-delay expired "
"for the tcp-request content actions.");
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto internal;
}
s->waiting_entity.type = 1;
s->waiting_entity.type = STRM_ENTITY_RULE;
s->waiting_entity.ptr = rule;
goto missing_data;
case ACT_RET_DENY:
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto deny;
case ACT_RET_ABRT:
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto abort;
case ACT_RET_ERR:
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto internal;
case ACT_RET_INV:
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto invalid;
}
@ -208,12 +208,12 @@ resume_execution:
/* If not action function defined, check for known actions */
if (rule->action == ACT_ACTION_ALLOW) {
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto end;
}
else if (rule->action == ACT_ACTION_DENY) {
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto deny;
}
@ -328,7 +328,7 @@ int tcp_inspect_response(struct stream *s, struct channel *rep, int an_bit)
rule = s->current_rule;
s->current_rule = NULL;
if (!(rep->flags & SC_FL_ERROR) && !(rep->flags & (CF_READ_TIMEOUT|CF_WRITE_TIMEOUT))) {
s->waiting_entity.type = 0;
s->waiting_entity.type = STRM_ENTITY_NONE;
s->waiting_entity.ptr = NULL;
}
if ((def_rules && s->current_rule_list == def_rules) || s->current_rule_list == rules)
@ -361,7 +361,7 @@ resume_execution:
break;
case ACT_RET_STOP:
case ACT_RET_DONE:
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto end;
case ACT_RET_YIELD:
@ -370,28 +370,28 @@ resume_execution:
send_log(s->be, LOG_WARNING,
"Internal error: yield not allowed if the inspect-delay expired "
"for the tcp-response content actions.");
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto internal;
}
s->waiting_entity.type = 1;
s->waiting_entity.type = STRM_ENTITY_RULE;
s->waiting_entity.ptr = rule;
channel_dont_close(rep);
goto missing_data;
case ACT_RET_DENY:
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto deny;
case ACT_RET_ABRT:
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto abort;
case ACT_RET_ERR:
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto internal;
case ACT_RET_INV:
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto invalid;
}
@ -400,12 +400,12 @@ resume_execution:
/* If not action function defined, check for known actions */
if (rule->action == ACT_ACTION_ALLOW) {
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto end;
}
else if (rule->action == ACT_ACTION_DENY) {
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto deny;
}
@ -414,7 +414,7 @@ resume_execution:
sc_must_kill_conn(s->scb);
sc_abort(s->scb);
sc_shutdown(s->scb);
s->last_entity.type = 1;
s->last_entity.type = STRM_ENTITY_RULE;
s->last_entity.ptr = rule;
goto end;
}