The following commit has been merged in the master branch: commit 1531504d691e67d13b7ca515de90cf9cdbcf12d3 Author: Marek Lindner lindner_marek@yahoo.de Date: Tue Dec 5 00:40:03 2006 +0100
- bind_to_iface for send sockets - check for missing interface before backgrounding - fix packet burst while scheduling own packet
diff --git a/batman.c b/batman.c index 10e9f8e..e5be5e6 100755 --- a/batman.c +++ b/batman.c @@ -777,15 +777,15 @@ void schedule_forward_packet( struct packet *in, int unidirectional, struct orig struct forw_node *forw_node = NULL, *forw_node_new; struct list_head *forw_pos;
- if (debug_level == 4) - output("schedule_forward_packet(): \n"); + if ( debug_level == 4 ) + output( "schedule_forward_packet(): \n" );
- if (in->ttl <= 1) { - if (debug_level == 4) - output("ttl exceeded \n"); + if ( in->ttl <= 1 ) { + if ( debug_level == 4 ) + output( "ttl exceeded \n" ); } else if ( ( orig_node->router != neigh ) && ( in->orig != neigh ) ) { - if (debug_level == 4) - output("not my best neighbour\n"); + if ( debug_level == 4 ) + output( "not my best neighbour\n" ); } else {
forw_node_new = alloc_memory(sizeof (struct forw_node)); @@ -796,10 +796,10 @@ void schedule_forward_packet( struct packet *in, int unidirectional, struct orig forw_node_new->pack.ttl--;
if (unidirectional) { - if (debug_level == 4) - output("sending with unidirectional flag \n"); + if ( debug_level == 4 ) + output( "sending with unidirectional flag \n" );
- forw_node_new->pack.flags = (forw_node_new->pack.flags | UNIDIRECTIONAL); + forw_node_new->pack.flags = ( forw_node_new->pack.flags | UNIDIRECTIONAL ); }
forw_node_new->when = get_time(); @@ -1109,8 +1109,7 @@ int batman() int is_my_addr, is_my_orig, is_broadcast, is_duplicate, is_bidirectional, forward_duplicate_packet; int time_count = 0, curr_time;
- last_own_packet = get_time() - orginator_interval; - debug_timeout = get_time(); + last_own_packet = debug_timeout = get_time(); bidirectional_timeout = orginator_interval * 3;
if ( !( list_empty(&hna_list) ) ) { @@ -1151,8 +1150,6 @@ int batman() if (debug_level == 4) output(" \n \n");
- schedule_own_packet(); - if(vis_if.sock && time_count == 50) { time_count = 0; @@ -1163,7 +1160,7 @@ int batman()
/* harden select_timeout against sudden time change (e.g. ntpdate) */ curr_time = get_time(); - select_timeout = ( curr_time >= last_own_packet + orginator_interval ? orginator_interval : last_own_packet + orginator_interval - curr_time ); + select_timeout = ( curr_time >= last_own_packet + orginator_interval - 10 ? orginator_interval : last_own_packet + orginator_interval - curr_time );
res = receive_packet((unsigned char *)&in, sizeof (struct packet), hna_recv_buff, &hna_buff_len, &neigh, select_timeout, &if_incoming);
@@ -1344,6 +1341,8 @@ int batman()
}
+ schedule_own_packet(); + send_outstanding_packets();
if ( ( routing_class != 0 ) && ( curr_gateway == NULL ) ) diff --git a/posix.c b/posix.c index 2cf8d48..27d2d65 100644 --- a/posix.c +++ b/posix.c @@ -998,21 +998,21 @@ int main(int argc, char *argv[]) }
if ( ( gateway_class != 0 ) && ( routing_class != 0 ) ) { - fprintf(stderr, "Error - routing class can't be set while gateway class is in use !\n"); + fprintf( stderr, "Error - routing class can't be set while gateway class is in use !\n" ); usage(); close_all_sockets(); exit(EXIT_FAILURE); }
if ( ( gateway_class != 0 ) && ( pref_gateway != 0 ) ) { - fprintf(stderr, "Error - preferred gateway can't be set while gateway class is in use !\n"); + fprintf( stderr, "Error - preferred gateway can't be set while gateway class is in use !\n" ); usage(); close_all_sockets(); exit(EXIT_FAILURE); }
if ( ( routing_class == 0 ) && ( pref_gateway != 0 ) ) { - fprintf(stderr, "Error - preferred gateway can't be set without specifying routing class !\n"); + fprintf( stderr, "Error - preferred gateway can't be set without specifying routing class !\n" ); usage(); close_all_sockets(); exit(EXIT_FAILURE); @@ -1023,6 +1023,13 @@ int main(int argc, char *argv[]) exit( 1 ); }
+ if ( argc <= found_args ) { + fprintf( stderr,"Error - no interface specified\n", strerror(errno) ); + usage(); + close_all_sockets(); + exit(EXIT_FAILURE); + } +
/* daemonize */ if ( debug_level == 0 ) { @@ -1150,6 +1157,13 @@ int main(int argc, char *argv[])
}
+ if ( bind_to_iface( batman_if->udp_send_sock, batman_if->dev ) < 0 ) { + + close_all_sockets(); + exit(EXIT_FAILURE); + + } + if ( bind( batman_if->udp_send_sock, (struct sockaddr *)&batman_if->addr, sizeof (struct sockaddr_in) ) < 0 ) {
do_log( "Error - can't bind send socket: %s\n", strerror(errno) ); @@ -1246,14 +1260,6 @@ int main(int argc, char *argv[]) memset(&vis_if, 0, sizeof(vis_if));
- if ( found_ifs == 0 ) { - do_log( "Error - no interface specified\n", strerror(errno) ); - usage(); - close_all_sockets(); - exit(EXIT_FAILURE); - } - - if ( debug_level > 0 ) {
printf("debug level: %i\n", debug_level);