Staging: batman-adv: Use kernel functions to identify broadcasts
[deliverable/linux.git] / drivers / staging / batman-adv / main.c
CommitLineData
5beef3c9 1/*
9b6d10b7 2 * Copyright (C) 2007-2010 B.A.T.M.A.N. contributors:
5beef3c9
AL
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"
47fdf097 23#include "bat_sysfs.h"
c4121432 24#include "bat_debugfs.h"
5beef3c9
AL
25#include "routing.h"
26#include "send.h"
8a2e042c 27#include "originator.h"
5beef3c9 28#include "soft-interface.h"
c4121432 29#include "icmp_socket.h"
5beef3c9
AL
30#include "translation-table.h"
31#include "hard-interface.h"
dfaf9dd3 32#include "gateway_client.h"
5beef3c9
AL
33#include "types.h"
34#include "vis.h"
35#include "hash.h"
5beef3c9
AL
36
37struct list_head if_list;
5beef3c9 38
6e0e9388 39unsigned char broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
5beef3c9
AL
40
41struct workqueue_struct *bat_event_workqueue;
42
c0cad1e7 43static int __init batman_init(void)
5beef3c9 44{
5beef3c9 45 INIT_LIST_HEAD(&if_list);
5beef3c9 46
5beef3c9
AL
47 /* the name should not be longer than 10 chars - see
48 * http://lwn.net/Articles/23634/ */
49 bat_event_workqueue = create_singlethread_workqueue("bat_events");
50
51 if (!bat_event_workqueue)
52 return -ENOMEM;
53
c4121432
SE
54 bat_socket_init();
55 debugfs_init();
5beef3c9 56
5beef3c9
AL
57 register_netdevice_notifier(&hard_if_notifier);
58
c1641862
SE
59 pr_info("B.A.T.M.A.N. advanced %s%s (compatibility version %i) "
60 "loaded\n", SOURCE_VERSION, REVISION_VERSION_STR,
61 COMPAT_VERSION);
5beef3c9
AL
62
63 return 0;
5beef3c9
AL
64}
65
c0cad1e7 66static void __exit batman_exit(void)
5beef3c9 67{
08f20b5e 68 debugfs_destroy();
208e13e4
ML
69 unregister_netdevice_notifier(&hard_if_notifier);
70 hardif_remove_interfaces();
5beef3c9 71
8c70f138 72 flush_workqueue(bat_event_workqueue);
5beef3c9
AL
73 destroy_workqueue(bat_event_workqueue);
74 bat_event_workqueue = NULL;
09686b56 75
67c3b705 76 rcu_barrier();
5beef3c9
AL
77}
78
8c70f138 79int mesh_init(struct net_device *soft_iface)
5beef3c9 80{
8c70f138
ML
81 struct bat_priv *bat_priv = netdev_priv(soft_iface);
82
83 spin_lock_init(&bat_priv->orig_hash_lock);
84 spin_lock_init(&bat_priv->forw_bat_list_lock);
85 spin_lock_init(&bat_priv->forw_bcast_list_lock);
86 spin_lock_init(&bat_priv->hna_lhash_lock);
87 spin_lock_init(&bat_priv->hna_ghash_lock);
dfaf9dd3 88 spin_lock_init(&bat_priv->gw_list_lock);
8c70f138
ML
89 spin_lock_init(&bat_priv->vis_hash_lock);
90 spin_lock_init(&bat_priv->vis_list_lock);
42019357 91 spin_lock_init(&bat_priv->softif_neigh_lock);
8c70f138
ML
92
93 INIT_HLIST_HEAD(&bat_priv->forw_bat_list);
94 INIT_HLIST_HEAD(&bat_priv->forw_bcast_list);
dfaf9dd3 95 INIT_HLIST_HEAD(&bat_priv->gw_list);
42019357 96 INIT_HLIST_HEAD(&bat_priv->softif_neigh_list);
8c70f138
ML
97
98 if (originator_init(bat_priv) < 1)
5beef3c9
AL
99 goto err;
100
8c70f138 101 if (hna_local_init(bat_priv) < 1)
5beef3c9
AL
102 goto err;
103
8c70f138 104 if (hna_global_init(bat_priv) < 1)
5beef3c9
AL
105 goto err;
106
8c70f138 107 hna_local_add(soft_iface, soft_iface->dev_addr);
5beef3c9 108
8c70f138 109 if (vis_init(bat_priv) < 1)
5beef3c9
AL
110 goto err;
111
8c70f138 112 atomic_set(&bat_priv->mesh_state, MESH_ACTIVE);
5beef3c9
AL
113 goto end;
114
115err:
c1641862 116 pr_err("Unable to allocate memory for mesh information structures: "
6d45d8df 117 "out of mem ?\n");
8c70f138
ML
118 mesh_free(soft_iface);
119 return -1;
120
5beef3c9 121end:
8c70f138 122 return 0;
5beef3c9
AL
123}
124
8c70f138 125void mesh_free(struct net_device *soft_iface)
5beef3c9 126{
8c70f138 127 struct bat_priv *bat_priv = netdev_priv(soft_iface);
5beef3c9 128
8c70f138
ML
129 atomic_set(&bat_priv->mesh_state, MESH_DEACTIVATING);
130
131 purge_outstanding_packets(bat_priv, NULL);
5beef3c9 132
8c70f138 133 vis_quit(bat_priv);
5beef3c9 134
dfaf9dd3 135 gw_node_purge(bat_priv);
8c70f138 136 originator_free(bat_priv);
5beef3c9 137
8c70f138
ML
138 hna_local_free(bat_priv);
139 hna_global_free(bat_priv);
5beef3c9 140
42019357
ML
141 softif_neigh_purge(bat_priv);
142
8c70f138 143 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
5beef3c9
AL
144}
145
146void inc_module_count(void)
147{
148 try_module_get(THIS_MODULE);
149}
150
151void dec_module_count(void)
152{
153 module_put(THIS_MODULE);
154}
155
5beef3c9
AL
156int is_my_mac(uint8_t *addr)
157{
158 struct batman_if *batman_if;
51e21ae3 159
5beef3c9
AL
160 rcu_read_lock();
161 list_for_each_entry_rcu(batman_if, &if_list, list) {
51e21ae3
ML
162 if (batman_if->if_status != IF_ACTIVE)
163 continue;
164
165 if (compare_orig(batman_if->net_dev->dev_addr, addr)) {
5beef3c9
AL
166 rcu_read_unlock();
167 return 1;
168 }
169 }
170 rcu_read_unlock();
171 return 0;
172
173}
174
c0cad1e7
RD
175module_init(batman_init);
176module_exit(batman_exit);
177
5beef3c9
AL
178MODULE_LICENSE("GPL");
179
180MODULE_AUTHOR(DRIVER_AUTHOR);
181MODULE_DESCRIPTION(DRIVER_DESC);
182MODULE_SUPPORTED_DEVICE(DRIVER_DEVICE);
183#ifdef REVISION_VERSION
184MODULE_VERSION(SOURCE_VERSION "-" REVISION_VERSION);
185#else
186MODULE_VERSION(SOURCE_VERSION);
187#endif
This page took 0.124617 seconds and 5 git commands to generate.