1a74702c6SGeorge Wang/* Copyright (c) 2017 - 2022 LiteSpeed Technologies Inc. See LICENSE. */ 29626cfc2SDmitri Tikhonov/* 39626cfc2SDmitri Tikhonov * lsquic_parse_common.h 49626cfc2SDmitri Tikhonov */ 59626cfc2SDmitri Tikhonov 69626cfc2SDmitri Tikhonov#ifndef LSQUIC_PARSE_COMMON_H 79626cfc2SDmitri Tikhonov#define LSQUIC_PARSE_COMMON_H 1 89626cfc2SDmitri Tikhonov 9fb3e20e0SDmitri Tikhonov#ifdef WIN32 10fb3e20e0SDmitri Tikhonov#include "vc_compat.h" 11fb3e20e0SDmitri Tikhonov#endif 12fb3e20e0SDmitri Tikhonov 139626cfc2SDmitri Tikhonovstruct lsquic_packet_in; 145392f7a3SLiteSpeed Techstruct packin_parse_state; 159626cfc2SDmitri Tikhonov 169626cfc2SDmitri Tikhonovstruct packin_parse_state { 179626cfc2SDmitri Tikhonov const unsigned char *pps_p; /* Pointer to packet number */ 189626cfc2SDmitri Tikhonov unsigned pps_nbytes; /* Number of bytes in packet number */ 199626cfc2SDmitri Tikhonov}; 209626cfc2SDmitri Tikhonov 219626cfc2SDmitri Tikhonovint 229626cfc2SDmitri Tikhonovlsquic_parse_packet_in_begin (struct lsquic_packet_in *, 235392f7a3SLiteSpeed Tech size_t length, int is_server, unsigned cid_len, 245392f7a3SLiteSpeed Tech struct packin_parse_state *); 259626cfc2SDmitri Tikhonov 269626cfc2SDmitri Tikhonovint 275392f7a3SLiteSpeed Techlsquic_parse_packet_in_server_begin (struct lsquic_packet_in *packet_in, 285392f7a3SLiteSpeed Tech size_t length, int is_server_UNUSED, unsigned cid_len, 295392f7a3SLiteSpeed Tech struct packin_parse_state *); 305392f7a3SLiteSpeed Tech 315392f7a3SLiteSpeed Techint 325392f7a3SLiteSpeed Techlsquic_ietf_v1_parse_packet_in_begin (struct lsquic_packet_in *, 335392f7a3SLiteSpeed Tech size_t length, int is_server, unsigned cid_len, 345392f7a3SLiteSpeed Tech struct packin_parse_state *); 355392f7a3SLiteSpeed Tech 365392f7a3SLiteSpeed Techint 375392f7a3SLiteSpeed Techlsquic_Q046_parse_packet_in_begin (struct lsquic_packet_in *, 385392f7a3SLiteSpeed Tech size_t length, int is_server, unsigned cid_len, 395392f7a3SLiteSpeed Tech struct packin_parse_state *); 405392f7a3SLiteSpeed Tech 415392f7a3SLiteSpeed Techint 427a8b2eceSDmitri Tikhonovlsquic_Q050_parse_packet_in_begin (struct lsquic_packet_in *, 435392f7a3SLiteSpeed Tech size_t length, int is_server, unsigned cid_len, 445392f7a3SLiteSpeed Tech struct packin_parse_state *); 455392f7a3SLiteSpeed Tech 465392f7a3SLiteSpeed Techint 475392f7a3SLiteSpeed Techlsquic_ietf_v1_parse_packet_in_long_begin (struct lsquic_packet_in *, 485392f7a3SLiteSpeed Tech size_t length, int is_server, unsigned cid_len, 495392f7a3SLiteSpeed Tech struct packin_parse_state *); 505392f7a3SLiteSpeed Tech 515392f7a3SLiteSpeed Techint 525392f7a3SLiteSpeed Techlsquic_ietf_v1_parse_packet_in_short_begin (struct lsquic_packet_in *, 535392f7a3SLiteSpeed Tech size_t length, int is_server, unsigned cid_len, 545392f7a3SLiteSpeed Tech struct packin_parse_state *); 555392f7a3SLiteSpeed Tech 565392f7a3SLiteSpeed Techstruct sockaddr; 575392f7a3SLiteSpeed Techenum lsquic_version; 585392f7a3SLiteSpeed Techstruct lsquic_engine_public; 595392f7a3SLiteSpeed Tech 605392f7a3SLiteSpeed Techint 615392f7a3SLiteSpeed Techlsquic_gquic_gen_ver_nego_pkt (unsigned char *buf, size_t bufsz, 625392f7a3SLiteSpeed Tech const lsquic_cid_t *cid, unsigned versions); 635392f7a3SLiteSpeed Techint 645392f7a3SLiteSpeed Techlsquic_Q046_gen_ver_nego_pkt (unsigned char *buf, size_t bufsz, 65a0e1aeeeSDmitri Tikhonov const lsquic_cid_t *scid, const lsquic_cid_t *dcid, unsigned versions, 66a0e1aeeeSDmitri Tikhonov uint8_t); 675392f7a3SLiteSpeed Techint 685392f7a3SLiteSpeed Techlsquic_ietf_v1_gen_ver_nego_pkt (unsigned char *buf, size_t bufsz, 69a0e1aeeeSDmitri Tikhonov const lsquic_cid_t *scid, const lsquic_cid_t *dcid, unsigned versions, 70a0e1aeeeSDmitri Tikhonov uint8_t); 715392f7a3SLiteSpeed Tech 725392f7a3SLiteSpeed Tech#define GQUIC_RESET_SZ 33 735392f7a3SLiteSpeed Techssize_t 745392f7a3SLiteSpeed Techlsquic_generate_gquic_reset (const lsquic_cid_t *, unsigned char *buf, 755392f7a3SLiteSpeed Tech size_t buf_sz); 765392f7a3SLiteSpeed Tech 775392f7a3SLiteSpeed Techint 785392f7a3SLiteSpeed Techlsquic_is_valid_iquic_hs_packet (const unsigned char *buf, size_t buf_sz, 795392f7a3SLiteSpeed Tech lsquic_ver_tag_t *tag); 805392f7a3SLiteSpeed Tech 815392f7a3SLiteSpeed Techint 827a8b2eceSDmitri Tikhonovlsquic_is_valid_ietf_v1_or_Q046plus_hs_packet (const unsigned char *buf, 835392f7a3SLiteSpeed Tech size_t length, lsquic_ver_tag_t *tagp); 849626cfc2SDmitri Tikhonov 8514e3680dSDmitri Tikhonov/* Instead of just -1 like CHECK_SPACE(), this macro returns the number 8614e3680dSDmitri Tikhonov * of bytes needed. 8714e3680dSDmitri Tikhonov */ 8814e3680dSDmitri Tikhonov#define CHECK_STREAM_SPACE(need, pstart, pend) do { \ 8914e3680dSDmitri Tikhonov if ((intptr_t) (need) > ((pend) - (pstart))) { \ 9014e3680dSDmitri Tikhonov return -((int) (need)); \ 9114e3680dSDmitri Tikhonov } \ 9214e3680dSDmitri Tikhonov} while (0) 9314e3680dSDmitri Tikhonov 949626cfc2SDmitri Tikhonov#endif 95