コード例 #1
0
ファイル: team.c プロジェクト: mtomaschewski/wicked
static dbus_bool_t
__ni_objectmodel_team_set_link_watch(ni_dbus_object_t *object, const ni_dbus_property_t *property,
				const ni_dbus_variant_t *argument, DBusError *error)
{
	const ni_dbus_variant_t *entry;
	ni_team_t *team;
	unsigned int i;

	if (!(team = __ni_objectmodel_team_write_handle(object, error)))
		return FALSE;

	if (!ni_dbus_variant_is_dict(argument))
		return FALSE;

	i = 0; entry = NULL;
	while ((entry = ni_dbus_dict_get_next(argument, "watch", entry))) {
		const ni_dbus_variant_t *dict;
		ni_team_link_watch_type_t type;
		ni_team_link_watch_t *lw;
		const char *name;

		if (!ni_dbus_struct_get_string(entry, 0, &name)) {
			dbus_set_error(error, DBUS_ERROR_INVALID_ARGS,
					"bad array element %u value for property %s; missed subtype",
					i, property->name);
			return FALSE;
		}

		if (!ni_team_link_watch_name_to_type(name, &type)) {
			dbus_set_error(error, DBUS_ERROR_INVALID_ARGS,
					"bad array element %u for property %s; unsupported subtype %s",
					i, property->name, name);
			return FALSE;
		}

		if (!(dict = ni_dbus_struct_get(entry, 1))) {
			dbus_set_error(error, DBUS_ERROR_INVALID_ARGS,
					"missed team link_watch member dict in array element %u", i);
			return FALSE;
		}

		if (!ni_dbus_variant_is_dict(dict)) {
			dbus_set_error(error, DBUS_ERROR_INVALID_ARGS,
					"team link_watch array element %u is not a dict", i);
			return FALSE;
		}

		lw = ni_team_link_watch_new(type);
		if (!__ni_objectmodel_team_link_watch_from_dict(lw, dict, error, property)) {
			ni_team_link_watch_free(lw);
			return FALSE;
		}

		ni_team_link_watch_array_append(&team->link_watch, lw);
		i++;
	}
	return TRUE;
}
コード例 #2
0
ファイル: lldp.c プロジェクト: mchf/wicked
/*
 * Query the chassis-id attribute
 */
