handle variables that contain variables trunk
authorchristos <christos@NetBSD.org>
Thu, 12 Jan 2012 20:41:33 +0000
branchtrunk
changeset 208136 36585f0f4936
parent 208135 2803e6995290
child 208137 cfb0ee09123f
handle variables that contain variables
usr.sbin/npf/npfctl/npf_parse.y
usr.sbin/npf/npfctl/npf_var.c
--- a/usr.sbin/npf/npfctl/npf_parse.y	Thu Jan 12 19:49:37 2012 +0000
+++ b/usr.sbin/npf/npfctl/npf_parse.y	Thu Jan 12 20:41:33 2012 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: npf_parse.y,v 1.1 2012/01/08 21:34:21 rmind Exp $	*/
+/*	$NetBSD: npf_parse.y,v 1.2 2012/01/12 20:41:33 christos Exp $	*/
 
 /*-
  * Copyright (c) 2011-2012 The NetBSD Foundation, Inc.
@@ -661,6 +661,7 @@
 		const int type = npfvar_get_type(vp);
 
 		switch (type) {
+		case NPFVAR_VAR_ID:
 		case NPFVAR_STRING:
 			$$ = npfctl_parse_iface(npfvar_expand_string(vp));
 			break;
@@ -690,6 +691,7 @@
 		const int type = npfvar_get_type(vp);
 
 		switch (type) {
+		case NPFVAR_VAR_ID:
 		case NPFVAR_STRING:
 			$$ = npfctl_find_ifindex(npfvar_expand_string(vp));
 			break;
--- a/usr.sbin/npf/npfctl/npf_var.c	Thu Jan 12 19:49:37 2012 +0000
+++ b/usr.sbin/npf/npfctl/npf_var.c	Thu Jan 12 20:41:33 2012 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: npf_var.c,v 1.1 2012/01/08 21:34:21 rmind Exp $	*/
+/*	$NetBSD: npf_var.c,v 1.2 2012/01/12 20:41:33 christos Exp $	*/
 
 /*-
  * Copyright (c) 2011-2012 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: npf_var.c,v 1.1 2012/01/08 21:34:21 rmind Exp $");
+__RCSID("$NetBSD: npf_var.c,v 1.2 2012/01/12 20:41:33 christos Exp $");
 
 #include <stdlib.h>
 #include <string.h>
@@ -54,6 +54,7 @@
 };
 
 static npfvar_t *	var_list = NULL;
+static size_t		var_num = 0;
 
 npfvar_t *
 npfvar_create(const char *name)
@@ -86,6 +87,7 @@
 {
 	vp->v_next = var_list;
 	var_list = vp;
+	var_num++;
 }
 
 npfvar_t *
@@ -185,11 +187,16 @@
 	return vp ? vp->v_type : -1;
 }
 
-void *
-npfvar_get_data(const npfvar_t *vp, int type, size_t idx)
+static void *
+npfvar_get_data1(const npfvar_t *vp, int type, size_t idx, size_t level)
 {
 	npf_element_t *el;
 
+	if (level >= var_num) {
+		yyerror("variable loop for '%s'", vp->v_key);
+		return NULL;
+	}
+
 	if (vp == NULL)
 		return NULL;
 
@@ -209,5 +216,15 @@
 	while (idx--) {
 		el = el->e_next;
 	}
+
+	if (vp->v_type == NPFVAR_VAR_ID)
+		return npfvar_get_data1(npfvar_lookup(el->e_data), type, 0,
+			level + 1);
 	return el->e_data;
 }
+
+void *
+npfvar_get_data(const npfvar_t *vp, int type, size_t idx)
+{
+	return npfvar_get_data1(vp, type, idx, 0);
+}