Code Coverage: vinyl-cache/bin/vinyld/http2/cache_http2_panic.c
 
82217aa4fc7094b3610340078afaf78cd95a8ec9
 
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_int.h"
36
37
#include "cache/cache_transport.h"
38
#include "http2/cache_http2.h"
39
40
static const char *
41
h2_panic_error(const struct h2_error_s *e)
42 3
{
43 3
        if (e == NULL)
44 3
                return ("(null)");
45 0
        else
46 0
                return (e->name);
47 3
}
48
49
static void
50
h2_panic_settings(struct vsb *vsb, const struct h2_settings *s)
51 2
{
52 2
        int cont = 0;
53
54 2
#define H2_SETTING(U,l,...)                     \
55 18
        do {                                    \
56 18
                if (cont)                       \
57 18
                        VSB_printf(vsb, ", ");  \
58 18
                cont = 1;                       \
59 18
                VSB_printf(vsb, "0x%x", s->l);  \
60 18
        } while (0);
61 2
#include "tbl/h2_settings.h"
62 2
#undef H2_SETTING
63 2
}
64
65
void
66
h2_sess_panic(struct vsb *vsb, const struct sess *sp)
67 1
{
68 1
        uintptr_t *up;
69 1
        struct h2_sess *h2;
70 1
        struct h2_req *r2;
71
72 1
        AZ(SES_Get_proto_priv(sp, &up));
73
74 1
        AN(up);
75 1
        h2 = (void*)*up;
76 1
        if (PAN_dump_struct(vsb, h2, H2_SESS_MAGIC, "h2_sess"))
77 0
                return;
78 1
        VSB_printf(vsb, "refcnt = %d, bogosity = %d, error = %s\n",
79 1
            h2->refcnt, h2->bogosity, h2_panic_error(h2->error));
80 1
        VSB_printf(vsb,
81 1
            "open_streams = %d, highest_stream = %u,"
82 1
            " goaway_last_stream = %u,\n",
83 1
            h2->open_streams, h2->highest_stream, h2->goaway_last_stream);
84 1
        VSB_cat(vsb, "local_settings = {");
85 1
        h2_panic_settings(vsb, &h2->local_settings);
86 1
        VSB_cat(vsb, "},\n");
87 1
        VSB_cat(vsb, "remote_settings = {");
88 1
        h2_panic_settings(vsb, &h2->remote_settings);
89 1
        VSB_cat(vsb, "},\n");
90 1
        VSB_printf(vsb,
91 1
            "{rxf_len, rxf_type, rxf_flags, rxf_stream} ="
92 1
            " {%u, %u, 0x%x, %u},\n",
93 1
            h2->rxf_len, h2->rxf_type, h2->rxf_flags, h2->rxf_stream);
94 2
        VTAILQ_FOREACH(r2, &h2->streams, list) {
95 2
                if (PAN_dump_struct(vsb, r2, H2_REQ_MAGIC, "stream"))
96 0
                        continue;
97 2
                VSB_printf(vsb, "id = %u, state = ", r2->stream);
98 2
                switch (r2->state) {
99 2
#define H2_STREAM(U,sd,d) case H2_S_##U: VSB_printf(vsb, "%s", sd); break;
100 0
#include <tbl/h2_stream.h>
101 0
                default:
102 0
                        VSB_printf(vsb, " 0x%x", r2->state);
103 0
                        break;
104 2
                }
105 2
                VSB_cat(vsb, ",\n");
106
107 2
                VSB_printf(vsb, "h2_sess = %p, scheduled = %d, error = %s,\n",
108 2
                    r2->h2sess, r2->scheduled, h2_panic_error(r2->error));
109 2
                VSB_printf(vsb, "t_send = %f, t_winupd = %f,\n",
110 2
                    r2->t_send, r2->t_winupd);
111 2
                VSB_printf(vsb, "t_window = %jd, r_window = %jd,\n",
112 2
                    (intmax_t)r2->t_window, (intmax_t)r2->r_window);
113
114 2
                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 0
                            "{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 2
                VSB_indent(vsb, -2);
125 2
                VSB_cat(vsb, "},\n");
126 2
        }
127 1
        VSB_indent(vsb, -2);
128 1
}