From e4932cc390e77c7af2f7085e1caedad44b3420f2 Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Wed, 23 Feb 2011 21:05:39 +0100 Subject: [PATCH] ipconfig: Split ipconfig_set_gateway() ipconfig_set_gateway() sets the gateway pointer while gateway_add() sets the route. --- src/connman.h | 2 ++ src/ipconfig.c | 50 +++++++++++++++++++++++++++++++++++--------------- src/network.c | 26 +++++++++++++++++--------- 3 files changed, 54 insertions(+), 24 deletions(-) diff --git a/src/connman.h b/src/connman.h index 5bcb827..0b44b9b 100644 --- a/src/connman.h +++ b/src/connman.h @@ -263,6 +263,8 @@ void __connman_ipconfig_set_element_ipv6_gateway( int __connman_ipconfig_address_add(struct connman_ipconfig *ipconfig); int __connman_ipconfig_address_remove(struct connman_ipconfig *ipconfig); +int __connman_ipconfig_gateway_add(struct connman_ipconfig *ipconfig); +void __connman_ipconfig_gateway_remove(struct connman_ipconfig *ipconfig); unsigned char __connman_ipconfig_netmask_prefix_len(const char *netmask); int __connman_ipconfig_set_proxy_autoconfig(struct connman_ipconfig *ipconfig, diff --git a/src/ipconfig.c b/src/ipconfig.c index 0ca44b8..ca983b4 100644 --- a/src/ipconfig.c +++ b/src/ipconfig.c @@ -1054,31 +1054,51 @@ const char *__connman_ipconfig_get_gateway(struct connman_ipconfig *ipconfig) void __connman_ipconfig_set_gateway(struct connman_ipconfig *ipconfig, const char *gateway) { - struct connman_service *service; + DBG(""); if (ipconfig->address == NULL) return; + g_free(ipconfig->address->gateway); + ipconfig->address->gateway = g_strdup(gateway); +} + +int __connman_ipconfig_gateway_add(struct connman_ipconfig *ipconfig) +{ + struct connman_service *service; + + DBG(""); + + if (ipconfig->address == NULL || ipconfig->address->gateway == NULL) + return -EINVAL; service = __connman_service_lookup_from_index(ipconfig->index); - if (service != NULL) - __connman_connection_gateway_remove(service); + if (service == NULL) + return -EINVAL; - g_free(ipconfig->address->gateway); - ipconfig->address->gateway = g_strdup(gateway); + __connman_connection_gateway_remove(service); - if (service != NULL && ipconfig->address->gateway != NULL) { - if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6) { - __connman_connection_gateway_add(service, - NULL, + if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6) { + return __connman_connection_gateway_add(service, NULL, ipconfig->address->gateway, - ipconfig->address->peer); - } else if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV4) { - __connman_connection_gateway_add(service, + ipconfig->address->peer); + } else if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV4) { + return __connman_connection_gateway_add(service, ipconfig->address->gateway, - NULL, - ipconfig->address->peer); - } + NULL, ipconfig->address->peer); } + + return 0; +} + +void __connman_ipconfig_gateway_remove(struct connman_ipconfig *ipconfig) +{ + struct connman_service *service; + + DBG(""); + + service = __connman_service_lookup_from_index(ipconfig->index); + if (service != NULL) + __connman_connection_gateway_remove(service); } unsigned char __connman_ipconfig_get_prefixlen(struct connman_ipconfig *ipconfig) diff --git a/src/network.c b/src/network.c index 3f3e825..83ba518 100644 --- a/src/network.c +++ b/src/network.c @@ -696,11 +696,8 @@ static void set_connected_manual(struct connman_network *network) set_configuration(network); err = __connman_ipconfig_address_add(ipconfig); - if (err < 0) { - connman_network_set_error(network, - CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL); - return; - } + if (err < 0) + goto err; connman_element_get_value(&network->element, CONNMAN_PROPERTY_ID_IPV4_NAMESERVER, &nameserver); @@ -709,8 +706,12 @@ static void set_connected_manual(struct connman_network *network) connman_element_get_value(&network->element, CONNMAN_PROPERTY_ID_IPV4_GATEWAY, &gateway); - if (gateway != NULL) + if (gateway != NULL) { __connman_ipconfig_set_gateway(ipconfig, gateway); + err = __connman_ipconfig_gateway_add(ipconfig); + if (err < 0) + goto err; + } network->connecting = FALSE; @@ -718,6 +719,11 @@ static void set_connected_manual(struct connman_network *network) __connman_service_indicate_state(service, CONNMAN_SERVICE_STATE_READY, CONNMAN_IPCONFIG_TYPE_IPV4); + +err: + connman_network_set_error(network, + CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL); + return; } static int set_connected_dhcp(struct connman_network *network) @@ -1090,8 +1096,10 @@ static int manual_ipv4_set(struct connman_network *network, connman_element_get_value(&network->element, CONNMAN_PROPERTY_ID_IPV4_GATEWAY, &gateway); - if (gateway != NULL) + if (gateway != NULL) { __connman_ipconfig_set_gateway(ipconfig, gateway); + __connman_ipconfig_gateway_add(ipconfig); + } __connman_service_indicate_state(service, CONNMAN_SERVICE_STATE_READY, CONNMAN_IPCONFIG_TYPE_IPV4); @@ -1212,10 +1220,10 @@ int connman_network_set_ipaddress(struct connman_network *network, __connman_ipconfig_set_local(ipconfig, ipaddress->local); __connman_ipconfig_set_peer(ipconfig, ipaddress->peer); __connman_ipconfig_set_broadcast(ipconfig, ipaddress->broadcast); - __connman_ipconfig_set_gateway(ipconfig, ipaddress->gateway); __connman_ipconfig_set_prefixlen(ipconfig, ipaddress->prefixlen); + __connman_ipconfig_set_gateway(ipconfig, ipaddress->gateway); - return 0; + return __connman_ipconfig_gateway_add(ipconfig); } int connman_network_set_pac(struct connman_network *network, -- 2.7.4