static void ipv4ll_available_cb(GDHCPClient *dhcp_client, gpointer user_data) { struct connman_dhcp *dhcp = user_data; char *address, *netmask; struct connman_service *service; struct connman_ipconfig *ipconfig; unsigned char prefixlen; DBG("IPV4LL available"); service = connman_service_lookup_from_network(dhcp->network); if (service == NULL) return; ipconfig = __connman_service_get_ip4config(service); if (ipconfig == NULL) return; address = g_dhcp_client_get_address(dhcp_client); netmask = g_dhcp_client_get_netmask(dhcp_client); prefixlen = __connman_ipaddress_netmask_prefix_len(netmask); __connman_ipconfig_set_method(ipconfig, CONNMAN_IPCONFIG_METHOD_DHCP); __connman_ipconfig_set_local(ipconfig, address); __connman_ipconfig_set_prefixlen(ipconfig, prefixlen); __connman_ipconfig_set_gateway(ipconfig, NULL); dhcp_valid(dhcp); g_free(address); g_free(netmask); }
/** * 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 int dhcpv6_info_request(struct connman_dhcpv6 *dhcp) { struct connman_service *service; GDHCPClient *dhcp_client; GDHCPClientError error; int index, ret; DBG("dhcp %p", dhcp); index = connman_network_get_index(dhcp->network); dhcp_client = g_dhcp_client_new(G_DHCP_IPV6, index, &error); if (error != G_DHCP_CLIENT_ERROR_NONE) { clear_timer(dhcp); return -EINVAL; } if (getenv("CONNMAN_DHCPV6_DEBUG")) g_dhcp_client_set_debug(dhcp_client, dhcpv6_debug, "DHCPv6"); service = connman_service_lookup_from_network(dhcp->network); if (service == NULL) { clear_timer(dhcp); g_dhcp_client_unref(dhcp_client); return -EINVAL; } ret = set_duid(service, dhcp->network, dhcp_client, index); if (ret < 0) { clear_timer(dhcp); g_dhcp_client_unref(dhcp_client); return ret; } g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID); g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DNS_SERVERS); g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SNTP_SERVERS); g_dhcpv6_client_set_oro(dhcp_client, 2, G_DHCPV6_DNS_SERVERS, G_DHCPV6_SNTP_SERVERS); g_dhcp_client_register_event(dhcp_client, G_DHCP_CLIENT_EVENT_INFORMATION_REQ, info_req_cb, dhcp); dhcp->dhcp_client = dhcp_client; return g_dhcp_client_start(dhcp_client, NULL); }
int __connman_dhcp_start(struct connman_ipconfig *ipconfig, struct connman_network *network, dhcp_cb callback, gpointer user_data) { const char *last_addr = NULL; struct connman_dhcp *dhcp; int err; DBG(""); if (network) { struct connman_service *service; service = connman_service_lookup_from_network(network); if (!service) return -EINVAL; } last_addr = __connman_ipconfig_get_dhcp_address(ipconfig); dhcp = g_hash_table_lookup(ipconfig_table, ipconfig); if (!dhcp) { dhcp = g_try_new0(struct connman_dhcp, 1); if (!dhcp) return -ENOMEM; dhcp->ipconfig = ipconfig; __connman_ipconfig_ref(ipconfig); if (network) { dhcp->network = network; connman_network_ref(network); } err = dhcp_initialize(dhcp); if (err < 0) { if (network) connman_network_unref(network); g_free(dhcp); return err; } g_hash_table_insert(ipconfig_table, ipconfig, dhcp); }
int connman_device_disconnect_service(struct connman_device *device) { DBG("device %p", device); device->reconnect = false; if (device->network) { struct connman_service *service = connman_service_lookup_from_network(device->network); if (service) __connman_service_disconnect(service); else connman_network_set_connected(device->network, false); } return 0; }
int __connman_device_disable(struct connman_device *device) { int err; DBG("device %p", device); if (!device->driver || !device->driver->disable) return -EOPNOTSUPP; /* Ongoing power enable request */ if (device->powered_pending == PENDING_ENABLE) return -EBUSY; if (device->powered_pending == PENDING_DISABLE) return -EALREADY; if (device->powered_pending == PENDING_NONE && device->powered == FALSE) return -EALREADY; device->powered_pending = PENDING_DISABLE; device->reconnect = FALSE; if (device->network) { struct connman_service *service = connman_service_lookup_from_network(device->network); if (service != NULL) __connman_service_disconnect(service); else connman_network_set_connected(device->network, FALSE); } err = device->driver->disable(device); if (err == 0 || err == -EALREADY) { connman_device_set_powered(device, FALSE); goto done; } if (err == -EINPROGRESS) device->pending_timeout = g_timeout_add_seconds(4, device_pending_reset, device); done: return err; }
static bool apply_dhcp_invalidate_on_network(struct connman_dhcp *dhcp) { struct connman_service *service; int i; if (!dhcp->network) return true; service = connman_service_lookup_from_network(dhcp->network); if (!service) { connman_error("Can not lookup service"); return false; } __connman_service_set_domainname(service, NULL); __connman_ipconfig_set_proxy_autoconfig(dhcp->ipconfig, NULL); if (dhcp->timeservers) { for (i = 0; dhcp->timeservers[i]; i++) { __connman_service_timeserver_remove(service, dhcp->timeservers[i]); } g_strfreev(dhcp->timeservers); dhcp->timeservers = NULL; } if (dhcp->nameservers) { for (i = 0; dhcp->nameservers[i]; i++) { __connman_service_nameserver_remove(service, dhcp->nameservers[i], false); } g_strfreev(dhcp->nameservers); dhcp->nameservers = NULL; } return true; }
static int dhcp_initialize(struct connman_dhcp *dhcp) { GDHCPClient *dhcp_client; GDHCPClientError error; int index; DBG("dhcp %p", dhcp); index = __connman_ipconfig_get_index(dhcp->ipconfig); dhcp_client = g_dhcp_client_new(G_DHCP_IPV4, index, &error); if (error != G_DHCP_CLIENT_ERROR_NONE) return -EINVAL; if (getenv("CONNMAN_DHCP_DEBUG")) { dhcp->dhcp_debug_prefix = g_strdup_printf("DHCP index %d", index); g_dhcp_client_set_debug(dhcp_client, dhcp_debug, dhcp->dhcp_debug_prefix); } g_dhcp_client_set_id(dhcp_client); if (dhcp->network) { struct connman_service *service; const char *hostname; service = connman_service_lookup_from_network(dhcp->network); hostname = __connman_service_get_hostname(service); if (!hostname) hostname = connman_utsname_get_hostname(); if (hostname) g_dhcp_client_set_send(dhcp_client, G_DHCP_HOST_NAME, hostname); g_dhcp_client_set_request(dhcp_client, G_DHCP_HOST_NAME); g_dhcp_client_set_request(dhcp_client, G_DHCP_DNS_SERVER); g_dhcp_client_set_request(dhcp_client, G_DHCP_DOMAIN_NAME); g_dhcp_client_set_request(dhcp_client, G_DHCP_NTP_SERVER); g_dhcp_client_set_request(dhcp_client, 252); g_dhcp_client_set_request(dhcp_client, G_DHCP_MTU); } g_dhcp_client_set_request(dhcp_client, G_DHCP_SUBNET); g_dhcp_client_set_request(dhcp_client, G_DHCP_ROUTER); g_dhcp_client_register_event(dhcp_client, G_DHCP_CLIENT_EVENT_LEASE_AVAILABLE, lease_available_cb, dhcp); g_dhcp_client_register_event(dhcp_client, G_DHCP_CLIENT_EVENT_LEASE_LOST, lease_lost_cb, dhcp); g_dhcp_client_register_event(dhcp_client, G_DHCP_CLIENT_EVENT_NO_LEASE, no_lease_cb, dhcp); dhcp->dhcp_client = dhcp_client; return 0; }
static bool apply_lease_available_on_network(GDHCPClient *dhcp_client, struct connman_dhcp *dhcp) { char **nameservers, **timeservers, *pac = NULL; struct connman_service *service; GList *list, *option = NULL; int ns_entries; int i; if (!dhcp->network) return true; service = connman_service_lookup_from_network(dhcp->network); if (!service) { connman_error("Can not lookup service"); return false; } option = g_dhcp_client_get_option(dhcp_client, G_DHCP_MTU); if (option && option->data) { int mtu, index, err; mtu = atoi(option->data); if (mtu >= IPV6_MIN_MTU && mtu <= ETH_DATA_LEN) { index = __connman_ipconfig_get_index(dhcp->ipconfig); err = connman_inet_set_mtu(index, mtu); DBG("MTU %d index %d err %d", mtu, index, err); } } option = g_dhcp_client_get_option(dhcp_client, 252); if (option) pac = g_strdup(option->data); option = g_dhcp_client_get_option(dhcp_client, G_DHCP_DNS_SERVER); ns_entries = g_list_length(option); nameservers = g_try_new0(char *, ns_entries + 1); if (nameservers) { for (i = 0, list = option;list; list = list->next, i++) nameservers[i] = g_strdup(list->data); nameservers[ns_entries] = NULL; } option = g_dhcp_client_get_option(dhcp_client, G_DHCP_DOMAIN_NAME); if (option) __connman_service_set_domainname(service, option->data); option = g_dhcp_client_get_option(dhcp_client, G_DHCP_HOST_NAME); if (option) __connman_service_set_hostname(service, option->data); option = g_dhcp_client_get_option(dhcp_client, G_DHCP_NTP_SERVER); ns_entries = g_list_length(option); timeservers = g_try_new0(char *, ns_entries + 1); if (timeservers) { for (i = 0, list = option; list; list = list->next, i++) timeservers[i] = g_strdup(list->data); timeservers[ns_entries] = NULL; } if (!compare_string_arrays(nameservers, dhcp->nameservers)) { if (dhcp->nameservers) { for (i = 0; dhcp->nameservers[i]; i++) { __connman_service_nameserver_remove(service, dhcp->nameservers[i], false); } g_strfreev(dhcp->nameservers); } dhcp->nameservers = nameservers; for (i = 0; dhcp->nameservers && dhcp->nameservers[i]; i++) { __connman_service_nameserver_append(service, dhcp->nameservers[i], false); } } else { g_strfreev(nameservers); } if (!compare_string_arrays(timeservers, dhcp->timeservers)) { if (dhcp->timeservers) { for (i = 0; dhcp->timeservers[i]; i++) { __connman_service_timeserver_remove(service, dhcp->timeservers[i]); } g_strfreev(dhcp->timeservers); } dhcp->timeservers = timeservers; for (i = 0; dhcp->timeservers && dhcp->timeservers[i]; i++) { __connman_service_timeserver_append(service, dhcp->timeservers[i]); } } else { g_strfreev(timeservers); } if (g_strcmp0(pac, dhcp->pac) != 0) { g_free(dhcp->pac); dhcp->pac = pac; __connman_ipconfig_set_proxy_autoconfig(dhcp->ipconfig, dhcp->pac); } if (connman_setting_get_bool("Enable6to4")) __connman_6to4_probe(service); return true; }
/** * @brief Add the network associated to its qmi device */ static void add_network(struct qmi_data *qmi) { struct connman_network *network = NULL; int index; struct connman_service *service = NULL; g_return_if_fail(qmi); DBG("data %p", qmi); if(qmi->network != NULL) { DBG("network %p already exists.", qmi->network); return; } /* Create an new qmi network */ network = connman_network_create(qmi->devpath, CONNMAN_NETWORK_TYPE_QMI); if(network == NULL) { connman_error("Network could not be created."); return; } DBG("network %p", qmi->network); /* Set network properties */ index = connman_device_get_index(qmi->device); connman_network_set_index(network, index); connman_network_set_data(network, qmi); connman_network_set_strength(network, qmi->strength); connman_network_set_group(network, qmi->group); if(qmi->provider) g_free(qmi->provider); qmi->provider = g_strdup("no-name"); connman_network_set_name(network, qmi->provider); /* Add the created network */ if (connman_device_add_network(qmi->device, network) < 0) { connman_error("Network not added to the device."); connman_network_unref(network); network = NULL; return; } qmi->network = network; /* Get configured values from the created *.config file */ service = connman_service_lookup_from_network(network); DBG("service %p", service); if(service == NULL) { connman_error("No service available"); return; } service = connman_service_ref(service); if(qmi->apn) g_free(qmi->apn); qmi->apn = g_strdup(connman_service_get_string(service, "APN")); if(qmi->passphrase) g_free(qmi->passphrase); qmi->passphrase = g_strdup(connman_service_get_string(service, "Passphrase")); if(qmi->username) g_free(qmi->username); qmi->username = g_strdup(connman_service_get_string(service, "Username")); if(qmi->provider) g_free(qmi->provider); qmi->provider = g_strdup(connman_service_get_string(service, "Provider")); if(qmi->provider == NULL) qmi->provider = g_strdup("no-name"); connman_network_set_name(network, qmi->provider); connman_network_update(qmi->network); DBG("network %p IMSI %s APN %s PW %s Username %s", qmi->network, qmi->imsi, qmi->apn, qmi->passphrase, qmi->username); connman_service_unref(service); if((qmi->imsi == NULL) || (qmi->apn == NULL) || (qmi->passphrase == NULL)) { connman_error("There are not all required parameters available"); return; } }
static int set_addresses(GDHCPClient *dhcp_client, struct connman_dhcpv6 *dhcp) { struct connman_service *service; struct connman_ipconfig *ipconfig; int entries, i; GList *option, *list; char **nameservers, **timeservers; const char *c_address; char *address = NULL; service = connman_service_lookup_from_network(dhcp->network); if (service == NULL) { connman_error("Can not lookup service"); return -EINVAL; } ipconfig = __connman_service_get_ip6config(service); if (ipconfig == NULL) { connman_error("Could not lookup ip6config"); return -EINVAL; } option = g_dhcp_client_get_option(dhcp_client, G_DHCPV6_DNS_SERVERS); entries = g_list_length(option); nameservers = g_try_new0(char *, entries + 1); if (nameservers != NULL) { for (i = 0, list = option; list; list = list->next, i++) nameservers[i] = g_strdup(list->data); } if (compare_string_arrays(nameservers, dhcp->nameservers) == FALSE) { if (dhcp->nameservers != NULL) { for (i = 0; dhcp->nameservers[i] != NULL; i++) __connman_service_nameserver_remove(service, dhcp->nameservers[i], FALSE); g_strfreev(dhcp->nameservers); } dhcp->nameservers = nameservers; for (i = 0; dhcp->nameservers != NULL && dhcp->nameservers[i] != NULL; i++) __connman_service_nameserver_append(service, dhcp->nameservers[i], FALSE); } else g_strfreev(nameservers); option = g_dhcp_client_get_option(dhcp_client, G_DHCPV6_SNTP_SERVERS); entries = g_list_length(option); timeservers = g_try_new0(char *, entries + 1); if (timeservers != NULL) { for (i = 0, list = option; list; list = list->next, i++) timeservers[i] = g_strdup(list->data); } if (compare_string_arrays(timeservers, dhcp->timeservers) == FALSE) { if (dhcp->timeservers != NULL) { for (i = 0; dhcp->timeservers[i] != NULL; i++) __connman_service_timeserver_remove(service, dhcp->timeservers[i]); g_strfreev(dhcp->timeservers); } dhcp->timeservers = timeservers; for (i = 0; dhcp->timeservers != NULL && dhcp->timeservers[i] != NULL; i++) __connman_service_timeserver_append(service, dhcp->timeservers[i]); } else g_strfreev(timeservers); option = g_dhcp_client_get_option(dhcp_client, G_DHCPV6_IA_NA); if (option != NULL) address = g_strdup(option->data); else { option = g_dhcp_client_get_option(dhcp_client, G_DHCPV6_IA_TA); if (option != NULL) address = g_strdup(option->data); } c_address = __connman_ipconfig_get_local(ipconfig); if (address != NULL && ((c_address != NULL && g_strcmp0(address, c_address) != 0) || (c_address == NULL))) { int prefix_len; /* Is this prefix part of the subnet we are suppose to use? */ prefix_len = check_ipv6_addr_prefix(dhcp->prefixes, address); __connman_ipconfig_set_local(ipconfig, address); __connman_ipconfig_set_prefixlen(ipconfig, prefix_len); DBG("new address %s/%d", address, prefix_len); } return 0; }
static void info_req_cb(GDHCPClient *dhcp_client, gpointer user_data) { struct connman_dhcpv6 *dhcp = user_data; struct connman_service *service; int entries, i; GList *option, *list; char **nameservers, **timeservers; DBG("dhcpv6 information-request %p", dhcp); service = connman_service_lookup_from_network(dhcp->network); if (service == NULL) { connman_error("Can not lookup service"); return; } option = g_dhcp_client_get_option(dhcp_client, G_DHCPV6_DNS_SERVERS); entries = g_list_length(option); nameservers = g_try_new0(char *, entries + 1); if (nameservers != NULL) { for (i = 0, list = option; list; list = list->next, i++) nameservers[i] = g_strdup(list->data); } if (compare_string_arrays(nameservers, dhcp->nameservers) == FALSE) { if (dhcp->nameservers != NULL) { for (i = 0; dhcp->nameservers[i] != NULL; i++) __connman_service_nameserver_remove(service, dhcp->nameservers[i], FALSE); g_strfreev(dhcp->nameservers); } dhcp->nameservers = nameservers; for (i = 0; dhcp->nameservers != NULL && dhcp->nameservers[i] != NULL; i++) __connman_service_nameserver_append(service, dhcp->nameservers[i], FALSE); } else g_strfreev(nameservers); option = g_dhcp_client_get_option(dhcp_client, G_DHCPV6_SNTP_SERVERS); entries = g_list_length(option); timeservers = g_try_new0(char *, entries + 1); if (timeservers != NULL) { for (i = 0, list = option; list; list = list->next, i++) timeservers[i] = g_strdup(list->data); } if (compare_string_arrays(timeservers, dhcp->timeservers) == FALSE) { if (dhcp->timeservers != NULL) { for (i = 0; dhcp->timeservers[i] != NULL; i++) __connman_service_timeserver_remove(service, dhcp->timeservers[i]); g_strfreev(dhcp->timeservers); } dhcp->timeservers = timeservers; for (i = 0; dhcp->timeservers != NULL && dhcp->timeservers[i] != NULL; i++) __connman_service_timeserver_append(service, dhcp->timeservers[i]); } else g_strfreev(timeservers); if (dhcp->callback != NULL) { uint16_t status = g_dhcpv6_client_get_status(dhcp_client); dhcp->callback(dhcp->network, status == 0 ? TRUE : FALSE); } }
static int dhcpv6_solicitation(struct connman_dhcpv6 *dhcp) { struct connman_service *service; struct connman_ipconfig *ipconfig_ipv6; GDHCPClient *dhcp_client; GDHCPClientError error; int index, ret; DBG("dhcp %p", dhcp); index = connman_network_get_index(dhcp->network); dhcp_client = g_dhcp_client_new(G_DHCP_IPV6, index, &error); if (error != G_DHCP_CLIENT_ERROR_NONE) { clear_timer(dhcp); return -EINVAL; } if (getenv("CONNMAN_DHCPV6_DEBUG")) g_dhcp_client_set_debug(dhcp_client, dhcpv6_debug, "DHCPv6"); service = connman_service_lookup_from_network(dhcp->network); if (service == NULL) { clear_timer(dhcp); g_dhcp_client_unref(dhcp_client); return -EINVAL; } ret = set_duid(service, dhcp->network, dhcp_client, index); if (ret < 0) { clear_timer(dhcp); g_dhcp_client_unref(dhcp_client); return ret; } g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID); g_dhcp_client_set_request(dhcp_client, G_DHCPV6_RAPID_COMMIT); g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DNS_SERVERS); g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SNTP_SERVERS); g_dhcpv6_client_set_oro(dhcp_client, 2, G_DHCPV6_DNS_SERVERS, G_DHCPV6_SNTP_SERVERS); ipconfig_ipv6 = __connman_service_get_ip6config(service); dhcp->use_ta = __connman_ipconfig_ipv6_privacy_enabled(ipconfig_ipv6); g_dhcpv6_client_set_ia(dhcp_client, index, dhcp->use_ta == TRUE ? G_DHCPV6_IA_TA : G_DHCPV6_IA_NA, NULL, NULL, FALSE); clear_callbacks(dhcp_client); g_dhcp_client_register_event(dhcp_client, G_DHCP_CLIENT_EVENT_SOLICITATION, solicitation_cb, dhcp); g_dhcp_client_register_event(dhcp_client, G_DHCP_CLIENT_EVENT_ADVERTISE, advertise_cb, dhcp); dhcp->dhcp_client = dhcp_client; return g_dhcp_client_start(dhcp_client, NULL); }
static int dhcp_request(struct connman_dhcp *dhcp) { struct connman_service *service; struct connman_ipconfig *ipconfig; GDHCPClient *dhcp_client; GDHCPClientError error; const char *hostname; int index; DBG("dhcp %p", dhcp); index = connman_network_get_index(dhcp->network); dhcp_client = g_dhcp_client_new(G_DHCP_IPV4, index, &error); if (error != G_DHCP_CLIENT_ERROR_NONE) return -EINVAL; if (getenv("CONNMAN_DHCP_DEBUG")) g_dhcp_client_set_debug(dhcp_client, dhcp_debug, "DHCP"); g_dhcp_client_set_id(dhcp_client); hostname = connman_utsname_get_hostname(); if (hostname != NULL) g_dhcp_client_set_send(dhcp_client, G_DHCP_HOST_NAME, hostname); g_dhcp_client_set_request(dhcp_client, G_DHCP_HOST_NAME); g_dhcp_client_set_request(dhcp_client, G_DHCP_SUBNET); g_dhcp_client_set_request(dhcp_client, G_DHCP_DNS_SERVER); g_dhcp_client_set_request(dhcp_client, G_DHCP_DOMAIN_NAME); g_dhcp_client_set_request(dhcp_client, G_DHCP_NTP_SERVER); g_dhcp_client_set_request(dhcp_client, G_DHCP_ROUTER); g_dhcp_client_set_request(dhcp_client, 252); g_dhcp_client_register_event(dhcp_client, G_DHCP_CLIENT_EVENT_LEASE_AVAILABLE, lease_available_cb, dhcp); g_dhcp_client_register_event(dhcp_client, G_DHCP_CLIENT_EVENT_IPV4LL_AVAILABLE, ipv4ll_available_cb, dhcp); g_dhcp_client_register_event(dhcp_client, G_DHCP_CLIENT_EVENT_LEASE_LOST, lease_lost_cb, dhcp); g_dhcp_client_register_event(dhcp_client, G_DHCP_CLIENT_EVENT_IPV4LL_LOST, ipv4ll_lost_cb, dhcp); g_dhcp_client_register_event(dhcp_client, G_DHCP_CLIENT_EVENT_NO_LEASE, no_lease_cb, dhcp); dhcp->dhcp_client = dhcp_client; service = connman_service_lookup_from_network(dhcp->network); ipconfig = __connman_service_get_ip4config(service); /* * Clear the addresses at startup so that lease callback will * take the lease and set ip address properly. */ __connman_ipconfig_clear_address(ipconfig); return g_dhcp_client_start(dhcp_client, __connman_ipconfig_get_dhcp_address(ipconfig)); }
static void lease_available_cb(GDHCPClient *dhcp_client, gpointer user_data) { struct connman_dhcp *dhcp = user_data; GList *list, *option = NULL; char *address, *netmask = NULL, *gateway = NULL; const char *c_address, *c_gateway; char *domainname = NULL, *hostname = NULL; char **nameservers, **timeservers, *pac = NULL; int ns_entries; struct connman_ipconfig *ipconfig; struct connman_service *service; unsigned char prefixlen, c_prefixlen; gboolean ip_change; int i; DBG("Lease available"); service = connman_service_lookup_from_network(dhcp->network); if (service == NULL) { connman_error("Can not lookup service"); return; } ipconfig = __connman_service_get_ip4config(service); if (ipconfig == NULL) { connman_error("Could not lookup ipconfig"); return; } c_address = __connman_ipconfig_get_local(ipconfig); c_gateway = __connman_ipconfig_get_gateway(ipconfig); c_prefixlen = __connman_ipconfig_get_prefixlen(ipconfig); address = g_dhcp_client_get_address(dhcp_client); __connman_ipconfig_set_dhcp_address(ipconfig, address); DBG("last address %s", address); option = g_dhcp_client_get_option(dhcp_client, G_DHCP_SUBNET); if (option != NULL) netmask = g_strdup(option->data); option = g_dhcp_client_get_option(dhcp_client, G_DHCP_ROUTER); if (option != NULL) gateway = g_strdup(option->data); prefixlen = __connman_ipaddress_netmask_prefix_len(netmask); if (prefixlen == 255) connman_warn("netmask: %s is invalid", netmask); DBG("c_address %s", c_address); if (address != NULL && c_address != NULL && g_strcmp0(address, c_address) != 0) ip_change = TRUE; else if (gateway != NULL && c_gateway != NULL && g_strcmp0(gateway, c_gateway) != 0) ip_change = TRUE; else if (prefixlen != c_prefixlen) ip_change = TRUE; else if (c_address == NULL || c_gateway == NULL) ip_change = TRUE; else ip_change = FALSE; option = g_dhcp_client_get_option(dhcp_client, G_DHCP_DNS_SERVER); ns_entries = g_list_length(option); nameservers = g_try_new0(char *, ns_entries + 1); if (nameservers != NULL) { for (i = 0, list = option; list; list = list->next, i++) nameservers[i] = g_strdup(list->data); nameservers[ns_entries] = NULL; } option = g_dhcp_client_get_option(dhcp_client, G_DHCP_DOMAIN_NAME); if (option != NULL) domainname = g_strdup(option->data); if (connman_setting_get_bool("AllowHostnameUpdates") == TRUE) { option = g_dhcp_client_get_option(dhcp_client, G_DHCP_HOST_NAME); if (option != NULL) hostname = g_strdup(option->data); } option = g_dhcp_client_get_option(dhcp_client, G_DHCP_NTP_SERVER); ns_entries = g_list_length(option); timeservers = g_try_new0(char *, ns_entries + 1); if (timeservers != NULL) { for (i = 0, list = option; list; list = list->next, i++) timeservers[i] = g_strdup(list->data); timeservers[ns_entries] = NULL; } option = g_dhcp_client_get_option(dhcp_client, 252); if (option != NULL) pac = g_strdup(option->data); __connman_ipconfig_set_method(ipconfig, CONNMAN_IPCONFIG_METHOD_DHCP); if (ip_change == TRUE) { __connman_ipconfig_set_local(ipconfig, address); __connman_ipconfig_set_prefixlen(ipconfig, prefixlen); __connman_ipconfig_set_gateway(ipconfig, gateway); } if (compare_string_arrays(nameservers, dhcp->nameservers) == FALSE) { if (dhcp->nameservers != NULL) { for (i = 0; dhcp->nameservers[i] != NULL; i++) { __connman_service_nameserver_remove(service, dhcp->nameservers[i], FALSE); } g_strfreev(dhcp->nameservers); } dhcp->nameservers = nameservers; for (i = 0; dhcp->nameservers != NULL && dhcp->nameservers[i] != NULL; i++) { __connman_service_nameserver_append(service, dhcp->nameservers[i], FALSE); } } else { g_strfreev(nameservers); } if (compare_string_arrays(timeservers, dhcp->timeservers) == FALSE) { if (dhcp->timeservers != NULL) { for (i = 0; dhcp->timeservers[i] != NULL; i++) { __connman_service_timeserver_remove(service, dhcp->timeservers[i]); } g_strfreev(dhcp->timeservers); } dhcp->timeservers = timeservers; for (i = 0; dhcp->timeservers != NULL && dhcp->timeservers[i] != NULL; i++) { __connman_service_timeserver_append(service, dhcp->timeservers[i]); } } else { g_strfreev(timeservers); } if (g_strcmp0(pac, dhcp->pac) != 0) { g_free(dhcp->pac); dhcp->pac = pac; __connman_service_set_pac(service, dhcp->pac); } __connman_service_set_domainname(service, domainname); if (domainname != NULL) __connman_utsname_set_domainname(domainname); if (hostname != NULL) __connman_utsname_set_hostname(hostname); if (ip_change == TRUE) dhcp_valid(dhcp); __connman_6to4_probe(service); g_free(address); g_free(netmask); g_free(gateway); g_free(domainname); g_free(hostname); }