aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@nxc.no>2018-02-01 15:16:07 +0100
committerSergey Poznyakoff <gray@nxc.no>2018-02-01 17:10:10 +0100
commit85f908426e444a596b979a9569bf83fadfa5ace1 (patch)
tree7513334ef43be06b45f39f13ef9b6a3bf37931d8
parent94973146c58df26b20e17e2e5b1274216ca88969 (diff)
downloadvarnish-mib-85f908426e444a596b979a9569bf83fadfa5ace1.tar.gz
varnish-mib-85f908426e444a596b979a9569bf83fadfa5ace1.tar.bz2
Rewrite for Varnish 5.x
* configure.ac (AC_CHECK_VSC_C_MAIN_MEMBERS): Remove. * src/.gitignore: Update. * src/Makefile.am (varnish_mib_la_SOURCES): Add new sources. * src/backend.h: New file. * src/belex.l: New file. * src/statdict.c: New file. * src/ban.c: Rewrite. * src/betab.c: Rewrite. * src/varnish_mib.mib2c: Rewrite. * src/vcli.c: Rewrite.
-rw-r--r--configure.ac5
-rw-r--r--src/.gitignore1
-rw-r--r--src/Makefile.am3
-rw-r--r--src/backend.h16
-rw-r--r--src/ban.c15
-rw-r--r--src/belex.l178
-rw-r--r--src/betab.c482
-rw-r--r--src/statdict.c172
-rw-r--r--src/varnish_mib.mib2c227
-rw-r--r--src/vcli.c69
10 files changed, 830 insertions, 338 deletions
diff --git a/configure.ac b/configure.ac
index cf0bf05..c334724 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,5 +1,5 @@
1# This file is part of Varnish-mib -*- autoconf -*- 1# This file is part of Varnish-mib -*- autoconf -*-
2# Copyright (C) 2014-2016 Sergey Poznyakoff 2# Copyright (C) 2014-2018 Sergey Poznyakoff
3# 3#
4# Varnish-mib is free software; you can redistribute it and/or modify 4# Varnish-mib is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by 5# it under the terms of the GNU General Public License as published by
@@ -32,6 +32,7 @@ if test "x$ac_cv_prog_cc_c99" = xno; then
32 AC_MSG_ERROR([could not find a C99 compatible compiler]) 32 AC_MSG_ERROR([could not find a C99 compatible compiler])
33fi 33fi
34AC_PROG_CPP 34AC_PROG_CPP
35AM_PROG_LEX
35 36
36AC_PROG_INSTALL 37AC_PROG_INSTALL
37AC_PROG_LIBTOOL 38AC_PROG_LIBTOOL
@@ -57,8 +58,6 @@ if test -n "$v"; then
57 IFS=$save_IFS 58 IFS=$save_IFS
58fi 59fi
59 60
60AC_CHECK_VSC_C_MAIN_MEMBERS
61
62# Check for Net-SNMP 61# Check for Net-SNMP
63AC_PATH_PROG([NET_SNMP_CONFIG], net-snmp-config, none, $PATH) 62AC_PATH_PROG([NET_SNMP_CONFIG], net-snmp-config, none, $PATH)
64if test "$NET_SNMP_CONFIG" = "none"; then 63if test "$NET_SNMP_CONFIG" = "none"; then
diff --git a/src/.gitignore b/src/.gitignore
index 61958b7..f40282a 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -1,2 +1,3 @@
1varnish_mib.c 1varnish_mib.c
2varnish_mib.h 2varnish_mib.h
3belex.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 48c786b..3a7f12a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -20,9 +20,12 @@ dlmod_LTLIBRARIES = varnish-mib.la
20varnish_mib_la_SOURCES = \ 20varnish_mib_la_SOURCES = \
21 auth.c\ 21 auth.c\
22 ban.c\ 22 ban.c\
23 backend.h\
24 belex.l\
23 betab.c\ 25 betab.c\
24 sha256.c\ 26 sha256.c\
25 sha256.h\ 27 sha256.h\
28 statdict.c\
26 varnish_mib.c\ 29 varnish_mib.c\
27 varnish_mib.h\ 30 varnish_mib.h\
28 vcli.c 31 vcli.c
diff --git a/src/backend.h b/src/backend.h
new file mode 100644
index 0000000..0c15e60
--- /dev/null
+++ b/src/backend.h
@@ -0,0 +1,16 @@
1typedef struct be_string {
2 char const *start;
3 size_t len;
4} be_string_t;
5
6typedef void (*regfun_t)(be_string_t *, be_string_t *, be_string_t *, void *);
7
8void read_defs(const char *str, size_t len, regfun_t regfun, void *d);
9void varnish_backend_table_timeout_parser(const char *token, char *line);
10struct VSC_point;
11void backend_register(char const *name, size_t len, char const *param,
12 const struct VSC_point *vpt);
13void backend_clear(void);
14int backend_collect_addr(void);
15void backend_parser(const char *str, size_t len, regfun_t regfun, void *d);
16
diff --git a/src/ban.c b/src/ban.c
index 26dc5f4..0c354e9 100644
--- a/src/ban.c
+++ b/src/ban.c
@@ -38,7 +38,7 @@ send_ban_cmd(vcli_conn_t *conn, const char *expr)
38int 38int
39varnish_ban(netsnmp_agent_request_info *reqinfo, 39varnish_ban(netsnmp_agent_request_info *reqinfo,
40 netsnmp_request_info *requests, 40 netsnmp_request_info *requests,
41 struct VSM_data *vd) 41 struct vsm *vsm)
42{ 42{
43 int rc; 43 int rc;
44 struct vcli_conn conn; 44 struct vcli_conn conn;
@@ -52,7 +52,7 @@ varnish_ban(netsnmp_agent_request_info *reqinfo,
52 memcpy(expr, requests->requestvb->val.string, len); 52 memcpy(expr, requests->requestvb->val.string, len);
53 expr[len] = 0; 53 expr[len] = 0;
54 DEBUGMSGTL(("varnish_ban", "setting ban %s\n", expr)); 54 DEBUGMSGTL(("varnish_ban", "setting ban %s\n", expr));
55 rc = vcli_connect(vd, &conn); 55 rc = vcli_connect(vsm, &conn);
56 if (rc == SNMP_ERR_NOERROR) { 56 if (rc == SNMP_ERR_NOERROR) {
57 rc = send_ban_cmd(&conn, expr); 57 rc = send_ban_cmd(&conn, expr);
58 vcli_disconnect(&conn); 58 vcli_disconnect(&conn);
@@ -151,13 +151,14 @@ banTable_load(netsnmp_cache *cache, void *vmagic)
151 int rc; 151 int rc;
152 struct vcli_conn conn; 152 struct vcli_conn conn;
153 char *p; 153 char *p;
154 struct VSM_data *vd; 154
155 struct vsm *vsm = varnish_get_vsm_data();
156 if (!vsm)
157 return SNMP_ERR_GENERR;
155 158
156 DEBUGMSGTL(("varnish_ban", "reloading ban table\n")); 159 DEBUGMSGTL(("varnish_ban", "reloading ban table\n"));
157 vd = varnish_get_vsm_data(); 160 rc = vcli_connect(vsm, &conn);
158 if (!vd) 161
159 return SNMP_ERR_NOSUCHNAME;
160 rc = vcli_connect(vd, &conn);
161 if (rc != SNMP_ERR_NOERROR) 162 if (rc != SNMP_ERR_NOERROR)
162 return rc; 163 return rc;
163 164
diff --git a/src/belex.l b/src/belex.l
new file mode 100644
index 0000000..f35f114
--- /dev/null
+++ b/src/belex.l
@@ -0,0 +1,178 @@
1%option nounput
2%option noinput
3
4%{
5#include "backend.h"
6
7enum {
8 T_BOGUS = 256,
9 T_IDENT,
10 T_NUMBER,
11 T_STRING,
12 T_BACKEND,
13 T_HOST,
14 T_PORT
15};
16
17static char const *input_string;
18static size_t input_len;
19static size_t input_pos;
20static char const *string_start;
21static size_t current_pos;
22
23#define YY_INPUT(buf,result,max_size) \
24 do { \
25 size_t n = input_len - input_pos; \
26 if (n > max_size) \
27 n = max_size; \
28 memcpy(buf, input_string, n); \
29 input_pos += n; \
30 result = n; \
31 } while (0)
32
33#define YY_USER_ACTION \
34 current_pos += yyleng;
35
36#define YY_DECL static int yylex(void)
37static int yywrap(void);
38
39static char const *
40input_point(void)
41{
42 return input_string + current_pos;
43}
44
45#define YYSTYPE be_string_t
46#define YYSTYPE_INITIALIZER { NULL, 0 }
47
48static YYSTYPE yylval;
49%}
50
51%x COMMENT STR
52
53%%
54 /* C-style comments */
55"/*" BEGIN(COMMENT);
56<COMMENT>[^*]* /* eat anything that's not a '*' */
57<COMMENT>"*"+[^*/]* /* eat up '*'s not followed by '/'s */
58<COMMENT>"*"+"/" BEGIN(INITIAL);
59
60 /* Single-line comments */
61"//".*\n ;
62#.*\n ;
63
64 /* Multi-line strings */
65"{\"" { BEGIN(STR); string_start = input_point(); }
66<STR>[^\"]* /* eat anything that's not a '"' */
67<STR>"\""+[^"}]* /* eat up '"'s not followed by '}'s */
68<STR>"\""+"}" { BEGIN(INITIAL);
69 yylval.start = string_start;
70 yylval.len = input_point() - yylval.start - 2;
71 return T_STRING;
72 }
73 /* Single-line strings */
74\".*\" {
75 yylval.start = input_point() - yyleng + 1;
76 yylval.len = yyleng - 2;
77 return T_STRING;
78 }
79backend return T_BACKEND;
80".host" return T_HOST;
81".port" return T_PORT;
82"{"|"}"|"="|";" return yytext[0];
83
84[a-zA-Z_][a-zA-Z0-9_.]+ {
85 yylval.start = input_point() - yyleng;
86 yylval.len = yyleng;
87 return T_IDENT;
88 }
89[0-9]+ return T_NUMBER;
90
91[ \t\n]+ ;
92
93. return T_BOGUS;
94
95%%
96int
97yywrap(void)
98{
99 return 1;
100}
101
102static void
103set_input(char const *str, size_t len)