From 14921d074bd7f6d47bce8ad955baf088446e64ac Mon Sep 17 00:00:00 2001 From: Sam Leffler Date: Mon, 19 Oct 2009 10:52:59 -0700 Subject: [PATCH] Fix command line options for device filtering Also re-implement -I option to filter devices discovered through netlink. --- src/connman.h | 2 ++ src/element.c | 29 ++++++++++++++++++++++------- src/inet.c | 8 +++++++- src/ipconfig.c | 15 +++++++++++++-- 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/src/connman.h b/src/connman.h index 5eee390..1fad19b 100644 --- a/src/connman.h +++ b/src/connman.h @@ -223,6 +223,8 @@ int __connman_element_append_ipv4(struct connman_element *element, int __connman_element_set_ipv4(struct connman_element *element, const char *name, DBusMessageIter *value); +gboolean __connman_element_device_isfiltered(const char *devname); + int __connman_ipv4_init(void); void __connman_ipv4_cleanup(void); diff --git a/src/element.c b/src/element.c index 430242f..c8ca76e 100644 --- a/src/element.c +++ b/src/element.c @@ -37,6 +37,7 @@ static DBusConnection *connection; static GNode *element_root = NULL; static GSList *driver_list = NULL; static gchar *device_filter = NULL; +static gchar *nodevice_filter = NULL; static gboolean started = FALSE; @@ -1371,6 +1372,21 @@ static void register_element(gpointer data, gpointer user_data) probe_element(element); } +gboolean __connman_element_device_isfiltered(const char *devname) +{ + if (device_filter != NULL && + g_pattern_match_simple(device_filter, devname) == FALSE) { + DBG("ignoring device %s (no match)", devname); + return TRUE; + } + if (nodevice_filter != NULL && + g_pattern_match_simple(nodevice_filter, devname) == TRUE) { + DBG("ignoring device %s (match no)", devname); + return TRUE; + } + return FALSE; +} + /** * connman_element_register: * @element: the element to register @@ -1389,13 +1405,10 @@ int connman_element_register(struct connman_element *element, if (element->devname == NULL) element->devname = g_strdup(element->name); - if (device_filter && element->type == CONNMAN_ELEMENT_TYPE_DEVICE) { - if (g_pattern_match_simple(device_filter, - element->devname) == FALSE) { - DBG("ignoring %s [%s] device", element->name, - element->devname); - return -EPERM; - } + if (element->type == CONNMAN_ELEMENT_TYPE_DEVICE && + __connman_element_device_isfiltered(element->devname) == TRUE) { + DBG("ignoring %s [%s] device", element->name, element->devname); + return -EPERM; } if (connman_element_ref(element) == NULL) @@ -1580,6 +1593,7 @@ int __connman_element_init(const char *device, const char *nodevice) return -EIO; device_filter = g_strdup(device); + nodevice_filter = g_strdup(nodevice); element = connman_element_create("root"); @@ -1692,6 +1706,7 @@ void __connman_element_cleanup(void) g_node_destroy(element_root); element_root = NULL; + g_free(nodevice_filter); g_free(device_filter); if (connection == NULL) diff --git a/src/inet.c b/src/inet.c index 4ced09b..7f4d139 100644 --- a/src/inet.c +++ b/src/inet.c @@ -441,6 +441,11 @@ struct connman_device *connman_inet_create_device(int index) devname = connman_inet_ifname(index); if (devname == NULL) return NULL; + if (__connman_element_device_isfiltered(devname) == TRUE) { + connman_info("Ignoring network interface %s (filtered)", + devname); + return NULL; + } __connman_udev_get_devtype(devname); @@ -448,7 +453,8 @@ struct connman_device *connman_inet_create_device(int index) switch (type) { case CONNMAN_DEVICE_TYPE_UNKNOWN: - connman_info("Ignoring network interface %s", devname); + connman_info("Ignoring network interface %s (type unknown)", + devname); g_free(devname); return NULL; case CONNMAN_DEVICE_TYPE_ETHERNET: diff --git a/src/ipconfig.c b/src/ipconfig.c index edbdb3e..c18d36b 100644 --- a/src/ipconfig.c +++ b/src/ipconfig.c @@ -292,6 +292,7 @@ void __connman_ipconfig_newlink(int index, unsigned short type, GString *str; gboolean up = FALSE, down = FALSE; gboolean lower_up = FALSE, lower_down = FALSE; + char *ifname; DBG("index %d", index); @@ -302,12 +303,22 @@ void __connman_ipconfig_newlink(int index, unsigned short type, if (ipdevice != NULL) goto update; + ifname = connman_inet_ifname(index); + if (__connman_element_device_isfiltered(ifname) == TRUE) { + connman_info("Ignoring network interface %s (filtered)", + ifname); + g_free(ifname); + return; + } + ipdevice = g_try_new0(struct connman_ipdevice, 1); - if (ipdevice == NULL) + if (ipdevice == NULL) { + g_free(ifname); return; + } ipdevice->index = index; - ipdevice->ifname = connman_inet_ifname(index); + ipdevice->ifname = ifname; ipdevice->type = type; g_hash_table_insert(ipdevice_hash, GINT_TO_POINTER(index), ipdevice); -- 2.7.4