Skip to contentSkip to conversation

batctl: pre-netlink restructuring, part 1

PATCH In review Sven Eckelmann 1 participant 44 messages Oct 25, 2018 – Nov 3, 2018 Kbuild

lore
Share & tools
lore
#0 lore raw

v3 cover batctl: pre-netlink restructuring, part 1

Hi,

the batctl command already has support to get (previously debugfs) tables via netlink. It does this while still being able to fall back to the old debugfs tables on kernels which don't support the new generic netlink family.

Something similar should be done in the future for the settings which are currently part of sysfs. But we can already see that the current integration of netlink in batctl only done in a single file - netlink.c But this file is already starting to be so big that working with it is rather cumbersome.

So as first steps:

* restructure command registration
* move commands in separate files (which should store their actual implementation)
* add a new helper command to receive multicast group messages from the kernel

More things will follow in the future.

Changes:

v3:

* correctly split ap_isolation and bonding patch
* fix copyright headers for new files
* move more routing_algo specific code to its command specific file
* fix build problems with musl in OpenWrt 18.06
* switch Makefile's OBJ + OBJ_BISECT to obj-y and obj-n
* add way to "freely" disable some commands for size optimization reasons

- it is for example now possible to reduce the size of the batctl on mips_24kc_musl from 64604 bytes to 14252 bytes when only the interface commands are required (I know, stupid example)
- the binary to generate the debug tables output for the same architectur

    used 26988 bytes

v2:

* Add missing orig_interval.c

Kind regards,
Sven

Sven Eckelmann (42):
batctl: Drop unused define SOCKET_PATH_FMT
batctl: Use common code organization for statistics
batctl: Drop legacy vis_* related warning messages
batctl: Move loglevel command to separate file
batctl: Move log command to separate file
batctl: Move gw_mode command to separate file
batctl: Move routing_algo command to separate file
batctl: Rename tp_meter to throughputmeter
batctl: Introduce datastructure for subcommands
batctl: Add per command flags
batctl: Use command structure for remaining subcommands
batctl: Use getopt to parse main options
batctl: Store usage line next to command
batctl: Prepare command infrastructure for shared functions
batctl: Add type to command to structure usage output
batctl: Convert debug table to command infrastructure
batctl: Convert sysfs settings to command infrastructure
batctl: Move backbonetable debug table to own file
batctl: Move claimtable debug table to own file
batctl: Move dat_cache debug table to own file
batctl: Move gateways debug table to own file
batctl: Move mcast_flags debug table to own file
batctl: Move nc_nodes debug table to own file
batctl: Move neighbors debug table to own file
batctl: Move originators debug table to own file
batctl: Move transglobal debug table to own file
batctl: Move translocal debug table to own file
batctl: Move aggregation setting to own file
batctl: Move ap_isolation setting to own file
batctl: Move bonding setting to own file
batctl: Move bridge_loop_avoidance setting to own file
batctl: Move distributed_arp_table setting to own file
batctl: Move fragmentation setting to own file
batctl: Move isolation_mark setting to own file
batctl: Move multicast_mode setting to own file
batctl: Move network_coding setting to own file
batctl: Move orig_interval setting to own file
batctl: Use external netlink socket for debug tables
batctl: Move routing_algo specific code it command source file
batctl: Add command to monitor for netlink events
batctl: Simplify enabling for bisect_iv subcommand
batctl: Allow to enable/disable subcommands

 Makefile                        |   91 ++-
 translate.h => aggregation.c    |   15 +-
 ap_isolation.c                  |   33 +
 backbonetable.c                 |  126 ++++
 bisect_iv.c                     |    6 +-
 bisect_iv.h                     |    4 -
 traceroute.h => bonding.c       |   15 +-
 bridge_loop_avoidance.c         |   33 +
 claimtable.c                    |  131 ++++
 dat_cache.c                     |  147 +++++
 debug.c                         |  218 +------
 debug.h                         |   38 +-
 distributed_arp_table.c         |   33 +
 event.c                         |  246 ++++++++
 ping.h => fragmentation.c       |   15 +-
 functions.c                     |   28 +-
 functions.h                     |    1 -
 gateways.c                      |  175 +++++
 gw_mode.c                       |  171 +++++
 interface.c                     |   23 +-
 ioctl.h                         |   28 -
 isolation_mark.c                |   35 +
 log.c                           |   73 +++
 loglevel.c                      |  147 +++++
 main.c                          |  274 ++++----
 main.h                          |   65 +-
 man/batctl.8                    |    4 +
 mcast_flags.c                   |  180 ++++++
 multicast_mode.c                |   33 +
 interface.h => nc_nodes.c       |   14 +-
 neighbors.c                     |  142 +++++
 netlink.c                       | 1332 ++++-----------------------------------
 netlink.h                       |   55 +-
 network_coding.c                |   33 +
 orig_interval.c                 |   35 +
 originators.c                   |  228 +++++++
 ping.c                          |   10 +-
 routing_algo.c                  |  263 ++++++++
 ioctl.c => statistics.c         |   10 +-
 sys.c                           |  432 +------------
 sys.h                           |   39 +-
 tcpdump.c                       |    5 +-
 tcpdump.h                       |    2 -
 tp_meter.c => throughputmeter.c |   10 +-
 tp_meter.h                      |   28 -
 traceroute.c                    |   10 +-
 transglobal.c                   |  162 +++++
 translate.c                     |    8 +-
 translocal.c                    |  158 +++++
 49 files changed, 3156 insertions(+), 2208 deletions(-)
 rename translate.h => aggregation.c (67%)
 create mode 100644 ap_isolation.c
 create mode 100644 backbonetable.c
 rename traceroute.h => bonding.c (68%)
 create mode 100644 bridge_loop_avoidance.c
 create mode 100644 claimtable.c
 create mode 100644 dat_cache.c
 create mode 100644 distributed_arp_table.c
 create mode 100644 event.c
 rename ping.h => fragmentation.c (67%)
 create mode 100644 gateways.c
 create mode 100644 gw_mode.c
 delete mode 100644 ioctl.h
 create mode 100644 isolation_mark.c
 create mode 100644 log.c
 create mode 100644 loglevel.c
 create mode 100644 mcast_flags.c
 create mode 100644 multicast_mode.c
 rename interface.h => nc_nodes.c (73%)
 create mode 100644 neighbors.c
 create mode 100644 network_coding.c
 create mode 100644 orig_interval.c
 create mode 100644 originators.c
 create mode 100644 routing_algo.c
 rename ioctl.c => statistics.c (90%)
 rename tp_meter.c => throughputmeter.c (97%)
 delete mode 100644 tp_meter.h
 create mode 100644 transglobal.c
 create mode 100644 translocal.c
Signature · 1 line
2.11.0
#1 lore raw

PATCH v3 1/42 batctl: Drop unused define SOCKET_PATH_FMT

The commit 4bd751eed4dc ("batctl: Implement non-routing batadv_icmp in userspace") removed the last code section which referenced SOCKET_PATH_FMT.

---
 main.h | 2 --
 1 file changed, 2 deletions(-)
main.h +0 -2
index 5cd2f46..e8c6db7 100644
@@ -29,8 +29,6 @@
 #define SOURCE_VERSION "2018.4"
 #endif
 
-#define SOCKET_PATH_FMT "%s/batman_adv/%s/socket"
-
 #define EXIT_NOSUCCESS 2
 
 #define OPT_LONG_MAX_LEN 25
Signature · 1 line
2.11.0
#2 lore raw

PATCH v3 2/42 batctl: Use common code organization for statistics

In reply to Sven Eckelmann

Most commands have a separate file which is called like command itself. They also tend to share the same function signature to make it easier to use. Do the same for the ethtool statistics to make it easier to find.

---
 Makefile                | 2 +-
 main.c                  | 4 ++--
 ioctl.c => statistics.c | 6 ++++--
 ioctl.h => statistics.h | 6 +++---
 4 files changed, 10 insertions(+), 8 deletions(-)
 rename ioctl.c => statistics.c (95%)
 rename ioctl.h => statistics.h (88%)
Makefile +1 -1
index 4b417d5..6f620be 100755
@@ -34,10 +34,10 @@ OBJ += genl.o
 OBJ += hash.o
 OBJ += icmp_helper.o
 OBJ += interface.o
-OBJ += ioctl.o
 OBJ += main.o
 OBJ += netlink.o
 OBJ += ping.o
+OBJ += statistics.o
 OBJ += sys.o
 OBJ += tcpdump.o
 OBJ += tp_meter.o
main.c +2 -2
index d5504e0..e904a1f 100644
@@ -37,7 +37,7 @@
 #include "tcpdump.h"
 #include "tp_meter.h"
 #include "bisect_iv.h"
-#include "ioctl.h"
+#include "statistics.h"
 #include "functions.h"
 
 char mesh_dfl_iface[] = "bat0";
@@ -187,7 +187,7 @@ int main(int argc, char **argv)
 
 	} else if ((strcmp(argv[1], "statistics") == 0) || (strcmp(argv[1], "s") == 0)) {
 
-		ret = ioctl_statistics_get(mesh_iface);
+		ret = statistics(mesh_iface, argc - 1, argv + 1);
 
 	} else if ((strcmp(argv[1], "translate") == 0) || (strcmp(argv[1], "t") == 0)) {
 
statistics.c renamed from ioctl.c +4 -2
similarity index 95%
rename from ioctl.c
rename to statistics.c
index 6f9a056..8a889ca 100644
@@ -34,7 +34,8 @@
 #include <linux/ethtool.h>
 #include <stdint.h>
 
-#include "ioctl.h"
+#include "main.h"
+#include "statistics.h"
 
 void check_root_or_die(const char *cmd);
 
@@ -102,7 +103,8 @@ static int statistics_custom_get(int fd, struct ifreq *ifr)
 	return ret;
 }
 
-int ioctl_statistics_get(char *mesh_iface)
+int statistics(char *mesh_iface, int argc __maybe_unused,
+	       char **argv __maybe_unused)
 {
 	struct ifreq ifr;
 	int fd = -1, ret = EXIT_FAILURE;
statistics.h renamed from ioctl.h +3 -3
similarity index 88%
rename from ioctl.h
rename to statistics.h
index 1b216c0..3737a48 100644
@@ -20,9 +20,9 @@
  * License-Filename: LICENSES/preferred/GPL-2.0
  */
 
-#ifndef _BATCTL_IOCTL_H
-#define _BATCTL_IOCTL_H
+#ifndef _BATCTL_STATISTICS_H
+#define _BATCTL_STATISTICS_H
 
-int ioctl_statistics_get(char *mesh_iface);
+int statistics(char *mesh_iface, int argc, char **argv);
 
 #endif
Signature · 1 line
2.11.0
#3 lore raw

PATCH v3 3/42 batctl: Drop legacy vis_* related warning messages

In reply to Sven Eckelmann

The vis support code was removed with batman-adv 2014.0.0 (Linux 3.13). All kernel versions with up to this version are EOL for a while and also batctl warned now about this problem for nearly 5 years. It should therefore no (serious) problem to remove these warning messages.

---
 debug.c | 28 ----------------------------
 debug.h |  1 -
 main.c  |  6 ------
 3 files changed, 35 deletions(-)
debug.c +0 -28
index 63fb633..185e26d 100644
@@ -269,34 +269,6 @@ int debug_print_routing_algos(void)
 	return read_file(full_path, DEBUG_ROUTING_ALGOS, 0, 0, 0, 0);
 }
 
-int print_vis_info(char *mesh_iface)
-{
-	char full_path[MAX_PATH+1];
-	char *debugfs_mnt;
-	FILE *fp;
-
-	check_root_or_die("batctl vis_data");
-
-	debugfs_mnt = debugfs_mount(NULL);
-	if (!debugfs_mnt) {
-		fprintf(stderr, "Error - can't mount or find debugfs\n");
-		return -1;
-	}
-
-	debugfs_make_path(DEBUG_BATIF_PATH_FMT "/vis_data", mesh_iface, full_path, sizeof(full_path));
-	fp = fopen(full_path, "r");
-	if (fp) {
-		fclose(fp);
-		fprintf(stderr, "Error - batctl version is newer than kernel module - the kernel module still supports\n"
-				"vis, but later versions will not. The vis functionality has been moved to the userspace\n"
-				"daemon ''alfred''. Please either downgrade to an older (compatible) batctl version or use alfred.\n");
-	} else {
-		fprintf(stderr, "Error - The installed batctl version and kernel module don't have vis support. The vis functionality\n"
-				"has been moved to the userspace daemon ''alfred''.\n");
-	}
-	return 0;
-}
-
 static void log_usage(void)
 {
 	fprintf(stderr, "Usage: batctl [options] log [parameters]\n");
debug.h +0 -1
index 9c57aa6..5508eaf 100644
@@ -59,6 +59,5 @@ extern const struct debug_table_data batctl_debug_tables[BATCTL_TABLE_NUM];
 int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv);
 int log_print(char *mesh_iface, int argc, char **argv);
 int debug_print_routing_algos(void);
-int print_vis_info(char *mesh_iface);
 
 #endif
main.c +0 -6
index e904a1f..3a6011b 100644
@@ -175,12 +175,6 @@ int main(int argc, char **argv)
 
 		ret = log_print(mesh_iface, argc - 1, argv + 1);
 
-        /* vis legacy support */
-	} else if ((strcmp(argv[1], "vis_data") == 0) || (strcmp(argv[1], "vd") == 0) ||
-	           (strcmp(argv[1], "vis_mode") == 0) || (strcmp(argv[1], "vm") == 0)) {
-
-		ret = print_vis_info(mesh_iface);
-
 	} else if ((strcmp(argv[1], "gw_mode") == 0) || (strcmp(argv[1], "gw") == 0)) {
 
 		ret = handle_gw_setting(mesh_iface, argc - 1, argv + 1);
Signature · 1 line
2.11.0
#4 lore raw

PATCH v3 4/42 batctl: Move loglevel command to separate file

In reply to Sven Eckelmann

More complex commands in batctl are stored in separate files which are called like the actual command name. This makes it easier to group functionality and detect which parts belong to a more complex construct.

---
 Makefile   |   1 +
 loglevel.c | 144 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 loglevel.h |  28 ++++++++++++
 main.c     |   3 +-
 sys.c      | 114 ------------------------------------------------
 sys.h      |   1 -
 6 files changed, 175 insertions(+), 116 deletions(-)
 create mode 100644 loglevel.c
 create mode 100644 loglevel.h
Makefile +1 -0
index 6f620be..1271200 100755
@@ -34,6 +34,7 @@ OBJ += genl.o
 OBJ += hash.o
 OBJ += icmp_helper.o
 OBJ += interface.o
+OBJ += loglevel.o
 OBJ += main.o
 OBJ += netlink.o
 OBJ += ping.o
loglevel.c new file +144 -0

144 lines not on this page · raw message

loglevel.h new file +28 -0
new file mode 100644
index 0000000..2644f46
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2009-2018  B.A.T.M.A.N. contributors:
+ *
+ * Marek Lindner <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ *
+ * License-Filename: LICENSES/preferred/GPL-2.0
+ */
+
+#ifndef _BATCTL_LOGLEVEL_H
+#define _BATCTL_LOGLEVEL_H
+
+int loglevel(char *mesh_iface, int argc, char **argv);
+
+#endif
main.c +2 -1
index 3a6011b..ac4bc47 100644
@@ -38,6 +38,7 @@
 #include "tp_meter.h"
 #include "bisect_iv.h"
 #include "statistics.h"
+#include "loglevel.h"
 #include "functions.h"
 
 char mesh_dfl_iface[] = "bat0";
@@ -169,7 +170,7 @@ int main(int argc, char **argv)
 
 	} else if ((strcmp(argv[1], "loglevel") == 0) || (strcmp(argv[1], "ll") == 0)) {
 
-		ret = handle_loglevel(mesh_iface, argc - 1, argv + 1);
+		ret = loglevel(mesh_iface, argc - 1, argv + 1);
 
 	} else if ((strcmp(argv[1], "log") == 0) || (strcmp(argv[1], "l") == 0)) {
 
sys.c +0 -114

120 lines not on this page · raw message

sys.h +0 -1
index 95b2a1e..5e98ab1 100644
@@ -71,7 +71,6 @@ extern const char *sysfs_param_enable[];
 extern const char *sysfs_param_server[];
 extern const struct settings_data batctl_settings[BATCTL_SETTINGS_NUM];
 
-int handle_loglevel(char *mesh_iface, int argc, char **argv);
 int handle_sys_setting(char *mesh_iface, int setting, int argc, char **argv);
 int handle_gw_setting(char *mesh_iface, int argc, char **argv);
 int handle_ra_setting(int argc, char **argv);
Signature · 1 line
2.11.0
#5 lore raw

PATCH v3 5/42 batctl: Move log command to separate file

In reply to Sven Eckelmann

More complex commands in batctl are stored in separate files which are called like the actual command name. This makes it easier to group functionality and detect which parts belong to a more complex construct.

---
 Makefile |  1 +
 debug.c  | 41 -------------------------------------
 debug.h  |  1 -
 log.c    | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 log.h    | 28 ++++++++++++++++++++++++++
 main.c   |  1 +
 6 files changed, 100 insertions(+), 42 deletions(-)
 create mode 100644 log.c
 create mode 100644 log.h
Makefile +1 -0
index 1271200..a988058 100755
@@ -35,6 +35,7 @@ OBJ += hash.o
 OBJ += icmp_helper.o
 OBJ += interface.o
 OBJ += loglevel.o
+OBJ += log.o
 OBJ += main.o
 OBJ += netlink.o
 OBJ += ping.o
debug.c +0 -41

44 lines not on this page · raw message

debug.h +0 -1
index 5508eaf..d9a2e3a 100644
@@ -57,7 +57,6 @@ struct debug_table_data {
 extern const struct debug_table_data batctl_debug_tables[BATCTL_TABLE_NUM];
 
 int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv);
-int log_print(char *mesh_iface, int argc, char **argv);
 int debug_print_routing_algos(void);
 
 #endif
log.c new file +70 -0

70 lines not on this page · raw message

log.h new file +28 -0
new file mode 100644
index 0000000..4ba00e3
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2009-2018  B.A.T.M.A.N. contributors:
+ *
+ * Marek Lindner <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ *
+ * License-Filename: LICENSES/preferred/GPL-2.0
+ */
+
+#ifndef _BATCTL_LOG_H
+#define _BATCTL_LOG_H
+
+int log_print(char *mesh_iface, int argc, char **argv);
+
+#endif
main.c +1 -0
index ac4bc47..5b3e570 100644
@@ -39,6 +39,7 @@
 #include "bisect_iv.h"
 #include "statistics.h"
 #include "loglevel.h"
+#include "log.h"
 #include "functions.h"
 
 char mesh_dfl_iface[] = "bat0";
Signature · 1 line
2.11.0
#6 lore raw

PATCH v3 6/42 batctl: Move gw_mode command to separate file

In reply to Sven Eckelmann

More complex commands in batctl are stored in separate files which are called like the actual command name. This makes it easier to group functionality and detect which parts belong to a more complex construct.

---
 Makefile  |   1 +
 gw_mode.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 gw_mode.h |  28 +++++++++++
 main.c    |   3 +-
 sys.c     | 129 -----------------------------------------------
 sys.h     |  10 ----
 6 files changed, 199 insertions(+), 140 deletions(-)
 create mode 100644 gw_mode.c
 create mode 100644 gw_mode.h
Makefile +1 -0
index a988058..9b960b6 100755
@@ -31,6 +31,7 @@ OBJ += debugfs.o
 OBJ += debug.o
 OBJ += functions.o
 OBJ += genl.o
+OBJ += gw_mode.o
 OBJ += hash.o
 OBJ += icmp_helper.o
 OBJ += interface.o
gw_mode.c new file +168 -0

168 lines not on this page · raw message

gw_mode.h new file +28 -0
new file mode 100644
index 0000000..d4d3fb5
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2009-2018  B.A.T.M.A.N. contributors:
+ *
+ * Marek Lindner <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ *
+ * License-Filename: LICENSES/preferred/GPL-2.0
+ */
+
+#ifndef _BATCTL_GW_MODE_H
+#define _BATCTL_GW_MODE_H
+
+int gw_mode(char *mesh_iface, int argc, char **argv);
+
+#endif
main.c +2 -1
index 5b3e570..6160a72 100644
@@ -40,6 +40,7 @@
 #include "statistics.h"
 #include "loglevel.h"
 #include "log.h"
+#include "gw_mode.h"
 #include "functions.h"
 
 char mesh_dfl_iface[] = "bat0";
@@ -179,7 +180,7 @@ int main(int argc, char **argv)
 
 	} else if ((strcmp(argv[1], "gw_mode") == 0) || (strcmp(argv[1], "gw") == 0)) {
 
-		ret = handle_gw_setting(mesh_iface, argc - 1, argv + 1);
+		ret = gw_mode(mesh_iface, argc - 1, argv + 1);
 
 	} else if ((strcmp(argv[1], "statistics") == 0) || (strcmp(argv[1], "s") == 0)) {
 
sys.c +0 -129

135 lines not on this page · raw message

sys.h +0 -10
index 5e98ab1..e1d0f9b 100644
@@ -28,9 +28,6 @@
 #define SYS_BATIF_PATH_FMT	"/sys/class/net/%s/mesh/"
 #define SYS_LOG_LEVEL		"log_level"
 #define SYS_LOG			"log"
-#define SYS_GW_MODE		"gw_mode"
-#define SYS_GW_SEL		"gw_sel_class"
-#define SYS_GW_BW		"gw_bandwidth"
 #define SYS_IFACE_PATH		"/sys/class/net"
 #define SYS_IFACE_DIR		SYS_IFACE_PATH"/%s/"
 #define SYS_MESH_IFACE_FMT	SYS_IFACE_PATH"/%s/batman_adv/mesh_iface"
@@ -54,12 +51,6 @@ enum batctl_settings_list {
 	BATCTL_SETTINGS_NUM,
 };
 
-enum gw_modes {
-	GW_MODE_OFF,
-	GW_MODE_CLIENT,
-	GW_MODE_SERVER,
-};
-
 struct settings_data {
 	const char opt_long[OPT_LONG_MAX_LEN];
 	const char opt_short[OPT_SHORT_MAX_LEN];
@@ -72,7 +63,6 @@ extern const char *sysfs_param_server[];
 extern const struct settings_data batctl_settings[BATCTL_SETTINGS_NUM];
 
 int handle_sys_setting(char *mesh_iface, int setting, int argc, char **argv);
-int handle_gw_setting(char *mesh_iface, int argc, char **argv);
 int handle_ra_setting(int argc, char **argv);
 
 #endif
Signature · 1 line
2.11.0
#7 lore raw

PATCH v3 7/42 batctl: Move routing_algo command to separate file

In reply to Sven Eckelmann

More complex commands in batctl are stored in separate files which are called like the actual command name. This makes it easier to group functionality and detect which parts belong to a more complex construct.

---
 Makefile       |   1 +
 main.c         |   3 +-
 routing_algo.c | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 routing_algo.h |  28 +++++++++++++
 sys.c          |  92 -----------------------------------------
 sys.h          |   3 --
 6 files changed, 158 insertions(+), 96 deletions(-)
 create mode 100644 routing_algo.c
 create mode 100644 routing_algo.h
Makefile +1 -0
index 9b960b6..9ff4fe4 100755
@@ -40,6 +40,7 @@ OBJ += log.o
 OBJ += main.o
 OBJ += netlink.o
 OBJ += ping.o
+OBJ += routing_algo.o
 OBJ += statistics.o
 OBJ += sys.o
 OBJ += tcpdump.o
main.c +2 -1
index 6160a72..4abee13 100644
@@ -41,6 +41,7 @@
 #include "loglevel.h"
 #include "log.h"
 #include "gw_mode.h"
+#include "routing_algo.h"
 #include "functions.h"
 
 char mesh_dfl_iface[] = "bat0";
@@ -153,7 +154,7 @@ int main(int argc, char **argv)
 #endif
 	} else if ((strcmp(argv[1], "routing_algo") == 0) || (strcmp(argv[1], "ra") == 0)) {
 
-		ret = handle_ra_setting(argc - 1, argv + 1);
+		ret = routing_algo(mesh_iface, argc - 1, argv + 1);
 
 	} else if (check_mesh_iface(mesh_iface) < 0) {
 		fprintf(stderr, "Error - interface %s is not present or not a batman-adv interface\n", mesh_iface);
routing_algo.c new file +127 -0

127 lines not on this page · raw message

routing_algo.h new file +28 -0
new file mode 100644
index 0000000..db246c6
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2009-2018  B.A.T.M.A.N. contributors:
+ *
+ * Marek Lindner <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ *
+ * License-Filename: LICENSES/preferred/GPL-2.0
+ */
+
+#ifndef _BATCTL_ROUTING_ALGO_H
+#define _BATCTL_ROUTING_ALGO_H
+
+int routing_algo(char *mesh_iface, int argc, char **argv);
+
+#endif
sys.c +0 -92

95 lines not on this page · raw message

sys.h +0 -3
index e1d0f9b..5f0280f 100644
@@ -33,8 +33,6 @@
 #define SYS_MESH_IFACE_FMT	SYS_IFACE_PATH"/%s/batman_adv/mesh_iface"
 #define SYS_IFACE_STATUS_FMT	SYS_IFACE_PATH"/%s/batman_adv/iface_status"
 #define SYS_VLAN_PATH		SYS_IFACE_PATH"/%s/mesh/vlan%d/"
-#define SYS_ROUTING_ALGO_FMT	SYS_IFACE_PATH"/%s/mesh/routing_algo"
-#define SYS_SELECTED_RA_PATH	"/sys/module/batman_adv/parameters/routing_algo"
 #define VLAN_ID_MAX_LEN		4
 
 enum batctl_settings_list {
@@ -63,6 +61,5 @@ extern const char *sysfs_param_server[];
 extern const struct settings_data batctl_settings[BATCTL_SETTINGS_NUM];
 
 int handle_sys_setting(char *mesh_iface, int setting, int argc, char **argv);
-int handle_ra_setting(int argc, char **argv);
 
 #endif
Signature · 1 line
2.11.0
#8 lore raw

PATCH v3 8/42 batctl: Rename tp_meter to throughputmeter

In reply to Sven Eckelmann

The command itself is called throughputmeter but the file and function is called tp_meter. Use "throughputmeter" for both to make it easier to identify the correct source file.

---
 Makefile                        | 2 +-
 main.c                          | 4 ++--
 tp_meter.c => throughputmeter.c | 4 ++--
 tp_meter.h => throughputmeter.h | 8 ++++----
 4 files changed, 9 insertions(+), 9 deletions(-)
 rename tp_meter.c => throughputmeter.c (99%)
 rename tp_meter.h => throughputmeter.h (83%)
Makefile +1 -1
index 9ff4fe4..b4777b7 100755
@@ -44,7 +44,7 @@ OBJ += routing_algo.o
 OBJ += statistics.o
 OBJ += sys.o
 OBJ += tcpdump.o
-OBJ += tp_meter.o
+OBJ += throughputmeter.o
 OBJ += traceroute.o
 OBJ += translate.o
 OBJ_BISECT = bisect_iv.o
main.c +2 -2
index 4abee13..34f5a62 100644
@@ -35,7 +35,7 @@
 #include "translate.h"
 #include "traceroute.h"
 #include "tcpdump.h"
-#include "tp_meter.h"
+#include "throughputmeter.h"
 #include "bisect_iv.h"
 #include "statistics.h"
 #include "loglevel.h"
@@ -165,7 +165,7 @@ int main(int argc, char **argv)
 
 	} else if ((strcmp(argv[1], "throughputmeter") == 0) || (strcmp(argv[1], "tp") == 0)) {
 
-		ret = tp_meter (mesh_iface, argc -1, argv + 1);
+		ret = throughputmeter(mesh_iface, argc -1, argv + 1);
 
 	} else if ((strcmp(argv[1], "traceroute") == 0) || (strcmp(argv[1], "tr") == 0)) {
 
throughputmeter.c renamed from tp_meter.c +2 -2
similarity index 99%
rename from tp_meter.c
rename to throughputmeter.c
index c790485..bb53d56 100644
@@ -21,7 +21,7 @@
  */
 
 #include "main.h"
-#include "tp_meter.h"
+#include "throughputmeter.h"
 
 #include <netinet/ether.h>
 #include <netinet/in.h>
@@ -389,7 +389,7 @@ static void tp_meter_usage(void)
 	fprintf(stderr, "\t -n don't convert addresses to bat-host names\n");
 }
 
-int tp_meter(char *mesh_iface, int argc, char **argv)
+int throughputmeter(char *mesh_iface, int argc, char **argv)
 {
 	struct bat_host *bat_host;
 	uint64_t throughput;
throughputmeter.h renamed from tp_meter.h +4 -4
similarity index 83%
rename from tp_meter.h
rename to throughputmeter.h
index 72006ba..2c04c12 100644
@@ -20,9 +20,9 @@
  * License-Filename: LICENSES/preferred/GPL-2.0
  */
 
-#ifndef _BATCTL_TP_METER_H
-#define _BATCTL_TP_METER_H
+#ifndef _BATCTL_THROUGHPUTMETER_H
+#define _BATCTL_THROUGHPUTMETER_H
 
-int tp_meter(char *mesh_iface, int argc, char **argv);
+int throughputmeter(char *mesh_iface, int argc, char **argv);
 
-#endif /* _BATCTL_TP_METER_H */
+#endif /* _BATCTL_THROUGHPUTMETER_H */
Signature · 1 line
2.11.0
#9 lore raw

PATCH v3 9/42 batctl: Introduce datastructure for subcommands

In reply to Sven Eckelmann

The registration of more complex subcommands in batctl required a lot of extra code to get it integrated in the main routine. This lead to a hard to read main function which switches between the subcommand which performs an action.

The command structure allows us to provide an simpler way to insert functionality. It currently only works for complete separated commands which operates on already existing batman-adv interface. But it is flexible enough to later also support the rest of the commands.

---
 gw_mode.c         |  4 +++-
 gw_mode.h         | 28 -------------------------
 log.c             |  4 +++-
 log.h             | 28 -------------------------
 loglevel.c        |  4 +++-
 loglevel.h        | 28 -------------------------
 main.c            | 63 ++++++++++++++++++++-----------------------------------
 main.h            | 18 ++++++++++++++++
 ping.c            |  5 +++--
 ping.h            | 28 -------------------------
 statistics.c      |  7 ++++---
 statistics.h      | 28 -------------------------
 throughputmeter.c |  5 +++--
 throughputmeter.h | 28 -------------------------
 traceroute.c      |  5 +++--
 traceroute.h      | 28 -------------------------
 translate.c       |  5 +++--
 translate.h       | 28 -------------------------
 18 files changed, 66 insertions(+), 278 deletions(-)
 delete mode 100644 gw_mode.h
 delete mode 100644 log.h
 delete mode 100644 loglevel.h
 delete mode 100644 ping.h
 delete mode 100644 statistics.h
 delete mode 100644 throughputmeter.h
 delete mode 100644 traceroute.h
 delete mode 100644 translate.h
gw_mode.c +3 -1
index a92644e..884f38e 100644
@@ -45,7 +45,7 @@ static void gw_mode_usage(void)
 	fprintf(stderr, " \t -h print this help\n");
 }
 
-int gw_mode(char *mesh_iface, int argc, char **argv)
+static int gw_mode(char *mesh_iface, int argc, char **argv)
 {
 	int optchar, res = EXIT_FAILURE;
 	char *path_buff, gw_mode;
@@ -166,3 +166,5 @@ int gw_mode(char *mesh_iface, int argc, char **argv)
 	free(path_buff);
 	return res;
 }
+
+COMMAND(gw_mode, "gw");
gw_mode.h deleted +0 -28
deleted file mode 100644
index d4d3fb5..0000000
@@ -1,28 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/* Copyright (C) 2009-2018  B.A.T.M.A.N. contributors:
- *
- * Marek Lindner <[email protected]>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA
- *
- * License-Filename: LICENSES/preferred/GPL-2.0
- */
-
-#ifndef _BATCTL_GW_MODE_H
-#define _BATCTL_GW_MODE_H
-
-int gw_mode(char *mesh_iface, int argc, char **argv);
-
-#endif
log.c +3 -1
index fc31c66..66594f6 100644
@@ -36,7 +36,7 @@ static void log_usage(void)
 	fprintf(stderr, " \t -n don't replace mac addresses with bat-host names\n");
 }
 
-int log_print(char *mesh_iface, int argc, char **argv)
+static int log_print(char *mesh_iface, int argc, char **argv)
 {
 	int optchar, res, read_opt = USE_BAT_HOSTS | LOG_MODE;
 	char full_path[MAX_PATH+1];
@@ -68,3 +68,5 @@ int log_print(char *mesh_iface, int argc, char **argv)
 	res = read_file(full_path, DEBUG_LOG, read_opt, 0, 0, 0);
 	return res;
 }
+
+COMMAND_NAMED(log, "l", log_print);
log.h deleted +0 -28
deleted file mode 100644
index 4ba00e3..0000000
@@ -1,28 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/* Copyright (C) 2009-2018  B.A.T.M.A.N. contributors:
- *
- * Marek Lindner <[email protected]>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA
- *
- * License-Filename: LICENSES/preferred/GPL-2.0
- */
-
-#ifndef _BATCTL_LOG_H
-#define _BATCTL_LOG_H
-
-int log_print(char *mesh_iface, int argc, char **argv);
-
-#endif
loglevel.c +3 -1
index 584cb37..3d9cf3a 100644
@@ -47,7 +47,7 @@ static void log_level_usage(void)
 	fprintf(stderr, " \t tp      Messages related to throughput meter\n");
 }
 
