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 "translation-table.h" |
| 24 | #include "soft-interface.h" |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 25 | #include "hard-interface.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 26 | #include "hash.h" |
| 27 | #include "originator.h" |
| 28 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 29 | static void tt_local_purge(struct work_struct *work); |
| 30 | static void _tt_global_del_orig(struct bat_priv *bat_priv, |
| 31 | struct tt_global_entry *tt_global_entry, |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 32 | char *message); |
| 33 | |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 34 | /* returns 1 if they are the same mac addr */ |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 35 | static int compare_ltt(struct hlist_node *node, void *data2) |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 36 | { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 37 | void *data1 = container_of(node, struct tt_local_entry, hash_entry); |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 38 | |
| 39 | return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0); |
| 40 | } |
| 41 | |
| 42 | /* returns 1 if they are the same mac addr */ |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 43 | static int compare_gtt(struct hlist_node *node, void *data2) |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 44 | { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 45 | void *data1 = container_of(node, struct tt_global_entry, hash_entry); |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 46 | |
| 47 | return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0); |
| 48 | } |
| 49 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 50 | static void tt_local_start_timer(struct bat_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 51 | { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 52 | INIT_DELAYED_WORK(&bat_priv->tt_work, tt_local_purge); |
| 53 | queue_delayed_work(bat_event_workqueue, &bat_priv->tt_work, 10 * HZ); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 56 | static struct tt_local_entry *tt_local_hash_find(struct bat_priv *bat_priv, |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 57 | void *data) |
| 58 | { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 59 | struct hashtable_t *hash = bat_priv->tt_local_hash; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 60 | struct hlist_head *head; |
| 61 | struct hlist_node *node; |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 62 | struct tt_local_entry *tt_local_entry, *tt_local_entry_tmp = NULL; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 63 | int index; |
| 64 | |
| 65 | if (!hash) |
| 66 | return NULL; |
| 67 | |
| 68 | index = choose_orig(data, hash->size); |
| 69 | head = &hash->table[index]; |
| 70 | |
| 71 | rcu_read_lock(); |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 72 | hlist_for_each_entry_rcu(tt_local_entry, node, head, hash_entry) { |
| 73 | if (!compare_eth(tt_local_entry, data)) |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 74 | continue; |
| 75 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 76 | tt_local_entry_tmp = tt_local_entry; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 77 | break; |
| 78 | } |
| 79 | rcu_read_unlock(); |
| 80 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 81 | return tt_local_entry_tmp; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 84 | static struct tt_global_entry *tt_global_hash_find(struct bat_priv *bat_priv, |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 85 | void *data) |
| 86 | { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 87 | struct hashtable_t *hash = bat_priv->tt_global_hash; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 88 | struct hlist_head *head; |
| 89 | struct hlist_node *node; |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 90 | struct tt_global_entry *tt_global_entry; |
| 91 | struct tt_global_entry *tt_global_entry_tmp = NULL; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 92 | int index; |
| 93 | |
| 94 | if (!hash) |
| 95 | return NULL; |
| 96 | |
| 97 | index = choose_orig(data, hash->size); |
| 98 | head = &hash->table[index]; |
| 99 | |
| 100 | rcu_read_lock(); |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 101 | hlist_for_each_entry_rcu(tt_global_entry, node, head, hash_entry) { |
| 102 | if (!compare_eth(tt_global_entry, data)) |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 103 | continue; |
| 104 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 105 | tt_global_entry_tmp = tt_global_entry; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 106 | break; |
| 107 | } |
| 108 | rcu_read_unlock(); |
| 109 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 110 | return tt_global_entry_tmp; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 113 | int tt_local_init(struct bat_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 114 | { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 115 | if (bat_priv->tt_local_hash) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 116 | return 1; |
| 117 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 118 | bat_priv->tt_local_hash = hash_new(1024); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 119 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 120 | if (!bat_priv->tt_local_hash) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 121 | return 0; |
| 122 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 123 | atomic_set(&bat_priv->tt_local_changed, 0); |
| 124 | tt_local_start_timer(bat_priv); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 125 | |
| 126 | return 1; |
| 127 | } |
| 128 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 129 | void tt_local_add(struct net_device *soft_iface, uint8_t *addr) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 130 | { |
| 131 | struct bat_priv *bat_priv = netdev_priv(soft_iface); |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 132 | struct tt_local_entry *tt_local_entry; |
| 133 | struct tt_global_entry *tt_global_entry; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 134 | int required_bytes; |
| 135 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 136 | spin_lock_bh(&bat_priv->tt_lhash_lock); |
| 137 | tt_local_entry = tt_local_hash_find(bat_priv, addr); |
| 138 | spin_unlock_bh(&bat_priv->tt_lhash_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 139 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 140 | if (tt_local_entry) { |
| 141 | tt_local_entry->last_seen = jiffies; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 142 | return; |
| 143 | } |
| 144 | |
| 145 | /* only announce as many hosts as possible in the batman-packet and |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 146 | space in batman_packet->num_tt That also should give a limit to |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 147 | MAC-flooding. */ |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 148 | required_bytes = (bat_priv->num_local_tt + 1) * ETH_ALEN; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 149 | required_bytes += BAT_PACKET_LEN; |
| 150 | |
| 151 | if ((required_bytes > ETH_DATA_LEN) || |
| 152 | (atomic_read(&bat_priv->aggregated_ogms) && |
| 153 | required_bytes > MAX_AGGREGATION_BYTES) || |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 154 | (bat_priv->num_local_tt + 1 > 255)) { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 155 | bat_dbg(DBG_ROUTES, bat_priv, |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 156 | "Can't add new local tt entry (%pM): " |
| 157 | "number of local tt entries exceeds packet size\n", |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 158 | addr); |
| 159 | return; |
| 160 | } |
| 161 | |
| 162 | bat_dbg(DBG_ROUTES, bat_priv, |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 163 | "Creating new local tt entry: %pM\n", addr); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 164 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 165 | tt_local_entry = kmalloc(sizeof(struct tt_local_entry), GFP_ATOMIC); |
| 166 | if (!tt_local_entry) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 167 | return; |
| 168 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 169 | memcpy(tt_local_entry->addr, addr, ETH_ALEN); |
| 170 | tt_local_entry->last_seen = jiffies; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 171 | |
| 172 | /* the batman interface mac address should never be purged */ |
Marek Lindner | 39901e7 | 2011-02-18 12:28:08 +0000 | [diff] [blame] | 173 | if (compare_eth(addr, soft_iface->dev_addr)) |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 174 | tt_local_entry->never_purge = 1; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 175 | else |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 176 | tt_local_entry->never_purge = 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 177 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 178 | spin_lock_bh(&bat_priv->tt_lhash_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 179 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 180 | hash_add(bat_priv->tt_local_hash, compare_ltt, choose_orig, |
| 181 | tt_local_entry, &tt_local_entry->hash_entry); |
| 182 | bat_priv->num_local_tt++; |
| 183 | atomic_set(&bat_priv->tt_local_changed, 1); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 184 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 185 | spin_unlock_bh(&bat_priv->tt_lhash_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 186 | |
| 187 | /* remove address from global hash if present */ |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 188 | spin_lock_bh(&bat_priv->tt_ghash_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 189 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 190 | tt_global_entry = tt_global_hash_find(bat_priv, addr); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 191 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 192 | if (tt_global_entry) |
| 193 | _tt_global_del_orig(bat_priv, tt_global_entry, |
| 194 | "local tt received"); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 195 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 196 | spin_unlock_bh(&bat_priv->tt_ghash_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 197 | } |
| 198 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 199 | int tt_local_fill_buffer(struct bat_priv *bat_priv, |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 200 | unsigned char *buff, int buff_len) |
| 201 | { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 202 | struct hashtable_t *hash = bat_priv->tt_local_hash; |
| 203 | struct tt_local_entry *tt_local_entry; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 204 | struct hlist_node *node; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 205 | struct hlist_head *head; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 206 | int i, count = 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 207 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 208 | spin_lock_bh(&bat_priv->tt_lhash_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 209 | |
| 210 | for (i = 0; i < hash->size; i++) { |
| 211 | head = &hash->table[i]; |
| 212 | |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 213 | rcu_read_lock(); |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 214 | hlist_for_each_entry_rcu(tt_local_entry, node, |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 215 | head, hash_entry) { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 216 | if (buff_len < (count + 1) * ETH_ALEN) |
| 217 | break; |
| 218 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 219 | memcpy(buff + (count * ETH_ALEN), tt_local_entry->addr, |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 220 | ETH_ALEN); |
| 221 | |
| 222 | count++; |
| 223 | } |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 224 | rcu_read_unlock(); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 225 | } |
| 226 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 227 | /* if we did not get all new local tts see you next time ;-) */ |
| 228 | if (count == bat_priv->num_local_tt) |
| 229 | atomic_set(&bat_priv->tt_local_changed, 0); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 230 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 231 | spin_unlock_bh(&bat_priv->tt_lhash_lock); |
Sven Eckelmann | 53320fe | 2010-12-20 10:32:03 -0800 | [diff] [blame] | 232 | return count; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 235 | int tt_local_seq_print_text(struct seq_file *seq, void *offset) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 236 | { |
| 237 | struct net_device *net_dev = (struct net_device *)seq->private; |
| 238 | struct bat_priv *bat_priv = netdev_priv(net_dev); |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 239 | struct hashtable_t *hash = bat_priv->tt_local_hash; |
| 240 | struct tt_local_entry *tt_local_entry; |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 241 | struct hard_iface *primary_if; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 242 | struct hlist_node *node; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 243 | struct hlist_head *head; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 244 | size_t buf_size, pos; |
| 245 | char *buff; |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 246 | int i, ret = 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 247 | |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 248 | primary_if = primary_if_get_selected(bat_priv); |
| 249 | if (!primary_if) { |
| 250 | ret = seq_printf(seq, "BATMAN mesh %s disabled - " |
| 251 | "please specify interfaces to enable it\n", |
| 252 | net_dev->name); |
| 253 | goto out; |
| 254 | } |
| 255 | |
| 256 | if (primary_if->if_status != IF_ACTIVE) { |
| 257 | ret = seq_printf(seq, "BATMAN mesh %s disabled - " |
| 258 | "primary interface not active\n", |
| 259 | net_dev->name); |
| 260 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | seq_printf(seq, "Locally retrieved addresses (from %s) " |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 264 | "announced via TT:\n", |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 265 | net_dev->name); |
| 266 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 267 | spin_lock_bh(&bat_priv->tt_lhash_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 268 | |
| 269 | buf_size = 1; |
| 270 | /* Estimate length for: " * xx:xx:xx:xx:xx:xx\n" */ |
| 271 | for (i = 0; i < hash->size; i++) { |
| 272 | head = &hash->table[i]; |
| 273 | |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 274 | rcu_read_lock(); |
| 275 | __hlist_for_each_rcu(node, head) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 276 | buf_size += 21; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 277 | rcu_read_unlock(); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | buff = kmalloc(buf_size, GFP_ATOMIC); |
| 281 | if (!buff) { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 282 | spin_unlock_bh(&bat_priv->tt_lhash_lock); |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 283 | ret = -ENOMEM; |
| 284 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 285 | } |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 286 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 287 | buff[0] = '\0'; |
| 288 | pos = 0; |
| 289 | |
| 290 | for (i = 0; i < hash->size; i++) { |
| 291 | head = &hash->table[i]; |
| 292 | |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 293 | rcu_read_lock(); |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 294 | hlist_for_each_entry_rcu(tt_local_entry, node, |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 295 | head, hash_entry) { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 296 | pos += snprintf(buff + pos, 22, " * %pM\n", |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 297 | tt_local_entry->addr); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 298 | } |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 299 | rcu_read_unlock(); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 300 | } |
| 301 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 302 | spin_unlock_bh(&bat_priv->tt_lhash_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 303 | |
| 304 | seq_printf(seq, "%s", buff); |
| 305 | kfree(buff); |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 306 | out: |
| 307 | if (primary_if) |
| 308 | hardif_free_ref(primary_if); |
| 309 | return ret; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 312 | static void _tt_local_del(struct hlist_node *node, void *arg) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 313 | { |
| 314 | struct bat_priv *bat_priv = (struct bat_priv *)arg; |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 315 | void *data = container_of(node, struct tt_local_entry, hash_entry); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 316 | |
| 317 | kfree(data); |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 318 | bat_priv->num_local_tt--; |
| 319 | atomic_set(&bat_priv->tt_local_changed, 1); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 320 | } |
| 321 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 322 | static void tt_local_del(struct bat_priv *bat_priv, |
| 323 | struct tt_local_entry *tt_local_entry, |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 324 | char *message) |
| 325 | { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 326 | bat_dbg(DBG_ROUTES, bat_priv, "Deleting local tt entry (%pM): %s\n", |
| 327 | tt_local_entry->addr, message); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 328 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 329 | hash_remove(bat_priv->tt_local_hash, compare_ltt, choose_orig, |
| 330 | tt_local_entry->addr); |
| 331 | _tt_local_del(&tt_local_entry->hash_entry, bat_priv); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 332 | } |
| 333 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 334 | void tt_local_remove(struct bat_priv *bat_priv, |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 335 | uint8_t *addr, char *message) |
| 336 | { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 337 | struct tt_local_entry *tt_local_entry; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 338 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 339 | spin_lock_bh(&bat_priv->tt_lhash_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 340 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 341 | tt_local_entry = tt_local_hash_find(bat_priv, addr); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 342 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 343 | if (tt_local_entry) |
| 344 | tt_local_del(bat_priv, tt_local_entry, message); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 345 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 346 | spin_unlock_bh(&bat_priv->tt_lhash_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 347 | } |
| 348 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 349 | static void tt_local_purge(struct work_struct *work) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 350 | { |
| 351 | struct delayed_work *delayed_work = |
| 352 | container_of(work, struct delayed_work, work); |
| 353 | struct bat_priv *bat_priv = |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 354 | container_of(delayed_work, struct bat_priv, tt_work); |
| 355 | struct hashtable_t *hash = bat_priv->tt_local_hash; |
| 356 | struct tt_local_entry *tt_local_entry; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 357 | struct hlist_node *node, *node_tmp; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 358 | struct hlist_head *head; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 359 | unsigned long timeout; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 360 | int i; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 361 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 362 | spin_lock_bh(&bat_priv->tt_lhash_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 363 | |
| 364 | for (i = 0; i < hash->size; i++) { |
| 365 | head = &hash->table[i]; |
| 366 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 367 | hlist_for_each_entry_safe(tt_local_entry, node, node_tmp, |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 368 | head, hash_entry) { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 369 | if (tt_local_entry->never_purge) |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 370 | continue; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 371 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 372 | timeout = tt_local_entry->last_seen; |
| 373 | timeout += TT_LOCAL_TIMEOUT * HZ; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 374 | |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 375 | if (time_before(jiffies, timeout)) |
| 376 | continue; |
| 377 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 378 | tt_local_del(bat_priv, tt_local_entry, |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 379 | "address timed out"); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 380 | } |
| 381 | } |
| 382 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 383 | spin_unlock_bh(&bat_priv->tt_lhash_lock); |
| 384 | tt_local_start_timer(bat_priv); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 385 | } |
| 386 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 387 | void tt_local_free(struct bat_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 388 | { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 389 | if (!bat_priv->tt_local_hash) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 390 | return; |
| 391 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 392 | cancel_delayed_work_sync(&bat_priv->tt_work); |
| 393 | hash_delete(bat_priv->tt_local_hash, _tt_local_del, bat_priv); |
| 394 | bat_priv->tt_local_hash = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 395 | } |
| 396 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 397 | int tt_global_init(struct bat_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 398 | { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 399 | if (bat_priv->tt_global_hash) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 400 | return 1; |
| 401 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 402 | bat_priv->tt_global_hash = hash_new(1024); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 403 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 404 | if (!bat_priv->tt_global_hash) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 405 | return 0; |
| 406 | |
| 407 | return 1; |
| 408 | } |
| 409 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 410 | void tt_global_add_orig(struct bat_priv *bat_priv, |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 411 | struct orig_node *orig_node, |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 412 | unsigned char *tt_buff, int tt_buff_len) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 413 | { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 414 | struct tt_global_entry *tt_global_entry; |
| 415 | struct tt_local_entry *tt_local_entry; |
| 416 | int tt_buff_count = 0; |
| 417 | unsigned char *tt_ptr; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 418 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 419 | while ((tt_buff_count + 1) * ETH_ALEN <= tt_buff_len) { |
| 420 | spin_lock_bh(&bat_priv->tt_ghash_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 421 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 422 | tt_ptr = tt_buff + (tt_buff_count * ETH_ALEN); |
| 423 | tt_global_entry = tt_global_hash_find(bat_priv, tt_ptr); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 424 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 425 | if (!tt_global_entry) { |
| 426 | spin_unlock_bh(&bat_priv->tt_ghash_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 427 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 428 | tt_global_entry = |
| 429 | kmalloc(sizeof(struct tt_global_entry), |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 430 | GFP_ATOMIC); |
| 431 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 432 | if (!tt_global_entry) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 433 | break; |
| 434 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 435 | memcpy(tt_global_entry->addr, tt_ptr, ETH_ALEN); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 436 | |
| 437 | bat_dbg(DBG_ROUTES, bat_priv, |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 438 | "Creating new global tt entry: " |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 439 | "%pM (via %pM)\n", |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 440 | tt_global_entry->addr, orig_node->orig); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 441 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 442 | spin_lock_bh(&bat_priv->tt_ghash_lock); |
| 443 | hash_add(bat_priv->tt_global_hash, compare_gtt, |
| 444 | choose_orig, tt_global_entry, |
| 445 | &tt_global_entry->hash_entry); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 446 | |
| 447 | } |
| 448 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 449 | tt_global_entry->orig_node = orig_node; |
| 450 | spin_unlock_bh(&bat_priv->tt_ghash_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 451 | |
| 452 | /* remove address from local hash if present */ |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 453 | spin_lock_bh(&bat_priv->tt_lhash_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 454 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 455 | tt_ptr = tt_buff + (tt_buff_count * ETH_ALEN); |
| 456 | tt_local_entry = tt_local_hash_find(bat_priv, tt_ptr); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 457 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 458 | if (tt_local_entry) |
| 459 | tt_local_del(bat_priv, tt_local_entry, |
| 460 | "global tt received"); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 461 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 462 | spin_unlock_bh(&bat_priv->tt_lhash_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 463 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 464 | tt_buff_count++; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | /* initialize, and overwrite if malloc succeeds */ |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 468 | orig_node->tt_buff = NULL; |
| 469 | orig_node->tt_buff_len = 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 470 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 471 | if (tt_buff_len > 0) { |
| 472 | orig_node->tt_buff = kmalloc(tt_buff_len, GFP_ATOMIC); |
| 473 | if (orig_node->tt_buff) { |
| 474 | memcpy(orig_node->tt_buff, tt_buff, tt_buff_len); |
| 475 | orig_node->tt_buff_len = tt_buff_len; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 476 | } |
| 477 | } |
| 478 | } |
| 479 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 480 | int tt_global_seq_print_text(struct seq_file *seq, void *offset) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 481 | { |
| 482 | struct net_device *net_dev = (struct net_device *)seq->private; |
| 483 | struct bat_priv *bat_priv = netdev_priv(net_dev); |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 484 | struct hashtable_t *hash = bat_priv->tt_global_hash; |
| 485 | struct tt_global_entry *tt_global_entry; |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 486 | struct hard_iface *primary_if; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 487 | struct hlist_node *node; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 488 | struct hlist_head *head; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 489 | size_t buf_size, pos; |
| 490 | char *buff; |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 491 | int i, ret = 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 492 | |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 493 | primary_if = primary_if_get_selected(bat_priv); |
| 494 | if (!primary_if) { |
| 495 | ret = seq_printf(seq, "BATMAN mesh %s disabled - please " |
| 496 | "specify interfaces to enable it\n", |
| 497 | net_dev->name); |
| 498 | goto out; |
| 499 | } |
| 500 | |
| 501 | if (primary_if->if_status != IF_ACTIVE) { |
| 502 | ret = seq_printf(seq, "BATMAN mesh %s disabled - " |
| 503 | "primary interface not active\n", |
| 504 | net_dev->name); |
| 505 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 506 | } |
| 507 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 508 | seq_printf(seq, |
| 509 | "Globally announced TT entries received via the mesh %s\n", |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 510 | net_dev->name); |
| 511 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 512 | spin_lock_bh(&bat_priv->tt_ghash_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 513 | |
| 514 | buf_size = 1; |
| 515 | /* Estimate length for: " * xx:xx:xx:xx:xx:xx via xx:xx:xx:xx:xx:xx\n"*/ |
| 516 | for (i = 0; i < hash->size; i++) { |
| 517 | head = &hash->table[i]; |
| 518 | |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 519 | rcu_read_lock(); |
| 520 | __hlist_for_each_rcu(node, head) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 521 | buf_size += 43; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 522 | rcu_read_unlock(); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | buff = kmalloc(buf_size, GFP_ATOMIC); |
| 526 | if (!buff) { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 527 | spin_unlock_bh(&bat_priv->tt_ghash_lock); |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 528 | ret = -ENOMEM; |
| 529 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 530 | } |
| 531 | buff[0] = '\0'; |
| 532 | pos = 0; |
| 533 | |
| 534 | for (i = 0; i < hash->size; i++) { |
| 535 | head = &hash->table[i]; |
| 536 | |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 537 | rcu_read_lock(); |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 538 | hlist_for_each_entry_rcu(tt_global_entry, node, |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 539 | head, hash_entry) { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 540 | pos += snprintf(buff + pos, 44, |
| 541 | " * %pM via %pM\n", |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 542 | tt_global_entry->addr, |
| 543 | tt_global_entry->orig_node->orig); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 544 | } |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 545 | rcu_read_unlock(); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 546 | } |
| 547 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 548 | spin_unlock_bh(&bat_priv->tt_ghash_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 549 | |
| 550 | seq_printf(seq, "%s", buff); |
| 551 | kfree(buff); |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 552 | out: |
| 553 | if (primary_if) |
| 554 | hardif_free_ref(primary_if); |
| 555 | return ret; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 556 | } |
| 557 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 558 | static void _tt_global_del_orig(struct bat_priv *bat_priv, |
| 559 | struct tt_global_entry *tt_global_entry, |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 560 | char *message) |
| 561 | { |
| 562 | bat_dbg(DBG_ROUTES, bat_priv, |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 563 | "Deleting global tt entry %pM (via %pM): %s\n", |
| 564 | tt_global_entry->addr, tt_global_entry->orig_node->orig, |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 565 | message); |
| 566 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 567 | hash_remove(bat_priv->tt_global_hash, compare_gtt, choose_orig, |
| 568 | tt_global_entry->addr); |
| 569 | kfree(tt_global_entry); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 570 | } |
| 571 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 572 | void tt_global_del_orig(struct bat_priv *bat_priv, |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 573 | struct orig_node *orig_node, char *message) |
| 574 | { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 575 | struct tt_global_entry *tt_global_entry; |
| 576 | int tt_buff_count = 0; |
| 577 | unsigned char *tt_ptr; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 578 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 579 | if (orig_node->tt_buff_len == 0) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 580 | return; |
| 581 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 582 | spin_lock_bh(&bat_priv->tt_ghash_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 583 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 584 | while ((tt_buff_count + 1) * ETH_ALEN <= orig_node->tt_buff_len) { |
| 585 | tt_ptr = orig_node->tt_buff + (tt_buff_count * ETH_ALEN); |
| 586 | tt_global_entry = tt_global_hash_find(bat_priv, tt_ptr); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 587 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 588 | if ((tt_global_entry) && |
| 589 | (tt_global_entry->orig_node == orig_node)) |
| 590 | _tt_global_del_orig(bat_priv, tt_global_entry, |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 591 | message); |
| 592 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 593 | tt_buff_count++; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 594 | } |
| 595 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 596 | spin_unlock_bh(&bat_priv->tt_ghash_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 597 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 598 | orig_node->tt_buff_len = 0; |
| 599 | kfree(orig_node->tt_buff); |
| 600 | orig_node->tt_buff = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 601 | } |
| 602 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 603 | static void tt_global_del(struct hlist_node *node, void *arg) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 604 | { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 605 | void *data = container_of(node, struct tt_global_entry, hash_entry); |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 606 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 607 | kfree(data); |
| 608 | } |
| 609 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 610 | void tt_global_free(struct bat_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 611 | { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 612 | if (!bat_priv->tt_global_hash) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 613 | return; |
| 614 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 615 | hash_delete(bat_priv->tt_global_hash, tt_global_del, NULL); |
| 616 | bat_priv->tt_global_hash = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | struct orig_node *transtable_search(struct bat_priv *bat_priv, uint8_t *addr) |
| 620 | { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 621 | struct tt_global_entry *tt_global_entry; |
Marek Lindner | 7b36e8e | 2011-02-18 12:28:10 +0000 | [diff] [blame] | 622 | struct orig_node *orig_node = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 623 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 624 | spin_lock_bh(&bat_priv->tt_ghash_lock); |
| 625 | tt_global_entry = tt_global_hash_find(bat_priv, addr); |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 626 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 627 | if (!tt_global_entry) |
Marek Lindner | 7b36e8e | 2011-02-18 12:28:10 +0000 | [diff] [blame] | 628 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 629 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 630 | if (!atomic_inc_not_zero(&tt_global_entry->orig_node->refcount)) |
Marek Lindner | 7b36e8e | 2011-02-18 12:28:10 +0000 | [diff] [blame] | 631 | goto out; |
| 632 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 633 | orig_node = tt_global_entry->orig_node; |
Marek Lindner | 7b36e8e | 2011-02-18 12:28:10 +0000 | [diff] [blame] | 634 | |
| 635 | out: |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 636 | spin_unlock_bh(&bat_priv->tt_ghash_lock); |
Marek Lindner | 7b36e8e | 2011-02-18 12:28:10 +0000 | [diff] [blame] | 637 | return orig_node; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 638 | } |