Module Name:    src
Committed By:   christos
Date:           Sat Aug  6 12:48:23 UTC 2016

Modified Files:
        src/sys/net: if_ppp.c if_sl.c if_strip.c

Log Message:
make strip and slip modular, and cosmetic for ppp.


To generate a diff of this commit:
cvs rdiff -u -r1.154 -r1.155 src/sys/net/if_ppp.c
cvs rdiff -u -r1.124 -r1.125 src/sys/net/if_sl.c
cvs rdiff -u -r1.104 -r1.105 src/sys/net/if_strip.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/if_ppp.c
diff -u src/sys/net/if_ppp.c:1.154 src/sys/net/if_ppp.c:1.155
--- src/sys/net/if_ppp.c:1.154	Sat Aug  6 08:42:40 2016
+++ src/sys/net/if_ppp.c	Sat Aug  6 08:48:23 2016
@@ -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 @@ pppinit(void)
 {
 
 	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 @@ pppinit(void)
 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;
 }
 

Index: src/sys/net/if_sl.c
diff -u src/sys/net/if_sl.c:1.124 src/sys/net/if_sl.c:1.125
--- src/sys/net/if_sl.c:1.124	Fri Jun 10 09:27:16 2016
+++ src/sys/net/if_sl.c	Sat Aug  6 08:48:23 2016
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: if_sl.c,v 1.
 #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 @@ struct if_clone sl_cloner =
 
 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 @@ void
 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 @@ sl_clone_destroy(struct ifnet *ifp)
 }
 
 static int
-slinit(struct sl_softc *sc)
+slcreate(struct sl_softc *sc)
 {
 
 	if (sc->sc_mbuf == NULL) {
@@ -312,7 +338,7 @@ slopen(dev_t dev, struct tty *tp)
 			    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 @@ slioctl(struct ifnet *ifp, u_long cmd, v
 	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;
+}

Index: src/sys/net/if_strip.c
diff -u src/sys/net/if_strip.c:1.104 src/sys/net/if_strip.c:1.105
--- src/sys/net/if_strip.c:1.104	Fri Jun 10 09:27:16 2016
+++ src/sys/net/if_strip.c	Sat Aug  6 08:48:23 2016
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: if_strip.c,v
 #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 @@ struct if_clone strip_cloner =
 
 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 @@ static struct linesw strip_disc = {
 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 @@ strip_clone_destroy(struct ifnet *ifp)
 }
 
 static int
-stripinit(struct strip_softc *sc)
+stripcreate(struct strip_softc *sc)
 {
 	u_char *p;
 
@@ -483,7 +509,7 @@ stripopen(dev_t dev, struct tty *tp)
 		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_Message(struct strip_softc *stri
 		RecvErr("unparsed radio error message:", strip_info);
 	}
 }
+
+/*
+ * Module infrastructure
+ */
+
+MODULE(MODULE_CLASS_DRIVER, if_strip, "slcompress");
+
+#ifdef _MODULE
+CFDRIVER_DECL(strip, DV_IFNET, NULL);
+#endif
+
+static int
+if_strip_modcmd(modcmd_t cmd, void *arg)
+{
+	int error = 0;
+
+	switch (cmd) {
+	case MODULE_CMD_INIT:
+#ifdef _MODULE
+		error = config_cfdriver_attach(&strip_cd);
+		if (error) {
+			aprint_error("%s: unable to register cfdriver for"
+			    "%s, error %d\n", __func__, strip_cd.cd_name,
+			    error);
+			break;
+		}
+
+#endif
+		/* Init the unit list and line discipline stuff */
+		stripinit();
+		break;
+
+	case MODULE_CMD_FINI:
+		/*
+		 * Make sure it's ok to detach - no units left, and
+		 * line discipline is removed
+		 */
+		error = stripdetach();
+		if (error != 0)
+			break;
+#ifdef _MODULE
+		/* Remove device from autoconf database */
+		error = config_cfdriver_detach(&strip_cd);
+		if (error) {
+			aprint_error("%s: failed to detach %s cfdriver, "
+			    "error %d\n", __func__, strip_cd.cd_name, error);
+			break;
+		}
+#endif
+		break;
+
+	case MODULE_CMD_STAT:
+		error = ENOTTY;
+		break;
+	default:
+		error = ENOTTY;
+		break;
+	}
+
+	return error;
+}

Reply via email to