varnish-cache/bin/varnishd/http2/cache_http2_panic.c
0
/*-
1
 * Copyright (c) 2016 Varnish Software AS
2
 * All rights reserved.
3
 *
4
 * Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
5
 *
6
 * SPDX-License-Identifier: BSD-2-Clause
7
 *
8
 * Redistribution and use in source and binary forms, with or without
9
 * modification, are permitted provided that the following conditions
10
 * are met:
11
 * 1. Redistributions of source code must retain the above copyright
12
 *    notice, this list of conditions and the following disclaimer.
13
 * 2. Redistributions in binary form must reproduce the above copyright
14
 *    notice, this list of conditions and the following disclaimer in the
15
 *    documentation and/or other materials provided with the distribution.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
21
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27
 * SUCH DAMAGE.
28
 *
29
 */
30
31
#include "config.h"
32
33
#include <stdint.h>
34 25
35 0
#include "cache/cache_varnishd.h"
36 0
37 0
#include "cache/cache_transport.h"
38 0
#include "http2/cache_http2.h"
39 25
40 0
static const char *
41 75
h2_panic_error(const struct h2_error_s *e)
42 50
{
43 75
        if (e == NULL)
44 75
                return ("(null)");
45
        else
46 0
                return (e->name);
47 75
}
48
49
static void
50 50
h2_panic_settings(struct vsb *vsb, const struct h2_settings *s)
51
{
52 50
        int cont = 0;
53 50
54
#define H2_SETTING(U,l,...)                     \
55
        do {                                    \
56
                if (cont)                       \
57
                        VSB_printf(vsb, ", ");  \
58
                cont = 1;                       \
59
                VSB_printf(vsb, "0x%x", s->l);  \
60
        } while (0);
61
#include "tbl/h2_settings.h"
62
#undef H2_SETTING
63 50
}
64 50
65
void
66 25
h2_sess_panic(struct vsb *vsb, const struct sess *sp)
67
{
68
        uintptr_t *up;
69
        struct h2_sess *h2;
70
        struct h2_req *r2;
71
72 25
        AZ(SES_Get_proto_priv(sp, &up));
73
74 75
        AN(up);
75 25
        h2 = (void*)*up;
76 25
        if (PAN_dump_struct(vsb, h2, H2_SESS_MAGIC, "h2_sess"))
77 0
                return;
78 50
        VSB_printf(vsb, "refcnt = %d, bogosity = %d, error = %s\n",
79 25
            h2->refcnt, h2->bogosity, h2_panic_error(h2->error));
80 50
        VSB_printf(vsb,
81
            "open_streams = %u, highest_stream = %u,"
82
            " goaway_last_stream = %u,\n",
83 25
            h2->open_streams, h2->highest_stream, h2->goaway_last_stream);
84 75
        VSB_cat(vsb, "local_settings = {");
85 25
        h2_panic_settings(vsb, &h2->local_settings);
86 25
        VSB_cat(vsb, "},\n");
87 25
        VSB_cat(vsb, "remote_settings = {");
88 25
        h2_panic_settings(vsb, &h2->remote_settings);
89 25
        VSB_cat(vsb, "},\n");
90 50
        VSB_printf(vsb,
91
            "{rxf_len, rxf_type, rxf_flags, rxf_stream} ="
92
            " {%u, %u, 0x%x, %u},\n",
93 25
            h2->rxf_len, h2->rxf_type, h2->rxf_flags, h2->rxf_stream);
94 125
        VTAILQ_FOREACH(r2, &h2->streams, list) {
95 50
                if (PAN_dump_struct(vsb, r2, H2_REQ_MAGIC, "stream"))
96 0
                        continue;
97 50
                VSB_printf(vsb, "id = %u, state = ", r2->stream);
98 50
                switch (r2->state) {
99
#define H2_STREAM(U,sd,d) case H2_S_##U: VSB_printf(vsb, "%s", sd); break;
100
#include <tbl/h2_stream.h>
101
                default:
102 0
                        VSB_printf(vsb, " 0x%x", r2->state);
103 0
                        break;
104
                }
105 50
                VSB_cat(vsb, ",\n");
106
107 100
                VSB_printf(vsb, "h2_sess = %p, scheduled = %d, error = %s,\n",
108 50
                    r2->h2sess, r2->scheduled, h2_panic_error(r2->error));
109 100
                VSB_printf(vsb, "t_send = %f, t_winupd = %f,\n",
110 50
                    r2->t_send, r2->t_winupd);
111 100
                VSB_printf(vsb, "t_window = %jd, r_window = %jd,\n",
112 50
                    (intmax_t)r2->t_window, (intmax_t)r2->r_window);
113
114 50
                if (!PAN_dump_struct(vsb, r2->rxbuf, H2_RXBUF_MAGIC, "rxbuf")) {
115 0
                        VSB_printf(vsb, "stvbuf = %p,\n", r2->rxbuf->stvbuf);
116 0
                        VSB_printf(vsb,
117
                            "{size, tail, head} = {%u, %ju, %ju},\n",
118 0
                            r2->rxbuf->size, (uintmax_t)r2->rxbuf->tail,
119 0
                            (uintmax_t)r2->rxbuf->head);
120 0
                        VSB_indent(vsb, -2);
121 0
                        VSB_cat(vsb, "},\n");
122 0
                }
123
124 50
                VSB_indent(vsb, -2);
125 50
                VSB_cat(vsb, "},\n");
126 50
        }
127 25
        VSB_indent(vsb, -2);
128 25
}