MINOR: h2: add a bit-based frame type representation

This will ease checks among sets of frames.
This commit is contained in:
Willy Tarreau 2018-12-21 14:56:57 +01:00
parent 3bf6918cb2
commit deab244dc1

View File

@ -82,6 +82,26 @@ enum h2_ft {
H2_FT_ENTRIES /* must be last */
} __attribute__((packed));
/* frame types, turned to bits or bit fields */
enum {
/* one bit per frame type */
H2_FT_DATA_BIT = 1U << H2_FT_DATA,
H2_FT_HEADERS_BIT = 1U << H2_FT_HEADERS,
H2_FT_PRIORITY_BIT = 1U << H2_FT_PRIORITY,
H2_FT_RST_STREAM_BIT = 1U << H2_FT_RST_STREAM,
H2_FT_SETTINGS_BIT = 1U << H2_FT_SETTINGS,
H2_FT_PUSH_PROMISE_BIT = 1U << H2_FT_PUSH_PROMISE,
H2_FT_PING_BIT = 1U << H2_FT_PING,
H2_FT_GOAWAY_BIT = 1U << H2_FT_GOAWAY,
H2_FT_WINDOW_UPDATE_BIT = 1U << H2_FT_WINDOW_UPDATE,
H2_FT_CONTINUATION_BIT = 1U << H2_FT_CONTINUATION,
/* padded frames */
H2_FT_PADDED_MASK = (1U << H2_FT_DATA) | (1U << H2_FT_HEADERS) | (1U << H2_FT_PUSH_PROMISE),
/* flow controlled frames */
H2_FT_FC_MASK = (1U << H2_FT_DATA),
};
/* flags defined for each frame type */
// RFC7540 #6.1
@ -110,6 +130,9 @@ enum h2_ft {
// RFC7540 #6.8 : GOAWAY defines no flags
// RFC7540 #6.9 : WINDOW_UPDATE defines no flags
// PADDED is the exact same among DATA, HEADERS and PUSH_PROMISE (8)
#define H2_F_PADDED 0x08
/* HTTP/2 error codes - RFC7540 #7 */
enum h2_err {
H2_ERR_NO_ERROR = 0x0,
@ -163,6 +186,12 @@ int h2_make_htx_response(struct http_hdr *list, struct htx *htx, unsigned int *m
* Some helpful debugging functions.
*/
/* returns a bit corresponding to the frame type */
static inline unsigned int h2_ft_bit(enum h2_ft ft)
{
return 1U << ft;
}
/* returns the frame type as a string */
static inline const char *h2_ft_str(int type)
{