Skip to content

Commit 9498803

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 5f98341 commit 9498803

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
@@ -3516,6 +3516,18 @@ tfw_hpack_hdr_expand(TfwHttpResp *__restrict resp, TfwStr *__restrict hdr,
35163516
return tfw_hpack_str_expand(mit, iter, skb_head, &s_val, NULL);
35173517
}
35183518

3519+
static inline int
3520+
__tfw_hpack_check_and_split_hdr(TfwStr *__restrict hdr, TfwStr *h_name,
3521+
TfwStr *h_val, bool trans)
3522+
{
3523+
if (unlikely(TFW_STR_PLAIN(hdr) || TFW_STR_DUP(hdr)
3524+
|| !tfw_http_hdr_split(hdr, h_name, h_val, trans)
3525+
|| TFW_STR_EMPTY(h_name)))
3526+
return -EINVAL;
3527+
3528+
return 0;
3529+
}
3530+
35193531
/**
35203532
* Perform encoding of the header @hdr into the HTTP/2 HPACK format.
35213533
*
@@ -3544,14 +3556,6 @@ __tfw_hpack_encode(TfwHttpResp *__restrict resp, TfwStr *__restrict hdr,
35443556
bool name_indexed = true;
35453557
TfwStr h_name = {}, h_val = {};
35463558

3547-
#define __HDR_SPLIT(hdr) \
3548-
do { \
3549-
if (unlikely(TFW_STR_PLAIN(hdr) || TFW_STR_DUP(hdr) \
3550-
|| !tfw_http_hdr_split(hdr, &h_name, &h_val, trans) \
3551-
|| TFW_STR_EMPTY(&h_name))) \
3552-
return -EINVAL; \
3553-
} while(0)
3554-
35553559
if (WARN_ON_ONCE(!hdr || TFW_STR_EMPTY(hdr)))
35563560
return -EINVAL;
35573561

@@ -3563,16 +3567,16 @@ do { \
35633567
T_DBG_PRINT_HPACK_RBTREE(tbl);
35643568

35653569
if (!st_full_index && dyn_indexing) {
3566-
__HDR_SPLIT(hdr);
3570+
r = __tfw_hpack_check_and_split_hdr(hdr, &h_name, &h_val,
3571+
trans);
3572+
if (unlikely(r))
3573+
return r;
3574+
35673575
assert_spin_locked(&conn->sk->sk_lock.slock);
35683576
r = tfw_hpack_encoder_index(tbl, &h_name, &h_val,
35693577
&index, resp->flags);
3570-
if (r < 0)
3571-
return r;
35723578
}
35733579

3574-
if (TFW_STR_PLAIN(hdr))
3575-
35763580
if (st_full_index || HPACK_IDX_RES(r) == HPACK_IDX_ST_FOUND) {
35773581
/*
35783582
* The full index (whether static or dynamic) always takes
@@ -3621,17 +3625,19 @@ do { \
36213625

36223626
encode:
36233627
if (use_pool) {
3624-
if (!dyn_indexing)
3625-
__HDR_SPLIT(hdr);
3628+
if (!dyn_indexing) {
3629+
r = __tfw_hpack_check_and_split_hdr(hdr, &h_name,
3630+
&h_val, trans);
3631+
if (unlikely(r < 0))
3632+
return r;
3633+
}
36263634
r = tfw_hpack_hdr_add(resp, &h_name, &h_val, &idx,
36273635
name_indexed, trans);
36283636
} else {
36293637
r = tfw_hpack_hdr_expand(resp, hdr, &idx, name_indexed);
36303638
}
36313639

36323640
return r;
3633-
3634-
#undef __HDR_SPLIT
36353641
}
36363642

36373643
int

0 commit comments

Comments
 (0)