Skip to content

Commit f0b01d5

Browse files
committed
Implement a dbg acceptor as a VEXT
it actually just uses the TCP acceptor code, but tests plugging via an extension
1 parent 4007cd8 commit f0b01d5

File tree

6 files changed

+210
-1
lines changed

6 files changed

+210
-1
lines changed

bin/varnishtest/tests/x00001.vtc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
varnishtest "Minimal acceptor VEXT test"
2+
3+
shell -err -expect {Error: Acceptor foo not found} {
4+
varnishd -b None -a %foo,socket -n ${tmpdir}
5+
}
6+
7+
shell -err -expect {Error: Acceptor bar not found} {
8+
varnishd -b None -a name=%bar,socket -n ${tmpdir}
9+
}
10+
11+
varnish v1 \
12+
-arg "-E ${topbuild}/vmod/.libs/libvmod_vext_debug.so" \
13+
-arg "-a dbg=%dbg,${listen_addr}" \
14+
-vcl {
15+
16+
backend none none;
17+
18+
sub vcl_recv {
19+
return (synth(200));
20+
}
21+
} -start
22+
23+
#client c1 -repeat 10 {
24+
client c1 {
25+
txreq
26+
rxresp
27+
} -run

vmod/Makefile.am

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ include $(srcdir)/automake_boilerplate_blob.am
3131
include $(srcdir)/automake_boilerplate_h2.am
3232
include $(srcdir)/automake_boilerplate_cookie.am
3333
include $(srcdir)/automake_boilerplate_debug.am
34+
include $(srcdir)/automake_boilerplate_vext_debug.am
3435
include $(srcdir)/automake_boilerplate_directors.am
3536
include $(srcdir)/automake_boilerplate_proxy.am
3637
include $(srcdir)/automake_boilerplate_purge.am
@@ -55,6 +56,8 @@ vmod_debug_symbols_regex = 'Vmod_.*_Data'
5556
# not --strict
5657
vmodtoolargs_debug = --boilerplate -o vcc_debug_if
5758

58-
dist_noinst_DATA = $(srcdir)/vmod_debug.vcc
59+
dist_noinst_DATA = \
60+
$(srcdir)/vmod_debug.vcc \
61+
$(srcdir)/vmod_vext_debug.vcc
5962

6063
dist_vcc_DATA = $(vmod_vcc_files)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
## Generated by vmodtool.py --boilerplate.
2+
3+
vmod_vext_debug_vcc ?= $(srcdir)/vmod_vext_debug.vcc
4+
5+
vmod_vcc_files += $(vmod_vext_debug_vcc)
6+
7+
vmod_LTLIBRARIES += libvmod_vext_debug.la
8+
9+
libvmod_vext_debug_la_SOURCES = \
10+
vmod_vext_debug.c \
11+
vmod_vext_debug_acceptor.c
12+
13+
libvmod_vext_debug_la_CFLAGS =
14+
15+
vmodtoolargs_vext_debug ?= --strict --boilerplate -o vcc_vext_debug_if
16+
vmod_vext_debug_symbols_regex ?= Vmod_vext_debug_Data
17+
18+
libvmod_vext_debug_la_LDFLAGS = \
19+
-export-symbols-regex $(vmod_vext_debug_symbols_regex) \
20+
$(AM_LDFLAGS) \
21+
$(VMOD_LDFLAGS)
22+
23+
nodist_libvmod_vext_debug_la_SOURCES = vcc_vext_debug_if.c vcc_vext_debug_if.h
24+
25+
EXTRA_libvmod_vext_debug_la_DEPENDENCIES = $(nodist_libvmod_vext_debug_la_SOURCES)
26+
27+
EXTRA_DIST += automake_boilerplate_vext_debug.am
28+
29+
$(libvmod_vext_debug_la_OBJECTS): vcc_vext_debug_if.h
30+
31+
vcc_vext_debug_if.h vmod_vext_debug.rst vmod_vext_debug.man.rst: vcc_vext_debug_if.c
32+
33+
# A doc-change will not update mtime on the .h and .c files, so a
34+
# touch(1) is necessary to signal that vmodtool was in fact run.
35+
vcc_vext_debug_if.c: $(VMODTOOL) $(srcdir)/vmod_vext_debug.vcc
36+
@PYTHON@ $(VMODTOOL) $(vmodtoolargs_vext_debug) $(srcdir)/vmod_vext_debug.vcc
37+
touch vcc_vext_debug_if.c
38+
39+
clean-local: clean-vmod-vext_debug
40+
41+
clean-vmod-vext_debug:
42+
rm -f $(nodist_libvmod_vext_debug_la_SOURCES)
43+
rm -f vmod_vext_debug.rst vmod_vext_debug.man.rst

