1 /* Copyright (C) 2007-2016 B.A.T.M.A.N. contributors:
3 * Marek Lindner, Simon Wunderlich
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.
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.
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/>.
20 #include <linux/errno.h>
21 #include <linux/list.h>
22 #include <linux/moduleparam.h>
23 #include <linux/printk.h>
24 #include <linux/seq_file.h>
25 #include <linux/stddef.h>
26 #include <linux/string.h>
30 char batadv_routing_algo
[20] = "BATMAN_IV";
31 static struct hlist_head batadv_algo_list
;
34 * batadv_algo_init - Initialize batman-adv algorithm management data structures
36 void batadv_algo_init(void)
38 INIT_HLIST_HEAD(&batadv_algo_list
);
41 static struct batadv_algo_ops
*batadv_algo_get(char *name
)
43 struct batadv_algo_ops
*bat_algo_ops
= NULL
, *bat_algo_ops_tmp
;
45 hlist_for_each_entry(bat_algo_ops_tmp
, &batadv_algo_list
, list
) {
46 if (strcmp(bat_algo_ops_tmp
->name
, name
) != 0)
49 bat_algo_ops
= bat_algo_ops_tmp
;
56 int batadv_algo_register(struct batadv_algo_ops
*bat_algo_ops
)
58 struct batadv_algo_ops
*bat_algo_ops_tmp
;
60 bat_algo_ops_tmp
= batadv_algo_get(bat_algo_ops
->name
);
61 if (bat_algo_ops_tmp
) {
62 pr_info("Trying to register already registered routing algorithm: %s\n",
67 /* all algorithms must implement all ops (for now) */
68 if (!bat_algo_ops
->iface
.enable
||
69 !bat_algo_ops
->iface
.disable
||
70 !bat_algo_ops
->iface
.update_mac
||
71 !bat_algo_ops
->iface
.primary_set
||
72 !bat_algo_ops
->neigh
.cmp
||
73 !bat_algo_ops
->neigh
.is_similar_or_better
) {
74 pr_info("Routing algo '%s' does not implement required ops\n",
79 INIT_HLIST_NODE(&bat_algo_ops
->list
);
80 hlist_add_head(&bat_algo_ops
->list
, &batadv_algo_list
);
85 int batadv_algo_select(struct batadv_priv
*bat_priv
, char *name
)
87 struct batadv_algo_ops
*bat_algo_ops
;
89 bat_algo_ops
= batadv_algo_get(name
);
93 bat_priv
->algo_ops
= bat_algo_ops
;
98 int batadv_algo_seq_print_text(struct seq_file
*seq
, void *offset
)
100 struct batadv_algo_ops
*bat_algo_ops
;
102 seq_puts(seq
, "Available routing algorithms:\n");
104 hlist_for_each_entry(bat_algo_ops
, &batadv_algo_list
, list
) {
105 seq_printf(seq
, " * %s\n", bat_algo_ops
->name
);
111 static int batadv_param_set_ra(const char *val
, const struct kernel_param
*kp
)
113 struct batadv_algo_ops
*bat_algo_ops
;
114 char *algo_name
= (char *)val
;
115 size_t name_len
= strlen(algo_name
);
117 if (name_len
> 0 && algo_name
[name_len
- 1] == '\n')
118 algo_name
[name_len
- 1] = '\0';
120 bat_algo_ops
= batadv_algo_get(algo_name
);
122 pr_err("Routing algorithm '%s' is not supported\n", algo_name
);
126 return param_set_copystring(algo_name
, kp
);
129 static const struct kernel_param_ops batadv_param_ops_ra
= {
130 .set
= batadv_param_set_ra
,
131 .get
= param_get_string
,
134 static struct kparam_string batadv_param_string_ra
= {
135 .maxlen
= sizeof(batadv_routing_algo
),
136 .string
= batadv_routing_algo
,
139 module_param_cb(routing_algo
, &batadv_param_ops_ra
, &batadv_param_string_ra
,