diff --git a/sys/net/npf/npf.c b/sys/net/npf/npf.c index 58da0255701e..28fc6baf73fc 100644 --- a/sys/net/npf/npf.c +++ b/sys/net/npf/npf.c @@ -1,4 +1,4 @@ -/* $NetBSD: npf.c,v 1.26 2015/10/18 20:39:53 jmcneill Exp $ */ +/* $NetBSD: npf.c,v 1.27 2015/10/19 00:29:57 christos Exp $ */ /*- * Copyright (c) 2009-2013 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: npf.c,v 1.26 2015/10/18 20:39:53 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: npf.c,v 1.27 2015/10/19 00:29:57 christos Exp $"); #include #include @@ -54,12 +54,26 @@ __KERNEL_RCSID(0, "$NetBSD: npf.c,v 1.26 2015/10/18 20:39:53 jmcneill Exp $"); #include "npf_impl.h" #include "npf_conn.h" +#ifndef _MODULE +#include "opt_modular.h" +#endif + #include "ioconf.h" /* * Module and device structures. */ +#ifdef MODULAR +/* + * Modular kernels load drivers too early, and we need percpu to be inited + * So we make this misc; a better way would be to have early boot and late + * boot drivers + */ +MODULE(MODULE_CLASS_MISC, npf, NULL); +#else +/* This module autoloads via /dev/npf so it needs to be a driver */ MODULE(MODULE_CLASS_DRIVER, npf, NULL); +#endif static int npf_fini(void); static int npf_dev_open(dev_t, int, int, lwp_t *); @@ -91,10 +105,7 @@ const struct cdevsw npf_cdevsw = { static int npf_init(void) { -#ifdef _MODULE - devmajor_t bmajor = NODEVMAJOR, cmajor = NODEVMAJOR; -#endif - int error = 0; + KASSERT(npf_stats_percpu == NULL); npf_stats_percpu = percpu_alloc(NPF_STATS_SIZE); npf_sysctl = NULL; @@ -112,14 +123,18 @@ npf_init(void) npf_config_init(); #ifdef _MODULE + devmajor_t bmajor = NODEVMAJOR, cmajor = NODEVMAJOR; + /* Attach /dev/npf device. */ - error = devsw_attach("npf", NULL, &bmajor, &npf_cdevsw, &cmajor); + int error = devsw_attach("npf", NULL, &bmajor, &npf_cdevsw, &cmajor); if (error) { /* It will call devsw_detach(), which is safe. */ (void)npf_fini(); } -#endif return error; +#else + return 0; +#endif } static int @@ -182,7 +197,16 @@ npf_modcmd(modcmd_t cmd, void *arg) void npfattach(int nunits) { - npf_init(); +#ifdef MODULAR + /* + * Modular kernels will automatically load any built-in modules + * and call their modcmd() routine, so we don't need to do it + * again as part of pseudo-device configuration. + */ + return; +#else + (void)npf_init(); +#endif } static int