1 From: Sven Eckelmann <sven@narfation.org>
2 Date: Thu, 13 Jun 2019 21:12:16 +0200
3 Subject: batctl: Add elp_interval setting command
5 B.A.T.M.A.N. V introduced a hard interface specific setting called
6 elp_interval. It defines the interval in milliseconds in which batman-adv
7 emits probing packets for neighbor sensing (ELP).
9 Signed-off-by: Sven Eckelmann <sven@narfation.org>
11 Forwarded: https://patchwork.open-mesh.org/patch/17949/
13 diff --git a/Makefile b/Makefile
14 index b7bd545e92963c62128efe60c0dc401bdd9fa023..f071da20f866bff6c162d697d2e43fa9d68ee08d 100755
17 @@ -45,6 +45,7 @@ $(eval $(call add_command,bridge_loop_avoidance,y))
18 $(eval $(call add_command,claimtable,y))
19 $(eval $(call add_command,dat_cache,y))
20 $(eval $(call add_command,distributed_arp_table,y))
21 +$(eval $(call add_command,elp_interval,y))
22 $(eval $(call add_command,event,y))
23 $(eval $(call add_command,fragmentation,y))
24 $(eval $(call add_command,gateways,y))
25 diff --git a/README.rst b/README.rst
26 index bc54412bc77dae1889d4f05298c34efc1966776b..92983aa6030e2a890283bca448b9203cd4d56b51 100644
29 @@ -386,6 +386,22 @@ Example::
36 +display or modify the elp interval in ms for hard interface
40 + batctl hardif $hardif elp_interval|et [interval]
44 + $ batctl hardif eth0 elp_interval 200
45 + $ batctl hardif eth0 elp_interval
52 diff --git a/elp_interval.c b/elp_interval.c
54 index 0000000000000000000000000000000000000000..0a5e98923a622f52e523696b1ec1bfb856eeca9f
58 +// SPDX-License-Identifier: GPL-2.0
59 +/* Copyright (C) 2009-2019 B.A.T.M.A.N. contributors:
61 + * Marek Lindner <mareklindner@neomailbox.ch>
63 + * License-Filename: LICENSES/preferred/GPL-2.0
74 +static struct elp_interval_data {
75 + uint32_t elp_interval;
78 +static int parse_elp_interval(struct state *state, int argc, char *argv[])
80 + struct settings_data *settings = state->cmd->arg;
81 + struct elp_interval_data *data = settings->data;
85 + fprintf(stderr, "Error - incorrect number of arguments (expected 1)\n");
89 + data->elp_interval = strtoul(argv[1], &endptr, 0);
90 + if (!endptr || *endptr != '\0') {
91 + fprintf(stderr, "Error - the supplied argument is invalid: %s\n", argv[1]);
98 +static int print_elp_interval(struct nl_msg *msg, void *arg)
100 + struct nlattr *attrs[BATADV_ATTR_MAX + 1];
101 + struct nlmsghdr *nlh = nlmsg_hdr(msg);
102 + struct genlmsghdr *ghdr;
105 + if (!genlmsg_valid_hdr(nlh, 0))
108 + ghdr = nlmsg_data(nlh);
110 + if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0),
111 + genlmsg_len(ghdr), batadv_netlink_policy)) {
115 + if (!attrs[BATADV_ATTR_ELP_INTERVAL])
118 + printf("%u\n", nla_get_u32(attrs[BATADV_ATTR_ELP_INTERVAL]));
124 +static int get_attrs_elp_interval(struct nl_msg *msg, void *arg)
126 + struct state *state = arg;
128 + nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, state->hif);
133 +static int get_elp_interval(struct state *state)
135 + return sys_simple_nlquery(state, BATADV_CMD_GET_HARDIF,
136 + get_attrs_elp_interval, print_elp_interval);
139 +static int set_attrs_elp_interval(struct nl_msg *msg, void *arg)
141 + struct state *state = arg;
142 + struct settings_data *settings = state->cmd->arg;
143 + struct elp_interval_data *data = settings->data;
145 + nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, state->hif);
146 + nla_put_u32(msg, BATADV_ATTR_ELP_INTERVAL, data->elp_interval);
151 +static int set_elp_interval(struct state *state)
153 + return sys_simple_nlquery(state, BATADV_CMD_SET_HARDIF,
154 + set_attrs_elp_interval, NULL);
157 +static struct settings_data batctl_settings_elp_interval = {
158 + .sysfs_name = "elp_interval",
159 + .data = &elp_interval,
160 + .parse = parse_elp_interval,
161 + .netlink_get = get_elp_interval,
162 + .netlink_set = set_elp_interval,
165 +COMMAND_NAMED(SUBCOMMAND_HIF, elp_interval, "et", handle_sys_setting,
166 + COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK,
167 + &batctl_settings_elp_interval,
168 + "[interval] \tdisplay or modify elp_interval setting");
169 diff --git a/man/batctl.8 b/man/batctl.8
170 index acb4288c4e6f59b322d20631ef8e3aee6f2215e5..690da023fd1ac6f51915a9167e92030a650fe1bd 100644
173 @@ -93,6 +93,10 @@ the bonding mode.
174 batctl will monitor for events from the netlink kernel interface of batman-adv. The local timestamp of the event will be printed
175 when parameter \fB\-t\fP is specified. Parameter \fB\-r\fP will do the same but with relative timestamps.
177 +.IP "\fBhardif <hardif>\fP \fBelp_interval\fP|\fBet\fP [\fBinterval\fP]"
178 +If no parameter is given the current ELP interval setting of the hard interface is displayed otherwise the parameter is used to set the
179 +ELP interval. The interval is in units of milliseconds.
181 .IP "\fBfragmentation\fP|\fBf\fP [\fB0\fP|\fB1\fP]"
182 If no parameter is given the current fragmentation mode setting is displayed. Otherwise the parameter is used to enable or
183 disable fragmentation.