1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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"
33#include "vis.h"
34#include "hash.h"
35
36
37
38
39struct list_head hardif_list;
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{
47 INIT_LIST_HEAD(&hardif_list);
48
49
50
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
61 pr_info("B.A.T.M.A.N. advanced %s%s (compatibility version %i) "
62 "loaded\n", SOURCE_VERSION, REVISION_VERSION_STR,
63 COMPAT_VERSION);
64
65 return 0;
66}
67
68static void __exit batman_exit(void)
69{
70 debugfs_destroy();
71 unregister_netdevice_notifier(&hard_if_notifier);
72 hardif_remove_interfaces();
73
74 flush_workqueue(bat_event_workqueue);
75 destroy_workqueue(bat_event_workqueue);
76 bat_event_workqueue = NULL;
77
78 rcu_barrier();
79}
80
81int mesh_init(struct net_device *soft_iface)
82{
83 struct bat_priv *bat_priv = netdev_priv(soft_iface);
84
85 spin_lock_init(&bat_priv->forw_bat_list_lock);
86 spin_lock_init(&bat_priv->forw_bcast_list_lock);
87 spin_lock_init(&bat_priv->tt_lhash_lock);
88 spin_lock_init(&bat_priv->tt_ghash_lock);
89 spin_lock_init(&bat_priv->gw_list_lock);
90 spin_lock_init(&bat_priv->vis_hash_lock);
91 spin_lock_init(&bat_priv->vis_list_lock);
92 spin_lock_init(&bat_priv->softif_neigh_lock);
93 spin_lock_init(&bat_priv->softif_neigh_vid_lock);
94
95 INIT_HLIST_HEAD(&bat_priv->forw_bat_list);
96 INIT_HLIST_HEAD(&bat_priv->forw_bcast_list);
97 INIT_HLIST_HEAD(&bat_priv->gw_list);
98 INIT_HLIST_HEAD(&bat_priv->softif_neigh_vids);
99
100 if (originator_init(bat_priv) < 1)
101 goto err;
102
103 if (tt_local_init(bat_priv) < 1)
104 goto err;
105
106 if (tt_global_init(bat_priv) < 1)
107 goto err;
108
109 tt_local_add(soft_iface, soft_iface->dev_addr);
110
111 if (vis_init(bat_priv) < 1)
112 goto err;
113
114 atomic_set(&bat_priv->mesh_state, MESH_ACTIVE);
115 goto end;
116
117err:
118 pr_err("Unable to allocate memory for mesh information structures: "
119 "out of mem ?\n");
120 mesh_free(soft_iface);
121 return -1;
122
123end:
124 return 0;
125}
126
127void mesh_free(struct net_device *soft_iface)
128{
129 struct bat_priv *bat_priv = netdev_priv(soft_iface);
130
131 atomic_set(&bat_priv->mesh_state, MESH_DEACTIVATING);
132
133 purge_outstanding_packets(bat_priv, NULL);
134
135 vis_quit(bat_priv);
136
137 gw_node_purge(bat_priv);
138 originator_free(bat_priv);
139
140 tt_local_free(bat_priv);
141 tt_global_free(bat_priv);
142
143 softif_neigh_purge(bat_priv);
144
145 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
146}
147
148void inc_module_count(void)
149{
150 try_module_get(THIS_MODULE);
151}
152
153void dec_module_count(void)
154{
155 module_put(THIS_MODULE);
156}
157
158int is_my_mac(uint8_t *addr)
159{
160 struct hard_iface *hard_iface;
161
162 rcu_read_lock();
163 list_for_each_entry_rcu(hard_iface, &hardif_list, list) {
164 if (hard_iface->if_status != IF_ACTIVE)
165 continue;
166
167 if (compare_eth(hard_iface->net_dev->dev_addr, addr)) {
168 rcu_read_unlock();
169 return 1;
170 }
171 }
172 rcu_read_unlock();
173 return 0;
174
175}
176
177module_init(batman_init);
178module_exit(batman_exit);
179
180MODULE_LICENSE("GPL");
181
182MODULE_AUTHOR(DRIVER_AUTHOR);
183MODULE_DESCRIPTION(DRIVER_DESC);
184MODULE_SUPPORTED_DEVICE(DRIVER_DEVICE);
185#ifdef REVISION_VERSION
186MODULE_VERSION(SOURCE_VERSION "-" REVISION_VERSION);
187#else
188MODULE_VERSION(SOURCE_VERSION);
189#endif
190