Exemplo n.º 1
0
static int
get_ethtool_link_settings(const ni_netdev_ref_t *ref, ni_ethtool_t *ethtool, struct ethtool_args *args)
{
	ni_ethtool_link_settings_t *link;
	const char *name;

	(void)args;
	if (ni_ethtool_get_link_settings(ref, ethtool) < 0 || !(link = ethtool->link_settings))
		return -1;

	printf("link-settings:\n");
	if (ni_tristate_is_set(link->autoneg))
		printf("\tautoneg: %s\n", ni_format_boolean(link->autoneg));
	if (link->speed != NI_ETHTOOL_SPEED_UNKNOWN)
		printf("\tspeed: %u\n", link->speed);
	if ((name = ni_ethtool_link_duplex_name(link->duplex)))
		printf("\tduplex: %s\n", name);
	if ((name = ni_ethtool_link_port_name(link->port)))
		printf("\tport: %s\n", name);
	if ((name = ni_ethtool_link_mdix_name(link->tp_mdix)))
		printf("\tmdix: %s\n", name);
	if ((name = ni_ethtool_link_mdio_name(link->mdio_support)))
		printf("\tmdio: %s\n", name);
	if (link->phy_address != NI_ETHTOOL_PHYAD_UNKNOWN)
		printf("\tphy-address: %u\n", link->phy_address);
	if (link->transceiver != NI_ETHTOOL_XCVR_UNKNOWN)
		printf("\ttransceiver: %u\n", link->transceiver);

	get_ethtool_link_advertising("supported", &link->supported);
	get_ethtool_link_advertising("advertising",  &link->advertising);
	get_ethtool_link_advertising("lp-advertising", &link->lp_advertising);
	return 0;
}
Exemplo n.º 2
0
static void
get_ethtool_link_advertising(const char *type, ni_bitfield_t *bitfield)
{
	ni_string_array_t tmp = NI_STRING_ARRAY_INIT;
	char *hexstr = NULL;
	unsigned int n;

	if (!ni_bitfield_isset(bitfield) || !type)
		return;

	printf("\t%s:\n", type);
	printf("\t\tautoneg: %s\n", ni_format_boolean(ni_ethtool_link_adv_autoneg(bitfield)));
	ni_ethtool_link_adv_set_autoneg(bitfield, FALSE);

	if (get_ethtool_link_adv_name_array(&tmp, bitfield, ni_ethtool_link_adv_port_name)) {
		printf("\t\tport-types:\n");
		for (n = 0; n < tmp.count; ++n) {
			printf("\t\t\ttype: %s\n", tmp.data[n]);
		}
	}
	ni_string_array_destroy(&tmp);

	if (get_ethtool_link_adv_name_array(&tmp, bitfield, ni_ethtool_link_adv_speed_name)) {
		printf("\t\tspeed-modes:\n");
		for (n = 0; n < tmp.count; ++n) {
			printf("\t\t\tmode: %s\n", tmp.data[n]);
		}
	}
	ni_string_array_destroy(&tmp);

	if (get_ethtool_link_adv_name_array(&tmp, bitfield, ni_ethtool_link_adv_pause_name)) {
		printf("\t\tpause-frames:\n");
		for (n = 0; n < tmp.count; ++n) {
			printf("\t\t\ttype: %s\n", tmp.data[n]);
		}
	}
	ni_string_array_destroy(&tmp);

	if (get_ethtool_link_adv_name_array(&tmp, bitfield, ni_ethtool_link_adv_fec_name)) {
		printf("\t\tfec-modes:\n");
		for (n = 0; n < tmp.count; ++n) {
			printf("\t\t\tmode: %s\n", tmp.data[n]);
		}
	}
	ni_string_array_destroy(&tmp);

	if (get_ethtool_link_adv_name_array(&tmp, bitfield, ni_ethtool_link_adv_port_name)) {
		printf("\t\tport-types:\n");
		for (n = 0; n < tmp.count; ++n) {
			printf("\t\t\ttype: %s\n", tmp.data[n]);
		}
	}
	ni_string_array_destroy(&tmp);

	if (ni_bitfield_isset(bitfield) && ni_bitfield_format(bitfield, &hexstr, TRUE))
		printf("\t\tunknown: %s\n", hexstr);
	ni_string_free(&hexstr);
}
Exemplo n.º 3
0
/*
 * link-detected
 */
