Source-Changes-HG archive

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

[src/trunk]: src/sys/net/npf npfkern: eliminate INACTIVE_ID and use 0 for unr...



details:   https://anonhg.NetBSD.org/src/rev/1ff11cf6f0e0
branches:  trunk
changeset: 339326:1ff11cf6f0e0
user:      rmind <rmind%NetBSD.org@localhost>
date:      Sun Jul 12 23:51:53 2015 +0000

description:
npfkern: eliminate INACTIVE_ID and use 0 for unregistered interfaces.

diffstat:

 sys/net/npf/npf_if.c   |  34 ++++++++++++++--------------------
 sys/net/npf/npf_mbuf.c |   6 +++---
 2 files changed, 17 insertions(+), 23 deletions(-)

diffs (139 lines):

diff -r a34800a6b650 -r 1ff11cf6f0e0 sys/net/npf/npf_if.c
--- a/sys/net/npf/npf_if.c      Sun Jul 12 14:06:52 2015 +0000
+++ b/sys/net/npf/npf_if.c      Sun Jul 12 23:51:53 2015 +0000
@@ -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 @@
 
 #include "npf_impl.h"
 
-#define        INACTIVE_ID     ((u_int)-1)
-
 typedef struct {
        char            n_ifname[IFNAMSIZ];
 } npf_ifmap_t;
@@ -68,12 +69,6 @@
 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 @@
 
        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 @@
                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 @@
        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 @@
 
        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 @@
 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 @@
 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();
 }
diff -r a34800a6b650 -r 1ff11cf6f0e0 sys/net/npf/npf_mbuf.c
--- a/sys/net/npf/npf_mbuf.c    Sun Jul 12 14:06:52 2015 +0000
+++ b/sys/net/npf/npf_mbuf.c    Sun Jul 12 23:51:53 2015 +0000
@@ -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->nb_mbuf0 = m;
        nbuf->nb_ifp = ifp;
-       nbuf->nb_ifid =  ifid;
+       nbuf->nb_ifid = ifid;
        nbuf_reset(nbuf);
 }
 



Home | Main Index | Thread Index | Old Index