lsquic_parse_common.h revision a74702c6
1/* Copyright (c) 2017 - 2022 LiteSpeed Technologies Inc.  See LICENSE. */
2/*
3 * lsquic_parse_common.h
4 */
5
6#ifndef LSQUIC_PARSE_COMMON_H
7#define LSQUIC_PARSE_COMMON_H 1
8
9#ifdef WIN32
10#include "vc_compat.h"
11#endif
12
13struct lsquic_packet_in;
14struct packin_parse_state;
15
16struct packin_parse_state {
17    const unsigned char     *pps_p;      /* Pointer to packet number */
18    unsigned                 pps_nbytes; /* Number of bytes in packet number */
19};
20
21int
22lsquic_parse_packet_in_begin (struct lsquic_packet_in *,
23                size_t length, int is_server, unsigned cid_len,
24                struct packin_parse_state *);
25
26int
27lsquic_parse_packet_in_server_begin (struct lsquic_packet_in *packet_in,
28                size_t length, int is_server_UNUSED, unsigned cid_len,
29                struct packin_parse_state *);
30
31int
32lsquic_ietf_v1_parse_packet_in_begin (struct lsquic_packet_in *,
33            size_t length, int is_server, unsigned cid_len,
34            struct packin_parse_state *);
35
36int
37lsquic_Q046_parse_packet_in_begin (struct lsquic_packet_in *,
38            size_t length, int is_server, unsigned cid_len,
39            struct packin_parse_state *);
40
41int
42lsquic_Q050_parse_packet_in_begin (struct lsquic_packet_in *,
43            size_t length, int is_server, unsigned cid_len,
44            struct packin_parse_state *);
45
46int
47lsquic_ietf_v1_parse_packet_in_long_begin (struct lsquic_packet_in *,
48            size_t length, int is_server, unsigned cid_len,
49            struct packin_parse_state *);
50
51int
52lsquic_ietf_v1_parse_packet_in_short_begin (struct lsquic_packet_in *,
53            size_t length, int is_server, unsigned cid_len,
54            struct packin_parse_state *);
55
56struct sockaddr;
57enum lsquic_version;
58struct lsquic_engine_public;
59
60int
61lsquic_gquic_gen_ver_nego_pkt (unsigned char *buf, size_t bufsz,
62                               const lsquic_cid_t *cid, unsigned versions);
63int
64lsquic_Q046_gen_ver_nego_pkt (unsigned char *buf, size_t bufsz,
65    const lsquic_cid_t *scid, const lsquic_cid_t *dcid, unsigned versions,
66    uint8_t);
67int
68lsquic_ietf_v1_gen_ver_nego_pkt (unsigned char *buf, size_t bufsz,
69    const lsquic_cid_t *scid, const lsquic_cid_t *dcid, unsigned versions,
70    uint8_t);
71
72#define GQUIC_RESET_SZ 33
73ssize_t
74lsquic_generate_gquic_reset (const lsquic_cid_t *, unsigned char *buf,
75                                                            size_t buf_sz);
76
77int
78lsquic_is_valid_iquic_hs_packet (const unsigned char *buf, size_t buf_sz,
79                                                    lsquic_ver_tag_t *tag);
80
81int
82lsquic_is_valid_ietf_v1_or_Q046plus_hs_packet (const unsigned char *buf,
83                                    size_t length, lsquic_ver_tag_t *tagp);
84
85/* Instead of just -1 like CHECK_SPACE(), this macro returns the number
86 * of bytes needed.
87 */
88#define CHECK_STREAM_SPACE(need, pstart, pend) do {                 \
89    if ((intptr_t) (need) > ((pend) - (pstart))) {                  \
90        return -((int) (need));                                     \
91    }                                                               \
92} while (0)
93
94#endif
95