summaryrefslogtreecommitdiffstats
path: root/network
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2007-10-31 14:48:55 +0000
committerLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2007-10-31 14:48:55 +0000
commita67fa98d477404a1b65e283b646db77914106c35 (patch)
tree72120a44300bb1582789b3e13063293f79c52a86 /network
parent97fd2ad39b3a08d695f5d45783e2dd0ee377bf3f (diff)
Remove bridge creation of NAP and make a better use of ahavi-autoipd.
Diffstat (limited to 'network')
-rw-r--r--network/common.c85
-rw-r--r--network/server.c9
2 files changed, 76 insertions, 18 deletions
diff --git a/network/common.c b/network/common.c
index cf351153..7a88a1bd 100644
--- a/network/common.c
+++ b/network/common.c
@@ -69,6 +69,7 @@ static const char *nap = NULL;
struct bnep_data {
char *devname;
+ char *script;
int pid;
};
@@ -226,12 +227,29 @@ int bnep_if_up(const char *devname, uint16_t id)
{
int sd, err, pid;
struct ifreq ifr;
- const char *argv[3], *script;
+ const char *argv[5];
struct bnep_data *bnep;
GSpawnFlags flags;
+ GSList *l;
- if (g_slist_find_custom(pids, devname, find_devname))
- return 0;
+ /* Check if a script is running */
+ if ((l = g_slist_find_custom(pids, devname, find_devname))) {
+ bnep = l->data;
+
+ if (bnep->script && !strcmp(bnep->script, "avahi-autoipd")) {
+ argv[0] = bnep->script;
+ argv[1] = devname;
+ argv[2] = "--refresh";
+ argv[3] = NULL;
+
+ flags = G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH;
+ g_spawn_async(NULL, (char **) argv, NULL, flags,
+ bnep_setup, (gpointer) devname, &pid,
+ NULL);
+
+ return bnep->pid;
+ }
+ }
sd = socket(AF_INET6, SOCK_DGRAM, 0);
memset(&ifr, 0, sizeof(ifr));
@@ -241,7 +259,7 @@ int bnep_if_up(const char *devname, uint16_t id)
if ((ioctl(sd, SIOCSIFFLAGS, (caddr_t) &ifr)) < 0) {
err = errno;
- error("Could not bring up %d. %s(%d)", devname, strerror(err),
+ error("Could not bring up %s. %s(%d)", devname, strerror(err),
err);
return -err;
}
@@ -253,18 +271,25 @@ int bnep_if_up(const char *devname, uint16_t id)
goto done;
if (id == BNEP_SVC_PANU)
- script = panu;
+ bnep->script = g_strdup(panu);
else if (id == BNEP_SVC_GN)
- script = gn;
+ bnep->script = g_strdup(gn);
else
- script = nap;
+ bnep->script = g_strdup(nap);
- if (!script)
+ if (!bnep->script)
goto done;
- argv[0] = script;
+ argv[0] = bnep->script;
argv[1] = devname;
- argv[2] = NULL;
+
+ if (!strcmp(bnep->script, "avahi-autoipd")) {
+ argv[2] = "--no-drop-root";
+ argv[3] = "--no-chroot";
+ argv[4] = NULL;
+ } else
+ argv[2] = NULL;
+
flags = G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH;
if (!g_spawn_async(NULL, (char **) argv, NULL, flags, bnep_setup,
(gpointer) devname, &pid, NULL)) {
@@ -283,29 +308,49 @@ done:
int bnep_if_down(const char *devname)
{
- int sd, err;
+ int sd, err, pid;
struct ifreq ifr;
struct bnep_data *bnep;
GSList *l;
+ GSpawnFlags flags;
+ const char *argv[4];
l = g_slist_find_custom(pids, devname, find_devname);
if (!l)
return 0;
bnep = l->data;
- if (bnep->pid) {
- err = kill(bnep->pid, SIGTERM);
- if (err < 0)
- error("kill(%d, SIGTERM): %s (%d)", bnep->pid,
- strerror(errno), errno);
+
+ if (!bnep->pid)
+ goto done;
+
+ if (bnep->script && !strcmp (bnep->script, "avahi-autoipd")) {
+ argv[0] = bnep->script;
+ argv[1] = devname;
+ argv[2] = "--kill";
+ argv[3] = NULL;
+
+ flags = G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH;
+ g_spawn_async(NULL, (char **) argv, NULL, flags, bnep_setup,
+ (gpointer) devname, &pid, NULL);
+
+ goto done;
}
+ /* Kill script */
+ err = kill(bnep->pid, SIGTERM);
+ if (err < 0)
+ error("kill(%d, SIGTERM): %s (%d)", bnep->pid,
+ strerror(errno), errno);
+
+done:
sd = socket(AF_INET6, SOCK_DGRAM, 0);
memset(&ifr, 0, sizeof(ifr));
strcpy(ifr.ifr_name, devname);
ifr.ifr_flags &= ~IFF_UP;
+ /* Bring down the interface */
if ((ioctl(sd, SIOCSIFFLAGS, (caddr_t) &ifr)) < 0) {
err = errno;
error("Could not bring down %d. %s(%d)", devname, strerror(err),
@@ -314,7 +359,13 @@ int bnep_if_down(const char *devname)
}
pids = g_slist_remove(pids, bnep);
- g_free(bnep->devname);
+
+ if (bnep->devname)
+ g_free(bnep->devname);
+
+ if (bnep->script)
+ g_free(bnep->script);
+
g_free(bnep);
return 0;
diff --git a/network/server.c b/network/server.c
index 1622d102..e9db7df9 100644
--- a/network/server.c
+++ b/network/server.c
@@ -640,7 +640,7 @@ int server_init(DBusConnection *conn, const char *iface_prefix,
goto fail;
}
- lm = secure? L2CAP_LM_SECURE : 0;
+ lm = secure ? L2CAP_LM_SECURE : 0;
if (lm && setsockopt(sk, SOL_L2CAP, L2CAP_LM, &lm, sizeof(lm)) < 0) {
err = errno;
error("Failed to set link mode. %s(%d)",
@@ -662,6 +662,10 @@ int server_init(DBusConnection *conn, const char *iface_prefix,
g_io_channel_set_close_on_unref(bnep_io, FALSE);
g_io_add_watch(bnep_io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
connect_event, NULL);
+
+ if (bridge_create(BNEP_SVC_GN) < 0)
+ error("Can't create GN bridge");
+
return 0;
fail:
@@ -684,6 +688,9 @@ void server_exit()
bnep_io = NULL;
}
+ if (bridge_remove(BNEP_SVC_GN) < 0)
+ error("Can't remove GN bridge");
+
dbus_connection_unref(connection);
connection = NULL;
}