static int
get_ethtool_link_detected(const ni_netdev_ref_t *ref, ni_ethtool_t *ethtool, struct ethtool_args *args)
{
	(void)args;
	if (ni_ethtool_get_link_detected(ref, ethtool) < 0 || !ni_tristate_is_set(ethtool->link_detected))
		return -1;

	printf("link-detected: %s\n", ni_format_boolean(ethtool->link_detected));
	return 0;
}
Exemplo n.º 4
0
int
ni_ethtool_set_priv_flags(const char *ifname, ni_ethtool_t *ethtool, const ni_ethtool_priv_flags_t *pflags)
{
	static const ni_ethtool_cmd_info_t NI_ETHTOOL_CMD_SPFLAGS = {
		ETHTOOL_SPFLAGS,	"set priv-flags"
	};
	struct ethtool_value ecmd;
	unsigned int i, bit;
	const char *name;
	ni_bool_t enabled;
	int ret;

	if (!pflags || !pflags->names.count)
		return 1; /* nothing to set */
	if (!ethtool->priv_flags && (ret = ni_ethtool_get_priv_flags(ifname, ethtool)) < 0)
		return ret;
	if (!ethtool->priv_flags || !ethtool->priv_flags->names.count)
		return -EOPNOTSUPP;

	memset(&ecmd, 0, sizeof(ecmd));
	ecmd.data = ethtool->priv_flags->bitmap;
	/* set every single bit separately in case one fails? */
	for (i = 0; i < pflags->names.count; ++i) {
		name = pflags->names.data[i];
		if (ni_string_empty(name))
			continue;

		enabled = !!(pflags->bitmap & NI_BIT(i));
		bit = ni_string_array_index(&ethtool->priv_flags->names, name);
		if (bit == -1U) {
			ni_info("%s: unable to set unknown driver private flag '%s'",
					ifname, name);
			continue;
		}

		ni_debug_verbose(NI_LOG_DEBUG1, NI_TRACE_IFCONFIG,
				"%s: setting driver private flag '%s' to %s",
				ifname, name, ni_format_boolean(enabled));
		if (enabled)
			ecmd.data |= NI_BIT(bit);
		else
			ecmd.data &= ~NI_BIT(bit);
	}
	if (ecmd.data == ethtool->priv_flags->bitmap)
		return 0;

	ret = ni_ethtool_call(ifname, &NI_ETHTOOL_CMD_SPFLAGS, &ecmd, NULL);
	ni_ethtool_set_supported(ethtool, NI_ETHTOOL_SUPP_SET_PRIV_FLAGS,
				ret != -EOPNOTSUPP);
	if (ret < 0)
		return ret;

	return 0;
}
Exemplo n.º 5
0
int main(int argc, char **argv)
{
	ni_teamd_client_t *tdc;
	const char *command, *param1, *param2;
	char *val = NULL;
	ni_json_t *json;
	int rv = 0;

	if (argc < 3) {
		printf("Usage: teamd-test ifname command [param1] [param2]\n");
		return -2;
	}
	command = argv[2];
	param1 = argv[3];
	param2 = argv[4];

	if (ni_init("teamd-test") < 0)
		return -1;
	ni_config_teamd_enable(NI_CONFIG_TEAMD_CTL_DETECT_ONCE);

	tdc = ni_teamd_client_open(argv[1]);

	if (ni_string_eq(command, "state-item-get"))
		rv = ni_teamd_ctl_state_get_item(tdc, param1, &val);
	else if (ni_string_eq(command, "state-item-set"))
		rv = ni_teamd_ctl_state_set_item(tdc, param1, param2);
	else if (ni_string_eq(command, "state-dump"))
		rv = ni_teamd_ctl_state_dump(tdc, &val);
	else if (ni_string_eq(command, "config-dump"))
		rv = ni_teamd_ctl_config_dump(tdc, FALSE, &val);
	else if (ni_string_eq(command, "config-dump-actual"))
		rv = ni_teamd_ctl_config_dump(tdc, TRUE, &val);

	printf("%s\n", val ? val : ni_format_boolean(!!rv));

	if (val && (json = ni_json_parse_string(val))) {
		ni_stringbuf_t buf = NI_STRINGBUF_INIT_DYNAMIC;

		ni_json_format_string(&buf, json, NULL);
		printf("type<%s>: %s\n",
			ni_json_type_name(ni_json_type(json)), buf.string);
		ni_stringbuf_destroy(&buf);
		ni_json_free(json);
	} else if (val) {
		printf("json parsing error\n");
	}

	ni_string_free(&val);
	return rv;
}