2 * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors:
4 * Marek Lindner, Simon Wunderlich
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.
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.
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
23 #include "bat_sysfs.h"
24 #include "bat_debugfs.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"
37 /* List manipulations on hardif_list have to be rtnl_lock()'ed,
38 * list traversals just rcu-locked */
39 struct list_head hardif_list
;
41 unsigned char broadcast_addr
[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
43 struct workqueue_struct
*bat_event_workqueue
;
45 static int __init
batman_init(void)
47 INIT_LIST_HEAD(&hardif_list
);
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");
53 if (!bat_event_workqueue
)
59 register_netdevice_notifier(&hard_if_notifier
);
61 pr_info("B.A.T.M.A.N. advanced %s (compatibility version %i) "
62 "loaded\n", SOURCE_VERSION
, COMPAT_VERSION
);
67 static void __exit
batman_exit(void)
70 unregister_netdevice_notifier(&hard_if_notifier
);
71 hardif_remove_interfaces();
73 flush_workqueue(bat_event_workqueue
);
74 destroy_workqueue(bat_event_workqueue
);
75 bat_event_workqueue
= NULL
;
80 int mesh_init(struct net_device
*soft_iface
)
82 struct bat_priv
*bat_priv
= netdev_priv(soft_iface
);
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
->tt_changes_list_lock
);
87 spin_lock_init(&bat_priv
->tt_req_list_lock
);
88 spin_lock_init(&bat_priv
->tt_roam_list_lock
);
89 spin_lock_init(&bat_priv
->tt_buff_lock
);
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
);
94 spin_lock_init(&bat_priv
->softif_neigh_vid_lock
);
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
);
99 INIT_HLIST_HEAD(&bat_priv
->softif_neigh_vids
);
100 INIT_LIST_HEAD(&bat_priv
->tt_changes_list
);
101 INIT_LIST_HEAD(&bat_priv
->tt_req_list
);
102 INIT_LIST_HEAD(&bat_priv
->tt_roam_list
);
104 if (originator_init(bat_priv
) < 1)
107 if (tt_init(bat_priv
) < 1)
110 tt_local_add(soft_iface
, soft_iface
->dev_addr
, NULL_IFINDEX
);
112 if (vis_init(bat_priv
) < 1)
115 atomic_set(&bat_priv
->gw_reselect
, 0);
116 atomic_set(&bat_priv
->mesh_state
, MESH_ACTIVE
);
120 mesh_free(soft_iface
);
127 void mesh_free(struct net_device
*soft_iface
)
129 struct bat_priv
*bat_priv
= netdev_priv(soft_iface
);
131 atomic_set(&bat_priv
->mesh_state
, MESH_DEACTIVATING
);
133 purge_outstanding_packets(bat_priv
, NULL
);
137 gw_node_purge(bat_priv
);
138 originator_free(bat_priv
);
142 softif_neigh_purge(bat_priv
);
144 atomic_set(&bat_priv
->mesh_state
, MESH_INACTIVE
);
147 void inc_module_count(void)
149 try_module_get(THIS_MODULE
);
152 void dec_module_count(void)
154 module_put(THIS_MODULE
);
157 int is_my_mac(const uint8_t *addr
)
159 const struct hard_iface
*hard_iface
;
162 list_for_each_entry_rcu(hard_iface
, &hardif_list
, list
) {
163 if (hard_iface
->if_status
!= IF_ACTIVE
)
166 if (compare_eth(hard_iface
->net_dev
->dev_addr
, addr
)) {
176 module_init(batman_init
);
177 module_exit(batman_exit
);
179 MODULE_LICENSE("GPL");
181 MODULE_AUTHOR(DRIVER_AUTHOR
);
182 MODULE_DESCRIPTION(DRIVER_DESC
);
183 MODULE_SUPPORTED_DEVICE(DRIVER_DEVICE
);
184 MODULE_VERSION(SOURCE_VERSION
);