Skip to content

Commit

Permalink
fw/http: While splitting linear data
Browse files Browse the repository at this point in the history
during h1->h2 transformation, reassign body TfwStr skb if necessary

Signed-off-by: Petr Vyazovik <[email protected]>
  • Loading branch information
s0nx committed Mar 31, 2023
1 parent 15e235a commit 55f56a4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 18 deletions.
15 changes: 0 additions & 15 deletions fw/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -4803,21 +4803,6 @@ tfw_h2_append_predefined_body(TfwHttpResp *resp, unsigned int stream_id,
return 0;
}

static TfwStr*
__tfw_h2_get_body_start(TfwHttpResp* resp)
{
TfwStr *c, *end;

TFW_STR_FOR_EACH_CHUNK(c, &resp->body, end) {
/* Skip chunking data such as chunk size and extension */
if (!(c->flags & TFW_STR_CUT))
return c;
continue;
}

return NULL;
}

/**
* Split response into http/2 frames with respect to remote peer MAX_FRAME_SIZE
* settings. Both HEADERS and DATA frames require framing or peer will reject
Expand Down
17 changes: 17 additions & 0 deletions fw/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,23 @@ typedef struct {
(r)->body.len - (r)->stream->parser.cut_len : \
(r)->body.len


static inline TfwStr*
__tfw_h2_get_body_start(TfwHttpResp* resp)
{
TfwStr *c, *end;

TFW_STR_FOR_EACH_CHUNK(c, &resp->body, end) {
/* Skip chunking data such as chunk size and extension */
if (!(c->flags & TFW_STR_CUT))
return c;
continue;
}

return NULL;
}


#define __FOR_EACH_HDR_FIELD(pos, end, msg, soff, eoff) \
for ((pos) = &(msg)->h_tbl->tbl[soff], \
(end) = &(msg)->h_tbl->tbl[eoff]; \
Expand Down
28 changes: 25 additions & 3 deletions fw/http_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1525,6 +1525,17 @@ __tfw_h2_msg_shrink_frags(TfwMsgIter *it, const char *body,
}
}

static void
tfw_h2_body_skb_set(TfwHttpResp *resp, struct sk_buff *nskb)
{
if (test_bit(TFW_HTTP_B_CHUNKED, resp->flags)) {
TfwStr *h2_body = __tfw_h2_get_body_start(resp);
h2_body->skb = nskb;
} else {
resp->body.skb = nskb;
}
}

/*
* Delete SKBs and paged fragments related to @resp that contains response
* headers. SKBs and fragments will be "unlinked" and placed to @cleanup.
Expand Down Expand Up @@ -1552,9 +1563,9 @@ tfw_h2_msg_cutoff_headers(TfwHttpResp *resp, TfwHttpRespCleanup* cleanup)

if ((begin <= off) && (end >= off)) {
it->frag = -1;
/* We would end up here if the start of the body or
* the end of CRLF lies within the linear data area
* of the current @it->skb
/* We would end up here if the start of the body
* or the end of CRLF lies within the linear
* data area of the current @it->skb
*/
ret = ss_skb_linear_transform(it->skb,
&nskb_head, body);
Expand All @@ -1569,6 +1580,17 @@ tfw_h2_msg_cutoff_headers(TfwHttpResp *resp, TfwHttpRespCleanup* cleanup)
ss_skb_queue_tail(&cleanup->skb_head,
it->skb);
it->skb = nskb_head;
if (body) {
/*
* If the original @it->skb
* has been replaced, we need
* to reassign an SKB in body
* TfwStr or h2 message framing
* would be broken.
*/
tfw_h2_body_skb_set(resp,
nskb_head);
}
}
break;
}
Expand Down

0 comments on commit 55f56a4

Please sign in to comment.