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