blob: fb87bdc2ce9bdba9b551f90fcdcada42fdc594a4 [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
Sven Eckelmannc3caf512011-05-03 11:51:38 +020036
37/* List manipulations on hardif_list have to be rtnl_lock()'ed,
38 * list traversals just rcu-locked */
Marek Lindner4389e472011-02-18 12:33:19 +000039struct list_head hardif_list;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000040
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{
Marek Lindner4389e472011-02-18 12:33:19 +000047 INIT_LIST_HEAD(&hardif_list);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000048
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
Sven Eckelmann44c43492011-07-05 10:42:51 +020061 pr_info("B.A.T.M.A.N. advanced %s (compatibility version %i) "
62 "loaded\n", SOURCE_VERSION, COMPAT_VERSION);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000063
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
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000084 spin_lock_init(&bat_priv->forw_bat_list_lock);
85 spin_lock_init(&bat_priv->forw_bcast_list_lock);
Antonio Quartullia73105b2011-04-27 14:27:44 +020086 spin_lock_init(&bat_priv->tt_changes_list_lock);
87 spin_lock_init(&bat_priv->tt_req_list_lock);
Antonio Quartullicc47f662011-04-27 14:27:57 +020088 spin_lock_init(&bat_priv->tt_roam_list_lock);
Antonio Quartullia73105b2011-04-27 14:27:44 +020089 spin_lock_init(&bat_priv->tt_buff_lock);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000090 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);
Marek Lindner61906ae2011-04-21 15:52:17 +020094 spin_lock_init(&bat_priv->softif_neigh_vid_lock);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000095
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);
Marek Lindner61906ae2011-04-21 15:52:17 +020099 INIT_HLIST_HEAD(&bat_priv->softif_neigh_vids);
Antonio Quartullia73105b2011-04-27 14:27:44 +0200100 INIT_LIST_HEAD(&bat_priv->tt_changes_list);
101 INIT_LIST_HEAD(&bat_priv->tt_req_list);
Antonio Quartullicc47f662011-04-27 14:27:57 +0200102 INIT_LIST_HEAD(&bat_priv->tt_roam_list);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000103
104 if (originator_init(bat_priv) < 1)
105 goto err;
106
Antonio Quartullia73105b2011-04-27 14:27:44 +0200107 if (tt_init(bat_priv) < 1)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000108 goto err;
109
Antonio Quartullibc279082011-07-07 15:35:35 +0200110 tt_local_add(soft_iface, soft_iface->dev_addr, NULL_IFINDEX);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000111
112 if (vis_init(bat_priv) < 1)
113 goto err;
114
Antonio Quartulli2265c142011-04-27 00:22:00 +0200115 atomic_set(&bat_priv->gw_reselect, 0);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000116 atomic_set(&bat_priv->mesh_state, MESH_ACTIVE);
117 goto end;
118
119err:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000120 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
Antonio Quartullia73105b2011-04-27 14:27:44 +0200140 tt_free(bat_priv);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000141
142 softif_neigh_purge(bat_priv);
143
144 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
145}
146
147void inc_module_count(void)
148{
149 try_module_get(THIS_MODULE);
150}
151
152void dec_module_count(void)
153{
154 module_put(THIS_MODULE);
155}
156
Sven Eckelmann747e4222011-05-14 23:14:50 +0200157int is_my_mac(const uint8_t *addr)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000158{
Sven Eckelmann747e4222011-05-14 23:14:50 +0200159 const struct hard_iface *hard_iface;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000160
161 rcu_read_lock();
Marek Lindnere6c10f42011-02-18 12:33:20 +0000162 list_for_each_entry_rcu(hard_iface, &hardif_list, list) {
163 if (hard_iface->if_status != IF_ACTIVE)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000164 continue;
165
Marek Lindnere6c10f42011-02-18 12:33:20 +0000166 if (compare_eth(hard_iface->net_dev->dev_addr, addr)) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000167 rcu_read_unlock();
168 return 1;
169 }
170 }
171 rcu_read_unlock();
172 return 0;
173
174}
175
176module_init(batman_init);
177module_exit(batman_exit);
178
179MODULE_LICENSE("GPL");
180
181MODULE_AUTHOR(DRIVER_AUTHOR);
182MODULE_DESCRIPTION(DRIVER_DESC);
183MODULE_SUPPORTED_DEVICE(DRIVER_DEVICE);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000184MODULE_VERSION(SOURCE_VERSION);