blob: 09c21f26156c4fb73f4f3bfbde960be1faedcb15 [file] [log] [blame]
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001/*
Sven Eckelmann64afe352011-01-27 10:38:15 +01002 * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00003 *
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"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000033#include "vis.h"
34#include "hash.h"
35
36struct list_head if_list;
37
38unsigned char broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
39
40struct workqueue_struct *bat_event_workqueue;
41
42static int __init batman_init(void)
43{
44 INIT_LIST_HEAD(&if_list);
45
46 /* the name should not be longer than 10 chars - see
47 * http://lwn.net/Articles/23634/ */
48 bat_event_workqueue = create_singlethread_workqueue("bat_events");
49
50 if (!bat_event_workqueue)
51 return -ENOMEM;
52
53 bat_socket_init();
54 debugfs_init();
55
56 register_netdevice_notifier(&hard_if_notifier);
57
58 pr_info("B.A.T.M.A.N. advanced %s%s (compatibility version %i) "
59 "loaded\n", SOURCE_VERSION, REVISION_VERSION_STR,
60 COMPAT_VERSION);
61
62 return 0;
63}
64
65static void __exit batman_exit(void)
66{
67 debugfs_destroy();
68 unregister_netdevice_notifier(&hard_if_notifier);
69 hardif_remove_interfaces();
70
71 flush_workqueue(bat_event_workqueue);
72 destroy_workqueue(bat_event_workqueue);
73 bat_event_workqueue = NULL;
74
75 rcu_barrier();
76}
77
78int mesh_init(struct net_device *soft_iface)
79{
80 struct bat_priv *bat_priv = netdev_priv(soft_iface);
81
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000082 spin_lock_init(&bat_priv->forw_bat_list_lock);
83 spin_lock_init(&bat_priv->forw_bcast_list_lock);
84 spin_lock_init(&bat_priv->hna_lhash_lock);
85 spin_lock_init(&bat_priv->hna_ghash_lock);
86 spin_lock_init(&bat_priv->gw_list_lock);
87 spin_lock_init(&bat_priv->vis_hash_lock);
88 spin_lock_init(&bat_priv->vis_list_lock);
89 spin_lock_init(&bat_priv->softif_neigh_lock);
90
91 INIT_HLIST_HEAD(&bat_priv->forw_bat_list);
92 INIT_HLIST_HEAD(&bat_priv->forw_bcast_list);
93 INIT_HLIST_HEAD(&bat_priv->gw_list);
94 INIT_HLIST_HEAD(&bat_priv->softif_neigh_list);
95
96 if (originator_init(bat_priv) < 1)
97 goto err;
98
99 if (hna_local_init(bat_priv) < 1)
100 goto err;
101
102 if (hna_global_init(bat_priv) < 1)
103 goto err;
104
105 hna_local_add(soft_iface, soft_iface->dev_addr);
106
107 if (vis_init(bat_priv) < 1)
108 goto err;
109
110 atomic_set(&bat_priv->mesh_state, MESH_ACTIVE);
111 goto end;
112
113err:
114 pr_err("Unable to allocate memory for mesh information structures: "
115 "out of mem ?\n");
116 mesh_free(soft_iface);
117 return -1;
118
119end:
120 return 0;
121}
122
123void mesh_free(struct net_device *soft_iface)
124{
125 struct bat_priv *bat_priv = netdev_priv(soft_iface);
126
127 atomic_set(&bat_priv->mesh_state, MESH_DEACTIVATING);
128
129 purge_outstanding_packets(bat_priv, NULL);
130
131 vis_quit(bat_priv);
132
133 gw_node_purge(bat_priv);
134 originator_free(bat_priv);
135
136 hna_local_free(bat_priv);
137 hna_global_free(bat_priv);
138
139 softif_neigh_purge(bat_priv);
140
141 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
142}
143
144void inc_module_count(void)
145{
146 try_module_get(THIS_MODULE);
147}
148
149void dec_module_count(void)
150{
151 module_put(THIS_MODULE);
152}
153
154int is_my_mac(uint8_t *addr)
155{
156 struct batman_if *batman_if;
157
158 rcu_read_lock();
159 list_for_each_entry_rcu(batman_if, &if_list, list) {
160 if (batman_if->if_status != IF_ACTIVE)
161 continue;
162
Marek Lindner39901e72011-02-18 12:28:08 +0000163 if (compare_eth(batman_if->net_dev->dev_addr, addr)) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000164 rcu_read_unlock();
165 return 1;
166 }
167 }
168 rcu_read_unlock();
169 return 0;
170
171}
172
173module_init(batman_init);
174module_exit(batman_exit);
175
176MODULE_LICENSE("GPL");
177
178MODULE_AUTHOR(DRIVER_AUTHOR);
179MODULE_DESCRIPTION(DRIVER_DESC);
180MODULE_SUPPORTED_DEVICE(DRIVER_DEVICE);
181#ifdef REVISION_VERSION
182MODULE_VERSION(SOURCE_VERSION "-" REVISION_VERSION);
183#else
184MODULE_VERSION(SOURCE_VERSION);
185#endif