batctl: unify debug table handling and remove redundant code
PATCH 1/3 batctl: unify debug table handling and remove redundant code
Signed-off-by Marek Lindner <[email protected]>
--- debug.c | 111 +++++++++++++++++++++++++++++---------------------------------- debug.h | 27 +++++++++++---- main.c | 74 +++++++++++++++++------------------------- main.h | 5 +++ 4 files changed, 105 insertions(+), 112 deletions(-)
debug.c +51 -60
@@ -33,64 +33,53 @@#include "debugfs.h" #include "functions.h" -void originators_usage (void ) +const struct debug_table_data batctl_debug_tables[BATCTL_TABLE_NUM ] = { + { + .opt_long ="originators" , + .opt_short ="o" , + .debugfs_name ="originators" , + }, + { + .opt_long ="gateways" , + .opt_short ="gwl" , + .debugfs_name ="gateways" , + }, + { + .opt_long ="translocal" , + .opt_short ="tl" , + .debugfs_name ="transtable_local" , + }, + { + .opt_long ="transglobal" , + .opt_short ="tg" , + .debugfs_name ="transtable_global" , + }, + { + .opt_long ="claimtable" , + .opt_short ="cl" , + .debugfs_name ="bla_claim_table" , + }, + { + .opt_long ="backbonetable" , + .opt_short ="bbt" , + .debugfs_name ="bla_backbone_table" , + }, +}; + +void debug_table_usage (int debug_table) { -printf ("Usage: batctl [options] originators \n" ); +printf ("Usage: batctl [options] %s|%s\n" , + batctl_debug_tables[debug_table].opt_long, batctl_debug_tables[debug_table].opt_short);printf ("options:\n" );printf (" \t -h print this help\n" );printf (" \t -n don't replace mac addresses with bat-host names\n" ); -printf (" \t -w [interval] watch mode - refresh the originator table continuously\n" ); -printf (" \t -t timeout interval - don't print originators not seen for x.y seconds \n" ); -} - -void trans_local_usage (void ) -{ -printf ("Usage: batctl [options] translocal \n" ); -printf ("options:\n" ); -printf (" \t -h print this help\n" ); -printf (" \t -n don't replace mac addresses with bat-host names\n" ); -printf (" \t -w [interval] watch mode - refresh the local translation table continuously\n" ); -} - -void trans_global_usage (void ) -{ -printf ("Usage: batctl [options] transglobal \n" ); -printf ("options:\n" ); -printf (" \t -h print this help\n" ); -printf (" \t -n don't replace mac addresses with bat-host names\n" ); -printf (" \t -w [interval] watch mode - refresh the global translation table continuously\n" ); -} - -void bla_claim_table_usage (void ) -{ -printf ("Usage: batctl [options] claimtable \n" ); -printf ("options:\n" ); -printf (" \t -h print this help\n" ); -printf (" \t -n don't replace mac addresses with bat-host names\n" ); -printf (" \t -w [interval] watch mode - refresh the bridge loop avoidance claim table continuously\n" ); -} +printf (" \t -w [interval] watch mode - refresh the table continuously\n" ); -void bla_backbone_table_usage (void ) -{ -printf ("Usage: batctl [options] backbone table\n" ); -printf ("options:\n" ); -printf (" \t -h print this help\n" ); -printf (" \t -n don't replace mac addresses with bat-host names\n" ); -printf (" \t -w [interval] watch mode - refresh the bridge loop avoidance backbone table continuously\n" ); -} - - -void gateways_usage (void ) -{ -printf ("Usage: batctl [options] gateways \n" ); -printf ("options:\n" ); -printf (" \t -h print this help\n" ); -printf (" \t -n don't replace mac addresses with bat-host names\n" ); -printf (" \t -w [interval] watch mode - refresh the gateway server list continuously\n" ); +if (debug_table ==BATCTL_TABLE_ORIGINATORS ) +printf (" \t -t timeout interval - don't print originators not seen for x.y seconds \n" ); } -int handle_debug_table (char *mesh_iface,int argc,char **argv, -char *file_path,void table_usage (void )) +int handle_debug_table (char *mesh_iface,int debug_table,int argc,char **argv) {int optchar, read_opt =USE_BAT_HOSTS ;char full_path[MAX_PATH +1 ];
@@ -102,7 +91,7 @@ int handle_debug_table(char *mesh_iface, int argc, char **argv,while ((optchar =getopt (argc, argv,"hnw:t:" )) !=-1 ) {switch (optchar) {case 'h' : -table_usage (); +debug_table_usage (debug_table);return EXIT_SUCCESS ;case 'n' : read_opt &= ~USE_BAT_HOSTS ;
@@ -115,36 +104,37 @@ int handle_debug_table(char *mesh_iface, int argc, char **argv, }if (!sscanf (optarg,"%f" , &watch_interval)) { -printf ("Error - provided argument of -w is not a number\n" ); +printf ("Error - provided argument of '-%c' is not a number\n" , optchar);return EXIT_FAILURE ; }break ;case 't' : -if (table_usage != originators_usage) { -table_usage (); +if (debug_table !=BATCTL_TABLE_ORIGINATORS ) { +printf ("Error - unrecognised option '-%c'\n" , optchar); +debug_table_usage (debug_table);return EXIT_FAILURE ; } read_opt |=NO_OLD_ORIGS ;if (!sscanf (optarg,"%f" , &orig_timeout)) { -printf ("Error - provided argument of -t is not a number\n" ); +printf ("Error - provided argument of '-%c' is not a number\n" , optchar);return EXIT_FAILURE ; }break ;case '?' :if (optopt =='t' ) -printf ("Error - argument -t needs a number\n" ); +printf ("Error - option '-t' needs a number as argument\n" );else if (optopt =='w' ) { read_opt |=CLR_CONT_READ ;break ; }else -printf ("Error - unrecognised option -%c\n" , optopt); +printf ("Error - unrecognised option: '-%c'\n" , optopt);return EXIT_FAILURE ;default : -table_usage (); +debug_table_usage (debug_table);return EXIT_FAILURE ; } }
@@ -156,7 +146,8 @@ int handle_debug_table(char *mesh_iface, int argc, char **argv, }debugfs_make_path (DEBUG_BATIF_PATH_FMT "/" , mesh_iface, full_path,sizeof (full_path)); -return read_file (full_path, file_path, read_opt, orig_timeout, watch_interval); +return read_file (full_path, (char *)batctl_debug_tables[debug_table].debugfs_name, + read_opt, orig_timeout, watch_interval); }static void log_usage (void )
debug.h +19 -8
@@ -21,21 +21,32 @@#define DEBUG_BATIF_PATH_FMT "%s/batman_adv/%s" -#define DEBUG_ORIGINATORS "originators" -#define DEBUG_TRANSTABLE_LOCAL "transtable_local" -#define DEBUG_TRANSTABLE_GLOBAL "transtable_global" -#define DEBUG_BLA_CLAIM_TABLE "bla_claim_table" -#define DEBUG_BLA_BACKBONE_TABLE "bla_backbone_table" -#define DEBUG_GATEWAYS "gateways"#define DEBUG_VIS_DATA "vis_data"#define DEBUG_LOG "log" +enum batctl_debug_tables { +BATCTL_TABLE_ORIGINATORS , +BATCTL_TABLE_GATEWAYS , +BATCTL_TABLE_TRANSLOCAL , +BATCTL_TABLE_TRANSGLOBAL , +BATCTL_TABLE_BLA_CLAIMS , +BATCTL_TABLE_BLA_BACKBONES , +BATCTL_TABLE_NUM , +}; + +struct debug_table_data { +const char opt_long[OPT_LONG_MAX_LEN ]; +const char opt_short[OPT_SHORT_MAX_LEN ]; +const char debugfs_name[DEBUG_TABLE_PATH_MAX_LEN ]; +}; + +extern const struct debug_table_data batctl_debug_tables[BATCTL_TABLE_NUM ]; +void originators_usage (void );void trans_local_usage (void );void trans_global_usage (void );void bla_claim_table_usage (void );void bla_backbone_table_usage (void );void gateways_usage (void ); -int handle_debug_table (char *mesh_iface,int argc,char **argv, -char *file_path,void table_usage (void )); +int handle_debug_table (char *mesh_iface,int debug_table,int argc,char **argv);int log_print (char *mesh_iface,int argc,char **argv);
main.c +30 -44
122 lines not on this page · raw message
main.h +5 -0
@@ -27,6 +27,11 @@#define EXIT_NOSUCCESS 2 +#define OPT_LONG_MAX_LEN 25 +#define OPT_SHORT_MAX_LEN 5 + +#define DEBUG_TABLE_PATH_MAX_LEN 20 +#define __packed __attribute((packed))/* linux kernel compat */ extern char module_ver_path[];
Signature · 1 line
1.7.9.1
PATCH 2/3 batctl: unify settings handling and remove redundant code
Signed-off-by Marek Lindner <[email protected]>
--- functions.c | 2 +- main.c | 67 +++++++++++------------------- main.h | 1 + sys.c | 131 ++++++++++++++++++++++++++++++++-------------------------- sys.h | 30 +++++++++----- 5 files changed, 118 insertions(+), 113 deletions(-)
functions.c +1 -1
@@ -44,7 +44,7 @@ char *line_ptr = NULL;const char *sysfs_compile_out_param[] = {SYS_LOG ,SYS_LOG_LEVEL , -SYS_BRIDGE_LOOP_AVOIDANCE , + batctl_settings[BATCTL_SETTINGS_BLA ].sysfs_name,NULL , };
main.c +24 -43
101 lines not on this page · raw message
main.h +1 -0
@@ -31,6 +31,7 @@#define OPT_SHORT_MAX_LEN 5#define DEBUG_TABLE_PATH_MAX_LEN 20 +#define SETTINGS_PATH_MAX_LEN 25#define __packed __attribute((packed))/* linux kernel compat */
sys.c +72 -59
187 lines not on this page · raw message
sys.h +20 -10
@@ -23,20 +23,24 @@#define SYS_BATIF_PATH_FMT "/sys/class/net/%s/mesh/"#define SYS_LOG_LEVEL "log_level"#define SYS_LOG "log" -#define SYS_AGGR "aggregated_ogms" -#define SYS_BONDING "bonding" -#define SYS_BRIDGE_LOOP_AVOIDANCE "bridge_loop_avoidance"#define SYS_GW_MODE "gw_mode"#define SYS_GW_SEL "gw_sel_class"#define SYS_GW_BW "gw_bandwidth" -#define SYS_VIS_MODE "vis_mode" -#define SYS_ORIG_INTERVAL "orig_interval"#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_FRAG "fragmentation" -#define SYS_AP_ISOLA "ap_isolation" + +enum batctl_settings_list { +BATCTL_SETTINGS_ORIG_INTERVAL , +BATCTL_SETTINGS_AP_ISOLATION , +BATCTL_SETTINGS_BLA , +BATCTL_SETTINGS_VIS_MODE , +BATCTL_SETTINGS_AGGREGATION , +BATCTL_SETTINGS_BONDING , +BATCTL_SETTINGS_FRAGMENTATION , +BATCTL_SETTINGS_NUM , +};enum gw_modes {GW_MODE_OFF ,
@@ -44,8 +48,16 @@ enum gw_modes { GW_MODE_SERVER, }; +struct settings_data { +const char opt_long[OPT_LONG_MAX_LEN ]; +const char opt_short[OPT_SHORT_MAX_LEN ]; +const char sysfs_name[SETTINGS_PATH_MAX_LEN ]; +const char **params; +}; +extern const char *sysfs_param_enable[];extern const char *sysfs_param_server[]; +extern const struct settings_data batctl_settings[BATCTL_SETTINGS_NUM ];void aggregation_usage (void );void bonding_usage (void );
@@ -57,7 +69,5 @@ void vis_mode_usage(void);void orig_interval_usage (void );int interface (char *mesh_iface,int argc,char **argv);int handle_loglevel (char *mesh_iface,int argc,char **argv); -int handle_sys_setting (char *mesh_iface,int argc,char **argv, -char *file_path,void setting_usage (void ), -const char *sysfs_param[]); +int handle_sys_setting (char *mesh_iface,int setting,int argc,char **argv);int handle_gw_setting (char *mesh_iface,int argc,char **argv);
Signature · 1 line
1.7.9.1
PATCH 3/3 batctl: beef up man page
In reply to Marek LindnerSigned-off-by Marek Lindner <[email protected]>
--- README | 14 ++-- bisect.c | 4 +- debug.c | 8 +- main.c | 4 +- man/batctl.8 | 251 +++++++++++++++++++++++++++++++--------------------------- ping.c | 4 +- sys.c | 12 ++-- tcpdump.c | 4 +- traceroute.c | 4 +- 9 files changed, 160 insertions(+), 145 deletions(-)
README +7 -7
@@ -81,8 +81,8 @@ batctl ping Sends a Layer 2 batman-adv ping to check round trip time and connectivity -Usage: batctl ping [options] mac|bat-host -options: +Usage: batctl ping [parameters] mac|bat-host +parameters: -c ping packet count -h print this help -i interval in seconds
@@ -106,7 +106,7 @@ batctl traceroute Traceroute sends 3 packets to each hop, awaits the answers and prints out the response times. -Usage: batctl traceroute [options] mac|bat-host +Usage: batctl traceroute [parameters] mac|bat-host Example:
@@ -128,8 +128,8 @@ batctl tcpdump tcpdump layer 2 and/or layer 3 traffic on the given interface -Usage: batctl tcpdump [options] interface [interface] -options: +Usage: batctl tcpdump [parameters] interface [interface] +parameters: -c compat filter - only display packets matching own compat version (14) -h print this help -n don't convert addresses to bat-host names
@@ -182,8 +182,8 @@ bat-host name) to only see data connected to this originator. If "-n" was given batctl will not replace the mac addresses with bat-host names in the output. -Usage: batctl bisect [options] <file1> <file2> .. <fileN> -options: +Usage: batctl bisect [parameters] <file1> <file2> .. <fileN> +parameters: -h print this help -l run a loop detection of given mac address or bat-host (default) -n don't convert addresses to bat-host names
bisect.c +2 -2
@@ -37,8 +37,8 @@ static struct bat_node *curr_bat_node = NULL;static void bisect_usage (void ) { -printf ("Usage: batctl bisect [options] <file1> <file2> .. <fileN>\n" ); -printf ("options:\n" ); +printf ("Usage: batctl bisect [parameters] <file1> <file2> .. <fileN>\n" ); +printf ("parameters:\n" );printf (" \t -h print this help\n" );printf (" \t -l run a loop detection of given mac address or bat-host (default)\n" );printf (" \t -n don't convert addresses to bat-host names\n" );
debug.c +4 -4
@@ -68,9 +68,9 @@ const struct debug_table_data batctl_debug_tables[BATCTL_TABLE_NUM] = {void debug_table_usage (int debug_table) { -printf ("Usage: batctl [options] %s|%s\n" , +printf ("Usage: batctl [options] %s|%s [parameters]\n" , batctl_debug_tables[debug_table].opt_long, batctl_debug_tables[debug_table].opt_short); -printf ("options:\n" ); +printf ("parameters:\n" );printf (" \t -h print this help\n" );printf (" \t -n don't replace mac addresses with bat-host names\n" );printf (" \t -w [interval] watch mode - refresh the table continuously\n" );
@@ -152,8 +152,8 @@ int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv)static void log_usage (void ) { -printf ("Usage: batctl [options] log \n" ); -printf ("options:\n" ); +printf ("Usage: batctl [options] log [parameters]\n" ); +printf ("parameters:\n" );printf (" \t -h print this help\n" );printf (" \t -n don't replace mac addresses with bat-host names\n" ); }
main.c +2 -2
@@ -47,10 +47,10 @@ void print_usage(void) {int i, opt_indent; -printf ("Usage: batctl [options] command|debug table \n" ); +printf ("Usage: batctl [options] command|debug table [parameters]\n" );printf ("options:\n" );printf (" \t-m mesh interface (default 'bat0')\n" ); -printf (" \t-h print this help (or 'batctl <command|debug table> -h' for the specific help)\n" ); +printf (" \t-h print this help (or 'batctl <command|debug table> -h' for the parameter help)\n" );printf (" \t-v print version\n" );printf ("\n" );
man/batctl.8 +133 -118
316 lines not on this page · raw message
ping.c +2 -2
@@ -44,8 +44,8 @@ char is_aborted = 0;void ping_usage (void ) { -printf ("Usage: batctl ping [options] mac|bat-host \n" ); -printf ("options:\n" ); +printf ("Usage: batctl [options] ping [parameters] mac|bat-host \n" ); +printf ("parameters:\n" );printf (" \t -c ping packet count \n" );printf (" \t -h print this help\n" );printf (" \t -i interval in seconds\n" );
sys.c +6 -6
@@ -97,8 +97,8 @@ const struct settings_data batctl_settings[BATCTL_SETTINGS_NUM] = {static void interface_usage (void ) { -printf ("Usage: batctl interface [options] [add|del iface(s)] \n" ); -printf ("options:\n" ); +printf ("Usage: batctl [options] interface [parameters] [add|del iface(s)]\n" ); +printf ("parameters:\n" );printf (" \t -h print this help\n" ); }
@@ -237,8 +237,8 @@ err:static void log_level_usage (void ) { -printf ("Usage: batctl [options] loglevel [level[ level[ level]]...]\n" ); -printf ("options:\n" ); +printf ("Usage: batctl [options] loglevel [parameters] [level[ level[ level]]...]\n" ); +printf ("parameters:\n" );printf (" \t -h print this help\n" );printf ("levels:\n" );printf (" \t none Debug logging is disabled\n" );
@@ -324,7 +324,7 @@ out:void settings_usage (int setting) { -printf ("Usage: batctl [options] %s|%s" , +printf ("Usage: batctl [options] %s|%s [parameters]" , (char *)batctl_settings[setting].opt_long, (char *)batctl_settings[setting].opt_short);if (batctl_settings[setting].params == sysfs_param_enable)
@@ -334,7 +334,7 @@ void settings_usage(int setting)else printf ("\n" ); -printf ("options:\n" ); +printf ("parameters:\n" );printf (" \t -h print this help\n" ); }
tcpdump.c +2 -2
@@ -59,8 +59,8 @@ static void parse_eth_hdr(unsigned char *packet_buff, ssize_t buff_len, int readstatic void tcpdump_usage (void ) { -printf ("Usage: batctl tcpdump [options] interface [interface]\n" ); -printf ("options:\n" ); +printf ("Usage: batctl tcpdump [parameters] interface [interface]\n" ); +printf ("parameters:\n" );printf (" \t -c compat filter - only display packets matching own compat version (%i)\n" ,BATADV_COMPAT_VERSION );printf (" \t -h print this help\n" );printf (" \t -n don't convert addresses to bat-host names\n" );
traceroute.c +2 -2
@@ -43,8 +43,8 @@void traceroute_usage (void ) { -printf ("Usage: batctl traceroute [options] mac|bat-host \n" ); -printf ("options:\n" ); +printf ("Usage: batctl [options] traceroute [parameters] mac|bat-host \n" ); +printf ("parameters:\n" );printf (" \t -h print this help\n" );printf (" \t -n don't convert addresses to bat-host names\n" ); }
Signature · 1 line
1.7.9.1
Marek Lindner
AppliedQuoted 8 lines · On Saturday, June 23, 2012 18:40:10 Marek Lindner wrote:
Signed-off-by Marek Lindner <[email protected]>--- debug.c | 111 +++++++++++++++++++++++++++++---------------------------------- debug.h | 27 +++++++++++---- main.c | 74 +++++++++++++++++------------------------- main.h | 5 +++ 4 files changed, 105 insertions(+), 112 deletions(-)
Applied in revision 4f6745d.
Regards,
Marek
Marek Lindner
AppliedRe: [B.A.T.M.A.N.] [PATCH 2/3] batctl: unify settings handling and remove redundant code
In reply to Marek LindnerQuoted 9 lines · On Saturday, June 23, 2012 18:40:11 Marek Lindner wrote:
Signed-off-by Marek Lindner <[email protected]>--- functions.c | 2 +- main.c | 67 +++++++++++------------------- main.h | 1 + sys.c | 131 ++++++++++++++++++++++++++++++++-------------------------- sys.h | 30 +++++++++----- 5 files changed, 118 insertions(+), 113 deletions(-)
Applied in revision 5ec3a91.
Regards,
Marek
Marek Lindner
AppliedRe: [B.A.T.M.A.N.] [PATCH 3/3] batctl: beef up man page
In reply to Marek LindnerQuoted 13 lines · On Saturday, June 23, 2012 18:40:12 Marek Lindner wrote:
Signed-off-by Marek Lindner <[email protected]>--- README | 14 ++-- bisect.c | 4 +- debug.c | 8 +- main.c | 4 +- man/batctl.8 | 251 +++++++++++++++++++++++++++++++--------------------------- ping.c | 4 +- sys.c | 12 ++-- tcpdump.c | 4 +- traceroute.c | 4 +- 9 files changed, 160 insertions(+), 145 deletions(-)
Applied in revision 40cc393.
Regards,
Marek