lsquic_parse_gquic_be.h revision bfc7bfd8
1/* Copyright (c) 2017 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#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) 12#include <sys/endian.h> 13#define bswap_16 bswap16 14#define bswap_32 bswap32 15#define bswap_64 bswap64 16#elif defined(__APPLE__) 17#include <libkern/OSByteOrder.h> 18#define bswap_16 OSSwapInt16 19#define bswap_32 OSSwapInt32 20#define bswap_64 OSSwapInt64 21#else 22#include <byteswap.h> 23#endif 24 25#define CHECK_SPACE(need, pstart, pend) \ 26 do { if ((intptr_t) (need) > ((pend) - (pstart))) { return -1; } } while (0) 27 28#if __BYTE_ORDER == __LITTLE_ENDIAN 29#define READ_UINT(varname, varwidth, src, nbytes) do { \ 30 varname = 0; \ 31 memcpy((unsigned char *) &varname + varwidth / 8 - (nbytes), (src), \ 32 (nbytes)); \ 33 varname = bswap_##varwidth(varname); \ 34} while (0) 35#else 36#define READ_UINT(varname, varwidth, src, nbytes) do { \ 37 varname = 0; \ 38 memcpy((unsigned char *) &varname + varwidth / 8 - (nbytes), (src), \ 39 (nbytes)); \ 40} while (0) 41#endif 42 43uint64_t 44gquic_be_read_float_time16 (const void *mem); 45 46void 47gquic_be_write_float_time16 (lsquic_time_t time_us, void *mem); 48 49void 50gquic_be_parse_packet_in_finish (lsquic_packet_in_t *packet_in, 51 struct packin_parse_state *state); 52 53int 54gquic_be_gen_ver_nego_pkt (unsigned char *buf, size_t bufsz, uint64_t conn_id, 55 unsigned version_bitmask); 56 57int 58gquic_be_gen_reg_pkt_header (unsigned char *buf, size_t bufsz, const lsquic_cid_t *conn_id, 59 const lsquic_ver_tag_t *ver, const unsigned char *nonce, 60 lsquic_packno_t packno, enum lsquic_packno_bits bits); 61 62int 63gquic_be_gen_stream_frame (unsigned char *buf, size_t buf_len, uint32_t stream_id, 64 uint64_t offset, int fin, size_t size, 65 gsf_read_f gsf_read, void *stream); 66 67int 68gquic_be_parse_stream_frame (const unsigned char *buf, size_t rem_packet_sz, 69 stream_frame_t *stream_frame); 70 71lsquic_packno_t 72gquic_be_parse_ack_high (const unsigned char *buf, size_t buf_len); 73 74int 75gquic_be_parse_ack_frame (const unsigned char *buf, size_t buf_len, ack_info_t *ack); 76 77int 78gquic_be_gen_stop_waiting_frame(unsigned char *buf, size_t buf_len, 79 lsquic_packno_t cur_packno, enum lsquic_packno_bits bits, 80 lsquic_packno_t least_unacked_packno); 81 82int 83gquic_be_parse_stop_waiting_frame (const unsigned char *buf, size_t buf_len, 84 lsquic_packno_t cur_packno, enum lsquic_packno_bits bits, 85 lsquic_packno_t *least_unacked); 86 87int 88gquic_be_skip_stop_waiting_frame (size_t buf_len, enum lsquic_packno_bits bits); 89 90int 91gquic_be_gen_window_update_frame (unsigned char *buf, int buf_len, uint32_t stream_id, 92 uint64_t offset); 93 94int 95gquic_be_parse_window_update_frame (const unsigned char *buf, size_t buf_len, 96 uint32_t *stream_id, uint64_t *offset); 97 98int 99gquic_be_gen_blocked_frame (unsigned char *buf, size_t buf_len, uint32_t stream_id); 100 101int 102gquic_be_parse_blocked_frame (const unsigned char *buf, size_t buf_len, 103 uint32_t *stream_id); 104 105int 106gquic_be_gen_rst_frame (unsigned char *buf, size_t buf_len, uint32_t stream_id, 107 uint64_t offset, uint32_t error_code); 108 109int 110gquic_be_parse_rst_frame (const unsigned char *buf, size_t buf_len, uint32_t *stream_id, 111 uint64_t *offset, uint32_t *error_code); 112 113int 114gquic_be_gen_ping_frame (unsigned char *buf, int buf_len); 115 116int 117gquic_be_gen_connect_close_frame (unsigned char *buf, int buf_len, uint32_t error_code, 118 const char *reason, int reason_len); 119 120int 121gquic_be_parse_connect_close_frame (const unsigned char *buf, size_t buf_len, 122 uint32_t *error_code, uint16_t *reason_len, uint8_t *reason_offset); 123 124int 125gquic_be_gen_goaway_frame(unsigned char *buf, size_t buf_len, uint32_t error_code, 126 uint32_t last_good_stream_id, const char *reason, 127 size_t reason_len); 128 129int 130gquic_be_parse_goaway_frame (const unsigned char *buf, size_t buf_len, 131 uint32_t *error_code, uint32_t *last_good_stream_id, 132 uint16_t *reason_length, const char **reason); 133 134int 135gquic_be_gen_ack_frame (unsigned char *outbuf, size_t outbuf_sz, 136 gaf_rechist_first_f rechist_first, gaf_rechist_next_f rechist_next, 137 gaf_rechist_largest_recv_f rechist_largest_recv, 138 void *rechist, lsquic_time_t now, int *has_missing); 139 140#endif 141