nm-applet/nm-tool: indication of device with default route



Hi,

it would be nice to be able to see which device has the default route in nm-tool and nm-applet. I have implemented the core functionality to find out whether a device has the default route in NetworkManagerSystem, see below.

How would one use this from nm-tool/nm-applet as I assume NetworkManagerSystem should not be exposed by the bindings.

Markus

/*
 * nm_system_device_has_default_ip4_route
 *
 * Returns, whether the given device has the default route
 *
 */
gboolean
nm_system_device_has_default_ip4_route (const char *iface)
{
	struct nl_handle  * nlh = NULL;
	struct nl_cache *route_cache = NULL;
	struct nl_object *route = NULL;
	DefaultRouteCheckData check_data;

	int iface_idx, iface_idx_found;

	nlh = nm_netlink_get_default_handle ();
	if (nlh == NULL)
		goto out;

	route_cache = rtnl_route_alloc_cache (nlh);
	if (!route_cache)
		return FALSE;
	nl_cache_mngt_provide (route_cache);

	iface_idx = nm_netlink_iface_to_index (iface);

	memset (&check_data, 0, sizeof (check_data));
	check_data.iface = iface;
	check_data.nlh = nlh;
	check_data.ifindex = iface_idx;
	check_data.family = AF_INET;

	for (route = nl_cache_get_first (route_cache);
		route != NULL;
		route = nl_cache_get_next(route) ) {
iface_idx_found = check_one_address_for_gateway(route, &check_data);
		if ( iface_idx_found >= 0) {
			if (iface_idx == iface_idx_found) {
				nl_cache_free(route_cache);
				return TRUE;
			}
		}
	}
out:
	return FALSE;
}




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]