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 | |
| 18 | #include "bat_algo.h" |
| 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> |
| 24 | #include <linux/init.h> |
Antonio Quartulli | 261e264 | 2016-01-16 16:40:18 +0800 | [diff] [blame] | 25 | #include <linux/jiffies.h> |
| 26 | #include <linux/netdevice.h> |
| 27 | #include <linux/rculist.h> |
| 28 | #include <linux/rcupdate.h> |
| 29 | #include <linux/seq_file.h> |
Sven Eckelmann | a45e932 | 2016-05-06 11:43:38 +0200 | [diff] [blame] | 30 | #include <linux/stddef.h> |
Antonio Quartulli | 9786906 | 2016-01-16 16:40:17 +0800 | [diff] [blame] | 31 | #include <linux/types.h> |
Antonio Quartulli | c833484 | 2015-11-10 18:50:51 +0100 | [diff] [blame] | 32 | #include <linux/workqueue.h> |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 33 | |
| 34 | #include "bat_v_elp.h" |
Antonio Quartulli | 0da0035 | 2016-01-16 16:40:12 +0800 | [diff] [blame] | 35 | #include "bat_v_ogm.h" |
Antonio Quartulli | b6cf5d4 | 2016-04-14 09:37:05 +0800 | [diff] [blame] | 36 | #include "hard-interface.h" |
Antonio Quartulli | 261e264 | 2016-01-16 16:40:18 +0800 | [diff] [blame] | 37 | #include "hash.h" |
Antonio Quartulli | 9786906 | 2016-01-16 16:40:17 +0800 | [diff] [blame] | 38 | #include "originator.h" |
Linus Luessing | 162bd64 | 2016-01-16 16:40:10 +0800 | [diff] [blame] | 39 | #include "packet.h" |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 40 | |
Antonio Quartulli | b6cf5d4 | 2016-04-14 09:37:05 +0800 | [diff] [blame] | 41 | static void batadv_v_iface_activate(struct batadv_hard_iface *hard_iface) |
| 42 | { |
| 43 | /* B.A.T.M.A.N. V does not use any queuing mechanism, therefore it can |
| 44 | * set the interface as ACTIVE right away, without any risk of race |
| 45 | * condition |
| 46 | */ |
| 47 | if (hard_iface->if_status == BATADV_IF_TO_BE_ACTIVATED) |
| 48 | hard_iface->if_status = BATADV_IF_ACTIVE; |
| 49 | } |
| 50 | |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 51 | static int batadv_v_iface_enable(struct batadv_hard_iface *hard_iface) |
| 52 | { |
Antonio Quartulli | 0da0035 | 2016-01-16 16:40:12 +0800 | [diff] [blame] | 53 | int ret; |
| 54 | |
| 55 | ret = batadv_v_elp_iface_enable(hard_iface); |
| 56 | if (ret < 0) |
| 57 | return ret; |
| 58 | |
| 59 | ret = batadv_v_ogm_iface_enable(hard_iface); |
| 60 | if (ret < 0) |
| 61 | batadv_v_elp_iface_disable(hard_iface); |
| 62 | |
Antonio Quartulli | 0b5ecc6 | 2016-01-16 16:40:14 +0800 | [diff] [blame] | 63 | /* enable link throughput auto-detection by setting the throughput |
| 64 | * override to zero |
| 65 | */ |
| 66 | atomic_set(&hard_iface->bat_v.throughput_override, 0); |
| 67 | |
Antonio Quartulli | 0da0035 | 2016-01-16 16:40:12 +0800 | [diff] [blame] | 68 | return ret; |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static void batadv_v_iface_disable(struct batadv_hard_iface *hard_iface) |
| 72 | { |
| 73 | batadv_v_elp_iface_disable(hard_iface); |
| 74 | } |
| 75 | |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 76 | static void batadv_v_primary_iface_set(struct batadv_hard_iface *hard_iface) |
| 77 | { |
| 78 | batadv_v_elp_primary_iface_set(hard_iface); |
Antonio Quartulli | 0da0035 | 2016-01-16 16:40:12 +0800 | [diff] [blame] | 79 | batadv_v_ogm_primary_iface_set(hard_iface); |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 80 | } |
| 81 | |
Antonio Quartulli | 1653f61 | 2016-05-02 01:14:40 +0800 | [diff] [blame^] | 82 | /** |
| 83 | * batadv_v_iface_update_mac - react to hard-interface MAC address change |
| 84 | * @hard_iface: the modified interface |
| 85 | * |
| 86 | * If the modified interface is the primary one, update the originator |
| 87 | * address in the ELP and OGM messages to reflect the new MAC address. |
| 88 | */ |
| 89 | static void batadv_v_iface_update_mac(struct batadv_hard_iface *hard_iface) |
| 90 | { |
| 91 | struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); |
| 92 | struct batadv_hard_iface *primary_if; |
| 93 | |
| 94 | primary_if = batadv_primary_if_get_selected(bat_priv); |
| 95 | if (primary_if != hard_iface) |
| 96 | goto out; |
| 97 | |
| 98 | batadv_v_primary_iface_set(hard_iface); |
| 99 | out: |
| 100 | if (primary_if) |
| 101 | batadv_hardif_put(primary_if); |
| 102 | } |
| 103 | |
Linus Luessing | 162bd64 | 2016-01-16 16:40:10 +0800 | [diff] [blame] | 104 | static void |
| 105 | batadv_v_hardif_neigh_init(struct batadv_hardif_neigh_node *hardif_neigh) |
| 106 | { |
| 107 | ewma_throughput_init(&hardif_neigh->bat_v.throughput); |
Antonio Quartulli | c833484 | 2015-11-10 18:50:51 +0100 | [diff] [blame] | 108 | INIT_WORK(&hardif_neigh->bat_v.metric_work, |
| 109 | batadv_v_elp_throughput_metric_update); |
Linus Luessing | 162bd64 | 2016-01-16 16:40:10 +0800 | [diff] [blame] | 110 | } |
| 111 | |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 112 | static void batadv_v_ogm_schedule(struct batadv_hard_iface *hard_iface) |
| 113 | { |
| 114 | } |
| 115 | |
| 116 | static void batadv_v_ogm_emit(struct batadv_forw_packet *forw_packet) |
| 117 | { |
| 118 | } |
| 119 | |
Antonio Quartulli | 261e264 | 2016-01-16 16:40:18 +0800 | [diff] [blame] | 120 | /** |
| 121 | * batadv_v_orig_print_neigh - print neighbors for the originator table |
| 122 | * @orig_node: the orig_node for which the neighbors are printed |
| 123 | * @if_outgoing: outgoing interface for these entries |
| 124 | * @seq: debugfs table seq_file struct |
| 125 | * |
| 126 | * Must be called while holding an rcu lock. |
| 127 | */ |
| 128 | static void |
| 129 | batadv_v_orig_print_neigh(struct batadv_orig_node *orig_node, |
| 130 | struct batadv_hard_iface *if_outgoing, |
| 131 | struct seq_file *seq) |
| 132 | { |
| 133 | struct batadv_neigh_node *neigh_node; |
| 134 | struct batadv_neigh_ifinfo *n_ifinfo; |
| 135 | |
| 136 | hlist_for_each_entry_rcu(neigh_node, &orig_node->neigh_list, list) { |
| 137 | n_ifinfo = batadv_neigh_ifinfo_get(neigh_node, if_outgoing); |
| 138 | if (!n_ifinfo) |
| 139 | continue; |
| 140 | |
| 141 | seq_printf(seq, " %pM (%9u.%1u)", |
| 142 | neigh_node->addr, |
| 143 | n_ifinfo->bat_v.throughput / 10, |
| 144 | n_ifinfo->bat_v.throughput % 10); |
| 145 | |
| 146 | batadv_neigh_ifinfo_put(n_ifinfo); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | /** |
Linus Luessing | 626d23e | 2016-01-16 16:40:19 +0800 | [diff] [blame] | 151 | * batadv_v_hardif_neigh_print - print a single ELP neighbour node |
| 152 | * @seq: neighbour table seq_file struct |
| 153 | * @hardif_neigh: hardif neighbour information |
| 154 | */ |
| 155 | static void |
| 156 | batadv_v_hardif_neigh_print(struct seq_file *seq, |
| 157 | struct batadv_hardif_neigh_node *hardif_neigh) |
| 158 | { |
| 159 | int last_secs, last_msecs; |
| 160 | u32 throughput; |
| 161 | |
| 162 | last_secs = jiffies_to_msecs(jiffies - hardif_neigh->last_seen) / 1000; |
| 163 | last_msecs = jiffies_to_msecs(jiffies - hardif_neigh->last_seen) % 1000; |
| 164 | throughput = ewma_throughput_read(&hardif_neigh->bat_v.throughput); |
| 165 | |
| 166 | seq_printf(seq, "%pM %4i.%03is (%9u.%1u) [%10s]\n", |
| 167 | hardif_neigh->addr, last_secs, last_msecs, throughput / 10, |
| 168 | throughput % 10, hardif_neigh->if_incoming->net_dev->name); |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * batadv_v_neigh_print - print the single hop neighbour list |
| 173 | * @bat_priv: the bat priv with all the soft interface information |
| 174 | * @seq: neighbour table seq_file struct |
| 175 | */ |
| 176 | static void batadv_v_neigh_print(struct batadv_priv *bat_priv, |
| 177 | struct seq_file *seq) |
| 178 | { |
| 179 | struct net_device *net_dev = (struct net_device *)seq->private; |
| 180 | struct batadv_hardif_neigh_node *hardif_neigh; |
| 181 | struct batadv_hard_iface *hard_iface; |
| 182 | int batman_count = 0; |
| 183 | |
Antonio Quartulli | 925a6f3 | 2016-03-12 10:30:18 +0100 | [diff] [blame] | 184 | seq_puts(seq, |
| 185 | " Neighbor last-seen ( throughput) [ IF]\n"); |
Linus Luessing | 626d23e | 2016-01-16 16:40:19 +0800 | [diff] [blame] | 186 | |
| 187 | rcu_read_lock(); |
| 188 | list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) { |
| 189 | if (hard_iface->soft_iface != net_dev) |
| 190 | continue; |
| 191 | |
| 192 | hlist_for_each_entry_rcu(hardif_neigh, |
| 193 | &hard_iface->neigh_list, list) { |
| 194 | batadv_v_hardif_neigh_print(seq, hardif_neigh); |
| 195 | batman_count++; |
| 196 | } |
| 197 | } |
| 198 | rcu_read_unlock(); |
| 199 | |
| 200 | if (batman_count == 0) |
| 201 | seq_puts(seq, "No batman nodes in range ...\n"); |
| 202 | } |
| 203 | |
| 204 | /** |
Antonio Quartulli | 261e264 | 2016-01-16 16:40:18 +0800 | [diff] [blame] | 205 | * batadv_v_orig_print - print the originator table |
| 206 | * @bat_priv: the bat priv with all the soft interface information |
| 207 | * @seq: debugfs table seq_file struct |
| 208 | * @if_outgoing: the outgoing interface for which this should be printed |
| 209 | */ |
| 210 | static void batadv_v_orig_print(struct batadv_priv *bat_priv, |
| 211 | struct seq_file *seq, |
| 212 | struct batadv_hard_iface *if_outgoing) |
| 213 | { |
| 214 | struct batadv_neigh_node *neigh_node; |
| 215 | struct batadv_hashtable *hash = bat_priv->orig_hash; |
| 216 | int last_seen_msecs, last_seen_secs; |
| 217 | struct batadv_orig_node *orig_node; |
| 218 | struct batadv_neigh_ifinfo *n_ifinfo; |
| 219 | unsigned long last_seen_jiffies; |
| 220 | struct hlist_head *head; |
| 221 | int batman_count = 0; |
| 222 | u32 i; |
| 223 | |
Antonio Quartulli | 925a6f3 | 2016-03-12 10:30:18 +0100 | [diff] [blame] | 224 | seq_puts(seq, |
| 225 | " Originator last-seen ( throughput) Nexthop [outgoingIF]: Potential nexthops ...\n"); |
Antonio Quartulli | 261e264 | 2016-01-16 16:40:18 +0800 | [diff] [blame] | 226 | |
| 227 | for (i = 0; i < hash->size; i++) { |
| 228 | head = &hash->table[i]; |
| 229 | |
| 230 | rcu_read_lock(); |
| 231 | hlist_for_each_entry_rcu(orig_node, head, hash_entry) { |
| 232 | neigh_node = batadv_orig_router_get(orig_node, |
| 233 | if_outgoing); |
| 234 | if (!neigh_node) |
| 235 | continue; |
| 236 | |
| 237 | n_ifinfo = batadv_neigh_ifinfo_get(neigh_node, |
| 238 | if_outgoing); |
| 239 | if (!n_ifinfo) |
| 240 | goto next; |
| 241 | |
| 242 | last_seen_jiffies = jiffies - orig_node->last_seen; |
| 243 | last_seen_msecs = jiffies_to_msecs(last_seen_jiffies); |
| 244 | last_seen_secs = last_seen_msecs / 1000; |
| 245 | last_seen_msecs = last_seen_msecs % 1000; |
| 246 | |
| 247 | seq_printf(seq, "%pM %4i.%03is (%9u.%1u) %pM [%10s]:", |
| 248 | orig_node->orig, last_seen_secs, |
| 249 | last_seen_msecs, |
| 250 | n_ifinfo->bat_v.throughput / 10, |
| 251 | n_ifinfo->bat_v.throughput % 10, |
| 252 | neigh_node->addr, |
| 253 | neigh_node->if_incoming->net_dev->name); |
| 254 | |
| 255 | batadv_v_orig_print_neigh(orig_node, if_outgoing, seq); |
| 256 | seq_puts(seq, "\n"); |
| 257 | batman_count++; |
| 258 | |
| 259 | next: |
| 260 | batadv_neigh_node_put(neigh_node); |
| 261 | if (n_ifinfo) |
| 262 | batadv_neigh_ifinfo_put(n_ifinfo); |
| 263 | } |
| 264 | rcu_read_unlock(); |
| 265 | } |
| 266 | |
| 267 | if (batman_count == 0) |
| 268 | seq_puts(seq, "No batman nodes in range ...\n"); |
| 269 | } |
| 270 | |
Antonio Quartulli | 9786906 | 2016-01-16 16:40:17 +0800 | [diff] [blame] | 271 | static int batadv_v_neigh_cmp(struct batadv_neigh_node *neigh1, |
| 272 | struct batadv_hard_iface *if_outgoing1, |
| 273 | struct batadv_neigh_node *neigh2, |
| 274 | struct batadv_hard_iface *if_outgoing2) |
| 275 | { |
| 276 | struct batadv_neigh_ifinfo *ifinfo1, *ifinfo2; |
Sven Eckelmann | 71f9d27 | 2016-05-06 11:43:39 +0200 | [diff] [blame] | 277 | int ret = 0; |
Antonio Quartulli | 9786906 | 2016-01-16 16:40:17 +0800 | [diff] [blame] | 278 | |
| 279 | ifinfo1 = batadv_neigh_ifinfo_get(neigh1, if_outgoing1); |
Sven Eckelmann | 71f9d27 | 2016-05-06 11:43:39 +0200 | [diff] [blame] | 280 | if (WARN_ON(!ifinfo1)) |
| 281 | goto err_ifinfo1; |
| 282 | |
Antonio Quartulli | 9786906 | 2016-01-16 16:40:17 +0800 | [diff] [blame] | 283 | ifinfo2 = batadv_neigh_ifinfo_get(neigh2, if_outgoing2); |
Sven Eckelmann | 71f9d27 | 2016-05-06 11:43:39 +0200 | [diff] [blame] | 284 | if (WARN_ON(!ifinfo2)) |
| 285 | goto err_ifinfo2; |
Antonio Quartulli | 9786906 | 2016-01-16 16:40:17 +0800 | [diff] [blame] | 286 | |
Sven Eckelmann | 71f9d27 | 2016-05-06 11:43:39 +0200 | [diff] [blame] | 287 | ret = ifinfo1->bat_v.throughput - ifinfo2->bat_v.throughput; |
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 | batadv_neigh_ifinfo_put(ifinfo2); |
| 290 | err_ifinfo2: |
| 291 | batadv_neigh_ifinfo_put(ifinfo1); |
| 292 | err_ifinfo1: |
| 293 | return ret; |
Antonio Quartulli | 9786906 | 2016-01-16 16:40:17 +0800 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | static bool batadv_v_neigh_is_sob(struct batadv_neigh_node *neigh1, |
| 297 | struct batadv_hard_iface *if_outgoing1, |
| 298 | struct batadv_neigh_node *neigh2, |
| 299 | struct batadv_hard_iface *if_outgoing2) |
| 300 | { |
| 301 | struct batadv_neigh_ifinfo *ifinfo1, *ifinfo2; |
| 302 | u32 threshold; |
Sven Eckelmann | 71f9d27 | 2016-05-06 11:43:39 +0200 | [diff] [blame] | 303 | bool ret = false; |
Antonio Quartulli | 9786906 | 2016-01-16 16:40:17 +0800 | [diff] [blame] | 304 | |
| 305 | ifinfo1 = batadv_neigh_ifinfo_get(neigh1, if_outgoing1); |
Sven Eckelmann | 71f9d27 | 2016-05-06 11:43:39 +0200 | [diff] [blame] | 306 | if (WARN_ON(!ifinfo1)) |
| 307 | goto err_ifinfo1; |
Antonio Quartulli | 9786906 | 2016-01-16 16:40:17 +0800 | [diff] [blame] | 308 | |
Sven Eckelmann | 71f9d27 | 2016-05-06 11:43:39 +0200 | [diff] [blame] | 309 | ifinfo2 = batadv_neigh_ifinfo_get(neigh2, if_outgoing2); |
| 310 | if (WARN_ON(!ifinfo2)) |
| 311 | goto err_ifinfo2; |
Sven Eckelmann | a45e932 | 2016-05-06 11:43:38 +0200 | [diff] [blame] | 312 | |
Antonio Quartulli | 9786906 | 2016-01-16 16:40:17 +0800 | [diff] [blame] | 313 | threshold = ifinfo1->bat_v.throughput / 4; |
| 314 | threshold = ifinfo1->bat_v.throughput - threshold; |
| 315 | |
Sven Eckelmann | 71f9d27 | 2016-05-06 11:43:39 +0200 | [diff] [blame] | 316 | ret = ifinfo2->bat_v.throughput > threshold; |
| 317 | |
| 318 | batadv_neigh_ifinfo_put(ifinfo2); |
| 319 | err_ifinfo2: |
| 320 | batadv_neigh_ifinfo_put(ifinfo1); |
| 321 | err_ifinfo1: |
| 322 | return ret; |
Antonio Quartulli | 9786906 | 2016-01-16 16:40:17 +0800 | [diff] [blame] | 323 | } |
| 324 | |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 325 | static struct batadv_algo_ops batadv_batman_v __read_mostly = { |
| 326 | .name = "BATMAN_V", |
Antonio Quartulli | b6cf5d4 | 2016-04-14 09:37:05 +0800 | [diff] [blame] | 327 | .bat_iface_activate = batadv_v_iface_activate, |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 328 | .bat_iface_enable = batadv_v_iface_enable, |
| 329 | .bat_iface_disable = batadv_v_iface_disable, |
| 330 | .bat_iface_update_mac = batadv_v_iface_update_mac, |
| 331 | .bat_primary_iface_set = batadv_v_primary_iface_set, |
Linus Luessing | 162bd64 | 2016-01-16 16:40:10 +0800 | [diff] [blame] | 332 | .bat_hardif_neigh_init = batadv_v_hardif_neigh_init, |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 333 | .bat_ogm_emit = batadv_v_ogm_emit, |
| 334 | .bat_ogm_schedule = batadv_v_ogm_schedule, |
Antonio Quartulli | 261e264 | 2016-01-16 16:40:18 +0800 | [diff] [blame] | 335 | .bat_orig_print = batadv_v_orig_print, |
Antonio Quartulli | 9786906 | 2016-01-16 16:40:17 +0800 | [diff] [blame] | 336 | .bat_neigh_cmp = batadv_v_neigh_cmp, |
| 337 | .bat_neigh_is_similar_or_better = batadv_v_neigh_is_sob, |
Linus Luessing | 626d23e | 2016-01-16 16:40:19 +0800 | [diff] [blame] | 338 | .bat_neigh_print = batadv_v_neigh_print, |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 339 | }; |
| 340 | |
| 341 | /** |
Antonio Quartulli | 0da0035 | 2016-01-16 16:40:12 +0800 | [diff] [blame] | 342 | * batadv_v_mesh_init - initialize the B.A.T.M.A.N. V private resources for a |
| 343 | * mesh |
| 344 | * @bat_priv: the object representing the mesh interface to initialise |
| 345 | * |
| 346 | * Return: 0 on success or a negative error code otherwise |
| 347 | */ |
| 348 | int batadv_v_mesh_init(struct batadv_priv *bat_priv) |
| 349 | { |
| 350 | return batadv_v_ogm_init(bat_priv); |
| 351 | } |
| 352 | |
| 353 | /** |
| 354 | * batadv_v_mesh_free - free the B.A.T.M.A.N. V private resources for a mesh |
| 355 | * @bat_priv: the object representing the mesh interface to free |
| 356 | */ |
| 357 | void batadv_v_mesh_free(struct batadv_priv *bat_priv) |
| 358 | { |
| 359 | batadv_v_ogm_free(bat_priv); |
| 360 | } |
| 361 | |
| 362 | /** |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 363 | * batadv_v_init - B.A.T.M.A.N. V initialization function |
| 364 | * |
| 365 | * Description: Takes care of initializing all the subcomponents. |
| 366 | * It is invoked upon module load only. |
| 367 | * |
| 368 | * Return: 0 on success or a negative error code otherwise |
| 369 | */ |
| 370 | int __init batadv_v_init(void) |
| 371 | { |
Linus Luessing | 162bd64 | 2016-01-16 16:40:10 +0800 | [diff] [blame] | 372 | int ret; |
| 373 | |
| 374 | /* B.A.T.M.A.N. V echo location protocol packet */ |
| 375 | ret = batadv_recv_handler_register(BATADV_ELP, |
| 376 | batadv_v_elp_packet_recv); |
| 377 | if (ret < 0) |
| 378 | return ret; |
| 379 | |
Antonio Quartulli | 0da0035 | 2016-01-16 16:40:12 +0800 | [diff] [blame] | 380 | ret = batadv_recv_handler_register(BATADV_OGM2, |
| 381 | batadv_v_ogm_packet_recv); |
Linus Luessing | 162bd64 | 2016-01-16 16:40:10 +0800 | [diff] [blame] | 382 | if (ret < 0) |
Antonio Quartulli | 0da0035 | 2016-01-16 16:40:12 +0800 | [diff] [blame] | 383 | goto elp_unregister; |
| 384 | |
| 385 | ret = batadv_algo_register(&batadv_batman_v); |
| 386 | if (ret < 0) |
| 387 | goto ogm_unregister; |
| 388 | |
| 389 | return ret; |
| 390 | |
| 391 | ogm_unregister: |
| 392 | batadv_recv_handler_unregister(BATADV_OGM2); |
| 393 | |
| 394 | elp_unregister: |
| 395 | batadv_recv_handler_unregister(BATADV_ELP); |
Linus Luessing | 162bd64 | 2016-01-16 16:40:10 +0800 | [diff] [blame] | 396 | |
| 397 | return ret; |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 398 | } |