batctl: Add vid support and hardif settings
v3 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]. The current consensus seems to be that a more iw-like interface is prefered.
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 meshif 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
Changes
=======
v3
--
* drop prefix "dev" and "slave"
v2
--
* replaced (while still being compatible) -m option with "meshif"/"dev" prefix
* added alternative "slave" for "hardif" prefix
* automatically detect meshif for "hardif"/"slave"
* introduced enum selector_prefix to make code to select correct subcommands/code paths better readable
* add helper to automatically guess the type of netdev to allow omission of meshif/slave/vlan/... in some situations
v1
--
* initial version
[1] https://www.open-mesh.org/issues/373
Kind regards,
Sven
Sven Eckelmann (6):
batctl: Make vlan setting explicit
batctl: Integrate hardif setting framework
batctl: Add elp_interval setting command
batctl: Add throughput_override setting command
batctl: Replace '-m meshif' option with selector prefix
batctl: Allow to omit explicit prefix name
Makefile | 2 + README.rst | 33 +++++ aggregation.c | 2 +- ap_isolation.c | 15 ++- bonding.c | 2 +- bridge_loop_avoidance.c | 2 +- distributed_arp_table.c | 2 +- elp_interval.c | 111 ++++++++++++++++ fragmentation.c | 2 +- functions.c | 119 +++++++++++++++--- functions.h | 8 +- gw_mode.c | 2 +- hop_penalty.c | 2 +- interface.c | 2 +- isolation_mark.c | 2 +- loglevel.c | 2 +- main.c | 271 ++++++++++++++++++++++++++++++++++++---- main.h | 23 +++- man/batctl.8 | 60 +++++---- multicast_fanout.c | 2 +- multicast_forceflood.c | 2 +- multicast_mode.c | 2 +- network_coding.c | 2 +- orig_interval.c | 2 +- ping.c | 2 +- statistics.c | 2 +- sys.c | 73 +++++++++-- sys.h | 5 +- throughput_override.c | 113 +++++++++++++++++ throughputmeter.c | 2 +- traceroute.c | 2 +- translate.c | 2 +- 32 files changed, 770 insertions(+), 103 deletions(-) create mode 100644 elp_interval.c create mode 100644 throughput_override.c
Signature · 1 line
2.20.1
PATCH v3 1/6 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 | 13 +++- functions.c | 61 ++++++++++++--- functions.h | 4 +- main.c | 200 +++++++++++++++++++++++++++++++++++++++++++------ main.h | 13 +++- man/batctl.8 | 8 +- sys.c | 50 ++++++++++--- 7 files changed, 294 insertions(+), 55 deletions(-)
ap_isolation.c +9 -4
@@ -28,7 +28,7 @@ static int get_attrs_ap_isolation(struct nl_msg *msg, void *arg) {struct state *state = arg; -if (state->vid >=0 ) +if (state->selector ==SP_VLAN )nla_put_u16 (msg,BATADV_ATTR_VLANID , state->vid);return 0 ;
@@ -38,7 +38,7 @@ static int get_ap_isolation(struct state *state) {enum batadv_nl_commands nl_cmd =BATADV_CMD_SET_MESH ; -if (state->vid >=0 ) +if (state->selector ==SP_VLAN ) nl_cmd =BATADV_CMD_GET_VLAN ; return sys_simple_nlquery(state, nl_cmd, get_attrs_ap_isolation,
@@ -53,7 +53,7 @@ static int set_attrs_ap_isolation(struct nl_msg *msg, void *arg)nla_put_u8 (msg,BATADV_ATTR_AP_ISOLATION_ENABLED , data->val); -if (state->vid >=0 ) +if (state->selector ==SP_VLAN )nla_put_u16 (msg,BATADV_ATTR_VLANID , state->vid);return 0 ;
@@ -63,7 +63,7 @@ static int set_ap_isolation(struct state *state) {enum batadv_nl_commands nl_cmd =BATADV_CMD_SET_MESH ; -if (state->vid >=0 ) +if (state->selector ==SP_VLAN ) nl_cmd =BATADV_CMD_SET_VLAN ;return sys_simple_nlquery (state, nl_cmd, set_attrs_ap_isolation,NULL );
@@ -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" );
functions.c +50 -11
91 lines not on this page · raw message
functions.h +3 -1
@@ -50,7 +50,9 @@ struct ether_addr *translate_mac(const char *mesh_iface,struct ether_addr *resolve_mac (const char *asc);int query_rtnl_link (int ifindex,nl_recvmsg_msg_cb_t func,void *arg);int netlink_simple_request (struct nl_msg *msg); -int translate_mesh_iface (struct state *state); +int translate_mesh_iface_vlan (struct state *state,const char *vlandev); +int translate_vlan_iface (struct state *state,const char *vlandev); +int translate_vid (struct state *state,const char *vidstr);int get_algoname (const char *mesh_iface,char *algoname,size_t algoname_len);int check_mesh_iface (struct state *state);int check_mesh_iface_ownership (struct state *state,char *hard_iface);
main.c +176 -24
265 lines not on this page · raw message
main.h +10 -3
@@ -56,13 +56,20 @@ enum command_flags { COMMAND_FLAG_INVERSE = BIT(2), }; +enum selector_prefix { +SP_NONE_OR_MESHIF , +SP_VLAN , +}; +enum command_type {SUBCOMMAND , +SUBCOMMAND_VID ,DEBUGTABLE , };struct state {char *arg_iface; +enum selector_prefix selector;char mesh_iface[IF_NAMESIZE ];unsigned int mesh_ifindex;int vid;
@@ -84,7 +91,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 +100,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 +6 -2
@@ -46,7 +46,7 @@ performances, is also included. .SH OPTIONS .TP .I \fBoptions: -\-m specify mesh interface or VLAN created on top of a mesh interface (default 'bat0') +\-m specify mesh interface (default 'bat0') .br \-h print general batctl help .br
@@ -70,7 +70,11 @@ originator interval. The interval is in units of milliseconds. .br .IP "\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. +disable ap isolation. +.br +.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 for the specified VLAN is displayed. Otherwise the parameter is used to enable or +disable ap isolation for the specified VLAN. .br .IP "\fBbridge_loop_avoidance\fP|\fBbl\fP [\fB0\fP|\fB1\fP]" If no parameter is given the current bridge loop avoidance setting is displayed. Otherwise the parameter is used to enable
sys.c +40 -10
64 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v3 2/6 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 hardif eth0 ...
--- functions.c | 22 ++++++++++++++++++++++ functions.h | 1 + main.c | 26 +++++++++++++++++++++++++- main.h | 8 +++++++- sys.c | 15 +++++++++++++++ sys.h | 5 +++-- 6 files changed, 73 insertions(+), 4 deletions(-)
functions.c +22 -0
@@ -998,6 +998,28 @@ int translate_vid(struct state *state, const char *vidstr)return 0 ; } +int translate_hard_iface (struct state *state,const char *hardif) +{ +struct rtnl_link_iface_data link_data; +unsigned int arg_ifindex; + + arg_ifindex =if_nametoindex (hardif); +if (arg_ifindex ==0 ) +return -ENODEV ; + +query_rtnl_link_single (arg_ifindex, &link_data); +if (!link_data.master_found) +return -ENOLINK ; + +if (!if_indextoname (link_data.master, state->mesh_iface)) +return -ENOLINK ; + + state->hif = arg_ifindex; + state->selector =SP_HARDIF ; + +return 0 ; +} +static int check_mesh_iface_netlink (struct state *state) {struct rtnl_link_iface_data link_data;
functions.h +1 -0
@@ -53,6 +53,7 @@ int netlink_simple_request(struct nl_msg *msg);int translate_mesh_iface_vlan (struct state *state,const char *vlandev);int translate_vlan_iface (struct state *state,const char *vlandev);int translate_vid (struct state *state,const char *vidstr); +int translate_hard_iface (struct state *state,const char *hardif);int get_algoname (const char *mesh_iface,char *algoname,size_t algoname_len);int check_mesh_iface (struct state *state);int check_mesh_iface_ownership (struct state *state,char *hard_iface);
main.c +25 -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 ;
@@ -153,6 +161,9 @@ static const struct command *find_command(struct state *state, const char *name)case SP_VLAN : types =BIT (SUBCOMMAND_VID );break ; +case SP_HARDIF : + types =BIT (SUBCOMMAND_HIF ); +break ;default :return NULL ; }
@@ -171,6 +182,9 @@ static int detect_selector_prefix(int argc, char *argv[],if (strcmp (argv[0 ],"vlan" ) ==0 ) { *selector =SP_VLAN ;return 2 ; + }else if (strcmp (argv[0 ],"hardif" ) ==0 ) { + *selector =SP_HARDIF ; +return 2 ; }return 0 ;
@@ -197,7 +211,17 @@ static int parse_meshif_args(struct state *state, int argc, char *argv[]) dev_arg, strerror(-ret));return ret; } +return parsed_args; +case SP_HARDIF : + ret =translate_hard_iface (state, dev_arg); +if (ret <0 ) { +fprintf (stderr,"Error - invalid hardif %s: %s\n" , + dev_arg,strerror (-ret)); +return ret; + } +snprintf (state->hard_iface,sizeof (state->hard_iface),"%s" , + dev_arg);return parsed_args;case SP_NONE_OR_MESHIF :/* not allowed - see detect_selector_prefix */
main.h +7 -1
@@ -59,11 +59,13 @@ enum command_flags {enum selector_prefix {SP_NONE_OR_MESHIF ,SP_VLAN , +SP_HARDIF , };enum command_type {SUBCOMMAND ,SUBCOMMAND_VID , +SUBCOMMAND_HIF ,DEBUGTABLE , };
@@ -72,7 +74,11 @@ struct state {enum selector_prefix selector;char mesh_iface[IF_NAMESIZE ];unsigned int mesh_ifindex; -int vid; +char hard_iface[IF_NAMESIZE ]; +union { +unsigned int hif; +int vid; + };const struct command *cmd;struct nl_sock *sock;
sys.c +15 -0
@@ -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 ;
@@ -271,6 +278,14 @@ int handle_sys_setting(struct state *state, int argc, char **argv)snprintf (path_buff,PATH_BUFF_LEN ,SYS_VLAN_PATH , state->mesh_iface, state->vid);break ; +case SP_HARDIF : +/* 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); +break ; }if (argc ==1 ) {
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
PATCH v3 3/6 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
@@ -97,6 +97,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 v3 4/6 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
@@ -207,6 +207,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
PATCH v3 5/6 batctl: Replace '-m meshif' option with selector prefix
In reply to Sven EckelmannThe '-m meshif' option doesn't follow the prefix style which is used for VLANs/hard interfaces. It is also not clear for a user which command understands the '-m' option and which is actually operating on a global/non-meshif specific scope. To clean this up, an additional command prefix called meshif is implemented:
$ batctl meshif bat0 ...
This can be omitted when it would be "meshif bat0". And when it is specified, all non-meshif specific subcommands will be rejected.
The old option '-m meshif' option is still available to avoid breaking existing scripts. It will will show an error message but continues to work for now. Users of batctl should still transition to the new format.
--- aggregation.c | 2 +- ap_isolation.c | 2 +- bonding.c | 2 +- bridge_loop_avoidance.c | 2 +- distributed_arp_table.c | 2 +- fragmentation.c | 2 +- gw_mode.c | 2 +- hop_penalty.c | 2 +- interface.c | 2 +- isolation_mark.c | 2 +- loglevel.c | 2 +- main.c | 33 +++++++++++++++++++++++++------ main.h | 2 ++ man/batctl.8 | 44 ++++++++++++++++++++--------------------- multicast_fanout.c | 2 +- multicast_forceflood.c | 2 +- multicast_mode.c | 2 +- network_coding.c | 2 +- orig_interval.c | 2 +- ping.c | 2 +- statistics.c | 2 +- sys.c | 10 +++++++++- throughputmeter.c | 2 +- traceroute.c | 2 +- translate.c | 2 +- 25 files changed, 81 insertions(+), 50 deletions(-)
aggregation.c +1 -1
@@ -55,7 +55,7 @@ static struct settings_data batctl_settings_aggregation = { .netlink_set = set_aggregated_ogms, }; -COMMAND_NAMED (SUBCOMMAND , aggregation,"ag" , handle_sys_setting, +COMMAND_NAMED (SUBCOMMAND_MIF , aggregation,"ag" , handle_sys_setting,COMMAND_FLAG_MESH_IFACE |COMMAND_FLAG_NETLINK , &batctl_settings_aggregation,"[0|1] \tdisplay or modify aggregation setting" );
ap_isolation.c +1 -1
@@ -77,7 +77,7 @@ static struct settings_data batctl_settings_ap_isolation = { .netlink_set = set_ap_isolation, }; -COMMAND_NAMED (SUBCOMMAND , ap_isolation,"ap" , handle_sys_setting, +COMMAND_NAMED (SUBCOMMAND_MIF , 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" );
bonding.c +1 -1
@@ -54,7 +54,7 @@ static struct settings_data batctl_settings_bonding = { .netlink_set = set_bonding, }; -COMMAND_NAMED (SUBCOMMAND , bonding,"b" , handle_sys_setting, +COMMAND_NAMED (SUBCOMMAND_MIF , bonding,"b" , handle_sys_setting,COMMAND_FLAG_MESH_IFACE |COMMAND_FLAG_NETLINK , &batctl_settings_bonding,"[0|1] \tdisplay or modify bonding setting" );
bridge_loop_avoidance.c +1 -1
@@ -55,7 +55,7 @@ static struct settings_data batctl_settings_bridge_loop_avoidance = { .netlink_set = set_bridge_loop_avoidance, }; -COMMAND_NAMED (SUBCOMMAND , bridge_loop_avoidance,"bl" , handle_sys_setting, +COMMAND_NAMED (SUBCOMMAND_MIF , bridge_loop_avoidance,"bl" , handle_sys_setting,COMMAND_FLAG_MESH_IFACE |COMMAND_FLAG_NETLINK , &batctl_settings_bridge_loop_avoidance,"[0|1] \tdisplay or modify bridge_loop_avoidance setting" );
distributed_arp_table.c +1 -1
@@ -55,7 +55,7 @@ static struct settings_data batctl_settings_distributed_arp_table = { .netlink_set = set_distributed_arp_table, }; -COMMAND_NAMED (SUBCOMMAND , distributed_arp_table,"dat" , handle_sys_setting, +COMMAND_NAMED (SUBCOMMAND_MIF , distributed_arp_table,"dat" , handle_sys_setting,COMMAND_FLAG_MESH_IFACE |COMMAND_FLAG_NETLINK , &batctl_settings_distributed_arp_table,"[0|1] \tdisplay or modify distributed_arp_table setting" );
fragmentation.c +1 -1
@@ -55,7 +55,7 @@ static struct settings_data batctl_settings_fragmentation = { .netlink_set = set_fragmentation, }; -COMMAND_NAMED (SUBCOMMAND , fragmentation,"f" , handle_sys_setting, +COMMAND_NAMED (SUBCOMMAND_MIF , fragmentation,"f" , handle_sys_setting,COMMAND_FLAG_MESH_IFACE |COMMAND_FLAG_NETLINK , &batctl_settings_fragmentation,"[0|1] \tdisplay or modify fragmentation setting" );
gw_mode.c +1 -1
@@ -392,6 +392,6 @@ static int gw_mode(struct state *state, int argc, char **argv)return res; } -COMMAND (SUBCOMMAND , gw_mode,"gw" , +COMMAND (SUBCOMMAND_MIF , gw_mode,"gw" ,COMMAND_FLAG_MESH_IFACE |COMMAND_FLAG_NETLINK ,NULL ,"[mode] \tdisplay or modify the gateway mode" );
hop_penalty.c +1 -1
@@ -95,7 +95,7 @@ static struct settings_data batctl_settings_hop_penalty = { .netlink_set = set_hop_penalty, }; -COMMAND_NAMED (SUBCOMMAND , hop_penalty,"hp" , handle_sys_setting, +COMMAND_NAMED (SUBCOMMAND_MIF , hop_penalty,"hp" , handle_sys_setting,COMMAND_FLAG_MESH_IFACE |COMMAND_FLAG_NETLINK , &batctl_settings_hop_penalty,"[penalty] \tdisplay or modify hop_penalty setting" );
interface.c +1 -1
@@ -541,5 +541,5 @@ static int interface(struct state *state, int argc, char **argv)return EXIT_FAILURE ; } -COMMAND (SUBCOMMAND , interface,"if" ,0 ,NULL , +COMMAND (SUBCOMMAND_MIF , interface,"if" ,0 ,NULL ,"[add|del iface(s)]\tdisplay or modify the interface settings" );
isolation_mark.c +1 -1
@@ -134,7 +134,7 @@ static struct settings_data batctl_settings_isolation_mark = { .netlink_set = set_isolation_mark, }; -COMMAND_NAMED (SUBCOMMAND , isolation_mark,"mark" , handle_sys_setting, +COMMAND_NAMED (SUBCOMMAND_MIF , isolation_mark,"mark" , handle_sys_setting,COMMAND_FLAG_MESH_IFACE |COMMAND_FLAG_NETLINK , &batctl_settings_isolation_mark,"[mark] \tdisplay or modify isolation_mark setting" );
loglevel.c +1 -1
@@ -212,6 +212,6 @@ static int loglevel(struct state *state, int argc, char **argv)return res; } -COMMAND (SUBCOMMAND , loglevel,"ll" , +COMMAND (SUBCOMMAND_MIF , loglevel,"ll" ,COMMAND_FLAG_MESH_IFACE |COMMAND_FLAG_NETLINK ,NULL ,"[level] \tdisplay or modify the log level" );
main.c +27 -6
@@ -35,6 +35,7 @@ static void print_usage(void) { .label = "commands:\n", .types =BIT (SUBCOMMAND ) | +BIT (SUBCOMMAND_MIF ) |BIT (SUBCOMMAND_VID ) | BIT(SUBCOMMAND_HIF), },
@@ -47,9 +48,13 @@ static void print_usage(void)"" , NULL, }; +const char *meshif_prefixes[] = { +"meshif <netdev> " , +NULL , + };const char *vlan_prefixes[] = {"vlan <vdev> " , -"vid <vid> " , +"meshif <netdev> vid <vid> " ,NULL , }; const char *hardif_prefixes[] = {
@@ -64,7 +69,6 @@ static void print_usage(void)fprintf (stderr,"Usage: batctl [options] command|debug table [parameters]\n" );fprintf (stderr,"options:\n" ); -fprintf (stderr," \t-m mesh interface (default 'bat0')\n" );fprintf (stderr," \t-h print this help (or 'batctl <command|debug table> -h' for the parameter help)\n" );fprintf (stderr," \t-v print version\n" );
@@ -83,6 +87,10 @@ static void print_usage(void)continue ;switch (cmd->type) { +case DEBUGTABLE : +case SUBCOMMAND_MIF : + prefixes = meshif_prefixes; +break ;case SUBCOMMAND_VID : prefixes = vlan_prefixes;break ;
@@ -102,7 +110,7 @@ static void print_usage(void)snprintf (buf,sizeof (buf),"%s%s|%s" , *prefix, cmd->name, cmd->abbr); -fprintf (stderr," \t%-35s%s\n" , buf, +fprintf (stderr," \t%-43s%s\n" , buf, cmd->usage); } }
@@ -155,8 +163,11 @@ static const struct command *find_command(struct state *state, const char *name)switch (state->selector) {case SP_NONE_OR_MESHIF : - types =BIT (SUBCOMMAND ) | -BIT (DEBUGTABLE ); + types =BIT (SUBCOMMAND ); +/* fall through */ +case SP_MESHIF : + types |=BIT (SUBCOMMAND_MIF ) | +BIT (DEBUGTABLE );break ;case SP_VLAN : types =BIT (SUBCOMMAND_VID );
@@ -179,7 +190,10 @@ static int detect_selector_prefix(int argc, char *argv[],return -EINVAL ;/* only detect selector prefix which identifies meshif */ -if (strcmp (argv[0 ],"vlan" ) ==0 ) { +if (strcmp (argv[0 ],"meshif" ) ==0 ) { + *selector =SP_MESHIF ; +return 2 ; + }else if (strcmp (argv[0 ],"vlan" ) ==0 ) { *selector =SP_VLAN ;return 2 ; }else if (strcmp (argv[0 ],"hardif" ) ==0 ) {
@@ -204,6 +218,11 @@ static int parse_meshif_args(struct state *state, int argc, char *argv[]) dev_arg = argv[parsed_args -1 ];switch (selector) { +case SP_MESHIF : +snprintf (state->mesh_iface,sizeof (state->mesh_iface),"%s" , + dev_arg); + state->selector =SP_MESHIF ; +return parsed_args;case SP_VLAN : ret =translate_vlan_iface (state, dev_arg);if (ret <0 ) {
@@ -252,6 +271,7 @@ static int parse_dev_args(struct state *state, int argc, char *argv[])switch (state->selector) {case SP_NONE_OR_MESHIF : +case SP_MESHIF :/* continue below */ break ;default :
@@ -297,6 +317,7 @@ int main(int argc, char **argv) "Error - multiple mesh interfaces specified\n"); goto err; } +fprintf (stderr,"Warning - option -m was deprecated in will be removed in the future\n" ); state.arg_iface = argv[2 ];break ;
main.h +2 -0
@@ -58,12 +58,14 @@ enum command_flags {enum selector_prefix {SP_NONE_OR_MESHIF , +SP_MESHIF ,SP_VLAN ,SP_HARDIF , };enum command_type {SUBCOMMAND , +SUBCOMMAND_MIF ,SUBCOMMAND_VID ,SUBCOMMAND_HIF ,DEBUGTABLE ,
man/batctl.8 +22 -22
141 lines not on this page · raw message
multicast_fanout.c +1 -1
@@ -95,7 +95,7 @@ static struct settings_data batctl_settings_multicast_fanout = { .netlink_set = set_multicast_fanout, }; -COMMAND_NAMED (SUBCOMMAND , multicast_fanout,"mo" , handle_sys_setting, +COMMAND_NAMED (SUBCOMMAND_MIF , multicast_fanout,"mo" , handle_sys_setting,COMMAND_FLAG_MESH_IFACE |COMMAND_FLAG_NETLINK , &batctl_settings_multicast_fanout,"[fanout] \tdisplay or modify multicast_fanout setting" );
multicast_forceflood.c +1 -1
@@ -75,7 +75,7 @@ static struct settings_data batctl_settings_multicast_forceflood = { .netlink_set = set_multicast_forceflood, }; -COMMAND_NAMED (SUBCOMMAND , multicast_forceflood,"mff" , handle_sys_setting, +COMMAND_NAMED (SUBCOMMAND_MIF , multicast_forceflood,"mff" , handle_sys_setting,COMMAND_FLAG_MESH_IFACE |COMMAND_FLAG_NETLINK |COMMAND_FLAG_INVERSE , &batctl_settings_multicast_forceflood,"[0|1] \tdisplay or modify multicast_forceflood setting" );
multicast_mode.c +1 -1
@@ -75,6 +75,6 @@ static struct settings_data batctl_settings_multicast_mode = { .netlink_set = set_multicast_mode, }; -COMMAND_NAMED (SUBCOMMAND , multicast_mode,"mm" , handle_sys_setting, +COMMAND_NAMED (SUBCOMMAND_MIF , multicast_mode,"mm" , handle_sys_setting,COMMAND_FLAG_MESH_IFACE |COMMAND_FLAG_NETLINK , &batctl_settings_multicast_mode,NULL );
network_coding.c +1 -1
@@ -55,7 +55,7 @@ static struct settings_data batctl_settings_network_coding = { .netlink_set = set_network_coding, }; -COMMAND_NAMED (SUBCOMMAND , network_coding,"nc" , handle_sys_setting, +COMMAND_NAMED (SUBCOMMAND_MIF , network_coding,"nc" , handle_sys_setting,COMMAND_FLAG_MESH_IFACE |COMMAND_FLAG_NETLINK , &batctl_settings_network_coding,"[0|1] \tdisplay or modify network_coding setting" );
orig_interval.c +1 -1
@@ -95,7 +95,7 @@ static struct settings_data batctl_settings_orig_interval = { .netlink_set = set_orig_interval, }; -COMMAND_NAMED (SUBCOMMAND , orig_interval,"it" , handle_sys_setting, +COMMAND_NAMED (SUBCOMMAND_MIF , orig_interval,"it" , handle_sys_setting,COMMAND_FLAG_MESH_IFACE |COMMAND_FLAG_NETLINK , &batctl_settings_orig_interval,"[interval] \tdisplay or modify orig_interval setting" );
ping.c +1 -1
@@ -323,5 +323,5 @@ static int ping(struct state *state, int argc, char **argv)return ret; } -COMMAND (SUBCOMMAND , ping,"p" ,COMMAND_FLAG_MESH_IFACE ,NULL , +COMMAND (SUBCOMMAND_MIF , ping,"p" ,COMMAND_FLAG_MESH_IFACE ,NULL ,"<destination> \tping another batman adv host via layer 2" );
statistics.c +1 -1
@@ -112,5 +112,5 @@ static int statistics(struct state *state, int argc __maybe_unused,return ret; } -COMMAND (SUBCOMMAND , statistics,"s" ,COMMAND_FLAG_MESH_IFACE ,NULL , +COMMAND (SUBCOMMAND_MIF , statistics,"s" ,COMMAND_FLAG_MESH_IFACE ,NULL ," \tprint mesh statistics" );
sys.c +9 -1
@@ -145,9 +145,13 @@ static void settings_usage(struct state *state)"" , NULL, }; +const char *meshif_prefixes[] = { +"meshif <netdev> " , +NULL , + };const char *vlan_prefixes[] = {"vlan <vdev> " , -"vid <vid> " , +"meshif <netdev> vid <vid> " ,NULL , }; const char *hardif_prefixes[] = {
@@ -159,6 +163,9 @@ static void settings_usage(struct state *state)const char **prefix;switch (state->cmd->type) { +case SUBCOMMAND_MIF : + prefixes = meshif_prefixes; +break ;case SUBCOMMAND_VID : prefixes = vlan_prefixes;break ;
@@ -268,6 +275,7 @@ int handle_sys_setting(struct state *state, int argc, char **argv)switch (state->selector) {case SP_NONE_OR_MESHIF : +case SP_MESHIF :snprintf (path_buff,PATH_BUFF_LEN ,SYS_BATIF_PATH_FMT , state->mesh_iface);break ;
throughputmeter.c +1 -1
@@ -529,5 +529,5 @@ static int throughputmeter(struct state *state, int argc, char **argv)return ret; } -COMMAND (SUBCOMMAND , throughputmeter,"tp" ,COMMAND_FLAG_MESH_IFACE ,NULL , +COMMAND (SUBCOMMAND_MIF , throughputmeter,"tp" ,COMMAND_FLAG_MESH_IFACE ,NULL ,"<destination> \tstart a throughput measurement" );
traceroute.c +1 -1
@@ -209,5 +209,5 @@ static int traceroute(struct state *state, int argc, char **argv)return ret; } -COMMAND (SUBCOMMAND , traceroute,"tr" ,COMMAND_FLAG_MESH_IFACE ,NULL , +COMMAND (SUBCOMMAND_MIF , traceroute,"tr" ,COMMAND_FLAG_MESH_IFACE ,NULL ,"<destination> \ttraceroute another batman adv host via layer 2" );
translate.c +1 -1
@@ -64,5 +64,5 @@ static int translate(struct state *state, int argc, char **argv)return ret; } -COMMAND (SUBCOMMAND , translate,"t" ,COMMAND_FLAG_MESH_IFACE ,NULL , +COMMAND (SUBCOMMAND_MIF , translate,"t" ,COMMAND_FLAG_MESH_IFACE ,NULL ,"<destination> \ttranslate a destination to the originator responsible for it" );
Signature · 1 line
2.20.1
PATCH v3 6/6 batctl: Allow to omit explicit prefix name
In reply to Sven Eckelmannbatctl allows three types of netdev based prefixes
* meshif <netdev>
* vlan <vdev>
* hardif <netdev>
The first word is used to tell batctl that the netdev is expected to be of a specific type and all further information should be parsed in context of this specific type. This avoids ambiguity when parsing the command line information.
But there are various situations when there is no ambiguity at all. For all of them, following points are true:
* <netdev|vdev> exists * <netdev|vdev> has not the name of any existing batctl subcommand * <netdev|vdev> is not "vlan", "vid", "hardif" or "meshif"
In these situations, the first word can be omitted and batctl can guess the type automatically.
--- functions.c | 36 +++++++++++++++++++++++++++++++++--- functions.h | 3 +++ main.c | 28 +++++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 4 deletions(-)
functions.c +33 -3
@@ -1020,11 +1020,11 @@ int translate_hard_iface(struct state *state, const char *hardif)return 0 ; } -static int check_mesh_iface_netlink (struct state *state) +static int check_mesh_iface_netlink (unsigned int ifindex) {struct rtnl_link_iface_data link_data; -query_rtnl_link_single (state->mesh_ifindex, &link_data); +query_rtnl_link_single (ifindex, &link_data);if (!link_data.kind_found)return -1 ;
@@ -1034,6 +1034,36 @@ static int check_mesh_iface_netlink(struct state *state)return 0 ; } +int guess_netdev_type (const char *netdev,enum selector_prefix *type) +{ +struct rtnl_link_iface_data link_data; +unsigned int netdev_ifindex; + + netdev_ifindex =if_nametoindex (netdev); +if (netdev_ifindex ==0 ) +return -ENODEV ; + +query_rtnl_link_single (netdev_ifindex, &link_data); + +if (link_data.kind_found &&strcmp (link_data.kind,"batadv" ) ==0 ) { + *type =SP_MESHIF ; +return 0 ; + } + +if (link_data.master_found && +check_mesh_iface_netlink (link_data.master) >=0 ) { + *type =SP_HARDIF ; +return 0 ; + } + +if (link_data.kind_found &&strcmp (link_data.kind,"vlan" ) ==0 ) { + *type =SP_VLAN ; +return 0 ; + } + +return -EINVAL ; +} +static int check_mesh_iface_sysfs (struct state *state) {char path_buff[PATH_BUFF_LEN ];
@@ -1060,7 +1090,7 @@ int check_mesh_iface(struct state *state)if (state->mesh_ifindex ==0 )return -1 ; - ret =check_mesh_iface_netlink (state); + ret =check_mesh_iface_netlink (state->mesh_ifindex);if (ret ==0 )return ret;
functions.h +3 -0
@@ -16,6 +16,8 @@#include <stddef.h> #include <stdint.h> +#include "main.h" +/** * enum batadv_bandwidth_units - bandwidth unit types */
@@ -54,6 +56,7 @@ int translate_mesh_iface_vlan(struct state *state, const char *vlandev);int translate_vlan_iface (struct state *state,const char *vlandev);int translate_vid (struct state *state,const char *vidstr);int translate_hard_iface (struct state *state,const char *hardif); +int guess_netdev_type (const char *netdev,enum selector_prefix *type);int get_algoname (const char *mesh_iface,char *algoname,size_t algoname_len);int check_mesh_iface (struct state *state);int check_mesh_iface_ownership (struct state *state,char *hard_iface);
main.c +27 -1
@@ -204,6 +204,32 @@ static int detect_selector_prefix(int argc, char *argv[],return 0 ; } +static int guess_selector_prefix (int argc,char *argv[], +enum selector_prefix *selector) +{ +int ret; + +/* check if there is a direct hit with full prefix */ + ret =detect_selector_prefix (argc, argv, selector); +if (ret >0 ) +return ret; + +/* not enough remaining arguments to detect anything */ +if (argc <1 ) +return -EINVAL ; + +/* don't try to parse subcommand names as network interface */ +if (find_command_by_types (0xffffffff , argv[0 ])) +return -EEXIST ; + +/* check if it is a netdev - and if it exists, try to guess what kind */ + ret =guess_netdev_type (argv[0 ], selector); +if (ret <0 ) +return ret; + +return 1 ; +} +static int parse_meshif_args (struct state *state,int argc,char *argv[]) {enum selector_prefix selector;
@@ -211,7 +237,7 @@ static int parse_meshif_args(struct state *state, int argc, char *argv[])char *dev_arg;int ret; - parsed_args =detect_selector_prefix (argc, argv, &selector); + parsed_args =guess_selector_prefix (argc, argv, &selector);if (parsed_args <1 ) goto fallback_meshif_vlan;
Signature · 1 line
2.20.1