Source-Changes-HG archive

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

[src/trunk]: src Modularize the ppp driver, and adjust dependencies of the co...



details:   https://anonhg.NetBSD.org/src/rev/7ab1bb3e1e6b
branches:  trunk
changeset: 817040:7ab1bb3e1e6b
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Sat Aug 06 02:35:05 2016 +0000

description:
Modularize the ppp driver, and adjust dependencies of the compressor
modules.

For now, this is still included as a built-in module in GENERIC kernels.

diffstat:

 distrib/sets/lists/modules/mi |    4 +-
 sys/modules/Makefile          |    3 +-
 sys/modules/ppp/Makefile      |   16 +++++
 sys/modules/ppp/ppp.ioconf    |    7 ++
 sys/net/bsd-comp.c            |    6 +-
 sys/net/if_ppp.c              |  118 ++++++++++++++++++++++++++++++++++++++---
 sys/net/ppp-deflate.c         |    6 +-
 sys/net/ppp_tty.c             |    7 +-
 8 files changed, 146 insertions(+), 21 deletions(-)

diffs (truncated from 334 to 300 lines):

diff -r 568a94ebab38 -r 7ab1bb3e1e6b distrib/sets/lists/modules/mi
--- a/distrib/sets/lists/modules/mi     Sat Aug 06 00:58:55 2016 +0000
+++ b/distrib/sets/lists/modules/mi     Sat Aug 06 02:35:05 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.87 2016/08/04 23:54:45 pgoyette Exp $
+# $NetBSD: mi,v 1.88 2016/08/06 02:35:05 pgoyette Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -198,6 +198,8 @@
 ./@MODULEDIR@/pf/pf.kmod                       base-kernel-modules     kmod
 ./@MODULEDIR@/portal                           base-obsolete           obsolete
 ./@MODULEDIR@/portal/portal.kmod               base-obsolete           obsolete
+./@MODULEDIR@/ppp                              base-kernel-modules     kmod
+./@MODULEDIR@/ppp/ppp.kmod                     base-kernel-modules     kmod
 ./@MODULEDIR@/ppp_bsdcomp                      base-kernel-modules     kmod
 ./@MODULEDIR@/ppp_bsdcomp/ppp_bsdcomp.kmod     base-kernel-modules     kmod
 ./@MODULEDIR@/ppp_deflate                      base-kernel-modules     kmod
diff -r 568a94ebab38 -r 7ab1bb3e1e6b sys/modules/Makefile
--- a/sys/modules/Makefile      Sat Aug 06 00:58:55 2016 +0000
+++ b/sys/modules/Makefile      Sat Aug 06 02:35:05 2016 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.169 2016/08/05 17:12:13 scole Exp $
+#      $NetBSD: Makefile,v 1.170 2016/08/06 02:35:05 pgoyette Exp $
 
 .include <bsd.own.mk>
 
@@ -79,6 +79,7 @@
 SUBDIR+=       overlay
 SUBDIR+=       pciverbose
 SUBDIR+=       pf
+SUBDIR+=       ppp
 SUBDIR+=       ppp_bsdcomp
 SUBDIR+=       ppp_deflate
 SUBDIR+=       procfs
