7982cef5d20e705869b7891c488965fec5ee2672
[feed/routing.git] / batctl / patches / 0004-batctl-Add-throughput_override-setting-command.patch
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
4
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.
9
10 Signed-off-by: Sven Eckelmann <sven@narfation.org>
11
12 Forwarded: https://patchwork.open-mesh.org/patch/17950/
13
14 diff --git a/Makefile b/Makefile
15 index f071da20f866bff6c162d697d2e43fa9d68ee08d..e3747a2a28eb34323e34a1e22f5507dd1d7cd0f6 100755
16 --- a/Makefile
17 +++ b/Makefile
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
28 --- a/README.rst
29 +++ b/README.rst
30 @@ -402,6 +402,23 @@ Example::
31 200
32
33
34 +batctl throughput override
35 +==========================
36 +
37 +display or modify the throughput override in kbit/s for hard interface
38 +
39 +Usage::
40 +
41 + batctl hardif $hardif throughput_override|to [kbit]
42 +
43 +Example::
44 +
45 + $ batctl hardif eth0 throughput_override 15000
46 + $ batctl hardif eth0 throughput_override 15mbit
47 + $ batctl hardif eth0 throughput_override
48 + 15.0 MBit
49 +
50 +
51 batctl loglevel
52 ===============
53
54 diff --git a/man/batctl.8 b/man/batctl.8
55 index 690da023fd1ac6f51915a9167e92030a650fe1bd..b8218963712bbf0cc9470459896fc904cd393748 100644
56 --- a/man/batctl.8
57 +++ b/man/batctl.8
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.
61 .br
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
65 +interface.
66 +Just enter any number (optionally followed by "kbit" or "mbit").
67 +.br
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
72 new file mode 100644
73 index 0000000000000000000000000000000000000000..28a6588b9417cca213ebde3545a3eb425592ad89
74 --- /dev/null
75 +++ b/throughput_override.c
76 @@ -0,0 +1,113 @@
77 +// SPDX-License-Identifier: GPL-2.0
78 +/* Copyright (C) 2009-2019 B.A.T.M.A.N. contributors:
79 + *
80 + * Marek Lindner <mareklindner@neomailbox.ch>
81 + *
82 + * License-Filename: LICENSES/preferred/GPL-2.0
83 + */
84 +
85 +#include <errno.h>
86 +#include <stddef.h>
87 +#include <stdint.h>
88 +#include <string.h>
89 +
90 +#include "functions.h"
91 +#include "main.h"
92 +#include "sys.h"
93 +
94 +static struct throughput_override_data {
95 + uint32_t throughput_override;
96 +} throughput_override;
97 +
98 +static int parse_throughput_override(struct state *state, int argc, char *argv[])
99 +{
100 + struct settings_data *settings = state->cmd->arg;
101 + struct throughput_override_data *data = settings->data;
102 + bool ret;
103 +
104 + if (argc != 2) {
105 + fprintf(stderr, "Error - incorrect number of arguments (expected 1)\n");
106 + return -EINVAL;
107 + }
108 +
109 + ret = parse_throughput(argv[1], "throughput override",
110 + &data->throughput_override);
111 + if (!ret)
112 + return -EINVAL;
113 +
114 + return 0;
115 +}
116 +
117 +static int print_throughput_override(struct nl_msg *msg, void *arg)
118 +{
119 + struct nlattr *attrs[BATADV_ATTR_MAX + 1];
120 + struct nlmsghdr *nlh = nlmsg_hdr(msg);
121 + struct genlmsghdr *ghdr;
122 + int *result = arg;
123 + uint32_t mbit;
124 +
125 + if (!genlmsg_valid_hdr(nlh, 0))
126 + return NL_OK;
127 +
128 + ghdr = nlmsg_data(nlh);
129 +
130 + if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0),
131 + genlmsg_len(ghdr), batadv_netlink_policy)) {
132 + return NL_OK;
133 + }
134 +
135 + if (!attrs[BATADV_ATTR_THROUGHPUT_OVERRIDE])
136 + return NL_OK;
137 +
138 + mbit = nla_get_u32(attrs[BATADV_ATTR_THROUGHPUT_OVERRIDE]);
139 + printf("%u.%u MBit\n", mbit / 10, mbit % 10);
140 +
141 + *result = 0;
142 + return NL_STOP;
143 +}
144 +
145 +static int get_attrs_elp_isolation(struct nl_msg *msg, void *arg)
146 +{
147 + struct state *state = arg;
148 +
149 + nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, state->hif);
150 +
151 + return 0;
152 +}
153 +
154 +static int get_throughput_override(struct state *state)
155 +{
156 + return sys_simple_nlquery(state, BATADV_CMD_GET_HARDIF,
157 + get_attrs_elp_isolation, print_throughput_override);
158 +}
159 +
160 +static int set_attrs_throughput_override(struct nl_msg *msg, void *arg)
161 +{
162 + struct state *state = arg;
163 + struct settings_data *settings = state->cmd->arg;
164 + struct throughput_override_data *data = settings->data;
165 +
166 + nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, state->hif);
167 + nla_put_u32(msg, BATADV_ATTR_THROUGHPUT_OVERRIDE, data->throughput_override);
168 +
169 + return 0;
170 +}
171 +
172 +static int set_throughput_override(struct state *state)
173 +{
174 + return sys_simple_nlquery(state, BATADV_CMD_SET_HARDIF,
175 + set_attrs_throughput_override, NULL);
176 +}
177 +
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,
184 +};
185 +
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");