From c5d31ed8bec42e6f80cb752c3295844d67f6b48a Mon Sep 17 00:00:00 2001 From: Amaury Denoyelle Date: Tue, 14 Jun 2022 17:34:53 +0200 Subject: [PATCH] MINOR: qpack: add comments and remove a useless trace Add comments on the decoding function to facilitate code analysis. Also remove the qpack_debug_hexdump() which prints the whole left buffer on each header parsing. With large HEADERS frame payload, QPACK traces are complicated to debug with this statement. --- include/haproxy/qpack-dec.h | 10 +++++----- src/qpack-dec.c | 13 ++++++++++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/include/haproxy/qpack-dec.h b/include/haproxy/qpack-dec.h index b847c8027..991e1a9f7 100644 --- a/include/haproxy/qpack-dec.h +++ b/include/haproxy/qpack-dec.h @@ -29,11 +29,11 @@ struct http_hdr; *Nothing to see with the RFC. */ enum { - QPACK_ERR_NONE = 0, - QPACK_ERR_RIC, - QPACK_ERR_DB, - QPACK_ERR_TRUNCATED, - QPACK_ERR_HUFFMAN, + QPACK_ERR_NONE = 0, /* no error */ + QPACK_ERR_RIC, /* cannot decode Required Insert Count prefix field */ + QPACK_ERR_DB, /* cannot decode Delta Base prefix field */ + QPACK_ERR_TRUNCATED, /* truncated stream */ + QPACK_ERR_HUFFMAN, /* huffman decoding error */ }; struct qpack_dec { diff --git a/src/qpack-dec.c b/src/qpack-dec.c index 3ca2eda65..82ffd81e0 100644 --- a/src/qpack-dec.c +++ b/src/qpack-dec.c @@ -181,8 +181,13 @@ static int qpack_decode_fs_pfx(uint64_t *enc_ric, uint64_t *db, int *sign_bit, return 0; } -/* Decode a field section from bytes length buffer. - * Produces the output into buffer. +/* Decode a field section from the buffer of bytes. Each parsed + * header is inserted into and uses as a storage for some elements + * pointing into it. An end marker is inserted at the end of the list with + * empty strings as name/value. + * + * Returns 0 on success. In case of error, a negative code QPACK_ERR_* is + * returned. */ int qpack_decode_fs(const unsigned char *raw, size_t len, struct buffer *tmp, struct http_hdr *list) @@ -195,6 +200,7 @@ int qpack_decode_fs(const unsigned char *raw, size_t len, struct buffer *tmp, qpack_debug_hexdump(stderr, "[QPACK-DEC-FS] ", (const char *)raw, 0, len); + /* parse field section prefix */ ret = qpack_decode_fs_pfx(&enc_ric, &db, &s, &raw, &len); if (ret < 0) { qpack_debug_printf(stderr, "##ERR@%d(%d)\n", __LINE__, ret); @@ -206,9 +212,10 @@ int qpack_decode_fs(const unsigned char *raw, size_t len, struct buffer *tmp, (unsigned long long)enc_ric, (unsigned long long)db, !!s); /* Decode field lines */ while (len) { - qpack_debug_hexdump(stderr, "raw ", (const char *)raw, 0, len); + /* parse field line representation */ efl_type = *raw & QPACK_EFL_BITMASK; qpack_debug_printf(stderr, "efl_type=0x%02x\n", efl_type); + if (efl_type == QPACK_LFL_WPBNM) { /* Literal field line with post-base name reference */ uint64_t index __maybe_unused, length;