Example #1
0
NMIP6Config *
nm_ip6_config_new_for_interface (int ifindex)
{
	NMIP6Config *ip6;
	GArray *addrs_array, *routes_array;
	NMPlatformIP6Address *addrs;
	NMPlatformIP6Route *routes;
	NMIP6Address *addr;
	NMIP6Route *route;
	int i;

	addrs_array = nm_platform_ip6_address_get_all (ifindex);
	if (addrs_array->len == 0) {
		g_array_unref (addrs_array);
		return NULL;
	}

	ip6 = nm_ip6_config_new ();

	addrs = (NMPlatformIP6Address *)addrs_array->data;
	for (i = 0; i < addrs_array->len; i++) {
		addr = nm_ip6_address_new ();
		nm_ip6_address_set_address (addr, &addrs[i].address);
		nm_ip6_address_set_prefix (addr, addrs[i].plen);
		nm_ip6_config_take_address (ip6, addr);
	}
	g_array_unref (addrs_array);

	routes_array = nm_platform_ip6_route_get_all (ifindex);
	routes = (NMPlatformIP6Route *)routes_array->data;
	for (i = 0; i < routes_array->len; i++) {
		/* Default route ignored; it's handled internally by NM and not
		* tracked in the device's IP config.
		*/
		if (routes[i].plen == 0)
			continue;

		route = nm_ip6_route_new ();
		nm_ip6_route_set_dest (route, &routes[i].network);
		nm_ip6_route_set_prefix (route, routes[i].plen);
		nm_ip6_route_set_next_hop (route, &routes[i].gateway);
		nm_ip6_route_set_metric (route, routes[i].metric);
		nm_ip6_config_take_route (ip6, route);
	}
	g_array_unref (routes_array);

	return ip6;
}
Example #2
0
static gboolean
do_ip6_address_get_all (char **argv)
{
	int ifindex = parse_ifindex (argv[0]);
	GArray *addresses;
	NMPlatformIP6Address *address;
	char addrstr[INET6_ADDRSTRLEN];
	int i;

	if (ifindex) {
		addresses = nm_platform_ip6_address_get_all (NM_PLATFORM_GET, ifindex);
		for (i = 0; i < addresses->len; i++) {
			address = &g_array_index (addresses, NMPlatformIP6Address, i);
			inet_ntop (AF_INET6, &address->address, addrstr, sizeof (addrstr));
			printf ("%s/%d\n", addrstr, address->plen);
		}
		g_array_unref (addresses);
	}

	return !!ifindex;
}
Example #3
0
static void
dump_interface (NMPlatformLink *link)
{
	GArray *ip6_addresses;
	GArray *ip4_addresses;
	const NMPlatformIP6Address *ip6_address;
	const NMPlatformIP4Address *ip4_address;
	char addrstr[INET6_ADDRSTRLEN];
	GArray *ip6_routes;
	GArray *ip4_routes;
	const NMPlatformIP6Route *ip6_route;
	const NMPlatformIP4Route *ip4_route;
	char networkstr[INET6_ADDRSTRLEN];
	char gatewaystr[INET6_ADDRSTRLEN];
	int vlan_id, vlan_parent;
	const char *address;
	size_t addrlen;
	int i;

	g_assert (link->up || !link->connected);

	printf ("%d: %s: %s", link->ifindex, link->name, link->type_name);
	if (link->up)
		printf (" %s", link->connected ? "CONNECTED" : "DISCONNECTED");
	else
		printf (" DOWN");
	if (!link->arp)
		printf (" noarp");
	if (link->master)
		printf (" master %d", link->master);
	if (link->parent)
		printf (" parent %d", link->parent);
	printf (" mtu %d", link->mtu);
	printf ("\n");
	if (link->driver)
		printf ("    driver: %s\n", link->driver);
	printf ("    UDI: %s\n", link->udi);
	nm_platform_vlan_get_info (link->ifindex, &vlan_parent, &vlan_id);
	if (vlan_parent)
		printf ("    vlan parent %d id %d\n", vlan_parent, vlan_id);

	if (nm_platform_link_is_software (link->ifindex))
		printf ("    class software\n");
	if (nm_platform_link_supports_slaves (link->ifindex))
		printf ("    class supports-slaves\n");
	if (nm_platform_link_supports_carrier_detect (link->ifindex))
		printf ("    feature carrier-detect\n");
	if (nm_platform_link_supports_vlans (link->ifindex))
		printf ("    feature vlans\n");

	address = nm_platform_link_get_address (link->ifindex, &addrlen);
	if (address) {
		printf ("    link-address ");
		for (i = 0; i < addrlen; i++)
			printf ("%s%02hhx", i ? ":" : "", address[i]);
		printf ("\n");
	}

	ip4_addresses = nm_platform_ip4_address_get_all (link->ifindex);
	ip6_addresses = nm_platform_ip6_address_get_all (link->ifindex);

	g_assert (ip4_addresses);
	g_assert (ip6_addresses);

	for (i = 0; i < ip4_addresses->len; i++) {
		ip4_address = &g_array_index (ip4_addresses, NMPlatformIP4Address, i);
		inet_ntop (AF_INET, &ip4_address->address, addrstr, sizeof (addrstr));
		printf ("    ip4-address %s/%d\n", addrstr, ip4_address->plen);
	}

	for (i = 0; i < ip6_addresses->len; i++) {
		ip6_address = &g_array_index (ip6_addresses, NMPlatformIP6Address, i);
		inet_ntop (AF_INET6, &ip6_address->address, addrstr, sizeof (addrstr));
		printf ("    ip6-address %s/%d\n", addrstr, ip6_address->plen);
	}

	g_array_unref (ip4_addresses);
	g_array_unref (ip6_addresses);

	ip4_routes = nm_platform_ip4_route_get_all (link->ifindex);
	ip6_routes = nm_platform_ip6_route_get_all (link->ifindex);

	g_assert (ip4_routes);
	g_assert (ip6_routes);

	for (i = 0; i < ip4_routes->len; i++) {
		ip4_route = &g_array_index (ip4_routes, NMPlatformIP4Route, i);
		inet_ntop (AF_INET, &ip4_route->network, networkstr, sizeof (networkstr));
		inet_ntop (AF_INET, &ip4_route->gateway, gatewaystr, sizeof (gatewaystr));
		printf ("    ip4-route %s/%d via %s\n", networkstr, ip4_route->plen, gatewaystr);
	}

	for (i = 0; i < ip6_routes->len; i++) {
		ip6_route = &g_array_index (ip6_routes, NMPlatformIP6Route, i);
		inet_ntop (AF_INET6, &ip6_route->network, networkstr, sizeof (networkstr));
		inet_ntop (AF_INET6, &ip6_route->gateway, gatewaystr, sizeof (gatewaystr));
		printf ("    ip6-route %s/%d via %s\n", networkstr, ip6_route->plen, gatewaystr);
	}

	g_array_unref (ip4_routes);
	g_array_unref (ip6_routes);
}