aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv/main.c
diff options
context:
space:
mode:
authorMarek Lindner <lindner_marek@yahoo.de>2011-11-28 04:40:17 -0500
committerMarek Lindner <lindner_marek@yahoo.de>2012-02-16 13:50:20 -0500
commit1c280471b013e26c833fc86acc231c73442cfa21 (patch)
treeff48395664f514b1c8f2f14e78c5b3c4da653702 /net/batman-adv/main.c
parent6e242f9037f8a82ce2608c20a5460b670b2d5ff4 (diff)
batman-adv: add infrastructure to change routing algorithm at runtime
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
Diffstat (limited to 'net/batman-adv/main.c')
-rw-r--r--net/batman-adv/main.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index 71b56cf9cdd6..7c87a341f29f 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -32,11 +32,14 @@
32#include "gateway_client.h" 32#include "gateway_client.h"
33#include "vis.h" 33#include "vis.h"
34#include "hash.h" 34#include "hash.h"
35#include "bat_algo.h"
35 36
36 37
37/* List manipulations on hardif_list have to be rtnl_lock()'ed, 38/* List manipulations on hardif_list have to be rtnl_lock()'ed,
38 * list traversals just rcu-locked */ 39 * list traversals just rcu-locked */
39struct list_head hardif_list; 40struct list_head hardif_list;
41char bat_routing_algo[20] = "BATMAN IV";
42static struct hlist_head bat_algo_list;
40 43
41unsigned char broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 44unsigned char broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
42 45
@@ -45,6 +48,9 @@ struct workqueue_struct *bat_event_workqueue;
45static int __init batman_init(void) 48static int __init batman_init(void)
46{ 49{
47 INIT_LIST_HEAD(&hardif_list); 50 INIT_LIST_HEAD(&hardif_list);
51 INIT_HLIST_HEAD(&bat_algo_list);
52
53 bat_iv_init();
48 54
49 /* the name should not be longer than 10 chars - see 55 /* the name should not be longer than 10 chars - see
50 * http://lwn.net/Articles/23634/ */ 56 * http://lwn.net/Articles/23634/ */
@@ -172,6 +178,72 @@ int is_my_mac(const uint8_t *addr)
172 return 0; 178 return 0;
173} 179}
174 180
181static struct bat_algo_ops *bat_algo_get(char *name)
182{
183 struct bat_algo_ops *bat_algo_ops = NULL, *bat_algo_ops_tmp;
184 struct hlist_node *node;
185
186 hlist_for_each_entry(bat_algo_ops_tmp, node, &bat_algo_list, list) {
187 if (strcmp(bat_algo_ops_tmp->name, name) != 0)
188 continue;
189
190 bat_algo_ops = bat_algo_ops_tmp;
191 break;
192 }
193
194 return bat_algo_ops;
195}
196
197int bat_algo_register(struct bat_algo_ops *bat_algo_ops)
198{
199 struct bat_algo_ops *bat_algo_ops_tmp;
200 int ret = -1;
201
202 bat_algo_ops_tmp = bat_algo_get(bat_algo_ops->name);
203 if (bat_algo_ops_tmp) {
204 pr_info("Trying to register already registered routing "
205 "algorithm: %s\n", bat_algo_ops->name);
206 goto out;
207 }
208
209 INIT_HLIST_NODE(&bat_algo_ops->list);
210 hlist_add_head(&bat_algo_ops->list, &bat_algo_list);
211 ret = 0;
212
213out:
214 return ret;
215}
216
217int bat_algo_select(struct bat_priv *bat_priv, char *name)
218{
219 struct bat_algo_ops *bat_algo_ops;
220 int ret = -1;
221
222 bat_algo_ops = bat_algo_get(name);
223 if (!bat_algo_ops)
224 goto out;
225
226 bat_priv->bat_algo_ops = bat_algo_ops;
227 ret = 0;
228
229out:
230 return ret;
231}
232
233int bat_algo_seq_print_text(struct seq_file *seq, void *offset)
234{
235 struct bat_algo_ops *bat_algo_ops;
236 struct hlist_node *node;
237
238 seq_printf(seq, "Available routing algorithms:\n");
239
240 hlist_for_each_entry(bat_algo_ops, node, &bat_algo_list, list) {
241 seq_printf(seq, "%s\n", bat_algo_ops->name);
242 }
243
244 return 0;
245}
246
175module_init(batman_init); 247module_init(batman_init);
176module_exit(batman_exit); 248module_exit(batman_exit);
177 249