git: 9bcc1e97dda8 - main - ipfw: cleanup SYSINIT(9)s

From: Gleb Smirnoff <glebius_at_FreeBSD.org>
Date: Fri, 16 Oct 2026 21:17:25 UTC
The branch main has been updated by glebius:

URL: https://cgit.FreeBSD.org/src/commit/?id=9bcc1e97dda8e926483b81874884211bbe4f36e9

commit 9bcc1e97dda8e926483b81874884211bbe4f36e9
Author:     Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2026-10-16 21:09:05 +0000
Commit:     Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2026-10-16 21:09:05 +0000

    ipfw: cleanup SYSINIT(9)s
    
    Make them all belong to SI_SUB_PROTO_FIREWALL and explicitly specify
    order.  Prefer SYSINIT() over modevent, for those subsystems that don't
    have dependencies.  All subsystems just depend on the main module and they
    don't depend on each other, except dummynet which also has submodules.
    Thus, keep DECLARE_MODULE() only for the main module and dummynet.
    
    Differential Revision:  https://reviews.freebsd.org/D60685
---
 sys/netpfil/ipfw/dn_sched.h          |  2 +-
 sys/netpfil/ipfw/ip_dummynet.c       | 10 +++---
 sys/netpfil/ipfw/ip_fw2.c            | 60 +++++++-----------------------------
 sys/netpfil/ipfw/ip_fw_compat.c      |  9 ++----
 sys/netpfil/ipfw/ip_fw_nat.c         | 44 ++++----------------------
 sys/netpfil/ipfw/nat64/ip_fw_nat64.c | 36 +++-------------------
 sys/netpfil/ipfw/nptv6/ip_fw_nptv6.c | 18 ++++-------
 7 files changed, 35 insertions(+), 144 deletions(-)

diff --git a/sys/netpfil/ipfw/dn_sched.h b/sys/netpfil/ipfw/dn_sched.h
index 476ac4145974..ade15c6db631 100644
--- a/sys/netpfil/ipfw/dn_sched.h
+++ b/sys/netpfil/ipfw/dn_sched.h
@@ -206,6 +206,6 @@ int dn_sched_modevent(module_t mod, int cmd, void *arg);
 		#name, dn_sched_modevent, dnsched		\
 	};							\
 	DECLARE_MODULE(name, name##_mod, 			\
-		SI_SUB_PROTO_FIREWALL, SI_ORDER_ANY); 		\
+		SI_SUB_PROTO_FIREWALL, SI_ORDER_THIRD);		\
         MODULE_DEPEND(name, dummynet, 3, 3, 3)
 #endif /* _DN_SCHED_H */
diff --git a/sys/netpfil/ipfw/ip_dummynet.c b/sys/netpfil/ipfw/ip_dummynet.c
index 61442c617753..f834fb2b7ba6 100644
--- a/sys/netpfil/ipfw/ip_dummynet.c
+++ b/sys/netpfil/ipfw/ip_dummynet.c
@@ -2704,16 +2704,15 @@ static moduledata_t dummynet_mod = {
 	"dummynet", dummynet_modevent, NULL
 };
 
-#define	DN_SI_SUB	SI_SUB_PROTO_FIREWALL
-#define	DN_MODEV_ORD	(SI_ORDER_ANY - 128) /* after ipfw */
-DECLARE_MODULE(dummynet, dummynet_mod, DN_SI_SUB, DN_MODEV_ORD);
+DECLARE_MODULE(dummynet, dummynet_mod, SI_SUB_PROTO_FIREWALL, SI_ORDER_SECOND);
 MODULE_VERSION(dummynet, 3);
 
 /*
  * Starting up. Done in order after dummynet_modevent() has been called.
  * VNET_SYSINIT is also called for each existing vnet and each new vnet.
  */
