Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/net make strip and slip modular, and cosmetic for ppp.
details: https://anonhg.NetBSD.org/src/rev/251b3f5bf6c3
branches: trunk
changeset: 346904:251b3f5bf6c3
user: christos <christos%NetBSD.org@localhost>
date: Sat Aug 06 12:48:23 2016 +0000
description:
make strip and slip modular, and cosmetic for ppp.
diffstat:
sys/net/if_ppp.c | 10 +++--
sys/net/if_sl.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++---
sys/net/if_strip.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++---
3 files changed, 192 insertions(+), 16 deletions(-)
diffs (truncated from 359 to 300 lines):
diff -r 48d28497e244 -r 251b3f5bf6c3 sys/net/if_ppp.c
--- a/sys/net/if_ppp.c Sat Aug 06 12:44:03 2016 +0000
+++ b/sys/net/if_ppp.c Sat Aug 06 12:48:23 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_ppp.c,v 1.154 2016/08/06 12:42:40 pgoyette Exp $ */
+/* $NetBSD: if_ppp.c,v 1.155 2016/08/06 12:48:23 christos Exp $ */
/* Id: if_ppp.c,v 1.6 1997/03/04 03:33:00 paulus Exp */
/*
@@ -102,7 +102,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ppp.c,v 1.154 2016/08/06 12:42:40 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ppp.c,v 1.155 2016/08/06 12:48:23 christos Exp $");
#ifdef _KERNEL_OPT
#include "ppp.h"
@@ -245,7 +245,7 @@
{
if (ttyldisc_attach(&ppp_disc) != 0)
- panic("pppattach");
+ panic("%s", __func__);
mutex_init(&ppp_list_lock, MUTEX_DEFAULT, IPL_NONE);
LIST_INIT(&ppp_softc_list);
@@ -255,12 +255,14 @@
static int
pppdetach(void)
{
- int error;
+ int error = 0;
if (!LIST_EMPTY(&ppp_softc_list))
error = EBUSY;
+
if (error == 0)
error = ttyldisc_detach(&ppp_disc);
+
return error;
}
diff -r 48d28497e244 -r 251b3f5bf6c3 sys/net/if_sl.c
--- a/sys/net/if_sl.c Sat Aug 06 12:44:03 2016 +0000
+++ b/sys/net/if_sl.c Sat Aug 06 12:48:23 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_sl.c,v 1.124 2016/06/10 13:27:16 ozaki-r Exp $ */
+/* $NetBSD: if_sl.c,v 1.125 2016/08/06 12:48:23 christos Exp $ */
/*
* Copyright (c) 1987, 1989, 1992, 1993
@@ -60,7 +60,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_sl.c,v 1.124 2016/06/10 13:27:16 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_sl.c,v 1.125 2016/08/06 12:48:23 christos Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -85,6 +85,8 @@
#endif
#include <sys/cpu.h>
#include <sys/intr.h>
+#include <sys/device.h>
+#include <sys/module.h>
#include <net/if.h>
#include <net/if_types.h>
@@ -190,7 +192,7 @@
static void slintr(void *);
-static int slinit(struct sl_softc *);
+static int slcreate(struct sl_softc *);
static struct mbuf *sl_btom(struct sl_softc *, int);
static int slclose(struct tty *, int);
@@ -219,13 +221,37 @@
slattach(int n __unused)
{
+ /*
+ * Nothing to do here, initialization is handled by the
+ * module initialization code in slinit() below).
+ */
+}
+
+static void
+slinit(void)
+{
+
if (ttyldisc_attach(&slip_disc) != 0)
- panic("slattach");
+ panic("%s", __func__);
LIST_INIT(&sl_softc_list);
if_clone_attach(&sl_cloner);
}
static int
+sldetach(void)
+{
+ int error = 0;
+
+ if (!LIST_EMPTY(&sl_softc_list))
+ error = EBUSY;
+
+ if (error == 0)
+ error = ttyldisc_detach(&slip_disc);
+
+ return error;
+}
+
+static int
sl_clone_create(struct if_clone *ifc, int unit)
{
struct sl_softc *sc;
@@ -267,7 +293,7 @@
}
static int
-slinit(struct sl_softc *sc)
+slcreate(struct sl_softc *sc)
{
if (sc->sc_mbuf == NULL) {
@@ -312,7 +338,7 @@
slintr, sc);
if (sc->sc_si == NULL)
return ENOMEM;
- if (slinit(sc) == 0) {
+ if (slcreate(sc) == 0) {
softint_disestablish(sc->sc_si);
return ENOBUFS;
}
@@ -1036,3 +1062,64 @@
splx(s);
return error;
}
+
+
+/*
+ * Module infrastructure
+ */
+
+MODULE(MODULE_CLASS_DRIVER, if_sl, "slcompress");
+
+#ifdef _MODULE
+CFDRIVER_DECL(sl, DV_IFNET, NULL);
+#endif
+
+static int
+if_sl_modcmd(modcmd_t cmd, void *arg)
+{
+ int error = 0;
+
+ switch (cmd) {
+ case MODULE_CMD_INIT:
+#ifdef _MODULE
+ error = config_cfdriver_attach(&sl_cd);
+ if (error) {
+ aprint_error("%s: unable to register cfdriver for"
+ "%s, error %d\n", __func__, sl_cd.cd_name, error);
+ break;
+ }
+
+#endif
+ /* Init the unit list and line discipline stuff */
+ slinit();
+ break;
+
+ case MODULE_CMD_FINI:
+ /*
+ * Make sure it's ok to detach - no units left, and
+ * line discipline is removed
+ */
+ error = sldetach();
+ if (error != 0)
+ break;
+#ifdef _MODULE
+ /* Remove device from autoconf database */
+ error = config_cfdriver_detach(&sl_cd);
+ if (error) {
+ aprint_error("%s: failed to detach %s cfdriver, "
+ "error %d\n", __func__, sl_cd.cd_name, error);
+ break;
+ }
+#endif
+ break;
+
+ case MODULE_CMD_STAT:
+ error = ENOTTY;
+ break;
+ default:
+ error = ENOTTY;
+ break;
+ }
+
+ return error;
+}
diff -r 48d28497e244 -r 251b3f5bf6c3 sys/net/if_strip.c
--- a/sys/net/if_strip.c Sat Aug 06 12:44:03 2016 +0000
+++ b/sys/net/if_strip.c Sat Aug 06 12:48:23 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_strip.c,v 1.104 2016/06/10 13:27:16 ozaki-r Exp $ */
+/* $NetBSD: if_strip.c,v 1.105 2016/08/06 12:48:23 christos Exp $ */
/* from: NetBSD: if_sl.c,v 1.38 1996/02/13 22:00:23 christos Exp $ */
/*
@@ -87,7 +87,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_strip.c,v 1.104 2016/06/10 13:27:16 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_strip.c,v 1.105 2016/08/06 12:48:23 christos Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -113,6 +113,8 @@
#include <sys/cpu.h>
#include <sys/intr.h>
#include <sys/socketvar.h>
+#include <sys/device.h>
+#include <sys/module.h>
#include <net/if.h>
#include <net/if_dl.h>
@@ -222,7 +224,7 @@
static void stripintr(void *);
-static int stripinit(struct strip_softc *);
+static int stripcreate(struct strip_softc *);
static struct mbuf *strip_btom(struct strip_softc *, int);
/*
@@ -353,13 +355,37 @@
void
stripattach(void)
{
+ /*
+ * Nothing to do here, initialization is handled by the
+ * module initialization code in slinit() below).
+ */
+}
+
+static void
+stripinit(void)
+{
+
if (ttyldisc_attach(&strip_disc) != 0)
- panic("stripattach");
+ panic("%s", __func__);
LIST_INIT(&strip_softc_list);
if_clone_attach(&strip_cloner);
}
static int
+stripdetach(void)
+{
+ int error = 0;
+
+ if (!LIST_EMPTY(&strip_softc_list))
+ error = EBUSY;
+
+ if (error == 0)
+ error = ttyldisc_detach(&strip_disc);
+
+ return error;
+}
+
+static int
strip_clone_create(struct if_clone *ifc, int unit)
{
struct strip_softc *sc;
@@ -407,7 +433,7 @@
}
static int
-stripinit(struct strip_softc *sc)
+stripcreate(struct strip_softc *sc)
{
u_char *p;
@@ -483,7 +509,7 @@
if (sc->sc_ttyp == NULL) {
sc->sc_si = softint_establish(SOFTINT_NET,
stripintr, sc);
- if (stripinit(sc) == 0) {
+ if (stripcreate(sc) == 0) {
softint_disestablish(sc->sc_si);
return (ENOBUFS);
}
@@ -1973,3 +1999,64 @@
RecvErr("unparsed radio error message:", strip_info);
}
}
+
+/*
Home |
Main Index |
Thread Index |
Old Index