All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/2] batctl: Prepare JSON commands
@ 2021-05-13 14:10 Alexander Sarmanow
  2021-05-13 14:10 ` [PATCH v3 1/2] batctl: main: Prepare DEBUGJSON command type Alexander Sarmanow
  2021-05-13 14:10 ` [PATCH v3 2/2] batctl: debug: Introduce handler for DEBUGJSON Alexander Sarmanow
  0 siblings, 2 replies; 5+ messages in thread
From: Alexander Sarmanow @ 2021-05-13 14:10 UTC (permalink / raw)
  To: sven; +Cc: b.a.t.m.a.n, sw, Alexander Sarmanow

This patches reffering to following patches:

[1] https://lists.open-mesh.org/mailman3/hyperkitty/list/b.a.t.m.a.n@lists.open-mesh.org/thread/SAQYUZQ7I7H7VWHFPVLBUDYCFX7HNWLO/
[2] https://lists.open-mesh.org/mailman3/hyperkitty/list/b.a.t.m.a.n@lists.open-mesh.org/thread/IV2OFJ2KJX52K4ARZ5MIWZ2A42WOKJRO/
[3] https://lists.open-mesh.org/mailman3/hyperkitty/list/b.a.t.m.a.n@lists.open-mesh.org/thread/EYQBFU5O7E3KKRG2YVPLRGHHN3OFIPYP/
[4] https://lists.open-mesh.org/mailman3/hyperkitty/list/b.a.t.m.a.n@lists.open-mesh.org/thread/WKIBP64G27O23MBAPHECSKNJMUESWFAG/
[5] https://lists.open-mesh.org/mailman3/hyperkitty/list/b.a.t.m.a.n@lists.open-mesh.org/thread/Y3XXIYCJWME4CQNWRBIRYJ6ZOL4MI2FT/
[6] https://lists.open-mesh.org/mailman3/hyperkitty/list/b.a.t.m.a.n@lists.open-mesh.org/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(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3 1/2] batctl: main: Prepare DEBUGJSON command type
  2021-05-13 14:10 [PATCH v3 0/2] batctl: Prepare JSON commands Alexander Sarmanow
@ 2021-05-13 14:10 ` Alexander Sarmanow
  2021-05-14 12:20   ` Sven Eckelmann
  2021-05-13 14:10 ` [PATCH v3 2/2] batctl: debug: Introduce handler for DEBUGJSON Alexander Sarmanow
  1 sibling, 1 reply; 5+ messages in thread
From: Alexander Sarmanow @ 2021-05-13 14:10 UTC (permalink / raw)
  To: sven; +Cc: b.a.t.m.a.n, sw, Alexander Sarmanow

The introduction of JSON debug commands requires a new command type.

Signed-off-by: Alexander Sarmanow <asarmanow@gmail.com>
---
 main.c       | 14 ++++++++++----
 main.h       |  1 +
 man/batctl.8 | 15 +++++++++++++--
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/main.c b/main.c
index d9b63f3..1371bc0 100644
--- a/main.c
+++ b/main.c
@@ -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;
 	}
diff --git a/main.h b/main.h
index 81b7a27..f5f00d2 100644
--- a/main.h
+++ b/main.h
@@ -69,6 +69,7 @@ enum command_type {
 	SUBCOMMAND_VID,
 	SUBCOMMAND_HIF,
 	DEBUGTABLE,
+	DEBUGJSON,
 };
 
 struct state {
diff --git a/man/batctl.8 b/man/batctl.8
index d490100..b2abedc 100644
--- a/man/batctl.8
+++ b/man/batctl.8
@@ -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
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 2/2] batctl: debug: Introduce handler for DEBUGJSON
  2021-05-13 14:10 [PATCH v3 0/2] batctl: Prepare JSON commands Alexander Sarmanow
  2021-05-13 14:10 ` [PATCH v3 1/2] batctl: main: Prepare DEBUGJSON command type Alexander Sarmanow
@ 2021-05-13 14:10 ` Alexander Sarmanow
  2021-05-14 16:15   ` Sven Eckelmann
  1 sibling, 1 reply; 5+ messages in thread
From: Alexander Sarmanow @ 2021-05-13 14:10 UTC (permalink / raw)
  To: sven; +Cc: b.a.t.m.a.n, sw, Alexander Sarmanow

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 <asarmanow@gmail.com>
---
 debug.c | 29 +++++++++++++++++++++++++++++
 debug.h |  5 +++++
 2 files changed, 34 insertions(+)

diff --git a/debug.c b/debug.c
index 458c137..20467c7 100644
--- a/debug.c
+++ b/debug.c
@@ -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;
+}
diff --git a/debug.h b/debug.h
index bfc6224..90f2e68 100644
--- a/debug.h
+++ b/debug.h
@@ -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
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 1/2] batctl: main: Prepare DEBUGJSON command type
  2021-05-13 14:10 ` [PATCH v3 1/2] batctl: main: Prepare DEBUGJSON command type Alexander Sarmanow
@ 2021-05-14 12:20   ` Sven Eckelmann
  0 siblings, 0 replies; 5+ messages in thread
From: Sven Eckelmann @ 2021-05-14 12:20 UTC (permalink / raw)
  To: Alexander Sarmanow; +Cc: b.a.t.m.a.n, Alexander Sarmanow

[-- Attachment #1: Type: text/plain, Size: 652 bytes --]

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

[...]
> +.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.

This makes no sense. The batman-adv kernel module doesn't come with debug JSON.

Kind regards,
	Sven

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 2/2] batctl: debug: Introduce handler for DEBUGJSON
  2021-05-13 14:10 ` [PATCH v3 2/2] batctl: debug: Introduce handler for DEBUGJSON Alexander Sarmanow
@ 2021-05-14 16:15   ` Sven Eckelmann
  0 siblings, 0 replies; 5+ messages in thread
From: Sven Eckelmann @ 2021-05-14 16:15 UTC (permalink / raw)
  To: Alexander Sarmanow; +Cc: b.a.t.m.a.n

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 <asarmanow@gmail.com>
> ---
>  debug.c | 29 +++++++++++++++++++++++++++++
>  debug.h |  5 +++++
>  2 files changed, 34 insertions(+)
> 
> diff --git a/debug.c b/debug.c
> index 458c137..20467c7 100644
> --- a/debug.c
> +++ b/debug.c

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-05-14 16:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-13 14:10 [PATCH v3 0/2] batctl: Prepare JSON commands Alexander Sarmanow
2021-05-13 14:10 ` [PATCH v3 1/2] batctl: main: Prepare DEBUGJSON command type Alexander Sarmanow
2021-05-14 12:20   ` Sven Eckelmann
2021-05-13 14:10 ` [PATCH v3 2/2] batctl: debug: Introduce handler for DEBUGJSON Alexander Sarmanow
2021-05-14 16:15   ` Sven Eckelmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.