core: convert nm_system_get_link_type() to return an int

Kills the strdup() and avoids having the caller free the memory. Also renames
the function to nm_system_get_iface_type() since "link" is not a common term
in NM.

Signed-off-by: Thomas Graf <tgraf@redhat.com>
This commit is contained in:
Thomas Graf 2011-11-09 11:22:39 +01:00 committed by Dan Williams
parent e654bb8d1d
commit d839e1c817
3 changed files with 35 additions and 22 deletions

View file

@ -1423,33 +1423,39 @@ out:
}
/**
* nm_system_get_link_type:
* @name: name of link
* nm_system_get_iface_type:
* @name: name of interface
*
* Lookup virtual link type. The returned string is allocated and needs
* to be freed after usage.
* Lookup the type of an interface
*
* Returns: Name of virtual link type or NULL if not a virtual link.
* Returns: Interface type (NM_IFACE_TYPE_*) or NM_IFACE_TYPE_UNSPEC.
**/
char *
nm_system_get_link_type (const char *name)
int
nm_system_get_iface_type (const char *name)
{
struct rtnl_link *result;
struct nl_sock *nlh;
char *type;
int res = NM_IFACE_TYPE_UNSPEC;
nlh = nm_netlink_get_default_handle ();
if (!nlh)
return NULL;
goto out;
if (rtnl_link_get_kernel (nlh, 0, name, &result) < 0)
return NULL;
goto out;
if ((type = rtnl_link_get_type (result)))
type = g_strdup (type);
type = rtnl_link_get_type (result);
if (!g_strcmp0 (type, "bond"))
res = NM_IFACE_TYPE_BOND;
else if (!g_strcmp0 (type, "vlan"))
res = NM_IFACE_TYPE_VLAN;
else if (!g_strcmp0 (type, "dummy"))
res = NM_IFACE_TYPE_DUMMY;
rtnl_link_put (result);
return type;
out:
return res;
}

View file

@ -95,6 +95,13 @@ gboolean nm_system_add_bonding_master (NMSettingBond *setting);
gboolean nm_system_iface_enslave (NMDevice *slave, NMDevice *master);
gboolean nm_system_iface_release (NMDevice *slave, NMDevice *master);
char * nm_system_get_link_type (const char *name);
enum {
NM_IFACE_TYPE_UNSPEC = 0,
NM_IFACE_TYPE_BOND,
NM_IFACE_TYPE_VLAN,
NM_IFACE_TYPE_DUMMY,
};
int nm_system_get_iface_type (const char *name);
#endif

View file

@ -423,15 +423,15 @@ device_creator (NMUdevManager *manager,
}
if (!driver) {
char *type;
switch (nm_system_get_iface_type (ifname)) {
case NM_IFACE_TYPE_BOND:
driver = "bonding";
break;
type = nm_system_get_link_type (ifname);
if (type) {
if (g_strcmp0 (type, "bond") == 0)
driver = "bonding";
g_free (type);
} else if (g_str_has_prefix (ifname, "easytether")) {
driver = "easytether";
default:
if (g_str_has_prefix (ifname, "easytether"))
driver = "easytether";
break;
}
if (!driver) {