Skip to content

Commit 85cf8c8

Browse files
neocturnesimonwunderlich
authored andcommitted
batman-adv: netlink: add originator and neighbor table queries
Add BATADV_CMD_GET_ORIGINATORS and BATADV_CMD_GET_NEIGHBORS commands, using handlers bat_orig_dump and bat_neigh_dump in batadv_algo_ops. Will always return -EOPNOTSUPP for now, as no implementations exist yet. Signed-off-by: Matthias Schiffer <[email protected]> Signed-off-by: Andrew Lunn <[email protected]> [[email protected]: Rewrite based on new algo_ops structures] Signed-off-by: Sven Eckelmann <[email protected]> Signed-off-by: Simon Wunderlich <[email protected]> Signed-off-by: Marek Lindner <[email protected]>
1 parent f32ed4b commit 85cf8c8

File tree

5 files changed

+190
-0
lines changed

5 files changed

+190
-0
lines changed

include/uapi/linux/batman_adv.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ enum batadv_nl_attrs {
131131
* @BATADV_CMD_GET_HARDIFS: Query list of hard interfaces
132132
* @BATADV_CMD_GET_TRANSTABLE_LOCAL: Query list of local translations
133133
* @BATADV_CMD_GET_TRANSTABLE_GLOBAL Query list of global translations
134+
* @BATADV_CMD_GET_ORIGINATORS: Query list of originators
135+
* @BATADV_CMD_GET_NEIGHBORS: Query list of neighbours
134136
* @__BATADV_CMD_AFTER_LAST: internal use
135137
* @BATADV_CMD_MAX: highest used command number
136138
*/
@@ -143,6 +145,8 @@ enum batadv_nl_commands {
143145
BATADV_CMD_GET_HARDIFS,
144146
BATADV_CMD_GET_TRANSTABLE_LOCAL,
145147
BATADV_CMD_GET_TRANSTABLE_GLOBAL,
148+
BATADV_CMD_GET_ORIGINATORS,
149+
BATADV_CMD_GET_NEIGHBORS,
146150
/* add new commands above here */
147151
__BATADV_CMD_AFTER_LAST,
148152
BATADV_CMD_MAX = __BATADV_CMD_AFTER_LAST - 1

net/batman-adv/netlink.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
#include "bat_algo.h"
4141
#include "hard-interface.h"
42+
#include "originator.h"
4243
#include "soft-interface.h"
4344
#include "tp_meter.h"
4445
#include "translation-table.h"
@@ -554,6 +555,18 @@ static struct genl_ops batadv_netlink_ops[] = {
554555
.policy = batadv_netlink_policy,
555556
.dumpit = batadv_tt_global_dump,
556557
},
558+
{
559+
.cmd = BATADV_CMD_GET_ORIGINATORS,
560+
.flags = GENL_ADMIN_PERM,
561+
.policy = batadv_netlink_policy,
562+
.dumpit = batadv_orig_dump,
563+
},
564+
{
565+
.cmd = BATADV_CMD_GET_NEIGHBORS,
566+
.flags = GENL_ADMIN_PERM,
567+
.policy = batadv_netlink_policy,
568+
.dumpit = batadv_hardif_neigh_dump,
569+
},
557570
};
558571

559572
/**

net/batman-adv/originator.c

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@
2828
#include <linux/list.h>
2929
#include <linux/lockdep.h>
3030
#include <linux/netdevice.h>
31+
#include <linux/netlink.h>
3132
#include <linux/rculist.h>
3233
#include <linux/seq_file.h>
34+
#include <linux/skbuff.h>
3335
#include <linux/slab.h>
3436
#include <linux/spinlock.h>
3537
#include <linux/workqueue.h>
38+
#include <net/sock.h>
39+
#include <uapi/linux/batman_adv.h>
3640

3741
#include "bat_algo.h"
3842
#include "distributed-arp-table.h"
@@ -42,8 +46,10 @@
4246
#include "hash.h"
4347
#include "log.h"
4448
#include "multicast.h"
49+
#include "netlink.h"
4550
#include "network-coding.h"
4651
#include "routing.h"
52+
#include "soft-interface.h"
4753
#include "translation-table.h"
4854

4955
/* hash class keys */
@@ -720,6 +726,83 @@ int batadv_hardif_neigh_seq_print_text(struct seq_file *seq, void *offset)
720726
return 0;
721727
}
722728

