The following commit has been merged in the master branch: commit e51f3f885e79efb98f95a0f34a22c0dab03f43ae Author: Marek Lindner lindner_marek@yahoo.de Date: Tue Aug 22 20:14:00 2006 +0200
tcp server for gw function
diff --git a/batman.c b/batman.c index 786f702..9ae5ed0 100755 --- a/batman.c +++ b/batman.c @@ -315,7 +315,7 @@ static void update_routes( struct orig_node *orig_node ) if (debug_level >= 2) output("Deleting previous route\n");
- add_del_route(orig_node->orig, orig_node->router, 1, orig_node->batman_if->dev, orig_node->batman_if->send_sock); + add_del_route(orig_node->orig, orig_node->router, 1, orig_node->batman_if->dev, orig_node->batman_if->udp_send_sock); }
if (debug_level >= 2) { output("Adding new route\n"); } @@ -323,7 +323,7 @@ static void update_routes( struct orig_node *orig_node )
/* TODO: maybe the order delete, add should be changed ???? */ orig_node->batman_if = max_if; - add_del_route(orig_node->orig, next_hop->addr, 0, orig_node->batman_if->dev, orig_node->batman_if->send_sock); + add_del_route(orig_node->orig, next_hop->addr, 0, orig_node->batman_if->dev, orig_node->batman_if->udp_send_sock);
orig_node->router = next_hop->addr; } @@ -650,7 +650,7 @@ void send_outstanding_packets()
batman_if = list_entry(if_pos, struct batman_if, list);
- if (send_packet((unsigned char *)pack, sizeof (struct packet), &batman_if->broad, batman_if->send_sock) < 0) { + if (send_packet((unsigned char *)pack, sizeof (struct packet), &batman_if->broad, batman_if->udp_send_sock) < 0) { output("ERROR: send_packet returned -1 \n"); exit( -1); } @@ -718,7 +718,7 @@ void purge() /* for all origins... */ list_for_each_safe(orig_pos, orig_temp, &orig_list) { orig_node = list_entry(orig_pos, struct orig_node, list); - + /* for all neighbours towards the origins... */ list_for_each_safe(neigh_pos, neigh_temp, &orig_node->neigh_list) { neigh_node = list_entry(neigh_pos, struct neigh_node, list); @@ -790,7 +790,7 @@ void purge() if (debug_level >= 2) output("Deleting route to originator \n");
- add_del_route(orig_node->orig, 0, 1, orig_node->batman_if->dev, orig_node->batman_if->send_sock); + add_del_route(orig_node->orig, 0, 1, orig_node->batman_if->dev, orig_node->batman_if->udp_send_sock); free_memory(orig_node);
} @@ -987,7 +987,7 @@ int batman() orig_node = list_entry(orig_pos, struct orig_node, list);
if (orig_node->router != 0) - add_del_route(orig_node->orig, orig_node->router, 1, orig_node->batman_if->dev, batman_if->send_sock); + add_del_route(orig_node->orig, orig_node->router, 1, orig_node->batman_if->dev, batman_if->udp_send_sock); }
set_forwarding(forward_old); diff --git a/batman.h b/batman.h index 6d1e21e..d26e2c7 100755 --- a/batman.h +++ b/batman.h @@ -52,7 +52,7 @@ extern int found_ifs;
extern struct list_head if_list; extern struct vis_if vis_if; - + struct packet { unsigned long orig; @@ -113,8 +113,9 @@ struct batman_if { struct list_head list; char *dev; - int send_sock; - int recv_sock; + int udp_send_sock; + int udp_recv_sock; + int tcp_gw_sock; int if_num; struct sockaddr_in addr; struct sockaddr_in broad; diff --git a/linux.c b/linux.c index 1d1bd52..0de94ff 100755 --- a/linux.c +++ b/linux.c @@ -114,9 +114,9 @@ void close_all_sockets()
list_for_each(if_pos, &if_list) { batman_if = list_entry(if_pos, struct batman_if, list); - close(batman_if->recv_sock); + close(batman_if->udp_recv_sock); } - + if(vis_if.sock) close(vis_if.sock); } @@ -239,8 +239,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->recv_sock, &wait_set); - if ( batman_if->recv_sock > max_sock ) max_sock = batman_if->recv_sock; + FD_SET(batman_if->udp_recv_sock, &wait_set); + if ( batman_if->udp_recv_sock > max_sock ) max_sock = batman_if->udp_recv_sock;
}
@@ -266,9 +266,9 @@ int receive_packet(unsigned char *buff, int len, unsigned int *neigh, unsigned i list_for_each(if_pos, &if_list) { batman_if = list_entry(if_pos, struct batman_if, list);
- if ( FD_ISSET( batman_if->recv_sock, &wait_set) ) { + if ( FD_ISSET( batman_if->udp_recv_sock, &wait_set) ) {
- if (recvfrom(batman_if->recv_sock, buff, len, 0, (struct sockaddr *)&addr, &addr_len) < 0) + if (recvfrom(batman_if->udp_recv_sock, buff, len, 0, (struct sockaddr *)&addr, &addr_len) < 0) { fprintf(stderr, "Cannot receive packet: %s\n", strerror(errno)); return -1; @@ -305,7 +305,7 @@ static void handler(int sig)
int main(int argc, char *argv[]) { - struct in_addr tmp_pref_gw; + struct in_addr tmp_ip_holder; struct batman_if *batman_if; struct ifreq int_req; int on = 1, res, optchar, found_args = 1; @@ -313,7 +313,7 @@ int main(int argc, char *argv[]) unsigned int vis_server = 0;
dev = NULL; - memset(&tmp_pref_gw, 0, sizeof (struct in_addr)); + memset(&tmp_ip_holder, 0, sizeof (struct in_addr));
printf( "B.A.T.M.A.N-II v%s (internal version %i)\n", VERSION, BATMAN_VERSION );
@@ -382,14 +382,14 @@ int main(int argc, char *argv[]) case 'p':
errno = 0; - if ( inet_pton(AF_INET, optarg, &tmp_pref_gw) < 1 ) { + if ( inet_pton(AF_INET, optarg, &tmp_ip_holder) < 1 ) {
printf( "Invalid preferred gateway IP specified: %s\n", optarg ); exit(EXIT_FAILURE);
}
- pref_gateway = tmp_pref_gw.s_addr; + pref_gateway = tmp_ip_holder.s_addr;
found_args += 2; break; @@ -397,14 +397,14 @@ int main(int argc, char *argv[]) case 's':
errno = 0; - if ( inet_pton(AF_INET, optarg, &tmp_pref_gw) < 1 ) { + if ( inet_pton(AF_INET, optarg, &tmp_ip_holder) < 1 ) {
printf( "Invalid preferred visualation server IP specified: %s\n", optarg ); exit(EXIT_FAILURE);
}
- vis_server = tmp_pref_gw.s_addr; + vis_server = tmp_ip_holder.s_addr;
found_args += 2; @@ -436,9 +436,9 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); }
- batman_if->recv_sock = socket(PF_INET, SOCK_DGRAM, 0); + batman_if->udp_recv_sock = socket(PF_INET, SOCK_DGRAM, 0);
- if (batman_if->recv_sock < 0) + if (batman_if->udp_recv_sock < 0) { fprintf(stderr, "Cannot create socket: %s", strerror(errno)); exit(EXIT_FAILURE); @@ -447,7 +447,7 @@ int main(int argc, char *argv[]) memset(&int_req, 0, sizeof (struct ifreq)); strcpy(int_req.ifr_name, batman_if->dev);
- if (ioctl(batman_if->recv_sock, SIOCGIFADDR, &int_req) < 0) + if (ioctl(batman_if->udp_recv_sock, SIOCGIFADDR, &int_req) < 0) { fprintf(stderr, "Cannot get IP address of interface %s\n", batman_if->dev); close_all_sockets(); @@ -458,7 +458,7 @@ int main(int argc, char *argv[]) batman_if->addr.sin_port = htons(PORT); batman_if->addr.sin_addr.s_addr = ((struct sockaddr_in *)&int_req.ifr_addr)->sin_addr.s_addr;
- if (ioctl(batman_if->recv_sock, SIOCGIFBRDADDR, &int_req) < 0) + if (ioctl(batman_if->udp_recv_sock, SIOCGIFBRDADDR, &int_req) < 0) { fprintf(stderr, "Cannot get broadcast IP address of interface %s\n", batman_if->dev); close_all_sockets(); @@ -469,21 +469,34 @@ int main(int argc, char *argv[]) batman_if->broad.sin_port = htons(PORT); batman_if->broad.sin_addr.s_addr = ((struct sockaddr_in *)&int_req.ifr_broadaddr)->sin_addr.s_addr;
- if (setsockopt(batman_if->recv_sock, SOL_SOCKET, SO_BROADCAST, &on, sizeof (int)) < 0) + if (setsockopt(batman_if->udp_recv_sock, SOL_SOCKET, SO_BROADCAST, &on, sizeof (int)) < 0) { fprintf(stderr, "Cannot enable broadcasts: %s\n", strerror(errno)); close_all_sockets(); exit(EXIT_FAILURE); }
- if (bind(batman_if->recv_sock, (struct sockaddr *)&batman_if->broad, sizeof (struct sockaddr_in)) < 0) + if (bind(batman_if->udp_recv_sock, (struct sockaddr *)&batman_if->broad, sizeof (struct sockaddr_in)) < 0) { fprintf(stderr, "Cannot bind socket: %s\n", strerror(errno)); close_all_sockets(); exit(EXIT_FAILURE); }
- batman_if->send_sock = batman_if->recv_sock; + batman_if->udp_send_sock = batman_if->udp_recv_sock; + + if ( gateway_class != 0 ) { + + batman_if->tcp_gw_sock = socket(PF_INET, SOCK_STREAM, 0); + + if (batman_if->tcp_gw_sock < 0) { + fprintf(stderr, "Cannot create socket: %s", strerror(errno)); + 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)); @@ -504,7 +517,7 @@ int main(int argc, char *argv[]) vis_if.sock = socket( PF_INET, SOCK_DGRAM, 0); } else memset(&vis_if, 0, sizeof(vis_if)); - +
if (found_ifs == 0) { @@ -527,6 +540,13 @@ int main(int argc, char *argv[]) return 1; }
+ if ( ( routing_class == 0 ) && ( pref_gateway != 0 ) ) + { + fprintf(stderr, "Error - preferred gateway can't be set without specifying routing class !\n"); + usage(); + return 1; + } + if ( debug_level > 0 ) printf("debug level: %i\n", debug_level); if ( ( debug_level > 0 ) && ( orginator_interval != 1000 ) ) printf( "orginator interval: %i\n", orginator_interval ); if ( ( debug_level > 0 ) && ( gateway_class > 0 ) ) printf( "gateway class: %i\n", gateway_class );