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
35
#include "cache/cache_varnishd.h"
36
37
#include "cache/cache_transport.h"
38
#include "http2/cache_http2.h"
39
40
static const char *
41 120
h2_panic_error(const struct h2_error_s *e)
42 80
{
43 120
        if (e == NULL)
44 120
                return ("(null)");
45
        else
46 0
                return (e->name);
47 120
}
48
49
static void
50 80
h2_panic_settings(struct vsb *vsb, const struct h2_settings *s)
51
{
52 80
        int cont = 0;
53 80
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
}
64 80
65
void
66 40
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 40
        AZ(SES_Get_proto_priv(sp, &up));
73
74 120
        AN(up);
75 40
        h2 = (void*)*up;
76 40
        if (PAN_dump_struct(vsb, h2, H2_SESS_MAGIC, "h2_sess"))
77 0
                return;
78 80
        VSB_printf(vsb, "refcnt = %d, bogosity = %d, error = %s\n",
79 40
            h2->refcnt, h2->bogosity, h2_panic_error(h2->error));
80 80
        VSB_printf(vsb,
81
            "open_streams = %d, highest_stream = %u,"
82
            " goaway_last_stream = %u,\n",
83 40
            h2->open_streams, h2->highest_stream, h2->goaway_last_stream);
84 120
        VSB_cat(vsb, "local_settings = {");
85 40
        h2_panic_settings(vsb, &h2->local_settings);
86 40
        VSB_cat(vsb, "},\n");
87 40
        VSB_cat(vsb, "remote_settings = {");
88 40
        h2_panic_settings(vsb, &h2->remote_settings);
89 40
        VSB_cat(vsb, "},\n");
90 80
        VSB_printf(vsb,
91
            "{rxf_len, rxf_type, rxf_flags, rxf_stream} ="
92
            " {%u, %u, 0x%x, %u},\n",
93 40
            h2->rxf_len, h2->rxf_type, h2->rxf_flags, h2->rxf_stream);
94 120
        VTAILQ_FOREACH(r2, &h2->streams, list) {
95 160
                if (PAN_dump_struct(vsb, r2, H2_REQ_MAGIC, "stream"))
96 0
                        continue;
97 80
                VSB_printf(vsb, "id = %u, state = ", r2->stream);
98 80
                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
                        VSB_printf(vsb, " 0x%x", r2->state);
103
                        break;
104
                }
105 80
                VSB_cat(vsb, ",\n");
106
107 160
                VSB_printf(vsb, "h2_sess = %p, scheduled = %d, error = %s,\n",
108 80
                    r2->h2sess, r2->scheduled, h2_panic_error(r2->error));
109 160
                VSB_printf(vsb, "t_send = %f, t_winupd = %f,\n",
110 80
                    r2->t_send, r2->t_winupd);
111 160
                VSB_printf(vsb, "t_window = %jd, r_window = %jd,\n",
112 80
                    (intmax_t)r2->t_window, (intmax_t)r2->r_window);
113
114 80
                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 80
                VSB_indent(vsb, -2);
125 80
                VSB_cat(vsb, "},\n");
126 80
        }
127 40
        VSB_indent(vsb, -2);
128 40
}