Beispiel #1
0
/*ARGSUSED*/
static dladm_status_t
print_flow(show_flow_state_t *state, dladm_flow_attr_t *attr,
    flow_fields_buf_t *fbuf)
{
	char		link[MAXLINKNAMELEN];
	dladm_status_t	status;

	if ((status = dladm_datalink_id2info(handle, attr->fa_linkid, NULL,
	    NULL, NULL, link, sizeof (link))) != DLADM_STATUS_OK) {
		return (status);
	}

	(void) snprintf(fbuf->flow_name, sizeof (fbuf->flow_name),
	    "%s", attr->fa_flowname);
	(void) snprintf(fbuf->flow_link, sizeof (fbuf->flow_link),
	    "%s", link);

	(void) dladm_flow_attr_ip2str(attr, fbuf->flow_ipaddr,
	    sizeof (fbuf->flow_ipaddr));
	(void) dladm_flow_attr_proto2str(attr, fbuf->flow_proto,
	    sizeof (fbuf->flow_proto));
	if ((attr->fa_flow_desc.fd_mask & FLOW_ULP_PORT_LOCAL) != 0) {
		(void) dladm_flow_attr_port2str(attr, fbuf->flow_lport,
		    sizeof (fbuf->flow_lport));
	}
	if ((attr->fa_flow_desc.fd_mask & FLOW_ULP_PORT_REMOTE) != 0) {
		(void) dladm_flow_attr_port2str(attr, fbuf->flow_rport,
		    sizeof (fbuf->flow_rport));
	}
	(void) dladm_flow_attr_dsfield2str(attr, fbuf->flow_dsfield,
	    sizeof (fbuf->flow_dsfield));

	return (DLADM_STATUS_OK);
}
Beispiel #2
0
int collect_link_names( dladm_handle_t handle,
                        datalink_id_t link_id, void* arg )
{
	char** it = arg;

	dladm_datalink_id2info( handle, link_id, NULL, NULL, NULL,
	                        *it, MAXLINKNAMELEN );

	*it += MAXLINKNAMELEN;

	return DLADM_WALK_CONTINUE;
}
Beispiel #3
0
vlan_infos_t* get_vlan_infos()
{
	char* links;
	int links_len = 0;

	dladm_walk_datalink_id( &count_links, handle, &links_len,
	                        DATALINK_CLASS_VLAN, DATALINK_ANY_MEDIATYPE,
	                        DLADM_OPT_ACTIVE | DLADM_OPT_PERSIST );

	char* links_it = links = malloc( links_len * MAXLINKNAMELEN );

	dladm_walk_datalink_id( &collect_link_names, handle, &links_it,
	                        DATALINK_CLASS_VLAN, DATALINK_ANY_MEDIATYPE,
	                        DLADM_OPT_ACTIVE | DLADM_OPT_PERSIST );

	vlan_infos_t* infos = malloc_vlan_infos( links_len );
	infos->len = links_len;

	for ( int i = 0; i < links_len; ++i )
	{
		char* name = links + i * MAXLINKNAMELEN;
		datalink_id_t vlanid = { 0 };
		dladm_vlan_attr_t	vinfo;
		char parent[ MAXLINKNAMELEN ] = { 0 };

		strcpy( infos->vlan_infos[ i ]->name, name );

		if ( DLADM_STATUS_OK != dladm_name2info( handle, name, &vlanid,
		                                         NULL, NULL, NULL ) )
		{
		}
		else
		{
			dladm_vlan_info( handle, vlanid, &vinfo, DLADM_OPT_ACTIVE );

			if ( DLADM_STATUS_OK != dladm_datalink_id2info( handle, vinfo.dv_linkid,
			                                                NULL, NULL, NULL,
			                                                parent, sizeof( parent ) ) )
			{
			}
			else
			{
				infos->vlan_infos[ i ]->tag = vinfo.dv_vid;
				strcpy( infos->vlan_infos[ i ]->link, parent );
			}
		}
	}

	free( links );

	return infos;
}
Beispiel #4
0
/*
 * Wrapper of dladm_walk_flow(show_walk_fn,...) to make it
 * usable to dladm_walk_datalink_id()
 */
