lsquic_ev_log.c revision b55a5117
17d09751dSDmitri Tikhonov/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc.  See LICENSE. */
2461e84d8SAmol Deshpande#ifndef WIN32
350aadb33SDmitri Tikhonov#include <arpa/inet.h>
4461e84d8SAmol Deshpande#else
5461e84d8SAmol Deshpande#include <vc_compat.h>
6461e84d8SAmol Deshpande#endif
750aadb33SDmitri Tikhonov#include <errno.h>
850aadb33SDmitri Tikhonov#include <inttypes.h>
950aadb33SDmitri Tikhonov#include <stdlib.h>
1050aadb33SDmitri Tikhonov#include <string.h>
11461e84d8SAmol Deshpande#include <sys/queue.h>
1250aadb33SDmitri Tikhonov
13b55a5117SDmitri Tikhonov#include <openssl/x509.h>
14b55a5117SDmitri Tikhonov
1550aadb33SDmitri Tikhonov#include "lsquic.h"
1650aadb33SDmitri Tikhonov#include "lsquic_types.h"
1750aadb33SDmitri Tikhonov#include "lsquic_int_types.h"
1850aadb33SDmitri Tikhonov#include "lsquic_packet_common.h"
195392f7a3SLiteSpeed Tech#include "lsquic_packet_gquic.h"
2050aadb33SDmitri Tikhonov#include "lsquic_packet_in.h"
2150aadb33SDmitri Tikhonov#include "lsquic_packet_out.h"
2250aadb33SDmitri Tikhonov#include "lsquic_parse.h"
2350aadb33SDmitri Tikhonov#include "lsquic_frame_common.h"
243b55e6aeSDmitri Tikhonov#include "lsquic_headers.h"
259626cfc2SDmitri Tikhonov#include "lsquic_str.h"
265392f7a3SLiteSpeed Tech#include "lsquic_frame_reader.h"
275392f7a3SLiteSpeed Tech#include "lsquic_enc_sess.h"
2850aadb33SDmitri Tikhonov#include "lsquic_ev_log.h"
295392f7a3SLiteSpeed Tech#include "lsquic_sizes.h"
305392f7a3SLiteSpeed Tech#include "lsquic_trans_params.h"
315392f7a3SLiteSpeed Tech#include "lsquic_util.h"
325392f7a3SLiteSpeed Tech#include "lsquic_hash.h"
335392f7a3SLiteSpeed Tech#include "lsquic_conn.h"
3455613f44SDmitri Tikhonov#include "lsxpack_header.h"
3550aadb33SDmitri Tikhonov
3650aadb33SDmitri Tikhonov#define LSQUIC_LOGGER_MODULE LSQLM_EVENT
3750aadb33SDmitri Tikhonov#include "lsquic_logger.h"
3850aadb33SDmitri Tikhonov
3950aadb33SDmitri Tikhonov
4050aadb33SDmitri Tikhonov/*  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  */
4150aadb33SDmitri Tikhonov/*  ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  */
4250aadb33SDmitri Tikhonov/* Messages that do not include connection ID go above this point */
4350aadb33SDmitri Tikhonov
4450aadb33SDmitri Tikhonov#define LSQUIC_LOG_CONN_ID cid
45461e84d8SAmol Deshpande#define LCID(...) LSQ_LOG2(LSQ_LOG_DEBUG, __VA_ARGS__)   /* LCID: log with CID */
4650aadb33SDmitri Tikhonov
4750aadb33SDmitri Tikhonov/* Messages that are to include connection ID go below this point */
4850aadb33SDmitri Tikhonov/*  ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  */
4950aadb33SDmitri Tikhonov/*  VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV  */
5050aadb33SDmitri Tikhonov
5150aadb33SDmitri Tikhonovvoid
525392f7a3SLiteSpeed Techlsquic_ev_log_packet_in (const lsquic_cid_t *cid,
535392f7a3SLiteSpeed Tech                                        const lsquic_packet_in_t *packet_in)
5450aadb33SDmitri Tikhonov{
559626cfc2SDmitri Tikhonov    switch (packet_in->pi_flags & (
565392f7a3SLiteSpeed Tech                                   PI_FROM_MINI|
579626cfc2SDmitri Tikhonov                                                PI_GQUIC))
589626cfc2SDmitri Tikhonov    {
595392f7a3SLiteSpeed Tech    case PI_FROM_MINI|PI_GQUIC:
605392f7a3SLiteSpeed Tech        LCID("packet in: %"PRIu64" (from mini)", packet_in->pi_packno);
615392f7a3SLiteSpeed Tech        break;
625392f7a3SLiteSpeed Tech    case PI_FROM_MINI:
635392f7a3SLiteSpeed Tech        LCID("packet in: %"PRIu64" (from mini), type: %s, ecn: %u",
645392f7a3SLiteSpeed Tech            packet_in->pi_packno, lsquic_hety2str[packet_in->pi_header_type],
655392f7a3SLiteSpeed Tech            lsquic_packet_in_ecn(packet_in));
665392f7a3SLiteSpeed Tech        break;
679626cfc2SDmitri Tikhonov    case PI_GQUIC:
685392f7a3SLiteSpeed Tech        LCID("packet in: %"PRIu64", size: %u", packet_in->pi_packno,
695392f7a3SLiteSpeed Tech            (unsigned) (packet_in->pi_data_sz + GQUIC_PACKET_HASH_SZ));
709626cfc2SDmitri Tikhonov        break;
719626cfc2SDmitri Tikhonov    default:
7202b6086dSDmitri Tikhonov        if (packet_in->pi_flags & PI_LOG_QL_BITS)
7302b6086dSDmitri Tikhonov            LCID("packet in: %"PRIu64", type: %s, size: %u; ecn: %u, spin: %d; "
7402b6086dSDmitri Tikhonov                "path: %hhu; Q: %d; L: %d",
7502b6086dSDmitri Tikhonov                packet_in->pi_packno, lsquic_hety2str[packet_in->pi_header_type],
7602b6086dSDmitri Tikhonov                (unsigned) (packet_in->pi_data_sz + IQUIC_TAG_LEN),
7702b6086dSDmitri Tikhonov                lsquic_packet_in_ecn(packet_in),
7802b6086dSDmitri Tikhonov                /* spin bit value is only valid for short packet headers */
7902b6086dSDmitri Tikhonov                lsquic_packet_in_spin_bit(packet_in), packet_in->pi_path_id,
8002b6086dSDmitri Tikhonov                ((packet_in->pi_flags & PI_SQUARE_BIT) > 0),
8102b6086dSDmitri Tikhonov                ((packet_in->pi_flags & PI_LOSS_BIT) > 0));
8202b6086dSDmitri Tikhonov        else
8302b6086dSDmitri Tikhonov            LCID("packet in: %"PRIu64", type: %s, size: %u; ecn: %u, spin: %d; "
8402b6086dSDmitri Tikhonov                "path: %hhu",
8502b6086dSDmitri Tikhonov                packet_in->pi_packno, lsquic_hety2str[packet_in->pi_header_type],
8602b6086dSDmitri Tikhonov                (unsigned) (packet_in->pi_data_sz + IQUIC_TAG_LEN),
8702b6086dSDmitri Tikhonov                lsquic_packet_in_ecn(packet_in),
8802b6086dSDmitri Tikhonov                /* spin bit value is only valid for short packet headers */
8902b6086dSDmitri Tikhonov                lsquic_packet_in_spin_bit(packet_in), packet_in->pi_path_id);
909626cfc2SDmitri Tikhonov        break;
919626cfc2SDmitri Tikhonov    }
9250aadb33SDmitri Tikhonov}
9350aadb33SDmitri Tikhonov
9450aadb33SDmitri Tikhonov
9550aadb33SDmitri Tikhonovvoid
965392f7a3SLiteSpeed Techlsquic_ev_log_ack_frame_in (const lsquic_cid_t *cid,
975392f7a3SLiteSpeed Tech                                        const struct ack_info *acki)
9850aadb33SDmitri Tikhonov{
99de46bf2fSDmitri Tikhonov    char buf[MAX_ACKI_STR_SZ];
10050aadb33SDmitri Tikhonov
101de46bf2fSDmitri Tikhonov    lsquic_acki2str(acki, buf, sizeof(buf));
102de46bf2fSDmitri Tikhonov    LCID("ACK frame in: %s", buf);
10350aadb33SDmitri Tikhonov}
10450aadb33SDmitri Tikhonov
10550aadb33SDmitri Tikhonov
10650aadb33SDmitri Tikhonovvoid
1075392f7a3SLiteSpeed Techlsquic_ev_log_stream_frame_in (const lsquic_cid_t *cid,
10850aadb33SDmitri Tikhonov                                        const struct stream_frame *frame)
10950aadb33SDmitri Tikhonov{
1105392f7a3SLiteSpeed Tech    LCID("STREAM frame in: stream %"PRIu64"; offset %"PRIu64"; size %"PRIu16
11150aadb33SDmitri Tikhonov        "; fin: %d", frame->stream_id, frame->data_frame.df_offset,
11250aadb33SDmitri Tikhonov        frame->data_frame.df_size, (int) frame->data_frame.df_fin);
11350aadb33SDmitri Tikhonov}
11450aadb33SDmitri Tikhonov
11550aadb33SDmitri Tikhonov
11650aadb33SDmitri Tikhonovvoid
1175392f7a3SLiteSpeed Techlsquic_ev_log_crypto_frame_in (const lsquic_cid_t *cid,
1185392f7a3SLiteSpeed Tech                        const struct stream_frame *frame, unsigned enc_level)
1195392f7a3SLiteSpeed Tech{
1205392f7a3SLiteSpeed Tech    LCID("CRYPTO frame in: level %u; offset %"PRIu64"; size %"PRIu16,
1215392f7a3SLiteSpeed Tech        enc_level, frame->data_frame.df_offset, frame->data_frame.df_size);
1225392f7a3SLiteSpeed Tech}
1235392f7a3SLiteSpeed Tech
1245392f7a3SLiteSpeed Tech
1255392f7a3SLiteSpeed Techvoid
1265392f7a3SLiteSpeed Techlsquic_ev_log_stop_waiting_frame_in (const lsquic_cid_t *cid,
1275392f7a3SLiteSpeed Tech                                                        lsquic_packno_t least)
12850aadb33SDmitri Tikhonov{
12950aadb33SDmitri Tikhonov    LCID("STOP_WAITING frame in: least unacked packno %"PRIu64, least);
13050aadb33SDmitri Tikhonov}
13150aadb33SDmitri Tikhonov
13250aadb33SDmitri Tikhonov
13350aadb33SDmitri Tikhonovvoid
1345392f7a3SLiteSpeed Techlsquic_ev_log_window_update_frame_in (const lsquic_cid_t *cid,
1355392f7a3SLiteSpeed Tech                                lsquic_stream_id_t stream_id, uint64_t offset)
13650aadb33SDmitri Tikhonov{
1375392f7a3SLiteSpeed Tech    LCID("WINDOW_UPDATE frame in: stream %"PRIu64"; offset %"PRIu64,
13850aadb33SDmitri Tikhonov        stream_id, offset);
13950aadb33SDmitri Tikhonov}
14050aadb33SDmitri Tikhonov
14150aadb33SDmitri Tikhonov
14250aadb33SDmitri Tikhonovvoid
1435392f7a3SLiteSpeed Techlsquic_ev_log_blocked_frame_in (const lsquic_cid_t *cid,
1445392f7a3SLiteSpeed Tech                                            lsquic_stream_id_t stream_id)
14550aadb33SDmitri Tikhonov{
1465392f7a3SLiteSpeed Tech    LCID("BLOCKED frame in: stream %"PRIu64, stream_id);
14750aadb33SDmitri Tikhonov}
14850aadb33SDmitri Tikhonov
14950aadb33SDmitri Tikhonov
15050aadb33SDmitri Tikhonovvoid
1515392f7a3SLiteSpeed Techlsquic_ev_log_connection_close_frame_in (const lsquic_cid_t *cid,
1525392f7a3SLiteSpeed Tech                    uint64_t error_code, int reason_len, const char *reason)
15350aadb33SDmitri Tikhonov{
1545392f7a3SLiteSpeed Tech    LCID("CONNECTION_CLOSE frame in: error code %"PRIu64", reason: %.*s",
15550aadb33SDmitri Tikhonov        error_code, reason_len, reason);
15650aadb33SDmitri Tikhonov}
15750aadb33SDmitri Tikhonov
15850aadb33SDmitri Tikhonov
15950aadb33SDmitri Tikhonovvoid
1605392f7a3SLiteSpeed Techlsquic_ev_log_goaway_frame_in (const lsquic_cid_t *cid, uint32_t error_code,
1615392f7a3SLiteSpeed Tech            lsquic_stream_id_t stream_id, int reason_len, const char *reason)
16250aadb33SDmitri Tikhonov{
1635392f7a3SLiteSpeed Tech    LCID("GOAWAY frame in: error code %"PRIu32", stream %"PRIu64
16450aadb33SDmitri Tikhonov        ", reason: %.*s", error_code, stream_id, reason_len, reason);
16550aadb33SDmitri Tikhonov}
16650aadb33SDmitri Tikhonov
16750aadb33SDmitri Tikhonov
16850aadb33SDmitri Tikhonovvoid
1695392f7a3SLiteSpeed Techlsquic_ev_log_rst_stream_frame_in (const lsquic_cid_t *cid,
1705392f7a3SLiteSpeed Tech        lsquic_stream_id_t stream_id, uint64_t offset, uint64_t error_code)
17150aadb33SDmitri Tikhonov{
1725392f7a3SLiteSpeed Tech    LCID("RST_STREAM frame in: error code %"PRIu64", stream %"PRIu64
17350aadb33SDmitri Tikhonov        ", offset: %"PRIu64, error_code, stream_id, offset);
17450aadb33SDmitri Tikhonov}
17550aadb33SDmitri Tikhonov
17650aadb33SDmitri Tikhonov
17750aadb33SDmitri Tikhonovvoid
1785392f7a3SLiteSpeed Techlsquic_ev_log_stop_sending_frame_in (const lsquic_cid_t *cid,
1795392f7a3SLiteSpeed Tech                        lsquic_stream_id_t stream_id, uint64_t error_code)
1805392f7a3SLiteSpeed Tech{
1815392f7a3SLiteSpeed Tech    LCID("STOP_SENDING frame in: error code %"PRIu64", stream %"PRIu64,
1825392f7a3SLiteSpeed Tech                                                     error_code, stream_id);
1835392f7a3SLiteSpeed Tech}
1845392f7a3SLiteSpeed Tech
1855392f7a3SLiteSpeed Tech
1865392f7a3SLiteSpeed Techvoid
1875392f7a3SLiteSpeed Techlsquic_ev_log_padding_frame_in (const lsquic_cid_t *cid, size_t len)
18850aadb33SDmitri Tikhonov{
18950aadb33SDmitri Tikhonov    LCID("PADDING frame in of %zd bytes", len);
19050aadb33SDmitri Tikhonov}
19150aadb33SDmitri Tikhonov
19250aadb33SDmitri Tikhonov
19350aadb33SDmitri Tikhonovvoid
1945392f7a3SLiteSpeed Techlsquic_ev_log_ping_frame_in (const lsquic_cid_t *cid)
19550aadb33SDmitri Tikhonov{
19650aadb33SDmitri Tikhonov    LCID("PING frame in");
19750aadb33SDmitri Tikhonov}
19850aadb33SDmitri Tikhonov
19950aadb33SDmitri Tikhonov
20050aadb33SDmitri Tikhonovvoid
2015392f7a3SLiteSpeed Techlsquic_ev_log_packet_created (const lsquic_cid_t *cid,
20250aadb33SDmitri Tikhonov                                const struct lsquic_packet_out *packet_out)
20350aadb33SDmitri Tikhonov{
20450aadb33SDmitri Tikhonov    LCID("created packet %"PRIu64"; flags: version=%d, nonce=%d, conn_id=%d",
20550aadb33SDmitri Tikhonov        packet_out->po_packno,
20650aadb33SDmitri Tikhonov        !!(packet_out->po_flags & PO_VERSION),
20750aadb33SDmitri Tikhonov        !!(packet_out->po_flags & PO_NONCE),
20850aadb33SDmitri Tikhonov        !!(packet_out->po_flags & PO_CONN_ID));
20950aadb33SDmitri Tikhonov}
21050aadb33SDmitri Tikhonov
21150aadb33SDmitri Tikhonov
21250aadb33SDmitri Tikhonovvoid
2135392f7a3SLiteSpeed Techlsquic_ev_log_packet_sent (const lsquic_cid_t *cid,
21450aadb33SDmitri Tikhonov                                const struct lsquic_packet_out *packet_out)
21550aadb33SDmitri Tikhonov{
21650aadb33SDmitri Tikhonov    char frames[lsquic_frame_types_str_sz];
21750aadb33SDmitri Tikhonov    if (lsquic_packet_out_verneg(packet_out))
21850aadb33SDmitri Tikhonov        LCID("sent version negotiation packet, size %hu",
21950aadb33SDmitri Tikhonov                                                    packet_out->po_data_sz);
2205392f7a3SLiteSpeed Tech    else if (lsquic_packet_out_retry(packet_out))
2215392f7a3SLiteSpeed Tech        LCID("sent stateless retry packet, size %hu", packet_out->po_data_sz);
22250aadb33SDmitri Tikhonov    else if (lsquic_packet_out_pubres(packet_out))
22350aadb33SDmitri Tikhonov        LCID("sent public reset packet, size %hu", packet_out->po_data_sz);
2245392f7a3SLiteSpeed Tech    else if (packet_out->po_lflags & POL_GQUIC)
22550aadb33SDmitri Tikhonov        LCID("sent packet %"PRIu64", size %hu, frame types: %s",
22650aadb33SDmitri Tikhonov            packet_out->po_packno, packet_out->po_enc_data_sz,
22750aadb33SDmitri Tikhonov                /* Frame types is a list of different frames types contained
22850aadb33SDmitri Tikhonov                 * in the packet, no more.  Count and order of frames is not
22950aadb33SDmitri Tikhonov                 * printed.
23050aadb33SDmitri Tikhonov                 */
23150aadb33SDmitri Tikhonov                lsquic_frame_types_to_str(frames, sizeof(frames),
23250aadb33SDmitri Tikhonov                                                packet_out->po_frame_types));
23302b6086dSDmitri Tikhonov    else if (packet_out->po_lflags & POL_LOG_QL_BITS)
23402b6086dSDmitri Tikhonov        LCID("sent packet %"PRIu64", type %s, crypto: %s, size %hu, frame "
23502b6086dSDmitri Tikhonov            "types: %s, ecn: %u, spin: %d; kp: %u, path: %hhu, flags: %u; "
23602b6086dSDmitri Tikhonov            "Q: %u; L: %u",
23702b6086dSDmitri Tikhonov            packet_out->po_packno, lsquic_hety2str[packet_out->po_header_type],
23802b6086dSDmitri Tikhonov            lsquic_enclev2str[ lsquic_packet_out_enc_level(packet_out) ],
23902b6086dSDmitri Tikhonov            packet_out->po_enc_data_sz,
24002b6086dSDmitri Tikhonov                /* Frame types is a list of different frames types contained
24102b6086dSDmitri Tikhonov                 * in the packet, no more.  Count and order of frames is not
24202b6086dSDmitri Tikhonov                 * printed.
24302b6086dSDmitri Tikhonov                 */
24402b6086dSDmitri Tikhonov                lsquic_frame_types_to_str(frames, sizeof(frames),
24502b6086dSDmitri Tikhonov                                                packet_out->po_frame_types),
24602b6086dSDmitri Tikhonov                lsquic_packet_out_ecn(packet_out),
24702b6086dSDmitri Tikhonov                /* spin bit value is only valid for short packet headers */
24802b6086dSDmitri Tikhonov                lsquic_packet_out_spin_bit(packet_out),
24902b6086dSDmitri Tikhonov                lsquic_packet_out_kp(packet_out),
25002b6086dSDmitri Tikhonov                packet_out->po_path->np_path_id,
25102b6086dSDmitri Tikhonov                (unsigned) packet_out->po_flags,
25202b6086dSDmitri Tikhonov                lsquic_packet_out_square_bit(packet_out),
25302b6086dSDmitri Tikhonov                lsquic_packet_out_loss_bit(packet_out));
2549626cfc2SDmitri Tikhonov    else
2559626cfc2SDmitri Tikhonov        LCID("sent packet %"PRIu64", type %s, crypto: %s, size %hu, frame "
25684dbbb75SDmitri Tikhonov            "types: %s, ecn: %u, spin: %d; kp: %u, path: %hhu, flags: %u",
2579626cfc2SDmitri Tikhonov            packet_out->po_packno, lsquic_hety2str[packet_out->po_header_type],
2589626cfc2SDmitri Tikhonov            lsquic_enclev2str[ lsquic_packet_out_enc_level(packet_out) ],
2599626cfc2SDmitri Tikhonov            packet_out->po_enc_data_sz,
2609626cfc2SDmitri Tikhonov                /* Frame types is a list of different frames types contained
2619626cfc2SDmitri Tikhonov                 * in the packet, no more.  Count and order of frames is not
2629626cfc2SDmitri Tikhonov                 * printed.
2639626cfc2SDmitri Tikhonov                 */
2649626cfc2SDmitri Tikhonov                lsquic_frame_types_to_str(frames, sizeof(frames),
2655392f7a3SLiteSpeed Tech                                                packet_out->po_frame_types),
2665392f7a3SLiteSpeed Tech                lsquic_packet_out_ecn(packet_out),
2675392f7a3SLiteSpeed Tech                /* spin bit value is only valid for short packet headers */
2685392f7a3SLiteSpeed Tech                lsquic_packet_out_spin_bit(packet_out),
2695392f7a3SLiteSpeed Tech                lsquic_packet_out_kp(packet_out),
27084dbbb75SDmitri Tikhonov                packet_out->po_path->np_path_id,
27184dbbb75SDmitri Tikhonov                (unsigned) packet_out->po_flags);
27250aadb33SDmitri Tikhonov}
27350aadb33SDmitri Tikhonov
27450aadb33SDmitri Tikhonov
27550aadb33SDmitri Tikhonovvoid
2765392f7a3SLiteSpeed Techlsquic_ev_log_packet_not_sent (const lsquic_cid_t *cid,
27750aadb33SDmitri Tikhonov                                const struct lsquic_packet_out *packet_out)
27850aadb33SDmitri Tikhonov{
27950aadb33SDmitri Tikhonov    char frames[lsquic_frame_types_str_sz];
28050aadb33SDmitri Tikhonov    LCID("unsent packet %"PRIu64", size %hu, frame types: %s",
28150aadb33SDmitri Tikhonov        packet_out->po_packno, packet_out->po_enc_data_sz,
28250aadb33SDmitri Tikhonov            /* Frame types is a list of different frames types contained in
28350aadb33SDmitri Tikhonov             * the packet, no more.  Count and order of frames is not printed.
28450aadb33SDmitri Tikhonov             */
28550aadb33SDmitri Tikhonov            lsquic_frame_types_to_str(frames, sizeof(frames),
28650aadb33SDmitri Tikhonov                                                packet_out->po_frame_types));
28750aadb33SDmitri Tikhonov}
28850aadb33SDmitri Tikhonov
28950aadb33SDmitri Tikhonov
29050aadb33SDmitri Tikhonovvoid
2915392f7a3SLiteSpeed Techlsquic_ev_log_http_headers_in (const lsquic_cid_t *cid, int is_server,
29250aadb33SDmitri Tikhonov                                        const struct uncompressed_headers *uh)
29350aadb33SDmitri Tikhonov{
2943b55e6aeSDmitri Tikhonov    const struct http1x_headers *h1h;
29550aadb33SDmitri Tikhonov    const char *cr, *p;
29650aadb33SDmitri Tikhonov
29750aadb33SDmitri Tikhonov    if (uh->uh_flags & UH_PP)
2985392f7a3SLiteSpeed Tech        LCID("read push promise; stream %"PRIu64", promised stream %"PRIu64,
29950aadb33SDmitri Tikhonov            uh->uh_stream_id, uh->uh_oth_stream_id);
30050aadb33SDmitri Tikhonov    else
3015392f7a3SLiteSpeed Tech        LCID("read %s headers; stream: %"PRIu64", depends on stream: %"PRIu64
30250aadb33SDmitri Tikhonov            ", weight: %hu, exclusive: %d, fin: %d",
30350aadb33SDmitri Tikhonov            is_server ? "request" : "response",
30450aadb33SDmitri Tikhonov            uh->uh_stream_id, uh->uh_oth_stream_id, uh->uh_weight,
30550aadb33SDmitri Tikhonov            (int) uh->uh_exclusive, !!(uh->uh_flags & UH_FIN));
30650aadb33SDmitri Tikhonov
3073b55e6aeSDmitri Tikhonov    if (uh->uh_flags & UH_H1H)
30850aadb33SDmitri Tikhonov    {
3093b55e6aeSDmitri Tikhonov        h1h = uh->uh_hset;
3103b55e6aeSDmitri Tikhonov        for (p = h1h->h1h_buf; p < h1h->h1h_buf + h1h->h1h_size; p = cr + 2)
3113b55e6aeSDmitri Tikhonov        {
3123b55e6aeSDmitri Tikhonov            cr = strchr(p, '\r');
3133b55e6aeSDmitri Tikhonov            if (cr && cr > p)
3143b55e6aeSDmitri Tikhonov                LCID("  %.*s", (int) (cr - p), p);
3153b55e6aeSDmitri Tikhonov            else
3163b55e6aeSDmitri Tikhonov                break;
3173b55e6aeSDmitri Tikhonov        }
31850aadb33SDmitri Tikhonov    }
31950aadb33SDmitri Tikhonov}
32050aadb33SDmitri Tikhonov
32150aadb33SDmitri Tikhonov
32250aadb33SDmitri Tikhonovvoid
3235392f7a3SLiteSpeed Techlsquic_ev_log_action_stream_frame (const lsquic_cid_t *cid,
324c51ce338SDmitri Tikhonov    const struct parse_funcs *pf, const unsigned char *buf, size_t bufsz,
325c51ce338SDmitri Tikhonov    const char *what)
32650aadb33SDmitri Tikhonov{
32750aadb33SDmitri Tikhonov    struct stream_frame frame;
32850aadb33SDmitri Tikhonov    int len;
32950aadb33SDmitri Tikhonov
33050aadb33SDmitri Tikhonov    len = pf->pf_parse_stream_frame(buf, bufsz, &frame);
33150aadb33SDmitri Tikhonov    if (len > 0)
3325392f7a3SLiteSpeed Tech        LCID("%s STREAM frame: stream %"PRIu64", offset: %"PRIu64
333c51ce338SDmitri Tikhonov            ", size: %"PRIu16", fin: %d", what, frame.stream_id,
33450aadb33SDmitri Tikhonov            frame.data_frame.df_offset, frame.data_frame.df_size,
33550aadb33SDmitri Tikhonov            frame.data_frame.df_fin);
33650aadb33SDmitri Tikhonov    else
33750aadb33SDmitri Tikhonov        LSQ_LOG2(LSQ_LOG_WARN, "cannot parse STREAM frame");
33850aadb33SDmitri Tikhonov}
33950aadb33SDmitri Tikhonov
34050aadb33SDmitri Tikhonov
34150aadb33SDmitri Tikhonovvoid
3425392f7a3SLiteSpeed Techlsquic_ev_log_generated_crypto_frame (const lsquic_cid_t *cid,
3435392f7a3SLiteSpeed Tech       const struct parse_funcs *pf, const unsigned char *buf, size_t bufsz)
3445392f7a3SLiteSpeed Tech{
3455392f7a3SLiteSpeed Tech    struct stream_frame frame;
3465392f7a3SLiteSpeed Tech    int len;
3475392f7a3SLiteSpeed Tech
3485392f7a3SLiteSpeed Tech    len = pf->pf_parse_crypto_frame(buf, bufsz, &frame);
3495392f7a3SLiteSpeed Tech    if (len > 0)
3505392f7a3SLiteSpeed Tech        LCID("generated CRYPTO frame: offset: %"PRIu64", size: %"PRIu16,
3515392f7a3SLiteSpeed Tech            frame.data_frame.df_offset, frame.data_frame.df_size);
3525392f7a3SLiteSpeed Tech    else
3535392f7a3SLiteSpeed Tech        LSQ_LOG2(LSQ_LOG_WARN, "cannot parse CRYPTO frame");
3545392f7a3SLiteSpeed Tech}
3555392f7a3SLiteSpeed Tech
3565392f7a3SLiteSpeed Tech
3575392f7a3SLiteSpeed Techvoid
3585392f7a3SLiteSpeed Techlsquic_ev_log_generated_ack_frame (const lsquic_cid_t *cid,
3595392f7a3SLiteSpeed Tech                const struct parse_funcs *pf, const unsigned char *ack_buf,
3605392f7a3SLiteSpeed Tech                size_t ack_buf_sz)
36150aadb33SDmitri Tikhonov{
36250aadb33SDmitri Tikhonov    struct ack_info acki;
36350aadb33SDmitri Tikhonov    int len;
364de46bf2fSDmitri Tikhonov    char buf[MAX_ACKI_STR_SZ];
36550aadb33SDmitri Tikhonov
3665392f7a3SLiteSpeed Tech    len = pf->pf_parse_ack_frame(ack_buf, ack_buf_sz, &acki,
3675392f7a3SLiteSpeed Tech                                                    TP_DEF_ACK_DELAY_EXP);
36850aadb33SDmitri Tikhonov    if (len < 0)
36950aadb33SDmitri Tikhonov    {
37050aadb33SDmitri Tikhonov        LSQ_LOG2(LSQ_LOG_WARN, "cannot parse ACK frame");
37150aadb33SDmitri Tikhonov        return;
37250aadb33SDmitri Tikhonov    }
37350aadb33SDmitri Tikhonov
374de46bf2fSDmitri Tikhonov    lsquic_acki2str(&acki, buf, sizeof(buf));
375de46bf2fSDmitri Tikhonov    LCID("generated ACK frame: %s", buf);
37650aadb33SDmitri Tikhonov}
37750aadb33SDmitri Tikhonov
37850aadb33SDmitri Tikhonov
37950aadb33SDmitri Tikhonovvoid
3805392f7a3SLiteSpeed Techlsquic_ev_log_generated_new_token_frame (const lsquic_cid_t *cid,
3815392f7a3SLiteSpeed Tech                const struct parse_funcs *pf, const unsigned char *frame_buf,
3825392f7a3SLiteSpeed Tech                size_t frame_buf_sz)
3835392f7a3SLiteSpeed Tech{
3845392f7a3SLiteSpeed Tech    const unsigned char *token;
3855392f7a3SLiteSpeed Tech    size_t sz;
3865392f7a3SLiteSpeed Tech    char *buf;
3875392f7a3SLiteSpeed Tech    int len;
3885392f7a3SLiteSpeed Tech
3895392f7a3SLiteSpeed Tech    len = pf->pf_parse_new_token_frame(frame_buf, frame_buf_sz, &token, &sz);
3905392f7a3SLiteSpeed Tech    if (len < 0)
3915392f7a3SLiteSpeed Tech    {
3925392f7a3SLiteSpeed Tech        LSQ_LOG2(LSQ_LOG_WARN, "cannot parse NEW_TOKEN frame");
3935392f7a3SLiteSpeed Tech        return;
3945392f7a3SLiteSpeed Tech    }
3955392f7a3SLiteSpeed Tech
3965392f7a3SLiteSpeed Tech    buf = malloc(sz * 2 + 1);
3975392f7a3SLiteSpeed Tech    if (buf)
3985392f7a3SLiteSpeed Tech    {
3995392f7a3SLiteSpeed Tech        lsquic_hexstr(token, sz, buf, sz * 2 + 1);
4005392f7a3SLiteSpeed Tech        LCID("generated NEW_TOKEN frame: %s", buf);
4015392f7a3SLiteSpeed Tech        free(buf);
4025392f7a3SLiteSpeed Tech    }
4035392f7a3SLiteSpeed Tech}
4045392f7a3SLiteSpeed Tech
4055392f7a3SLiteSpeed Tech
4065392f7a3SLiteSpeed Techvoid
4075392f7a3SLiteSpeed Techlsquic_ev_log_generated_path_chal_frame (const lsquic_cid_t *cid,
4085392f7a3SLiteSpeed Tech                const struct parse_funcs *pf, const unsigned char *frame_buf,
4095392f7a3SLiteSpeed Tech                size_t frame_buf_sz)
4105392f7a3SLiteSpeed Tech{
4115392f7a3SLiteSpeed Tech    uint64_t chal;
4125392f7a3SLiteSpeed Tech    int len;
4135392f7a3SLiteSpeed Tech    char hexbuf[sizeof(chal) * 2 + 1];
4145392f7a3SLiteSpeed Tech
4155392f7a3SLiteSpeed Tech    len = pf->pf_parse_path_chal_frame(frame_buf, frame_buf_sz, &chal);
4165392f7a3SLiteSpeed Tech    if (len > 0)
4175392f7a3SLiteSpeed Tech        LCID("generated PATH_CHALLENGE(%s) frame",
4185392f7a3SLiteSpeed Tech                        HEXSTR((unsigned char *) &chal, sizeof(chal), hexbuf));
4195392f7a3SLiteSpeed Tech    else
4205392f7a3SLiteSpeed Tech        LSQ_LOG2(LSQ_LOG_WARN, "cannot parse PATH_CHALLENGE frame");
4215392f7a3SLiteSpeed Tech}
4225392f7a3SLiteSpeed Tech
4235392f7a3SLiteSpeed Tech
4245392f7a3SLiteSpeed Techvoid
4255392f7a3SLiteSpeed Techlsquic_ev_log_generated_path_resp_frame (const lsquic_cid_t *cid,
4265392f7a3SLiteSpeed Tech                const struct parse_funcs *pf, const unsigned char *frame_buf,
4275392f7a3SLiteSpeed Tech                size_t frame_buf_sz)
4285392f7a3SLiteSpeed Tech{
4295392f7a3SLiteSpeed Tech    uint64_t resp;
4305392f7a3SLiteSpeed Tech    int len;
4315392f7a3SLiteSpeed Tech    char hexbuf[sizeof(resp) * 2 + 1];
4325392f7a3SLiteSpeed Tech
4335392f7a3SLiteSpeed Tech    len = pf->pf_parse_path_resp_frame(frame_buf, frame_buf_sz, &resp);
4345392f7a3SLiteSpeed Tech    if (len > 0)
4355392f7a3SLiteSpeed Tech        LCID("generated PATH_RESPONSE(%s) frame",
4365392f7a3SLiteSpeed Tech                        HEXSTR((unsigned char *) &resp, sizeof(resp), hexbuf));
4375392f7a3SLiteSpeed Tech    else
4385392f7a3SLiteSpeed Tech        LSQ_LOG2(LSQ_LOG_WARN, "cannot parse PATH_RESPONSE frame");
4395392f7a3SLiteSpeed Tech}
4405392f7a3SLiteSpeed Tech
4415392f7a3SLiteSpeed Tech
4425392f7a3SLiteSpeed Techvoid
4435392f7a3SLiteSpeed Techlsquic_ev_log_generated_new_connection_id_frame (const lsquic_cid_t *cid,
4445392f7a3SLiteSpeed Tech                const struct parse_funcs *pf, const unsigned char *frame_buf,
4455392f7a3SLiteSpeed Tech                size_t frame_buf_sz)
4465392f7a3SLiteSpeed Tech{
4475392f7a3SLiteSpeed Tech    const unsigned char *token;
4485392f7a3SLiteSpeed Tech    lsquic_cid_t new_cid;
4495392f7a3SLiteSpeed Tech    uint64_t seqno, retire_prior_to;
4505392f7a3SLiteSpeed Tech    int len;
4515392f7a3SLiteSpeed Tech    char token_buf[IQUIC_SRESET_TOKEN_SZ * 2 + 1];
4525392f7a3SLiteSpeed Tech    char cid_buf[MAX_CID_LEN * 2 + 1];
4535392f7a3SLiteSpeed Tech
4545392f7a3SLiteSpeed Tech    len = pf->pf_parse_new_conn_id(frame_buf, frame_buf_sz, &seqno,
4555392f7a3SLiteSpeed Tech                                        &retire_prior_to, &new_cid, &token);
4565392f7a3SLiteSpeed Tech    if (len < 0)
4575392f7a3SLiteSpeed Tech    {
4585392f7a3SLiteSpeed Tech        LSQ_LOG2(LSQ_LOG_WARN, "cannot parse NEW_CONNECTION_ID frame");
4595392f7a3SLiteSpeed Tech        return;
4605392f7a3SLiteSpeed Tech    }
4615392f7a3SLiteSpeed Tech
4625392f7a3SLiteSpeed Tech    lsquic_hexstr(new_cid.idbuf, new_cid.len, cid_buf, sizeof(cid_buf));
4635392f7a3SLiteSpeed Tech    lsquic_hexstr(token, IQUIC_SRESET_TOKEN_SZ, token_buf, sizeof(token_buf));
4645392f7a3SLiteSpeed Tech    LCID("generated NEW_CONNECTION_ID frame: seqno: %"PRIu64"; retire prior "
4655392f7a3SLiteSpeed Tech        "to: %"PRIu64"; cid: %s; token: %s", seqno, retire_prior_to,
4665392f7a3SLiteSpeed Tech        cid_buf, token_buf);
4675392f7a3SLiteSpeed Tech}
4685392f7a3SLiteSpeed Tech
4695392f7a3SLiteSpeed Tech
4705392f7a3SLiteSpeed Techvoid
4715392f7a3SLiteSpeed Techlsquic_ev_log_generated_stop_waiting_frame (const lsquic_cid_t *cid,
47250aadb33SDmitri Tikhonov                                            lsquic_packno_t lunack)
47350aadb33SDmitri Tikhonov{
47450aadb33SDmitri Tikhonov    LCID("generated STOP_WAITING frame; least unacked: %"PRIu64, lunack);
47550aadb33SDmitri Tikhonov}
47650aadb33SDmitri Tikhonov
47750aadb33SDmitri Tikhonov
47850aadb33SDmitri Tikhonovvoid
4795392f7a3SLiteSpeed Techlsquic_ev_log_generated_stop_sending_frame (const lsquic_cid_t *cid,
4805392f7a3SLiteSpeed Tech                            lsquic_stream_id_t stream_id, uint16_t error_code)
4815392f7a3SLiteSpeed Tech{
4825392f7a3SLiteSpeed Tech    LCID("generated STOP_SENDING frame; stream ID: %"PRIu64"; error code: "
4835392f7a3SLiteSpeed Tech                                            "%"PRIu16, stream_id, error_code);
4845392f7a3SLiteSpeed Tech}
4855392f7a3SLiteSpeed Tech
4865392f7a3SLiteSpeed Tech
4875392f7a3SLiteSpeed Techvoid
4885392f7a3SLiteSpeed Techlsquic_ev_log_generated_http_headers (const lsquic_cid_t *cid,
4895392f7a3SLiteSpeed Tech                    lsquic_stream_id_t stream_id,
49050aadb33SDmitri Tikhonov                    int is_server, const struct http_prio_frame *prio_frame,
49150aadb33SDmitri Tikhonov                    const struct lsquic_http_headers *headers)
49250aadb33SDmitri Tikhonov{
4935392f7a3SLiteSpeed Tech    lsquic_stream_id_t dep_stream_id;
49450aadb33SDmitri Tikhonov    int exclusive, i;
49550aadb33SDmitri Tikhonov    unsigned short weight;
49650aadb33SDmitri Tikhonov
49750aadb33SDmitri Tikhonov    if (is_server)
4985392f7a3SLiteSpeed Tech        LCID("generated HTTP response HEADERS for stream %"PRIu64, stream_id);
49950aadb33SDmitri Tikhonov    else
50050aadb33SDmitri Tikhonov    {
50150aadb33SDmitri Tikhonov        memcpy(&dep_stream_id, prio_frame->hpf_stream_id, 4);
50250aadb33SDmitri Tikhonov        dep_stream_id = htonl(dep_stream_id);
50350aadb33SDmitri Tikhonov        exclusive = dep_stream_id >> 31;
50450aadb33SDmitri Tikhonov        dep_stream_id &= ~(1 << 31);
50550aadb33SDmitri Tikhonov        weight = prio_frame->hpf_weight + 1;
5065392f7a3SLiteSpeed Tech        LCID("generated HTTP request HEADERS for stream %"PRIu64
5075392f7a3SLiteSpeed Tech            ", dep stream: %"PRIu64", weight: %hu, exclusive: %d", stream_id,
50850aadb33SDmitri Tikhonov            dep_stream_id, weight, exclusive);
50950aadb33SDmitri Tikhonov    }
51050aadb33SDmitri Tikhonov
51150aadb33SDmitri Tikhonov    for (i = 0; i < headers->count; ++i)
51255613f44SDmitri Tikhonov        if (headers->headers[i].buf)
51355613f44SDmitri Tikhonov            LCID("  %.*s: %.*s",
51455613f44SDmitri Tikhonov                (int)    headers->headers[i].name_len,
51555613f44SDmitri Tikhonov                lsxpack_header_get_name(&headers->headers[i]),
51655613f44SDmitri Tikhonov                (int)    headers->headers[i].val_len,
51755613f44SDmitri Tikhonov                lsxpack_header_get_value(&headers->headers[i]));
51850aadb33SDmitri Tikhonov}
51950aadb33SDmitri Tikhonov
52050aadb33SDmitri Tikhonov
52150aadb33SDmitri Tikhonovvoid
5225392f7a3SLiteSpeed Techlsquic_ev_log_generated_http_push_promise (const lsquic_cid_t *cid,
5235392f7a3SLiteSpeed Tech            lsquic_stream_id_t stream_id, lsquic_stream_id_t promised_stream_id,
52455613f44SDmitri Tikhonov            const struct lsquic_http_headers *headers)
52550aadb33SDmitri Tikhonov{
52650aadb33SDmitri Tikhonov    int i;
52750aadb33SDmitri Tikhonov
5285392f7a3SLiteSpeed Tech    LCID("generated HTTP PUSH_PROMISE for stream %"PRIu64"; promised stream %"
5295392f7a3SLiteSpeed Tech        PRIu64, stream_id, promised_stream_id);
53050aadb33SDmitri Tikhonov
53150aadb33SDmitri Tikhonov    for (i = 0; i < headers->count; ++i)
53255613f44SDmitri Tikhonov        if (headers->headers[i].buf)
53350aadb33SDmitri Tikhonov            LCID("  %.*s: %.*s",
53455613f44SDmitri Tikhonov                (int)    headers->headers[i].name_len,
53555613f44SDmitri Tikhonov                lsxpack_header_get_name(&headers->headers[i]),
53655613f44SDmitri Tikhonov                (int)    headers->headers[i].val_len,
53755613f44SDmitri Tikhonov                lsxpack_header_get_value(&headers->headers[i]));
53850aadb33SDmitri Tikhonov}
53955cd0b38SDmitri Tikhonov
54055cd0b38SDmitri Tikhonovvoid
5415392f7a3SLiteSpeed Techlsquic_ev_log_create_connection (const lsquic_cid_t *cid,
54255cd0b38SDmitri Tikhonov                                    const struct sockaddr *local_sa,
54355cd0b38SDmitri Tikhonov                                    const struct sockaddr *peer_sa)
54455cd0b38SDmitri Tikhonov{
54555cd0b38SDmitri Tikhonov    LCID("connection created");
54655cd0b38SDmitri Tikhonov}
54755cd0b38SDmitri Tikhonov
54855cd0b38SDmitri Tikhonov
54955cd0b38SDmitri Tikhonovvoid
5505392f7a3SLiteSpeed Techlsquic_ev_log_hsk_completed (const lsquic_cid_t *cid)
55155cd0b38SDmitri Tikhonov{
55255cd0b38SDmitri Tikhonov    LCID("handshake completed");
55355cd0b38SDmitri Tikhonov}
55455cd0b38SDmitri Tikhonov
55555cd0b38SDmitri Tikhonov
55655cd0b38SDmitri Tikhonovvoid
5575392f7a3SLiteSpeed Techlsquic_ev_log_zero_rtt (const lsquic_cid_t *cid)
55855cd0b38SDmitri Tikhonov{
55955cd0b38SDmitri Tikhonov    LCID("zero_rtt successful");
56055cd0b38SDmitri Tikhonov}
56155cd0b38SDmitri Tikhonov
56255cd0b38SDmitri Tikhonov
56355cd0b38SDmitri Tikhonovvoid
5645392f7a3SLiteSpeed Techlsquic_ev_log_check_certs (const lsquic_cid_t *cid, const lsquic_str_t **certs,
56555cd0b38SDmitri Tikhonov                                                                size_t count)
56655cd0b38SDmitri Tikhonov{
56755cd0b38SDmitri Tikhonov    LCID("check certs");
56855cd0b38SDmitri Tikhonov}
56955cd0b38SDmitri Tikhonov
57055cd0b38SDmitri Tikhonov
57155cd0b38SDmitri Tikhonovvoid
572b55a5117SDmitri Tikhonovlsquic_ev_log_cert_chain (const lsquic_cid_t *cid, struct stack_st_X509 *chain)
573b55a5117SDmitri Tikhonov{
574b55a5117SDmitri Tikhonov    X509_NAME *name;
575b55a5117SDmitri Tikhonov    X509 *cert;
576b55a5117SDmitri Tikhonov    unsigned i;
577b55a5117SDmitri Tikhonov    char buf[0x100];
578b55a5117SDmitri Tikhonov
579b55a5117SDmitri Tikhonov    for (i = 0; i < sk_X509_num(chain); ++i)
580b55a5117SDmitri Tikhonov    {
581b55a5117SDmitri Tikhonov        cert = sk_X509_value(chain, i);
582b55a5117SDmitri Tikhonov        name = X509_get_subject_name(cert);
583b55a5117SDmitri Tikhonov        LCID("cert #%u: name: %s", i,
584b55a5117SDmitri Tikhonov                                X509_NAME_oneline(name, buf, sizeof(buf)));
585b55a5117SDmitri Tikhonov    }
586b55a5117SDmitri Tikhonov}
587b55a5117SDmitri Tikhonov
588b55a5117SDmitri Tikhonov
589b55a5117SDmitri Tikhonovvoid
5905392f7a3SLiteSpeed Techlsquic_ev_log_version_negotiation (const lsquic_cid_t *cid,
59155cd0b38SDmitri Tikhonov                                        const char *action, const char *ver)
59255cd0b38SDmitri Tikhonov{
59355cd0b38SDmitri Tikhonov    LCID("version negotiation: %s version %s", action, ver);
59455cd0b38SDmitri Tikhonov}
595