summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2008-03-12 14:48:31 +0100
committerMarcel Holtmann <marcel@holtmann.org>2008-03-12 14:48:31 +0100
commitc1925f58614237c3ecd8adce5c0b3f7d82b847cf (patch)
tree983a29bc3c5aeb444084546fd7844e31616e19aa
parent79280d0cf6a006988cb3c6394da44b2aa4c38271 (diff)
downloadconnman-c1925f58614237c3ecd8adce5c0b3f7d82b847cf.tar.gz
connman-c1925f58614237c3ecd8adce5c0b3f7d82b847cf.tar.bz2
connman-c1925f58614237c3ecd8adce5c0b3f7d82b847cf.zip
Add option for interface limitation
-rw-r--r--src/connman.h2
-rw-r--r--src/iface.c23
-rw-r--r--src/main.c22
3 files changed, 36 insertions, 11 deletions
diff --git a/src/connman.h b/src/connman.h
index 76bffe55..c253a8e3 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -59,7 +59,7 @@ void __connman_plugin_cleanup(void);
#include <connman/iface.h>
-int __connman_iface_init(DBusConnection *conn);
+int __connman_iface_init(DBusConnection *conn, const char *interface);
void __connman_iface_cleanup(void);
struct connman_iface *__connman_iface_find(int index);
diff --git a/src/iface.c b/src/iface.c
index 65e4cdd0..18c44f66 100644
--- a/src/iface.c
+++ b/src/iface.c
@@ -47,6 +47,8 @@
static DBusConnection *connection = NULL;
+static gchar *ifname_filter = NULL;
+
static GSList *drivers = NULL;
int connman_iface_register(struct connman_iface_driver *driver)
@@ -1095,7 +1097,7 @@ static int probe_device(LibHalContext *ctx,
{
DBusConnection *conn;
struct connman_iface *iface;
- char *temp, *sysfs;
+ char *temp, *sysfs, *ifname;
int err;
DBG("ctx %p driver %p udi %s", ctx, driver, udi);
@@ -1124,10 +1126,20 @@ static int probe_device(LibHalContext *ctx,
iface->index = -1;
- if (g_str_has_prefix(driver->capability, "net") == TRUE)
+ if (g_str_has_prefix(driver->capability, "net") == TRUE) {
iface->index = libhal_device_get_property_int(ctx, udi,
"net.linux.ifindex", NULL);
+ ifname = libhal_device_get_property_string(ctx, udi,
+ "net.interface", NULL);
+ if (ifname != NULL && ifname_filter != NULL &&
+ *ifname_filter != '\0' &&
+ g_str_equal(ifname, ifname_filter) == FALSE) {
+ device_free(iface);
+ return -1;
+ }
+ }
+
iface->type = CONNMAN_IFACE_TYPE_UNKNOWN;
iface->flags = 0;
iface->state = CONNMAN_IFACE_STATE_UNKNOWN;
@@ -1340,7 +1352,7 @@ static void hal_cleanup(void *data)
static guint hal_watch = 0;
-int __connman_iface_init(DBusConnection *conn)
+int __connman_iface_init(DBusConnection *conn, const char *interface)
{
DBG("conn %p", conn);
@@ -1348,6 +1360,9 @@ int __connman_iface_init(DBusConnection *conn)
if (connection == NULL)
return -1;
+ if (interface != NULL)
+ ifname_filter = g_strdup(interface);
+
hal_init(connection);
hal_watch = g_dbus_add_watch(connection, "org.freedesktop.Hal",
@@ -1364,5 +1379,7 @@ void __connman_iface_cleanup(void)
hal_cleanup(connection);
+ g_free(ifname_filter);
+
dbus_connection_unref(connection);
}
diff --git a/src/main.c b/src/main.c
index a4962b2a..e9174401 100644
--- a/src/main.c
+++ b/src/main.c
@@ -30,6 +30,7 @@
#include <signal.h>
#include <getopt.h>
#include <sys/stat.h>
+#include <net/if.h>
#include <gdbus.h>
@@ -47,7 +48,7 @@ static void usage(void)
printf("Connection Manager version %s\n\n", VERSION);
printf("Usage:\n"
- "\tconnmand [options]\n"
+ "\tconnmand [-i <interface>] [options]\n"
"\n");
printf("Options:\n"
@@ -58,10 +59,11 @@ static void usage(void)
}
static struct option options[] = {
- { "nodaemon", 0, 0, 'n' },
- { "compat", 0, 0, 'c' },
- { "debug", 0, 0, 'd' },
- { "help", 0, 0, 'h' },
+ { "interface", 1, 0, 'i' },
+ { "nodaemon", 0, 0, 'n' },
+ { "compat", 0, 0, 'c' },
+ { "debug", 0, 0, 'd' },
+ { "help", 0, 0, 'h' },
{ }
};
@@ -70,10 +72,16 @@ int main(int argc, char *argv[])
DBusConnection *conn;
DBusError err;
struct sigaction sa;
+ char interface[IFNAMSIZ];
int opt, detach = 1, compat = 0, debug = 0;
- while ((opt = getopt_long(argc, argv, "+ncdh", options, NULL)) != EOF) {
+ memset(interface, 0, IFNAMSIZ);
+
+ while ((opt = getopt_long(argc, argv, "+i:ncdh", options, NULL)) != EOF) {
switch (opt) {
+ case 'i':
+ snprintf(interface, IFNAMSIZ, "%s", optarg);
+ break;
case 'n':
detach = 0;
break;
@@ -136,7 +144,7 @@ int main(int argc, char *argv[])
__connman_rtnl_init();
- __connman_iface_init(conn);
+ __connman_iface_init(conn, interface);
memset(&sa, 0, sizeof(sa));
sa.sa_handler = sig_term;