729+
/**
730+
* batadv_hardif_neigh_dump - Dump to netlink the neighbor infos for a specific
731+
* outgoing interface
732+
* @msg: message to dump into
733+
* @cb: parameters for the dump
734+
*
735+
* Return: 0 or error value
736+
*/
737+
int batadv_hardif_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb)
738+
{
739+
struct net *net = sock_net(cb->skb->sk);
740+
struct net_device *soft_iface;
741+
struct net_device *hard_iface = NULL;
742+
struct batadv_hard_iface *hardif = BATADV_IF_DEFAULT;
743+
struct batadv_priv *bat_priv;
744+
struct batadv_hard_iface *primary_if = NULL;
745+
int ret;
746+
int ifindex, hard_ifindex;
747+
748+
ifindex = batadv_netlink_get_ifindex(cb->nlh, BATADV_ATTR_MESH_IFINDEX);
749+
if (!ifindex)
750+
return -EINVAL;
751+
752+
soft_iface = dev_get_by_index(net, ifindex);
753+
if (!soft_iface || !batadv_softif_is_valid(soft_iface)) {
754+
ret = -ENODEV;
755+
goto out;
756+
}
757+
758+
bat_priv = netdev_priv(soft_iface);
759+
760+
primary_if = batadv_primary_if_get_selected(bat_priv);
761+
if (!primary_if || primary_if->if_status != BATADV_IF_ACTIVE) {
762+
ret = -ENOENT;
763+
goto out;
764+
}
765+
766+
hard_ifindex = batadv_netlink_get_ifindex(cb->nlh,
767+
BATADV_ATTR_HARD_IFINDEX);
768+
if (hard_ifindex) {
769+
hard_iface = dev_get_by_index(net, hard_ifindex);
770+
if (hard_iface)
771+
hardif = batadv_hardif_get_by_netdev(hard_iface);
772+
773+
if (!hardif) {
774+
ret = -ENODEV;
775+
goto out;
776+
}
777+
778+
if (hardif->soft_iface != soft_iface) {
779+
ret = -ENOENT;
780+
goto out;
781+
}
782+
}
783+
784+
if (!bat_priv->algo_ops->neigh.dump) {
785+
ret = -EOPNOTSUPP;
786+
goto out;
787+
}
788+
789+
bat_priv->algo_ops->neigh.dump(msg, cb, bat_priv, hardif);
790+
791+
ret = msg->len;
792+
793+
out:
794+
if (hardif)
795+
batadv_hardif_put(hardif);
796+
if (hard_iface)
797+
dev_put(hard_iface);
798+
if (primary_if)
799+
batadv_hardif_put(primary_if);
800+
if (soft_iface)
801+
dev_put(soft_iface);
802+
803+
return ret;
804+
}
805+
723806
/**
724807
* batadv_orig_ifinfo_release - release orig_ifinfo from lists and queue for
725808
* free after rcu grace period
@@ -1330,6 +1413,83 @@ int batadv_orig_hardif_seq_print_text(struct seq_file *seq, void *offset)
13301413
return 0;
13311414
}
13321415

1416+
/**
1417+
* batadv_orig_dump - Dump to netlink the originator infos for a specific
1418+
* outgoing interface
1419+
* @msg: message to dump into
1420+
* @cb: parameters for the dump
1421+
*
1422+
* Return: 0 or error value
1423+
*/
1424+
int batadv_orig_dump(struct sk_buff *msg, struct netlink_callback *cb)
1425+
{
1426+
struct net *net = sock_net(cb->skb->sk);
1427+
struct net_device *soft_iface;
1428+
struct net_device *hard_iface = NULL;
1429+
struct batadv_hard_iface *hardif = BATADV_IF_DEFAULT;
1430+
struct batadv_priv *bat_priv;
1431+
struct batadv_hard_iface *primary_if = NULL;
1432+
int ret;
1433+
int ifindex, hard_ifindex;
1434+
1435+
ifindex = batadv_netlink_get_ifindex(cb->nlh, BATADV_ATTR_MESH_IFINDEX);
1436+
if (!ifindex)
1437+
return -EINVAL;
1438+
1439+
soft_iface = dev_get_by_index(net, ifindex);
1440+
if (!soft_iface || !batadv_softif_is_valid(soft_iface)) {
1441+
ret = -ENODEV;
1442+
goto out;
1443+
}
1444+
1445+
bat_priv = netdev_priv(soft_iface);
1446+
1447+
primary_if = batadv_primary_if_get_selected(bat_priv);
1448+
if (!primary_if || primary_if->if_status != BATADV_IF_ACTIVE) {
1449+
ret = -ENOENT;
1450+
goto out;
1451+
}
1452+
1453+
hard_ifindex = batadv_netlink_get_ifindex(cb->nlh,
1454+
BATADV_ATTR_HARD_IFINDEX);
1455+
if (hard_ifindex) {
1456+
hard_iface = dev_get_by_index(net, hard_ifindex);
1457+
if (hard_iface)
1458+
hardif = batadv_hardif_get_by_netdev(hard_iface);
1459+
1460+
if (!hardif) {
1461+
ret = -ENODEV;
1462+
goto out;
1463+
}
1464+
1465+
if (hardif->soft_iface != soft_iface) {
1466+
ret = -ENOENT;
1467+
goto out;
1468+
}
1469+
}
1470+
1471+
if (!bat_priv->algo_ops->orig.dump) {
1472+
ret = -EOPNOTSUPP;
1473+
goto out;
1474+
}
1475+
1476+
bat_priv->algo_ops->orig.dump(msg, cb, bat_priv, hardif);
1477+
1478+
ret = msg->len;
1479+
1480+
out:
1481+
if (hardif)
1482+
batadv_hardif_put(hardif);
1483+
if (hard_iface)
1484+
dev_put(hard_iface);
1485+
if (primary_if)
1486+
batadv_hardif_put(primary_if);
1487+
if (soft_iface)
1488+
dev_put(soft_iface);
1489+
1490+
return ret;
1491+
}
1492+
13331493
int batadv_orig_hash_add_if(struct batadv_hard_iface *hard_iface,
13341494
int max_if_num)
13351495
{

net/batman-adv/originator.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131

3232
#include "hash.h"
3333

34+
struct netlink_callback;
3435
struct seq_file;
36+
struct sk_buff;
3537

3638
bool batadv_compare_orig(const struct hlist_node *node, const void *data2);
3739
int batadv_originator_init(struct batadv_priv *bat_priv);
@@ -61,6 +63,7 @@ batadv_neigh_ifinfo_get(struct batadv_neigh_node *neigh,
6163
struct batadv_hard_iface *if_outgoing);
6264
void batadv_neigh_ifinfo_put(struct batadv_neigh_ifinfo *neigh_ifinfo);
6365

66+
int batadv_hardif_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb);
6467
int batadv_hardif_neigh_seq_print_text(struct seq_file *seq, void *offset);
6568

