[4.1] c4c5027 Introduce a new ACL type for VMODs

Lasse Karstensen lkarsten at varnish-software.com
Thu Feb 25 15:11:14 CET 2016


commit c4c5027418232c503afd4a3cf1e96327c008c007
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Tue Feb 23 16:39:24 2016 +0100

    Introduce a new ACL type for VMODs

diff --git a/include/vrt.h b/include/vrt.h
index ad43ef6..9a27305 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -50,6 +50,7 @@
 /***********************************************************************/
 
 struct VCL_conf;
+struct vrt_acl;
 struct busyobj;
 struct director;
 struct http;
@@ -67,6 +68,7 @@ struct ws;
  * (alphabetic order)
  */
 
+typedef const struct vrt_acl *			VCL_ACL;
 typedef const struct director *			VCL_BACKEND;
 typedef const struct vmod_priv *		VCL_BLOB;
 typedef unsigned				VCL_BOOL;
@@ -237,6 +239,14 @@ struct vrt_ref {
 /* ACL related */
 #define VRT_ACL_MAXADDR		16	/* max(IPv4, IPv6) */
 
+typedef int acl_f (VRT_CTX, VCL_IP);
+
+struct vrt_acl {
+	unsigned	magic;
+#define VRT_ACL_MAGIC	0x78329d96
+	acl_f		*match;
+};
+
 void VRT_acl_log(VRT_CTX, const char *msg);
 
 /* req related */
diff --git a/lib/libvcc/vcc_acl.c b/lib/libvcc/vcc_acl.c
index 78d9ec5..98f24d8 100644
--- a/lib/libvcc/vcc_acl.c
+++ b/lib/libvcc/vcc_acl.c
@@ -351,7 +351,7 @@ vcc_acl_emit(struct vcc *tl, const char *acln, int anon)
 	struct token *t;
 	struct inifin *ifp;
 
-	Fh(tl, 0, "\nstatic int\n");
+	Fh(tl, 0, "\nstatic int __match_proto__(acl_f)\n");
 	Fh(tl, 0,
 	    "match_acl_%s_%s(VRT_CTX, const VCL_IP p)\n",
 	    anon ? "anon" : "named", acln);
@@ -443,6 +443,15 @@ vcc_acl_emit(struct vcc *tl, const char *acln, int anon)
 	if (!anon)
 		Fh(tl, 0, "\tVRT_acl_log(ctx, \"NO_MATCH %s\");\n", acln);
 	Fh(tl, 0, "\treturn (0);\n}\n");
+
+	if (anon)
+		return;
+
+	/* Emit the struct that will be referenced */
+	Fh(tl, 0, "\nconst struct vrt_acl vrt_acl_named_%s = {\n", acln);
+	Fh(tl, 0, "\t.magic = VRT_ACL_MAGIC,\n");
+	Fh(tl, 0, "\t.match = &match_acl_named_%s,\n", acln);
+	Fh(tl, 0, "};\n\n");
 }
 
 void



More information about the varnish-commit mailing list