Module Name:    src
Committed By:   snj
Date:           Fri Jul 17 04:37:22 UTC 2015

Modified Files:
        src/sys/net/npf [netbsd-7]: npf_if.c npf_mbuf.c
        src/usr.sbin/npf [netbsd-7]: npf.7
        src/usr.sbin/npf/npfctl [netbsd-7]: npf_var.c

Log Message:
Pull up following revision(s) (requested by rmind in ticket #880):
        sys/net/npf/npf_if.c: revision 1.5
        sys/net/npf/npf_mbuf.c: revision 1.14
        usr.sbin/npf/npf.7: revision 1.3
        usr.sbin/npf/npfctl/npf_var.c: revision 1.9
npfkern: eliminate INACTIVE_ID and use 0 for unregistered interfaces.
--
- npfvar_get_type1: check for NULL first.
- Minor fix for the npf(7) man page.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.4.2.1 src/sys/net/npf/npf_if.c
cvs rdiff -u -r1.13 -r1.13.2.1 src/sys/net/npf/npf_mbuf.c
cvs rdiff -u -r1.2 -r1.2.2.1 src/usr.sbin/npf/npf.7
cvs rdiff -u -r1.8 -r1.8.4.1 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/sys/net/npf/npf_if.c
diff -u src/sys/net/npf/npf_if.c:1.4 src/sys/net/npf/npf_if.c:1.4.2.1
--- src/sys/net/npf/npf_if.c:1.4	Sun Aug 10 19:09:43 2014
+++ src/sys/net/npf/npf_if.c	Fri Jul 17 04:37:22 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: npf_if.c,v 1.4 2014/08/10 19:09:43 rmind Exp $	*/
+/*	$NetBSD: npf_if.c,v 1.4.2.1 2015/07/17 04:37:22 snj Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -35,14 +35,17 @@
  * NPF uses its own interface IDs (npf-if-id).  When NPF configuration is
  * (re)loaded, each required interface name is registered and a matching
  * network interface gets an ID assigned.  If an interface is not present,
- * it gets an ID on attach.  Any other interfaces get INACTIVE_ID.
+ * it gets an ID on attach.
+ *
+ * IDs start from 1.  Zero is reserved to indicate "no interface" case or
+ * an interface of no interest (i.e. not registered).
  *
  * The IDs are mapped synchronously based on interface events which are
  * monitored using pfil(9) hooks.
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_if.c,v 1.4 2014/08/10 19:09:43 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_if.c,v 1.4.2.1 2015/07/17 04:37:22 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "pf.h"
@@ -59,8 +62,6 @@ __KERNEL_RCSID(0, "$NetBSD: npf_if.c,v 1
 
 #include "npf_impl.h"
 
-#define	INACTIVE_ID	((u_int)-1)
-
 typedef struct {
 	char		n_ifname[IFNAMSIZ];
 } npf_ifmap_t;
@@ -68,12 +69,6 @@ typedef struct {
 static npf_ifmap_t	npf_ifmap[NPF_MAX_IFMAP]	__read_mostly;
 static u_int		npf_ifmap_cnt			__read_mostly;
 
-/*
- * NOTE: IDs start from 1.  Zero is reserved for "no interface" and
- * (unsigned)-1 for "inactive interface".  Therefore, an interface
- * can have either INACTIVE_ID or non-zero ID.
- */
-
 static u_int
 npf_ifmap_new(void)
 {
@@ -85,7 +80,7 @@ npf_ifmap_new(void)
 
 	if (npf_ifmap_cnt == NPF_MAX_IFMAP) {
 		printf("npf_ifmap_new: out of slots; bump NPF_MAX_IFMAP\n");
-		return INACTIVE_ID;
+		return 0;
 	}
 	return ++npf_ifmap_cnt;
 }
@@ -101,7 +96,7 @@ npf_ifmap_lookup(const char *ifname)
 		if (nim->n_ifname[0] && strcmp(nim->n_ifname, ifname) == 0)
 			return i + 1;
 	}
-	return INACTIVE_ID;
+	return 0;
 }
 
 u_int
@@ -112,11 +107,10 @@ npf_ifmap_register(const char *ifname)
 	u_int i;
 
 	npf_config_enter();
