lsquic_packet_out.h revision da99665b
17d09751dSDmitri Tikhonov/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc.  See LICENSE. */
250aadb33SDmitri Tikhonov/*
350aadb33SDmitri Tikhonov * lsquic_packet_out.h -- Structure and routines dealing with packet_out
450aadb33SDmitri Tikhonov */
550aadb33SDmitri Tikhonov
650aadb33SDmitri Tikhonov#ifndef LSQUIC_PACKET_OUT_H
750aadb33SDmitri Tikhonov#define LSQUIC_PACKET_OUT_H 1
850aadb33SDmitri Tikhonov
950aadb33SDmitri Tikhonov#include <sys/queue.h>
1050aadb33SDmitri Tikhonov
1150aadb33SDmitri Tikhonovstruct malo;
129626cfc2SDmitri Tikhonovstruct lsquic_conn;
1350aadb33SDmitri Tikhonovstruct lsquic_engine_public;
1450aadb33SDmitri Tikhonovstruct lsquic_mm;
1550aadb33SDmitri Tikhonovstruct lsquic_stream;
165392f7a3SLiteSpeed Techstruct network_path;
1750aadb33SDmitri Tikhonovstruct parse_funcs;
185392f7a3SLiteSpeed Techstruct bwp_state;
1950aadb33SDmitri Tikhonov
2050aadb33SDmitri Tikhonov/* Each stream_rec is associated with one packet_out.  packet_out can have
2150aadb33SDmitri Tikhonov * zero or more stream_rec structures.  stream_rec keeps a pointer to a stream
224d83f5bdSDmitri Tikhonov * that has STREAM or RST_STREAM frames inside packet_out.  `sr_frame_type'
234d83f5bdSDmitri Tikhonov * specifies the type of the frame; if this value is zero, values of the
244d83f5bdSDmitri Tikhonov * other struct members are not valid.  `sr_off' indicates where inside
254d83f5bdSDmitri Tikhonov * packet_out->po_data the frame begins and `sr_len' is its length.
2650aadb33SDmitri Tikhonov *
27c51ce338SDmitri Tikhonov * We need this information for three reasons:
2850aadb33SDmitri Tikhonov *   1. A stream is not destroyed until all of its STREAM and RST_STREAM
2950aadb33SDmitri Tikhonov *      frames are acknowledged.  This is to make sure that we do not exceed
3050aadb33SDmitri Tikhonov *      maximum allowed number of streams.
3150aadb33SDmitri Tikhonov *   2. When a packet is resubmitted, STREAM frames for a stream that has
3250aadb33SDmitri Tikhonov *      been reset are not to be resubmitted.
33c51ce338SDmitri Tikhonov *   3. A buffered packet may have to be split before it is scheduled (this
34c51ce338SDmitri Tikhonov *      occurs if we guessed incorrectly the number of bytes required to
35c51ce338SDmitri Tikhonov *      encode the packet number and the actual number would make packet
36c51ce338SDmitri Tikhonov *      larger than the max).
37c51ce338SDmitri Tikhonov *
3850aadb33SDmitri Tikhonov */
3950aadb33SDmitri Tikhonovstruct stream_rec {
4050aadb33SDmitri Tikhonov    struct lsquic_stream    *sr_stream;
41c51ce338SDmitri Tikhonov    unsigned short           sr_off,
42c51ce338SDmitri Tikhonov                             sr_len;
436aba801dSDmitri Tikhonov    enum quic_frame_type     sr_frame_type:16;
4450aadb33SDmitri Tikhonov};
4550aadb33SDmitri Tikhonov
464d83f5bdSDmitri Tikhonov#define srec_taken(srec) ((srec)->sr_frame_type)
4750aadb33SDmitri Tikhonov
4850aadb33SDmitri Tikhonovstruct stream_rec_arr {
49c51ce338SDmitri Tikhonov    TAILQ_ENTRY(stream_rec_arr)     next_stream_rec_arr;
5050aadb33SDmitri Tikhonov    struct stream_rec               srecs[
5150aadb33SDmitri Tikhonov      ( 64                              /* Efficient size for malo allocator */
52c51ce338SDmitri Tikhonov      - sizeof(TAILQ_ENTRY(stream_rec)) /* next_stream_rec_arr */
5350aadb33SDmitri Tikhonov      ) / sizeof(struct stream_rec)
5450aadb33SDmitri Tikhonov    ];
5550aadb33SDmitri Tikhonov};
5650aadb33SDmitri Tikhonov
57c51ce338SDmitri TikhonovTAILQ_HEAD(stream_rec_arr_tailq, stream_rec_arr);
58c51ce338SDmitri Tikhonov
595392f7a3SLiteSpeed Tech
6050aadb33SDmitri Tikhonovtypedef struct lsquic_packet_out
6150aadb33SDmitri Tikhonov{
6250aadb33SDmitri Tikhonov    /* `po_next' is used for packets_out, unacked_packets and expired_packets
6350aadb33SDmitri Tikhonov     * lists.
6450aadb33SDmitri Tikhonov     */
6550aadb33SDmitri Tikhonov    TAILQ_ENTRY(lsquic_packet_out)
6650aadb33SDmitri Tikhonov                       po_next;
6750aadb33SDmitri Tikhonov    lsquic_time_t      po_sent;       /* Time sent */
6850aadb33SDmitri Tikhonov    lsquic_packno_t    po_packno;
695392f7a3SLiteSpeed Tech    lsquic_packno_t    po_ack2ed;       /* If packet has ACK frame, value of
705392f7a3SLiteSpeed Tech                                         * largest acked in it.
715392f7a3SLiteSpeed Tech                                         */
725392f7a3SLiteSpeed Tech    struct lsquic_packet_out
735392f7a3SLiteSpeed Tech                      *po_loss_chain;   /* Circular linked list */
7450aadb33SDmitri Tikhonov
755392f7a3SLiteSpeed Tech    enum quic_ft_bit   po_frame_types;  /* Bitmask of QUIC_FRAME_* */
76bfc7bfd8SDmitri Tikhonov    enum packet_out_flags {
775392f7a3SLiteSpeed Tech            /* TODO XXX Phase out PO_MINI in favor of a more specialized flag:
785392f7a3SLiteSpeed Tech             * we only need an indicator that a packet contains STREAM frames
795392f7a3SLiteSpeed Tech             * but no associated srecs.  This type of packets in only created
805392f7a3SLiteSpeed Tech             * by GQUIC mini conn.
815392f7a3SLiteSpeed Tech             */
825392f7a3SLiteSpeed Tech        PO_MINI     = (1 << 0),         /* Allocated by mini connection */
83bfc7bfd8SDmitri Tikhonov        PO_HELLO    = (1 << 1),         /* Packet contains SHLO or CHLO data */
845392f7a3SLiteSpeed Tech        PO_SENT     = (1 << 2),         /* Packet has been sent (mini only) */
85bfc7bfd8SDmitri Tikhonov        PO_ENCRYPTED= (1 << 3),         /* po_enc_data has encrypted data */
86bfc7bfd8SDmitri Tikhonov        PO_SREC_ARR = (1 << 4),
87bfc7bfd8SDmitri Tikhonov#define POBIT_SHIFT 5
88bfc7bfd8SDmitri Tikhonov        PO_BITS_0   = (1 << 5),         /* PO_BITS_0 and PO_BITS_1 encode the */
89bfc7bfd8SDmitri Tikhonov        PO_BITS_1   = (1 << 6),         /*   packet number length.  See macros below. */
90bfc7bfd8SDmitri Tikhonov        PO_NONCE    = (1 << 7),         /* Use value in `po_nonce' to generate header */
91bfc7bfd8SDmitri Tikhonov        PO_VERSION  = (1 << 8),         /* Use value in `po_ver_tag' to generate header */
92bfc7bfd8SDmitri Tikhonov        PO_CONN_ID  = (1 << 9),         /* Include connection ID in public header */
93bfc7bfd8SDmitri Tikhonov        PO_REPACKNO = (1 <<10),         /* Regenerate packet number */
94bfc7bfd8SDmitri Tikhonov        PO_NOENCRYPT= (1 <<11),         /* Do not encrypt data in po_data */
95bfc7bfd8SDmitri Tikhonov        PO_VERNEG   = (1 <<12),         /* Version negotiation packet. */
96bfc7bfd8SDmitri Tikhonov        PO_STREAM_END
97bfc7bfd8SDmitri Tikhonov                    = (1 <<13),         /* STREAM frame reaches the end of the packet: no
98bfc7bfd8SDmitri Tikhonov                                         * further writes are allowed.
99bfc7bfd8SDmitri Tikhonov                                         */
100bfc7bfd8SDmitri Tikhonov        PO_SCHED    = (1 <<14),         /* On scheduled queue */
10116a9b66aSDmitri Tikhonov        PO_SENT_SZ  = (1 <<15),
1027a8b2eceSDmitri Tikhonov        PO_LONGHEAD = (1 <<16),
1031e75f938SDmitri Tikhonov#define POIPv6_SHIFT 20
1041e75f938SDmitri Tikhonov        PO_IPv6     = (1 <<20),         /* Set if pmi_allocate was passed is_ipv6=1,
1051e75f938SDmitri Tikhonov                                         *   otherwise unset.
1061e75f938SDmitri Tikhonov                                         */
1078252b0b9SDmitri Tikhonov        PO_LIMITED  = (1 <<21),         /* Used to credit sc_next_limit if needed. */
1085392f7a3SLiteSpeed Tech#define POPNS_SHIFT 22
1095392f7a3SLiteSpeed Tech        PO_PNS_HSK  = (1 <<22),         /* PNS bits contain the value of the */
1105392f7a3SLiteSpeed Tech        PO_PNS_APP  = (1 <<23),         /*   packet number space. */
1115392f7a3SLiteSpeed Tech        PO_RETRY    = (1 <<24),         /* Retry packet */
1125392f7a3SLiteSpeed Tech        PO_RETX     = (1 <<25),         /* Retransmitted packet: don't append to it */
113de46bf2fSDmitri Tikhonov        PO_POISON   = (1 <<26),         /* Used to detect opt-ACK attack */
1145392f7a3SLiteSpeed Tech        PO_LOSS_REC = (1 <<27),         /* This structure is a loss record */
1155392f7a3SLiteSpeed Tech        /* Only one of PO_SCHED, PO_UNACKED, or PO_LOST can be set.  If pressed
1165392f7a3SLiteSpeed Tech         * for room in the enum, we can switch to using two bits to represent
1175392f7a3SLiteSpeed Tech         * this information.
1185392f7a3SLiteSpeed Tech         */
1195392f7a3SLiteSpeed Tech        PO_UNACKED  = (1 <<28),         /* On unacked queue */
1205392f7a3SLiteSpeed Tech        PO_LOST     = (1 <<29),         /* On lost queue */
1215392f7a3SLiteSpeed Tech#define POSPIN_SHIFT 30
1225392f7a3SLiteSpeed Tech        PO_SPIN_BIT = (1 <<30),         /* Value of the spin bit */
1239626cfc2SDmitri Tikhonov    }                  po_flags;
124bfc7bfd8SDmitri Tikhonov    unsigned short     po_data_sz;      /* Number of usable bytes in data */
125bfc7bfd8SDmitri Tikhonov    unsigned short     po_enc_data_sz;  /* Number of usable bytes in data */
12616a9b66aSDmitri Tikhonov    unsigned short     po_sent_sz;      /* If PO_SENT_SZ is set, real size of sent buffer. */
127bfc7bfd8SDmitri Tikhonov    unsigned short     po_regen_sz;     /* Number of bytes at the beginning
128bfc7bfd8SDmitri Tikhonov                                         * of data containing bytes that are
129bfc7bfd8SDmitri Tikhonov                                         * not to be retransmitted, e.g. ACK
130bfc7bfd8SDmitri Tikhonov                                         * frames.
131bfc7bfd8SDmitri Tikhonov                                         */
132bfc7bfd8SDmitri Tikhonov    unsigned short     po_n_alloc;      /* Total number of bytes allocated in po_data */
1335392f7a3SLiteSpeed Tech    unsigned short     po_token_len;
1349626cfc2SDmitri Tikhonov    enum header_type   po_header_type:8;
1355392f7a3SLiteSpeed Tech    unsigned char      po_path_id;
1365392f7a3SLiteSpeed Tech    enum {
1375392f7a3SLiteSpeed Tech        POL_GQUIC    = 1 << 0,         /* Used for logging */
1385392f7a3SLiteSpeed Tech#define POLEV_SHIFT 1
1395392f7a3SLiteSpeed Tech        POL_ELBIT_0  = 1 << 1,         /* EL bits encode the crypto level. */
1405392f7a3SLiteSpeed Tech        POL_ELBIT_1  = 1 << 2,
1415392f7a3SLiteSpeed Tech#define POKP_SHIFT 3
1429fc12041SDmitri Tikhonov        POL_KEY_PHASE= 1 << 3,
1435392f7a3SLiteSpeed Tech#define POECN_SHIFT 4
1445392f7a3SLiteSpeed Tech        POL_ECNBIT_0 = 1 << 4,
1455392f7a3SLiteSpeed Tech        POL_ECNBIT_1 = 1 << 5,
14602b6086dSDmitri Tikhonov        POL_LOG_QL_BITS = 1 << 6,
14702b6086dSDmitri Tikhonov        POL_SQUARE_BIT = 1 << 7,
14802b6086dSDmitri Tikhonov        POL_LOSS_BIT = 1 << 8,
149da99665bSDmitri Tikhonov#ifndef NDEBUG
150da99665bSDmitri Tikhonov        POL_HEADER_PROT = 1 << 9,       /* Header protection applied */
151da99665bSDmitri Tikhonov#endif
15202b6086dSDmitri Tikhonov    }                  po_lflags:16;
153bfc7bfd8SDmitri Tikhonov    unsigned char     *po_data;
154bfc7bfd8SDmitri Tikhonov
15550aadb33SDmitri Tikhonov    /* A lot of packets contain data belonging to only one stream.  Thus,
156c51ce338SDmitri Tikhonov     * `one' is used first.  If this is not enough, any number of
15750aadb33SDmitri Tikhonov     * stream_rec_arr structures can be allocated to handle more stream
15850aadb33SDmitri Tikhonov     * records.
15950aadb33SDmitri Tikhonov     */
160c51ce338SDmitri Tikhonov    union {
161c51ce338SDmitri Tikhonov        struct stream_rec               one;
162c51ce338SDmitri Tikhonov        struct stream_rec_arr_tailq     arr;
163c51ce338SDmitri Tikhonov    }                  po_srecs;
16450aadb33SDmitri Tikhonov
16550aadb33SDmitri Tikhonov    /* If PO_ENCRYPTED is set, this points to the buffer that holds encrypted
16650aadb33SDmitri Tikhonov     * data.
16750aadb33SDmitri Tikhonov     */
16850aadb33SDmitri Tikhonov    unsigned char     *po_enc_data;
16950aadb33SDmitri Tikhonov
17050aadb33SDmitri Tikhonov    lsquic_ver_tag_t   po_ver_tag;      /* Set if PO_VERSION is set */
17150aadb33SDmitri Tikhonov    unsigned char     *po_nonce;        /* Use to generate header if PO_NONCE is set */
1725392f7a3SLiteSpeed Tech    const struct network_path
1735392f7a3SLiteSpeed Tech                      *po_path;
1745392f7a3SLiteSpeed Tech#define po_token po_nonce
1755392f7a3SLiteSpeed Tech    struct bwp_state  *po_bwp_state;
17650aadb33SDmitri Tikhonov} lsquic_packet_out_t;
17750aadb33SDmitri Tikhonov
1785392f7a3SLiteSpeed Tech/* This is to make sure these bit names are not used, they are only for
1795392f7a3SLiteSpeed Tech * convenience in gdb output.
1805392f7a3SLiteSpeed Tech */
1815392f7a3SLiteSpeed Tech#define PO_PNS_HSK
1825392f7a3SLiteSpeed Tech#define PO_PNS_APP
1835392f7a3SLiteSpeed Tech
18450aadb33SDmitri Tikhonov/* The size of lsquic_packet_out_t could be further reduced:
18550aadb33SDmitri Tikhonov *
18650aadb33SDmitri Tikhonov * po_ver_tag could be encoded as a few bits representing enum lsquic_version
18750aadb33SDmitri Tikhonov * in po_flags.  The cost is a bit of complexity.  This will save us four bytes.
18850aadb33SDmitri Tikhonov */
18950aadb33SDmitri Tikhonov
19050aadb33SDmitri Tikhonov#define lsquic_packet_out_avail(p) ((unsigned short) \
19150aadb33SDmitri Tikhonov                                        ((p)->po_n_alloc - (p)->po_data_sz))
19250aadb33SDmitri Tikhonov
19350aadb33SDmitri Tikhonov#define lsquic_packet_out_packno_bits(p) (((p)->po_flags >> POBIT_SHIFT) & 0x3)
19450aadb33SDmitri Tikhonov
195bfc7bfd8SDmitri Tikhonov#define lsquic_packet_out_set_packno_bits(p, b) do {                    \
196bfc7bfd8SDmitri Tikhonov    (p)->po_flags &= ~(0x3 << POBIT_SHIFT);                             \
197bfc7bfd8SDmitri Tikhonov    (p)->po_flags |= ((b) & 0x3) << POBIT_SHIFT;                        \
198bfc7bfd8SDmitri Tikhonov} while (0)
199bfc7bfd8SDmitri Tikhonov
2001e75f938SDmitri Tikhonov#define lsquic_packet_out_ipv6(p) ((int)(((p)->po_flags >> POIPv6_SHIFT) & 1))
2011e75f938SDmitri Tikhonov
2021e75f938SDmitri Tikhonov#define lsquic_packet_out_set_ipv6(p, b) do {                           \
2031e75f938SDmitri Tikhonov    (p)->po_flags &= ~(1 << POIPv6_SHIFT);                              \
2041e75f938SDmitri Tikhonov    (p)->po_flags |= ((b) & 1) << POIPv6_SHIFT;                         \
2051e75f938SDmitri Tikhonov} while (0)
2061e75f938SDmitri Tikhonov
2075392f7a3SLiteSpeed Tech#define lsquic_packet_out_spin_bit(p) (((p)->po_flags & PO_SPIN_BIT) > 0)
20802b6086dSDmitri Tikhonov#define lsquic_packet_out_square_bit(p) (((p)->po_lflags & POL_SQUARE_BIT) > 0)
20902b6086dSDmitri Tikhonov#define lsquic_packet_out_loss_bit(p) (((p)->po_lflags & POL_LOSS_BIT) > 0)
2105392f7a3SLiteSpeed Tech
2115392f7a3SLiteSpeed Tech#define lsquic_packet_out_set_spin_bit(p, b) do {                       \
2125392f7a3SLiteSpeed Tech    (p)->po_flags &= ~PO_SPIN_BIT;                                      \
2135392f7a3SLiteSpeed Tech    (p)->po_flags |= ((b) & 1) << POSPIN_SHIFT;                         \
2145392f7a3SLiteSpeed Tech} while (0)
2155392f7a3SLiteSpeed Tech
2165392f7a3SLiteSpeed Tech#define lsquic_po_header_length(lconn, po_flags, dcid_len) ( \
2175392f7a3SLiteSpeed Tech    lconn->cn_pf->pf_packout_max_header_size(lconn, po_flags, dcid_len))
21850aadb33SDmitri Tikhonov
2199626cfc2SDmitri Tikhonov#define lsquic_packet_out_total_sz(lconn, p) (\
220b55a5117SDmitri Tikhonov    (lconn)->cn_pf->pf_packout_size(lconn, p))
221bfc7bfd8SDmitri Tikhonov
22216a9b66aSDmitri Tikhonov#if __GNUC__
22316a9b66aSDmitri Tikhonov#if LSQUIC_EXTRA_CHECKS
2249626cfc2SDmitri Tikhonov#define lsquic_packet_out_sent_sz(lconn, p) (                               \
22516a9b66aSDmitri Tikhonov        __builtin_expect(((p)->po_flags & PO_SENT_SZ), 1) ?                 \
2268ae5ecb4SDmitri Tikhonov        (assert(((p)->po_flags & PO_HELLO /* Avoid client DCID change */)   \
2278ae5ecb4SDmitri Tikhonov            || (p)->po_sent_sz == lsquic_packet_out_total_sz(lconn, p)),    \
2289626cfc2SDmitri Tikhonov            (p)->po_sent_sz) : lsquic_packet_out_total_sz(lconn, p))
22916a9b66aSDmitri Tikhonov#   else
2309626cfc2SDmitri Tikhonov#define lsquic_packet_out_sent_sz(lconn, p) (                               \
23116a9b66aSDmitri Tikhonov        __builtin_expect(((p)->po_flags & PO_SENT_SZ), 1) ?                 \
2329626cfc2SDmitri Tikhonov        (p)->po_sent_sz : lsquic_packet_out_total_sz(lconn, p))
23316a9b66aSDmitri Tikhonov#endif
23416a9b66aSDmitri Tikhonov#else
2359626cfc2SDmitri Tikhonov#   define lsquic_packet_out_sent_sz(lconn, p) (                            \
23616a9b66aSDmitri Tikhonov        (p)->po_flags & PO_SENT_SZ ?                                        \
2379626cfc2SDmitri Tikhonov        (p)->po_sent_sz : lsquic_packet_out_total_sz(lconn, p))
23816a9b66aSDmitri Tikhonov#endif
23916a9b66aSDmitri Tikhonov
24050aadb33SDmitri Tikhonov#define lsquic_packet_out_verneg(p) \
2415392f7a3SLiteSpeed Tech    (((p)->po_flags & (PO_NOENCRYPT|PO_VERNEG|PO_RETRY)) == (PO_NOENCRYPT|PO_VERNEG))
24250aadb33SDmitri Tikhonov
24350aadb33SDmitri Tikhonov#define lsquic_packet_out_pubres(p) \
2445392f7a3SLiteSpeed Tech    (((p)->po_flags & (PO_NOENCRYPT|PO_VERNEG|PO_RETRY)) ==  PO_NOENCRYPT           )
2455392f7a3SLiteSpeed Tech
2465392f7a3SLiteSpeed Tech#define lsquic_packet_out_retry(p) \
2475392f7a3SLiteSpeed Tech    (((p)->po_flags & (PO_NOENCRYPT|PO_VERNEG|PO_RETRY)) == (PO_NOENCRYPT|PO_RETRY) )
24850aadb33SDmitri Tikhonov
2499626cfc2SDmitri Tikhonov#define lsquic_packet_out_set_enc_level(p, level) do {                      \
2505392f7a3SLiteSpeed Tech    (p)->po_lflags &= ~(3 << POLEV_SHIFT);                                  \
2515392f7a3SLiteSpeed Tech    (p)->po_lflags |= level << POLEV_SHIFT;                                 \
2525392f7a3SLiteSpeed Tech} while (0)
2535392f7a3SLiteSpeed Tech
2545392f7a3SLiteSpeed Tech#define lsquic_packet_out_enc_level(p)  (((p)->po_lflags >> POLEV_SHIFT) & 3)
2555392f7a3SLiteSpeed Tech
2565392f7a3SLiteSpeed Tech#define lsquic_packet_out_set_kp(p, kp) do {                                \
2575392f7a3SLiteSpeed Tech    (p)->po_lflags &= ~(1 << POKP_SHIFT);                                   \
2585392f7a3SLiteSpeed Tech    (p)->po_lflags |= kp << POKP_SHIFT;                                     \
2595392f7a3SLiteSpeed Tech} while (0)
2605392f7a3SLiteSpeed Tech
2615392f7a3SLiteSpeed Tech#define lsquic_packet_out_kp(p)  (((p)->po_lflags >> POKP_SHIFT) & 1)
2625392f7a3SLiteSpeed Tech
2635392f7a3SLiteSpeed Tech#define lsquic_packet_out_set_pns(p, pns) do {                              \
2645392f7a3SLiteSpeed Tech    (p)->po_flags &= ~(3 << POPNS_SHIFT);                                   \
2655392f7a3SLiteSpeed Tech    (p)->po_flags |= pns << POPNS_SHIFT;                                    \
2665392f7a3SLiteSpeed Tech} while (0)
2675392f7a3SLiteSpeed Tech
2685392f7a3SLiteSpeed Tech#define lsquic_packet_out_pns(p)  (((p)->po_flags >> POPNS_SHIFT) & 3)
2695392f7a3SLiteSpeed Tech
2705392f7a3SLiteSpeed Tech#define lsquic_packet_out_set_ecn(p, ecn) do {                              \
2715392f7a3SLiteSpeed Tech    (p)->po_lflags &= ~(3 << POECN_SHIFT);                                  \
2725392f7a3SLiteSpeed Tech    (p)->po_lflags |= ecn << POECN_SHIFT;                                   \
2739626cfc2SDmitri Tikhonov} while (0)
2749626cfc2SDmitri Tikhonov
2755392f7a3SLiteSpeed Tech#define lsquic_packet_out_ecn(p)  (((p)->po_lflags >> POECN_SHIFT) & 3)
2769626cfc2SDmitri Tikhonov
27750aadb33SDmitri Tikhonovstruct packet_out_srec_iter {
27850aadb33SDmitri Tikhonov    lsquic_packet_out_t         *packet_out;
27950aadb33SDmitri Tikhonov    struct stream_rec_arr       *cur_srec_arr;
28050aadb33SDmitri Tikhonov    unsigned                     srec_idx;
281c51ce338SDmitri Tikhonov    int                          impl_idx;
28250aadb33SDmitri Tikhonov};
28350aadb33SDmitri Tikhonov
2845392f7a3SLiteSpeed Tech
28550aadb33SDmitri Tikhonovstruct stream_rec *
286a5fa05f9SDmitri Tikhonovlsquic_posi_first (struct packet_out_srec_iter *posi, lsquic_packet_out_t *);
28750aadb33SDmitri Tikhonov
28850aadb33SDmitri Tikhonovstruct stream_rec *
289a5fa05f9SDmitri Tikhonovlsquic_posi_next (struct packet_out_srec_iter *posi);
29050aadb33SDmitri Tikhonov
29150aadb33SDmitri Tikhonovlsquic_packet_out_t *
29250aadb33SDmitri Tikhonovlsquic_packet_out_new (struct lsquic_mm *, struct malo *, int use_cid,
293c7d81ce1SDmitri Tikhonov                       const struct lsquic_conn *, enum packno_bits,
2945392f7a3SLiteSpeed Tech                       const lsquic_ver_tag_t *, const unsigned char *nonce,
2955392f7a3SLiteSpeed Tech                       const struct network_path *);
29650aadb33SDmitri Tikhonov
29750aadb33SDmitri Tikhonovvoid
29850aadb33SDmitri Tikhonovlsquic_packet_out_destroy (lsquic_packet_out_t *,
2991e75f938SDmitri Tikhonov                        struct lsquic_engine_public *, void *peer_ctx);
30050aadb33SDmitri Tikhonov
30150aadb33SDmitri Tikhonovint
30250aadb33SDmitri Tikhonovlsquic_packet_out_add_stream (lsquic_packet_out_t *packet_out,
30350aadb33SDmitri Tikhonov                              struct lsquic_mm *mm,
30450aadb33SDmitri Tikhonov                              struct lsquic_stream *new_stream,
3056aba801dSDmitri Tikhonov                              enum quic_frame_type,
306c51ce338SDmitri Tikhonov                              unsigned short off, unsigned short len);
30750aadb33SDmitri Tikhonov
308bfc7bfd8SDmitri Tikhonovunsigned
3095392f7a3SLiteSpeed Techlsquic_packet_out_elide_reset_stream_frames (lsquic_packet_out_t *,
3105392f7a3SLiteSpeed Tech                                                    lsquic_stream_id_t);
311c51ce338SDmitri Tikhonov
312c51ce338SDmitri Tikhonovint
313c51ce338SDmitri Tikhonovlsquic_packet_out_split_in_two (struct lsquic_mm *, lsquic_packet_out_t *,
314c51ce338SDmitri Tikhonov    lsquic_packet_out_t *, const struct parse_funcs *, unsigned excess_bytes);
31550aadb33SDmitri Tikhonov
31650aadb33SDmitri Tikhonovvoid
31750aadb33SDmitri Tikhonovlsquic_packet_out_chop_regen (lsquic_packet_out_t *);
31850aadb33SDmitri Tikhonov
319c51ce338SDmitri Tikhonovvoid
320c51ce338SDmitri Tikhonovlsquic_packet_out_ack_streams (struct lsquic_packet_out *);
321c51ce338SDmitri Tikhonov
322c51ce338SDmitri Tikhonovvoid
323c51ce338SDmitri Tikhonovlsquic_packet_out_zero_pad (struct lsquic_packet_out *);
324c51ce338SDmitri Tikhonov
325c51ce338SDmitri Tikhonovsize_t
326c51ce338SDmitri Tikhonovlsquic_packet_out_mem_used (const struct lsquic_packet_out *);
327c51ce338SDmitri Tikhonov
328c51ce338SDmitri Tikhonovint
329c51ce338SDmitri Tikhonovlsquic_packet_out_turn_on_fin (struct lsquic_packet_out *,
330c51ce338SDmitri Tikhonov                   const struct parse_funcs *, const struct lsquic_stream *);
331c51ce338SDmitri Tikhonov
33250aadb33SDmitri Tikhonov#endif
333