summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-12-26 11:54:30 +0100
committerThomas Haller <thaller@redhat.com>2017-01-04 14:18:01 +0100
commite8d5a8356c871624bf3be471e995f434bd027f25 (patch)
treeb3cf2947dcc7b4fd641581fab4ec57c4828f30ab
parentd481489804237d44fe69344eb117c5b724b5a38c (diff)
downloadNetworkManager-e8d5a8356c871624bf3be471e995f434bd027f25.tar.gz
platform: add wrappers for if_nametoindex() and if_indextoname()
-rw-r--r--src/platform/nm-platform-utils.c22
-rw-r--r--src/platform/nm-platform-utils.h3
-rw-r--r--src/platform/nm-platform.c16
-rw-r--r--src/platform/nm-platform.h3
4 files changed, 44 insertions, 0 deletions
diff --git a/src/platform/nm-platform-utils.c b/src/platform/nm-platform-utils.c
index 8b6994e20e..2c2b19a21d 100644
--- a/src/platform/nm-platform-utils.c
+++ b/src/platform/nm-platform-utils.c
@@ -38,7 +38,29 @@
#include "nm-core-utils.h"
+/******************************************************************
+ * utils
+ ******************************************************************/
+
extern char *if_indextoname (unsigned int __ifindex, char *__ifname);
+unsigned int if_nametoindex (const char *__ifname);
+
+const char *
+nmp_utils_if_indextoname (int ifindex, char *out_ifname/*IFNAMSIZ*/)
+{
+ g_return_val_if_fail (ifindex > 0, NULL);
+ g_return_val_if_fail (out_ifname, NULL);
+
+ return if_indextoname (ifindex, out_ifname);
+}
+
+int
+nmp_utils_if_nametoindex (const char *ifname)
+{
+ g_return_val_if_fail (ifname, 0);
+
+ return if_nametoindex (ifname);
+}
/******************************************************************
* ethtool
diff --git a/src/platform/nm-platform-utils.h b/src/platform/nm-platform-utils.h
index ea9607e6a3..699e80c698 100644
--- a/src/platform/nm-platform-utils.h
+++ b/src/platform/nm-platform-utils.h
@@ -74,6 +74,9 @@ NMIPConfigSource nmp_utils_ip_config_source_coerce_from_rtprot (NMIPConfigSource
NMIPConfigSource nmp_utils_ip_config_source_round_trip_rtprot (NMIPConfigSource source) _nm_const;
const char * nmp_utils_ip_config_source_to_string (NMIPConfigSource source, char *buf, gsize len);
+const char *nmp_utils_if_indextoname (int ifindex, char *out_ifname/*IFNAMSIZ*/);
+int nmp_utils_if_nametoindex (const char *ifname);
+
int nmp_utils_sysctl_open_netdir (int ifindex,
const char *ifname_guess,
char *out_ifname);
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index d0b65adf08..9d972a5897 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -770,6 +770,22 @@ nm_platform_link_get_ifindex (NMPlatform *self, const char *name)
return pllink ? pllink->ifindex : 0;
}
+const char *
+nm_platform_if_indextoname (NMPlatform *self, int ifindex, char *out_ifname/* of size IFNAMSIZ */)
+{
+ _CHECK_SELF_NETNS (self, klass, netns, FALSE);
+
+ return nmp_utils_if_indextoname (ifindex, out_ifname);
+}
+
+int
+nm_platform_if_nametoindex (NMPlatform *self, const char *ifname)
+{
+ _CHECK_SELF_NETNS (self, klass, netns, FALSE);
+
+ return nmp_utils_if_nametoindex (ifname);
+}
+
/**
* nm_platform_link_get_name:
* @self: platform instance
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h
index 55d7a6f20e..91f8ab5d6f 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -738,6 +738,9 @@ gint64 nm_platform_sysctl_get_int_checked (NMPlatform *self, const char *pathid,
gboolean nm_platform_sysctl_set_ip6_hop_limit_safe (NMPlatform *self, const char *iface, int value);
+const char *nm_platform_if_indextoname (NMPlatform *self, int ifindex, char *out_ifname/* of size IFNAMSIZ */);
+int nm_platform_if_nametoindex (NMPlatform *self, const char *ifname);
+
const NMPlatformLink *nm_platform_link_get (NMPlatform *self, int ifindex);
const NMPlatformLink *nm_platform_link_get_by_ifname (NMPlatform *self, const char *ifname);
const NMPlatformLink *nm_platform_link_get_by_address (NMPlatform *self, gconstpointer address, size_t length);