batctl: netlink restructuring, part 3
cover batctl: netlink restructuring, part 3
As mentioned earlier, the netlink config restructuring in batctl will be splitted in multiple steps. The first step was already merged and the RFC changes for the netlink interface in batman-adv were just posted.
Since it doesn't make sense to have a full implementation in batctl when the batman-adv part is not yet in a finished state. But it also is useless to have only the batman-adv RFC part without a userspace tool. The (by default disabled) config subcommand is (my) solution for this problem. It allows developers to play around with this interface and assign new values for specific keys and to read the current config state.
Make sure that you enable it during the build:
$ make clean; make CONFIG_config=y
Kind regards,
Sven
Sven Eckelmann (2):
batctl: Add generic netlink configuration subcommand
batctl: Add support for config mcast group in event monitor
Makefile | 1 + batman_adv.h | 55 ++++++ config.c | 542 +++++++++++++++++++++++++++++++++++++++++++++++++++ event.c | 100 ++++++++++ man/batctl.8 | 37 ++++ netlink.c | 3 + 6 files changed, 738 insertions(+) create mode 100644 config.c
Signature · 1 line
2.19.1
RFC 1/2 batctl: Add generic netlink configuration subcommand
The batman-adv netlink commandset receive different new commands to read and set the configuration values for mesh interfaces, hard interfaces and VLANs. These are not yet accessible via the normal subcommands. But developers still need access to them to test the kernel interface.
The "config" subcommand provides this functionality for all previously mentioned command classes. It is not suitable for endusers because there is no pretty printing and the user must know the exact type of data (and unit) for the option he wants to change.
--- Makefile | 1 + batman_adv.h | 55 ++++++ config.c | 542 +++++++++++++++++++++++++++++++++++++++++++++++++++ man/batctl.8 | 37 ++++ netlink.c | 3 + 5 files changed, 638 insertions(+) create mode 100644 config.c
Makefile +1 -0
@@ -57,6 +57,7 @@ $(eval $(call add_command,bisect_iv,$(CONFIG_BATCTL_BISECT))) $(eval $(call add_command,bonding,y)) $(eval $(call add_command,bridge_loop_avoidance,y)) $(eval $(call add_command,claimtable,y)) +$(eval $(call add_command,config,n)) $(eval $(call add_command,dat_cache,y)) $(eval $(call add_command,distributed_arp_table,y)) $(eval $(call add_command,event,y))
batman_adv.h +55 -0
73 lines not on this page · raw message
config.c new file +542 -0
542 lines not on this page · raw message
man/batctl.8 +37 -0
@@ -338,6 +338,43 @@ specific sequence number, min. Furthermore using "\-o" you can filter the output given batctl will not replace the MAC addresses with bat\-host names in the output. .RE .br +.IP "\fBconfig\fP [\fB\-H hardif\fP][\fB\-V VLANID\fP] \fBoption\fP [\fBtype\fP \fBvalue\fP]" +Gets or sets raw configuration options in the batman-adv module for either the +batadv soft interface, a hard (slave) interface or a VLAN of the batadv soft +interface. Providing no option name will dump all the configuration options +for the selected softif/hardif/VLAN. Providing only the option name will +retrieve the configuration configuration value. Providing a full +option\-type\-value tripplet will set the value in the kernel. The supported +types are u32 (0-4294967295), u16 (0-65535), u8 (0-255), bool (true/false) and +string. +For example: +.sp +.if n \{\ +.RS 10 +.\} +.nf +# retrieve all configuration options for the soft interface +batctl config +# retrieve all configuration options for the hard interface +batctl config -H eth0 +# retrieve all configuration options for the VLANID 0 +batctl config -V 0 + +# retrieve throughput_override for hard interface eth0 +batctl config -H eth0 throughput_override u32 + +# set fragmentation for bat0 +batctl config fragmentation bool false + +# set orig_interval for bat0 +batctl config orig_interval u32 5000 +.fi +.if n \{\ +.RE +.\} +.RE +.PP +.br .IP "\fBthroughputmeter\fP|\fBtp\fP \fBMAC\fP" This command starts a throughput test entirely controlled by batman module in kernel space: the computational resources needed to align memory and copy data
netlink.c +3 -0
@@ -107,6 +107,9 @@ struct nla_policy batadv_netlink_policy[NUM_BATADV_ATTR] = { [BATADV_ATTR_DAT_CACHE_VID] = { .type = NLA_U16 }, [BATADV_ATTR_MCAST_FLAGS] = { .type = NLA_U32 }, [BATADV_ATTR_MCAST_FLAGS_PRIV] = { .type = NLA_U32 }, + [BATADV_ATTR_VLANID] = { .type = NLA_U16 }, + [BATADV_ATTR_OPTION_NAME] = { .type = NLA_NUL_STRING }, + [BATADV_ATTR_OPTION_TYPE] = { .type = NLA_U8 }, };int netlink_create (struct state *state)
Signature · 1 line
2.19.1
RFC 2/2 batctl: Add support for config mcast group in event monitor
In reply to Sven EckelmannThe netlink set netlink messages issued by the config subcommands get as reply a multicast message with the new value. The event monitor should show these messages similar to the tp_meter results.
--- event.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+)
event.c +100 -0
@@ -22,6 +22,7 @@#include <errno.h> #include <getopt.h> +#include <net/if.h> #include <netinet/if_ether.h> #include <netlink/netlink.h> #include <netlink/genl/genl.h>
@@ -87,6 +88,25 @@ static int event_prepare(struct state *state) skip_tp_meter: + mcid =nl_get_multicast_id (state->sock,BATADV_NL_NAME , +BATADV_NL_MCAST_GROUP_CONFIG ); +if (mcid <0 ) { +fprintf (stderr,"Failed to resolve batadv config multicast group: %d\n" , + mcid); +/* ignore error for now */ + goto skip_config; + } + + ret =nl_socket_add_membership (state->sock, mcid); +if (ret) { +fprintf (stderr,"Failed to join batadv config multicast group: %d\n" , + ret); +/* ignore error for now */ + goto skip_config; + } + +skip_config: +return 0 ; }
@@ -145,6 +165,81 @@ static void event_parse_tp_meter(struct nlattr **attrs)printf ("tp_meter 0x%08x: %s\n" , cookie, result_str); } +static const int option_mandatory[] = { +BATADV_ATTR_MESH_IFINDEX , +BATADV_ATTR_OPTION_NAME , +BATADV_ATTR_OPTION_TYPE , +/* BATADV_ATTR_OPTION_VALUE, */ +}; + +static void event_parse_option (struct nlattr **attrs) +{ +char meshif_buf[IF_NAMESIZE ]; +char hardif_buf[IF_NAMESIZE ]; +char extra_info[256 ]; +char *meshif_name; +char *hardif_name; +uint32_t hardif_ifindex; +uint32_t mesh_ifindex; +const char *name; +uint16_t vid; +uint8_t type; + +/* ignore entry when attributes are missing */ +if (missing_mandatory_attrs (attrs, option_mandatory, +ARRAY_SIZE (option_mandatory))) +return ; + + mesh_ifindex =nla_get_u32 (attrs[BATADV_ATTR_MESH_IFINDEX ]); + meshif_name =if_indextoname (mesh_ifindex, meshif_buf); +if (!meshif_name) +return ; + +if (attrs[BATADV_ATTR_HARD_IFINDEX ]) { + hardif_ifindex =nla_get_u32 (attrs[BATADV_ATTR_HARD_IFINDEX ]); + hardif_name =if_indextoname (hardif_ifindex, hardif_buf); +if (!hardif_name) +return ; + +snprintf (extra_info,sizeof (extra_info)," (%s)" , hardif_name); + }else if (attrs[BATADV_ATTR_VLANID ]) { + vid =nla_get_u16 (attrs[BATADV_ATTR_VLANID ]); + +snprintf (extra_info,sizeof (extra_info)," (vid %u)" , vid); + }else { + extra_info[0 ] ='\0' ; + } + + name =nla_get_string (attrs[BATADV_ATTR_OPTION_NAME ]); + type =nla_get_u8 (attrs[BATADV_ATTR_OPTION_TYPE ]); + +if (type !=NLA_FLAG && !attrs[BATADV_ATTR_OPTION_VALUE ]) +return ; + +switch (type) { +case NLA_U8 : +printf ("%s%s: %s u8 %u\n" , meshif_name, extra_info, name, +nla_get_u8 (attrs[BATADV_ATTR_OPTION_VALUE ])); +break ; +case NLA_U16 : +printf ("%s%s: %s u16 %u\n" , meshif_name, extra_info, name, +nla_get_u16 (attrs[BATADV_ATTR_OPTION_VALUE ])); +break ; +case NLA_U32 : +printf ("%s%s: %s u32 %u\n" , meshif_name, extra_info, name, +nla_get_u32 (attrs[BATADV_ATTR_OPTION_VALUE ])); +break ; +case NLA_NUL_STRING : +printf ("%s%s: %s string %s\n" , meshif_name, extra_info, name, +nla_get_string (attrs[BATADV_ATTR_OPTION_VALUE ])); +break ; +case NLA_FLAG : +printf ("%s%s: %s bool %s\n" , meshif_name, extra_info, name, + attrs[BATADV_ATTR_OPTION_VALUE ] ?"true" :"false" ); +break ; + } +} +static unsigned long long get_timestamp (struct event_args *event_args) {unsigned long long prevtime =0 ;
@@ -190,6 +285,11 @@ static int event_parse(struct nl_msg *msg, void *arg)case BATADV_CMD_TP_METER :event_parse_tp_meter (attrs);break ; +case BATADV_CMD_SET_OPTION : +case BATADV_CMD_SET_OPTION_HARDIF : +case BATADV_CMD_SET_OPTION_VLAN : +event_parse_option (attrs); +break ;default :printf ("Received unknown event %u\n" , ghdr->cmd);break ;
Signature · 1 line
2.19.1