lsquic_parse_common.h revision 5392f7a3
1229fce07SDmitri Tikhonov/* Copyright (c) 2017 - 2019 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 385392f7a3SLiteSpeed Techlsquic_Q046_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, 615392f7a3SLiteSpeed Tech const lsquic_cid_t *scid, const lsquic_cid_t *dcid, unsigned versions); 625392f7a3SLiteSpeed Techint 635392f7a3SLiteSpeed Techlsquic_ietf_v1_gen_ver_nego_pkt (unsigned char *buf, size_t bufsz, 645392f7a3SLiteSpeed Tech const lsquic_cid_t *scid, const lsquic_cid_t *dcid, unsigned versions); 655392f7a3SLiteSpeed Techint 665392f7a3SLiteSpeed Techlsquic_iquic_gen_retry_pkt (unsigned char *buf, size_t bufsz, 675392f7a3SLiteSpeed Tech const struct lsquic_engine_public *, const lsquic_cid_t *scid, 685392f7a3SLiteSpeed Tech const lsquic_cid_t *dcid, enum lsquic_version, const struct sockaddr *, 695392f7a3SLiteSpeed Tech uint8_t random_nybble); 705392f7a3SLiteSpeed Techssize_t 715392f7a3SLiteSpeed Techlsquic_generate_iquic_reset (const lsquic_cid_t *, unsigned char *buf, 725392f7a3SLiteSpeed Tech size_t buf_sz); 735392f7a3SLiteSpeed Tech 745392f7a3SLiteSpeed Tech#define GQUIC_RESET_SZ 33 755392f7a3SLiteSpeed Techssize_t 765392f7a3SLiteSpeed Techlsquic_generate_gquic_reset (const lsquic_cid_t *, unsigned char *buf, 775392f7a3SLiteSpeed Tech size_t buf_sz); 785392f7a3SLiteSpeed Tech 795392f7a3SLiteSpeed Techint 805392f7a3SLiteSpeed Techlsquic_is_valid_iquic_hs_packet (const unsigned char *buf, size_t buf_sz, 815392f7a3SLiteSpeed Tech lsquic_ver_tag_t *tag); 825392f7a3SLiteSpeed Tech 835392f7a3SLiteSpeed Techint 845392f7a3SLiteSpeed Techlsquic_is_valid_ietf_v1_or_Q046_hs_packet (const unsigned char *buf, 855392f7a3SLiteSpeed Tech size_t length, lsquic_ver_tag_t *tagp); 869626cfc2SDmitri Tikhonov 8714e3680dSDmitri Tikhonov/* Instead of just -1 like CHECK_SPACE(), this macro returns the number 8814e3680dSDmitri Tikhonov * of bytes needed. 8914e3680dSDmitri Tikhonov */ 9014e3680dSDmitri Tikhonov#define CHECK_STREAM_SPACE(need, pstart, pend) do { \ 9114e3680dSDmitri Tikhonov if ((intptr_t) (need) > ((pend) - (pstart))) { \ 9214e3680dSDmitri Tikhonov return -((int) (need)); \ 9314e3680dSDmitri Tikhonov } \ 9414e3680dSDmitri Tikhonov} while (0) 9514e3680dSDmitri Tikhonov 969626cfc2SDmitri Tikhonov#endif 97