Beispiel #1
0
static NMIP6Device *
nm_ip6_device_new (NMIP6Manager *manager, int ifindex)
{
	NMIP6ManagerPrivate *priv = NM_IP6_MANAGER_GET_PRIVATE (manager);
	NMIP6Device *device;

	g_return_val_if_fail (ifindex > 0, NULL);

	device = g_slice_new0 (NMIP6Device);
	if (!device) {
		nm_log_err (LOGD_IP6, "(%d): out of memory creating IP6 addrconf object.",
		            ifindex);
		return NULL;
	}

	device->ifindex = ifindex;
	device->iface = g_strdup (nm_netlink_index_to_iface (ifindex));
	if (!device->iface) {
		nm_log_err (LOGD_IP6, "(%d): could not find interface name from index.",
		            ifindex);
		goto error;
	}

	device->manager = manager;

	device->rdnss_servers = g_array_new (FALSE, FALSE, sizeof (NMIP6RDNSS));

	device->dnssl_domains = g_array_new (FALSE, FALSE, sizeof (NMIP6DNSSL));

	g_hash_table_replace (priv->devices, GINT_TO_POINTER (device->ifindex), device);

	/* and the original value of IPv6 enable/disable */
	device->disable_ip6_path = g_strdup_printf ("/proc/sys/net/ipv6/conf/%s/disable_ipv6",
	                                            device->iface);
	g_assert (device->disable_ip6_path);
	device->disable_ip6_save_valid = nm_utils_get_proc_sys_net_value (device->disable_ip6_path,
	                                                                  device->iface,
	                                                                  &device->disable_ip6_save);

	return device;

error:
	nm_ip6_device_destroy (device);
	return NULL;
}
gboolean
nm_utils_get_proc_sys_net_value_with_bounds (const char *path,
                                             const char *iface,
                                             gint32 *out_value,
                                             gint32 valid_min,
                                             gint32 valid_max)
{
	gboolean result;
	gint32 val;

	result = nm_utils_get_proc_sys_net_value (path, iface, &val);

	if (result) {
		if (val >= valid_min && val <= valid_max)
			*out_value = val;
		else
			result = FALSE;
	}

	return result;
}