[commits] batman; test conversation; branch, master, updated. 84f5b39ce5c463cc2312eb4a8cd94234d841c054

postmaster at open-mesh.org postmaster at open-mesh.org
Sun Dec 19 23:44:30 CET 2010


The following commit has been merged in the master branch:
commit 43dd362b49c3e6d11b552f4385def3dab04316ec
Author: Marek Lindner <lindner_marek at yahoo.de>
Date:   Tue Oct 24 00:33:38 2006 +0200

    hna feature added - major fixes II

diff --git a/CHANGELOG b/CHANGELOG
index 5f54fd5..f42328e 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -19,6 +19,7 @@ new functions:
 - batman version check added
 - preferred gateway funtion added
 - UDP tunnel implemented
+- Network announcement implemented
 - daemonizing batman -> batmand
 - improving output / logging to syslog added
 - FreeBSD support added
diff --git a/batman.c b/batman.c
index 79656ce..2cef64d 100755
--- a/batman.c
+++ b/batman.c
@@ -279,14 +279,15 @@ static void choose_gw()
 
 
 
-static void update_routes( struct orig_node *orig_node )
+static void update_routes( struct orig_node *orig_node, unsigned char *hna_recv_buff, int hna_buff_len )
 {
 
 	struct list_head *neigh_pos, *pack_pos;
 	struct neigh_node *neigh_node, *next_hop;
 	struct pack_node *pack_node;
 	struct batman_if *max_if;
-	int max_pack, max_ttl, neigh_ttl[found_ifs], neigh_pkts[found_ifs];
+	int max_pack, max_ttl, neigh_ttl[found_ifs], neigh_pkts[found_ifs], hna_buff_count;
+	unsigned int hna, netmask;
 	static char orig_str[ADDR_STR_LEN], next_str[ADDR_STR_LEN];
 
 	if (debug_level == 3)
@@ -326,7 +327,8 @@ static void update_routes( struct orig_node *orig_node )
 		}
 	}
 
