Exemplo n.º 1
0
static dbus_bool_t
__ni_objectmodel_ovs_bridge_get_ports(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_ovs_bridge_t *ovsbr;
	unsigned int i;

	ni_dbus_dict_array_init(result);

	if (!(ovsbr = __ni_objectmodel_ovs_bridge_read_handle(object, error)))
		return ni_dbus_error_property_not_present(error, object->path, property->name);

	for (i = 0; i < ovsbr->ports.count; ++i) {
		const ni_ovs_bridge_port_t *port = ovsbr->ports.data[i];

		if (!port || ni_string_empty(port->device.name))
			continue;

		if (!(dict = ni_dbus_dict_array_add(result)))
			return FALSE;

		ni_dbus_variant_init_dict(dict);
		if (!__ni_objectmodel_ovs_bridge_port_to_dict(port, dict, error))
			return FALSE;
	}
	return TRUE;
}
Exemplo n.º 2
0
/*
 * OVS Bridge vlan
 */
static dbus_bool_t
__ni_objectmodel_ovs_bridge_get_vlan(const ni_dbus_object_t *object, const ni_dbus_property_t *property,
					ni_dbus_variant_t *result, DBusError *error)
{
	const ni_ovs_bridge_t *ovsbr;

	if (!(ovsbr = __ni_objectmodel_ovs_bridge_read_handle(object, error)))
		return ni_dbus_error_property_not_present(error, object->path, property->name);

	if (ni_string_empty(ovsbr->config.vlan.parent.name))
		return ni_dbus_error_property_not_present(error, object->path, property->name);

	ni_dbus_variant_init_dict(result);
	ni_dbus_dict_add_string(result, "parent", ovsbr->config.vlan.parent.name);
	ni_dbus_dict_add_uint16(result, "tag", ovsbr->config.vlan.tag);
	return TRUE;
}
Exemplo n.º 3
0
/*
 * Get/set MII monitoring info
 */
static dbus_bool_t
__ni_objectmodel_bonding_get_miimon(const ni_dbus_object_t *object,
				const ni_dbus_property_t *property,
				ni_dbus_variant_t *result,
				DBusError *error)
{
	const ni_bonding_t *bond;

	if (!(bond = __ni_objectmodel_bonding_read_handle(object, error)))
		return FALSE;

	if (bond->monitoring != NI_BOND_MONITOR_MII)
		return ni_dbus_error_property_not_present(error, object->path, property->name);

	ni_dbus_dict_add_uint32(result, "frequency", bond->miimon.frequency);
	ni_dbus_dict_add_uint32(result, "updelay", bond->miimon.updelay);
	ni_dbus_dict_add_uint32(result, "downdelay", bond->miimon.downdelay);
	ni_dbus_dict_add_uint32(result, "carrier-detect", bond->miimon.carrier_detect);
	return TRUE;
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
0
/*
 * Get/set ARP monitoring info
 */
static dbus_bool_t
__ni_objectmodel_bonding_get_arpmon(const ni_dbus_object_t *object,
				const ni_dbus_property_t *property,
				ni_dbus_variant_t *result,
				DBusError *error)
{
	const ni_bonding_t *bond;
	ni_dbus_variant_t *var;

	if (!(bond = __ni_objectmodel_bonding_read_handle(object, error)))
		return FALSE;

	if (bond->monitoring != NI_BOND_MONITOR_ARP)
		return ni_dbus_error_property_not_present(error, object->path, property->name);

	ni_dbus_dict_add_uint32(result, "interval", bond->arpmon.interval);
	ni_dbus_dict_add_uint32(result, "validate", bond->arpmon.validate);
	var = ni_dbus_dict_add(result, "targets");
	ni_dbus_variant_set_string_array(var,
			(const char **) bond->arpmon.targets.data,
			bond->arpmon.targets.count);
	return TRUE;
}
Exemplo n.º 6
0
Arquivo: lldp.c Projeto: mchf/wicked
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;
}
Exemplo n.º 7
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;
}