The following commit has been merged in the master branch: commit bd1aa08095262b13b34bcdc7aba78379e7fc6f77 Author: Marek Lindner lindner_marek@yahoo.de Date: Mon Jan 29 20:30:03 2007 +0100
fix misleading identification string
diff --git a/batman.c b/batman.c index 3b36154..1178d15 100644 --- a/batman.c +++ b/batman.c @@ -94,8 +94,10 @@ unsigned int pref_gateway = 0; unsigned char *hna_buff = NULL;
short num_hna = 0; -short found_ifs = 0;
+short found_ifs = 0; +int receive_max_sock = 0; +fd_set receive_wait_set;
static LIST_HEAD(orig_list); @@ -170,15 +172,18 @@ void verbose_usage(void) }
/* this function finds or creates an originator entry for the given address if it does not exits */ -struct orig_node *get_orig_node( unsigned int addr ) -{ +struct orig_node *get_orig_node( unsigned int addr ) { + struct list_head *pos; struct orig_node *orig_node;
- list_for_each(pos, &orig_list) { - orig_node = list_entry(pos, struct orig_node, list); - if (orig_node->orig == addr) + list_for_each( pos, &orig_list ) { + + orig_node = list_entry( pos, struct orig_node, list ); + + if ( orig_node->orig == addr ) return orig_node; + }
debug_output( 4, "Creating new originator\n" ); @@ -197,6 +202,7 @@ struct orig_node *get_orig_node( unsigned int addr ) list_add_tail( &orig_node->list, &orig_list );
return orig_node; + }
@@ -556,8 +562,8 @@ void debug() {
addr_to_string(neigh_node->addr, str, sizeof (str));
- debug_output( 1, " %s(%i) %s", str, neigh_node->packet_count, bit_print( neigh_node->seq_bits ) ); - debug_output( 4, "\t\t%s (%d) %s\n", str, neigh_node->packet_count , bit_print( neigh_node->seq_bits ) ); + debug_output( 1, " %s(%i)", str, neigh_node->packet_count ); + debug_output( 4, "\t\t%s (%d)\n", str, neigh_node->packet_count );
}
@@ -1345,7 +1351,7 @@ int batman() if ( debug_level > 0 ) printf( "Deleting all BATMAN routes\n" );
- purge( get_time() + TIMEOUT + orginator_interval ); + purge( get_time() + ( 2 * TIMEOUT ) + orginator_interval );
list_for_each_safe( hna_pos, hna_pos_tmp, &hna_list ) { diff --git a/batman.h b/batman.h index 5f84dbb..5cdcd69 100644 --- a/batman.h +++ b/batman.h @@ -74,6 +74,8 @@ extern struct gw_node *curr_gateway; pthread_t curr_gateway_thread_id;
extern short found_ifs; +extern int receive_max_sock; +extern fd_set receive_wait_set;
extern struct list_head if_list; extern struct list_head hna_list; diff --git a/os.h b/os.h index 76381e3..1cfef85 100644 --- a/os.h +++ b/os.h @@ -36,7 +36,7 @@ void addr_to_string(unsigned int addr, char *str, int len);
int receive_packet(unsigned char *packet_buff, int packet_buff_len, int *hna_buff_len, unsigned int *neigh, unsigned int timeout, struct batman_if **if_incoming);
-int send_packet(unsigned char *buff, int len, struct sockaddr_in *broad, int sock); +int send_packet( unsigned char *packet_buff, int packet_buff_len, struct sockaddr_in *broad, int send_sock ); int rand_num(int limit); int bind_to_iface( int udp_recv_sock, char *dev ); int probe_tun(); diff --git a/posix-specific.c b/posix-specific.c index 41464ed..6d03f48 100644 --- a/posix-specific.c +++ b/posix-specific.c @@ -377,14 +377,14 @@ void apply_init_args( int argc, char *argv[] ) {
}
- hna_node = debugMalloc(sizeof(struct hna_node), 16); - memset(hna_node, 0, sizeof(struct hna_node)); - INIT_LIST_HEAD(&hna_node->list); + hna_node = debugMalloc( sizeof(struct hna_node), 16 ); + memset( hna_node, 0, sizeof(struct hna_node) ); + INIT_LIST_HEAD( &hna_node->list );
hna_node->addr = tmp_ip_holder.s_addr; hna_node->netmask = netmask;
- list_add_tail(&hna_node->list, &hna_list); + list_add_tail( &hna_node->list, &hna_list );
*slash_ptr = '/'; found_args += 2; @@ -594,6 +594,8 @@ void apply_init_args( int argc, char *argv[] ) {
}
+ FD_ZERO( &receive_wait_set ); + while ( argc > found_args ) {
batman_if = debugMalloc( sizeof(struct batman_if), 17 ); @@ -604,10 +606,15 @@ void apply_init_args( int argc, char *argv[] ) { batman_if->dev = argv[found_args]; batman_if->if_num = found_ifs;
- list_add_tail(&batman_if->list, &if_list); + list_add_tail( &batman_if->list, &if_list );
init_interface ( batman_if );
+ if ( batman_if->udp_recv_sock > receive_max_sock ) + receive_max_sock = batman_if->udp_recv_sock; + + FD_SET( batman_if->udp_recv_sock, &receive_wait_set ); + addr_to_string(batman_if->addr.sin_addr.s_addr, str1, sizeof (str1)); addr_to_string(batman_if->broad.sin_addr.s_addr, str2, sizeof (str2));
@@ -850,20 +857,20 @@ void init_interface ( struct batman_if *batman_if ) struct ifreq int_req; short on = 1;
- if ( strlen(batman_if->dev) > IFNAMSIZ - 1 ) { + if ( strlen( batman_if->dev ) > IFNAMSIZ - 1 ) { debug_output( 0, "Error - interface name too long: %s\n", batman_if->dev ); close_all_sockets(); exit(EXIT_FAILURE); }
- batman_if->udp_send_sock = socket(PF_INET, SOCK_DGRAM, 0); + batman_if->udp_send_sock = socket( PF_INET, SOCK_DGRAM, 0 ); if (batman_if->udp_send_sock < 0) { debug_output( 0, "Error - can't create send socket: %s", strerror(errno) ); close_all_sockets(); exit(EXIT_FAILURE); }
- batman_if->udp_recv_sock = socket(PF_INET, SOCK_DGRAM, 0); + 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) ); @@ -872,8 +879,8 @@ void init_interface ( struct batman_if *batman_if )
}
- memset(&int_req, 0, sizeof (struct ifreq)); - strncpy(int_req.ifr_name, batman_if->dev, IFNAMSIZ - 1); + memset( &int_req, 0, sizeof (struct ifreq) ); + strncpy( int_req.ifr_name, batman_if->dev, IFNAMSIZ - 1 );
if ( ioctl( batman_if->udp_recv_sock, SIOCGIFADDR, &int_req ) < 0 ) {
@@ -1238,19 +1245,19 @@ void close_all_sockets() { struct list_head *if_pos, *if_pos_tmp; struct batman_if *batman_if;
- list_for_each_safe(if_pos, if_pos_tmp, &if_list) { + list_for_each_safe( if_pos, if_pos_tmp, &if_list ) {
- batman_if = list_entry(if_pos, struct batman_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); + close( batman_if->tcp_gw_sock );
}
- close(batman_if->udp_recv_sock); - close(batman_if->udp_send_sock); + close( batman_if->udp_recv_sock ); + close( batman_if->udp_send_sock );
list_del( if_pos ); debugFree( if_pos, 203 ); @@ -1260,8 +1267,8 @@ void close_all_sockets() { if ( ( routing_class != 0 ) && ( curr_gateway != NULL ) ) del_default_route();
- if (vis_if.sock) - close(vis_if.sock); + if ( vis_if.sock ) + close( vis_if.sock );
if ( unix_if.unix_sock ) close( unix_if.unix_sock ); @@ -1280,67 +1287,55 @@ void close_all_sockets() {
int receive_packet( unsigned char *packet_buff, int packet_buff_len, int *hna_buff_len, unsigned int *neigh, unsigned int timeout, struct batman_if **if_incoming ) {
- fd_set wait_set; - int res, max_sock = 0; struct sockaddr_in addr; - unsigned int addr_len; struct timeval tv; struct list_head *if_pos; struct batman_if *batman_if; - struct packet *p; + unsigned int addr_len; + int res; + fd_set tmp_wait_set = receive_wait_set;
tv.tv_sec = timeout / 1000; - tv.tv_usec = (timeout % 1000) * 1000; - + tv.tv_usec = ( timeout % 1000 ) * 1000; + addr_len = sizeof(struct sockaddr_in);
- FD_ZERO(&wait_set); + while (1) {
- list_for_each(if_pos, &if_list) { - - batman_if = list_entry(if_pos, struct batman_if, list); - - FD_SET(batman_if->udp_recv_sock, &wait_set); - - if ( batman_if->udp_recv_sock > max_sock ) - max_sock = batman_if->udp_recv_sock; - - } + res = select( receive_max_sock + 1, &tmp_wait_set, NULL, NULL, &tv );
- for (;;) - { - res = select( max_sock + 1, &wait_set, NULL, NULL, &tv ); - - if (res >= 0) + if ( res >= 0 ) break;
if ( errno != EINTR ) { + debug_output( 0, "Error - can't select: %s\n", strerror(errno) ); return -1; + } + }
if ( res == 0 ) return 0;
- addr_len = sizeof (struct sockaddr_in); + list_for_each( if_pos, &if_list ) {
- list_for_each(if_pos, &if_list) { - batman_if = list_entry(if_pos, struct batman_if, list); + batman_if = list_entry( if_pos, struct batman_if, list );
- if ( FD_ISSET( batman_if->udp_recv_sock, &wait_set) ) { + if ( FD_ISSET( batman_if->udp_recv_sock, &tmp_wait_set ) ) {
if ( ( *hna_buff_len = recvfrom( batman_if->udp_recv_sock, packet_buff, packet_buff_len - 1, 0, (struct sockaddr *)&addr, &addr_len ) ) < 0 ) { + debug_output( 0, "Error - can't receive packet: %s\n", strerror(errno) ); return -1; + }
if ( *hna_buff_len < sizeof(struct packet) ) return 0; - p = (struct packet *) packet_buff; - p->seqno = ntohs(p->seqno); /* network to host order for our 16bit seqno. - * ip adress shall remain in network order, - * so we don't swap bytes for p->orig. */ + + ((struct packet *)packet_buff)->seqno = ntohs( ((struct packet *)packet_buff)->seqno ); /* network to host order for our 16bit seqno.*/
(*if_incoming) = batman_if; @@ -1358,13 +1353,11 @@ int receive_packet( unsigned char *packet_buff, int packet_buff_len, int *hna_bu
-int send_packet(unsigned char *buff, int len, struct sockaddr_in *broad, int sock) -{ - struct packet *p; - p=(struct packet *)buff; - p->seqno = htons(p->seqno); /* change sequence number to network order. ip address(es) remain in network order */ +int send_packet( unsigned char *packet_buff, int packet_buff_len, struct sockaddr_in *broad, int send_sock ) { + + ((struct packet *)packet_buff)->seqno = htons( ((struct packet *)packet_buff)->seqno ); /* change sequence number to network order */
- if ( sendto( sock, buff, len, 0, (struct sockaddr *)broad, sizeof (struct sockaddr_in) ) < 0 ) { + if ( sendto( send_sock, packet_buff, packet_buff_len, 0, (struct sockaddr *)broad, sizeof(struct sockaddr_in) ) < 0 ) {
if ( errno == 1 ) {