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



On Mon, 2008-05-26 at 10:18 +0200, Markus Becker wrote:
> 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.

The Policy object already has an idea of whether or not the device is
the "default" device, and it sets that on the ActiveConnection object
(either NMActRequest or NMVPNConnection actually, which both export the
ActiveConnection interface).

So nm-tool could just look for the active connection object with the
'default' property equal to True, and then mark that active connection
object's device as the default.

Dan

> 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;
> }
> 
> 
> _______________________________________________
> NetworkManager-list mailing list
> NetworkManager-list gnome org
> http://mail.gnome.org/mailman/listinfo/networkmanager-list



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