From: Willy Tarreau Date: Fri, 21 Dec 2018 13:56:57 +0000 (+0100) Subject: MINOR: h2: add a bit-based frame type representation X-Git-Tag: v2.0-dev1~328 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=deab244dc150032e1c57368289391af73c0b8aee;p=thirdparty%2Fhaproxy.git MINOR: h2: add a bit-based frame type representation This will ease checks among sets of frames. --- diff --git a/include/common/h2.h b/include/common/h2.h index acc80c017d..29270115bc 100644 --- a/include/common/h2.h +++ b/include/common/h2.h @@ -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) {