@@ -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))
@@ -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
================
@@ -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
new file mode 100644
@@ -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, "");