--- src/tethering.c | 43 +++++++++++++++++++++++++++++-------------- 1 files changed, 29 insertions(+), 14 deletions(-)
diff --git a/src/tethering.c b/src/tethering.c index e310cf0..75dcce2 100644 --- a/src/tethering.c +++ b/src/tethering.c @@ -49,11 +49,6 @@ #define BRIDGE_PROC_DIR "/proc/sys/net/bridge" #define BRIDGE_NAME "tether" -#define BRIDGE_IP "192.168.218.1" -#define BRIDGE_BCAST "192.168.218.255" -#define BRIDGE_SUBNET "255.255.255.0" -#define BRIDGE_IP_START "192.168.218.100" -#define BRIDGE_IP_END "192.168.218.200" #define BRIDGE_DNS "8.8.8.8" #define DEFAULT_MTU 1500 @@ -64,6 +59,7 @@ static char *default_interface = NULL; static volatile gint tethering_enabled; static GDHCPServer *tethering_dhcp_server = NULL; +static struct connman_ippool *dhcp_pool = NULL; static DBusConnection *connection; static GHashTable *pn_hash; @@ -244,7 +240,8 @@ static int remove_bridge(const char *name) return 0; } -static int enable_bridge(const char *name) +static int enable_bridge(const char *name, const char *broadcast, + const char *gateway) { int err, index; @@ -254,7 +251,7 @@ static int enable_bridge(const char *name) err = __connman_inet_modify_address(RTM_NEWADDR, NLM_F_REPLACE | NLM_F_ACK, index, AF_INET, - BRIDGE_IP, NULL, 24, BRIDGE_BCAST); + gateway, NULL, 24, broadcast); if (err < 0) return err; @@ -335,6 +332,11 @@ static void disable_nat(const char *interface) void __connman_tethering_set_enabled(void) { int err; + const char *gateway; + const char *broadcast; + const char *start_ip; + const char *end_ip; + const char *subnet; DBG("enabled %d", tethering_enabled + 1); @@ -345,24 +347,35 @@ void __connman_tethering_set_enabled(void) if (err < 0) return; - err = enable_bridge(BRIDGE_NAME); + dhcp_pool = __connman_ippool_create(BRIDGE_NAME, 100, 100, + &gateway, &broadcast, + &start_ip, &end_ip, + &subnet, &err); + if (dhcp_pool == NULL) { + connman_error("Fail to create pool with error %d", + err); + return; + } + + err = enable_bridge(BRIDGE_NAME, gateway, broadcast); if (err < 0) { remove_bridge(BRIDGE_NAME); return; } - dns = BRIDGE_IP; + dns = gateway; 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); + tethering_dhcp_server = dhcp_server_start(BRIDGE_NAME, gateway, + subnet, + start_ip, + end_ip, + 24 * 3600, + dns); if (tethering_dhcp_server == NULL) { disable_bridge(BRIDGE_NAME); remove_bridge(BRIDGE_NAME); @@ -388,6 +401,8 @@ void __connman_tethering_set_disabled(void) disable_bridge(BRIDGE_NAME); + __connman_ippool_remove(dhcp_pool); + remove_bridge(BRIDGE_NAME); DBG("tethering stopped"); -- 1.7.1 _______________________________________________ connman mailing list connman@connman.net http://lists.connman.net/listinfo/connman