Author: marek
Date: 2009-10-26 20:48:30 +0000 (Mon, 26 Oct 2009)
New Revision: 1459
Modified:
trunk/batctl/bisect.c
trunk/batctl/bisect.h
trunk/batctl/man/batctl.8
Log:
[batctl] bisect - add orig event filter
Modified: trunk/batctl/bisect.c
===================================================================
--- trunk/batctl/bisect.c 2009-10-26 19:17:52 UTC (rev 1458)
+++ trunk/batctl/bisect.c 2009-10-26 20:48:30 UTC (rev 1459)
@@ -40,6 +40,7 @@
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");
+ printf(" \t -o only display orig events that affect given mac address or bat-host\n");
printf(" \t -r print routing tables of given mac address or bat-host\n");
printf(" \t -s seqno range to limit the output\n");
printf(" \t -t trace seqnos of given mac address or bat-host\n");
@@ -777,7 +778,7 @@
return -1;
}
-static void loop_detection(char *loop_orig, int seqno_min, int seqno_max, int read_opt)
+static void loop_detection(char *loop_orig, int seqno_min, int seqno_max, char *filter_orig, int read_opt)
{
struct bat_node *bat_node;
struct orig_event *orig_event;
@@ -795,12 +796,18 @@
get_name_by_macstr(loop_orig, read_opt));
if ((seqno_min == -1) && (seqno_max == -1))
- printf("[all sequence numbers]\n");
+ printf("[all sequence numbers]");
else if (seqno_min == seqno_max)
- printf("[sequence number: %i]\n", seqno_min);
+ printf("[sequence number: %i]", seqno_min);
else
- printf("[sequence number range: %i-%i]\n", seqno_min, seqno_max);
+ printf("[sequence number range: %i-%i]", seqno_min, seqno_max);
+ if (!compare_name(filter_orig, check_orig))
+ printf(" [filter originator: %s]",
+ get_name_by_macstr(filter_orig, read_opt));
+
+ printf("\n");
+
while (NULL != (hashit = hash_iterate(node_hash, hashit))) {
bat_node = hashit->bucket->data;
@@ -815,6 +822,10 @@
if (bat_node == orig_event->orig_node)
continue;
+ if (!compare_name(filter_orig, check_orig) &&
+ !compare_name(filter_orig, orig_event->orig_node->name))
+ continue;
+
/* we might have no log file from this node */
if (list_empty(&orig_event->event_list)) {
fprintf(stderr, "No seqno data of originator '%s' - skipping\n",
@@ -926,23 +937,35 @@
}
static void seqno_trace_print(struct list_head_first *trace_list, char *trace_orig,
- int seqno_min, int seqno_max, int read_opt)
+ int seqno_min, int seqno_max, char *filter_orig, int read_opt)
{
struct seqno_trace *seqno_trace;
- char head[MAX_LINE];
+ char head[MAX_LINE], check_orig[NAME_LEN];
int i;
+ /* if no option was given filter_orig is empty */
+ memset(check_orig, 0, NAME_LEN);
+
printf("Sequence number flow of originator: %s ",
get_name_by_macstr(trace_orig, read_opt));
if ((seqno_min == -1) && (seqno_max == -1))
- printf("[all sequence numbers]\n");
+ printf("[all sequence numbers]");
else if (seqno_min == seqno_max)
- printf("[sequence number: %i]\n", seqno_min);
+ printf("[sequence number: %i]", seqno_min);
else
- printf("[sequence number range: %i-%i]\n", seqno_min, seqno_max);
+ printf("[sequence number range: %i-%i]", seqno_min, seqno_max);
+ if (!compare_name(filter_orig, check_orig))
+ printf(" [filter originator: %s]",
+ get_name_by_macstr(filter_orig, read_opt));
+
+ printf("\n");
+
list_for_each_entry(seqno_trace, trace_list, list) {
+ if (!seqno_trace->print)
+ continue;
+
printf("+=> %s (seqno %i)\n",
get_name_by_macstr(trace_orig, read_opt),
seqno_trace->seqno);
@@ -1109,6 +1132,7 @@
INIT_LIST_HEAD(&seqno_trace->list);
seqno_trace->seqno = seqno_event->seqno;
+ seqno_trace->print = 0;
seqno_trace->seqno_trace_neigh.num_neighbors = 0;
@@ -1126,7 +1150,7 @@
}
static int seqno_trace_add(struct list_head_first *trace_list, struct bat_node *bat_node,
- struct seqno_event *seqno_event)
+ struct seqno_event *seqno_event, char print_trace)
{
struct seqno_trace *seqno_trace = NULL, *seqno_trace_tmp = NULL, *seqno_trace_prev = NULL;
struct seqno_trace_neigh *seqno_trace_neigh;
@@ -1157,6 +1181,9 @@
list_add_before(&seqno_trace_prev->list, &seqno_trace_tmp->list, &seqno_trace->list);
}
+ if (print_trace)
+ seqno_trace->print = print_trace;
+
seqno_trace_neigh = seqno_trace_find_neigh(seqno_event->neigh,
seqno_event->prev_sender,
&seqno_trace->seqno_trace_neigh);
@@ -1177,7 +1204,7 @@
return 0;
}
-static void trace_seqnos(char *trace_orig, int seqno_min, int seqno_max, int read_opt)
+static void trace_seqnos(char *trace_orig, int seqno_min, int seqno_max, char *filter_orig, int read_opt)
{
struct bat_node *bat_node;
struct orig_event *orig_event;
@@ -1185,8 +1212,11 @@
struct hash_it_t *hashit = NULL;
struct list_head_first trace_list;
struct seqno_trace *seqno_trace, *seqno_trace_tmp;
+ char check_orig[NAME_LEN], print_trace;
int res;
+ /* if no option was given filter_orig is empty */
+ memset(check_orig, 0, NAME_LEN);
INIT_LIST_HEAD_FIRST(trace_list);
while (NULL != (hashit = hash_iterate(node_hash, hashit))) {
@@ -1212,15 +1242,22 @@
if ((seqno_max != -1) && (seqno_event->seqno > seqno_max))
continue;
- res = seqno_trace_add(&trace_list, bat_node, seqno_event);
+ /* if no filter option was given all seqno traces are to be printed */
+ print_trace = compare_name(filter_orig, check_orig);
+ if (!compare_name(filter_orig, check_orig) &&
+ compare_name(filter_orig, bat_node->name))
+ print_trace = 1;
+
+ res = seqno_trace_add(&trace_list, bat_node, seqno_event, print_trace);
+
if (res < 1)
goto out;
}
}
}
- seqno_trace_print(&trace_list, trace_orig, seqno_min, seqno_max, read_opt);
+ seqno_trace_print(&trace_list, trace_orig, seqno_min, seqno_max, filter_orig, read_opt);
out:
list_for_each_entry_safe(seqno_trace, seqno_trace_tmp, &trace_list, list) {
@@ -1231,23 +1268,33 @@
return;
}
-static void print_rt_tables(char *rt_orig, int seqno_min, int seqno_max, int read_opt)
+static void print_rt_tables(char *rt_orig, int seqno_min, int seqno_max, char *filter_orig, int read_opt)
{
struct bat_node *bat_node;
struct rt_table *rt_table;
struct seqno_event *seqno_event;
+ char check_orig[NAME_LEN];
int i;
+ /* if no option was given filter_orig is empty */
+ memset(check_orig, 0, NAME_LEN);
+
printf("Routing tables of originator: %s ",
get_name_by_macstr(rt_orig, read_opt));
if ((seqno_min == -1) && (seqno_max == -1))
- printf("[all sequence numbers]\n");
+ printf("[all sequence numbers]");
else if (seqno_min == seqno_max)
- printf("[sequence number: %i]\n", seqno_min);
+ printf("[sequence number: %i]", seqno_min);
else
- printf("[sequence number range: %i-%i]\n", seqno_min, seqno_max);
+ printf("[sequence number range: %i-%i]", seqno_min, seqno_max);
+ if (!compare_name(filter_orig, check_orig))
+ printf(" [filter originator: %s]",
+ get_name_by_macstr(filter_orig, read_opt));
+
+ printf("\n");
+
bat_node = node_get(rt_orig);
if (!bat_node)
goto out;
@@ -1259,6 +1306,10 @@
list_for_each_entry(rt_table, &bat_node->rt_table_list, list) {
seqno_event = rt_table->rt_hist->seqno_event;
+ if (!compare_name(filter_orig, check_orig) &&
+ !compare_name(filter_orig, seqno_event->orig->name))
+ continue;
+
if ((seqno_min != -1) && (seqno_event->seqno < seqno_min))
continue;
@@ -1347,11 +1398,12 @@
int read_opt = USE_BAT_HOSTS, num_parsed_files;
int tmp_seqno, seqno_max = -1, seqno_min = -1;
char *trace_orig_ptr = NULL, *rt_orig_ptr = NULL, *loop_orig_ptr = NULL;
- char orig[NAME_LEN], *dash_ptr;
+ char orig[NAME_LEN], filter_orig[NAME_LEN], *dash_ptr, *filter_orig_ptr = NULL;
memset(orig, 0, NAME_LEN);
+ memset(filter_orig, 0, NAME_LEN);
- while ((optchar = getopt(argc, argv, "hl:nr:s:t:")) != -1) {
+ while ((optchar = getopt(argc, argv, "hl:no:r:s:t:")) != -1) {
switch (optchar) {
case 'h':
bisect_usage();
@@ -1364,6 +1416,10 @@
read_opt &= ~USE_BAT_HOSTS;
found_args += 1;
break;
+ case 'o':
+ filter_orig_ptr = optarg;
+ found_args += ((*((char*)(optarg - 1)) == optchar ) ? 1 : 2);
+ break;
case 'r':
rt_orig_ptr = optarg;
found_args += ((*((char*)(optarg - 1)) == optchar ) ? 1 : 2);
@@ -1453,6 +1509,13 @@
goto err;
}
+ if (filter_orig_ptr) {
+ res = get_orig_addr(filter_orig_ptr, filter_orig);
+
+ if (res < 1)
+ goto err;
+ }
+
while (argc > found_args) {
res = parse_log_file(argv[found_args]);
@@ -1468,11 +1531,11 @@
}
if (trace_orig_ptr)
- trace_seqnos(orig, seqno_min, seqno_max, read_opt);
+ trace_seqnos(orig, seqno_min, seqno_max, filter_orig, read_opt);
else if (rt_orig_ptr)
- print_rt_tables(orig, seqno_min, seqno_max, read_opt);
+ print_rt_tables(orig, seqno_min, seqno_max, filter_orig, read_opt);
else
- loop_detection(orig, seqno_min, seqno_max, read_opt);
+ loop_detection(orig, seqno_min, seqno_max, filter_orig, read_opt);
ret = EXIT_SUCCESS;
Modified: trunk/batctl/bisect.h
===================================================================
--- trunk/batctl/bisect.h 2009-10-26 19:17:52 UTC (rev 1458)
+++ trunk/batctl/bisect.h 2009-10-26 20:48:30 UTC (rev 1459)
@@ -89,5 +89,6 @@
struct seqno_trace {
struct list_head list;
int seqno;
+ char print;
struct seqno_trace_neigh seqno_trace_neigh;
};
Modified: trunk/batctl/man/batctl.8
===================================================================
--- trunk/batctl/man/batctl.8 2009-10-26 19:17:52 UTC (rev 1458)
+++ trunk/batctl/man/batctl.8 2009-10-26 20:48:30 UTC (rev 1459)
@@ -78,7 +78,7 @@
Per default batctl will display all packets that were seen on the given interface(s). The "\-p" options allows to filter certain packet types: 1 displays batman ogm packets only, 2 displays batman icmp packets only, etc. These numbers can be added to filter more than one packet type, e.g. use "\-p 3" to display batman ogm packets and batman icmp packets only. If "\-n" was given batctl will not replace the mac addresses with bat\-host names in the output.
.br
.IP "\fBbisect logfile1 logfile2 .. logfileN\fP"
-Analyzes the logfiles to build a small internal database of all sent sequence numbers and routing table changes. This database can be used to search for routing loops (default action), to trace OGMs of a host (use "-t" to specify the mac address or bat\-host name) throughout the network or to display routing tables of the nodes (use "-r" to specify the mac address or bat\-host name). You can name a specific sequence number or a range using the "-s" option to reduce the trace output. If "\-n" was given batctl will not replace the mac addresses with bat\-host names in the output.
+Analyzes the logfiles to build a small internal database of all sent sequence numbers and routing table changes. This database can be used to search for routing loops (default action), to trace OGMs of a host (use "-t" to specify the mac address or bat\-host name) throughout the network or to display routing tables of the nodes (use "-r" to specify the mac address or bat\-host name). You can name a specific sequence number or a range using the "-s" option to limit the output's range. Furthermore you can filter the output by specifying an originator (use "-o" to specify the mac address or 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.
.br
.SH FILES
.TP