ipconfig: Split ipconfig_set_gateway()
authorSamuel Ortiz <sameo@linux.intel.com>
Wed, 23 Feb 2011 20:05:39 +0000 (21:05 +0100)
committerSamuel Ortiz <sameo@linux.intel.com>
Wed, 23 Feb 2011 20:05:39 +0000 (21:05 +0100)
ipconfig_set_gateway() sets the gateway pointer while gateway_add() sets
the route.

src/connman.h
src/ipconfig.c
src/network.c

index 5bcb827..0b44b9b 100644 (file)
@@ -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,
index 0ca44b8..ca983b4 100644 (file)
@@ -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)
index 3f3e825..83ba518 100644 (file)
@@ -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,