Author: marek Date: 2010-06-28 14:25:03 +0200 (Mon, 28 Jun 2010) New Revision: 1728
Modified: trunk/batctl/debug.c trunk/batctl/debug.h trunk/batctl/functions.c trunk/batctl/man/batctl.8 trunk/batctl/sys.c trunk/batctl/sys.h Log: batctl: add debug log support
batctl offers the possibilities to read the debug log file in the debugfs folder of batman-adv (given that the debug log was compiled in).
Signed-off-by: Marek Lindner lindner_marek@yahoo.de
Modified: trunk/batctl/debug.c =================================================================== --- trunk/batctl/debug.c 2010-06-28 12:25:01 UTC (rev 1727) +++ trunk/batctl/debug.c 2010-06-28 12:25:03 UTC (rev 1728) @@ -101,3 +101,46 @@ debugfs_make_path(DEBUG_BATIF_PATH "/", full_path, sizeof(full_path)); return read_file(full_path, file_path, read_opt); } + +static void log_usage(void) +{ + printf("Usage: batctl [options] log \n"); + printf("options:\n"); + printf(" \t -h print this help\n"); + printf(" \t -n don't replace mac addresses with bat-host names\n"); +} + +int log_print(int argc, char **argv) +{ + int optchar, res, read_opt = USE_BAT_HOSTS | LOG_MODE; + char full_path[MAX_PATH+1]; + char *debugfs_mnt; + + while ((optchar = getopt(argc, argv, "hn")) != -1) { + switch (optchar) { + case 'h': + log_usage(); + return EXIT_SUCCESS; + case 'n': + read_opt &= ~USE_BAT_HOSTS; + break; + default: + log_usage(); + return EXIT_FAILURE; + } + } + + debugfs_mnt = debugfs_mount(NULL); + if (!debugfs_mnt) { + printf("Error - can't mount or find debugfs\n"); + return EXIT_FAILURE; + } + + debugfs_make_path(DEBUG_BATIF_PATH "/", full_path, sizeof(full_path)); + res = read_file(full_path, DEBUG_LOG, read_opt); + + if ((res != EXIT_SUCCESS) && (errno == ENOENT)) + printf("To read the debug log you need to compile the module with debugging enabled (see the README)\n"); + + return res; +}
Modified: trunk/batctl/debug.h =================================================================== --- trunk/batctl/debug.h 2010-06-28 12:25:01 UTC (rev 1727) +++ trunk/batctl/debug.h 2010-06-28 12:25:03 UTC (rev 1728) @@ -26,9 +26,11 @@ #define DEBUG_TRANSTABLE_GLOBAL "transtable_global" #define DEBUG_GATEWAYS "gateways" #define DEBUG_VIS_DATA "vis_data" +#define DEBUG_LOG "log"
void originators_usage(void); void trans_local_usage(void); void trans_global_usage(void); void gateways_usage(void); int handle_debug_table(int argc, char **argv, char *file_path, void table_usage(void)); +int log_print(int argc, char **argv);
Modified: trunk/batctl/functions.c =================================================================== --- trunk/batctl/functions.c 2010-06-28 12:25:01 UTC (rev 1727) +++ trunk/batctl/functions.c 2010-06-28 12:25:03 UTC (rev 1728) @@ -99,24 +99,6 @@ return get_name_by_macaddr(mac_addr, read_opt); }
-static int check_proc_dir(char *dir) -{ - struct stat st; - - if (stat("/proc/", &st) != 0) { - printf("Error - the folder '/proc' was not found on the system\n"); - printf("Please make sure that the proc filesystem is properly mounted\n"); - return EXIT_FAILURE; - } - - if (stat(dir, &st) == 0) - return EXIT_SUCCESS; - - printf("Error - the folder '%s' was not found within the proc filesystem\n", dir); - printf("Please make sure that the batman-adv kernel module is loaded\n"); - return EXIT_FAILURE; -} - static int check_sys_dir(char *dir) { struct stat st; @@ -148,10 +130,7 @@ if (read_opt & USE_BAT_HOSTS) bat_hosts_init();
- if (strstr(dir, "/proc/")) { - if (check_proc_dir(dir) != EXIT_SUCCESS) - goto out; - } else if (strstr(dir, "/sys/")) { + if (strstr(dir, "/sys/")) { if (check_sys_dir(dir) != EXIT_SUCCESS) goto out; } @@ -178,12 +157,6 @@ if (read_opt & USE_READ_BUFF) break;
- if (read_opt & LOG_MODE) { - /* omit log lines which don't start with the correct tag */ - if (strncmp(line_ptr, BATMAN_ADV_TAG, strlen(BATMAN_ADV_TAG)) != 0) - continue; - } - if (!(read_opt & USE_BAT_HOSTS)) { printf("%s", line_ptr); continue; @@ -267,10 +240,7 @@ char full_path[500]; ssize_t write_len;
- if (strstr(dir, "/proc/")) { - if (check_proc_dir(dir) != EXIT_SUCCESS) - goto out; - } else if (strstr(dir, "/sys/")) { + if (strstr(dir, "/sys/")) { if (check_sys_dir(dir) != EXIT_SUCCESS) goto out; }
Modified: trunk/batctl/man/batctl.8 =================================================================== --- trunk/batctl/man/batctl.8 2010-06-28 12:25:01 UTC (rev 1727) +++ trunk/batctl/man/batctl.8 2010-06-28 12:25:03 UTC (rev 1728) @@ -63,10 +63,10 @@ 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 "\fBloglevel\fP|\fBll\fP [\fBlevel\fP]" -If no parameter is given the current log level settings are displayed otherwise the parameter is used to set the log level. Level 0 disables all verbose logging. Level 1 enables messages related to routing / flooding / broadcasting. Level 2 enables messages related to route or hna added / changed / deleted. Level 3 enables all messages. The messages are sent to the kernel log. Use \fBdmesg\fP(1) 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. +If no parameter is given the current log level settings are displayed otherwise the parameter is used to set the log level. Level 0 disables all verbose logging. Level 1 enables messages related to routing / flooding / broadcasting. Level 2 enables messages related to route or hna added / changed / deleted. Level 3 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. .br -.IP "\fBlog\fP|\fBl\fP [\fBlogfile\fP][\fB-w\fP][\fB-n\fP]\fP" -batctl will read the file logfile, or stdin if the logfile parameter is not given, applying filtering so only the B.A.T.M.A.N. Advanced messages are displayed. Once the end of the file has been reached batctl will exit unless the option "-w" was specified which causes batctl to continue reading the file and print log output whenever new log data has been appended to the file. +.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] [\fBgw_class\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 gateway class. Its function depends on whether the node is a server or a client. 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.
Modified: trunk/batctl/sys.c =================================================================== --- trunk/batctl/sys.c 2010-06-28 12:25:01 UTC (rev 1727) +++ trunk/batctl/sys.c 2010-06-28 12:25:03 UTC (rev 1728) @@ -169,46 +169,6 @@ return EXIT_FAILURE; }
-static void log_usage(void) -{ - printf("Usage: batctl [options] log [logfile]\n"); - printf("Note: if no logfile was specified stdin is read"); - 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 watch mode - read the log file continuously\n"); -} - -int log_print(int argc, char **argv) -{ - int optchar, read_opt = USE_BAT_HOSTS | LOG_MODE; - int found_args = 1; - - while ((optchar = getopt(argc, argv, "hnw")) != -1) { - switch (optchar) { - case 'h': - log_usage(); - return EXIT_SUCCESS; - case 'n': - read_opt &= ~USE_BAT_HOSTS; - found_args += 1; - break; - case 'w': - read_opt |= CONT_READ; - found_args += 1; - break; - default: - log_usage(); - return EXIT_FAILURE; - } - } - - if (argc > found_args) - return read_file("", argv[found_args], read_opt); - else - return read_file("", "/proc/self/fd/0", read_opt); -} - static void log_level_usage(void) { printf("Usage: batctl [options] loglevel [level]\n"); @@ -232,11 +192,11 @@ }
if (argc != 1) { - res = write_file(SYS_MODULE_PATH, SYS_LOG_LEVEL, argv[1], NULL); + res = write_file(SYS_BATIF_PATH, SYS_LOG_LEVEL, argv[1], NULL); goto out; }
- res = read_file(SYS_MODULE_PATH, SYS_LOG_LEVEL, SINGLE_READ | USE_READ_BUFF); + res = read_file(SYS_BATIF_PATH, SYS_LOG_LEVEL, SINGLE_READ | USE_READ_BUFF);
if (res != EXIT_SUCCESS) goto out;
Modified: trunk/batctl/sys.h =================================================================== --- trunk/batctl/sys.h 2010-06-28 12:25:01 UTC (rev 1727) +++ trunk/batctl/sys.h 2010-06-28 12:25:03 UTC (rev 1728) @@ -20,9 +20,8 @@ */
-#define SYS_MODULE_PATH "/sys/module/batman_adv/" #define SYS_BATIF_PATH "/sys/class/net/bat0/mesh/" -#define SYS_LOG_LEVEL "parameters/debug" +#define SYS_LOG_LEVEL "log_level" #define SYS_LOG "log" #define SYS_AGGR "aggregated_ogms" #define SYS_BONDING "bonding" @@ -41,7 +40,6 @@ void gw_mode_usage(void); void vis_mode_usage(void); void orig_interval_usage(void); -int log_print(int argc, char **argv); int interface(int argc, char **argv); int handle_loglevel(int argc, char **argv); int handle_sys_setting(int argc, char **argv, char *file_path,