Skip to content

Commit d7129da

Browse files
ecsvsimonwunderlich
authored andcommitted
batman-adv: netlink: add gateway table queries
Add BATADV_CMD_GET_GATEWAYS commands, using handlers bat_gw_dump in batadv_algo_ops. Will always return -EOPNOTSUPP for now, as no implementations exist yet. Signed-off-by: Sven Eckelmann <[email protected]> Signed-off-by: Marek Lindner <[email protected]> Signed-off-by: Simon Wunderlich <[email protected]>
1 parent f02a478 commit d7129da

File tree

5 files changed

+82
-0
lines changed

5 files changed

+82
-0
lines changed

include/uapi/linux/batman_adv.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ enum batadv_tt_client_flags {
8888
* @BATADV_ATTR_NEIGH_ADDRESS: Neighbour MAC address
8989
* @BATADV_ATTR_TQ: TQ to neighbour
9090
* @BATADV_ATTR_THROUGHPUT: Estimated throughput to Neighbour
91+
* @BATADV_ATTR_BANDWIDTH_UP: Reported uplink bandwidth
92+
* @BATADV_ATTR_BANDWIDTH_DOWN: Reported downlink bandwidth
93+
* @BATADV_ATTR_ROUTER: Gateway router MAC address
9194
* @__BATADV_ATTR_AFTER_LAST: internal use
9295
* @NUM_BATADV_ATTR: total number of batadv_nl_attrs available
9396
* @BATADV_ATTR_MAX: highest attribute number currently defined
@@ -120,6 +123,9 @@ enum batadv_nl_attrs {
120123
BATADV_ATTR_NEIGH_ADDRESS,
121124
BATADV_ATTR_TQ,
122125
BATADV_ATTR_THROUGHPUT,
126+
BATADV_ATTR_BANDWIDTH_UP,
127+
BATADV_ATTR_BANDWIDTH_DOWN,
128+
BATADV_ATTR_ROUTER,
123129
/* add attributes above here, update the policy in netlink.c */
124130
__BATADV_ATTR_AFTER_LAST,
125131
NUM_BATADV_ATTR = __BATADV_ATTR_AFTER_LAST,
@@ -139,6 +145,7 @@ enum batadv_nl_attrs {
139145
* @BATADV_CMD_GET_TRANSTABLE_GLOBAL Query list of global translations
140146
* @BATADV_CMD_GET_ORIGINATORS: Query list of originators
141147
* @BATADV_CMD_GET_NEIGHBORS: Query list of neighbours
148+
* @BATADV_CMD_GET_GATEWAYS: Query list of gateways
142149
* @__BATADV_CMD_AFTER_LAST: internal use
143150
* @BATADV_CMD_MAX: highest used command number
144151
*/
@@ -153,6 +160,7 @@ enum batadv_nl_commands {
153160
BATADV_CMD_GET_TRANSTABLE_GLOBAL,
154161
BATADV_CMD_GET_ORIGINATORS,
155162
BATADV_CMD_GET_NEIGHBORS,
163+
BATADV_CMD_GET_GATEWAYS,
156164
/* add new commands above here */
157165
__BATADV_CMD_AFTER_LAST,
158166
BATADV_CMD_MAX = __BATADV_CMD_AFTER_LAST - 1

net/batman-adv/gateway_client.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <linux/atomic.h>
2222
#include <linux/byteorder/generic.h>
23+
#include <linux/errno.h>
2324
#include <linux/etherdevice.h>
2425
#include <linux/fs.h>
2526
#include <linux/if_ether.h>
@@ -31,6 +32,7 @@
3132
#include <linux/kref.h>
3233
#include <linux/list.h>
3334
#include <linux/netdevice.h>
35+
#include <linux/netlink.h>
3436
#include <linux/rculist.h>
3537
#include <linux/rcupdate.h>
3638
#include <linux/seq_file.h>
@@ -39,13 +41,17 @@
3941
#include <linux/spinlock.h>
4042
#include <linux/stddef.h>
4143
#include <linux/udp.h>
44+
#include <net/sock.h>
45+
#include <uapi/linux/batman_adv.h>
4246

4347
#include "gateway_common.h"
4448
#include "hard-interface.h"
4549
#include "log.h"
50+
#include "netlink.h"
4651
#include "originator.h"
4752
#include "packet.h"
4853
#include "routing.h"
54+
#include "soft-interface.h"
4955
#include "sysfs.h"
5056
#include "translation-table.h"
5157

@@ -500,6 +506,59 @@ int batadv_gw_client_seq_print_text(struct seq_file *seq, void *offset)
500506
return 0;
501507
}
502508

509+
/**
510+
* batadv_gw_dump - Dump gateways into a message
511+
* @msg: Netlink message to dump into
512+
* @cb: Control block containing additional options
513+
*
514+
* Return: Error code, or length of message
515+
*/
516+
int batadv_gw_dump(struct sk_buff *msg, struct netlink_callback *cb)
517+
{
518+
struct batadv_hard_iface *primary_if = NULL;
519+
struct net *net = sock_net(cb->skb->sk);
520+
struct net_device *soft_iface;
521+
struct batadv_priv *bat_priv;
522+
int ifindex;
523+
int ret;
524+
525+
ifindex = batadv_netlink_get_ifindex(cb->nlh,
526+
BATADV_ATTR_MESH_IFINDEX);
527+
if (!ifindex)
528+
return -EINVAL;
529+
530+
soft_iface = dev_get_by_index(net, ifindex);
531+
if (!soft_iface || !batadv_softif_is_valid(soft_iface)) {
532+
ret = -ENODEV;
533+
goto out;
534+
}
535+
536+
bat_priv = netdev_priv(soft_iface);
537+
538+
primary_if = batadv_primary_if_get_selected(bat_priv);
539+
if (!primary_if || primary_if->if_status != BATADV_IF_ACTIVE) {
540+
ret = -ENOENT;
541+
goto out;
542+
}
543+
544+
if (!bat_priv->algo_ops->gw.dump) {
545+
ret = -EOPNOTSUPP;
546+
goto out;
547+
}
548+
549+
bat_priv->algo_ops->gw.dump(msg, cb, bat_priv);
550+
551+
ret = msg->len;
552+
553+
out:
554+
if (primary_if)
555+
batadv_hardif_put(primary_if);
556+
if (soft_iface)
557+
dev_put(soft_iface);
558+
559+
return ret;
560+
}
561+
503562
/**
504563
* batadv_gw_dhcp_recipient_get - check if a packet is a DHCP message
505564
* @skb: the packet to check

net/batman-adv/gateway_client.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/types.h>
2424

2525
struct batadv_tvlv_gateway_data;
26+
struct netlink_callback;
2627
struct seq_file;
2728
struct sk_buff;
2829

@@ -43,6 +44,7 @@ void batadv_gw_node_put(struct batadv_gw_node *gw_node);
4344
struct batadv_gw_node *
4445
batadv_gw_get_selected_gw_node(struct batadv_priv *bat_priv);
4546
int batadv_gw_client_seq_print_text(struct seq_file *seq, void *offset);
47+
int batadv_gw_dump(struct sk_buff *msg, struct netlink_callback *cb);
4648
bool batadv_gw_out_of_range(struct batadv_priv *bat_priv, struct sk_buff *skb);
4749
enum batadv_dhcp_recipient
4850
batadv_gw_dhcp_recipient_get(struct sk_buff *skb, unsigned int *header_len,

net/batman-adv/netlink.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <uapi/linux/batman_adv.h>
3939

4040
#include "bat_algo.h"
41+
#include "gateway_client.h"
4142
#include "hard-interface.h"
4243
#include "originator.h"
4344
#include "soft-interface.h"
@@ -87,6 +88,9 @@ static struct nla_policy batadv_netlink_policy[NUM_BATADV_ATTR] = {
8788
[BATADV_ATTR_NEIGH_ADDRESS] = { .len = ETH_ALEN },
8889
[BATADV_ATTR_TQ] = { .type = NLA_U8 },
8990
[BATADV_ATTR_THROUGHPUT] = { .type = NLA_U32 },
91+
[BATADV_ATTR_BANDWIDTH_UP] = { .type = NLA_U32 },
92+
[BATADV_ATTR_BANDWIDTH_DOWN] = { .type = NLA_U32 },
93+
[BATADV_ATTR_ROUTER] = { .len = ETH_ALEN },
9094
};
9195

9296
/**
@@ -570,6 +574,12 @@ static struct genl_ops batadv_netlink_ops[] = {
570574
.policy = batadv_netlink_policy,
571575
.dumpit = batadv_hardif_neigh_dump,
572576
},
577+
{
578+
.cmd = BATADV_CMD_GET_GATEWAYS,
579+
.flags = GENL_ADMIN_PERM,
580+
.policy = batadv_netlink_policy,
581+
.dumpit = batadv_gw_dump,
582+
},
573583
};
574584

575585
/**

net/batman-adv/types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,6 +1469,7 @@ struct batadv_algo_orig_ops {
14691469
* @is_eligible: check if a newly discovered GW is a potential candidate for
14701470
* the election as best GW (optional)
14711471
* @print: print the gateway table (optional)
1472+
* @dump: dump gateways to a netlink socket (optional)
14721473
*/
14731474
struct batadv_algo_gw_ops {
14741475
ssize_t (*store_sel_class)(struct batadv_priv *bat_priv, char *buff,
@@ -1480,6 +1481,8 @@ struct batadv_algo_gw_ops {
14801481
struct batadv_orig_node *curr_gw_orig,
14811482
struct batadv_orig_node *orig_node);
14821483
void (*print)(struct batadv_priv *bat_priv, struct seq_file *seq);
1484+
void (*dump)(struct sk_buff *msg, struct netlink_callback *cb,
1485+
struct batadv_priv *priv);
14831486
};
14841487

14851488
/**

0 commit comments

Comments
 (0)