Source-Changes-HG archive

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

[src/trunk]: src - npfctl: fix table IDs (breakage since the table naming was...



details:   https://anonhg.NetBSD.org/src/rev/5c8bbd5a347f
branches:  trunk
changeset: 326563:5c8bbd5a347f
user:      rmind <rmind%NetBSD.org@localhost>
date:      Mon Feb 03 02:21:52 2014 +0000

description:
- npfctl: fix table IDs (breakage since the table naming was added).
- libnpf: remove npf_table_exists_p() from public API.

diffstat:

 lib/libnpf/npf.3                |  16 ++--------------
 lib/libnpf/npf.c                |  10 +++++-----
 lib/libnpf/npf.h                |   3 +--
 usr.sbin/npf/npfctl/npf_build.c |  28 ++++++++++++++++++++++------
 usr.sbin/npf/npfctl/npf_data.c  |  11 +++++++----
 usr.sbin/npf/npfctl/npfctl.h    |   4 ++--
 6 files changed, 39 insertions(+), 33 deletions(-)

diffs (209 lines):

diff -r add9c507d919 -r 5c8bbd5a347f lib/libnpf/npf.3
--- a/lib/libnpf/npf.3  Sun Feb 02 23:17:54 2014 +0000
+++ b/lib/libnpf/npf.3  Mon Feb 03 02:21:52 2014 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: npf.3,v 1.14 2014/01/08 10:14:21 njoly Exp $
+.\"    $NetBSD: npf.3,v 1.15 2014/02/03 02:21:52 rmind Exp $
 .\"
 .\" Copyright (c) 2011-2013 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd November 12, 2013
+.Dd February 2, 2014
 .Dt NPF 3
 .Os
 .Sh NAME
@@ -82,8 +82,6 @@
 .Ft int
 .Fn npf_table_add_entry "nl_table_t *tl" "int af" \
 "in_addr_t addr" "in_addr_t mask"
-.Ft bool
-.Fn npf_table_exists_p "nl_config_t *ncf" "u_int tid"
 .Ft int
 .Fn npf_table_insert "nl_config_t *ncf" "nl_table_t *tl"
 .Ft void
@@ -290,16 +288,6 @@
 for IPv4 or
 .Dv AF_INET6
 for IPv6 address.
-.It Fn npf_table_exists_p "ncf" "name"
-Determine whether table with ID
-.Fa tid
-exists in the configuration
-.Fa ncf .
-Return
-.Dv true
-if exists, and
-.Dv false
-otherwise.
 .It Fn npf_table_insert "ncf" "tl"
 Insert table into set of configuration.
 Routine performs a check for duplicate table ID.
diff -r add9c507d919 -r 5c8bbd5a347f lib/libnpf/npf.c
--- a/lib/libnpf/npf.c  Sun Feb 02 23:17:54 2014 +0000
+++ b/lib/libnpf/npf.c  Mon Feb 03 02:21:52 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npf.c,v 1.24 2013/11/22 00:25:51 rmind Exp $   */
+/*     $NetBSD: npf.c,v 1.25 2014/02/03 02:21:52 rmind Exp $   */
 
 /*-
  * Copyright (c) 2010-2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf.c,v 1.24 2013/11/22 00:25:51 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf.c,v 1.25 2014/02/03 02:21:52 rmind Exp $");
 
 #include <sys/types.h>
 #include <netinet/in_systm.h>
@@ -961,8 +961,8 @@
        return 0;
 }
 
-bool
-npf_table_exists_p(nl_config_t *ncf, const char *name)
+static bool
+_npf_table_exists_p(nl_config_t *ncf, const char *name)
 {
        prop_dictionary_t tldict;
        prop_object_iterator_t it;
@@ -988,7 +988,7 @@
        if (!prop_dictionary_get_cstring_nocopy(tldict, "name", &name)) {
                return EINVAL;
        }
-       if (npf_table_exists_p(ncf, name)) {
+       if (_npf_table_exists_p(ncf, name)) {
                return EEXIST;
        }
        prop_array_add(ncf->ncf_table_list, tldict);
diff -r add9c507d919 -r 5c8bbd5a347f lib/libnpf/npf.h
--- a/lib/libnpf/npf.h  Sun Feb 02 23:17:54 2014 +0000
+++ b/lib/libnpf/npf.h  Mon Feb 03 02:21:52 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npf.h,v 1.21 2013/11/22 00:25:51 rmind Exp $   */
+/*     $NetBSD: npf.h,v 1.22 2014/02/03 02:21:52 rmind Exp $   */
 
 /*-
  * Copyright (c) 2011-2013 The NetBSD Foundation, Inc.
@@ -111,7 +111,6 @@
 nl_table_t *   npf_table_create(const char *, u_int, int);
 int            npf_table_add_entry(nl_table_t *, int,
                    const npf_addr_t *, const npf_netmask_t);
-bool           npf_table_exists_p(nl_config_t *, const char *);
 int            npf_table_insert(nl_config_t *, nl_table_t *);
 void           npf_table_destroy(nl_table_t *);
 
diff -r add9c507d919 -r 5c8bbd5a347f usr.sbin/npf/npfctl/npf_build.c
--- a/usr.sbin/npf/npfctl/npf_build.c   Sun Feb 02 23:17:54 2014 +0000
+++ b/usr.sbin/npf/npfctl/npf_build.c   Mon Feb 03 02:21:52 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npf_build.c,v 1.31 2013/11/22 00:25:51 rmind Exp $     */
+/*     $NetBSD: npf_build.c,v 1.32 2014/02/03 02:21:52 rmind Exp $     */
 
 /*-
  * Copyright (c) 2011-2013 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: npf_build.c,v 1.31 2013/11/22 00:25:51 rmind Exp $");
+__RCSID("$NetBSD: npf_build.c,v 1.32 2014/02/03 02:21:52 rmind Exp $");
 
 #include <sys/types.h>
 #include <sys/ioctl.h>
@@ -123,10 +123,25 @@
        return 0;
 }
 
-bool
-npfctl_table_exists_p(const char *name)
+unsigned
+npfctl_table_getid(const char *name)
 {
-       return npf_conf ? npf_table_exists_p(npf_conf, name) : false;
+       unsigned tid = (unsigned)-1;
+       nl_table_t *tl;
+
+       /* XXX dynamic ruleset */
+       if (!npf_conf) {
+               return (unsigned)-1;
+       }
+
+       /* XXX: Iterating all as we need to rewind for the next call. */
+       while ((tl = npf_table_iterate(npf_conf)) != NULL) {
+               const char *tname = npf_table_getname(tl);
+               if (strcmp(tname, name) == 0) {
+                       tid = npf_table_getid(tl);
+               }
+       }
+       return tid;
 }
 
 static in_port_t
