The following commit has been merged in the master branch: commit 7d676210e5fd4282f5be7094336455aede86174f Author: Marek Lindner lindner_marek@yahoo.de Date: Mon Oct 2 14:37:07 2006 +0200
udp tunnel part VI
diff --git a/batman.c b/batman.c index d82e8e5..9ac431f 100755 --- a/batman.c +++ b/batman.c @@ -71,13 +71,6 @@ int orginator_interval = 1000; /* orginator message interval in miliseconds */ struct gw_node *curr_gateway = NULL; pthread_t curr_gateway_thread_id = 0;
-/*struct batman_if *curr_gateway_batman_if = NULL; -unsigned int curr_gateway_ip = 0; -char *curr_gateway_tun_if = NULL; -int curr_gateway_tcp_sock = 0; -int curr_gateway_tun_sock = 0; -int curr_gateway_tun_fd = 0;*/ - unsigned int pref_gateway = 0; int found_ifs = 0;
@@ -260,19 +253,17 @@ static void choose_gw() curr_gateway = tmp_curr_gw;
/* may be the last gateway is now gone */ - if ( curr_gateway != NULL ) { + if ( ( curr_gateway != NULL ) && ( !is_aborted() ) ) {
if (debug_level >= 1) { addr_to_string( curr_gateway->orig_node->orig, orig_str, ADDR_STR_LEN ); output( "Adding default route to %s (%i,%i,%i)\n", orig_str, max_gw_class, max_packets, max_gw_factor ); }
- /*curr_gateway_ip = curr_gateway->orig_node->orig; - curr_gateway_batman_if = curr_gateway->orig_node->batman_if;*/ - }
- add_default_route(); + if ( !is_aborted() ) + add_default_route();
}
diff --git a/batman.h b/batman.h index 272ce00..b9b9826 100755 --- a/batman.h +++ b/batman.h @@ -52,13 +52,6 @@ extern unsigned int pref_gateway; extern struct gw_node *curr_gateway; pthread_t curr_gateway_thread_id;
-/*extern struct batman_if *curr_gateway_batman_if; -extern unsigned int curr_gateway_ip; -extern char *curr_gateway_tun_if; -extern int curr_gateway_tcp_sock; -extern int curr_gateway_tun_sock; -extern int curr_gateway_tun_fd;*/ - extern int found_ifs;
extern struct list_head if_list; diff --git a/linux.c b/linux.c index ceefed7..e25507f 100755 --- a/linux.c +++ b/linux.c @@ -102,25 +102,35 @@ void add_del_route(unsigned int dest, unsigned int router, int del, char *dev, i addr = (struct sockaddr_in *)&route.rt_genmask;
addr->sin_family = AF_INET; - addr->sin_addr.s_addr = 0xffffffff; + addr->sin_addr.s_addr = ( ( ( dest == 0 ) && ( router == 0 ) ) ? 0x00000000 : 0xffffffff );
route.rt_flags = RTF_HOST | RTF_UP; + route.rt_metric = 1;
- if (dest != router) + if ( (dest != router) || ( ( dest == 0 ) && ( router == 0 ) ) ) { addr = (struct sockaddr_in *)&route.rt_gateway;
addr->sin_family = AF_INET; addr->sin_addr.s_addr = router;
- route.rt_flags |= RTF_GATEWAY; + if ( ( dest == 0 ) && ( router == 0 ) ) { + + route.rt_metric = 0; + route.rt_flags = RTF_UP; + output("%s default route via %s\n", del ? "Deleting" : "Adding", dev); + + } else { + + route.rt_flags |= RTF_GATEWAY; + output("route to %s via %s (%s)\n", del ? "Deleting" : "Adding", str1, str2, dev); + + }
- output("%s route to %s via %s (%s)\n", del ? "Deleting" : "Adding", str1, str2, dev); } else { output("%s route to %s via 0.0.0.0 (%s)\n", del ? "Deleting" : "Adding", str1, dev); }
- route.rt_metric = 1;
route.rt_dev = dev;
@@ -164,7 +174,7 @@ int del_dev_tun( int fd ) {
}
-int add_dev_tun( struct batman_if *batman_if, unsigned int dest_addr, char *tun_dev, int *fd ) { +int add_dev_tun( unsigned int tun_addr, char *tun_dev, int *fd ) {
int tmp_fd; struct ifreq ifr; @@ -209,8 +219,7 @@ int add_dev_tun( struct batman_if *batman_if, unsigned int dest_addr, char *tun_
/* set ip of this end point of tunnel */ memset( &addr, 0, sizeof(addr) ); -// addr.sin_addr.s_addr = batman_if->addr.sin_addr.s_addr; - addr.sin_addr.s_addr = dest_addr; + addr.sin_addr.s_addr = tun_addr; addr.sin_family = AF_INET; memcpy( &ifr.ifr_addr, &addr, sizeof(struct sockaddr) );
@@ -224,21 +233,6 @@ int add_dev_tun( struct batman_if *batman_if, unsigned int dest_addr, char *tun_
}
- /* TODO: remove dest_addr from function call */ - /* set ip of this remote point of tunnel */ - /*memset( &addr, 0, sizeof(addr) ); - addr.sin_addr.s_addr = dest_addr; - addr.sin_family = AF_INET; - memcpy( &ifr.ifr_addr, &addr, sizeof(struct sockaddr) ); - - if ( ioctl( tmp_fd, SIOCSIFDSTADDR, &ifr) < 0 ) { - - perror("SIOCSIFDSTADDR"); - del_dev_tun( *fd ); - close( tmp_fd ); - return -1; - - }*/
if ( ioctl( tmp_fd, SIOCGIFFLAGS, &ifr) < 0 ) {
diff --git a/os.h b/os.h index 0197869..092602a 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( struct batman_if *batman_if, unsigned int dest_addr, char *tun_dev, int *fd ); +int add_dev_tun( unsigned int dest_addr, char *tun_dev, int *fd );
#endif diff --git a/posix.c b/posix.c index ff72f3f..54b78ee 100644 --- a/posix.c +++ b/posix.c @@ -160,9 +160,9 @@ void *client_to_gw_tun( void *arg ) { }
- if ( add_dev_tun( curr_gateway_batman_if, tmp_ip_holder.s_addr, curr_gateway_tun_if, &curr_gateway_tun_fd ) > 0 ) { + if ( add_dev_tun( curr_gateway_batman_if->addr.sin_addr.s_addr, curr_gateway_tun_if, &curr_gateway_tun_fd ) > 0 ) {
-// add_del_route( 0, curr_gateway_ip, 0, curr_gateway_tun_if, curr_gateway_tun_fd ); + add_del_route( 0, 0, 0, curr_gateway_tun_if, curr_gateway_batman_if->udp_send_sock );
} else {
@@ -267,7 +267,7 @@ void *client_to_gw_tun( void *arg ) { }
/* cleanup */ -// add_del_route( 0, curr_gateway_ip, 1, curr_gateway_tun_if, curr_gateway_tun_fd ); + add_del_route( 0, 0, 1, curr_gateway_tun_if, curr_gateway_batman_if->udp_send_sock );
curr_gateway = NULL;
@@ -492,7 +492,7 @@ void *gw_listen( void *arg ) {
}
- if ( add_dev_tun( batman_if, tmp_ip_holder.s_addr, tun_dev, &tun_fd ) < 0 ) { + if ( add_dev_tun( tmp_ip_holder.s_addr, tun_dev, &tun_fd ) < 0 ) { printf( "Could not open tun device on interface: %s\n", gw_addr ); return NULL; }