Skip to content

Commit def53f2

Browse files
Fix according review
- Codestyle fixes. - Add comments - Move `-tfw_h2_hpack_encode_trailer_headers` to http2.c and make it static.
1 parent 0999ce9 commit def53f2

File tree

7 files changed

+74
-74
lines changed

7 files changed

+74
-74
lines changed

fw/cache.c

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,16 @@ __tfw_dbg_dump_ce(const TfwCacheEntry *ce)
203203
#define TFW_CSTR_SPEC_IDX 0x2
204204
/*
205205
* TfwCStr contains header, which should be skipped for http2 responses
206-
* constructed from cache.
206+
* constructed from cache. We skip transfer encoding header, when we
207+
* build response from cache for HTTP2 request.
208+
* RFC 9113 8.1:
209+
* HTTP/2 uses DATA frames to carry message content. The chunked
210+
* transfer encoding defined in Section 7.1 of [HTTP/1.1] cannot be
211+
* used in HTTP/2; see Section 8.2.2.
207212
*/
208213
#define TFW_CSTR_SKIP_FOR_H2 0x4
209214

210-
/*
211-
* TfwCStr contains trailer.
212-
*/
215+
/* TfwCStr contains trailer. */
213216
#define TFW_CSTR_TRAILER 0x8
214217

