static struct in6_addr *
get_ip6_next_hop (gchar * next_hop)
{
	gchar *tmp;
	struct in6_addr *tmp_ip6_addr = g_slice_new0 (struct in6_addr);

	if (!next_hop)
		return 0;
	tmp = find_gateway_str (next_hop);
	if (!tmp) {
		PLUGIN_WARN (IFNET_PLUGIN_NAME,
			     "Couldn't obtain next_hop in \"%s\"", next_hop);
		return 0;
	}
	tmp = g_strdup (tmp);
	strip_string (tmp, ' ');
	strip_string (tmp, '"');
	g_strstrip (tmp);
	if (!inet_pton (AF_INET6, tmp, tmp_ip6_addr))
		goto error;
	g_free (tmp);
	return tmp_ip6_addr;
      error:
	if (!is_ip4_address (tmp))
		PLUGIN_WARN (IFNET_PLUGIN_NAME,
			     "Can't handle IPv6 next_hop: %s", tmp);
	g_free (tmp);
	g_slice_free (struct in6_addr, tmp_ip6_addr);

	return NULL;
}
static guint32
get_ip4_gateway (gchar * gateway)
{
	gchar *tmp, *split;
	struct in_addr tmp_ip4_addr;

	if (!gateway)
		return 0;
	tmp = find_gateway_str (gateway);
	if (!tmp) {
		PLUGIN_WARN (IFNET_PLUGIN_NAME,
			     "Couldn't obtain gateway in \"%s\"", gateway);
		return 0;
	}
	tmp = g_strdup (tmp);
	strip_string (tmp, ' ');
	strip_string (tmp, '"');
	if ((split = strstr (tmp, "\"")) != NULL)
		*split = '\0';
	if (!inet_pton (AF_INET, tmp, &tmp_ip4_addr))
		goto error;
	g_free (tmp);
	return tmp_ip4_addr.s_addr;
      error:
	if (!is_ip6_address (tmp))
		PLUGIN_WARN (IFNET_PLUGIN_NAME, "Can't handle IPv4 gateway: %s",
			     tmp);
	g_free (tmp);
	return 0;
}
Exemplo n.º 3
0
static char *
get_ip6_next_hop (gchar * next_hop)
{
	gchar *tmp;

	if (!next_hop)
		return NULL;
	tmp = find_gateway_str (next_hop);
	if (!tmp) {
		nm_log_warn (LOGD_SETTINGS, "Couldn't obtain next_hop in \"%s\"", next_hop);
		return NULL;
	}
	tmp = g_strdup (tmp);
	strip_string (tmp, ' ');
	strip_string (tmp, '"');
	g_strstrip (tmp);
	if (!nm_utils_ipaddr_valid (AF_INET6, tmp))
		goto error;
	return tmp;
error:
	if (!is_ip4_address (tmp))
		nm_log_warn (LOGD_SETTINGS, "Can't handle IPv6 next_hop: %s", tmp);
	g_free (tmp);

	return NULL;
}
Exemplo n.º 4
0
ip_block *
convert_ip4_routes_block (const char *conn_name)
{
	gchar **ipset;
	guint length;
	guint i;
	gchar *ip;
	ip_block *start = NULL, *current = NULL, *iblock = NULL;

	g_return_val_if_fail (conn_name != NULL, NULL);

	ipset = split_routes (ifnet_get_data (conn_name, "routes"));
	length = ipset ? g_strv_length (ipset) : 0;
	for (i = 0; i < length; i++) {
		ip = ipset[i];
		if (find_default_gateway_str (ip) || strstr (ip, "::")
		    || !find_gateway_str (ip))
			continue;
		ip = strip_string (ip, '"');
		iblock = create_ip4_block (ip);
		if (iblock == NULL)
			continue;
		iblock->next_hop = get_ip4_gateway (ip);
		if (start == NULL)
			start = current = iblock;
		else {
			current->next = iblock;
			current = iblock;
		}
	}
	g_strfreev (ipset);
	return start;
}
Exemplo n.º 5
0
static char *
get_ip4_gateway (gchar * gateway)
{
	gchar *tmp, *split;

	if (!gateway)
		return NULL;
	tmp = find_gateway_str (gateway);
	if (!tmp) {
		nm_log_warn (LOGD_SETTINGS, "Couldn't obtain gateway in \"%s\"", gateway);
		return NULL;
	}
	tmp = g_strdup (tmp);
	strip_string (tmp, ' ');
	strip_string (tmp, '"');

	// Only one gateway is selected
	if ((split = strstr (tmp, "\"")) != NULL)
		*split = '\0';

	if (!nm_utils_ipaddr_valid (AF_INET, tmp))
		goto error;
	return tmp;
error:
	if (!is_ip6_address (tmp))
		nm_log_warn (LOGD_SETTINGS, "Can't handle IPv4 gateway: %s", tmp);
	g_free (tmp);
	return NULL;
}