lsquic_packet_in.h revision c51ce338
150aadb33SDmitri Tikhonov/* Copyright (c) 2017 LiteSpeed Technologies Inc. See LICENSE. */ 250aadb33SDmitri Tikhonov/* 350aadb33SDmitri Tikhonov * lsquic_packet_in.h 450aadb33SDmitri Tikhonov */ 550aadb33SDmitri Tikhonov 650aadb33SDmitri Tikhonov#ifndef LSQUIC_PACKET_IN_H 750aadb33SDmitri Tikhonov#define LSQUIC_PACKET_IN_H 1 850aadb33SDmitri Tikhonov 950aadb33SDmitri Tikhonov#include <sys/queue.h> 1050aadb33SDmitri Tikhonov 1150aadb33SDmitri Tikhonovstruct lsquic_packet_in; 1250aadb33SDmitri Tikhonov 1350aadb33SDmitri Tikhonovstruct data_frame 1450aadb33SDmitri Tikhonov{ 1550aadb33SDmitri Tikhonov const unsigned char *df_data; /* Pointer to data */ 1650aadb33SDmitri Tikhonov uint64_t df_offset; /* Stream offset */ 1750aadb33SDmitri Tikhonov uint16_t df_read_off; /* Read offset */ 1850aadb33SDmitri Tikhonov uint16_t df_size; /* Size of df_data */ 1950aadb33SDmitri Tikhonov signed char df_fin; /* FIN? */ 2050aadb33SDmitri Tikhonov}; 2150aadb33SDmitri Tikhonov 2250aadb33SDmitri Tikhonovtypedef struct stream_frame 2350aadb33SDmitri Tikhonov{ 2450aadb33SDmitri Tikhonov /* Stream frames are stored in a list inside stream. */ 2550aadb33SDmitri Tikhonov TAILQ_ENTRY(stream_frame) next_frame; 2650aadb33SDmitri Tikhonov 2750aadb33SDmitri Tikhonov /* `data' points somewhere into the packet payload. The packet object 2850aadb33SDmitri Tikhonov * is reference-counted. When the frame is freed, the packet is released 2950aadb33SDmitri Tikhonov * via lsquic_packet_put(). If data_length is zero, the frame does not 3050aadb33SDmitri Tikhonov * keep a reference to the incoming packet and this pointer is not set. 3150aadb33SDmitri Tikhonov */ 3250aadb33SDmitri Tikhonov struct lsquic_packet_in *packet_in; 3350aadb33SDmitri Tikhonov 3450aadb33SDmitri Tikhonov struct data_frame data_frame; 3550aadb33SDmitri Tikhonov 3650aadb33SDmitri Tikhonov uint32_t stream_id; /* Parsed from packet */ 3750aadb33SDmitri Tikhonov} stream_frame_t; 3850aadb33SDmitri Tikhonov 3950aadb33SDmitri Tikhonovtypedef struct lsquic_packet_in 4050aadb33SDmitri Tikhonov{ 4150aadb33SDmitri Tikhonov TAILQ_ENTRY(lsquic_packet_in) pi_next; 4250aadb33SDmitri Tikhonov lsquic_time_t pi_received; /* Time received */ 4350aadb33SDmitri Tikhonov lsquic_cid_t pi_conn_id; 4450aadb33SDmitri Tikhonov lsquic_packno_t pi_packno; 4550aadb33SDmitri Tikhonov unsigned short pi_header_sz; /* Points to payload */ 4650aadb33SDmitri Tikhonov unsigned short pi_data_sz; /* Data plus header */ 4750aadb33SDmitri Tikhonov /* A packet may be referred to by one or more frames and packets_in 4850aadb33SDmitri Tikhonov * list. 4950aadb33SDmitri Tikhonov */ 5050aadb33SDmitri Tikhonov unsigned short pi_refcnt; 5150aadb33SDmitri Tikhonov short pi_frame_types; 5250aadb33SDmitri Tikhonov unsigned short pi_hsk_stream; /* Offset to handshake stream 5350aadb33SDmitri Tikhonov * frame, only valid if 5450aadb33SDmitri Tikhonov * PI_HSK_STREAM is set. 5550aadb33SDmitri Tikhonov */ 5650aadb33SDmitri Tikhonov unsigned char pi_quic_ver; /* Offset to QUIC version */ 5750aadb33SDmitri Tikhonov unsigned char pi_nonce; /* Offset to nonce */ 5850aadb33SDmitri Tikhonov enum { 5950aadb33SDmitri Tikhonov PI_DECRYPTED = (1 << 0), 6050aadb33SDmitri Tikhonov PI_OWN_DATA = (1 << 1), /* We own pi_data */ 6150aadb33SDmitri Tikhonov PI_CONN_ID = (1 << 2), /* pi_conn_id is set */ 62c51ce338SDmitri Tikhonov#define PIBIT_ENC_LEV_SHIFT 5 63c51ce338SDmitri Tikhonov PI_ENC_LEV_BIT_0= (1 << 5), /* Encodes encryption level */ 64c51ce338SDmitri Tikhonov PI_ENC_LEV_BIT_1= (1 << 6), /* (see enum enc_level). */ 6550aadb33SDmitri Tikhonov } pi_flags:8; 6650aadb33SDmitri Tikhonov /* If PI_OWN_DATA flag is not set, `pi_data' points to user-supplied 6750aadb33SDmitri Tikhonov * packet data, which is NOT TO BE MODIFIED. 6850aadb33SDmitri Tikhonov */ 6950aadb33SDmitri Tikhonov unsigned char *pi_data; 7050aadb33SDmitri Tikhonov} lsquic_packet_in_t; 7150aadb33SDmitri Tikhonov 7250aadb33SDmitri Tikhonov#define lsquic_packet_in_public_flags(p) ((p)->pi_data[0]) 7350aadb33SDmitri Tikhonov 7450aadb33SDmitri Tikhonov#define lsquic_packet_in_is_prst(p) \ 7550aadb33SDmitri Tikhonov (lsquic_packet_in_public_flags(p) & PACKET_PUBLIC_FLAGS_RST) 7650aadb33SDmitri Tikhonov 7750aadb33SDmitri Tikhonov#define lsquic_packet_in_packno_bits(p) \ 7850aadb33SDmitri Tikhonov ((lsquic_packet_in_public_flags(p) >> 4) & 3) 7950aadb33SDmitri Tikhonov 8050aadb33SDmitri Tikhonov#define lsquic_packet_in_upref(p) (++(p)->pi_refcnt) 8150aadb33SDmitri Tikhonov 8250aadb33SDmitri Tikhonov#define lsquic_packet_in_get(p) (lsquic_packet_in_upref(p), (p)) 8350aadb33SDmitri Tikhonov 8450aadb33SDmitri Tikhonov#define lsquic_packet_in_nonce(p) \ 8550aadb33SDmitri Tikhonov ((p)->pi_nonce ? (p)->pi_data + (p)->pi_nonce : NULL) 8650aadb33SDmitri Tikhonov 87c51ce338SDmitri Tikhonov#define lsquic_packet_in_enc_level(p) \ 88c51ce338SDmitri Tikhonov (((p)->pi_flags >> PIBIT_ENC_LEV_SHIFT) & 0x3) 89c51ce338SDmitri Tikhonov 9050aadb33SDmitri Tikhonov/* The version iterator is used on a version negotiation packet only. 9150aadb33SDmitri Tikhonov * The iterator functions return 1 when next version is returned and 9250aadb33SDmitri Tikhonov * 0 when there are no more versions. 9350aadb33SDmitri Tikhonov */ 9450aadb33SDmitri Tikhonovstruct ver_iter 9550aadb33SDmitri Tikhonov{ 9650aadb33SDmitri Tikhonov const struct lsquic_packet_in *packet_in; 9750aadb33SDmitri Tikhonov unsigned off; 9850aadb33SDmitri Tikhonov}; 9950aadb33SDmitri Tikhonov 10050aadb33SDmitri Tikhonovint 10150aadb33SDmitri Tikhonovpacket_in_ver_first (const lsquic_packet_in_t *packet_in, struct ver_iter *, 10250aadb33SDmitri Tikhonov lsquic_ver_tag_t *ver_tag); 10350aadb33SDmitri Tikhonov 10450aadb33SDmitri Tikhonovint 10550aadb33SDmitri Tikhonovpacket_in_ver_next (struct ver_iter *, lsquic_ver_tag_t *ver_tag); 10650aadb33SDmitri Tikhonov 107c51ce338SDmitri Tikhonovsize_t 108c51ce338SDmitri Tikhonovlsquic_packet_in_mem_used (const struct lsquic_packet_in *); 109c51ce338SDmitri Tikhonov 11050aadb33SDmitri Tikhonov#endif 111