summaryrefslogtreecommitdiff
path: root/src/tethering.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tethering.c')
-rw-r--r--src/tethering.c83
1 files changed, 43 insertions, 40 deletions
diff --git a/src/tethering.c b/src/tethering.c
index c362b8d6..b4ab993c 100644
--- a/src/tethering.c
+++ b/src/tethering.c
@@ -65,7 +65,7 @@
#define PRIVATE_NETWORK_SECONDARY_DNS "8.8.4.4"
static char *default_interface = NULL;
-static volatile gint tethering_enabled;
+static volatile int tethering_enabled;
static GDHCPServer *tethering_dhcp_server = NULL;
static DBusConnection *connection;
static GHashTable *pn_hash;
@@ -336,44 +336,44 @@ static void disable_nat(const char *interface)
void __connman_tethering_set_enabled(void)
{
int err;
+ const char *dns;
DBG("enabled %d", tethering_enabled + 1);
- if (g_atomic_int_exchange_and_add(&tethering_enabled, 1) == 0) {
- const char *dns;
+ if (__sync_fetch_and_add(&tethering_enabled, 1) != 0)
+ return;
- err = create_bridge(BRIDGE_NAME);
- if (err < 0)
- return;
+ err = create_bridge(BRIDGE_NAME);
+ if (err < 0)
+ return;
- err = enable_bridge(BRIDGE_NAME);
- if (err < 0) {
- remove_bridge(BRIDGE_NAME);
- return;
- }
+ err = enable_bridge(BRIDGE_NAME);
+ if (err < 0) {
+ remove_bridge(BRIDGE_NAME);
+ return;
+ }
- dns = BRIDGE_IP;
- if (__connman_dnsproxy_add_listener(BRIDGE_NAME) < 0) {
- connman_error("Can't add listener %s to DNS proxy",
+ dns = BRIDGE_IP;
+ if (__connman_dnsproxy_add_listener(BRIDGE_NAME) < 0) {
+ connman_error("Can't add listener %s to DNS proxy",
BRIDGE_NAME);
- dns = BRIDGE_DNS;
- }
-
- tethering_dhcp_server =
- dhcp_server_start(BRIDGE_NAME,
- BRIDGE_IP, BRIDGE_SUBNET,
- BRIDGE_IP_START, BRIDGE_IP_END,
- 24 * 3600, dns);
- if (tethering_dhcp_server == NULL) {
- disable_bridge(BRIDGE_NAME);
- remove_bridge(BRIDGE_NAME);
- return;
- }
-
- enable_nat(default_interface);
-
- DBG("tethering started");
+ dns = BRIDGE_DNS;
+ }
+
+ tethering_dhcp_server =
+ dhcp_server_start(BRIDGE_NAME,
+ BRIDGE_IP, BRIDGE_SUBNET,
+ BRIDGE_IP_START, BRIDGE_IP_END,
+ 24 * 3600, dns);
+ if (tethering_dhcp_server == NULL) {
+ disable_bridge(BRIDGE_NAME);
+ remove_bridge(BRIDGE_NAME);
+ return;
}
+
+ enable_nat(default_interface);
+
+ DBG("tethering started");
}
void __connman_tethering_set_disabled(void)
@@ -382,17 +382,18 @@ void __connman_tethering_set_disabled(void)
__connman_dnsproxy_remove_listener(BRIDGE_NAME);
- if (g_atomic_int_dec_and_test(&tethering_enabled) == TRUE) {
- disable_nat(default_interface);
+ if (__sync_fetch_and_sub(&tethering_enabled, 1) != 1)
+ return;
+
+ disable_nat(default_interface);
- dhcp_server_stop(tethering_dhcp_server);
+ dhcp_server_stop(tethering_dhcp_server);
- disable_bridge(BRIDGE_NAME);
+ disable_bridge(BRIDGE_NAME);
- remove_bridge(BRIDGE_NAME);
+ remove_bridge(BRIDGE_NAME);
- DBG("tethering stopped");
- }
+ DBG("tethering stopped");
}
void __connman_tethering_update_interface(const char *interface)
@@ -410,7 +411,8 @@ void __connman_tethering_update_interface(const char *interface)
default_interface = g_strdup(interface);
- if (!g_atomic_int_get(&tethering_enabled))
+ __sync_synchronize();
+ if (tethering_enabled == 0)
return;
enable_nat(interface);
@@ -613,7 +615,8 @@ void __connman_tethering_cleanup(void)
{
DBG("");
- if (g_atomic_int_get(&tethering_enabled)) {
+ __sync_synchronize();
+ if (tethering_enabled == 0) {
if (tethering_dhcp_server)
dhcp_server_stop(tethering_dhcp_server);
disable_bridge(BRIDGE_NAME);