Source-Changes-HG archive

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

[src/trunk]: src/sys/net/npf NPF: fix the interface table initialisation on l...



details:   https://anonhg.NetBSD.org/src/rev/9d3ce64a86c7
branches:  trunk
changeset: 820202:9d3ce64a86c7
user:      rmind <rmind%NetBSD.org@localhost>
date:      Tue Jan 03 00:58:05 2017 +0000

description:
NPF: fix the interface table initialisation on load.

diffstat:

 sys/net/npf/npf_conf.c   |   9 ++++++---
 sys/net/npf/npf_ifaddr.c |  34 ++++++++++++++++++----------------
 sys/net/npf/npf_impl.h   |   4 ++--
 sys/net/npf/npf_os.c     |  11 ++++++++---
 4 files changed, 34 insertions(+), 24 deletions(-)

diffs (155 lines):

diff -r b481557983d8 -r 9d3ce64a86c7 sys/net/npf/npf_conf.c
--- a/sys/net/npf/npf_conf.c    Tue Jan 03 00:50:11 2017 +0000
+++ b/sys/net/npf/npf_conf.c    Tue Jan 03 00:58:05 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npf_conf.c,v 1.10 2016/12/26 23:05:06 christos Exp $   */
+/*     $NetBSD: npf_conf.c,v 1.11 2017/01/03 00:58:05 rmind Exp $      */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -49,7 +49,7 @@
 
 #ifdef _KERNEL
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_conf.c,v 1.10 2016/12/26 23:05:06 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_conf.c,v 1.11 2017/01/03 00:58:05 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -157,7 +157,7 @@
                npf_ifmap_flush(npf);
                npf_conn_load(npf, conns, !flush);
                mutex_exit(&npf->config_lock);
-               return;
+               goto done;
        }
 
        /*
@@ -183,6 +183,9 @@
 
        /* Finally, it is safe to destroy the old config. */
        npf_config_destroy(onc);
+done:
+       /* Sync all interface address tables (can be done asynchronously). */
+       npf_ifaddr_syncall(npf);
 }
 
 /*
diff -r b481557983d8 -r 9d3ce64a86c7 sys/net/npf/npf_ifaddr.c
--- a/sys/net/npf/npf_ifaddr.c  Tue Jan 03 00:50:11 2017 +0000
+++ b/sys/net/npf/npf_ifaddr.c  Tue Jan 03 00:58:05 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npf_ifaddr.c,v 1.1 2017/01/02 21:49:51 rmind Exp $     */
+/*     $NetBSD: npf_ifaddr.c,v 1.2 2017/01/03 00:58:05 rmind Exp $     */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_ifaddr.c,v 1.1 2017/01/02 21:49:51 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_ifaddr.c,v 1.2 2017/01/03 00:58:05 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -46,20 +46,6 @@
 
 #include "npf_impl.h"
 
-void
-npf_ifaddr_init(npf_t *npf)
-{
-       ifnet_t *ifp;
-
-       KERNEL_LOCK(1, NULL);
-       IFNET_LOCK();
-       IFNET_WRITER_FOREACH(ifp) {
-               npf_ifaddr_sync(npf, ifp);
-       }
-       IFNET_UNLOCK();
-       KERNEL_UNLOCK_ONE(NULL);
-}
-
 static npf_table_t *
 lookup_ifnet_table(npf_t *npf, ifnet_t *ifp)
 {
@@ -177,3 +163,19 @@
        }
        replace_ifnet_table(npf, t);
 }
+
+void
+npf_ifaddr_syncall(npf_t *npf)
+{
+       ifnet_t *ifp;
+
+       KERNEL_LOCK(1, NULL);
+       IFNET_LOCK();
+       IFNET_WRITER_FOREACH(ifp) {
+               npf_ifaddr_sync(npf, ifp);
+       }
+       IFNET_UNLOCK();
+       KERNEL_UNLOCK_ONE(NULL);
+}
+
+
diff -r b481557983d8 -r 9d3ce64a86c7 sys/net/npf/npf_impl.h
--- a/sys/net/npf/npf_impl.h    Tue Jan 03 00:50:11 2017 +0000
+++ b/sys/net/npf/npf_impl.h    Tue Jan 03 00:58:05 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npf_impl.h,v 1.66 2017/01/02 21:49:51 rmind Exp $      */
+/*     $NetBSD: npf_impl.h,v 1.67 2017/01/03 00:58:05 rmind Exp $      */
 
 /*-
  * Copyright (c) 2009-2014 The NetBSD Foundation, Inc.
@@ -247,9 +247,9 @@
 u_int          npf_ifmap_getid(npf_t *, const ifnet_t *);
 const char *   npf_ifmap_getname(npf_t *, const u_int);
 
-void           npf_ifaddr_init(npf_t *);
 void           npf_ifaddr_sync(npf_t *, ifnet_t *);
 void           npf_ifaddr_flush(npf_t *, ifnet_t *);
+void           npf_ifaddr_syncall(npf_t *);
 
 /* Packet filter hooks. */
 int            npf_pfil_register(bool);
diff -r b481557983d8 -r 9d3ce64a86c7 sys/net/npf/npf_os.c
--- a/sys/net/npf/npf_os.c      Tue Jan 03 00:50:11 2017 +0000
+++ b/sys/net/npf/npf_os.c      Tue Jan 03 00:58:05 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npf_os.c,v 1.4 2017/01/02 23:02:04 christos Exp $      */
+/*     $NetBSD: npf_os.c,v 1.5 2017/01/03 00:58:05 rmind Exp $ */
 
 /*-
  * Copyright (c) 2009-2016 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #ifdef _KERNEL
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_os.c,v 1.4 2017/01/02 23:02:04 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_os.c,v 1.5 2017/01/03 00:58:05 rmind Exp $");
 
 #ifdef _KERNEL_OPT
 #include "pf.h"
@@ -153,7 +153,6 @@
        npf = npf_create(0, NULL, &kern_ifops);
        npf_setkernctx(npf);
        npf_pfil_register(true);
-       npf_ifaddr_init(npf);
 
 #ifdef _MODULE
        devmajor_t bmajor = NODEVMAJOR, cmajor = NODEVMAJOR;
@@ -445,6 +444,12 @@
                    PFIL_ALL, npf_ph_inet6);
                KASSERT(error == 0);
        }
+
+       /*
+        * It is necessary to re-sync all/any interface address tables,
+        * since we did not listen for any changes.
+        */
+       npf_ifaddr_syncall(npf);
        pfil_registered = true;
 out:
        KERNEL_UNLOCK_ONE(NULL);



Home | Main Index | Thread Index | Old Index