batctl: Add vid support and hardif settings
cover batctl: Add vid support and hardif settings
Hi,
I've asked a quite while back for some ideas regarding the support for hard interface settings in batctl [1]. But I got no feedback at all. So I've decided to just implement the first option and use it as chance to improve the vlan settings.
vlan settings
=============
The requirement to have a VLAN master device on top of the batadv mesh interface is artificially limiting the capabilities of batctl. Not all master devices in linux which register a VLAN are from type "vlan" and are only registering a single VLAN.
For example VLAN aware bridges can create multiple VLANs. These require that the VLAN is identified using the VID and not the vlan device.
It is now possible to specify the vlan using:
$ batctl vlan bat0.8 ap_isolation enable $ batctl -m bat0 vid 8 ap_isolation enable
hardif settings
===============
The infrastructure for the new vlan/vid prefix of commands can now be used to introduce another prefix: "hardif".
B.A.T.M.A.N. V introduced two additional settings which are hard (slave) interface specific. These can can finally be implemented in batctl. This will allow to change/read these settings when sysfs support is not enabled in the kernel.
$ batctl hardif eth0 throughput_override 15mbit $ batctl hardif eth0 elp_interval
Kind regards,
Sven
[1] https://www.open-mesh.org/issues/373
Sven Eckelmann (4):
batctl: Make vlan setting explicit
batctl: Integrate hardif setting framework
batctl: Add elp_interval setting command
batctl: Add throughput_override setting command
Makefile | 2 + README.rst | 33 +++++++++ ap_isolation.c | 5 ++ elp_interval.c | 111 +++++++++++++++++++++++++++++ main.c | 160 +++++++++++++++++++++++++++++++++++------- main.h | 10 ++- man/batctl.8 | 12 +++- sys.c | 57 ++++++++++++--- sys.h | 5 +- throughput_override.c | 113 +++++++++++++++++++++++++++++ 10 files changed, 470 insertions(+), 38 deletions(-) create mode 100644 elp_interval.c create mode 100644 throughput_override.c
Signature · 1 line
2.20.1
PATCH 1/4 batctl: Make vlan setting explicit
The requirement to have a VLAN master device on top of the batadv mesh interface is artificially limiting the capabilities of batctl. Not all master devices in linux which register a VLAN are from type "vlan" and are only registering a single VLAN.
For example VLAN aware bridges can create multiple VLANs. These require that the VLAN is identified using the VID and not the vlan device.
--- ap_isolation.c | 5 ++ main.c | 133 ++++++++++++++++++++++++++++++++++++++++--------- main.h | 7 +-- man/batctl.8 | 2 +- sys.c | 32 ++++++++++-- 5 files changed, 148 insertions(+), 31 deletions(-)
ap_isolation.c +5 -0
@@ -81,3 +81,8 @@ COMMAND_NAMED(SUBCOMMAND, ap_isolation, "ap", handle_sys_setting,COMMAND_FLAG_MESH_IFACE |COMMAND_FLAG_NETLINK , &batctl_settings_ap_isolation, "[0|1] \tdisplay or modify ap_isolation setting"); + +COMMAND_NAMED (SUBCOMMAND_VID , ap_isolation,"ap" , handle_sys_setting, +COMMAND_FLAG_MESH_IFACE |COMMAND_FLAG_NETLINK , + &batctl_settings_ap_isolation, +"[0|1] \tdisplay or modify ap_isolation setting for vlan device or id" );
main.c +109 -24
197 lines not on this page · raw message
main.h +4 -3
@@ -58,6 +58,7 @@ enum command_flags {enum command_type {SUBCOMMAND , +SUBCOMMAND_VID ,DEBUGTABLE , };
@@ -84,7 +85,7 @@ struct command { };#define COMMAND_NAMED (_type, _name, _abbr, _handler, _flags, _arg, _usage) \ - static const struct command command_ ## _name = { \ + static const struct command command_ ## _name ## _ ## _type = { \ .type = (_type), \ .name = (#_name), \ .abbr = _abbr, \
@@ -93,8 +94,8 @@ struct command { .arg = (_arg), \ .usage = (_usage), \ }; \ - static const struct command *__command_ ## _name \ - __attribute__((__used__)) __attribute__ ((__section__ ("__command"))) = &command_ ## _name + static const struct command *__command_ ## _name ## _ ## _type \ + __attribute__((__used__)) __attribute__ ((__section__ ("__command"))) = &command_ ## _name ## _ ## _type#define COMMAND (_type, _handler, _abbr, _flags, _arg, _usage) \ COMMAND_NAMED(_type, _handler, _abbr, _handler, _flags, _arg, _usage)
man/batctl.8 +1 -1
@@ -68,7 +68,7 @@ free all attached interfaces and remove batman-adv interface. If no parameter is given the current originator interval setting is displayed otherwise the parameter is used to set the originator interval. The interval is in units of milliseconds. .br -.IP "\fBap_isolation\fP|\fBap\fP [\fB0\fP|\fB1\fP]" +.IP "[\fBvlan <vdev>\fP|\fBvid <vid>\fP] \fBap_isolation\fP|\fBap\fP [\fB0\fP|\fB1\fP]" If no parameter is given the current ap isolation setting is displayed. Otherwise the parameter is used to enable or disable ap isolation. This command can be used in conjunction with "\-m" option to target per VLAN configurations. .br
sys.c +29 -3
@@ -141,9 +141,35 @@ 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->usage :"" ); +const char *default_prefixes[] = { +"" , +NULL , + }; +const char *vlan_prefixes[] = { +"vlan <vdev> " , +"vid <vid> " , +NULL , + }; +const char *linestart ="Usage:" ; +const char **prefixes; +const char **prefix; + +switch (state->cmd->type) { +case SUBCOMMAND_VID : + prefixes = vlan_prefixes; +break ; +default : + prefixes = default_prefixes; +break ; + } + +for (prefix = &prefixes[0 ]; *prefix; prefix++) { +fprintf (stderr,"%s batctl [options] %s%s|%s [parameters] %s\n" , + linestart, *prefix, state->cmd->name, state->cmd->abbr, + state->cmd->usage ? state->cmd->usage :"" ); + + linestart =" " ; + }fprintf (stderr,"parameters:\n" );fprintf (stderr," \t -h print this help\n" );
Signature · 1 line
2.20.1
PATCH 2/4 batctl: Integrate hardif setting framework
In reply to Sven Eckelmannbatctl currently supports settings which are either mesh interface or vlan specific. But B.A.T.M.A.N. V introduced two additional settings which are hard (slave) interface specific.
To support these, an additional command prefix called hardif is implemented for some sysfs commands:
$ batctl -m bat0 hardif eth0 ...
--- main.c | 29 ++++++++++++++++++++++++++++- main.h | 3 +++ sys.c | 25 ++++++++++++++++++++----- sys.h | 5 +++-- 4 files changed, 54 insertions(+), 8 deletions(-)
main.c +28 -1
@@ -35,7 +35,8 @@ static void print_usage(void) { .label = "commands:\n", .types = BIT(SUBCOMMAND) | - BIT(SUBCOMMAND_VID), + BIT(SUBCOMMAND_VID) | + BIT(SUBCOMMAND_HIF), }, { .label = "debug tables: \tdisplay the corresponding debug table\n",
@@ -51,6 +52,10 @@ static void print_usage(void)"vid <vid> " , NULL, }; +const char *hardif_prefixes[] = { +"hardif <netdev> " , +NULL , + };const struct command **p;const char **prefixes;const char **prefix;
@@ -81,6 +86,9 @@ static void print_usage(void)case SUBCOMMAND_VID : prefixes = vlan_prefixes;break ; +case SUBCOMMAND_HIF : + prefixes = hardif_prefixes; +break ;default : prefixes = default_prefixes;break ;
@@ -133,6 +141,12 @@ static const struct command *find_command(struct state *state, const char *name)if (state->vid <0 && cmd->type ==SUBCOMMAND_VID )continue ; +if (state->hif >0 && cmd->type !=SUBCOMMAND_HIF ) +continue ; + +if (state->hif ==0 && cmd->type ==SUBCOMMAND_HIF ) +continue ; +if (strcmp (cmd->name, name) ==0 )return cmd;
@@ -180,6 +194,18 @@ static int parse_dev_args(struct state *state, int argc, char *argv[]) state->arg_iface = argv[1 ];translate_mesh_iface (state); +return 2 ; + }else if (strcmp (argv[0 ],"hardif" ) ==0 ) { + state->hif =if_nametoindex (argv[1 ]); +if (state->hif ==0 ) { +fprintf (stderr,"Error - hard interface not found\n" ); +return -ENODEV ; + } + +snprintf (state->hard_iface,sizeof (state->hard_iface),"%s" , + argv[1 ]); + +translate_mesh_iface (state);return 2 ; }else {/* parse vlan as part of -m parameter */
@@ -193,6 +219,7 @@ int main(int argc, char **argv)const struct command *cmd;struct state state = { .arg_iface = mesh_dfl_iface, + .hif =0 , .cmd =NULL , };int dev_arguments;
main.h +3 -0
@@ -59,6 +59,7 @@ enum command_flags {enum command_type {SUBCOMMAND ,SUBCOMMAND_VID , +SUBCOMMAND_HIF ,DEBUGTABLE , };
@@ -66,6 +67,8 @@ struct state {char *arg_iface;char mesh_iface[IF_NAMESIZE ];unsigned int mesh_ifindex; +char hard_iface[IF_NAMESIZE ]; +unsigned int hif;int vid;const struct command *cmd;
sys.c +20 -5
@@ -150,6 +150,10 @@ static void settings_usage(struct state *state)"vid <vid> " , NULL, }; +const char *hardif_prefixes[] = { +"hardif <netdev> " , +NULL , + };const char *linestart ="Usage:" ;const char **prefixes;const char **prefix;
@@ -158,6 +162,9 @@ static void settings_usage(struct state *state)case SUBCOMMAND_VID : prefixes = vlan_prefixes;break ; +case SUBCOMMAND_HIF : + prefixes = hardif_prefixes; +break ;default : prefixes = default_prefixes;break ;
@@ -259,15 +266,23 @@ int handle_sys_setting(struct state *state, int argc, char **argv)return EXIT_FAILURE ; } -/* if the specified interface is a VLAN then change the path to point -* to the proper "vlan%{vid}" subfolder in the sysfs tree. -*/ -if (state->vid >=0 ) +if (state->hif >0 ) { +/* if a hard interface was specified then change the path to +* point to the proper ${hardif}/batman-adv path in the sysfs +* tree. +*/ +snprintf (path_buff,PATH_BUFF_LEN ,SYS_HARDIF_PATH , + state->hard_iface); + }else if (state->vid >=0 ) { +/* if the specified interface is a VLAN then change the path to +* point to the proper "vlan%{vid}" subfolder in the sysfs tree. +*/ snprintf (path_buff,PATH_BUFF_LEN ,SYS_VLAN_PATH , state->mesh_iface, state->vid); -else + }else {snprintf (path_buff,PATH_BUFF_LEN ,SYS_BATIF_PATH_FMT , state->mesh_iface); + }if (argc ==1 ) { res =sys_read_setting (state, path_buff, settings->sysfs_name);
sys.h +3 -2
@@ -21,8 +21,9 @@#define SYS_BATIF_PATH_FMT "/sys/class/net/%s/mesh/"#define SYS_IFACE_PATH "/sys/class/net"#define SYS_IFACE_DIR SYS_IFACE_PATH"/%s/" -#define SYS_MESH_IFACE_FMT SYS_IFACE_PATH"/%s/batman_adv/mesh_iface" -#define SYS_IFACE_STATUS_FMT SYS_IFACE_PATH"/%s/batman_adv/iface_status" +#define SYS_HARDIF_PATH SYS_IFACE_DIR "batman_adv/" +#define SYS_MESH_IFACE_FMT SYS_HARDIF_PATH "mesh_iface" +#define SYS_IFACE_STATUS_FMT SYS_HARDIF_PATH "iface_status"#define SYS_VLAN_PATH SYS_IFACE_PATH"/%s/mesh/vlan%d/"#define SYS_ROUTING_ALGO_FMT SYS_IFACE_PATH"/%s/mesh/routing_algo"#define VLAN_ID_MAX_LEN 4
Signature · 1 line
2.20.1
Re: [PATCH 2/4] batctl: Integrate hardif setting framework
Quoted 11 lines · Sven Eckelmann
batctl currently supports settings which are either mesh interface or vlan specific. But B.A.T.M.A.N. V introduced two additional settings which are hard (slave) interface specific.
To support these, an additional command prefix called hardif is implemented for some sysfs commands:
$ batctl -m bat0 hardif eth0 ...Signed-off-by Sven Eckelmann <[email protected]>---
Three thoughts/questions:
Currently we do not allow adding a hard-interface to two meshes, right? So the "-m bat0" here is redundant?
Have we used the terminology "hard interface" in UI and documentation before? Maybe it's just me, but I'm wondering whether the terms "soft interface" and "hard interface" might be a bit confusing to users, as these days people not only add hardware interfaces but also virtual ones. And these terms are not used in other projects (afaik). Maybe just stick to the more commonly used term "slave interface" and keep "hard" and "soft" interface as internal?
I'm wondering how it would look like if we were having settings both applicable to a soft and hard interface. What about using a "-s <slave-iface>", similar to the "-m <mesh-iface>" instead of the "hardif" command prefix? So that you could do things like:
$ batctl [-m <mesh-iface>|-s <slave-iface>] multicast_fanout <int>
in the future, for instance.
Regards, Linus
Re: [PATCH 2/4] batctl: Integrate hardif setting framework
Quoted 10 lines · On Sunday, 16 June 2019 16:53:16 CEST Linus Lüssing wrote:
Quoted 9 lines · Sven Eckelmann
batctl currently supports settings which are either mesh interface or vlan specific. But B.A.T.M.A.N. V introduced two additional settings which are hard (slave) interface specific.
To support these, an additional command prefix called hardif is implemented for some sysfs commands:
$ batctl -m bat0 hardif eth0 ...
Quoted 7 lines
Quoted 2 lines
Signed-off-by Sven Eckelmann <[email protected]>---
Three thoughts/questions:
Currently we do not allow adding a hard-interface to two meshes, right? So the "-m bat0" here is redundant?
Yes and no. This is also the way how the netlink interface is addressing the device. But implementation wise - this should be rather easy. I've already added the code to query_rtnl_link_single a while back. See check_mesh_iface_ownership_netlink as an example.
So it is now a question of how many magic we want to implement at the beginning. We already had the problem that the old vlan selection logic (-m) could be used to run weird commands which you shouldn't be able to run that way. Because of this I would ask to deprecate the '-m' parameter in favor of an optional(?) meshif selector prefix. And show this selector prefix for vid and for all meshif specific commands.
Quoted 8 lines
Have we used the terminology "hard interface" in UI and documentation before? Maybe it's just me, but I'm wondering whether the terms "soft interface" and "hard interface" might be a bit confusing to users, as these days people not only add hardware interfaces but also virtual ones. And these terms are not used in other projects (afaik). Maybe just stick to the more commonly used term "slave interface" and keep "hard" and "soft" interface as internal?
We are using hardif for example in the OpenWrt config integration. And the netlink stuff is called this way. Also the event parser already print events out as "hardif" events (for hardif related events only of course).
And yes, this was then also used in the documentation.
Quoted 6 lines
I'm wondering how it would look like if we were having settings both applicable to a soft and hard interface. What about using a "-s <slave-iface>", similar to the "-m <mesh-iface>" instead of the "hardif" command prefix? So that you could do things like:
$ batctl [-m <mesh-iface>|-s <slave-iface>] multicast_fanout <int>
Just do it like you do it for ap_isolation - which is for both vlan and meshif:
batctl ap_isolation
batctl vid 1 ap_isolation
Using these selector prefixes instead of -parameter value things allows us to correctly filter the commands and to provide an overview of commands with the information for which object type it can be used. Something like the stuff we are doing for ap_isolation with this patchset:
ap_isolation|ap [0|1] display or modify ap_isolation setting
vlan <vdev> ap_isolation|ap [0|1] display or modify ap_isolation setting for vlan device or id
vid <vid> ap_isolation|ap [0|1] display or modify ap_isolation setting for vlan device or idAnd I tend to have problems with -parameters when the order is too important and not really clear. For example following would work:
batctl -m bat0 ping 01:23:45:67:89:af
But not following:
batctl ping -m bat0 01:23:45:67:89:af
While you can learn to handle this correctly, it seems to more intuitive to have it tree structured from the start. Simply to make it clear on what you are operating now. Something more like:
[meshif <dev>] aggregation|ag [0|1] display or modify aggregation setting
[meshif <dev>] ap_isolation|ap [0|1] display or modify ap_isolation setting
vlan <vdev> ap_isolation|ap [0|1] display or modify ap_isolation setting for vlan device or id
[meshif <dev>] vid <vid> ap_isolation|ap [0|1] display or modify ap_isolation setting for vlan device or id
[meshif <dev>] bonding|b [0|1] display or modify bonding setting
[meshif <dev>] bridge_loop_avoidance|bl [0|1] display or modify bridge_loop_avoidance setting
[meshif <dev>] distributed_arp_table|dat [0|1] display or modify distributed_arp_table setting
hardif <netdev> elp_interval|et [interval] display or modify elp_interval setting
event|e display events from batman-adv
[meshif <dev>] fragmentation|f [0|1] display or modify fragmentation setting
[meshif <dev>] gw_mode|gw [mode] display or modify the gateway mode
[meshif <dev>] hop_penalty|hp [penalty] display or modify hop_penalty setting
[meshif <dev>] interface|if [add|del iface(s)] display or modify the interface settings
[meshif <dev>] isolation_mark|mark [mark] display or modify isolation_mark setting
[meshif <dev>] loglevel|ll [level] display or modify the log level
[meshif <dev>] multicast_fanout|mo [fanout] display or modify multicast_fanout setting
[meshif <dev>] multicast_forceflood|mff [0|1] display or modify multicast_forceflood setting
[meshif <dev>] network_coding|nc [0|1] display or modify network_coding setting
[meshif <dev>] orig_interval|it [interval] display or modify orig_interval setting
[meshif <dev>] ping|p <destination> ping another batman adv host via layer 2
routing_algo|ra [mode] display or modify the routing algorithm
[meshif <dev>] statistics|s print mesh statistics
[meshif <dev>] tcpdump|td <interface> tcpdump layer 2 traffic on the given interface
hardif <netdev> throughput_override|to [mbit] display or modify throughput_override setting
[meshif <dev>] throughputmeter|tp <destination> start a throughput measurement
[meshif <dev>] traceroute|tr <destination> traceroute another batman adv host via layer 2
[meshif <dev>] translate|t <destination> translate a destination to the originator responsible for itKind regards,
Sven
PATCH 3/4 batctl: Add elp_interval setting command
In reply to Sven EckelmannB.A.T.M.A.N. V introduced a hard interface specific setting called elp_interval. It defines the interval in milliseconds in which batman-adv emits probing packets for neighbor sensing (ELP).
--- Makefile | 1 + README.rst | 16 +++++++ elp_interval.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++++ man/batctl.8 | 4 ++ 4 files changed, 132 insertions(+) create mode 100644 elp_interval.c
Makefile +1 -0
@@ -45,6 +45,7 @@ $(eval $(call add_command,bridge_loop_avoidance,y)) $(eval $(call add_command,claimtable,y)) $(eval $(call add_command,dat_cache,y)) $(eval $(call add_command,distributed_arp_table,y)) +$(eval $(call add_command,elp_interval,y)) $(eval $(call add_command,event,y)) $(eval $(call add_command,fragmentation,y)) $(eval $(call add_command,gateways,y))
README.rst +16 -0
@@ -386,6 +386,22 @@ Example:: 1000 +batctl elp interval +=================== + +display or modify the elp interval in ms for hard interface + +Usage:: + + batctl hardif $hardif elp_interval|et [interval] + +Example:: + + $ batctl hardif eth0 elp_interval 200 + $ batctl hardif eth0 elp_interval + 200 + + batctl loglevel ===============
elp_interval.c new file +111 -0
111 lines not on this page · raw message
man/batctl.8 +4 -0
@@ -93,6 +93,10 @@ the bonding mode. batctl will monitor for events from the netlink kernel interface of batman-adv. The local timestamp of the event will be printed when parameter \fB\-t\fP is specified. Parameter \fB\-r\fP will do the same but with relative timestamps. .br +.IP "\fBhardif <hardif>\fP \fBelp_interval\fP|\fBet\fP [\fBinterval\fP]" +If no parameter is given the current ELP interval setting of the hard interface is displayed otherwise the parameter is used to set the +ELP interval. The interval is in units of milliseconds. +.br .IP "\fBfragmentation\fP|\fBf\fP [\fB0\fP|\fB1\fP]" If no parameter is given the current fragmentation mode setting is displayed. Otherwise the parameter is used to enable or disable fragmentation.
Signature · 1 line
2.20.1
PATCH 4/4 batctl: Add throughput_override setting command
In reply to Sven EckelmannB.A.T.M.A.N. V introduced a hard interface specific setting called throughput. It defines the throughput value to be used by B.A.T.M.A.N. V when estimating the link throughput using this interface. If the value is set to 0 then batman-adv will try to estimate the throughput by itself.
--- Makefile | 1 + README.rst | 17 +++++++ man/batctl.8 | 6 +++ throughput_override.c | 113 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 137 insertions(+) create mode 100644 throughput_override.c
Makefile +1 -0
@@ -67,6 +67,7 @@ $(eval $(call add_command,ping,y)) $(eval $(call add_command,routing_algo,y)) $(eval $(call add_command,statistics,y)) $(eval $(call add_command,tcpdump,y)) +$(eval $(call add_command,throughput_override,y)) $(eval $(call add_command,throughputmeter,y)) $(eval $(call add_command,traceroute,y)) $(eval $(call add_command,transglobal,y))
README.rst +17 -0
@@ -402,6 +402,23 @@ Example:: 200 +batctl throughput override +========================== + +display or modify the throughput override in kbit/s for hard interface + +Usage:: + + batctl hardif $hardif throughput_override|to [kbit] + +Example:: + + $ batctl hardif eth0 throughput_override 15000 + $ batctl hardif eth0 throughput_override 15mbit + $ batctl hardif eth0 throughput_override + 15.0 MBit + + batctl loglevel ===============
man/batctl.8 +6 -0
@@ -203,6 +203,12 @@ supported routing algorithms are displayed. Otherwise the parameter is used to select the routing algorithm for the following batX interface to be created. .br +.IP "\fBhardif <hardif>\fP \fBthroughput_override|to\fP [\fBbandwidth\fP]\fP" +If no parameter is given the current througput override is displayed otherwise +the parameter is used to set the throughput override for the specified hard +interface. +Just enter any number (optionally followed by "kbit" or "mbit"). +.br .IP "\fBisolation_mark\fP|\fBmark\fP" If no parameter is given the current isolation mark value is displayed. Otherwise the parameter is used to set or unset the isolation mark used by the
throughput_override.c new file +113 -0
113 lines not on this page · raw message
Signature · 1 line
2.20.1