Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 1 | /* Copyright (C) 2013-2016 B.A.T.M.A.N. contributors: |
| 2 | * |
| 3 | * Linus Lüssing, Marek Lindner |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of version 2 of the GNU General Public |
| 7 | * License as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but |
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | |
Sven Eckelmann | a2d0816 | 2016-05-15 11:07:46 +0200 | [diff] [blame] | 18 | #include "bat_v.h" |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 19 | #include "main.h" |
| 20 | |
Antonio Quartulli | 0b5ecc6 | 2016-01-16 16:40:14 +0800 | [diff] [blame] | 21 | #include <linux/atomic.h> |
Antonio Quartulli | 9786906 | 2016-01-16 16:40:17 +0800 | [diff] [blame] | 22 | #include <linux/bug.h> |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 23 | #include <linux/cache.h> |
Antonio Quartulli | 0868694 | 2016-07-03 12:46:32 +0200 | [diff] [blame] | 24 | #include <linux/errno.h> |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 25 | #include <linux/init.h> |
Antonio Quartulli | 261e264 | 2016-01-16 16:40:18 +0800 | [diff] [blame] | 26 | #include <linux/jiffies.h> |
Antonio Quartulli | 0868694 | 2016-07-03 12:46:32 +0200 | [diff] [blame] | 27 | #include <linux/kernel.h> |
Antonio Quartulli | 261e264 | 2016-01-16 16:40:18 +0800 | [diff] [blame] | 28 | #include <linux/netdevice.h> |
| 29 | #include <linux/rculist.h> |
| 30 | #include <linux/rcupdate.h> |
| 31 | #include <linux/seq_file.h> |
Sven Eckelmann | a45e932 | 2016-05-06 11:43:38 +0200 | [diff] [blame] | 32 | #include <linux/stddef.h> |
Antonio Quartulli | 9786906 | 2016-01-16 16:40:17 +0800 | [diff] [blame] | 33 | #include <linux/types.h> |
Antonio Quartulli | c833484 | 2015-11-10 18:50:51 +0100 | [diff] [blame] | 34 | #include <linux/workqueue.h> |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 35 | |
Sven Eckelmann | a2d0816 | 2016-05-15 11:07:46 +0200 | [diff] [blame] | 36 | #include "bat_algo.h" |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 37 | #include "bat_v_elp.h" |
Antonio Quartulli | 0da0035 | 2016-01-16 16:40:12 +0800 | [diff] [blame] | 38 | #include "bat_v_ogm.h" |
Antonio Quartulli | 0868694 | 2016-07-03 12:46:32 +0200 | [diff] [blame] | 39 | #include "gateway_client.h" |
| 40 | #include "gateway_common.h" |
Antonio Quartulli | b6cf5d4 | 2016-04-14 09:37:05 +0800 | [diff] [blame] | 41 | #include "hard-interface.h" |
Antonio Quartulli | 261e264 | 2016-01-16 16:40:18 +0800 | [diff] [blame] | 42 | #include "hash.h" |
Antonio Quartulli | 9786906 | 2016-01-16 16:40:17 +0800 | [diff] [blame] | 43 | #include "originator.h" |
Linus Luessing | 162bd64 | 2016-01-16 16:40:10 +0800 | [diff] [blame] | 44 | #include "packet.h" |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 45 | |
Antonio Quartulli | b6cf5d4 | 2016-04-14 09:37:05 +0800 | [diff] [blame] | 46 | static void batadv_v_iface_activate(struct batadv_hard_iface *hard_iface) |
| 47 | { |
Marek Lindner | ebe24ce | 2016-05-07 19:54:17 +0800 | [diff] [blame] | 48 | struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); |
| 49 | struct batadv_hard_iface *primary_if; |
| 50 | |
| 51 | primary_if = batadv_primary_if_get_selected(bat_priv); |
| 52 | |
| 53 | if (primary_if) { |
| 54 | batadv_v_elp_iface_activate(primary_if, hard_iface); |
| 55 | batadv_hardif_put(primary_if); |
| 56 | } |
| 57 | |
Antonio Quartulli | b6cf5d4 | 2016-04-14 09:37:05 +0800 | [diff] [blame] | 58 | /* B.A.T.M.A.N. V does not use any queuing mechanism, therefore it can |
| 59 | * set the interface as ACTIVE right away, without any risk of race |
| 60 | * condition |
| 61 | */ |
| 62 | if (hard_iface->if_status == BATADV_IF_TO_BE_ACTIVATED) |
| 63 | hard_iface->if_status = BATADV_IF_ACTIVE; |
| 64 | } |
| 65 | |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 66 | static int batadv_v_iface_enable(struct batadv_hard_iface *hard_iface) |
| 67 | { |
Antonio Quartulli | 0da0035 | 2016-01-16 16:40:12 +0800 | [diff] [blame] | 68 | int ret; |
| 69 | |
| 70 | ret = batadv_v_elp_iface_enable(hard_iface); |
| 71 | if (ret < 0) |
| 72 | return ret; |
| 73 | |
| 74 | ret = batadv_v_ogm_iface_enable(hard_iface); |
| 75 | if (ret < 0) |
| 76 | batadv_v_elp_iface_disable(hard_iface); |
| 77 | |
| 78 | return ret; |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | static void batadv_v_iface_disable(struct batadv_hard_iface *hard_iface) |
| 82 | { |
| 83 | batadv_v_elp_iface_disable(hard_iface); |
| 84 | } |
| 85 | |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 86 | static void batadv_v_primary_iface_set(struct batadv_hard_iface *hard_iface) |
| 87 | { |
| 88 | batadv_v_elp_primary_iface_set(hard_iface); |
Antonio Quartulli | 0da0035 | 2016-01-16 16:40:12 +0800 | [diff] [blame] | 89 | batadv_v_ogm_primary_iface_set(hard_iface); |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 90 | } |
| 91 | |
Antonio Quartulli | 1653f61 | 2016-05-02 01:14:40 +0800 | [diff] [blame] | 92 | /** |
| 93 | * batadv_v_iface_update_mac - react to hard-interface MAC address change |
| 94 | * @hard_iface: the modified interface |
| 95 | * |
| 96 | * If the modified interface is the primary one, update the originator |
| 97 | * address in the ELP and OGM messages to reflect the new MAC address. |
| 98 | */ |
| 99 | static void batadv_v_iface_update_mac(struct batadv_hard_iface *hard_iface) |
| 100 | { |
| 101 | struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); |
| 102 | struct batadv_hard_iface *primary_if; |
| 103 | |
| 104 | primary_if = batadv_primary_if_get_selected(bat_priv); |
| 105 | if (primary_if != hard_iface) |
| 106 | goto out; |
| 107 | |
| 108 | batadv_v_primary_iface_set(hard_iface); |
| 109 | out: |
| 110 | if (primary_if) |
| 111 | batadv_hardif_put(primary_if); |
| 112 | } |
| 113 | |
Linus Luessing | 162bd64 | 2016-01-16 16:40:10 +0800 | [diff] [blame] | 114 | static void |
| 115 | batadv_v_hardif_neigh_init(struct batadv_hardif_neigh_node *hardif_neigh) |
| 116 | { |
| 117 | ewma_throughput_init(&hardif_neigh->bat_v.throughput); |
Antonio Quartulli | c833484 | 2015-11-10 18:50:51 +0100 | [diff] [blame] | 118 | INIT_WORK(&hardif_neigh->bat_v.metric_work, |
| 119 | batadv_v_elp_throughput_metric_update); |
Linus Luessing | 162bd64 | 2016-01-16 16:40:10 +0800 | [diff] [blame] | 120 | } |
| 121 | |
Antonio Quartulli | 261e264 | 2016-01-16 16:40:18 +0800 | [diff] [blame] | 122 | /** |
| 123 | * batadv_v_orig_print_neigh - print neighbors for the originator table |
| 124 | * @orig_node: the orig_node for which the neighbors are printed |
| 125 | * @if_outgoing: outgoing interface for these entries |
| 126 | * @seq: debugfs table seq_file struct |
| 127 | * |
| 128 | * Must be called while holding an rcu lock. |
| 129 | */ |
| 130 | static void |
| 131 | batadv_v_orig_print_neigh(struct batadv_orig_node *orig_node, |
| 132 | struct batadv_hard_iface *if_outgoing, |
| 133 | struct seq_file *seq) |
| 134 | { |
| 135 | struct batadv_neigh_node *neigh_node; |
| 136 | struct batadv_neigh_ifinfo *n_ifinfo; |
| 137 | |
| 138 | hlist_for_each_entry_rcu(neigh_node, &orig_node->neigh_list, list) { |
| 139 | n_ifinfo = batadv_neigh_ifinfo_get(neigh_node, if_outgoing); |
| 140 | if (!n_ifinfo) |
| 141 | continue; |
| 142 | |
| 143 | seq_printf(seq, " %pM (%9u.%1u)", |
| 144 | neigh_node->addr, |
| 145 | n_ifinfo->bat_v.throughput / 10, |
| 146 | n_ifinfo->bat_v.throughput % 10); |
| 147 | |
| 148 | batadv_neigh_ifinfo_put(n_ifinfo); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | /** |
Linus Luessing | 626d23e | 2016-01-16 16:40:19 +0800 | [diff] [blame] | 153 | * batadv_v_hardif_neigh_print - print a single ELP neighbour node |
| 154 | * @seq: neighbour table seq_file struct |
| 155 | * @hardif_neigh: hardif neighbour information |
| 156 | */ |
| 157 | static void |
| 158 | batadv_v_hardif_neigh_print(struct seq_file *seq, |
| 159 | struct batadv_hardif_neigh_node *hardif_neigh) |
| 160 | { |
| 161 | int last_secs, last_msecs; |
| 162 | u32 throughput; |
| 163 | |
| 164 | last_secs = jiffies_to_msecs(jiffies - hardif_neigh->last_seen) / 1000; |
| 165 | last_msecs = jiffies_to_msecs(jiffies - hardif_neigh->last_seen) % 1000; |
| 166 | throughput = ewma_throughput_read(&hardif_neigh->bat_v.throughput); |
| 167 | |
| 168 | seq_printf(seq, "%pM %4i.%03is (%9u.%1u) [%10s]\n", |
| 169 | hardif_neigh->addr, last_secs, last_msecs, throughput / 10, |
| 170 | throughput % 10, hardif_neigh->if_incoming->net_dev->name); |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * batadv_v_neigh_print - print the single hop neighbour list |
| 175 | * @bat_priv: the bat priv with all the soft interface information |
| 176 | * @seq: neighbour table seq_file struct |
| 177 | */ |
| 178 | static void batadv_v_neigh_print(struct batadv_priv *bat_priv, |
| 179 | struct seq_file *seq) |
| 180 | { |
| 181 | struct net_device *net_dev = (struct net_device *)seq->private; |
| 182 | struct batadv_hardif_neigh_node *hardif_neigh; |
| 183 | struct batadv_hard_iface *hard_iface; |
| 184 | int batman_count = 0; |
| 185 | |
Antonio Quartulli | 925a6f3 | 2016-03-12 10:30:18 +0100 | [diff] [blame] | 186 | seq_puts(seq, |
| 187 | " Neighbor last-seen ( throughput) [ IF]\n"); |
Linus Luessing | 626d23e | 2016-01-16 16:40:19 +0800 | [diff] [blame] | 188 | |
| 189 | rcu_read_lock(); |
| 190 | list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) { |
| 191 | if (hard_iface->soft_iface != net_dev) |
| 192 | continue; |
| 193 | |
| 194 | hlist_for_each_entry_rcu(hardif_neigh, |
| 195 | &hard_iface->neigh_list, list) { |
| 196 | batadv_v_hardif_neigh_print(seq, hardif_neigh); |
| 197 | batman_count++; |
| 198 | } |
| 199 | } |
| 200 | rcu_read_unlock(); |
| 201 | |
| 202 | if (batman_count == 0) |
| 203 | seq_puts(seq, "No batman nodes in range ...\n"); |
| 204 | } |
| 205 | |
| 206 | /** |
Antonio Quartulli | 261e264 | 2016-01-16 16:40:18 +0800 | [diff] [blame] | 207 | * batadv_v_orig_print - print the originator table |
| 208 | * @bat_priv: the bat priv with all the soft interface information |
| 209 | * @seq: debugfs table seq_file struct |
| 210 | * @if_outgoing: the outgoing interface for which this should be printed |
| 211 | */ |
| 212 | static void batadv_v_orig_print(struct batadv_priv *bat_priv, |
| 213 | struct seq_file *seq, |
| 214 | struct batadv_hard_iface *if_outgoing) |
| 215 | { |
| 216 | struct batadv_neigh_node *neigh_node; |
| 217 | struct batadv_hashtable *hash = bat_priv->orig_hash; |
| 218 | int last_seen_msecs, last_seen_secs; |
| 219 | struct batadv_orig_node *orig_node; |
| 220 | struct batadv_neigh_ifinfo *n_ifinfo; |
| 221 | unsigned long last_seen_jiffies; |
| 222 | struct hlist_head *head; |
| 223 | int batman_count = 0; |
| 224 | u32 i; |
| 225 | |
Antonio Quartulli | 925a6f3 | 2016-03-12 10:30:18 +0100 | [diff] [blame] | 226 | seq_puts(seq, |
| 227 | " Originator last-seen ( throughput) Nexthop [outgoingIF]: Potential nexthops ...\n"); |
Antonio Quartulli | 261e264 | 2016-01-16 16:40:18 +0800 | [diff] [blame] | 228 | |
| 229 | for (i = 0; i < hash->size; i++) { |
| 230 | head = &hash->table[i]; |
| 231 | |
| 232 | rcu_read_lock(); |
| 233 | hlist_for_each_entry_rcu(orig_node, head, hash_entry) { |
| 234 | neigh_node = batadv_orig_router_get(orig_node, |
| 235 | if_outgoing); |
| 236 | if (!neigh_node) |
| 237 | continue; |
| 238 | |
| 239 | n_ifinfo = batadv_neigh_ifinfo_get(neigh_node, |
| 240 | if_outgoing); |
| 241 | if (!n_ifinfo) |
| 242 | goto next; |
| 243 | |
| 244 | last_seen_jiffies = jiffies - orig_node->last_seen; |
| 245 | last_seen_msecs = jiffies_to_msecs(last_seen_jiffies); |
| 246 | last_seen_secs = last_seen_msecs / 1000; |
| 247 | last_seen_msecs = last_seen_msecs % 1000; |
| 248 | |
| 249 | seq_printf(seq, "%pM %4i.%03is (%9u.%1u) %pM [%10s]:", |
| 250 | orig_node->orig, last_seen_secs, |
| 251 | last_seen_msecs, |
| 252 | n_ifinfo->bat_v.throughput / 10, |
| 253 | n_ifinfo->bat_v.throughput % 10, |
| 254 | neigh_node->addr, |
| 255 | neigh_node->if_incoming->net_dev->name); |
| 256 | |
| 257 | batadv_v_orig_print_neigh(orig_node, if_outgoing, seq); |
| 258 | seq_puts(seq, "\n"); |
| 259 | batman_count++; |
| 260 | |
| 261 | next: |
| 262 | batadv_neigh_node_put(neigh_node); |
| 263 | if (n_ifinfo) |
| 264 | batadv_neigh_ifinfo_put(n_ifinfo); |
| 265 | } |
| 266 | rcu_read_unlock(); |
| 267 | } |
| 268 | |
| 269 | if (batman_count == 0) |
| 270 | seq_puts(seq, "No batman nodes in range ...\n"); |
| 271 | } |
| 272 | |
Antonio Quartulli | 9786906 | 2016-01-16 16:40:17 +0800 | [diff] [blame] | 273 | static int batadv_v_neigh_cmp(struct batadv_neigh_node *neigh1, |
| 274 | struct batadv_hard_iface *if_outgoing1, |
| 275 | struct batadv_neigh_node *neigh2, |
| 276 | struct batadv_hard_iface *if_outgoing2) |
| 277 | { |
| 278 | struct batadv_neigh_ifinfo *ifinfo1, *ifinfo2; |
Sven Eckelmann | 71f9d27 | 2016-05-06 11:43:39 +0200 | [diff] [blame] | 279 | int ret = 0; |
Antonio Quartulli | 9786906 | 2016-01-16 16:40:17 +0800 | [diff] [blame] | 280 | |
| 281 | ifinfo1 = batadv_neigh_ifinfo_get(neigh1, if_outgoing1); |
Sven Eckelmann | 71f9d27 | 2016-05-06 11:43:39 +0200 | [diff] [blame] | 282 | if (WARN_ON(!ifinfo1)) |
| 283 | goto err_ifinfo1; |
| 284 | |
Antonio Quartulli | 9786906 | 2016-01-16 16:40:17 +0800 | [diff] [blame] | 285 | ifinfo2 = batadv_neigh_ifinfo_get(neigh2, if_outgoing2); |
Sven Eckelmann | 71f9d27 | 2016-05-06 11:43:39 +0200 | [diff] [blame] | 286 | if (WARN_ON(!ifinfo2)) |
| 287 | goto err_ifinfo2; |
Antonio Quartulli | 9786906 | 2016-01-16 16:40:17 +0800 | [diff] [blame] | 288 | |
Sven Eckelmann | 71f9d27 | 2016-05-06 11:43:39 +0200 | [diff] [blame] | 289 | ret = ifinfo1->bat_v.throughput - ifinfo2->bat_v.throughput; |
Antonio Quartulli | 9786906 | 2016-01-16 16:40:17 +0800 | [diff] [blame] | 290 | |
Sven Eckelmann | 71f9d27 | 2016-05-06 11:43:39 +0200 | [diff] [blame] | 291 | batadv_neigh_ifinfo_put(ifinfo2); |
| 292 | err_ifinfo2: |
| 293 | batadv_neigh_ifinfo_put(ifinfo1); |
| 294 | err_ifinfo1: |
| 295 | return ret; |
Antonio Quartulli | 9786906 | 2016-01-16 16:40:17 +0800 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | static bool batadv_v_neigh_is_sob(struct batadv_neigh_node *neigh1, |
| 299 | struct batadv_hard_iface *if_outgoing1, |
| 300 | struct batadv_neigh_node *neigh2, |
| 301 | struct batadv_hard_iface *if_outgoing2) |
| 302 | { |
| 303 | struct batadv_neigh_ifinfo *ifinfo1, *ifinfo2; |
| 304 | u32 threshold; |
Sven Eckelmann | 71f9d27 | 2016-05-06 11:43:39 +0200 | [diff] [blame] | 305 | bool ret = false; |
Antonio Quartulli | 9786906 | 2016-01-16 16:40:17 +0800 | [diff] [blame] | 306 | |
| 307 | ifinfo1 = batadv_neigh_ifinfo_get(neigh1, if_outgoing1); |
Sven Eckelmann | 71f9d27 | 2016-05-06 11:43:39 +0200 | [diff] [blame] | 308 | if (WARN_ON(!ifinfo1)) |
| 309 | goto err_ifinfo1; |
Antonio Quartulli | 9786906 | 2016-01-16 16:40:17 +0800 | [diff] [blame] | 310 | |
Sven Eckelmann | 71f9d27 | 2016-05-06 11:43:39 +0200 | [diff] [blame] | 311 | ifinfo2 = batadv_neigh_ifinfo_get(neigh2, if_outgoing2); |
| 312 | if (WARN_ON(!ifinfo2)) |
| 313 | goto err_ifinfo2; |
Sven Eckelmann | a45e932 | 2016-05-06 11:43:38 +0200 | [diff] [blame] | 314 | |
Antonio Quartulli | 9786906 | 2016-01-16 16:40:17 +0800 | [diff] [blame] | 315 | threshold = ifinfo1->bat_v.throughput / 4; |
| 316 | threshold = ifinfo1->bat_v.throughput - threshold; |
| 317 | |
Sven Eckelmann | 71f9d27 | 2016-05-06 11:43:39 +0200 | [diff] [blame] | 318 | ret = ifinfo2->bat_v.throughput > threshold; |
| 319 | |
| 320 | batadv_neigh_ifinfo_put(ifinfo2); |
| 321 | err_ifinfo2: |
| 322 | batadv_neigh_ifinfo_put(ifinfo1); |
| 323 | err_ifinfo1: |
| 324 | return ret; |
Antonio Quartulli | 9786906 | 2016-01-16 16:40:17 +0800 | [diff] [blame] | 325 | } |
| 326 | |
Antonio Quartulli | 0868694 | 2016-07-03 12:46:32 +0200 | [diff] [blame] | 327 | static ssize_t batadv_v_store_sel_class(struct batadv_priv *bat_priv, |
| 328 | char *buff, size_t count) |
| 329 | { |
| 330 | u32 old_class, class; |
| 331 | |
| 332 | if (!batadv_parse_throughput(bat_priv->soft_iface, buff, |
| 333 | "B.A.T.M.A.N. V GW selection class", |
| 334 | &class)) |
| 335 | return -EINVAL; |
| 336 | |
| 337 | old_class = atomic_read(&bat_priv->gw.sel_class); |
| 338 | atomic_set(&bat_priv->gw.sel_class, class); |
| 339 | |
| 340 | if (old_class != class) |
| 341 | batadv_gw_reselect(bat_priv); |
| 342 | |
| 343 | return count; |
| 344 | } |
| 345 | |
| 346 | static ssize_t batadv_v_show_sel_class(struct batadv_priv *bat_priv, char *buff) |
| 347 | { |
| 348 | u32 class = atomic_read(&bat_priv->gw.sel_class); |
| 349 | |
| 350 | return sprintf(buff, "%u.%u MBit\n", class / 10, class % 10); |
| 351 | } |
| 352 | |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 353 | static struct batadv_algo_ops batadv_batman_v __read_mostly = { |
| 354 | .name = "BATMAN_V", |
Antonio Quartulli | 29824a5 | 2016-05-25 23:27:31 +0800 | [diff] [blame] | 355 | .iface = { |
| 356 | .activate = batadv_v_iface_activate, |
| 357 | .enable = batadv_v_iface_enable, |
| 358 | .disable = batadv_v_iface_disable, |
| 359 | .update_mac = batadv_v_iface_update_mac, |
| 360 | .primary_set = batadv_v_primary_iface_set, |
| 361 | }, |
| 362 | .neigh = { |
| 363 | .hardif_init = batadv_v_hardif_neigh_init, |
| 364 | .cmp = batadv_v_neigh_cmp, |
| 365 | .is_similar_or_better = batadv_v_neigh_is_sob, |
| 366 | .print = batadv_v_neigh_print, |
| 367 | }, |
| 368 | .orig = { |
| 369 | .print = batadv_v_orig_print, |
| 370 | }, |
Antonio Quartulli | 0868694 | 2016-07-03 12:46:32 +0200 | [diff] [blame] | 371 | .gw = { |
| 372 | .store_sel_class = batadv_v_store_sel_class, |
| 373 | .show_sel_class = batadv_v_show_sel_class, |
| 374 | }, |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 375 | }; |
| 376 | |
| 377 | /** |
Marek Lindner | 7db682d | 2016-05-10 22:31:59 +0800 | [diff] [blame] | 378 | * batadv_v_hardif_init - initialize the algorithm specific fields in the |
| 379 | * hard-interface object |
| 380 | * @hard_iface: the hard-interface to initialize |
| 381 | */ |
| 382 | void batadv_v_hardif_init(struct batadv_hard_iface *hard_iface) |
| 383 | { |
| 384 | /* enable link throughput auto-detection by setting the throughput |
| 385 | * override to zero |
| 386 | */ |
| 387 | atomic_set(&hard_iface->bat_v.throughput_override, 0); |
| 388 | atomic_set(&hard_iface->bat_v.elp_interval, 500); |
| 389 | } |
| 390 | |
| 391 | /** |
Antonio Quartulli | 0da0035 | 2016-01-16 16:40:12 +0800 | [diff] [blame] | 392 | * batadv_v_mesh_init - initialize the B.A.T.M.A.N. V private resources for a |
| 393 | * mesh |
| 394 | * @bat_priv: the object representing the mesh interface to initialise |
| 395 | * |
| 396 | * Return: 0 on success or a negative error code otherwise |
| 397 | */ |
| 398 | int batadv_v_mesh_init(struct batadv_priv *bat_priv) |
| 399 | { |
| 400 | return batadv_v_ogm_init(bat_priv); |
| 401 | } |
| 402 | |
| 403 | /** |
| 404 | * batadv_v_mesh_free - free the B.A.T.M.A.N. V private resources for a mesh |
| 405 | * @bat_priv: the object representing the mesh interface to free |
| 406 | */ |
| 407 | void batadv_v_mesh_free(struct batadv_priv *bat_priv) |
| 408 | { |
| 409 | batadv_v_ogm_free(bat_priv); |
| 410 | } |
| 411 | |
| 412 | /** |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 413 | * batadv_v_init - B.A.T.M.A.N. V initialization function |
| 414 | * |
| 415 | * Description: Takes care of initializing all the subcomponents. |
| 416 | * It is invoked upon module load only. |
| 417 | * |
| 418 | * Return: 0 on success or a negative error code otherwise |
| 419 | */ |
| 420 | int __init batadv_v_init(void) |
| 421 | { |
Linus Luessing | 162bd64 | 2016-01-16 16:40:10 +0800 | [diff] [blame] | 422 | int ret; |
| 423 | |
| 424 | /* B.A.T.M.A.N. V echo location protocol packet */ |
| 425 | ret = batadv_recv_handler_register(BATADV_ELP, |
| 426 | batadv_v_elp_packet_recv); |
| 427 | if (ret < 0) |
| 428 | return ret; |
| 429 | |
Antonio Quartulli | 0da0035 | 2016-01-16 16:40:12 +0800 | [diff] [blame] | 430 | ret = batadv_recv_handler_register(BATADV_OGM2, |
| 431 | batadv_v_ogm_packet_recv); |
Linus Luessing | 162bd64 | 2016-01-16 16:40:10 +0800 | [diff] [blame] | 432 | if (ret < 0) |
Antonio Quartulli | 0da0035 | 2016-01-16 16:40:12 +0800 | [diff] [blame] | 433 | goto elp_unregister; |
| 434 | |
| 435 | ret = batadv_algo_register(&batadv_batman_v); |
| 436 | if (ret < 0) |
| 437 | goto ogm_unregister; |
| 438 | |
| 439 | return ret; |
| 440 | |
| 441 | ogm_unregister: |
| 442 | batadv_recv_handler_unregister(BATADV_OGM2); |
| 443 | |
| 444 | elp_unregister: |
| 445 | batadv_recv_handler_unregister(BATADV_ELP); |
Linus Luessing | 162bd64 | 2016-01-16 16:40:10 +0800 | [diff] [blame] | 446 | |
| 447 | return ret; |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 448 | } |