-int loglevel(char *mesh_iface, int argc, char **argv)
+static int loglevel(char *mesh_iface, int argc, char **argv)
 {
 	int optchar, res = EXIT_FAILURE;
 	int log_level = 0;
@@ -142,3 +142,5 @@ int loglevel(char *mesh_iface, int argc, char **argv)
 	free(path_buff);
 	return res;
 }
+
+COMMAND(loglevel, "ll");
loglevel.h deleted +0 -28
deleted file mode 100644
index 2644f46..0000000
@@ -1,28 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/* Copyright (C) 2009-2018  B.A.T.M.A.N. contributors:
- *
- * Marek Lindner <[email protected]>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA
- *
- * License-Filename: LICENSES/preferred/GPL-2.0
- */
-
-#ifndef _BATCTL_LOGLEVEL_H
-#define _BATCTL_LOGLEVEL_H
-
-int loglevel(char *mesh_iface, int argc, char **argv);
-
-#endif
main.c +23 -40

91 lines not on this page · raw message

main.h +18 -0
index e8c6db7..f7e2f64 100644
@@ -57,4 +57,22 @@ extern char module_ver_path[];
 #define BATADV_PRINT_VID(vid) (vid & BATADV_VLAN_HAS_TAG ? \
 			       (int)(vid & VLAN_VID_MASK) : -1)
 
+struct command {
+	const char *name;
+	const char *abbr;
+	int (*handler)(char *mesh_iface, int argc, char **argv);
+};
+
+#define COMMAND_NAMED(_name, _abbr, _handler) \
+	static const struct command command_ ## _name = { \
+		.name = (#_name), \
+		.abbr = _abbr, \
+		.handler = (_handler), \
+	}; \
+	static const struct command *__command_ ## _name \
+	__attribute__((__used__)) __attribute__ ((__section__ ("__command"))) = &command_ ## _name
+
+#define COMMAND(_handler, _abbr) \
+	COMMAND_NAMED(_handler, _abbr, _handler)
+
 #endif
ping.c +3 -2
index dc88e22..a4a1851 100644
@@ -39,7 +39,6 @@
 
 #include "batadv_packet.h"
 #include "main.h"
-#include "ping.h"
 #include "functions.h"
 #include "bat-hosts.h"
 #include "debugfs.h"
@@ -73,7 +72,7 @@ static void sig_handler(int sig)
 	}
 }
 
-int ping(char *mesh_iface, int argc, char **argv)
+static int ping(char *mesh_iface, int argc, char **argv)
 {
 	struct batadv_icmp_packet_rr icmp_packet_out, icmp_packet_in;
 	struct timeval tv;
@@ -345,3 +344,5 @@ int ping(char *mesh_iface, int argc, char **argv)
 	bat_hosts_free();
 	return ret;
 }
+
+COMMAND(ping, "p");
ping.h deleted +0 -28
deleted file mode 100644
index f09ffb2..0000000
@@ -1,28 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/* Copyright (C) 2009-2018  B.A.T.M.A.N. contributors:
- *
- * Marek Lindner <[email protected]>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA
- *
- * License-Filename: LICENSES/preferred/GPL-2.0
- */
-
-#ifndef _BATCTL_PING_H
-#define _BATCTL_PING_H
-
-int ping(char *mesh_iface, int argc, char **argv);
-
-#endif
statistics.c +4 -3
index 8a889ca..dea3ac1 100644
@@ -35,7 +35,6 @@
 #include <stdint.h>
 
 #include "main.h"
-#include "statistics.h"
 
 void check_root_or_die(const char *cmd);
 
@@ -103,8 +102,8 @@ static int statistics_custom_get(int fd, struct ifreq *ifr)
 	return ret;
 }
 
-int statistics(char *mesh_iface, int argc __maybe_unused,
-	       char **argv __maybe_unused)
+static int statistics(char *mesh_iface, int argc __maybe_unused,
+		      char **argv __maybe_unused)
 {
 	struct ifreq ifr;
 	int fd = -1, ret = EXIT_FAILURE;
@@ -126,3 +125,5 @@ int statistics(char *mesh_iface, int argc __maybe_unused,
 		close(fd);
 	return ret;
 }
+
+COMMAND(statistics, "s");
statistics.h deleted +0 -28
deleted file mode 100644
index 3737a48..0000000
@@ -1,28 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/* Copyright (C) 2012-2018  B.A.T.M.A.N. contributors:
- *
- * Marek Lindner <[email protected]>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA
- *
- * License-Filename: LICENSES/preferred/GPL-2.0
- */
-
-#ifndef _BATCTL_STATISTICS_H
-#define _BATCTL_STATISTICS_H
-
-int statistics(char *mesh_iface, int argc, char **argv);
-
-#endif
throughputmeter.c +3 -2
index bb53d56..372bfc4 100644
@@ -21,7 +21,6 @@
  */
 
 #include "main.h"
-#include "throughputmeter.h"
 
 #include <netinet/ether.h>
 #include <netinet/in.h>
@@ -389,7 +388,7 @@ static void tp_meter_usage(void)
 	fprintf(stderr, "\t -n don't convert addresses to bat-host names\n");
 }
 
-int throughputmeter(char *mesh_iface, int argc, char **argv)
+static int throughputmeter(char *mesh_iface, int argc, char **argv)
 {
 	struct bat_host *bat_host;
 	uint64_t throughput;
@@ -543,3 +542,5 @@ int throughputmeter(char *mesh_iface, int argc, char **argv)
 	bat_hosts_free();
 	return ret;
 }
+
+COMMAND(throughputmeter, "tp");
throughputmeter.h deleted +0 -28
deleted file mode 100644
index 2c04c12..0000000
@@ -1,28 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/* Copyright (C) 2013-2018  B.A.T.M.A.N. contributors:
- *
- * Antonio Quartulli <[email protected]>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA
- *
- * License-Filename: LICENSES/preferred/GPL-2.0
- */
-
-#ifndef _BATCTL_THROUGHPUTMETER_H
-#define _BATCTL_THROUGHPUTMETER_H
-
-int throughputmeter(char *mesh_iface, int argc, char **argv);
-
-#endif /* _BATCTL_THROUGHPUTMETER_H */
traceroute.c +3 -2
index ba7e27d..5c55c7b 100644
@@ -36,7 +36,6 @@
 
 #include "batadv_packet.h"
 #include "main.h"
-#include "traceroute.h"
 #include "functions.h"
 #include "bat-hosts.h"
 #include "debugfs.h"
@@ -56,7 +55,7 @@ static void traceroute_usage(void)
 	fprintf(stderr, " \t -T don't try to translate mac to originator address\n");
 }
 
-int traceroute(char *mesh_iface, int argc, char **argv)
+static int traceroute(char *mesh_iface, int argc, char **argv)
 {
 	struct batadv_icmp_packet icmp_packet_out, icmp_packet_in;
 	struct bat_host *bat_host;
@@ -231,3 +230,5 @@ int traceroute(char *mesh_iface, int argc, char **argv)
 	bat_hosts_free();
 	return ret;
 }
+
+COMMAND(traceroute, "tr");
traceroute.h deleted +0 -28
deleted file mode 100644
index ffe0252..0000000
@@ -1,28 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/* Copyright (C) 2009-2018  B.A.T.M.A.N. contributors:
- *
- * Marek Lindner <[email protected]>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA
- *
- * License-Filename: LICENSES/preferred/GPL-2.0
- */
-
-#ifndef _BATCTL_TRACEROUTE_H
-#define _BATCTL_TRACEROUTE_H
-
-int traceroute(char *mesh_iface, int argc, char **argv);
-
-#endif
translate.c +3 -2
index 9059f20..ec6baaf 100644
@@ -24,7 +24,6 @@
 #include <stdlib.h>
 
 #include "main.h"
-#include "translate.h"
 #include "functions.h"
 #include "bat-hosts.h"
 
@@ -34,7 +33,7 @@ static void translate_usage(void)
 	fprintf(stderr, "Usage: batctl [options] translate mac|bat-host|host_name|IPv4_address\n");
 }
 
-int translate(char *mesh_iface, int argc, char **argv)
+static int translate(char *mesh_iface, int argc, char **argv)
 {
 	struct ether_addr *dst_mac = NULL;
 	struct bat_host *bat_host;
@@ -78,3 +77,5 @@ int translate(char *mesh_iface, int argc, char **argv)
 	bat_hosts_free();
 	return ret;
 }
+
+COMMAND(translate, "t");
translate.h deleted +0 -28
deleted file mode 100644
index 8155827..0000000
@@ -1,28 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/* Copyright (C) 2009-2018  B.A.T.M.A.N. contributors:
- *
- * Marek Lindner <[email protected]>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA
- *
- * License-Filename: LICENSES/preferred/GPL-2.0
- */
-
-#ifndef _BATCTL_TRANSLATE_H
-#define _BATCTL_TRANSLATE_H
-
-int translate(char *mesh_iface, int argc, char **argv);
-
-#endif
Signature · 1 line
2.11.0
#10 lore raw

PATCH v3 10/42 batctl: Add per command flags

In reply to Sven Eckelmann

Some commands have different prerequists than other commands. Using flags to specify them would allow batctl to use the same command structure for the non-mesh_iface based command as for mesh_iface based commands.

---
 gw_mode.c         |  2 +-
 log.c             |  2 +-
 loglevel.c        |  2 +-
 main.c            | 13 ++++++++++---
 main.h            | 12 +++++++++---
 ping.c            |  2 +-
 statistics.c      |  2 +-
 throughputmeter.c |  2 +-
 traceroute.c      |  2 +-
 translate.c       |  2 +-
 10 files changed, 27 insertions(+), 14 deletions(-)
gw_mode.c +1 -1
index 884f38e..f07dc99 100644
@@ -167,4 +167,4 @@ static int gw_mode(char *mesh_iface, int argc, char **argv)
 	return res;
 }
 
-COMMAND(gw_mode, "gw");
+COMMAND(gw_mode, "gw", COMMAND_FLAG_MESH_IFACE);
log.c +1 -1
index 66594f6..585f1c9 100644
@@ -69,4 +69,4 @@ static int log_print(char *mesh_iface, int argc, char **argv)
 	return res;
 }
 
-COMMAND_NAMED(log, "l", log_print);
+COMMAND_NAMED(log, "l", log_print, COMMAND_FLAG_MESH_IFACE);
loglevel.c +1 -1
index 3d9cf3a..06519e7 100644
@@ -143,4 +143,4 @@ static int loglevel(char *mesh_iface, int argc, char **argv)
 	return res;
 }
 
-COMMAND(loglevel, "ll");
+COMMAND(loglevel, "ll", COMMAND_FLAG_MESH_IFACE);
main.c +10 -3
index 14f4774..dacfb12 100644
@@ -169,12 +169,19 @@ int main(int argc, char **argv)
 
 		ret = routing_algo(mesh_iface, argc - 1, argv + 1);
 
-	} else if (check_mesh_iface(mesh_iface) < 0) {
-		fprintf(stderr, "Error - interface %s is not present or not a batman-adv interface\n", mesh_iface);
-		exit(EXIT_FAILURE);
 	} else if ((cmd = find_command(argv[1]))) {
+		if (cmd->flags & COMMAND_FLAG_MESH_IFACE &&
+		    check_mesh_iface(mesh_iface) < 0) {
+			fprintf(stderr, "Error - interface %s is not present or not a batman-adv interface\n", mesh_iface);
+			exit(EXIT_FAILURE);
+		}
+
 		ret = cmd->handler(mesh_iface, argc - 1, argv + 1);
 	} else {
+		if (check_mesh_iface(mesh_iface) < 0) {
+			fprintf(stderr, "Error - interface %s is not present or not a batman-adv interface\n", mesh_iface);
+			exit(EXIT_FAILURE);
+		}
 
 		for (i = 0; i < BATCTL_SETTINGS_NUM; i++) {
 			if ((strcmp(argv[1], batctl_settings[i].opt_long) != 0) &&
main.h +9 -3
index f7e2f64..c461d6b 100644
@@ -57,22 +57,28 @@ extern char module_ver_path[];
 #define BATADV_PRINT_VID(vid) (vid & BATADV_VLAN_HAS_TAG ? \
 			       (int)(vid & VLAN_VID_MASK) : -1)
 
+enum command_flags {
+	COMMAND_FLAG_MESH_IFACE = BIT(0),
+};
+
 struct command {
 	const char *name;
 	const char *abbr;
 	int (*handler)(char *mesh_iface, int argc, char **argv);
+	uint32_t flags;
 };
 
-#define COMMAND_NAMED(_name, _abbr, _handler) \
+#define COMMAND_NAMED(_name, _abbr, _handler, _flags) \
 	static const struct command command_ ## _name = { \
 		.name = (#_name), \
 		.abbr = _abbr, \
 		.handler = (_handler), \
+		.flags = (_flags), \
 	}; \
 	static const struct command *__command_ ## _name \
 	__attribute__((__used__)) __attribute__ ((__section__ ("__command"))) = &command_ ## _name
 
-#define COMMAND(_handler, _abbr) \
-	COMMAND_NAMED(_handler, _abbr, _handler)
+#define COMMAND(_handler, _abbr, _flags) \
+	COMMAND_NAMED(_handler, _abbr, _handler, _flags)
 
 #endif
ping.c +1 -1
index a4a1851..2da49d4 100644
@@ -345,4 +345,4 @@ static int ping(char *mesh_iface, int argc, char **argv)
 	return ret;
 }
 
-COMMAND(ping, "p");
+COMMAND(ping, "p", COMMAND_FLAG_MESH_IFACE);
statistics.c +1 -1
index dea3ac1..cb6c1e8 100644
@@ -126,4 +126,4 @@ static int statistics(char *mesh_iface, int argc __maybe_unused,
 	return ret;
 }
 
-COMMAND(statistics, "s");
+COMMAND(statistics, "s", COMMAND_FLAG_MESH_IFACE);
throughputmeter.c +1 -1
index 372bfc4..e9e318c 100644
@@ -543,4 +543,4 @@ static int throughputmeter(char *mesh_iface, int argc, char **argv)
 	return ret;
 }
 
-COMMAND(throughputmeter, "tp");
+COMMAND(throughputmeter, "tp", COMMAND_FLAG_MESH_IFACE);
traceroute.c +1 -1
index 5c55c7b..1352201 100644
@@ -231,4 +231,4 @@ static int traceroute(char *mesh_iface, int argc, char **argv)
 	return ret;
 }
 
-COMMAND(traceroute, "tr");
+COMMAND(traceroute, "tr", COMMAND_FLAG_MESH_IFACE);
translate.c +1 -1
index ec6baaf..d2d34f5 100644
@@ -78,4 +78,4 @@ static int translate(char *mesh_iface, int argc, char **argv)
 	return ret;
 }
 
-COMMAND(translate, "t");
+COMMAND(translate, "t", COMMAND_FLAG_MESH_IFACE);
Signature · 1 line
2.11.0
#11 lore raw

PATCH v3 11/42 batctl: Use command structure for remaining subcommands

In reply to Sven Eckelmann

The command datastructure was extended to be usable for mesh_iface and non-mesh_iface subcommands. The referenced subcommands only have to use the same function signature to work correctly.

The introduction of dummy parameter to the functions allows therefore to convert all non-settings and non-debug-tables subcommands to the new infrastructure.

---
 bisect_iv.c    |  5 ++++-
 bisect_iv.h    |  4 ----
 interface.c    |  6 +++---
 interface.h    | 30 ------------------------------
 main.c         | 23 +----------------------
 routing_algo.c |  4 +++-
 routing_algo.h | 28 ----------------------------
 tcpdump.c      |  4 +++-
 tcpdump.h      |  2 --
 9 files changed, 14 insertions(+), 92 deletions(-)
 delete mode 100644 interface.h
 delete mode 100644 routing_algo.h
bisect_iv.c +4 -1
index d71ceda..f87f915 100644
@@ -32,6 +32,7 @@
 #include "bisect_iv.h"
 #include "bat-hosts.h"
 #include "hash.h"
+#include "main.h"
 #include "functions.h"
 
 static struct hashtable_t *node_hash = NULL;
@@ -1440,7 +1441,7 @@ static int get_orig_addr(char *orig_name, char *orig_addr)
 	return 0;
 }
 
-int bisect_iv(int argc, char **argv)
+static int bisect_iv(char *mesh_iface __maybe_unused, int argc, char **argv)
 {
 	int ret = EXIT_FAILURE, res, optchar, found_args = 1;
 	int read_opt = USE_BAT_HOSTS, num_parsed_files;
@@ -1593,3 +1594,5 @@ int bisect_iv(int argc, char **argv)
 	bat_hosts_free();
 	return ret;
 }
+
+COMMAND(bisect_iv, "bisect_iv", 0);
bisect_iv.h +0 -4
index 7932c2f..5f5200c 100644
@@ -33,10 +33,6 @@
 #define RT_FLAG_UPDATE 2
 #define RT_FLAG_DELETE 3
 
-int bisect_iv(int argc, char **argv);
-
-
-
 struct bat_node {
 	char name[NAME_LEN];
 	struct list_head orig_event_list;
interface.c +3 -3
index 5951b47..485ed0a 100644
@@ -20,8 +20,6 @@
  * License-Filename: LICENSES/preferred/GPL-2.0
  */
 
-#include "interface.h"
-
 #include <unistd.h>
 #include <stdio.h>
 #include <stdbool.h>
@@ -299,7 +297,7 @@ static int set_master_interface(const char *iface, unsigned int ifmaster)
 	return err;
 }
 
-int interface(char *mesh_iface, int argc, char **argv)
+static int interface(char *mesh_iface, int argc, char **argv)
 {
 	int i, optchar;
 	int ret;
@@ -459,3 +457,5 @@ int interface(char *mesh_iface, int argc, char **argv)
 err:
 	return EXIT_FAILURE;
 }
+
+COMMAND(interface, "if", 0);
interface.h deleted +0 -30
deleted file mode 100644
index 83ca129..0000000
@@ -1,30 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/* Copyright (C) 2009-2018  B.A.T.M.A.N. contributors:
- *
- * Marek Lindner <[email protected]>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA
- *
- * License-Filename: LICENSES/preferred/GPL-2.0
- */
-
-#ifndef _BATCTL_INTERFACE_H
-#define _BATCTL_INTERFACE_H
-
-#include "main.h"
-
-int interface(char *mesh_iface, int argc, char **argv);
-
-#endif
main.c +1 -22
index dacfb12..fa4371c 100644
@@ -30,10 +30,6 @@
 #include "main.h"
 #include "sys.h"
 #include "debug.h"
-#include "interface.h"
-#include "tcpdump.h"
-#include "bisect_iv.h"
-#include "routing_algo.h"
 #include "functions.h"
 
 char mesh_dfl_iface[] = "bat0";
@@ -152,24 +148,7 @@ int main(int argc, char **argv)
 		exit(EXIT_SUCCESS);
 	}
 
