lsquic_packet_in.c revision 229fce07
1229fce07SDmitri Tikhonov/* Copyright (c) 2017 - 2019 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 1750aadb33SDmitri Tikhonovpacket_in_ver_first (const lsquic_packet_in_t *packet_in, struct ver_iter *vi, 1850aadb33SDmitri Tikhonov lsquic_ver_tag_t *ver_tag) 1950aadb33SDmitri Tikhonov{ 2050aadb33SDmitri Tikhonov vi->packet_in = packet_in; 2150aadb33SDmitri Tikhonov vi->off = packet_in->pi_quic_ver; 2250aadb33SDmitri Tikhonov return packet_in_ver_next(vi, ver_tag); 2350aadb33SDmitri Tikhonov} 2450aadb33SDmitri Tikhonov 2550aadb33SDmitri Tikhonov 2650aadb33SDmitri Tikhonovint 2750aadb33SDmitri Tikhonovpacket_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} 55