packet: Add 'cpu' fanout policy.
[linux-2.6-block.git] / net / batman-adv / main.c
CommitLineData
c6c8fea2 1/*
64afe353 2 * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors:
c6c8fea2
SE
3 *
4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#include "main.h"
23#include "bat_sysfs.h"
24#include "bat_debugfs.h"
25#include "routing.h"
26#include "send.h"
27#include "originator.h"
28#include "soft-interface.h"
29#include "icmp_socket.h"
30#include "translation-table.h"
31#include "hard-interface.h"
32#include "gateway_client.h"
c6c8fea2
SE
33#include "vis.h"
34#include "hash.h"
35
c3caf519
SE
36
37/* List manipulations on hardif_list have to be rtnl_lock()'ed,
38 * list traversals just rcu-locked */
4389e47a 39struct list_head hardif_list;
c6c8fea2
SE
40
41unsigned char broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
42
43struct workqueue_struct *bat_event_workqueue;
44
45static int __init batman_init(void)
46{
4389e47a 47 INIT_LIST_HEAD(&hardif_list);
c6c8fea2
SE
48
49 /* the name should not be longer than 10 chars - see
50 * http://lwn.net/Articles/23634/ */
51 bat_event_workqueue = create_singlethread_workqueue("bat_events");
52
53 if (!bat_event_workqueue)
54 return -ENOMEM;
55
56 bat_socket_init();
57 debugfs_init();
58
59 register_netdevice_notifier(&hard_if_notifier);
60
44c4349a
SE
61 pr_info("B.A.T.M.A.N. advanced %s (compatibility version %i) "
62 "loaded\n", SOURCE_VERSION, COMPAT_VERSION);
c6c8fea2
SE
63
64 return 0;
65}
66
67static void __exit batman_exit(void)
68{
69 debugfs_destroy();
70 unregister_netdevice_notifier(&hard_if_notifier);
71 hardif_remove_interfaces();
72
73 flush_workqueue(bat_event_workqueue);
74 destroy_workqueue(bat_event_workqueue);
75 bat_event_workqueue = NULL;
76
77 rcu_barrier();
78}
79
80int mesh_init(struct net_device *soft_iface)
81{
82 struct bat_priv *bat_priv = netdev_priv(soft_iface);
83
c6c8fea2
SE
84 spin_lock_init(&bat_priv->forw_bat_list_lock);
85 spin_lock_init(&bat_priv->forw_bcast_list_lock);
a73105b8
AQ
86 spin_lock_init(&bat_priv->tt_changes_list_lock);
87 spin_lock_init(&bat_priv->tt_req_list_lock);
cc47f66e 88 spin_lock_init(&bat_priv->tt_roam_list_lock);
a73105b8 89 spin_lock_init(&bat_priv->tt_buff_lock);
c6c8fea2
SE
90 spin_lock_init(&bat_priv->gw_list_lock);
91 spin_lock_init(&bat_priv->vis_hash_lock);
92 spin_lock_init(&bat_priv->vis_list_lock);
93 spin_lock_init(&bat_priv->softif_neigh_lock);
61906ae8 94 spin_lock_init(&bat_priv->softif_neigh_vid_lock);
c6c8fea2
SE
95
96 INIT_HLIST_HEAD(&bat_priv->forw_bat_list);
97 INIT_HLIST_HEAD(&bat_priv->forw_bcast_list);
98 INIT_HLIST_HEAD(&bat_priv->gw_list);
61906ae8 99 INIT_HLIST_HEAD(&bat_priv->softif_neigh_vids);
a73105b8
AQ
100 INIT_LIST_HEAD(&bat_priv->tt_changes_list);
101 INIT_LIST_HEAD(&bat_priv->tt_req_list);
cc47f66e 102 INIT_LIST_HEAD(&bat_priv->tt_roam_list);
c6c8fea2
SE
103
104 if (originator_init(bat_priv) < 1)
105 goto err;
106
a73105b8 107 if (tt_init(bat_priv) < 1)
c6c8fea2
SE
108 goto err;
109
2dafb49d 110 tt_local_add(soft_iface, soft_iface->dev_addr);
c6c8fea2
SE
111
112 if (vis_init(bat_priv) < 1)
113 goto err;
114
2265c141 115 atomic_set(&bat_priv->gw_reselect, 0);
c6c8fea2
SE
116 atomic_set(&bat_priv->mesh_state, MESH_ACTIVE);
117 goto end;
118
119err:
120 pr_err("Unable to allocate memory for mesh information structures: "
121 "out of mem ?\n");
122 mesh_free(soft_iface);
123 return -1;
124
125end:
126 return 0;
127}
128
129void mesh_free(struct net_device *soft_iface)
130{
131 struct bat_priv *bat_priv = netdev_priv(soft_iface);
132
133 atomic_set(&bat_priv->mesh_state, MESH_DEACTIVATING);
134
135 purge_outstanding_packets(bat_priv, NULL);
136
137 vis_quit(bat_priv);
138
139 gw_node_purge(bat_priv);
140 originator_free(bat_priv);
141
a73105b8 142 tt_free(bat_priv);
c6c8fea2
SE
143
144 softif_neigh_purge(bat_priv);
145
146 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
147}
148
149void inc_module_count(void)
150{
151 try_module_get(THIS_MODULE);
152}
153
154void dec_module_count(void)
155{
156 module_put(THIS_MODULE);
157}
158
747e4221 159int is_my_mac(const uint8_t *addr)
c6c8fea2 160{
747e4221 161 const struct hard_iface *hard_iface;
c6c8fea2
SE
162
163 rcu_read_lock();
e6c10f43
ML
164 list_for_each_entry_rcu(hard_iface, &hardif_list, list) {
165 if (hard_iface->if_status != IF_ACTIVE)
c6c8fea2
SE
166 continue;
167
e6c10f43 168 if (compare_eth(hard_iface->net_dev->dev_addr, addr)) {
c6c8fea2
SE
169 rcu_read_unlock();
170 return 1;
171 }
172 }
173 rcu_read_unlock();
174 return 0;
175
176}
177
178module_init(batman_init);
179module_exit(batman_exit);
180
181MODULE_LICENSE("GPL");
182
183MODULE_AUTHOR(DRIVER_AUTHOR);
184MODULE_DESCRIPTION(DRIVER_DESC);
185MODULE_SUPPORTED_DEVICE(DRIVER_DEVICE);
c6c8fea2 186MODULE_VERSION(SOURCE_VERSION);