Hi Tomasz,
On 07/09/2014 02:36 PM, Tomasz Bursztyka wrote:
> Thus dhcp code will be usable in peer, where there is no service nor
> network objects.
> ---
> src/connman.h | 8 +-
> src/dhcp.c | 364
> +++++++++++++++++++++++++++++-----------------------------
> src/network.c | 19 ++-
> 3 files changed, 203 insertions(+), 188 deletions(-)
>
> diff --git a/src/connman.h b/src/connman.h
> index f286b12..c855634 100644
> --- a/src/connman.h
> +++ b/src/connman.h
> @@ -433,10 +433,12 @@ enum __connman_dhcpv6_status {
> typedef void (* dhcpv6_cb) (struct connman_network *network,
> enum __connman_dhcpv6_status status, gpointer data);
>
> -typedef void (* dhcp_cb) (struct connman_network *network,
> +typedef void (* dhcp_cb) (struct connman_ipconfig *ipconfig,
> + struct connman_network *opt_network,
> bool success, gpointer data);
> -int __connman_dhcp_start(struct connman_network *network, dhcp_cb callback);
> -void __connman_dhcp_stop(struct connman_network *network);
> +int __connman_dhcp_start(struct connman_ipconfig *ipconfig,
> + struct connman_network *opt_network, dhcp_cb callback);
I don't know if we should encode if a parameter is optional. Looks a bit
strange.
> +void __connman_dhcp_stop(struct connman_ipconfig *ipconfig);
> int __connman_dhcp_init(void);
> void __connman_dhcp_cleanup(void);
> int __connman_dhcpv6_init(void);
> diff --git a/src/dhcp.c b/src/dhcp.c
> index 3cacb6a..179cc03 100644
> --- a/src/dhcp.c
> +++ b/src/dhcp.c
> @@ -39,6 +39,7 @@
> #define RATE_LIMIT_INTERVAL 60 /* delay between successive attempts */
>
> struct connman_dhcp {
> + struct connman_ipconfig *ipconfig;
> struct connman_network *network;
Maybe add a comment here to *network, that is optional.
> dhcp_cb callback;
>
> @@ -54,7 +55,7 @@ struct connman_dhcp {
> char *dhcp_debug_prefix;
> };
>
> -static GHashTable *network_table;
> +static GHashTable *ipconfig_table;
> static bool ipv4ll_running;
>
> static void dhcp_free(struct connman_dhcp *dhcp)
> @@ -98,8 +99,6 @@ static void ipv4ll_stop_client(struct connman_dhcp *dhcp)
> */
> static void dhcp_invalidate(struct connman_dhcp *dhcp, bool callback)
> {
> - struct connman_service *service;
> - struct connman_ipconfig *ipconfig;
> int i;
>
> DBG("dhcp %p callback %u", dhcp, callback);
> @@ -107,52 +106,54 @@ static void dhcp_invalidate(struct connman_dhcp *dhcp,
> bool callback)
> if (!dhcp)
> return;
>
> - service = connman_service_lookup_from_network(dhcp->network);
> - if (!service)
> - return;
> -
> - ipconfig = __connman_service_get_ip4config(service);
> - if (!ipconfig)
> - return;
> + __connman_6to4_remove(dhcp->ipconfig);
>
> - __connman_6to4_remove(ipconfig);
> + if (dhcp->network) {
> + struct connman_service *service;
> + service = connman_service_lookup_from_network(dhcp->network);
> + if (!service) {
> + connman_error("Can not lookup service");
> + return;
> + }
>
> - __connman_service_set_domainname(service, NULL);
> - __connman_ipconfig_set_proxy_autoconfig(ipconfig, NULL);
> + __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,
> + if (dhcp->timeservers) {
> + for (i = 0; dhcp->timeservers[i]; i++) {
> + __connman_service_timeserver_remove(service,
> dhcp->timeservers[i]);
> + }
> }
> - }
>
> - if (dhcp->nameservers) {
> - for (i = 0; dhcp->nameservers[i]; i++) {
> - __connman_service_nameserver_remove(service,
> + if (dhcp->nameservers) {
> + for (i = 0; dhcp->nameservers[i]; 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_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(ipconfig);
> + __connman_ipconfig_address_remove(dhcp->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);
> + __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->network, false, NULL);
> + dhcp->callback(dhcp->ipconfig, dhcp->network, false, NULL);
> }
Maybe splitting the invalidate into two function, one which handles the
ipconfig part and one the network? Don't know if that works.
>
> static void dhcp_valid(struct connman_dhcp *dhcp)
> {
> if (dhcp->callback)
> - dhcp->callback(dhcp->network, true, NULL);
> + dhcp->callback(dhcp->ipconfig, dhcp->network, true, NULL);
> }
>
> static void dhcp_debug(const char *str, void *data)
> @@ -174,7 +175,7 @@ static int ipv4ll_start_client(struct connman_dhcp *dhcp)
> if (dhcp->ipv4ll_client)
> return -EALREADY;
>
> - index = connman_network_get_index(dhcp->network);
> + index = __connman_ipconfig_get_index(dhcp->ipconfig);
>
> ipv4ll_client = g_dhcp_client_new(G_DHCP_IPV4LL, index, &error);
> if (error != G_DHCP_CLIENT_ERROR_NONE)
> @@ -189,10 +190,12 @@ static int ipv4ll_start_client(struct connman_dhcp
> *dhcp)
>
> g_dhcp_client_set_id(ipv4ll_client);
>
> - hostname = connman_utsname_get_hostname();
> - if (hostname)
> - g_dhcp_client_set_send(ipv4ll_client, G_DHCP_HOST_NAME,
> - hostname);
> + if (dhcp->network) {
> + hostname = connman_utsname_get_hostname();
> + if (hostname)
> + g_dhcp_client_set_send(ipv4ll_client,
> + G_DHCP_HOST_NAME, hostname);
> + }
>
> g_dhcp_client_register_event(ipv4ll_client,
> G_DHCP_CLIENT_EVENT_IPV4LL_LOST, ipv4ll_lost_cb, dhcp);
> @@ -216,19 +219,11 @@ static int ipv4ll_start_client(struct connman_dhcp
> *dhcp)
> static gboolean dhcp_retry_cb(gpointer user_data)
> {
> struct connman_dhcp *dhcp = user_data;
> - struct connman_service *service;
> - struct connman_ipconfig *ipconfig;
>
> dhcp->timeout = 0;
>
> - service = connman_service_lookup_from_network(dhcp->network);
> - if (!service)
> - return FALSE;
> -
> - ipconfig = __connman_service_get_ip4config(service);
> -
> g_dhcp_client_start(dhcp->dhcp_client,
> - __connman_ipconfig_get_dhcp_address(ipconfig));
> + __connman_ipconfig_get_dhcp_address(dhcp->ipconfig));
>
> return FALSE;
> }
> @@ -305,10 +300,6 @@ static void lease_available_cb(GDHCPClient *dhcp_client,
> gpointer user_data)
> GList *list, *option = NULL;
> char *address, *netmask = NULL, *gateway = NULL;
> const char *c_address, *c_gateway;
> - char **nameservers, **timeservers, *pac = NULL;
> - int ns_entries;
> - struct connman_ipconfig *ipconfig;
> - struct connman_service *service;
> unsigned char prefixlen, c_prefixlen;
> bool ip_change;
> int i;
> @@ -320,25 +311,13 @@ static void lease_available_cb(GDHCPClient
> *dhcp_client, gpointer user_data)
> dhcp_invalidate(dhcp, false);
> }
>
> - service = connman_service_lookup_from_network(dhcp->network);
> - if (!service) {
> - connman_error("Can not lookup service");
> - return;
> - }
> -
> - ipconfig = __connman_service_get_ip4config(service);
> - if (!ipconfig) {
> - 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);
> + 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(ipconfig, address);
> + __connman_ipconfig_set_dhcp_address(dhcp->ipconfig, address);
> DBG("last address %s", address);
>
> option = g_dhcp_client_get_option(dhcp_client, G_DHCP_SUBNET);
> @@ -366,96 +345,117 @@ static void lease_available_cb(GDHCPClient
> *dhcp_client, gpointer user_data)
> 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) {
> - for (i = 0, list = option; list; list = list->next, i++)
> - nameservers[i] = g_strdup(list->data);
> - nameservers[ns_entries] = NULL;
> + __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);
> }
>
> - option = g_dhcp_client_get_option(dhcp_client, G_DHCP_DOMAIN_NAME);
> - if (option)
> - __connman_service_set_domainname(service, option->data);
> + if (dhcp->network) {
> + char **nameservers, **timeservers, *pac = NULL;
> + struct connman_service *service;
> + int ns_entries;
>
> - 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;
> - }
> + service = connman_service_lookup_from_network(dhcp->network);
> + if (!service) {
> + connman_error("Can not lookup service");
> + return;
> + }
>
> - option = g_dhcp_client_get_option(dhcp_client, 252);
> - if (option)
> - pac = g_strdup(option->data);
> + 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) {
> + list = option;
> + for (i = 0; list; list = list->next, i++)
> + nameservers[i] = g_strdup(list->data);
> + nameservers[ns_entries] = NULL;
> + }
>
> - __connman_ipconfig_set_method(ipconfig, CONNMAN_IPCONFIG_METHOD_DHCP);
> + 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) {
> + list = option;
> + for (i = 0; list; list = list->next, i++)
> + timeservers[i] = g_strdup(list->data);
> + timeservers[ns_entries] = NULL;
> + }
>
> - if (ip_change) {
> - __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)) {
> + if (dhcp->nameservers) {
> + for (i = 0; dhcp->nameservers[i]; i++) {
> + __connman_service_nameserver_remove(
> + service, dhcp->nameservers[i],
> + false);
> + }
> + g_strfreev(dhcp->nameservers);
> + }
>
> - if (!compare_string_arrays(nameservers, dhcp->nameservers)) {
> - if (dhcp->nameservers) {
> - for (i = 0; dhcp->nameservers[i]; i++) {
> - __connman_service_nameserver_remove(service,
> + dhcp->nameservers = nameservers;
> +
> + for (i = 0; dhcp->nameservers &&
> + dhcp->nameservers[i]; i++) {
> + __connman_service_nameserver_append(service,
> dhcp->nameservers[i], false);
> }
> - g_strfreev(dhcp->nameservers);
> + } else {
> + g_strfreev(nameservers);
> }
>
> - dhcp->nameservers = 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);
> + }
>
> - for (i = 0; dhcp->nameservers &&
> - dhcp->nameservers[i]; i++) {
> - __connman_service_nameserver_append(service,
> - dhcp->nameservers[i], false);
> - }
> - } else {
> - g_strfreev(nameservers);
> - }
> + dhcp->timeservers = timeservers;
>
> - if (!compare_string_arrays(timeservers, dhcp->timeservers)) {
> - if (dhcp->timeservers) {
> - for (i = 0; dhcp->timeservers[i]; i++) {
> - __connman_service_timeserver_remove(service,
> + for (i = 0; dhcp->timeservers &&
> + dhcp->timeservers[i]; i++) {
> + __connman_service_timeserver_append(service,
> dhcp->timeservers[i]);
> }
> - g_strfreev(dhcp->timeservers);
> + } else {
> + g_strfreev(timeservers);
> }
>
> - dhcp->timeservers = timeservers;
> + if (g_strcmp0(pac, dhcp->pac) != 0) {
> + g_free(dhcp->pac);
> + dhcp->pac = pac;
>
> - for (i = 0; dhcp->timeservers &&
> - dhcp->timeservers[i]; i++) {
> - __connman_service_timeserver_append(service,
> - dhcp->timeservers[i]);
> + __connman_ipconfig_set_proxy_autoconfig(dhcp->ipconfig,
> + dhcp->pac);
> }
> - } else {
> - g_strfreev(timeservers);
> - }
> -
> - if (g_strcmp0(pac, dhcp->pac) != 0) {
> - g_free(dhcp->pac);
> - dhcp->pac = pac;
>
> - __connman_ipconfig_set_proxy_autoconfig(ipconfig, dhcp->pac);
> + __connman_6to4_probe(service);
> }
>
> if (ip_change)
> dhcp_valid(dhcp);
>
> - __connman_6to4_probe(service);
> -
> g_free(address);
> g_free(netmask);
> g_free(gateway);
Again, if possible I would split the ipconfig and network part into two
functions.
> @@ -465,29 +465,20 @@ static void ipv4ll_available_cb(GDHCPClient
> *ipv4ll_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)
> - return;
> -
> - ipconfig = __connman_service_get_ip4config(service);
> - if (!ipconfig)
> - return;
> -
> address = g_dhcp_client_get_address(ipv4ll_client);
> netmask = g_dhcp_client_get_netmask(ipv4ll_client);
>
> prefixlen = connman_ipaddress_calc_netmask_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);
> + __connman_ipconfig_set_method(dhcp->ipconfig,
> + CONNMAN_IPCONFIG_METHOD_DHCP);
> + __connman_ipconfig_set_local(dhcp->ipconfig, address);
> + __connman_ipconfig_set_prefixlen(dhcp->ipconfig, prefixlen);
> + __connman_ipconfig_set_gateway(dhcp->ipconfig, NULL);
>
> dhcp_valid(dhcp);
>
> @@ -497,15 +488,13 @@ static void ipv4ll_available_cb(GDHCPClient
> *ipv4ll_client, gpointer user_data)
>
> static int dhcp_initialize(struct connman_dhcp *dhcp)
> {
> - struct connman_service *service;
> GDHCPClient *dhcp_client;
> GDHCPClientError error;
> - const char *hostname;
> int index;
>
> DBG("dhcp %p", dhcp);
>
> - index = connman_network_get_index(dhcp->network);
> + 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)
> @@ -520,22 +509,29 @@ static int dhcp_initialize(struct connman_dhcp *dhcp)
>
> g_dhcp_client_set_id(dhcp_client);
>
> - service = connman_service_lookup_from_network(dhcp->network);
> + if (dhcp->network) {
> + struct connman_service *service;
> + const char *hostname;
>
> - hostname = __connman_service_get_hostname(service);
> - if (!hostname)
> - hostname = connman_utsname_get_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);
> + 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_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,
> @@ -576,34 +572,40 @@ static int dhcp_release(struct connman_dhcp *dhcp)
> return 0;
> }
>
> -int __connman_dhcp_start(struct connman_network *network, dhcp_cb callback)
> +int __connman_dhcp_start(struct connman_ipconfig *ipconfig,
> + struct connman_network *opt_network, dhcp_cb callback)
> {
> - struct connman_service *service;
> - struct connman_ipconfig *ipconfig;
> const char *last_addr = NULL;
> struct connman_dhcp *dhcp;
>
> DBG("");
>
> - service = connman_service_lookup_from_network(network);
> - if (!service)
> - return -EINVAL;
> + if (opt_network) {
> + struct connman_service *service;
>
> - ipconfig = __connman_service_get_ip4config(service);
> - if (ipconfig)
> - last_addr = __connman_ipconfig_get_dhcp_address(ipconfig);
> + service = connman_service_lookup_from_network(opt_network);
> + if (!service)
> + return -EINVAL;
> + }
> +
> + last_addr = __connman_ipconfig_get_dhcp_address(ipconfig);
>
> - dhcp = g_hash_table_lookup(network_table, network);
> + dhcp = g_hash_table_lookup(ipconfig_table, ipconfig);
> if (!dhcp) {
>
> dhcp = g_try_new0(struct connman_dhcp, 1);
> if (!dhcp)
> return -ENOMEM;
>
> - dhcp->network = network;
> - connman_network_ref(network);
> + dhcp->ipconfig = ipconfig;
> + __connman_ipconfig_ref(ipconfig);
> +
> + if (opt_network) {
> + dhcp->network = opt_network;
> + connman_network_ref(opt_network);
> + }
>
> - g_hash_table_insert(network_table, network, dhcp);
> + g_hash_table_insert(ipconfig_table, ipconfig, dhcp);
>
> dhcp_initialize(dhcp);
> }
> @@ -613,19 +615,21 @@ int __connman_dhcp_start(struct connman_network
> *network, dhcp_cb callback)
> return g_dhcp_client_start(dhcp->dhcp_client, last_addr);
> }
>
> -void __connman_dhcp_stop(struct connman_network *network)
> +void __connman_dhcp_stop(struct connman_ipconfig *ipconfig)
> {
> struct connman_dhcp *dhcp;
>
> - DBG("network_table %p network %p", network_table, network);
> + DBG("ipconfig_table %p ipconfig %p", ipconfig_table, ipconfig);
>
> - if (!network_table)
> + if (!ipconfig_table)
> return;
>
> - dhcp = g_hash_table_lookup(network_table, network);
> + dhcp = g_hash_table_lookup(ipconfig_table, ipconfig);
> if (dhcp) {
> - g_hash_table_remove(network_table, network);
> - connman_network_unref(network);
> + g_hash_table_remove(ipconfig_table, ipconfig);
> + __connman_ipconfig_unref(ipconfig);
> + if (dhcp->network)
> + connman_network_unref(dhcp->network);
> dhcp_release(dhcp);
> dhcp_invalidate(dhcp, false);
> dhcp_free(dhcp);
> @@ -636,8 +640,8 @@ int __connman_dhcp_init(void)
> {
> DBG("");
>
> - network_table = g_hash_table_new_full(g_direct_hash, g_direct_equal,
> - NULL, NULL);
> + ipconfig_table = g_hash_table_new_full(g_direct_hash, g_direct_equal,
> + NULL, NULL);
>
> return 0;
> }
> @@ -646,6 +650,6 @@ void __connman_dhcp_cleanup(void)
> {
> DBG("");
>
> - g_hash_table_destroy(network_table);
> - network_table = NULL;
> + g_hash_table_destroy(ipconfig_table);
> + ipconfig_table = NULL;
> }
> diff --git a/src/network.c b/src/network.c
> index 37f807c..4b5fb27 100644
> --- a/src/network.c
> +++ b/src/network.c
> @@ -202,7 +202,8 @@ static void dhcp_failure(struct connman_network *network)
> __connman_ipconfig_gateway_remove(ipconfig_ipv4);
> }
>
> -static void dhcp_callback(struct connman_network *network,
> +static void dhcp_callback(struct connman_ipconfig *ipconfig,
> + struct connman_network *network,
> bool success, gpointer data)
> {
> if (success)
> @@ -285,13 +286,18 @@ err:
>
> static int set_connected_dhcp(struct connman_network *network)
> {
> + struct connman_service *service;
> + struct connman_ipconfig *ipconfig_ipv4;
> int err;
>
> DBG("network %p", network);
>
> set_configuration(network, CONNMAN_IPCONFIG_TYPE_IPV4);
>
> - err = __connman_dhcp_start(network, dhcp_callback);
> + service = connman_service_lookup_from_network(network);
> + ipconfig_ipv4 = __connman_service_get_ip4config(service);
> +
> + err = __connman_dhcp_start(ipconfig_ipv4, network, dhcp_callback);
> if (err < 0) {
> connman_error("Can not request DHCP lease");
> return err;
> @@ -717,7 +723,7 @@ static void set_disconnected(struct connman_network
> *network)
> case CONNMAN_IPCONFIG_METHOD_MANUAL:
> break;
> case CONNMAN_IPCONFIG_METHOD_DHCP:
> - __connman_dhcp_stop(network);
> + __connman_dhcp_stop(ipconfig_ipv4);
> break;
> }
> }
> @@ -1607,6 +1613,7 @@ int __connman_network_clear_ipconfig(struct
> connman_network *network,
> struct connman_ipconfig *ipconfig)
> {
> struct connman_service *service;
> + struct connman_ipconfig *ipconfig_ipv4;
> enum connman_ipconfig_method method;
> enum connman_ipconfig_type type;
>
> @@ -1614,6 +1621,7 @@ int __connman_network_clear_ipconfig(struct
> connman_network *network,
> if (!service)
> return -EINVAL;
>
> + ipconfig_ipv4 = __connman_service_get_ip4config(service);
> method = __connman_ipconfig_get_method(ipconfig);
> type = __connman_ipconfig_get_config_type(ipconfig);
>
> @@ -1629,7 +1637,7 @@ int __connman_network_clear_ipconfig(struct
> connman_network *network,
> __connman_ipconfig_address_remove(ipconfig);
> break;
> case CONNMAN_IPCONFIG_METHOD_DHCP:
> - __connman_dhcp_stop(network);
> + __connman_dhcp_stop(ipconfig_ipv4);
> break;
> }
>
> @@ -1691,7 +1699,8 @@ int __connman_network_set_ipconfig(struct
> connman_network *network,
> case CONNMAN_IPCONFIG_METHOD_MANUAL:
> return manual_ipv4_set(network, ipconfig_ipv4);
> case CONNMAN_IPCONFIG_METHOD_DHCP:
> - return __connman_dhcp_start(network, dhcp_callback);
> + return __connman_dhcp_start(ipconfig_ipv4,
> + network, dhcp_callback);
> }
> }
>
If you think it would be better to have a patch on top for refactoring
instead changing this one, I don't mind.
cheers,
daniel
_______________________________________________
connman mailing list
[email protected]
https://lists.connman.net/mailman/listinfo/connman