5 * Copyright (C) 2007-2009 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 static GSList *device_list = NULL;
32 static struct connman_device *find_device(int index)
36 for (list = device_list; list; list = list->next) {
37 struct connman_device *device = list->data;
39 if (connman_device_get_index(device) == index)
46 static void detect_newlink(unsigned short type, int index,
47 unsigned flags, unsigned change)
49 struct connman_device *device;
51 DBG("type %d index %d", type, index);
53 device = find_device(index);
57 device = connman_inet_create_device(index);
61 if (connman_device_register(device) < 0) {
62 connman_device_unref(device);
66 device_list = g_slist_append(device_list, device);
69 static void detect_dellink(unsigned short type, int index,
70 unsigned flags, unsigned change)
72 struct connman_device *device;
74 DBG("type %d index %d", type, index);
76 device = find_device(index);
80 device_list = g_slist_remove(device_list, device);
82 connman_device_unregister(device);
83 connman_device_unref(device);
86 static struct connman_rtnl detect_rtnl = {
88 .priority = CONNMAN_RTNL_PRIORITY_LOW,
89 .newlink = detect_newlink,
90 .dellink = detect_dellink,
93 int __connman_detect_init(void)
99 err = connman_rtnl_register(&detect_rtnl);
103 connman_rtnl_send_getlink();
108 void __connman_detect_cleanup(void)
114 connman_rtnl_unregister(&detect_rtnl);
116 for (list = device_list; list; list = list->next) {
117 struct connman_device *device = list->data;
119 connman_device_unregister(device);
120 connman_device_unref(device);
123 g_slist_free(device_list);