-VNET_SYSINIT(vnet_dn_init, DN_SI_SUB, DN_MODEV_ORD+2, ip_dn_vnet_init, NULL);
+VNET_SYSINIT(vnet_dn_init, SI_SUB_PROTO_FIREWALL, SI_ORDER_SECOND,
+    ip_dn_vnet_init, NULL);
 
 /*
  * Shutdown handlers up shop. These are done in REVERSE ORDER, but still
@@ -2721,7 +2720,8 @@ VNET_SYSINIT(vnet_dn_init, DN_SI_SUB, DN_MODEV_ORD+2, ip_dn_vnet_init, NULL);
  * VNET_SYSUNINIT is also called for each exiting vnet as it exits.
  * or when the module is unloaded.
  */
-VNET_SYSUNINIT(vnet_dn_uninit, DN_SI_SUB, DN_MODEV_ORD+2, ip_dn_vnet_destroy, NULL);
+VNET_SYSUNINIT(vnet_dn_uninit, SI_SUB_PROTO_FIREWALL, SI_ORDER_SECOND,
+    ip_dn_vnet_destroy, NULL);
 
 #ifdef NEW_AQM
 
diff --git a/sys/netpfil/ipfw/ip_fw2.c b/sys/netpfil/ipfw/ip_fw2.c
index c1ae8bd9be1f..718a603aba3a 100644
--- a/sys/netpfil/ipfw/ip_fw2.c
+++ b/sys/netpfil/ipfw/ip_fw2.c
@@ -3584,7 +3584,7 @@ sysctl_ipfw_tables_sets(SYSCTL_HANDLER_ARGS)
  * Stuff that must be initialised only on boot or module load
  */
 static void
