LCOV - code coverage report
Current view: top level - waltz/quic/templ - fd_quic_frame.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 44 52 84.6 %
Date: 2024-11-13 11:58:15 Functions: 12 22 54.5 %

          Line data    Source code
       1             : #ifdef HEADER_fd_src_waltz_quic_templ_fd_quic_frame_types_templ_h
       2             : #error "fd_quic_frame_types_templ.c included twice"
       3             : #endif
       4             : #define HEADER_fd_src_waltz_quic_templ_fd_quic_frame_types_templ_h
       5             : 
       6             : #include "../fd_quic_enum.h"
       7             : #include "../../../util/fd_util.h"
       8             : 
       9             : /* FD_QUIC_FRAME_TYPES describes the frame types and their attributes.
      10             : 
      11             :    Columns:
      12             :    - ID:  frame type as seen on the wire
      13             :    - MID: frame ID used in fd_quic metrics (FIXME use ID instead when fd_metrics supports sparse enums) */
      14             : 
      15             : #define FD_QUIC_FRAME_TYPES(X)                                                    \
      16             : /*  ID    MID Handler              Definition        Pkts          Spec */ \
      17       24768 :   X(0x00, 21, padding,             "Section 19.1 ",  I, H, 0, 1,   N, P)   \
      18       24768 :   X(0x01, 20, ping,                "Section 19.2 ",  I, H, 0, 1,    ,  )   \
      19     2150740 :   X(0x02,  1, ack,                 "Section 19.3 ",  I, H, _, 1,   N, C)   \
      20     2150740 :   X(0x03,  1, ack,                 "Section 19.3 ",  I, H, _, 1,   N, C)   \
      21         129 :   X(0x04,  2, reset_stream,        "Section 19.4 ",  _, _, 0, 1,    ,  )   \
      22           0 :   X(0x05,  3, stop_sending,        "Section 19.5 ",  _, _, 0, 1,    ,  )   \
      23       42141 :   X(0x06,  4, crypto,              "Section 19.6 ",  I, H, _, 1,    ,  )   \
      24       42141 :   X(0x07,  5, new_token,           "Section 19.7 ",  _, _, _, 1,    ,  )   \
      25           0 :   X(0x08,  6, stream,              "Section 19.8 ",  _, _, 0, 1,   F,  )   \
      26    25161723 :   X(0x09,  6, stream,              "Section 19.8 ",  _, _, 0, 1,   F,  )   \
      27    25161723 :   X(0x0a,  6, stream,              "Section 19.8 ",  _, _, 0, 1,   F,  )   \
      28     8536630 :   X(0x0b,  6, stream,              "Section 19.8 ",  _, _, 0, 1,   F,  )   \
      29        9810 :   X(0x0c,  6, stream,              "Section 19.8 ",  _, _, 0, 1,   F,  )   \
      30           3 :   X(0x0d,  6, stream,              "Section 19.8 ",  _, _, 0, 1,   F,  )   \
      31        7635 :   X(0x0e,  6, stream,              "Section 19.8 ",  _, _, 0, 1,   F,  )   \
      32     8536618 :   X(0x0f,  6, stream,              "Section 19.8 ",  _, _, 0, 1,   F,  )   \
      33     8536618 :   X(0x10,  7, max_data,            "Section 19.9 ",  _, _, 0, 1,    ,  )   \
      34     1066307 :   X(0x11,  8, max_stream_data,     "Section 19.10",  _, _, 0, 1,    ,  )   \
      35           0 :   X(0x12,  9, max_streams,         "Section 19.11",  _, _, 0, 1,    ,  )   \
      36         210 :   X(0x13,  9, max_streams,         "Section 19.11",  _, _, 0, 1,    ,  )   \
      37         210 :   X(0x14, 10, data_blocked,        "Section 19.12",  _, _, 0, 1,    ,  )   \
      38           0 :   X(0x15, 11, stream_data_blocked, "Section 19.13",  _, _, 0, 1,    ,  )   \
      39           0 :   X(0x16, 12, streams_blocked,     "Section 19.14",  _, _, 0, 1,    ,  )   \
      40          57 :   X(0x17, 12, streams_blocked,     "Section 19.14",  _, _, 0, 1,    ,  )   \
      41          57 :   X(0x18, 13, new_conn_id,         "Section 19.15",  _, _, 0, 1,   P,  )   \
      42           0 :   X(0x19, 14, retire_conn_id,      "Section 19.16",  _, _, 0, 1,    ,  )   \
      43           0 :   X(0x1a, 15, path_challenge,      "Section 19.17",  _, _, 0, 1,   P,  )   \
      44           0 :   X(0x1b, 16, path_response,       "Section 19.18",  _, _, _, 1,   P,  )   \
      45          42 :   X(0x1c, 17, conn_close_0,        "Section 19.19",  I, H, 0, 1,   N,  )   \
      46        6012 :   X(0x1d, 18, conn_close_1,        "Section 19.19",  _, _, 0, 1,   N,  )   \
      47        6012 :   X(0x1e, 19, handshake_done,      "Section 19.20",  _, _, _, 1,    ,  )
      48             : 
      49             : #define FD_QUIC_FRAME_TYPE_CNT (0x1f) /* lookup tables should have this many entries */
      50             : 
      51             : 
      52             : /* Lookup table for allowed frame types *******************************/
      53             : 
      54             : #define PKT_FLAG__ 0u
      55             : #define PKT_FLAG_I (1u<<FD_QUIC_PKT_TYPE_INITIAL)    /* allowed in INITIAL */
      56             : #define PKT_FLAG_H (1u<<FD_QUIC_PKT_TYPE_HANDSHAKE)  /* allowed in HANDSHAKE */
      57             : #define PKT_FLAG_0 (1u<<FD_QUIC_PKT_TYPE_ZERO_RTT)   /* allowed in 0-RTT */
      58             : #define PKT_FLAG_1 (1u<<FD_QUIC_PKT_TYPE_ONE_RTT)    /* allowed in 1-RTT */
      59             : 
      60             : static uchar const __attribute__((aligned(0x20)))
      61             : fd_quic_frame_type_flags[ FD_QUIC_FRAME_TYPE_CNT ] = {
      62             : 
      63             :   #define F(T,MID,NAME,_0,F0,F1,F2,F3,...) \
      64             :       [T] = PKT_FLAG_##F0 + PKT_FLAG_##F1 + PKT_FLAG_##F2 + PKT_FLAG_##F3,
      65             :     FD_QUIC_FRAME_TYPES(F)
      66             :   #undef F
      67             : 
      68             : };
      69             : 
      70             : #undef PKT_FLAG__
      71             : #undef PKT_FLAG_I
      72             : #undef PKT_FLAG_H
      73             : #undef PKT_FLAG_0
      74             : #undef PKT_FLAG_1
      75             : 
      76             : /* fd_quic_frame_type_allowed checks whether a frame type is allowed for
      77             :    a given packet type.  pkt_type is one of FD_QUIC_PKT_TYPE_{INITIAL,
      78             :    HANDSHAKE,ZERO_RTT,ONE_RTT}.  Returns 1 if the frame type is allowed,
      79             :    0 otherwise. */
      80             : 
      81             : FD_FN_PURE static inline int
      82             : fd_quic_frame_type_allowed( uint pkt_type,
      83    45549410 :                             uint frame_type ) {
      84    45549410 :   if( FD_UNLIKELY( pkt_type > FD_QUIC_PKT_TYPE_ONE_RTT ) ) return 0;
      85    45549410 :   if( FD_UNLIKELY( frame_type >= FD_QUIC_FRAME_TYPE_CNT ) ) return 0;
      86    45549365 :   return !!( fd_quic_frame_type_flags[frame_type] & (1u<<pkt_type) );
      87    45549410 : }
      88             : 
      89             : 
      90             : /* Lookup table for frame metric IDs **********************************/
      91             : 
      92             : static uchar const __attribute__((aligned(0x20)))
      93             : fd_quic_frame_metric_id[ FD_QUIC_FRAME_TYPE_CNT ] = {
      94             :   # define F(T,MID,...) [T] = (MID),
      95             :     FD_QUIC_FRAME_TYPES(F)
      96             :   # undef F
      97             : };
      98             : 
      99             : 
     100             : /* Frame handlers *****************************************************/
     101             : 
     102             : /* Generate frame interpreter (decode + handle) */
     103             : 
     104             : #define FD_TEMPL_DEF_STRUCT_BEGIN(NAME)                                   \
     105             :   static ulong fd_quic_interpret_##NAME(                                  \
     106             :       void *        const ctx,                                            \
     107             :       uchar const * const buf,                                            \
     108             :       ulong         const buf_sz                                          \
     109    45548870 :   ) {                                                                     \
     110    45548870 :     fd_quic_##NAME##_t frame[1];                                          \
     111    45548870 :     uchar const *       p0 = buf;                                         \
     112    45548870 :     uchar const * const p1 = buf+buf_sz;                                  \
     113    45548870 :     ulong               rc;                                               \
     114    45548870 :                                                                           \
     115    45548870 :     rc = fd_quic_decode_##NAME( frame, p0, (ulong)(p1-p0) );              \
     116    45548870 :     if( FD_UNLIKELY( rc==FD_QUIC_PARSE_FAIL ) ) return FD_QUIC_PARSE_FAIL;\
     117    45548870 :     p0 += rc;                                                             \
     118    45548837 :                                                                           \
     119    45548837 :     rc = fd_quic_frame_handle_##NAME( ctx, frame, p0, (ulong)(p1-p0) );   \
     120    45548837 :     if( FD_UNLIKELY( rc==FD_QUIC_PARSE_FAIL ) ) return FD_QUIC_PARSE_FAIL;\
     121    45548837 :     p0 += rc;                                                             \
     122    45548720 :                                                                           \
     123    45548720 :     return (ulong)(p0-buf);                                               \
     124    45548837 :   }
     125             : #include "fd_quic_dft.h"
     126             : #include "fd_quic_frames_templ.h"
     127             : #include "fd_quic_undefs.h"

Generated by: LCOV version 1.14