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 | |
Sven Eckelmann | c3caf51 | 2011-05-03 11:51:38 +0200 | [diff] [blame] | 36 | |
| 37 | /* List manipulations on hardif_list have to be rtnl_lock()'ed, |
| 38 | * list traversals just rcu-locked */ |
Marek Lindner | 4389e47 | 2011-02-18 12:33:19 +0000 | [diff] [blame] | 39 | struct list_head hardif_list; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 40 | |
| 41 | unsigned char broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
| 42 | |
| 43 | struct workqueue_struct *bat_event_workqueue; |
| 44 | |
| 45 | static int __init batman_init(void) |
| 46 | { |
Marek Lindner | 4389e47 | 2011-02-18 12:33:19 +0000 | [diff] [blame] | 47 | INIT_LIST_HEAD(&hardif_list); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 48 | |
| 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 | |
| 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 | |
| 68 | static 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 | |
| 81 | int mesh_init(struct net_device *soft_iface) |
| 82 | { |
| 83 | struct bat_priv *bat_priv = netdev_priv(soft_iface); |
| 84 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 85 | spin_lock_init(&bat_priv->forw_bat_list_lock); |
| 86 | spin_lock_init(&bat_priv->forw_bcast_list_lock); |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 87 | spin_lock_init(&bat_priv->tt_lhash_lock); |
| 88 | spin_lock_init(&bat_priv->tt_ghash_lock); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 89 | spin_lock_init(&bat_priv->tt_changes_list_lock); |
| 90 | spin_lock_init(&bat_priv->tt_req_list_lock); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame^] | 91 | spin_lock_init(&bat_priv->tt_roam_list_lock); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 92 | spin_lock_init(&bat_priv->tt_buff_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 93 | spin_lock_init(&bat_priv->gw_list_lock); |
| 94 | spin_lock_init(&bat_priv->vis_hash_lock); |
| 95 | spin_lock_init(&bat_priv->vis_list_lock); |
| 96 | spin_lock_init(&bat_priv->softif_neigh_lock); |
Marek Lindner | 61906ae | 2011-04-21 15:52:17 +0200 | [diff] [blame] | 97 | spin_lock_init(&bat_priv->softif_neigh_vid_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 98 | |
| 99 | INIT_HLIST_HEAD(&bat_priv->forw_bat_list); |
| 100 | INIT_HLIST_HEAD(&bat_priv->forw_bcast_list); |
| 101 | INIT_HLIST_HEAD(&bat_priv->gw_list); |
Marek Lindner | 61906ae | 2011-04-21 15:52:17 +0200 | [diff] [blame] | 102 | INIT_HLIST_HEAD(&bat_priv->softif_neigh_vids); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 103 | INIT_LIST_HEAD(&bat_priv->tt_changes_list); |
| 104 | INIT_LIST_HEAD(&bat_priv->tt_req_list); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame^] | 105 | INIT_LIST_HEAD(&bat_priv->tt_roam_list); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 106 | |
| 107 | if (originator_init(bat_priv) < 1) |
| 108 | goto err; |
| 109 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 110 | if (tt_init(bat_priv) < 1) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 111 | goto err; |
| 112 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 113 | tt_local_add(soft_iface, soft_iface->dev_addr); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 114 | |
| 115 | if (vis_init(bat_priv) < 1) |
| 116 | goto err; |
| 117 | |
| 118 | atomic_set(&bat_priv->mesh_state, MESH_ACTIVE); |
| 119 | goto end; |
| 120 | |
| 121 | err: |
| 122 | pr_err("Unable to allocate memory for mesh information structures: " |
| 123 | "out of mem ?\n"); |
| 124 | mesh_free(soft_iface); |
| 125 | return -1; |
| 126 | |
| 127 | end: |
| 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | void mesh_free(struct net_device *soft_iface) |
| 132 | { |
| 133 | struct bat_priv *bat_priv = netdev_priv(soft_iface); |
| 134 | |
| 135 | atomic_set(&bat_priv->mesh_state, MESH_DEACTIVATING); |
| 136 | |
| 137 | purge_outstanding_packets(bat_priv, NULL); |
| 138 | |
| 139 | vis_quit(bat_priv); |
| 140 | |
| 141 | gw_node_purge(bat_priv); |
| 142 | originator_free(bat_priv); |
| 143 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 144 | tt_free(bat_priv); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 145 | |
| 146 | softif_neigh_purge(bat_priv); |
| 147 | |
| 148 | atomic_set(&bat_priv->mesh_state, MESH_INACTIVE); |
| 149 | } |
| 150 | |
| 151 | void inc_module_count(void) |
| 152 | { |
| 153 | try_module_get(THIS_MODULE); |
| 154 | } |
| 155 | |
| 156 | void dec_module_count(void) |
| 157 | { |
| 158 | module_put(THIS_MODULE); |
| 159 | } |
| 160 | |
Sven Eckelmann | 747e422 | 2011-05-14 23:14:50 +0200 | [diff] [blame] | 161 | int is_my_mac(const uint8_t *addr) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 162 | { |
Sven Eckelmann | 747e422 | 2011-05-14 23:14:50 +0200 | [diff] [blame] | 163 | const struct hard_iface *hard_iface; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 164 | |
| 165 | rcu_read_lock(); |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 166 | list_for_each_entry_rcu(hard_iface, &hardif_list, list) { |
| 167 | if (hard_iface->if_status != IF_ACTIVE) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 168 | continue; |
| 169 | |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 170 | if (compare_eth(hard_iface->net_dev->dev_addr, addr)) { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 171 | rcu_read_unlock(); |
| 172 | return 1; |
| 173 | } |
| 174 | } |
| 175 | rcu_read_unlock(); |
| 176 | return 0; |
| 177 | |
| 178 | } |
| 179 | |
| 180 | module_init(batman_init); |
| 181 | module_exit(batman_exit); |
| 182 | |
| 183 | MODULE_LICENSE("GPL"); |
| 184 | |
| 185 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 186 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 187 | MODULE_SUPPORTED_DEVICE(DRIVER_DEVICE); |
| 188 | #ifdef REVISION_VERSION |
| 189 | MODULE_VERSION(SOURCE_VERSION "-" REVISION_VERSION); |
| 190 | #else |
| 191 | MODULE_VERSION(SOURCE_VERSION); |
| 192 | #endif |