lsquic_parse_gquic_be.h revision 5392f7a3
1/* Copyright (c) 2017 - 2019 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
15gquic_be_read_float_time16 (const void *mem);
16
17void
18gquic_be_write_float_time16 (lsquic_time_t time_us, void *mem);
19
20void
21gquic_be_parse_packet_in_finish (lsquic_packet_in_t *packet_in,
22                                            struct packin_parse_state *state);
23
24int
25gquic_be_gen_ver_nego_pkt (unsigned char *buf, size_t bufsz,
26                    const lsquic_cid_t *, unsigned version_bitmask);
27
28int
29gquic_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
34gquic_be_parse_stream_frame (const unsigned char *buf, size_t rem_packet_sz,
35                       stream_frame_t *stream_frame);
36
37lsquic_packno_t
38gquic_be_parse_ack_high (const unsigned char *buf, size_t buf_len);
39
40int
41gquic_be_parse_ack_frame (const unsigned char *buf, size_t buf_len,
42                                                struct ack_info *, uint8_t);
43
44int
45gquic_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
50gquic_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
55gquic_be_skip_stop_waiting_frame (size_t buf_len, enum packno_bits bits);
56
57int
58gquic_be_gen_window_update_frame (unsigned char *buf, int buf_len,
59                            lsquic_stream_id_t stream_id, uint64_t offset);
60
61int
62gquic_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
66gquic_be_gen_blocked_frame (unsigned char *buf, size_t buf_len,
67                            lsquic_stream_id_t stream_id);
68
69int
70gquic_be_parse_blocked_frame (const unsigned char *buf, size_t buf_len,
71                                                lsquic_stream_id_t *stream_id);
72
73int
74gquic_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
78gquic_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
82gquic_be_gen_ping_frame (unsigned char *buf, int buf_len);
83
84int
85gquic_be_gen_connect_close_frame (unsigned char *buf, size_t buf_len,
86    int app_error, unsigned error_code, const char *reason, int reason_len);
87
88int
89gquic_be_parse_connect_close_frame (const unsigned char *buf, size_t buf_len,
90        int *app_error, uint64_t *error_code,
91        uint16_t *reason_len, uint8_t *reason_offset);
92
93int
94gquic_be_gen_goaway_frame(unsigned char *buf, size_t buf_len, uint32_t error_code,
95                     lsquic_stream_id_t last_good_stream_id, const char *reason,
96                     size_t reason_len);
97
98int
99gquic_be_parse_goaway_frame (const unsigned char *buf, size_t buf_len,
100               uint32_t *error_code, lsquic_stream_id_t *last_good_stream_id,
101                       uint16_t *reason_length, const char **reason);
102
103int
104gquic_be_gen_ack_frame (unsigned char *outbuf, size_t outbuf_sz,
105        gaf_rechist_first_f rechist_first, gaf_rechist_next_f rechist_next,
106        gaf_rechist_largest_recv_f rechist_largest_recv,
107        void *rechist, lsquic_time_t now, int *has_missing, lsquic_packno_t *,
108        const uint64_t *);
109
110#endif
111