The following commit has been merged in the master branch: commit 9a2152a39730bff1e6dbdc3a24750235e1d22b5a Author: Marek Lindner lindner_marek@yahoo.de Date: Wed Sep 6 22:33:41 2006 +0200
gateway functions
diff --git a/CHANGELOG b/CHANGELOG index 2ad2c4e..dbf690e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,6 +10,8 @@ new functions: - set orginator interval via command line switch - batman version check added - preferred gateway funtion added +- FreeBSD support added +- Mac OS X support added
bug fixes: @@ -18,6 +20,7 @@ bug fixes: - performance improvement in purge() - performance improvement in isDuplicate() - JITTER removed +- interval removed - fix crash in purge() - check for router before route is deleted - ignore all packets with broadcast source IP - prevent routing loop by forwarding o-packets only from best neighbour diff --git a/batman.c b/batman.c index 63bc137..cc59d1a 100755 --- a/batman.c +++ b/batman.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2006 BATMAN contributors: * Thomas Lopatic, Corinna 'Elektra' Aichele, Axel Neumann, - * Felix Fietkau + * Felix Fietkau, Marek Lindner * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public @@ -944,7 +944,7 @@ int batman()
}
- if (debug_level >= 2) { + if (debug_level >= 0) { if ( is_duplicate ) output("Duplicate packet \n");
diff --git a/batman.h b/batman.h index 8c20afc..2b276f2 100755 --- a/batman.h +++ b/batman.h @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 BATMAN contributors: - * Thomas Lopatic, Corinna 'Elektra' Aichele, Axel Neumann + * Thomas Lopatic, Corinna 'Elektra' Aichele, Axel Neumann, Marek Lindner * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation. @@ -121,6 +121,15 @@ struct batman_if struct sockaddr_in addr; struct sockaddr_in broad; struct packet out; + struct list_head client_list; +}; + +struct gw_client +{ + struct list_head list; + struct batman_if *batman_if; + int sock; + struct sockaddr_in addr; };
struct vis_if { diff --git a/os.h b/os.h index 7d4ff54..ab43924 100755 --- a/os.h +++ b/os.h @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 BATMAN contributors: - * Thomas Lopatic + * Thomas Lopatic, Marek Lindner * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation. diff --git a/posix.c b/posix.c index 7f1bb16..71daf64 100644 --- a/posix.c +++ b/posix.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 BATMAN contributors: - * Thomas Lopatic + * Thomas Lopatic, Marek Lindner * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation. @@ -89,9 +89,14 @@ void close_all_sockets()
list_for_each(if_pos, &if_list) { batman_if = list_entry(if_pos, struct batman_if, list); -// pthread_join( batman_if->listen_thread_id, NULL ); - close(batman_if->tcp_gw_sock); + + if ( gateway_class != 0 ) { + pthread_join( batman_if->listen_thread_id, NULL ); + close(batman_if->tcp_gw_sock); + } + close(batman_if->udp_recv_sock); + close(batman_if->udp_send_sock); }
if(vis_if.sock) @@ -169,7 +174,8 @@ int receive_packet(unsigned char *buff, int len, unsigned int *neigh, unsigned i 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; + if ( batman_if->udp_recv_sock > max_sock ) + max_sock = batman_if->udp_recv_sock;
}
@@ -235,25 +241,75 @@ static void handler(int sig) void *gw_listen( void *arg ) {
struct batman_if *batman_if = (struct batman_if *)arg; - struct sockaddr_in client_addr; + struct gw_client *gw_client; + struct timeval tv; socklen_t sin_size = sizeof(struct sockaddr_in); char str1[16], str2[16]; - int client_fd; + int res, max_sock; + fd_set wait_sockets; + + + + max_sock = batman_if->tcp_gw_sock;
while (!is_aborted()) {
- if ( ( client_fd = accept(batman_if->tcp_gw_sock, (struct sockaddr *)&client_addr, &sin_size) ) == -1 ) { - perror("accept"); - continue; - } + tv.tv_sec = 1; + tv.tv_usec = 0; + + FD_ZERO(&wait_sockets); + FD_SET(batman_if->tcp_gw_sock, &wait_sockets); + res = select(max_sock + 1, &wait_sockets, NULL, NULL, &tv); + + if (res > 0) { + + /* new client */ + if ( FD_ISSET( batman_if->tcp_gw_sock, &wait_sockets ) ) { + + gw_client = alloc_memory(sizeof(struct gw_client)); + memset(gw_client, 0, sizeof(struct gw_client)); + + if ( ( gw_client->sock = accept(batman_if->tcp_gw_sock, (struct sockaddr *)&gw_client->addr, &sin_size) ) == -1 ) { + perror("accept"); + continue; + } + + INIT_LIST_HEAD(&gw_client->list); + gw_client->batman_if = batman_if; + + FD_SET(gw_client->sock, &wait_sockets); + if ( gw_client->sock > max_sock ) + max_sock = gw_client->sock; + + if ( debug_level >= 0 ) { + addr_to_string(batman_if->addr.sin_addr.s_addr, str1, sizeof (str1)); + addr_to_string(gw_client->addr.sin_addr.s_addr, str2, sizeof (str2)); + printf( "gateway: %s got connection from %s\n", str1, str2 ); + } + + list_add_tail(&gw_client->list, &batman_if->client_list); + + /* client sent keep alive */ + } else { + +// 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; +// +// } + + } + + } else if ( ( res < 0 ) && (errno != EINTR) ) { + + fprintf(stderr, "Cannot select: %s\n", strerror(errno)); + return NULL;
- if ( debug_level >= 0 ) { - addr_to_string(batman_if->addr.sin_addr.s_addr, str1, sizeof (str1)); - addr_to_string(client_addr.sin_addr.s_addr, str2, sizeof (str2)); - printf( "gateway: %s got connection from %s\n", str1, str2 ); }
- close( client_fd );
}
@@ -384,6 +440,7 @@ int main(int argc, char *argv[]) batman_if = alloc_memory(sizeof(struct batman_if)); memset(batman_if, 0, sizeof(struct batman_if)); INIT_LIST_HEAD(&batman_if->list); + INIT_LIST_HEAD(&batman_if->client_list);
batman_if->dev = argv[found_args]; batman_if->if_num = found_ifs; @@ -455,7 +512,7 @@ int main(int argc, char *argv[]) close_all_sockets(); exit(EXIT_FAILURE); } - + 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));