|
Loading...
|
connman@connman.net
[Prev] Thread [Next] | [Prev] Date [Next]
[PATCH v0 2/2] tethering: Use __connman_dhcp_server_*() Daniel Wagner Mon Feb 13 08:00:16 2012
From: Daniel Wagner <[EMAIL PROTECTED]>
Instead the private implementation in tethering.c.
---
src/tethering.c | 102 +++++++++---------------------------------------------
1 files changed, 17 insertions(+), 85 deletions(-)
diff --git a/src/tethering.c b/src/tethering.c
index 161e971..888c51f 100644
--- a/src/tethering.c
+++ b/src/tethering.c
@@ -57,7 +57,7 @@
#define PRIVATE_NETWORK_SECONDARY_DNS "8.8.4.4"
static volatile int tethering_enabled;
-static GDHCPServer *tethering_dhcp_server = NULL;
+static struct connman_dhcp_server *tethering_dhcp_server = NULL;
static struct connman_ippool *dhcp_ippool = NULL;
static DBusConnection *connection;
static GHashTable *pn_hash;
@@ -89,83 +89,6 @@ const char *__connman_tethering_get_bridge(void)
return BRIDGE_NAME;
}
-static void dhcp_server_debug(const char *str, void *data)
-{
- connman_info("%s: %s\n", (const char *) data, str);
-}
-
-static void dhcp_server_error(GDHCPServerError error)
-{
- switch (error) {
- case G_DHCP_SERVER_ERROR_NONE:
- connman_error("OK");
- break;
- case G_DHCP_SERVER_ERROR_INTERFACE_UNAVAILABLE:
- connman_error("Interface unavailable");
- break;
- case G_DHCP_SERVER_ERROR_INTERFACE_IN_USE:
- connman_error("Interface in use");
- break;
- case G_DHCP_SERVER_ERROR_INTERFACE_DOWN:
- connman_error("Interface down");
- break;
- case G_DHCP_SERVER_ERROR_NOMEM:
- connman_error("No memory");
- break;
- case G_DHCP_SERVER_ERROR_INVALID_INDEX:
- connman_error("Invalid index");
- break;
- case G_DHCP_SERVER_ERROR_INVALID_OPTION:
- connman_error("Invalid option");
- break;
- case G_DHCP_SERVER_ERROR_IP_ADDRESS_INVALID:
- connman_error("Invalid address");
- break;
- }
-}
-
-static GDHCPServer *dhcp_server_start(const char *bridge,
- const char *router, const char* subnet,
- const char *start_ip, const char *end_ip,
- unsigned int lease_time, const char *dns)
-{
- GDHCPServerError error;
- GDHCPServer *dhcp_server;
- int index;
-
- DBG("");
-
- index = connman_inet_ifindex(bridge);
- if (index < 0)
- return NULL;
-
- dhcp_server = g_dhcp_server_new(G_DHCP_IPV4, index, &error);
- if (dhcp_server == NULL) {
- dhcp_server_error(error);
- return NULL;
- }
-
- g_dhcp_server_set_debug(dhcp_server, dhcp_server_debug, "DHCP server");
-
- g_dhcp_server_set_lease_time(dhcp_server, lease_time);
- g_dhcp_server_set_option(dhcp_server, G_DHCP_SUBNET, subnet);
- g_dhcp_server_set_option(dhcp_server, G_DHCP_ROUTER, router);
- g_dhcp_server_set_option(dhcp_server, G_DHCP_DNS_SERVER, dns);
- g_dhcp_server_set_ip_range(dhcp_server, start_ip, end_ip);
-
- g_dhcp_server_start(dhcp_server);
-
- return dhcp_server;
-}
-
-static void dhcp_server_stop(GDHCPServer *server)
-{
- if (server == NULL)
- return;
-
- g_dhcp_server_unref(server);
-}
-
static void tethering_restart(struct connman_ippool *pool, void *user_data)
{
__connman_tethering_set_disabled();
@@ -220,11 +143,18 @@ void __connman_tethering_set_enabled(void)
dns = BRIDGE_DNS;
}
- tethering_dhcp_server = dhcp_server_start(BRIDGE_NAME,
+ tethering_dhcp_server = __connman_dhcp_server_create(index);
+ if (tethering_dhcp_server == NULL) {
+ __connman_bridge_disable(BRIDGE_NAME);
+ __connman_bridge_remove(BRIDGE_NAME);
+ return;
+ }
+
+ if (__connman_dhcp_server_start(tethering_dhcp_server,
gateway, subnet_mask,
start_ip, end_ip,
- 24 * 3600, dns);
- if (tethering_dhcp_server == NULL) {
+ 24 * 3600, dns) != 0) {
+ __connman_dhcp_server_unref(tethering_dhcp_server);
__connman_bridge_disable(BRIDGE_NAME);
__connman_bridge_remove(BRIDGE_NAME);
return;
@@ -248,8 +178,8 @@ void __connman_tethering_set_disabled(void)
__connman_nat_disable(BRIDGE_NAME);
- dhcp_server_stop(tethering_dhcp_server);
-
+ __connman_dhcp_server_stop(tethering_dhcp_server);
+ __connman_dhcp_server_unref(tethering_dhcp_server);
tethering_dhcp_server = NULL;
__connman_bridge_disable(BRIDGE_NAME);
@@ -479,8 +409,10 @@ void __connman_tethering_cleanup(void)
__sync_synchronize();
if (tethering_enabled == 0) {
- if (tethering_dhcp_server)
- dhcp_server_stop(tethering_dhcp_server);
+ if (tethering_dhcp_server != NULL) {
+ __connman_dhcp_server_stop(tethering_dhcp_server);
+ __connman_dhcp_server_unref(tethering_dhcp_server);
+ }
__connman_bridge_disable(BRIDGE_NAME);
__connman_bridge_remove(BRIDGE_NAME);
__connman_nat_disable(BRIDGE_NAME);
--
1.7.9.48.g85da4d
_______________________________________________
connman mailing list
[EMAIL PROTECTED]
http://lists.connman.net/listinfo/connman
- [PATCH v0 0/2] Move DHCP server from tethering.c to dhcp.c Daniel Wagner 2012/02/13
- [PATCH v0 1/2] dhcp: Add dhcp server functions Daniel Wagner 2012/02/13
- [PATCH v0 2/2] tethering: Use __connman_dhcp_server_*() Daniel Wagner 2012/02/13 <=