]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: h2: add a bit-based frame type representation
authorWilly Tarreau <w@1wt.eu>
Fri, 21 Dec 2018 13:56:57 +0000 (14:56 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 24 Dec 2018 10:45:00 +0000 (11:45 +0100)
This will ease checks among sets of frames.

include/common/h2.h

index acc80c017d4c2c6cf5f326bfeb123ccd1b5423c4..29270115bc0c0bbbe4b552cdcd8c59943b888fdd 100644 (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)
 {