diff -r 568a94ebab38 -r 7ab1bb3e1e6b sys/modules/ppp/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/modules/ppp/Makefile  Sat Aug 06 02:35:05 2016 +0000
@@ -0,0 +1,16 @@
+# $NetBSD: Makefile,v 1.1 2016/08/06 02:35:05 pgoyette Exp $
+
+.include "../Makefile.inc"
+
+.PATH:  ${S}/net
+
+KMOD=          ppp
+IOCONF=                ppp.ioconf
+SRCS=          if_ppp.c ppp_tty.c
+
+CPPFLAGS+=     -DINET
+CPPFLAGS+=     -DPPP_FILTER
+CPPFLAGS+=     -DPPP_DEFLATE
+CPPFLAGS+=     -DPPP_BSDCOMP
+
+.include <bsd.kmodule.mk>
diff -r 568a94ebab38 -r 7ab1bb3e1e6b sys/modules/ppp/ppp.ioconf
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/modules/ppp/ppp.ioconf        Sat Aug 06 02:35:05 2016 +0000
@@ -0,0 +1,7 @@
+#      $NetBSD: ppp.ioconf,v 1.1 2016/08/06 02:35:05 pgoyette Exp $
+
+ioconf         ppp
+
+include                "conf/files"
+
+pseudo-device   ppp
diff -r 568a94ebab38 -r 7ab1bb3e1e6b sys/net/bsd-comp.c
--- a/sys/net/bsd-comp.c        Sat Aug 06 00:58:55 2016 +0000
+++ b/sys/net/bsd-comp.c        Sat Aug 06 02:35:05 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bsd-comp.c,v 1.20 2008/11/29 23:15:20 cube Exp $       */
+/*     $NetBSD: bsd-comp.c,v 1.21 2016/08/06 02:35:06 pgoyette Exp $   */
 /*     Id: bsd-comp.c,v 1.6 1996/08/28 06:31:58 paulus Exp     */
 
 /* Because this code is derived from the 4.3BSD compress source:
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bsd-comp.c,v 1.20 2008/11/29 23:15:20 cube Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bsd-comp.c,v 1.21 2016/08/06 02:35:06 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1090,7 +1090,7 @@
 #endif /* DEBUG */
 }
 
-MODULE(MODULE_CLASS_MISC, ppp_bsdcomp, NULL);
+MODULE(MODULE_CLASS_MISC, ppp_bsdcomp, "ppp");
 
 static int
 ppp_bsdcomp_modcmd(modcmd_t cmd, void *arg)
diff -r 568a94ebab38 -r 7ab1bb3e1e6b sys/net/if_ppp.c
--- a/sys/net/if_ppp.c  Sat Aug 06 00:58:55 2016 +0000
+++ b/sys/net/if_ppp.c  Sat Aug 06 02:35:05 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ppp.c,v 1.152 2016/06/10 13:27:16 ozaki-r Exp $     */
+/*     $NetBSD: if_ppp.c,v 1.153 2016/08/06 02:35:06 pgoyette Exp $    */
 /*     Id: if_ppp.c,v 1.6 1997/03/04 03:33:00 paulus Exp       */
 
 /*
@@ -102,11 +102,10 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ppp.c,v 1.152 2016/06/10 13:27:16 ozaki-r Exp $");
-
-#include "ppp.h"
+__KERNEL_RCSID(0, "$NetBSD: if_ppp.c,v 1.153 2016/08/06 02:35:06 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
+#include "ppp.h"
 #include "opt_inet.h"
 #include "opt_gateway.h"
 #include "opt_ppp.h"
@@ -133,6 +132,8 @@
 #include <sys/kauth.h>
 #include <sys/intr.h>
 #include <sys/socketvar.h>
+#include <sys/device.h>
+#include <sys/module.h>
 
 #include <net/if.h>
 #include <net/if_types.h>
@@ -181,6 +182,8 @@
 
 static void    pppintr(void *);
 
+extern struct linesw ppp_disc;
+
 /*
  * Some useful mbuf macros not in mbuf.h.
  */
@@ -214,11 +217,11 @@
     IF_CLONE_INITIALIZER("ppp", ppp_clone_create, ppp_clone_destroy);
 
 #ifdef PPP_COMPRESS
-ONCE_DECL(ppp_compressor_mtx_init);
 static LIST_HEAD(, compressor) ppp_compressors = { NULL };
 static kmutex_t ppp_compressors_mtx;
 
 static int ppp_compressor_init(void);
+static int ppp_compressor_destroy(void);
 static struct compressor *ppp_get_compressor(uint8_t);
 static void ppp_compressor_rele(struct compressor *);
 #endif /* PPP_COMPRESS */