static int
show_flowprop_onelink(dladm_handle_t dh, datalink_id_t linkid, void *arg)
{
	char	name[MAXLINKNAMELEN];

	if (dladm_datalink_id2info(dh, linkid, NULL, NULL, NULL, name,
	    sizeof (name)) != DLADM_STATUS_OK)
		return (DLADM_WALK_TERMINATE);

	(void) dladm_walk_flow(show_flowprop, dh, linkid, arg, B_FALSE);

	return (DLADM_WALK_CONTINUE);
}
Beispiel #5
0
static int dladm_callback(dladm_handle_t dh, datalink_id_t linkid, void *obj) {
	dladm_status_t		status;
	char			link[MAXLINKNAMELEN];
	datalink_class_t	dl_class;
	uint32_t		flags;
	std::list<std::string> *interfaces = (std::list<std::string> *)(obj);

	if ((status = dladm_datalink_id2info(g_handle, linkid, &flags, &dl_class,
	    NULL, link, sizeof (link))) != DLADM_STATUS_OK) {
		return (status);
	}

	interfaces->push_back(link);

	return (DLADM_WALK_CONTINUE);
}
char* get_etherstub_parameter( char *name, char* parameter)
{

	dladm_status_t status;
	datalink_class_t	class;
	datalink_id_t linkid;
	uint_t		maxpropertycnt = 1;
	uint32_t	flags = DLADM_OPT_ACTIVE;

	status = dladm_name2info(handle, name, &linkid, NULL, &class,
	    NULL);

	if (status != DLADM_STATUS_OK)
		return NULL;

	char *value = (char*)malloc(MAXLENGTH);

	dladm_vnic_attr_t	vinfo;

	if(strcasecmp("OVER", parameter) == 0)
	{
		if (dladm_vnic_info(handle, linkid, &vinfo, flags) !=
		    DLADM_STATUS_OK) {
			(void) strcpy(value, "?");
			return value;
		}
		
		if (dladm_datalink_id2info(handle, vinfo.va_link_id, NULL, NULL,
		    NULL, value, MAXLENGTH) != DLADM_STATUS_OK)
			(void) strcpy(value, "?");
	}
	else if(strcasecmp("MTU", parameter) == 0 || strcasecmp("BRIDGE", parameter) == 0 || strcasecmp("STATE", parameter) == 0)
	{
		status = dladm_get_linkprop(handle, linkid,
			    DLADM_PROP_VAL_CURRENT, parameter, &value, &maxpropertycnt);
	}
	else if(strcasecmp("CLASS", parameter) == 0)
	{
		(void) dladm_class2str(class, value);
	}
Beispiel #7
0
/*ARGSUSED*/
static int
net_getinfo(rcm_handle_t *hd, char *rsrc, id_t id, uint_t flag,
    char **info, char **errstr, nvlist_t *proplist, rcm_info_t **depend_info)
{
	int		len;
	dladm_status_t	status;
	char		link[MAXLINKNAMELEN];
	char		errmsg[DLADM_STRSIZE];
	char		*exported;
	const char	*info_fmt;
	net_cache_t	*node;

	assert(hd != NULL);
	assert(rsrc != NULL);
	assert(id == (id_t)0);
	assert(info != NULL);
	assert(depend_info != NULL);

	rcm_log_message(RCM_TRACE1, _("NET: getinfo(%s)\n"), rsrc);

	info_fmt = _("Network interface %s");

	(void) mutex_lock(&cache_lock);
	node = cache_lookup(rsrc);
	if (!node) {
		rcm_log_message(RCM_WARNING,
		    _("NET: unrecognized resource %s\n"), rsrc);
		(void) mutex_unlock(&cache_lock);
		errno = ENOENT;
		return (RCM_FAILURE);
	}

	len = strlen(info_fmt) + MAXLINKNAMELEN + 1;
	if ((status = dladm_datalink_id2info(dld_handle, node->linkid, NULL,
	    NULL, NULL, link, sizeof (link))) != DLADM_STATUS_OK) {
		rcm_log_message(RCM_ERROR,
		    _("NET: usage(%s) get link name failure(%s)\n"),
		    node->resource, dladm_status2str(status, errmsg));
		(void) mutex_unlock(&cache_lock);
		return (RCM_FAILURE);
	} else if ((*info = (char *)malloc(len)) == NULL) {
		rcm_log_message(RCM_ERROR, _("NET: malloc failure"));
		(void) mutex_unlock(&cache_lock);
		return (RCM_FAILURE);
	}

	/* Fill in the string */
	(void) snprintf(*info, len, info_fmt, link);

	len = strlen("SUNW_datalink/") + LINKID_STR_WIDTH + 1;
	exported = malloc(len);
	if (!exported) {
		rcm_log_message(RCM_ERROR, _("NET: allocation failure"));
		free(*info);
		(void) mutex_unlock(&cache_lock);
		return (RCM_FAILURE);
	}
	(void) snprintf(exported, len, "SUNW_datalink/%u", node->linkid);
	(void) mutex_unlock(&cache_lock);

	/* Get dependent info if requested */
	if ((flag & RCM_INCLUDE_DEPENDENT) || (flag & RCM_INCLUDE_SUBTREE)) {
		(void) rcm_get_info(hd, exported, flag, depend_info);
	}

	(void) nvlist_add_string(proplist, RCM_CLIENT_NAME, "SunOS");
	(void) nvlist_add_string_array(proplist, RCM_CLIENT_EXPORTS,
	    &exported, 1);

	free(exported);
	return (RCM_SUCCESS);
}
Beispiel #8
0
static int
dltran_dump_transceivers(dladm_handle_t hdl, datalink_id_t linkid, void *arg)
{
	dladm_status_t status;
	char name[MAXLINKNAMELEN];
	dld_ioc_gettran_t gt;
	uint_t count, i, tranid = UINT_MAX;
	boolean_t tran_found = B_FALSE;
	uint_t *tranidp = arg;

	if (tranidp != NULL)
		tranid = *tranidp;

	if ((status = dladm_datalink_id2info(hdl, linkid, NULL, NULL, NULL,
	    name, sizeof (name))) != DLADM_STATUS_OK) {
		(void) fprintf(stderr, "failed to get datalink name for link "
		    "%d: %s", linkid, dladm_status2str(status,
		    dltran_dlerrmsg));
		dltran_errors++;
		return (DLADM_WALK_CONTINUE);
	}

	bzero(&gt, sizeof (gt));
	gt.dgt_linkid = linkid;
	gt.dgt_tran_id = DLDIOC_GETTRAN_GETNTRAN;

	if (ioctl(dladm_dld_fd(hdl), DLDIOC_GETTRAN, &gt) != 0) {
		if (errno != ENOTSUP) {
			(void) fprintf(stderr, "failed to get transceiver "
			    "count for device %s: %s\n",
			    name, strerror(errno));
			dltran_errors++;
		}
		return (DLADM_WALK_CONTINUE);
	}

	count = gt.dgt_tran_id;
	(void) printf("%s: discovered %d transceiver%s\n", name, count,
	    count > 1 ? "s" : "");
	for (i = 0; i < count; i++) {
		if (tranid != UINT_MAX && i != tranid)
			continue;
		if (tranid != UINT_MAX)
			tran_found = B_TRUE;
		bzero(&gt, sizeof (gt));
		gt.dgt_linkid = linkid;
		gt.dgt_tran_id = i;

		if (ioctl(dladm_dld_fd(hdl), DLDIOC_GETTRAN, &gt) != 0) {
			(void) fprintf(stderr, "failed to get tran info for "
			    "%s: %s\n", name, strerror(errno));
			dltran_errors++;
			return (DLADM_WALK_CONTINUE);
		}

		if (dltran_hex && !gt.dgt_present)
			continue;
		if (!dltran_hex && !dltran_write) {
			(void) printf("\ttransceiver %d present: %s\n", i,
			    gt.dgt_present ? "yes" : "no");
			if (!gt.dgt_present)
				continue;
			(void) printf("\ttransceiver %d usable: %s\n", i,
			    gt.dgt_usable ? "yes" : "no");
		}

		if (dltran_verbose) {
			dltran_verbose_dump(linkid, i);
		}

		if (dltran_write) {
			if (!gt.dgt_present) {
				(void) fprintf(stderr, "warning: no "
				    "transceiver present in port %d, not "
				    "writing\n", i);
				dltran_errors++;
				continue;
			}
			dltran_write_page(linkid, i);
		}

		if (dltran_hex) {
			printf("transceiver %d data:\n", i);
			dltran_hex_dump(linkid, i);
		}
	}

	if (tranid != UINT_MAX && !tran_found) {
		dltran_errors++;
		(void) fprintf(stderr, "failed to find transceiver %d on "
		    "link %s\n", tranid, name);
	}

	return (DLADM_WALK_CONTINUE);
}
Beispiel #9
0
static int
aoeadm_list_ports(int argc, char **argv)
{
	AOE_STATUS	ret;
	aoe_port_list_t	*portlist = NULL;
	char		c;
	dladm_handle_t	handle;
	int		i;
	int		portid = -1;
	int		verbose = 0;
	uint32_t	nports;

	while ((c = getopt(argc, argv, "v")) != -1) {
		switch (c) {
		case 'v':
			verbose = 1;
			break;
		default:
			usage();
		}
	}

	argc -= optind;
	argv += optind;

	if (argc == 1) {
		errno = 0;
		portid = strtol(argv[0], (char **)NULL, 10);
		if (errno != 0 || portid < 0)
			usage();
	}

	ret = aoe_get_port_list(&nports, &portlist);

	if (ret != AOE_STATUS_OK) {
		(void) fprintf(stderr, _("Failed to list ports: %s\n"),
		    aoe_strerror(ret));
		return (ret);
	}

	if (nports == 0) {
		free(portlist);
		return (0);
	}

	if (dladm_open(&handle) != DLADM_STATUS_OK)
		handle = NULL;

	for (i = 0; i < nports; i++) {
		aoe_port_instance_t *pi = &portlist->ports[i];
		char		linknames[AOE_MAX_MACOBJ * MAXLINKNAMELEN];
		int		j;

		if (portid >= 0 && pi->api_port_id != portid)
			continue;

		if ((pi->api_port_type == AOE_CLIENT_INITIATOR &&
		    strcmp(cmdname, "list-target") == 0) ||
		    (pi->api_port_type == AOE_CLIENT_TARGET &&
		    strcmp(cmdname, "list-initiator") == 0))
			continue;

		/* Convert linkid to interface name */
		for (j = 0; j < pi->api_mac_cnt; j++) {
			aoe_mac_instance_t *mi = &pi->api_mac[j];
			char	*linkname = linknames + j * MAXLINKNAMELEN;

			if (handle == NULL ||
			    dladm_datalink_id2info(handle, mi->ami_mac_linkid,
			    NULL, NULL, NULL, linkname, MAXLINKNAMELEN - 1) !=
			    DLADM_STATUS_OK)
				(void) strcpy(linkname, "<unknown>");
		}

		print_port_info(pi, linknames, verbose);

		if (portid >= 0) {
			if (handle != NULL)
				dladm_close(handle);
			free(portlist);
			return (0);
		}
	}

	if (handle != NULL)
		dladm_close(handle);
	free(portlist);

	return (portid >= 0 ? 1 : 0);
}
Beispiel #10
0
/*
 * Callback function that configures a single datalink in a non-global zone.
 */
static int
i_ipadm_zone_network_attr(dladm_handle_t dh, datalink_id_t linkid, void *arg)
{
	ngz_walk_data_t *nwd = arg;
	zoneid_t zoneid = nwd->ngz_zoneid;
	uint8_t buf[PIPE_BUF];
	dladm_status_t dlstatus;
	ipadm_status_t ipstatus;
	char link[MAXLINKNAMELEN];
	ipadm_handle_t iph = nwd->ngz_iph;
	int rtsock = iph->iph_rtsock;
	char *ifname = nwd->ngz_ifname;
	boolean_t s10c = nwd->ngz_s10c;
	boolean_t is_ipmgmtd = (iph->iph_flags & IPH_IPMGMTD);
	size_t bufsize = sizeof (buf);

	bzero(buf, bufsize);
	ipstatus = i_ipadm_zone_get_network(zoneid, linkid,
	    ZONE_NETWORK_ADDRESS, buf, &bufsize);
	if (ipstatus != IPADM_SUCCESS)
		goto fail;

	dlstatus = dladm_datalink_id2info(dh, linkid, NULL, NULL,
	    NULL, link, sizeof (link));
	if (dlstatus != DLADM_STATUS_OK)
		return (DLADM_WALK_CONTINUE);

	/*
	 * if ifname has been specified, then skip interfaces that don't match
	 */
	if (ifname != NULL && strcmp(ifname, link) != 0)
		return (DLADM_WALK_CONTINUE);

	/*
	 * Plumb the interface and configure addresses on for S10 Containers.
	 * We need to always do this for S10C because ipadm persistent
	 * configuration is not available in S10C. For ipkg zones,
	 * we skip the actual plumbing/configuration, but will call the
	 * (*ngz_persist_if)() callback to create the persistent state for the
	 * interface. The interface will be configured in ipkg zones when
	 * ipadm_enable_if() is invoked to restore persistent configuration.
	 */
	if (is_ipmgmtd && !s10c) {
		(void) i_ipadm_ngz_persist_if(link, (char *)buf,
		    nwd->ngz_persist_if);
		return (DLADM_WALK_CONTINUE);
	}
	ipstatus = i_ipadm_ngz_addr(iph, link, (char *)buf);
	if (ipstatus != IPADM_SUCCESS)
		goto fail;

	/* apply any default router information.  */
	bufsize = sizeof (buf);
	bzero(buf, bufsize);
	ipstatus = i_ipadm_zone_get_network(zoneid, linkid,
	    ZONE_NETWORK_DEFROUTER, buf, &bufsize);
	if (ipstatus != IPADM_SUCCESS)
		goto fail;

	i_ipadm_create_ngz_route(rtsock, link, buf, bufsize);

	return (DLADM_WALK_CONTINUE);
fail:
	if (ifname != NULL) {
		nwd->ngz_ipstatus = ipstatus;
		return (DLADM_WALK_TERMINATE);
	}
	return (DLADM_WALK_CONTINUE);
}