summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Eckelmann <sven@narfation.org>2016-05-15 05:07:44 -0400
committerSimon Wunderlich <sw@simonwunderlich.de>2016-06-30 04:29:43 -0400
commit01d350d14712d1e8dbf2b00c82d2fc7c48d34e04 (patch)
tree0d96722cd01fd8a955d378d8f0464ee12253f957
parent1f8dce4992d03fc15cfbaf67cd09f0d1648c4606 (diff)
batman-adv: move bat_algo functions into a separate file
The bat_algo functionality in main.c is mostly unrelated to the rest of the content. It still takes up a large portion of this source file (~15%, 103 lines). Moving it to a separate file makes it better visible as a main component of the batman-adv implementation and hides it less in the other helper functions in main.c. Signed-off-by: Sven Eckelmann <sven@narfation.org> Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch> Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
-rw-r--r--net/batman-adv/Makefile1
-rw-r--r--net/batman-adv/bat_algo.c140
-rw-r--r--net/batman-adv/bat_algo.h12
-rw-r--r--net/batman-adv/bat_v_ogm.c1
-rw-r--r--net/batman-adv/debugfs.c1
-rw-r--r--net/batman-adv/main.c105
-rw-r--r--net/batman-adv/main.h4
-rw-r--r--net/batman-adv/originator.c1
-rw-r--r--net/batman-adv/routing.c1
-rw-r--r--net/batman-adv/soft-interface.c1
-rw-r--r--net/batman-adv/translation-table.c1
11 files changed, 160 insertions, 108 deletions
diff --git a/net/batman-adv/Makefile b/net/batman-adv/Makefile
index 5c6ece0cfc17..5260c17e2069 100644
--- a/net/batman-adv/Makefile
+++ b/net/batman-adv/Makefile
@@ -17,6 +17,7 @@
17# 17#
18 18
19obj-$(CONFIG_BATMAN_ADV) += batman-adv.o 19obj-$(CONFIG_BATMAN_ADV) += batman-adv.o
20batman-adv-y += bat_algo.o
20batman-adv-y += bat_iv_ogm.o 21batman-adv-y += bat_iv_ogm.o
21batman-adv-$(CONFIG_BATMAN_ADV_BATMAN_V) += bat_v.o 22batman-adv-$(CONFIG_BATMAN_ADV_BATMAN_V) += bat_v.o
22batman-adv-$(CONFIG_BATMAN_ADV_BATMAN_V) += bat_v_elp.o 23batman-adv-$(CONFIG_BATMAN_ADV_BATMAN_V) += bat_v_elp.o
diff --git a/net/batman-adv/bat_algo.c b/net/batman-adv/bat_algo.c
new file mode 100644
index 000000000000..610d4de0f6b0
--- /dev/null
+++ b/net/batman-adv/bat_algo.c
@@ -0,0 +1,140 @@
1/* Copyright (C) 2007-2016 B.A.T.M.A.N. contributors:
2 *
3 * Marek Lindner, Simon Wunderlich
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 "main.h"
19
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>
27
28#include "bat_algo.h"
29
30char batadv_routing_algo[20] = "BATMAN_IV";
31static struct hlist_head batadv_algo_list;
32
33/**
34 * batadv_algo_init - Initialize batman-adv algorithm management data structures
35 */
36void batadv_algo_init(void)
37{
38 INIT_HLIST_HEAD(&batadv_algo_list);
39}
40
41static struct batadv_algo_ops *batadv_algo_get(char *name)
42{
43 struct batadv_algo_ops *bat_algo_ops = NULL, *bat_algo_ops_tmp;
44
45 hlist_for_each_entry(bat_algo_ops_tmp, &batadv_algo_list, list) {
46 if (strcmp(bat_algo_ops_tmp->name, name) != 0)
47 continue;
48
49 bat_algo_ops = bat_algo_ops_tmp;
50 break;
51 }
52
53 return bat_algo_ops;
54}
55
56int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops)
57{
58 struct batadv_algo_ops *bat_algo_ops_tmp;
59
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",
63 bat_algo_ops->name);
64 return -EEXIST;
65 }
66
67 /* all algorithms must implement all ops (for now) */
68 if (!bat_algo_ops->bat_iface_enable ||
69 !bat_algo_ops->bat_iface_disable ||
70 !bat_algo_ops->bat_iface_update_mac ||
71 !bat_algo_ops->bat_primary_iface_set ||
72 !bat_algo_ops->bat_neigh_cmp ||
73 !bat_algo_ops->bat_neigh_is_similar_or_better) {
74 pr_info("Routing algo '%s' does not implement required ops\n",
75 bat_algo_ops->name);
76 return -EINVAL;
77 }
78
79 INIT_HLIST_NODE(&bat_algo_ops->list);
80 hlist_add_head(&bat_algo_ops->list, &batadv_algo_list);
81
82 return 0;
83}
84
85int batadv_algo_select(struct batadv_priv *bat_priv, char *name)
86{
87 struct batadv_algo_ops *bat_algo_ops;
88
89 bat_algo_ops = batadv_algo_get(name);
90 if (!bat_algo_ops)
91 return -EINVAL;
92
93 bat_priv->bat_algo_ops = bat_algo_ops;
94
95 return 0;
96}
97
98int batadv_algo_seq_print_text(struct seq_file *seq, void *offset)
99{
100 struct batadv_algo_ops *bat_algo_ops;
101
102 seq_puts(seq, "Available routing algorithms:\n");
103
104 hlist_for_each_entry(bat_algo_ops, &batadv_algo_list, list) {
105 seq_printf(seq, " * %s\n", bat_algo_ops->name);
106 }
107
108 return 0;
109}
110
111static int batadv_param_set_ra(const char *val, const struct kernel_param *kp)
112{
113 struct batadv_algo_ops *bat_algo_ops;
114 char *algo_name = (char *)val;
115 size_t name_len = strlen(algo_name);
116
117 if (name_len > 0 && algo_name[name_len - 1] == '\n')
118 algo_name[name_len - 1] = '\0';
119
120 bat_algo_ops = batadv_algo_get(algo_name);
121 if (!bat_algo_ops) {
122 pr_err("Routing algorithm '%s' is not supported\n", algo_name);
123 return -EINVAL;
124 }
125
126 return param_set_copystring(algo_name, kp);
127}
128
129static const struct kernel_param_ops batadv_param_ops_ra = {
130 .set = batadv_param_set_ra,
131 .get = param_get_string,
132};
133
134static struct kparam_string batadv_param_string_ra = {
135 .maxlen = sizeof(batadv_routing_algo),
136 .string = batadv_routing_algo,
137};
138
139module_param_cb(routing_algo, &batadv_param_ops_ra, &batadv_param_string_ra,
140 0644);
diff --git a/net/batman-adv/bat_algo.h b/net/batman-adv/bat_algo.h
index 36542962de7d..8c7e761ff23b 100644
--- a/net/batman-adv/bat_algo.h
+++ b/net/batman-adv/bat_algo.h
@@ -20,8 +20,20 @@
20 20
21#include "main.h" 21#include "main.h"
22 22
23#include <linux/types.h>
24
25struct seq_file;
26
23int batadv_iv_init(void); 27int batadv_iv_init(void);
24 28
29extern char batadv_routing_algo[];
30extern struct list_head batadv_hardif_list;
31
32void batadv_algo_init(void);
33int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops);
34int batadv_algo_select(struct batadv_priv *bat_priv, char *name);
35int batadv_algo_seq_print_text(struct seq_file *seq, void *offset);
36
25#ifdef CONFIG_BATMAN_ADV_BATMAN_V 37#ifdef CONFIG_BATMAN_ADV_BATMAN_V
26 38
27int batadv_v_init(void); 39int batadv_v_init(void);
diff --git a/net/batman-adv/bat_v_ogm.c b/net/batman-adv/bat_v_ogm.c
index ca5a679d112f..93e3d760bfe0 100644
--- a/net/batman-adv/bat_v_ogm.c
+++ b/net/batman-adv/bat_v_ogm.c
@@ -39,6 +39,7 @@
39#include <linux/types.h> 39#include <linux/types.h>
40#include <linux/workqueue.h> 40#include <linux/workqueue.h>
41 41
42#include "bat_algo.h"
42#include "hard-interface.h" 43#include "hard-interface.h"
43#include "hash.h" 44#include "hash.h"
44#include "originator.h" 45#include "originator.h"
diff --git a/net/batman-adv/debugfs.c b/net/batman-adv/debugfs.c
index f187a8ff2184..227c84b9db03 100644
--- a/net/batman-adv/debugfs.c
+++ b/net/batman-adv/debugfs.c
@@ -44,6 +44,7 @@
44#include <linux/wait.h> 44#include <linux/wait.h>
45#include <stdarg.h> 45#include <stdarg.h>
46 46
47#include "bat_algo.h"
47#include "bridge_loop_avoidance.h" 48#include "bridge_loop_avoidance.h"
48#include "distributed-arp-table.h" 49#include "distributed-arp-table.h"
49#include "gateway_client.h" 50#include "gateway_client.h"
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index 225d63e0c711..c5a7cab0f567 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -32,7 +32,6 @@
32#include <linux/kref.h> 32#include <linux/kref.h>
33#include <linux/list.h> 33#include <linux/list.h>
34#include <linux/module.h> 34#include <linux/module.h>
35#include <linux/moduleparam.h>
36#include <linux/netdevice.h> 35#include <linux/netdevice.h>
37#include <linux/rculist.h> 36#include <linux/rculist.h>
38#include <linux/rcupdate.h> 37#include <linux/rcupdate.h>
@@ -68,8 +67,6 @@
68struct list_head batadv_hardif_list; 67struct list_head batadv_hardif_list;
69static int (*batadv_rx_handler[256])(struct sk_buff *, 68static int (*batadv_rx_handler[256])(struct sk_buff *,
70 struct batadv_hard_iface *); 69 struct batadv_hard_iface *);
71char batadv_routing_algo[20] = "BATMAN_IV";
72static struct hlist_head batadv_algo_list;
73 70
74unsigned char batadv_broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 71unsigned char batadv_broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
75 72
@@ -80,7 +77,7 @@ static void batadv_recv_handler_init(void);
80static int __init batadv_init(void) 77static int __init batadv_init(void)
81{ 78{
82 INIT_LIST_HEAD(&batadv_hardif_list); 79 INIT_LIST_HEAD(&batadv_hardif_list);
83 INIT_HLIST_HEAD(&batadv_algo_list); 80 batadv_algo_init();
84 81
85 batadv_recv_handler_init(); 82 batadv_recv_handler_init();
86 83
@@ -535,76 +532,6 @@ void batadv_recv_handler_unregister(u8 packet_type)
535 batadv_rx_handler[packet_type] = batadv_recv_unhandled_packet; 532 batadv_rx_handler[packet_type] = batadv_recv_unhandled_packet;
536} 533}
537 534
538static struct batadv_algo_ops *batadv_algo_get(char *name)
539{
540 struct batadv_algo_ops *bat_algo_ops = NULL, *bat_algo_ops_tmp;
541
542 hlist_for_each_entry(bat_algo_ops_tmp, &batadv_algo_list, list) {
543 if (strcmp(bat_algo_ops_tmp->name, name) != 0)
544 continue;
545
546 bat_algo_ops = bat_algo_ops_tmp;
547 break;
548 }
549
550 return bat_algo_ops;
551}
552
553int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops)
554{
555 struct batadv_algo_ops *bat_algo_ops_tmp;
556
557 bat_algo_ops_tmp = batadv_algo_get(bat_algo_ops->name);
558 if (bat_algo_ops_tmp) {
559 pr_info("Trying to register already registered routing algorithm: %s\n",
560 bat_algo_ops->name);
561 return -EEXIST;
562 }
563
564 /* all algorithms must implement all ops (for now) */
565 if (!bat_algo_ops->bat_iface_enable ||
566 !bat_algo_ops->bat_iface_disable ||
567 !bat_algo_ops->bat_iface_update_mac ||
568 !bat_algo_ops->bat_primary_iface_set ||
569 !bat_algo_ops->bat_neigh_cmp ||
570 !bat_algo_ops->bat_neigh_is_similar_or_better) {
571 pr_info("Routing algo '%s' does not implement required ops\n",
572 bat_algo_ops->name);
573 return -EINVAL;
574 }
575
576 INIT_HLIST_NODE(&bat_algo_ops->list);
577 hlist_add_head(&bat_algo_ops->list, &batadv_algo_list);
578
579 return 0;
580}
581
582int batadv_algo_select(struct batadv_priv *bat_priv, char *name)
583{
584 struct batadv_algo_ops *bat_algo_ops;
585
586 bat_algo_ops = batadv_algo_get(name);
587 if (!bat_algo_ops)
588 return -EINVAL;
589
590 bat_priv->bat_algo_ops = bat_algo_ops;
591
592 return 0;
593}
594
595int batadv_algo_seq_print_text(struct seq_file *seq, void *offset)
596{
597 struct batadv_algo_ops *bat_algo_ops;
598
599 seq_puts(seq, "Available routing algorithms:\n");
600
601 hlist_for_each_entry(bat_algo_ops, &batadv_algo_list, list) {
602 seq_printf(seq, " * %s\n", bat_algo_ops->name);
603 }
604
605 return 0;
606}
607
608/** 535/**
609 * batadv_skb_crc32 - calculate CRC32 of the whole packet and skip bytes in 536 * batadv_skb_crc32 - calculate CRC32 of the whole packet and skip bytes in
610 * the header 537 * the header
@@ -691,36 +618,6 @@ bool batadv_vlan_ap_isola_get(struct batadv_priv *bat_priv, unsigned short vid)
691 return ap_isolation_enabled; 618 return ap_isolation_enabled;
692} 619}
693 620
694static int batadv_param_set_ra(const char *val, const struct kernel_param *kp)
695{
696 struct batadv_algo_ops *bat_algo_ops;
697 char *algo_name = (char *)val;
698 size_t name_len = strlen(algo_name);
699
700 if (name_len > 0 && algo_name[name_len - 1] == '\n')
701 algo_name[name_len - 1] = '\0';
702
703 bat_algo_ops = batadv_algo_get(algo_name);
704 if (!bat_algo_ops) {
705 pr_err("Routing algorithm '%s' is not supported\n", algo_name);
706 return -EINVAL;
707 }
708
709 return param_set_copystring(algo_name, kp);
710}
711
712static const struct kernel_param_ops batadv_param_ops_ra = {
713 .set = batadv_param_set_ra,
714 .get = param_get_string,
715};
716
717static struct kparam_string batadv_param_string_ra = {
718 .maxlen = sizeof(batadv_routing_algo),
719 .string = batadv_routing_algo,
720};
721
722module_param_cb(routing_algo, &batadv_param_ops_ra, &batadv_param_string_ra,
723 0644);
724module_init(batadv_init); 621module_init(batadv_init);
725module_exit(batadv_exit); 622module_exit(batadv_exit);
726 623
diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h
index 3af6582aab8b..3ec62853e519 100644
--- a/net/batman-adv/main.h
+++ b/net/batman-adv/main.h
@@ -196,7 +196,6 @@ struct sk_buff;
196#define BATADV_PRINT_VID(vid) ((vid & BATADV_VLAN_HAS_TAG) ? \ 196#define BATADV_PRINT_VID(vid) ((vid & BATADV_VLAN_HAS_TAG) ? \
197 (int)(vid & VLAN_VID_MASK) : -1) 197 (int)(vid & VLAN_VID_MASK) : -1)
198 198
199extern char batadv_routing_algo[];
200extern struct list_head batadv_hardif_list; 199extern struct list_head batadv_hardif_list;
201 200
202extern unsigned char batadv_broadcast_addr[]; 201extern unsigned char batadv_broadcast_addr[];
@@ -217,9 +216,6 @@ batadv_recv_handler_register(u8 packet_type,
217 int (*recv_handler)(struct sk_buff *, 216 int (*recv_handler)(struct sk_buff *,
218 struct batadv_hard_iface *)); 217 struct batadv_hard_iface *));
219void batadv_recv_handler_unregister(u8 packet_type); 218void batadv_recv_handler_unregister(u8 packet_type);
220int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops);
221int batadv_algo_select(struct batadv_priv *bat_priv, char *name);
222int batadv_algo_seq_print_text(struct seq_file *seq, void *offset);
223__be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr); 219__be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr);
224 220
225/** 221/**
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index 076d258c92e1..592cbda283e3 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -34,6 +34,7 @@
34#include <linux/spinlock.h> 34#include <linux/spinlock.h>
35#include <linux/workqueue.h> 35#include <linux/workqueue.h>
36 36
37#include "bat_algo.h"
37#include "distributed-arp-table.h" 38#include "distributed-arp-table.h"
38#include "fragmentation.h" 39#include "fragmentation.h"
39#include "gateway_client.h" 40#include "gateway_client.h"
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index 8cb459a57219..b9c7325ea0aa 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -34,6 +34,7 @@
34#include <linux/spinlock.h> 34#include <linux/spinlock.h>
35#include <linux/stddef.h> 35#include <linux/stddef.h>
36 36
37#include "bat_algo.h"
37#include "bitarray.h" 38#include "bitarray.h"
38#include "bridge_loop_avoidance.h" 39#include "bridge_loop_avoidance.h"
39#include "distributed-arp-table.h" 40#include "distributed-arp-table.h"
diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
index b60999da134d..f75631e21e48 100644
--- a/net/batman-adv/soft-interface.c
+++ b/net/batman-adv/soft-interface.c
@@ -48,6 +48,7 @@
48#include <linux/types.h> 48#include <linux/types.h>
49#include <linux/workqueue.h> 49#include <linux/workqueue.h>
50 50
51#include "bat_algo.h"
51#include "bridge_loop_avoidance.h" 52#include "bridge_loop_avoidance.h"
52#include "debugfs.h" 53#include "debugfs.h"
53#include "distributed-arp-table.h" 54#include "distributed-arp-table.h"
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index 6c8d624e4581..5c3cf7ffc77e 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -44,6 +44,7 @@
44#include <linux/string.h> 44#include <linux/string.h>
45#include <linux/workqueue.h> 45#include <linux/workqueue.h>
46 46
47#include "bat_algo.h"
47#include "bridge_loop_avoidance.h" 48#include "bridge_loop_avoidance.h"
48#include "hard-interface.h" 49#include "hard-interface.h"
49#include "hash.h" 50#include "hash.h"