lsquic_parse_common.h revision 7d09751d
17d09751dSDmitri Tikhonov/* Copyright (c) 2017 - 2020 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 99626cfc2SDmitri Tikhonovstruct lsquic_packet_in; 105392f7a3SLiteSpeed Techstruct packin_parse_state; 119626cfc2SDmitri Tikhonov 129626cfc2SDmitri Tikhonovstruct packin_parse_state { 139626cfc2SDmitri Tikhonov const unsigned char *pps_p; /* Pointer to packet number */ 149626cfc2SDmitri Tikhonov unsigned pps_nbytes; /* Number of bytes in packet number */ 159626cfc2SDmitri Tikhonov}; 169626cfc2SDmitri Tikhonov 179626cfc2SDmitri Tikhonovint 189626cfc2SDmitri Tikhonovlsquic_parse_packet_in_begin (struct lsquic_packet_in *, 195392f7a3SLiteSpeed Tech size_t length, int is_server, unsigned cid_len, 205392f7a3SLiteSpeed Tech struct packin_parse_state *); 219626cfc2SDmitri Tikhonov 229626cfc2SDmitri Tikhonovint 235392f7a3SLiteSpeed Techlsquic_parse_packet_in_server_begin (struct lsquic_packet_in *packet_in, 245392f7a3SLiteSpeed Tech size_t length, int is_server_UNUSED, unsigned cid_len, 255392f7a3SLiteSpeed Tech struct packin_parse_state *); 265392f7a3SLiteSpeed Tech 275392f7a3SLiteSpeed Techint 285392f7a3SLiteSpeed Techlsquic_ietf_v1_parse_packet_in_begin (struct lsquic_packet_in *, 295392f7a3SLiteSpeed Tech size_t length, int is_server, unsigned cid_len, 305392f7a3SLiteSpeed Tech struct packin_parse_state *); 315392f7a3SLiteSpeed Tech 325392f7a3SLiteSpeed Techint 335392f7a3SLiteSpeed Techlsquic_Q046_parse_packet_in_begin (struct lsquic_packet_in *, 345392f7a3SLiteSpeed Tech size_t length, int is_server, unsigned cid_len, 355392f7a3SLiteSpeed Tech struct packin_parse_state *); 365392f7a3SLiteSpeed Tech 375392f7a3SLiteSpeed Techint 387a8b2eceSDmitri Tikhonovlsquic_Q050_parse_packet_in_begin (struct lsquic_packet_in *, 395392f7a3SLiteSpeed Tech size_t length, int is_server, unsigned cid_len, 405392f7a3SLiteSpeed Tech struct packin_parse_state *); 415392f7a3SLiteSpeed Tech 425392f7a3SLiteSpeed Techint 435392f7a3SLiteSpeed Techlsquic_ietf_v1_parse_packet_in_long_begin (struct lsquic_packet_in *, 445392f7a3SLiteSpeed Tech size_t length, int is_server, unsigned cid_len, 455392f7a3SLiteSpeed Tech struct packin_parse_state *); 465392f7a3SLiteSpeed Tech 475392f7a3SLiteSpeed Techint 485392f7a3SLiteSpeed Techlsquic_ietf_v1_parse_packet_in_short_begin (struct lsquic_packet_in *, 495392f7a3SLiteSpeed Tech size_t length, int is_server, unsigned cid_len, 505392f7a3SLiteSpeed Tech struct packin_parse_state *); 515392f7a3SLiteSpeed Tech 525392f7a3SLiteSpeed Techstruct sockaddr; 535392f7a3SLiteSpeed Techenum lsquic_version; 545392f7a3SLiteSpeed Techstruct lsquic_engine_public; 555392f7a3SLiteSpeed Tech 565392f7a3SLiteSpeed Techint 575392f7a3SLiteSpeed Techlsquic_gquic_gen_ver_nego_pkt (unsigned char *buf, size_t bufsz, 585392f7a3SLiteSpeed Tech const lsquic_cid_t *cid, unsigned versions); 595392f7a3SLiteSpeed Techint 605392f7a3SLiteSpeed Techlsquic_Q046_gen_ver_nego_pkt (unsigned char *buf, size_t bufsz, 61a0e1aeeeSDmitri Tikhonov const lsquic_cid_t *scid, const lsquic_cid_t *dcid, unsigned versions, 62a0e1aeeeSDmitri Tikhonov uint8_t); 635392f7a3SLiteSpeed Techint 645392f7a3SLiteSpeed Techlsquic_ietf_v1_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_iquic_gen_retry_pkt (unsigned char *buf, size_t bufsz, 695392f7a3SLiteSpeed Tech const struct lsquic_engine_public *, const lsquic_cid_t *scid, 705392f7a3SLiteSpeed Tech const lsquic_cid_t *dcid, enum lsquic_version, const struct sockaddr *, 715392f7a3SLiteSpeed Tech uint8_t random_nybble); 725392f7a3SLiteSpeed Techssize_t 735392f7a3SLiteSpeed Techlsquic_generate_iquic_reset (const lsquic_cid_t *, unsigned char *buf, 745392f7a3SLiteSpeed Tech size_t buf_sz); 755392f7a3SLiteSpeed Tech 765392f7a3SLiteSpeed Tech#define GQUIC_RESET_SZ 33 775392f7a3SLiteSpeed Techssize_t 785392f7a3SLiteSpeed Techlsquic_generate_gquic_reset (const lsquic_cid_t *, unsigned char *buf, 795392f7a3SLiteSpeed Tech size_t buf_sz); 805392f7a3SLiteSpeed Tech 815392f7a3SLiteSpeed Techint 825392f7a3SLiteSpeed Techlsquic_is_valid_iquic_hs_packet (const unsigned char *buf, size_t buf_sz, 835392f7a3SLiteSpeed Tech lsquic_ver_tag_t *tag); 845392f7a3SLiteSpeed Tech 855392f7a3SLiteSpeed Techint 867a8b2eceSDmitri Tikhonovlsquic_is_valid_ietf_v1_or_Q046plus_hs_packet (const unsigned char *buf, 875392f7a3SLiteSpeed Tech size_t length, lsquic_ver_tag_t *tagp); 889626cfc2SDmitri Tikhonov 8914e3680dSDmitri Tikhonov/* Instead of just -1 like CHECK_SPACE(), this macro returns the number 9014e3680dSDmitri Tikhonov * of bytes needed. 9114e3680dSDmitri Tikhonov */ 9214e3680dSDmitri Tikhonov#define CHECK_STREAM_SPACE(need, pstart, pend) do { \ 9314e3680dSDmitri Tikhonov if ((intptr_t) (need) > ((pend) - (pstart))) { \ 9414e3680dSDmitri Tikhonov return -((int) (need)); \ 9514e3680dSDmitri Tikhonov } \ 9614e3680dSDmitri Tikhonov} while (0) 9714e3680dSDmitri Tikhonov 989626cfc2SDmitri Tikhonov#endif 99