Skip to content

Commit 5499e1b

Browse files
committed
Got rid off tfw_hpack_decode_int().
Length of header name and its size(HPACK int) strored in `TfwCStr`.
1 parent a6ff061 commit 5499e1b

File tree

2 files changed

+26
-53
lines changed

2 files changed

+26
-53
lines changed

fw/cache.c

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,15 @@ __tfw_dbg_dump_ce(const TfwCacheEntry *ce)
187187
* String header for cache entries used for TfwStr serialization.
188188
*
189189
* @flags - TFW_CSTR_DUPLICATE and TFW_CSTR_HPACK_IDX or zero;
190-
* @len - string length or number of duplicates;
190+
* @name_len - Header name length. Used for raw headers;
191+
* @name_len_sz - HPACK int size of @name_len;
191192
* @idx - HPACK static index or index of special header;
192193
*/
193194
typedef struct {
194195
unsigned long flags : 8,
195-
len : 48,
196+
name_len: 11,
197+
name_len_sz : 2,
198+
len : 35,
196199
idx : 8;
197200
} TfwCStr;
198201

@@ -766,12 +769,16 @@ tfw_cache_set_status(TDB *db, TfwCacheEntry *ce, TfwHttpResp *resp,
766769
}
767770

768771
static bool
769-
tfw_cache_skip_hdr(TfwCStr *str, char *p, const TfwHdrMods *h_mods)
772+
tfw_cache_skip_hdr(const TfwCStr *str, char *p, const TfwHdrMods *h_mods)
770773
{
771-
unsigned int len, i;
774+
unsigned int i;
772775
const TfwHdrModsDesc *desc;
773-
const char *last = p + str->len;
774-
TfwStr hdr = {};
776+
/*
777+
* Move to beggining of the header name. Skip first byte of HPACK
778+
* string and name length size.
779+
*/
780+
TfwStr hdr = { .data = p + str->name_len_sz + 1,
781+
.len = str->name_len };
775782

776783
/* Fast path for special headers */
777784
if (str->flags & TFW_CSTR_SPEC_IDX) {
@@ -789,22 +796,6 @@ tfw_cache_skip_hdr(TfwCStr *str, char *p, const TfwHdrMods *h_mods)
789796
return test_bit(hpack_idx, h_mods->s_tbl);
790797
}
791798

792-
p++;
793-
len = *p++ & 0x7F;
794-
795-
if (unlikely(len == 0))
796-
return true;
797-
798-
if (unlikely(len == 0x7F)
799-
&& unlikely(tfw_hpack_decode_int(&p, last, &len)))
800-
{
801-
T_WARN("Error while decoding hpack int");
802-
return true;
803-
}
804-
805-
hdr.data = p;
806-
hdr.len = len;
807-
808799
for (i = h_mods->spec_num; i < h_mods->sz; ++i) {
809800
int cmplen;
810801
char* mod_hdr_name;
@@ -1234,11 +1225,13 @@ do { \
12341225
ce->hdr_len += TFW_CSTR_HDRLEN; \
12351226
} while (0)
12361227

1237-
#define CSTR_WRITE_HDR(f, l, i) \
1238-
do { \
1239-
cs->flags = f; \
1240-
cs->len = l; \
1241-
cs->idx = i; \
1228+
#define CSTR_WRITE_HDR(f, l, nl, i) \
1229+
do { \
1230+
cs->flags = f; \
1231+
cs->len = l; \
1232+
cs->name_len = nl; \
1233+
cs->name_len_sz = tfw_hpack_int_size(nl, 0x7f); \
1234+
cs->idx = i; \
12421235
} while (0)
12431236

12441237
/**
@@ -1574,9 +1567,9 @@ tfw_cache_h2_copy_hdr(TfwCacheEntry *ce, TfwHttpResp *resp, int hid, char **p,
15741567
CSTR_MOVE_HDR();
15751568
if (hid >= TFW_HTTP_HDR_REGULAR && hid < TFW_HTTP_HDR_RAW)
15761569
CSTR_WRITE_HDR(TFW_CSTR_SPEC_IDX | TFW_CSTR_DUPLICATE,
1577-
hdr->nchunks, hid);
1570+
hdr->nchunks, 0, hid);
15781571
else
1579-
CSTR_WRITE_HDR(TFW_CSTR_DUPLICATE, hdr->nchunks,
1572+
CSTR_WRITE_HDR(TFW_CSTR_DUPLICATE, hdr->nchunks, 0,
15801573
st_index);
15811574
}
15821575

@@ -1619,9 +1612,10 @@ tfw_cache_h2_copy_hdr(TfwCacheEntry *ce, TfwHttpResp *resp, int hid, char **p,
16191612

16201613
if (hid >= TFW_HTTP_HDR_REGULAR && hid < TFW_HTTP_HDR_RAW)
16211614
CSTR_WRITE_HDR(TFW_CSTR_SPEC_IDX,
1622-
ce->hdr_len - prev_len, hid);
1615+
ce->hdr_len - prev_len, 0, hid);
16231616
else
1624-
CSTR_WRITE_HDR(0, ce->hdr_len - prev_len, st_index);
1617+
CSTR_WRITE_HDR(0, ce->hdr_len - prev_len, s_nm.len,
1618+
st_index);
16251619
}
16261620

16271621
T_DBG3("%s: p=[%p], trec=[%p], ce->hdr_len='%u', tot_len='%zu'\n",
@@ -1672,7 +1666,7 @@ tfw_cache_h2_add_hdr(TfwCacheEntry *ce, char **p, TdbVRec **trec,
16721666
if (tfw_cache_h2_copy_str(&ce->hdr_len, p, trec, val, tot_len))
16731667
return -ENOMEM;
16741668

1675-
CSTR_WRITE_HDR(0, ce->hdr_len - prev_len - TFW_CSTR_HDRLEN, st_idx);
1669+
CSTR_WRITE_HDR(0, ce->hdr_len - prev_len - TFW_CSTR_HDRLEN, 0, st_idx);
16761670

16771671
return ce->hdr_len - prev_len;
16781672
}

fw/hpack.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -326,26 +326,5 @@ tfw_hpack_int_size(unsigned long index, unsigned short max)
326326

327327
return size;
328328
}
329-
330-
static inline int
331-
tfw_hpack_decode_int(char **p, const char *last, unsigned int *val)
332-
{
333-
char *src = *p;
334-
unsigned int c, m = 0;
335-
336-
do {
337-
if (src >= last)
338-
return 0;
339-
c = *src++;
340-
*val += (c & 127) << m;
341-
m += 7;
342-
if (*val > HPACK_INT_LIMIT)
343-
return -EINVAL;
344-
} while (c > 127);
345-
346-
*p = src;
347-
348-
return 0;
349-
}
350329
unsigned short tfw_hpack_find_hdr_idx(const TfwStr *hdr);
351330
#endif /* __TFW_HPACK_H__ */

0 commit comments

Comments
 (0)