Beispiel #1
0
/*
 * Property link_watch
 */
static dbus_bool_t
__ni_objectmodel_team_get_link_watch(const ni_dbus_object_t *object, const ni_dbus_property_t *property,
				ni_dbus_variant_t *result, DBusError *error)
{
	const ni_team_t *team;
	unsigned int i;

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

	if (!team->link_watch.count)
		return FALSE;

	ni_dbus_variant_init_dict(result);
	for (i = 0; i < team->link_watch.count; i++) {
		ni_team_link_watch_t *lw = team->link_watch.data[i];
		ni_dbus_variant_t *entry;
		ni_dbus_variant_t *dict;
		const char *name;

		if (!(name = ni_team_link_watch_type_to_name(lw->type)))
			continue;

		entry = ni_dbus_dict_add(result, "watch");
		ni_dbus_variant_init_struct(entry);
		ni_dbus_struct_add_string(entry, name);
		dict = ni_dbus_struct_add(entry);
		ni_dbus_variant_init_dict(dict);
		__ni_objectmodel_team_link_watch_to_dict(lw, dict, error, object, property);
	}
	return TRUE;
}
Beispiel #2
0
static dbus_bool_t
ni_objectmodel_ppp_get_mode(const ni_dbus_object_t *object, const ni_dbus_property_t *property,
				ni_dbus_variant_t *result, DBusError *error)
{
	ni_dbus_variant_t *dict;
	const ni_ppp_t *ppp;
	const char *mode;

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

	if (NI_PPP_MODE_UNKNOWN == ppp->mode.type)
		return ni_dbus_error_property_not_present(error, object->path, property->name);

	if (!(mode = ni_ppp_mode_type_to_name(ppp->mode.type))) {
		dbus_set_error(error, DBUS_ERROR_INVALID_ARGS,
				"bad property %s; unsupported mode type %u",
				property->name, ppp->mode.type);
		return FALSE;
	}

	ni_dbus_variant_init_struct(result);
	ni_dbus_struct_add_string(result, mode);
	dict = ni_dbus_struct_add(result);
	ni_dbus_variant_init_dict(dict);

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

			if (!ni_string_empty(pppoe->device.name))
				ni_dbus_dict_add_string(dict, "device", pppoe->device.name);
		}
		break;

	default:
		return FALSE;
	}

	return TRUE;
}
Beispiel #3
0
static dbus_bool_t
__ni_objectmodel_netif_get_port_id(const ni_dbus_object_t *object, const ni_dbus_property_t *property,
		                                        ni_dbus_variant_t *strct, DBusError *error)
{
	const ni_lldp_t *lldp;
	const char *kind;
	char default_kind[64];

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

	if (lldp->port_id.type == NI_LLDP_PORT_ID_INVALID)
		return ni_dbus_error_property_not_present(error, object->path, property->name);

	kind = __ni_objectmodel_port_id_type_to_name(lldp->port_id.type);
	if (kind == NULL) {
		dbus_set_error(error, DBUS_ERROR_INVALID_ARGS,
				"bad property %s; unsupported subtype %u", property->name, lldp->port_id.type);
		return FALSE;
	}
	snprintf(default_kind, sizeof(default_kind), "default-%s", kind);

	ni_dbus_variant_init_struct(strct);

	switch (lldp->port_id.type) {
	case NI_LLDP_PORT_ID_PORT_COMPONENT:
	case NI_LLDP_PORT_ID_INTERFACE_NAME:
	case NI_LLDP_PORT_ID_INTERFACE_ALIAS:
	case NI_LLDP_PORT_ID_AGENT_CIRCUIT_ID:
		if (lldp->chassis_id.string_value) {
			ni_dbus_struct_add_string(strct, kind);
			ni_dbus_struct_add_string(strct, lldp->chassis_id.string_value);
		} else {
			ni_dbus_struct_add_string(strct, default_kind);
		}
		break;

	case NI_LLDP_PORT_ID_MAC_ADDRESS:
		if (lldp->port_id.mac_addr_value.len != 0) {
			ni_dbus_struct_add_string(strct, kind);
			__ni_objectmodel_struct_add_hwaddr(strct, &lldp->port_id.mac_addr_value);
		} else {
			ni_dbus_struct_add_string(strct, default_kind);
		}
		break;

	case NI_LLDP_PORT_ID_NETWORK_ADDRESS:
		if (lldp->port_id.net_addr_value.ss_family != AF_UNSPEC) {
			ni_dbus_struct_add_string(strct, kind);
			__ni_objectmodel_struct_add_sockaddr(strct, &lldp->port_id.net_addr_value);
		} else {
			ni_dbus_struct_add_string(strct, default_kind);
		}
		break;

	default:
		ni_error("LLDP port-id: unsupported subtype %u", lldp->port_id.type);
		return FALSE;
	}

	return TRUE;
}
Beispiel #4
0
static dbus_bool_t
__ni_objectmodel_team_get_runner(const ni_dbus_object_t *object, const ni_dbus_property_t *property,
				ni_dbus_variant_t *result, DBusError *error)
{
	ni_dbus_variant_t *dict;
	const ni_team_t *team;
	const char *name;

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

	if (!team->runner.type)
		return ni_dbus_error_property_not_present(error, object->path, property->name);

	if (!(name = ni_team_runner_type_to_name(team->runner.type))) {
		dbus_set_error(error, DBUS_ERROR_INVALID_ARGS,
				"bad property %s; unsupported runner name type %u",
				property->name, team->runner.type);
		return FALSE;
	}

	ni_dbus_variant_init_struct(result);
	ni_dbus_struct_add_string(result, name);
	dict = ni_dbus_struct_add(result);
	ni_dbus_variant_init_dict(dict);

	switch (team->runner.type) {
	case NI_TEAM_RUNNER_ACTIVE_BACKUP: {
			const ni_team_runner_active_backup_t *ab = &team->runner.ab;
			ni_dbus_dict_add_uint32(dict, "hwaddr_policy", ab->config.hwaddr_policy);
		}
		break;

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

			ni_dbus_dict_add_uint32(dict, "tx_hash", lb->config.tx_hash);
			txb = ni_dbus_dict_add(dict, "tx_balancer");
			ni_dbus_variant_init_dict(txb);
			ni_dbus_dict_add_uint32(txb, "name", lb->config.tx_balancer.type);
			ni_dbus_dict_add_uint32(txb, "balancing_interval", lb->config.tx_balancer.interval);
		}
		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: {
			const ni_team_runner_lacp_t *lacp = &team->runner.lacp;
			ni_dbus_variant_t *txb;

			ni_dbus_dict_add_bool(dict, "active", lacp->config.active);
			ni_dbus_dict_add_bool(dict, "fast_rate", lacp->config.fast_rate);
			ni_dbus_dict_add_uint16(dict, "sys_prio", lacp->config.sys_prio);
			ni_dbus_dict_add_uint16(dict, "min_ports", lacp->config.min_ports);
			ni_dbus_dict_add_uint32(dict, "select_policy", lacp->config.select_policy);

			ni_dbus_dict_add_uint32(dict, "tx_hash", lacp->config.tx_hash);
			txb = ni_dbus_dict_add(dict, "tx_balancer");
			ni_dbus_variant_init_dict(txb);
			ni_dbus_dict_add_uint32(txb, "name", lacp->config.tx_balancer.type);
			ni_dbus_dict_add_uint32(txb, "balancing_interval", lacp->config.tx_balancer.interval);
		}
		break;

	default:
		return FALSE;
	}
	return TRUE;
}