Author: marek Date: 2010-07-07 01:07:45 +0200 (Wed, 07 Jul 2010) New Revision: 1732
Modified: trunk/batctl/debug.c trunk/batctl/functions.c trunk/batctl/functions.h trunk/batctl/sys.c Log: batctl: Add timeout filtering option for originators
This commit introduces the -t switch for originator table output. It makes use of the new last-seen field in batman-adv, the user can specify a timeout interval in seconds (with 3 digits precision before and after a possible dot) if he/she considers a node as dead after this time. (of course this is just influencing the displaying and not actually declearing a node as dead for routing decisions)
Signed-off-by: Linus L?\195?\188ssing linus.luessing@web.de
Modified: trunk/batctl/debug.c =================================================================== --- trunk/batctl/debug.c 2010-07-01 20:29:52 UTC (rev 1731) +++ trunk/batctl/debug.c 2010-07-06 23:07:45 UTC (rev 1732) @@ -40,6 +40,7 @@ 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 - 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) @@ -74,8 +75,9 @@ int optchar, read_opt = USE_BAT_HOSTS; char full_path[MAX_PATH+1]; char *debugfs_mnt; + float orig_timeout;
- while ((optchar = getopt(argc, argv, "hnw")) != -1) { + while ((optchar = getopt(argc, argv, "hnwt:")) != -1) { switch (optchar) { case 'h': table_usage(); @@ -86,6 +88,21 @@ case 'w': read_opt |= CLR_CONT_READ; break; + case 't': + if (table_usage != originators_usage) { + table_usage(); + 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"); + return EXIT_FAILURE; + } + break; + case '?': + if (optopt == 't' && table_usage == originators_usage) + return EXIT_FAILURE; default: table_usage(); return EXIT_FAILURE; @@ -99,7 +116,7 @@ }
debugfs_make_path(DEBUG_BATIF_PATH "/", full_path, sizeof(full_path)); - return read_file(full_path, file_path, read_opt); + return read_file(full_path, file_path, read_opt, orig_timeout); }
static void log_usage(void) @@ -137,7 +154,7 @@ }
debugfs_make_path(DEBUG_BATIF_PATH "/", full_path, sizeof(full_path)); - res = read_file(full_path, DEBUG_LOG, read_opt); + res = read_file(full_path, DEBUG_LOG, read_opt, 0);
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");
Modified: trunk/batctl/functions.c =================================================================== --- trunk/batctl/functions.c 2010-07-01 20:29:52 UTC (rev 1731) +++ trunk/batctl/functions.c 2010-07-06 23:07:45 UTC (rev 1732) @@ -117,11 +117,12 @@ return EXIT_FAILURE; }
-int read_file(char *dir, char *fname, int read_opt) +int read_file(char *dir, char *fname, int read_opt, float orig_timeout) { struct ether_addr *mac_addr; struct bat_host *bat_host; int res = EXIT_FAILURE; + float last_seen; char full_path[500], *buff_ptr, *space_ptr, extra_char; size_t len = 0; ssize_t read; @@ -157,6 +158,12 @@ if (read_opt & USE_READ_BUFF) break;
+ /* skip timed out originators */ + if (read_opt & NO_OLD_ORIGS) + if (sscanf(line_ptr, "%*s %f", &last_seen) + && (last_seen > orig_timeout)) + continue; + if (!(read_opt & USE_BAT_HOSTS)) { printf("%s", line_ptr); continue;
Modified: trunk/batctl/functions.h =================================================================== --- trunk/batctl/functions.h 2010-07-01 20:29:52 UTC (rev 1731) +++ trunk/batctl/functions.h 2010-07-06 23:07:45 UTC (rev 1732) @@ -33,7 +33,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 read_file(char *dir, char *path, int read_opt); +int read_file(char *dir, char *path, int read_opt, float orig_timeout); int write_file(char *dir, char *fname, char *arg1, char *arg2);
extern char *line_ptr; @@ -46,4 +46,5 @@ LOG_MODE = 0x08, USE_READ_BUFF = 0x10, SILENCE_ERRORS = 0x20, + NO_OLD_ORIGS = 0x40, };
Modified: trunk/batctl/sys.c =================================================================== --- trunk/batctl/sys.c 2010-07-01 20:29:52 UTC (rev 1731) +++ trunk/batctl/sys.c 2010-07-06 23:07:45 UTC (rev 1732) @@ -79,7 +79,7 @@
while ((iface_dir = readdir(iface_base_dir)) != NULL) { snprintf(path_buff, PATH_BUFF_LEN, SYS_MESH_IFACE_FMT, iface_dir->d_name); - res = read_file("", path_buff, SINGLE_READ | USE_READ_BUFF | SILENCE_ERRORS); + res = read_file("", path_buff, SINGLE_READ | USE_READ_BUFF | SILENCE_ERRORS, 0); if (res != EXIT_SUCCESS) continue;
@@ -93,7 +93,7 @@ line_ptr = NULL;
snprintf(path_buff, PATH_BUFF_LEN, SYS_IFACE_STATUS_FMT, iface_dir->d_name); - res = read_file("", path_buff, SINGLE_READ | USE_READ_BUFF | SILENCE_ERRORS); + res = read_file("", path_buff, SINGLE_READ | USE_READ_BUFF | SILENCE_ERRORS, 0); if (res != EXIT_SUCCESS) { printf("<error reading status>\n"); continue; @@ -196,7 +196,7 @@ goto out; }
- res = read_file(SYS_BATIF_PATH, SYS_LOG_LEVEL, SINGLE_READ | USE_READ_BUFF); + res = read_file(SYS_BATIF_PATH, SYS_LOG_LEVEL, SINGLE_READ | USE_READ_BUFF, 0);
if (res != EXIT_SUCCESS) goto out; @@ -271,7 +271,7 @@ }
if (argc == 1) - return read_file(SYS_BATIF_PATH, file_path, SINGLE_READ); + return read_file(SYS_BATIF_PATH, file_path, SINGLE_READ, 0);
if (!sysfs_param) goto write_file;