Repository : ssh://git@diktynna/batctl
On branch : master
commit 8005298091034d3838f0070e6436fe263695d585 Author: Alexander Sarmanow asarmanow@gmail.com Date: Thu May 13 16:10:33 2021 +0200
batctl: Introduce JSON_* command types
The JSON_MIF, JSON_HIF and JSON_VID subcommand types will provide access to the various batadv generic netlink query types. This will allow a consumer to query the state of a batadv interface (and its hard-interfaces/vlans) without the need to:
* understand the details of generic netlink and the batadv family * parse the text response of the debug tables or other subcommands
These commands can become a way to retrieve the information in a machine readable way but they must be considered at the moment as "experimental" and changes in the structure might still happpen.
Signed-off-by: Alexander Sarmanow asarmanow@gmail.com [sven@narfation.org: fix commit message, cleanup changes, split up in vid/mif/hif types, fix manpage] Signed-off-by: Sven Eckelmann sven@narfation.org
8005298091034d3838f0070e6436fe263695d585 main.c | 24 ++++++++++++++++++------ main.h | 3 +++ man/batctl.8 | 16 +++++++++++++++- 3 files changed, 36 insertions(+), 7 deletions(-)
diff --git a/main.c b/main.c index d9b63f3..d20539f 100644 --- a/main.c +++ b/main.c @@ -43,6 +43,12 @@ static void print_usage(void) .label = "debug tables: \tdisplay the corresponding debug table\n", .types = BIT(DEBUGTABLE), }, + { + .label = "JSON queries: \tdisplay results of netlink query as JSON\n", + .types = BIT(JSON_MIF) | + BIT(JSON_VID) | + BIT(JSON_HIF), + }, }; const char *default_prefixes[] = { "", @@ -67,9 +73,9 @@ static void print_usage(void) char buf[64]; size_t i;
- fprintf(stderr, "Usage: batctl [options] command|debug table [parameters]\n"); + fprintf(stderr, "Usage: batctl [options] command|debug table|debug json [parameters]\n"); fprintf(stderr, "options:\n"); - fprintf(stderr, " \t-h print this help (or 'batctl <command|debug table> -h' for the parameter help)\n"); + fprintf(stderr, " \t-h print this help (or 'batctl <command|debug table|debug json> -h' for the parameter help)\n"); fprintf(stderr, " \t-v print version\n");
for (i = 0; i < sizeof(type) / sizeof(*type); i++) { @@ -88,12 +94,15 @@ static void print_usage(void)
switch (cmd->type) { case DEBUGTABLE: + case JSON_MIF: case SUBCOMMAND_MIF: prefixes = meshif_prefixes; break; + case JSON_VID: case SUBCOMMAND_VID: prefixes = vlan_prefixes; break; + case JSON_HIF: case SUBCOMMAND_HIF: prefixes = hardif_prefixes; break; @@ -167,13 +176,16 @@ static const struct command *find_command(struct state *state, const char *name) /* fall through */ case SP_MESHIF: types |= BIT(SUBCOMMAND_MIF) | - BIT(DEBUGTABLE); + BIT(DEBUGTABLE) | + BIT(JSON_MIF); break; case SP_VLAN: - types = BIT(SUBCOMMAND_VID); + types = BIT(JSON_VID) | + BIT(SUBCOMMAND_VID); break; case SP_HARDIF: - types = BIT(SUBCOMMAND_HIF); + types = BIT(JSON_HIF) | + BIT(SUBCOMMAND_HIF); break; default: return NULL; @@ -380,7 +392,7 @@ int main(int argc, char **argv) cmd = find_command(&state, argv[0]); if (!cmd) { fprintf(stderr, - "Error - no valid command or debug table specified: %s\n", + "Error - no valid command or debug table/JSON specified: %s\n", argv[0]); goto err; } diff --git a/main.h b/main.h index 81b7a27..6b4cd76 100644 --- a/main.h +++ b/main.h @@ -69,6 +69,9 @@ enum command_type { SUBCOMMAND_VID, SUBCOMMAND_HIF, DEBUGTABLE, + JSON_MIF, + JSON_VID, + JSON_HIF, };
struct state { diff --git a/man/batctl.8 b/man/batctl.8 index bc0dfb6..ce78fca 100644 --- a/man/batctl.8 +++ b/man/batctl.8 @@ -27,7 +27,7 @@ .SH NAME batctl - B.A.T.M.A.N. advanced control and management tool .SH SYNOPSIS -.B batctl [\fIoptions\fP]\ \fIcommand\fP|\fIdebug\ table\fP\ [\fIparameters\fP] +.B batctl [\fIoptions\fP]\ \fIcommand\fP|\fIdebug\ table\fP|\fIdebug\ JSON\fP\ [\fIparameters\fP] .br .SH DESCRIPTION batctl offers a convenient way to configure the batman-adv kernel module as well as displaying debug information @@ -293,6 +293,20 @@ List of debug tables: .RE .RE .br +.br +.PP +.I \fBJSON queries: +.IP +The generic netlink family provided by the batman-adv kernel module can be +queried (read-only) by batctl and automatically translated to JSON. This +can be used to monitor the state of the system without the need of parsing +the freeform debug tables or the native netlink messages. + + +.RS 7 +List of available JSON queries: +.RE +.br .IP "[\fBmeshif <netdev>\fP] \fBtranslate\fP|\fBt\fP \fBMAC_address\fP|\fBbat-host_name\fP|\fBhost_name\fP|\fBIP_address\fP"
Translates a destination (hostname, IP, MAC, bat_host-name) to the originator