Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/npf/npfctl handle variables that contain variables



details:   https://anonhg.NetBSD.org/src/rev/e9caaac7cb28
branches:  trunk
changeset: 772697:e9caaac7cb28
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Jan 12 20:41:33 2012 +0000

description:
handle variables that contain variables

diffstat:

 usr.sbin/npf/npfctl/npf_parse.y |   4 +++-
 usr.sbin/npf/npfctl/npf_var.c   |  25 +++++++++++++++++++++----
 2 files changed, 24 insertions(+), 5 deletions(-)

diffs (94 lines):

diff -r 41e3e1d220ca -r e9caaac7cb28 usr.sbin/npf/npfctl/npf_parse.y
--- 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;
diff -r 41e3e1d220ca -r e9caaac7cb28 usr.sbin/npf/npfctl/npf_var.c
--- 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);
+}



Home | Main Index | Thread Index | Old Index