diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2016-07-03 07:31:35 -0400 |
---|---|---|
committer | Simon Wunderlich <sw@simonwunderlich.de> | 2016-08-09 01:54:36 -0400 |
commit | 07a3061e0832fe22932e0fa977581e45b9c42431 (patch) | |
tree | 7ba704ec4c864bc69589ed0e3950aab259b15207 | |
parent | 94969208c8c7f3dd06c0e5e61155077b573d5d5f (diff) |
batman-adv: netlink: add routing_algo query
BATADV_CMD_GET_ROUTING_ALGOS is used to get the list of supported routing
algorithms.
Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
[sven.eckelmann@open-mesh.com: Reduce the number of changes to
BATADV_CMD_GET_ROUTING_ALGOS, fix includes]
Signed-off-by: Sven Eckelmann <sven.eckelmann@open-mesh.com>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
-rw-r--r-- | include/uapi/linux/batman_adv.h | 2 | ||||
-rw-r--r-- | net/batman-adv/bat_algo.c | 68 | ||||
-rw-r--r-- | net/batman-adv/bat_algo.h | 3 | ||||
-rw-r--r-- | net/batman-adv/netlink.c | 9 | ||||
-rw-r--r-- | net/batman-adv/netlink.h | 3 |
5 files changed, 84 insertions, 1 deletions
diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index 0fbf6fd4711b..7afce444a64e 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h | |||
@@ -73,6 +73,7 @@ enum batadv_nl_attrs { | |||
73 | * @BATADV_CMD_GET_MESH_INFO: Query basic information about batman-adv device | 73 | * @BATADV_CMD_GET_MESH_INFO: Query basic information about batman-adv device |
74 | * @BATADV_CMD_TP_METER: Start a tp meter session | 74 | * @BATADV_CMD_TP_METER: Start a tp meter session |
75 | * @BATADV_CMD_TP_METER_CANCEL: Cancel a tp meter session | 75 | * @BATADV_CMD_TP_METER_CANCEL: Cancel a tp meter session |
76 | * @BATADV_CMD_GET_ROUTING_ALGOS: Query the list of routing algorithms. | ||
76 | * @__BATADV_CMD_AFTER_LAST: internal use | 77 | * @__BATADV_CMD_AFTER_LAST: internal use |
77 | * @BATADV_CMD_MAX: highest used command number | 78 | * @BATADV_CMD_MAX: highest used command number |
78 | */ | 79 | */ |
@@ -81,6 +82,7 @@ enum batadv_nl_commands { | |||
81 | BATADV_CMD_GET_MESH_INFO, | 82 | BATADV_CMD_GET_MESH_INFO, |
82 | BATADV_CMD_TP_METER, | 83 | BATADV_CMD_TP_METER, |
83 | BATADV_CMD_TP_METER_CANCEL, | 84 | BATADV_CMD_TP_METER_CANCEL, |
85 | BATADV_CMD_GET_ROUTING_ALGOS, | ||
84 | /* add new commands above here */ | 86 | /* add new commands above here */ |
85 | __BATADV_CMD_AFTER_LAST, | 87 | __BATADV_CMD_AFTER_LAST, |
86 | BATADV_CMD_MAX = __BATADV_CMD_AFTER_LAST - 1 | 88 | BATADV_CMD_MAX = __BATADV_CMD_AFTER_LAST - 1 |
diff --git a/net/batman-adv/bat_algo.c b/net/batman-adv/bat_algo.c index 81dbbf569bd4..f2cc50d354d9 100644 --- a/net/batman-adv/bat_algo.c +++ b/net/batman-adv/bat_algo.c | |||
@@ -20,12 +20,18 @@ | |||
20 | #include <linux/errno.h> | 20 | #include <linux/errno.h> |
21 | #include <linux/list.h> | 21 | #include <linux/list.h> |
22 | #include <linux/moduleparam.h> | 22 | #include <linux/moduleparam.h> |
23 | #include <linux/netlink.h> | ||
23 | #include <linux/printk.h> | 24 | #include <linux/printk.h> |
24 | #include <linux/seq_file.h> | 25 | #include <linux/seq_file.h> |
26 | #include <linux/skbuff.h> | ||
25 | #include <linux/stddef.h> | 27 | #include <linux/stddef.h> |
26 | #include <linux/string.h> | 28 | #include <linux/string.h> |
29 | #include <net/genetlink.h> | ||
30 | #include <net/netlink.h> | ||
31 | #include <uapi/linux/batman_adv.h> | ||
27 | 32 | ||
28 | #include "bat_algo.h" | 33 | #include "bat_algo.h" |
34 | #include "netlink.h" | ||
29 | 35 | ||
30 | char batadv_routing_algo[20] = "BATMAN_IV"; | 36 | char batadv_routing_algo[20] = "BATMAN_IV"; |
31 | static struct hlist_head batadv_algo_list; | 37 | static struct hlist_head batadv_algo_list; |
@@ -138,3 +144,65 @@ static struct kparam_string batadv_param_string_ra = { | |||
138 | 144 | ||
139 | module_param_cb(routing_algo, &batadv_param_ops_ra, &batadv_param_string_ra, | 145 | module_param_cb(routing_algo, &batadv_param_ops_ra, &batadv_param_string_ra, |
140 | 0644); | 146 | 0644); |
147 | |||
148 | /** | ||
149 | * batadv_algo_dump_entry - fill in information about one supported routing | ||
150 | * algorithm | ||
151 | * @msg: netlink message to be sent back | ||
152 | * @portid: Port to reply to | ||
153 | * @seq: Sequence number of message | ||
154 | * @bat_algo_ops: Algorithm to be dumped | ||
155 | * | ||
156 | * Return: Error number, or 0 on success | ||
157 | */ | ||
158 | static int batadv_algo_dump_entry(struct sk_buff *msg, u32 portid, u32 seq, | ||
159 | struct batadv_algo_ops *bat_algo_ops) | ||
160 | { | ||
161 | void *hdr; | ||
162 | |||
163 | hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, | ||
164 | NLM_F_MULTI, BATADV_CMD_GET_ROUTING_ALGOS); | ||
165 | if (!hdr) | ||
166 | return -EMSGSIZE; | ||
167 | |||
168 | if (nla_put_string(msg, BATADV_ATTR_ALGO_NAME, bat_algo_ops->name)) | ||
169 | goto nla_put_failure; | ||
170 | |||
171 | genlmsg_end(msg, hdr); | ||
172 | return 0; | ||
173 | |||
174 | nla_put_failure: | ||
175 | genlmsg_cancel(msg, hdr); | ||
176 | return -EMSGSIZE; | ||
177 | } | ||
178 | |||
179 | /** | ||
180 | * batadv_algo_dump - fill in information about supported routing | ||
181 | * algorithms | ||
182 | * @msg: netlink message to be sent back | ||
183 | * @cb: Parameters to the netlink request | ||
184 | * | ||
185 | * Return: Length of reply message. | ||
186 | */ | ||
187 | int batadv_algo_dump(struct sk_buff *msg, struct netlink_callback *cb) | ||
188 | { | ||
189 | int portid = NETLINK_CB(cb->skb).portid; | ||
190 | struct batadv_algo_ops *bat_algo_ops; | ||
191 | int skip = cb->args[0]; | ||
192 | int i = 0; | ||
193 | |||
194 | hlist_for_each_entry(bat_algo_ops, &batadv_algo_list, list) { | ||
195 | if (i++ < skip) | ||
196 | continue; | ||
197 | |||
198 | if (batadv_algo_dump_entry(msg, portid, cb->nlh->nlmsg_seq, | ||
199 | bat_algo_ops)) { | ||
200 | i--; | ||
201 | break; | ||
202 | } | ||
203 | } | ||
204 | |||
205 | cb->args[0] = i; | ||
206 | |||
207 | return msg->len; | ||
208 | } | ||
diff --git a/net/batman-adv/bat_algo.h b/net/batman-adv/bat_algo.h index 860d773dd8fa..3b5b69cdd12b 100644 --- a/net/batman-adv/bat_algo.h +++ b/net/batman-adv/bat_algo.h | |||
@@ -22,7 +22,9 @@ | |||
22 | 22 | ||
23 | #include <linux/types.h> | 23 | #include <linux/types.h> |
24 | 24 | ||
25 | struct netlink_callback; | ||
25 | struct seq_file; | 26 | struct seq_file; |
27 | struct sk_buff; | ||
26 | 28 | ||
27 | extern char batadv_routing_algo[]; | 29 | extern char batadv_routing_algo[]; |
28 | extern struct list_head batadv_hardif_list; | 30 | extern struct list_head batadv_hardif_list; |
@@ -31,5 +33,6 @@ void batadv_algo_init(void); | |||
31 | int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops); | 33 | int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops); |
32 | int batadv_algo_select(struct batadv_priv *bat_priv, char *name); | 34 | int batadv_algo_select(struct batadv_priv *bat_priv, char *name); |
33 | int batadv_algo_seq_print_text(struct seq_file *seq, void *offset); | 35 | int batadv_algo_seq_print_text(struct seq_file *seq, void *offset); |
36 | int batadv_algo_dump(struct sk_buff *msg, struct netlink_callback *cb); | ||
34 | 37 | ||
35 | #endif /* _NET_BATMAN_ADV_BAT_ALGO_H_ */ | 38 | #endif /* _NET_BATMAN_ADV_BAT_ALGO_H_ */ |
diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c index 231f8eaf075b..19fb2657e274 100644 --- a/net/batman-adv/netlink.c +++ b/net/batman-adv/netlink.c | |||
@@ -32,13 +32,14 @@ | |||
32 | #include <net/netlink.h> | 32 | #include <net/netlink.h> |
33 | #include <uapi/linux/batman_adv.h> | 33 | #include <uapi/linux/batman_adv.h> |
34 | 34 | ||
35 | #include "bat_algo.h" | ||
35 | #include "hard-interface.h" | 36 | #include "hard-interface.h" |
36 | #include "soft-interface.h" | 37 | #include "soft-interface.h" |
37 | #include "tp_meter.h" | 38 | #include "tp_meter.h" |
38 | 39 | ||
39 | struct sk_buff; | 40 | struct sk_buff; |
40 | 41 | ||
41 | static struct genl_family batadv_netlink_family = { | 42 | struct genl_family batadv_netlink_family = { |
42 | .id = GENL_ID_GENERATE, | 43 | .id = GENL_ID_GENERATE, |
43 | .hdrsize = 0, | 44 | .hdrsize = 0, |
44 | .name = BATADV_NL_NAME, | 45 | .name = BATADV_NL_NAME, |
@@ -399,6 +400,12 @@ static struct genl_ops batadv_netlink_ops[] = { | |||
399 | .policy = batadv_netlink_policy, | 400 | .policy = batadv_netlink_policy, |
400 | .doit = batadv_netlink_tp_meter_cancel, | 401 | .doit = batadv_netlink_tp_meter_cancel, |
401 | }, | 402 | }, |
403 | { | ||
404 | .cmd = BATADV_CMD_GET_ROUTING_ALGOS, | ||
405 | .flags = GENL_ADMIN_PERM, | ||
406 | .policy = batadv_netlink_policy, | ||
407 | .dumpit = batadv_algo_dump, | ||
408 | }, | ||
402 | }; | 409 | }; |
403 | 410 | ||
404 | /** | 411 | /** |
diff --git a/net/batman-adv/netlink.h b/net/batman-adv/netlink.h index 945653ab58c6..b399f49504df 100644 --- a/net/batman-adv/netlink.h +++ b/net/batman-adv/netlink.h | |||
@@ -21,6 +21,7 @@ | |||
21 | #include "main.h" | 21 | #include "main.h" |
22 | 22 | ||
23 | #include <linux/types.h> | 23 | #include <linux/types.h> |
24 | #include <net/genetlink.h> | ||
24 | 25 | ||
25 | void batadv_netlink_register(void); | 26 | void batadv_netlink_register(void); |
26 | void batadv_netlink_unregister(void); | 27 | void batadv_netlink_unregister(void); |
@@ -29,4 +30,6 @@ int batadv_netlink_tpmeter_notify(struct batadv_priv *bat_priv, const u8 *dst, | |||
29 | u8 result, u32 test_time, u64 total_bytes, | 30 | u8 result, u32 test_time, u64 total_bytes, |
30 | u32 cookie); | 31 | u32 cookie); |
31 | 32 | ||
33 | extern struct genl_family batadv_netlink_family; | ||
34 | |||
32 | #endif /* _NET_BATMAN_ADV_NETLINK_H_ */ | 35 | #endif /* _NET_BATMAN_ADV_NETLINK_H_ */ |