batctl: Prepare JSON commands
v3 cover batctl: Prepare JSON commands
This patches reffering to following patches:
[1] https://lists.open-mesh.org/mailman3/hyperkitty/list/[email protected]/thread/SAQYUZQ7I7H7VWHFPVLBUDYCFX7HNWLO/
[2] https://lists.open-mesh.org/mailman3/hyperkitty/list/[email protected]/thread/IV2OFJ2KJX52K4ARZ5MIWZ2A42WOKJRO/
[3] https://lists.open-mesh.org/mailman3/hyperkitty/list/[email protected]/thread/EYQBFU5O7E3KKRG2YVPLRGHHN3OFIPYP/
[4] https://lists.open-mesh.org/mailman3/hyperkitty/list/[email protected]/thread/WKIBP64G27O23MBAPHECSKNJMUESWFAG/
[5] https://lists.open-mesh.org/mailman3/hyperkitty/list/[email protected]/thread/Y3XXIYCJWME4CQNWRBIRYJ6ZOL4MI2FT/
[6] https://lists.open-mesh.org/mailman3/hyperkitty/list/[email protected]/thread/LYMU5ZA3I6YVHHRZVY3RJJR4KDHF76QI/
Alexander Sarmanow (2):
batctl: main: Prepare DEBUGJSON command type
batctl: debug: Introduce handler for DEBUGJSON
debug.c | 29 +++++++++++++++++++++++++++++ debug.h | 5 +++++ main.c | 14 ++++++++++---- main.h | 1 + man/batctl.8 | 15 +++++++++++++-- 5 files changed, 58 insertions(+), 6 deletions(-)
Signature · 1 line
2.25.1
PATCH v3 1/2 batctl: main: Prepare DEBUGJSON command type
The introduction of JSON debug commands requires a new command type.
--- main.c | 14 ++++++++++---- main.h | 1 + man/batctl.8 | 15 +++++++++++++-- 3 files changed, 24 insertions(+), 6 deletions(-)
main.c +10 -4
@@ -43,6 +43,10 @@ static void print_usage(void) .label = "debug tables: \tdisplay the corresponding debug table\n", .types = BIT(DEBUGTABLE), }, + { + .label = "debug JSONs: \tdisplay the corresponding debug JSON\n", + .types = BIT(DEBUGJSON), + }, };const char *default_prefixes[] = {"" ,
@@ -67,9 +71,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++) {
@@ -87,6 +91,7 @@ static void print_usage(void)continue ;switch (cmd->type) { +case DEBUGJSON :case DEBUGTABLE :case SUBCOMMAND_MIF : prefixes = meshif_prefixes;
@@ -167,7 +172,8 @@ 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 (DEBUGJSON );break ;case SP_VLAN : types =BIT (SUBCOMMAND_VID );
@@ -380,7 +386,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; }
main.h +1 -0
@@ -69,6 +69,7 @@ enum command_type {SUBCOMMAND_VID ,SUBCOMMAND_HIF ,DEBUGTABLE , + DEBUGJSON, }; struct state {
man/batctl.8 +13 -2
@@ -27,11 +27,11 @@ .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 -such as originator tables, translation tables and the debug log. In combination with a bat\-hosts file batctl allows +such as originator tables/JSON, translation tables/JSON and the debug log. In combination with a bat\-hosts file batctl allows the use of host names instead of MAC addresses. .PP B.A.T.M.A.N. advanced operates on layer 2. Thus all hosts participating in the virtual switched network are transparently
@@ -294,6 +294,17 @@ List of debug tables: .RE .RE .br +.br +.PP +.I \fBdebug JSONs: +.IP +The batman-adv kernel module comes with a variety of debug JSONs containing various information about the state of the mesh +seen by each individual node. + +.RS 7 +List of debug JSONs: +.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
Signature · 1 line
2.25.1
Re: [PATCH v3 1/2] batctl: main: Prepare DEBUGJSON command type
Quoted 1 line · On Thursday, 13 May 2021 16:10:33 CEST Alexander Sarmanow wrote:
The introduction of JSON debug commands requires a new command type.
You only added a DEBUGJSON for MIF. But you would also need one for HIF and VID
And then you will not only print the "debug" tables but just the netlink query answers. So it should be called differently
[...]
man/batctl.8 List of debug tables: · line 302
Quoted 6 lines
+.br
+.PP
+.I \fBdebug JSONs:
+.IPman/batctl.8 +2
-0+The batman-adv kernel module comes with a variety of debug JSONs containing various information about the state of the mesh +seen by each individual node.
This makes no sense. The batman-adv kernel module doesn't come with debug JSON.
Kind regards,
Sven
PATCH v3 2/2 batctl: debug: Introduce handler for DEBUGJSON
In reply to Alexander SarmanowDEBUGJSON commands require an own handler, since they may have their own parameters. So far there is currently only the help parameter, but more can be added in future.
--- debug.c | 29 +++++++++++++++++++++++++++++ debug.h | 5 +++++ 2 files changed, 34 insertions(+)
debug.c +29 -0
@@ -42,6 +42,14 @@ static void debug_table_usage(struct state *state)fprintf (stderr," \t -m print multicast mac addresses only\n" ); } +static void debug_json_usage (struct state *state) +{ +fprintf (stderr,"Usage: batctl [options] %s|%s [parameters]\n" , + state->cmd->name, state->cmd->abbr); +fprintf (stderr,"parameters:\n" ); +fprintf (stderr," \t -h print this help\n" ); +} +int handle_debug_table (struct state *state,int argc,char **argv) {struct debug_table_data *debug_table = state->cmd->arg;
@@ -148,3 +156,24 @@ int handle_debug_table(struct state *state, int argc, char **argv) orig_timeout, watch_interval);return err; } + +int handle_debug_json (struct state *state,int argc,char **argv) +{ +struct debug_json_data *debug_json = state->cmd->arg; +int optchar; +int err; + +while ((optchar =getopt (argc, argv,"h" )) !=-1 ) { +switch (optchar) { +case 'h' : +debug_json_usage (state); +return EXIT_SUCCESS ; + } + } + +check_root_or_die ("batctl" ); + + err = debug_json->netlink_fn (state); + +return err; +}
debug.h +5 -0
@@ -21,6 +21,11 @@ struct debug_table_data { unsigned int option_orig_iface:1; }; +struct debug_json_data { +int (*netlink_fn)(struct state *state); +}; +int handle_debug_table (struct state *state,int argc,char **argv); +int handle_debug_json (struct state *state,int argc,char **argv);#endif
Signature · 1 line
2.25.1
Re: [PATCH v3 2/2] batctl: debug: Introduce handler for DEBUGJSON
debug.c
Quoted 14 lines · On Thursday, 13 May 2021 16:10:34 CEST Alexander Sarmanow wrote:
DEBUGJSON commands require an own handler, since they may have their own parameters. So far there is currently only the help parameter, but more can be added in future.
Signed-off-by Alexander Sarmanow <[email protected]>--- debug.c | 29 +++++++++++++++++++++++++++++ debug.h | 5 +++++ 2 files changed, 34 insertions(+)debug.c +0
-0
These commands are not for debug tables and would better fit in the the genl_json file (or something similar).
And a lot of functionality is missing here. You basically duplicated the same function in the actual neighbors_json, originators_json, transglobal_json and translocal_json files. Stuff which could have been handled globally for the netlink queries with JSON output.
Kind regards,
Sven