1 From: Sven Eckelmann <sven@narfation.org>
2 Date: Thu, 13 Jun 2019 21:12:17 +0200
3 Subject: batctl: Add throughput_override setting command
5 B.A.T.M.A.N. V introduced a hard interface specific setting called
6 throughput. It defines the throughput value to be used by B.A.T.M.A.N. V
7 when estimating the link throughput using this interface. If the value is
8 set to 0 then batman-adv will try to estimate the throughput by itself.
10 Signed-off-by: Sven Eckelmann <sven@narfation.org>
12 Forwarded: https://patchwork.open-mesh.org/patch/17950/
14 diff --git a/Makefile b/Makefile
15 index f071da20f866bff6c162d697d2e43fa9d68ee08d..e3747a2a28eb34323e34a1e22f5507dd1d7cd0f6 100755
18 @@ -67,6 +67,7 @@ $(eval $(call add_command,ping,y))
19 $(eval $(call add_command,routing_algo,y))
20 $(eval $(call add_command,statistics,y))
21 $(eval $(call add_command,tcpdump,y))
22 +$(eval $(call add_command,throughput_override,y))
23 $(eval $(call add_command,throughputmeter,y))
24 $(eval $(call add_command,traceroute,y))
25 $(eval $(call add_command,transglobal,y))
26 diff --git a/README.rst b/README.rst
27 index 92983aa6030e2a890283bca448b9203cd4d56b51..128f539852fa085d023fb6d26ae436e76b617bb6 100644
30 @@ -402,6 +402,23 @@ Example::
34 +batctl throughput override
35 +==========================
37 +display or modify the throughput override in kbit/s for hard interface
41 + batctl hardif $hardif throughput_override|to [kbit]
45 + $ batctl hardif eth0 throughput_override 15000
46 + $ batctl hardif eth0 throughput_override 15mbit
47 + $ batctl hardif eth0 throughput_override
54 diff --git a/man/batctl.8 b/man/batctl.8
55 index 690da023fd1ac6f51915a9167e92030a650fe1bd..b8218963712bbf0cc9470459896fc904cd393748 100644
58 @@ -203,6 +203,12 @@ supported routing algorithms are displayed.
59 Otherwise the parameter is used to select the routing algorithm for the following
60 batX interface to be created.
62 +.IP "\fBhardif <hardif>\fP \fBthroughput_override|to\fP [\fBbandwidth\fP]\fP"
63 +If no parameter is given the current througput override is displayed otherwise
64 +the parameter is used to set the throughput override for the specified hard
66 +Just enter any number (optionally followed by "kbit" or "mbit").
68 .IP "\fBisolation_mark\fP|\fBmark\fP"
69 If no parameter is given the current isolation mark value is displayed.
70 Otherwise the parameter is used to set or unset the isolation mark used by the
71 diff --git a/throughput_override.c b/throughput_override.c
73 index 0000000000000000000000000000000000000000..28a6588b9417cca213ebde3545a3eb425592ad89
75 +++ b/throughput_override.c
77 +// SPDX-License-Identifier: GPL-2.0
78 +/* Copyright (C) 2009-2019 B.A.T.M.A.N. contributors:
80 + * Marek Lindner <mareklindner@neomailbox.ch>
82 + * License-Filename: LICENSES/preferred/GPL-2.0
90 +#include "functions.h"
94 +static struct throughput_override_data {
95 + uint32_t throughput_override;
96 +} throughput_override;
98 +static int parse_throughput_override(struct state *state, int argc, char *argv[])
100 + struct settings_data *settings = state->cmd->arg;
101 + struct throughput_override_data *data = settings->data;
105 + fprintf(stderr, "Error - incorrect number of arguments (expected 1)\n");
109 + ret = parse_throughput(argv[1], "throughput override",
110 + &data->throughput_override);
117 +static int print_throughput_override(struct nl_msg *msg, void *arg)
119 + struct nlattr *attrs[BATADV_ATTR_MAX + 1];
120 + struct nlmsghdr *nlh = nlmsg_hdr(msg);
121 + struct genlmsghdr *ghdr;
125 + if (!genlmsg_valid_hdr(nlh, 0))
128 + ghdr = nlmsg_data(nlh);
130 + if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0),
131 + genlmsg_len(ghdr), batadv_netlink_policy)) {
135 + if (!attrs[BATADV_ATTR_THROUGHPUT_OVERRIDE])
138 + mbit = nla_get_u32(attrs[BATADV_ATTR_THROUGHPUT_OVERRIDE]);
139 + printf("%u.%u MBit\n", mbit / 10, mbit % 10);
145 +static int get_attrs_elp_isolation(struct nl_msg *msg, void *arg)
147 + struct state *state = arg;
149 + nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, state->hif);
154 +static int get_throughput_override(struct state *state)
156 + return sys_simple_nlquery(state, BATADV_CMD_GET_HARDIF,
157 + get_attrs_elp_isolation, print_throughput_override);
160 +static int set_attrs_throughput_override(struct nl_msg *msg, void *arg)
162 + struct state *state = arg;
163 + struct settings_data *settings = state->cmd->arg;
164 + struct throughput_override_data *data = settings->data;
166 + nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, state->hif);
167 + nla_put_u32(msg, BATADV_ATTR_THROUGHPUT_OVERRIDE, data->throughput_override);
172 +static int set_throughput_override(struct state *state)
174 + return sys_simple_nlquery(state, BATADV_CMD_SET_HARDIF,
175 + set_attrs_throughput_override, NULL);
178 +static struct settings_data batctl_settings_throughput_override = {
179 + .sysfs_name = "throughput_override",
180 + .data = &throughput_override,
181 + .parse = parse_throughput_override,
182 + .netlink_get = get_throughput_override,
183 + .netlink_set = set_throughput_override,
186 +COMMAND_NAMED(SUBCOMMAND_HIF, throughput_override, "to", handle_sys_setting,
187 + COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK,
188 + &batctl_settings_throughput_override,
189 + "[mbit] \tdisplay or modify throughput_override setting");