Module Name:    src
Committed By:   rmind
Date:           Mon Feb  3 02:21:52 UTC 2014

Modified Files:
        src/lib/libnpf: npf.3 npf.c npf.h
        src/usr.sbin/npf/npfctl: npf_build.c npf_data.c npfctl.h

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


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/lib/libnpf/npf.3
cvs rdiff -u -r1.24 -r1.25 src/lib/libnpf/npf.c
cvs rdiff -u -r1.21 -r1.22 src/lib/libnpf/npf.h
cvs rdiff -u -r1.31 -r1.32 src/usr.sbin/npf/npfctl/npf_build.c
cvs rdiff -u -r1.23 -r1.24 src/usr.sbin/npf/npfctl/npf_data.c
cvs rdiff -u -r1.34 -r1.35 src/usr.sbin/npf/npfctl/npfctl.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libnpf/npf.3
diff -u src/lib/libnpf/npf.3:1.14 src/lib/libnpf/npf.3:1.15
--- src/lib/libnpf/npf.3:1.14	Wed Jan  8 10:14:21 2014
+++ src/lib/libnpf/npf.3	Mon Feb  3 02:21:52 2014
@@ -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 @@ must be either
 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.

Index: src/lib/libnpf/npf.c
diff -u src/lib/libnpf/npf.c:1.24 src/lib/libnpf/npf.c:1.25
--- src/lib/libnpf/npf.c:1.24	Fri Nov 22 00:25:51 2013
+++ src/lib/libnpf/npf.c	Mon Feb  3 02:21:52 2014
@@ -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 @@ npf_table_add_entry(nl_table_t *tl, int 
 	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 @@ npf_table_insert(nl_config_t *ncf, nl_ta
 	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);

Index: src/lib/libnpf/npf.h
diff -u src/lib/libnpf/npf.h:1.21 src/lib/libnpf/npf.h:1.22
--- src/lib/libnpf/npf.h:1.21	Fri Nov 22 00:25:51 2013
+++ src/lib/libnpf/npf.h	Mon Feb  3 02:21:52 2014
@@ -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 @@ int		npf_nat_insert(nl_config_t *, nl_na
 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 *);
 

Index: src/usr.sbin/npf/npfctl/npf_build.c
diff -u src/usr.sbin/npf/npfctl/npf_build.c:1.31 src/usr.sbin/npf/npfctl/npf_build.c:1.32
--- src/usr.sbin/npf/npfctl/npf_build.c:1.31	Fri Nov 22 00:25:51 2013
+++ src/usr.sbin/npf/npfctl/npf_build.c	Mon Feb  3 02:21:52 2014
@@ -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 @@ npfctl_debug_addif(const char *ifname)
 	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 @@ npfctl_build_vars(npf_bpf_t *ctx, sa_fam
 			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;
 		}

Index: src/usr.sbin/npf/npfctl/npf_data.c
diff -u src/usr.sbin/npf/npfctl/npf_data.c:1.23 src/usr.sbin/npf/npfctl/npf_data.c:1.24
--- src/usr.sbin/npf/npfctl/npf_data.c:1.23	Fri Nov 22 00:25:51 2013
+++ src/usr.sbin/npf/npfctl/npf_data.c	Mon Feb  3 02:21:52 2014
@@ -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 @@ npfctl_parse_fam_addr_mask(const char *a
 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));
 }
 
 /*

Index: src/usr.sbin/npf/npfctl/npfctl.h
diff -u src/usr.sbin/npf/npfctl/npfctl.h:1.34 src/usr.sbin/npf/npfctl/npfctl.h:1.35
--- src/usr.sbin/npf/npfctl/npfctl.h:1.34	Fri Nov  8 00:38:26 2013
+++ src/usr.sbin/npf/npfctl/npfctl.h	Mon Feb  3 02:21:52 2014
@@ -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_parse_string(const char *);
 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 *);

Reply via email to