lsquic_parse_common.h revision 9fc12041
1/* Copyright (c) 2017 - 2020 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_Q050_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, 62 uint8_t); 63int 64lsquic_ietf_v1_gen_ver_nego_pkt (unsigned char *buf, size_t bufsz, 65 const lsquic_cid_t *scid, const lsquic_cid_t *dcid, unsigned versions, 66 uint8_t); 67int 68lsquic_iquic_gen_retry_pkt (unsigned char *buf, size_t bufsz, 69 const struct lsquic_engine_public *, const lsquic_cid_t *scid, 70 const lsquic_cid_t *dcid, enum lsquic_version, const struct sockaddr *, 71 uint8_t random_nybble); 72 73#define GQUIC_RESET_SZ 33 74ssize_t 75lsquic_generate_gquic_reset (const lsquic_cid_t *, unsigned char *buf, 76 size_t buf_sz); 77 78int 79lsquic_is_valid_iquic_hs_packet (const unsigned char *buf, size_t buf_sz, 80 lsquic_ver_tag_t *tag); 81 82int 83lsquic_is_valid_ietf_v1_or_Q046plus_hs_packet (const unsigned char *buf, 84 size_t length, lsquic_ver_tag_t *tagp); 85 86/* Instead of just -1 like CHECK_SPACE(), this macro returns the number 87 * of bytes needed. 88 */ 89#define CHECK_STREAM_SPACE(need, pstart, pend) do { \ 90 if ((intptr_t) (need) > ((pend) - (pstart))) { \ 91 return -((int) (need)); \ 92 } \ 93} while (0) 94 95#endif 96