Re: [PATCH 3/9] bonding: Detect virtual bonding devices and create an ethernet device



On Fri, 2011-09-23 at 14:52 +0200, Thomas Graf wrote:
> Signed-off-by: Thomas Graf <tgraf redhat com>
> ---
>  src/nm-system.c       |   32 ++++++++++++++++++++++++++++++++
>  src/nm-system.h       |    2 ++
>  src/nm-udev-manager.c |   13 +++++++++++--
>  3 files changed, 45 insertions(+), 2 deletions(-)
> 
> diff --git a/src/nm-system.c b/src/nm-system.c
> index 2d0393a..1b8f224 100644
> --- a/src/nm-system.c
> +++ b/src/nm-system.c
> @@ -1206,3 +1206,35 @@ nm_system_add_bonding_master(NMSettingBond *setting)
>  
>  	return TRUE;
>  }
> +
> +/**
> + * nm_system_get_link_type:
> + * @name: name of link
> + *
> + * Lookup virtual link type. The returned string is allocated and needs
> + * to be freed after usage.
> + *
> + * Returns: Name of virtual link type or NULL if not a virtual link.
> + **/
> +char *
> +nm_system_get_link_type(const char *name)
> +{
> +	struct rtnl_link *result;
> +	struct nl_sock *nlh;
> +	char *type;
> +
> +	nlh = nm_netlink_get_default_handle ();
> +	if (!nlh)
> +		return NULL;
> +
> +	if (rtnl_link_get_kernel (nlh, 0, name, &result) < 0)
> +		return NULL;
> +
> +	if ((type = rtnl_link_get_type (result)))
> +		type = g_strdup(type);
> +
> +	rtnl_link_put (result);
> +
> +	return type;
> +}
> +
> diff --git a/src/nm-system.h b/src/nm-system.h
> index a606503..1fe91f6 100644
> --- a/src/nm-system.h
> +++ b/src/nm-system.h
> @@ -92,4 +92,6 @@ gboolean		nm_system_iface_set_mac                 (int ifindex, const struct eth
>  
>  gboolean		nm_system_add_bonding_master	(NMSettingBond *setting);
>  
> +char *			nm_system_get_link_type		(const char *name);
> +
>  #endif
> diff --git a/src/nm-udev-manager.c b/src/nm-udev-manager.c
> index 72501c2..0f2b066 100644
> --- a/src/nm-udev-manager.c
> +++ b/src/nm-udev-manager.c
> @@ -41,6 +41,7 @@
>  #if WITH_WIMAX
>  #include "nm-device-wimax.h"
>  #endif
> +#include "nm-system.h"
>  
>  typedef struct {
>  	GUdevClient *client;
> @@ -458,9 +459,17 @@ device_creator (NMUdevManager *manager,
>  	}
>  
>  	if (!driver) {
> -		if (g_str_has_prefix (ifname, "easytether")) {
> +		char *type;
> +
> +		type = nm_system_get_link_type (ifname);
> +		if (type) {
> +			if (g_strcmp0 (type, "bond") == 0)
> +				driver = "bonding";

Don't we need to free 'type' here?  If we want to avoid this we could
make nm_system_get_link_type() return an enum that we convert inside the
function too (freeing the value there instead of making callers do it).
Maybe not worth it, but might help prevent leaks later.

Dan

> +		} else if (g_str_has_prefix (ifname, "easytether")) {
>  			driver = "easytether";
> -		} else {
> +		}
> +		
> +		if (!driver) {
>  			nm_log_warn (LOGD_HW, "%s: couldn't determine device driver; ignoring...", path);
>  			goto out;
>  		}




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