The following commit has been merged in the master branch:
commit 22ecce4e638c4b7cb98c6e9f438b5105cfe7dccc
Author: Marek Lindner <lindner_marek(a)yahoo.de>
Date: Fri Feb 2 15:50:43 2007 +0100
complete 64bit transition
diff --git a/batman.c b/batman.c
index 1178d15..bb69bdc 100644
--- a/batman.c
+++ b/batman.c
@@ -38,7 +38,7 @@
* Beware that high debugging levels eat a lot of CPU-Power
*/
-short debug_level = 0;
+uint8_t debug_level = 0;
/* "-g" is the command line switch for the gateway class,
* 0 no gateway
@@ -69,7 +69,7 @@ char *gw2string[] = { "No Gateway",
"6 MBit",
">6 MBit" };
-short gateway_class = 0;
+uint8_t gateway_class = 0;
/* "-r" is the command line switch for the routing class,
* 0 set no default route
@@ -79,24 +79,24 @@ short gateway_class = 0;
* this option is used to set the routing behaviour
*/
-short routing_class = 0;
+uint8_t routing_class = 0;
-unsigned long orginator_interval = 1000; /* orginator message interval in miliseconds */
+int16_t orginator_interval = 1000; /* orginator message interval in miliseconds */
-unsigned int bidirectional_timeout = 0; /* bidirectional neighbour reply timeout in ms */
+uint32_t bidirectional_timeout = 0; /* bidirectional neighbour reply timeout in ms */
struct gw_node *curr_gateway = NULL;
pthread_t curr_gateway_thread_id = 0;
-unsigned int pref_gateway = 0;
+uint32_t pref_gateway = 0;
unsigned char *hna_buff = NULL;
-short num_hna = 0;
+uint8_t num_hna = 0;
-short found_ifs = 0;
-int receive_max_sock = 0;
+uint8_t found_ifs = 0;
+int32_t receive_max_sock = 0;
fd_set receive_wait_set;
@@ -111,68 +111,75 @@ struct vis_if vis_if;
struct unix_if unix_if;
struct debug_clients debug_clients;
-void usage(void)
-{
- fprintf(stderr, "Usage: batman [options] interface [interface interface]\n" );
- fprintf(stderr, " -a announce network(s)\n" );
- fprintf(stderr, " -b run connection in batch mode\n" );
- fprintf(stderr, " -c connect via unix socket\n" );
- fprintf(stderr, " -d debug level\n" );
- fprintf(stderr, " -g gateway class\n" );
- fprintf(stderr, " -h this help\n" );
- fprintf(stderr, " -H verbose help\n" );
- fprintf(stderr, " -o orginator interval in ms\n" );
- fprintf(stderr, " -p preferred gateway\n" );
- fprintf(stderr, " -r routing class\n" );
- fprintf(stderr, " -s visualisation server\n" );
- fprintf(stderr, " -v print version\n" );
+
+
+void usage( void ) {
+
+ fprintf( stderr, "Usage: batman [options] interface [interface interface]\n" );
+ fprintf( stderr, " -a announce network(s)\n" );
+ fprintf( stderr, " -b run connection in batch mode\n" );
+ fprintf( stderr, " -c connect via unix socket\n" );
+ fprintf( stderr, " -d debug level\n" );
+ fprintf( stderr, " -g gateway class\n" );
+ fprintf( stderr, " -h this help\n" );
+ fprintf( stderr, " -H verbose help\n" );
+ fprintf( stderr, " -o orginator interval in ms\n" );
+ fprintf( stderr, " -p preferred gateway\n" );
+ fprintf( stderr, " -r routing class\n" );
+ fprintf( stderr, " -s visualisation server\n" );
+ fprintf( stderr, " -v print version\n" );
+
}
-void verbose_usage(void)
-{
- fprintf(stderr, "Usage: batman [options] interface [interface interface]\n\n" );
- fprintf(stderr, " -a announce network(s)\n" );
- fprintf(stderr, " network/netmask is expected\n" );
- fprintf(stderr, " -b run connection in batch mode\n" );
- fprintf(stderr, " -c connect to running batmand via unix socket\n" );
- fprintf(stderr, " -d debug level\n" );
- fprintf(stderr, " default: 0 -> debug disabled\n" );
- fprintf(stderr, " allowed values: 1 -> list neighbours\n" );
- fprintf(stderr, " 2 -> list gateways\n" );
- fprintf(stderr, " 3 -> observe batman\n" );
- fprintf(stderr, " 4 -> observe batman (very verbose)\n\n" );
- fprintf(stderr, " -g gateway class\n" );
- fprintf(stderr, " default: 0 -> this is not an internet gateway\n" );
- fprintf(stderr, " allowed values: 1 -> modem line\n" );
- fprintf(stderr, " 2 -> ISDN line\n" );
- fprintf(stderr, " 3 -> double ISDN\n" );
- fprintf(stderr, " 4 -> 256 KBit\n" );
- fprintf(stderr, " 5 -> UMTS / 0.5 MBit\n" );
- fprintf(stderr, " 6 -> 1 MBit\n" );
- fprintf(stderr, " 7 -> 2 MBit\n" );
- fprintf(stderr, " 8 -> 3 MBit\n" );
- fprintf(stderr, " 9 -> 5 MBit\n" );
- fprintf(stderr, " 10 -> 6 MBit\n" );
- fprintf(stderr, " 11 -> >6 MBit\n\n" );
- fprintf(stderr, " -h shorter help\n" );
- fprintf(stderr, " -H this help\n" );
- fprintf(stderr, " -o orginator interval in ms\n" );
- fprintf(stderr, " default: 1000, allowed values: >0\n\n" );
- fprintf(stderr, " -p preferred gateway\n" );
- fprintf(stderr, " default: none, allowed values: IP\n\n" );
- fprintf(stderr, " -r routing class (only needed if gateway class = 0)\n" );
- fprintf(stderr, " default: 0 -> set no default route\n" );
- fprintf(stderr, " allowed values: 1 -> use fast internet connection\n" );
- fprintf(stderr, " 2 -> use stable internet connection\n" );
- fprintf(stderr, " 3 -> use best statistic internet connection (olsr style)\n\n" );
- fprintf(stderr, " -s visualisation server\n" );
- fprintf(stderr, " default: none, allowed values: IP\n\n" );
- fprintf(stderr, " -v print version\n" );
+
+
+void verbose_usage( void ) {
+
+ fprintf( stderr, "Usage: batman [options] interface [interface interface]\n\n" );
+ fprintf( stderr, " -a announce network(s)\n" );
+ fprintf( stderr, " network/netmask is expected\n" );
+ fprintf( stderr, " -b run connection in batch mode\n" );
+ fprintf( stderr, " -c connect to running batmand via unix socket\n" );
+ fprintf( stderr, " -d debug level\n" );
+ fprintf( stderr, " default: 0 -> debug disabled\n" );
+ fprintf( stderr, " allowed values: 1 -> list neighbours\n" );
+ fprintf( stderr, " 2 -> list gateways\n" );
+ fprintf( stderr, " 3 -> observe batman\n" );
+ fprintf( stderr, " 4 -> observe batman (very verbose)\n\n" );
+ fprintf( stderr, " -g gateway class\n" );
+ fprintf( stderr, " default: 0 -> this is not an internet gateway\n" );
+ fprintf( stderr, " allowed values: 1 -> modem line\n" );
+ fprintf( stderr, " 2 -> ISDN line\n" );
+ fprintf( stderr, " 3 -> double ISDN\n" );
+ fprintf( stderr, " 4 -> 256 KBit\n" );
+ fprintf( stderr, " 5 -> UMTS / 0.5 MBit\n" );
+ fprintf( stderr, " 6 -> 1 MBit\n" );
+ fprintf( stderr, " 7 -> 2 MBit\n" );
+ fprintf( stderr, " 8 -> 3 MBit\n" );
+ fprintf( stderr, " 9 -> 5 MBit\n" );
+ fprintf( stderr, " 10 -> 6 MBit\n" );
+ fprintf( stderr, " 11 -> >6 MBit\n\n" );
+ fprintf( stderr, " -h shorter help\n" );
+ fprintf( stderr, " -H this help\n" );
+ fprintf( stderr, " -o orginator interval in ms\n" );
+ fprintf( stderr, " default: 1000, allowed values: >0\n\n" );
+ fprintf( stderr, " -p preferred gateway\n" );
+ fprintf( stderr, " default: none, allowed values: IP\n\n" );
+ fprintf( stderr, " -r routing class (only needed if gateway class = 0)\n" );
+ fprintf( stderr, " default: 0 -> set no default route\n" );
+ fprintf( stderr, " allowed values: 1 -> use fast internet connection\n" );
+ fprintf( stderr, " 2 -> use stable internet connection\n" );
+ fprintf( stderr, " 3 -> use best statistic internet connection (olsr style)\n\n" );
+ fprintf( stderr, " -s visualisation server\n" );
+ fprintf( stderr, " default: none, allowed values: IP\n\n" );
+ fprintf( stderr, " -v print version\n" );
}
+
+
/* this function finds or creates an originator entry for the given address if it does not exits */
-struct orig_node *get_orig_node( unsigned int addr ) {
+struct orig_node *get_orig_node( uint32_t addr ) {
struct list_head *pos;
struct orig_node *orig_node;
@@ -206,16 +213,17 @@ struct orig_node *get_orig_node( unsigned int addr ) {
}
-void add_del_hna( struct orig_node *orig_node, int del ) {
- int hna_buff_count = 0;
- unsigned int hna, netmask;
+void add_del_hna( struct orig_node *orig_node, int8_t del ) {
+
+ uint16_t hna_buff_count = 0;
+ uint32_t hna, netmask;
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 ];
+ memcpy( &hna, ( uint32_t *)&orig_node->hna_buff[ hna_buff_count * 5 ], 4 );
+ netmask = ( uint32_t )orig_node->hna_buff[ ( hna_buff_count * 5 ) + 4 ];
if ( ( netmask > 0 ) && ( netmask < 33 ) )
add_del_route( hna, netmask, orig_node->router->addr, del, orig_node->batman_if->dev, orig_node->batman_if->udp_send_sock );
@@ -239,7 +247,7 @@ static void choose_gw() {
struct list_head *pos;
struct gw_node *gw_node, *tmp_curr_gw = NULL;
- int max_gw_class = 0, max_packets = 0, max_gw_factor = 0;
+ uint8_t max_gw_class = 0, max_packets = 0, max_gw_factor = 0;
static char orig_str[ADDR_STR_LEN];
@@ -343,7 +351,7 @@ static void choose_gw() {
-static void update_routes( struct orig_node *orig_node, struct neigh_node *neigh_node, unsigned char *hna_recv_buff, int hna_buff_len ) {
+static void update_routes( struct orig_node *orig_node, struct neigh_node *neigh_node, unsigned char *hna_recv_buff, int16_t hna_buff_len ) {
static char orig_str[ADDR_STR_LEN], next_str[ADDR_STR_LEN];
@@ -431,13 +439,15 @@ static void update_routes( struct orig_node *orig_node, struct neigh_node *neigh
}
-static void update_gw_list( struct orig_node *orig_node, unsigned char new_gwflags ) {
+
+
+static void update_gw_list( struct orig_node *orig_node, uint8_t new_gwflags ) {
struct list_head *gw_pos, *gw_pos_tmp;
struct gw_node *gw_node;
static char orig_str[ADDR_STR_LEN];
- list_for_each_safe(gw_pos, gw_pos_tmp, &gw_list) {
+ list_for_each_safe( gw_pos, gw_pos_tmp, &gw_list ) {
gw_node = list_entry(gw_pos, struct gw_node, list);
@@ -469,15 +479,15 @@ static void update_gw_list( struct orig_node *orig_node, unsigned char new_gwfla
addr_to_string( orig_node->orig, orig_str, ADDR_STR_LEN );
debug_output( 3, "Found new gateway %s -> class: %i - %s\n", orig_str, new_gwflags, gw2string[new_gwflags] );
- gw_node = debugMalloc(sizeof(struct gw_node), 5);
- memset(gw_node, 0, sizeof(struct gw_node));
- INIT_LIST_HEAD(&gw_node->list);
+ gw_node = debugMalloc( sizeof(struct gw_node), 5 );
+ memset( gw_node, 0, sizeof(struct gw_node) );
+ INIT_LIST_HEAD( &gw_node->list );
gw_node->orig_node = orig_node;
gw_node->unavail_factor = 0;
gw_node->last_failure = get_time();
- list_add_tail(&gw_node->list, &gw_list);
+ list_add_tail( &gw_node->list, &gw_list );
choose_gw();
@@ -492,7 +502,7 @@ void debug() {
struct orig_node *orig_node;
struct neigh_node *neigh_node;
struct gw_node *gw_node;
- unsigned int batman_count = 0;
+ uint16_t batman_count = 0;
static char str[ADDR_STR_LEN], str2[ADDR_STR_LEN];
@@ -500,7 +510,7 @@ void debug() {
debug_output( 2, "BOD\n" );
- if ( list_empty(&gw_list) ) {
+ if ( list_empty( &gw_list ) ) {
debug_output( 2, "No gateways in range ...\n" );
@@ -543,8 +553,8 @@ void debug() {
}
- list_for_each(orig_pos, &orig_list) {
- orig_node = list_entry(orig_pos, struct orig_node, list);
+ list_for_each( orig_pos, &orig_list ) {
+ orig_node = list_entry( orig_pos, struct orig_node, list );
if ( orig_node->router == NULL )
continue;
@@ -557,10 +567,10 @@ void debug() {
debug_output( 1, "%s, GW: %s(%i) via:", str, str2, orig_node->router->packet_count );
debug_output( 4, "%s, GW: %s(%i), last_aware:%u via:\n", str, str2, orig_node->router->packet_count, orig_node->last_aware );
- list_for_each(neigh_pos, &orig_node->neigh_list) {
- neigh_node = list_entry(neigh_pos, struct neigh_node, list);
+ list_for_each( neigh_pos, &orig_node->neigh_list ) {
+ neigh_node = list_entry( neigh_pos, struct neigh_node, list );
- addr_to_string(neigh_node->addr, str, sizeof (str));
+ addr_to_string( neigh_node->addr, str, sizeof (str) );
debug_output( 1, " %s(%i)", str, neigh_node->packet_count );
debug_output( 4, "\t\t%s (%d)\n", str, neigh_node->packet_count );
@@ -586,19 +596,19 @@ void debug() {
-int isDuplicate( unsigned int orig, unsigned short seqno ) {
+int isDuplicate( uint32_t orig, uint16_t seqno ) {
struct list_head *orig_pos, *neigh_pos;
struct orig_node *orig_node;
struct neigh_node *neigh_node;
- list_for_each(orig_pos, &orig_list) {
- orig_node = list_entry(orig_pos, struct orig_node, list);
+ list_for_each( orig_pos, &orig_list ) {
+ orig_node = list_entry( orig_pos, struct orig_node, list );
if ( orig == orig_node->orig ) {
- list_for_each(neigh_pos, &orig_node->neigh_list) {
- neigh_node = list_entry(neigh_pos, struct neigh_node, list);
+ list_for_each( neigh_pos, &orig_node->neigh_list ) {
+ neigh_node = list_entry( neigh_pos, struct neigh_node, list );
if ( get_bit_status( neigh_node->seq_bits, orig_node->last_seqno, seqno ) )
return 1;
@@ -619,7 +629,7 @@ int isDuplicate( unsigned int orig, unsigned short seqno ) {
int isBidirectionalNeigh( struct orig_node *orig_neigh_node, struct batman_if *if_incoming ) {
- if( orig_neigh_node->bidirect_link[if_incoming->if_num] > 0 && (orig_neigh_node->bidirect_link[if_incoming->if_num] + (bidirectional_timeout)) >= get_time() )
+ if( orig_neigh_node->bidirect_link[if_incoming->if_num] > 0 && ( orig_neigh_node->bidirect_link[if_incoming->if_num] + (bidirectional_timeout) ) >= get_time() )
return 1;
else
return 0;
@@ -628,12 +638,11 @@ int isBidirectionalNeigh( struct orig_node *orig_neigh_node, struct batman_if *i
-void update_originator( struct orig_node *orig_node, struct packet *in, unsigned int neigh, struct batman_if *if_incoming, unsigned char *hna_recv_buff, int hna_buff_len ) {
+void update_originator( struct orig_node *orig_node, struct packet *in, uint32_t neigh, struct batman_if *if_incoming, unsigned char *hna_recv_buff, int16_t hna_buff_len ) {
struct list_head *neigh_pos;
struct neigh_node *neigh_node = NULL, *tmp_neigh_node, *best_neigh_node;
- int max_packet_count = 0;
- char is_new_seqno = 0;
+ uint8_t max_packet_count = 0, is_new_seqno = 0;
debug_output( 4, "update_originator(): Searching and updating originator entry of received packet, \n" );
@@ -641,7 +650,7 @@ void update_originator( struct orig_node *orig_node, struct packet *in, unsigned
list_for_each( neigh_pos, &orig_node->neigh_list ) {
- tmp_neigh_node = list_entry(neigh_pos, struct neigh_node, list);
+ tmp_neigh_node = list_entry( neigh_pos, struct neigh_node, list );
if ( ( tmp_neigh_node->addr == neigh ) && ( tmp_neigh_node->if_incoming == if_incoming ) ) {
@@ -669,12 +678,12 @@ void update_originator( struct orig_node *orig_node, struct packet *in, unsigned
neigh_node = debugMalloc( sizeof (struct neigh_node), 6 );
memset( neigh_node, 0, sizeof(struct neigh_node) );
- INIT_LIST_HEAD(&neigh_node->list);
+ INIT_LIST_HEAD( &neigh_node->list );
neigh_node->addr = neigh;
neigh_node->if_incoming = if_incoming;
- list_add_tail(&neigh_node->list, &orig_node->neigh_list);
+ list_add_tail( &neigh_node->list, &orig_node->neigh_list );
} else {
@@ -696,10 +705,13 @@ void update_originator( struct orig_node *orig_node, struct packet *in, unsigned
neigh_node->last_aware = get_time();
- if( is_new_seqno ) {
+ if ( is_new_seqno ) {
+
debug_output( 4, "updating last_seqno: old %d, new %d \n", orig_node->last_seqno, in->seqno );
+
orig_node->last_seqno = in->seqno;
neigh_node->last_ttl = in->ttl;
+
}
/* update routing table and check for changed hna announcements */
@@ -712,7 +724,9 @@ void update_originator( struct orig_node *orig_node, struct packet *in, unsigned
}
-void schedule_forward_packet( struct packet *in, int unidirectional, int directlink, unsigned char *hna_recv_buff, int hna_buff_len, struct batman_if *if_outgoing ) {
+
+
+void schedule_forward_packet( struct packet *in, uint8_t unidirectional, uint8_t directlink, unsigned char *hna_recv_buff, int16_t hna_buff_len, struct batman_if *if_outgoing ) {
struct forw_node *forw_node_new;
@@ -776,13 +790,15 @@ void schedule_forward_packet( struct packet *in, int unidirectional, int directl
}
+
+
void send_outstanding_packets() {
struct forw_node *forw_node;
struct list_head *forw_pos, *if_pos, *temp;
struct batman_if *batman_if;
static char orig_str[ADDR_STR_LEN];
- int directlink;
+ uint8_t directlink;
if ( list_empty( &forw_list ) )
return;
@@ -880,12 +896,14 @@ void send_outstanding_packets() {
}
+
+
void schedule_own_packet() {
struct forw_node *forw_node_new;
struct list_head *if_pos;
struct batman_if *batman_if;
- int curr_time;
+ uint32_t curr_time;
curr_time = get_time();
@@ -933,21 +951,22 @@ void schedule_own_packet() {
-void purge( unsigned int curr_time ) {
+void purge( uint32_t curr_time ) {
struct list_head *orig_pos, *neigh_pos, *orig_temp, *neigh_temp;
struct list_head *gw_pos, *gw_pos_tmp;
struct orig_node *orig_node;
struct neigh_node *neigh_node;
struct gw_node *gw_node;
- short gw_purged = 0;
+ uint8_t gw_purged = 0;
static char orig_str[ADDR_STR_LEN];
debug_output( 4, "purge() \n" );
/* for all origins... */
- list_for_each_safe(orig_pos, orig_temp, &orig_list) {
- orig_node = list_entry(orig_pos, struct orig_node, list);
+ list_for_each_safe( orig_pos, orig_temp, &orig_list ) {
+
+ orig_node = list_entry( orig_pos, struct orig_node, list );
if ( (int)( ( orig_node->last_aware + ( 2 * TIMEOUT ) ) < curr_time ) ) {
@@ -994,7 +1013,8 @@ void purge( unsigned int curr_time ) {
/* for all neighbours towards this orginator ... */
list_for_each_safe( neigh_pos, neigh_temp, &orig_node->neigh_list ) {
- neigh_node = list_entry(neigh_pos, struct neigh_node, list);
+
+ neigh_node = list_entry( neigh_pos, struct neigh_node, list );
if ( (int)( ( neigh_node->last_aware + ( 2 * TIMEOUT ) ) < curr_time ) ) {
@@ -1014,6 +1034,8 @@ void purge( unsigned int curr_time ) {
}
+
+
void send_vis_packet()
{
struct list_head *pos;
@@ -1043,21 +1065,22 @@ void send_vis_packet()
}
}
-int batman()
-{
+int8_t batman() {
+
struct list_head *if_pos, *neigh_pos, *hna_pos, *hna_pos_tmp, *forw_pos, *forw_pos_tmp;
struct orig_node *orig_neigh_node, *orig_node;
struct batman_if *batman_if, *if_incoming;
struct neigh_node *neigh_node;
struct hna_node *hna_node;
struct forw_node *forw_node;
- unsigned int neigh, hna, netmask, debug_timeout, select_timeout;
+ uint32_t neigh, hna, netmask, debug_timeout, select_timeout;
unsigned char in[1501], *hna_recv_buff;
static char orig_str[ADDR_STR_LEN], neigh_str[ADDR_STR_LEN];
- short forward_old, res, hna_buff_count;
- short if_rp_filter_all_old, if_rp_filter_default_old;
- short is_my_addr, is_my_orig, is_broadcast, is_duplicate, is_bidirectional, forward_duplicate_packet;
- int time_count = 0, curr_time, hna_buff_len;
+ int16_t hna_buff_count, hna_buff_len;
+ uint8_t forward_old, if_rp_filter_all_old, if_rp_filter_default_old;
+ uint8_t is_my_addr, is_my_orig, is_broadcast, is_duplicate, is_bidirectional, forward_duplicate_packet;
+ int8_t res;
+ uint32_t time_count = 0, curr_time;
last_own_packet = debug_timeout = get_time();
bidirectional_timeout = orginator_interval * 3;
@@ -1117,7 +1140,7 @@ int batman()
curr_time = get_time();
select_timeout = ( curr_time >= last_own_packet + orginator_interval - 10 ? orginator_interval : last_own_packet + orginator_interval - curr_time );
- res = receive_packet( ( unsigned char *)&in, 1501, &hna_buff_len, &neigh, select_timeout, &if_incoming );
+ res = receive_packet( ( unsigned char *)&in, sizeof(in), &hna_buff_len, &neigh, select_timeout, &if_incoming );
if ( res < 0 )
return -1;
@@ -1133,7 +1156,7 @@ int batman()
hna_buff_len -= sizeof(struct packet);
hna_recv_buff = ( hna_buff_len > 4 ? in + sizeof(struct packet) : NULL );
- list_for_each(if_pos, &if_list) {
+ list_for_each( if_pos, &if_list ) {
batman_if = list_entry(if_pos, struct batman_if, list);
@@ -1181,8 +1204,8 @@ int batman()
while ( ( hna_buff_count + 1 ) * 5 <= hna_buff_len ) {
- memmove( &hna, ( unsigned int *)&hna_recv_buff[ hna_buff_count * 5 ], 4 );
- netmask = ( unsigned int )hna_recv_buff[ ( hna_buff_count * 5 ) + 4 ];
+ memmove( &hna, ( uint32_t *)&hna_recv_buff[ hna_buff_count * 5 ], 4 );
+ netmask = ( uint32_t )hna_recv_buff[ ( hna_buff_count * 5 ) + 4 ];
addr_to_string( hna, orig_str, sizeof (orig_str) );
@@ -1279,7 +1302,7 @@ int batman()
} else if ( ( orig_node->router != NULL ) && ( orig_node->router->addr == neigh ) ) {
- list_for_each(neigh_pos, &orig_node->neigh_list) {
+ list_for_each( neigh_pos, &orig_node->neigh_list ) {
neigh_node = list_entry(neigh_pos, struct neigh_node, list);
diff --git a/batman.h b/batman.h
index aba8e7f..f313510 100644
--- a/batman.h
+++ b/batman.h
@@ -61,20 +61,20 @@
-extern short debug_level;
-extern short gateway_class;
-extern short routing_class;
-extern short num_hna;
-extern unsigned long orginator_interval;
-extern unsigned int pref_gateway;
+extern uint8_t debug_level;
+extern uint8_t gateway_class;
+extern uint8_t routing_class;
+extern uint8_t num_hna;
+extern int16_t orginator_interval;
+extern uint32_t pref_gateway;
extern unsigned char *hna_buff;
extern struct gw_node *curr_gateway;
pthread_t curr_gateway_thread_id;
-extern short found_ifs;
-extern int receive_max_sock;
+extern uint8_t found_ifs;
+extern int32_t receive_max_sock;
extern fd_set receive_wait_set;
extern struct list_head if_list;
@@ -96,25 +96,25 @@ struct packet
struct orig_node /* structure for orig_list maintaining nodes of mesh */
{
struct list_head list;
- unsigned int orig;
+ uint32_t orig;
struct neigh_node *router;
struct batman_if *batman_if;
- unsigned int *bidirect_link; /* if node is a bidrectional neighbour, when my originator packet was broadcasted (replied) by this node and received by me */
- unsigned int last_aware; /* when last packet from this node was received */
- unsigned char gwflags; /* flags related to gateway functions: gateway class */
+ uint32_t *bidirect_link; /* if node is a bidrectional neighbour, when my originator packet was broadcasted (replied) by this node and received by me */
+ uint32_t last_aware; /* when last packet from this node was received */
+ uint8_t gwflags; /* flags related to gateway functions: gateway class */
unsigned char *hna_buff;
- int hna_buff_len;
- uint16_t last_seqno; /* last known squence number */
+ int16_t hna_buff_len;
+ uint16_t last_seqno; /* last and best known squence number */
struct list_head neigh_list;
};
struct neigh_node
{
struct list_head list;
- unsigned int addr;
- unsigned short packet_count;
- unsigned char last_ttl; /* ttl of last received packet */
- unsigned int last_aware; /* when last packet via this neighbour was received */
+ uint32_t addr;
+ uint16_t packet_count;
+ uint8_t last_ttl; /* ttl of last received packet */
+ uint32_t last_aware; /* when last packet via this neighbour was received */
TYPE_OF_WORD seq_bits[ NUM_WORDS ];
struct batman_if *if_incoming;
};
@@ -122,17 +122,17 @@ struct neigh_node
struct hna_node
{
struct list_head list;
- unsigned int addr;
- unsigned int netmask;
+ uint32_t addr;
+ uint16_t netmask;
};
struct forw_node /* structure for forw_list maintaining packets to be send/forwarded */
{
struct list_head list;
- unsigned int when;
- int own;
+ uint32_t when;
+ uint8_t own;
unsigned char *pack_buff;
- int pack_buff_len;
+ int32_t pack_buff_len;
struct batman_if *if_outgoing;
};
@@ -140,20 +140,20 @@ struct gw_node
{
struct list_head list;
struct orig_node *orig_node;
- int unavail_factor;
- int last_failure;
+ uint16_t unavail_factor;
+ uint32_t last_failure;
};
struct batman_if
{
struct list_head list;
char *dev;
- int udp_send_sock;
- int udp_recv_sock;
- int tcp_gw_sock;
- int tunnel_sock;
- short if_num;
- short if_rp_filter_old;
+ int32_t udp_send_sock;
+ int32_t udp_recv_sock;
+ int32_t tcp_gw_sock;
+ int32_t tunnel_sock;
+ int16_t if_num;
+ int16_t if_rp_filter_old;
pthread_t listen_thread_id;
struct sockaddr_in addr;
struct sockaddr_in broad;
@@ -165,18 +165,18 @@ struct gw_client
{
struct list_head list;
struct batman_if *batman_if;
- int sock;
- unsigned int last_keep_alive;
+ int32_t sock;
+ uint32_t last_keep_alive;
struct sockaddr_in addr;
};
struct vis_if {
- int sock;
+ int32_t sock;
struct sockaddr_in addr;
};
struct unix_if {
- int unix_sock;
+ int32_t unix_sock;
pthread_t listen_thread_id;
struct sockaddr_un addr;
struct list_head client_list;
@@ -184,34 +184,34 @@ struct unix_if {
struct unix_client {
struct list_head list;
- int sock;
- char debug_level;
+ int32_t sock;
+ uint8_t debug_level;
struct sockaddr_un addr;
};
struct debug_clients {
void *fd_list[4];
- short clients_num[4];
+ int16_t clients_num[4];
};
struct debug_level_info {
struct list_head list;
- int fd;
+ int32_t fd;
};
-int batman();
-void usage(void);
-void verbose_usage(void);
-void del_default_route();
-int add_default_route();
+int8_t batman( void );
+void usage( void );
+void verbose_usage( void );
+void del_default_route();
+int8_t add_default_route();
void bit_init( TYPE_OF_WORD *seq_bits );
-int get_bit_status( TYPE_OF_WORD *seq_bits, uint16_t last_seqno, uint16_t curr_seqno );
-char* bit_print( TYPE_OF_WORD *seq_bits );
-void bit_mark( TYPE_OF_WORD *seq_bits, int n );
-void bit_shift( TYPE_OF_WORD *seq_bits, int n );
-char bit_get_packet( TYPE_OF_WORD *seq_bits, int seq_num_diff, int set_mark );
+uint8_t get_bit_status( TYPE_OF_WORD *seq_bits, uint16_t last_seqno, uint16_t curr_seqno );
+char *bit_print( TYPE_OF_WORD *seq_bits );
+void bit_mark( TYPE_OF_WORD *seq_bits, int32_t n );
+void bit_shift( TYPE_OF_WORD *seq_bits, int32_t n );
+char bit_get_packet( TYPE_OF_WORD *seq_bits, int32_t seq_num_diff, int8_t set_mark );
int bit_packet_count( TYPE_OF_WORD *seq_bits );
#endif
diff --git a/bitarray.c b/bitarray.c
index a98e9d4..dccd5fd 100644
--- a/bitarray.c
+++ b/bitarray.c
@@ -37,7 +37,7 @@ void bit_init( TYPE_OF_WORD *seq_bits ) {
};
/* returns true if corresponding bit in given seq_bits indicates so and curr_seqno is within range of last_seqno */
-int get_bit_status( TYPE_OF_WORD *seq_bits, uint16_t last_seqno, uint16_t curr_seqno ) {
+uint8_t get_bit_status( TYPE_OF_WORD *seq_bits, uint16_t last_seqno, uint16_t curr_seqno ) {
int word_offset,word_num;
//TBD: not shure for wrap arounds, what about: if ( curr_seqno - last_seqno > 0 || curr_seqno - last_seqno <
@@ -81,8 +81,8 @@ char* bit_print( TYPE_OF_WORD *seq_bits ) {
}
/* turn corresponding bit on, so we can remember that we got the packet */
-void bit_mark( TYPE_OF_WORD *seq_bits, int n ) {
- int word_offset,word_num;
+void bit_mark( TYPE_OF_WORD *seq_bits, int32_t n ) {
+ int32_t word_offset,word_num;
if ( n<0 || n >= SEQ_RANGE ) { /* if too old, just drop it */
// printf("got old packet, dropping\n");
@@ -98,9 +98,9 @@ void bit_mark( TYPE_OF_WORD *seq_bits, int n ) {
}
/* shift the packet array p by n places. */
-void bit_shift( TYPE_OF_WORD *seq_bits, int n ) {
- int word_offset, word_num;
- int i;
+void bit_shift( TYPE_OF_WORD *seq_bits, int32_t n ) {
+ int32_t word_offset, word_num;
+ int32_t i;
// bit_print( seq_bits );
if( n<=0 ) return;
@@ -142,7 +142,7 @@ void bit_shift( TYPE_OF_WORD *seq_bits, int n ) {
/* receive and process one packet, returns 1 if received seq_num is considered new, 0 if old */
-char bit_get_packet( TYPE_OF_WORD *seq_bits, int seq_num_diff, int set_mark ) {
+char bit_get_packet( TYPE_OF_WORD *seq_bits, int32_t seq_num_diff, int8_t set_mark ) {
int i;
diff --git a/linux-specific.c b/linux-specific.c
index 693e51f..d15769e 100644
--- a/linux-specific.c
+++ b/linux-specific.c
@@ -43,7 +43,7 @@
#include "batman-specific.h"
-void add_del_route( unsigned int dest, unsigned int netmask, unsigned int router, int del, char *dev, int sock ) {
+void add_del_route( uint32_t dest, uint16_t netmask, uint32_t router, int8_t del, char *dev, int32_t sock ) {
struct rtentry route;
char str1[16], str2[16];
@@ -107,9 +107,9 @@ void add_del_route( unsigned int dest, unsigned int netmask, unsigned int router
/* Probe for tun interface availability */
-int probe_tun()
-{
- int fd;
+int8_t probe_tun() {
+
+ int32_t fd;
if ( ( fd = open( "/dev/net/tun", O_RDWR ) ) < 0 ) {
@@ -124,7 +124,7 @@ int probe_tun()
}
-int del_dev_tun( int fd ) {
+int8_t del_dev_tun( int32_t fd ) {
if ( ioctl( fd, TUNSETPERSIST, 0 ) < 0 ) {
@@ -140,9 +140,9 @@ int del_dev_tun( int fd ) {
}
-int add_dev_tun( struct batman_if *batman_if, unsigned int tun_addr, char *tun_dev, size_t tun_dev_size, int *fd ) {
+int8_t add_dev_tun( struct batman_if *batman_if, uint32_t tun_addr, char *tun_dev, size_t tun_dev_size, int32_t *fd ) {
- int tmp_fd;
+ int32_t tmp_fd;
struct ifreq ifr_tun, ifr_if;
struct sockaddr_in addr;
diff --git a/linux.c b/linux.c
index efebbd4..71850c0 100644
--- a/linux.c
+++ b/linux.c
@@ -42,7 +42,7 @@
#include "os.h"
#include "batman-specific.h"
-void set_rp_filter(int state, char* dev)
+void set_rp_filter(int32_t state, char* dev)
{
FILE *f;
char filename[100], *colon_ptr;
@@ -63,10 +63,10 @@ void set_rp_filter(int state, char* dev)
*colon_ptr = ':';
}
-int get_rp_filter(char *dev)
+int32_t get_rp_filter(char *dev)
{
FILE *f;
- int state = 0;
+ int32_t state = 0;
char filename[100], *colon_ptr;
/* if given interface is an alias use parent interface */
@@ -87,7 +87,7 @@ int get_rp_filter(char *dev)
return state;
}
-void set_forwarding(int state)
+void set_forwarding(int32_t state)
{
FILE *f;
@@ -98,10 +98,10 @@ void set_forwarding(int state)
fclose(f);
}
-int get_forwarding(void)
+int32_t get_forwarding(void)
{
FILE *f;
- int state = 0;
+ int32_t state = 0;
if((f = fopen("/proc/sys/net/ipv4/ip_forward", "r")) == NULL)
return 0;
@@ -112,7 +112,7 @@ int get_forwarding(void)
return state;
}
-int bind_to_iface( int udp_recv_sock, char *dev ) {
+int8_t bind_to_iface( int32_t udp_recv_sock, char *dev ) {
char *colon_ptr;
diff --git a/os.h b/os.h
index 1cfef85..11986c9 100644
--- a/os.h
+++ b/os.h
@@ -22,39 +22,39 @@
#include "batman-specific.h"
-unsigned int get_time(void);
-void set_forwarding(int);
-int get_forwarding(void);
-void set_rp_filter(int state, char* dev);
-int get_rp_filter(char *dev);
+uint32_t get_time( void );
+void set_forwarding(int32_t state);
+int32_t get_forwarding(void);
+void set_rp_filter(int32_t state, char* dev);
+int32_t get_rp_filter(char *dev);
-void add_del_route( unsigned int dest, unsigned int netmask, unsigned int router, int del, char *dev, int sock );
-int is_aborted();
-void addr_to_string(unsigned int addr, char *str, int len);
+void add_del_route( uint32_t dest, uint16_t netmask, uint32_t router, int8_t del, char *dev, int32_t sock );
+int8_t is_aborted();
+void addr_to_string( uint32_t addr, char *str, int32_t len );
-int receive_packet(unsigned char *packet_buff, int packet_buff_len, int *hna_buff_len, unsigned int *neigh, unsigned int timeout, struct batman_if **if_incoming);
+int8_t receive_packet( unsigned char *packet_buff, int32_t packet_buff_len, int16_t *hna_buff_len, uint32_t *neigh, uint32_t timeout, struct batman_if **if_incoming );
-int send_packet( unsigned char *packet_buff, int packet_buff_len, struct sockaddr_in *broad, int send_sock );
-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, size_t tun_dev_size, int *fd );
+int8_t send_packet( unsigned char *packet_buff, int packet_buff_len, struct sockaddr_in *broad, int send_sock );
+int32_t rand_num( int32_t limit );
+int8_t bind_to_iface( int32_t udp_recv_sock, char *dev );
+int8_t probe_tun();
+int8_t del_dev_tun( int32_t fd );
+int8_t add_dev_tun( struct batman_if *batman_if, uint32_t dest_addr, char *tun_dev, size_t tun_dev_size, int32_t *fd );
void apply_init_args( int argc, char *argv[] );
void init_interface ( struct batman_if *batman_if );
void init_interface_gw ( struct batman_if *batman_if );
-int print_animation( void );
+void print_animation( void );
void close_all_sockets();
void *gw_listen( void *arg );
void *client_to_gw_tun( void *arg );
void debug();
-void debug_output( short debug_prio, char *format, ... );
+void debug_output( int8_t debug_prio, char *format, ... );
void cleanup();
diff --git a/posix-specific.c b/posix-specific.c
index 4e80cfe..f2a365f 100644
--- a/posix-specific.c
+++ b/posix-specific.c
@@ -45,11 +45,11 @@
#include "allocate.h"
-void debug_output( short debug_prio, char *format, ... ) {
+void debug_output( int8_t debug_prio, char *format, ... ) {
struct list_head *debug_pos;
struct debug_level_info *debug_level_info;
- short debug_prio_intern;
+ int8_t debug_prio_intern;
va_list args;
@@ -117,7 +117,8 @@ void *unix_listen( void *arg ) {
struct debug_level_info *debug_level_info;
struct list_head *unix_pos, *unix_pos_tmp, *debug_pos, *debug_pos_tmp;
struct timeval tv;
- int res, status, max_sock;
+ int32_t status, max_sock;
+ int8_t res;
unsigned char buff[1500];
fd_set wait_sockets, tmp_wait_sockets;
socklen_t sun_size = sizeof(struct sockaddr_un);
@@ -326,11 +327,13 @@ void apply_init_args( int argc, char *argv[] ) {
struct hna_node *hna_node;
struct debug_level_info *debug_level_info;
// struct timeval tv;
- short found_args = 1, unix_client = 0, batch_mode = 0, batch_counter = 0, netmask;
+ uint8_t found_args = 1, unix_client = 0, batch_mode = 0, batch_counter = 0;
+ uint16_t netmask;
+ int8_t res;
- int optchar, res, recv_buff_len, bytes_written;
+ int32_t optchar, recv_buff_len, bytes_written;
char str1[16], str2[16], *slash_ptr, unix_string[100], buff[1500], *buff_ptr, *cr_ptr;
- unsigned int vis_server = 0;
+ uint32_t vis_server = 0;
// fd_set wait_sockets, tmp_wait_sockets;
memset(&tmp_ip_holder, 0, sizeof (struct in_addr));
@@ -369,7 +372,7 @@ void apply_init_args( int argc, char *argv[] ) {
exit(EXIT_FAILURE);
}
- if ( netmask < 0 || netmask > 32 ) {
+ if ( netmask < 1 || netmask > 32 ) {
*slash_ptr = '/';
printf( "Invalid announced network (netmask is invalid): %s\n", optarg );
@@ -408,7 +411,7 @@ void apply_init_args( int argc, char *argv[] ) {
exit(EXIT_FAILURE);
}
- if ( debug_level < 0 || debug_level > 4 ) {
+ if ( debug_level > 4 ) {
printf( "Invalid debug level: %i\nDebug level has to be between 0 and 4.\n", debug_level );
exit(EXIT_FAILURE);
}
@@ -426,7 +429,7 @@ void apply_init_args( int argc, char *argv[] ) {
exit(EXIT_FAILURE);
}
- if ( gateway_class < 0 || gateway_class > 11 ) {
+ if ( gateway_class > 11 ) {
printf( "Invalid gateway class specified: %i.\nThe class is a value between 0 and 11.\n", gateway_class );
exit(EXIT_FAILURE);
}
@@ -443,14 +446,11 @@ void apply_init_args( int argc, char *argv[] ) {
errno = 0;
orginator_interval = strtol (optarg, NULL , 10);
- if ( (errno == ERANGE && ((orginator_interval == LONG_MAX) || (orginator_interval == LONG_MIN)) ) || (errno != 0 && orginator_interval == 0) ) {
- perror("strtol");
- exit(EXIT_FAILURE);
- }
+ if ( orginator_interval < 1 ) {
- if (orginator_interval < 1) {
printf( "Invalid orginator interval specified: %i.\nThe Interval has to be greater than 0.\n", orginator_interval );
exit(EXIT_FAILURE);
+
}
found_args += 2;
@@ -476,14 +476,11 @@ void apply_init_args( int argc, char *argv[] ) {
errno = 0;
routing_class = strtol (optarg, NULL , 10);
- if ( ( errno == ERANGE ) || ( errno != 0 && routing_class == 0 ) ) {
- perror("strtol");
- exit(EXIT_FAILURE);
- }
+ if ( routing_class > 3 ) {
- if (routing_class < 0 || routing_class > 3) {
printf( "Invalid routing class specified: %i.\nThe class is a value between 0 and 3.\n", routing_class );
exit(EXIT_FAILURE);
+
}
found_args += 2;
@@ -1225,7 +1222,7 @@ void del_default_route() {
-int add_default_route() {
+int8_t add_default_route() {
if ( pthread_create( &curr_gateway_thread_id, NULL, &client_to_gw_tun, curr_gateway ) != 0 ) {
@@ -1285,14 +1282,14 @@ void close_all_sockets() {
-int receive_packet( unsigned char *packet_buff, int packet_buff_len, int *hna_buff_len, unsigned int *neigh, unsigned int timeout, struct batman_if **if_incoming ) {
+int8_t receive_packet( unsigned char *packet_buff, int32_t packet_buff_len, int16_t *hna_buff_len, uint32_t *neigh, uint32_t timeout, struct batman_if **if_incoming ) {
struct sockaddr_in addr;
struct timeval tv;
struct list_head *if_pos;
struct batman_if *batman_if;
- unsigned int addr_len;
- int res;
+ uint32_t addr_len;
+ int8_t res;
fd_set tmp_wait_set = receive_wait_set;
@@ -1354,7 +1351,7 @@ int receive_packet( unsigned char *packet_buff, int packet_buff_len, int *hna_bu
-int send_packet( unsigned char *packet_buff, int packet_buff_len, struct sockaddr_in *broad, int send_sock ) {
+int8_t send_packet( unsigned char *packet_buff, int32_t packet_buff_len, struct sockaddr_in *broad, int32_t send_sock ) {
((struct packet *)packet_buff)->seqno = htons( ((struct packet *)packet_buff)->seqno ); /* change sequence number to network order */
@@ -1378,6 +1375,8 @@ int send_packet( unsigned char *packet_buff, int packet_buff_len, struct sockadd
}
+
+
void *gw_listen( void *arg ) {
struct batman_if *batman_if = (struct batman_if *)arg;
@@ -1611,7 +1610,7 @@ void *gw_listen( void *arg ) {
void cleanup() {
- short i;
+ int8_t i;
struct debug_level_info *debug_level_info;
struct list_head *debug_pos, *debug_pos_tmp;
diff --git a/posix.c b/posix.c
index 12684c8..f14090e 100644
--- a/posix.c
+++ b/posix.c
@@ -73,8 +73,8 @@ static void get_time_internal(struct timeval *tv)
tv->tv_usec = usec;
}
-unsigned int get_time(void)
-{
+uint32_t get_time( void ) {
+
struct timeval tv;
get_time_internal(&tv);
@@ -139,7 +139,7 @@ void bat_wait( int T, int t ) {
-int print_animation( void ) {
+void print_animation( void ) {
system( "clear" );
BAT_LOGO_END( 0, 50 );
@@ -209,37 +209,39 @@ int print_animation( void ) {
sym_print( 12, 6, "\\" );
BAT_LOGO_END( 0 ,35 );
- return 0;
-
}
-int is_aborted()
-{
+int8_t is_aborted() {
+
return stop != 0;
+
}
-void addr_to_string(unsigned int addr, char *str, int len)
-{
+void addr_to_string( uint32_t addr, char *str, int32_t len ) {
+
inet_ntop(AF_INET, &addr, str, len);
+
}
-int rand_num(int limit)
-{
+int32_t rand_num( int32_t limit ) {
+
return ( limit == 0 ? 0 : rand() % limit );
+
}
-static void handler(int sig)
-{
+static void handler( int32_t sig ) {
+
stop = 1;
+
}
int main( int argc, char *argv[] ) {
- short res;
+ int8_t res;
stop = 0;
// memset( &device_node_array[0], 0, sizeof( device_node_array ) );
--
batman; test conversation