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