static dbus_bool_t
__ni_objectmodel_netif_set_chassis_id(ni_dbus_object_t *object, const ni_dbus_property_t *property,
		                                        const ni_dbus_variant_t *strct, DBusError *error)
{
	ni_dbus_variant_t *member;
	const char *kind;
	ni_lldp_t *lldp;
	int type;

	if (!(lldp = __ni_objectmodel_lldp_write_handle(object, error)))
		return FALSE;

	if (!ni_dbus_struct_get_string(strct, 0, &kind))
		return FALSE;

	if (!strncmp(kind, "default-", 8)) {
		/* For "default-$foobar" types, there's no subsequent members in this struct */
		member = NULL;
		kind += 8;
	} else {
		if (!(member = ni_dbus_struct_get(strct, 1)))
			return FALSE;
	}

	if ((type = __ni_objectmodel_chassis_id_name_to_type(kind)) < 0) {
		dbus_set_error(error, DBUS_ERROR_INVALID_ARGS,
				"bad value for property %s; unsupported subtype %s", property->name, kind);
		return FALSE;
	}

	switch (type) {
	case NI_LLDP_CHASSIS_ID_INTERFACE_NAME:
	case NI_LLDP_CHASSIS_ID_INTERFACE_ALIAS:
	case NI_LLDP_CHASSIS_ID_CHASSIS_COMPONENT:
	case NI_LLDP_CHASSIS_ID_PORT_COMPONENT:
		if (!try_set_string(member, &lldp->chassis_id.string_value))
			return FALSE;
		break;

	case NI_LLDP_CHASSIS_ID_MAC_ADDRESS:
		if (!try_set_mac_address(member, &lldp->chassis_id.mac_addr_value))
			return FALSE;
		break;

	case NI_LLDP_CHASSIS_ID_NETWORK_ADDRESS:
		if (!try_set_net_address(member, &lldp->chassis_id.net_addr_value))
			return FALSE;
		break;

	default:
		ni_error("%s: don't know how to handle chassis-id subtype %s", __func__, kind);
		return FALSE;
	}

	return TRUE;
}
コード例 #3
0
ファイル: ppp.c プロジェクト: mtomaschewski/wicked
static dbus_bool_t
ni_objectmodel_ppp_set_mode(ni_dbus_object_t *object, const ni_dbus_property_t *property,
				const ni_dbus_variant_t *argument, DBusError *error)
{
	ni_dbus_variant_t *dict;
	const char *mode;
	ni_ppp_t *ppp;

	if (!(ppp = ni_objectmodel_ppp_handle(object, TRUE, error)))
		return FALSE;

	if (!ni_dbus_struct_get_string(argument, 0, &mode)) {
		dbus_set_error(error, DBUS_ERROR_INVALID_ARGS,
				"bad value for property %s; missed subtype", property->name);
		return FALSE;
	}

	if (!ni_ppp_mode_name_to_type(mode, &ppp->mode.type)) {
		dbus_set_error(error, DBUS_ERROR_INVALID_ARGS,
				"bad value for property %s; unsupported subtype %s", property->name, mode);
		return FALSE;
	}

	if (!(dict = ni_dbus_struct_get(argument, 1))) {
		dbus_set_error(error, DBUS_ERROR_INVALID_ARGS, "missed ppp mode member dict");
		return FALSE;
	}
	if (!ni_dbus_variant_is_dict(dict)) {
		dbus_set_error(error, DBUS_ERROR_INVALID_ARGS, "ppp mode member is not a dict");
		return FALSE;
	}

	ni_ppp_mode_init(&ppp->mode, ppp->mode.type);
	switch (ppp->mode.type) {
	case NI_PPP_MODE_PPPOE: {
			ni_ppp_mode_pppoe_t *pppoe = &ppp->mode.pppoe;
			const char *string;

			if (ni_dbus_dict_get_string(dict, "device", &string))
				ni_netdev_ref_set_ifname(&pppoe->device, string);
		}
		break;

	default:
		return FALSE;
	}

	return TRUE;
}
コード例 #4
0
ファイル: team.c プロジェクト: mtomaschewski/wicked
static dbus_bool_t
__ni_objectmodel_team_set_runner(ni_dbus_object_t *object, const ni_dbus_property_t *property,
				const ni_dbus_variant_t *argument, DBusError *error)
{
	ni_dbus_variant_t *dict;
	const char *name;
	ni_team_t *team;

	if (!(team = __ni_objectmodel_team_write_handle(object, error)))
		return FALSE;

	if (!ni_dbus_struct_get_string(argument, 0, &name)) {
		dbus_set_error(error, DBUS_ERROR_INVALID_ARGS,
				"bad value for property %s; missed subtype", property->name);
		return FALSE;
	}

	if (!ni_team_runner_name_to_type(name, &team->runner.type)) {
		dbus_set_error(error, DBUS_ERROR_INVALID_ARGS,
				"bad value for property %s; unsupported subtype %s", property->name, name);
		return FALSE;
	}

	if (!(dict = ni_dbus_struct_get(argument, 1))) {
		dbus_set_error(error, DBUS_ERROR_INVALID_ARGS, "missed team runner member dict");
		return FALSE;
	}
	if (!ni_dbus_variant_is_dict(dict)) {
		dbus_set_error(error, DBUS_ERROR_INVALID_ARGS, "team runner member is not a dict");
		return FALSE;
	}

	ni_team_runner_init(&team->runner, team->runner.type);
	switch (team->runner.type) {
	case NI_TEAM_RUNNER_ACTIVE_BACKUP: {
			ni_team_runner_active_backup_t *ab = &team->runner.ab;
			uint32_t u32;

			if (ni_dbus_dict_get_uint32(dict, "hwaddr_policy", &u32))
				ab->config.hwaddr_policy = u32;
			else
				ab->config.hwaddr_policy = NI_TEAM_AB_HWADDR_POLICY_SAME_ALL;
		}
		break;

	case NI_TEAM_RUNNER_LOAD_BALANCE: {
			ni_team_runner_load_balance_t *lb = &team->runner.lb;
			ni_dbus_variant_t *txb;
			uint32_t u32;

			if (ni_dbus_dict_get_uint32(dict, "tx_hash", &u32))
				lb->config.tx_hash = u32;
			else	lb->config.tx_hash = NI_TEAM_TX_HASH_NONE;

			txb = ni_dbus_dict_get(dict, "tx_balancer");
			if (txb) {
				if (ni_dbus_dict_get_uint32(txb, "name", &u32) &&
				    ni_team_tx_balancer_type_to_name(u32))
					lb->config.tx_balancer.type = u32;
				else	lb->config.tx_balancer.type = NI_TEAM_TX_BALANCER_BASIC;
				if (ni_dbus_dict_get_uint32(txb, "balancing_interval", &u32))
					lb->config.tx_balancer.interval = u32;
				else	lb->config.tx_balancer.interval = 50;
			}
		}
		break;

	case NI_TEAM_RUNNER_ROUND_ROBIN:
		break;

	case NI_TEAM_RUNNER_BROADCAST:
		break;

	case NI_TEAM_RUNNER_RANDOM:
		break;

	case NI_TEAM_RUNNER_LACP: {
			ni_team_runner_lacp_t *lacp = &team->runner.lacp;
			ni_dbus_variant_t *txb;
			dbus_bool_t b;
			uint16_t u16;
			uint32_t u32;

			if (ni_dbus_dict_get_bool(dict, "active", &b))
				lacp->config.active = b;
			else	lacp->config.active = TRUE;

			if (ni_dbus_dict_get_uint16(dict, "sys_prio", &u16))
				lacp->config.sys_prio = u16;
			else	lacp->config.sys_prio = 255;

			if (ni_dbus_dict_get_bool(dict, "fast_rate", &b))
				lacp->config.fast_rate = b;
			else	lacp->config.fast_rate = FALSE;

			if (ni_dbus_dict_get_uint16(dict, "min_ports", &u16) && u16 < 256)
				lacp->config.sys_prio = u16;
			else	lacp->config.sys_prio = 0;

			if (ni_dbus_dict_get_uint32(dict, "select_policy", &u32))
				lacp->config.select_policy = u32;
			else	lacp->config.select_policy = NI_TEAM_LACP_SELECT_POLICY_PRIO;

			if (ni_dbus_dict_get_uint32(dict, "tx_hash", &u32))
				lacp->config.tx_hash = u32;
			else	lacp->config.tx_hash = NI_TEAM_TX_HASH_NONE;

			txb = ni_dbus_dict_get(dict, "tx_balancer");
			if (txb) {
				if (ni_dbus_dict_get_uint32(txb, "name", &u32) &&
				    ni_team_tx_balancer_type_to_name(u32))
					lacp->config.tx_balancer.type = u32;
				else	lacp->config.tx_balancer.type = NI_TEAM_TX_BALANCER_BASIC;
				if (ni_dbus_dict_get_uint32(txb, "balancing_interval", &u32))
					lacp->config.tx_balancer.interval = u32;
				else	lacp->config.tx_balancer.interval = 50;
			}
		}
		break;

	default:
		return FALSE;
	}
	return TRUE;
}