@@ -230,7 +233,16 @@
 void
 pppattach(int n __unused)
 {
-       extern struct linesw ppp_disc;
+
+       /*
+        * Nothing to do here, initialization is handled by the
+        * module initialization code in pppinit() below).
+        */
+}
+
+static void
+pppinit(void)
+{
 
        if (ttyldisc_attach(&ppp_disc) != 0)
                panic("pppattach");
@@ -238,7 +250,18 @@
        mutex_init(&ppp_list_lock, MUTEX_DEFAULT, IPL_NONE);
        LIST_INIT(&ppp_softc_list);
        if_clone_attach(&ppp_cloner);
-       RUN_ONCE(&ppp_compressor_mtx_init, ppp_compressor_init);
+}
+
+static int
+pppdetach(void)
+{
+       int error;
+
+       if (!LIST_EMPTY(&ppp_softc_list))
+               error = EBUSY;
+       if (error == 0)
+               error = ttyldisc_detach(&ppp_disc);
+       return error;
 }
 
 static struct ppp_softc *
@@ -1798,6 +1821,14 @@
        return 0;
 }
 
+static int
+ppp_compressor_destroy(void)
+{
+
+       mutex_destroy(&ppp_compressors_mtx);
+       return 0;
+}
+
 static void
 ppp_compressor_rele(struct compressor *cp)
 {
@@ -1865,8 +1896,6 @@
        int error = 0;
        size_t i;
 
-       RUN_ONCE(&ppp_compressor_mtx_init, ppp_compressor_init);
-
        mutex_enter(&ppp_compressors_mtx);
        for (i = 0; i < ncomp; i++) {
                if (ppp_get_compressor_noload(pc[i].compress_proto,
@@ -1907,3 +1936,74 @@
 
        return error;
 }
+
+/*
+ * Module infrastructure
+ */
+
+#ifdef PPP_FILTER
+#define PPP_DEP "bpf_filter,"
+#else
+#define PPP_DEP
+#endif
+
+MODULE(MODULE_CLASS_DRIVER, ppp, PPP_DEP "slcompress");
+
+#ifdef _MODULE
+CFDRIVER_DECL(ppp, DV_IFNET, NULL);
+#endif
+
+static int
+ppp_modcmd(modcmd_t cmd, void *arg)
+{
+       int error = 0;
+
+       switch (cmd) {
+       case MODULE_CMD_INIT:
+               /* Init the compressor sub-sub-system */
+               ppp_compressor_init();
+
+#ifdef _MODULE
+               error = config_cfdriver_attach(&ppp_cd);
+               if (error) {
+                       aprint_error("%s: unable to register cfdriver for"
+                           "%s, error %d\n", __func__, ppp_cd.cd_name, error);
+                       ppp_compressor_destroy();
+                       break;
+               }
+
+#endif
+               /* Init the unit list and line discipline stuff */
+               pppinit();
+               break;
+
+       case MODULE_CMD_FINI:
+               /*
+                * Make sure it's ok to detach - no units left, and
+                * line discipline is removed
+                */
+               error = pppdetach();
+               if (error != 0)
+                       break;
+#ifdef _MODULE
+               /* Remove device from autoconf database */
+               error = config_cfdriver_detach(&ppp_cd);
+               if (error) {
+                       aprint_error("%s: failed to detach %s cfdriver, "
+                           "error %d\n", __func__, ppp_cd.cd_name, error);
+                       break;
+               }
+#endif
+               ppp_compressor_destroy();
+               break;
+
+       case MODULE_CMD_STAT:
+               error = ENOTTY;
+               break;
+       default:
+               error = ENOTTY;
+               break;
+       }
+
+       return error;
+}
diff -r 568a94ebab38 -r 7ab1bb3e1e6b sys/net/ppp-deflate.c
--- a/sys/net/ppp-deflate.c     Sat Aug 06 00:58:55 2016 +0000
+++ b/sys/net/ppp-deflate.c     Sat Aug 06 02:35:05 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ppp-deflate.c,v 1.21 2016/04/05 23:44:05 pgoyette Exp $        */
+/*     $NetBSD: ppp-deflate.c,v 1.22 2016/08/06 02:35:06 pgoyette Exp $        */
 /*     Id: ppp-deflate.c,v 1.5 1997/03/04 03:33:28 paulus Exp  */
 
 /*
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ppp-deflate.c,v 1.21 2016/04/05 23:44:05 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ppp-deflate.c,v 1.22 2016/08/06 02:35:06 pgoyette Exp $");
 



Home | Main Index | Thread Index | Old Index