lsquic_packet_common.c revision 7d09751d
1/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc.  See LICENSE. */
2/*
3 * lsquic_packet_common.c -- some common packet-related routines
4 */
5
6#include <stdint.h>
7#include <stdio.h>
8#include <time.h>
9
10#include "lsquic.h"
11#include "lsquic_types.h"
12#include "lsquic_logger.h"
13#include "lsquic_enc_sess.h"
14#include "lsquic_packet_common.h"
15
16
17const char *
18lsquic_frame_types_to_str (char *buf, size_t bufsz,
19                                           enum quic_ft_bit frame_types)
20{
21    char *p;
22    int i, w;
23    size_t sz;
24
25    if (bufsz > 0)
26        buf[0] = '\0';
27
28    p = buf;
29    for (i = 0; i < N_QUIC_FRAMES; ++i)
30    {
31        if (frame_types & (1 << i))
32        {
33            sz = bufsz - (p - buf);
34            w = snprintf(p, sz, "%.*s%s", p > buf, " ",
35                            frame_type_2_str[i] + sizeof("QUIC_FRAME_") - 1);
36            if (w > (int) sz)
37            {
38                LSQ_WARN("not enough room for all frame types");
39                break;
40            }
41            p += w;
42        }
43        frame_types &= ~(1 << i);
44    }
45
46    return buf;
47}
48
49
50const char *const lsquic_hety2str[] =
51{
52    [HETY_NOT_SET]      = "Short",
53    [HETY_VERNEG]       = "Version Negotiation",
54    [HETY_INITIAL]      = "Initial",
55    [HETY_RETRY]        = "Retry",
56    [HETY_HANDSHAKE]    = "Handshake",
57    [HETY_0RTT]         = "0-RTT",
58};
59
60
61/* [draft-ietf-quic-tls-14], Section 4 */
62const enum packnum_space lsquic_hety2pns[] =
63{
64    [HETY_NOT_SET]      = PNS_APP,
65    [HETY_VERNEG]       = 0,
66    [HETY_INITIAL]      = PNS_INIT,
67    [HETY_RETRY]        = 0,
68    [HETY_HANDSHAKE]    = PNS_HSK,
69    [HETY_0RTT]         = PNS_APP,
70};
71
72
73/* [draft-ietf-quic-tls-14], Section 4 */
74const enum packnum_space lsquic_enclev2pns[] =
75{
76    [ENC_LEV_CLEAR]      = PNS_INIT,
77    [ENC_LEV_INIT]       = PNS_HSK,
78    [ENC_LEV_EARLY]      = PNS_APP,
79    [ENC_LEV_FORW]       = PNS_APP,
80};
81
82
83const char *const lsquic_pns2str[] =
84{
85    [PNS_INIT]  = "Init PNS",
86    [PNS_HSK]   = "Handshake PNS",
87    [PNS_APP]   = "App PNS",
88};
89