diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/.gitignore | 1 | ||||
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/backend.h | 16 | ||||
-rw-r--r-- | src/ban.c | 15 | ||||
-rw-r--r-- | src/belex.l | 178 | ||||
-rw-r--r-- | src/betab.c | 482 | ||||
-rw-r--r-- | src/statdict.c | 172 | ||||
-rw-r--r-- | src/varnish_mib.mib2c | 227 | ||||
-rw-r--r-- | src/vcli.c | 69 |
9 files changed, 828 insertions, 335 deletions
diff --git a/src/.gitignore b/src/.gitignore index 61958b7..f40282a 100644 --- a/src/.gitignore +++ b/src/.gitignore | |||
@@ -1,2 +1,3 @@ | |||
1 | varnish_mib.c | 1 | varnish_mib.c |
2 | varnish_mib.h | 2 | varnish_mib.h |
3 | belex.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 | |||
20 | varnish_mib_la_SOURCES = \ | 20 | varnish_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 @@ | |||
1 | typedef struct be_string { | ||
2 | char const *start; | ||
3 | size_t len; | ||
4 | } be_string_t; | ||
5 | |||
6 | typedef void (*regfun_t)(be_string_t *, be_string_t *, be_string_t *, void *); | ||
7 | |||
8 | void read_defs(const char *str, size_t len, regfun_t regfun, void *d); | ||
9 | void varnish_backend_table_timeout_parser(const char *token, char *line); | ||
10 | struct VSC_point; | ||
11 | void backend_register(char const *name, size_t len, char const *param, | ||
12 | const struct VSC_point *vpt); | ||
13 | void backend_clear(void); | ||
14 | int backend_collect_addr(void); | ||
15 | void backend_parser(const char *str, size_t len, regfun_t regfun, void *d); | ||
16 | |||
@@ -38,7 +38,7 @@ send_ban_cmd(vcli_conn_t *conn, const char *expr) | |||
38 | int | 38 | int |
39 | varnish_ban(netsnmp_agent_request_info *reqinfo, | 39 | varnish_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 | |||
7 | enum { | ||
8 | T_BOGUS = 256, | ||
9 | T_IDENT, | ||
10 | T_NUMBER, | ||
11 | T_STRING, | ||
12 | T_BACKEND, | ||
13 | T_HOST, | ||
14 | T_PORT | ||
15 | }; | ||
16 | |||
17 | static char const *input_string; | ||
18 | static size_t input_len; | ||
19 | static size_t input_pos; | ||
20 | static char const *string_start; | ||
21 | static 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) | ||
37 | static int yywrap(void); | ||
38 | |||
39 | static char const * | ||
40 | input_point(void) | ||
41 | { | ||
42 | return input_string + current_pos; | ||
43 | } | ||
44 | |||
45 | #define YYSTYPE be_string_t | ||
46 | #define YYSTYPE_INITIALIZER { NULL, 0 } | ||
47 | |||
48 | static 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 | } | ||
79 | backend 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 | %% | ||
96 | int | ||
97 | yywrap(void) | ||
98 | { | ||
99 | return 1; | ||
100 | } | ||
101 | |||
102 | static void | ||
103 | set_input(char const *str, size_t len) | ||
104 | { | ||
105 | input_string = str; | ||
106 | input_len = len; | ||
107 | input_pos = 0; | ||
108 | current_pos = 0; | ||
109 | } | ||
110 | |||
111 | static int brace_nesting; | ||
112 | |||
113 | static void | ||
114 | read_backend(regfun_t regfun, void *d) | ||
115 | { | ||
116 | int c; | ||
117 | int in_statement; | ||
118 | YYSTYPE label, host = YYSTYPE_INITIALIZER, port = YYSTYPE_INITIALIZER; | ||
119 | |||
120 | if ((c = yylex()) != T_IDENT && c != T_STRING) | ||
121 | return; | ||
122 | label = yylval; | ||
123 | if ((c = yylex()) != '{') | ||
124 | return; | ||
125 | brace_nesting++; | ||
126 | in_statement = 0; | ||
127 | while (brace_nesting == 1) { | ||
128 | c = yylex(); | ||
129 | if (c == 0) | ||
130 | break; | ||
131 | else if (c == '{') | ||
132 | brace_nesting++; | ||
133 | else if (c == '}') | ||
134 | brace_nesting++; | ||
135 | else if (in_statement) { | ||
136 | if (c == ';') | ||
137 | in_statement = 0; | ||
138 | } else { | ||
139 | in_statement = 1; | ||
140 | if (c == T_HOST || c == T_PORT) { | ||
141 | YYSTYPE *stk = c == T_HOST ? &host : &port; | ||
142 | in_statement = 1; | ||