Skip to contentSkip to conversation

batctl: replace multicast_mode with multicast_forceflood command

PATCH New Linus Lüssing 1 participant 1 message Feb 16, 2019 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 batctl: replace multicast_mode with multicast_forceflood command

This patch hides the multicast_mode setting in the UI and adds a new multicast_forceflood command. multicast_forceflood is basically the inverse of the current multicast_mode setting.

For the netlink config additions to batman-adv "multicast_mode" was not added. Instead a "multicast_forceflood" attribute was introduced.

The multicast_mode batctl command is kept for compatibility for now but should be removed eventually.

---
 Makefile               |  1 +
 README.rst             |  8 ++---
 functions.c            | 16 ++++++++-
 functions.h            |  1 +
 main.c                 |  3 ++
 main.h                 |  1 +
 man/batctl.8           |  8 +++--
 multicast_forceflood.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++
 multicast_mode.c       |  3 +-
 sys.c                  | 30 +++++++++++++---
 10 files changed, 151 insertions(+), 15 deletions(-)
 create mode 100644 multicast_forceflood.c
Makefile +1 -0
index 4d8b709..7c050c0 100755
@@ -68,6 +68,7 @@ $(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_forceflood,y))
 $(eval $(call add_command,multicast_mode,y))
 $(eval $(call add_command,nc_nodes,y))
 $(eval $(call add_command,neighbors,y))
README.rst +4 -4
index 4c0f544..6db68d7 100644
@@ -468,14 +468,14 @@ Usage::
 Note that network coding requires a working promiscuous mode on all interfaces.
 
 
-batctl multicast_mode
-=====================
+batctl multicast_forceflood
+===========================
 
-display or modify the multicast mode setting
+display or modify the multicast forceflood setting
 
 Usage::
 
-  batctl multicast_mode|mm [0|1]
+  batctl multicast_forceflood|mff [0|1]
 
 
 batctl mcast_flags
functions.c +15 -1
index 76deab7..a202969 100644
@@ -175,6 +175,16 @@ static bool ether_addr_valid(const uint8_t *addr)
 	return true;
 }
 