-	if (next_hop != NULL) {
+	if ( next_hop != NULL ) {
+
 		if (debug_level == 3) {
 			addr_to_string(orig_node->orig, orig_str, ADDR_STR_LEN);
 			addr_to_string(next_hop->addr, next_str, ADDR_STR_LEN);
@@ -336,13 +338,36 @@ static void update_routes( struct orig_node *orig_node )
 		orig_node->packet_count = neigh_pkts[max_if->if_num];
 
 		if (orig_node->router != next_hop->addr) {
+
 			if (debug_level == 3)
-			output("Route changed\n");
+				output("Route changed\n");
 
 			if (orig_node->router != 0) {
 				if (debug_level == 3)
 					output("Deleting previous route\n");
 
+				/* remove old announced network(s) */
+				if ( orig_node->hna_buff_len > 0 ) {
+
+					hna_buff_count = 0;
+
+					while ( ( hna_buff_count + 1 ) * 5 <= orig_node->hna_buff_len ) {
+
+						memcpy( &hna, ( unsigned int *)&orig_node->hna_buff[ hna_buff_count * 5 ], 4 );
+						netmask = ( unsigned int )orig_node->hna_buff[ ( hna_buff_count * 5 ) + 4 ];
+
+						if ( ( netmask > 0 ) && ( netmask < 33 ) )
+							add_del_route( hna, netmask, orig_node->orig, 1, orig_node->batman_if->dev, orig_node->batman_if->udp_send_sock );
+
+						hna_buff_count++;
+
+					}
+
+					free_memory( orig_node->hna_buff );
+					orig_node->hna_buff_len = 0;
+
+				}
+
 				add_del_route(orig_node->orig, 32, orig_node->router, 1, orig_node->batman_if->dev, orig_node->batman_if->udp_send_sock);
 			}
 
@@ -350,12 +375,37 @@ static void update_routes( struct orig_node *orig_node )
 				output("Adding new route\n");
 
 
-			/* TODO: maybe the order delete, add should be changed ???? */
 			orig_node->batman_if = max_if;
 			add_del_route(orig_node->orig, 32, next_hop->addr, 0, orig_node->batman_if->dev, orig_node->batman_if->udp_send_sock);
 
 			orig_node->router = next_hop->addr;
+
+			/* add new announced network(s) */
+			if ( hna_buff_len > 0 ) {
+
+				orig_node->hna_buff = alloc_memory( hna_buff_len );
+				orig_node->hna_buff_len = hna_buff_len;
+
+				memcpy( orig_node->hna_buff, hna_recv_buff, hna_buff_len );
+
+				hna_buff_count = 0;
+
+				while ( ( hna_buff_count + 1 ) * 5 <= orig_node->hna_buff_len ) {
+
+					memcpy( &hna, ( unsigned int *)&orig_node->hna_buff[ hna_buff_count * 5 ], 4 );
+					netmask = ( unsigned int )orig_node->hna_buff[ ( hna_buff_count * 5 ) + 4 ];
+
+					if ( ( netmask > 0 ) && ( netmask < 33 ) )
+						add_del_route( hna, netmask, orig_node->orig, 0, orig_node->batman_if->dev, orig_node->batman_if->udp_send_sock );
+
+					hna_buff_count++;
+
+				}
+
+			}
+
 		}
+
 	}
 
 }
@@ -403,7 +453,7 @@ static void update_gw_list( struct orig_node *orig_node, unsigned char new_gwfla
 
 	if (debug_level == 1) {
 		addr_to_string( orig_node->orig, orig_str, ADDR_STR_LEN );
-		printf( "Found new gateway %s with class %i\n", orig_str, new_gwflags );
+		printf( "Found new gateway %s (class: %i)\n", orig_str, new_gwflags );
 	}
 
 	gw_node = alloc_memory(sizeof(struct gw_node));
@@ -551,8 +601,6 @@ void update_originator( struct packet *in, unsigned int neigh, struct batman_if
 	struct orig_node *orig_node;
 	struct neigh_node *neigh_node = NULL;
 	struct pack_node *pack_node = NULL;
-	unsigned int hna, netmask;
-	int hna_buff_count = 0;
 
 	if (debug_level == 3)
 		output("update_originator(): Searching and updating originator entry of received packet,  \n");
@@ -613,56 +661,7 @@ void update_originator( struct packet *in, unsigned int neigh, struct batman_if
 	pack_node->ttl = in->ttl;
 	pack_node->time = get_time();
 
-	/* announced network(s) */
-	if ( ( hna_buff_len > 0 ) || ( orig_node->hna_buff_len > 0 ) ) {
-
-		/* remove old announced network(s) */
-		if ( orig_node->hna_buff_len > 0 ) {
-
-			while ( ( hna_buff_count + 1 ) * 5 <= orig_node->hna_buff_len ) {
-
-				memmove( &hna, ( unsigned int *)&orig_node->hna_buff[ hna_buff_count * 5 ], 4 );
-				netmask = ( unsigned int )orig_node->hna_buff[ ( hna_buff_count * 5 ) + 4 ];
-
-				if ( netmask < 32 )
-					add_del_route( hna, netmask, orig_node->orig, 1, orig_node->batman_if->dev, orig_node->batman_if->udp_send_sock );
-
-				hna_buff_count++;
-
-			}
-
-			free_memory( orig_node->hna_buff );
-			orig_node->hna_buff_len = 0;
-
-		}
-
-		/* add new announced network(s) */
-		if ( hna_buff_len > 0 ) {
-
-			orig_node->hna_buff = alloc_memory( hna_buff_len );
-			orig_node->hna_buff_len = hna_buff_len;
-
-			memcpy( orig_node->hna_buff, hna_recv_buff, hna_buff_len );
-
-			hna_buff_count = 0;
-
-			while ( ( hna_buff_count + 1 ) * 5 <= orig_node->hna_buff_len ) {
-
-				memmove( &hna, ( unsigned int *)&orig_node->hna_buff[ hna_buff_count * 5 ], 4 );
-				netmask = ( unsigned int )orig_node->hna_buff[ ( hna_buff_count * 5 ) + 4 ];
-
-				if ( netmask < 32 )
-					add_del_route( hna, netmask, orig_node->orig, 0, orig_node->batman_if->dev, orig_node->batman_if->udp_send_sock );
-
-				hna_buff_count++;
-
-			}
-
-		}
-
-	}
-
-	update_routes( orig_node );
+	update_routes( orig_node, hna_recv_buff, hna_buff_len );
 
 }
 
@@ -928,7 +927,7 @@ void purge()
 					memmove( &hna, ( unsigned int *)&orig_node->hna_buff[ hna_buff_count * 5 ], 4 );
 					netmask = ( unsigned int )orig_node->hna_buff[ ( hna_buff_count * 5 ) + 4 ];
 
-					if ( netmask < 32 )
+					if ( ( netmask > 0 ) && ( netmask < 33 ) )
 						add_del_route( hna, netmask, orig_node->orig, 1, orig_node->batman_if->dev, orig_node->batman_if->udp_send_sock );
 
 					hna_buff_count++;
@@ -945,7 +944,7 @@ void purge()
 				if (debug_level == 3)
 					output("Deleting route to originator \n");
 
-				add_del_route(orig_node->orig, 32, 0, 1, orig_node->batman_if->dev, orig_node->batman_if->udp_send_sock);
+				add_del_route(orig_node->orig, 32, orig_node->router, 1, orig_node->batman_if->dev, orig_node->batman_if->udp_send_sock);
 
 				free_memory(orig_node);
 
@@ -1154,10 +1153,10 @@ int batman()
 
 							addr_to_string(hna, orig_str, sizeof (orig_str));
 
-							if ( netmask > 32 )
-								printf( "hna: %s/%i -> ignoring (invalid netmask)\n", orig_str, netmask );
-							else
+							if ( ( netmask > 0 ) && ( netmask < 33 ) )
 								printf( "hna: %s/%i\n", orig_str, netmask );
+							else
+								printf( "hna: %s/%i -> ignoring (invalid netmask)\n", orig_str, netmask );
 
 							hna_buff_count++;
 
@@ -1233,10 +1232,34 @@ int batman()
 		printf("Deleting all BATMAN routes\n");
 
 	list_for_each(orig_pos, &orig_list) {
+
 		orig_node = list_entry(orig_pos, struct orig_node, list);
 
-		if (orig_node->router != 0)
+		/* remove old announced network(s) */
+		if ( orig_node->hna_buff_len > 0 ) {
+
+			hna_buff_count = 0;
+
+			while ( ( hna_buff_count + 1 ) * 5 <= orig_node->hna_buff_len ) {
+
+				memcpy( &hna, ( unsigned int *)&orig_node->hna_buff[ hna_buff_count * 5 ], 4 );
+				netmask = ( unsigned int )orig_node->hna_buff[ ( hna_buff_count * 5 ) + 4 ];
+
+				if ( ( netmask > 0 ) && ( netmask < 33 ) )
+					add_del_route( hna, netmask, orig_node->orig, 1, orig_node->batman_if->dev, orig_node->batman_if->udp_send_sock );
+
+				hna_buff_count++;
+
+			}
+
+			free_memory( orig_node->hna_buff );
+			orig_node->hna_buff_len = 0;
+
+		}
+
+		if ( orig_node->router != 0 )
 			add_del_route(orig_node->orig, 32, orig_node->router, 1, orig_node->batman_if->dev, batman_if->udp_send_sock);
+
 	}
 
 	set_forwarding(forward_old);
diff --git a/bsd.c b/bsd.c
index 0bf11c4..5174414 100644
--- a/bsd.c
+++ b/bsd.c
@@ -100,8 +100,7 @@ struct rt_msg
 	struct sockaddr_in gateway;
 };
 
-void add_del_route(unsigned int dest, unsigned int router, int del,
-		char *dev, int sock)
+void add_del_route( unsigned int dest, unsigned int netmask, unsigned int router, int del, char *dev, int sock ) {
 {
 	char str1[16], str2[16];
 	int rt_sock;
diff --git a/linux.c b/linux.c
index 1c3c4d4..d5cb6d6 100755
--- a/linux.c
+++ b/linux.c
@@ -108,10 +108,9 @@ void add_del_route( unsigned int dest, unsigned int netmask, unsigned int router
 	addr = (struct sockaddr_in *)&route.rt_genmask;
 
 	addr->sin_family = AF_INET;
-	addr->sin_addr.s_addr = netmask;
-// 	addr->sin_addr.s_addr = ( ( ( dest == 0 ) && ( router == 0 ) ) ? 0x00000000 : 0xffffffff );
+	addr->sin_addr.s_addr = ( netmask == 32 ? 0xffffffff : htonl( ~ ( 0xffffffff >> netmask ) ) );
 
-	route.rt_flags = ( netmask == 32 ? RTF_HOST | RTF_UP : RTF_UP );
+	route.rt_flags = ( netmask == 32 ? ( RTF_HOST | RTF_UP ) : RTF_UP );
 	route.rt_metric = 1;
 
 	if ( (dest != router) || ( ( dest == 0 ) && ( router == 0 ) ) )
@@ -124,7 +123,6 @@ void add_del_route( unsigned int dest, unsigned int netmask, unsigned int router
 		if ( ( dest == 0 ) && ( router == 0 ) ) {
 
 			route.rt_metric = 0;
-			route.rt_flags = RTF_UP;
 
 			if ( debug_level == 1 ) {
 				printf("%s default route via %s\n", del ? "Deleting" : "Adding", dev);
@@ -137,9 +135,9 @@ void add_del_route( unsigned int dest, unsigned int netmask, unsigned int router
 			route.rt_flags |= RTF_GATEWAY;
 
 			if ( debug_level == 1 ) {
-				printf("%s route to %s via %s/%i (%s)\n", del ? "Deleting" : "Adding", str1, str2, netmask, dev);
+				printf("%s route to %s/%i via %s (%s)\n", del ? "Deleting" : "Adding", str1, netmask, str2, dev);
 			} else if ( debug_level == 3 ) {
-				output("%s route to %s via %s/%i (%s)\n", del ? "Deleting" : "Adding", str1, str2, netmask, dev);
+				output("%s route to %s/%i via %s (%s)\n", del ? "Deleting" : "Adding", str1, netmask, str2, dev);
 			}
 
 		}
@@ -154,11 +152,10 @@ void add_del_route( unsigned int dest, unsigned int netmask, unsigned int router
 
 	}
 
-
 	route.rt_dev = dev;
 
 	if ( ioctl( sock, del ? SIOCDELRT : SIOCADDRT, &route ) < 0 ) {
-		snprintf( log_str, sizeof( log_str ), "Error - can't %s route to %s via %s: %s\n", del ? "delete" : "add", str1, str2, strerror(errno) );
+		snprintf( log_str, sizeof( log_str ), "Error - can't %s route to %s/%i via %s: %s\n", del ? "delete" : "add", str1, netmask, str2, strerror(errno) );
 		do_log( log_str, strerror(errno) );
 	}
 

-- 
batman; test conversation


More information about the commits mailing list