1a74702c6SGeorge Wang/* Copyright (c) 2017 - 2022 LiteSpeed Technologies Inc. See LICENSE. */ 250aadb33SDmitri Tikhonov#include <assert.h> 350aadb33SDmitri Tikhonov#include <stdint.h> 450aadb33SDmitri Tikhonov#include <string.h> 5461e84d8SAmol Deshpande#include <sys/queue.h> 6461e84d8SAmol Deshpande#ifdef WIN32 7461e84d8SAmol Deshpande#include <vc_compat.h> 8461e84d8SAmol Deshpande#endif 950aadb33SDmitri Tikhonov 1050aadb33SDmitri Tikhonov#include "lsquic_int_types.h" 1150aadb33SDmitri Tikhonov#include "lsquic_types.h" 12bfc7bfd8SDmitri Tikhonov#include "lsquic_packet_common.h" 1350aadb33SDmitri Tikhonov#include "lsquic_packet_in.h" 1450aadb33SDmitri Tikhonov 1550aadb33SDmitri Tikhonov 1650aadb33SDmitri Tikhonovint 17a5fa05f9SDmitri Tikhonovlsquic_packet_in_ver_first (const lsquic_packet_in_t *packet_in, 18a5fa05f9SDmitri Tikhonov struct ver_iter *vi, lsquic_ver_tag_t *ver_tag) 1950aadb33SDmitri Tikhonov{ 2050aadb33SDmitri Tikhonov vi->packet_in = packet_in; 2150aadb33SDmitri Tikhonov vi->off = packet_in->pi_quic_ver; 22a5fa05f9SDmitri Tikhonov return lsquic_packet_in_ver_next(vi, ver_tag); 2350aadb33SDmitri Tikhonov} 2450aadb33SDmitri Tikhonov 2550aadb33SDmitri Tikhonov 2650aadb33SDmitri Tikhonovint 27a5fa05f9SDmitri Tikhonovlsquic_packet_in_ver_next (struct ver_iter *vi, lsquic_ver_tag_t *ver_tag) 2850aadb33SDmitri Tikhonov{ 2950aadb33SDmitri Tikhonov if (vi->off + 4 <= vi->packet_in->pi_header_sz) 3050aadb33SDmitri Tikhonov { 3150aadb33SDmitri Tikhonov memcpy(ver_tag, vi->packet_in->pi_data + vi->off, 4); 3250aadb33SDmitri Tikhonov vi->off += 4; 3350aadb33SDmitri Tikhonov return 1; 3450aadb33SDmitri Tikhonov } 3550aadb33SDmitri Tikhonov else 3650aadb33SDmitri Tikhonov { 3750aadb33SDmitri Tikhonov assert(vi->packet_in->pi_header_sz == vi->off); 3850aadb33SDmitri Tikhonov return 0; 3950aadb33SDmitri Tikhonov } 4050aadb33SDmitri Tikhonov} 41c51ce338SDmitri Tikhonov 42c51ce338SDmitri Tikhonov 43c51ce338SDmitri Tikhonovsize_t 44c51ce338SDmitri Tikhonovlsquic_packet_in_mem_used (const struct lsquic_packet_in *packet_in) 45c51ce338SDmitri Tikhonov{ 46c51ce338SDmitri Tikhonov size_t size; 47c51ce338SDmitri Tikhonov 48c51ce338SDmitri Tikhonov size = sizeof(*packet_in); 49c51ce338SDmitri Tikhonov 50c51ce338SDmitri Tikhonov if (packet_in->pi_flags & PI_OWN_DATA) 51c51ce338SDmitri Tikhonov size += packet_in->pi_data_sz; 52c51ce338SDmitri Tikhonov 53c51ce338SDmitri Tikhonov return size; 54c51ce338SDmitri Tikhonov} 555392f7a3SLiteSpeed Tech 565392f7a3SLiteSpeed Tech 575392f7a3SLiteSpeed Techvoid 585392f7a3SLiteSpeed Techlsquic_scid_from_packet_in (const struct lsquic_packet_in *packet_in, 595392f7a3SLiteSpeed Tech lsquic_cid_t *scid) 605392f7a3SLiteSpeed Tech{ 615392f7a3SLiteSpeed Tech scid->len = packet_in->pi_scid_len; 625392f7a3SLiteSpeed Tech memcpy(scid->idbuf, packet_in->pi_data + packet_in->pi_scid_off, scid->len); 635392f7a3SLiteSpeed Tech} 64