The following commit has been merged in the master branch: commit fe53ac6cf1d4313a842521190afd5f905b4c023d Author: Marek Lindner lindner_marek@yahoo.de Date: Fri Oct 6 14:37:55 2006 +0200
get MTU of real interface keep_alive_string added
diff --git a/linux.c b/linux.c index 026b8de..63b4385 100755 --- a/linux.c +++ b/linux.c @@ -174,15 +174,16 @@ int del_dev_tun( int fd ) {
}
-int add_dev_tun( unsigned int tun_addr, char *tun_dev, int *fd ) { +int add_dev_tun( struct batman_if *batman_if, unsigned int tun_addr, char *tun_dev, int *fd ) {
int tmp_fd; - struct ifreq ifr; + struct ifreq ifr_tun, ifr_if; struct sockaddr_in addr;
/* set up tunnel device */ - memset( &ifr, 0, sizeof(ifr) ); - ifr.ifr_flags = IFF_TUN | IFF_NO_PI; + memset( &ifr_tun, 0, sizeof(ifr_tun) ); + memset( &ifr_if, 0, sizeof(ifr_if) ); + ifr_tun.ifr_flags = IFF_TUN | IFF_NO_PI;
if ( ( *fd = open( "/dev/net/tun", O_RDWR ) ) < 0 ) {
@@ -191,7 +192,7 @@ int add_dev_tun( unsigned int tun_addr, char *tun_dev, int *fd ) {
}
- if ( ( ioctl( *fd, TUNSETIFF, (void *) &ifr ) ) < 0 ) { + if ( ( ioctl( *fd, TUNSETIFF, (void *) &ifr_tun ) ) < 0 ) {
perror("TUNSETIFF"); close(*fd); @@ -221,10 +222,10 @@ int add_dev_tun( unsigned int tun_addr, char *tun_dev, int *fd ) { memset( &addr, 0, sizeof(addr) ); addr.sin_addr.s_addr = tun_addr; addr.sin_family = AF_INET; - memcpy( &ifr.ifr_addr, &addr, sizeof(struct sockaddr) ); + memcpy( &ifr_tun.ifr_addr, &addr, sizeof(struct sockaddr) );
- if ( ioctl( tmp_fd, SIOCSIFADDR, &ifr) < 0 ) { + if ( ioctl( tmp_fd, SIOCSIFADDR, &ifr_tun) < 0 ) {
perror("SIOCSIFADDR"); del_dev_tun( *fd ); @@ -234,7 +235,7 @@ int add_dev_tun( unsigned int tun_addr, char *tun_dev, int *fd ) { }
- if ( ioctl( tmp_fd, SIOCGIFFLAGS, &ifr) < 0 ) { + if ( ioctl( tmp_fd, SIOCGIFFLAGS, &ifr_tun) < 0 ) {
perror("SIOCGIFFLAGS"); del_dev_tun( *fd ); @@ -243,10 +244,10 @@ int add_dev_tun( unsigned int tun_addr, char *tun_dev, int *fd ) {
}
- ifr.ifr_flags |= IFF_UP; - ifr.ifr_flags |= IFF_RUNNING; + ifr_tun.ifr_flags |= IFF_UP; + ifr_tun.ifr_flags |= IFF_RUNNING;
- if ( ioctl( tmp_fd, SIOCSIFFLAGS, &ifr) < 0 ) { + if ( ioctl( tmp_fd, SIOCSIFFLAGS, &ifr_tun) < 0 ) {
perror("SIOCSIFFLAGS"); del_dev_tun( *fd ); @@ -255,7 +256,10 @@ int add_dev_tun( unsigned int tun_addr, char *tun_dev, int *fd ) {
}
- if ( ioctl( tmp_fd, SIOCGIFMTU, &ifr ) < 0 ) { + /* get MTU from real interface */ + strncpy( ifr_if.ifr_name, batman_if->dev, IFNAMSIZ - 1 ); + + if ( ioctl( tmp_fd, SIOCGIFMTU, &ifr_if ) < 0 ) {
perror("SIOCGIFMTU"); del_dev_tun( *fd ); @@ -264,15 +268,16 @@ int add_dev_tun( unsigned int tun_addr, char *tun_dev, int *fd ) {
}
- if ( ifr.ifr_mtu < 500 ) { + /* set MTU of tun interface: real MTU - 28 */ + if ( ifr_if.ifr_mtu < 100 ) {
- fprintf(stderr, "Warning: MTU smaller than 500 - cannot reduce MTU anymore\n" ); + fprintf(stderr, "Warning: MTU smaller than 100 - cannot reduce MTU anymore\n" );
} else {
- ifr.ifr_mtu -= 28; + ifr_tun.ifr_mtu = ifr_if.ifr_mtu - 28;
- if ( ioctl( tmp_fd, SIOCSIFMTU, &ifr ) < 0 ) { + if ( ioctl( tmp_fd, SIOCSIFMTU, &ifr_tun ) < 0 ) {
perror("SIOCSIFMTU"); del_dev_tun( *fd ); @@ -284,7 +289,7 @@ int add_dev_tun( unsigned int tun_addr, char *tun_dev, int *fd ) { }
- strncpy( tun_dev, ifr.ifr_name, IFNAMSIZ - 1 ); + strncpy( tun_dev, ifr_tun.ifr_name, IFNAMSIZ - 1 ); close( tmp_fd );
return 1; diff --git a/os.h b/os.h index 092602a..0197869 100755 --- a/os.h +++ b/os.h @@ -38,6 +38,6 @@ int rand_num(int limit); int bind_to_iface( int udp_recv_sock, char *dev ); int probe_tun(); int del_dev_tun( int fd ); -int add_dev_tun( unsigned int dest_addr, char *tun_dev, int *fd ); +int add_dev_tun( struct batman_if *batman_if, unsigned int dest_addr, char *tun_dev, int *fd );
#endif diff --git a/posix.c b/posix.c index 18c942c..0ce5cd6 100644 --- a/posix.c +++ b/posix.c @@ -94,7 +94,7 @@ void *client_to_gw_tun( void *arg ) { struct timeval tv; int res, max_sock, status, buff_len, curr_gateway_tcp_sock, curr_gateway_tun_sock, curr_gateway_tun_fd, server_keep_alive_timeout; unsigned int addr_len, curr_gateway_ip; - char curr_gateway_tun_if[IFNAMSIZ]; + char curr_gateway_tun_if[IFNAMSIZ], keep_alive_string[] = "ping\0"; unsigned char buff[1500]; fd_set wait_sockets, tmp_wait_sockets;
@@ -155,7 +155,7 @@ void *client_to_gw_tun( void *arg ) { }
- if ( add_dev_tun( curr_gateway_batman_if->addr.sin_addr.s_addr, curr_gateway_tun_if, &curr_gateway_tun_fd ) > 0 ) { + if ( add_dev_tun( curr_gateway_batman_if, curr_gateway_batman_if->addr.sin_addr.s_addr, curr_gateway_tun_if, &curr_gateway_tun_fd ) > 0 ) {
add_del_route( 0, 0, 0, curr_gateway_tun_if, curr_gateway_batman_if->udp_send_sock );
@@ -184,11 +184,11 @@ void *client_to_gw_tun( void *arg ) { while ( ( !is_aborted() ) && ( curr_gateway != NULL ) ) {
- if (server_keep_alive_timeout + 30000 < get_time()) { + if ( server_keep_alive_timeout + 30000 < get_time() ) {
server_keep_alive_timeout = get_time(); - strcpy (buff, "ping\0"); - if (write (curr_gateway_tcp_sock, buff,5) < 0) { + + if ( write( curr_gateway_tcp_sock, keep_alive_string, sizeof( keep_alive_string ) ) < 0 ) { fprintf(stderr, "server_keepalive failed: no connect to server\n"); break; } @@ -500,7 +500,7 @@ void *gw_listen( void *arg ) {
}
- if ( add_dev_tun( tmp_ip_holder.s_addr, tun_dev, &tun_fd ) < 0 ) { + if ( add_dev_tun( batman_if, tmp_ip_holder.s_addr, tun_dev, &tun_fd ) < 0 ) { printf( "Could not open tun device on interface: %s\n", gw_addr ); return NULL; }