summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Becker <chemobejk@gmail.com>2019-06-27 12:17:43 +0300
committerStefan Becker <chemobejk@gmail.com>2019-06-27 19:52:07 +0300
commit7b4b46f97c2d37da38eba4637dcf040105269772 (patch)
treec214ec5f518c3f8a131e136a99898eb0e9ceb6cc
parent0245565e056b7a919d92033eada4c090ebc436e9 (diff)
downloadlibnice-7b4b46f97c2d37da38eba4637dcf040105269772.tar.gz
interfaces: allow list of ignored prefixes
Improve on commit b4abda09c79e4ce372a3771300abf568c85c7ff5 Instead of checking one prefix, check against a list of prefixes. This allows libnice to be configured to ignore interfaces from virtual machines and containers.
-rw-r--r--agent/interfaces.c72
1 files changed, 53 insertions, 19 deletions
diff --git a/agent/interfaces.c b/agent/interfaces.c
index 3bfae3e..3a3b39c 100644
--- a/agent/interfaces.c
+++ b/agent/interfaces.c
@@ -73,6 +73,13 @@
#endif /* G_OS_UNIX */
+#ifdef IGNORED_IFACE_PREFIX
+static const gchar *ignored_iface_prefix_list[] = {
+ IGNORED_IFACE_PREFIX,
+ NULL
+};
+#endif
+
#if (defined(G_OS_UNIX) && defined(HAVE_GETIFADDRS)) || defined(G_OS_WIN32)
/* Works on both UNIX and Windows. Magic! */
static gchar *
@@ -253,7 +260,10 @@ nice_interfaces_get_local_ips (gboolean include_loopback)
GList *ips = NULL;
struct ifaddrs *ifa, *results;
GList *loopbacks = NULL;
-
+#ifdef IGNORED_IFACE_PREFIX
+ const gchar **prefix;
+ gboolean ignored = FALSE;
+#endif
if (getifaddrs (&results) < 0)
return NULL;
@@ -290,18 +300,28 @@ nice_interfaces_get_local_ips (gboolean include_loopback)
nice_debug ("Ignoring loopback interface");
g_free (addr_string);
}
+ continue;
+ }
+
#ifdef IGNORED_IFACE_PREFIX
- } else if (g_str_has_prefix (ifa->ifa_name, IGNORED_IFACE_PREFIX)) {
- nice_debug ("Ignoring interface %s as it matches prefix %s",
- ifa->ifa_name, IGNORED_IFACE_PREFIX);
- g_free (addr_string);
-#endif
- } else {
- if (nice_interfaces_is_private_ip (ifa->ifa_addr))
- ips = add_ip_to_list (ips, addr_string, TRUE);
- else
- ips = add_ip_to_list (ips, addr_string, FALSE);
+ for (prefix = ignored_iface_prefix_list; *prefix; prefix++) {
+ if (g_str_has_prefix (ifa->ifa_name, *prefix)) {
+ nice_debug ("Ignoring interface %s as it matches prefix %s",
+ ifa->ifa_name, *prefix);
+ g_free (addr_string);
+ ignored = true;
+ break;
+ }
}
+
+ if (ignored)
+ continue;
+#endif
+
+ if (nice_interfaces_is_private_ip (ifa->ifa_addr))
+ ips = add_ip_to_list (ips, addr_string, TRUE);
+ else
+ ips = add_ip_to_list (ips, addr_string, FALSE);
}
freeifaddrs (results);
@@ -324,6 +344,10 @@ nice_interfaces_get_local_ips (gboolean include_loopback)
struct ifconf ifc;
struct sockaddr_in *sa;
GList *loopbacks = NULL;
+#ifdef IGNORED_IFACE_PREFIX
+ const gchar **prefix;
+ gboolean ignored = FALSE;
+#endif
if ((sockfd = socket (AF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0) {
nice_debug ("Error : Cannot open socket to retrieve interface list");
@@ -381,17 +405,27 @@ nice_interfaces_get_local_ips (gboolean include_loopback)
loopbacks = add_ip_to_list (loopbacks, g_strdup (inet_ntoa (sa->sin_addr)), TRUE);
else
nice_debug ("Ignoring loopback interface");
+ continue;
+ }
+
#ifdef IGNORED_IFACE_PREFIX
- } else if (g_str_has_prefix (ifr->ifr_name, IGNORED_IFACE_PREFIX)) {
- nice_debug ("Ignoring interface %s as it matches prefix %s",
- ifr->ifr_name, IGNORED_IFACE_PREFIX);
+ for (prefix = ignored_iface_prefix_list; *prefix; prefix++) {
+ if (g_str_has_prefix (ifr->ifr_name, *prefix)) {
+ nice_debug ("Ignoring interface %s as it matches prefix %s",
+ ifr->ifr_name, *prefix);
+ ignored = true;
+ break;
+ }
+ }
+
+ if (ignored)
+ continue;
#endif
+
+ if (nice_interfaces_is_private_ip ((struct sockaddr *) sa)) {
+ ips = add_ip_to_list (ips, g_strdup (inet_ntoa (sa->sin_addr)), TRUE);
} else {
- if (nice_interfaces_is_private_ip ((struct sockaddr *) sa)) {
- ips = add_ip_to_list (ips, g_strdup (inet_ntoa (sa->sin_addr)), TRUE);
- } else {
- ips = add_ip_to_list (ips, g_strdup (inet_ntoa (sa->sin_addr)), FALSE);
- }
+ ips = add_ip_to_list (ips, g_strdup (inet_ntoa (sa->sin_addr)), FALSE);
}
}