-	if ((strcmp(argv[1], "interface") == 0) || (strcmp(argv[1], "if") == 0)) {
-
-		ret = interface(mesh_iface, argc - 1, argv + 1);
-
-	} else if ((strcmp(argv[1], "tcpdump") == 0) || (strcmp(argv[1], "td") == 0)) {
-
-		ret = tcpdump(argc - 1, argv + 1);
-
-#ifdef BATCTL_BISECT
-	} else if ((strcmp(argv[1], "bisect_iv") == 0)) {
-
-		ret = bisect_iv(argc - 1, argv + 1);
-#endif
-	} else if ((strcmp(argv[1], "routing_algo") == 0) || (strcmp(argv[1], "ra") == 0)) {
-
-		ret = routing_algo(mesh_iface, argc - 1, argv + 1);
-
-	} else if ((cmd = find_command(argv[1]))) {
+	if ((cmd = find_command(argv[1]))) {
 		if (cmd->flags & COMMAND_FLAG_MESH_IFACE &&
 		    check_mesh_iface(mesh_iface) < 0) {
 			fprintf(stderr, "Error - interface %s is not present or not a batman-adv interface\n", mesh_iface);
routing_algo.c +3 -1
index 89af6c5..2026224 100644
@@ -41,7 +41,7 @@ static void ra_mode_usage(void)
 	fprintf(stderr, " \t -h print this help\n");
 }
 
-int routing_algo(char *mesh_iface __maybe_unused, int argc, char **argv)
+static int routing_algo(char *mesh_iface __maybe_unused, int argc, char **argv)
 {
 	DIR *iface_base_dir;
 	struct dirent *iface_dir;
@@ -125,3 +125,5 @@ int routing_algo(char *mesh_iface __maybe_unused, int argc, char **argv)
 out:
 	return res;
 }
+
+COMMAND(routing_algo, "ra", 0);
routing_algo.h deleted +0 -28
deleted file mode 100644
index db246c6..0000000
@@ -1,28 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/* Copyright (C) 2009-2018  B.A.T.M.A.N. contributors:
- *
- * Marek Lindner <[email protected]>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA
- *
- * License-Filename: LICENSES/preferred/GPL-2.0
- */
-
-#ifndef _BATCTL_ROUTING_ALGO_H
-#define _BATCTL_ROUTING_ALGO_H
-
-int routing_algo(char *mesh_iface, int argc, char **argv);
-
-#endif
tcpdump.c +3 -1
index dc4ccd3..fd2b35a 100644
@@ -1210,7 +1210,7 @@ static void sig_handler(int sig)
 	}
 }
 
-int tcpdump(int argc, char **argv)
+static int tcpdump(char *mesh_iface __maybe_unused, int argc, char **argv)
 {
 	struct timeval tv;
 	struct dump_if *dump_if, *dump_if_tmp;
@@ -1351,3 +1351,5 @@ int tcpdump(int argc, char **argv)
 	bat_hosts_free();
 	return ret;
 }
+
+COMMAND(tcpdump, "td", 0);
tcpdump.h +0 -2
index f73211b..db92fce 100644
@@ -113,6 +113,4 @@ struct prism_header {
 #define PRISM_HEADER_LEN sizeof(struct prism_header)
 #define RADIOTAP_HEADER_LEN sizeof(struct radiotap_header)
 
-int tcpdump(int argc, char **argv);
-
 #endif
Signature · 1 line
2.11.0
#12 lore raw

PATCH v3 12/42 batctl: Use getopt to parse main options

In reply to Sven Eckelmann

The handwritten option parser is rather fragile and doesn't support all features of a normal commandline option parser. Instead use getopt to handle the most critical parts and keep it more flexible.

---
 main.c | 95 +++++++++++++++++++++++++++++++++++++++---------------------------
 1 file changed, 56 insertions(+), 39 deletions(-)
main.c +56 -39
index fa4371c..f5df477 100644
@@ -22,6 +22,7 @@
 
 
 
+#include <getopt.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -87,6 +88,25 @@ static void print_usage(void)
 #endif
 }
 
+static void version(void)
+{
+	int ret;
+
+	printf("batctl %s [batman-adv: ", SOURCE_VERSION);
+
+	ret = read_file("", module_ver_path, USE_READ_BUFF | SILENCE_ERRORS, 0, 0, 0);
+	if ((line_ptr) && (line_ptr[strlen(line_ptr) - 1] == '\n'))
+		line_ptr[strlen(line_ptr) - 1] = '\0';
+
+	if (ret == EXIT_SUCCESS)
+		printf("%s]\n", line_ptr);
+	else
+		printf("module not loaded]\n");
+
+	free(line_ptr);
+	exit(EXIT_SUCCESS);
+}
+
 static const struct command *find_command(const char *name)
 {
 	const struct command **p;
@@ -109,53 +129,48 @@ int main(int argc, char **argv)
 	const struct command *cmd;
 	int i, ret = EXIT_FAILURE;
 	char *mesh_iface = mesh_dfl_iface;
-
-	if ((argc > 1) && (strcmp(argv[1], "-m") == 0)) {
-		if (argc < 3) {
-			fprintf(stderr, "Error - the option '-m' needs a parameter\n");
+	int opt;
+
+	while ((opt = getopt(argc, argv, "+hm:v")) != -1) {
+		switch (opt) {
+		case 'h':
+			print_usage();
+			exit(EXIT_SUCCESS);
+			break;
+		case 'm':
+			if (mesh_iface != mesh_dfl_iface) {
+				fprintf(stderr,
+					"Error - multiple mesh interfaces specified\n");
+				goto err;
+			}
+
+			mesh_iface = argv[2];
+			break;
+		case 'v':
+			version();
+			break;
+		default:
 			goto err;
 		}
-
-		mesh_iface = argv[2];
-
-		argv += 2;
-		argc -= 2;
 	}
 
-	if (argc < 2) {
+	if (optind >= argc) {
 		fprintf(stderr, "Error - no command specified\n");
 		goto err;
 	}
 
-	if (strcmp(argv[1], "-h") == 0) {
-		print_usage();
-		exit(EXIT_SUCCESS);
-	}
-
-	if (strcmp(argv[1], "-v") == 0) {
-		printf("batctl %s [batman-adv: ", SOURCE_VERSION);
-
-		ret = read_file("", module_ver_path, USE_READ_BUFF | SILENCE_ERRORS, 0, 0, 0);
-		if ((line_ptr) && (line_ptr[strlen(line_ptr) - 1] == '\n'))
-			line_ptr[strlen(line_ptr) - 1] = '\0';
-
-		if (ret == EXIT_SUCCESS)
-			printf("%s]\n", line_ptr);
-		else
-			printf("module not loaded]\n");
-
-		free(line_ptr);
-		exit(EXIT_SUCCESS);
-	}
+	argv += optind;
+	argc -= optind;
+	optind = 0;
 
-	if ((cmd = find_command(argv[1]))) {
+	if ((cmd = find_command(argv[0]))) {
 		if (cmd->flags & COMMAND_FLAG_MESH_IFACE &&
 		    check_mesh_iface(mesh_iface) < 0) {
 			fprintf(stderr, "Error - interface %s is not present or not a batman-adv interface\n", mesh_iface);
 			exit(EXIT_FAILURE);
 		}
 
-		ret = cmd->handler(mesh_iface, argc - 1, argv + 1);
+		ret = cmd->handler(mesh_iface, argc, argv);
 	} else {
 		if (check_mesh_iface(mesh_iface) < 0) {
 			fprintf(stderr, "Error - interface %s is not present or not a batman-adv interface\n", mesh_iface);
@@ -163,24 +178,26 @@ int main(int argc, char **argv)
 		}
 
 		for (i = 0; i < BATCTL_SETTINGS_NUM; i++) {
-			if ((strcmp(argv[1], batctl_settings[i].opt_long) != 0) &&
-			    (strcmp(argv[1], batctl_settings[i].opt_short) != 0))
+			if ((strcmp(argv[0], batctl_settings[i].opt_long) != 0) &&
+			    (strcmp(argv[0], batctl_settings[i].opt_short) != 0))
 				continue;
 
-			ret = handle_sys_setting(mesh_iface, i, argc - 1, argv + 1);
+			ret = handle_sys_setting(mesh_iface, i, argc, argv);
 			goto out;
 		}
 
 		for (i = 0; i < BATCTL_TABLE_NUM; i++) {
-			if ((strcmp(argv[1], batctl_debug_tables[i].opt_long) != 0) &&
-			    (strcmp(argv[1], batctl_debug_tables[i].opt_short) != 0))
+			if ((strcmp(argv[0], batctl_debug_tables[i].opt_long) != 0) &&
+			    (strcmp(argv[0], batctl_debug_tables[i].opt_short) != 0))
 				continue;
 
-			ret = handle_debug_table(mesh_iface, i, argc - 1, argv + 1);
+			ret = handle_debug_table(mesh_iface, i, argc, argv);
 			goto out;
 		}
 
-		fprintf(stderr, "Error - no valid command or debug table specified: %s\n", argv[1]);
+		fprintf(stderr,
+			"Error - no valid command or debug table specified: %s\n",
+			argv[0]);
 		print_usage();
 	}
 
Signature · 1 line
2.11.0
#13 lore raw

PATCH v3 13/42 batctl: Store usage line next to command

In reply to Sven Eckelmann

The single line usage information for a subcommand is the simplest way to learn how to use a command. It is displayed when either the -h option is used or when the initial part of the batctl command is incorrect.

Since the commands are no longer registered manually in the main function, the usage line should also no longer be stored there. Instead add it to the same file as the command itself.

---
 Makefile          | 13 +++++++------
 bisect_iv.c       |  3 ++-
 gw_mode.c         |  3 ++-
 interface.c       |  3 ++-
 log.c             |  3 ++-
 loglevel.c        |  3 ++-
 main.c            | 31 +++++++++++++++----------------
 main.h            |  8 +++++---
 ping.c            |  3 ++-
 routing_algo.c    |  3 ++-
 statistics.c      |  3 ++-
 tcpdump.c         |  3 ++-
 throughputmeter.c |  3 ++-
 traceroute.c      |  3 ++-
 translate.c       |  3 ++-
 15 files changed, 51 insertions(+), 37 deletions(-)
Makefile +7 -6
index b4777b7..842795b 100755
@@ -26,7 +26,13 @@ export CONFIG_BATCTL_BISECT=n
 
 # batctl build
 BINARY_NAME = batctl
+
+OBJ_BISECT = bisect_iv.o
+
 OBJ += bat-hosts.o
+ifeq ($(CONFIG_BATCTL_BISECT),y)
+OBJ += $(OBJ_BISECT)
+endif
 OBJ += debugfs.o
 OBJ += debug.o
 OBJ += functions.o
@@ -47,7 +53,7 @@ OBJ += tcpdump.o
 OBJ += throughputmeter.o
 OBJ += traceroute.o
 OBJ += translate.o
-OBJ_BISECT = bisect_iv.o
+
 MANPAGE = man/batctl.8
 
 # batctl flags and options
@@ -95,11 +101,6 @@ CFLAGS += $(LIBNL_GENL_CFLAGS)
 LDLIBS += $(LIBNL_GENL_LDLIBS)
 
 # standard build tools
-ifeq ($(CONFIG_BATCTL_BISECT),y)
-OBJ += $(OBJ_BISECT)
-CPPFLAGS += -DBATCTL_BISECT
-endif
-
 CC ?= gcc
 RM ?= rm -f
 INSTALL ?= install
bisect_iv.c +2 -1
index f87f915..6da82b9 100644
@@ -1595,4 +1595,5 @@ static int bisect_iv(char *mesh_iface __maybe_unused, int argc, char **argv)
 	return ret;
 }
 
-COMMAND(bisect_iv, "bisect_iv", 0);
+COMMAND(bisect_iv, "bisect_iv", 0,
+	"<file1> .. <fileN>\tanalyze given batman iv log files for routing stability");
gw_mode.c +2 -1
index f07dc99..da22ff0 100644
@@ -167,4 +167,5 @@ static int gw_mode(char *mesh_iface, int argc, char **argv)
 	return res;
 }
 
-COMMAND(gw_mode, "gw", COMMAND_FLAG_MESH_IFACE);
+COMMAND(gw_mode, "gw", COMMAND_FLAG_MESH_IFACE,
+	"[mode]            \tdisplay or modify the gateway mode");
interface.c +2 -1
index 485ed0a..d2883a9 100644
@@ -458,4 +458,5 @@ static int interface(char *mesh_iface, int argc, char **argv)
 	return EXIT_FAILURE;
 }
 
-COMMAND(interface, "if", 0);
+COMMAND(interface, "if", 0,
+	"[add|del iface(s)]\tdisplay or modify the interface settings");
log.c +2 -1
index 585f1c9..e28466d 100644
@@ -69,4 +69,5 @@ static int log_print(char *mesh_iface, int argc, char **argv)
 	return res;
 }
 
-COMMAND_NAMED(log, "l", log_print, COMMAND_FLAG_MESH_IFACE);
+COMMAND_NAMED(log, "l", log_print, COMMAND_FLAG_MESH_IFACE,
+	      "                  \tread the log produced by the kernel module");
loglevel.c +2 -1
index 06519e7..3dc1a1c 100644
@@ -143,4 +143,5 @@ static int loglevel(char *mesh_iface, int argc, char **argv)
 	return res;
 }
 
-COMMAND(loglevel, "ll", COMMAND_FLAG_MESH_IFACE);
+COMMAND(loglevel, "ll", COMMAND_FLAG_MESH_IFACE,
+	"[level]           \tdisplay or modify the log level");
main.c +15 -16
index f5df477..b9b19de 100644
@@ -41,7 +41,9 @@ extern const struct command *__stop___command[];
 
 static void print_usage(void)
 {
+	const struct command **p;
 	int i, opt_indent;
+	char buf[32];
 
 	fprintf(stderr, "Usage: batctl [options] command|debug table [parameters]\n");
 	fprintf(stderr, "options:\n");
@@ -51,7 +53,19 @@ static void print_usage(void)
 	fprintf(stderr, "\n");
 
 	fprintf(stderr, "commands:\n");
-	fprintf(stderr, " \tinterface|if               [add|del iface(s)]\tdisplay or modify the interface settings\n");
+
+	for (p = __start___command; p < __stop___command; p++) {
+		const struct command *cmd = *p;
+
+		if (strcmp(cmd->name, cmd->abbr) == 0)
+			snprintf(buf, sizeof(buf), "%s", cmd->name);
+		else
+			snprintf(buf, sizeof(buf), "%s|%s", cmd->name,
+				 cmd->abbr);
+
+		fprintf(stderr, " \t%-27s%s\n", buf, cmd->usage);
+	}
+
 	for (i = 0; i < BATCTL_SETTINGS_NUM; i++) {
 		fprintf(stderr, " \t%s|%s", batctl_settings[i].opt_long, batctl_settings[i].opt_short);
 		opt_indent = strlen(batctl_settings[i].opt_long) + strlen(batctl_settings[i].opt_short);
@@ -66,26 +80,11 @@ static void print_usage(void)
 			fprintf(stderr, "                                display or modify %s setting\n",
 			       batctl_settings[i].opt_long);
 	}
-	fprintf(stderr, " \tloglevel|ll                [level]           \tdisplay or modify the log level\n");
-	fprintf(stderr, " \tlog|l                                        \tread the log produced by the kernel module\n");
-	fprintf(stderr, " \tgw_mode|gw                 [mode]            \tdisplay or modify the gateway mode\n");
-	fprintf(stderr, " \trouting_algo|ra            [mode]            \tdisplay or modify the routing algorithm\n");
 	fprintf(stderr, "\n");
 
 	fprintf(stderr, "debug tables:                                   \tdisplay the corresponding debug table\n");
 	for (i = 0; i < BATCTL_TABLE_NUM; i++)
 		fprintf(stderr, " \t%s|%s\n", batctl_debug_tables[i].opt_long, batctl_debug_tables[i].opt_short);
-
-	fprintf(stderr, "\n");
-	fprintf(stderr, " \tstatistics|s                                 \tprint mesh statistics\n");
-	fprintf(stderr, " \tping|p                     <destination>     \tping another batman adv host via layer 2\n");
-	fprintf(stderr, " \ttraceroute|tr              <destination>     \ttraceroute another batman adv host via layer 2\n");
-	fprintf(stderr, " \ttcpdump|td                 <interface>       \ttcpdump layer 2 traffic on the given interface\n");
-	printf(" \tthroughputmeter|tp         <destination>     \tstart a throughput measurement\n");
-	fprintf(stderr, " \ttranslate|t                <destination>     \ttranslate a destination to the originator responsible for it\n");
-#ifdef BATCTL_BISECT
-	fprintf(stderr, " \tbisect_iv                  <file1> .. <fileN>\tanalyze given batman iv log files for routing stability\n");
-#endif
 }
 
 static void version(void)
main.h +5 -3
index c461d6b..b39e350 100644
@@ -66,19 +66,21 @@ struct command {
 	const char *abbr;
 	int (*handler)(char *mesh_iface, int argc, char **argv);
 	uint32_t flags;
+	const char *usage;
 };
 
-#define COMMAND_NAMED(_name, _abbr, _handler, _flags) \
+#define COMMAND_NAMED(_name, _abbr, _handler, _flags, _usage) \
 	static const struct command command_ ## _name = { \
 		.name = (#_name), \
 		.abbr = _abbr, \
 		.handler = (_handler), \
 		.flags = (_flags), \
+		.usage = (_usage), \
 	}; \
 	static const struct command *__command_ ## _name \
 	__attribute__((__used__)) __attribute__ ((__section__ ("__command"))) = &command_ ## _name
 
-#define COMMAND(_handler, _abbr, _flags) \
-	COMMAND_NAMED(_handler, _abbr, _handler, _flags)
+#define COMMAND(_handler, _abbr, _flags, _usage) \
+	COMMAND_NAMED(_handler, _abbr, _handler, _flags, _usage)
 
 #endif
ping.c +2 -1
index 2da49d4..efaf011 100644
@@ -345,4 +345,5 @@ static int ping(char *mesh_iface, int argc, char **argv)
 	return ret;
 }
 
-COMMAND(ping, "p", COMMAND_FLAG_MESH_IFACE);
+COMMAND(ping, "p", COMMAND_FLAG_MESH_IFACE,
+	"<destination>     \tping another batman adv host via layer 2");
routing_algo.c +2 -1
index 2026224..8cc4ff1 100644
@@ -126,4 +126,5 @@ static int routing_algo(char *mesh_iface __maybe_unused, int argc, char **argv)
 	return res;
 }
 
-COMMAND(routing_algo, "ra", 0);
+COMMAND(routing_algo, "ra", 0,
+	"[mode]            \tdisplay or modify the routing algorithm");
statistics.c +2 -1
index cb6c1e8..908bbaf 100644
@@ -126,4 +126,5 @@ static int statistics(char *mesh_iface, int argc __maybe_unused,
 	return ret;
 }
 
-COMMAND(statistics, "s", COMMAND_FLAG_MESH_IFACE);
+COMMAND(statistics, "s", COMMAND_FLAG_MESH_IFACE,
+	"                  \tprint mesh statistics");
tcpdump.c +2 -1
index fd2b35a..62e4a64 100644
@@ -1352,4 +1352,5 @@ static int tcpdump(char *mesh_iface __maybe_unused, int argc, char **argv)
 	return ret;
 }
 
-COMMAND(tcpdump, "td", 0);
+COMMAND(tcpdump, "td", 0,
+	"<interface>       \ttcpdump layer 2 traffic on the given interface");
throughputmeter.c +2 -1
index e9e318c..ebd35a6 100644
@@ -543,4 +543,5 @@ static int throughputmeter(char *mesh_iface, int argc, char **argv)
 	return ret;
 }
 
-COMMAND(throughputmeter, "tp", COMMAND_FLAG_MESH_IFACE);
+COMMAND(throughputmeter, "tp", COMMAND_FLAG_MESH_IFACE,
+	"<destination>     \tstart a throughput measurement");
traceroute.c +2 -1
index 1352201..9446bcd 100644
@@ -231,4 +231,5 @@ static int traceroute(char *mesh_iface, int argc, char **argv)
 	return ret;
 }
 
-COMMAND(traceroute, "tr", COMMAND_FLAG_MESH_IFACE);
+COMMAND(traceroute, "tr", COMMAND_FLAG_MESH_IFACE,
+	"<destination>     \ttraceroute another batman adv host via layer 2");
translate.c +2 -1
index d2d34f5..95de9a2 100644
@@ -78,4 +78,5 @@ static int translate(char *mesh_iface, int argc, char **argv)
 	return ret;
 }
 
-COMMAND(translate, "t", COMMAND_FLAG_MESH_IFACE);
+COMMAND(translate, "t", COMMAND_FLAG_MESH_IFACE,
+	"<destination>     \ttranslate a destination to the originator responsible for it");
Signature · 1 line
2.11.0
#14 lore raw

PATCH v3 14/42 batctl: Prepare command infrastructure for shared functions

In reply to Sven Eckelmann

The command structure first mapped from one name and abbrevation to a single function of batctl. But there can be commands which share a significant portion of the code. To support these kind of things better, add an additional arg pointer to the command structure. The handler then receive a state struct from the main function instead of the mesh_iface.

The command implementation can then use the state to retrieve both the mesh_iface and the cmd with the arg pointer.

---
 bisect_iv.c       |  4 ++--
 gw_mode.c         |  6 +++---
 interface.c       | 20 ++++++++++----------
 log.c             |  6 +++---
 loglevel.c        |  6 +++---
 main.c            | 29 +++++++++++++++++++----------
 main.h            | 15 +++++++++++----
 ping.c            |  8 ++++----
 routing_algo.c    |  4 ++--
 statistics.c      |  6 +++---
 tcpdump.c         |  4 ++--
 throughputmeter.c |  8 ++++----
 traceroute.c      |  8 ++++----
 translate.c       |  6 +++---
 14 files changed, 73 insertions(+), 57 deletions(-)
bisect_iv.c +2 -2
index 6da82b9..c6fc708 100644
@@ -1441,7 +1441,7 @@ static int get_orig_addr(char *orig_name, char *orig_addr)
 	return 0;
 }
 
-static int bisect_iv(char *mesh_iface __maybe_unused, int argc, char **argv)
+static int bisect_iv(struct state *state __maybe_unused, int argc, char **argv)
 {
 	int ret = EXIT_FAILURE, res, optchar, found_args = 1;
 	int read_opt = USE_BAT_HOSTS, num_parsed_files;
@@ -1595,5 +1595,5 @@ static int bisect_iv(char *mesh_iface __maybe_unused, int argc, char **argv)
 	return ret;
 }
 
-COMMAND(bisect_iv, "bisect_iv", 0,
+COMMAND(bisect_iv, "bisect_iv", 0, NULL,
 	"<file1> .. <fileN>\tanalyze given batman iv log files for routing stability");
gw_mode.c +3 -3
index da22ff0..bd530d5 100644
@@ -45,7 +45,7 @@ static void gw_mode_usage(void)
 	fprintf(stderr, " \t -h print this help\n");
 }
 
-static int gw_mode(char *mesh_iface, int argc, char **argv)
+static int gw_mode(struct state *state, int argc, char **argv)
 {
 	int optchar, res = EXIT_FAILURE;
 	char *path_buff, gw_mode;
@@ -68,7 +68,7 @@ static int gw_mode(char *mesh_iface, int argc, char **argv)
 		return EXIT_FAILURE;
 	}
 
-	snprintf(path_buff, PATH_BUFF_LEN, SYS_BATIF_PATH_FMT, mesh_iface);
+	snprintf(path_buff, PATH_BUFF_LEN, SYS_BATIF_PATH_FMT, state->mesh_iface);
 
 	if (argc == 1) {
 		res = read_file(path_buff, SYS_GW_MODE, USE_READ_BUFF, 0, 0, 0);
@@ -167,5 +167,5 @@ static int gw_mode(char *mesh_iface, int argc, char **argv)
 	return res;
 }
 
-COMMAND(gw_mode, "gw", COMMAND_FLAG_MESH_IFACE,
+COMMAND(gw_mode, "gw", COMMAND_FLAG_MESH_IFACE, NULL,
 	"[mode]            \tdisplay or modify the gateway mode");
interface.c +10 -10
index d2883a9..5f69cb3 100644
@@ -297,7 +297,7 @@ static int set_master_interface(const char *iface, unsigned int ifmaster)
 	return err;
 }
 
