lsquic_parse_gquic_be.h revision c7d81ce1
1229fce07SDmitri Tikhonov/* Copyright (c) 2017 - 2019 LiteSpeed Technologies Inc. See LICENSE. */ 250aadb33SDmitri Tikhonov#ifndef LSQUIC_PARSE_GQUIC_BE_H 350aadb33SDmitri Tikhonov#define LSQUIC_PARSE_GQUIC_BE_H 450aadb33SDmitri Tikhonov 550aadb33SDmitri Tikhonov/* Header file to make it easy to reference gQUIC parsing functions. This 650aadb33SDmitri Tikhonov * is only meant to be used internally. The alternative would be to place 750aadb33SDmitri Tikhonov * all gQUIC-big-endian functions -- from all versions -- in a single file, 850aadb33SDmitri Tikhonov * and that would be a mess. 950aadb33SDmitri Tikhonov */ 1050aadb33SDmitri Tikhonov 1150aadb33SDmitri Tikhonov#define CHECK_SPACE(need, pstart, pend) \ 1250aadb33SDmitri Tikhonov do { if ((intptr_t) (need) > ((pend) - (pstart))) { return -1; } } while (0) 1350aadb33SDmitri Tikhonov 1450aadb33SDmitri Tikhonov#if __BYTE_ORDER == __LITTLE_ENDIAN 1550aadb33SDmitri Tikhonov#define READ_UINT(varname, varwidth, src, nbytes) do { \ 1650aadb33SDmitri Tikhonov varname = 0; \ 1750aadb33SDmitri Tikhonov memcpy((unsigned char *) &varname + varwidth / 8 - (nbytes), (src), \ 1850aadb33SDmitri Tikhonov (nbytes)); \ 1950aadb33SDmitri Tikhonov varname = bswap_##varwidth(varname); \ 2050aadb33SDmitri Tikhonov} while (0) 2150aadb33SDmitri Tikhonov#else 2250aadb33SDmitri Tikhonov#define READ_UINT(varname, varwidth, src, nbytes) do { \ 2350aadb33SDmitri Tikhonov varname = 0; \ 2450aadb33SDmitri Tikhonov memcpy((unsigned char *) &varname + varwidth / 8 - (nbytes), (src), \ 2550aadb33SDmitri Tikhonov (nbytes)); \ 2650aadb33SDmitri Tikhonov} while (0) 2750aadb33SDmitri Tikhonov#endif 2850aadb33SDmitri Tikhonov 2950aadb33SDmitri Tikhonovuint64_t 3050aadb33SDmitri Tikhonovgquic_be_read_float_time16 (const void *mem); 3150aadb33SDmitri Tikhonov 3250aadb33SDmitri Tikhonovvoid 3350aadb33SDmitri Tikhonovgquic_be_write_float_time16 (lsquic_time_t time_us, void *mem); 3450aadb33SDmitri Tikhonov 3550aadb33SDmitri Tikhonovvoid 3650aadb33SDmitri Tikhonovgquic_be_parse_packet_in_finish (lsquic_packet_in_t *packet_in, 3750aadb33SDmitri Tikhonov struct packin_parse_state *state); 3850aadb33SDmitri Tikhonov 3950aadb33SDmitri Tikhonovint 4050aadb33SDmitri Tikhonovgquic_be_gen_ver_nego_pkt (unsigned char *buf, size_t bufsz, uint64_t conn_id, 4150aadb33SDmitri Tikhonov unsigned version_bitmask); 4250aadb33SDmitri Tikhonov 4350aadb33SDmitri Tikhonovint 4450aadb33SDmitri Tikhonovgquic_be_gen_stream_frame (unsigned char *buf, size_t buf_len, uint32_t stream_id, 45bfc7bfd8SDmitri Tikhonov uint64_t offset, int fin, size_t size, 4650aadb33SDmitri Tikhonov gsf_read_f gsf_read, void *stream); 4750aadb33SDmitri Tikhonov 4850aadb33SDmitri Tikhonovint 4950aadb33SDmitri Tikhonovgquic_be_parse_stream_frame (const unsigned char *buf, size_t rem_packet_sz, 5050aadb33SDmitri Tikhonov stream_frame_t *stream_frame); 5150aadb33SDmitri Tikhonov 5250aadb33SDmitri Tikhonovlsquic_packno_t 5350aadb33SDmitri Tikhonovgquic_be_parse_ack_high (const unsigned char *buf, size_t buf_len); 5450aadb33SDmitri Tikhonov 5550aadb33SDmitri Tikhonovint 5650aadb33SDmitri Tikhonovgquic_be_parse_ack_frame (const unsigned char *buf, size_t buf_len, ack_info_t *ack); 5750aadb33SDmitri Tikhonov 5850aadb33SDmitri Tikhonovint 5950aadb33SDmitri Tikhonovgquic_be_gen_stop_waiting_frame(unsigned char *buf, size_t buf_len, 60c7d81ce1SDmitri Tikhonov lsquic_packno_t cur_packno, enum packno_bits bits, 6150aadb33SDmitri Tikhonov lsquic_packno_t least_unacked_packno); 6250aadb33SDmitri Tikhonov 6350aadb33SDmitri Tikhonovint 6450aadb33SDmitri Tikhonovgquic_be_parse_stop_waiting_frame (const unsigned char *buf, size_t buf_len, 65c7d81ce1SDmitri Tikhonov lsquic_packno_t cur_packno, enum packno_bits bits, 6650aadb33SDmitri Tikhonov lsquic_packno_t *least_unacked); 6750aadb33SDmitri Tikhonov 6850aadb33SDmitri Tikhonovint 69c7d81ce1SDmitri Tikhonovgquic_be_skip_stop_waiting_frame (size_t buf_len, enum packno_bits bits); 7050aadb33SDmitri Tikhonov 7150aadb33SDmitri Tikhonovint 7250aadb33SDmitri Tikhonovgquic_be_gen_window_update_frame (unsigned char *buf, int buf_len, uint32_t stream_id, 7350aadb33SDmitri Tikhonov uint64_t offset); 7450aadb33SDmitri Tikhonov 7550aadb33SDmitri Tikhonovint 7650aadb33SDmitri Tikhonovgquic_be_parse_window_update_frame (const unsigned char *buf, size_t buf_len, 7750aadb33SDmitri Tikhonov uint32_t *stream_id, uint64_t *offset); 7850aadb33SDmitri Tikhonov 7950aadb33SDmitri Tikhonovint 8050aadb33SDmitri Tikhonovgquic_be_gen_blocked_frame (unsigned char *buf, size_t buf_len, uint32_t stream_id); 8150aadb33SDmitri Tikhonov 8250aadb33SDmitri Tikhonovint 8350aadb33SDmitri Tikhonovgquic_be_parse_blocked_frame (const unsigned char *buf, size_t buf_len, 8450aadb33SDmitri Tikhonov uint32_t *stream_id); 8550aadb33SDmitri Tikhonov 8650aadb33SDmitri Tikhonovint 8750aadb33SDmitri Tikhonovgquic_be_gen_rst_frame (unsigned char *buf, size_t buf_len, uint32_t stream_id, 8850aadb33SDmitri Tikhonov uint64_t offset, uint32_t error_code); 8950aadb33SDmitri Tikhonov 9050aadb33SDmitri Tikhonovint 9150aadb33SDmitri Tikhonovgquic_be_parse_rst_frame (const unsigned char *buf, size_t buf_len, uint32_t *stream_id, 9250aadb33SDmitri Tikhonov uint64_t *offset, uint32_t *error_code); 9350aadb33SDmitri Tikhonov 9450aadb33SDmitri Tikhonovint 9550aadb33SDmitri Tikhonovgquic_be_gen_ping_frame (unsigned char *buf, int buf_len); 9650aadb33SDmitri Tikhonov 9750aadb33SDmitri Tikhonovint 9850aadb33SDmitri Tikhonovgquic_be_gen_connect_close_frame (unsigned char *buf, int buf_len, uint32_t error_code, 9950aadb33SDmitri Tikhonov const char *reason, int reason_len); 10050aadb33SDmitri Tikhonov 10150aadb33SDmitri Tikhonovint 10250aadb33SDmitri Tikhonovgquic_be_parse_connect_close_frame (const unsigned char *buf, size_t buf_len, 10350aadb33SDmitri Tikhonov uint32_t *error_code, uint16_t *reason_len, uint8_t *reason_offset); 10450aadb33SDmitri Tikhonov 10550aadb33SDmitri Tikhonovint 10650aadb33SDmitri Tikhonovgquic_be_gen_goaway_frame(unsigned char *buf, size_t buf_len, uint32_t error_code, 10750aadb33SDmitri Tikhonov uint32_t last_good_stream_id, const char *reason, 10850aadb33SDmitri Tikhonov size_t reason_len); 10950aadb33SDmitri Tikhonov 11050aadb33SDmitri Tikhonovint 11150aadb33SDmitri Tikhonovgquic_be_parse_goaway_frame (const unsigned char *buf, size_t buf_len, 11250aadb33SDmitri Tikhonov uint32_t *error_code, uint32_t *last_good_stream_id, 11350aadb33SDmitri Tikhonov uint16_t *reason_length, const char **reason); 11450aadb33SDmitri Tikhonov 11550aadb33SDmitri Tikhonovint 11650aadb33SDmitri Tikhonovgquic_be_gen_ack_frame (unsigned char *outbuf, size_t outbuf_sz, 11750aadb33SDmitri Tikhonov gaf_rechist_first_f rechist_first, gaf_rechist_next_f rechist_next, 11850aadb33SDmitri Tikhonov gaf_rechist_largest_recv_f rechist_largest_recv, 11916a9b66aSDmitri Tikhonov void *rechist, lsquic_time_t now, int *has_missing, lsquic_packno_t *); 12050aadb33SDmitri Tikhonov 12150aadb33SDmitri Tikhonov#endif 122