Skip to content

Commit

Permalink
Cosmetic patсh for __tfw_http_msg_expand_from_pool()
Browse files Browse the repository at this point in the history
Moving body logic extracted to function and do it
only if we have the body. Pointer to body never be
NULL more safer not use it wthout check the body
length.
  • Loading branch information
const-t authored and EvgeniiMekhanik committed May 26, 2023
1 parent 2055a7b commit 2417cda
Showing 1 changed file with 42 additions and 21 deletions.
63 changes: 42 additions & 21 deletions fw/http_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,41 @@ tfw_http_msg_setup_transform_pool(TfwHttpTransIter *mit, TfwPool* pool)
return 0;
}

/*
* Move body to @nskb if body located in current skb.
*/
static inline int
__tfw_http_msg_move_body(TfwHttpResp *resp, struct sk_buff *nskb)
{
TfwMsgIter *it = &resp->mit.iter;
struct sk_buff **body;
int r, frag;
char *p;

if (test_bit(TFW_HTTP_B_CHUNKED, resp->flags)) {
TfwStream *stream = resp->stream;

p = stream->parser.body_start_data;
body = &stream->parser.body_start_skb;
} else {
p = TFW_STR_CHUNK(&resp->body, 0)->data;
body = &resp->body.skb;
}

if (*body != it->skb)
return 0;

if ((r = ss_skb_find_frag_by_offset(*body, p, &frag)))
return r;

/* Move body to the next skb. */
ss_skb_move_frags(it->skb, nskb, frag,
skb_shinfo(it->skb)->nr_frags - frag);
*body = nskb;

return 0;
}

/*
* Expand message by @str increasing size of current paged fragment or add
* new paged fragment using @pool if room in current pool's chunk is not enough.
Expand Down Expand Up @@ -1442,32 +1477,18 @@ __tfw_http_msg_expand_from_pool(TfwHttpResp *resp, const TfwStr *str,

if (unlikely(skb_room == 0 || nr_frags == MAX_SKB_FRAGS))
{
struct sk_buff *nskb, **body;
char *p;

if (test_bit(TFW_HTTP_B_CHUNKED, resp->flags)) {
TfwStream *stream = resp->stream;
struct sk_buff *nskb = ss_skb_alloc(0);

p = stream->parser.body_start_data;
body = &stream->parser.body_start_skb;
} else {
p = TFW_STR_CHUNK(&resp->body, 0)->data;
body = &resp->body.skb;
}

nskb = ss_skb_alloc(0);
if (!nskb)
return -ENOMEM;

if (*body == it->skb) {
int frag;

if ((r = ss_skb_find_frag_by_offset(*body, p, &frag)))
if (resp->body.len > 0) {
r = __tfw_http_msg_move_body(resp,
nskb);
if (unlikely(r)) {
T_WARN("Error during moving body");
return r;
/* Move body to the next skb. */
ss_skb_move_frags(it->skb, nskb, frag,
nr_frags - frag);
*body = nskb;
}
}

skb_shinfo(nskb)->tx_flags =
Expand Down

0 comments on commit 2417cda

Please sign in to comment.