-static int interface(char *mesh_iface, int argc, char **argv)
+static int interface(struct state *state, int argc, char **argv)
 {
 	int i, optchar;
 	int ret;
@@ -327,7 +327,7 @@ static int interface(char *mesh_iface, int argc, char **argv)
 	rest_argv = &argv[optind];
 
 	if (rest_argc == 0)
-		return print_interfaces(mesh_iface);
+		return print_interfaces(state->mesh_iface);
 
 	check_root_or_die("batctl interface");
 
@@ -370,7 +370,7 @@ static int interface(char *mesh_iface, int argc, char **argv)
 
 	switch (rest_argv[0][0]) {
 	case 'c':
-		ret = create_interface(mesh_iface);
+		ret = create_interface(state->mesh_iface);
 		if (ret < 0) {
 			fprintf(stderr,
 				"Error - failed to add create batman-adv interface: %s\n",
@@ -379,7 +379,7 @@ static int interface(char *mesh_iface, int argc, char **argv)
 		}
 		return EXIT_SUCCESS;
 	case 'D':
-		ret = destroy_interface(mesh_iface);
+		ret = destroy_interface(state->mesh_iface);
 		if (ret < 0) {
 			fprintf(stderr,
 				"Error - failed to destroy batman-adv interface: %s\n",
@@ -392,9 +392,9 @@ static int interface(char *mesh_iface, int argc, char **argv)
 	}
 
 	/* get index of batman-adv interface - or try to create it */
-	ifmaster = if_nametoindex(mesh_iface);
+	ifmaster = if_nametoindex(state->mesh_iface);
 	if (!manual_mode && !ifmaster && rest_argv[0][0] == 'a') {
-		ret = create_interface(mesh_iface);
+		ret = create_interface(state->mesh_iface);
 		if (ret < 0) {
 			fprintf(stderr,
 				"Error - failed to create batman-adv interface: %s\n",
@@ -402,7 +402,7 @@ static int interface(char *mesh_iface, int argc, char **argv)
 			goto err;
 		}
 
-		ifmaster = if_nametoindex(mesh_iface);
+		ifmaster = if_nametoindex(state->mesh_iface);
 	}
 
 	if (!ifmaster) {
@@ -447,9 +447,9 @@ static int interface(char *mesh_iface, int argc, char **argv)
 
 	/* check if there is no interface left and then destroy mesh_iface */
 	if (!manual_mode && rest_argv[0][0] == 'd') {
-		cnt = count_interfaces(mesh_iface);
+		cnt = count_interfaces(state->mesh_iface);
 		if (cnt == 0)
-			destroy_interface(mesh_iface);
+			destroy_interface(state->mesh_iface);
 	}
 
 	return EXIT_SUCCESS;
@@ -458,5 +458,5 @@ static int interface(char *mesh_iface, int argc, char **argv)
 	return EXIT_FAILURE;
 }
 
-COMMAND(interface, "if", 0,
+COMMAND(interface, "if", 0, NULL,
 	"[add|del iface(s)]\tdisplay or modify the interface settings");
log.c +3 -3
index e28466d..b4f0b86 100644
@@ -36,7 +36,7 @@ static void log_usage(void)
 	fprintf(stderr, " \t -n don't replace mac addresses with bat-host names\n");
 }
 
-static int log_print(char *mesh_iface, int argc, char **argv)
+static int log_print(struct state *state, int argc, char **argv)
 {
 	int optchar, res, read_opt = USE_BAT_HOSTS | LOG_MODE;
 	char full_path[MAX_PATH+1];
@@ -64,10 +64,10 @@ static int log_print(char *mesh_iface, int argc, char **argv)
 		return EXIT_FAILURE;
 	}
 
-	debugfs_make_path(DEBUG_BATIF_PATH_FMT "/", mesh_iface, full_path, sizeof(full_path));
+	debugfs_make_path(DEBUG_BATIF_PATH_FMT "/", state->mesh_iface, full_path, sizeof(full_path));
 	res = read_file(full_path, DEBUG_LOG, read_opt, 0, 0, 0);
 	return res;
 }
 
-COMMAND_NAMED(log, "l", log_print, COMMAND_FLAG_MESH_IFACE,
+COMMAND_NAMED(log, "l", log_print, COMMAND_FLAG_MESH_IFACE, NULL,
 	      "                  \tread the log produced by the kernel module");
loglevel.c +3 -3
index 3dc1a1c..7a61524 100644
@@ -47,7 +47,7 @@ static void log_level_usage(void)
 	fprintf(stderr, " \t tp      Messages related to throughput meter\n");
 }
 
-static int loglevel(char *mesh_iface, int argc, char **argv)
+static int loglevel(struct state *state, int argc, char **argv)
 {
 	int optchar, res = EXIT_FAILURE;
 	int log_level = 0;
@@ -72,7 +72,7 @@ static int loglevel(char *mesh_iface, int argc, char **argv)
 		return EXIT_FAILURE;
 	}
 
-	snprintf(path_buff, PATH_BUFF_LEN, SYS_BATIF_PATH_FMT, mesh_iface);
+	snprintf(path_buff, PATH_BUFF_LEN, SYS_BATIF_PATH_FMT, state->mesh_iface);
 
 	if (argc != 1) {
 		check_root_or_die("batctl loglevel");
@@ -143,5 +143,5 @@ static int loglevel(char *mesh_iface, int argc, char **argv)
 	return res;
 }
 
-COMMAND(loglevel, "ll", COMMAND_FLAG_MESH_IFACE,
+COMMAND(loglevel, "ll", COMMAND_FLAG_MESH_IFACE, NULL,
 	"[level]           \tdisplay or modify the log level");
main.c +19 -10
index b9b19de..e20f914 100644
@@ -127,7 +127,10 @@ int main(int argc, char **argv)
 {
 	const struct command *cmd;
 	int i, ret = EXIT_FAILURE;
-	char *mesh_iface = mesh_dfl_iface;
+	struct state state = {
+		.mesh_iface = mesh_dfl_iface,
+		.cmd = NULL,
+	};
 	int opt;
 
 	while ((opt = getopt(argc, argv, "+hm:v")) != -1) {
@@ -137,13 +140,13 @@ int main(int argc, char **argv)
 			exit(EXIT_SUCCESS);
 			break;
 		case 'm':
-			if (mesh_iface != mesh_dfl_iface) {
+			if (state.mesh_iface != mesh_dfl_iface) {
 				fprintf(stderr,
 					"Error - multiple mesh interfaces specified\n");
 				goto err;
 			}
 
-			mesh_iface = argv[2];
+			state.mesh_iface = argv[2];
 			break;
 		case 'v':
 			version();
@@ -163,16 +166,22 @@ int main(int argc, char **argv)
 	optind = 0;
 
 	if ((cmd = find_command(argv[0]))) {
+		state.cmd = cmd;
+
 		if (cmd->flags & COMMAND_FLAG_MESH_IFACE &&
-		    check_mesh_iface(mesh_iface) < 0) {
-			fprintf(stderr, "Error - interface %s is not present or not a batman-adv interface\n", mesh_iface);
+		    check_mesh_iface(state.mesh_iface) < 0) {
+			fprintf(stderr,
+				"Error - interface %s is not present or not a batman-adv interface\n",
+				state.mesh_iface);
 			exit(EXIT_FAILURE);
 		}
 
-		ret = cmd->handler(mesh_iface, argc, argv);
+		ret = cmd->handler(&state, argc, argv);
 	} else {
-		if (check_mesh_iface(mesh_iface) < 0) {
-			fprintf(stderr, "Error - interface %s is not present or not a batman-adv interface\n", mesh_iface);
+		if (check_mesh_iface(state.mesh_iface) < 0) {
+			fprintf(stderr,
+				"Error - interface %s is not present or not a batman-adv interface\n",
+				state.mesh_iface);
 			exit(EXIT_FAILURE);
 		}
 
@@ -181,7 +190,7 @@ int main(int argc, char **argv)
 			    (strcmp(argv[0], batctl_settings[i].opt_short) != 0))
 				continue;
 
-			ret = handle_sys_setting(mesh_iface, i, argc, argv);
+			ret = handle_sys_setting(state.mesh_iface, i, argc, argv);
 			goto out;
 		}
 
@@ -190,7 +199,7 @@ int main(int argc, char **argv)
 			    (strcmp(argv[0], batctl_debug_tables[i].opt_short) != 0))
 				continue;
 
-			ret = handle_debug_table(mesh_iface, i, argc, argv);
+			ret = handle_debug_table(state.mesh_iface, i, argc, argv);
 			goto out;
 		}
 
main.h +11 -4
index b39e350..77eb432 100644
@@ -61,26 +61,33 @@ enum command_flags {
 	COMMAND_FLAG_MESH_IFACE = BIT(0),
 };
 
+struct state {
+	char *mesh_iface;
+	const struct command *cmd;
+};
+
 struct command {
 	const char *name;
 	const char *abbr;
-	int (*handler)(char *mesh_iface, int argc, char **argv);
+	int (*handler)(struct state *state, int argc, char **argv);
 	uint32_t flags;
+	void *arg;
 	const char *usage;
 };
 
-#define COMMAND_NAMED(_name, _abbr, _handler, _flags, _usage) \
+#define COMMAND_NAMED(_name, _abbr, _handler, _flags, _arg, _usage) \
 	static const struct command command_ ## _name = { \
 		.name = (#_name), \
 		.abbr = _abbr, \
 		.handler = (_handler), \
 		.flags = (_flags), \
+		.arg = (_arg), \
 		.usage = (_usage), \
 	}; \
 	static const struct command *__command_ ## _name \
 	__attribute__((__used__)) __attribute__ ((__section__ ("__command"))) = &command_ ## _name
 
-#define COMMAND(_handler, _abbr, _flags, _usage) \
-	COMMAND_NAMED(_handler, _abbr, _handler, _flags, _usage)
+#define COMMAND(_handler, _abbr, _flags, _arg, _usage) \
+	COMMAND_NAMED(_handler, _abbr, _handler, _flags, _arg, _usage)
 
 #endif
ping.c +4 -4
index efaf011..24af0e8 100644
@@ -72,7 +72,7 @@ static void sig_handler(int sig)
 	}
 }
 
-static int ping(char *mesh_iface, int argc, char **argv)
+static int ping(struct state *state, int argc, char **argv)
 {
 	struct batadv_icmp_packet_rr icmp_packet_out, icmp_packet_in;
 	struct timeval tv;
@@ -152,7 +152,7 @@ static int ping(char *mesh_iface, int argc, char **argv)
 	}
 
 	if (!disable_translate_mac)
-		dst_mac = translate_mac(mesh_iface, dst_mac);
+		dst_mac = translate_mac(state->mesh_iface, dst_mac);
 
 	mac_string = ether_ntoa_long(dst_mac);
 	signal(SIGINT, sig_handler);
@@ -199,7 +199,7 @@ static int ping(char *mesh_iface, int argc, char **argv)
 
 		icmp_packet_out.seqno = htons(++seq_counter);
 
-		res = icmp_interface_write(mesh_iface,
+		res = icmp_interface_write(state->mesh_iface,
 					   (struct batadv_icmp_header *)&icmp_packet_out,
 					   packet_len);
 		if (res < 0) {
@@ -345,5 +345,5 @@ static int ping(char *mesh_iface, int argc, char **argv)
 	return ret;
 }
 
-COMMAND(ping, "p", COMMAND_FLAG_MESH_IFACE,
+COMMAND(ping, "p", COMMAND_FLAG_MESH_IFACE, NULL,
 	"<destination>     \tping another batman adv host via layer 2");
routing_algo.c +2 -2
index 8cc4ff1..30e588b 100644
@@ -41,7 +41,7 @@ static void ra_mode_usage(void)
 	fprintf(stderr, " \t -h print this help\n");
 }
 
-static int routing_algo(char *mesh_iface __maybe_unused, int argc, char **argv)
+static int routing_algo(struct state *state __maybe_unused, int argc, char **argv)
 {
 	DIR *iface_base_dir;
 	struct dirent *iface_dir;
@@ -126,5 +126,5 @@ static int routing_algo(char *mesh_iface __maybe_unused, int argc, char **argv)
 	return res;
 }
 
-COMMAND(routing_algo, "ra", 0,
+COMMAND(routing_algo, "ra", 0, NULL,
 	"[mode]            \tdisplay or modify the routing algorithm");
statistics.c +3 -3
index 908bbaf..26ffe44 100644
@@ -102,14 +102,14 @@ static int statistics_custom_get(int fd, struct ifreq *ifr)
 	return ret;
 }
 
-static int statistics(char *mesh_iface, int argc __maybe_unused,
+static int statistics(struct state *state, int argc __maybe_unused,
 		      char **argv __maybe_unused)
 {
 	struct ifreq ifr;
 	int fd = -1, ret = EXIT_FAILURE;
 
 	memset(&ifr, 0, sizeof(ifr));
-	strncpy(ifr.ifr_name, mesh_iface, sizeof(ifr.ifr_name));
+	strncpy(ifr.ifr_name, state->mesh_iface, sizeof(ifr.ifr_name));
 	ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
 
 	fd = socket(AF_INET, SOCK_DGRAM, 0);
@@ -126,5 +126,5 @@ static int statistics(char *mesh_iface, int argc __maybe_unused,
 	return ret;
 }
 
-COMMAND(statistics, "s", COMMAND_FLAG_MESH_IFACE,
+COMMAND(statistics, "s", COMMAND_FLAG_MESH_IFACE, NULL,
 	"                  \tprint mesh statistics");
tcpdump.c +2 -2
index 62e4a64..5c93842 100644
@@ -1210,7 +1210,7 @@ static void sig_handler(int sig)
 	}
 }
 
-static int tcpdump(char *mesh_iface __maybe_unused, int argc, char **argv)
+static int tcpdump(struct state *state __maybe_unused, int argc, char **argv)
 {
 	struct timeval tv;
 	struct dump_if *dump_if, *dump_if_tmp;
@@ -1352,5 +1352,5 @@ static int tcpdump(char *mesh_iface __maybe_unused, int argc, char **argv)
 	return ret;
 }
 
-COMMAND(tcpdump, "td", 0,
+COMMAND(tcpdump, "td", 0, NULL,
 	"<interface>       \ttcpdump layer 2 traffic on the given interface");
throughputmeter.c +4 -4
index ebd35a6..0c5e38a 100644
@@ -388,7 +388,7 @@ static void tp_meter_usage(void)
 	fprintf(stderr, "\t -n don't convert addresses to bat-host names\n");
 }
 
-static int throughputmeter(char *mesh_iface, int argc, char **argv)
+static int throughputmeter(struct state *state, int argc, char **argv)
 {
 	struct bat_host *bat_host;
 	uint64_t throughput;
@@ -458,7 +458,7 @@ static int throughputmeter(char *mesh_iface, int argc, char **argv)
 		dst_string = ether_ntoa_long(dst_mac);
 
 	/* for sighandler */
-	tp_mesh_iface = mesh_iface;
+	tp_mesh_iface = state->mesh_iface;
 	signal(SIGINT, tp_sig_handler);
 	signal(SIGTERM, tp_sig_handler);
 
@@ -466,7 +466,7 @@ static int throughputmeter(char *mesh_iface, int argc, char **argv)
 	if (!listen_sock)
 		goto out;
 
-	ret = tp_meter_start(mesh_iface, dst_mac, time, &cookie);
+	ret = tp_meter_start(state->mesh_iface, dst_mac, time, &cookie);
 	if (ret < 0) {
 		printf("Failed to send tp_meter request to kernel: %d\n", ret);
 		goto out;
@@ -543,5 +543,5 @@ static int throughputmeter(char *mesh_iface, int argc, char **argv)
 	return ret;
 }
 
-COMMAND(throughputmeter, "tp", COMMAND_FLAG_MESH_IFACE,
+COMMAND(throughputmeter, "tp", COMMAND_FLAG_MESH_IFACE, NULL,
 	"<destination>     \tstart a throughput measurement");
traceroute.c +4 -4
index 9446bcd..77c3188 100644
@@ -55,7 +55,7 @@ static void traceroute_usage(void)
 	fprintf(stderr, " \t -T don't try to translate mac to originator address\n");
 }
 
-static int traceroute(char *mesh_iface, int argc, char **argv)
+static int traceroute(struct state *state, int argc, char **argv)
 {
 	struct batadv_icmp_packet icmp_packet_out, icmp_packet_in;
 	struct bat_host *bat_host;
@@ -113,7 +113,7 @@ static int traceroute(char *mesh_iface, int argc, char **argv)
 	}
 
 	if (!disable_translate_mac)
-		dst_mac = translate_mac(mesh_iface, dst_mac);
+		dst_mac = translate_mac(state->mesh_iface, dst_mac);
 
 	mac_string = ether_ntoa_long(dst_mac);
 
@@ -146,7 +146,7 @@ static int traceroute(char *mesh_iface, int argc, char **argv)
 			icmp_packet_out.seqno = htons(++seq_counter);
 			time_delta[i] = 0.0;
 
-			res = icmp_interface_write(mesh_iface,
+			res = icmp_interface_write(state->mesh_iface,
 					   (struct batadv_icmp_header *)&icmp_packet_out,
 					   sizeof(icmp_packet_out));
 			if (res < 0) {
@@ -231,5 +231,5 @@ static int traceroute(char *mesh_iface, int argc, char **argv)
 	return ret;
 }
 
-COMMAND(traceroute, "tr", COMMAND_FLAG_MESH_IFACE,
+COMMAND(traceroute, "tr", COMMAND_FLAG_MESH_IFACE, NULL,
 	"<destination>     \ttraceroute another batman adv host via layer 2");
translate.c +3 -3
index 95de9a2..38f26df 100644
@@ -33,7 +33,7 @@ static void translate_usage(void)
 	fprintf(stderr, "Usage: batctl [options] translate mac|bat-host|host_name|IPv4_address\n");
 }
 
-static int translate(char *mesh_iface, int argc, char **argv)
+static int translate(struct state *state, int argc, char **argv)
 {
 	struct ether_addr *dst_mac = NULL;
 	struct bat_host *bat_host;
@@ -64,7 +64,7 @@ static int translate(char *mesh_iface, int argc, char **argv)
 		}
 	}
 
-	dst_mac = translate_mac(mesh_iface, dst_mac);
+	dst_mac = translate_mac(state->mesh_iface, dst_mac);
 	if (dst_mac) {
 		mac_string = ether_ntoa_long(dst_mac);
 		printf("%s\n", mac_string);
@@ -78,5 +78,5 @@ static int translate(char *mesh_iface, int argc, char **argv)
 	return ret;
 }
 
-COMMAND(translate, "t", COMMAND_FLAG_MESH_IFACE,
+COMMAND(translate, "t", COMMAND_FLAG_MESH_IFACE, NULL,
 	"<destination>     \ttranslate a destination to the originator responsible for it");
Signature · 1 line
2.11.0
#15 lore raw

PATCH v3 15/42 batctl: Add type to command to structure usage output

In reply to Sven Eckelmann

The usage output of batctl is structured in different sections. This should be preserved when the remaining subcommands are converted to the command infrastructure.

---
 bisect_iv.c       |  2 +-
 gw_mode.c         |  2 +-
 interface.c       |  2 +-
 log.c             |  2 +-
 loglevel.c        |  2 +-
 main.c            | 68 +++++++++++++++++++++++++++++++++++--------------------
 main.h            | 12 +++++++---
 ping.c            |  2 +-
 routing_algo.c    |  2 +-
 statistics.c      |  2 +-
 tcpdump.c         |  2 +-
 throughputmeter.c |  2 +-
 traceroute.c      |  2 +-
 translate.c       |  2 +-
 14 files changed, 64 insertions(+), 40 deletions(-)
bisect_iv.c +1 -1
index c6fc708..420317e 100644
@@ -1595,5 +1595,5 @@ static int bisect_iv(struct state *state __maybe_unused, int argc, char **argv)
 	return ret;
 }
 
-COMMAND(bisect_iv, "bisect_iv", 0, NULL,
+COMMAND(SUBCOMMAND, bisect_iv, "bisect_iv", 0, NULL,
 	"<file1> .. <fileN>\tanalyze given batman iv log files for routing stability");
gw_mode.c +1 -1
index bd530d5..4093f89 100644
@@ -167,5 +167,5 @@ static int gw_mode(struct state *state, int argc, char **argv)
 	return res;
 }
 
-COMMAND(gw_mode, "gw", COMMAND_FLAG_MESH_IFACE, NULL,
+COMMAND(SUBCOMMAND, gw_mode, "gw", COMMAND_FLAG_MESH_IFACE, NULL,
 	"[mode]            \tdisplay or modify the gateway mode");
interface.c +1 -1
index 5f69cb3..3c176a8 100644
@@ -458,5 +458,5 @@ static int interface(struct state *state, int argc, char **argv)
 	return EXIT_FAILURE;
 }
 
-COMMAND(interface, "if", 0, NULL,
+COMMAND(SUBCOMMAND, interface, "if", 0, NULL,
 	"[add|del iface(s)]\tdisplay or modify the interface settings");
log.c +1 -1
index b4f0b86..cd69676 100644
@@ -69,5 +69,5 @@ static int log_print(struct state *state, int argc, char **argv)
 	return res;
 }
 
-COMMAND_NAMED(log, "l", log_print, COMMAND_FLAG_MESH_IFACE, NULL,
+COMMAND_NAMED(SUBCOMMAND, log, "l", log_print, COMMAND_FLAG_MESH_IFACE, NULL,
 	      "                  \tread the log produced by the kernel module");
loglevel.c +1 -1
index 7a61524..fed70c8 100644
@@ -143,5 +143,5 @@ static int loglevel(struct state *state, int argc, char **argv)
 	return res;
 }
 
-COMMAND(loglevel, "ll", COMMAND_FLAG_MESH_IFACE, NULL,
+COMMAND(SUBCOMMAND, loglevel, "ll", COMMAND_FLAG_MESH_IFACE, NULL,
 	"[level]           \tdisplay or modify the log level");
main.c +43 -25

88 lines not on this page · raw message

main.h +9 -3
index 77eb432..052304c 100644
@@ -61,12 +61,17 @@ enum command_flags {
 	COMMAND_FLAG_MESH_IFACE = BIT(0),
 };
 
+enum command_type {
+	SUBCOMMAND,
+};
+
 struct state {
 	char *mesh_iface;
 	const struct command *cmd;
 };
 
 struct command {
+	enum command_type type;
 	const char *name;
 	const char *abbr;
 	int (*handler)(struct state *state, int argc, char **argv);
@@ -75,8 +80,9 @@ struct command {
 	const char *usage;
 };
 
-#define COMMAND_NAMED(_name, _abbr, _handler, _flags, _arg, _usage) \
+#define COMMAND_NAMED(_type, _name, _abbr, _handler, _flags, _arg, _usage) \
 	static const struct command command_ ## _name = { \
+		.type = (_type), \
 		.name = (#_name), \
 		.abbr = _abbr, \
 		.handler = (_handler), \
@@ -87,7 +93,7 @@ struct command {
 	static const struct command *__command_ ## _name \
 	__attribute__((__used__)) __attribute__ ((__section__ ("__command"))) = &command_ ## _name
 
-#define COMMAND(_handler, _abbr, _flags, _arg, _usage) \
-	COMMAND_NAMED(_handler, _abbr, _handler, _flags, _arg, _usage)
+#define COMMAND(_type, _handler, _abbr, _flags, _arg, _usage) \
+	COMMAND_NAMED(_type, _handler, _abbr, _handler, _flags, _arg, _usage)
 
 #endif
ping.c +1 -1
index 24af0e8..5c13d81 100644
@@ -345,5 +345,5 @@ static int ping(struct state *state, int argc, char **argv)
 	return ret;
 }
 
-COMMAND(ping, "p", COMMAND_FLAG_MESH_IFACE, NULL,
+COMMAND(SUBCOMMAND, ping, "p", COMMAND_FLAG_MESH_IFACE, NULL,
 	"<destination>     \tping another batman adv host via layer 2");
routing_algo.c +1 -1
index 30e588b..ded9284 100644
@@ -126,5 +126,5 @@ static int routing_algo(struct state *state __maybe_unused, int argc, char **arg
 	return res;
 }
 
-COMMAND(routing_algo, "ra", 0, NULL,
+COMMAND(SUBCOMMAND, routing_algo, "ra", 0, NULL,
 	"[mode]            \tdisplay or modify the routing algorithm");
statistics.c +1 -1
index 26ffe44..d684fa5 100644
@@ -126,5 +126,5 @@ static int statistics(struct state *state, int argc __maybe_unused,
 	return ret;
 }
 
-COMMAND(statistics, "s", COMMAND_FLAG_MESH_IFACE, NULL,
+COMMAND(SUBCOMMAND, statistics, "s", COMMAND_FLAG_MESH_IFACE, NULL,
 	"                  \tprint mesh statistics");
tcpdump.c +1 -1
index 5c93842..42713d3 100644
@@ -1352,5 +1352,5 @@ static int tcpdump(struct state *state __maybe_unused, int argc, char **argv)
 	return ret;
 }
 
-COMMAND(tcpdump, "td", 0, NULL,
+COMMAND(SUBCOMMAND, tcpdump, "td", 0, NULL,
 	"<interface>       \ttcpdump layer 2 traffic on the given interface");
throughputmeter.c +1 -1
index 0c5e38a..de20b66 100644
@@ -543,5 +543,5 @@ static int throughputmeter(struct state *state, int argc, char **argv)
 	return ret;
 }
 
-COMMAND(throughputmeter, "tp", COMMAND_FLAG_MESH_IFACE, NULL,
+COMMAND(SUBCOMMAND, throughputmeter, "tp", COMMAND_FLAG_MESH_IFACE, NULL,
 	"<destination>     \tstart a throughput measurement");
traceroute.c +1 -1
index 77c3188..6e325c4 100644
@@ -231,5 +231,5 @@ static int traceroute(struct state *state, int argc, char **argv)
 	return ret;
 }
 
-COMMAND(traceroute, "tr", COMMAND_FLAG_MESH_IFACE, NULL,
+COMMAND(SUBCOMMAND, traceroute, "tr", COMMAND_FLAG_MESH_IFACE, NULL,
 	"<destination>     \ttraceroute another batman adv host via layer 2");
translate.c +1 -1
index 38f26df..ad51ddf 100644
@@ -78,5 +78,5 @@ static int translate(struct state *state, int argc, char **argv)
 	return ret;
 }
 
-COMMAND(translate, "t", COMMAND_FLAG_MESH_IFACE, NULL,
+COMMAND(SUBCOMMAND, translate, "t", COMMAND_FLAG_MESH_IFACE, NULL,
 	"<destination>     \ttranslate a destination to the originator responsible for it");
Signature · 1 line
2.11.0
#16 lore raw

PATCH v3 16/42 batctl: Convert debug table to command infrastructure

In reply to Sven Eckelmann

Most of the commands were already converted to the new command infrastructure. To use the new state and pre-initialization steps, the debugfs tables also have to be converted.

---
 debug.c     | 228 +++++++++++++++++++++++++++++++++---------------------------
 debug.h     |  35 ++++------
 functions.c |  10 +--
 main.c      |  19 ++---
 main.h      |   2 +-
 5 files changed, 150 insertions(+), 144 deletions(-)
debug.c +127 -101
index 9bc4d0c..016b148 100644
@@ -32,101 +32,34 @@
 #include "netlink.h"
 #include "sys.h"
 
-const struct debug_table_data batctl_debug_tables[BATCTL_TABLE_NUM] = {
-	{
-		.opt_long = "neighbors",
-		.opt_short = "n",
-		.debugfs_name = "neighbors",
-		.header_lines = 2,
-		.netlink_fn = netlink_print_neighbors,
-	},
-	{
-		.opt_long = "originators",
-		.opt_short = "o",
-		.debugfs_name = "originators",
-		.header_lines = 2,
-		.netlink_fn = netlink_print_originators,
-	},
-	{
-		.opt_long = "gateways",
-		.opt_short = "gwl",
-		.debugfs_name = "gateways",
-		.header_lines = 1,
-		.netlink_fn = netlink_print_gateways,
-	},
-	{
-		.opt_long = "translocal",
-		.opt_short = "tl",
-		.debugfs_name = "transtable_local",
-		.header_lines = 2,
-		.netlink_fn = netlink_print_translocal,
-	},
-	{
-		.opt_long = "transglobal",
-		.opt_short = "tg",
-		.debugfs_name = "transtable_global",
-		.header_lines = 2,
-		.netlink_fn = netlink_print_transglobal,
-	},
-	{
-		.opt_long = "claimtable",
-		.opt_short = "cl",
-		.debugfs_name = "bla_claim_table",
-		.header_lines = 2,
-		.netlink_fn = netlink_print_bla_claim,
-	},
-	{
-		.opt_long = "backbonetable",
-		.opt_short = "bbt",
-		.debugfs_name = "bla_backbone_table",
-		.header_lines = 2,
-		.netlink_fn = netlink_print_bla_backbone,
-	},
-	{
-		.opt_long = "dat_cache",
-		.opt_short = "dc",
-		.debugfs_name = "dat_cache",
-		.header_lines = 2,
-		.netlink_fn = netlink_print_dat_cache,
-	},
-	{
-		.opt_long = "nc_nodes",
-		.opt_short = "nn",
-		.debugfs_name = "nc_nodes",
-		.header_lines = 0,
-	},
-	{
-		.opt_long = "mcast_flags",
-		.opt_short = "mf",
-		.debugfs_name = "mcast_flags",
-		.header_lines = 6,
-		.netlink_fn = netlink_print_mcast_flags,
-	},
-};
-
-static void debug_table_usage(int debug_table)
+static void debug_table_usage(struct state *state)
 {
+	struct debug_table_data *debug_table = state->cmd->arg;
+
 	fprintf(stderr, "Usage: batctl [options] %s|%s [parameters]\n",
-	       batctl_debug_tables[debug_table].opt_long, batctl_debug_tables[debug_table].opt_short);
+		state->cmd->name, state->cmd->abbr);
 	fprintf(stderr, "parameters:\n");
 	fprintf(stderr, " \t -h print this help\n");
 	fprintf(stderr, " \t -n don't replace mac addresses with bat-host names\n");
 	fprintf(stderr, " \t -H don't show the header\n");
 	fprintf(stderr, " \t -w [interval] watch mode - refresh the table continuously\n");
 
-	if (debug_table == BATCTL_TABLE_ORIGINATORS) {
+	if (debug_table->option_watch_interval)
 		fprintf(stderr, " \t -t timeout interval - don't print originators not seen for x.y seconds \n");
+
+	if (debug_table->option_orig_iface)
 		fprintf(stderr, " \t -i [interface] - show multiif originator table for a specific interface\n");
-	}
 
-	if (debug_table == BATCTL_TABLE_TRANSLOCAL ||
-	    debug_table == BATCTL_TABLE_TRANSGLOBAL) {
-		fprintf(stderr, " \t -u|-m print unicast or multicast mac addresses only\n");
-	}
+	if (debug_table->option_unicast_only)
+		fprintf(stderr, " \t -u print unicast mac addresses only\n");
+
+	if (debug_table->option_multicast_only)
+		fprintf(stderr, " \t -m print multicast mac addresses only\n");
 }
 
-int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv)
+int handle_debug_table(struct state *state, int argc, char **argv)
 {
+	struct debug_table_data *debug_table = state->cmd->arg;
 	int optchar, read_opt = USE_BAT_HOSTS;
 	char full_path[MAX_PATH+1];
 	char *debugfs_mnt;
@@ -138,7 +71,7 @@ int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv)
 	while ((optchar = getopt(argc, argv, "hnw:t:Humi:")) != -1) {
 		switch (optchar) {
 		case 'h':
-			debug_table_usage(debug_table);
+			debug_table_usage(state);
 			return EXIT_SUCCESS;
 		case 'n':
 			read_opt &= ~USE_BAT_HOSTS;
@@ -156,9 +89,9 @@ int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv)
 			}
 			break;
 		case 't':
-			if (debug_table != BATCTL_TABLE_ORIGINATORS) {
+			if (debug_table->option_watch_interval) {
 				fprintf(stderr, "Error - unrecognised option '-%c'\n", optchar);
-				debug_table_usage(debug_table);
+				debug_table_usage(state);
 				return EXIT_FAILURE;
 			}
 
@@ -172,33 +105,31 @@ int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv)
 			read_opt |= SKIP_HEADER;
 			break;
 		case 'u':
-			if (debug_table != BATCTL_TABLE_TRANSLOCAL &&
-			    debug_table != BATCTL_TABLE_TRANSGLOBAL) {
+			if (debug_table->option_unicast_only) {
 				fprintf(stderr, "Error - unrecognised option '-%c'\n", optchar);
-				debug_table_usage(debug_table);
+				debug_table_usage(state);
 				return EXIT_FAILURE;
 			}
 
 			read_opt |= UNICAST_ONLY;
 			break;
 		case 'm':
-			if (debug_table != BATCTL_TABLE_TRANSLOCAL &&
-			    debug_table != BATCTL_TABLE_TRANSGLOBAL) {
+			if (debug_table->option_multicast_only) {
 				fprintf(stderr, "Error - unrecognised option '-%c'\n", optchar);
-				debug_table_usage(debug_table);
+				debug_table_usage(state);
 				return EXIT_FAILURE;
 			}
 
 			read_opt |= MULTICAST_ONLY;
 			break;
 		case 'i':
-			if (debug_table != BATCTL_TABLE_ORIGINATORS) {
+			if (debug_table->option_orig_iface) {
 				fprintf(stderr, "Error - unrecognised option '-%c'\n", optchar);
-				debug_table_usage(debug_table);
+				debug_table_usage(state);
 				return EXIT_FAILURE;
 			}
 
-			if (check_mesh_iface_ownership(mesh_iface, optarg) != EXIT_SUCCESS)
+			if (check_mesh_iface_ownership(state->mesh_iface, optarg) != EXIT_SUCCESS)
 				return EXIT_FAILURE;
 
 			orig_iface = optarg;
@@ -217,7 +148,7 @@ int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv)
 
 			return EXIT_FAILURE;
 		default:
-			debug_table_usage(debug_table);
+			debug_table_usage(state);
 			return EXIT_FAILURE;
 		}
 	}
@@ -226,7 +157,7 @@ int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv)
 
 	if (read_opt & UNICAST_ONLY && read_opt & MULTICAST_ONLY) {
 		fprintf(stderr, "Error - '-u' and '-m' are exclusive options\n");
-		debug_table_usage(debug_table);
+		debug_table_usage(state);
 		return EXIT_FAILURE;
 	}
 
@@ -236,9 +167,9 @@ int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv)
 		return EXIT_FAILURE;
 	}
 
-	if (batctl_debug_tables[debug_table].netlink_fn) {
-		err = batctl_debug_tables[debug_table].netlink_fn(
-			mesh_iface, orig_iface, read_opt, orig_timeout,
+	if (debug_table->netlink_fn) {
+		err = debug_table->netlink_fn(
+			state->mesh_iface, orig_iface, read_opt, orig_timeout,
 			watch_interval);
 		if (err != -EOPNOTSUPP)
 			return err;
@@ -247,11 +178,11 @@ int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv)
 	if (orig_iface)
 		debugfs_make_path(DEBUG_BATIF_PATH_FMT "/", orig_iface, full_path, sizeof(full_path));
 	else
-		debugfs_make_path(DEBUG_BATIF_PATH_FMT "/", mesh_iface, full_path, sizeof(full_path));
+		debugfs_make_path(DEBUG_BATIF_PATH_FMT "/", state->mesh_iface, full_path, sizeof(full_path));
 
-	return read_file(full_path, (char *)batctl_debug_tables[debug_table].debugfs_name,
+	return read_file(full_path, debug_table->debugfs_name,
 			 read_opt, orig_timeout, watch_interval,
-			 batctl_debug_tables[debug_table].header_lines);
+			 debug_table->header_lines);
 }
 
 int debug_print_routing_algos(void)
@@ -268,3 +199,98 @@ int debug_print_routing_algos(void)
 	debugfs_make_path(DEBUG_BATIF_PATH_FMT, "", full_path, sizeof(full_path));
 	return read_file(full_path, DEBUG_ROUTING_ALGOS, 0, 0, 0, 0);
 }
+
+static struct debug_table_data batctl_debug_table_neighbors = {
+	.debugfs_name = "neighbors",
+	.header_lines = 2,
+	.netlink_fn = netlink_print_neighbors,
+};
+
+COMMAND_NAMED(DEBUGTABLE, neighbors, "n", handle_debug_table,
+	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_neighbors, "");
+
+static struct debug_table_data batctl_debug_table_originators = {
+	.debugfs_name = "originators",
+	.header_lines = 2,
+	.netlink_fn = netlink_print_originators,
+	.option_watch_interval = 1,
+	.option_orig_iface = 1,
+};
+
+COMMAND_NAMED(DEBUGTABLE, originators, "o", handle_debug_table,
+	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_originators, "");
+
+static struct debug_table_data batctl_debug_table_gateways = {
+	.debugfs_name = "gateways",
+	.header_lines = 1,
+	.netlink_fn = netlink_print_gateways,
+};
+
+COMMAND_NAMED(DEBUGTABLE, gateways, "gwl", handle_debug_table,
+	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_gateways, "");
+
+static struct debug_table_data batctl_debug_table_translocal = {
+	.debugfs_name = "transtable_local",
+	.header_lines = 2,
+	.netlink_fn = netlink_print_translocal,
+	.option_unicast_only = 1,
+	.option_multicast_only = 1,
+};
+
+COMMAND_NAMED(DEBUGTABLE, translocal, "tl", handle_debug_table,
+	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_translocal, "");
+
+static struct debug_table_data batctl_debug_table_transglobal = {
+	.debugfs_name = "transtable_global",
+	.header_lines = 2,
+	.netlink_fn = netlink_print_transglobal,
+	.option_unicast_only = 1,
+	.option_multicast_only = 1,
+};
+
+COMMAND_NAMED(DEBUGTABLE, transglobal, "tg", handle_debug_table,
+	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_transglobal, "");
+
+static struct debug_table_data batctl_debug_table_claimtable = {
+	.debugfs_name = DEBUG_CLAIMTABLE,
+	.header_lines = 2,
+	.netlink_fn = netlink_print_bla_claim,
+};
+
+COMMAND_NAMED(DEBUGTABLE, claimtable, "cl", handle_debug_table,
+	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_claimtable, "");
+
+static struct debug_table_data batctl_debug_table_backbonetable = {
+	.debugfs_name = DEBUG_BACKBONETABLE,
+	.header_lines = 2,
+	.netlink_fn = netlink_print_bla_backbone,
+};
+
+COMMAND_NAMED(DEBUGTABLE, backbonetable, "bbt", handle_debug_table,
+	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_backbonetable, "");
+
+static struct debug_table_data batctl_debug_table_dat_cache = {
+	.debugfs_name = DEBUG_DAT_CACHE,
+	.header_lines = 2,
+	.netlink_fn = netlink_print_dat_cache,
+};
+
+COMMAND_NAMED(DEBUGTABLE, dat_cache, "dc", handle_debug_table,
+	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_dat_cache, "");
+
+static struct debug_table_data batctl_debug_table_nc_nodes = {
+	.debugfs_name = DEBUG_NC_NODES,
+	.header_lines = 0,
+};
+
+COMMAND_NAMED(DEBUGTABLE, nc_nodes, "nn", handle_debug_table,
+	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_nc_nodes, "");
+
+static struct debug_table_data batctl_debug_table_mcast_flags = {
+	.debugfs_name = DEBUG_MCAST_FLAGS,
+	.header_lines = 6,
+	.netlink_fn = netlink_print_mcast_flags,
+};
+
+COMMAND_NAMED(DEBUGTABLE, mcast_flags, "mf", handle_debug_table,
+	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_mcast_flags, "");
debug.h +13 -22
index d9a2e3a..79c489a 100644
@@ -28,35 +28,26 @@
 
 #define DEBUG_BATIF_PATH_FMT "%s/batman_adv/%s"
 #define DEBUG_TRANSTABLE_GLOBAL "transtable_global"
+#define DEBUG_BACKBONETABLE "bla_backbone_table"
+#define DEBUG_CLAIMTABLE "bla_claim_table"
+#define DEBUG_DAT_CACHE "dat_cache"
+#define DEBUG_NC_NODES "nc_nodes"
+#define DEBUG_MCAST_FLAGS "mcast_flags"
 #define DEBUG_LOG "log"
 #define DEBUG_ROUTING_ALGOS "routing_algos"
 
-enum batctl_debug_tables {
-	BATCTL_TABLE_NEIGHBORS,
-	BATCTL_TABLE_ORIGINATORS,
-	BATCTL_TABLE_GATEWAYS,
-	BATCTL_TABLE_TRANSLOCAL,
-	BATCTL_TABLE_TRANSGLOBAL,
-	BATCTL_TABLE_BLA_CLAIMS,
-	BATCTL_TABLE_BLA_BACKBONES,
-	BATCTL_TABLE_DAT,
-	BATCTL_TABLE_NETWORK_CODING_NODES,
-	BATCTL_TABLE_MCAST_FLAGS,
-	BATCTL_TABLE_NUM,
-};
-
 struct debug_table_data {
-       const char opt_long[OPT_LONG_MAX_LEN];
-       const char opt_short[OPT_SHORT_MAX_LEN];
-       const char debugfs_name[DEBUG_TABLE_PATH_MAX_LEN];
-       size_t header_lines;
-       int (*netlink_fn)(char *mesh_iface, char *hard_iface, int read_opt,
+	const char *debugfs_name;
+	size_t header_lines;
+	int (*netlink_fn)(char *mesh_iface, char *hard_iface, int read_opt,
 			 float orig_timeout, float watch_interval);
+	unsigned int option_unicast_only:1;
+	unsigned int option_multicast_only:1;
+	unsigned int option_watch_interval:1;
+	unsigned int option_orig_iface:1;
 };
 
-extern const struct debug_table_data batctl_debug_tables[BATCTL_TABLE_NUM];
-
-int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv);
+int handle_debug_table(struct state *state, int argc, char **argv);
 int debug_print_routing_algos(void);
 
 #endif
functions.c +5 -5
index e0e9978..faa9478 100644
@@ -73,11 +73,11 @@ const char *fs_compile_out_param[] = {
 	batctl_settings[BATCTL_SETTINGS_DAT].sysfs_name,
 	batctl_settings[BATCTL_SETTINGS_NETWORK_CODING].sysfs_name,
 	batctl_settings[BATCTL_SETTINGS_MULTICAST_MODE].sysfs_name,
-	batctl_debug_tables[BATCTL_TABLE_BLA_CLAIMS].debugfs_name,
-	batctl_debug_tables[BATCTL_TABLE_BLA_BACKBONES].debugfs_name,
-	batctl_debug_tables[BATCTL_TABLE_DAT].debugfs_name,
-	batctl_debug_tables[BATCTL_TABLE_NETWORK_CODING_NODES].debugfs_name,
-	batctl_debug_tables[BATCTL_TABLE_MCAST_FLAGS].debugfs_name,
+	DEBUG_DAT_CACHE,
+	DEBUG_BACKBONETABLE,
+	DEBUG_DAT_CACHE,
+	DEBUG_NC_NODES,
+	DEBUG_MCAST_FLAGS,
 	NULL,
 };
 
main.c +4 -15
index 251d753..f5920a4 100644
@@ -43,6 +43,7 @@ static void print_usage(void)
 {
 	enum command_type type[] = {
 		SUBCOMMAND,
+		DEBUGTABLE,
 	};
 	const struct command **p;
 	int opt_indent;
@@ -63,6 +64,9 @@ static void print_usage(void)
 		case SUBCOMMAND:
 			fprintf(stderr, "commands:\n");
 			break;
+		case DEBUGTABLE:
+			fprintf(stderr, "debug tables:                                   \tdisplay the corresponding debug table\n");
+			break;
 		}
 
 		for (p = __start___command; p < __stop___command; p++) {
@@ -97,12 +101,6 @@ static void print_usage(void)
 			}
 		}
 	}
-
-	fprintf(stderr, "\n");
-
-	fprintf(stderr, "debug tables:                                   \tdisplay the corresponding debug table\n");
-	for (i = 0; i < BATCTL_TABLE_NUM; i++)
-		fprintf(stderr, " \t%s|%s\n", batctl_debug_tables[i].opt_long, batctl_debug_tables[i].opt_short);
 }
 
 static void version(void)
@@ -212,15 +210,6 @@ int main(int argc, char **argv)
 			goto out;
 		}
 
-		for (i = 0; i < BATCTL_TABLE_NUM; i++) {
-			if ((strcmp(argv[0], batctl_debug_tables[i].opt_long) != 0) &&
-			    (strcmp(argv[0], batctl_debug_tables[i].opt_short) != 0))
-				continue;
-
-			ret = handle_debug_table(state.mesh_iface, i, argc, argv);
-			goto out;
-		}
-
 		fprintf(stderr,
 			"Error - no valid command or debug table specified: %s\n",
 			argv[0]);
main.h +1 -1
index 052304c..5fa248c 100644
@@ -34,7 +34,6 @@
 #define OPT_LONG_MAX_LEN 25
 #define OPT_SHORT_MAX_LEN 5
 
-#define DEBUG_TABLE_PATH_MAX_LEN 20
 #define SETTINGS_PATH_MAX_LEN 25
 
 #if BYTE_ORDER == BIG_ENDIAN
@@ -63,6 +62,7 @@ enum command_flags {
 
 enum command_type {
 	SUBCOMMAND,
+	DEBUGTABLE,
 };
 
 struct state {
Signature · 1 line
2.11.0
#17 lore raw

PATCH v3 17/42 batctl: Convert sysfs settings to command infrastructure

In reply to Sven Eckelmann

Most of the commands were already converted to the new command infrastructure. To use the new state and pre-initialization steps, the sysfs settings also have to be converted.

---
 functions.c |   8 +--
 main.c      |  67 ++++++----------------
 main.h      |   5 --
 sys.c       | 187 +++++++++++++++++++++++++++++++++---------------------------
 sys.h       |  25 ++------
 5 files changed, 130 insertions(+), 162 deletions(-)
functions.c +4 -4
index faa9478..0a7b587 100644
@@ -69,10 +69,10 @@ char *line_ptr = NULL;
 const char *fs_compile_out_param[] = {
 	SYS_LOG,
 	SYS_LOG_LEVEL,
-	batctl_settings[BATCTL_SETTINGS_BLA].sysfs_name,
-	batctl_settings[BATCTL_SETTINGS_DAT].sysfs_name,
-	batctl_settings[BATCTL_SETTINGS_NETWORK_CODING].sysfs_name,
-	batctl_settings[BATCTL_SETTINGS_MULTICAST_MODE].sysfs_name,
+	SYS_BLA,
+	SYS_DAT,
+	SYS_NETWORK_CODING,
+	SYS_MULTICAST_MODE,
 	DEBUG_DAT_CACHE,
 	DEBUG_BACKBONETABLE,
 	DEBUG_DAT_CACHE,
main.c +16 -51

103 lines not on this page · raw message

main.h +0 -5
index 5fa248c..8d91480 100644
@@ -31,11 +31,6 @@
 
 #define EXIT_NOSUCCESS 2
 
-#define OPT_LONG_MAX_LEN 25
-#define OPT_SHORT_MAX_LEN 5
-
-#define SETTINGS_PATH_MAX_LEN 25
-
 #if BYTE_ORDER == BIG_ENDIAN
 #define __BIG_ENDIAN_BITFIELD
 #elif BYTE_ORDER == LITTLE_ENDIAN
sys.c +104 -83

245 lines not on this page · raw message

sys.h +6 -19
index 5f0280f..20e1934 100644
@@ -28,6 +28,10 @@
 #define SYS_BATIF_PATH_FMT	"/sys/class/net/%s/mesh/"
 #define SYS_LOG_LEVEL		"log_level"
 #define SYS_LOG			"log"
+#define SYS_BLA			"bridge_loop_avoidance"
+#define SYS_DAT			"distributed_arp_table"
+#define SYS_NETWORK_CODING	"network_coding"
+#define SYS_MULTICAST_MODE	"multicast_mode"
 #define SYS_IFACE_PATH		"/sys/class/net"
 #define SYS_IFACE_DIR		SYS_IFACE_PATH"/%s/"
 #define SYS_MESH_IFACE_FMT	SYS_IFACE_PATH"/%s/batman_adv/mesh_iface"
@@ -35,31 +39,14 @@
 #define SYS_VLAN_PATH		SYS_IFACE_PATH"/%s/mesh/vlan%d/"
 #define VLAN_ID_MAX_LEN		4
 
-enum batctl_settings_list {
-	BATCTL_SETTINGS_ORIG_INTERVAL,
-	BATCTL_SETTINGS_AP_ISOLATION,
-	BATCTL_SETTINGS_BLA,
-	BATCTL_SETTINGS_DAT,
-	BATCTL_SETTINGS_AGGREGATION,
-	BATCTL_SETTINGS_BONDING,
-	BATCTL_SETTINGS_FRAGMENTATION,
-	BATCTL_SETTINGS_NETWORK_CODING,
-	BATCTL_SETTINGS_ISOLATION_MARK,
-	BATCTL_SETTINGS_MULTICAST_MODE,
-	BATCTL_SETTINGS_NUM,
-};
-
 struct settings_data {
-	const char opt_long[OPT_LONG_MAX_LEN];
-	const char opt_short[OPT_SHORT_MAX_LEN];
-	const char sysfs_name[SETTINGS_PATH_MAX_LEN];
+	const char *sysfs_name;
 	const char **params;
 };
 
 extern const char *sysfs_param_enable[];
 extern const char *sysfs_param_server[];
-extern const struct settings_data batctl_settings[BATCTL_SETTINGS_NUM];
 
-int handle_sys_setting(char *mesh_iface, int setting, int argc, char **argv);
+int handle_sys_setting(struct state *state, int argc, char **argv);
 
 #endif
Signature · 1 line
2.11.0
#18 lore raw

PATCH v3 18/42 batctl: Move backbonetable debug table to own file

In reply to Sven Eckelmann

The netlink.c file contains to many different functions and mixes helper functions with actual command implementations. The debug table commands should be placed in separate files to better group the command specific code sections together.

---
 Makefile        |   1 +
 backbonetable.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 debug.c         |   9 ----
 main.h          |   8 ++++
 netlink.c       | 108 +++---------------------------------------------
 netlink.h       |  19 ++++++++-
 6 files changed, 157 insertions(+), 113 deletions(-)
 create mode 100644 backbonetable.c
Makefile +1 -0
index 842795b..704a0d8 100755
@@ -30,6 +30,7 @@ BINARY_NAME = batctl
 OBJ_BISECT = bisect_iv.o
 
 OBJ += bat-hosts.o
+OBJ += backbonetable.o
 ifeq ($(CONFIG_BATCTL_BISECT),y)
 OBJ += $(OBJ_BISECT)
 endif
backbonetable.c new file +125 -0

125 lines not on this page · raw message

debug.c +0 -9
index 016b148..6eba9d8 100644
@@ -260,15 +260,6 @@ static struct debug_table_data batctl_debug_table_claimtable = {
 COMMAND_NAMED(DEBUGTABLE, claimtable, "cl", handle_debug_table,
 	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_claimtable, "");
 
-static struct debug_table_data batctl_debug_table_backbonetable = {
-	.debugfs_name = DEBUG_BACKBONETABLE,
-	.header_lines = 2,
-	.netlink_fn = netlink_print_bla_backbone,
-};
-
-COMMAND_NAMED(DEBUGTABLE, backbonetable, "bbt", handle_debug_table,
-	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_backbonetable, "");
-
 static struct debug_table_data batctl_debug_table_dat_cache = {
 	.debugfs_name = DEBUG_DAT_CACHE,
 	.header_lines = 2,
main.h +8 -0
index 8d91480..2656dcf 100644
@@ -51,6 +51,14 @@ extern char module_ver_path[];
 #define BATADV_PRINT_VID(vid) (vid & BATADV_VLAN_HAS_TAG ? \
 			       (int)(vid & VLAN_VID_MASK) : -1)
 
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
+
+#ifndef container_of
+#define container_of(ptr, type, member) __extension__ ({ \
+	const __typeof__(((type *)0)->member) *__pmember = (ptr); \
+	(type *)((char *)__pmember - offsetof(type, member)); })
+#endif
+
 enum command_flags {
 	COMMAND_FLAG_MESH_IFACE = BIT(0),
 };
netlink.c +6 -102

138 lines not on this page · raw message

netlink.h +17 -2
index 089e25e..7bda0d3 100644
@@ -26,6 +26,16 @@
 #include <netlink/genl/genl.h>
 #include <netlink/genl/ctrl.h>
 
+struct print_opts {
+	int read_opt;
+	float orig_timeout;
+	float watch_interval;
+	nl_recvmsg_msg_cb_t callback;
+	char *remaining_header;
+	const char *static_header;
+	uint8_t nl_cmd;
+};
+
 struct ether_addr;
 
 int netlink_print_routing_algos(void);
@@ -43,8 +53,6 @@ int netlink_print_gateways(char *mesh_iface, char *orig_iface, int read_opt,
 			   float orig_timeout, float watch_interval);
 int netlink_print_bla_claim(char *mesh_iface, char *orig_iface, int read_opt,
 			    float orig_timeout, float watch_interval);
-int netlink_print_bla_backbone(char *mesh_iface, char *orig_iface, int read_opt,
-			       float orig_timeout, float watch_interval);
 int netlink_print_dat_cache(char *mesh_iface, char *orig_iface, int read_opt,
 			    float orig_timeout, float watch_interval);
 int netlink_print_mcast_flags(char *mesh_iface, char *orig_iface, int read_opt,
@@ -58,4 +66,11 @@ int get_primarymac_netlink(const char *mesh_iface, uint8_t *primarymac);
 
 extern struct nla_policy batadv_netlink_policy[];
 
+int missing_mandatory_attrs(struct nlattr *attrs[], const int mandatory[],
+			    int num);
+int netlink_print_common(char *mesh_iface, char *orig_iface, int read_opt,
+			 float orig_timeout, float watch_interval,
+			 const char *header, uint8_t nl_cmd,
+			 nl_recvmsg_msg_cb_t callback);
+
 #endif /* _BATCTL_NETLINK_H */
Signature · 1 line
2.11.0
#19 lore raw

PATCH v3 19/42 batctl: Move claimtable debug table to own file

In reply to Sven Eckelmann

The netlink.c file contains to many different functions and mixes helper functions with actual command implementations. The debug table commands should be placed in separate files to better group the command specific code sections together.

---
 Makefile     |   1 +
 claimtable.c | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 debug.c      |   9 ----
 netlink.c    |  84 -------------------------------------
 netlink.h    |   2 -
 5 files changed, 133 insertions(+), 95 deletions(-)
 create mode 100644 claimtable.c
Makefile +1 -0
index 704a0d8..cdc5948 100755
@@ -34,6 +34,7 @@ OBJ += backbonetable.o
 ifeq ($(CONFIG_BATCTL_BISECT),y)
 OBJ += $(OBJ_BISECT)
 endif
+OBJ += claimtable.o
 OBJ += debugfs.o
 OBJ += debug.o
 OBJ += functions.o
claimtable.c new file +132 -0

132 lines not on this page · raw message

debug.c +0 -9
index 6eba9d8..c8a2845 100644
@@ -251,15 +251,6 @@ static struct debug_table_data batctl_debug_table_transglobal = {
 COMMAND_NAMED(DEBUGTABLE, transglobal, "tg", handle_debug_table,
 	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_transglobal, "");
 
-static struct debug_table_data batctl_debug_table_claimtable = {
-	.debugfs_name = DEBUG_CLAIMTABLE,
-	.header_lines = 2,
-	.netlink_fn = netlink_print_bla_claim,
-};
-
-COMMAND_NAMED(DEBUGTABLE, claimtable, "cl", handle_debug_table,
-	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_claimtable, "");
-
 static struct debug_table_data batctl_debug_table_dat_cache = {
 	.debugfs_name = DEBUG_DAT_CACHE,
 	.header_lines = 2,
netlink.c +0 -84

96 lines not on this page · raw message

netlink.h +0 -2
index 7bda0d3..514dfa3 100644
@@ -51,8 +51,6 @@ int netlink_print_translocal(char *mesh_iface, char *orig_iface, int read_opt,
 			     float orig_timeout, float watch_interval);
 int netlink_print_gateways(char *mesh_iface, char *orig_iface, int read_opt,
 			   float orig_timeout, float watch_interval);
-int netlink_print_bla_claim(char *mesh_iface, char *orig_iface, int read_opt,
-			    float orig_timeout, float watch_interval);
 int netlink_print_dat_cache(char *mesh_iface, char *orig_iface, int read_opt,
 			    float orig_timeout, float watch_interval);
 int netlink_print_mcast_flags(char *mesh_iface, char *orig_iface, int read_opt,
Signature · 1 line
2.11.0
#20 lore raw

PATCH v3 20/42 batctl: Move dat_cache debug table to own file

In reply to Sven Eckelmann

The netlink.c file contains to many different functions and mixes helper functions with actual command implementations. The debug table commands should be placed in separate files to better group the command specific code sections together.

---
 Makefile     |   1 +
 claimtable.c |   4 +-
 dat_cache.c  | 146 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 debug.c      |   9 ----
 netlink.c    |  96 ---------------------------------------
 netlink.h    |   2 -
 6 files changed, 148 insertions(+), 110 deletions(-)
 create mode 100644 dat_cache.c
Makefile +1 -0
index cdc5948..648c7bc 100755
@@ -35,6 +35,7 @@ ifeq ($(CONFIG_BATCTL_BISECT),y)
 OBJ += $(OBJ_BISECT)
 endif
 OBJ += claimtable.o
+OBJ += dat_cache.o
 OBJ += debugfs.o
 OBJ += debug.o
 OBJ += functions.o
claimtable.c +1 -3
index 06473d0..06f42dc 100644
@@ -1,9 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 /* Copyright (C) 2009-2018  B.A.T.M.A.N. contributors:
  *
- * Andrew Lunn <[email protected]>
- * Simon Wunderlich <[email protected]>
- * Sven Eckelmann <[email protected]>
+ * Linus Lüssing <[email protected]>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of version 2 of the GNU General Public
dat_cache.c new file +146 -0

146 lines not on this page · raw message

debug.c +0 -9
index c8a2845..29c8252 100644
@@ -251,15 +251,6 @@ static struct debug_table_data batctl_debug_table_transglobal = {
 COMMAND_NAMED(DEBUGTABLE, transglobal, "tg", handle_debug_table,
 	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_transglobal, "");
 
-static struct debug_table_data batctl_debug_table_dat_cache = {
-	.debugfs_name = DEBUG_DAT_CACHE,
-	.header_lines = 2,
-	.netlink_fn = netlink_print_dat_cache,
-};
-
-COMMAND_NAMED(DEBUGTABLE, dat_cache, "dc", handle_debug_table,
-	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_dat_cache, "");
-
 static struct debug_table_data batctl_debug_table_nc_nodes = {
 	.debugfs_name = DEBUG_NC_NODES,
 	.header_lines = 0,
netlink.c +0 -96

108 lines not on this page · raw message

netlink.h +0 -2
index 514dfa3..7549838 100644
@@ -51,8 +51,6 @@ int netlink_print_translocal(char *mesh_iface, char *orig_iface, int read_opt,
 			     float orig_timeout, float watch_interval);
 int netlink_print_gateways(char *mesh_iface, char *orig_iface, int read_opt,
 			   float orig_timeout, float watch_interval);
-int netlink_print_dat_cache(char *mesh_iface, char *orig_iface, int read_opt,
-			    float orig_timeout, float watch_interval);
 int netlink_print_mcast_flags(char *mesh_iface, char *orig_iface, int read_opt,
 			      float orig_timeout, float watch_interval);
 
Signature · 1 line
2.11.0
#21 lore raw

PATCH v3 21/42 batctl: Move gateways debug table to own file

In reply to Sven Eckelmann

The netlink.c file contains to many different functions and mixes helper functions with actual command implementations. The debug table commands should be placed in separate files to better group the command specific code sections together.

---
 Makefile   |   1 +
 debug.c    |   9 ----
 gateways.c | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 netlink.c  | 130 ++-------------------------------------------
 netlink.h  |   8 +--
 5 files changed, 183 insertions(+), 140 deletions(-)
 create mode 100644 gateways.c
Makefile +1 -0
index 648c7bc..3a8e785 100755
@@ -39,6 +39,7 @@ OBJ += dat_cache.o
 OBJ += debugfs.o
 OBJ += debug.o
 OBJ += functions.o
+OBJ += gateways.o
 OBJ += genl.o
 OBJ += gw_mode.o
 OBJ += hash.o
debug.c +0 -9
index 29c8252..7bf8bff 100644
@@ -220,15 +220,6 @@ static struct debug_table_data batctl_debug_table_originators = {
 COMMAND_NAMED(DEBUGTABLE, originators, "o", handle_debug_table,
 	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_originators, "");
 
-static struct debug_table_data batctl_debug_table_gateways = {
-	.debugfs_name = "gateways",
-	.header_lines = 1,
-	.netlink_fn = netlink_print_gateways,
-};
-
-COMMAND_NAMED(DEBUGTABLE, gateways, "gwl", handle_debug_table,
-	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_gateways, "");
-
 static struct debug_table_data batctl_debug_table_translocal = {
 	.debugfs_name = "transtable_local",
 	.header_lines = 2,
gateways.c new file +175 -0

175 lines not on this page · raw message

netlink.c +3 -127

154 lines not on this page · raw message

netlink.h +4 -4
index 7549838..ecf4b01 100644
@@ -43,17 +43,14 @@ int netlink_print_originators(char *mesh_iface, char *orig_iface, int read_opt,
 			      float orig_timeout, float watch_interval);
 int netlink_print_neighbors(char *mesh_iface, char *orig_iface, int read_opt,
 			    float orig_timeout, float watch_interval);
-int netlink_print_gateways(char *mesh_iface, char *orig_iface, int read_opt,
-			   float orig_timeout, float watch_interval);
 int netlink_print_transglobal(char *mesh_iface, char *orig_iface, int read_opt,
 			      float orig_timeout, float watch_interval);
 int netlink_print_translocal(char *mesh_iface, char *orig_iface, int read_opt,
 			     float orig_timeout, float watch_interval);
-int netlink_print_gateways(char *mesh_iface, char *orig_iface, int read_opt,
-			   float orig_timeout, float watch_interval);
 int netlink_print_mcast_flags(char *mesh_iface, char *orig_iface, int read_opt,
 			      float orig_timeout, float watch_interval);
 
+char *netlink_get_info(int ifindex, uint8_t nl_cmd, const char *header);
 int translate_mac_netlink(const char *mesh_iface, const struct ether_addr *mac,
 			  struct ether_addr *mac_out);
 int get_nexthop_netlink(const char *mesh_iface, const struct ether_addr *mac,
@@ -69,4 +66,7 @@ int netlink_print_common(char *mesh_iface, char *orig_iface, int read_opt,
 			 const char *header, uint8_t nl_cmd,
 			 nl_recvmsg_msg_cb_t callback);
 
+extern char algo_name_buf[256];
+extern int last_err;
+
 #endif /* _BATCTL_NETLINK_H */
Signature · 1 line
2.11.0
#22 lore raw

PATCH v3 22/42 batctl: Move mcast_flags debug table to own file

In reply to Sven Eckelmann

The netlink.c file contains to many different functions and mixes helper functions with actual command implementations. The debug table commands should be placed in separate files to better group the command specific code sections together.

---
 Makefile      |   1 +
 debug.c       |   9 ---
 gateways.c    |   3 +-
 mcast_flags.c | 179 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 netlink.c     | 133 +------------------------------------------
 netlink.h     |   5 +-
 6 files changed, 186 insertions(+), 144 deletions(-)
 create mode 100644 mcast_flags.c
Makefile +1 -0
index 3a8e785..a725986 100755
@@ -48,6 +48,7 @@ OBJ += interface.o
 OBJ += loglevel.o
 OBJ += log.o
 OBJ += main.o
+OBJ += mcast_flags.o
 OBJ += netlink.o
 OBJ += ping.o
 OBJ += routing_algo.o
debug.c +0 -9
index 7bf8bff..4b480a3 100644
@@ -249,12 +249,3 @@ static struct debug_table_data batctl_debug_table_nc_nodes = {
 
 COMMAND_NAMED(DEBUGTABLE, nc_nodes, "nn", handle_debug_table,
 	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_nc_nodes, "");
-
-static struct debug_table_data batctl_debug_table_mcast_flags = {
-	.debugfs_name = DEBUG_MCAST_FLAGS,
-	.header_lines = 6,
-	.netlink_fn = netlink_print_mcast_flags,
-};
-
-COMMAND_NAMED(DEBUGTABLE, mcast_flags, "mf", handle_debug_table,
-	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_mcast_flags, "");
gateways.c +1 -2
index f81bf20..ca5d6ec 100644
@@ -1,8 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 /* Copyright (C) 2009-2018  B.A.T.M.A.N. contributors:
  *
- * Andrew Lunn <[email protected]>
- * Sven Eckelmann <[email protected]>
+ * Linus Lüssing <[email protected]>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of version 2 of the GNU General Public
mcast_flags.c new file +179 -0

179 lines not on this page · raw message

netlink.c +2 -131

151 lines not on this page · raw message

netlink.h +3 -2
index ecf4b01..e0fa466 100644
@@ -25,6 +25,7 @@
 
 #include <netlink/genl/genl.h>
 #include <netlink/genl/ctrl.h>
+#include <stdint.h>
 
 struct print_opts {
 	int read_opt;
@@ -47,8 +48,6 @@ int netlink_print_transglobal(char *mesh_iface, char *orig_iface, int read_opt,
 			      float orig_timeout, float watch_interval);
 int netlink_print_translocal(char *mesh_iface, char *orig_iface, int read_opt,
 			     float orig_timeout, float watch_interval);
-int netlink_print_mcast_flags(char *mesh_iface, char *orig_iface, int read_opt,
-			      float orig_timeout, float watch_interval);
 
 char *netlink_get_info(int ifindex, uint8_t nl_cmd, const char *header);
 int translate_mac_netlink(const char *mesh_iface, const struct ether_addr *mac,
@@ -68,5 +67,7 @@ int netlink_print_common(char *mesh_iface, char *orig_iface, int read_opt,
 
 extern char algo_name_buf[256];
 extern int last_err;
+extern int64_t mcast_flags;
+extern int64_t mcast_flags_priv;
 
 #endif /* _BATCTL_NETLINK_H */
Signature · 1 line
2.11.0
#23 lore raw

PATCH v3 23/42 batctl: Move nc_nodes debug table to own file

In reply to Sven Eckelmann

The other commands are stored in separate files and nc_nodes might also receive a netlink implementation. The latter would increase the complexity significantly and thus justify that the command is also added via an extra file.

---
 Makefile   |  1 +
 debug.c    |  8 --------
 nc_nodes.c | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 33 insertions(+), 8 deletions(-)
 create mode 100644 nc_nodes.c
Makefile +1 -0
index a725986..ac4824b 100755
@@ -49,6 +49,7 @@ OBJ += loglevel.o
 OBJ += log.o
 OBJ += main.o
 OBJ += mcast_flags.o
+OBJ += nc_nodes.o
 OBJ += netlink.o
 OBJ += ping.o
 OBJ += routing_algo.o
debug.c +0 -8
index 4b480a3..531c6aa 100644
@@ -241,11 +241,3 @@ static struct debug_table_data batctl_debug_table_transglobal = {
 
 COMMAND_NAMED(DEBUGTABLE, transglobal, "tg", handle_debug_table,
 	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_transglobal, "");
-
-static struct debug_table_data batctl_debug_table_nc_nodes = {
-	.debugfs_name = DEBUG_NC_NODES,
-	.header_lines = 0,
-};
-
-COMMAND_NAMED(DEBUGTABLE, nc_nodes, "nn", handle_debug_table,
-	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_nc_nodes, "");
nc_nodes.c new file +32 -0
new file mode 100644
index 0000000..9cf437d
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2009-2018  B.A.T.M.A.N. contributors:
+ *
+ * Marek Lindner <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ *
+ * License-Filename: LICENSES/preferred/GPL-2.0
+ */
+
+#include "debug.h"
+#include "main.h"
+
+static struct debug_table_data batctl_debug_table_nc_nodes = {
+	.debugfs_name = DEBUG_NC_NODES,
+	.header_lines = 0,
+};
+
+COMMAND_NAMED(DEBUGTABLE, nc_nodes, "nn", handle_debug_table,
+	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_nc_nodes, "");
Signature · 1 line
2.11.0
#24 lore raw

PATCH v3 24/42 batctl: Move neighbors debug table to own file

In reply to Sven Eckelmann

The netlink.c file contains to many different functions and mixes helper functions with actual command implementations. The debug table commands should be placed in separate files to better group the command specific code sections together.

---
 Makefile    |   1 +
 debug.c     |   9 ----
 neighbors.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 netlink.c   |  94 ----------------------------------------
 netlink.h   |   2 -
 5 files changed, 142 insertions(+), 105 deletions(-)
 create mode 100644 neighbors.c
Makefile +1 -0
index ac4824b..d447663 100755
@@ -50,6 +50,7 @@ OBJ += log.o
 OBJ += main.o
 OBJ += mcast_flags.o
 OBJ += nc_nodes.o
+OBJ += neighbors.o
 OBJ += netlink.o
 OBJ += ping.o
 OBJ += routing_algo.o
debug.c +0 -9
index 531c6aa..a5e7276 100644
@@ -200,15 +200,6 @@ int debug_print_routing_algos(void)
 	return read_file(full_path, DEBUG_ROUTING_ALGOS, 0, 0, 0, 0);
 }
 
-static struct debug_table_data batctl_debug_table_neighbors = {
-	.debugfs_name = "neighbors",
-	.header_lines = 2,
-	.netlink_fn = netlink_print_neighbors,
-};
-
-COMMAND_NAMED(DEBUGTABLE, neighbors, "n", handle_debug_table,
-	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_neighbors, "");
-
 static struct debug_table_data batctl_debug_table_originators = {
 	.debugfs_name = "originators",
 	.header_lines = 2,
neighbors.c new file +141 -0

141 lines not on this page · raw message

netlink.c +0 -94

106 lines not on this page · raw message

netlink.h +0 -2
index e0fa466..bfac3a5 100644
@@ -42,8 +42,6 @@ struct ether_addr;
 int netlink_print_routing_algos(void);
 int netlink_print_originators(char *mesh_iface, char *orig_iface, int read_opt,
 			      float orig_timeout, float watch_interval);
-int netlink_print_neighbors(char *mesh_iface, char *orig_iface, int read_opt,
-			    float orig_timeout, float watch_interval);
 int netlink_print_transglobal(char *mesh_iface, char *orig_iface, int read_opt,
 			      float orig_timeout, float watch_interval);
 int netlink_print_translocal(char *mesh_iface, char *orig_iface, int read_opt,
Signature · 1 line
2.11.0
#25 lore raw

PATCH v3 25/42 batctl: Move originators debug table to own file

In reply to Sven Eckelmann

The netlink.c file contains to many different functions and mixes helper functions with actual command implementations. The debug table commands should be placed in separate files to better group the command specific code sections together.

---
 Makefile      |   1 +
 debug.c       |  11 ---
 netlink.c     | 175 --------------------------------------------
 netlink.h     |   2 -
 originators.c | 227 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 228 insertions(+), 188 deletions(-)
 create mode 100644 originators.c
Makefile +1 -0
index d447663..059c602 100755
@@ -53,6 +53,7 @@ OBJ += nc_nodes.o
 OBJ += neighbors.o
 OBJ += netlink.o
 OBJ += ping.o
+OBJ += originators.o
 OBJ += routing_algo.o
 OBJ += statistics.o
 OBJ += sys.o
debug.c +0 -11
index a5e7276..f4cc2ea 100644
@@ -200,17 +200,6 @@ int debug_print_routing_algos(void)
 	return read_file(full_path, DEBUG_ROUTING_ALGOS, 0, 0, 0, 0);
 }
 
-static struct debug_table_data batctl_debug_table_originators = {
-	.debugfs_name = "originators",
-	.header_lines = 2,
-	.netlink_fn = netlink_print_originators,
-	.option_watch_interval = 1,
-	.option_orig_iface = 1,
-};
-
-COMMAND_NAMED(DEBUGTABLE, originators, "o", handle_debug_table,
-	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_originators, "");
-
 static struct debug_table_data batctl_debug_table_translocal = {
 	.debugfs_name = "transtable_local",
 	.header_lines = 2,
netlink.c +0 -175

187 lines not on this page · raw message

netlink.h +0 -2
index bfac3a5..a099482 100644
@@ -40,8 +40,6 @@ struct print_opts {
 struct ether_addr;
 
 int netlink_print_routing_algos(void);
-int netlink_print_originators(char *mesh_iface, char *orig_iface, int read_opt,
-			      float orig_timeout, float watch_interval);
 int netlink_print_transglobal(char *mesh_iface, char *orig_iface, int read_opt,
 			      float orig_timeout, float watch_interval);
 int netlink_print_translocal(char *mesh_iface, char *orig_iface, int read_opt,
originators.c new file +227 -0

227 lines not on this page · raw message

Signature · 1 line
2.11.0
#26 lore raw

PATCH v3 26/42 batctl: Move transglobal debug table to own file

In reply to Sven Eckelmann

The netlink.c file contains to many different functions and mixes helper functions with actual command implementations. The debug table commands should be placed in separate files to better group the command specific code sections together.

---
 Makefile      |   1 +
 debug.c       |  11 ----
 netlink.c     | 112 ----------------------------------------
 netlink.h     |   2 -
 transglobal.c | 161 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 162 insertions(+), 125 deletions(-)
 create mode 100644 transglobal.c
Makefile +1 -0
index 059c602..ef0c28b 100755
@@ -60,6 +60,7 @@ OBJ += sys.o
 OBJ += tcpdump.o
 OBJ += throughputmeter.o
 OBJ += traceroute.o
+OBJ += transglobal.o
 OBJ += translate.o
 
 MANPAGE = man/batctl.8
debug.c +0 -11
index f4cc2ea..5f2ad04 100644
@@ -210,14 +210,3 @@ static struct debug_table_data batctl_debug_table_translocal = {
 
 COMMAND_NAMED(DEBUGTABLE, translocal, "tl", handle_debug_table,
 	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_translocal, "");
-
-static struct debug_table_data batctl_debug_table_transglobal = {
-	.debugfs_name = "transtable_global",
-	.header_lines = 2,
-	.netlink_fn = netlink_print_transglobal,
-	.option_unicast_only = 1,
-	.option_multicast_only = 1,
-};
-
-COMMAND_NAMED(DEBUGTABLE, transglobal, "tg", handle_debug_table,
-	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_transglobal, "");
netlink.c +0 -112

124 lines not on this page · raw message

netlink.h +0 -2
index a099482..1cec0f7 100644
@@ -40,8 +40,6 @@ struct print_opts {
 struct ether_addr;
 
 int netlink_print_routing_algos(void);
-int netlink_print_transglobal(char *mesh_iface, char *orig_iface, int read_opt,
-			      float orig_timeout, float watch_interval);
 int netlink_print_translocal(char *mesh_iface, char *orig_iface, int read_opt,
 			     float orig_timeout, float watch_interval);
 
transglobal.c new file +161 -0

161 lines not on this page · raw message

Signature · 1 line
2.11.0
#27 lore raw

PATCH v3 27/42 batctl: Move translocal debug table to own file

In reply to Sven Eckelmann

The netlink.c file contains to many different functions and mixes helper functions with actual command implementations. The debug table commands should be placed in separate files to better group the command specific code sections together.

---
 Makefile     |   1 +
 debug.c      |  11 -----
 netlink.c    | 108 ----------------------------------------
 netlink.h    |   2 -
 translocal.c | 157 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 158 insertions(+), 121 deletions(-)
 create mode 100644 translocal.c
Makefile +1 -0
index ef0c28b..93db44a 100755
@@ -62,6 +62,7 @@ OBJ += throughputmeter.o
 OBJ += traceroute.o
 OBJ += transglobal.o
 OBJ += translate.o
+OBJ += translocal.o
 
 MANPAGE = man/batctl.8
 
debug.c +0 -11
index 5f2ad04..17dde92 100644
@@ -199,14 +199,3 @@ int debug_print_routing_algos(void)
 	debugfs_make_path(DEBUG_BATIF_PATH_FMT, "", full_path, sizeof(full_path));
 	return read_file(full_path, DEBUG_ROUTING_ALGOS, 0, 0, 0, 0);
 }
-
-static struct debug_table_data batctl_debug_table_translocal = {
-	.debugfs_name = "transtable_local",
-	.header_lines = 2,
-	.netlink_fn = netlink_print_translocal,
-	.option_unicast_only = 1,
-	.option_multicast_only = 1,
-};
-
-COMMAND_NAMED(DEBUGTABLE, translocal, "tl", handle_debug_table,
-	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_translocal, "");
netlink.c +0 -108

120 lines not on this page · raw message

netlink.h +0 -2
index 1cec0f7..0b21ac1 100644
@@ -40,8 +40,6 @@ struct print_opts {
 struct ether_addr;
 
 int netlink_print_routing_algos(void);
-int netlink_print_translocal(char *mesh_iface, char *orig_iface, int read_opt,
-			     float orig_timeout, float watch_interval);
 
 char *netlink_get_info(int ifindex, uint8_t nl_cmd, const char *header);
 int translate_mac_netlink(const char *mesh_iface, const struct ether_addr *mac,
translocal.c new file +157 -0

157 lines not on this page · raw message

Signature · 1 line
2.11.0
#28 lore raw

PATCH v3 28/42 batctl: Move aggregation setting to own file

In reply to Sven Eckelmann

The sysfs settings are planned to get also be implemented in netlink. To avoid cluttering up netlink.c again, it should be stored in a separate file. This also allows to order the usage lines using the Makefile.

---
 Makefile      |  1 +
 aggregation.c | 33 +++++++++++++++++++++++++++++++++
 sys.c         |  9 ---------
 3 files changed, 34 insertions(+), 9 deletions(-)
 create mode 100644 aggregation.c
Makefile +1 -0
index 93db44a..dfc59af 100755
@@ -29,6 +29,7 @@ BINARY_NAME = batctl
 
 OBJ_BISECT = bisect_iv.o
 
+OBJ += aggregation.o
 OBJ += bat-hosts.o
 OBJ += backbonetable.o
 ifeq ($(CONFIG_BATCTL_BISECT),y)
aggregation.c new file +33 -0
new file mode 100644
index 0000000..57c1dbb
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2009-2018  B.A.T.M.A.N. contributors:
+ *
+ * Marek Lindner <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ *
+ * License-Filename: LICENSES/preferred/GPL-2.0
+ */
+
+#include "main.h"
+#include "sys.h"
+
+static struct settings_data batctl_settings_aggregation = {
+	.sysfs_name = "aggregated_ogms",
+	.params = sysfs_param_enable,
+};
+
+COMMAND_NAMED(SUBCOMMAND, aggregation, "ag", handle_sys_setting,
+	      COMMAND_FLAG_MESH_IFACE, &batctl_settings_aggregation,
+	      "[0|1]             \tdisplay or modify aggregation setting");
sys.c +0 -9
index 08b389e..00e452c 100644
@@ -173,15 +173,6 @@ COMMAND_NAMED(SUBCOMMAND, distributed_arp_table, "dat", handle_sys_setting,
 	      COMMAND_FLAG_MESH_IFACE, &batctl_settings_distributed_arp_table,
 	      "[0|1]             \tdisplay or modify distributed_arp_table setting");
 
-static struct settings_data batctl_settings_aggregation = {
-	.sysfs_name = "aggregated_ogms",
-	.params = sysfs_param_enable,
-};
-
-COMMAND_NAMED(SUBCOMMAND, aggregation, "ag", handle_sys_setting,
-	      COMMAND_FLAG_MESH_IFACE, &batctl_settings_aggregation,
-	      "[0|1]             \tdisplay or modify aggregation setting");
-
 static struct settings_data batctl_settings_bonding = {
 	.sysfs_name = "bonding",
 	.params = sysfs_param_enable,
Signature · 1 line
2.11.0
#29 lore raw

PATCH v3 29/42 batctl: Move ap_isolation setting to own file

In reply to Sven Eckelmann

The sysfs settings are planned to get also be implemented in netlink. To avoid cluttering up netlink.c again, it should be stored in a separate file. This also allows to order the usage lines using the Makefile.

---
 Makefile       |  1 +
 ap_isolation.c | 33 +++++++++++++++++++++++++++++++++
 sys.c          |  9 ---------
 3 files changed, 34 insertions(+), 9 deletions(-)
 create mode 100644 ap_isolation.c
Makefile +1 -0
index dfc59af..0a72595 100755
@@ -30,6 +30,7 @@ BINARY_NAME = batctl
 OBJ_BISECT = bisect_iv.o
 
 OBJ += aggregation.o
+OBJ += ap_isolation.o
 OBJ += bat-hosts.o
 OBJ += backbonetable.o
 ifeq ($(CONFIG_BATCTL_BISECT),y)
ap_isolation.c new file +33 -0
new file mode 100644
index 0000000..2d16c68
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2009-2018  B.A.T.M.A.N. contributors:
+ *
+ * Antonio Quartulli <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ *
+ * License-Filename: LICENSES/preferred/GPL-2.0
+ */
+
+#include "main.h"
+#include "sys.h"
+
+static struct settings_data batctl_settings_ap_isolation = {
+	.sysfs_name = "ap_isolation",
+	.params = sysfs_param_enable,
+};
+
+COMMAND_NAMED(SUBCOMMAND, ap_isolation, "ap", handle_sys_setting,
+	      COMMAND_FLAG_MESH_IFACE, &batctl_settings_ap_isolation,
+	      "[0|1]             \tdisplay or modify ap_isolation setting");
sys.c +0 -9
index 00e452c..80d9fa1 100644
@@ -146,15 +146,6 @@ COMMAND_NAMED(SUBCOMMAND, orig_interval, "it", handle_sys_setting,
 	      COMMAND_FLAG_MESH_IFACE, &batctl_settings_orig_interval,
 	      "[interval]        \tdisplay or modify orig_interval setting");
 
-static struct settings_data batctl_settings_ap_isolation = {
-	.sysfs_name = "ap_isolation",
-	.params = sysfs_param_enable,
-};
-
-COMMAND_NAMED(SUBCOMMAND, ap_isolation, "ap", handle_sys_setting,
-	      COMMAND_FLAG_MESH_IFACE, &batctl_settings_ap_isolation,
-	      "[0|1]             \tdisplay or modify ap_isolation setting");
-
 static struct settings_data batctl_settings_bridge_loop_avoidance = {
 	.sysfs_name = SYS_BLA,
 	.params = sysfs_param_enable,
Signature · 1 line
2.11.0
#30 lore raw

PATCH v3 30/42 batctl: Move bonding setting to own file

In reply to Sven Eckelmann

The sysfs settings are planned to get also be implemented in netlink. To avoid cluttering up netlink.c again, it should be stored in a separate file. This also allows to order the usage lines using the Makefile.

---
 Makefile  |  1 +
 bonding.c | 33 +++++++++++++++++++++++++++++++++
 sys.c     |  9 ---------
 3 files changed, 34 insertions(+), 9 deletions(-)
 create mode 100644 bonding.c
Makefile +1 -0
index 0a72595..c1b8484 100755
@@ -36,6 +36,7 @@ OBJ += backbonetable.o
 ifeq ($(CONFIG_BATCTL_BISECT),y)
 OBJ += $(OBJ_BISECT)
 endif
+OBJ += bonding.o
 OBJ += claimtable.o
 OBJ += dat_cache.o
 OBJ += debugfs.o
bonding.c new file +33 -0
new file mode 100644
index 0000000..f7105c9
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2009-2018  B.A.T.M.A.N. contributors:
+ *
+ * Marek Lindner <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ *
+ * License-Filename: LICENSES/preferred/GPL-2.0
+ */
+
+#include "main.h"
+#include "sys.h"
+
+static struct settings_data batctl_settings_bonding = {
+	.sysfs_name = "bonding",
+	.params = sysfs_param_enable,
+};
+
+COMMAND_NAMED(SUBCOMMAND, bonding, "b", handle_sys_setting,
+	      COMMAND_FLAG_MESH_IFACE, &batctl_settings_bonding,
+	      "[0|1]             \tdisplay or modify bonding setting");
sys.c +0 -9
index 80d9fa1..8ad925e 100644
@@ -164,15 +164,6 @@ COMMAND_NAMED(SUBCOMMAND, distributed_arp_table, "dat", handle_sys_setting,
 	      COMMAND_FLAG_MESH_IFACE, &batctl_settings_distributed_arp_table,
 	      "[0|1]             \tdisplay or modify distributed_arp_table setting");
 
-static struct settings_data batctl_settings_bonding = {
-	.sysfs_name = "bonding",
-	.params = sysfs_param_enable,
-};
-
-COMMAND_NAMED(SUBCOMMAND, bonding, "b", handle_sys_setting,
-	      COMMAND_FLAG_MESH_IFACE, &batctl_settings_bonding,
-	      "[0|1]             \tdisplay or modify bonding setting");
-
 static struct settings_data batctl_settings_fragmentation = {
 	.sysfs_name = "fragmentation",
 	.params = sysfs_param_enable,
Signature · 1 line
2.11.0
#31 lore raw

PATCH v3 31/42 batctl: Move bridge_loop_avoidance setting to own file

In reply to Sven Eckelmann

The sysfs settings are planned to get also be implemented in netlink. To avoid cluttering up netlink.c again, it should be stored in a separate file. This also allows to order the usage lines using the Makefile.

---
 Makefile                |  1 +
 bridge_loop_avoidance.c | 33 +++++++++++++++++++++++++++++++++
 sys.c                   |  9 ---------
 3 files changed, 34 insertions(+), 9 deletions(-)
 create mode 100644 bridge_loop_avoidance.c
Makefile +1 -0
index c1b8484..6664aa0 100755
@@ -37,6 +37,7 @@ ifeq ($(CONFIG_BATCTL_BISECT),y)
 OBJ += $(OBJ_BISECT)
 endif
 OBJ += bonding.o
+OBJ += bridge_loop_avoidance.o
 OBJ += claimtable.o
 OBJ += dat_cache.o
 OBJ += debugfs.o
bridge_loop_avoidance.c new file +33 -0
new file mode 100644
index 0000000..0db49f2
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2009-2018  B.A.T.M.A.N. contributors:
+ *
+ * Simon Wunderlich <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ *
+ * License-Filename: LICENSES/preferred/GPL-2.0
+ */
+
+#include "main.h"
+#include "sys.h"
+
+static struct settings_data batctl_settings_bridge_loop_avoidance = {
+	.sysfs_name = SYS_BLA,
+	.params = sysfs_param_enable,
+};
+
+COMMAND_NAMED(SUBCOMMAND, bridge_loop_avoidance, "bl", handle_sys_setting,
+	      COMMAND_FLAG_MESH_IFACE, &batctl_settings_bridge_loop_avoidance,
+	      "[0|1]             \tdisplay or modify bridge_loop_avoidance setting");
sys.c +0 -9
index 8ad925e..e08738d 100644
@@ -146,15 +146,6 @@ COMMAND_NAMED(SUBCOMMAND, orig_interval, "it", handle_sys_setting,
 	      COMMAND_FLAG_MESH_IFACE, &batctl_settings_orig_interval,
 	      "[interval]        \tdisplay or modify orig_interval setting");
 
-static struct settings_data batctl_settings_bridge_loop_avoidance = {
-	.sysfs_name = SYS_BLA,
-	.params = sysfs_param_enable,
-};
-
-COMMAND_NAMED(SUBCOMMAND, bridge_loop_avoidance, "bl", handle_sys_setting,
-	      COMMAND_FLAG_MESH_IFACE, &batctl_settings_bridge_loop_avoidance,
-	      "[0|1]             \tdisplay or modify bridge_loop_avoidance setting");
-
 static struct settings_data batctl_settings_distributed_arp_table = {
 	.sysfs_name = SYS_DAT,
 	.params = sysfs_param_enable,
Signature · 1 line
2.11.0
#32 lore raw

PATCH v3 32/42 batctl: Move distributed_arp_table setting to own file

In reply to Sven Eckelmann

The sysfs settings are planned to get also be implemented in netlink. To avoid cluttering up netlink.c again, it should be stored in a separate file. This also allows to order the usage lines using the Makefile.

---
 Makefile                |  1 +
 distributed_arp_table.c | 33 +++++++++++++++++++++++++++++++++
 sys.c                   |  9 ---------
 3 files changed, 34 insertions(+), 9 deletions(-)
 create mode 100644 distributed_arp_table.c
Makefile +1 -0
index 6664aa0..9cbef82 100755
@@ -42,6 +42,7 @@ OBJ += claimtable.o
 OBJ += dat_cache.o
 OBJ += debugfs.o
 OBJ += debug.o
+OBJ += distributed_arp_table.o
 OBJ += functions.o
 OBJ += gateways.o
 OBJ += genl.o
distributed_arp_table.c new file +33 -0
new file mode 100644
index 0000000..ba6e5b7
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2009-2018  B.A.T.M.A.N. contributors:
+ *
+ * Antonio Quartulli <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ *
+ * License-Filename: LICENSES/preferred/GPL-2.0
+ */
+
+#include "main.h"
+#include "sys.h"
+
+static struct settings_data batctl_settings_distributed_arp_table = {
+	.sysfs_name = SYS_DAT,
+	.params = sysfs_param_enable,
+};
+
+COMMAND_NAMED(SUBCOMMAND, distributed_arp_table, "dat", handle_sys_setting,
+	      COMMAND_FLAG_MESH_IFACE, &batctl_settings_distributed_arp_table,
+	      "[0|1]             \tdisplay or modify distributed_arp_table setting");
sys.c +0 -9
index e08738d..9ce7a90 100644
@@ -146,15 +146,6 @@ COMMAND_NAMED(SUBCOMMAND, orig_interval, "it", handle_sys_setting,
 	      COMMAND_FLAG_MESH_IFACE, &batctl_settings_orig_interval,
 	      "[interval]        \tdisplay or modify orig_interval setting");
 
-static struct settings_data batctl_settings_distributed_arp_table = {
-	.sysfs_name = SYS_DAT,
-	.params = sysfs_param_enable,
-};
-
-COMMAND_NAMED(SUBCOMMAND, distributed_arp_table, "dat", handle_sys_setting,
-	      COMMAND_FLAG_MESH_IFACE, &batctl_settings_distributed_arp_table,
-	      "[0|1]             \tdisplay or modify distributed_arp_table setting");
-
 static struct settings_data batctl_settings_fragmentation = {
 	.sysfs_name = "fragmentation",
 	.params = sysfs_param_enable,
Signature · 1 line
2.11.0
#33 lore raw

PATCH v3 33/42 batctl: Move fragmentation setting to own file

In reply to Sven Eckelmann

The sysfs settings are planned to get also be implemented in netlink. To avoid cluttering up netlink.c again, it should be stored in a separate file. This also allows to order the usage lines using the Makefile.

---
 Makefile        |  1 +
 fragmentation.c | 33 +++++++++++++++++++++++++++++++++
 sys.c           |  9 ---------
 3 files changed, 34 insertions(+), 9 deletions(-)
 create mode 100644 fragmentation.c
Makefile +1 -0
index 9cbef82..7f82d44 100755
@@ -43,6 +43,7 @@ OBJ += dat_cache.o
 OBJ += debugfs.o
 OBJ += debug.o
 OBJ += distributed_arp_table.o
+OBJ += fragmentation.o
 OBJ += functions.o
 OBJ += gateways.o
 OBJ += genl.o
fragmentation.c new file +33 -0
new file mode 100644
index 0000000..e159bdd
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2009-2018  B.A.T.M.A.N. contributors:
+ *
+ * Marek Lindner <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ *
+ * License-Filename: LICENSES/preferred/GPL-2.0
+ */
+
+#include "main.h"
+#include "sys.h"
+
+static struct settings_data batctl_settings_fragmentation = {
+	.sysfs_name = "fragmentation",
+	.params = sysfs_param_enable,
+};
+
+COMMAND_NAMED(SUBCOMMAND, fragmentation, "f", handle_sys_setting,
+	      COMMAND_FLAG_MESH_IFACE, &batctl_settings_fragmentation,
+	      "[0|1]             \tdisplay or modify fragmentation setting");
sys.c +0 -9
index 9ce7a90..f81298b 100644
@@ -146,15 +146,6 @@ COMMAND_NAMED(SUBCOMMAND, orig_interval, "it", handle_sys_setting,
 	      COMMAND_FLAG_MESH_IFACE, &batctl_settings_orig_interval,
 	      "[interval]        \tdisplay or modify orig_interval setting");
 
-static struct settings_data batctl_settings_fragmentation = {
-	.sysfs_name = "fragmentation",
-	.params = sysfs_param_enable,
-};
-
-COMMAND_NAMED(SUBCOMMAND, fragmentation, "f", handle_sys_setting,
-	      COMMAND_FLAG_MESH_IFACE, &batctl_settings_fragmentation,
-	      "[0|1]             \tdisplay or modify fragmentation setting");
-
 static struct settings_data batctl_settings_network_coding = {
 	.sysfs_name = SYS_NETWORK_CODING,
 	.params = sysfs_param_enable,
Signature · 1 line
2.11.0
#34 lore raw

PATCH v3 34/42 batctl: Move isolation_mark setting to own file

In reply to Sven Eckelmann

The sysfs settings are planned to get also be implemented in netlink. To avoid cluttering up netlink.c again, it should be stored in a separate file. This also allows to order the usage lines using the Makefile.

---
 Makefile         |  1 +
 isolation_mark.c | 35 +++++++++++++++++++++++++++++++++++
 sys.c            |  9 ---------
 3 files changed, 36 insertions(+), 9 deletions(-)
 create mode 100644 isolation_mark.c
Makefile +1 -0
index 7f82d44..9598065 100755
@@ -51,6 +51,7 @@ OBJ += gw_mode.o
 OBJ += hash.o
 OBJ += icmp_helper.o
 OBJ += interface.o
+OBJ += isolation_mark.o
 OBJ += loglevel.o
 OBJ += log.o
 OBJ += main.o
isolation_mark.c new file +35 -0
new file mode 100644
index 0000000..13ba869
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2009-2018  B.A.T.M.A.N. contributors:
+ *
+ * Antonio Quartulli <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ *
+ * License-Filename: LICENSES/preferred/GPL-2.0
+ */
+
+#include <stddef.h>
+
+#include "main.h"
+#include "sys.h"
+
+static struct settings_data batctl_settings_isolation_mark = {
+	.sysfs_name = "isolation_mark",
+	.params = NULL,
+};
+
+COMMAND_NAMED(SUBCOMMAND, isolation_mark, "mark", handle_sys_setting,
+	      COMMAND_FLAG_MESH_IFACE, &batctl_settings_isolation_mark,
+	      "[mark]            \tdisplay or modify isolation_mark setting");
sys.c +0 -9
index f81298b..355b801 100644
@@ -155,15 +155,6 @@ COMMAND_NAMED(SUBCOMMAND, network_coding, "nc", handle_sys_setting,
 	      COMMAND_FLAG_MESH_IFACE, &batctl_settings_network_coding,
 	      "[0|1]             \tdisplay or modify network_coding setting");
 
-static struct settings_data batctl_settings_isolation_mark = {
-	.sysfs_name = "isolation_mark",
-	.params = NULL,
-};
-
-COMMAND_NAMED(SUBCOMMAND, isolation_mark, "mark", handle_sys_setting,
-	      COMMAND_FLAG_MESH_IFACE, &batctl_settings_isolation_mark,
-	      "[mark]            \tdisplay or modify isolation_mark setting");
-
 static struct settings_data batctl_settings_multicast_mode = {
 	.sysfs_name = SYS_MULTICAST_MODE,
 	.params = sysfs_param_enable,
Signature · 1 line
2.11.0
#35 lore raw

PATCH v3 35/42 batctl: Move multicast_mode setting to own file

In reply to Sven Eckelmann

The sysfs settings are planned to get also be implemented in netlink. To avoid cluttering up netlink.c again, it should be stored in a separate file. This also allows to order the usage lines using the Makefile.

---
 Makefile         |  1 +
 multicast_mode.c | 33 +++++++++++++++++++++++++++++++++
 sys.c            |  9 ---------
 3 files changed, 34 insertions(+), 9 deletions(-)
 create mode 100644 multicast_mode.c
Makefile +1 -0
index 9598065..9e5199d 100755
@@ -56,6 +56,7 @@ OBJ += loglevel.o
 OBJ += log.o
 OBJ += main.o
 OBJ += mcast_flags.o
+OBJ += multicast_mode.o
 OBJ += nc_nodes.o
 OBJ += neighbors.o
 OBJ += netlink.o
multicast_mode.c new file +33 -0
new file mode 100644
index 0000000..8542928
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2009-2018  B.A.T.M.A.N. contributors:
+ *
+ * Linus Lüssing <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ *
+ * License-Filename: LICENSES/preferred/GPL-2.0
+ */
+
+#include "main.h"
+#include "sys.h"
+
+static struct settings_data batctl_settings_multicast_mode = {
+	.sysfs_name = SYS_MULTICAST_MODE,
+	.params = sysfs_param_enable,
+};
+
+COMMAND_NAMED(SUBCOMMAND, multicast_mode, "mm", handle_sys_setting,
+	      COMMAND_FLAG_MESH_IFACE, &batctl_settings_multicast_mode,
+	      "[0|1]             \tdisplay or modify multicast_mode setting");
sys.c +0 -9
index 355b801..80ef3ab 100644
@@ -154,12 +154,3 @@ static struct settings_data batctl_settings_network_coding = {
 COMMAND_NAMED(SUBCOMMAND, network_coding, "nc", handle_sys_setting,
 	      COMMAND_FLAG_MESH_IFACE, &batctl_settings_network_coding,
 	      "[0|1]             \tdisplay or modify network_coding setting");
-
-static struct settings_data batctl_settings_multicast_mode = {
-	.sysfs_name = SYS_MULTICAST_MODE,
-	.params = sysfs_param_enable,
-};
-
-COMMAND_NAMED(SUBCOMMAND, multicast_mode, "mm", handle_sys_setting,
-	      COMMAND_FLAG_MESH_IFACE, &batctl_settings_multicast_mode,
-	      "[0|1]             \tdisplay or modify multicast_mode setting");
Signature · 1 line
2.11.0
#36 lore raw

PATCH v3 36/42 batctl: Move network_coding setting to own file

In reply to Sven Eckelmann

The sysfs settings are planned to get also be implemented in netlink. To avoid cluttering up netlink.c again, it should be stored in a separate file. This also allows to order the usage lines using the Makefile.

---
 Makefile         |  1 +
 network_coding.c | 33 +++++++++++++++++++++++++++++++++
 sys.c            |  9 ---------
 3 files changed, 34 insertions(+), 9 deletions(-)
 create mode 100644 network_coding.c
Makefile +1 -0
index 9e5199d..8582bf6 100755
@@ -60,6 +60,7 @@ OBJ += multicast_mode.o
 OBJ += nc_nodes.o
 OBJ += neighbors.o
 OBJ += netlink.o
+OBJ += network_coding.o
 OBJ += ping.o
 OBJ += originators.o
 OBJ += routing_algo.o
network_coding.c new file +33 -0
new file mode 100644
index 0000000..a4c4296
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2009-2018  B.A.T.M.A.N. contributors:
+ *
+ * Martin Hundebøll <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ *
+ * License-Filename: LICENSES/preferred/GPL-2.0
+ */
+
+#include "main.h"
+#include "sys.h"
+
+static struct settings_data batctl_settings_network_coding = {
+	.sysfs_name = SYS_NETWORK_CODING,
+	.params = sysfs_param_enable,
+};
+
+COMMAND_NAMED(SUBCOMMAND, network_coding, "nc", handle_sys_setting,
+	      COMMAND_FLAG_MESH_IFACE, &batctl_settings_network_coding,
+	      "[0|1]             \tdisplay or modify network_coding setting");
sys.c +0 -9
index 80ef3ab..932a7e8 100644
@@ -145,12 +145,3 @@ static struct settings_data batctl_settings_orig_interval = {
 COMMAND_NAMED(SUBCOMMAND, orig_interval, "it", handle_sys_setting,
 	      COMMAND_FLAG_MESH_IFACE, &batctl_settings_orig_interval,
 	      "[interval]        \tdisplay or modify orig_interval setting");
-
-static struct settings_data batctl_settings_network_coding = {
-	.sysfs_name = SYS_NETWORK_CODING,
-	.params = sysfs_param_enable,
-};
-
-COMMAND_NAMED(SUBCOMMAND, network_coding, "nc", handle_sys_setting,
-	      COMMAND_FLAG_MESH_IFACE, &batctl_settings_network_coding,
-	      "[0|1]             \tdisplay or modify network_coding setting");
Signature · 1 line
2.11.0
#37 lore raw

PATCH v3 37/42 batctl: Move orig_interval setting to own file

In reply to Sven Eckelmann

The sysfs settings are planned to get also be implemented in netlink. To avoid cluttering up netlink.c again, it should be stored in a separate file. This also allows to order the usage lines using the Makefile.

---
 Makefile        |  1 +
 orig_interval.c | 35 +++++++++++++++++++++++++++++++++++
 sys.c           |  9 ---------
 3 files changed, 36 insertions(+), 9 deletions(-)
 create mode 100644 orig_interval.c
Makefile +1 -0
index 8582bf6..a6971d8 100755
@@ -63,6 +63,7 @@ OBJ += netlink.o
 OBJ += network_coding.o
 OBJ += ping.o
 OBJ += originators.o
+OBJ += orig_interval.o
 OBJ += routing_algo.o
 OBJ += statistics.o
 OBJ += sys.o
orig_interval.c new file +35 -0
new file mode 100644
index 0000000..d308ea2
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2009-2018  B.A.T.M.A.N. contributors:
+ *
+ * Marek Lindner <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ *
+ * License-Filename: LICENSES/preferred/GPL-2.0
+ */
+
+#include <stddef.h>
+
+#include "main.h"
+#include "sys.h"
+
+static struct settings_data batctl_settings_orig_interval = {
+	.sysfs_name = "orig_interval",
+	.params = NULL,
+};
+
+COMMAND_NAMED(SUBCOMMAND, orig_interval, "it", handle_sys_setting,
+	      COMMAND_FLAG_MESH_IFACE, &batctl_settings_orig_interval,
+	      "[interval]        \tdisplay or modify orig_interval setting");
sys.c +0 -9
index 932a7e8..6b98ac4 100644
@@ -136,12 +136,3 @@ int handle_sys_setting(struct state *state, int argc, char **argv)
 	free(base_dev);
 	return res;
 }
-
-static struct settings_data batctl_settings_orig_interval = {
-	.sysfs_name = "orig_interval",
-	.params = NULL,
-};
-
-COMMAND_NAMED(SUBCOMMAND, orig_interval, "it", handle_sys_setting,
-	      COMMAND_FLAG_MESH_IFACE, &batctl_settings_orig_interval,
-	      "[interval]        \tdisplay or modify orig_interval setting");
Signature · 1 line
2.11.0
#38 lore raw

PATCH v3 38/42 batctl: Use external netlink socket for debug tables

In reply to Sven Eckelmann

The netlink socket is used by the debug table functionality to retrieve the tables. The initialization can be centralized and moved to the main function (controlled by a flag) to share it between the other commands.

Since more commands will use netlink in the future, this flag can reduce the implementation effort significantly.

---
 backbonetable.c |   7 ++--
 claimtable.c    |   7 ++--
 dat_cache.c     |   9 ++---
 debug.c         |   5 ++-
 debug.h         |   2 +-
 gateways.c      |  11 ++++---
 main.c          |  18 +++++++++-
 main.h          |   9 +++++
 mcast_flags.c   |  11 ++++---
 neighbors.c     |   7 ++--
 netlink.c       | 100 +++++++++++++++++++++++++++++++++++++-------------------
 netlink.h       |   7 +++-
 originators.c   |  11 ++++---
 transglobal.c   |   7 ++--
 translocal.c    |   7 ++--
 15 files changed, 145 insertions(+), 73 deletions(-)
backbonetable.c +4 -3
index d2e58d1..b82fbe7 100644
@@ -104,11 +104,11 @@ static int bla_backbone_callback(struct nl_msg *msg, void *arg)
 	return NL_OK;
 }
 
-static int netlink_print_bla_backbone(char *mesh_iface, char *orig_iface,
+static int netlink_print_bla_backbone(struct state *state, char *orig_iface,
 				      int read_opts, float orig_timeout,
 				      float watch_interval)
 {
-	return netlink_print_common(mesh_iface, orig_iface, read_opts,
+	return netlink_print_common(state, orig_iface, read_opts,
 				    orig_timeout, watch_interval,
 				    "Originator           VID   last seen (CRC   )\n",
 				    BATADV_CMD_GET_BLA_BACKBONE,
@@ -122,4 +122,5 @@ static struct debug_table_data batctl_debug_table_backbonetable = {
 };
 
 COMMAND_NAMED(DEBUGTABLE, backbonetable, "bbt", handle_debug_table,
-	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_backbonetable, "");
+	      COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK,
+	      &batctl_debug_table_backbonetable, "");
claimtable.c +4 -3
index 06f42dc..5410392 100644
@@ -109,11 +109,11 @@ static int bla_claim_callback(struct nl_msg *msg, void *arg)
 	return NL_OK;
 }
 
-static int netlink_print_bla_claim(char *mesh_iface, char *orig_iface,
+static int netlink_print_bla_claim(struct state *state, char *orig_iface,
 				   int read_opts, float orig_timeout,
 				   float watch_interval)
 {
-	return netlink_print_common(mesh_iface, orig_iface, read_opts,
+	return netlink_print_common(state, orig_iface, read_opts,
 				    orig_timeout, watch_interval,
 				    "Client               VID      Originator        [o] (CRC   )\n",
 				    BATADV_CMD_GET_BLA_CLAIM,
@@ -127,4 +127,5 @@ static struct debug_table_data batctl_debug_table_claimtable = {
 };
 
 COMMAND_NAMED(DEBUGTABLE, claimtable, "cl", handle_debug_table,
-	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_claimtable, "");
+	      COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK,
+	      &batctl_debug_table_claimtable, "");
dat_cache.c +5 -4
index a56fb11..edf8c72 100644
@@ -113,7 +113,7 @@ static int dat_cache_callback(struct nl_msg *msg, void *arg)
 	return NL_OK;
 }
 
-static int netlink_print_dat_cache(char *mesh_iface, char *orig_iface,
+static int netlink_print_dat_cache(struct state *state, char *orig_iface,
 				   int read_opts, float orig_timeout,
 				   float watch_interval)
 {
@@ -121,13 +121,13 @@ static int netlink_print_dat_cache(char *mesh_iface, char *orig_iface,
 	int ret;
 
 	ret = asprintf(&header, "Distributed ARP Table (%s):\n%s\n",
-		       mesh_iface,
+		       state->mesh_iface,
 		       "          IPv4             MAC        VID   last-seen");
 
 	if (ret < 0)
 		return ret;
 
-	ret = netlink_print_common(mesh_iface, orig_iface, read_opts,
+	ret = netlink_print_common(state, orig_iface, read_opts,
 				   orig_timeout, watch_interval, header,
 				   BATADV_CMD_GET_DAT_CACHE,
 				   dat_cache_callback);
@@ -143,4 +143,5 @@ static struct debug_table_data batctl_debug_table_dat_cache = {
 };
 
 COMMAND_NAMED(DEBUGTABLE, dat_cache, "dc", handle_debug_table,
-	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_dat_cache, "");
+	      COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK,
+	      &batctl_debug_table_dat_cache, "");
debug.c +2 -3
index 17dde92..b908e00 100644
@@ -168,9 +168,8 @@ int handle_debug_table(struct state *state, int argc, char **argv)
 	}
 
 	if (debug_table->netlink_fn) {
-		err = debug_table->netlink_fn(
-			state->mesh_iface, orig_iface, read_opt, orig_timeout,
-			watch_interval);
+		err = debug_table->netlink_fn(state , orig_iface, read_opt,
+					      orig_timeout, watch_interval);
 		if (err != -EOPNOTSUPP)
 			return err;
 	}
debug.h +1 -1
index 79c489a..525a46b 100644
@@ -39,7 +39,7 @@
 struct debug_table_data {
 	const char *debugfs_name;
 	size_t header_lines;
-	int (*netlink_fn)(char *mesh_iface, char *hard_iface, int read_opt,
+	int (*netlink_fn)(struct state *state, char *hard_iface, int read_opt,
 			 float orig_timeout, float watch_interval);
 	unsigned int option_unicast_only:1;
 	unsigned int option_multicast_only:1;
gateways.c +6 -5
index ca5d6ec..ff7693f 100644
@@ -127,7 +127,7 @@ static int gateways_callback(struct nl_msg *msg, void *arg)
 	return NL_OK;
 }
 
-static int netlink_print_gateways(char *mesh_iface, char *orig_iface,
+static int netlink_print_gateways(struct state *state, char *orig_iface,
 				  int read_opts, float orig_timeout,
 				  float watch_interval)
 {
@@ -135,9 +135,9 @@ static int netlink_print_gateways(char *mesh_iface, char *orig_iface,
 	char *info_header;
 	int ifindex;
 
-	ifindex = if_nametoindex(mesh_iface);
+	ifindex = if_nametoindex(state->mesh_iface);
 	if (!ifindex) {
-		fprintf(stderr, "Interface %s is unknown\n", mesh_iface);
+		fprintf(stderr, "Interface %s is unknown\n", state->mesh_iface);
 		return -ENODEV;
 	}
 
@@ -157,7 +157,7 @@ static int netlink_print_gateways(char *mesh_iface, char *orig_iface,
 	if (!header)
 		return -EINVAL;
 
-	return netlink_print_common(mesh_iface, orig_iface, read_opts,
+	return netlink_print_common(state, orig_iface, read_opts,
 				    orig_timeout, watch_interval,
 				    header,
 				    BATADV_CMD_GET_GATEWAYS,
@@ -171,4 +171,5 @@ static struct debug_table_data batctl_debug_table_gateways = {
 };
 
 COMMAND_NAMED(DEBUGTABLE, gateways, "gwl", handle_debug_table,
-	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_gateways, "");
+	      COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK,
+	      &batctl_debug_table_gateways, "");
main.c +17 -1
index 9fc6bfb..ab7da45 100644
@@ -21,7 +21,7 @@
  */
 
 
-
+#include <errno.h>
 #include <getopt.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -32,6 +32,7 @@
 #include "sys.h"
 #include "debug.h"
 #include "functions.h"
+#include "netlink.h"
 
 char mesh_dfl_iface[] = "bat0";
 char module_ver_path[] = "/sys/module/batman_adv/version";
@@ -180,8 +181,23 @@ int main(int argc, char **argv)
 		exit(EXIT_FAILURE);
 	}
 
+	if (cmd->flags & COMMAND_FLAG_NETLINK) {
+		ret = netlink_create(&state);
+		if (ret < 0 && ret != -EOPNOTSUPP) {
+			/* TODO handle -EOPNOTSUPP as error when fallbacks were
+			 * removed
+			 */
+			fprintf(stderr,
+				"Error - failed to connect to batadv\n");
+			exit(EXIT_FAILURE);
+		}
+	}
+
 	ret = cmd->handler(&state, argc, argv);
 
+	if (cmd->flags & COMMAND_FLAG_NETLINK)
+		netlink_destroy(&state);
+
 	return ret;
 
 err:
main.h +9 -0
index 2656dcf..4a48f61 100644
@@ -25,6 +25,10 @@
 
 #include <stdint.h>
 
+#include <netlink/genl/ctrl.h>
+#include <netlink/genl/genl.h>
+#include <netlink/netlink.h>
+
 #ifndef SOURCE_VERSION
 #define SOURCE_VERSION "2018.4"
 #endif
@@ -61,6 +65,7 @@ extern char module_ver_path[];
 
 enum command_flags {
 	COMMAND_FLAG_MESH_IFACE = BIT(0),
+	COMMAND_FLAG_NETLINK = BIT(1),
 };
 
 enum command_type {
@@ -71,6 +76,10 @@ enum command_type {
 struct state {
 	char *mesh_iface;
 	const struct command *cmd;
+
+	struct nl_sock *sock;
+	struct nl_cb *cb;
+	int batadv_family;
 };
 
 struct command {
mcast_flags.c +6 -5
index e35cce3..0dc4227 100644
@@ -105,7 +105,7 @@ static int mcast_flags_callback(struct nl_msg *msg, void *arg)
 	return NL_OK;
 }
 
-static int netlink_print_mcast_flags(char *mesh_iface, char *orig_iface,
+static int netlink_print_mcast_flags(struct state *state, char *orig_iface,
 				     int read_opts, float orig_timeout,
 				     float watch_interval)
 {
@@ -116,9 +116,9 @@ static int netlink_print_mcast_flags(char *mesh_iface, char *orig_iface,
 	int ifindex;
 	int ret;
 
-	ifindex = if_nametoindex(mesh_iface);
+	ifindex = if_nametoindex(state->mesh_iface);
 	if (!ifindex) {
-		fprintf(stderr, "Interface %s is unknown\n", mesh_iface);
+		fprintf(stderr, "Interface %s is unknown\n", state->mesh_iface);
 		return -ENODEV;
 	}
 
@@ -160,7 +160,7 @@ static int netlink_print_mcast_flags(char *mesh_iface, char *orig_iface,
 	if (ret < 0)
 		return ret;
 
-	ret = netlink_print_common(mesh_iface, orig_iface, read_opts,
+	ret = netlink_print_common(state, orig_iface, read_opts,
 				   orig_timeout, watch_interval, header,
 				   BATADV_CMD_GET_MCAST_FLAGS,
 				   mcast_flags_callback);
@@ -176,4 +176,5 @@ static struct debug_table_data batctl_debug_table_mcast_flags = {
 };
 
 COMMAND_NAMED(DEBUGTABLE, mcast_flags, "mf", handle_debug_table,
-	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_mcast_flags, "");
+	      COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK,
+	      &batctl_debug_table_mcast_flags, "");
neighbors.c +4 -3
index f7ea9ec..76b45ea 100644
@@ -120,11 +120,11 @@ static int neighbors_callback(struct nl_msg *msg, void *arg)
 	return NL_OK;
 }
 
-static int netlink_print_neighbors(char *mesh_iface, char *orig_iface,
+static int netlink_print_neighbors(struct state *state, char *orig_iface,
 				   int read_opts, float orig_timeout,
 				   float watch_interval)
 {
-	return netlink_print_common(mesh_iface, orig_iface, read_opts,
+	return netlink_print_common(state, orig_iface, read_opts,
 				    orig_timeout, watch_interval,
 				    "IF             Neighbor              last-seen\n",
 				    BATADV_CMD_GET_NEIGHBORS,
@@ -138,4 +138,5 @@ static struct debug_table_data batctl_debug_table_neighbors = {
 };
 
 COMMAND_NAMED(DEBUGTABLE, neighbors, "n", handle_debug_table,
-	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_neighbors, "");
+	      COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK,
+	      &batctl_debug_table_neighbors, "");
netlink.c +67 -33

159 lines not on this page · raw message

netlink.h +6 -1
index 0b21ac1..2526b07 100644
@@ -27,6 +27,8 @@
 #include <netlink/genl/ctrl.h>
 #include <stdint.h>
 
+struct state;
+
 struct print_opts {
 	int read_opt;
 	float orig_timeout;
@@ -39,6 +41,9 @@ struct print_opts {
 
 struct ether_addr;
 
+int netlink_create(struct state *state);
+void netlink_destroy(struct state *state);
+
 int netlink_print_routing_algos(void);
 
 char *netlink_get_info(int ifindex, uint8_t nl_cmd, const char *header);
@@ -52,7 +57,7 @@ extern struct nla_policy batadv_netlink_policy[];
 
 int missing_mandatory_attrs(struct nlattr *attrs[], const int mandatory[],
 			    int num);
-int netlink_print_common(char *mesh_iface, char *orig_iface, int read_opt,
+int netlink_print_common(struct state *state, char *orig_iface, int read_opt,
 			 float orig_timeout, float watch_interval,
 			 const char *header, uint8_t nl_cmd,
 			 nl_recvmsg_msg_cb_t callback);
originators.c +6 -5
index 54526e3..c29300a 100644
@@ -179,7 +179,7 @@ static int originators_callback(struct nl_msg *msg, void *arg)
 	return NL_OK;
 }
 
-static int netlink_print_originators(char *mesh_iface, char *orig_iface,
+static int netlink_print_originators(struct state *state, char *orig_iface,
 				     int read_opts, float orig_timeout,
 				     float watch_interval)
 {
@@ -187,9 +187,9 @@ static int netlink_print_originators(char *mesh_iface, char *orig_iface,
 	char *info_header;
 	int ifindex;
 
-	ifindex = if_nametoindex(mesh_iface);
+	ifindex = if_nametoindex(state->mesh_iface);
 	if (!ifindex) {
-		fprintf(stderr, "Interface %s is unknown\n", mesh_iface);
+		fprintf(stderr, "Interface %s is unknown\n", state->mesh_iface);
 		return -ENODEV;
 	}
 
@@ -209,7 +209,7 @@ static int netlink_print_originators(char *mesh_iface, char *orig_iface,
 	if (!header)
 		return -EINVAL;
 
-	return netlink_print_common(mesh_iface, orig_iface, read_opts,
+	return netlink_print_common(state, orig_iface, read_opts,
 				    orig_timeout, watch_interval, header,
 				    BATADV_CMD_GET_ORIGINATORS,
 				    originators_callback);
@@ -224,4 +224,5 @@ static struct debug_table_data batctl_debug_table_originators = {
 };
 
 COMMAND_NAMED(DEBUGTABLE, originators, "o", handle_debug_table,
-	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_originators, "");
+	      COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK,
+	      &batctl_debug_table_originators, "");
transglobal.c +4 -3
index f61aa9f..fbbce25 100644
@@ -138,11 +138,11 @@ static int transglobal_callback(struct nl_msg *msg, void *arg)
 	return NL_OK;
 }
 
-static int netlink_print_transglobal(char *mesh_iface, char *orig_iface,
+static int netlink_print_transglobal(struct state *state, char *orig_iface,
 				     int read_opts, float orig_timeout,
 				     float watch_interval)
 {
-	return netlink_print_common(mesh_iface, orig_iface, read_opts,
+	return netlink_print_common(state, orig_iface, read_opts,
 				    orig_timeout, watch_interval,
 				    "   Client             VID Flags Last ttvn     Via        ttvn  (CRC       )\n",
 				    BATADV_CMD_GET_TRANSTABLE_GLOBAL,
@@ -158,4 +158,5 @@ static struct debug_table_data batctl_debug_table_transglobal = {
 };
 
 COMMAND_NAMED(DEBUGTABLE, transglobal, "tg", handle_debug_table,
-	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_transglobal, "");
+	      COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK,
+	      &batctl_debug_table_transglobal, "");
translocal.c +4 -3
index 815dc1e..1057abd 100644
@@ -134,11 +134,11 @@ static int translocal_callback(struct nl_msg *msg, void *arg)
 	return NL_OK;
 }
 
-static int netlink_print_translocal(char *mesh_iface, char *orig_iface,
+static int netlink_print_translocal(struct state *state, char *orig_iface,
 				    int read_opts, float orig_timeout,
 				    float watch_interval)
 {
-	return netlink_print_common(mesh_iface, orig_iface, read_opts,
+	return netlink_print_common(state, orig_iface, read_opts,
 				    orig_timeout, watch_interval,
 				    "Client             VID Flags    Last seen (CRC       )\n",
 				    BATADV_CMD_GET_TRANSTABLE_LOCAL,
@@ -154,4 +154,5 @@ static struct debug_table_data batctl_debug_table_translocal = {
 };
 
 COMMAND_NAMED(DEBUGTABLE, translocal, "tl", handle_debug_table,
-	      COMMAND_FLAG_MESH_IFACE, &batctl_debug_table_translocal, "");
+	      COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK,
+	      &batctl_debug_table_translocal, "");
Signature · 1 line
2.11.0
#39 lore raw

PATCH v3 39/42 batctl: Move routing_algo specific code it command source file

In reply to Sven Eckelmann

It is easier to work on the actual command implementation when its source code is also saved it the correct source file. Only the shared code should be in the shared code location.

---
 debug.c        |  15 -------
 debug.h        |   1 -
 functions.c    |  10 -----
 functions.h    |   1 -
 netlink.c      | 116 ++++---------------------------------------------
 netlink.h      |   8 +++-
 routing_algo.c | 133 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 147 insertions(+), 137 deletions(-)
debug.c +0 -15
index b908e00..2979dff 100644
@@ -183,18 +183,3 @@ int handle_debug_table(struct state *state, int argc, char **argv)
 			 read_opt, orig_timeout, watch_interval,
 			 debug_table->header_lines);
 }
-
-int debug_print_routing_algos(void)
-{
-	char full_path[MAX_PATH+1];
-	char *debugfs_mnt;
-
-	debugfs_mnt = debugfs_mount(NULL);
-	if (!debugfs_mnt) {
-		fprintf(stderr, "Error - can't mount or find debugfs\n");
-		return -1;
-	}
-
-	debugfs_make_path(DEBUG_BATIF_PATH_FMT, "", full_path, sizeof(full_path));
-	return read_file(full_path, DEBUG_ROUTING_ALGOS, 0, 0, 0, 0);
-}
debug.h +0 -1
index 525a46b..2dac1b7 100644
@@ -48,6 +48,5 @@ struct debug_table_data {
 };
 
 int handle_debug_table(struct state *state, int argc, char **argv);
-int debug_print_routing_algos(void);
 
 #endif
functions.c +0 -10
index 0a7b587..bdede8b 100644
@@ -905,16 +905,6 @@ int vlan_get_link(const char *ifname, char **parent)
 	return arg.vid;
 }
 
-int print_routing_algos(void)
-{
-	int err;
-
-	err = netlink_print_routing_algos();
-	if (err == -EOPNOTSUPP)
-		err = debug_print_routing_algos();
-	return err;
-}
-
 int query_rtnl_link(int ifindex, nl_recvmsg_msg_cb_t func, void *arg)
 {
 	struct ifinfomsg rt_hdr = {
functions.h +0 -1
index d3144d0..c16ba2e 100644
@@ -57,7 +57,6 @@ int check_mesh_iface_ownership(char *mesh_iface, char *hard_iface);
 void get_random_bytes(void *buf, size_t buflen);
 void check_root_or_die(const char *cmd);
 
-int print_routing_algos(void);
 extern char *line_ptr;
 
 enum {
netlink.c +8 -108

158 lines not on this page · raw message

netlink.h +6 -2
index 2526b07..b91ca10 100644
@@ -44,8 +44,6 @@ struct ether_addr;
 int netlink_create(struct state *state);
 void netlink_destroy(struct state *state);
 
-int netlink_print_routing_algos(void);
-
 char *netlink_get_info(int ifindex, uint8_t nl_cmd, const char *header);
 int translate_mac_netlink(const char *mesh_iface, const struct ether_addr *mac,
 			  struct ether_addr *mac_out);
@@ -62,6 +60,12 @@ int netlink_print_common(struct state *state, char *orig_iface, int read_opt,
 			 const char *header, uint8_t nl_cmd,
 			 nl_recvmsg_msg_cb_t callback);
 
+int netlink_print_common_cb(struct nl_msg *msg, void *arg);
+int netlink_stop_callback(struct nl_msg *msg, void *arg);
+int netlink_print_error(struct sockaddr_nl *nla, struct nlmsgerr *nlerr,
+			void *arg);
+void netlink_print_remaining_header(struct print_opts *opts);
+
 extern char algo_name_buf[256];
 extern int last_err;
 extern int64_t mcast_flags;
routing_algo.c +133 -0

151 lines not on this page · raw message

Signature · 1 line
2.11.0
#40 lore raw

PATCH v3 40/42 batctl: Add command to monitor for netlink events

In reply to Sven Eckelmann

The netlink multicast groups of batman-adv are currently used to inform userspace about finished throughputmeter runs. It will later also be used to inform about changes of settings of a specific batadv interface.

The "event" will wait for these messages and print brief summaries about the received data. This can be used during the development of new features or to monitor running systems.

---
 Makefile     |   1 +
 event.c      | 246 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 man/batctl.8 |   4 +
 3 files changed, 251 insertions(+)
 create mode 100644 event.c
Makefile +1 -0
index a6971d8..cf2b1c7 100755
@@ -43,6 +43,7 @@ OBJ += dat_cache.o
 OBJ += debugfs.o
 OBJ += debug.o
 OBJ += distributed_arp_table.o
+OBJ += event.o
 OBJ += fragmentation.o
 OBJ += functions.o
 OBJ += gateways.o
event.c new file +246 -0

246 lines not on this page · raw message

man/batctl.8 +4 -0
index d5fc530..fe6cf93 100644
@@ -89,6 +89,10 @@ OGM packet aggregation.
 If no parameter is given the current bonding mode setting is displayed. Otherwise the parameter is used to enable or disable
 the bonding mode.
 .br
+.IP "\fBevent\fP|\fBe\fP [\fB\-t\fP|\fB\-r\fP]"
+batctl will monitor for events from the netlink kernel interface of batman-adv. The local timestamp of the event will be printed
+when parameter \fB\-t\fP is specified. Parameter \fB\-r\fP will do the same but with relative timestamps.
+.br
 .IP "\fBfragmentation\fP|\fBf\fP [\fB0\fP|\fB1\fP]"
 If no parameter is given the current fragmentation mode setting is displayed. Otherwise the parameter is used to enable or
 disable fragmentation.
Signature · 1 line
2.11.0
#41 lore raw

PATCH v3 41/42 batctl: Simplify enabling for bisect_iv subcommand

In reply to Sven Eckelmann

The variable content of CONFIG_BATCTL_BISECT can be used to decide whether the bisect_iv command is enabled or not. This would make it possible in the future to introduce a generic way to enable or disable commands. Combining this with link-time-optimization and/or function/data-section allows to relatively freely scale the functionality of batctl and its size.

---
 Makefile | 96 +++++++++++++++++++++++++++++++---------------------------------
 1 file changed, 46 insertions(+), 50 deletions(-)
Makefile +46 -50
index cf2b1c7..dfcfbd9 100755
@@ -27,53 +27,49 @@ export CONFIG_BATCTL_BISECT=n
 # batctl build
 BINARY_NAME = batctl
 
-OBJ_BISECT = bisect_iv.o
-
-OBJ += aggregation.o
-OBJ += ap_isolation.o
-OBJ += bat-hosts.o
-OBJ += backbonetable.o
-ifeq ($(CONFIG_BATCTL_BISECT),y)
-OBJ += $(OBJ_BISECT)
-endif
-OBJ += bonding.o
-OBJ += bridge_loop_avoidance.o
-OBJ += claimtable.o
-OBJ += dat_cache.o
-OBJ += debugfs.o
-OBJ += debug.o
-OBJ += distributed_arp_table.o
-OBJ += event.o
-OBJ += fragmentation.o
-OBJ += functions.o
-OBJ += gateways.o
-OBJ += genl.o
-OBJ += gw_mode.o
-OBJ += hash.o
-OBJ += icmp_helper.o
-OBJ += interface.o
-OBJ += isolation_mark.o
-OBJ += loglevel.o
-OBJ += log.o
-OBJ += main.o
-OBJ += mcast_flags.o
-OBJ += multicast_mode.o
-OBJ += nc_nodes.o
-OBJ += neighbors.o
-OBJ += netlink.o
-OBJ += network_coding.o
-OBJ += ping.o
-OBJ += originators.o
-OBJ += orig_interval.o
-OBJ += routing_algo.o
-OBJ += statistics.o
-OBJ += sys.o
-OBJ += tcpdump.o
-OBJ += throughputmeter.o
-OBJ += traceroute.o
-OBJ += transglobal.o
-OBJ += translate.o
-OBJ += translocal.o
+obj-y += aggregation.o
+obj-y += ap_isolation.o
+obj-y += bat-hosts.o
+obj-y += backbonetable.o
+obj-$(CONFIG_BATCTL_BISECT) += bisect_iv.o
+obj-y += bonding.o
+obj-y += bridge_loop_avoidance.o
+obj-y += claimtable.o
+obj-y += dat_cache.o
+obj-y += debugfs.o
+obj-y += debug.o
+obj-y += distributed_arp_table.o
+obj-y += event.o
+obj-y += fragmentation.o
+obj-y += functions.o
+obj-y += gateways.o
+obj-y += genl.o
+obj-y += gw_mode.o
+obj-y += hash.o
+obj-y += icmp_helper.o
+obj-y += interface.o
+obj-y += isolation_mark.o
+obj-y += loglevel.o
+obj-y += log.o
+obj-y += main.o
+obj-y += mcast_flags.o
+obj-y += multicast_mode.o
+obj-y += nc_nodes.o
+obj-y += neighbors.o
+obj-y += netlink.o
+obj-y += network_coding.o
+obj-y += ping.o
+obj-y += originators.o
+obj-y += orig_interval.o
+obj-y += routing_algo.o
+obj-y += statistics.o
+obj-y += sys.o
+obj-y += tcpdump.o
+obj-y += throughputmeter.o
+obj-y += traceroute.o
+obj-y += transglobal.o
+obj-y += translate.o
+obj-y += translocal.o
 
 MANPAGE = man/batctl.8
 
@@ -150,11 +146,11 @@ all: $(BINARY_NAME)
 .c.o:
 	$(COMPILE.c) -o $@ $<
 
-$(BINARY_NAME): $(OBJ)
+$(BINARY_NAME): $(obj-y)
 	$(LINK.o) $^ $(LDLIBS) -o $@
 
 clean:
-	$(RM) $(BINARY_NAME) $(OBJ) $(OBJ_BISECT) $(DEP)
+	$(RM) $(BINARY_NAME) $(obj-y) $(obj-n) $(DEP)
 
 install: $(BINARY_NAME)
 	$(MKDIR) $(DESTDIR)$(SBINDIR)
@@ -163,7 +159,7 @@ install: $(BINARY_NAME)
 	$(INSTALL) -m 0644 $(MANPAGE) $(DESTDIR)$(MANDIR)/man8
 
 # load dependencies
-DEP = $(OBJ:.o=.d) $(OBJ_BISECT:.o=.d)
+DEP = $(obj-y:.o=.d) $(obj-n:.o=.d)
 -include $(DEP)
 
 .PHONY: all clean install
Signature · 1 line
2.11.0
#42 lore raw

PATCH v3 42/42 batctl: Allow to enable/disable subcommands

In reply to Sven Eckelmann

Systems with limited space are usually not using all the functionality of batman-adv and of batctl. Still, most of the batctl is still build even when the corresponding batman-adv functionality would not be available. This becomes especially important for subcommands which implement most functionality in userspace when it was previously completely handled by the kernel.

An external build system for such system can now just select the commands it really needs. Combining this with link-time-optimizationa and/or function/data-section garbage collection allows to find the right mix between size and functionality.

---
 Makefile | 83 +++++++++++++++++++++++++++++++++++++---------------------------
 1 file changed, 48 insertions(+), 35 deletions(-)
Makefile +48 -35
index dfcfbd9..e6b2412 100755
@@ -20,56 +20,69 @@
 #
 # License-Filename: LICENSES/preferred/GPL-2.0
 
-# changing the CONFIG_* line to 'y' enables the related feature
-# batctl advanced debugging tool bisect:
+# just for backward compatibility - please use CONFIG_bisect_iv instead
 export CONFIG_BATCTL_BISECT=n
 
 # batctl build
 BINARY_NAME = batctl
 
-obj-y += aggregation.o
-obj-y += ap_isolation.o
 obj-y += bat-hosts.o
-obj-y += backbonetable.o
-obj-$(CONFIG_BATCTL_BISECT) += bisect_iv.o
-obj-y += bonding.o
-obj-y += bridge_loop_avoidance.o
-obj-y += claimtable.o
-obj-y += dat_cache.o
 obj-y += debugfs.o
 obj-y += debug.o
-obj-y += distributed_arp_table.o
-obj-y += event.o
-obj-y += fragmentation.o
 obj-y += functions.o
-obj-y += gateways.o
 obj-y += genl.o
-obj-y += gw_mode.o
 obj-y += hash.o
 obj-y += icmp_helper.o
-obj-y += interface.o
-obj-y += isolation_mark.o
-obj-y += loglevel.o
-obj-y += log.o
 obj-y += main.o
-obj-y += mcast_flags.o
-obj-y += multicast_mode.o
-obj-y += nc_nodes.o
-obj-y += neighbors.o
 obj-y += netlink.o
-obj-y += network_coding.o
-obj-y += ping.o
-obj-y += originators.o
-obj-y += orig_interval.o
-obj-y += routing_algo.o
-obj-y += statistics.o
 obj-y += sys.o
-obj-y += tcpdump.o
-obj-y += throughputmeter.o
-obj-y += traceroute.o
-obj-y += transglobal.o
-obj-y += translate.o
-obj-y += translocal.o
+
+define add_command
+  CONFIG_$(1):=$(2)
+  ifneq ($$(CONFIG_$(1)),y)
+    ifneq ($$(CONFIG_$(1)),n)
+      $$(warning invalid value for parameter CONFIG_$(1): $$(CONFIG_$(1)))
+    endif
+  endif
+
+  obj-$$(CONFIG_$(1)) += $(1).o
+endef # add_command
+
+# using the make parameter CONFIG_* (e.g. CONFIG_bisect_iv) with the value 'y'
+# enables the related feature and 'n' disables it
+$(eval $(call add_command,aggregation,y))
+$(eval $(call add_command,ap_isolation,y))
+$(eval $(call add_command,backbonetable,y))
+$(eval $(call add_command,bisect_iv,$(CONFIG_BATCTL_BISECT)))
+$(eval $(call add_command,bonding,y))
+$(eval $(call add_command,bridge_loop_avoidance,y))
+$(eval $(call add_command,claimtable,y))
+$(eval $(call add_command,dat_cache,y))
+$(eval $(call add_command,distributed_arp_table,y))
+$(eval $(call add_command,event,y))
+$(eval $(call add_command,fragmentation,y))
+$(eval $(call add_command,gateways,y))
+$(eval $(call add_command,gw_mode,y))
+$(eval $(call add_command,interface,y))
+$(eval $(call add_command,isolation_mark,y))
+$(eval $(call add_command,log,y))
+$(eval $(call add_command,loglevel,y))
+$(eval $(call add_command,mcast_flags,y))
+$(eval $(call add_command,multicast_mode,y))
+$(eval $(call add_command,nc_nodes,y))
+$(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,ping,y))
+$(eval $(call add_command,routing_algo,y))
+$(eval $(call add_command,statistics,y))
+$(eval $(call add_command,tcpdump,y))
+$(eval $(call add_command,throughputmeter,y))
+$(eval $(call add_command,traceroute,y))
+$(eval $(call add_command,transglobal,y))
+$(eval $(call add_command,translate,y))
+$(eval $(call add_command,translocal,y))
 
 MANPAGE = man/batctl.8
 
Signature · 1 line
2.11.0
#43 lore raw
In reply to Sven Eckelmann
Quoted 11 lines · On Donnerstag, 25. Oktober 2018 18:22:03 CET Sven Eckelmann wrote:

the batctl command already has support to get (previously debugfs) tables via netlink. It does this while still being able to fall back to the old debugfs tables on kernels which don't support the new generic netlink family.

Something similar should be done in the future for the settings which are currently part of sysfs. But we can already see that the current integration of netlink in batctl only done in a single file - netlink.c But this file is already starting to be so big that working with it is rather cumbersome.

Quoted 5 lines

So as first steps:

* restructure command registration
* move commands in separate files (which should store their actual implementation)
* add a new helper command to receive multicast group messages from the kernel

Added as 0a201c2..2f5dbd0 [1]

Kind regards,
Sven

[1] https://git.open-mesh.org/batctl.git/log/2f5dbd056b8be344b5492835b0924f6cf463ba4d