Add support for storing default gateway information
authorMarcel Holtmann <marcel@holtmann.org>
Sun, 9 Aug 2009 06:33:08 +0000 (23:33 -0700)
committerMarcel Holtmann <marcel@holtmann.org>
Sun, 9 Aug 2009 06:33:08 +0000 (23:33 -0700)
include/rtnl.h
src/connection.c
src/connman.h
src/ipconfig.c
src/rtnl.c

index 6c40f41..01f4d2f 100644 (file)
@@ -57,8 +57,6 @@ struct connman_rtnl {
 int connman_rtnl_register(struct connman_rtnl *rtnl);
 void connman_rtnl_unregister(struct connman_rtnl *rtnl);
 
-int connman_rtnl_send_getroute(void);
-
 #ifdef __cplusplus
 }
 #endif
index f722cc3..cfe4828 100644 (file)
@@ -614,8 +614,6 @@ int __connman_connection_init(void)
        if (connman_rtnl_register(&connection_rtnl) < 0)
                connman_error("Failed to setup RTNL gateway driver");
 
-       connman_rtnl_send_getroute();
-
        return connman_driver_register(&connection_driver);
 }
 
index f8709d7..1ba327f 100644 (file)
@@ -94,6 +94,7 @@ int __connman_security_check_privilege(DBusMessage *message,
 int __connman_ipconfig_get_index(struct connman_ipconfig *ipconfig);
 unsigned short __connman_ipconfig_get_type(struct connman_ipconfig *ipconfig);
 unsigned int __connman_ipconfig_get_flags(struct connman_ipconfig *ipconfig);
+const char *__connman_ipconfig_get_gateway(struct connman_ipconfig *ipconfig);
 
 void __connman_ipconfig_update_link(struct connman_ipconfig *ipconfig,
                                        unsigned flags, unsigned change);
index c149cc6..013a14f 100644 (file)
@@ -46,6 +46,7 @@ struct connman_ipconfig {
        unsigned int flags;
        enum connman_ipconfig_method method;
        GSList *address_list;
+       char *gateway;
 };
 
 static void free_address_list(struct connman_ipconfig *ipconfig)
@@ -57,7 +58,6 @@ static void free_address_list(struct connman_ipconfig *ipconfig)
 
                g_free(ipaddress->address);
                g_free(ipaddress);
-
                list->data = NULL;
        }
 
@@ -136,6 +136,8 @@ void connman_ipconfig_unref(struct connman_ipconfig *ipconfig)
                connman_info("%s {remove} index %d", ipconfig->interface,
                                                        ipconfig->index);
 
+               g_free(ipconfig->gateway);
+
                free_address_list(ipconfig);
 
                g_free(ipconfig->interface);
@@ -173,6 +175,11 @@ unsigned int __connman_ipconfig_get_flags(struct connman_ipconfig *ipconfig)
        return ipconfig->flags;
 }
 
+const char *__connman_ipconfig_get_gateway(struct connman_ipconfig *ipconfig)
+{
+       return ipconfig->gateway;
+}
+
 void __connman_ipconfig_update_link(struct connman_ipconfig *ipconfig,
                                        unsigned flags, unsigned change)
 {
@@ -260,6 +267,11 @@ void __connman_ipconfig_add_route(struct connman_ipconfig *ipconfig,
                                unsigned char scope, const char *destination,
                                                        const char *gateway)
 {
+       if (scope == 0 && g_strcmp0(destination, "0.0.0.0") == 0) {
+               g_free(ipconfig->gateway);
+               ipconfig->gateway = g_strdup(gateway);
+       }
+
        connman_info("%s {add} route %s gw %s scope %u <%s>",
                                        ipconfig->interface, destination,
                                        gateway, scope, scope2str(scope));
@@ -269,6 +281,11 @@ void __connman_ipconfig_del_route(struct connman_ipconfig *ipconfig,
                                unsigned char scope, const char *destination,
                                                        const char *gateway)
 {
+       if (scope == 0 && g_strcmp0(destination, "0.0.0.0") == 0) {
+               g_free(ipconfig->gateway);
+               ipconfig->gateway = NULL;
+       }
+
        connman_info("%s {del} route %s gw %s scope %u <%s>",
                                        ipconfig->interface, destination,
                                        gateway, scope, scope2str(scope));
index b036620..b13061c 100644 (file)
@@ -139,7 +139,7 @@ void connman_rtnl_remove_watch(unsigned int id)
        }
 }
 
-static void trigger_newlink(gpointer key, gpointer value, gpointer user_data)
+static void trigger_rtnl(gpointer key, gpointer value, gpointer user_data)
 {
        struct connman_rtnl *rtnl = user_data;
        struct connman_ipconfig *ipconfig = value;
@@ -154,6 +154,13 @@ static void trigger_newlink(gpointer key, gpointer value, gpointer user_data)
 
                rtnl->newlink(type, index, flags, 0);
        }
+
+       if (rtnl->newgateway) {
+               const char *gateway = __connman_ipconfig_get_gateway(ipconfig);
+
+               if (gateway != NULL)
+                       rtnl->newgateway(index, gateway);
+       }
 }
 
 static GSList *rtnl_list = NULL;
@@ -181,7 +188,7 @@ int connman_rtnl_register(struct connman_rtnl *rtnl)
        rtnl_list = g_slist_insert_sorted(rtnl_list, rtnl,
                                                        compare_priority);
 
-       g_hash_table_foreach(ipconfig_hash, trigger_newlink, rtnl);
+       g_hash_table_foreach(ipconfig_hash, trigger_rtnl, rtnl);
 
        return 0;
 }
@@ -934,7 +941,7 @@ static int send_getaddr(void)
        return queue_request(req);
 }
 
-int connman_rtnl_send_getroute(void)
+static int send_getroute(void)
 {
        struct rtnl_request *req;
 
@@ -992,7 +999,7 @@ void __connman_rtnl_start(void)
 
        send_getlink();
        send_getaddr();
-       connman_rtnl_send_getroute();
+       send_getroute();
 }
 
 void __connman_rtnl_cleanup(void)