*
* Connection Manager
*
- * Copyright (C) 2007-2012 Intel Corporation. All rights reserved.
+ * Copyright (C) 2007-2013 Intel Corporation. All rights reserved.
* Copyright (C) 2011 ProFUSION embedded systems
*
* This program is free software; you can redistribute it and/or modify
}
static GDHCPServer *dhcp_server_start(const char *bridge,
- const char *router, const char* subnet,
+ const char *router, const char *subnet,
const char *start_ip, const char *end_ip,
unsigned int lease_time, const char *dns)
{
return NULL;
dhcp_server = g_dhcp_server_new(G_DHCP_IPV4, index, &error);
- if (dhcp_server == NULL) {
+ if (!dhcp_server) {
dhcp_server_error(error);
return NULL;
}
static void dhcp_server_stop(GDHCPServer *server)
{
- if (server == NULL)
+ if (!server)
return;
g_dhcp_server_unref(server);
static void tethering_restart(struct connman_ippool *pool, void *user_data)
{
+ DBG("pool %p", pool);
__connman_tethering_set_disabled();
__connman_tethering_set_enabled();
}
index = connman_inet_ifindex(BRIDGE_NAME);
dhcp_ippool = __connman_ippool_create(index, 2, 252,
tethering_restart, NULL);
- if (dhcp_ippool == NULL) {
+ if (!dhcp_ippool) {
connman_error("Fail to create IP pool");
__connman_bridge_remove(BRIDGE_NAME);
__sync_fetch_and_sub(&tethering_enabled, 1);
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, broadcast);
+ 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);
}
ns = connman_setting_get_string_list("FallbackNameservers");
- if (ns != NULL) {
- if (ns[0] != NULL) {
+ if (ns) {
+ if (ns[0]) {
g_free(private_network_primary_dns);
private_network_primary_dns = g_strdup(ns[0]);
}
- if (ns[1] != NULL) {
+ if (ns[1]) {
g_free(private_network_secondary_dns);
private_network_secondary_dns = g_strdup(ns[1]);
}
gateway, subnet_mask,
start_ip, end_ip,
24 * 3600, dns);
- if (tethering_dhcp_server == NULL) {
+ if (!tethering_dhcp_server) {
__connman_bridge_disable(BRIDGE_NAME);
__connman_ippool_unref(dhcp_ippool);
__connman_bridge_remove(BRIDGE_NAME);
return;
}
- prefixlen =
- __connman_ipaddress_netmask_prefix_len(subnet_mask);
- __connman_nat_enable(BRIDGE_NAME, start_ip, prefixlen);
+ prefixlen = __connman_ipaddress_netmask_prefix_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");
}
DBG("enabled %d", tethering_enabled - 1);
- index = connman_inet_ifindex(BRIDGE_NAME);
- __connman_dnsproxy_remove_listener(index);
-
if (__sync_fetch_and_sub(&tethering_enabled, 1) != 1)
return;
+ __connman_ipv6pd_cleanup();
+
+ index = connman_inet_ifindex(BRIDGE_NAME);
+ __connman_dnsproxy_remove_listener(index);
+
__connman_nat_disable(BRIDGE_NAME);
dhcp_server_stop(tethering_dhcp_server);
DBUS_TYPE_STRING, &server_ip);
connman_dbus_dict_append_basic(&dict, "PeerIPv4",
DBUS_TYPE_STRING, &peer_ip);
- if (pn->primary_dns != NULL)
+ if (pn->primary_dns)
connman_dbus_dict_append_basic(&dict, "PrimaryDNS",
DBUS_TYPE_STRING, &pn->primary_dns);
- if (pn->secondary_dns != NULL)
+ if (pn->secondary_dns)
connman_dbus_dict_append_basic(&dict, "SecondaryDNS",
DBUS_TYPE_STRING, &pn->secondary_dns);
err = connman_inet_set_mtu(index, DEFAULT_MTU);
pn = g_try_new0(struct connman_private_network, 1);
- if (pn == NULL) {
+ if (!pn) {
err = -ENOMEM;
goto error;
}
owner_disconnect, pn, NULL);
pn->msg = msg;
pn->reply = dbus_message_new_method_return(pn->msg);
- if (pn->reply == NULL)
+ if (!pn->reply)
goto error;
pn->fd = fd;
pn->interface = iface;
pn->index = index;
pn->pool = __connman_ippool_create(pn->index, 1, 1, ippool_disconnect, pn);
- if (pn->pool == NULL) {
+ if (!pn->pool) {
errno = -ENOMEM;
goto error;
}
struct connman_private_network *pn;
pn = g_hash_table_lookup(pn_hash, path);
- if (pn == NULL)
+ if (!pn)
return -EACCES;
g_hash_table_remove(pn_hash, path);
tethering_enabled = 0;
connection = connman_dbus_get_connection();
- if (connection == NULL)
+ if (!connection)
return -EFAULT;
pn_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
void __connman_tethering_cleanup(void)
{
- DBG("");
+ DBG("enabled %d", tethering_enabled);
__sync_synchronize();
- if (tethering_enabled == 0) {
+ if (tethering_enabled > 0) {
if (tethering_dhcp_server)
dhcp_server_stop(tethering_dhcp_server);
__connman_bridge_disable(BRIDGE_NAME);
__connman_nat_disable(BRIDGE_NAME);
}
- if (connection == NULL)
+ if (!connection)
return;
g_hash_table_destroy(pn_hash);