|
| 1 | +/*- |
| 2 | + * Copyright 2023 UPLEX - Nils Goroll Systemoptimierung |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * Author: Nils Goroll <nils.goroll@uplex.de> |
| 6 | + * |
| 7 | + * SPDX-License-Identifier: BSD-2-Clause |
| 8 | + * |
| 9 | + * Redistribution and use in source and binary forms, with or without |
| 10 | + * modification, are permitted provided that the following conditions are met: |
| 11 | + * 1. Redistributions of source code must retain the above copyright notice, |
| 12 | + * this list of conditions and the following disclaimer. |
| 13 | + * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 14 | + * this list of conditions and the following disclaimer in the documentation |
| 15 | + * and/or other materials provided with the distribution. |
| 16 | + * |
| 17 | + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY |
| 18 | + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 19 | + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 20 | + * DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY |
| 21 | + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 22 | + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 23 | + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 24 | + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 26 | + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | + * |
| 28 | + */ |
| 29 | + |
| 30 | +#include "config.h" |
| 31 | + |
| 32 | +#include "cache/cache_varnishd.h" |
| 33 | + |
| 34 | +#include "vcc_if.h" |
| 35 | + |
| 36 | +#include "cache/cache_transport.h" |
| 37 | +#include "http2/cache_http2.h" |
| 38 | + |
| 39 | +static struct h2_sess * |
| 40 | +h2get(VRT_CTX) |
| 41 | +{ |
| 42 | + struct h2_sess *h2; |
| 43 | + uintptr_t *up; |
| 44 | + |
| 45 | + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); |
| 46 | + CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); // $Restrict client |
| 47 | + if (ctx->req->transport != &H2_transport) |
| 48 | + return (NULL); |
| 49 | + AZ(SES_Get_proto_priv(ctx->req->sp, &up)); |
| 50 | + CAST_OBJ_NOTNULL(h2, (void *)*up, H2_SESS_MAGIC); |
| 51 | + return (h2); |
| 52 | +} |
| 53 | +VCL_BOOL |
| 54 | +vmod_is(VRT_CTX) |
| 55 | +{ |
| 56 | + struct h2_sess *h2 = h2get(ctx); |
| 57 | + |
| 58 | + return (h2 != NULL); |
| 59 | +} |
| 60 | + |
| 61 | +#define GETSET(type, name, argname) \ |
| 62 | +type \ |
| 63 | +vmod_ ## name(VRT_CTX, struct vmod_##name##_arg *args) \ |
| 64 | +{ \ |
| 65 | + struct h2_sess *h2 = h2get(ctx); \ |
| 66 | + type r; \ |
| 67 | + \ |
| 68 | + if (h2 == NULL) \ |
| 69 | + return (-1); \ |
| 70 | + \ |
| 71 | + if (! args->valid_ ## argname) \ |
| 72 | + return (h2->name); \ |
| 73 | + if (h2->name == args->argname) \ |
| 74 | + return (h2->name); \ |
| 75 | + \ |
| 76 | + Lck_Lock(&h2->sess->mtx); \ |
| 77 | + r = h2->name; \ |
| 78 | + if (h2->name != args->argname) { \ |
| 79 | + h2->name = args->argname; \ |
| 80 | + h2->rst_budget = h2->rapid_reset_limit; \ |
| 81 | + h2->last_rst = ctx->now; \ |
| 82 | + } \ |
| 83 | + Lck_Unlock(&h2->sess->mtx); \ |
| 84 | + return (r); \ |
| 85 | +} |
| 86 | + |
| 87 | +GETSET(VCL_DURATION, rapid_reset, threshold) |
| 88 | +GETSET(VCL_INT, rapid_reset_limit, number) |
| 89 | +GETSET(VCL_DURATION, rapid_reset_period, duration) |
| 90 | + |
| 91 | +VCL_REAL |
| 92 | +vmod_rapid_reset_budget(VRT_CTX) |
| 93 | +{ |
| 94 | + struct h2_sess *h2 = h2get(ctx); |
| 95 | + |
| 96 | + if (h2 == NULL) |
| 97 | + return (-1); |
| 98 | + |
| 99 | + return (h2->rst_budget); |
| 100 | +} |
0 commit comments