Following JSON debug commands will be added: originators_json, neighbors_json, translocal_json, transglobal_json.
This patches reffering to following patches:
[1] https://lists.open-mesh.org/mailman3/hyperkitty/list/b.a.t.m.a.n@lists.open-... [2] https://lists.open-mesh.org/mailman3/hyperkitty/list/b.a.t.m.a.n@lists.open-... [3] https://lists.open-mesh.org/mailman3/hyperkitty/list/b.a.t.m.a.n@lists.open-... [4] https://lists.open-mesh.org/mailman3/hyperkitty/list/b.a.t.m.a.n@lists.open-... [5] https://lists.open-mesh.org/mailman3/hyperkitty/list/b.a.t.m.a.n@lists.open-... [6] https://lists.open-mesh.org/mailman3/hyperkitty/list/b.a.t.m.a.n@lists.open-... [7] https://lists.open-mesh.org/mailman3/hyperkitty/list/b.a.t.m.a.n@lists.open-... [8] https://lists.open-mesh.org/mailman3/hyperkitty/list/b.a.t.m.a.n@lists.open-...
Alexander Sarmanow (4): batctl: originators_json: Add originators_json command batctl: neighbors_json: Add neighbors_json command batctl: transglobal_json: Add transglobal_json command batctl: translocal_json: Add translocal_json command
Makefile | 4 +++ README.rst | 60 +++++++++++++++++++++++++++++++++ man/batctl.8 | 12 +++++++ neighbors_json.c | 82 ++++++++++++++++++++++++++++++++++++++++++++ originators_json.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++ transglobal_json.c | 81 ++++++++++++++++++++++++++++++++++++++++++++ translocal_json.c | 81 ++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 404 insertions(+) create mode 100644 neighbors_json.c create mode 100644 originators_json.c create mode 100644 transglobal_json.c create mode 100644 translocal_json.c
This is the JSON analogue of the originators table. By using the netlink_query_common function to query the available netlink attributes.
Signed-off-by: Alexander Sarmanow asarmanow@gmail.com --- Makefile | 1 + README.rst | 15 +++++++++ man/batctl.8 | 3 ++ originators_json.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 originators_json.c
diff --git a/Makefile b/Makefile index cee4f0c..9dfcfde 100755 --- a/Makefile +++ b/Makefile @@ -62,6 +62,7 @@ $(eval $(call add_command,neighbors,y)) $(eval $(call add_command,network_coding,y)) $(eval $(call add_command,orig_interval,y)) $(eval $(call add_command,originators,y)) +$(eval $(call add_command,originators_json,y)) $(eval $(call add_command,ping,y)) $(eval $(call add_command,routing_algo,y)) $(eval $(call add_command,statistics,y)) diff --git a/README.rst b/README.rst index 9c55ad5..c884bb3 100644 --- a/README.rst +++ b/README.rst @@ -356,6 +356,21 @@ Example:: fe:f0:00:00:01:01 0.510s (255) fe:f0:00:00:01:01 [ eth0]: fe:f1:00:00:01:01 (240) fe:f0:00:00:01:01 (255)
+batctl originators_json +======================= + +Check the Originators JSON (it's a JSON analogue of the Originators table) + +Usage:: + + batctl originators_json|oj + +Example:: + + $ batctl originators_json + [{"hard_ifindex":7,"orig_address":"fe:fe:00:00:01:01","best":true,"last_seen_msecs":700,"neigh_address":"fe:fe:00:00:02:01","tq":119},{"hard_ifindex":2,"orig_address":"fe:fe:00:00:03:01","best":true,"last_seen_msecs":1040,"neigh_address":"fe:fe:00:00:02:01","tq":116},{"hard_ifindex":7,"orig_address":"fe:fe:00:00:04:01","best":true,"last_seen_msecs":700,"neigh_address":"fe:fe:00:00:02:01","tq":119},{"hard_ifindex":2,"orig_address":"fe:fe:00:00:05:01","best":true,"last_seen_msecs":270,"neigh_address":"fe:fe:00:00:02:01","tq":140},{"hard_ifindex":2,"orig_address":"fe:fe:00:00:06:01","best":true,"last_seen_msecs":770,"neigh_address":"fe:fe:00:00:02:01","tq":91}] + + batctl interface ================
diff --git a/man/batctl.8 b/man/batctl.8 index b2abedc..155791d 100644 --- a/man/batctl.8 +++ b/man/batctl.8 @@ -303,6 +303,9 @@ seen by each individual node.
.RS 7 List of debug JSONs: +.RS 10 +- originators_json|oj +.RE .RE .br .IP "[\fBmeshif <netdev>\fP] \fBtranslate\fP|\fBt\fP \fBMAC_address\fP|\fBbat-host_name\fP|\fBhost_name\fP|\fBIP_address\fP" diff --git a/originators_json.c b/originators_json.c new file mode 100644 index 0000000..fc71098 --- /dev/null +++ b/originators_json.c @@ -0,0 +1,84 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) B.A.T.M.A.N. contributors: + * + * Alexander Sarmanow asarmanow@gmail.com + * + * License-Filename: LICENSES/preferred/GPL-2.0 + */ + +#include <errno.h> +#include <net/if.h> +#include <netinet/if_ether.h> +#include <netlink/netlink.h> +#include <netlink/genl/genl.h> +#include <netlink/genl/ctrl.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include <string.h> + +#include "batman_adv.h" +#include "debug.h" +#include "main.h" +#include "netlink.h" +#include "genl_json.h" + +static int originators_json_callback(struct nl_msg *msg, void *arg) +{ + struct nlattr *attrs[BATADV_ATTR_MAX+1]; + struct nlmsghdr *nlh = nlmsg_hdr(msg); + struct nlquery_opts *query_opts = arg; + struct json_opts *json_opts; + struct genlmsghdr *ghdr; + + json_opts = container_of(query_opts, struct json_opts, query_opts); + + if (!genlmsg_valid_hdr(nlh, 0)) { + fputs("Received invalid data from kernel.\n", stderr); + exit(1); + } + + ghdr = nlmsg_data(nlh); + + if (ghdr->cmd != BATADV_CMD_GET_ORIGINATORS) + return NL_OK; + + if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0), + genlmsg_len(ghdr), batadv_netlink_policy)) { + fputs("Received invalid data from kernel.\n", stderr); + exit(1); + } + + netlink_print_json_entries(attrs, json_opts); + json_opts->is_first = 0; + + return NL_OK; +} + +static int netlink_print_originators_json(struct state *state) +{ + int ret; + struct json_opts json_opts = { + .is_first = 1, + .query_opts = { + .err = 0, + }, + }; + + putc('[', stdout); + ret = netlink_query_common(state, state->mesh_ifindex, + BATADV_CMD_GET_ORIGINATORS, + originators_json_callback, + NLM_F_DUMP, &json_opts.query_opts); + puts("]\n"); + + return ret; +} + +static struct debug_json_data batctl_debug_json_originators = { + .netlink_fn = netlink_print_originators_json, +}; + +COMMAND_NAMED(DEBUGJSON, originators_json, "oj", handle_debug_json, + COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK, + &batctl_debug_json_originators, "");
This is the JSON analogue of the neighbors table. By using the netlink_query_common function to query the available netlink attributes.
Signed-off-by: Alexander Sarmanow asarmanow@gmail.com --- Makefile | 1 + README.rst | 15 +++++++++ man/batctl.8 | 3 ++ neighbors_json.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+) create mode 100644 neighbors_json.c
diff --git a/Makefile b/Makefile index 9dfcfde..874dc2f 100755 --- a/Makefile +++ b/Makefile @@ -59,6 +59,7 @@ $(eval $(call add_command,multicast_fanout,y)) $(eval $(call add_command,multicast_forceflood,y)) $(eval $(call add_command,multicast_mode,y)) $(eval $(call add_command,neighbors,y)) +$(eval $(call add_command,neighbors_json,y)) $(eval $(call add_command,network_coding,y)) $(eval $(call add_command,orig_interval,y)) $(eval $(call add_command,originators,y)) diff --git a/README.rst b/README.rst index c884bb3..f0ce43a 100644 --- a/README.rst +++ b/README.rst @@ -371,6 +371,21 @@ Example:: [{"hard_ifindex":7,"orig_address":"fe:fe:00:00:01:01","best":true,"last_seen_msecs":700,"neigh_address":"fe:fe:00:00:02:01","tq":119},{"hard_ifindex":2,"orig_address":"fe:fe:00:00:03:01","best":true,"last_seen_msecs":1040,"neigh_address":"fe:fe:00:00:02:01","tq":116},{"hard_ifindex":7,"orig_address":"fe:fe:00:00:04:01","best":true,"last_seen_msecs":700,"neigh_address":"fe:fe:00:00:02:01","tq":119},{"hard_ifindex":2,"orig_address":"fe:fe:00:00:05:01","best":true,"last_seen_msecs":270,"neigh_address":"fe:fe:00:00:02:01","tq":140},{"hard_ifindex":2,"orig_address":"fe:fe:00:00:06:01","best":true,"last_seen_msecs":770,"neigh_address":"fe:fe:00:00:02:01","tq":91}]
+batctl neighbors_json +===================== + +display the Neighbors JSON (analogue of the neighbors table) + +Usage:: + + batctl neighbors_json + +Example:: + + $ batctl neighbors_json|nj + [{"hard_ifindex":2,"last_seen_msecs":650,"neigh_address":"fe:fe:00:00:01:01"},{"hard_ifindex":2,"last_seen_msecs":650,"neigh_address":"fe:fe:00:00:01:02"}] + + batctl interface ================
diff --git a/man/batctl.8 b/man/batctl.8 index 155791d..1130a81 100644 --- a/man/batctl.8 +++ b/man/batctl.8 @@ -304,6 +304,9 @@ seen by each individual node. .RS 7 List of debug JSONs: .RS 10 +- neighbors_json|nj +.RE +.RS 10 - originators_json|oj .RE .RE diff --git a/neighbors_json.c b/neighbors_json.c new file mode 100644 index 0000000..7051c63 --- /dev/null +++ b/neighbors_json.c @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) B.A.T.M.A.N. contributors: + * + * Alexander Sarmanow asarmanow@gmail.com + * + * License-Filename: LICENSES/preferred/GPL-2.0 + */ + +#include <net/if.h> +#include <netinet/if_ether.h> +#include <netlink/netlink.h> +#include <netlink/genl/genl.h> +#include <netlink/genl/ctrl.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> + +#include "batman_adv.h" +#include "debug.h" +#include "main.h" +#include "netlink.h" +#include "genl_json.h" + +static int neighbors_json_callback(struct nl_msg *msg, void *arg) +{ + struct nlattr *attrs[BATADV_ATTR_MAX+1]; + struct nlmsghdr *nlh = nlmsg_hdr(msg); + struct nlquery_opts *query_opts = arg; + struct json_opts *json_opts; + struct genlmsghdr *ghdr; + + json_opts = container_of(query_opts, struct json_opts, query_opts); + + if (!genlmsg_valid_hdr(nlh, 0)) { + fputs("Received invalid data from kernel.\n", stderr); + exit(1); + } + + ghdr = nlmsg_data(nlh); + + if (ghdr->cmd != BATADV_CMD_GET_NEIGHBORS) + return NL_OK; + + if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0), + genlmsg_len(ghdr), batadv_netlink_policy)) { + fputs("Received invalid data from kernel.\n", stderr); + exit(1); + } + + netlink_print_json_entries(attrs, json_opts); + json_opts->is_first = 0; + + return NL_OK; +} + +static int netlink_print_neighbors_json(struct state *state) +{ + int ret; + struct json_opts json_opts = { + .is_first = 1, + .query_opts = { + .err = 0, + }, + }; + + putc('[', stdout); + ret = netlink_query_common(state, state->mesh_ifindex, + BATADV_CMD_GET_NEIGHBORS, + neighbors_json_callback, + NLM_F_DUMP, &json_opts.query_opts); + puts("]\n"); + + return ret; +} + +static struct debug_json_data batctl_debug_json_neighbors = { + .netlink_fn = netlink_print_neighbors_json, +}; + +COMMAND_NAMED(DEBUGJSON, neighbors_json, "nj", handle_debug_json, + COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK, + &batctl_debug_json_neighbors, "");
This is the JSON analogue of the transglobal table. By using the netlink_query_common function to query the available netlink attributes.
Signed-off-by: Alexander Sarmanow asarmanow@gmail.com --- Makefile | 1 + README.rst | 15 +++++++++ man/batctl.8 | 3 ++ transglobal_json.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+) create mode 100644 transglobal_json.c
diff --git a/Makefile b/Makefile index 874dc2f..cea3271 100755 --- a/Makefile +++ b/Makefile @@ -72,6 +72,7 @@ $(eval $(call add_command,throughput_override,y)) $(eval $(call add_command,throughputmeter,y)) $(eval $(call add_command,traceroute,y)) $(eval $(call add_command,transglobal,y)) +$(eval $(call add_command,transglobal_json,y)) $(eval $(call add_command,translate,y)) $(eval $(call add_command,translocal,y))
diff --git a/README.rst b/README.rst index f0ce43a..905e313 100644 --- a/README.rst +++ b/README.rst @@ -687,6 +687,21 @@ Flags that mean: If any of the flags is not enabled, a '.' will substitute its symbol.
+batctl transglobal_json +======================= + +display the global translation JSON (analogue of the transglobal table) + +Usage:: + + batctl transglobal_json|tgj + +Example:: + + $ batctl translglobal_json + [{"orig_address":"fe:fe:00:00:01:01","tt_address":"33:33:00:00:00:01","tt_ttvn":3,"last_ttvn":3,"crc32":1916279217,"tt_vid":0,"tt_flags":0,"best":true},{"orig_address":"fe:fe:00:00:01:02","tt_address":"33:33:00:00:00:02","tt_ttvn":3,"last_ttvn":3,"crc32":1916279217,"tt_vid":0,"tt_flags":0}] + + batctl dat_cache =================
diff --git a/man/batctl.8 b/man/batctl.8 index 1130a81..97d5738 100644 --- a/man/batctl.8 +++ b/man/batctl.8 @@ -309,6 +309,9 @@ List of debug JSONs: .RS 10 - originators_json|oj .RE +.RS 10 +- transglobal_json|tgj +.RE .RE .br .IP "[\fBmeshif <netdev>\fP] \fBtranslate\fP|\fBt\fP \fBMAC_address\fP|\fBbat-host_name\fP|\fBhost_name\fP|\fBIP_address\fP" diff --git a/transglobal_json.c b/transglobal_json.c new file mode 100644 index 0000000..612ffb8 --- /dev/null +++ b/transglobal_json.c @@ -0,0 +1,81 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) B.A.T.M.A.N. contributors: + * + * Alexander Sarmanow asarmanow@gmail.com + * + * License-Filename: LICENSES/preferred/GPL-2.0 + */ + +#include <netinet/if_ether.h> +#include <netlink/netlink.h> +#include <netlink/genl/genl.h> +#include <netlink/genl/ctrl.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> + +#include "batman_adv.h" +#include "debug.h" +#include "main.h" +#include "netlink.h" +#include "genl_json.h" + +static int transglobal_json_callback(struct nl_msg *msg, void *arg) +{ + struct nlquery_opts *query_opts = arg; + struct json_opts *json_opts; + struct nlattr *attrs[BATADV_ATTR_MAX+1]; + struct nlmsghdr *nlh = nlmsg_hdr(msg); + struct genlmsghdr *ghdr; + + json_opts = container_of(query_opts, struct json_opts, query_opts); + + if (!genlmsg_valid_hdr(nlh, 0)) { + fputs("Received invalid data from kernel.\n", stderr); + exit(1); + } + + ghdr = nlmsg_data(nlh); + + if (ghdr->cmd != BATADV_CMD_GET_TRANSTABLE_GLOBAL) + return NL_OK; + + if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0), + genlmsg_len(ghdr), batadv_netlink_policy)) { + fputs("Received invalid data from kernel.\n", stderr); + exit(1); + } + + netlink_print_json_entries(attrs, json_opts); + json_opts->is_first = 0; + + return NL_OK; +} + +static int netlink_print_transglobal_json(struct state *state) +{ + int ret; + struct json_opts json_opts = { + .is_first = 1, + .query_opts = { + .err = 0, + }, + }; + + putc('[', stdout); + ret = netlink_query_common(state, state->mesh_ifindex, + BATADV_CMD_GET_TRANSTABLE_GLOBAL, + transglobal_json_callback, + NLM_F_DUMP, &json_opts.query_opts); + puts("]\n"); + + return ret; +} + +static struct debug_json_data batctl_debug_json_transglobal = { + .netlink_fn = netlink_print_transglobal_json, +}; + +COMMAND_NAMED(DEBUGJSON, transglobal_json, "tgj", handle_debug_json, + COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK, + &batctl_debug_json_transglobal, "");
This is the JSON analogue of the translocal table. By using the netlink_query_common function to query the available netlink attributes.
Signed-off-by: Alexander Sarmanow asarmanow@gmail.com --- Makefile | 1 + README.rst | 15 +++++++++ man/batctl.8 | 3 ++ translocal_json.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+) create mode 100644 translocal_json.c
diff --git a/Makefile b/Makefile index cea3271..8afbdbe 100755 --- a/Makefile +++ b/Makefile @@ -75,6 +75,7 @@ $(eval $(call add_command,transglobal,y)) $(eval $(call add_command,transglobal_json,y)) $(eval $(call add_command,translate,y)) $(eval $(call add_command,translocal,y)) +$(eval $(call add_command,translocal_json,y))
MANPAGE = man/batctl.8
diff --git a/README.rst b/README.rst index 905e313..065c0ab 100644 --- a/README.rst +++ b/README.rst @@ -651,6 +651,21 @@ W/Wireless: If any of the flags is not enabled, a '.' will substitute its symbol.
+batctl translocal_json +====================== + +display the local translation JSON (analogue of the translocal table) + +Usage:: + + batctl translocal_json|tlj + +Example:: + + $ batctl translocal_json + [{"tt_address":"33:33:00:00:00:01","crc32":2147984693,"tt_vid":0,"tt_flags":256},{"tt_address":"33:33:00:00:00:01","crc32":2147984693,"tt_vid":0,"tt_flags":256},{"tt_address":"11:11:00:00:00:03","crc32":2147984693,"tt_vid":0,"tt_flags":256}] + + batctl transglobal ==================
diff --git a/man/batctl.8 b/man/batctl.8 index 97d5738..2b8a975 100644 --- a/man/batctl.8 +++ b/man/batctl.8 @@ -310,6 +310,9 @@ List of debug JSONs: - originators_json|oj .RE .RS 10 +- translocal_json|tlj +.RE +.RS 10 - transglobal_json|tgj .RE .RE diff --git a/translocal_json.c b/translocal_json.c new file mode 100644 index 0000000..38b64a0 --- /dev/null +++ b/translocal_json.c @@ -0,0 +1,81 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) B.A.T.M.A.N. contributors: + * + * Alexander Sarmanow asarmanow@gmail.com + * + * License-Filename: LICENSES/preferred/GPL-2.0 + */ + +#include <netinet/if_ether.h> +#include <netlink/netlink.h> +#include <netlink/genl/genl.h> +#include <netlink/genl/ctrl.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> + +#include "batman_adv.h" +#include "debug.h" +#include "main.h" +#include "netlink.h" +#include "genl_json.h" + +static int translocal_json_callback(struct nl_msg *msg, void *arg) +{ + struct nlquery_opts *query_opts = arg; + struct json_opts *json_opts; + struct nlattr *attrs[BATADV_ATTR_MAX+1]; + struct nlmsghdr *nlh = nlmsg_hdr(msg); + struct genlmsghdr *ghdr; + + json_opts = container_of(query_opts, struct json_opts, query_opts); + + if (!genlmsg_valid_hdr(nlh, 0)) { + fputs("Received invalid data from kernel.\n", stderr); + exit(1); + } + + ghdr = nlmsg_data(nlh); + + if (ghdr->cmd != BATADV_CMD_GET_TRANSTABLE_LOCAL) + return NL_OK; + + if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0), + genlmsg_len(ghdr), batadv_netlink_policy)) { + fputs("Received invalid data from kernel.\n", stderr); + exit(1); + } + + netlink_print_json_entries(attrs, json_opts); + json_opts->is_first = 0; + + return NL_OK; +} + +static int netlink_print_translocal_json(struct state *state) +{ + int ret; + struct json_opts json_opts = { + .is_first = 1, + .query_opts = { + .err = 0, + }, + }; + + putc('[', stdout); + ret = netlink_query_common(state, state->mesh_ifindex, + BATADV_CMD_GET_TRANSTABLE_LOCAL, + translocal_json_callback, + NLM_F_DUMP, &json_opts.query_opts); + puts("]\n"); + + return ret; +} + +static struct debug_json_data batctl_debug_json_translocal = { + .netlink_fn = netlink_print_translocal_json, +}; + +COMMAND_NAMED(DEBUGJSON, translocal_json, "tlj", handle_debug_json, + COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK, + &batctl_debug_json_translocal, "");
On Thursday, 13 May 2021 16:28:08 CEST Alexander Sarmanow wrote:
Following JSON debug commands will be added: originators_json, neighbors_json, translocal_json, transglobal_json.
Seems like this patchset is full of duplicated code which would have belonged as shared code in an earlier patch.
At the same time, a lot of functionality (batadv genl query commands) is missing - even stuff which was present in an earlier version of the patchset.
Kind regards, Sven
b.a.t.m.a.n@lists.open-mesh.org