Skip to content

Commit 11853e1

Browse files
authored
Merge pull request #2351 from tempesta-tech/MekhanikEvgenii/fix-1411-2
Fix deleteting previosly closed streams.
2 parents 0fd6d27 + 4891350 commit 11853e1

File tree

2 files changed

+87
-27
lines changed

2 files changed

+87
-27
lines changed

fw/http.c

Lines changed: 82 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3373,9 +3373,14 @@ __tfw_http_add_hdr_via(TfwHttpMsg *hm, int http_version, bool from_cache)
33733373
TfwStr crlf = { .data = S_CRLF, .len = SLEN(S_CRLF) };
33743374

33753375
r = tfw_http_msg_expand_data(&mit->iter, skb_head, &rh, NULL);
3376-
r |= tfw_http_msg_expand_data(&mit->iter, skb_head,
3376+
if (unlikely(r))
3377+
goto finish;
3378+
3379+
r = tfw_http_msg_expand_data(&mit->iter, skb_head,
33773380
&crlf, NULL);
33783381
}
3382+
3383+
finish:
33793384
if (r)
33803385
T_ERR("Unable to add via: header to msg [%p]\n", hm);
33813386
else
@@ -3558,13 +3563,17 @@ tfw_h1_set_loc_hdrs(TfwHttpMsg *hm, bool is_resp, bool from_cache)
35583563
/* h_mdf->eolen is ignored, add explicit CRLF. */
35593564
r = tfw_http_msg_expand_data(&mit->iter, skb_head,
35603565
&h_mdf, NULL);
3561-
r |= tfw_http_msg_expand_data(&mit->iter, skb_head,
3566+
if (unlikely(r))
3567+
goto finish;
3568+
3569+
r = tfw_http_msg_expand_data(&mit->iter, skb_head,
35623570
&crlf, NULL);
35633571
} else {
35643572
r = tfw_http_msg_hdr_xfrm_str(hm, &h_mdf, d->hid,
35653573
d->append);
35663574
}
35673575

3576+
finish:
35683577
if (r) {
35693578
T_ERR("can't update location-specific header in msg %p\n",
35703579
hm);
@@ -3912,11 +3921,18 @@ write_merged_cookie_headers(TfwStr *hdr, TfwMsgIter *it)
39123921
hval.nchunks--;
39133922
hval.len -= chunk->len;
39143923
}
3915-
r |= tfw_msg_write(it, cookie_dlm);
3916-
r |= tfw_msg_write(it, &hval);
3924+
r = tfw_msg_write(it, cookie_dlm);
3925+
if (unlikely(r))
3926+
return r;
3927+
3928+
r = tfw_msg_write(it, &hval);
3929+
if (unlikely(r))
3930+
return r;
3931+
39173932
cookie_dlm = &val_dlm;
39183933
}
3919-
return r | tfw_msg_write(it, &crlf);
3934+
3935+
return tfw_msg_write(it, &crlf);
39203936
}
39213937

39223938
static int
@@ -4123,20 +4139,40 @@ tfw_h2_adjust_req(TfwHttpReq *req)
41234139

41244140
if (WARN_ON_ONCE(h1_hdrs_sz < 0))
41254141
return -EINVAL;
4126-
if ((r = tfw_msg_iter_setup(&it, &new_head, h1_hdrs_sz, 0)))
4142+
4143+
r = tfw_msg_iter_setup(&it, &new_head, h1_hdrs_sz, 0);
4144+
if (unlikely(r))
41274145
return r;
41284146

41294147
/* First line. */
41304148
r = __h2_write_method(req, &it);
4131-
r |= tfw_msg_write(&it, &sp);
4132-
r |= tfw_msg_write(&it, &req->uri_path);
4133-
r |= tfw_msg_write(&it, &fl_end); /* start of Host: header */
4149+
if (unlikely(r))
4150+
goto err;
4151+
4152+
r = tfw_msg_write(&it, &sp);
4153+
if (unlikely(r))
4154+
goto err;
4155+
4156+
r = tfw_msg_write(&it, &req->uri_path);
4157+
if (unlikely(r))
4158+
goto err;
4159+
4160+
r = tfw_msg_write(&it, &fl_end); /* start of Host: header */
4161+
if (unlikely(r))
4162+
goto err;
4163+
41344164
if (auth)
41354165
__h2_msg_hdr_val(&ht->tbl[TFW_HTTP_HDR_H2_AUTHORITY], &host_val);
41364166
else if (host)
41374167
__h2_msg_hdr_val(&ht->tbl[TFW_HTTP_HDR_HOST], &host_val);
4138-
r |= tfw_msg_write(&it, &host_val);
4139-
r |= tfw_msg_write(&it, &crlf);
4168+
4169+
r = tfw_msg_write(&it, &host_val);
4170+
if (unlikely(r))
4171+
goto err;
4172+
4173+
r = tfw_msg_write(&it, &crlf);
4174+
if (unlikely(r))
4175+
goto err;
41404176

