Module Name: src
Committed By: christos
Date: Thu Jan 12 20:41:33 UTC 2012
Modified Files:
src/usr.sbin/npf/npfctl: npf_parse.y npf_var.c
Log Message:
handle variables that contain variables
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/npf/npfctl/npf_parse.y \
src/usr.sbin/npf/npfctl/npf_var.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.sbin/npf/npfctl/npf_parse.y
diff -u src/usr.sbin/npf/npfctl/npf_parse.y:1.1 src/usr.sbin/npf/npfctl/npf_parse.y:1.2
--- src/usr.sbin/npf/npfctl/npf_parse.y:1.1 Sun Jan 8 16:34:21 2012
+++ src/usr.sbin/npf/npfctl/npf_parse.y Thu Jan 12 15:41:33 2012
@@ -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 @@ iface
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 @@ ifindex
const int type = npfvar_get_type(vp);
switch (type) {
+ case NPFVAR_VAR_ID:
case NPFVAR_STRING:
$$ = npfctl_find_ifindex(npfvar_expand_string(vp));
break;
Index: src/usr.sbin/npf/npfctl/npf_var.c
diff -u src/usr.sbin/npf/npfctl/npf_var.c:1.1 src/usr.sbin/npf/npfctl/npf_var.c:1.2
--- src/usr.sbin/npf/npfctl/npf_var.c:1.1 Sun Jan 8 16:34:21 2012
+++ src/usr.sbin/npf/npfctl/npf_var.c Thu Jan 12 15:41:33 2012
@@ -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 @@ struct npfvar {
};
static npfvar_t * var_list = NULL;
+static size_t var_num = 0;
npfvar_t *
npfvar_create(const char *name)
@@ -86,6 +87,7 @@ npfvar_add(npfvar_t *vp)
{
vp->v_next = var_list;
var_list = vp;
+ var_num++;
}
npfvar_t *
@@ -185,11 +187,16 @@ npfvar_get_type(const npfvar_t *vp)
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 @@ npfvar_get_data(const npfvar_t *vp, int
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);
+}