[v8,1/2] batctl: Add attributes/command for BATADV_CMD_GET_MESH_INFO

Message ID 1462959332-23410-3-git-send-email-sven@open-mesh.com (mailing list archive)
State Accepted, archived
Delegated to: Marek Lindner
Headers

Commit Message

Sven Eckelmann May 11, 2016, 9:35 a.m. UTC
  From: Sven Eckelmann <sven.eckelmann@open-mesh.com>

BATADV_CMD_GET_MESH_INFO will be used as common function to retrieve
information from the kernel. This information can be used to display a
header for debugfs tables.

Signed-off-by: Sven Eckelmann <sven.eckelmann@open-mesh.com>
---
v8:
 * check *_IFNAME to not be larger than IFNAMSIZ as suggested by Antonio
 * rebase on current master
---
 batman_adv.h | 18 ++++++++++++++++++
 netlink.c    | 16 ++++++++++++++++
 2 files changed, 34 insertions(+)
  

Comments

Marek Lindner May 17, 2016, 9:19 a.m. UTC | #1
On Wednesday, May 11, 2016 11:35:31 Sven Eckelmann wrote:
> From: Sven Eckelmann <sven.eckelmann@open-mesh.com>
> 
> BATADV_CMD_GET_MESH_INFO will be used as common function to retrieve
> information from the kernel. This information can be used to display a
> header for debugfs tables.
> 
> Signed-off-by: Sven Eckelmann <sven.eckelmann@open-mesh.com>
> ---
> v8:
>  * check *_IFNAME to not be larger than IFNAMSIZ as suggested by Antonio
>  * rebase on current master
> ---
>  batman_adv.h | 18 ++++++++++++++++++
>  netlink.c    | 16 ++++++++++++++++
>  2 files changed, 34 insertions(+)

Applied (netlink.c section) in 071c16c.

Thanks,
Marek
  

Patch

diff --git a/batman_adv.h b/batman_adv.h
index ba611a7..a908140 100644
--- a/batman_adv.h
+++ b/batman_adv.h
@@ -24,12 +24,28 @@ 
  * enum batadv_nl_attrs - batman-adv netlink attributes
  *
  * @BATADV_ATTR_UNSPEC: unspecified attribute to catch errors
+ * @BATADV_ATTR_VERSION: batman-adv version string
+ * @BATADV_ATTR_ALGO_NAME: name of routing algorithm
+ * @BATADV_ATTR_MESH_IFINDEX: index of the batman-adv interface
+ * @BATADV_ATTR_MESH_IFNAME: name of the batman-adv interface
+ * @BATADV_ATTR_MESH_ADDRESS: mac address of the batman-adv interface
+ * @BATADV_ATTR_HARD_IFINDEX: index of the non-batman-adv interface
+ * @BATADV_ATTR_HARD_IFNAME: name of the non-batman-adv interface
+ * @BATADV_ATTR_HARD_ADDRESS: mac address of the non-batman-adv interface
  * @__BATADV_ATTR_AFTER_LAST: internal use
  * @NUM_BATADV_ATTR: total number of batadv_nl_attrs available
  * @BATADV_ATTR_MAX: highest attribute number currently defined
  */
 enum batadv_nl_attrs {
 	BATADV_ATTR_UNSPEC,
+	BATADV_ATTR_VERSION,
+	BATADV_ATTR_ALGO_NAME,
+	BATADV_ATTR_MESH_IFINDEX,
+	BATADV_ATTR_MESH_IFNAME,
+	BATADV_ATTR_MESH_ADDRESS,
+	BATADV_ATTR_HARD_IFINDEX,
+	BATADV_ATTR_HARD_IFNAME,
+	BATADV_ATTR_HARD_ADDRESS,
 	/* add attributes above here, update the policy in netlink.c */
 	__BATADV_ATTR_AFTER_LAST,
 	NUM_BATADV_ATTR = __BATADV_ATTR_AFTER_LAST,
@@ -40,11 +56,13 @@  enum batadv_nl_attrs {
  * enum batadv_nl_commands - supported batman-adv netlink commands
  *
  * @BATADV_CMD_UNSPEC: unspecified command to catch errors
+ * @BATADV_CMD_GET_MESH_INFO: Query basic information about batman-adv device
  * @__BATADV_CMD_AFTER_LAST: internal use
  * @BATADV_CMD_MAX: highest used command number
  */
 enum batadv_nl_commands {
 	BATADV_CMD_UNSPEC,
+	BATADV_CMD_GET_MESH_INFO,
 	/* add new commands above here */
 	__BATADV_CMD_AFTER_LAST,
 	BATADV_CMD_MAX = __BATADV_CMD_AFTER_LAST - 1
diff --git a/netlink.c b/netlink.c
index 409953a..74d7566 100644
--- a/netlink.c
+++ b/netlink.c
@@ -22,7 +22,23 @@ 
 #include "netlink.h"
 #include "main.h"
 
+#include <net/ethernet.h>
+
 #include "batman_adv.h"
 
 struct nla_policy batadv_netlink_policy[NUM_BATADV_ATTR] = {
+	[BATADV_ATTR_VERSION]		= { .type = NLA_STRING },
+	[BATADV_ATTR_ALGO_NAME]		= { .type = NLA_STRING },
+	[BATADV_ATTR_MESH_IFINDEX]	= { .type = NLA_U32 },
+	[BATADV_ATTR_MESH_IFNAME]	= { .type = NLA_STRING,
+					    .maxlen = IFNAMSIZ },
+	[BATADV_ATTR_MESH_ADDRESS]	= { .type = NLA_UNSPEC,
+					    .minlen = ETH_ALEN,
+					    .maxlen = ETH_ALEN },
+	[BATADV_ATTR_HARD_IFINDEX]	= { .type = NLA_U32 },
+	[BATADV_ATTR_HARD_IFNAME]	= { .type = NLA_STRING,
+					    .maxlen = IFNAMSIZ },
+	[BATADV_ATTR_HARD_ADDRESS]	= { .type = NLA_UNSPEC,
+					    .minlen = ETH_ALEN,
+					    .maxlen = ETH_ALEN },
 };