Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/net modularize some more drivers and merge the module glue
details: https://anonhg.NetBSD.org/src/rev/870606e6212a
branches: trunk
changeset: 346946:870606e6212a
user: christos <christos%NetBSD.org@localhost>
date: Sun Aug 07 17:38:33 2016 +0000
description:
modularize some more drivers and merge the module glue
diffstat:
sys/net/agr/if_agr.c | 42 +++++++++++++++++++++-
sys/net/if_faith.c | 43 ++++++++++++++++++++++-
sys/net/if_gif.c | 51 +++++++++++++++++++++++----
sys/net/if_gre.c | 44 ++++++++++++++++++++++-
sys/net/if_loop.c | 30 +++++++++++++++-
sys/net/if_module.h | 89 ++++++++++++++++++++++++++++++++++++++++++++++++
sys/net/if_mpls.c | 46 ++++++++++++++++++++++--
sys/net/if_ppp.c | 74 ++++++----------------------------------
sys/net/if_pppoe.c | 95 ++++++++++++---------------------------------------
sys/net/if_sl.c | 63 +++------------------------------
sys/net/if_srt.c | 51 +++++++++++++++++++++++++--
sys/net/if_stf.c | 42 ++++++++++++++++++++--
sys/net/if_strip.c | 65 +++-------------------------------
sys/net/if_tap.c | 55 ++++++++++++++++++++++-------
sys/net/if_tun.c | 47 ++++++++++++++++++++++---
sys/net/if_vlan.c | 39 ++++++++++++++++++++-
16 files changed, 574 insertions(+), 302 deletions(-)
diffs (truncated from 1594 to 300 lines):
diff -r e2eca0ab338e -r 870606e6212a sys/net/agr/if_agr.c
--- a/sys/net/agr/if_agr.c Sun Aug 07 17:33:04 2016 +0000
+++ b/sys/net/agr/if_agr.c Sun Aug 07 17:38:33 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_agr.c,v 1.38 2016/07/20 07:37:51 ozaki-r Exp $ */
+/* $NetBSD: if_agr.c,v 1.39 2016/08/07 17:38:34 christos Exp $ */
/*-
* Copyright (c)2005 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_agr.c,v 1.38 2016/07/20 07:37:51 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_agr.c,v 1.39 2016/08/07 17:38:34 christos Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -44,6 +44,9 @@
#include <sys/proc.h> /* XXX for curproc */
#include <sys/kauth.h>
#include <sys/xcall.h>
+#include <sys/device.h>
+#include <sys/module.h>
+#include <sys/atomic.h>
#include <net/bpf.h>
#include <net/if.h>
@@ -96,6 +99,8 @@
static struct if_clone agr_cloner =
IF_CLONE_INITIALIZER("agr", agr_clone_create, agr_clone_destroy);
+static u_int agr_count;
+
/*
* EXPORTED FUNCTIONS
*/
@@ -108,9 +113,32 @@
agrattach(int count)
{
+ /*
+ * Nothing to do here, initialization is handled by the
+ * module initialization code in agrinit() below).
+ */
+}
+
+static void
+agrinit(void)
+{
if_clone_attach(&agr_cloner);
}
+static int
+agrdetach(void)
+{
+ int error = 0;
+
+ if (agr_count != 0)
+ error = EBUSY;
+
+ if (error == 0)
+ if_clone_detach(&agr_cloner);
+
+ return error;
+}
+
/*
* agr_input: frame collector.
*/
@@ -338,7 +366,7 @@
if_attach(ifp);
agr_reset_iftype(ifp);
-
+ atomic_inc_uint(&agr_count);
return 0;
}
@@ -375,6 +403,7 @@
cv_destroy(&sc->sc_ports_cv);
agr_free_softc(sc);
+ atomic_dec_uint(&agr_count);
return 0;
}
@@ -1191,3 +1220,10 @@
return error;
}
+
+/*
+ * Module infrastructure
+ */
+#include <net/if_module.h>
+
+IF_MODULE(MODULE_CLASS_DRIVER, agr, "")
diff -r e2eca0ab338e -r 870606e6212a sys/net/if_faith.c
--- a/sys/net/if_faith.c Sun Aug 07 17:33:04 2016 +0000
+++ b/sys/net/if_faith.c Sun Aug 07 17:38:33 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_faith.c,v 1.53 2016/06/10 13:27:16 ozaki-r Exp $ */
+/* $NetBSD: if_faith.c,v 1.54 2016/08/07 17:38:33 christos Exp $ */
/* $KAME: if_faith.c,v 1.21 2001/02/20 07:59:26 itojun Exp $ */
/*
@@ -40,9 +40,11 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_faith.c,v 1.53 2016/06/10 13:27:16 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_faith.c,v 1.54 2016/08/07 17:38:33 christos Exp $");
+#ifdef _KERNEL_OPT
#include "opt_inet.h"
+#endif
#include <sys/param.h>
#include <sys/systm.h>
@@ -53,6 +55,9 @@
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/queue.h>
+#include <sys/device.h>
+#include <sys/module.h>
+#include <sys/atomic.h>
#include <sys/cpu.h>
@@ -98,15 +103,40 @@
#define FAITHMTU 1500
+static u_int faith_count;
+
/* ARGSUSED */
void
faithattach(int count)
{
+ /*
+ * Nothing to do here, initialization is handled by the
+ * module initialization code in faithinit() below).
+ */
+}
+
+static void
+faithinit(void)
+{
if_clone_attach(&faith_cloner);
}
static int
+faithdetach(void)
+{
+ int error = 0;
+
+ if (faith_count != 0)
+ error = EBUSY;
+
+ if (error == 0)
+ if_clone_detach(&faith_cloner);
+
+ return error;
+}
+
+static int
faith_clone_create(struct if_clone *ifc, int unit)
{
struct ifnet *ifp;
@@ -127,6 +157,7 @@
if_attach(ifp);
if_alloc_sadl(ifp);
bpf_attach(ifp, DLT_NULL, sizeof(u_int));
+ atomic_inc_uint(&faith_count);
return (0);
}
@@ -138,6 +169,7 @@
if_detach(ifp);
if_free(ifp);
+ atomic_dec_uint(&faith_count);
return (0);
}
@@ -294,3 +326,10 @@
return ret;
}
#endif
+
+/*
+ * Module infrastructure
+ */
+#include "if_module.h"
+
+IF_MODULE(MODULE_CLASS_DRIVER, faith, "")
diff -r e2eca0ab338e -r 870606e6212a sys/net/if_gif.c
--- a/sys/net/if_gif.c Sun Aug 07 17:33:04 2016 +0000
+++ b/sys/net/if_gif.c Sun Aug 07 17:38:33 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_gif.c,v 1.119 2016/07/04 04:43:46 knakahara Exp $ */
+/* $NetBSD: if_gif.c,v 1.120 2016/08/07 17:38:33 christos Exp $ */
/* $KAME: if_gif.c,v 1.76 2001/08/20 02:01:02 kjc Exp $ */
/*
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.119 2016/07/04 04:43:46 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.120 2016/08/07 17:38:33 christos Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -55,6 +55,8 @@
#include <sys/kmem.h>
#include <sys/sysctl.h>
#include <sys/xcall.h>
+#include <sys/device.h>
+#include <sys/module.h>
#include <net/if.h>
#include <net/if_types.h>
@@ -106,8 +108,6 @@
struct sockaddr *);
static void gif_delete_tunnel(struct ifnet *);
-static void gif_sysctl_setup(struct sysctllog **);
-
static int gif_clone_create(struct if_clone *, int);
static int gif_clone_destroy(struct ifnet *);
static int gif_check_nesting(struct ifnet *, struct mbuf *);
@@ -132,12 +132,15 @@
#endif
static int max_gif_nesting = MAX_GIF_NEST;
+static struct sysctllog *gif_sysctl;
+
static void
-gif_sysctl_setup(struct sysctllog **clog)
+gif_sysctl_setup(void)
{
+ gif_sysctl = NULL;
#ifdef INET
- sysctl_createv(clog, 0, NULL, NULL,
+ sysctl_createv(&gif_sysctl, 0, NULL, NULL,
CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
CTLTYPE_INT, "gifttl",
SYSCTL_DESCR("Default TTL for a gif tunnel datagram"),
@@ -146,7 +149,7 @@
IPCTL_GIF_TTL, CTL_EOL);
#endif
#ifdef INET6
- sysctl_createv(clog, 0, NULL, NULL,
+ sysctl_createv(&gif_sysctl, 0, NULL, NULL,
CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
CTLTYPE_INT, "gifhlim",
SYSCTL_DESCR("Default hop limit for a gif tunnel datagram"),
@@ -160,11 +163,36 @@
void
gifattach(int count)
{
+ /*
+ * Nothing to do here, initialization is handled by the
+ * module initialization code in gifinit() below).
+ */
+}
+
+static void
+gifinit(void)
+{
LIST_INIT(&gif_softc_list);
if_clone_attach(&gif_cloner);
- gif_sysctl_setup(NULL);
+ gif_sysctl_setup();
+}
+
+static int
+gifdetach(void)
+{
+ int error = 0;
+
+ if (!LIST_EMPTY(&gif_softc_list))
+ error = EBUSY;
+
+ if (error == 0) {
+ if_clone_detach(&gif_cloner);
+ sysctl_teardown(&gif_sysctl);
+ }
+
+ return error;
}
static int
@@ -1037,3 +1065,10 @@
Home |
Main Index |
Thread Index |
Old Index