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 <[email protected]>
---
 src/nm-system.c       |   32 +++++++++++++++++++-------------
 src/nm-system.h       |    9 ++++++++-
 src/nm-udev-manager.c |   18 +++++++++---------
 3 files changed, 36 insertions(+), 23 deletions(-)

diff --git a/src/nm-system.c b/src/nm-system.c
index 709a08b..3317eb4 100644
--- a/src/nm-system.c
+++ b/src/nm-system.c
@@ -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);
 
-       rtnl_link_put (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;
 
-       return type;
+       rtnl_link_put (result);
+out:
+       return res;
 }
 
diff --git a/src/nm-system.h b/src/nm-system.h
index 339dfa7..f151e90 100644
--- a/src/nm-system.h
+++ b/src/nm-system.h
@@ -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
diff --git a/src/nm-udev-manager.c b/src/nm-udev-manager.c
index ede39bb..55e1517 100644
--- a/src/nm-udev-manager.c
+++ b/src/nm-udev-manager.c
@@ -431,15 +431,15 @@ device_creator (NMUdevManager *manager,
        }
 
        if (!driver) {
-               char *type;
-
-               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";
+               switch (nm_system_get_iface_type (ifname)) {
+               case NM_IFACE_TYPE_BOND:
+                       driver = "bonding";
+                       break;
+
+               default:
+                       if (g_str_has_prefix (ifname, "easytether"))
+                               driver = "easytether";
+                       break;
                }
                
                if (!driver) {
-- 
1.7.6.4

_______________________________________________
networkmanager-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/networkmanager-list

Reply via email to