static void dhcp_cli(int argc, char **argv) { void *intrfc_handle = NULL; int wait_for_sec = WAIT_FOR_UAP_START; if (argc >= 3 && string_equal(argv[2], "start")) { if (!strncmp(argv[1], "mlan0", 5)) intrfc_handle = net_get_mlan_handle(); else if (!strncmp(argv[1], "uap0", 4)) { while(wait_for_sec) { wait_for_sec--; if (!is_uap_started()) { if (wait_for_sec == 0) { dhcp_e("unable" " to start DHCP server. Retry" " after uAP is started"); return; } } else break; os_thread_sleep(os_msec_to_ticks(1000)); } intrfc_handle = net_get_uap_handle(); } if (dhcp_server_start(intrfc_handle)) dhcp_e("unable to " "start DHCP server"); } else if (argc >= 3 && string_equal(argv[2], "stop")) dhcp_server_stop(); else { wmprintf("Usage: %s %s\r\n", DHCPS_COMMAND, DHCPS_HELP); wmprintf("Error: invalid argument\r\n"); } }
void __connman_tethering_set_disabled(void) { int index; DBG("enabled %d", tethering_enabled - 1); __connman_ipv6pd_cleanup(); index = connman_inet_ifindex(BRIDGE_NAME); __connman_dnsproxy_remove_listener(index); if (__sync_fetch_and_sub(&tethering_enabled, 1) != 1) return; __connman_nat_disable(BRIDGE_NAME); dhcp_server_stop(tethering_dhcp_server); tethering_dhcp_server = NULL; __connman_bridge_disable(BRIDGE_NAME); __connman_ippool_unref(dhcp_ippool); __connman_bridge_remove(BRIDGE_NAME); g_free(private_network_primary_dns); private_network_primary_dns = NULL; g_free(private_network_secondary_dns); private_network_secondary_dns = NULL; DBG("tethering stopped"); }
void __connman_tethering_cleanup(void) { DBG(""); if (g_atomic_int_get(&tethering_enabled)) { if (tethering_dhcp_server) dhcp_server_stop(tethering_dhcp_server); disable_bridge(BRIDGE_NAME); remove_bridge(BRIDGE_NAME); } if (connection == NULL) return; g_hash_table_destroy(pn_hash); dbus_connection_unref(connection); }
void __connman_tethering_set_disabled(void) { DBG("enabled %d", tethering_enabled - 1); __connman_dnsproxy_remove_listener(BRIDGE_NAME); if (g_atomic_int_dec_and_test(&tethering_enabled) == TRUE) { disable_nat(default_interface); dhcp_server_stop(tethering_dhcp_server); disable_bridge(BRIDGE_NAME); remove_bridge(BRIDGE_NAME); DBG("tethering stopped"); } }
void __connman_tethering_cleanup(void) { DBG("enabled %d", tethering_enabled); __sync_synchronize(); if (tethering_enabled > 0) { if (tethering_dhcp_server) dhcp_server_stop(tethering_dhcp_server); __connman_bridge_disable(BRIDGE_NAME); __connman_bridge_remove(BRIDGE_NAME); __connman_nat_disable(BRIDGE_NAME); } if (connection == NULL) return; g_hash_table_destroy(pn_hash); dbus_connection_unref(connection); }
void __connman_tethering_set_enabled(void) { int index; int err; const char *gateway; const char *broadcast; const char *subnet_mask; const char *start_ip; const char *end_ip; const char *dns; unsigned char prefixlen; char **ns; DBG("enabled %d", tethering_enabled + 1); if (__sync_fetch_and_add(&tethering_enabled, 1) != 0) return; err = __connman_bridge_create(BRIDGE_NAME); if (err < 0) { __sync_fetch_and_sub(&tethering_enabled, 1); return; } index = connman_inet_ifindex(BRIDGE_NAME); dhcp_ippool = __connman_ippool_create(index, 2, 252, tethering_restart, NULL); if (!dhcp_ippool) { connman_error("Fail to create IP pool"); __connman_bridge_remove(BRIDGE_NAME); __sync_fetch_and_sub(&tethering_enabled, 1); return; } gateway = __connman_ippool_get_gateway(dhcp_ippool); broadcast = __connman_ippool_get_broadcast(dhcp_ippool); subnet_mask = __connman_ippool_get_subnet_mask(dhcp_ippool); start_ip = __connman_ippool_get_start_ip(dhcp_ippool); end_ip = __connman_ippool_get_end_ip(dhcp_ippool); err = __connman_bridge_enable(BRIDGE_NAME, gateway, connman_ipaddress_calc_netmask_len(subnet_mask), broadcast); if (err < 0 && err != -EALREADY) { __connman_ippool_unref(dhcp_ippool); __connman_bridge_remove(BRIDGE_NAME); __sync_fetch_and_sub(&tethering_enabled, 1); return; } ns = connman_setting_get_string_list("FallbackNameservers"); if (ns) { if (ns[0]) { g_free(private_network_primary_dns); private_network_primary_dns = g_strdup(ns[0]); } if (ns[1]) { g_free(private_network_secondary_dns); private_network_secondary_dns = g_strdup(ns[1]); } DBG("Fallback ns primary %s secondary %s", private_network_primary_dns, private_network_secondary_dns); } dns = gateway; if (__connman_dnsproxy_add_listener(index) < 0) { connman_error("Can't add listener %s to DNS proxy", BRIDGE_NAME); dns = private_network_primary_dns; DBG("Serving %s nameserver to clients", dns); } tethering_dhcp_server = dhcp_server_start(BRIDGE_NAME, gateway, subnet_mask, start_ip, end_ip, 24 * 3600, dns); if (!tethering_dhcp_server) { __connman_bridge_disable(BRIDGE_NAME); __connman_ippool_unref(dhcp_ippool); __connman_bridge_remove(BRIDGE_NAME); __sync_fetch_and_sub(&tethering_enabled, 1); return; } prefixlen = connman_ipaddress_calc_netmask_len(subnet_mask); err = __connman_nat_enable(BRIDGE_NAME, start_ip, prefixlen); if (err < 0) { connman_error("Cannot enable NAT %d/%s", err, strerror(-err)); dhcp_server_stop(tethering_dhcp_server); __connman_bridge_disable(BRIDGE_NAME); __connman_ippool_unref(dhcp_ippool); __connman_bridge_remove(BRIDGE_NAME); __sync_fetch_and_sub(&tethering_enabled, 1); return; } err = __connman_ipv6pd_setup(BRIDGE_NAME); if (err < 0 && err != -EINPROGRESS) DBG("Cannot setup IPv6 prefix delegation %d/%s", err, strerror(-err)); DBG("tethering started"); }