Commit 0a2f9d80 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Split IP/ACL compilation into vcc_acl.c



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@555 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 7df2d4de
/*
* $Id: vcc_gen_obj.tcl 548 2006-07-21 20:51:24Z phk $
* $Id: vcc_gen_obj.tcl 550 2006-07-21 21:13:43Z phk $
*
* NB: This file is machine generated, DO NOT EDIT!
*
......@@ -10,6 +10,8 @@ const char * VRT_r_backend_host(struct backend *);
void VRT_l_backend_host(struct backend *, const char *);
const char * VRT_r_backend_port(struct backend *);
void VRT_l_backend_port(struct backend *, const char *);
const unsigned char * VRT_r_client_ip(struct sess *);
void VRT_l_client_ip(struct sess *, const unsigned char *);
const char * VRT_r_req_request(struct sess *);
void VRT_l_req_request(struct sess *, const char *);
const char * VRT_r_req_url(struct sess *);
......
......@@ -9,6 +9,7 @@ libvcl_la_SOURCES = \
vcc_compile.h \
vcc_token_defs.h \
\
vcc_acl.c \
vcc_compile.c \
vcc_fixed_token.c \
vcc_obj.c \
......
/*
* $Id$
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <netdb.h>
#include <stdio.h>
#include <stdarg.h>
#include <sbuf.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "vcc_priv.h"
#include "vcc_compile.h"
#include "libvcl.h"
unsigned
vcc_IpVal(struct tokenlist *tl)
{
unsigned u, v;
struct token *t;
t = tl->t;
u = UintVal(tl);
if (u < 256) {
v = u << 24;
Expect(tl, '.');
vcc_NextToken(tl);
t = tl->t;
u = UintVal(tl);
if (u < 256) {
v |= u << 16;
Expect(tl, '.');
vcc_NextToken(tl);
t = tl->t;
u = UintVal(tl);
if (u < 256) {
v |= u << 8;
Expect(tl, '.');
vcc_NextToken(tl);
t = tl->t;
u = UintVal(tl);
if (u < 256) {
v |= u;
return (v);
}
}
}
}
sbuf_printf(tl->sb, "Illegal octet in IP number\n");
vcc_ErrWhere(tl, t);
return (0);
}
void
vcc_Cond_Ip(struct var *vp, struct tokenlist *tl)
{
unsigned u;
switch (tl->t->tok) {
case '~':
vcc_NextToken(tl);
ExpectErr(tl, ID);
AddRef(tl, tl->t, R_ACL);
Fc(tl, 1, "ip_match(%s, acl_%T)\n", vp->rname, tl->t);
vcc_NextToken(tl);
break;
case T_EQ:
case T_NEQ:
Fc(tl, 1, "%s %T ", vp->rname, tl->t);
vcc_NextToken(tl);
u = vcc_IpVal(tl);
Fc(tl, 0, "%uU /* %u.%u.%u.%u */\n", u,
(u >> 24) & 0xff, (u >> 16) & 0xff,
(u >> 8) & 0xff, (u) & 0xff);
break;
default:
sbuf_printf(tl->sb, "Illegal condition ");
vcc_ErrToken(tl, tl->t);
sbuf_printf(tl->sb, " on IP number variable\n");
sbuf_printf(tl->sb, " only '==', '!=' and '~' are legal\n");
vcc_ErrWhere(tl, tl->t);
break;
}
}
void
vcc_Acl(struct tokenlist *tl)
{
unsigned u, m;
vcc_NextToken(tl);
ExpectErr(tl, ID);
AddDef(tl, tl->t, R_ACL);
Fh(tl, 0, "static struct vcl_acl acl_%T[];\n", tl->t);
Fc(tl, 1, "static struct vcl_acl acl_%T[] = {\n", tl->t);
vcc_NextToken(tl);
tl->indent += INDENT;
ExpectErr(tl, '{');
vcc_NextToken(tl);
while (tl->t->tok == CNUM) {
u = vcc_IpVal(tl);
if (tl->t->tok == '/') {
vcc_NextToken(tl);
ExpectErr(tl, CNUM);
m = UintVal(tl);
} else
m = 32;
ExpectErr(tl, ';');
vcc_NextToken(tl);
Fc(tl, 1, "{ %11uU, %3uU }, /* %u.%u.%u.%u/%u */\n",
u, m,
(u >> 24) & 0xff, (u >> 16) & 0xff,
(u >> 8) & 0xff, (u) & 0xff, m);
}
ExpectErr(tl, '}');
Fc(tl, 1, "{ %11uU, %3uU }\n", 0, 0);
tl->indent -= INDENT;
Fc(tl, 1, "};\n\n");
vcc_NextToken(tl);
}
......@@ -56,8 +56,6 @@
#include "libvcl.h"
#define ERRCHK(tl) do { if ((tl)->err) return; } while (0)
static struct method method_tab[] = {
#define VCL_RET_MAC(a,b,c,d)
#define VCL_MET_MAC(a,b,c) { "vcl_"#a, "default_vcl_"#a, c },
......@@ -77,11 +75,6 @@ const char *vcc_default_vcl_b, *vcc_default_vcl_e;
/*--------------------------------------------------------------------*/
#define ErrInternal(tl) vcc__ErrInternal(tl, __func__, __LINE__)
#define Expect(a, b) vcc__Expect(a, b, __LINE__)
#define ExpectErr(a, b) do { vcc__Expect(a, b, __LINE__); ERRCHK(a);} while (0)
#define L(tl, foo) do { \
tl->indent += INDENT; \
foo; \
......@@ -97,7 +90,7 @@ const char *vcc_default_vcl_b, *vcc_default_vcl_e;
* Printf output to the two sbufs, possibly indented
*/
static void
void
Fh(struct tokenlist *tl, int indent, const char *fmt, ...)
{
va_list ap;
......@@ -109,7 +102,7 @@ Fh(struct tokenlist *tl, int indent, const char *fmt, ...)
va_end(ap);
}
static void
void
Fc(struct tokenlist *tl, int indent, const char *fmt, ...)
{
va_list ap;
......@@ -210,7 +203,7 @@ FindRefStr(struct tokenlist *tl, const char *s, enum ref_type type)
return (0);
}
static void
void
AddRef(struct tokenlist *tl, struct token *t, enum ref_type type)
{
......@@ -230,7 +223,7 @@ AddRefStr(struct tokenlist *tl, const char *s, enum ref_type type)
AddRef(tl, t, type);
}
static void
void
AddDef(struct tokenlist *tl, struct token *t, enum ref_type type)
{
struct ref *r;
......@@ -321,7 +314,7 @@ RateUnit(struct tokenlist *tl)
* Recognize and convert { CNUM } to unsigned value
*/
static unsigned
unsigned
UintVal(struct tokenlist *tl)
{
unsigned d = 0;
......@@ -367,46 +360,6 @@ DoubleVal(struct tokenlist *tl)
/*--------------------------------------------------------------------*/
static unsigned
IpVal(struct tokenlist *tl)
{
unsigned u, v;
struct token *t;
t = tl->t;
u = UintVal(tl);
if (u < 256) {
v = u << 24;
Expect(tl, '.');
vcc_NextToken(tl);
t = tl->t;
u = UintVal(tl);
if (u < 256) {
v |= u << 16;
Expect(tl, '.');
vcc_NextToken(tl);
t = tl->t;
u = UintVal(tl);
if (u < 256) {
v |= u << 8;
Expect(tl, '.');
vcc_NextToken(tl);
t = tl->t;
u = UintVal(tl);
if (u < 256) {
v |= u;
return (v);
}
}
}
}
sbuf_printf(tl->sb, "Illegal octet in IP number\n");
vcc_ErrWhere(tl, t);
return (0);
}
/*--------------------------------------------------------------------*/
static struct var *
HeaderVar(struct tokenlist *tl __unused, struct token *t, struct var *vh)
{
......@@ -493,38 +446,6 @@ RateVal(struct tokenlist *tl)
/*--------------------------------------------------------------------*/
static void
Cond_Ip(struct var *vp, struct tokenlist *tl)
{
unsigned u;
switch (tl->t->tok) {
case '~':
vcc_NextToken(tl);
ExpectErr(tl, ID);
AddRef(tl, tl->t, R_ACL);
Fc(tl, 1, "ip_match(%s, acl_%T)\n", vp->rname, tl->t);
vcc_NextToken(tl);
break;
case T_EQ:
case T_NEQ:
Fc(tl, 1, "%s %T ", vp->rname, tl->t);
vcc_NextToken(tl);
u = IpVal(tl);
Fc(tl, 0, "%uU /* %u.%u.%u.%u */\n", u,
(u >> 24) & 0xff, (u >> 16) & 0xff,
(u >> 8) & 0xff, (u) & 0xff);
break;
default:
sbuf_printf(tl->sb, "Illegal condition ");
vcc_ErrToken(tl, tl->t);
sbuf_printf(tl->sb, " on IP number variable\n");
sbuf_printf(tl->sb, " only '==', '!=' and '~' are legal\n");
vcc_ErrWhere(tl, tl->t);
break;
}
}
static void
Cond_String(struct var *vp, struct tokenlist *tl)
{
......@@ -631,7 +552,7 @@ Cond_2(struct tokenlist *tl)
case INT: L(tl, Cond_Int(vp, tl)); break;
case SIZE: L(tl, Cond_Int(vp, tl)); break;
case BOOL: L(tl, Cond_Bool(vp, tl)); break;
case IP: L(tl, Cond_Ip(vp, tl)); break;
case IP: L(tl, vcc_Cond_Ip(vp, tl)); break;
case STRING: L(tl, Cond_String(vp, tl)); break;
case TIME: L(tl, Cond_Int(vp, tl)); break;
/* XXX backend == */
......@@ -742,7 +663,7 @@ IfStmt(struct tokenlist *tl)
static void
Action(struct tokenlist *tl)
{
unsigned a, u;
unsigned a;
struct var *vp;
struct token *at;
......@@ -825,10 +746,11 @@ Action(struct tokenlist *tl)
Fc(tl, 0, "%g", DoubleVal(tl));
Fc(tl, 0, ");\n");
break;
#if 0 /* XXX: enable if we find a legit use */
case IP:
if (tl->t->tok == '=') {
vcc_NextToken(tl);
u = IpVal(tl);
u = vcc_IpVal(tl);
Fc(tl, 0, "= %uU; /* %u.%u.%u.%u */\n",
u,
(u >> 24) & 0xff,
......@@ -843,6 +765,7 @@ Action(struct tokenlist *tl)
" only '=' is legal for IP numbers\n");
vcc_ErrWhere(tl, tl->t);
return;
#endif
case BACKEND:
if (tl->t->tok == '=') {
vcc_NextToken(tl);
......@@ -873,50 +796,6 @@ Action(struct tokenlist *tl)
/*--------------------------------------------------------------------*/
static void
Acl(struct tokenlist *tl)
{
unsigned u, m;
vcc_NextToken(tl);
ExpectErr(tl, ID);
AddDef(tl, tl->t, R_ACL);
Fh(tl, 0, "static struct vcl_acl acl_%T[];\n", tl->t);
Fc(tl, 1, "static struct vcl_acl acl_%T[] = {\n", tl->t);
vcc_NextToken(tl);
tl->indent += INDENT;
ExpectErr(tl, '{');
vcc_NextToken(tl);
while (tl->t->tok == CNUM) {
u = IpVal(tl);
if (tl->t->tok == '/') {
vcc_NextToken(tl);
ExpectErr(tl, CNUM);
m = UintVal(tl);
} else
m = 32;
ExpectErr(tl, ';');
vcc_NextToken(tl);
Fc(tl, 1, "{ %11uU, %3uU }, /* %u.%u.%u.%u/%u */\n",
u, m,
(u >> 24) & 0xff, (u >> 16) & 0xff,
(u >> 8) & 0xff, (u) & 0xff, m);
}
ExpectErr(tl, '}');
Fc(tl, 1, "{ %11uU, %3uU }\n", 0, 0);
tl->indent -= INDENT;
Fc(tl, 1, "};\n\n");
vcc_NextToken(tl);
}
/*--------------------------------------------------------------------*/
static void
Compound(struct tokenlist *tl)
{
......@@ -1099,7 +978,7 @@ Parse(struct tokenlist *tl)
ERRCHK(tl);
switch (tl->t->tok) {
case T_ACL:
Acl(tl);
vcc_Acl(tl);
break;
case T_SUB:
Function(tl);
......
......@@ -94,14 +94,26 @@ struct proc {
/*--------------------------------------------------------------------*/
/* vcc_acl.c */
void vcc_Acl(struct tokenlist *tl);
unsigned vcc_IpVal(struct tokenlist *tl);
void vcc_Cond_Ip(struct var *vp, struct tokenlist *tl);
/* vcc_compile.c */
extern const char *vcc_default_vcl_b, *vcc_default_vcl_e;
void Fh(struct tokenlist *tl, int indent, const char *fmt, ...);
void Fc(struct tokenlist *tl, int indent, const char *fmt, ...);
unsigned UintVal(struct tokenlist *tl);
void AddDef(struct tokenlist *tl, struct token *t, enum ref_type type);
void AddRef(struct tokenlist *tl, struct token *t, enum ref_type type);
/* vcc_obj.c */
extern struct var vcc_be_vars[];
extern struct var vcc_vars[];
extern const char *vrt_obj_h;
/* vcc_token.c */
void vcc_ErrToken(struct tokenlist *tl, struct token *t);
void vcc_ErrWhere(struct tokenlist *tl, struct token *t);
......@@ -112,3 +124,9 @@ void vcc_Lexer(struct tokenlist *tl, const char *b, const char *e);
void vcc_NextToken(struct tokenlist *tl);
void vcc__ErrInternal(struct tokenlist *tl, const char *func, unsigned line);
void vcc_AddToken(struct tokenlist *tl, unsigned tok, const char *b, const char *e);
#define ERRCHK(tl) do { if ((tl)->err) return; } while (0)
#define ErrInternal(tl) vcc__ErrInternal(tl, __func__, __LINE__)
#define Expect(a, b) vcc__Expect(a, b, __LINE__)
#define ExpectErr(a, b) do { vcc__Expect(a, b, __LINE__); ERRCHK(a);} while (0)
......@@ -12,6 +12,7 @@ set beobj {
# Objects which operate on sessions
set spobj {
{ client.ip IP }
{ req.request STRING }
{ req.url STRING }
{ req.proto STRING }
......@@ -22,6 +23,7 @@ set spobj {
{ req.http. HEADER }
}
set tt(IP) "const unsigned char *"
set tt(STRING) "const char *"
set tt(BOOL) "double"
set tt(BACKEND) "struct backend *"
......
......@@ -22,6 +22,10 @@ struct var vcc_be_vars[] = {
};
struct var vcc_vars[] = {
{ "client.ip", IP, 9,
"VRT_r_client_ip(sp)",
"VRT_l_client_ip(sp, ",
},
{ "req.request", STRING, 11,
"VRT_r_req_request(sp)",
"VRT_l_req_request(sp, ",
......@@ -70,6 +74,8 @@ const char *vrt_obj_h =
"void VRT_l_backend_host(struct backend *, const char *);\n"
"const char * VRT_r_backend_port(struct backend *);\n"
"void VRT_l_backend_port(struct backend *, const char *);\n"
"const unsigned char * VRT_r_client_ip(struct sess *);\n"
"void VRT_l_client_ip(struct sess *, const unsigned char *);\n"
"const char * VRT_r_req_request(struct sess *);\n"
"void VRT_l_req_request(struct sess *, const char *);\n"
"const char * VRT_r_req_url(struct sess *);\n"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment