Skip to content

Commit c64712b

Browse files
committed
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.
1 parent 537f20e commit c64712b

File tree

5 files changed

+73
-63
lines changed

5 files changed

+73
-63
lines changed

include/haproxy/stream-t.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@ enum {
156156
STRM_ET_DATA_ABRT = 0x0400, /* data phase aborted by external cause */
157157
};
158158

159+
160+
/* Types of entities that may interrupt a processing, teomporarily or not
161+
* depending on the context;
162+
*/
163+
enum {
164+
STRM_ENTITY_NONE = 0x0000,
165+
STRM_ENTITY_RULE = 0x0001,
166+
STRM_ENTITY_FILTER = 0x0002,
167+
};
168+
159169
/* This function is used to report flags in debugging tools. Please reflect
160170
* below any single-bit flag addition above in the same order via the
161171
* __APPEND_FLAG macro. The new end of the buffer is returned.
@@ -292,12 +302,12 @@ struct stream {
292302

293303
struct {
294304
void *ptr; /* Pointer on the entity (def: NULL) */
295-
int type; /* entity type (0: undef, 1: rule, 2: filter) */
305+
int type; /* entity type (STRM_ENTITY_*) */
296306
} last_entity; /* last evaluated entity that interrupted processing */
297307

298308
struct {
299309
void *ptr; /* Pointer on the entity (def: NULL) */
300-
int type; /* entity type (0: undef, 1: rule, 2: filter) */
310+
int type; /* entity type (STRM_ENTITY_*) */
301311
} waiting_entity; /* The entity waiting to continue its processing and interrupted by an error/timeout */
302312

303313
unsigned int stream_epoch; /* copy of stream_epoch when the stream was created */

