| Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1 | /* | 
| Sven Eckelmann | 64afe35 | 2011-01-27 10:38:15 +0100 | [diff] [blame] | 2 |  * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors: | 
| Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 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" | 
 | 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 Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 33 | #include "vis.h" | 
 | 34 | #include "hash.h" | 
 | 35 |  | 
| Marek Lindner | 4389e47 | 2011-02-18 12:33:19 +0000 | [diff] [blame] | 36 | struct list_head hardif_list; | 
| Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 37 |  | 
 | 38 | unsigned char broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; | 
 | 39 |  | 
 | 40 | struct workqueue_struct *bat_event_workqueue; | 
 | 41 |  | 
 | 42 | static int __init batman_init(void) | 
 | 43 | { | 
| Marek Lindner | 4389e47 | 2011-02-18 12:33:19 +0000 | [diff] [blame] | 44 | 	INIT_LIST_HEAD(&hardif_list); | 
| Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 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 |  | 
 | 65 | static 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 |  | 
 | 78 | int mesh_init(struct net_device *soft_iface) | 
 | 79 | { | 
 | 80 | 	struct bat_priv *bat_priv = netdev_priv(soft_iface); | 
 | 81 |  | 
| Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 82 | 	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); | 
| Marek Lindner | 61906ae | 2011-04-21 15:52:17 +0200 | [diff] [blame^] | 90 | 	spin_lock_init(&bat_priv->softif_neigh_vid_lock); | 
| Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 91 |  | 
 | 92 | 	INIT_HLIST_HEAD(&bat_priv->forw_bat_list); | 
 | 93 | 	INIT_HLIST_HEAD(&bat_priv->forw_bcast_list); | 
 | 94 | 	INIT_HLIST_HEAD(&bat_priv->gw_list); | 
| Marek Lindner | 61906ae | 2011-04-21 15:52:17 +0200 | [diff] [blame^] | 95 | 	INIT_HLIST_HEAD(&bat_priv->softif_neigh_vids); | 
| Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 96 |  | 
 | 97 | 	if (originator_init(bat_priv) < 1) | 
 | 98 | 		goto err; | 
 | 99 |  | 
 | 100 | 	if (hna_local_init(bat_priv) < 1) | 
 | 101 | 		goto err; | 
 | 102 |  | 
 | 103 | 	if (hna_global_init(bat_priv) < 1) | 
 | 104 | 		goto err; | 
 | 105 |  | 
 | 106 | 	hna_local_add(soft_iface, soft_iface->dev_addr); | 
 | 107 |  | 
 | 108 | 	if (vis_init(bat_priv) < 1) | 
 | 109 | 		goto err; | 
 | 110 |  | 
 | 111 | 	atomic_set(&bat_priv->mesh_state, MESH_ACTIVE); | 
 | 112 | 	goto end; | 
 | 113 |  | 
 | 114 | err: | 
 | 115 | 	pr_err("Unable to allocate memory for mesh information structures: " | 
 | 116 | 	       "out of mem ?\n"); | 
 | 117 | 	mesh_free(soft_iface); | 
 | 118 | 	return -1; | 
 | 119 |  | 
 | 120 | end: | 
 | 121 | 	return 0; | 
 | 122 | } | 
 | 123 |  | 
 | 124 | void mesh_free(struct net_device *soft_iface) | 
 | 125 | { | 
 | 126 | 	struct bat_priv *bat_priv = netdev_priv(soft_iface); | 
 | 127 |  | 
 | 128 | 	atomic_set(&bat_priv->mesh_state, MESH_DEACTIVATING); | 
 | 129 |  | 
 | 130 | 	purge_outstanding_packets(bat_priv, NULL); | 
 | 131 |  | 
 | 132 | 	vis_quit(bat_priv); | 
 | 133 |  | 
 | 134 | 	gw_node_purge(bat_priv); | 
 | 135 | 	originator_free(bat_priv); | 
 | 136 |  | 
 | 137 | 	hna_local_free(bat_priv); | 
 | 138 | 	hna_global_free(bat_priv); | 
 | 139 |  | 
 | 140 | 	softif_neigh_purge(bat_priv); | 
 | 141 |  | 
 | 142 | 	atomic_set(&bat_priv->mesh_state, MESH_INACTIVE); | 
 | 143 | } | 
 | 144 |  | 
 | 145 | void inc_module_count(void) | 
 | 146 | { | 
 | 147 | 	try_module_get(THIS_MODULE); | 
 | 148 | } | 
 | 149 |  | 
 | 150 | void dec_module_count(void) | 
 | 151 | { | 
 | 152 | 	module_put(THIS_MODULE); | 
 | 153 | } | 
 | 154 |  | 
 | 155 | int is_my_mac(uint8_t *addr) | 
 | 156 | { | 
| Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 157 | 	struct hard_iface *hard_iface; | 
| Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 158 |  | 
 | 159 | 	rcu_read_lock(); | 
| Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 160 | 	list_for_each_entry_rcu(hard_iface, &hardif_list, list) { | 
 | 161 | 		if (hard_iface->if_status != IF_ACTIVE) | 
| Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 162 | 			continue; | 
 | 163 |  | 
| Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 164 | 		if (compare_eth(hard_iface->net_dev->dev_addr, addr)) { | 
| Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 165 | 			rcu_read_unlock(); | 
 | 166 | 			return 1; | 
 | 167 | 		} | 
 | 168 | 	} | 
 | 169 | 	rcu_read_unlock(); | 
 | 170 | 	return 0; | 
 | 171 |  | 
 | 172 | } | 
 | 173 |  | 
 | 174 | module_init(batman_init); | 
 | 175 | module_exit(batman_exit); | 
 | 176 |  | 
 | 177 | MODULE_LICENSE("GPL"); | 
 | 178 |  | 
 | 179 | MODULE_AUTHOR(DRIVER_AUTHOR); | 
 | 180 | MODULE_DESCRIPTION(DRIVER_DESC); | 
 | 181 | MODULE_SUPPORTED_DEVICE(DRIVER_DEVICE); | 
 | 182 | #ifdef REVISION_VERSION | 
 | 183 | MODULE_VERSION(SOURCE_VERSION "-" REVISION_VERSION); | 
 | 184 | #else | 
 | 185 | MODULE_VERSION(SOURCE_VERSION); | 
 | 186 | #endif |