Ejemplo n.º 1
0
/*
 * Called by di_walk_node() to walk the list of device nodes and
 * force all nodes of type "network" to be loaded.
 *
 * Returns: DI_WALK_CONTINUE
 */
static int
process_node(di_node_t node, void *arg)
{
	di_prom_handle_t ph = (di_prom_handle_t)arg;
	char *pdevtype;
	int ret;

	/*
	 * Only want to process nodes whose device_type is "network".
	 */
	ret = di_prom_prop_lookup_strings(ph, node, "device_type", &pdevtype);
	if ((ret <= 0) || (strcmp(pdevtype, "network") != 0)) {
		return (DI_WALK_CONTINUE);
	}

	/*
	 * If the instance is '-1', then the driver for the device
	 * has not been loaded - so force it to be loaded. Ignore
	 * errors loading the driver.
	 */
	if (di_instance(node) == -1) {
		node = di_init_driver(di_driver_name(node), 0);
		if (node != DI_NODE_NIL) {
			di_fini(node);
		}
	}
	return (DI_WALK_CONTINUE);
}
Ejemplo n.º 2
0
/*
 * Walk all "service" device nodes to find the one with the
 * matching glvc minor name
 */
static char *
svc_name_to_glvc_dev_path(char *service)
{
	di_node_t root_node, service_node;
	char *glvc_path;
	char *minor_name;
	di_minor_t minor;
	char *dev_path = NULL;

	if (service == NULL)
		return (NULL);

	/* Ensure that the 'glvc' driver is loaded */
	root_node = di_init_driver("glvc", DINFOCPYALL);
	if (root_node == DI_NODE_NIL) {
		return (dev_path);
	}

	service_node = di_drv_first_node("glvc", root_node);

	while (service_node != DI_NODE_NIL) {
		/* Make sure node name matches service name */
		if (strcmp(service, di_node_name(service_node)) == 0) {
			/* Walk minor nodes */
			minor = di_minor_next(service_node, DI_NODE_NIL);

			while (minor != DI_NODE_NIL) {
				glvc_path = di_devfs_minor_path(minor);
				minor_name = di_minor_name(minor);

				if (strcmp(minor_name, "glvc") == 0) {
					dev_path = malloc(strlen(glvc_path) +
					    strlen(DEVICES_DIR) + 1);
					(void) strcpy(dev_path, DEVICES_DIR);
					(void) strcat(dev_path, glvc_path);
					di_devfs_path_free(glvc_path);
					break;
				}

				di_devfs_path_free(glvc_path);
				minor = di_minor_next(service_node, minor);
			}
		}
		if (dev_path != NULL)
			break;

		service_node = di_drv_next_node(service_node);
	}

	di_fini(root_node);
	return (dev_path);
}
Ejemplo n.º 3
0
/*
 * Walk all vldc device nodes to find the one with the
 * matching minor name
 */
static char *
svc_name_to_vldc_dev_path(char *service)
{
	di_node_t root_node, vldc_node;
	char *vldc_path;
	char *minor_name;
	di_minor_t minor;
	char *dev_path = NULL;

	/* Ensure that the 'vldc' driver is loaded */
	root_node = di_init_driver("vldc", DINFOCPYALL);
	if (root_node == DI_NODE_NIL) {
		return (dev_path);
	}

	vldc_node = di_drv_first_node("vldc", root_node);

	while (vldc_node != DI_NODE_NIL) {
		/* Walk minor nodes */
		minor = di_minor_next(vldc_node, DI_NODE_NIL);

		while (minor != DI_NODE_NIL) {
			vldc_path = di_devfs_minor_path(minor);
			minor_name = di_minor_name(minor);

			if (strcmp(minor_name, service) == 0) {
				dev_path = malloc(strlen(vldc_path) +
				    strlen(DEVICES_DIR) + 1);
				(void) strcpy(dev_path, DEVICES_DIR);
				(void) strcat(dev_path, vldc_path);
				di_devfs_path_free(vldc_path);
				break;
			}

			di_devfs_path_free(vldc_path);
			minor = di_minor_next(vldc_node, minor);
		}
		if (dev_path != NULL)
			break;

		vldc_node = di_drv_next_node(vldc_node);
	}

	di_fini(root_node);
	return (dev_path);
}
Ejemplo n.º 4
0
/*
 * Determine whether the interface was configured manually.
 */
static boolean_t
manual_if_init(void)
{
	boolean_t	ret = B_FALSE;
	char		*ncs;
	char		*devpath;
	di_node_t	node;
	int		instance;
	char		*drvname;
	char		ifname[IFNAMSIZ + 1];

	/*
	 * If net-config-strategy isn't "manual", don't go any further.
	 */
	if ((ncs = get_prop("chosen", BI_NET_CONFIG_STRATEGY, NULL)) == NULL ||
	    strcmp(ncs, "manual") != 0) {
		return (B_FALSE);
	}

	/*
	 * First check the 'bootpath' property of /chosen to see whether
	 * it specifies the path of a network device; if so, use this.
	 */
	if ((devpath = get_bootpath()) == NULL ||
	    (node = path2node(devpath)) == DI_NODE_NIL ||
	    !is_network_device(node)) {
		/*
		 * Must have been booted from CD-ROM or disk; attempt to
		 * use the path defined by the 'net' property of /aliases.
		 */
		free(devpath);
		if ((devpath = get_netalias()) == NULL ||
		    (node = path2node(devpath)) == DI_NODE_NIL ||
		    !is_network_device(node)) {
			goto cleanup;
		}
	}

	/*
	 * Get the driver name and instance number of this node.
	 * We may have to load the driver.
	 */
	if ((drvname = di_driver_name(node)) == NULL) {
		goto cleanup;
	}
	if ((instance = di_instance(node)) == -1) {
		di_node_t	tmp;

		/*
		 * Attempt to load the driver, create a new snapshot of the
		 * (possibly changed) device tree and re-compute our node.
		 */
		if ((tmp = di_init_driver(drvname, 0)) != DI_NODE_NIL) {
			di_fini(tmp);

			if (!snapshot_devtree() ||
			    (node = path2node(devpath)) == DI_NODE_NIL) {
				goto cleanup;
			}
		}
		instance = di_instance(node);
	}

	/*
	 * Construct the interface name.
	 */
	if (instance == -1) {
		(void) snprintf(ifname, sizeof (ifname),
		    "%s", di_driver_name(node));
	} else {
		(void) snprintf(ifname, sizeof (ifname),
		    "%s%d", di_driver_name(node), instance);
	}

	ret = netif_init(ifname, "manual");
cleanup:
	free(devpath);
	return (ret);
}