src/filters.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static int handle_analyzer_result(struct stream *s, struct channel *chn, unsigne
6262
strm_flt(strm)->current[CHN_IDX(chn)] = NULL; \
6363
if (!(chn_prod(chn)->flags & SC_FL_ERROR) && \
6464
!(chn->flags & (CF_READ_TIMEOUT|CF_WRITE_TIMEOUT))) { \
65-
(strm)->waiting_entity.type = 0; \
65+
(strm)->waiting_entity.type = STRM_ENTITY_NONE; \
6666
(strm)->waiting_entity.ptr = NULL; \
6767
} \
6868
goto resume_execution; \
@@ -78,11 +78,11 @@ static int handle_analyzer_result(struct stream *s, struct channel *chn, unsigne
7878
#define BREAK_EXECUTION(strm, chn, label) \
7979
do { \
8080
if (ret == 0) { \
81-
s->waiting_entity.type = 2; \
81+
s->waiting_entity.type = STRM_ENTITY_FILTER; \
8282
s->waiting_entity.ptr = filter; \
8383
} \
8484
else if (ret < 0) { \
85-
(strm)->last_entity.type = 2; \
85+
(strm)->last_entity.type = STRM_ENTITY_FILTER; \
8686
(strm)->last_entity.ptr = filter; \
8787
} \
8888
strm_flt(strm)->current[CHN_IDX(chn)] = filter; \
@@ -570,7 +570,7 @@ flt_set_stream_backend(struct stream *s, struct proxy *be)
570570
if (FLT_OPS(filter)->stream_set_backend) {
571571
filter->calls++;
572572
if (FLT_OPS(filter)->stream_set_backend(s, filter, be) < 0) {
573-
s->last_entity.type = 2;
573+
s->last_entity.type = STRM_ENTITY_FILTER;
574574
s->last_entity.ptr = filter;
575575
return -1;
576576
}
@@ -710,7 +710,7 @@ flt_http_payload(struct stream *s, struct http_msg *msg, unsigned int len)
710710
filter->calls++;
711711
ret = FLT_OPS(filter)->http_payload(s, filter, msg, out + offset, data - offset);
712712
if (ret < 0) {
713-
s->last_entity.type = 2;
713+
s->last_entity.type = STRM_ENTITY_FILTER;
714714
s->last_entity.ptr = filter;
715715
goto end;
716716
}
@@ -852,7 +852,7 @@ flt_post_analyze(struct stream *s, struct channel *chn, unsigned int an_bit)
852852
filter->calls++;
853853
ret = FLT_OPS(filter)->channel_post_analyze(s, filter, chn, an_bit);
854854
if (ret < 0) {
855-
s->last_entity.type = 2;
855+
s->last_entity.type = STRM_ENTITY_FILTER;
856856
s->last_entity.ptr = filter;
857857
break;
858858
}
@@ -1009,7 +1009,7 @@ flt_tcp_payload(struct stream *s, struct channel *chn, unsigned int len)
10091009
filter->calls++;
10101010
ret = FLT_OPS(filter)->tcp_payload(s, filter, chn, out + offset, data - offset);
10111011
if (ret < 0) {
1012-
s->last_entity.type = 2;
1012+
s->last_entity.type = STRM_ENTITY_FILTER;
10131013
s->last_entity.ptr = filter;
10141014
goto end;
10151015
}

src/http_ana.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2735,7 +2735,7 @@ static enum rule_result http_req_get_intercept_rule(struct proxy *px, struct lis
27352735
act_opts |= ACT_OPT_FINAL;
27362736

27372737
if (!(s->scf->flags & SC_FL_ERROR) & !(s->req.flags & (CF_READ_TIMEOUT|CF_WRITE_TIMEOUT))) {
2738-
s->waiting_entity.type = 0;
2738+
s->waiting_entity.type = STRM_ENTITY_NONE;
27392739
s->waiting_entity.ptr = NULL;
27402740
}
27412741

@@ -2744,7 +2744,7 @@ static enum rule_result http_req_get_intercept_rule(struct proxy *px, struct lis
27442744
break;
27452745
case ACT_RET_STOP:
27462746
rule_ret = HTTP_RULE_RES_STOP;
2747-
s->last_entity.type = 1;
2747+
s->last_entity.type = STRM_ENTITY_RULE;
27482748
s->last_entity.ptr = rule;
27492749
goto end;
27502750
case ACT_RET_YIELD:
@@ -2753,40 +2753,40 @@ static enum rule_result http_req_get_intercept_rule(struct proxy *px, struct lis
27532753
send_log(s->be, LOG_WARNING,
27542754
"Internal error: action yields while it is no long allowed "
27552755
"for the http-request actions.");
2756-
s->last_entity.type = 1;
2756+
s->last_entity.type = STRM_ENTITY_RULE;
27572757
s->last_entity.ptr = rule;
27582758
rule_ret = HTTP_RULE_RES_ERROR;
27592759
goto end;
27602760
}
2761-
s->waiting_entity.type = 1;
2761+
s->waiting_entity.type = STRM_ENTITY_RULE;
27622762
s->waiting_entity.ptr = rule;
27632763
rule_ret = HTTP_RULE_RES_YIELD;
27642764
goto end;
27652765
case ACT_RET_ERR:
27662766
rule_ret = HTTP_RULE_RES_ERROR;
2767-
s->last_entity.type = 1;
2767+
s->last_entity.type = STRM_ENTITY_RULE;
27682768
s->last_entity.ptr = rule;
27692769
goto end;
27702770
case ACT_RET_DONE:
27712771
rule_ret = HTTP_RULE_RES_DONE;
2772-
s->last_entity.type = 1;
2772+
s->last_entity.type = STRM_ENTITY_RULE;
27732773
s->last_entity.ptr = rule;
27742774
goto end;
27752775
case ACT_RET_DENY:
27762776
if (txn->status == -1)
27772777
txn->status = 403;
27782778
rule_ret = HTTP_RULE_RES_DENY;
2779-
s->last_entity.type = 1;
2779+
s->last_entity.type = STRM_ENTITY_RULE;
27802780
s->last_entity.ptr = rule;
27812781
goto end;
27822782
case ACT_RET_ABRT:
27832783
rule_ret = HTTP_RULE_RES_ABRT;
2784-
s->last_entity.type = 1;
2784+
s->last_entity.type = STRM_ENTITY_RULE;
27852785
s->last_entity.ptr = rule;
27862786
goto end;
27872787
case ACT_RET_INV:
27882788
rule_ret = HTTP_RULE_RES_BADREQ;
2789-
s->last_entity.type = 1;
2789+
s->last_entity.type = STRM_ENTITY_RULE;
27902790
s->last_entity.ptr = rule;
27912791
goto end;
27922792
}
@@ -2797,15 +2797,15 @@ static enum rule_result http_req_get_intercept_rule(struct proxy *px, struct lis
27972797
switch (rule->action) {
27982798
case ACT_ACTION_ALLOW:
27992799
rule_ret = HTTP_RULE_RES_STOP;
2800-
s->last_entity.type = 1;
2800+
s->last_entity.type = STRM_ENTITY_RULE;
28012801
s->last_entity.ptr = rule;
28022802
goto end;
28032803

28042804
case ACT_ACTION_DENY:
28052805
txn->status = rule->arg.http_reply->status;
28062806
txn->http_reply = rule->arg.http_reply;
28072807
rule_ret = HTTP_RULE_RES_DENY;
2808-
s->last_entity.type = 1;
2808+
s->last_entity.type = STRM_ENTITY_RULE;
28092809
s->last_entity.ptr = rule;
28102810
goto end;
28112811

@@ -2814,7 +2814,7 @@ static enum rule_result http_req_get_intercept_rule(struct proxy *px, struct lis
28142814
txn->status = rule->arg.http_reply->status;
28152815
txn->http_reply = rule->arg.http_reply;
28162816
rule_ret = HTTP_RULE_RES_DENY;
2817-
s->last_entity.type = 1;
2817+
s->last_entity.type = STRM_ENTITY_RULE;
28182818
s->last_entity.ptr = rule;
28192819
goto end;
28202820

@@ -2825,7 +2825,7 @@ static enum rule_result http_req_get_intercept_rule(struct proxy *px, struct lis
28252825
break;
28262826

28272827
rule_ret = ret ? HTTP_RULE_RES_ABRT : HTTP_RULE_RES_ERROR;
2828-
s->last_entity.type = 1;
2828+
s->last_entity.type = STRM_ENTITY_RULE;
28292829
s->last_entity.ptr = rule;
28302830
goto end;
28312831
}
@@ -2916,7 +2916,7 @@ static enum rule_result http_res_get_intercept_rule(struct proxy *px, struct lis
29162916
act_opts |= ACT_OPT_FINAL;
29172917

29182918
if (!(s->scb->flags & SC_FL_ERROR) & !(s->res.flags & (CF_READ_TIMEOUT|CF_WRITE_TIMEOUT))) {
2919-
s->waiting_entity.type = 0;
2919+
s->waiting_entity.type = STRM_ENTITY_NONE;
29202920
s->waiting_entity.ptr = NULL;
29212921
}
29222922

@@ -2925,7 +2925,7 @@ static enum rule_result http_res_get_intercept_rule(struct proxy *px, struct lis
29252925
break;
29262926
case ACT_RET_STOP:
29272927
rule_ret = HTTP_RULE_RES_STOP;
2928-
s->last_entity.type = 1;
2928+
s->last_entity.type = STRM_ENTITY_RULE;
29292929
s->last_entity.ptr = rule;
29302930
goto end;
29312931
case ACT_RET_YIELD:
@@ -2934,40 +2934,40 @@ static enum rule_result http_res_get_intercept_rule(struct proxy *px, struct lis
29342934
send_log(s->be, LOG_WARNING,
29352935
"Internal error: action yields while it is no long allowed "
29362936
"for the http-response/http-after-response actions.");
2937-
s->last_entity.type = 1;
2937+
s->last_entity.type = STRM_ENTITY_RULE;
29382938
s->last_entity.ptr = rule;
29392939
rule_ret = HTTP_RULE_RES_ERROR;
29402940
goto end;
29412941
}
2942-
s->waiting_entity.type = 1;
2942+
s->waiting_entity.type = STRM_ENTITY_RULE;
29432943
s->waiting_entity.ptr = rule;
29442944
rule_ret = HTTP_RULE_RES_YIELD;
29452945
goto end;
29462946
case ACT_RET_ERR:
29472947
rule_ret = HTTP_RULE_RES_ERROR;
2948-
s->last_entity.type = 1;
2948+
s->last_entity.type = STRM_ENTITY_RULE;
29492949
s->last_entity.ptr = rule;
29502950
goto end;
29512951
case ACT_RET_DONE:
29522952
rule_ret = HTTP_RULE_RES_DONE;
2953-
s->last_entity.type = 1;
2953+
s->last_entity.type = STRM_ENTITY_RULE;
29542954
s->last_entity.ptr = rule;
29552955
goto end;
29562956
case ACT_RET_DENY:
29572957
if (txn->status == -1)
29582958
txn->status = 502;
29592959
rule_ret = HTTP_RULE_RES_DENY;
2960-
s->last_entity.type = 1;
2960+
s->last_entity.type = STRM_ENTITY_RULE;
29612961
s->last_entity.ptr = rule;
29622962
goto end;
29632963
case ACT_RET_ABRT:
29642964
rule_ret = HTTP_RULE_RES_ABRT;
2965-
s->last_entity.type = 1;
2965+
s->last_entity.type = STRM_ENTITY_RULE;
29662966
s->last_entity.ptr = rule;
29672967
goto end;
29682968
case ACT_RET_INV:
29692969
rule_ret = HTTP_RULE_RES_BADREQ;
2970-
s->last_entity.type = 1;
2970+
s->last_entity.type = STRM_ENTITY_RULE;
29712971
s->last_entity.ptr = rule;
29722972
goto end;
29732973
}
@@ -2978,15 +2978,15 @@ static enum rule_result http_res_get_intercept_rule(struct proxy *px, struct lis
29782978
switch (rule->action) {
29792979
case ACT_ACTION_ALLOW:
29802980
rule_ret = HTTP_RULE_RES_STOP; /* "allow" rules are OK */
2981-
s->last_entity.type = 1;
2981+
s->last_entity.type = STRM_ENTITY_RULE;
29822982
s->last_entity.ptr = rule;
29832983
goto end;
29842984

29852985
case ACT_ACTION_DENY:
29862986
txn->status = rule->arg.http_reply->status;
29872987
txn->http_reply = rule->arg.http_reply;
29882988
rule_ret = HTTP_RULE_RES_DENY;
2989-
s->last_entity.type = 1;
2989+
s->last_entity.type = STRM_ENTITY_RULE;
29902990
s->last_entity.ptr = rule;
29912991
goto end;
29922992

@@ -2997,7 +2997,7 @@ static enum rule_result http_res_get_intercept_rule(struct proxy *px, struct lis
29972997
break;
29982998

29992999
rule_ret = ret ? HTTP_RULE_RES_ABRT : HTTP_RULE_RES_ERROR;
3000-
s->last_entity.type = 1;
3000+
s->last_entity.type = STRM_ENTITY_RULE;
30013001
s->last_entity.ptr = rule;
30023002
goto end;
30033003
}

src/stream.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,9 @@ struct stream *stream_new(struct session *sess, struct stconn *sc, struct buffer
389389
s->current_rule_list = NULL;
390390
s->current_rule = NULL;
391391
s->rules_exp = TICK_ETERNITY;
392-
s->last_entity.type = 0;
392+
s->last_entity.type = STRM_ENTITY_NONE;
393393
s->last_entity.ptr = NULL;
394-
s->waiting_entity.type = 0;
394+
s->waiting_entity.type = STRM_ENTITY_NONE;
395395
s->waiting_entity.ptr = NULL;
396396

397397
s->stkctr = NULL;
@@ -4101,7 +4101,7 @@ static int smp_fetch_last_rule_file(const struct arg *args, struct sample *smp,
41014101

41024102
smp->flags = SMP_F_VOL_TXN;
41034103
smp->data.type = SMP_T_STR;
4104-
if (!smp->strm || smp->strm->last_entity.type != 1)
4104+
if (!smp->strm || smp->strm->last_entity.type != STRM_ENTITY_RULE)
41054105
return 0;
41064106

41074107
rule = smp->strm->last_entity.ptr;
@@ -4117,7 +4117,7 @@ static int smp_fetch_last_rule_line(const struct arg *args, struct sample *smp,
41174117

41184118
smp->flags = SMP_F_VOL_TXN;
41194119
smp->data.type = SMP_T_SINT;
4120-
if (!smp->strm || smp->strm->last_entity.type != 1)
4120+
if (!smp->strm || smp->strm->last_entity.type != STRM_ENTITY_RULE)
41214121
return 0;
41224122

41234123
rule = smp->strm->last_entity.ptr;
@@ -4132,14 +4132,14 @@ static int smp_fetch_last_entity(const struct arg *args, struct sample *smp, con
41324132
if (!smp->strm)
41334133
return 0;
41344134

4135-
if (smp->strm->last_entity.type == 1) {
4135+
if (smp->strm->last_entity.type == STRM_ENTITY_RULE) {
41364136
struct act_rule *rule = smp->strm->last_entity.ptr;
41374137
struct buffer *trash = get_trash_chunk();
41384138

41394139
trash->data = snprintf(trash->area, trash->size, "%s:%d", rule->conf.file, rule->conf.line);
41404140
smp->data.u.str = *trash;
41414141
}
4142-
else if (smp->strm->last_entity.type == 2) {
4142+
else if (smp->strm->last_entity.type == STRM_ENTITY_FILTER) {
41434143
struct filter *filter = smp->strm->last_entity.ptr;
41444144

41454145
if (FLT_ID(filter)) {
@@ -4167,14 +4167,14 @@ static int smp_fetch_waiting_entity(const struct arg *args, struct sample *smp,
41674167
if (!smp->strm)
41684168
return 0;
41694169

4170-
if (smp->strm->waiting_entity.type == 1) {
4170+
if (smp->strm->waiting_entity.type == STRM_ENTITY_RULE) {
41714171
struct act_rule *rule = smp->strm->waiting_entity.ptr;
41724172
struct buffer *trash = get_trash_chunk();
41734173

41744174
trash->data = snprintf(trash->area, trash->size, "%s:%d", rule->conf.file, rule->conf.line);
41754175
smp->data.u.str = *trash;
41764176
}
4177-
else if (smp->strm->waiting_entity.type == 2) {
4177+
else if (smp->strm->waiting_entity.type == STRM_ENTITY_FILTER) {
41784178
struct filter *filter = smp->strm->waiting_entity.ptr;
41794179

41804180
if (FLT_ID(filter)) {

0 commit comments

Comments
 (0)