Skip to content

Commit 07a3061

Browse files
neocturnesimonwunderlich
authored andcommitted
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 <[email protected]> Signed-off-by: Andrew Lunn <[email protected]> [[email protected]: Reduce the number of changes to BATADV_CMD_GET_ROUTING_ALGOS, fix includes] Signed-off-by: Sven Eckelmann <[email protected]> Signed-off-by: Simon Wunderlich <[email protected]> Signed-off-by: Marek Lindner <[email protected]>
1 parent 9496920 commit 07a3061

File tree

5 files changed

+84
-1
lines changed

5 files changed

+84
-1
lines changed

include/uapi/linux/batman_adv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ enum batadv_nl_attrs {
7373
* @BATADV_CMD_GET_MESH_INFO: Query basic information about batman-adv device
7474
* @BATADV_CMD_TP_METER: Start a tp meter session
7575
* @BATADV_CMD_TP_METER_CANCEL: Cancel a tp meter session
76+
* @BATADV_CMD_GET_ROUTING_ALGOS: Query the list of routing algorithms.
7677
* @__BATADV_CMD_AFTER_LAST: internal use
7778
* @BATADV_CMD_MAX: highest used command number
7879
*/
@@ -81,6 +82,7 @@ enum batadv_nl_commands {
8182
BATADV_CMD_GET_MESH_INFO,
8283
BATADV_CMD_TP_METER,
8384
BATADV_CMD_TP_METER_CANCEL,
85+
BATADV_CMD_GET_ROUTING_ALGOS,
8486
/* add new commands above here */
8587
__BATADV_CMD_AFTER_LAST,
8688
BATADV_CMD_MAX = __BATADV_CMD_AFTER_LAST - 1

net/batman-adv/bat_algo.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,18 @@
2020
#include <linux/errno.h>
2121
#include <linux/list.h>
2222
#include <linux/moduleparam.h>
23+
#include <linux/netlink.h>
2324
#include <linux/printk.h>
2425
#include <linux/seq_file.h>
26+
#include <linux/skbuff.h>
2527
#include <linux/stddef.h>
2628
#include <linux/string.h>
29+
#include <net/genetlink.h>
30+
#include <net/netlink.h>
31+
#include <uapi/linux/batman_adv.h>
2732

2833
#include "bat_algo.h"
34+
#include "netlink.h"
2935

3036
char batadv_routing_algo[20] = "BATMAN_IV";
3137
static struct hlist_head batadv_algo_list;
@@ -138,3 +144,65 @@ static struct kparam_string batadv_param_string_ra = {
138144

139145
module_param_cb(routing_algo, &batadv_param_ops_ra, &batadv_param_string_ra,
140146
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+
}

net/batman-adv/bat_algo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222

2323
#include <linux/types.h>
2424

25+
struct netlink_callback;
2526
struct seq_file;
27+
struct sk_buff;
2628

2729
extern char batadv_routing_algo[];
2830
extern struct list_head batadv_hardif_list;
@@ -31,5 +33,6 @@ void batadv_algo_init(void);
3133
int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops);
3234
int batadv_algo_select(struct batadv_priv *bat_priv, char *name);
3335
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);
3437

3538
#endif /* _NET_BATMAN_ADV_BAT_ALGO_H_ */

net/batman-adv/netlink.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@
3232
#include <net/netlink.h>
3333
#include <uapi/linux/batman_adv.h>
3434

35+
#include "bat_algo.h"
3536
#include "hard-interface.h"
3637
#include "soft-interface.h"
3738
#include "tp_meter.h"
3839

3940
struct sk_buff;
4041

41-
static struct genl_family batadv_netlink_family = {
42+
struct genl_family batadv_netlink_family = {
4243
.id = GENL_ID_GENERATE,
4344
.hdrsize = 0,
4445
.name = BATADV_NL_NAME,
@@ -399,6 +400,12 @@ static struct genl_ops batadv_netlink_ops[] = {
399400
.policy = batadv_netlink_policy,
400401
.doit = batadv_netlink_tp_meter_cancel,
401402
},
403+
{
404+
.cmd = BATADV_CMD_GET_ROUTING_ALGOS,
405+
.flags = GENL_ADMIN_PERM,
406+
.policy = batadv_netlink_policy,
407+
.dumpit = batadv_algo_dump,
408+
},
402409
};
403410

404411
/**

net/batman-adv/netlink.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "main.h"
2222

2323
#include <linux/types.h>
24+
#include <net/genetlink.h>
2425

2526
void batadv_netlink_register(void);
2627
void batadv_netlink_unregister(void);
@@ -29,4 +30,6 @@ int batadv_netlink_tpmeter_notify(struct batadv_priv *bat_priv, const u8 *dst,
2930
u8 result, u32 test_time, u64 total_bytes,
3031
u32 cookie);
3132

33+
extern struct genl_family batadv_netlink_family;
34+
3235
#endif /* _NET_BATMAN_ADV_NETLINK_H_ */

0 commit comments

Comments
 (0)