6669
struct batadv_orig_ifinfo *
@@ -72,6 +75,7 @@ batadv_orig_ifinfo_new(struct batadv_orig_node *orig_node,
7275
void batadv_orig_ifinfo_put(struct batadv_orig_ifinfo *orig_ifinfo);
7376

7477
int batadv_orig_seq_print_text(struct seq_file *seq, void *offset);
78+
int batadv_orig_dump(struct sk_buff *msg, struct netlink_callback *cb);
7579
int batadv_orig_hardif_seq_print_text(struct seq_file *seq, void *offset);
7680
int batadv_orig_hash_add_if(struct batadv_hard_iface *hard_iface,
7781
int max_if_num);

net/batman-adv/types.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <linux/if_ether.h>
2929
#include <linux/kref.h>
3030
#include <linux/netdevice.h>
31+
#include <linux/netlink.h>
3132
#include <linux/sched.h> /* for linux/wait.h */
3233
#include <linux/spinlock.h>
3334
#include <linux/types.h>
@@ -1418,6 +1419,7 @@ struct batadv_algo_iface_ops {
14181419
* @is_similar_or_better: check if neigh1 is equally similar or better than
14191420
* neigh2 for their respective outgoing interface from the metric prospective
14201421
* @print: print the single hop neighbor list (optional)
1422+
* @dump: dump neighbors to a netlink socket (optional)
14211423
*/
14221424
struct batadv_algo_neigh_ops {
14231425
void (*hardif_init)(struct batadv_hardif_neigh_node *neigh);
@@ -1430,6 +1432,9 @@ struct batadv_algo_neigh_ops {
14301432
struct batadv_neigh_node *neigh2,
14311433
struct batadv_hard_iface *if_outgoing2);
14321434
void (*print)(struct batadv_priv *priv, struct seq_file *seq);
1435+
void (*dump)(struct sk_buff *msg, struct netlink_callback *cb,
1436+
struct batadv_priv *priv,
1437+
struct batadv_hard_iface *hard_iface);
14331438
};
14341439

14351440
/**
@@ -1441,6 +1446,7 @@ struct batadv_algo_neigh_ops {
14411446
* @del_if: ask the routing algorithm to apply the needed changes to the
14421447
* orig_node due to an hard-interface being removed from the mesh (optional)
14431448
* @print: print the originator table (optional)
1449+
* @dump: dump originators to a netlink socket (optional)
14441450
*/
14451451
struct batadv_algo_orig_ops {
14461452
void (*free)(struct batadv_orig_node *orig_node);
@@ -1449,6 +1455,9 @@ struct batadv_algo_orig_ops {
14491455
int del_if_num);
14501456
void (*print)(struct batadv_priv *priv, struct seq_file *seq,
14511457
struct batadv_hard_iface *hard_iface);
1458+
void (*dump)(struct sk_buff *msg, struct netlink_callback *cb,
1459+
struct batadv_priv *priv,
1460+
struct batadv_hard_iface *hard_iface);
14521461
};
14531462

14541463
/**

0 commit comments

Comments
 (0)