[v3,2/2] batctl: debug: Introduce handler for DEBUGJSON
Commit Message
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(+)
Comments
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
@@ -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;
+}
@@ -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