batctl: Switch active routing algo list to netlink
PATCH 1/3 batctl: Switch active routing algo list to netlink
The sysfs support is disabled by default in batman-adv since a while and will be removed in 2021. The generic netlink interface should be used instead. But the list of active routing algorithms was only available when batman-adv was build with sysfs support.
Instead of walking through (not existing) sysfs entries, query the list of batadv interfaces via rtnl and use the already existing helpers to get the routing algorithm.
--- routing_algo.c | 172 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 122 insertions(+), 50 deletions(-)
routing_algo.c +122 -50
@@ -6,7 +6,6 @@* License-Filename: LICENSES/preferred/GPL-2.0 */ -#include <dirent.h> #include <errno.h> #include <getopt.h> #include <netinet/if_ether.h>
@@ -159,14 +158,130 @@ static int print_routing_algos(void)return err; } +static struct nla_policy link_policy[IFLA_MAX +1 ] = { + [IFLA_IFNAME ] = { .type =NLA_STRING , .maxlen =IFNAMSIZ }, +}; + +struct print_ra_interfaces_rtnl_arg { +uint8_t header_shown:1 ; +}; + +static int print_ra_interfaces_rtnl_parse (struct nl_msg *msg,void *arg) +{ +struct print_ra_interfaces_rtnl_arg *print_arg = arg; +struct nlattr *attrs[IFLA_MAX +1 ]; +char algoname[256 ]; +struct ifinfomsg *ifm; +char *mesh_iface; +int ret; + + ifm =nlmsg_data (nlmsg_hdr (msg)); + ret =nlmsg_parse (nlmsg_hdr (msg),sizeof (*ifm), attrs,IFLA_MAX , + link_policy); +if (ret <0 ) + goto err; + +if (!attrs[IFLA_IFNAME ]) + goto err; + + mesh_iface =nla_get_string (attrs[IFLA_IFNAME ]); + + ret =get_algoname_netlink (mesh_iface, algoname,sizeof (algoname)); +if (ret <0 ) + goto err; + +if (!print_arg->header_shown) { + print_arg->header_shown = true; +printf ("Active routing protocol configuration:\n" ); + } + +printf (" * %s: %s\n" , mesh_iface, algoname); + +err: +return NL_OK ; +} + +static int print_ra_interfaces (void ) +{ +struct print_ra_interfaces_rtnl_arg print_arg = {}; + +struct ifinfomsg rt_hdr = { + .ifi_family =IFLA_UNSPEC , + }; +struct nlattr *linkinfo; +struct nl_sock *sock; +struct nl_msg *msg; +struct nl_cb *cb; +int err =0 ; +int ret; + + sock =nl_socket_alloc (); +if (!sock) +return -ENOMEM ; + + ret =nl_connect (sock,NETLINK_ROUTE ); +if (ret <0 ) { + err = -ENOMEM ; + goto err_free_sock; + } + + cb =nl_cb_alloc (NL_CB_DEFAULT ); +if (!cb) { + err = -ENOMEM ; + goto err_free_sock; + } + +nl_cb_set (cb,NL_CB_VALID ,NL_CB_CUSTOM , print_ra_interfaces_rtnl_parse, + &print_arg); + + msg =nlmsg_alloc_simple (RTM_GETLINK ,NLM_F_REQUEST |NLM_F_DUMP ); +if (!msg) { + err = -ENOMEM ; + goto err_free_cb; + } + + ret =nlmsg_append (msg, &rt_hdr,sizeof (rt_hdr),NLMSG_ALIGNTO ); +if (ret <0 ) { + err = -ENOMEM ; + goto err_free_msg; + } + + linkinfo =nla_nest_start (msg,IFLA_LINKINFO ); +if (!linkinfo) { + err = -ENOMEM ; + goto err_free_msg; + } + + ret =nla_put_string (msg,IFLA_INFO_KIND ,"batadv" ); +if (ret <0 ) { + err = -ENOMEM ; + goto err_free_msg; + } +nla_nest_end (msg, linkinfo); + + ret =nl_send_auto_complete (sock, msg); +if (ret <0 ) + goto err_free_msg; + +nl_recvmsgs (sock, cb); + +if (print_arg.header_shown) +printf ("\n" ); + +err_free_msg: +nlmsg_free (msg); +err_free_cb: +nl_cb_put (cb); +err_free_sock: +nl_socket_free (sock); + +return err; +} +static int routing_algo (struct state *state__maybe_unused ,int argc,char **argv) { -DIR *iface_base_dir; -struct dirent *iface_dir;int optchar; -char *path_buff;int res =EXIT_FAILURE ; -int first_iface =1 ;while ((optchar =getopt (argc, argv,"h" )) !=-1 ) {switch (optchar) {
@@ -183,48 +298,10 @@ static int routing_algo(struct state *state __maybe_unused, int argc, char **argif (argc ==2 ) { res =write_file (SYS_SELECTED_RA_PATH ,"" , argv[1 ],NULL ); - goto out; - } - - path_buff =malloc (PATH_BUFF_LEN ); -if (!path_buff) { -fprintf (stderr,"Error - could not allocate path buffer: out of memory ?\n" ); - goto out; - } - - iface_base_dir =opendir (SYS_IFACE_PATH ); -if (!iface_base_dir) { -fprintf (stderr,"Error - the directory '%s' could not be read: %s\n" , -SYS_IFACE_PATH ,strerror (errno)); -fprintf (stderr,"Is the batman-adv module loaded and sysfs mounted ?\n" ); - goto free_buff; - } - -while ((iface_dir =readdir (iface_base_dir)) !=NULL ) { -snprintf (path_buff,PATH_BUFF_LEN ,SYS_ROUTING_ALGO_FMT , iface_dir->d_name); - res =read_file ("" , path_buff,USE_READ_BUFF |SILENCE_ERRORS ,0 ,0 ,0 ); -if (res !=EXIT_SUCCESS ) -continue ; - -if (line_ptr[strlen (line_ptr) -1 ] =='\n' ) - line_ptr[strlen (line_ptr) -1 ] ='\0' ; - -if (first_iface) { - first_iface =0 ; -printf ("Active routing protocol configuration:\n" ); - } - -printf (" * %s: %s\n" , iface_dir->d_name, line_ptr); - -free (line_ptr); - line_ptr =NULL ; +return EXIT_FAILURE ; } -closedir (iface_base_dir); -free (path_buff); - -if (!first_iface) -printf ("\n" ); +print_ra_interfaces (); res =read_file ("" ,SYS_SELECTED_RA_PATH ,USE_READ_BUFF ,0 ,0 ,0 );if (res !=EXIT_SUCCESS )
@@ -237,11 +314,6 @@ static int routing_algo(struct state *state __maybe_unused, int argc, char **argprint_routing_algos ();return EXIT_SUCCESS ; - -free_buff: -free (path_buff); -out: -return res; } COMMAND(SUBCOMMAND, routing_algo, "ra", 0, NULL,
Signature · 1 line
2.28.0
PATCH 2/3 batctl: Drop deprecated debugfs support
The debugfs support is disabled by default in batman-adv since a while and will be removed in 2021. The generic netlink interface should be used instead.
The batctl support for it should be removed with the same release as the removal in batman-adv.
--- Makefile | 2 - README.rst | 10 ++-- backbonetable.c | 2 - claimtable.c | 2 - dat_cache.c | 2 - debug.c | 27 +-------- debug.h | 11 ---- debugfs.c | 140 ---------------------------------------------- debugfs.h | 25 --------- functions.c | 130 +++--------------------------------------- functions.h | 3 +- gateways.c | 2 - gw_mode.c | 6 +- icmp_helper.c | 1 - interface.c | 3 +- loglevel.c | 2 +- main.c | 2 +- man/batctl.8 | 7 +-- mcast_flags.c | 2 - nc_nodes.c | 18 ------ neighbors.c | 2 - originators.c | 2 - routing_algo.c | 20 +------ sys.c | 2 +- throughputmeter.c | 1 - transglobal.c | 2 - translocal.c | 2 - 27 files changed, 25 insertions(+), 403 deletions(-) delete mode 100644 debugfs.c delete mode 100644 debugfs.h delete mode 100644 nc_nodes.c
Makefile +0 -2
@@ -13,7 +13,6 @@ export CONFIG_BATCTL_BISECT=n BINARY_NAME = batctl obj-y += bat-hosts.o -obj-y += debugfs.o obj-y += debug.o obj-y += functions.o obj-y += genl.o
@@ -58,7 +57,6 @@ $(eval $(call add_command,mcast_flags,y)) $(eval $(call add_command,multicast_fanout,y)) $(eval $(call add_command,multicast_forceflood,y)) $(eval $(call add_command,multicast_mode,y)) -$(eval $(call add_command,nc_nodes,y)) $(eval $(call add_command,neighbors,y)) $(eval $(call add_command,network_coding,y)) $(eval $(call add_command,orig_interval,y))
README.rst +5 -5
@@ -18,11 +18,11 @@ settings. How does it work ? ================== -batctl uses the debugfs/batman_adv/bat0/socket device provided by the B.A.T.M.A.N. -advanced kernel module to inject custom icmp packets into the data flow. That's why -ping and traceroute work almost like their IP based counterparts. Tcpdump was -designed because B.A.T.M.A.N. advanced encapsulates all traffic within batman -packets, so that the normal tcpdump would not recognize the packets. +batctl uses the raw packet sockets to inject custom icmp packets into the data +flow. That's why ping and traceroute work almost like their IP based +counterparts. Tcpdump was designed because B.A.T.M.A.N. advanced encapsulates +all traffic within batman packets, so that the normal tcpdump would not +recognize the packets. The bat-hosts file
backbonetable.c +0 -2
@@ -102,8 +102,6 @@ static int netlink_print_bla_backbone(struct state *state, char *orig_iface, }static struct debug_table_data batctl_debug_table_backbonetable = { - .debugfs_name =DEBUG_BACKBONETABLE , - .header_lines =2 , .netlink_fn = netlink_print_bla_backbone, };
claimtable.c +0 -2
@@ -107,8 +107,6 @@ static int netlink_print_bla_claim(struct state *state, char *orig_iface, }static struct debug_table_data batctl_debug_table_claimtable = { - .debugfs_name =DEBUG_CLAIMTABLE , - .header_lines =2 , .netlink_fn = netlink_print_bla_claim, };
dat_cache.c +0 -2
@@ -123,8 +123,6 @@ static int netlink_print_dat_cache(struct state *state, char *orig_iface, }static struct debug_table_data batctl_debug_table_dat_cache = { - .debugfs_name =DEBUG_DAT_CACHE , - .header_lines =2 , .netlink_fn = netlink_print_dat_cache, };
debug.c +3 -24
@@ -13,7 +13,6 @@#include <errno.h> #include "debug.h" -#include "debugfs.h" #include "functions.h" #include "netlink.h" #include "sys.h"
@@ -47,8 +46,6 @@ int handle_debug_table(struct state *state, int argc, char **argv) {struct debug_table_data *debug_table = state->cmd->arg;int optchar, read_opt =USE_BAT_HOSTS ; -char full_path[MAX_PATH +1 ]; -char *debugfs_mnt;char *orig_iface =NULL ;float orig_timeout =0.0f ;float watch_interval =1 ;
@@ -147,25 +144,7 @@ int handle_debug_table(struct state *state, int argc, char **argv)return EXIT_FAILURE ; } - debugfs_mnt =debugfs_mount (NULL ); -if (!debugfs_mnt) { -fprintf (stderr,"Error - can't mount or find debugfs\n" ); -return EXIT_FAILURE ; - } - -if (debug_table->netlink_fn) { - err = debug_table->netlink_fn (state , orig_iface, read_opt, - orig_timeout, watch_interval); -if (err != -EOPNOTSUPP ) -return err; - } - -if (orig_iface) -debugfs_make_path (DEBUG_BATIF_PATH_FMT "/" , orig_iface, full_path,sizeof (full_path)); -else -debugfs_make_path (DEBUG_BATIF_PATH_FMT "/" , state->mesh_iface, full_path,sizeof (full_path)); - -return read_file (full_path, debug_table->debugfs_name, - read_opt, orig_timeout, watch_interval, - debug_table->header_lines); + err = debug_table->netlink_fn (state , orig_iface, read_opt, + orig_timeout, watch_interval); +return err; }
debug.h +0 -11
@@ -12,18 +12,7 @@#include <stddef.h> #include "main.h" -#define DEBUG_BATIF_PATH_FMT "%s/batman_adv/%s" -#define DEBUG_TRANSTABLE_GLOBAL "transtable_global" -#define DEBUG_BACKBONETABLE "bla_backbone_table" -#define DEBUG_CLAIMTABLE "bla_claim_table" -#define DEBUG_DAT_CACHE "dat_cache" -#define DEBUG_NC_NODES "nc_nodes" -#define DEBUG_MCAST_FLAGS "mcast_flags" -#define DEBUG_ROUTING_ALGOS "routing_algos" -struct debug_table_data { -const char *debugfs_name; -size_t header_lines;int (*netlink_fn)(struct state *state,char *hard_iface,int read_opt,float orig_timeout,float watch_interval);unsigned int option_unicast_only:1 ;
debugfs.c deleted +0 -140
140 lines not on this page · raw message
debugfs.h deleted +0 -25
@@ -1,25 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* Copyright (C) 2009 Clark Williams <[email protected]> -* Copyright (C) 2009 Xiao Guangrong <[email protected]> -* -* License-Filename: LICENSES/preferred/GPL-2.0 -*/ - -#ifndef __DEBUGFS_H__ -#define __DEBUGFS_H__ - -#ifndef MAX_PATH -# define MAX_PATH 256 -#endif - -#ifndef STR -# define _STR (x) #x -# define STR (x) _STR(x) -#endif - -extern int debugfs_valid_entry (const char *path); -extern char *debugfs_mount (const char *mountpoint); -extern int debugfs_make_path (const char *fmt,const char *mesh_iface, -char *buffer,int size); - -#endif /* __DEBUGFS_H__ */
functions.c +7 -123
190 lines not on this page · raw message
functions.h +1 -2
@@ -43,8 +43,7 @@ char *ether_ntoa_long(const struct ether_addr *addr);char *get_name_by_macaddr (struct ether_addr *mac_addr,int read_opt);char *get_name_by_macstr (char *mac_str,int read_opt);int file_exists (const char *fpath); -int read_file (const char *dir,const char *path,int read_opt, -float orig_timeout,float watch_interval,size_t header_lines); +int read_file (const char *dir,const char *path,int read_opt);int write_file (const char *dir,const char *fname,const char *arg1,const char *arg2); struct ether_addr *translate_mac(const char *mesh_iface,
gateways.c +0 -2
@@ -145,8 +145,6 @@ static int netlink_print_gateways(struct state *state, char *orig_iface, }static struct debug_table_data batctl_debug_table_gateways = { - .debugfs_name ="gateways" , - .header_lines =1 , .netlink_fn = netlink_print_gateways, };
gw_mode.c +3 -3
@@ -266,7 +266,7 @@ static int gw_read_setting(struct state *state, const char *path_buff)return EXIT_SUCCESS ;/* fallback to sysfs */ - res =read_file (path_buff,SYS_GW_MODE ,USE_READ_BUFF ,0 ,0 ,0 ); + res =read_file (path_buff,SYS_GW_MODE ,USE_READ_BUFF );if (res !=EXIT_SUCCESS ) goto out;
@@ -285,10 +285,10 @@ static int gw_read_setting(struct state *state, const char *path_buff)switch (gw_mode) {case BATADV_GW_MODE_CLIENT : - res =read_file (path_buff,SYS_GW_SEL ,USE_READ_BUFF ,0 ,0 ,0 ); + res =read_file (path_buff,SYS_GW_SEL ,USE_READ_BUFF );break ;case BATADV_GW_MODE_SERVER : - res =read_file (path_buff,SYS_GW_BW ,USE_READ_BUFF ,0 ,0 ,0 ); + res =read_file (path_buff,SYS_GW_BW ,USE_READ_BUFF );break ;default :printf ("off\n" );
icmp_helper.c +0 -1
@@ -28,7 +28,6 @@#include "batadv_packet.h" #include "debug.h" -#include "debugfs.h" #include "functions.h" #include "list.h" #include "netlink.h"
interface.c +1 -2
@@ -168,8 +168,7 @@ static int print_interfaces_rtnl_parse(struct nl_msg *msg, void *arg)if (!status) {snprintf (path_buff,sizeof (path_buff),SYS_IFACE_STATUS_FMT , ifname); - ret =read_file ("" , path_buff,USE_READ_BUFF |SILENCE_ERRORS , -0 ,0 ,0 ); + ret =read_file ("" , path_buff,USE_READ_BUFF |SILENCE_ERRORS );if (ret !=EXIT_SUCCESS ) status ="<error reading status>\n" ;else
loglevel.c +1 -1
@@ -96,7 +96,7 @@ static int log_level_read_setting(struct state *state, const char *path_buff)if (res >=0 )return EXIT_SUCCESS ; - res =read_file (path_buff,SYS_LOG_LEVEL ,USE_READ_BUFF ,0 ,0 ,0 ); + res =read_file (path_buff,SYS_LOG_LEVEL ,USE_READ_BUFF );if (res !=EXIT_SUCCESS )return res;
main.c +1 -1
@@ -123,7 +123,7 @@ static void version(void)printf ("batctl %s [batman-adv: " ,SOURCE_VERSION ); - ret =read_file ("" , module_ver_path,USE_READ_BUFF |SILENCE_ERRORS ,0 ,0 ,0 ); + ret =read_file ("" , module_ver_path,USE_READ_BUFF |SILENCE_ERRORS );if ((line_ptr) && (line_ptr[strlen (line_ptr) -1 ] =='\n' )) line_ptr[strlen (line_ptr) -1 ] ='\0' ;
man/batctl.8 +1 -6
@@ -241,9 +241,7 @@ Example 3: 16 or 0x0F .I \fBdebug tables: .IP The batman-adv kernel module comes with a variety of debug tables containing various information about the state of the mesh -seen by each individual node. These tables are exported via debugfs and easily accessible via batctl. You will need debugfs -support compiled into your kernel and preferably have mounted the debugfs to a well-known mountpoint. If debugfs is not -mounted batctl will attempt to do this step for you. +seen by each individual node. All of the debug tables support the following options: .RS 10
@@ -290,9 +288,6 @@ List of debug tables: \- dat_cache|dc (compile time option) .RE .RS 10 -\- nc_nodes|nn (compile time option) -.RE -.RS 10 \- mcast_flags|mf (compile time option) .RE .RE
mcast_flags.c +0 -2
@@ -154,8 +154,6 @@ static int netlink_print_mcast_flags(struct state *state, char *orig_iface, }static struct debug_table_data batctl_debug_table_mcast_flags = { - .debugfs_name =DEBUG_MCAST_FLAGS , - .header_lines =6 , .netlink_fn = netlink_print_mcast_flags, };
nc_nodes.c deleted +0 -18
@@ -1,18 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* Copyright (C) 2009-2020 B.A.T.M.A.N. contributors: -* -* Marek Lindner <[email protected]> -* -* License-Filename: LICENSES/preferred/GPL-2.0 -*/ - -#include "debug.h" -#include "main.h" - -static struct debug_table_data batctl_debug_table_nc_nodes = { - .debugfs_name =DEBUG_NC_NODES , - .header_lines =0 , -}; - -COMMAND_NAMED (DEBUGTABLE , nc_nodes,"nn" , handle_debug_table, -COMMAND_FLAG_MESH_IFACE , &batctl_debug_table_nc_nodes,"" );
neighbors.c +0 -2
@@ -118,8 +118,6 @@ static int netlink_print_neighbors(struct state *state, char *orig_iface, }static struct debug_table_data batctl_debug_table_neighbors = { - .debugfs_name ="neighbors" , - .header_lines =2 , .netlink_fn = netlink_print_neighbors, };
originators.c +0 -2
@@ -196,8 +196,6 @@ static int netlink_print_originators(struct state *state, char *orig_iface, }static struct debug_table_data batctl_debug_table_originators = { - .debugfs_name ="originators" , - .header_lines =2 , .netlink_fn = netlink_print_originators, .option_timeout_interval =1 , .option_orig_iface =1 ,
routing_algo.c +1 -19
@@ -19,7 +19,6 @@#include "batadv_packet.h" #include "batman_adv.h" #include "debug.h" -#include "debugfs.h" #include "functions.h" #include "main.h" #include "netlink.h"
@@ -133,28 +132,11 @@ static int netlink_print_routing_algos(void)return last_err; } -static int debug_print_routing_algos (void ) -{ -char full_path[MAX_PATH +1 ]; -char *debugfs_mnt; - - debugfs_mnt =debugfs_mount (NULL ); -if (!debugfs_mnt) { -fprintf (stderr,"Error - can't mount or find debugfs\n" ); -return -1 ; - } - -debugfs_make_path (DEBUG_BATIF_PATH_FMT ,"" , full_path,sizeof (full_path)); -return read_file (full_path,DEBUG_ROUTING_ALGOS ,0 ,0 ,0 ,0 ); -} -static int print_routing_algos (void ) {int err; err =netlink_print_routing_algos (); -if (err == -EOPNOTSUPP ) - err =debug_print_routing_algos ();return err; }
@@ -303,7 +285,7 @@ static int routing_algo(struct state *state __maybe_unused, int argc, char **argprint_ra_interfaces (); - res =read_file ("" ,SYS_SELECTED_RA_PATH ,USE_READ_BUFF ,0 ,0 ,0 ); + res =read_file ("" ,SYS_SELECTED_RA_PATH ,USE_READ_BUFF );if (res !=EXIT_SUCCESS )return EXIT_FAILURE ;
sys.c +1 -1
@@ -208,7 +208,7 @@ static int sys_read_setting(struct state *state, const char *path_buff,if (state->cmd->flags &COMMAND_FLAG_INVERSE ) read_opt |=INVERSE_BOOL ; - res =read_file (path_buff, sysfs_name, read_opt,0 ,0 ,0 ); + res =read_file (path_buff, sysfs_name, read_opt); }return res;
throughputmeter.c +0 -1
@@ -32,7 +32,6 @@#include "functions.h" #include "genl.h" #include "netlink.h" -#include "debugfs.h" static struct ether_addr *dst_mac;static char *tp_mesh_iface;
transglobal.c +0 -2
@@ -136,8 +136,6 @@ static int netlink_print_transglobal(struct state *state, char *orig_iface, }static struct debug_table_data batctl_debug_table_transglobal = { - .debugfs_name ="transtable_global" , - .header_lines =2 , .netlink_fn = netlink_print_transglobal, .option_unicast_only =1 , .option_multicast_only =1 ,
translocal.c +0 -2
@@ -132,8 +132,6 @@ static int netlink_print_translocal(struct state *state, char *orig_iface, }static struct debug_table_data batctl_debug_table_translocal = { - .debugfs_name ="transtable_local" , - .header_lines =2 , .netlink_fn = netlink_print_translocal, .option_unicast_only =1 , .option_multicast_only =1 ,
Signature · 1 line
2.28.0
PATCH 3/3 batctl: Drop deprecated sysfs support
In reply to Sven EckelmannThe sysfs support is disabled by default in batman-adv since a while and will be removed in 2021. The generic netlink interface should be used instead.
The batctl support for it should be removed with the same release as the removal in batman-adv.
--- aggregation.c | 1 - ap_isolation.c | 1 - bonding.c | 1 - bridge_loop_avoidance.c | 1 - distributed_arp_table.c | 1 - elp_interval.c | 1 - fragmentation.c | 1 - functions.c | 183 ++-------------------------------------- functions.h | 5 +- gw_mode.c | 111 +++--------------------- hop_penalty.c | 2 - interface.c | 15 +--- isolation_mark.c | 1 - loglevel.c | 44 +++------- main.c | 7 +- multicast_fanout.c | 1 - multicast_forceflood.c | 1 - multicast_mode.c | 1 - network_coding.c | 1 - orig_interval.c | 1 - routing_algo.c | 38 ++++++--- sys.c | 90 +++----------------- sys.h | 9 -- throughput_override.c | 1 - 24 files changed, 71 insertions(+), 447 deletions(-)
aggregation.c +0 -1
@@ -48,7 +48,6 @@ static int set_aggregated_ogms(struct state *state) }static struct settings_data batctl_settings_aggregation = { - .sysfs_name ="aggregated_ogms" , .data = &aggregated_ogms, .parse = parse_simple_boolean, .netlink_get = get_aggregated_ogms,
ap_isolation.c +0 -1
@@ -70,7 +70,6 @@ static int set_ap_isolation(struct state *state) }static struct settings_data batctl_settings_ap_isolation = { - .sysfs_name ="ap_isolation" , .data = &ap_isolation, .parse = parse_simple_boolean, .netlink_get = get_ap_isolation,
bonding.c +0 -1
@@ -47,7 +47,6 @@ static int set_bonding(struct state *state) }static struct settings_data batctl_settings_bonding = { - .sysfs_name ="bonding" , .data = &bonding, .parse = parse_simple_boolean, .netlink_get = get_bonding,
bridge_loop_avoidance.c +0 -1
@@ -48,7 +48,6 @@ static int set_bridge_loop_avoidance(struct state *state) }static struct settings_data batctl_settings_bridge_loop_avoidance = { - .sysfs_name ="bridge_loop_avoidance" , .data = &bridge_loop_avoidance, .parse = parse_simple_boolean, .netlink_get = get_bridge_loop_avoidance,
distributed_arp_table.c +0 -1
@@ -48,7 +48,6 @@ static int set_distributed_arp_table(struct state *state) }static struct settings_data batctl_settings_distributed_arp_table = { - .sysfs_name ="distributed_arp_table" , .data = &distributed_arp_table, .parse = parse_simple_boolean, .netlink_get = get_distributed_arp_table,
elp_interval.c +0 -1
@@ -98,7 +98,6 @@ static int set_elp_interval(struct state *state) }static struct settings_data batctl_settings_elp_interval = { - .sysfs_name ="elp_interval" , .data = &elp_interval, .parse = parse_elp_interval, .netlink_get = get_elp_interval,
fragmentation.c +0 -1
@@ -48,7 +48,6 @@ static int set_fragmentation(struct state *state) }static struct settings_data batctl_settings_fragmentation = { - .sysfs_name ="fragmentation" , .data = &fragmentation, .parse = parse_simple_boolean, .netlink_get = get_fragmentation,
functions.c +6 -177
242 lines not on this page · raw message
functions.h +1 -4
@@ -43,9 +43,7 @@ char *ether_ntoa_long(const struct ether_addr *addr);char *get_name_by_macaddr (struct ether_addr *mac_addr,int read_opt);char *get_name_by_macstr (char *mac_str,int read_opt);int file_exists (const char *fpath); -int read_file (const char *dir,const char *path,int read_opt); -int write_file (const char *dir,const char *fname,const char *arg1, -const char *arg2); +int read_file (const char *full_path,int read_opt);struct ether_addr *translate_mac (const char *mesh_iface,const struct ether_addr *mac);struct ether_addr *resolve_mac (const char *asc);
@@ -81,7 +79,6 @@ enum {SKIP_HEADER =0x100 ,UNICAST_ONLY =0x200 , MULTICAST_ONLY = 0x400, - INVERSE_BOOL = 0x800, };#endif
gw_mode.c +11 -100
147 lines not on this page · raw message
hop_penalty.c +0 -2
@@ -122,7 +122,6 @@ static int set_hop_penalty_if(struct state *state) }static struct settings_data batctl_settings_hop_penalty = { - .sysfs_name ="hop_penalty" , .data = &hop_penalty, .parse = parse_hop_penalty, .netlink_get = get_hop_penalty,
@@ -130,7 +129,6 @@ static struct settings_data batctl_settings_hop_penalty = { };static struct settings_data batctl_settings_hop_penalty_if = { - .sysfs_name =NULL , .data = &hop_penalty, .parse = parse_hop_penalty, .netlink_get = get_hop_penalty_if,
interface.c +2 -13
@@ -138,7 +138,6 @@ static int print_interfaces_rtnl_parse(struct nl_msg *msg, void *arg)struct print_interfaces_rtnl_arg *print_arg = arg;char iface_status[IFACE_STATUS_LEN ];struct nlattr *attrs[IFLA_MAX +1 ]; -char path_buff[PATH_BUFF_LEN ];struct ifinfomsg *ifm;char *ifname;int ret;
@@ -165,21 +164,11 @@ static int print_interfaces_rtnl_parse(struct nl_msg *msg, void *arg) goto err; status =get_iface_status_netlink (master, ifm->ifi_index, iface_status); -if (!status) { -snprintf (path_buff,sizeof (path_buff),SYS_IFACE_STATUS_FMT , - ifname); - ret =read_file ("" , path_buff,USE_READ_BUFF |SILENCE_ERRORS ); -if (ret !=EXIT_SUCCESS ) - status ="<error reading status>\n" ; -else - status = line_ptr; - } +if (!status) + status ="<error reading status>\n" ;printf ("%s: %s" , ifname, status); -free (line_ptr); - line_ptr =NULL ; - err:return NL_OK ; }
isolation_mark.c +0 -1
@@ -127,7 +127,6 @@ static int set_isolation_mark(struct state *state) }static struct settings_data batctl_settings_isolation_mark = { - .sysfs_name ="isolation_mark" , .data = &isolation_mark, .parse = parse_isolation_mark, .netlink_get = get_isolation_mark,
loglevel.c +10 -34
93 lines not on this page · raw message
main.c +2 -5
@@ -123,7 +123,7 @@ static void version(void)printf ("batctl %s [batman-adv: " ,SOURCE_VERSION ); - ret =read_file ("" , module_ver_path,USE_READ_BUFF |SILENCE_ERRORS ); + ret =read_file (module_ver_path,USE_READ_BUFF |SILENCE_ERRORS );if ((line_ptr) && (line_ptr[strlen (line_ptr) -1 ] =='\n' )) line_ptr[strlen (line_ptr) -1 ] ='\0' ;
@@ -397,10 +397,7 @@ int main(int argc, char **argv)if (cmd->flags &COMMAND_FLAG_NETLINK ) { ret =netlink_create (&state); -if (ret <0 && ret != -EOPNOTSUPP ) { -/* TODO handle -EOPNOTSUPP as error when fallbacks were -* removed -*/ +if (ret <0 ) {fprintf (stderr,"Error - failed to connect to batadv\n" );exit (EXIT_FAILURE );
multicast_fanout.c +0 -1
@@ -88,7 +88,6 @@ static int set_multicast_fanout(struct state *state) }static struct settings_data batctl_settings_multicast_fanout = { - .sysfs_name =NULL , .data = &multicast_fanout, .parse = parse_multicast_fanout, .netlink_get = get_multicast_fanout,
multicast_forceflood.c +0 -1
@@ -68,7 +68,6 @@ static int set_multicast_forceflood(struct state *state) }static struct settings_data batctl_settings_multicast_forceflood = { - .sysfs_name ="multicast_mode" , .data = &multicast_forceflood, .parse = parse_simple_boolean, .netlink_get = get_multicast_forceflood,
multicast_mode.c +0 -1
@@ -68,7 +68,6 @@ static int set_multicast_mode(struct state *state) }static struct settings_data batctl_settings_multicast_mode = { - .sysfs_name ="multicast_mode" , .data = &multicast_mode, .parse = parse_simple_boolean, .netlink_get = get_multicast_mode,
network_coding.c +0 -1
@@ -48,7 +48,6 @@ static int set_network_coding(struct state *state) }static struct settings_data batctl_settings_network_coding = { - .sysfs_name ="network_coding" , .data = &network_coding, .parse = parse_simple_boolean, .netlink_get = get_network_coding,
orig_interval.c +0 -1
@@ -88,7 +88,6 @@ static int set_orig_interval(struct state *state) }static struct settings_data batctl_settings_orig_interval = { - .sysfs_name ="orig_interval" , .data = &orig_interval, .parse = parse_orig_interval, .netlink_get = get_orig_interval,
routing_algo.c +28 -10
@@ -7,6 +7,7 @@*/ #include <errno.h> +#include <fcntl.h> #include <getopt.h> #include <netinet/if_ether.h> #include <netlink/netlink.h>
@@ -15,6 +16,9 @@#include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> #include "batadv_packet.h" #include "batman_adv.h"
@@ -73,7 +77,7 @@ static int routing_algos_callback(struct nl_msg *msg, void *arg __maybe_unused)return NL_OK ; } -static int netlink_print_routing_algos (void ) +static int print_routing_algos (void ) {struct nl_sock *sock;struct nl_msg *msg;
@@ -132,12 +136,28 @@ static int netlink_print_routing_algos(void)return last_err; } -static int print_routing_algos (void ) +static int write_default_ra (const char *full_path,const char *arg1) { -int err; +ssize_t write_len; +int fd =-1 ; - err =netlink_print_routing_algos (); -return err; + fd =open (full_path,O_WRONLY ); +if (fd <0 ) { +fprintf (stderr,"Error - can't open file '%s': %s\n" , full_path, +strerror (errno)); + +return EXIT_FAILURE ; + } + + write_len =write (fd, arg1,strlen (arg1) +1 ); +close (fd); +if (write_len <0 ) { +fprintf (stderr,"Error - can't write to file '%s': %s\n" , + full_path,strerror (errno)); +return EXIT_FAILURE ; + } + +return EXIT_SUCCESS ; }static struct nla_policy link_policy[IFLA_MAX +1 ] = {
@@ -278,14 +298,12 @@ static int routing_algo(struct state *state __maybe_unused, int argc, char **argcheck_root_or_die ("batctl routing_algo" ); -if (argc ==2 ) { - res =write_file (SYS_SELECTED_RA_PATH ,"" , argv[1 ],NULL ); -return EXIT_FAILURE ; - } +if (argc ==2 ) +return write_default_ra (SYS_SELECTED_RA_PATH , argv[1 ]);print_ra_interfaces (); - res =read_file ("" ,SYS_SELECTED_RA_PATH ,USE_READ_BUFF ); + res =read_file (SYS_SELECTED_RA_PATH ,USE_READ_BUFF );if (res !=EXIT_SUCCESS )return EXIT_FAILURE ;
sys.c +11 -79
136 lines not on this page · raw message
sys.h +0 -9
@@ -18,18 +18,9 @@#include "batman_adv.h" #include "netlink.h" -#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_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 4struct settings_data { -const char *sysfs_name;void *data;int (*parse)(struct state *state,int argc,char *argv[]);int (*netlink_get)(struct state *state);
throughput_override.c +0 -1
@@ -101,7 +101,6 @@ static int set_throughput_override(struct state *state) }static struct settings_data batctl_settings_throughput_override = { - .sysfs_name ="throughput_override" , .data = &throughput_override, .parse = parse_throughput_override, .netlink_get = get_throughput_override,
Signature · 1 line
2.28.0