lsquic_parse_gquic_be.h revision 2f2f4363
1/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc.  See LICENSE. */
2#ifndef LSQUIC_PARSE_GQUIC_BE_H
3#define LSQUIC_PARSE_GQUIC_BE_H
4
5/* Header file to make it easy to reference gQUIC parsing functions.  This
6 * is only meant to be used internally.  The alternative would be to place
7 * all gQUIC-big-endian functions -- from all versions -- in a single file,
8 * and that would be a mess.
9 */
10
11#define CHECK_SPACE(need, pstart, pend)  \
12    do { if ((intptr_t) (need) > ((pend) - (pstart))) { return -1; } } while (0)
13
14uint64_t
15lsquic_gquic_be_read_float_time16 (const void *mem);
16
17void
18lsquic_gquic_be_write_float_time16 (lsquic_time_t time_us, void *mem);
19
20void
21lsquic_gquic_be_parse_packet_in_finish (lsquic_packet_in_t *packet_in,
22                                            struct packin_parse_state *state);
23
24int
25lsquic_gquic_be_gen_ver_nego_pkt (unsigned char *buf, size_t bufsz,
26                    const lsquic_cid_t *, unsigned version_bitmask);
27
28int
29lsquic_gquic_be_gen_stream_frame (unsigned char *buf, size_t buf_len,
30    lsquic_stream_id_t stream_id, uint64_t offset, int fin, size_t size,
31    gsf_read_f gsf_read, void *stream);
32
33int
34lsquic_gquic_be_parse_stream_frame (const unsigned char *buf, size_t rem_packet_sz,
35                       stream_frame_t *stream_frame);
36
37lsquic_packno_t
38lsquic_gquic_be_parse_ack_high (const unsigned char *buf, size_t buf_len);
39
40int
41lsquic_gquic_be_parse_ack_frame (const unsigned char *buf, size_t buf_len,
42                                                struct ack_info *, uint8_t);
43
44int
45lsquic_gquic_be_gen_stop_waiting_frame(unsigned char *buf, size_t buf_len,
46                lsquic_packno_t cur_packno, enum packno_bits bits,
47                lsquic_packno_t least_unacked_packno);
48
49int
50lsquic_gquic_be_parse_stop_waiting_frame (const unsigned char *buf, size_t buf_len,
51                 lsquic_packno_t cur_packno, enum packno_bits bits,
52                 lsquic_packno_t *least_unacked);
53
54int
55lsquic_gquic_be_skip_stop_waiting_frame (size_t buf_len, enum packno_bits bits);
56
57int
58lsquic_gquic_be_gen_window_update_frame (unsigned char *buf, int buf_len,
59                            lsquic_stream_id_t stream_id, uint64_t offset);
60
61int
62lsquic_gquic_be_parse_window_update_frame (const unsigned char *buf, size_t buf_len,
63                              lsquic_stream_id_t *stream_id, uint64_t *offset);
64
65int
66lsquic_gquic_be_gen_blocked_frame (unsigned char *buf, size_t buf_len,
67                            lsquic_stream_id_t stream_id);
68
69int
70lsquic_gquic_be_parse_blocked_frame (const unsigned char *buf, size_t buf_len,
71                                                lsquic_stream_id_t *stream_id);
72
73int
74lsquic_gquic_be_gen_rst_frame (unsigned char *buf, size_t buf_len,
75        lsquic_stream_id_t stream_id, uint64_t offset, uint64_t error_code);
76
77int
78lsquic_gquic_be_parse_rst_frame (const unsigned char *buf, size_t buf_len,
79    lsquic_stream_id_t *stream_id, uint64_t *offset, uint64_t *error_code);
80
81int
82lsquic_gquic_be_gen_ping_frame (unsigned char *buf, int buf_len);
83
84size_t
85lsquic_gquic_be_connect_close_frame_size (int app_error, unsigned error_code,
86                                unsigned frame_type, size_t reason_len);
87
88int
89lsquic_gquic_be_gen_connect_close_frame (unsigned char *buf, size_t buf_len,
90    int app_error, unsigned error_code, const char *reason, int reason_len);
91
92int
93lsquic_gquic_be_parse_connect_close_frame (const unsigned char *buf, size_t buf_len,
94        int *app_error, uint64_t *error_code,
95        uint16_t *reason_len, uint8_t *reason_offset);
96
97int
98lsquic_gquic_be_gen_goaway_frame(unsigned char *buf, size_t buf_len, uint32_t error_code,
99                     lsquic_stream_id_t last_good_stream_id, const char *reason,
100                     size_t reason_len);
101
102int
103lsquic_gquic_be_parse_goaway_frame (const unsigned char *buf, size_t buf_len,
104               uint32_t *error_code, lsquic_stream_id_t *last_good_stream_id,
105                       uint16_t *reason_length, const char **reason);
106
107int
108lsquic_gquic_be_gen_ack_frame (unsigned char *outbuf, size_t outbuf_sz,
109        gaf_rechist_first_f rechist_first, gaf_rechist_next_f rechist_next,
110        gaf_rechist_largest_recv_f rechist_largest_recv,
111        void *rechist, lsquic_time_t now, int *has_missing, lsquic_packno_t *,
112        const uint64_t *);
113
114int
115lsquic_gquic_be_dec_stream_frame_size (unsigned char *buf, size_t new_size);
116
117#endif
118