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_ipconfig_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); }
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"); #if defined TIZEN_EXT /* * Description: When DHCP is failed, * most of naive users cannot understand auto-generated IP * (IPV4 link local) and serious troubles to make Internet connection. */ dhcp_invalidate(dhcp, TRUE); service = __connman_service_lookup_from_network(dhcp->network); if (service == NULL) return; __connman_service_ipconfig_indicate_state(service, CONNMAN_SERVICE_STATE_IDLE, CONNMAN_IPCONFIG_TYPE_IPV4); __connman_service_ipconfig_indicate_state(service, CONNMAN_SERVICE_STATE_IDLE, CONNMAN_IPCONFIG_TYPE_IPV6); return; #endif 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_ipconfig_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); }
static void setup_tun_interface(unsigned int flags, unsigned change, void *data) { struct connman_private_network *pn = data; unsigned char prefixlen; DBusMessageIter array, dict; int err; DBG("index %d flags %d change %d", pn->index, flags, change); if (flags & IFF_UP) return; prefixlen = __connman_ipconfig_netmask_prefix_len(PRIVATE_NETWORK_NETMASK); if ((__connman_inet_modify_address(RTM_NEWADDR, NLM_F_REPLACE | NLM_F_ACK, pn->index, AF_INET, pn->server_ip, pn->peer_ip, prefixlen, NULL)) < 0) { DBG("address setting failed"); return; } connman_inet_ifup(pn->index); err = enable_nat(default_interface); if (err < 0) { connman_error("failed to enable NAT on %s", default_interface); goto error; } dbus_message_iter_init_append(pn->reply, &array); dbus_message_iter_append_basic(&array, DBUS_TYPE_OBJECT_PATH, &pn->path); connman_dbus_dict_open(&array, &dict); connman_dbus_dict_append_basic(&dict, "ServerIPv4", DBUS_TYPE_STRING, &pn->server_ip); connman_dbus_dict_append_basic(&dict, "PeerIPv4", DBUS_TYPE_STRING, &pn->peer_ip); connman_dbus_dict_append_basic(&dict, "PrimaryDNS", DBUS_TYPE_STRING, &pn->primary_dns); connman_dbus_dict_append_basic(&dict, "SecondaryDNS", DBUS_TYPE_STRING, &pn->secondary_dns); connman_dbus_dict_close(&array, &dict); dbus_message_iter_append_basic(&array, DBUS_TYPE_UNIX_FD, &pn->fd); g_dbus_send_message(connection, pn->reply); return; error: pn->reply = __connman_error_failed(pn->msg, -err); g_dbus_send_message(connection, pn->reply); g_hash_table_remove(pn_hash, pn->path); }
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, *timeserver = NULL, *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_ipconfig_netmask_prefix_len(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); for (ns_entries = 0, list = option; list; list = list->next) ns_entries += 1; 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); 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); if (option != NULL) timeserver = g_strdup(option->data); 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]); } g_strfreev(dhcp->nameservers); } dhcp->nameservers = nameservers; for (i = 0; dhcp->nameservers[i] != NULL; i++) { __connman_service_nameserver_append(service, dhcp->nameservers[i]); } } else { g_strfreev(nameservers); } if (g_strcmp0(timeserver, dhcp->timeserver) != 0) { if (dhcp->timeserver != NULL) { __connman_service_timeserver_remove(service, dhcp->timeserver); g_free(dhcp->timeserver); } dhcp->timeserver = timeserver; if (dhcp->timeserver != NULL) __connman_service_timeserver_append(service, dhcp->timeserver); } 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); }