@@ -217,7 +232,8 @@
                        break;
                }
                case NPFVAR_TABLE: {
-                       u_int tid = atoi(data);
+                       u_int tid;
+                       memcpy(&tid, data, sizeof(u_int));
                        npfctl_bpf_table(ctx, opts, tid);
                        break;
                }
diff -r add9c507d919 -r 5c8bbd5a347f usr.sbin/npf/npfctl/npf_data.c
--- a/usr.sbin/npf/npfctl/npf_data.c    Sun Feb 02 23:17:54 2014 +0000
+++ b/usr.sbin/npf/npfctl/npf_data.c    Mon Feb 03 02:21:52 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npf_data.c,v 1.23 2013/11/22 00:25:51 rmind Exp $      */
+/*     $NetBSD: npf_data.c,v 1.24 2014/02/03 02:21:52 rmind Exp $      */
 
 /*-
  * Copyright (c) 2009-2012 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: npf_data.c,v 1.23 2013/11/22 00:25:51 rmind Exp $");
+__RCSID("$NetBSD: npf_data.c,v 1.24 2014/02/03 02:21:52 rmind Exp $");
 
 #include <sys/types.h>
 #include <sys/null.h>
@@ -223,11 +223,14 @@
 npfvar_t *
 npfctl_parse_table_id(const char *name)
 {
-       if (!npfctl_table_exists_p(name)) {
+       u_int tid;
+
+       tid = npfctl_table_getid(name);
+       if (tid == (unsigned)-1) {
                yyerror("table '%s' is not defined", name);
                return NULL;
        }
-       return npfvar_create_from_string(NPFVAR_TABLE, name);
+       return npfvar_create_element(NPFVAR_TABLE, &tid, sizeof(u_int));
 }
 
 /*
diff -r add9c507d919 -r 5c8bbd5a347f usr.sbin/npf/npfctl/npfctl.h
--- a/usr.sbin/npf/npfctl/npfctl.h      Sun Feb 02 23:17:54 2014 +0000
+++ b/usr.sbin/npf/npfctl/npfctl.h      Mon Feb 03 02:21:52 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npfctl.h,v 1.34 2013/11/08 00:38:26 rmind Exp $        */
+/*     $NetBSD: npfctl.h,v 1.35 2014/02/03 02:21:52 rmind Exp $        */
 
 /*-
  * Copyright (c) 2009-2013 The NetBSD Foundation, Inc.
@@ -112,7 +112,7 @@
 void           npfctl_print_error(const nl_error_t *);
 char *         npfctl_print_addrmask(int, const npf_addr_t *, npf_netmask_t);
 void           npfctl_note_interface(const char *);
-bool           npfctl_table_exists_p(const char *);
+unsigned       npfctl_table_getid(const char *);
 int            npfctl_protono(const char *);
 in_port_t      npfctl_portno(const char *);
 uint8_t                npfctl_icmpcode(int, uint8_t, const char *);



Home | Main Index | Thread Index | Old Index