The following commit has been merged in the master branch:
commit 3438fa2612921d0220b40db9872febeba17d8430
Author: Marek Lindner <lindner_marek(a)yahoo.de>
Date: Mon Mar 12 15:55:02 2007 +0100
fix display bug while using batman client
batch mode: let batman client exit quicker
update routes after neighbour purge
diff --git a/allocate.c b/allocate.c
index 665cef3..52cbb34 100644
--- a/allocate.c
+++ b/allocate.c
@@ -143,12 +143,12 @@ void checkIntegrity(void)
struct memoryUsage *memoryWalker;
- debug_output( 3, "Memory usage information:\n" );
+ debug_output( 3, " \nMemory usage information:\n" );
for ( memoryWalker = memoryList; memoryWalker != NULL; memoryWalker = memoryWalker->next ) {
if ( memoryWalker->counter != 0 )
- debug_output( 3, " tag: %''4i, num malloc: % 4i, bytes per malloc: %''4i, total: % 6i\n", memoryWalker->tag, memoryWalker->counter, memoryWalker->length, memoryWalker->counter * memoryWalker->length );
+ debug_output( 3, " tag: %''4i, num malloc: %4i, bytes per malloc: %''4i, total: %6i\n", memoryWalker->tag, memoryWalker->counter, memoryWalker->length, memoryWalker->counter * memoryWalker->length );
}
diff --git a/batman.c b/batman.c
index f6bf964..2ec4db4 100644
--- a/batman.c
+++ b/batman.c
@@ -644,7 +644,7 @@ int8_t batman() {
addr_to_string( ((struct packet *)&in)->orig, orig_str, sizeof(orig_str) );
addr_to_string( neigh, neigh_str, sizeof(neigh_str) );
- debug_output( 4, "Received BATMAN packet from %s (originator %s, seqno %d, TTL %d)\n", neigh_str, orig_str, ((struct packet *)&in)->seqno, ((struct packet *)&in)->ttl );
+ debug_output( 4, "Received BATMAN packet from %s (originator %s, seqno %d, TTL %d) \n", neigh_str, orig_str, ((struct packet *)&in)->seqno, ((struct packet *)&in)->ttl );
is_my_addr = is_my_orig = is_broadcast = is_duplicate = is_bidirectional = forward_duplicate_packet = 0;
@@ -672,7 +672,7 @@ int8_t batman() {
if ( hna_buff_len > 4 ) {
- debug_output( 4, "HNA information received (%i HNA network%s):\n", hna_buff_len / 5, ( hna_buff_len / 5 > 1 ? "s": "" ) );
+ debug_output( 4, "HNA information received (%i HNA network%s): \n", hna_buff_len / 5, ( hna_buff_len / 5 > 1 ? "s": "" ) );
hna_buff_count = 0;
while ( ( hna_buff_count + 1 ) * 5 <= hna_buff_len ) {
@@ -685,7 +685,7 @@ int8_t batman() {
if ( ( netmask > 0 ) && ( netmask < 33 ) )
debug_output( 4, "hna: %s/%i\n", orig_str, netmask );
else
- debug_output( 4, "hna: %s/%i -> ignoring (invalid netmask)\n", orig_str, netmask );
+ debug_output( 4, "hna: %s/%i -> ignoring (invalid netmask) \n", orig_str, netmask );
hna_buff_count++;
@@ -700,11 +700,11 @@ int8_t batman() {
} else if ( is_my_addr ) {
- debug_output( 4, "Drop packet: received my own broadcast (sender: %s)\n", neigh_str );
+ debug_output( 4, "Drop packet: received my own broadcast (sender: %s) \n", neigh_str );
} else if ( is_broadcast ) {
- debug_output( 4, "Drop packet: ignoring all packets with broadcast source IP (sender: %s)\n", neigh_str );
+ debug_output( 4, "Drop packet: ignoring all packets with broadcast source IP (sender: %s) \n", neigh_str );
} else if ( is_my_orig ) {
diff --git a/batman.h b/batman.h
index 575b17c..8b49a0f 100644
--- a/batman.h
+++ b/batman.h
@@ -104,7 +104,6 @@ struct packet
struct orig_node /* structure for orig_list maintaining nodes of mesh */
{
uint32_t orig;
- struct list_head list;
struct neigh_node *router;
struct batman_if *batman_if;
uint32_t *bidirect_link; /* if node is a bidrectional neighbour, when my originator packet was broadcasted (replied) by this node and received by me */
diff --git a/orginator.c b/orginator.c
index ca7ef82..5d46624 100644
--- a/orginator.c
+++ b/orginator.c
@@ -80,7 +80,6 @@ struct orig_node *get_orig_node( uint32_t addr ) {
orig_node = debugMalloc( sizeof(struct orig_node), 401 );
memset(orig_node, 0, sizeof(struct orig_node));
- INIT_LIST_HEAD(&orig_node->list);
INIT_LIST_HEAD(&orig_node->neigh_list);
orig_node->orig = addr;
@@ -102,7 +101,6 @@ struct orig_node *get_orig_node( uint32_t addr ) {
}
prof_stop( PROF_get_orig_node );
-
return orig_node;
}
@@ -209,7 +207,7 @@ void purge_orig( uint32_t curr_time ) {
struct orig_node *orig_node;
struct neigh_node *neigh_node, *best_neigh_node;
struct gw_node *gw_node;
- uint8_t gw_purged = 0, neigh_purged = 0, max_packet_count;
+ uint8_t gw_purged = 0, neigh_purged = 0;
static char orig_str[ADDR_STR_LEN];
debug_output( 4, "purge() \n" );
@@ -264,7 +262,7 @@ void purge_orig( uint32_t curr_time ) {
} else {
- max_packet_count = 0;
+ best_neigh_node = NULL;
/* for all neighbours towards this orginator ... */
list_for_each_safe( neigh_pos, neigh_temp, &orig_node->neigh_list ) {
@@ -279,19 +277,15 @@ void purge_orig( uint32_t curr_time ) {
} else {
- if ( neigh_node->packet_count > max_packet_count ) {
-
- max_packet_count = neigh_node->packet_count;
+ if ( ( best_neigh_node == NULL ) || ( neigh_node->packet_count > best_neigh_node->packet_count ) )
best_neigh_node = neigh_node;
- }
-
}
}
- if ( ( neigh_purged ) && ( ( orig_node->router == NULL ) || ( max_packet_count > orig_node->router->packet_count ) ) )
+ if ( ( neigh_purged ) && ( ( best_neigh_node == NULL ) || ( orig_node->router == NULL ) || ( best_neigh_node->packet_count > orig_node->router->packet_count ) ) )
update_routes( orig_node, best_neigh_node, orig_node->hna_buff, orig_node->hna_buff_len );
}
@@ -338,7 +332,7 @@ void debug_orig() {
if ( list_empty( &gw_list ) ) {
- debug_output( 2, "No gateways in range ...\n" );
+ debug_output( 2, "No gateways in range ... \n" );
} else {
@@ -353,18 +347,20 @@ void debug_orig() {
addr_to_string( gw_node->orig_node->router->addr, str2, sizeof (str2) );
if ( curr_gateway == gw_node ) {
- debug_output( 2, "=> %s via: %s(%i), gw_class %i - %s, reliability: %i\n", str, str2, gw_node->orig_node->router->packet_count, gw_node->orig_node->gwflags, gw2string[gw_node->orig_node->gwflags], gw_node->unavail_factor );
+ debug_output( 2, "=> %s via: %s(%i), gw_class %i - %s, reliability: %i \n", str, str2, gw_node->orig_node->router->packet_count, gw_node->orig_node->gwflags, gw2string[gw_node->orig_node->gwflags], gw_node->unavail_factor );
} else {
- debug_output( 2, "%s via: %s(%i), gw_class %i - %s, reliability: %i\n", str, str2, gw_node->orig_node->router->packet_count, gw_node->orig_node->gwflags, gw2string[gw_node->orig_node->gwflags], gw_node->unavail_factor );
+ debug_output( 2, "%s via: %s(%i), gw_class %i - %s, reliability: %i \n", str, str2, gw_node->orig_node->router->packet_count, gw_node->orig_node->gwflags, gw2string[gw_node->orig_node->gwflags], gw_node->unavail_factor );
}
}
if ( batman_count == 0 )
- debug_output( 2, "No gateways in range ...\n" );
+ debug_output( 2, "No gateways in range ... \n" );
}
+ debug_output( 2, "EOD\n" );
+
}
if ( ( debug_clients.clients_num[0] > 0 ) || ( debug_clients.clients_num[3] > 0 ) ) {
@@ -373,16 +369,16 @@ void debug_orig() {
if ( debug_clients.clients_num[3] > 0 ) {
- debug_output( 4, "------------------ DEBUG ------------------\n" );
- debug_output( 4, "Forward list\n" );
+ debug_output( 4, "------------------ DEBUG ------------------ \n" );
+ debug_output( 4, "Forward list \n" );
list_for_each( forw_pos, &forw_list ) {
forw_node = list_entry( forw_pos, struct forw_node, list );
addr_to_string( ((struct packet *)forw_node->pack_buff)->orig, str, sizeof (str) );
- debug_output( 4, " %s at %u\n", str, forw_node->send_time );
+ debug_output( 4, " %s at %u \n", str, forw_node->send_time );
}
- debug_output( 4, "Originator list\n" );
+ debug_output( 4, "Originator list \n" );
}
@@ -399,7 +395,7 @@ void debug_orig() {
addr_to_string( orig_node->router->addr, str2, sizeof (str2) );
debug_output( 1, "%s, GW: %s(%i) via:", str, str2, orig_node->router->packet_count );
- debug_output( 4, "%s, GW: %s(%i), last_aware:%u via:\n", str, str2, orig_node->router->packet_count, orig_node->last_aware );
+ debug_output( 4, "%s, GW: %s(%i), last_aware:%u via: \n", str, str2, orig_node->router->packet_count, orig_node->last_aware );
list_for_each( neigh_pos, &orig_node->neigh_list ) {
neigh_node = list_entry( neigh_pos, struct neigh_node, list );
@@ -407,22 +403,23 @@ void debug_orig() {
addr_to_string( neigh_node->addr, str, sizeof (str) );
debug_output( 1, " %s(%i)", str, neigh_node->packet_count );
- debug_output( 4, "\t\t%s (%d)\n", str, neigh_node->packet_count );
+ debug_output( 4, "\t\t%s (%d) \n", str, neigh_node->packet_count );
}
- debug_output( 1, "\n" );
+ debug_output( 1, " \n" );
}
if ( batman_count == 0 ) {
- debug_output( 1, "No batman nodes in range ...\n" );
- debug_output( 4, "No batman nodes in range ...\n" );
+ debug_output( 1, "No batman nodes in range ... \n" );
+ debug_output( 4, "No batman nodes in range ... \n" );
}
- debug_output( 4, "---------------------------------------------- END DEBUG\n" );
+ debug_output( 1, "EOD\n" );
+ debug_output( 4, "---------------------------------------------- END DEBUG \n" );
}
diff --git a/posix-specific.c b/posix-specific.c
index 3fd9dc8..de9e028 100644
--- a/posix-specific.c
+++ b/posix-specific.c
@@ -140,7 +140,7 @@ void *unix_listen( void *arg ) {
struct timeval tv;
int32_t status, max_sock;
int8_t res;
- unsigned char buff[1500];
+ unsigned char buff[10];
fd_set wait_sockets, tmp_wait_sockets;
socklen_t sun_size = sizeof(struct sockaddr_un);
@@ -203,7 +203,7 @@ void *unix_listen( void *arg ) {
/* debug_output( 3, "gateway: client sent data via unix socket: %s\n", buff ); */
- if ( ( buff[2] == '1' ) || ( buff[2] == '2' ) || ( buff[2] == '3' ) || ( buff[2] == '4' ) ) {
+ if ( ( status > 2 ) && ( ( buff[2] == '1' ) || ( buff[2] == '2' ) || ( buff[2] == '3' ) || ( buff[2] == '4' ) ) ) {
if ( unix_client->debug_level != 0 ) {
@@ -347,15 +347,14 @@ void apply_init_args( int argc, char *argv[] ) {
struct batman_if *batman_if;
struct hna_node *hna_node;
struct debug_level_info *debug_level_info;
-// struct timeval tv;
- uint8_t found_args = 1, unix_client = 0, batch_mode = 0, batch_counter = 0;
+ uint8_t found_args = 1, unix_client = 0, batch_mode = 0;
uint16_t netmask;
int8_t res;
int32_t optchar, recv_buff_len, bytes_written;
- char str1[16], str2[16], *slash_ptr, unix_string[100], buff[1500], *buff_ptr, *cr_ptr;
+ char str1[16], str2[16], *slash_ptr, *unix_buff, *buff_ptr, *cr_ptr;
uint32_t vis_server = 0;
-// fd_set wait_sockets, tmp_wait_sockets;
+
memset( &tmp_ip_holder, 0, sizeof (struct in_addr) );
stop = 0;
@@ -668,7 +667,7 @@ void apply_init_args( int argc, char *argv[] ) {
unlink( UNIX_PATH );
- unix_if.unix_sock = socket(AF_LOCAL, SOCK_STREAM, 0);
+ unix_if.unix_sock = socket( AF_LOCAL, SOCK_STREAM, 0 );
memset( &unix_if.addr, 0, sizeof(struct sockaddr_un) );
unix_if.addr.sun_family = AF_LOCAL;
@@ -736,47 +735,44 @@ void apply_init_args( int argc, char *argv[] ) {
}
- snprintf( unix_string, sizeof( unix_string ), "d:%i", debug_level );
-
-// FD_ZERO(&wait_sockets);
-// FD_SET(unix_if.unix_sock, &wait_sockets);
+ unix_buff = debugMalloc( 1500, 5001 );
+ snprintf( unix_buff, 10, "d:%i", debug_level );
- if ( write( unix_if.unix_sock, unix_string, strlen( unix_string ) ) < 0 ) {
+ if ( write( unix_if.unix_sock, unix_buff, 10 ) < 0 ) {
printf( "Error - can't write to unix socket: %s\n", strerror(errno) );
close( unix_if.unix_sock );
+ debugFree( unix_buff, 5101 );
exit(EXIT_FAILURE);
}
- while ( ( recv_buff_len = read( unix_if.unix_sock, buff, sizeof( buff ) ) ) > 0 ) {
+ while ( ( recv_buff_len = read( unix_if.unix_sock, unix_buff, 1500 ) ) > 0 ) {
- buff_ptr = buff;
+ unix_buff[recv_buff_len] = '\0';
+
+ buff_ptr = unix_buff;
bytes_written = 0;
while ( ( cr_ptr = strchr( buff_ptr, '\n' ) ) != NULL ) {
*cr_ptr = '\0';
- if ( strcmp( buff_ptr, "BOD" ) == 0 ) {
+ if ( strncmp( buff_ptr, "EOD", 3 ) == 0 ) {
if ( batch_mode ) {
- if ( batch_counter ) {
-
- close( unix_if.unix_sock );
- exit(EXIT_SUCCESS);
+ close( unix_if.unix_sock );
+ debugFree( unix_buff, 5102 );
+ exit(EXIT_SUCCESS);
- }
-
- batch_counter++;
+ }
- } else {
+ } else if ( strncmp( buff_ptr, "BOD", 3 ) == 0 ) {
+ if ( ! batch_mode )
system( "clear" );
- }
-
} else {
printf( "%s\n", buff_ptr );
@@ -793,10 +789,12 @@ void apply_init_args( int argc, char *argv[] ) {
}
+ close( unix_if.unix_sock );
+ debugFree( unix_buff, 5103 );
+
if ( recv_buff_len < 0 ) {
printf( "Error - can't read from unix socket: %s\n", strerror(errno) );
- close( unix_if.unix_sock );
exit(EXIT_FAILURE);
} else {
@@ -805,65 +803,6 @@ void apply_init_args( int argc, char *argv[] ) {
}
-// while ( 1 ) {
-//
-// if ( write( unix_if.unix_sock, unix_string, strlen( unix_string ) ) < 0 ) {
-//
-// printf( "Error - can't write to unix socket: %s\n", strerror(errno) );
-// close( unix_if.unix_sock );
-// exit(EXIT_FAILURE);
-//
-// }
-//
-// if ( ! batch_mode )
-// system( "clear" );
-//
-// while ( 1 ) {
-//
-// tv.tv_sec = 1;
-// tv.tv_usec = 0;
-// tmp_wait_sockets = wait_sockets;
-//
-// res = select( unix_if.unix_sock + 1, &tmp_wait_sockets, NULL, NULL, &tv );
-//
-// if ( res > 0 ) {
-//
-// if ( ( recv_buff_len = read( unix_if.unix_sock, buff, sizeof( buff ) ) ) < 0 ) {
-//
-// printf( "Error - can't read from unix socket: %s\n", strerror(errno) );
-// close( unix_if.unix_sock );
-// exit(EXIT_FAILURE);
-//
-// } else if ( recv_buff_len > 0 ) {
-//
-// printf( "%s", buff );
-//
-// }
-//
-// /* timeout reached */
-// } else if ( res == 0 ) {
-//
-// break;
-//
-// } else if ( ( res < 0 ) && ( errno != EINTR ) ) {
-//
-// printf( "Error - can't select: %s\n", strerror(errno) );
-// close( unix_if.unix_sock );
-// exit(EXIT_FAILURE);
-//
-// }
-//
-// }
-//
-// if ( batch_mode )
-// break;
-//
-// sleep( 1 );
-//
-// }
-
- close( unix_if.unix_sock );
-
}
exit(EXIT_SUCCESS);
diff --git a/profile.c b/profile.c
index eb373b2..d10f9ec 100644
--- a/profile.c
+++ b/profile.c
@@ -61,16 +61,14 @@ void prof_print() {
int32_t index;
- debug_output( 3, "\nProfile data:\n" );
+ debug_output( 3, " \nProfile data:\n" );
for ( index = 0; index < PROF_COUNT; index++ ) {
- debug_output( 3, " %''30s: cpu time = %10.3f, calls = %''6i\n", prof_container[index].name, (float)prof_container[index].total_time/CLOCKS_PER_SEC, prof_container[index].calls );
+ debug_output( 3, " %''30s: cpu time = %10.3f, calls = %''10i, avg time per call = %4.10f \n", prof_container[index].name, (float)prof_container[index].total_time/CLOCKS_PER_SEC, prof_container[index].calls, ( (float)prof_container[index].calls == 0 ? 0.0 : ( ( (float)prof_container[index].total_time/CLOCKS_PER_SEC ) / (float)prof_container[index].calls ) ) );
}
- debug_output( 3, "\n" );
-
}
--
batman; test conversation