Module Name: src
Committed By: rmind
Date: Sun Jul 12 23:51:53 UTC 2015
Modified Files:
src/sys/net/npf: npf_if.c npf_mbuf.c
Log Message:
npfkern: eliminate INACTIVE_ID and use 0 for unregistered interfaces.
To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/net/npf/npf_if.c
cvs rdiff -u -r1.13 -r1.14 src/sys/net/npf/npf_mbuf.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.5
--- src/sys/net/npf/npf_if.c:1.4 Sun Aug 10 19:09:43 2014
+++ src/sys/net/npf/npf_if.c Sun Jul 12 23:51:53 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.5 2015/07/12 23:51:53 rmind 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.5 2015/07/12 23:51:53 rmind 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.14
--- src/sys/net/npf/npf_mbuf.c:1.13 Sun Aug 10 19:09:43 2014
+++ src/sys/net/npf/npf_mbuf.c Sun Jul 12 23:51:53 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.14 2015/07/12 23:51:53 rmind 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.14 2015/07/12 23:51:53 rmind 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);
}