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");
	}
}
Esempio n. 2
0
void __connman_tethering_set_enabled(void)
{
	int err;

	DBG("enabled %d", tethering_enabled + 1);

	if (g_atomic_int_exchange_and_add(&tethering_enabled, 1) == 0) {
		const char *dns;

		err = create_bridge(BRIDGE_NAME);
		if (err < 0)
			return;

		err = enable_bridge(BRIDGE_NAME);
		if (err < 0 && err != -EALREADY) {
			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",
								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");
	}
}
Esempio n. 3
0
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 == NULL) {
		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_netmask_prefix_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 != NULL) {
		if (ns[0] != NULL) {
			g_free(private_network_primary_dns);
			private_network_primary_dns = g_strdup(ns[0]);
		}
		if (ns[1] != NULL) {
			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 == NULL) {
		__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_netmask_prefix_len(subnet_mask);
	__connman_nat_enable(BRIDGE_NAME, start_ip, prefixlen);

	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");
}