/** * dhcp_invalidate: Invalidate an existing DHCP lease * @dhcp: pointer to the DHCP lease to invalidate. * @callback: flag indicating whether or not to invoke the client callback * if present. * * Invalidates an existing DHCP lease, optionally invoking the client * callback. The caller may wish to avoid the client callback invocation * when the invocation of that callback might otherwise unnecessarily upset * service state due to the IP configuration change implied by this * invalidation. */ static void dhcp_invalidate(struct connman_dhcp *dhcp, bool callback) { DBG("dhcp %p callback %u", dhcp, callback); if (!dhcp) return; __connman_6to4_remove(dhcp->ipconfig); if (!apply_dhcp_invalidate_on_network(dhcp)) return; __connman_ipconfig_set_dhcp_address(dhcp->ipconfig, __connman_ipconfig_get_local(dhcp->ipconfig)); DBG("last address %s", __connman_ipconfig_get_dhcp_address(dhcp->ipconfig)); __connman_ipconfig_address_remove(dhcp->ipconfig); __connman_ipconfig_set_local(dhcp->ipconfig, NULL); __connman_ipconfig_set_broadcast(dhcp->ipconfig, NULL); __connman_ipconfig_set_gateway(dhcp->ipconfig, NULL); __connman_ipconfig_set_prefixlen(dhcp->ipconfig, 0); if (dhcp->callback && callback) dhcp->callback(dhcp->ipconfig, dhcp->network, false, dhcp->user_data); }
/** * dhcp_invalidate: Invalidate an existing DHCP lease * @dhcp: pointer to the DHCP lease to invalidate. * @callback: flag indicating whether or not to invoke the client callback * if present. * * Invalidates an existing DHCP lease, optionally invoking the client * callback. The caller may wish to avoid the client callback invocation * when the invocation of that callback might otherwise unnecessarily upset * service state due to the IP configuration change implied by this * invalidation. */ static void dhcp_invalidate(struct connman_dhcp *dhcp, connman_bool_t callback) { struct connman_service *service; struct connman_ipconfig *ipconfig; int i; DBG("dhcp %p callback %u", dhcp, callback); if (dhcp == NULL) return; service = connman_service_lookup_from_network(dhcp->network); if (service == NULL) goto out; ipconfig = __connman_service_get_ip4config(service); if (ipconfig == NULL) goto out; __connman_6to4_remove(ipconfig); __connman_service_set_domainname(service, NULL); __connman_service_set_pac(service, NULL); if (dhcp->timeservers != NULL) { for (i = 0; dhcp->timeservers[i] != NULL; i++) { __connman_service_timeserver_remove(service, dhcp->timeservers[i]); } } if (dhcp->nameservers != NULL) { for (i = 0; dhcp->nameservers[i] != NULL; i++) { __connman_service_nameserver_remove(service, dhcp->nameservers[i], FALSE); } } __connman_ipconfig_set_dhcp_address(ipconfig, __connman_ipconfig_get_local(ipconfig)); DBG("last address %s", __connman_ipconfig_get_dhcp_address(ipconfig)); __connman_ipconfig_address_remove(ipconfig); __connman_ipconfig_set_local(ipconfig, NULL); __connman_ipconfig_set_broadcast(ipconfig, NULL); __connman_ipconfig_set_gateway(ipconfig, NULL); __connman_ipconfig_set_prefixlen(ipconfig, 0); if (dhcp->callback != NULL && callback) dhcp->callback(dhcp->network, FALSE, NULL); out: dhcp_free(dhcp); }
static void dhcp_callback(struct connman_ipconfig *ipconfig, struct connman_network *network, bool success, gpointer data) { struct connman_peer *peer = data; int err; if (!success) goto error; DBG("lease acquired for ipconfig %p", ipconfig); err = __connman_ipconfig_address_add(ipconfig); if (err < 0) goto error; return; error: __connman_ipconfig_address_remove(ipconfig); connman_peer_set_state(peer, CONNMAN_PEER_STATE_FAILURE); }
int __connman_network_clear_ipconfig(struct connman_network *network, struct connman_ipconfig *ipconfig) { struct connman_service *service; enum connman_ipconfig_method method; enum connman_ipconfig_type type; service = __connman_service_lookup_from_network(network); if (service == NULL) return -EINVAL; method = __connman_ipconfig_get_method(ipconfig); type = __connman_ipconfig_get_config_type(ipconfig); switch (method) { case CONNMAN_IPCONFIG_METHOD_UNKNOWN: case CONNMAN_IPCONFIG_METHOD_OFF: case CONNMAN_IPCONFIG_METHOD_FIXED: case CONNMAN_IPCONFIG_METHOD_AUTO: return -EINVAL; case CONNMAN_IPCONFIG_METHOD_MANUAL: __connman_ipconfig_address_remove(ipconfig); break; case CONNMAN_IPCONFIG_METHOD_DHCP: __connman_dhcp_stop(network); break; } if (type == CONNMAN_IPCONFIG_TYPE_IPV6) __connman_service_ipconfig_indicate_state(service, CONNMAN_SERVICE_STATE_CONFIGURATION, CONNMAN_IPCONFIG_TYPE_IPV6); else if (type == CONNMAN_IPCONFIG_TYPE_IPV4) __connman_service_ipconfig_indicate_state(service, CONNMAN_SERVICE_STATE_CONFIGURATION, CONNMAN_IPCONFIG_TYPE_IPV4); return 0; }
static void lease_available_cb(GDHCPClient *dhcp_client, gpointer user_data) { struct connman_dhcp *dhcp = user_data; GList *option = NULL; char *address, *netmask = NULL, *gateway = NULL; const char *c_address, *c_gateway; unsigned char prefixlen, c_prefixlen; bool ip_change = false; DBG("Lease available"); if (dhcp->ipv4ll_client) { ipv4ll_stop_client(dhcp); dhcp_invalidate(dhcp, false); } c_address = __connman_ipconfig_get_local(dhcp->ipconfig); c_gateway = __connman_ipconfig_get_gateway(dhcp->ipconfig); c_prefixlen = __connman_ipconfig_get_prefixlen(dhcp->ipconfig); address = g_dhcp_client_get_address(dhcp_client); __connman_ipconfig_set_dhcp_address(dhcp->ipconfig, address); DBG("last address %s", address); option = g_dhcp_client_get_option(dhcp_client, G_DHCP_SUBNET); if (option) netmask = g_strdup(option->data); option = g_dhcp_client_get_option(dhcp_client, G_DHCP_ROUTER); if (option) gateway = g_strdup(option->data); prefixlen = connman_ipaddress_calc_netmask_len(netmask); if (prefixlen == 255) connman_warn("netmask: %s is invalid", netmask); DBG("c_address %s", c_address); if (g_strcmp0(address, c_address)) { ip_change = true; if (c_address) { /* Remove old ip address */ __connman_ipconfig_address_remove(dhcp->ipconfig); } } if (g_strcmp0(gateway, c_gateway)) { ip_change = true; if (c_gateway) { /* Remove gateway ip address */ __connman_ipconfig_gateway_remove(dhcp->ipconfig); } } else if (prefixlen != c_prefixlen) ip_change = true; __connman_ipconfig_set_method(dhcp->ipconfig, CONNMAN_IPCONFIG_METHOD_DHCP); if (ip_change) { __connman_ipconfig_set_local(dhcp->ipconfig, address); __connman_ipconfig_set_prefixlen(dhcp->ipconfig, prefixlen); __connman_ipconfig_set_gateway(dhcp->ipconfig, gateway); } if (!apply_lease_available_on_network(dhcp_client, dhcp)) goto done; if (ip_change) dhcp_valid(dhcp); done: g_free(address); g_free(netmask); g_free(gateway); }