Fix issues with hashing of RTNL interfaces and their flags
authorMarcel Holtmann <marcel@holtmann.org>
Sat, 8 Aug 2009 20:08:57 +0000 (13:08 -0700)
committerMarcel Holtmann <marcel@holtmann.org>
Sat, 8 Aug 2009 20:08:57 +0000 (13:08 -0700)
src/ipconfig.c
src/rtnl.c

index dbf0bc8..764836a 100644 (file)
 #include <config.h>
 #endif
 
+#include <net/if.h>
+
+#ifndef IFF_LOWER_UP
+#define IFF_LOWER_UP   0x10000
+#endif
+
 #include <gdbus.h>
 
 #include "connman.h"
@@ -31,6 +37,7 @@ struct connman_ipconfig {
        gint refcount;
        int index;
        char *interface;
+       unsigned int flags;
        enum connman_ipconfig_method method;
 };
 
@@ -121,8 +128,32 @@ int __connman_ipconfig_get_index(struct connman_ipconfig *ipconfig)
 void __connman_ipconfig_update_link(struct connman_ipconfig *ipconfig,
                                        unsigned flags, unsigned change)
 {
-       connman_info("%s {update} flags %u change %u", ipconfig->interface,
-                                                       flags, change);
+       GString *str;
+
+       if (flags == ipconfig->flags)
+               return;
+
+       ipconfig->flags = flags;
+
+       str = g_string_new(NULL);
+       if (str == NULL)
+               return;
+
+       if (flags & IFF_UP)
+               g_string_append(str, "UP");
+       else
+               g_string_append(str, "DOWN");
+
+       if (flags & IFF_RUNNING)
+               g_string_append(str, ",RUNNING");
+
+       if (flags & IFF_LOWER_UP)
+               g_string_append(str, ",LOWER_UP");
+
+       connman_info("%s {update} flags %u change %u <%s>",
+                               ipconfig->interface, flags, change, str->str);
+
+       g_string_free(str, TRUE);
 }
 
 void __connman_ipconfig_add_address(struct connman_ipconfig *ipconfig,
index 4412630..d7b317c 100644 (file)
@@ -167,19 +167,21 @@ static void process_newlink(unsigned short type, int index,
        case ARPHRD_ETHER:
        case ARPHRD_LOOPBACK:
        case ARPHRD_NONE:
-               ipconfig = g_hash_table_lookup(ipconfig_hash, &index);
+               ipconfig = g_hash_table_lookup(ipconfig_hash,
+                                               GINT_TO_POINTER(index));
                if (ipconfig == NULL) {
                        ipconfig = connman_ipconfig_create(index);
                        if (ipconfig != NULL) {
                                g_hash_table_insert(ipconfig_hash,
-                                                       &index, ipconfig);
+                                       GINT_TO_POINTER(index), ipconfig);
 
                                __connman_rtnl_register_ipconfig(ipconfig);
-
-                               __connman_ipconfig_update_link(ipconfig,
-                                                               flags, change);
                        }
                }
+
+               if (ipconfig != NULL)
+                       __connman_ipconfig_update_link(ipconfig,
+                                                       flags, change);
                break;
        }
 
@@ -217,7 +219,7 @@ static void process_dellink(unsigned short type, int index,
        case ARPHRD_ETHER:
        case ARPHRD_LOOPBACK:
        case ARPHRD_NONE:
-               g_hash_table_remove(ipconfig_hash, &index);
+               g_hash_table_remove(ipconfig_hash, GINT_TO_POINTER(index));
                break;
        }
 }
@@ -917,7 +919,7 @@ int __connman_rtnl_init(void)
 
        DBG("");
 
-       ipconfig_hash = g_hash_table_new_full(g_int_hash, g_int_equal,
+       ipconfig_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal,
                                                        NULL, free_ipconfig);
 
        sk = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);