summaryrefslogtreecommitdiffstats
path: root/network
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2007-09-28 13:32:50 +0000
committerLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2007-09-28 13:32:50 +0000
commitda7741d54263d6de3475b8c10db3c1dd3ebaebaf (patch)
tree20eed92b955623017d616241d9ca6a8de7e0fb36 /network
parent123ef726b4bb5c465cd8a5e7b7c003e55443b219 (diff)
Improve bridge and network interfaces manipulation.
Diffstat (limited to 'network')
-rw-r--r--network/bridge.c10
-rw-r--r--network/common.c51
-rw-r--r--network/network.conf6
-rw-r--r--network/server.c6
4 files changed, 46 insertions, 27 deletions
diff --git a/network/bridge.c b/network/bridge.c
index e481ca80..ad4fc72e 100644
--- a/network/bridge.c
+++ b/network/bridge.c
@@ -101,6 +101,7 @@ int bridge_remove(int id)
int bridge_add_interface(int id, const char *dev)
{
struct ifreq ifr;
+ int err;
int ifindex = if_nametoindex(dev);
const char *name = bridge_get_name(id);
@@ -113,8 +114,13 @@ int bridge_add_interface(int id, const char *dev)
strncpy(ifr.ifr_name, name, IFNAMSIZ);
ifr.ifr_ifindex = ifindex;
- if (ioctl(bridge_socket, SIOCBRADDIF, &ifr) < 0)
- return -errno;
+ err = ioctl(bridge_socket, SIOCBRADDIF, &ifr);
+ if (err < 0)
+ return err;
+
+ err = bnep_if_up(name, id);
+ if (err < 0)
+ return err;
return 0;
}
diff --git a/network/common.c b/network/common.c
index d7174a18..e634ac43 100644
--- a/network/common.c
+++ b/network/common.c
@@ -72,6 +72,14 @@ struct bnep_data {
int pid;
};
+static gint find_devname(gconstpointer a, gconstpointer b)
+{
+ struct bnep_data *data = (struct bnep_data *) a;
+ const char *devname = b;
+
+ return strcmp(data->devname, devname);
+}
+
static void script_exited(GPid pid, gint status, gpointer data)
{
struct bnep_data *bnep = data;
@@ -228,6 +236,9 @@ int bnep_if_up(const char *devname, uint16_t id)
struct bnep_data *bnep;
GSpawnFlags flags;
+ if (g_slist_find_custom(pids, devname, find_devname))
+ return 0;
+
sd = socket(AF_INET6, SOCK_DGRAM, 0);
memset(&ifr, 0, sizeof(ifr));
strcpy(ifr.ifr_name, devname);
@@ -241,8 +252,11 @@ int bnep_if_up(const char *devname, uint16_t id)
return -err;
}
+ bnep = g_new0(struct bnep_data, 1);
+ bnep->devname = g_strdup(devname);
+
if (!id)
- return 0;
+ goto done;
if (id == BNEP_SVC_PANU)
script = panu;
@@ -252,7 +266,7 @@ int bnep_if_up(const char *devname, uint16_t id)
script = nap;
if (!script)
- return 0;
+ goto done;
argv[0] = script;
argv[1] = devname;
@@ -261,34 +275,37 @@ int bnep_if_up(const char *devname, uint16_t id)
if (!g_spawn_async(NULL, (char **) argv, NULL, flags, bnep_setup,
(gpointer) devname, &pid, NULL)) {
error("Unable to execute %s", argv[0]);
- return -1;
+ return -EINVAL;
}
- bnep = g_new0(struct bnep_data, 1);
- bnep->devname = g_strdup(devname);
bnep->pid = pid;
- pids = g_slist_append(pids, bnep);
g_child_watch_add(pid, script_exited, bnep);
- return pid;
+done:
+ pids = g_slist_append(pids, bnep);
+
+ return bnep->pid;
}
int bnep_if_down(const char *devname)
{
int sd, err;
struct ifreq ifr;
+ struct bnep_data *data;
GSList *l;
- for(l = pids; l; l = g_slist_next(l)) {
- struct bnep_data *bnep = l->data;
+ l = g_slist_find_custom(pids, devname, find_devname);
+ if (!l)
+ return 0;
- if (strcmp(devname, bnep->devname) == 0) {
- if (kill(bnep->pid, SIGTERM) < 0)
- error("kill(%d, SIGTERM): %s (%d)", bnep->pid,
- strerror(errno), errno);
- pids = g_slist_remove(pids, bnep);
- break;
- }
+ data = l->data;
+ if (data->pid) {
+ err = kill(data->pid, SIGTERM);
+ if (err < 0)
+ error("kill(%d, SIGTERM): %s (%d)", data->pid,
+ strerror(errno), errno);
+ else
+ data->pid = 0;
}
sd = socket(AF_INET6, SOCK_DGRAM, 0);
@@ -304,6 +321,8 @@ int bnep_if_down(const char *devname)
return -err;
}
+ pids = g_slist_remove(pids, data);
+
return 0;
}
diff --git a/network/network.conf b/network/network.conf
index 51a873e7..8677bd7b 100644
--- a/network/network.conf
+++ b/network/network.conf
@@ -18,7 +18,7 @@
#Interface=
# PAN user connection interface up script. default:none
-#Script=avahi-autoipd
+Script=avahi-autoipd
[GN Role]
@@ -26,7 +26,7 @@
#Interface=
# Group Network connection interface up script. default:none
-#Script=avahi-autoipd
+Script=avahi-autoipd
[NAP Role]
@@ -34,4 +34,4 @@
#Interface=
# Network Access Point connection interface up script. default:none
-#Script=dhclient
+Script=dhclient
diff --git a/network/server.c b/network/server.c
index ac87ad19..a349bc32 100644
--- a/network/server.c
+++ b/network/server.c
@@ -80,7 +80,6 @@ struct network_server {
char *path; /* D-Bus path */
gboolean enable; /* Enable flag */
gboolean secure; /* Security flag */
- gboolean up; /* Interface up flag */
uint32_t record_id; /* Service record id */
uint16_t id; /* Service class identifier */
GSList *clients; /* Active connections */
@@ -346,11 +345,6 @@ static void authorization_callback(DBusPendingCall *pcall, void *data)
}
bnep_if_up(devname, 0);
- if (!ns->up) {
- bnep_if_up(bridge, ns->id);
- ns->iface = g_strdup(bridge);
- ns->up = TRUE;
- }
} else
bnep_if_up(devname, ns->id);