lsquic_parse_gquic_be.h revision 229fce07
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 14#if __BYTE_ORDER == __LITTLE_ENDIAN 15#define READ_UINT(varname, varwidth, src, nbytes) do { \ 16 varname = 0; \ 17 memcpy((unsigned char *) &varname + varwidth / 8 - (nbytes), (src), \ 18 (nbytes)); \ 19 varname = bswap_##varwidth(varname); \ 20} while (0) 21#else 22#define READ_UINT(varname, varwidth, src, nbytes) do { \ 23 varname = 0; \ 24 memcpy((unsigned char *) &varname + varwidth / 8 - (nbytes), (src), \ 25 (nbytes)); \ 26} while (0) 27#endif 28 29uint64_t 30gquic_be_read_float_time16 (const void *mem); 31 32void 33gquic_be_write_float_time16 (lsquic_time_t time_us, void *mem); 34 35void 36gquic_be_parse_packet_in_finish (lsquic_packet_in_t *packet_in, 37 struct packin_parse_state *state); 38 39int 40gquic_be_gen_ver_nego_pkt (unsigned char *buf, size_t bufsz, uint64_t conn_id, 41 unsigned version_bitmask); 42 43int 44gquic_be_gen_stream_frame (unsigned char *buf, size_t buf_len, uint32_t stream_id, 45 uint64_t offset, int fin, size_t size, 46 gsf_read_f gsf_read, void *stream); 47 48int 49gquic_be_parse_stream_frame (const unsigned char *buf, size_t rem_packet_sz, 50 stream_frame_t *stream_frame); 51 52lsquic_packno_t 53gquic_be_parse_ack_high (const unsigned char *buf, size_t buf_len); 54 55int 56gquic_be_parse_ack_frame (const unsigned char *buf, size_t buf_len, ack_info_t *ack); 57 58int 59gquic_be_gen_stop_waiting_frame(unsigned char *buf, size_t buf_len, 60 lsquic_packno_t cur_packno, enum lsquic_packno_bits bits, 61 lsquic_packno_t least_unacked_packno); 62 63int 64gquic_be_parse_stop_waiting_frame (const unsigned char *buf, size_t buf_len, 65 lsquic_packno_t cur_packno, enum lsquic_packno_bits bits, 66 lsquic_packno_t *least_unacked); 67 68int 69gquic_be_skip_stop_waiting_frame (size_t buf_len, enum lsquic_packno_bits bits); 70 71int 72gquic_be_gen_window_update_frame (unsigned char *buf, int buf_len, uint32_t stream_id, 73 uint64_t offset); 74 75int 76gquic_be_parse_window_update_frame (const unsigned char *buf, size_t buf_len, 77 uint32_t *stream_id, uint64_t *offset); 78 79int 80gquic_be_gen_blocked_frame (unsigned char *buf, size_t buf_len, uint32_t stream_id); 81 82int 83gquic_be_parse_blocked_frame (const unsigned char *buf, size_t buf_len, 84 uint32_t *stream_id); 85 86int 87gquic_be_gen_rst_frame (unsigned char *buf, size_t buf_len, uint32_t stream_id, 88 uint64_t offset, uint32_t error_code); 89 90int 91gquic_be_parse_rst_frame (const unsigned char *buf, size_t buf_len, uint32_t *stream_id, 92 uint64_t *offset, uint32_t *error_code); 93 94int 95gquic_be_gen_ping_frame (unsigned char *buf, int buf_len); 96 97int 98gquic_be_gen_connect_close_frame (unsigned char *buf, int buf_len, uint32_t error_code, 99 const char *reason, int reason_len); 100 101int 102gquic_be_parse_connect_close_frame (const unsigned char *buf, size_t buf_len, 103 uint32_t *error_code, uint16_t *reason_len, uint8_t *reason_offset); 104 105int 106gquic_be_gen_goaway_frame(unsigned char *buf, size_t buf_len, uint32_t error_code, 107 uint32_t last_good_stream_id, const char *reason, 108 size_t reason_len); 109 110int 111gquic_be_parse_goaway_frame (const unsigned char *buf, size_t buf_len, 112 uint32_t *error_code, uint32_t *last_good_stream_id, 113 uint16_t *reason_length, const char **reason); 114 115int 116gquic_be_gen_ack_frame (unsigned char *outbuf, size_t outbuf_sz, 117 gaf_rechist_first_f rechist_first, gaf_rechist_next_f rechist_next, 118 gaf_rechist_largest_recv_f rechist_largest_recv, 119 void *rechist, lsquic_time_t now, int *has_missing, lsquic_packno_t *); 120 121#endif 122