Skip to content

Commit d34f055

Browse files
neocturnesimonwunderlich
authored andcommitted
batman-adv: netlink: add translation table query
This adds the commands BATADV_CMD_GET_TRANSTABLE_LOCAL and BATADV_CMD_GET_TRANSTABLE_GLOBAL, which correspond to the transtable_local and transtable_global debugfs files. The batadv_tt_client_flags enum is moved to the UAPI to expose it as part of the netlink API. Signed-off-by: Matthias Schiffer <[email protected]> Signed-off-by: Andrew Lunn <[email protected]> [[email protected]: add policy for attributes, fix includes] Signed-off-by: Sven Eckelmann <[email protected]> [[email protected]: fix VID attributes content] Signed-off-by: Simon Wunderlich <[email protected]> Signed-off-by: Marek Lindner <[email protected]>
1 parent b60620c commit d34f055

File tree

6 files changed

+462
-37
lines changed

6 files changed

+462
-37
lines changed

include/uapi/linux/batman_adv.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,42 @@
2222

2323
#define BATADV_NL_MCAST_GROUP_TPMETER "tpmeter"
2424

25+
/**
26+
* enum batadv_tt_client_flags - TT client specific flags
27+
* @BATADV_TT_CLIENT_DEL: the client has to be deleted from the table
28+
* @BATADV_TT_CLIENT_ROAM: the client roamed to/from another node and the new
29+
* update telling its new real location has not been received/sent yet
30+
* @BATADV_TT_CLIENT_WIFI: this client is connected through a wifi interface.
31+
* This information is used by the "AP Isolation" feature
32+
* @BATADV_TT_CLIENT_ISOLA: this client is considered "isolated". This
33+
* information is used by the Extended Isolation feature
34+
* @BATADV_TT_CLIENT_NOPURGE: this client should never be removed from the table
35+
* @BATADV_TT_CLIENT_NEW: this client has been added to the local table but has
36+
* not been announced yet
37+
* @BATADV_TT_CLIENT_PENDING: this client is marked for removal but it is kept
38+
* in the table for one more originator interval for consistency purposes
39+
* @BATADV_TT_CLIENT_TEMP: this global client has been detected to be part of
40+
* the network but no nnode has already announced it
41+
*
42+
* Bits from 0 to 7 are called _remote flags_ because they are sent on the wire.
43+
* Bits from 8 to 15 are called _local flags_ because they are used for local
44+
* computations only.
45+
*
46+
* Bits from 4 to 7 - a subset of remote flags - are ensured to be in sync with
47+
* the other nodes in the network. To achieve this goal these flags are included
48+
* in the TT CRC computation.
49+
*/
50+
enum batadv_tt_client_flags {
51+
BATADV_TT_CLIENT_DEL = (1 << 0),
52+
BATADV_TT_CLIENT_ROAM = (1 << 1),
53+
BATADV_TT_CLIENT_WIFI = (1 << 4),
54+
BATADV_TT_CLIENT_ISOLA = (1 << 5),
55+
BATADV_TT_CLIENT_NOPURGE = (1 << 8),
56+
BATADV_TT_CLIENT_NEW = (1 << 9),
57+
BATADV_TT_CLIENT_PENDING = (1 << 10),
58+
BATADV_TT_CLIENT_TEMP = (1 << 11),
59+
};
60+
2561
/**
2662
* enum batadv_nl_attrs - batman-adv netlink attributes
2763
*
@@ -41,6 +77,14 @@
4177
* @BATADV_ATTR_TPMETER_COOKIE: session cookie to match tp_meter session
4278
* @BATADV_ATTR_PAD: attribute used for padding for 64-bit alignment
4379
* @BATADV_ATTR_ACTIVE: Flag indicating if the hard interface is active
80+
* @BATADV_ATTR_TT_ADDRESS: Client MAC address
81+
* @BATADV_ATTR_TT_TTVN: Translation table version
82+
* @BATADV_ATTR_TT_LAST_TTVN: Previous translation table version
83+
* @BATADV_ATTR_TT_CRC32: CRC32 over translation table
84+
* @BATADV_ATTR_TT_VID: VLAN ID
85+
* @BATADV_ATTR_TT_FLAGS: Translation table client flags
86+
* @BATADV_ATTR_FLAG_BEST: Flags indicating entry is the best
87+
* @BATADV_ATTR_LAST_SEEN_MSECS: Time in milliseconds since last seen
4488
* @__BATADV_ATTR_AFTER_LAST: internal use
4589
* @NUM_BATADV_ATTR: total number of batadv_nl_attrs available
4690
* @BATADV_ATTR_MAX: highest attribute number currently defined
@@ -62,6 +106,14 @@ enum batadv_nl_attrs {
62106
BATADV_ATTR_TPMETER_COOKIE,
63107
BATADV_ATTR_PAD,
64108
BATADV_ATTR_ACTIVE,
109+
BATADV_ATTR_TT_ADDRESS,
110+
BATADV_ATTR_TT_TTVN,
111+
BATADV_ATTR_TT_LAST_TTVN,
112+
BATADV_ATTR_TT_CRC32,
113+
BATADV_ATTR_TT_VID,
114+
BATADV_ATTR_TT_FLAGS,
115+
BATADV_ATTR_FLAG_BEST,
116+
BATADV_ATTR_LAST_SEEN_MSECS,
65117
/* add attributes above here, update the policy in netlink.c */
66118
__BATADV_ATTR_AFTER_LAST,
67119
NUM_BATADV_ATTR = __BATADV_ATTR_AFTER_LAST,
@@ -77,6 +129,8 @@ enum batadv_nl_attrs {
77129
* @BATADV_CMD_TP_METER_CANCEL: Cancel a tp meter session
78130
* @BATADV_CMD_GET_ROUTING_ALGOS: Query the list of routing algorithms.
79131
* @BATADV_CMD_GET_HARDIFS: Query list of hard interfaces
132+
* @BATADV_CMD_GET_TRANSTABLE_LOCAL: Query list of local translations
133+
* @BATADV_CMD_GET_TRANSTABLE_GLOBAL Query list of global translations
80134
* @__BATADV_CMD_AFTER_LAST: internal use
81135
* @BATADV_CMD_MAX: highest used command number
82136
*/
@@ -87,6 +141,8 @@ enum batadv_nl_commands {
87141
BATADV_CMD_TP_METER_CANCEL,
88142
BATADV_CMD_GET_ROUTING_ALGOS,
89143
BATADV_CMD_GET_HARDIFS,
144+
BATADV_CMD_GET_TRANSTABLE_LOCAL,
145+
BATADV_CMD_GET_TRANSTABLE_GLOBAL,
90146
/* add new commands above here */
91147
__BATADV_CMD_AFTER_LAST,
92148
BATADV_CMD_MAX = __BATADV_CMD_AFTER_LAST - 1

net/batman-adv/netlink.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "hard-interface.h"
4141
#include "soft-interface.h"
4242
#include "tp_meter.h"
43+
#include "translation-table.h"
4344

4445
struct genl_family batadv_netlink_family = {
4546
.id = GENL_ID_GENERATE,
@@ -73,6 +74,14 @@ static struct nla_policy batadv_netlink_policy[NUM_BATADV_ATTR] = {
7374
[BATADV_ATTR_TPMETER_BYTES] = { .type = NLA_U64 },
7475
[BATADV_ATTR_TPMETER_COOKIE] = { .type = NLA_U32 },
7576
[BATADV_ATTR_ACTIVE] = { .type = NLA_FLAG },
77+
[BATADV_ATTR_TT_ADDRESS] = { .len = ETH_ALEN },
78+
[BATADV_ATTR_TT_TTVN] = { .type = NLA_U8 },
79+
[BATADV_ATTR_TT_LAST_TTVN] = { .type = NLA_U8 },
80+
[BATADV_ATTR_TT_CRC32] = { .type = NLA_U32 },
81+
[BATADV_ATTR_TT_VID] = { .type = NLA_U16 },
82+
[BATADV_ATTR_TT_FLAGS] = { .type = NLA_U32 },
83+
[BATADV_ATTR_FLAG_BEST] = { .type = NLA_FLAG },
84+
[BATADV_ATTR_LAST_SEEN_MSECS] = { .type = NLA_U32 },
7685
};
7786

7887
/**
@@ -82,7 +91,7 @@ static struct nla_policy batadv_netlink_policy[NUM_BATADV_ATTR] = {
8291
*
8392
* Return: interface index, or 0.
8493
*/
85-
static int
94+
int
8695
batadv_netlink_get_ifindex(const struct nlmsghdr *nlh, int attrtype)
8796
{
8897
struct nlattr *attr = nlmsg_find_attr(nlh, GENL_HDRLEN, attrtype);
@@ -530,6 +539,18 @@ static struct genl_ops batadv_netlink_ops[] = {
530539
.policy = batadv_netlink_policy,
531540
.dumpit = batadv_netlink_dump_hardifs,
532541
},
542+
{
543+
.cmd = BATADV_CMD_GET_TRANSTABLE_LOCAL,
544+
.flags = GENL_ADMIN_PERM,
545+
.policy = batadv_netlink_policy,
546+
.dumpit = batadv_tt_local_dump,
547+
},
548+
{
549+
.cmd = BATADV_CMD_GET_TRANSTABLE_GLOBAL,
550+
.flags = GENL_ADMIN_PERM,
551+
.policy = batadv_netlink_policy,
552+
.dumpit = batadv_tt_global_dump,
553+
},
533554
};
534555

535556
/**

net/batman-adv/netlink.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@
2323
#include <linux/types.h>
2424
#include <net/genetlink.h>
2525

26+
struct nlmsghdr;
27+
2628
void batadv_netlink_register(void);
2729
void batadv_netlink_unregister(void);
30+
int batadv_netlink_get_ifindex(const struct nlmsghdr *nlh, int attrtype);
2831

2932
int batadv_netlink_tpmeter_notify(struct batadv_priv *bat_priv, const u8 *dst,
3033
u8 result, u32 test_time, u64 total_bytes,

net/batman-adv/packet.h

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -128,42 +128,6 @@ enum batadv_tt_data_flags {
128128
BATADV_TT_FULL_TABLE = BIT(4),
129129
};
130130

131-
/**
132-
* enum batadv_tt_client_flags - TT client specific flags
133-
* @BATADV_TT_CLIENT_DEL: the client has to be deleted from the table
134-
* @BATADV_TT_CLIENT_ROAM: the client roamed to/from another node and the new
135-
* update telling its new real location has not been received/sent yet
136-
* @BATADV_TT_CLIENT_WIFI: this client is connected through a wifi interface.
137-
* This information is used by the "AP Isolation" feature
138-
* @BATADV_TT_CLIENT_ISOLA: this client is considered "isolated". This
139-
* information is used by the Extended Isolation feature
140-
* @BATADV_TT_CLIENT_NOPURGE: this client should never be removed from the table
141-
* @BATADV_TT_CLIENT_NEW: this client has been added to the local table but has
142-
* not been announced yet
143-
* @BATADV_TT_CLIENT_PENDING: this client is marked for removal but it is kept
144-
* in the table for one more originator interval for consistency purposes
145-
* @BATADV_TT_CLIENT_TEMP: this global client has been detected to be part of
146-
* the network but no nnode has already announced it
147-
*
148-
* Bits from 0 to 7 are called _remote flags_ because they are sent on the wire.
149-
* Bits from 8 to 15 are called _local flags_ because they are used for local
150-
* computations only.
151-
*
152-
* Bits from 4 to 7 - a subset of remote flags - are ensured to be in sync with
153-
* the other nodes in the network. To achieve this goal these flags are included
154-
* in the TT CRC computation.
155-
*/
156-
enum batadv_tt_client_flags {
157-
BATADV_TT_CLIENT_DEL = BIT(0),
158-
BATADV_TT_CLIENT_ROAM = BIT(1),
159-
BATADV_TT_CLIENT_WIFI = BIT(4),
160-
BATADV_TT_CLIENT_ISOLA = BIT(5),
161-
BATADV_TT_CLIENT_NOPURGE = BIT(8),
162-
BATADV_TT_CLIENT_NEW = BIT(9),
163-
BATADV_TT_CLIENT_PENDING = BIT(10),
164-
BATADV_TT_CLIENT_TEMP = BIT(11),
165-
};
166-
167131
/**
168132
* enum batadv_vlan_flags - flags for the four MSB of any vlan ID field
169133
* @BATADV_VLAN_HAS_TAG: whether the field contains a valid vlan tag or not

0 commit comments

Comments
 (0)