vmod/vmod_vext_debug.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "config.h"
2+
#include "vdef.h"
3+
#include "vrt.h"
4+
#include "vcc_vext_debug_if.h"
5+
6+
VCL_VOID
7+
dbgvext_dummy(VRT_CTX)
8+
{
9+
(void) ctx;
10+
}

vmod/vmod_vext_debug.vcc

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright 2024 UPLEX - Nils Goroll Systemoptimierung
2+
# All rights reserved.
3+
#
4+
# Author: Nils Goroll <nils.goroll@uplex.de>
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+
$ABI strict
30+
$Prefix dbgvext
31+
$Module vext_debug 3 "Varnish Extension development, test and debug"
32+
$Synopsis auto
33+
DESCRIPTION
34+
===========
35+
36+
At this point, this vmod does not expose any interface to VCL.
37+
38+
It implements the "dbg" acceptor, which simply wraps the "tcp" acceptor.
39+
40+
$Function VOID dummy()

vmod/vmod_vext_debug_acceptor.c

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*-
2+
* Copyright 2024 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
11+
* are met:
12+
* 1. Redistributions of source code must retain the above copyright
13+
* notice, this list of conditions and the following disclaimer.
14+
* 2. Redistributions in binary form must reproduce the above copyright
15+
* notice, this list of conditions and the following disclaimer in the
16+
* documentation and/or other materials provided with the distribution.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
22+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28+
* SUCH DAMAGE.
29+
*/
30+
31+
#include "config.h"
32+
33+
#include <stdio.h>
34+
35+
#include "cache/cache_varnishd.h"
36+
#include "acceptor/cache_acceptor.h"
37+
#include "acceptor/mgt_acceptor.h"
38+
39+
struct acceptor DBG_acceptor;
40+
41+
// these callbacks are all noops, because we initialize our dbg acceptor as a
42+
// tcp acceptor, which keeps a list of its instances, so the respective
43+
// functions get already called through the tcp acceptor
44+
45+
static int
46+
acc_dbg_reopen(void)
47+
{
48+
return (0);
49+
}
50+
51+
static void
52+
acc_dbg_start(struct cli *cli)
53+
{
54+
(void) cli;
55+
}
56+
57+
static void
58+
acc_dbg_accept(struct pool * pp)
59+
{
60+
(void) pp;
61+
}
62+
63+
static void
64+
acc_dbg_update(pthread_mutex_t * shut_mtx)
65+
{
66+
(void) shut_mtx;
67+
}
68+
69+
static void
70+
acc_dbg_shutdown(void)
71+
{
72+
}
73+
74+
static void __attribute__((constructor))
75+
init_register_acceptor(void) {
76+
fprintf(stderr, "HELLO from dbg acceptor VEXT\n");
77+
DBG_acceptor = TCP_acceptor;
78+
DBG_acceptor.name = "dbg";
79+
DBG_acceptor.reopen = acc_dbg_reopen;
80+
DBG_acceptor.start = acc_dbg_start;
81+
DBG_acceptor.accept = acc_dbg_accept;
82+
DBG_acceptor.update = acc_dbg_update;
83+
DBG_acceptor.shutdown = acc_dbg_shutdown;
84+
85+
VCA_Add(&DBG_acceptor);
86+
}

0 commit comments

Comments
 (0)