r555 - in trunk/varnish-cache: include lib/libvcl

phk at projects.linpro.no phk at projects.linpro.no
Sat Jul 22 10:02:47 CEST 2006


Author: phk
Date: 2006-07-22 10:02:47 +0200 (Sat, 22 Jul 2006)
New Revision: 555

Added:
   trunk/varnish-cache/lib/libvcl/vcc_acl.c
Modified:
   trunk/varnish-cache/include/vrt_obj.h
   trunk/varnish-cache/lib/libvcl/Makefile.am
   trunk/varnish-cache/lib/libvcl/vcc_compile.c
   trunk/varnish-cache/lib/libvcl/vcc_compile.h
   trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl
   trunk/varnish-cache/lib/libvcl/vcc_obj.c
Log:
Split IP/ACL compilation into vcc_acl.c



Modified: trunk/varnish-cache/include/vrt_obj.h
===================================================================
--- trunk/varnish-cache/include/vrt_obj.h	2006-07-21 22:12:38 UTC (rev 554)
+++ trunk/varnish-cache/include/vrt_obj.h	2006-07-22 08:02:47 UTC (rev 555)
@@ -1,5 +1,5 @@
 /*
- * $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 @@
 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 *);

Modified: trunk/varnish-cache/lib/libvcl/Makefile.am
===================================================================
--- trunk/varnish-cache/lib/libvcl/Makefile.am	2006-07-21 22:12:38 UTC (rev 554)
+++ trunk/varnish-cache/lib/libvcl/Makefile.am	2006-07-22 08:02:47 UTC (rev 555)
@@ -9,6 +9,7 @@
 	vcc_compile.h \
 	vcc_token_defs.h \
 	\
+	vcc_acl.c \
 	vcc_compile.c \
 	vcc_fixed_token.c \
 	vcc_obj.c \

Added: trunk/varnish-cache/lib/libvcl/vcc_acl.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_acl.c	2006-07-21 22:12:38 UTC (rev 554)
+++ trunk/varnish-cache/lib/libvcl/vcc_acl.c	2006-07-22 08:02:47 UTC (rev 555)
@@ -0,0 +1,135 @@
+/*
+ * $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);
+}


Property changes on: trunk/varnish-cache/lib/libvcl/vcc_acl.c
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.c	2006-07-21 22:12:38 UTC (rev 554)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.c	2006-07-22 08:02:47 UTC (rev 555)
@@ -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 @@
 
 /*--------------------------------------------------------------------*/
 
-#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 @@
  * 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 @@
 	va_end(ap);
 }
 
-static void
+void
 Fc(struct tokenlist *tl, int indent, const char *fmt, ...)
 {
 	va_list ap;
@@ -210,7 +203,7 @@
 	return (0);
 }
 
-static void
+void
 AddRef(struct tokenlist *tl, struct token *t, enum ref_type type)
 {
 
@@ -230,7 +223,7 @@
 	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 @@
  * Recognize and convert { CNUM } to unsigned value
  */
 
-static unsigned
+unsigned
 UintVal(struct tokenlist *tl)
 {
 	unsigned d = 0;
@@ -367,46 +360,6 @@
 
 /*--------------------------------------------------------------------*/
 
-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)
 {
@@ -494,38 +447,6 @@
 /*--------------------------------------------------------------------*/
 
 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 @@
 		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 @@
 static void
 Action(struct tokenlist *tl)
 {
-	unsigned a, u;
+	unsigned a;
 	struct var *vp;
 	struct token *at;
 
@@ -825,10 +746,11 @@
 				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 @@
 			    " only '=' is legal for IP numbers\n");
 			vcc_ErrWhere(tl, tl->t);
 			return;
+#endif
 		case BACKEND:
 			if (tl->t->tok == '=') {
 				vcc_NextToken(tl);
@@ -874,50 +797,6 @@
 /*--------------------------------------------------------------------*/
 
 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 @@
 		ERRCHK(tl);
 		switch (tl->t->tok) {
 		case T_ACL:
-			Acl(tl);
+			vcc_Acl(tl);
 			break;
 		case T_SUB:
 			Function(tl);

Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.h	2006-07-21 22:12:38 UTC (rev 554)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.h	2006-07-22 08:02:47 UTC (rev 555)
@@ -94,14 +94,26 @@
 
 /*--------------------------------------------------------------------*/
 
+/* 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_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)
+

Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl	2006-07-21 22:12:38 UTC (rev 554)
+++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl	2006-07-22 08:02:47 UTC (rev 555)
@@ -12,6 +12,7 @@
 # Objects which operate on sessions
 
 set spobj {
+	{ client.ip	IP }
 	{ req.request	STRING }
         { req.url	STRING }
         { req.proto	STRING }
@@ -22,6 +23,7 @@
         { req.http.	HEADER }
 }
 
+set tt(IP)	"const unsigned char *"
 set tt(STRING)	"const char *"
 set tt(BOOL)	"double"
 set tt(BACKEND)	"struct backend *"

Modified: trunk/varnish-cache/lib/libvcl/vcc_obj.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_obj.c	2006-07-21 22:12:38 UTC (rev 554)
+++ trunk/varnish-cache/lib/libvcl/vcc_obj.c	2006-07-22 08:02:47 UTC (rev 555)
@@ -22,6 +22,10 @@
 };
 
 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 @@
 	"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"




More information about the varnish-commit mailing list