-	if ((i = npf_ifmap_lookup(ifname)) != INACTIVE_ID) {
+	if ((i = npf_ifmap_lookup(ifname)) != 0) {
 		goto out;
 	}
-	if ((i = npf_ifmap_new()) == INACTIVE_ID) {
-		i = INACTIVE_ID;
+	if ((i = npf_ifmap_new()) == 0) {
 		goto out;
 	}
 	nim = &npf_ifmap[i - 1];
@@ -146,7 +140,7 @@ npf_ifmap_flush(void)
 
 	KERNEL_LOCK(1, NULL);
 	IFNET_FOREACH(ifp) {
-		ifp->if_pf_kif = (void *)(uintptr_t)INACTIVE_ID;
+		ifp->if_pf_kif = (void *)(uintptr_t)0;
 	}
 	KERNEL_UNLOCK_ONE(NULL);
 }
@@ -155,8 +149,7 @@ u_int
 npf_ifmap_getid(const ifnet_t *ifp)
 {
 	const u_int i = (uintptr_t)ifp->if_pf_kif;
-
-	KASSERT(i == INACTIVE_ID || (i > 0 && i <= npf_ifmap_cnt));
+	KASSERT(i <= npf_ifmap_cnt);
 	return i;
 }
 
@@ -184,7 +177,8 @@ npf_ifmap_attach(ifnet_t *ifp)
 void
 npf_ifmap_detach(ifnet_t *ifp)
 {
+	/* Diagnostic. */
 	npf_config_enter();
-	ifp->if_pf_kif = (void *)(uintptr_t)INACTIVE_ID; /* diagnostic */
+	ifp->if_pf_kif = (void *)(uintptr_t)0;
 	npf_config_exit();
 }

Index: src/sys/net/npf/npf_mbuf.c
diff -u src/sys/net/npf/npf_mbuf.c:1.13 src/sys/net/npf/npf_mbuf.c:1.13.2.1
--- src/sys/net/npf/npf_mbuf.c:1.13	Sun Aug 10 19:09:43 2014
+++ src/sys/net/npf/npf_mbuf.c	Fri Jul 17 04:37:22 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: npf_mbuf.c,v 1.13 2014/08/10 19:09:43 rmind Exp $	*/
+/*	$NetBSD: npf_mbuf.c,v 1.13.2.1 2015/07/17 04:37:22 snj Exp $	*/
 
 /*-
  * Copyright (c) 2009-2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_mbuf.c,v 1.13 2014/08/10 19:09:43 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_mbuf.c,v 1.13.2.1 2015/07/17 04:37:22 snj Exp $");
 
 #include <sys/param.h>
 #include <sys/mbuf.h>
@@ -57,7 +57,7 @@ nbuf_init(nbuf_t *nbuf, struct mbuf *m, 
 
 	nbuf->nb_mbuf0 = m;
 	nbuf->nb_ifp = ifp;
-	nbuf->nb_ifid =  ifid;
+	nbuf->nb_ifid = ifid;
 	nbuf_reset(nbuf);
 }
 

Index: src/usr.sbin/npf/npf.7
diff -u src/usr.sbin/npf/npf.7:1.2 src/usr.sbin/npf/npf.7:1.2.2.1
--- src/usr.sbin/npf/npf.7:1.2	Sun Aug 10 19:09:43 2014
+++ src/usr.sbin/npf/npf.7	Fri Jul 17 04:37:22 2015
@@ -1,4 +1,4 @@
-.\"	$NetBSD: npf.7,v 1.2 2014/08/10 19:09:43 rmind Exp $
+.\"	$NetBSD: npf.7,v 1.2.2.1 2015/07/17 04:37:22 snj Exp $
 .\"
 .\" Copyright (c) 2009-2014 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 August 2, 2014
+.Dd July 13, 2015
 .Dt NPF 7
 .Os
 .Sh NAME
@@ -69,7 +69,7 @@ Traffic normalization (extension).
 Packet logging (extension).
 .El
 .Pp
-For a full set features and their description, see the NPF
+For a full set of features and their description, see the NPF
 documentation and other manual pages.
 .\" -----
 .Sh SEE ALSO

Index: src/usr.sbin/npf/npfctl/npf_var.c
diff -u src/usr.sbin/npf/npfctl/npf_var.c:1.8 src/usr.sbin/npf/npfctl/npf_var.c:1.8.4.1
--- src/usr.sbin/npf/npfctl/npf_var.c:1.8	Tue Nov 19 00:28:41 2013
+++ src/usr.sbin/npf/npfctl/npf_var.c	Fri Jul 17 04:37:22 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: npf_var.c,v 1.8 2013/11/19 00:28:41 rmind Exp $	*/
+/*	$NetBSD: npf_var.c,v 1.8.4.1 2015/07/17 04:37:22 snj Exp $	*/
 
 /*-
  * Copyright (c) 2011-2012 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: npf_var.c,v 1.8 2013/11/19 00:28:41 rmind Exp $");
+__RCSID("$NetBSD: npf_var.c,v 1.8.4.1 2015/07/17 04:37:22 snj Exp $");
 
 #include <stdlib.h>
 #include <string.h>
@@ -239,14 +239,14 @@ npfvar_get_type1(const npfvar_t *vp, siz
 {
 	npf_element_t *el;
 
+	if (vp == NULL)
+		return -1;
+
 	if (level >= var_num) {
 		yyerror("variable loop for '%s'", vp->v_key);
 		return -1;
 	}
 
-	if (vp == NULL)
-		return -1;
-
 	if (vp->v_count <= idx) {
 		yyerror("variable '%s' has only %zu elements, requested %zu",
 		    vp->v_key, vp->v_count, idx);

Reply via email to