*
* Connection Manager
*
- * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
+ * Copyright (C) 2007-2012 Intel Corporation. All rights reserved.
* Copyright (C) 2011 ProFUSION embedded systems
*
* This program is free software; you can redistribute it and/or modify
#include <string.h>
#include <fcntl.h>
#include <linux/if_tun.h>
+#include <linux/if_bridge.h>
#include "connman.h"
#define DBUS_TYPE_UNIX_FD -1
#endif
-#define BRIDGE_PROC_DIR "/proc/sys/net/bridge"
-
#define BRIDGE_NAME "tether"
#define BRIDGE_DNS "8.8.8.8"
const char *__connman_tethering_get_bridge(void)
{
- struct stat st;
+ int sk, err;
+ unsigned long args[3];
+
+ sk = socket(AF_INET, SOCK_STREAM, 0);
+ if (sk < 0)
+ return NULL;
- if (stat(BRIDGE_PROC_DIR, &st) < 0) {
+ args[0] = BRCTL_GET_VERSION;
+ args[1] = args[2] = 0;
+ err = ioctl(sk, SIOCGIFBR, &args);
+ close(sk);
+ if (err == -1) {
connman_error("Missing support for 802.1d ethernet bridging");
return NULL;
}
return;
err = __connman_bridge_create(BRIDGE_NAME);
- if (err < 0)
+ if (err < 0) {
+ __sync_fetch_and_sub(&tethering_enabled, 1);
return;
+ }
index = connman_inet_ifindex(BRIDGE_NAME);
- dhcp_ippool = __connman_ippool_create(index, 2, 253,
+ dhcp_ippool = __connman_ippool_create(index, 2, 252,
tethering_restart, NULL);
if (dhcp_ippool == NULL) {
connman_error("Fail to create IP pool");
+ __connman_bridge_remove(BRIDGE_NAME);
+ __sync_fetch_and_sub(&tethering_enabled, 1);
return;
}
err = __connman_bridge_enable(BRIDGE_NAME, gateway, broadcast);
if (err < 0 && err != -EALREADY) {
+ __connman_ippool_unref(dhcp_ippool);
__connman_bridge_remove(BRIDGE_NAME);
+ __sync_fetch_and_sub(&tethering_enabled, 1);
return;
}
24 * 3600, dns);
if (tethering_dhcp_server == NULL) {
__connman_bridge_disable(BRIDGE_NAME);
+ __connman_ippool_unref(dhcp_ippool);
__connman_bridge_remove(BRIDGE_NAME);
+ __sync_fetch_and_sub(&tethering_enabled, 1);
return;
}
g_free(pn);
}
-static void owner_disconnect(DBusConnection *connection, void *user_data)
+static void owner_disconnect(DBusConnection *conn, void *user_data)
{
struct connman_private_network *pn = user_data;
pn->fd = fd;
pn->interface = iface;
pn->index = index;
- pn->pool = __connman_ippool_create(pn->fd, 1, 1, ippool_disconnect, pn);
+ pn->pool = __connman_ippool_create(pn->index, 1, 1, ippool_disconnect, pn);
if (pn->pool == NULL) {
errno = -ENOMEM;
goto error;