LCOV - code coverage report
Current view: top level - waltz/h2 - fd_h2_proto.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 35 35 100.0 %
Date: 2026-04-01 06:30:45 Functions: 18 60 30.0 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_waltz_h2_fd_h2_proto_h
       2             : #define HEADER_fd_src_waltz_h2_fd_h2_proto_h
       3             : 
       4             : /* fd_h2_proto.h contains constants and data structures taken from
       5             :    HTTP/2 specs. */
       6             : 
       7             : #include "fd_h2_base.h"
       8             : 
       9             : /* FD_H2_FRAME_TYPE_* give HTTP/2 frame IDs.
      10             :    https://www.iana.org/assignments/http2-parameters/http2-parameters.xhtml#frame-type */
      11             : 
      12         279 : #define FD_H2_FRAME_TYPE_DATA            ((uchar)0x00)
      13         171 : #define FD_H2_FRAME_TYPE_HEADERS         ((uchar)0x01)
      14           3 : #define FD_H2_FRAME_TYPE_PRIORITY        ((uchar)0x02)
      15          24 : #define FD_H2_FRAME_TYPE_RST_STREAM      ((uchar)0x03)
      16          84 : #define FD_H2_FRAME_TYPE_SETTINGS        ((uchar)0x04)
      17          54 : #define FD_H2_FRAME_TYPE_PUSH_PROMISE    ((uchar)0x05)
      18          54 : #define FD_H2_FRAME_TYPE_PING            ((uchar)0x06)
      19          15 : #define FD_H2_FRAME_TYPE_GOAWAY          ((uchar)0x07)
      20           6 : #define FD_H2_FRAME_TYPE_WINDOW_UPDATE   ((uchar)0x08)
      21           3 : #define FD_H2_FRAME_TYPE_CONTINUATION    ((uchar)0x09)
      22           3 : #define FD_H2_FRAME_TYPE_ALTSVC          ((uchar)0x0a)
      23           3 : #define FD_H2_FRAME_TYPE_ORIGIN          ((uchar)0x0c)
      24           3 : #define FD_H2_FRAME_TYPE_PRIORITY_UPDATE ((uchar)0x10)
      25             : 
      26             : /* 4.1.  Frame Format
      27             :    All frames begin with a fixed 9-octet header followed by a variable-
      28             :    length payload.
      29             : 
      30             :     +-----------------------------------------------+
      31             :     |                 Length (24)                   |
      32             :     +---------------+---------------+---------------+
      33             :     |   Type (8)    |   Flags (8)   |
      34             :     +-+-------------+---------------+-------------------------------+
      35             :     |R|                 Stream Identifier (31)                      |
      36             :     +=+=============================================================+
      37             :     |                   Frame Payload (0...)                      ...
      38             :     +---------------------------------------------------------------+
      39             : 
      40             :                           Figure 1: Frame Layout
      41             : */
      42             : 
      43             : /* fd_h2_frame_{length,type} pack/unpack the typlen field as found in a
      44             :    frame header. The length is in bytes and does not include the 9-byte frame header. */
      45             : 
      46             : FD_FN_CONST static inline uchar
      47         138 : fd_h2_frame_type( uint typlen ) {
      48         138 :   return (uchar)( typlen>>24 ); /* in [0,2^8) */
      49         138 : }
      50             : 
      51             : FD_FN_CONST static inline uint
      52         132 : fd_h2_frame_length( uint typlen ) {
      53         132 :   return fd_uint_bswap( typlen<<8 ) & 0xFFFFFF; /* in [0,2^24) */
      54         132 : }
      55             : 
      56             : /* fd_h2_frame_typlen packs the typlen field for use in a frame header. */
      57             : 
      58             : FD_FN_CONST static inline uint
      59             : fd_h2_frame_typlen( ulong type,      /* in [0,2^8) */
      60         180 :                     ulong length ) { /* in [0,2^24) */
      61         180 :   return (fd_uint_bswap( (uint)length )>>8) | ((uint)type<<24);
      62         180 : }
      63             : 
      64             : FD_FN_CONST static inline uint
      65         105 : fd_h2_frame_stream_id( uint r_stream_id ) {
      66         105 :   return fd_uint_bswap( r_stream_id ) & 0x7fffffffu;
      67         105 : }
      68             : 
      69             : /* fd_h2_frame_hdr_t matches the encoding of a HTTP/2 frame header.
      70             :    https://www.rfc-editor.org/rfc/rfc9113.html#section-4.1 */
      71             : 
      72             : struct __attribute__((packed)) fd_h2_frame_hdr {
      73             :   uint  typlen;
      74             :   uchar flags;
      75             :   uint  r_stream_id;
      76             : };
      77             : 
      78             : typedef struct fd_h2_frame_hdr fd_h2_frame_hdr_t;
      79             : 
      80          69 : #define FD_H2_FLAG_ACK         ((uchar)0x01)
      81         159 : #define FD_H2_FLAG_END_STREAM  ((uchar)0x01)
      82          93 : #define FD_H2_FLAG_END_HEADERS ((uchar)0x04)
      83          33 : #define FD_H2_FLAG_PADDED      ((uchar)0x08)
      84             : #define FD_H2_FLAG_PRIORITY    ((uchar)0x20)
      85             : 
      86             : 
      87             : /* fd_h2_priority_t matches the encoding of a PRIORITY frame. */
      88             : 
      89             : struct __attribute__((packed)) fd_h2_priority {
      90             :   fd_h2_frame_hdr_t hdr;
      91             :   uint r_stream_dep;
      92             :   uchar weight;
      93             : };
      94             : 
      95             : typedef struct fd_h2_priority fd_h2_priority_t;
      96             : 
      97             : 
      98             : /* A SETTINGS frame contains a series of fd_h2_setting_t. */
      99             : 
     100             : struct __attribute__((packed)) fd_h2_setting {
     101             :   ushort id;
     102             :   uint   value;
     103             : };
     104             : 
     105             : typedef struct fd_h2_setting fd_h2_setting_t;
     106             : 
     107             : /* FD_H2_SETTINGS_* give HTTP/2 setting IDs.
     108             :    https://www.iana.org/assignments/http2-parameters/http2-parameters.xhtml#settings
     109             :    https://www.rfc-editor.org/rfc/rfc9113.html#section-6.5.2 */
     110             : 
     111           9 : #define FD_H2_SETTINGS_HEADER_TABLE_SIZE      ((ushort)0x01)
     112          18 : #define FD_H2_SETTINGS_ENABLE_PUSH            ((ushort)0x02)
     113          18 : #define FD_H2_SETTINGS_MAX_CONCURRENT_STREAMS ((ushort)0x03)
     114          18 : #define FD_H2_SETTINGS_INITIAL_WINDOW_SIZE    ((ushort)0x04)
     115          30 : #define FD_H2_SETTINGS_MAX_FRAME_SIZE         ((ushort)0x05)
     116          18 : #define FD_H2_SETTINGS_MAX_HEADER_LIST_SIZE   ((ushort)0x06)
     117             : 
     118             : 
     119             : /* fd_h2_ping_t matches the encoding of a PING frame.
     120             :    https://www.rfc-editor.org/rfc/rfc9113.html#name-ping
     121             :    Valid flags: ACK */
     122             : 
     123             : struct __attribute__((packed)) fd_h2_ping {
     124             :   fd_h2_frame_hdr_t hdr;
     125             : 
     126             :   ulong payload;
     127             : };
     128             : 
     129             : typedef struct fd_h2_ping fd_h2_ping_t;
     130             : 
     131             : 
     132             : /* fd_h2_goaway_t matches the encoding of a GOAWAY frame.
     133             :    https://www.rfc-editor.org/rfc/rfc9113.html#name-goaway */
     134             : 
     135             : struct __attribute__((packed)) fd_h2_goaway {
     136             :   fd_h2_frame_hdr_t hdr;
     137             : 
     138             :   uint last_stream_id;
     139             :   uint error_code;
     140             :   /* variable length debug data follows ... */
     141             : };
     142             : 
     143             : typedef struct fd_h2_goaway fd_h2_goaway_t;
     144             : 
     145             : 
     146             : /* fd_h2_window_update_t matches the encoding of a WINDOW_UPDATE frame.
     147             :    https://www.rfc-editor.org/rfc/rfc9113.html#name-window_update */
     148             : 
     149             : struct __attribute__((packed)) fd_h2_window_update {
     150             :   fd_h2_frame_hdr_t hdr;
     151             : 
     152             :   uint increment;
     153             : };
     154             : 
     155             : typedef struct fd_h2_window_update fd_h2_window_update_t;
     156             : 
     157             : 
     158             : /* fd_h2_rst_stream_t matches the encoding of a RST_STREAM frame.
     159             :    https://www.rfc-editor.org/rfc/rfc9113.html#name-rst_stream */
     160             : 
     161             : struct __attribute__((packed)) fd_h2_rst_stream {
     162             :   fd_h2_frame_hdr_t hdr;
     163             : 
     164             :   uint error_code;
     165             : };
     166             : 
     167             : typedef struct fd_h2_rst_stream fd_h2_rst_stream_t;
     168             : 
     169             : 
     170             : FD_PROTOTYPES_BEGIN
     171             : 
     172             : /* fd_h2_frame_name returns a static-lifetime uppercase cstr with the
     173             :    name of a HTTP/2 frame. */
     174             : 
     175             : FD_FN_CONST char const *
     176             : fd_h2_frame_name( uint frame_id );
     177             : 
     178             : /* fd_h2_setting_name returns a static-lifetime uppercase cstr with the
     179             :    name of a HTTP/2 setting. */
     180             : 
     181             : FD_FN_CONST char const *
     182             : fd_h2_setting_name( uint setting_id );
     183             : 
     184             : FD_PROTOTYPES_END
     185             : 
     186             : #endif /* HEADER_fd_src_waltz_h2_fd_h2_proto_h */

Generated by: LCOV version 1.14