Skip to content

Commit b36a343

Browse files
Fix according review
- Remove garbage - Change macros to `static inline` function. - We should not change return code of `tfw_hpack_encoder_index` beacuse if we can't add new header to the table we just not set HPACK_IDX_FLAG_ADD to result. But we don't need to check that return code of `tfw_hpack_encoder_index` is greater or equal to zero because it is always true.
1 parent 5130dab commit b36a343

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

fw/hpack.c

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3521,6 +3521,18 @@ tfw_hpack_hdr_expand(TfwHttpResp *__restrict resp, TfwStr *__restrict hdr,
35213521
return tfw_hpack_str_expand(mit, iter, skb_head, &s_val, NULL);
35223522
}
35233523

3524+
static inline int
3525+
__tfw_hpack_check_and_split_hdr(TfwStr *__restrict hdr, TfwStr *h_name,
3526+
TfwStr *h_val, bool trans)
3527+
{
3528+
if (unlikely(TFW_STR_PLAIN(hdr) || TFW_STR_DUP(hdr)
3529+
|| !tfw_http_hdr_split(hdr, h_name, h_val, trans)
3530+
|| TFW_STR_EMPTY(h_name)))
3531+
return -EINVAL;
3532+
3533+
return 0;
3534+
}
3535+
35243536
/**
35253537
* Perform encoding of the header @hdr into the HTTP/2 HPACK format.
35263538
*
@@ -3549,14 +3561,6 @@ __tfw_hpack_encode(TfwHttpResp *__restrict resp, TfwStr *__restrict hdr,
35493561
bool name_indexed = true;
35503562
TfwStr h_name = {}, h_val = {};
35513563

3552-
#define __HDR_SPLIT(hdr) \
3553-
do { \
3554-
if (unlikely(TFW_STR_PLAIN(hdr) || TFW_STR_DUP(hdr) \
3555-
|| !tfw_http_hdr_split(hdr, &h_name, &h_val, trans) \
3556-
|| TFW_STR_EMPTY(&h_name))) \
3557-
return -EINVAL; \
3558-
} while(0)
3559-
35603564
if (WARN_ON_ONCE(!hdr || TFW_STR_EMPTY(hdr)))
35613565
return -EINVAL;
35623566

@@ -3568,16 +3572,16 @@ do { \
35683572
T_DBG_PRINT_HPACK_RBTREE(tbl);
35693573

35703574
if (!st_full_index && dyn_indexing) {
3571-
__HDR_SPLIT(hdr);
3575+
r = __tfw_hpack_check_and_split_hdr(hdr, &h_name, &h_val,
3576+
trans);
3577+
if (unlikely(r))
3578+
return r;
3579+
35723580
assert_spin_locked(&conn->sk->sk_lock.slock);
35733581
r = tfw_hpack_encoder_index(tbl, &h_name, &h_val,
35743582
&index, resp->flags);
3575-
if (r < 0)
3576-
return r;
35773583
}
35783584

3579-
if (TFW_STR_PLAIN(hdr))
3580-
35813585
if (st_full_index || HPACK_IDX_RES(r) == HPACK_IDX_ST_FOUND) {
35823586
/*
35833587
* The full index (whether static or dynamic) always takes
@@ -3626,17 +3630,19 @@ do { \
36263630

36273631
encode:
36283632
if (use_pool) {
3629-
if (!dyn_indexing)
3630-
__HDR_SPLIT(hdr);
3633+
if (!dyn_indexing) {
3634+
r = __tfw_hpack_check_and_split_hdr(hdr, &h_name,
3635+
&h_val, trans);
3636+
if (unlikely(r < 0))
3637+
return r;
3638+
}
36313639
r = tfw_hpack_hdr_add(resp, &h_name, &h_val, &idx,
36323640
name_indexed, trans);
36333641
} else {
36343642
r = tfw_hpack_hdr_expand(resp, hdr, &idx, name_indexed);
36353643
}
36363644

36373645
return r;
3638-
3639-
#undef __HDR_SPLIT
36403646
}
36413647

36423648
int

0 commit comments

Comments
 (0)