Repository : ssh://git@open-mesh.org/batctl
On branch : master
commit 1ca604d5a0f25217afb07d96fa8225d1ee298824 Author: Linus Lüssing linus.luessing@c0d3.blue Date: Fri Feb 15 20:54:15 2019 +0100
batctl: add switch for setting multicast_fanout
This patch adds an option for the new multicast_fanout setting in batman-adv.
Signed-off-by: Linus Lüssing linus.luessing@c0d3.blue Signed-off-by: Sven Eckelmann sven@narfation.org
1ca604d5a0f25217afb07d96fa8225d1ee298824 Makefile | 1 + README.rst | 10 ++++++ batman_adv.h | 7 ++++ event.c | 4 +++ man/batctl.8 | 5 +++ multicast_fanout.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++ netlink.c | 1 + 7 files changed, 129 insertions(+)
diff --git a/Makefile b/Makefile index 645d157..df8b7b9 100755 --- a/Makefile +++ b/Makefile @@ -55,6 +55,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_fanout,y)) $(eval $(call add_command,multicast_forceflood,y)) $(eval $(call add_command,multicast_mode,y)) $(eval $(call add_command,nc_nodes,y)) diff --git a/README.rst b/README.rst index e20c7c4..03ea5e5 100644 --- a/README.rst +++ b/README.rst @@ -478,6 +478,16 @@ Usage:: batctl multicast_forceflood|mff [0|1]
+batctl multicast_fanout +======================= + +display or modify the multicast fanout setting + +Usage:: + + batctl multicast_fanout|mo [fanout] + + batctl mcast_flags ==================
diff --git a/batman_adv.h b/batman_adv.h index e53f2b5..67f4636 100644 --- a/batman_adv.h +++ b/batman_adv.h @@ -473,6 +473,13 @@ enum batadv_nl_attrs { */ BATADV_ATTR_THROUGHPUT_OVERRIDE,
+ /** + * @BATADV_ATTR_MULTICAST_FANOUT: defines the maximum number of packet + * copies that may be generated for a multicast-to-unicast conversion. + * Once this limit is exceeded distribution will fall back to broadcast. + */ + BATADV_ATTR_MULTICAST_FANOUT, + /* add attributes above here, update the policy in netlink.c */
/** diff --git a/event.c b/event.c index 50d1cd0..c1eb435 100644 --- a/event.c +++ b/event.c @@ -270,6 +270,10 @@ static void event_parse_set_mesh(struct nlattr **attrs) printf("* log_level 0x%08x\n", nla_get_u32(attrs[BATADV_ATTR_LOG_LEVEL]));
+ if (attrs[BATADV_ATTR_MULTICAST_FANOUT]) + printf("* multicast_fanout %u\n", + nla_get_u32(attrs[BATADV_ATTR_MULTICAST_FANOUT])); + if (attrs[BATADV_ATTR_MULTICAST_FORCEFLOOD_ENABLED]) printf("* multicast_forceflood %s\n", u8_to_boolstr(attrs[BATADV_ATTR_MULTICAST_FORCEFLOOD_ENABLED])); diff --git a/man/batctl.8 b/man/batctl.8 index 418bd96..8d7332a 100644 --- a/man/batctl.8 +++ b/man/batctl.8 @@ -111,6 +111,11 @@ disable multicast forceflood. This setting defines whether multicast optimizatio 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 "\fBmulticast_fanout\fP|\fBmo\fP [\fBfanout\fP]" +If no parameter is given the current multicast fanout setting is displayed. Otherwise the parameter is used to set +the multicast fanout. The multicast fanout defines the maximum number of packet copies that may be generated for a +multicast-to-unicast conversion. Once this limit is exceeded distribution will fall back to broadcast. +.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 level. Level 'none' disables all verbose logging. Level 'batman' enables messages related to routing / flooding / broadcasting. diff --git a/multicast_fanout.c b/multicast_fanout.c new file mode 100644 index 0000000..cec42a3 --- /dev/null +++ b/multicast_fanout.c @@ -0,0 +1,101 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) 2009-2019 B.A.T.M.A.N. contributors: + * + * Linus Lüssing linus.luessing@c0d3.blue + * + * License-Filename: LICENSES/preferred/GPL-2.0 + */ + +#include <errno.h> +#include <stddef.h> +#include <stdint.h> +#include <string.h> + +#include "main.h" +#include "sys.h" + +static struct multicast_fanout_data { + uint32_t multicast_fanout; +} multicast_fanout; + +static int parse_multicast_fanout(struct state *state, int argc, char *argv[]) +{ + struct settings_data *settings = state->cmd->arg; + struct multicast_fanout_data *data = settings->data; + char *endptr; + + if (argc != 2) { + fprintf(stderr, "Error - incorrect number of arguments (expected 1)\n"); + return -EINVAL; + } + + data->multicast_fanout = strtoul(argv[1], &endptr, 0); + if (!endptr || *endptr != '\0') { + fprintf(stderr, "Error - the supplied argument is invalid: %s\n", argv[1]); + return -EINVAL; + } + + return 0; +} + +static int print_multicast_fanout(struct nl_msg *msg, void *arg) +{ + struct nlattr *attrs[BATADV_ATTR_MAX + 1]; + struct nlmsghdr *nlh = nlmsg_hdr(msg); + struct genlmsghdr *ghdr; + int *result = arg; + + if (!genlmsg_valid_hdr(nlh, 0)) + return NL_OK; + + ghdr = nlmsg_data(nlh); + + if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0), + genlmsg_len(ghdr), batadv_netlink_policy)) { + return NL_OK; + } + + if (!attrs[BATADV_ATTR_MULTICAST_FANOUT]) + return NL_OK; + + printf("%u\n", nla_get_u32(attrs[BATADV_ATTR_MULTICAST_FANOUT])); + + *result = 0; + return NL_STOP; +} + +static int get_multicast_fanout(struct state *state) +{ + return sys_simple_nlquery(state, BATADV_CMD_GET_MESH, + NULL, print_multicast_fanout); +} + +static int set_attrs_multicast_fanout(struct nl_msg *msg, void *arg) +{ + struct state *state = arg; + struct settings_data *settings = state->cmd->arg; + struct multicast_fanout_data *data = settings->data; + + nla_put_u32(msg, BATADV_ATTR_MULTICAST_FANOUT, data->multicast_fanout); + + return 0; +} + +static int set_multicast_fanout(struct state *state) +{ + return sys_simple_nlquery(state, BATADV_CMD_SET_MESH, + set_attrs_multicast_fanout, NULL); +} + +static struct settings_data batctl_settings_multicast_fanout = { + .sysfs_name = NULL, + .data = &multicast_fanout, + .parse = parse_multicast_fanout, + .netlink_get = get_multicast_fanout, + .netlink_set = set_multicast_fanout, +}; + +COMMAND_NAMED(SUBCOMMAND, multicast_fanout, "mo", handle_sys_setting, + COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK, + &batctl_settings_multicast_fanout, + "[fanout] \tdisplay or modify multicast_fanout setting"); diff --git a/netlink.c b/netlink.c index aa45f4f..792249f 100644 --- a/netlink.c +++ b/netlink.c @@ -109,6 +109,7 @@ struct nla_policy batadv_netlink_policy[NUM_BATADV_ATTR] = { [BATADV_ATTR_HOP_PENALTY] = { .type = NLA_U8 }, [BATADV_ATTR_LOG_LEVEL] = { .type = NLA_U32 }, [BATADV_ATTR_MULTICAST_FORCEFLOOD_ENABLED] = { .type = NLA_U8 }, + [BATADV_ATTR_MULTICAST_FANOUT] = { .type = NLA_U32 }, [BATADV_ATTR_NETWORK_CODING_ENABLED] = { .type = NLA_U8 }, [BATADV_ATTR_ORIG_INTERVAL] = { .type = NLA_U32 }, [BATADV_ATTR_ELP_INTERVAL] = { .type = NLA_U32 },