+static void print_inv_bool(char *line)
+{
+	if (!strncmp("enabled", line, strlen("enabled")))
+		printf("disabled\n");
+	else if (!strncmp("disabled", line, strlen("disabled")))
+		printf("enabled\n");
+	else
+		printf("%s", line);
+}
+
 int read_file(const char *dir, const char *fname, int read_opt,
 	      float orig_timeout, float watch_interval, size_t header_lines)
 {
@@ -237,7 +247,11 @@ int read_file(const char *dir, const char *fname, int read_opt,
 			continue;
 
 		if (!(read_opt & USE_BAT_HOSTS)) {
-			printf("%s", line_ptr);
+			if (read_opt & INVERSE_BOOL)
+				print_inv_bool(line_ptr);
+			else
+				printf("%s", line_ptr);
+
 			continue;
 		}
 
functions.h +1 -0
index e2bbb4e..b3f2159 100644
@@ -91,6 +91,7 @@ enum {
 	SKIP_HEADER = 0x100,
 	UNICAST_ONLY = 0x200,
 	MULTICAST_ONLY = 0x400,
+	INVERSE_BOOL = 0x800,
 };
 
 #endif
main.c +3 -0
index 2a28642..199c7a4 100644
@@ -74,6 +74,9 @@ static void print_usage(void)
 			if (cmd->type != type[i])
 				continue;
 
+			if (!cmd->usage)
+				continue;
+
 			if (strcmp(cmd->name, cmd->abbr) == 0)
 				snprintf(buf, sizeof(buf), "%s", cmd->name);
 			else
main.h +1 -0
index fca2a32..92d0e61 100644
@@ -67,6 +67,7 @@ extern char module_ver_path[];
 enum command_flags {
 	COMMAND_FLAG_MESH_IFACE = BIT(0),
 	COMMAND_FLAG_NETLINK = BIT(1),
+	COMMAND_FLAG_INVERSE = BIT(2),
 };
 
 enum command_type {
man/batctl.8 +5 -3
index ed8e71f..695067f 100644
@@ -101,9 +101,11 @@ disable fragmentation.
 If no parameter is given the current network coding mode setting is displayed. Otherwise the parameter is used to enable or
 disable network coding.
 .br
-.IP "\fBmulticast_mode\fP|\fBmm\fP [\fB0\fP|\fB1\fP]"
-If no parameter is given the current multicast mode setting is displayed. Otherwise the parameter is used to enable or
-disable multicast optimizations (i.e. disabling means always sending own multicast frames via classic flooding).
+.IP "\fBmulticast_forceflood\fP|\fBmff\fP [\fB0\fP|\fB1\fP]"
+If no parameter is given the current multicast forceflood setting is displayed. Otherwise the parameter is used to enable or
+disable multicast forceflood. This setting defines whether multicast optimizations should be replaced by simple broadcast-like
+flooding of multicast packets. If set to non-zero then all nodes in the mesh are going to use classic flooding for any
+multicast packet with no optimizations.
 .br
 .IP "\fBloglevel\fP|\fBll\fP [\fBlevel\fP[ \fBlevel\fP[ \fBlevel\fP]] \fB...\fP]"
 If no parameter is given the current log level settings are displayed otherwise the parameter(s) is/are used to set the log
multicast_forceflood.c new file +95 -0

95 lines not on this page · raw message

multicast_mode.c +1 -2
index 836a744..fb17586 100644
@@ -91,5 +91,4 @@ static struct settings_data batctl_settings_multicast_mode = {
 
 COMMAND_NAMED(SUBCOMMAND, multicast_mode, "mm", handle_sys_setting,
 	      COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK,
-	      &batctl_settings_multicast_mode,
-	      "[0|1]             \tdisplay or modify multicast_mode setting");
+	      &batctl_settings_multicast_mode, NULL);
sys.c +25 -5
index 9a7966f..b0864cd 100644
@@ -156,7 +156,8 @@ int sys_simple_print_boolean(struct nl_msg *msg, void *arg,
 static void settings_usage(struct state *state)
 {
 	fprintf(stderr, "Usage: batctl [options] %s|%s [parameters] %s\n",
-		state->cmd->name, state->cmd->abbr, state->cmd->usage);
+		state->cmd->name, state->cmd->abbr,
+		state->cmd->usage ? state->cmd->usage : "");
 
 	fprintf(stderr, "parameters:\n");
 	fprintf(stderr, " \t -h print this help\n");
@@ -167,6 +168,7 @@ static int sys_read_setting(struct state *state, const char *path_buff,
 {
 	struct settings_data *settings = state->cmd->arg;
 	int res = EXIT_FAILURE;
+	int read_opt = NO_FLAGS;
 
 	if (settings->netlink_get) {
 		res = settings->netlink_get(state);
@@ -176,8 +178,12 @@ static int sys_read_setting(struct state *state, const char *path_buff,
 			return EXIT_SUCCESS;
 	}
 
-	if (sysfs_name)
-		res = read_file(path_buff, sysfs_name, NO_FLAGS, 0, 0, 0);
+	if (sysfs_name) {
+		if (state->cmd->flags & COMMAND_FLAG_INVERSE)
+			read_opt |= INVERSE_BOOL;
+
+		res = read_file(path_buff, sysfs_name, read_opt, 0, 0, 0);
+	}
 
 	return res;
 }
@@ -187,6 +193,7 @@ static int sys_write_setting(struct state *state, const char *path_buff,
 {
 	struct settings_data *settings = state->cmd->arg;
 	int res = EXIT_FAILURE;
+	char *argv1 = argv[1];
 
 	if (settings->netlink_set) {
 		res = settings->netlink_set(state);
@@ -196,9 +203,22 @@ static int sys_write_setting(struct state *state, const char *path_buff,
 			return EXIT_SUCCESS;
 	}
 
-	if (sysfs_name)
+	if (sysfs_name) {
+		if (state->cmd->flags & COMMAND_FLAG_INVERSE) {
+			if (!strncmp("0", argv[1], strlen("0")) ||
+			    !strncmp("disable", argv[1], strlen("disable")) ||
+			    !strncmp("disabled", argv[1], strlen("disabled"))) {
+				argv1 = "enabled";
+			} else if (!strncmp("1", argv[1], strlen("1")) ||
+				   !strncmp("enable", argv[1], strlen("enable")) ||
+				   !strncmp("enabled", argv[1], strlen("enabled"))) {
+				argv1 = "disabled";
+			}
+		}
+
 		res = write_file(path_buff, sysfs_name,
-				 argv[1], argc > 2 ? argv[2] : NULL);
+				 argv1, argc > 2 ? argv[2] : NULL);
+	}
 
 	return res;
 }
Signature · 1 line
2.11.0