Signed-off-by: Marek Lindner lindner_marek@yahoo.de --- debug.c | 111 +++++++++++++++++++++++++++++---------------------------------- debug.h | 27 +++++++++++---- main.c | 74 +++++++++++++++++------------------------- main.h | 5 +++ 4 files changed, 105 insertions(+), 112 deletions(-)
diff --git a/debug.c b/debug.c index 5dca633..8aa36c2 100644 --- a/debug.c +++ b/debug.c @@ -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) diff --git a/debug.h b/debug.h index 2c6d24c..36badf7 100644 --- a/debug.h +++ b/debug.h @@ -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); diff --git a/main.c b/main.c index 929b762..1482dbe 100644 --- a/main.c +++ b/main.c @@ -43,20 +43,23 @@ char mesh_dfl_iface[] = "bat0"; char module_ver_path[] = "/sys/module/batman_adv/version";
-void print_usage(void) { - printf("Usage: batctl [options] commands \n"); +void print_usage(void) +{ + int i; + + printf("Usage: batctl [options] command|debug table \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-v print version\n"); + printf("\n"); + printf("commands:\n"); printf(" \tinterface|if [add|del iface(s)]\tdisplay or modify the interface settings\n"); - printf(" \toriginators|o \tdisplay the originator table\n"); printf(" \tinterval|it [orig_interval] \tdisplay or modify the originator interval (in ms)\n"); printf(" \tloglevel|ll [level] \tdisplay or modify the log level\n"); printf(" \tlog|l \tread the log produced by the kernel module\n"); printf(" \tgw_mode|gw [mode] \tdisplay or modify the gateway mode\n"); - printf(" \tgateways|gwl \tdisplay the gateway server list\n"); - printf(" \ttranslocal|tl \tdisplay the local translation table\n"); - printf(" \ttransglobal|tg \tdisplay the global translation table\n"); - printf(" \tclaimtable|cl \tdisplay the bridge loop avoidance claim table\n"); - printf(" \tbackbonetable|bbl \tdisplay the bridge loop avoidance backbone table\n"); printf(" \tvis_mode|vm [mode] \tdisplay or modify the status of the VIS server\n"); printf(" \tvis_data|vd [dot|JSON] \tdisplay the VIS data in dot or JSON format\n"); printf(" \taggregation|ag [0|1] \tdisplay or modify the packet aggregation setting\n"); @@ -65,20 +68,22 @@ void print_usage(void) { printf(" \tfragmentation|f [0|1] \tdisplay or modify the fragmentation mode setting\n"); printf(" \tap_isolation|ap [0|1] \tdisplay or modify the ap isolation mode setting\n"); printf("\n"); + + printf("debug tables: \tdisplay the corresponding debug table\n"); + for (i = 0; i < BATCTL_TABLE_NUM; i++) + printf(" \t%s|%s\n", batctl_debug_tables[i].opt_long, batctl_debug_tables[i].opt_short); + + printf("\n"); printf(" \tstatistics|s \tprint mesh statistics\n"); printf(" \tping|p <destination> \tping another batman adv host via layer 2\n"); printf(" \ttraceroute|tr <destination> \ttraceroute another batman adv host via layer 2\n"); printf(" \ttcpdump|td <interface> \ttcpdump layer 2 traffic on the given interface\n"); printf(" \tbisect <file1> .. <fileN>\tanalyze given log files for routing stability\n"); - printf("options:\n"); - printf(" \t-m mesh interface (default 'bat0')\n"); - printf(" \t-h print this help (or 'batctl <command> -h' for the command specific help)\n"); - printf(" \t-v print version\n"); }
int main(int argc, char **argv) { - int ret = EXIT_FAILURE; + int i, ret = EXIT_FAILURE; char *mesh_iface = mesh_dfl_iface;
if ((argc > 1) && (strcmp(argv[1], "-m") == 0)) { @@ -140,31 +145,6 @@ int main(int argc, char **argv)
ret = interface(mesh_iface, argc - 1, argv + 1);
- } else if ((strcmp(argv[1], "originators") == 0) || (strcmp(argv[1], "o") == 0)) { - - ret = handle_debug_table(mesh_iface, argc - 1, argv + 1, - DEBUG_ORIGINATORS, originators_usage); - - } else if ((strcmp(argv[1], "translocal") == 0) || (strcmp(argv[1], "tl") == 0)) { - - ret = handle_debug_table(mesh_iface, argc - 1, argv + 1, - DEBUG_TRANSTABLE_LOCAL, trans_local_usage); - - } else if ((strcmp(argv[1], "transglobal") == 0) || (strcmp(argv[1], "tg") == 0)) { - - ret = handle_debug_table(mesh_iface, argc - 1, argv + 1, - DEBUG_TRANSTABLE_GLOBAL, trans_global_usage); - - } else if ((strcmp(argv[1], "claimtable") == 0) || (strcmp(argv[1], "cl") == 0)) { - - ret = handle_debug_table(mesh_iface, argc - 1, argv + 1, - DEBUG_BLA_CLAIM_TABLE, bla_claim_table_usage); - } else if ((strcmp(argv[1], "backbonetable") == 0) || (strcmp(argv[1], "bbl") == 0)) { - - ret = handle_debug_table(mesh_iface, argc - 1, argv + 1, - DEBUG_BLA_BACKBONE_TABLE, - bla_backbone_table_usage); - } else if ((strcmp(argv[1], "loglevel") == 0) || (strcmp(argv[1], "ll") == 0)) {
ret = handle_loglevel(mesh_iface, argc - 1, argv + 1); @@ -191,11 +171,6 @@ int main(int argc, char **argv)
ret = handle_gw_setting(mesh_iface, argc - 1, argv + 1);
- } else if ((strcmp(argv[1], "gateways") == 0) || (strcmp(argv[1], "gwl") == 0)) { - - ret = handle_debug_table(mesh_iface, argc - 1, argv + 1, - DEBUG_GATEWAYS, gateways_usage); - } else if ((strcmp(argv[1], "aggregation") == 0) || (strcmp(argv[1], "ag") == 0)) {
ret = handle_sys_setting(mesh_iface, argc - 1, argv + 1, @@ -230,10 +205,21 @@ int main(int argc, char **argv) ret = bisect(argc - 1, argv + 1);
} else { - printf("Error - no command specified\n"); + + for (i = 0; i < BATCTL_TABLE_NUM; i++) { + if ((strcmp(argv[1], batctl_debug_tables[i].opt_long) != 0) && + (strcmp(argv[1], batctl_debug_tables[i].opt_short) != 0)) + continue; + + ret = handle_debug_table(mesh_iface, i, argc - 1, argv + 1); + goto out; + } + + printf("Error - no valid command or debug table specified: %s\n", argv[1]); print_usage(); }
+out: return ret;
err: diff --git a/main.h b/main.h index 4819cf4..782ffde 100644 --- a/main.h +++ b/main.h @@ -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[];
Signed-off-by: Marek Lindner lindner_marek@yahoo.de --- functions.c | 2 +- main.c | 67 +++++++++++------------------- main.h | 1 + sys.c | 131 ++++++++++++++++++++++++++++++++-------------------------- sys.h | 30 +++++++++----- 5 files changed, 118 insertions(+), 113 deletions(-)
diff --git a/functions.c b/functions.c index 36a4d40..d08c7a0 100644 --- a/functions.c +++ b/functions.c @@ -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, };
diff --git a/main.c b/main.c index 1482dbe..ae0b3d2 100644 --- a/main.c +++ b/main.c @@ -45,7 +45,7 @@ char module_ver_path[] = "/sys/module/batman_adv/version";
void print_usage(void) { - int i; + int i, opt_indent;
printf("Usage: batctl [options] command|debug table \n"); printf("options:\n"); @@ -56,17 +56,24 @@ void print_usage(void)
printf("commands:\n"); printf(" \tinterface|if [add|del iface(s)]\tdisplay or modify the interface settings\n"); - printf(" \tinterval|it [orig_interval] \tdisplay or modify the originator interval (in ms)\n"); + for (i = 0; i < BATCTL_SETTINGS_NUM; i++) { + printf(" \t%s|%s", batctl_settings[i].opt_long, batctl_settings[i].opt_short); + opt_indent = strlen(batctl_settings[i].opt_long) + strlen(batctl_settings[i].opt_short); + + if (batctl_settings[i].params == sysfs_param_enable) + printf("%*s display or modify %s setting\n", + 31 - opt_indent, "[0|1]", batctl_settings[i].opt_long); + else if (batctl_settings[i].params == sysfs_param_server) + printf("%*s display or modify %s setting\n", + 41 - opt_indent, "[client|server]", batctl_settings[i].opt_long); + else + printf(" display or modify %s setting\n", + batctl_settings[i].opt_long); + } printf(" \tloglevel|ll [level] \tdisplay or modify the log level\n"); printf(" \tlog|l \tread the log produced by the kernel module\n"); printf(" \tgw_mode|gw [mode] \tdisplay or modify the gateway mode\n"); - printf(" \tvis_mode|vm [mode] \tdisplay or modify the status of the VIS server\n"); printf(" \tvis_data|vd [dot|JSON] \tdisplay the VIS data in dot or JSON format\n"); - printf(" \taggregation|ag [0|1] \tdisplay or modify the packet aggregation setting\n"); - printf(" \tbonding|b [0|1] \tdisplay or modify the bonding mode setting\n"); - printf(" \tbridge_loop_avoidance|bl [0|1] \tdisplay or modify the bridge loop avoidance setting\n"); - printf(" \tfragmentation|f [0|1] \tdisplay or modify the fragmentation mode setting\n"); - printf(" \tap_isolation|ap [0|1] \tdisplay or modify the ap isolation mode setting\n"); printf("\n");
printf("debug tables: \tdisplay the corresponding debug table\n"); @@ -153,16 +160,6 @@ int main(int argc, char **argv)
ret = log_print(mesh_iface, argc - 1, argv + 1);
- } else if ((strcmp(argv[1], "interval") == 0) || (strcmp(argv[1], "it") == 0)) { - - ret = handle_sys_setting(mesh_iface, argc - 1, argv + 1, - SYS_ORIG_INTERVAL, orig_interval_usage, NULL); - - } else if ((strcmp(argv[1], "vis_mode") == 0) || (strcmp(argv[1], "vm") == 0)) { - - ret = handle_sys_setting(mesh_iface, argc - 1, argv + 1, - SYS_VIS_MODE, vis_mode_usage, sysfs_param_server); - } else if ((strcmp(argv[1], "vis_data") == 0) || (strcmp(argv[1], "vd") == 0)) {
ret = vis_data(mesh_iface, argc - 1, argv + 1); @@ -171,31 +168,6 @@ int main(int argc, char **argv)
ret = handle_gw_setting(mesh_iface, argc - 1, argv + 1);
- } else if ((strcmp(argv[1], "aggregation") == 0) || (strcmp(argv[1], "ag") == 0)) { - - ret = handle_sys_setting(mesh_iface, argc - 1, argv + 1, - SYS_AGGR, aggregation_usage, sysfs_param_enable); - - } else if ((strcmp(argv[1], "bonding") == 0) || (strcmp(argv[1], "b") == 0)) { - - ret = handle_sys_setting(mesh_iface, argc - 1, argv + 1, - SYS_BONDING, bonding_usage, sysfs_param_enable); - - } else if ((strcmp(argv[1], "bridge_loop_avoidance") == 0) || (strcmp(argv[1], "bl") == 0)) { - - ret = handle_sys_setting(mesh_iface, argc - 1, argv + 1, - SYS_BRIDGE_LOOP_AVOIDANCE, bridge_loop_avoidance_usage, sysfs_param_enable); - - } else if ((strcmp(argv[1], "fragmentation") == 0) || (strcmp(argv[1], "f") == 0)) { - - ret = handle_sys_setting(mesh_iface, argc - 1, argv + 1, - SYS_FRAG, fragmentation_usage, sysfs_param_enable); - - } else if ((strcmp(argv[1], "ap_isolation") == 0) || (strcmp(argv[1], "ap") == 0)) { - - ret = handle_sys_setting(mesh_iface, argc - 1, argv + 1, - SYS_AP_ISOLA, ap_isolation_usage, sysfs_param_enable); - } else if ((strcmp(argv[1], "statistics") == 0) || (strcmp(argv[1], "s") == 0)) {
ret = ioctl_statistics_get(mesh_iface); @@ -206,6 +178,15 @@ int main(int argc, char **argv)
} else {
+ for (i = 0; i < BATCTL_SETTINGS_NUM; i++) { + if ((strcmp(argv[1], batctl_settings[i].opt_long) != 0) && + (strcmp(argv[1], batctl_settings[i].opt_short) != 0)) + continue; + + ret = handle_sys_setting(mesh_iface, i, argc - 1, argv + 1); + goto out; + } + for (i = 0; i < BATCTL_TABLE_NUM; i++) { if ((strcmp(argv[1], batctl_debug_tables[i].opt_long) != 0) && (strcmp(argv[1], batctl_debug_tables[i].opt_short) != 0)) diff --git a/main.h b/main.h index 782ffde..4c8b60b 100644 --- a/main.h +++ b/main.h @@ -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 */
diff --git a/sys.c b/sys.c index 5702c6c..63315fe 100644 --- a/sys.c +++ b/sys.c @@ -49,6 +49,52 @@ const char *sysfs_param_server[] = { NULL, };
+const struct settings_data batctl_settings[BATCTL_SETTINGS_NUM] = { + { + .opt_long = "orig_interval", + .opt_short = "it", + .sysfs_name = "orig_interval", + .params = NULL, + }, + { + .opt_long = "ap_isolation", + .opt_short = "ap", + .sysfs_name = "ap_isolation", + .params = sysfs_param_enable, + }, + { + .opt_long = "bridge_loop_avoidance", + .opt_short = "bl", + .sysfs_name = "bridge_loop_avoidance", + .params = sysfs_param_enable, + }, + { + .opt_long = "vis_mode", + .opt_short = "vm", + .sysfs_name = "vis_mode", + .params = sysfs_param_server, + }, + { + .opt_long = "aggregation", + .opt_short = "ag", + .sysfs_name = "aggregated_ogms", + .params = sysfs_param_enable, + }, + { + .opt_long = "bonding", + .opt_short = "b", + .sysfs_name = "bonding", + .params = sysfs_param_enable, + }, + { + .opt_long = "fragmentation", + .opt_short = "f", + .sysfs_name = "fragmentation", + .params = sysfs_param_enable, + }, + +}; + static void interface_usage(void) { printf("Usage: batctl interface [options] [add|del iface(s)] \n"); @@ -276,65 +322,23 @@ out: return res; }
-void aggregation_usage(void) -{ - printf("Usage: batctl [options] aggregation [0|1]\n"); - printf("options:\n"); - printf(" \t -h print this help\n"); -} - -void bonding_usage(void) -{ - printf("Usage: batctl [options] bonding [0|1]\n"); - printf("options:\n"); - printf(" \t -h print this help\n"); -} - -void bridge_loop_avoidance_usage(void) -{ - printf("Usage: batctl [options] bridge_loop_avoidance [0|1]\n"); - printf("options:\n"); - printf(" \t -h print this help\n"); -} - -void gw_mode_usage(void) -{ - printf("Usage: batctl [options] gw_mode [mode] [sel_class|bandwidth]\n"); - printf("options:\n"); - printf(" \t -h print this help\n"); -} - -void vis_mode_usage(void) -{ - printf("Usage: batctl [options] vis_mode [mode]\n"); - printf("options:\n"); - printf(" \t -h print this help\n"); -} - -void orig_interval_usage(void) +void settings_usage(int setting) { - printf("Usage: batctl [options] interval \n"); - printf("options:\n"); - printf(" \t -h print this help\n"); -} + printf("Usage: batctl [options] %s|%s", + (char *)batctl_settings[setting].opt_long, (char *)batctl_settings[setting].opt_short);
-void fragmentation_usage(void) -{ - printf("Usage: batctl [options] fragmentation [0|1]\n"); - printf("options:\n"); - printf(" \t -h print this help\n"); -} + if (batctl_settings[setting].params == sysfs_param_enable) + printf(" [0|1]\n"); + else if (batctl_settings[setting].params == sysfs_param_server) + printf(" [client|server]\n"); + else + printf("\n");
-void ap_isolation_usage(void) -{ - printf("Usage: batctl [options] ap_isolation [0|1]\n"); printf("options:\n"); printf(" \t -h print this help\n"); }
-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 optchar, res = EXIT_FAILURE; char *path_buff; @@ -343,10 +347,10 @@ int handle_sys_setting(char *mesh_iface, int argc, char **argv, while ((optchar = getopt(argc, argv, "h")) != -1) { switch (optchar) { case 'h': - setting_usage(); + settings_usage(setting); return EXIT_SUCCESS; default: - setting_usage(); + settings_usage(setting); return EXIT_FAILURE; } } @@ -355,14 +359,15 @@ int handle_sys_setting(char *mesh_iface, int argc, char **argv, snprintf(path_buff, PATH_BUFF_LEN, SYS_BATIF_PATH_FMT, mesh_iface);
if (argc == 1) { - res = read_file(path_buff, file_path, NO_FLAGS, 0, 0); + res = read_file(path_buff, (char *)batctl_settings[setting].sysfs_name, + NO_FLAGS, 0, 0); goto out; }
- if (!sysfs_param) + if (!batctl_settings[setting].params) goto write_file;
- ptr = sysfs_param; + ptr = batctl_settings[setting].params; while (*ptr) { if (strcmp(*ptr, argv[1]) == 0) goto write_file; @@ -373,7 +378,7 @@ int handle_sys_setting(char *mesh_iface, int argc, char **argv, printf("Error - the supplied argument is invalid: %s\n", argv[1]); printf("The following values are allowed:\n");
- ptr = sysfs_param; + ptr = batctl_settings[setting].params; while (*ptr) { printf(" * %s\n", *ptr); ptr++; @@ -382,13 +387,21 @@ int handle_sys_setting(char *mesh_iface, int argc, char **argv, goto out;
write_file: - res = write_file(path_buff, file_path, argv[1], argc > 2 ? argv[2] : NULL); + res = write_file(path_buff, (char *)batctl_settings[setting].sysfs_name, + argv[1], argc > 2 ? argv[2] : NULL);
out: free(path_buff); return res; }
+void gw_mode_usage(void) +{ + printf("Usage: batctl [options] gw_mode [mode] [sel_class|bandwidth]\n"); + printf("options:\n"); + printf(" \t -h print this help\n"); +} + int handle_gw_setting(char *mesh_iface, int argc, char **argv) { int optchar, res = EXIT_FAILURE; diff --git a/sys.h b/sys.h index f48902e..df9795e 100644 --- a/sys.h +++ b/sys.h @@ -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);
On Saturday, June 23, 2012 18:40:11 Marek Lindner wrote:
Signed-off-by: Marek Lindner lindner_marek@yahoo.de
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
Signed-off-by: Marek Lindner lindner_marek@yahoo.de --- 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(-)
diff --git a/README b/README index b06aacf..86c9f20 100644 --- a/README +++ b/README @@ -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 diff --git a/bisect.c b/bisect.c index b505b1a..8bc9c65 100644 --- a/bisect.c +++ b/bisect.c @@ -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"); diff --git a/debug.c b/debug.c index 8aa36c2..9b5146f 100644 --- a/debug.c +++ b/debug.c @@ -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"); } diff --git a/main.c b/main.c index ae0b3d2..1086f8e 100644 --- a/main.c +++ b/main.c @@ -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");
diff --git a/man/batctl.8 b/man/batctl.8 index af30b67..1a11508 100644 --- a/man/batctl.8 +++ b/man/batctl.8 @@ -23,30 +23,23 @@ .SH NAME batctl - B.A.T.M.A.N. advanced control and management tool .SH SYNOPSIS -.B batctl -.I [\fIbatctl-options\fP]\ \fIcommand\fP\ [\fIcommand-options\fP] +.B batctl [\fIoptions\fP]\ \fIcommand\fP|\fIdebug\ table\fP\ [\fIparameters\fP] .br .SH DESCRIPTION -batctl offers a convenient way to configure the batman-adv kernel -module as well as displaying debug information such as originator -tables, translation tables and the debug log. In combination with a -bat-hosts file batctl allows the use of host names instead of MAC -addresses. +batctl offers a convenient way to configure the batman-adv kernel module as well as displaying debug information +such as originator tables, translation tables and the debug log. In combination with a bat-hosts file batctl allows +the use of host names instead of MAC addresses. .PP -B.A.T.M.A.N. advanced operates on layer 2. Thus all hosts -participating in the virtual switched network are transparently -connected together for all protocols above layer 2. Therefore the -common diagnosis tools do not work as expected. To overcome these -problems batctl contains the commands \fBping\fP, \fBtraceroute\fP, -\fBtcpdump\fP which provide similar functionality to the normal -\fBping\fP(1), \fBtraceroute\fP(1), \fBtcpdump\fP(1) commands, but -modified to layer 2 behaviour or using the B.A.T.M.A.N. advanced -protocol. +B.A.T.M.A.N. advanced operates on layer 2. Thus all hosts participating in the virtual switched network are transparently +connected together for all protocols above layer 2. Therefore the common diagnosis tools do not work as expected. To +overcome these problems batctl contains the commands \fBping\fP, \fBtraceroute\fP, \fBtcpdump\fP which provide similar +functionality to the normal \fBping\fP(1), \fBtraceroute\fP(1), \fBtcpdump\fP(1) commands, but modified to layer 2 +behaviour or using the B.A.T.M.A.N. advanced protocol. .PP .PP .SH OPTIONS .TP -.I \fBbatctl-options: +.I \fBoptions: -m specify mesh interface (default 'bat0') .br -h print general batctl help @@ -55,23 +48,58 @@ protocol. .br .TP .I \fBcommands: -.IP "\fBinterface\fP|\fBif\fP [\fBadd\fP|\fBdel iface(s)\fP]" -If no parameter is given or the first parameter is neither "add" nor "del" the current interface settings are displayed. In order to add or delete interfaces specify "add" or "del" as first argument and append the interface names you wish to add or delete. +.IP "\fBinterface\fP|\fBif\fP [\fBadd\fP|\fBdel iface(s)\fP]" +If no parameter is given or the first parameter is neither "add" nor "del" the current interface settings are displayed. +In order to add or delete interfaces specify "add" or "del" as first argument and append the interface names you wish to +add or delete. Multiple interfaces can be specified. +.br +.IP "\fBorig_interval\fP|\fBit\fP [\fBinterval\fP]" +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]" +If no parameter is given the current ap isolation setting is displayed. Otherwise the parameter is used to enable or +disable ap isolation. +.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 +or disable the bridge loop avoidance. Bridge loop avoidance support has to be enabled when compiling the module otherwise +this option won't be available. .br -.IP "\fBoriginators\fP|\fBo\fP [\fB-w\fP [\fI\interval\fP]][\fB-n\fP][\fB-t\fP]" -Once started batctl will display the list of announced originators in the network. Use the "-w" option to let batctl refresh the list every second or add a number to let it refresh at a custom interval in seconds (with optional decimal places). If "-n" is given batctl will not replace the MAC addresses with bat-host names in the output. The "-t" option filters all originators that have not been seen for the specified amount of seconds (with optional decimal places) from the output. +.IP "\fBvis_mode|vm\fP [\fBclient|server\fP]\fP" +If no parameter is given the current vis mode is displayed otherwise the parameter is used to set the vis mode. +.br +.IP "\fBaggregation\fP|\fBag\fP [\fB0\fP|\fB1\fP]" +If no parameter is given the current aggregation setting is displayed. Otherwise the parameter is used to enable or disable +OGM packet aggregation. .br -.IP "\fBinterval\fP|\fBit\fP [\fBorig_interval\fP]" -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. +.IP "\fBbonding\fP|\fBb\fP [\fB0\fP|\fB1\fP]" +If no parameter is given the current bonding mode setting is displayed. Otherwise the parameter is used to enable or disable +the bonding mode. .br -.IP "\fBloglevel\fP|\fBll\fP [\fBlevel\fP[ \fBlevel\fP[ \fBlevel\fP]] \fB...\fP]" -If no parameter is given the current log level settings are displayed otherwise the parameter(s) is/are used to set the log level. Level 'none' disables all verbose logging. Level 'batman' enables messages related to routing / flooding / broadcasting. Level 'routes' enables messages related to routes being added / changed / deleted. Level 'tt' enables messages related to translation table operations. Level 'bla' enables messages related to the bridge loop avoidance. Level 'all' enables all messages. The messages are sent to the batman-adv debug log. Use \fBbatctl log\fP to see them. Make sure to have debugging output enabled when compiling the module otherwise the output as well as the loglevel options won't be available. +.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. .br -.IP "\fBlog\fP|\fBl\fP [\fB-n\fP]\fP" -batctl will read the batman-adv debug log which has to be compiled into the kernel module. If "-n" is given batctl will not replace the MAC addresses with bat-host names in the output. +.IP "\fBloglevel\fP|\fBll\fP [\fBlevel\fP[ \fBlevel\fP[ \fBlevel\fP]] \fB...\fP]" +If no parameter is given the current log level settings are displayed otherwise the parameter(s) is/are used to set the log +level. Level 'none' disables all verbose logging. Level 'batman' enables messages related to routing / flooding / broadcasting. +Level 'routes' enables messages related to routes being added / changed / deleted. Level 'tt' enables messages related to +translation table operations. Level 'bla' enables messages related to the bridge loop avoidance. Level 'all' enables all +messages. The messages are sent to the batman-adv debug log. Use \fBbatctl log\fP to retrieve it. Make sure to have debugging +output enabled when compiling the module otherwise the output as well as the loglevel options won't be available. .br -.IP "\fBgw_mode|gw\fP [\fBoff\fP|\fBclient\fP|\fBserver\fP] [\fBsel_class|bandwidth\fP]\fP" -If no parameter is given the current gateway mode is displayed otherwise the parameter is used to set the gateway mode. The second (optional) argument specifies the selection class (if 'client' was the first argument) or the gateway bandwidth (if 'server' was the first argument). If the node is a server this parameter is used to inform other nodes in the network about this node's internet connection bandwidth. Just enter any number (optionally followed by "kbit" or "mbit") and the batman-adv module will guess your appropriate gateway class. Use "/" to separate the down(hy and upload rates. You can omit the upload rate and the module will assume an upload of download / 5. +.IP "\fBlog\fP|\fBl\fP [\fB-n\fP]\fP" +batctl will read the batman-adv debug log which has to be compiled into the kernel module. If "-n" is given batctl will not +replace the MAC addresses with bat-host names in the output. +.br +.IP "\fBgw_mode|gw\fP [\fBoff\fP|\fBclient\fP|\fBserver\fP] [\fBsel_class|bandwidth\fP]\fP" +If no parameter is given the current gateway mode is displayed otherwise the parameter is used to set the gateway mode. The +second (optional) argument specifies the selection class (if 'client' was the first argument) or the gateway bandwidth (if +'server' was the first argument). If the node is a server this parameter is used to inform other nodes in the network about +this node's internet connection bandwidth. Just enter any number (optionally followed by "kbit" or "mbit") and the batman-adv +module will guess your appropriate gateway class. Use "/" to separate the down(hy and upload rates. You can omit the upload +rate and the module will assume an upload of download / 5. .RS 17 default: 2000 -> gateway class 20 .RE @@ -86,7 +114,8 @@ examples: 5000 -> gateway class 49 5mbit/1mbit .RE .RS 7 -If the node is a gateway client the parameter will decide which criterias to consider when the batman-adv module has to choose between different internet connections announced by the aforementioned servers. +If the node is a gateway client the parameter will decide which criterias to consider when the batman-adv module has to choose +between different internet connections announced by the aforementioned servers. .RE .RS 17 default: 20 -> late switch (TQ 20) @@ -108,63 +137,62 @@ chooses the gateway with the best link quality but switches to another gateway a .RE XX -> late switch connection .RS 7 -chooses the gateway with the best link quality but switches to another gateway as soon as a better one is found which is at least XX TQ better than the currently selected gateway (XX has to be a number between 3 and 256). +chooses the gateway with the best link quality but switches to another gateway as soon as a better one is found which is at +least XX TQ better than the currently selected gateway (XX has to be a number between 3 and 256). .RE .RE .br -.IP "\fBgateways|gwl\fP [\fB-w\fP [\fI\interval\fP]][\fB-n\fP]" -Once started batctl will display the list of announced gateways in the network. Use the "-w" option to let batctl refresh the list every second or add a number to let it refresh at a custom interval in seconds (with optional decimal places). If "-n" was given batctl will not replace the mac addresses with bat-host names in the output. -.br -.IP "\fBtranslocal\fP|\fBtl\fP [\fB-w\fP [\fI\interval\fP]][\fB-n\fP]" -Display the local translation table. batctl will refresh the list every second if the "-w" option was given or add a number to let it refresh at a custom interval in seconds (with optional decimal places). Use "-n" to let batctl not replace the MAC addresses with bat-host names in the output. -.br -.IP "\fBtransglobal\fP|\fBtg\fP [\fB-w\fP [\fI\interval\fP]][\fB-n\fP]" -Display the global translation table. batctl will refresh the list every second if the "-w" option was given or add a number to let it refresh at a custom interval in seconds (with optional decimal places). Use "-n" to let batctl not replace the MAC addresses with bat-host names in the output. -.br -.IP "\fBclaimtable\fP|\fBcl\fP [\fB-w\fP [\fI\interval\fP]][\fB-n\fP]" -Display the bridge loop avoidance claim table. batctl will refresh the list every second if the "-w" option was given or add a number to let it refresh at a custom interval in seconds (with optional decimal places). Use "-n" to let batctl not replace the MAC addresses with bat-host names in the output. -.br -.IP "\fBbackbonetable\fP|\fBbbl\fP [\fB-w\fP [\fI\interval\fP]][\fB-n\fP]" -Display the bridge loop avoidance backbone table. batctl will refresh the list every second if the "-w" option was given or add a number to let it refresh at a custom interval in seconds (with optional decimal places). Use "-n" to let batctl not replace the MAC addresses with bat-host names in the output. -.br -.IP "\fBvis_mode|vm\fP [\fBmode\fP]\fP" -If no parameter is given the current vis mode is displayed otherwise the parameter is used to set the vis mode. -.br -.IP "\fBvis_data|vd dot\fP [\fB-n\fP|\fB--numbers\fP][\fB-T\fP|\fB--no-TT\fP][\fB-2\fP|\fB--no-2nd\fP]" -Display the visualisation data in graphviz \fBdot\fP(1) format. If -"--numbers" or "-n" is given batctl will not replace the MAC -addresses with bat-host names in the output. With "--no-TT" or -"-T" the TT entries are not displayed, so the pure mesh topology can -be seen. With "--no-2nd" or "-2" a dot cluster is not formed around -primary and secondary addresses from the same device. -.br -.IP "\fBvis_data|vd json\fP [\fB-n\fP|\fB--numbers\fP][\fB-T\fP|\fB--no-TT\fP][\fB-2\fP|\fB--no-2nd\fP]" -Display the visualisation data in JSON format. If "--numbers" or -"-n" is given batctl will not replace the MAC addresses with bat-host -names in the output. With "--no-TT" or "-T" the TT entries are -not displayed, so the pure mesh topology can be seen. With -"--no-2nd" or "-2" a dot cluster is not formed around primary and -secondary addresses from the same device. -.br -.IP "\fBaggregation\fP|\fBag\fP [\fB1\fP|\fB0\fP]" -If no parameter is given the current aggregation setting is displayed. Otherwise the parameter is used to enable or disable packet aggregation. +.IP "\fBvis_data|vd dot\fP [\fB-n\fP|\fB--numbers\fP][\fB-T\fP|\fB--no-TT\fP][\fB-2\fP|\fB--no-2nd\fP]" +Display the visualisation data in graphviz \fBdot\fP(1) format. If "--numbers" or "-n" is given batctl will not replace +the MAC addresses with bat-host names in the output. With "--no-TT" or "-T" the TT entries are not displayed, so the pure +mesh topology can be seen. With "--no-2nd" or "-2" a dot cluster is not formed around primary and secondary addresses +from the same device. .br -.IP "\fBbonding\fP|\fBb\fP [\fB1\fP|\fB0\fP]" -If no parameter is given the current bonding mode setting is displayed. Otherwise the parameter is used to enable or disable the bonding mode. -.br -.IP "\fBbridge_loop_avoidance\fP|\fBbl\fP [\fB1\fP|\fB0\fP]" -If no parameter is given the current bridge loop avoidance setting is displayed. Otherwise the parameter is used to enable or disable the bridge loop avoidance. -.br -.IP "\fBfragmentation\fP|\fBf\fP [\fB1\fP|\fB0\fP]" -If no parameter is given the current fragmentation mode setting is displayed. Otherwise the parameter is used to enable or disable fragmentation. -.br -.IP "\fBap_isolation\fP|\fBap\fP [\fB1\fP|\fB0\fP]" -If no parameter is given the current ap isolation setting is displayed. Otherwise the parameter is used to enable or disable ap isolation. +.PP +.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 preferrably have mounted the debugfs to a well-known mountpoint. If debugfs is not +mounted batctl will attempt to do this step for you. + +All of the debug tables support the following options: +.RS 10 +-w refresh the list every second or add a number to let it refresh at a custom interval in seconds (with optional decimal places) +.RE +.RS 10 +-n do not replace the MAC addresses with bat-host names in the output +.RE + +.RS 7 +The originator table also supports the "-t" filter option to remove all originators from the output that have not been seen +for the specified amount of seconds (with optional decimal places). + +List of debug tables: +.RS 10 +- originators|o +.RE +.RS 10 +- gateways|gwl +.RE +.RS 10 +- translocal|tl +.RE +.RS 10 +- transglobal|tg +.RE +.RS 10 +- claimtable|cl (compile time option) +.RE +.RS 10 +- backbonetable|bbt (compile time option) +.RE +.RE .br .IP "\fBstatistics\fP|\fBs\fP" -Retrieve traffic counters from batman-adv kernel module. The output may vary depending on which features have -been compiled into the kernel module. For example, if the distributed arp table (short: dat) wasn't selected -as an option at compile time its counters won't be shown. +Retrieve traffic counters from batman-adv kernel module. The output may vary depending on which features have been compiled +into the kernel module. For example, if the distributed arp table (short: dat) wasn't selected as an option at compile time +its counters won't be shown. .br Each module subsystem has its own counters which are indicated by their prefixes: .RS 15 @@ -180,24 +208,19 @@ dat - distributed arp table counters All counters without a prefix concern payload (pure user data) traffic. .RE .br -.IP "\fBping\fP|\fBp\fP [\fB-c count\fP][\fB-i interval\fP][\fB-t time\fP][\fB-R\fP] \fBMAC_address\fP|\fBbat-host_name\fP" -Layer 2 ping of a MAC address or bat-host name. batctl will try to -find the bat-host name if the given parameter was not a MAC -address. The "-c" option tells batctl how man pings should be sent -before the program exits. Without the "-c" option batctl will continue -pinging without end. Use CTRL + C to stop it. With "-i" and "-t" -you can set the default interval between pings and the timeout time -for replies, both in seconds. When run with "-R", the route taken by -the ping messages will be recorded. +.IP "\fBping\fP|\fBp\fP [\fB-c count\fP][\fB-i interval\fP][\fB-t time\fP][\fB-R\fP] \fBMAC_address\fP|\fBbat-host_name\fP" +Layer 2 ping of a MAC address or bat-host name. batctl will try to find the bat-host name if the given parameter was +not a MAC address. The "-c" option tells batctl how man pings should be sent before the program exits. Without the "-c" +option batctl will continue pinging without end. Use CTRL + C to stop it. With "-i" and "-t" you can set the default +interval between pings and the timeout time for replies, both in seconds. When run with "-R", the route taken by the ping +messages will be recorded. .br -.IP "\fBtraceroute\fP|\fBtr\fP [\fB-n\fP] \fBMAC_address\fP|\fBbat-host_name\fP" -Layer 2 traceroute to a MAC address or bat-host name. batctl will try -to find the bat-host name if the given parameter was not a MAC -address. batctl will send 3 packets to each host and display the -response time. If "-n" is given batctl will not replace the MAC -addresses with bat-host names in the output. +.IP "\fBtraceroute\fP|\fBtr\fP [\fB-n\fP] \fBMAC_address\fP|\fBbat-host_name\fP" +Layer 2 traceroute to a MAC address or bat-host name. batctl will try to find the bat-host name if the given parameter +was not a MAC address. batctl will send 3 packets to each host and display the response time. If "-n" is given batctl will +not replace the MAC addresses with bat-host names in the output. .br -.IP "\fBtcpdump\fP|\fBtd\fP [\fB-c\fP][\fB-n\fP][\fB-p filter\fP][\fB-x filter\fP] \fBinterface ...\fP" +.IP "\fBtcpdump\fP|\fBtd\fP [\fB-c\fP][\fB-n\fP][\fB-p filter\fP][\fB-x filter\fP] \fBinterface ...\fP" batctl will display all packets that are seen on the given interface(s). A variety of options to filter the output are available: To only print packets that match the compatibility number of batctl specify the "-c" (compat filter) option. If "-n" is given batctl will not replace the MAC addresses with bat-host names in the output. To filter @@ -231,27 +254,21 @@ except specified). The following packet types are available: Example: batctl td <interface> -p 129 -> only display batman ogm packets and non batman packets .RE .br -.IP "\fBbisect\fP [\fB-l MAC\fP][\fB-t MAC\fP][\fB-r MAC\fP][\fB-s min\fP [\fB- max\fP]][\fB-o MAC\fP][\fB-n\fP] \fBlogfile1\fP [\fBlogfile2\fP ... \fBlogfileN\fP]" -Analyses the logfiles to build a small internal database of all sent -sequence numbers and routing table changes. This database can then be -analyzed in a number of different ways. With "-l" the database can be -used to search for routing loops. Use "-t" to trace OGMs of a host -throughout the network. Use "-r" to display routing tables of the -nodes. The option "-s" can be used to limit the output to a range of -sequence numbers, between min and max, or to one specific sequence -number, min. Furthermore using "-o" you can filter the output to a -specified originator. If "-n" is given batctl will not replace the -MAC addresses with bat-host names in the output. +.IP "\fBbisect\fP [\fB-l MAC\fP][\fB-t MAC\fP][\fB-r MAC\fP][\fB-s min\fP [\fB- max\fP]][\fB-o MAC\fP][\fB-n\fP] \fBlogfile1\fP [\fBlogfile2\fP ... \fBlogfileN\fP]" +Analyses the logfiles to build a small internal database of all sent sequence numbers and routing table changes. This +database can then be analyzed in a number of different ways. With "-l" the database can be used to search for routing +loops. Use "-t" to trace OGMs of a host throughout the network. Use "-r" to display routing tables of the nodes. The +option "-s" can be used to limit the output to a range of sequence numbers, between min and max, or to one specific +sequence number, min. Furthermore using "-o" you can filter the output to a specified originator. If "-n" is given +batctl will not replace the MAC addresses with bat-host names in the output. .br .SH FILES .TP .I "\fBbat-hosts\fP" -This file is similar to the /etc/hosts file. You can write one MAC -address and one host name per line. batctl will search for bat-hosts -in /etc, your home directory and the current directory. The found data -is used to match MAC address to your provided host name or replace MAC -addresses in debug output and logs. Host names are much easier to -remember than MAC addresses. +This file is similar to the /etc/hosts file. You can write one MAC address and one host name per line. batctl will search +for bat-hosts in /etc, your home directory and the current directory. The found data is used to match MAC address to your +provided host name or replace MAC addresses in debug output and logs. Host names are much easier to remember than MAC +addresses. .SH SEE ALSO .BR ping (1), .BR traceroute (1), @@ -259,9 +276,7 @@ remember than MAC addresses. .BR dmesg (1), .BR dot (1) .SH AUTHOR -batctl was written by Andreas Langer an.langer@gmx.de and Marek -Lindner lindner_marek@yahoo.de. +batctl was written by Andreas Langer an.langer@gmx.de and Marek Lindner lindner_marek@yahoo.de. .PP -This manual page was written by Simon Wunderlich -siwu@hrz.tu-chemnitz.de, Marek Lindner lindner_marek@yahoo.de and +This manual page was written by Simon Wunderlich siwu@hrz.tu-chemnitz.de, Marek Lindner lindner_marek@yahoo.de and Andrew Lunn andrew@lunn.ch diff --git a/ping.c b/ping.c index 85b4137..9f64a8f 100644 --- a/ping.c +++ b/ping.c @@ -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"); diff --git a/sys.c b/sys.c index 63315fe..caeb908 100644 --- a/sys.c +++ b/sys.c @@ -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"); }
diff --git a/tcpdump.c b/tcpdump.c index cbae9bb..1cd9a4e 100644 --- a/tcpdump.c +++ b/tcpdump.c @@ -59,8 +59,8 @@ static void parse_eth_hdr(unsigned char *packet_buff, ssize_t buff_len, int read
static 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"); diff --git a/traceroute.c b/traceroute.c index 31f77b0..c1aaad8 100644 --- a/traceroute.c +++ b/traceroute.c @@ -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"); }
On Saturday, June 23, 2012 18:40:12 Marek Lindner wrote:
Signed-off-by: Marek Lindner lindner_marek@yahoo.de
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
On Saturday, June 23, 2012 18:40:10 Marek Lindner wrote:
Signed-off-by: Marek Lindner lindner_marek@yahoo.de
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
b.a.t.m.a.n@lists.open-mesh.org