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 16:25:10 +0900

On Sat, Aug 27, 2005 at 01:35:48PM +0900, YONETANI Tomokazu wrote:
> Please find attached the reworked workaround and see if you like it;

Ugh, please disregard the previous one, wrong function and an extra patch.
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 06:36:38 -0000
@@ -88,6 +88,8 @@ 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 *);
+static int	ng_unload_module(const char *);
 
 /* Our own netgraph malloc type */
 MALLOC_DEFINE(M_NETGRAPH, "netgraph", "netgraph structures and ctrl messages");
@@ -302,6 +304,50 @@ static const struct ng_cmdlist ng_generi
 			Node routines
 ************************************************************************/
 
+static int
+ng_load_module(const char *name)
+{
+	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", name);
+	if ((path = linker_search_path(filename)) == NULL)
+		return (ENXIO);
+	error = linker_load_file(path, &lf);
+	FREE(path, M_LINKER);
+	if (error == 0)
+		lf->userrefs++;		/* pretend kldload'ed */
+	return (error);
+}
+
+static int
+ng_unload_module(const char *name)
+{
+	char 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", name);
+	if ((lf = linker_find_file_by_name(filename)) == NULL)
+		return (ENXIO);
+	error = linker_file_unload(lf);
+
+	if (error == 0)
+		lf->userrefs--;		/* pretend kldunload'ed */
+	return (error);
+}
+
 /*
  * Instantiate a node of the requested type
  */
@@ -317,25 +363,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 +940,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);
@@ -1782,11 +1822,17 @@ ngb_mod_event(module_t mod, int event, v
 	case MOD_LOAD:
 		/* Register line discipline */
 		crit_enter();
+		error = ng_load_module("ksocket");
+		if (error != 0) {
+			crit_exit();
+			break;
+		}
 		netisr_register(NETISR_NETGRAPH, cpu0_portfn, ngintr);
 		error = 0;
 		crit_exit();
 		break;
 	case MOD_UNLOAD:
+		ng_unload_module("ksocket");
 		/* You cant unload it because an interface may be using it.  */
 		error = EBUSY;
 		break;


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