Add gateway to connman_ipaddress
authorMartin Xu <martin.xu@intel.com>
Thu, 25 Mar 2010 03:36:48 +0000 (11:36 +0800)
committerSamuel Ortiz <sameo@linux.intel.com>
Thu, 25 Mar 2010 14:07:37 +0000 (15:07 +0100)
include/ipconfig.h
src/ipconfig.c

index 8e99c6d..0b70252 100644 (file)
@@ -37,12 +37,13 @@ struct connman_ipaddress {
        char *local;
        char *peer;
        char *broadcast;
+       char *gateway;
 };
 
 struct connman_ipaddress *connman_ipaddress_alloc(void);
 void connman_ipaddress_free(struct connman_ipaddress *ipaddress);
 void connman_ipaddress_set(struct connman_ipaddress *ipaddress,
-                               const char *address, const char *netmask);
+               const char *address, const char *netmask, const char *gateway);
 void connman_ipaddress_clear(struct connman_ipaddress *ipaddress);
 void connman_ipaddress_copy(struct connman_ipaddress *ipaddress,
                                        struct connman_ipaddress *source);
index 87f7c41..26380d8 100644 (file)
@@ -90,6 +90,7 @@ void connman_ipaddress_free(struct connman_ipaddress *ipaddress)
        g_free(ipaddress->broadcast);
        g_free(ipaddress->peer);
        g_free(ipaddress->local);
+       g_free(ipaddress->gateway);
        g_free(ipaddress);
 }
 
@@ -110,7 +111,7 @@ static unsigned char netmask2prefixlen(const char *netmask)
 }
 
 void connman_ipaddress_set(struct connman_ipaddress *ipaddress,
-                               const char *address, const char *netmask)
+               const char *address, const char *netmask, const char *gateway)
 {
        if (ipaddress == NULL)
                return;
@@ -122,6 +123,9 @@ void connman_ipaddress_set(struct connman_ipaddress *ipaddress,
 
        g_free(ipaddress->local);
        ipaddress->local = g_strdup(address);
+
+       g_free(ipaddress->gateway);
+       ipaddress->gateway = g_strdup(gateway);
 }
 
 void connman_ipaddress_clear(struct connman_ipaddress *ipaddress)
@@ -139,6 +143,9 @@ void connman_ipaddress_clear(struct connman_ipaddress *ipaddress)
 
        g_free(ipaddress->broadcast);
        ipaddress->broadcast = NULL;
+
+       g_free(ipaddress->gateway);
+       ipaddress->gateway = NULL;
 }
 
 void connman_ipaddress_copy(struct connman_ipaddress *ipaddress,
@@ -157,6 +164,9 @@ void connman_ipaddress_copy(struct connman_ipaddress *ipaddress,
 
        g_free(ipaddress->broadcast);
        ipaddress->broadcast = g_strdup(source->broadcast);
+
+       g_free(ipaddress->gateway);
+       ipaddress->gateway = g_strdup(source->gateway);
 }
 
 static void free_address_list(struct connman_ipdevice *ipdevice)
@@ -1122,7 +1132,7 @@ int __connman_ipconfig_set_ipv4config(struct connman_ipconfig *ipconfig,
                                                        DBusMessageIter *array)
 {
        enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
-       const char *address = NULL, *netmask = NULL;
+       const char *address = NULL, *netmask = NULL, *gateway = NULL;
        DBusMessageIter dict;
 
        DBG("ipconfig %p", ipconfig);
@@ -1165,12 +1175,17 @@ int __connman_ipconfig_set_ipv4config(struct connman_ipconfig *ipconfig,
                                return -EINVAL;
 
                        dbus_message_iter_get_basic(&entry, &netmask);
-               }
+               } else if (g_str_equal(key, "Gateway") == TRUE) {
+                       if (type != DBUS_TYPE_STRING)
+                               return -EINVAL;
 
+                       dbus_message_iter_get_basic(&entry, &gateway);
+               }
                dbus_message_iter_next(&dict);
        }
 
-       DBG("method %d address %s netmask %s", method, address, netmask);
+       DBG("method %d address %s netmask %s gateway %s",
+                               method, address, netmask, gateway);
 
        switch (method) {
        case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
@@ -1183,7 +1198,8 @@ int __connman_ipconfig_set_ipv4config(struct connman_ipconfig *ipconfig,
                        return -EINVAL;
 
                ipconfig->method = method;
-               connman_ipaddress_set(ipconfig->address, address, netmask);
+               connman_ipaddress_set(ipconfig->address,
+                               address, netmask, gateway);
                break;
 
        case CONNMAN_IPCONFIG_METHOD_DHCP:
@@ -1269,6 +1285,11 @@ int __connman_ipconfig_load(struct connman_ipconfig *ipconfig,
                                keyfile, identifier, key, NULL);
        g_free(key);
 
+       key = g_strdup_printf("%sgateway", prefix);
+       ipconfig->address->gateway = g_key_file_get_string(
+                               keyfile, identifier, key, NULL);
+       g_free(key);
+
        return 0;
 }
 
@@ -1306,7 +1327,13 @@ int __connman_ipconfig_save(struct connman_ipconfig *ipconfig,
        key = g_strdup_printf("%sbroadcast_address", prefix);
        if (ipconfig->address->broadcast != NULL)
                g_key_file_set_string(keyfile, identifier,
-                       "broadcast_address", ipconfig->address->broadcast);
+                       key, ipconfig->address->broadcast);
+       g_free(key);
+
+       key = g_strdup_printf("%sgateway", prefix);
+       if (ipconfig->address->gateway != NULL)
+               g_key_file_set_string(keyfile, identifier,
+                       key, ipconfig->address->gateway);
        g_free(key);
 
        return 0;