41414177
/* Skip host header: it's already written. */
41424178
FOR_EACH_HDR_FIELD_FROM(field, end, req, TFW_HTTP_HDR_REGULAR) {
@@ -4147,19 +4183,25 @@ tfw_h2_adjust_req(TfwHttpReq *req)
41474183
case TFW_HTTP_HDR_HOST:
41484184
continue; /* Already written. */
41494185
case TFW_HTTP_HDR_X_FORWARDED_FOR:
4150-
r |= tfw_msg_write(&it, &h_xff);
4186+
r = tfw_msg_write(&it, &h_xff);
4187+
if (unlikely(r))
4188+
goto err;
41514189
continue;
41524190
case TFW_HTTP_HDR_CONTENT_TYPE:
41534191
if (h_ct_replace) {
4154-
r |= tfw_msg_write(&it, &h_ct);
4192+
r = tfw_msg_write(&it, &h_ct);
4193+
if (unlikely(r))
4194+
goto err;
41554195
continue;
41564196
}
41574197
break;
41584198
case TFW_HTTP_HDR_COOKIE:
41594199
if (!TFW_STR_DUP(field))
41604200
break;
4161-
r |= write_merged_cookie_headers(
4201+
r = write_merged_cookie_headers(
41624202
&ht->tbl[TFW_HTTP_HDR_COOKIE], &it);
4203+
if (unlikely(r))
4204+
goto err;
41634205
continue;
41644206
default:
41654207
break;
@@ -4182,20 +4224,33 @@ tfw_h2_adjust_req(TfwHttpReq *req)
41824224
hval.nchunks++;
41834225
hval.len += chunk->len;
41844226
}
4185-
r |= tfw_msg_write(&it, &hval);
4186-
r |= tfw_msg_write(&it, &dlm);
4227+
r = tfw_msg_write(&it, &hval);
4228+
if (unlikely(r))
4229+
goto err;
4230+
r = tfw_msg_write(&it, &dlm);
4231+
if (unlikely(r))
4232+
goto err;
4233+
41874234
hval.chunks += hval.nchunks;
41884235
hval.nchunks = dup->nchunks - hval.nchunks;
41894236
hval.len = dup->len - hval.len;
4190-
r |= tfw_msg_write(&it, &hval);
41914237

4192-
r |= tfw_msg_write(&it, &crlf);
4238+
r = tfw_msg_write(&it, &hval);
4239+
if (unlikely(r))
4240+
goto err;
4241+
4242+
r = tfw_msg_write(&it, &crlf);
4243+
if (unlikely(r))
4244+
goto err;
41934245
}
41944246
if (unlikely(r))
41954247
goto err;
41964248
}
41974249

4198-
r |= tfw_msg_write(&it, &h_via);
4250+
r = tfw_msg_write(&it, &h_via);
4251+
if (unlikely(r))
4252+
goto err;
4253+
41994254
if (need_cl) {
42004255
h_cl = (TfwStr) {
42014256
.chunks = (TfwStr []) {
@@ -4207,11 +4262,12 @@ tfw_h2_adjust_req(TfwHttpReq *req)
42074262
.len = cl_len,
42084263
.nchunks = 4
42094264
};
4210-
r |= tfw_msg_write(&it, &h_cl);
4265+
r = tfw_msg_write(&it, &h_cl);
4266+
if (unlikely(r))
4267+
goto err;
42114268
}
42124269
/* Finally close headers. */
4213-
r |= tfw_msg_write(&it, &crlf);
4214-
4270+
r = tfw_msg_write(&it, &crlf);
42154271
if (unlikely(r))
42164272
goto err;
42174273

@@ -4259,11 +4315,12 @@ tfw_h2_adjust_req(TfwHttpReq *req)
42594315
}
42604316

42614317
return 0;
4318+
42624319
err:
42634320
ss_skb_queue_purge(&new_head);
4264-
T_DBG3("%s: req [%p] convertation to http1.1 has failed\n",
4265-
__func__, req);
4266-
return -EINVAL;
4321+
T_DBG3("%s: req [%px] convertation to http1.1 has failed"
4322+
" with result (%d)\n", __func__, req, r);
4323+
return r;
42674324
}
42684325

42694326
/*

fw/http2.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Tempesta FW
33
*
4-
* Copyright (C) 2024 Tempesta Technologies, Inc.
4+
* Copyright (C) 2024-2025 Tempesta Technologies, Inc.
55
*
66
* This program is free software; you can redistribute it and/or modify it
77
* under the terms of the GNU General Public License as published by
@@ -360,6 +360,7 @@ void
360360
tfw_h2_closed_streams_shrink(TfwH2Ctx *ctx)
361361
{
362362
TfwStream *cur;
363+
unsigned int max_streams = ctx->lsettings.max_streams;
363364
TfwStreamQueue *closed_streams = &ctx->closed_streams;
364365

365366
T_DBG3("%s: ctx [%p] closed streams num %lu\n", __func__, ctx,
@@ -368,7 +369,9 @@ tfw_h2_closed_streams_shrink(TfwH2Ctx *ctx)
368369
while (1) {
369370
spin_lock(&ctx->lock);
370371

371-
if (closed_streams->num <= TFW_MAX_CLOSED_STREAMS) {
372+
if (closed_streams->num <= TFW_MAX_CLOSED_STREAMS
373+
&& (ctx->streams_num < max_streams
374+
|| !closed_streams->num)) {
372375
spin_unlock(&ctx->lock);
373376
break;
374377
}

0 commit comments

Comments
 (0)