lsquic_parse_common.h revision 5392f7a3
1/* Copyright (c) 2017 - 2019 LiteSpeed Technologies Inc. See LICENSE. */ 2/* 3 * lsquic_parse_common.h 4 */ 5 6#ifndef LSQUIC_PARSE_COMMON_H 7#define LSQUIC_PARSE_COMMON_H 1 8 9struct lsquic_packet_in; 10struct packin_parse_state; 11 12struct packin_parse_state { 13 const unsigned char *pps_p; /* Pointer to packet number */ 14 unsigned pps_nbytes; /* Number of bytes in packet number */ 15}; 16 17int 18lsquic_parse_packet_in_begin (struct lsquic_packet_in *, 19 size_t length, int is_server, unsigned cid_len, 20 struct packin_parse_state *); 21 22int 23lsquic_parse_packet_in_server_begin (struct lsquic_packet_in *packet_in, 24 size_t length, int is_server_UNUSED, unsigned cid_len, 25 struct packin_parse_state *); 26 27int 28lsquic_ietf_v1_parse_packet_in_begin (struct lsquic_packet_in *, 29 size_t length, int is_server, unsigned cid_len, 30 struct packin_parse_state *); 31 32int 33lsquic_Q046_parse_packet_in_begin (struct lsquic_packet_in *, 34 size_t length, int is_server, unsigned cid_len, 35 struct packin_parse_state *); 36 37int 38lsquic_Q046_parse_packet_in_begin (struct lsquic_packet_in *, 39 size_t length, int is_server, unsigned cid_len, 40 struct packin_parse_state *); 41 42int 43lsquic_ietf_v1_parse_packet_in_long_begin (struct lsquic_packet_in *, 44 size_t length, int is_server, unsigned cid_len, 45 struct packin_parse_state *); 46 47int 48lsquic_ietf_v1_parse_packet_in_short_begin (struct lsquic_packet_in *, 49 size_t length, int is_server, unsigned cid_len, 50 struct packin_parse_state *); 51 52struct sockaddr; 53enum lsquic_version; 54struct lsquic_engine_public; 55 56int 57lsquic_gquic_gen_ver_nego_pkt (unsigned char *buf, size_t bufsz, 58 const lsquic_cid_t *cid, unsigned versions); 59int 60lsquic_Q046_gen_ver_nego_pkt (unsigned char *buf, size_t bufsz, 61 const lsquic_cid_t *scid, const lsquic_cid_t *dcid, unsigned versions); 62int 63lsquic_ietf_v1_gen_ver_nego_pkt (unsigned char *buf, size_t bufsz, 64 const lsquic_cid_t *scid, const lsquic_cid_t *dcid, unsigned versions); 65int 66lsquic_iquic_gen_retry_pkt (unsigned char *buf, size_t bufsz, 67 const struct lsquic_engine_public *, const lsquic_cid_t *scid, 68 const lsquic_cid_t *dcid, enum lsquic_version, const struct sockaddr *, 69 uint8_t random_nybble); 70ssize_t 71lsquic_generate_iquic_reset (const lsquic_cid_t *, unsigned char *buf, 72 size_t buf_sz); 73 74#define GQUIC_RESET_SZ 33 75ssize_t 76lsquic_generate_gquic_reset (const lsquic_cid_t *, unsigned char *buf, 77 size_t buf_sz); 78 79int 80lsquic_is_valid_iquic_hs_packet (const unsigned char *buf, size_t buf_sz, 81 lsquic_ver_tag_t *tag); 82 83int 84lsquic_is_valid_ietf_v1_or_Q046_hs_packet (const unsigned char *buf, 85 size_t length, lsquic_ver_tag_t *tagp); 86 87/* Instead of just -1 like CHECK_SPACE(), this macro returns the number 88 * of bytes needed. 89 */ 90#define CHECK_STREAM_SPACE(need, pstart, pend) do { \ 91 if ((intptr_t) (need) > ((pend) - (pstart))) { \ 92 return -((int) (need)); \ 93 } \ 94} while (0) 95 96#endif 97