-ipfw_init(void *dummy __unused)
+ipfw_init(void)
 {
 	/*
  	 * Only print out this stuff the first time around,
@@ -3636,7 +3636,7 @@ ipfw_init(void *dummy __unused)
  * Called for the removal of the last instance only on module unload.
  */
 static void
-ipfw_destroy(void *dummy __unused)
+ipfw_destroy(void)
 {
 
 	ipfw_iface_destroy();
@@ -3771,39 +3771,19 @@ vnet_ipfw_uninit(const void *unused)
 	return (0);
 }
 
-/*
- * Module event handler.
- * In general we have the choice of handling most of these events by the
- * event handler or by the (VNET_)SYS(UN)INIT handlers. I have chosen to
- * use the SYSINIT handlers as they are more capable of expressing the
- * flow of control during module and vnet operations, so this is just
- * a skeleton. Note there is no SYSINIT equivalent of the module
- * SHUTDOWN handler, but we don't have anything to do in that case anyhow.
- */
 static int
 ipfw_modevent(module_t mod, int type, void *unused)
 {
-	int err = 0;
-
 	switch (type) {
 	case MOD_LOAD:
-		/* Called once at module load or
-	 	 * system boot if compiled in. */
-		break;
-	case MOD_QUIESCE:
-		/* Called before unload. May veto unloading. */
+		ipfw_init();
 		break;
 	case MOD_UNLOAD:
-		/* Called during unload. */
-		break;
-	case MOD_SHUTDOWN:
-		/* Called during system shutdown. */
-		break;
-	default:
-		err = EOPNOTSUPP;
+		ipfw_destroy();
 		break;
 	}
-	return err;
+
+	return (0);
 }
 
 static moduledata_t ipfwmod = {
@@ -3812,13 +3792,7 @@ static moduledata_t ipfwmod = {
 	0
 };
 
-/* Define startup order. */
-#define	IPFW_SI_SUB_FIREWALL	SI_SUB_PROTO_FIREWALL
-#define	IPFW_MODEVENT_ORDER	(SI_ORDER_ANY - 255) /* On boot slot in here. */
-#define	IPFW_MODULE_ORDER	(IPFW_MODEVENT_ORDER + 1) /* A little later. */
-#define	IPFW_VNET_ORDER		(IPFW_MODEVENT_ORDER + 2) /* Later still. */
-
-DECLARE_MODULE(ipfw, ipfwmod, IPFW_SI_SUB_FIREWALL, IPFW_MODEVENT_ORDER);
+DECLARE_MODULE(ipfw, ipfwmod, SI_SUB_PROTO_FIREWALL, SI_ORDER_FIRST);
 FEATURE(ipfw_ctl3, "ipfw new sockopt calls");
 MODULE_VERSION(ipfw, 3);
 /* should declare some dependencies here */
@@ -3827,19 +3801,7 @@ MODULE_VERSION(ipfw, 3);
  * Starting up. Done in order after ipfwmod() has been called.
  * VNET_SYSINIT is also called for each existing vnet and each new vnet.
  */
-SYSINIT(ipfw_init, IPFW_SI_SUB_FIREWALL, IPFW_MODULE_ORDER,
-	    ipfw_init, NULL);
-VNET_SYSINIT(vnet_ipfw_init, IPFW_SI_SUB_FIREWALL, IPFW_VNET_ORDER,
-	    vnet_ipfw_init, NULL);
-
-/*
- * Closing up shop. These are done in REVERSE ORDER, but still
- * after ipfwmod() has been called. Not called on reboot.
- * VNET_SYSUNINIT is also called for each exiting vnet as it exits.
- * or when the module is unloaded.
- */
-SYSUNINIT(ipfw_destroy, IPFW_SI_SUB_FIREWALL, IPFW_MODULE_ORDER,
-	    ipfw_destroy, NULL);
-VNET_SYSUNINIT(vnet_ipfw_uninit, IPFW_SI_SUB_FIREWALL, IPFW_VNET_ORDER,
-	    vnet_ipfw_uninit, NULL);
-/* end of file */
+VNET_SYSINIT(vnet_ipfw_init, SI_SUB_PROTO_FIREWALL, SI_ORDER_SECOND,
+    vnet_ipfw_init, NULL);
+VNET_SYSUNINIT(vnet_ipfw_uninit, SI_SUB_PROTO_FIREWALL, SI_ORDER_SECOND,
+    vnet_ipfw_uninit, NULL);
diff --git a/sys/netpfil/ipfw/ip_fw_compat.c b/sys/netpfil/ipfw/ip_fw_compat.c
index a1c5349c4656..590159411509 100644
--- a/sys/netpfil/ipfw/ip_fw_compat.c
+++ b/sys/netpfil/ipfw/ip_fw_compat.c
@@ -703,12 +703,7 @@ static moduledata_t ipfw_compat_mod = {
 	0
 };
 
-/* Define startup order. */
-#define	IPFW_COMPAT_SI_SUB_FIREWALL	SI_SUB_PROTO_FIREWALL
-#define	IPFW_COMPAT_MODEVENT_ORDER	(SI_ORDER_ANY - 128) /* after ipfw */
-#define	IPFW_COMPAT_MODULE_ORDER	(IPFW_COMPAT_MODEVENT_ORDER + 1)
-
-DECLARE_MODULE(ipfw_compat, ipfw_compat_mod, IPFW_COMPAT_SI_SUB_FIREWALL,
-    IPFW_COMPAT_MODULE_ORDER);
+DECLARE_MODULE(ipfw_compat, ipfw_compat_mod, SI_SUB_PROTO_FIREWALL,
+    SI_ORDER_SECOND);
 MODULE_DEPEND(ipfw_compat, ipfw, 3, 3, 3);
 MODULE_VERSION(ipfw_compat, 1);
diff --git a/sys/netpfil/ipfw/ip_fw_nat.c b/sys/netpfil/ipfw/ip_fw_nat.c
index 6ebde03fe2e3..1131cd75afbd 100644
--- a/sys/netpfil/ipfw/ip_fw_nat.c
+++ b/sys/netpfil/ipfw/ip_fw_nat.c
@@ -1194,50 +1194,18 @@ ipfw_nat_destroy(void *dummy __unused)
 	ipfw_nat_get_log_ptr = NULL;
 }
 
-static int
-ipfw_nat_modevent(module_t mod, int type, void *unused)
-{
-	int err = 0;
-
-	switch (type) {
-	case MOD_LOAD:
-		break;
-
-	case MOD_UNLOAD:
-		break;
-
-	default:
-		return EOPNOTSUPP;
-		break;
-	}
-	return err;
-}
-
-static moduledata_t ipfw_nat_mod = {
-	"ipfw_nat",
-	ipfw_nat_modevent,
-	0
-};
-
-/* Define startup order. */
-#define	IPFW_NAT_SI_SUB_FIREWALL	SI_SUB_PROTO_FIREWALL
-#define	IPFW_NAT_MODEVENT_ORDER		(SI_ORDER_ANY - 128) /* after ipfw */
-#define	IPFW_NAT_MODULE_ORDER		(IPFW_NAT_MODEVENT_ORDER + 1)
-#define	IPFW_NAT_VNET_ORDER		(IPFW_NAT_MODEVENT_ORDER + 2)
-
-DECLARE_MODULE(ipfw_nat, ipfw_nat_mod, IPFW_NAT_SI_SUB_FIREWALL, SI_ORDER_ANY);
 MODULE_DEPEND(ipfw_nat, libalias, 1, 1, 1);
 MODULE_DEPEND(ipfw_nat, ipfw, 3, 3, 3);
 MODULE_VERSION(ipfw_nat, 1);
 
-SYSINIT(ipfw_nat_init, IPFW_NAT_SI_SUB_FIREWALL, IPFW_NAT_MODULE_ORDER,
-    ipfw_nat_init, NULL);
-VNET_SYSINIT(vnet_ipfw_nat_init, IPFW_NAT_SI_SUB_FIREWALL, IPFW_NAT_VNET_ORDER,
+SYSINIT(ipfw_nat_init, SI_SUB_PROTO_FIREWALL, SI_ORDER_SECOND, ipfw_nat_init,
+    NULL);
+VNET_SYSINIT(vnet_ipfw_nat_init, SI_SUB_PROTO_FIREWALL, SI_ORDER_SECOND,
     vnet_ipfw_nat_init, NULL);
 
-SYSUNINIT(ipfw_nat_destroy, IPFW_NAT_SI_SUB_FIREWALL, IPFW_NAT_MODULE_ORDER,
+SYSUNINIT(ipfw_nat_destroy, SI_SUB_PROTO_FIREWALL, SI_ORDER_SECOND,
     ipfw_nat_destroy, NULL);
-VNET_SYSUNINIT(vnet_ipfw_nat_uninit, IPFW_NAT_SI_SUB_FIREWALL,
-    IPFW_NAT_VNET_ORDER, vnet_ipfw_nat_uninit, NULL);
+VNET_SYSUNINIT(vnet_ipfw_nat_uninit, SI_SUB_PROTO_FIREWALL,
+    SI_ORDER_SECOND, vnet_ipfw_nat_uninit, NULL);
 
 /* end of file */
diff --git a/sys/netpfil/ipfw/nat64/ip_fw_nat64.c b/sys/netpfil/ipfw/nat64/ip_fw_nat64.c
index 17f8cc099aa5..230f42807820 100644
--- a/sys/netpfil/ipfw/nat64/ip_fw_nat64.c
+++ b/sys/netpfil/ipfw/nat64/ip_fw_nat64.c
@@ -114,38 +114,10 @@ vnet_ipfw_nat64_uninit(const void *arg __unused)
 	return (0);
 }
 
-static int
-ipfw_nat64_modevent(module_t mod, int type, void *unused)
-{
-
-	switch (type) {
-	case MOD_LOAD:
-	case MOD_UNLOAD:
-		break;
-	default:
-		return (EOPNOTSUPP);
-	}
-	return (0);
-}
-
-static moduledata_t ipfw_nat64_mod = {
-	"ipfw_nat64",
-	ipfw_nat64_modevent,
-	0
-};
-
-/* Define startup order. */
-#define	IPFW_NAT64_SI_SUB_FIREWALL	SI_SUB_PROTO_IFATTACHDOMAIN
-#define	IPFW_NAT64_MODEVENT_ORDER	(SI_ORDER_ANY - 128) /* after ipfw */
-#define	IPFW_NAT64_MODULE_ORDER		(IPFW_NAT64_MODEVENT_ORDER + 1)
-#define	IPFW_NAT64_VNET_ORDER		(IPFW_NAT64_MODEVENT_ORDER + 2)
-
-DECLARE_MODULE(ipfw_nat64, ipfw_nat64_mod, IPFW_NAT64_SI_SUB_FIREWALL,
-    SI_ORDER_ANY);
 MODULE_DEPEND(ipfw_nat64, ipfw, 3, 3, 3);
 MODULE_VERSION(ipfw_nat64, 1);
 
-VNET_SYSINIT(vnet_ipfw_nat64_init, IPFW_NAT64_SI_SUB_FIREWALL,
-    IPFW_NAT64_VNET_ORDER, vnet_ipfw_nat64_init, NULL);
-VNET_SYSUNINIT(vnet_ipfw_nat64_uninit, IPFW_NAT64_SI_SUB_FIREWALL,
-    IPFW_NAT64_VNET_ORDER, vnet_ipfw_nat64_uninit, NULL);
+VNET_SYSINIT(vnet_ipfw_nat64_init, SI_SUB_PROTO_FIREWALL, SI_ORDER_SECOND,
+    vnet_ipfw_nat64_init, NULL);
+VNET_SYSUNINIT(vnet_ipfw_nat64_uninit, SI_SUB_PROTO_FIREWALL, SI_ORDER_SECOND,
+    vnet_ipfw_nat64_uninit, NULL);
diff --git a/sys/netpfil/ipfw/nptv6/ip_fw_nptv6.c b/sys/netpfil/ipfw/nptv6/ip_fw_nptv6.c
index 2f2565171efb..66fe929b3910 100644
--- a/sys/netpfil/ipfw/nptv6/ip_fw_nptv6.c
+++ b/sys/netpfil/ipfw/nptv6/ip_fw_nptv6.c
@@ -79,18 +79,12 @@ static moduledata_t ipfw_nptv6_mod = {
 	0
 };
 
-/* Define startup order. */
-#define	IPFW_NPTV6_SI_SUB_FIREWALL	SI_SUB_PROTO_IFATTACHDOMAIN
-#define	IPFW_NPTV6_MODEVENT_ORDER	(SI_ORDER_ANY - 128) /* after ipfw */
-#define	IPFW_NPTV6_MODULE_ORDER		(IPFW_NPTV6_MODEVENT_ORDER + 1)
-#define	IPFW_NPTV6_VNET_ORDER		(IPFW_NPTV6_MODEVENT_ORDER + 2)
-
-DECLARE_MODULE(ipfw_nptv6, ipfw_nptv6_mod, IPFW_NPTV6_SI_SUB_FIREWALL,
-    IPFW_NPTV6_MODULE_ORDER);
+DECLARE_MODULE(ipfw_nptv6, ipfw_nptv6_mod, SI_SUB_PROTO_FIREWALL,
+    SI_ORDER_SECOND);
 MODULE_DEPEND(ipfw_nptv6, ipfw, 3, 3, 3);
 MODULE_VERSION(ipfw_nptv6, 1);
 
-VNET_SYSINIT(vnet_ipfw_nptv6_init, IPFW_NPTV6_SI_SUB_FIREWALL,
-    IPFW_NPTV6_VNET_ORDER, vnet_ipfw_nptv6_init, NULL);
-VNET_SYSUNINIT(vnet_ipfw_nptv6_uninit, IPFW_NPTV6_SI_SUB_FIREWALL,
-    IPFW_NPTV6_VNET_ORDER, vnet_ipfw_nptv6_uninit, NULL);
+VNET_SYSINIT(vnet_ipfw_nptv6_init, SI_SUB_PROTO_FIREWALL, SI_ORDER_SECOND,
+    vnet_ipfw_nptv6_init, NULL);
+VNET_SYSUNINIT(vnet_ipfw_nptv6_uninit, SI_SUB_PROTO_FIREWALL, SI_ORDER_SECOND,
+    vnet_ipfw_nptv6_uninit, NULL);