The following commit has been merged in the master branch: commit d2b2339ed60a7015dff7c2b827da32f401f6d6ad Author: Marek Lindner lindner_marek@yahoo.de Date: Sat Mar 31 14:20:34 2007 +0200
issue a warning if braodcast address is 0.0.0.0 fix crash on exit while using unix client on segfault remove tun interfaces first
diff --git a/batman.c b/batman.c index dea9056..83b6a90 100644 --- a/batman.c +++ b/batman.c @@ -101,6 +101,8 @@ uint8_t found_ifs = 0; int32_t receive_max_sock = 0; fd_set receive_wait_set;
+uint8_t unix_client = 0; + struct hashtable_t *orig_hash;
LIST_HEAD(forw_list); diff --git a/batman.h b/batman.h index c383b6c..eb1102c 100644 --- a/batman.h +++ b/batman.h @@ -81,6 +81,8 @@ extern uint8_t found_ifs; extern int32_t receive_max_sock; extern fd_set receive_wait_set;
+extern uint8_t unix_client; + extern struct hashtable_t *orig_hash;
extern struct list_head if_list; diff --git a/posix-specific.c b/posix-specific.c index 9f414b1..65383cc 100644 --- a/posix-specific.c +++ b/posix-specific.c @@ -379,7 +379,7 @@ 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; - uint8_t found_args = 1, unix_client = 0, batch_mode = 0; + uint8_t found_args = 1, batch_mode = 0; uint16_t netmask; int8_t res;
@@ -847,11 +847,12 @@ void apply_init_args( int argc, char *argv[] ) {
-void init_interface ( struct batman_if *batman_if ) -{ +void init_interface ( struct batman_if *batman_if ) { + struct ifreq int_req; int16_t on = 1;
+ if ( strlen( batman_if->dev ) > IFNAMSIZ - 1 ) { debug_output( 0, "Error - interface name too long: %s\n", batman_if->dev ); restore_defaults(); @@ -868,7 +869,7 @@ void init_interface ( struct batman_if *batman_if ) batman_if->udp_recv_sock = socket( PF_INET, SOCK_DGRAM, 0 ); if ( batman_if->udp_recv_sock < 0 ) {
- debug_output( 0, "Error - can't create recieve socket: %s", strerror(errno) ); + debug_output( 0, "Error - can't create receive socket: %s", strerror(errno) ); restore_defaults(); exit(EXIT_FAILURE);
@@ -901,6 +902,14 @@ void init_interface ( struct batman_if *batman_if ) batman_if->broad.sin_port = htons(PORT); batman_if->broad.sin_addr.s_addr = ((struct sockaddr_in *)&int_req.ifr_broadaddr)->sin_addr.s_addr;
+ if ( batman_if->broad.sin_addr.s_addr == 0 ) { + + debug_output( 0, "Error - invalid broadcast address detected (0.0.0.0): %s\n", batman_if->dev ); + restore_defaults(); + exit(EXIT_FAILURE); + + } + if ( setsockopt( batman_if->udp_send_sock, SOL_SOCKET, SO_BROADCAST, &on, sizeof (int) ) < 0 ) {
debug_output( 0, "Error - can't enable broadcasts: %s\n", strerror(errno) ); @@ -1621,9 +1630,37 @@ void *gw_listen( void *arg ) {
void restore_and_exit() {
- purge_orig( get_time() + ( 5 * TIMEOUT ) + orginator_interval ); + struct list_head *if_pos; + struct batman_if *batman_if; + + + if ( !unix_client ) { + + /* remove tun interface first */ + stop = 1;
- restore_defaults(); + list_for_each( if_pos, &if_list ) { + + batman_if = list_entry( if_pos, struct batman_if, list ); + + if ( batman_if->listen_thread_id != 0 ) { + + pthread_join( batman_if->listen_thread_id, NULL ); + close( batman_if->tcp_gw_sock ); + batman_if->listen_thread_id = 0; + + } + + } + + if ( ( routing_class != 0 ) && ( curr_gateway != NULL ) ) + del_default_route(); + + purge_orig( get_time() + ( 5 * TIMEOUT ) + orginator_interval ); + + restore_defaults(); + + }
exit(EXIT_FAILURE);