DragonFly BSD
DragonFly bugs List (threaded) for 2005-08
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: netgraph panics


From: YONETANI Tomokazu <qhwt+dfly@xxxxxxxxxx>
Date: Sat, 27 Aug 2005 13:35:48 +0900

On Fri, Aug 26, 2005 at 05:10:48PM +0100, Hiten Pandya wrote:
>  One more thing you could do is load the ng_ksocket.ko module from 
> kldload(2) system call's context in the module handler, which will then 
> remove the requirement for the user to load this module.
> 
> Since the module handler is GUARANTEED to have a process context, you can 
> easily call linker_preload_file from there, and load ng_ksocket.ko.
> 
> I mean, you could load ng_ksocket.ko in modhandler, ngb_mod_event() and 
> you can KEEP this ifdef section in ng_mkpeer so that OTHER netgraph module 
> files do not fall into this trap.  So under the MOD_LOAD case, you would 
> call the linker_preload_file() function, and unload it under the 
> MOD_UNLOAD case, naturally.

How/when can I unload it from the MOD_UNLOAD case in the module handler?

> By adding such a workaround, we at least know that the basic netgraph 
> operations will not fail because ng_ksocket.ko is missing, since we 
> preloaded one of the fundamental ng_ modules for them; they only need to 
> worry about the specific ones.

Please find attached the reworked workaround and see if you like it;
I split the code calling linker_* functions into a separate static function,
and added a comparison against curproc being NULL.  When the linker_* API is
free from the process, this comparison can go away.

Regards.
Index: netgraph/ng_base.c
===================================================================
RCS file: /home/source/dragonfly/cvs/src/sys/netgraph/netgraph/ng_base.c,v
retrieving revision 1.15
diff -u -p -r1.15 ng_base.c
--- netgraph/ng_base.c	2 Jun 2005 22:11:46 -0000	1.15
+++ netgraph/ng_base.c	27 Aug 2005 04:17:22 -0000
@@ -88,6 +88,7 @@ static int	ng_generic_msg(node_p here, s
 static ng_ID_t	ng_decodeidname(const char *name);
 static int	ngb_mod_event(module_t mod, int event, void *data);
 static int	ngintr(struct netmsg *);
+static int	ng_load_module(const char *);
 
 /* Our own netgraph malloc type */
 MALLOC_DEFINE(M_NETGRAPH, "netgraph", "netgraph structures and ctrl messages");
@@ -302,6 +303,30 @@ static const struct ng_cmdlist ng_generi
 			Node routines
 ************************************************************************/
 
+static int
+ng_load_module(const char *typename)
+{
+	char *path, filename[NG_TYPELEN + 4];
+	linker_file_t lf;
+	int error;
+
+	/* linker_* API won't work without a process context */
+	if (curproc == NULL)
+		return (ENXIO);
+
+	/* Not found, try to load it as a loadable module */
+	snprintf(filename, sizeof(filename), "ng_%s.ko", typename);
+	if ((path = linker_search_path(filename)) == NULL)
+		return (ENXIO);
+	error = linker_load_file(path, &lf);
+	FREE(path, M_LINKER);
+#if 0
+	if (error == 0)
+		lf->userrefs++;		/* pretend loaded by the syscall */
+#endif
+	return (error);
+}
+
 /*
  * Instantiate a node of the requested type
  */
@@ -317,25 +342,8 @@ ng_make_node(const char *typename, node_
 	}
 
 	/* Locate the node type */
-	if ((type = ng_findtype(typename)) == NULL) {
-		char *path, filename[NG_TYPELEN + 4];
-		linker_file_t lf;
-		int error;
-
-		/* Not found, try to load it as a loadable module */
-		snprintf(filename, sizeof(filename), "ng_%s.ko", typename);
-		if ((path = linker_search_path(filename)) == NULL)
-			return (ENXIO);
-		error = linker_load_file(path, &lf);
-		FREE(path, M_LINKER);
-		if (error != 0)
-			return (error);
-		lf->userrefs++;		/* pretend loaded by the syscall */
-
-		/* Try again, as now the type should have linked itself in */
-		if ((type = ng_findtype(typename)) == NULL)
-			return (ENXIO);
-	}
+	if ((type = ng_findtype(typename)) == NULL)
+		return (ENXIO);
 
 	/* Call the constructor */
 	if (type->constructor != NULL)
@@ -911,6 +919,17 @@ ng_mkpeer(node_p node, const char *name,
 
 	if ((error = ng_add_hook(node, name, &hook)))
 		return (error);
+
+	/* make sure we have the module needed */
+	if (ng_findtype(type) == NULL) {
+		/* Not found, try to load it as a loadable module */
+		error = ng_load_module(type);
+		if (error != 0) {
+			printf("required netgraph module ng_%s not loaded\n",
+			    type);
+			return (error);
+		}
+	}
 	if ((error = ng_make_node(type, &node2))) {
 		ng_destroy_hook(hook);
 		return (error);
@@ -1723,6 +1742,12 @@ ng_mod_event(module_t mod, int event, vo
 
 		/* Register new netgraph node type */
 		crit_enter();
+		/* make sure we have ng_ksocket loaded */
+		if (ng_findtype("ksocket") == NULL) {
+			error = ng_load_module("ksocket");
+			if (error != 0)
+				break;
+		}
 		if ((error = ng_newtype(type)) != 0) {
 			crit_exit();
 			break;
Index: pptpgre/ng_pptpgre.c
===================================================================
RCS file: /home/source/dragonfly/cvs/src/sys/netgraph/pptpgre/ng_pptpgre.c,v
retrieving revision 1.7
diff -u -p -r1.7 ng_pptpgre.c
--- pptpgre/ng_pptpgre.c	2 Jun 2005 22:11:46 -0000	1.7
+++ pptpgre/ng_pptpgre.c	11 Jun 2005 08:29:43 -0000
@@ -557,8 +557,10 @@ ng_pptpgre_xmit(node_p node, struct mbuf
 	NG_SEND_DATA(error, priv->lower, m, meta);
 
 	/* Start receive ACK timer if data was sent and not already running */
-	if (error == 0 && gre->hasSeq && priv->xmitSeq == priv->recvAck + 1)
+	if (error == 0 && gre->hasSeq && priv->xmitSeq == priv->recvAck + 1) {
+		ng_pptpgre_stop_recv_ack_timer(node);
 		ng_pptpgre_start_recv_ack_timer(node);
+	}
 	return (error);
 }
 


[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]