215218
/**
@@ -1065,8 +1068,8 @@ do { \
10651068

10661069
*p += TFW_CSTR_HDRLEN;
10671070
r = write_actor(db, trec, resp, p, s->len, &dc_iter);
1068-
if (unlikely(r))
1069-
break;
1071+
if (unlikely(r))
1072+
break;
10701073

10711074
dc_iter.skip = skip;
10721075
}
@@ -2753,7 +2756,8 @@ tfw_cache_purge_method(TfwHttpReq *req)
27532756

27542757
/* Deny PURGE requests by default. */
27552758
if (!(cache_cfg.cache && g_vhost->cache_purge
2756-
&& g_vhost->cache_purge_acl)) {
2759+
&& g_vhost->cache_purge_acl))
2760+
{
27572761
tfw_http_send_err_resp(req, 403, "purge: not configured");
27582762
return -EINVAL;
27592763
}
@@ -2851,14 +2855,6 @@ tfw_cache_build_resp_body(TDB *db, TdbVRec *trec, TfwMsgIter *it, char *p,
28512855
* Finish chunked body encoding. Add 0\r\n
28522856
* after chunked body.
28532857
*/
2854-
TfwStr b_len = {
2855-
.chunks = (TfwStr []){
2856-
{.data = S_ZERO, .len = SLEN(S_ZERO)},
2857-
{.data = S_CRLF, .len = SLEN(S_CRLF)}
2858-
},
2859-
.len = SLEN(S_ZERO S_CRLF),
2860-
.nchunks = 2
2861-
};
28622858
bool sh_frag = h2 ? false : true;
28632859
int r;
28642860

@@ -2941,6 +2937,11 @@ tfw_cache_build_resp_body(TDB *db, TdbVRec *trec, TfwMsgIter *it, char *p,
29412937
}
29422938

29432939
if (chunked_body) {
2940+
static TfwStr b_len = {
2941+
.data = S_ZERO S_CRLF,
2942+
.len = SLEN(S_ZERO S_CRLF)
2943+
};
2944+
29442945
r = tfw_http_msg_expand_data(it, &it->skb_head,
29452946
&g_crlf, NULL);
29462947
if (unlikely(r))
@@ -3057,7 +3058,6 @@ tfw_cache_build_resp(TfwHttpReq *req, TfwCacheEntry *ce, long age)
30573058
if (!(resp = tfw_http_msg_alloc_resp(req)))
30583059
goto out;
30593060

3060-
30613061
/* Copy version information and flags */
30623062
resp->version = ce->version;
30633063
tfw_http_copy_flags(resp->flags, ce->hmflags);
@@ -3171,15 +3171,17 @@ tfw_cache_build_resp(TfwHttpReq *req, TfwCacheEntry *ce, long age)
31713171
/* Fill skb with body from cache for HTTP/2 or HTTP/1.1 response. */
31723172
BUG_ON(p != TDB_PTR(db->hdr, ce->body));
31733173
if ((ce->body_len || chunked_body)
3174-
&& req->method != TFW_HTTP_METH_HEAD) {
3174+
&& req->method != TFW_HTTP_METH_HEAD)
3175+
{
31753176
if (tfw_cache_build_resp_body(db, trec, it, p, ce->body_len,
31763177
h2_mode, chunked_body))
31773178
goto free;
31783179
}
31793180
resp->content_length = ce->body_len;
31803181

31813182
if (unlikely(ce->trailer_off < ce->hdr_num)
3182-
&& req->method != TFW_HTTP_METH_HEAD) {
3183+
&& req->method != TFW_HTTP_METH_HEAD)
3184+
{
31833185
unsigned long t_len = 0;
31843186

31853187
if (h2_mode)

fw/http.c

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5080,47 +5080,6 @@ tfw_h2_hpack_encode_headers(TfwHttpResp *resp, const TfwHdrMods *h_mods)
50805080
return 0;
50815081
}
50825082

5083-
int
5084-
tfw_h2_hpack_encode_trailer_headers(TfwHttpResp *resp)
5085-
{
5086-
TfwHttpHdrMap *map = resp->mit.map;
5087-
TfwHttpHdrTbl *ht = resp->h_tbl;
5088-
unsigned int i;
5089-
int r;
5090-
5091-
for (i = map->trailer_idx; i < map->count; ++i) {
5092-
unsigned short hid = map->index[i].idx;
5093-
unsigned short d_num = map->index[i].d_idx;
5094-
TfwStr *tgt = &ht->tbl[hid];
5095-
5096-
if (TFW_STR_DUP(tgt))
5097-
tgt = TFW_STR_CHUNK(tgt, d_num);
5098-
5099-
if (WARN_ON_ONCE(!tgt
5100-
|| TFW_STR_EMPTY(tgt)
5101-
|| TFW_STR_DUP(tgt)))
5102-
return -EINVAL;
5103-
5104-
T_DBG3("%s: hid=%hu, d_num=%hu, nchunks=%u\n",
5105-
__func__, hid, d_num, ht->tbl[hid].nchunks);
5106-
5107-
/*
5108-
* 'Server' header must be replaced; thus, remove the original
5109-
* header (and all its duplicates) skipping it here; the new
5110-
* header will be written later, during new headers' addition
5111-
* stage.
5112-
*/
5113-
if (hid == TFW_HTTP_HDR_SERVER)
5114-
continue;
5115-
5116-
r = tfw_hpack_transform(resp, tgt);
5117-
if (unlikely(r))
5118-
return r;
5119-
}
5120-
5121-
return 0;
5122-
}
5123-
51245083
/**
51255084
* Split response body stored locally. Allocate a new skb and put body there
51265085
* by fragments. Every skb fragment has size of single page and has frame

fw/http.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,6 @@ int tfw_h2_resp_add_loc_hdrs(TfwHttpResp *resp, const TfwHdrMods *h_mods,
766766
int tfw_h2_resp_status_write(TfwHttpResp *resp, unsigned short status,
767767
bool use_pool, bool cache);
768768
int tfw_h2_resp_encode_headers(TfwHttpResp *resp);
769-
int tfw_h2_hpack_encode_trailer_headers(TfwHttpResp *resp);
770769
/*
771770
* Functions to send an HTTP error response to a client.
772771
*/

fw/http2.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,47 @@ tfw_h2_req_unlink_and_close_stream(TfwHttpReq *req)
480480
spin_unlock(&ctx->lock);
481481
}
482482

483+
static int
484+
tfw_h2_hpack_encode_trailer_headers(TfwHttpResp *resp)
485+
{
486+
TfwHttpHdrMap *map = resp->mit.map;
487+
TfwHttpHdrTbl *ht = resp->h_tbl;
488+
unsigned int i;
489+
int r;
490+
491+
for (i = map->trailer_idx; i < map->count; ++i) {
492+
unsigned short hid = map->index[i].idx;
493+
unsigned short d_num = map->index[i].d_idx;
494+
TfwStr *tgt = &ht->tbl[hid];
495+
496+
if (TFW_STR_DUP(tgt))
497+
tgt = TFW_STR_CHUNK(tgt, d_num);
498+
499+
if (WARN_ON_ONCE(!tgt
500+
|| TFW_STR_EMPTY(tgt)
501+
|| TFW_STR_DUP(tgt)))
502+
return -EINVAL;
503+
504+
T_DBG3("%s: hid=%hu, d_num=%hu, nchunks=%u\n",
505+
__func__, hid, d_num, ht->tbl[hid].nchunks);
506+
507+
/*
508+
* 'Server' header must be replaced; thus, remove the original
509+
* header (and all its duplicates) skipping it here; the new
510+
* header will be written later, during new headers' addition
511+
* stage.
512+
*/
513+
if (hid == TFW_HTTP_HDR_SERVER)
514+
continue;
515+
516+
r = tfw_hpack_transform(resp, tgt);
517+
if (unlikely(r))
518+
return r;
519+
}
520+
521+
return 0;
522+
}
523+
483524
int
484525
tfw_h2_stream_xmit_prepare_resp(TfwStream *stream)
485526
{
@@ -536,7 +577,8 @@ tfw_h2_stream_xmit_prepare_resp(TfwStream *stream)
536577
* on HEAD request.
537578
*/
538579
if (test_bit(TFW_HTTP_B_CHUNKED, resp->flags)
539-
&& !test_bit(TFW_HTTP_B_VOID_BODY, resp->flags)) {
580+
&& !test_bit(TFW_HTTP_B_VOID_BODY, resp->flags))
581+
{
540582
r = tfw_http_msg_cutoff_body_chunks(resp);
541583
if (unlikely(r)) {
542584
T_WARN("Failed to encode body");

fw/http_frame.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1897,7 +1897,6 @@ tfw_h2_calc_frame_flags(TfwStream *stream, TfwFrameType type,
18971897
&& type == HTTP2_HEADERS && trailers)
18981898
flags |= HTTP2_F_END_STREAM;
18991899

1900-
19011900
if (!stream->xmit.h_len && type != HTTP2_DATA && !trailers)
19021901
flags |= HTTP2_F_END_HEADERS;
19031902

fw/http_parser.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,6 @@ __FSM_STATE(st, cold) { \
467467
__FSM_JMP(RGen_HdrOtherN); \
468468
}
469469

470-
471470
#define __FSM_TX_AF_OWS_LAMBDA(st, st_next, lambda) \
472471
__FSM_STATE(st, cold) { \
473472
if (likely(c == ':')) { \
@@ -5331,9 +5330,9 @@ tfw_http_parse_req(void *req_data, unsigned char *data, unsigned int len,
53315330
&& C8_INT_LCM(p, 't', 'r', 'a', 'i',
53325331
'l', 'e', 'r', ':'))
53335332
{
5334-
__msg_hdr_chunk_fixup(data, __data_off(p + 8));
5333+
__msg_hdr_chunk_fixup(data, __data_off(p + 7));
53355334
parser->_i_st = &&Req_HdrTrailerV;
5336-
p += 8;
5335+
p += 7;
53375336
__FSM_MOVE_hdr_fixup(RGen_LWS, 1);
53385337
}
53395338
__FSM_MOVE(Req_HdrT);
@@ -11245,17 +11244,17 @@ __resp_parse_cache_control(TfwHttpResp *resp, unsigned char *data, size_t len)
1124511244

1124611245
__FSM_START(parser->_i_st);
1124711246

11248-
/*
11249-
* According RFC 7230 4.1.2:
11250-
* A sender MUST NOT generate a trailer that contains response
11251-
* control data (e.g., see Section 7.1 of [RFC7231]).
11252-
*/
11253-
if (unlikely(test_bit(TFW_HTTP_B_HEADERS_PARSED, resp->flags)))
11254-
return r;
11255-
1125611247
parser->cc_dir_flag = 0;
1125711248

1125811249
__FSM_STATE(Resp_I_CC_start) {
11250+
/*
11251+
* According RFC 7230 4.1.2:
11252+
* A sender MUST NOT generate a trailer that contains response
11253+
* control data (e.g., see Section 7.1 of [RFC7231]).
11254+
*/
11255+
if (unlikely(test_bit(TFW_HTTP_B_HEADERS_PARSED, resp->flags)))
11256+
return r;
11257+
1125911258
/* Spaces already skipped by RGen_LWS */
1126011259
/* Leading comma allowed per RFC 7230 Section 7 */
1126111260
if (c == ',')

fw/ss_skb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ ss_skb_data_ptr_by_offset(struct sk_buff *skb, unsigned int off)
429429
if (ss_skb_is_within_fragment(begin, begin + off, end))
430430
return begin + off;
431431

432-
off -= (end - begin);
432+
off -= end - begin;
433433
}
434434

435435
return NULL;

0 commit comments

Comments
 (0)