The following commit has been merged in the master branch: commit b7b2b7dd631643ee7d62e5fc682e4ef8c0cadb51 Author: Marek Lindner lindner_marek@yahoo.de Date: Tue Sep 12 10:01:39 2006 +0200
choose_gw activated and ipip tunnel fcts added III
diff --git a/batman.c b/batman.c index aec8f71..f297d33 100755 --- a/batman.c +++ b/batman.c @@ -170,7 +170,7 @@ struct orig_node *get_orig_node( unsigned int addr ) static void choose_gw() { struct list_head *pos; - struct gw_node *gw_node, *tmp_curr_gw; + struct gw_node *gw_node, *tmp_curr_gw = NULL; int max_gw_class = 0, max_packets = 0, max_gw_factor = 0; static char orig_str[ADDR_STR_LEN];
@@ -203,22 +203,30 @@ static void choose_gw() switch ( routing_class ) {
case 1: /* fast connection */ - if ( ( gw_node->orig_node->gwflags > max_gw_class ) || ( ( gw_node->orig_node->gwflags == max_gw_class ) && ( gw_node->orig_node->packet_count > max_packets ) ) ) tmp_curr_gw = gw_node; + if ( ( gw_node->orig_node->gwflags > max_gw_class ) || ( ( gw_node->orig_node->gwflags == max_gw_class ) && ( gw_node->orig_node->packet_count > max_packets ) ) ) + tmp_curr_gw = gw_node; break;
case 2: /* stable connection */ - if ( ( ( gw_node->orig_node->packet_count * gw_node->orig_node->gwflags ) > max_gw_factor ) || ( ( ( gw_node->orig_node->packet_count * gw_node->orig_node->gwflags ) == max_gw_factor ) && ( gw_node->orig_node->packet_count > max_packets ) ) ) tmp_curr_gw = gw_node; + if ( ( ( gw_node->orig_node->packet_count * gw_node->orig_node->gwflags ) > max_gw_factor ) || ( ( ( gw_node->orig_node->packet_count * gw_node->orig_node->gwflags ) == max_gw_factor ) && ( gw_node->orig_node->packet_count > max_packets ) ) ) + tmp_curr_gw = gw_node; break;
default: /* use best statistic (olsr style) */ - if ( gw_node->orig_node->packet_count > max_packets ) tmp_curr_gw = gw_node; + if ( gw_node->orig_node->packet_count > max_packets ) + tmp_curr_gw = gw_node; break;
}
- if ( gw_node->orig_node->gwflags > max_gw_class ) max_gw_class = gw_node->orig_node->gwflags; - if ( gw_node->orig_node->packet_count > max_packets ) max_packets = gw_node->orig_node->packet_count; - if ( ( gw_node->orig_node->packet_count * gw_node->orig_node->gwflags ) > max_gw_class ) max_gw_factor = ( gw_node->orig_node->packet_count * gw_node->orig_node->gwflags ); + if ( gw_node->orig_node->gwflags > max_gw_class ) + max_gw_class = gw_node->orig_node->gwflags; + + if ( gw_node->orig_node->packet_count > max_packets ) + max_packets = gw_node->orig_node->packet_count; + + if ( ( gw_node->orig_node->packet_count * gw_node->orig_node->gwflags ) > max_gw_class ) + max_gw_factor = ( gw_node->orig_node->packet_count * gw_node->orig_node->gwflags );
if ( ( pref_gateway != 0 ) && ( pref_gateway == gw_node->orig_node->orig ) ) {
@@ -247,14 +255,20 @@ static void choose_gw()
}
- if (debug_level >= 1) { - addr_to_string( tmp_curr_gw->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 = tmp_curr_gw; - curr_gateway_ip = curr_gateway->orig_node->orig; - curr_gateway_batman_if = curr_gateway->orig_node->batman_if; + + /* may be the last gateway is now gone */ + if ( curr_gateway != NULL ) { + + 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();
@@ -1038,6 +1052,9 @@ int batman()
send_outstanding_packets();
+ if ( ( routing_class != 0 ) && ( curr_gateway == NULL ) ) + choose_gw(); + purge(); debug(); time_count++; diff --git a/posix.c b/posix.c index 1c58bf2..937768e 100644 --- a/posix.c +++ b/posix.c @@ -164,7 +164,7 @@ int add_ipip_tun( struct batman_if *batman_if, unsigned int dest_addr, char *tun return -1;
} - + printf( "1\n" ); if ( ( ioctl( *fd, TUNSETIFF, (void *) &ifr ) ) < 0 ) {
perror("TUNSETIFF"); @@ -172,7 +172,7 @@ int add_ipip_tun( struct batman_if *batman_if, unsigned int dest_addr, char *tun return -1;
} - + printf( "2\n" ); if ( ioctl( *fd, TUNSETPERSIST, 1 ) < 0 ) {
perror("TUNSETPERSIST"); @@ -181,7 +181,7 @@ int add_ipip_tun( struct batman_if *batman_if, unsigned int dest_addr, char *tun
}
- + printf( "3\n" ); tmp_fd = socket(AF_INET, SOCK_DGRAM, 0);
if ( tmp_fd < 0 ) { @@ -197,7 +197,7 @@ int add_ipip_tun( struct batman_if *batman_if, unsigned int dest_addr, char *tun addr.sin_family = AF_INET; memcpy( &ifr.ifr_addr, &addr, sizeof(struct sockaddr) );
- + printf( "4\n" ); if ( ioctl( tmp_fd, SIOCSIFADDR, &ifr) < 0 ) {
perror("SIOCSIFADDR"); @@ -206,7 +206,7 @@ int add_ipip_tun( struct batman_if *batman_if, unsigned int dest_addr, char *tun return -1;
} - + printf( "5\n" ); /* set ip of this remote point of tunnel */ memset( &addr, 0, sizeof(addr) ); addr.sin_addr.s_addr = dest_addr; @@ -222,6 +222,27 @@ int add_ipip_tun( struct batman_if *batman_if, unsigned int dest_addr, char *tun
}
+ if ( ioctl( tmp_fd, SIOCGIFFLAGS, &ifr) < 0 ) { + + perror("SIOCGIFFLAGS"); + del_ipip_tun( *fd ); + close( tmp_fd ); + return -1; + + } + + ifr.ifr_flags |= IFF_UP; + ifr.ifr_flags |= IFF_RUNNING; + + if ( ioctl( tmp_fd, SIOCSIFFLAGS, &ifr) < 0 ) { + + perror("SIOCSIFFLAGS"); + del_ipip_tun( *fd ); + close( tmp_fd ); + return -1; + + } + close( tmp_fd ); strncpy( tun_dev, ifr.ifr_name, IFNAMSIZ );