The following commit has been merged in the master branch:
commit c16a85ffa93668db4bdb9897d45575536f698b08
Author: Marek Lindner <lindner_marek(a)yahoo.de>
Date: Mon Nov 6 20:37:30 2006 +0100
- memory leaks removed ;-)
diff --git a/batman.c b/batman.c
index f75e3d8..6262e03 100755
--- a/batman.c
+++ b/batman.c
@@ -53,6 +53,19 @@ int debug_level = 0;
* this option is used to determine packet path
*/
+char *gw2string[] = { "No Gateway",
+ "56 KBit (e.g. Modem)",
+ "64 KBit (e.g. ISDN)",
+ "128 KBit (e.g. double ISDN)",
+ "256 KBit",
+ "512 KBit (e.g. UMTS)",
+ "1 MBit",
+ "2 MBit",
+ "3 MBit",
+ "5 MBit",
+ "6 MBit",
+ ">6 MBit" };
+
int gateway_class = 0;
/* "-r" is the command line switch for the routing class,
@@ -109,7 +122,11 @@ void verbose_usage(void)
fprintf(stderr, " -a announce network(s)\n" );
fprintf(stderr, " network/netmask is expected\n" );
fprintf(stderr, " -d debug level\n" );
- fprintf(stderr, " default: 0, allowed values: 0 - 3\n\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" );
@@ -151,7 +168,7 @@ struct orig_node *get_orig_node( unsigned int addr )
return orig_node;
}
- if (debug_level == 3)
+ if (debug_level == 4)
output("Creating new originator\n");
orig_node = alloc_memory(sizeof(struct orig_node));
@@ -214,7 +231,7 @@ static void choose_gw()
if ( curr_gateway != NULL ) {
- if (debug_level == 1)
+ if (debug_level == 3)
printf( "Removing default route - no gateway in range\n" );
del_default_route();
@@ -267,7 +284,7 @@ static void choose_gw()
tmp_curr_gw = gw_node;
- if (debug_level == 1) {
+ if (debug_level == 3) {
addr_to_string( tmp_curr_gw->orig_node->orig, orig_str, ADDR_STR_LEN );
printf( "Preferred gateway found: %s (%i,%i,%i)\n", orig_str, gw_node->orig_node->gwflags, gw_node->orig_node->packet_count, ( gw_node->orig_node->packet_count * gw_node->orig_node->gwflags ) );
}
@@ -283,7 +300,7 @@ static void choose_gw()
if ( curr_gateway != NULL ) {
- if (debug_level == 1)
+ if (debug_level == 3)
printf( "Removing default route - better gateway found\n" );
del_default_route();
@@ -295,7 +312,7 @@ static void choose_gw()
/* may be the last gateway is now gone */
if ( ( curr_gateway != NULL ) && ( !is_aborted() ) ) {
- if (debug_level == 1) {
+ if (debug_level == 3) {
addr_to_string( curr_gateway->orig_node->orig, orig_str, ADDR_STR_LEN );
printf( "Adding default route to %s (%i,%i,%i)\n", orig_str, max_gw_class, max_packets, max_gw_factor );
}
@@ -320,7 +337,7 @@ static void update_routes( struct orig_node *orig_node, unsigned char *hna_recv_
int max_pack, max_ttl, neigh_ttl[found_ifs], neigh_pkts[found_ifs];
static char orig_str[ADDR_STR_LEN], next_str[ADDR_STR_LEN];
- if (debug_level == 3)
+ if (debug_level == 4)
output("update_routes() \n");
max_ttl = 0;
@@ -345,21 +362,23 @@ static void update_routes( struct orig_node *orig_node, unsigned char *hna_recv_
if ( neigh_pkts[pack_node->if_incoming->if_num] > neigh_pkts[max_if->if_num] ) max_if = pack_node->if_incoming;
}
- /* if received most orig_packets via this neighbour (or ) then
+ neigh_node->packet_count = neigh_pkts[max_if->if_num];
+
+ /* if received most orig_packets via this neighbour (or better ttl) then
select this neighbour as next hop for this origin */
if ((neigh_pkts[max_if->if_num] > max_pack) || ((neigh_pkts[max_if->if_num] == max_pack) && (neigh_ttl[max_if->if_num] > max_ttl))) {
max_pack = neigh_pkts[max_if->if_num];
max_ttl = neigh_ttl[max_if->if_num];
next_hop = neigh_node;
- if (debug_level == 3)
+ if (debug_level == 4)
output("%d living received packets via selected router \n", neigh_pkts[max_if->if_num] );
}
}
if ( next_hop != NULL ) {
- if (debug_level == 3) {
+ if (debug_level == 4) {
addr_to_string(orig_node->orig, orig_str, ADDR_STR_LEN);
addr_to_string(next_hop->addr, next_str, ADDR_STR_LEN);
output("Route to %s via %s\n", orig_str, next_str);
@@ -369,12 +388,12 @@ static void update_routes( struct orig_node *orig_node, unsigned char *hna_recv_
if (orig_node->router != next_hop->addr) {
- if (debug_level == 3)
+ if (debug_level == 4)
output("Route changed\n");
if (orig_node->router != 0) {
- if (debug_level == 3)
+ if (debug_level == 4)
output("Deleting previous route\n");
/* remove old announced network(s) */
@@ -385,7 +404,7 @@ static void update_routes( struct orig_node *orig_node, unsigned char *hna_recv_
}
- if (debug_level == 3)
+ if (debug_level == 4)
output("Adding new route\n");
@@ -441,7 +460,7 @@ static void update_gw_list( struct orig_node *orig_node, unsigned char new_gwfla
if ( gw_node->orig_node == orig_node ) {
- if (debug_level == 1) {
+ if (debug_level == 3) {
addr_to_string( gw_node->orig_node->orig, orig_str, ADDR_STR_LEN );
printf( "Gateway class of originator %s changed from %i to %i\n", orig_str, gw_node->orig_node->gwflags, new_gwflags );
@@ -453,7 +472,7 @@ static void update_gw_list( struct orig_node *orig_node, unsigned char new_gwfla
list_del(gw_pos);
free_memory(gw_pos);
- if (debug_level == 1)
+ if (debug_level == 3)
printf( "Gateway %s removed from gateway list\n", orig_str );
} else {
@@ -469,7 +488,7 @@ static void update_gw_list( struct orig_node *orig_node, unsigned char new_gwfla
}
- if (debug_level == 1) {
+ if (debug_level == 3) {
addr_to_string( orig_node->orig, orig_str, ADDR_STR_LEN );
printf( "Found new gateway %s (class: %i)\n", orig_str, new_gwflags );
}
@@ -488,68 +507,129 @@ static void update_gw_list( struct orig_node *orig_node, unsigned char new_gwfla
}
-static void debug()
-{
- struct list_head *forw_pos, *orig_pos, *neigh_pos, *pack_pos, *temp;
+
+
+static void debug() {
+
+ struct list_head *forw_pos, *orig_pos, *neigh_pos, *pack_pos;
struct forw_node *forw_node;
struct orig_node *orig_node;
struct neigh_node *neigh_node;
struct pack_node *pack_node;
- static char str[ADDR_STR_LEN];
- int l;
+ struct gw_node *gw_node;
+ static char str[ADDR_STR_LEN], str2[ADDR_STR_LEN];
- if (debug_level != 2)
+ if ( ( debug_level == 0 ) || ( debug_level == 3 ) )
return;
- if (debug_level == 2) {
- output("------------------ DEBUG ------------------\n");
- output("Forward list\n");
+ system( "clear" );
- list_for_each(forw_pos, &forw_list) {
- forw_node = list_entry(forw_pos, struct forw_node, list);
- addr_to_string(forw_node->pack.orig, str, sizeof (str));
- output(" %s at %u\n", str, forw_node->when);
- }
+ if ( debug_level == 2 ) {
+ if ( list_empty(&gw_list) ) {
- output("Originator list\n");
- }
+ printf( "No gateways in range ...\n" );
- list_for_each(orig_pos, &orig_list) {
- orig_node = list_entry(orig_pos, struct orig_node, list);
+ } else {
- addr_to_string(orig_node->orig, str, sizeof (str));
+ list_for_each(orig_pos, &gw_list) {
+ gw_node = list_entry(orig_pos, struct gw_node, list);
- output("%s, last_aware:%u, last_reply:%u, last_seen:%u via:\n",
- str, orig_node->last_aware, orig_node->last_reply, orig_node->last_seen);
+ addr_to_string( gw_node->orig_node->orig, str, sizeof (str) );
+ addr_to_string( gw_node->orig_node->router, str2, sizeof (str2) );
- list_for_each(neigh_pos, &orig_node->neigh_list) {
- neigh_node = list_entry(neigh_pos, struct neigh_node, list);
+ if ( curr_gateway == gw_node ) {
+ printf( "=> %s via: %s(%i), gw_class %i - %s, reliability: %i\n", str, str2, gw_node->orig_node->packet_count, gw_node->orig_node->gwflags, gw2string[gw_node->orig_node->gwflags], gw_node->unavail_factor );
+ } else {
+ printf( "%s via: %s(%i), gw_class %i - %s, reliability: %i\n", str, str2, gw_node->orig_node->packet_count, gw_node->orig_node->gwflags, gw2string[gw_node->orig_node->gwflags], gw_node->unavail_factor );
+ }
+
+ }
+
+ }
+
+ } else {
+
+ if ( debug_level == 4 ) {
+
+ output("------------------ DEBUG ------------------\n");
+ output("Forward list\n");
- l = 0;
- list_for_each(temp, &neigh_node->pack_list) {
- l++;
+ list_for_each(forw_pos, &forw_list) {
+ forw_node = list_entry(forw_pos, struct forw_node, list);
+ addr_to_string(forw_node->pack.orig, str, sizeof (str));
+ output(" %s at %u\n", str, forw_node->when);
}
- if (debug_level >= 2) {
- addr_to_string(neigh_node->addr, str, sizeof (str));
- output("\t\t%s (%d)\n", str, l);
+ }
+
+ if ( debug_level == 4 )
+ output("Originator list\n");
+
+ if ( list_empty(&orig_list) ) {
+
+ if ( debug_level != 4 ) {
+ printf( "No gateways in range ...\n" );
+ } else {
+ output( "No gateways in range ...\n" );
}
- if (debug_level >= 3) {
- list_for_each(pack_pos, &neigh_node->pack_list) {
- pack_node = list_entry(pack_pos, struct pack_node, list);
- output(" Sequence number: %d, TTL: %d at: %u \n",
- pack_node->seqno, pack_node->ttl, pack_node->time);
+ } else {
+
+ list_for_each(orig_pos, &orig_list) {
+ orig_node = list_entry(orig_pos, struct orig_node, list);
+
+ if ( orig_node->router == 0 )
+ continue;
+
+ addr_to_string( orig_node->orig, str, sizeof (str) );
+ addr_to_string( orig_node->router, str2, sizeof (str2) );
+
+ if ( debug_level != 4 ) {
+ printf( "%s, GW: %s(%i) via:", str, str2, orig_node->packet_count );
+ } else {
+ output("%s, GW: %s(%i), last_aware:%u, last_reply:%u, last_seen:%u via:\n", str, str2, orig_node->packet_count, orig_node->last_aware, orig_node->last_reply, orig_node->last_seen);
+ }
+
+ 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));
+
+ if ( debug_level != 4 ) {
+ printf( " %s(%i)", str, neigh_node->packet_count );
+ } else {
+ output( "\t\t%s (%d)\n", str, neigh_node->packet_count );
+ }
+
+ if ( debug_level == 4 ) {
+
+ list_for_each(pack_pos, &neigh_node->pack_list) {
+ pack_node = list_entry(pack_pos, struct pack_node, list);
+ output(" Sequence number: %d, TTL: %d at: %u \n",
+ pack_node->seqno, pack_node->ttl, pack_node->time);
+ }
+
+ }
+
}
+
+ if ( debug_level != 4 )
+ printf( "\n" );
+
}
+
}
+
+ if ( debug_level == 4 )
+ output("---------------------------------------------- END DEBUG\n");
+
}
- if (debug_level >= 2)
- output("---------------------------------------------- END DEBUG\n");
}
+
+
int isDuplicate(unsigned int orig, unsigned short seqno)
{
struct list_head *orig_pos, *neigh_pos, *pack_pos;
@@ -603,7 +683,7 @@ struct orig_node *update_last_hop(struct packet *in, unsigned int neigh)
{
struct orig_node *orig_neigh_node;
- if (debug_level == 3) {
+ if (debug_level == 4) {
output("update_last_hop(): Searching originator entry of last-hop neighbour of received packet \n"); }
orig_neigh_node = get_orig_node( neigh );
@@ -620,7 +700,7 @@ void update_originator( struct packet *in, unsigned int neigh, struct batman_if
struct neigh_node *neigh_node = NULL;
struct pack_node *pack_node = NULL;
- if (debug_level == 3)
+ if (debug_level == 4)
output("update_originator(): Searching and updating originator entry of received packet, \n");
orig_node = get_orig_node( in->orig );
@@ -641,7 +721,7 @@ void update_originator( struct packet *in, unsigned int neigh, struct batman_if
}
if (neigh_node == NULL) {
- if (debug_level == 3)
+ if (debug_level == 4)
output("Creating new last-hop neighbour of originator\n");
neigh_node = alloc_memory(sizeof (struct neigh_node));
@@ -651,7 +731,7 @@ void update_originator( struct packet *in, unsigned int neigh, struct batman_if
neigh_node->addr = neigh;
list_add_tail(&neigh_node->list, &orig_node->neigh_list);
- } else if (debug_level == 3)
+ } else if (debug_level == 4)
output("Updating existing last-hop neighbour of originator\n");
list_for_each(pack_pos, &neigh_node->pack_list) {
@@ -662,7 +742,7 @@ void update_originator( struct packet *in, unsigned int neigh, struct batman_if
}
if (pack_node == NULL) {
- if (debug_level == 3)
+ if (debug_level == 4)
output("Creating new packet entry for last-hop neighbor of originator \n");
pack_node = alloc_memory(sizeof (struct pack_node));
@@ -672,7 +752,7 @@ void update_originator( struct packet *in, unsigned int neigh, struct batman_if
pack_node->if_incoming = if_incoming;
list_add_tail(&pack_node->list, &neigh_node->pack_list);
} else
- if (debug_level == 3)
+ if (debug_level == 4)
output("ERROR - Updating existing packet\n");
neigh_node->best_ttl = in->ttl;
@@ -688,14 +768,14 @@ void schedule_forward_packet( struct packet *in, int unidirectional, struct orig
struct forw_node *forw_node, *forw_node_new;
struct list_head *forw_pos;
- if (debug_level == 3)
+ if (debug_level == 4)
output("schedule_forward_packet(): \n");
if (in->ttl <= 1) {
- if (debug_level == 3)
+ if (debug_level == 4)
output("ttl exceeded \n");
} else if ( ( orig_node->router != neigh ) && ( orig_node->router != 0 ) ) {
- if (debug_level == 3)
+ if (debug_level == 4)
output("not my best neighbour\n");
} else {
@@ -707,7 +787,7 @@ void schedule_forward_packet( struct packet *in, int unidirectional, struct orig
forw_node_new->pack.ttl--;
if (unidirectional) {
- if (debug_level == 3)
+ if (debug_level == 4)
output("sending with unidirectional flag \n");
forw_node_new->pack.flags = (forw_node_new->pack.flags | UNIDIRECTIONAL);
@@ -769,7 +849,7 @@ void send_outstanding_packets()
}
- if (debug_level == 3) {
+ if (debug_level == 4) {
addr_to_string(forw_node->pack.orig, orig_str, ADDR_STR_LEN);
output("Forwarding packet (originator %s, seqno %d, TTL %d)\n", orig_str, forw_node->pack.seqno, forw_node->pack.ttl);
}
@@ -779,13 +859,17 @@ void send_outstanding_packets()
batman_if = list_entry(if_pos, struct batman_if, list);
if (send_packet(send_buff, sizeof (struct packet) + forw_node->hna_buff_len, &batman_if->broad, batman_if->udp_send_sock) < 0) {
- do_log( "ERROR: %s returned -1\n", "send_packet" );
- exit( -1);
+ exit( -1 );
}
}
+ free_memory(send_buff);
list_del(forw_pos);
+
+ if ( forw_node->hna_buff_len > 0 )
+ free_memory(forw_node->hna_buff);
+
free_memory(forw_node);
}
@@ -858,7 +942,7 @@ void purge()
int gw_purged = 0;
static char orig_str[ADDR_STR_LEN], neigh_str[ADDR_STR_LEN];
- if (debug_level == 3)
+ if (debug_level == 4)
output("purge() \n");
/* for all origins... */
@@ -876,7 +960,7 @@ void purge()
/* remove them if outdated */
if ((int)((pack_node->time + TIMEOUT) < get_time()))
{
- if (debug_level == 3) {
+ if (debug_level == 4) {
addr_to_string(orig_node->orig, orig_str, ADDR_STR_LEN);
addr_to_string(neigh_node->addr, neigh_str, ADDR_STR_LEN);
output("Packet timeout (originator %s, neighbour %s, seqno %d, TTL %d, time %u)\n",
@@ -894,7 +978,7 @@ void purge()
/* if no more packets, remove neighbour (next hop) towards given origin */
if (list_empty(&neigh_node->pack_list)) {
- if (debug_level == 3) {
+ if (debug_level == 4) {
addr_to_string(neigh_node->addr, neigh_str, sizeof (neigh_str));
addr_to_string(orig_node->orig, orig_str, sizeof (orig_str));
output("Removing orphaned neighbour %s for originator %s\n", neigh_str, orig_str);
@@ -906,7 +990,7 @@ void purge()
/* if no more neighbours (next hops) towards given origin, remove origin */
if (list_empty(&orig_node->neigh_list) && ((int)(orig_node->last_aware) + TIMEOUT <= ((int)(get_time())))) {
- if (debug_level == 3) {
+ if (debug_level == 4) {
addr_to_string(orig_node->orig, orig_str, sizeof (orig_str));
output("Removing orphaned originator %s\n", orig_str);
}
@@ -918,7 +1002,7 @@ void purge()
if ( gw_node->orig_node == orig_node ) {
addr_to_string( gw_node->orig_node->orig, orig_str, ADDR_STR_LEN );
- if (debug_level == 1)
+ if (debug_level == 3)
printf( "Removing gateway %s from gateway list\n", orig_str );
list_del(gw_pos);
@@ -935,12 +1019,16 @@ void purge()
list_del(orig_pos);
/* remove old announced network(s) */
- if ( orig_node->hna_buff_len > 0 )
+ if ( orig_node->hna_buff_len > 0 ) {
+
add_del_hna( orig_node, 1 );
+ free_memory( orig_node->hna_buff );
+
+ }
if ( orig_node->router != 0 ) {
- if (debug_level == 3)
+ if (debug_level == 4)
output("Deleting route to originator \n");
add_del_route(orig_node->orig, 32, orig_node->router, 1, orig_node->batman_if->dev, orig_node->batman_if->udp_send_sock);
@@ -994,7 +1082,7 @@ int batman()
struct neigh_node *neigh_node;
struct hna_node *hna_node;
struct packet in;
- unsigned int neigh, hna, netmask;
+ unsigned int neigh, hna, netmask, debug_timeout;
unsigned char hna_recv_buff[1500 - sizeof (struct packet)];
static char orig_str[ADDR_STR_LEN], neigh_str[ADDR_STR_LEN];
int forward_old, res, hna_buff_len, hna_buff_count;
@@ -1002,6 +1090,7 @@ int batman()
int time_count = 0;
next_own = 0;
+ debug_timeout = get_time();
if ( !( list_empty(&hna_list) ) ) {
@@ -1038,7 +1127,7 @@ int batman()
while (!is_aborted())
{
- if (debug_level == 3)
+ if (debug_level == 4)
output(" \n \n");
schedule_own_packet();
@@ -1060,7 +1149,7 @@ int batman()
if (res > 0)
{
- if (debug_level == 3) {
+ if (debug_level == 4) {
addr_to_string(in.orig, orig_str, sizeof (orig_str));
addr_to_string(neigh, neigh_str, sizeof (neigh_str));
output("Received BATMAN packet from %s (originator %s, seqno %d, TTL %d)\n", neigh_str, orig_str, in.seqno, in.ttl);
@@ -1080,14 +1169,14 @@ int batman()
if (is_my_addr == 1 /* && in.orig == my_addr */) {
- if (debug_level == 3) {
+ if (debug_level == 4) {
addr_to_string(neigh, neigh_str, sizeof (neigh_str));
output("Ignoring all (zero-hop) packets send by me (sender: %s)\n", neigh_str);
}
} else if (is_broadcast == 1) {
- if (debug_level == 3) {
+ if (debug_level == 4) {
addr_to_string(neigh, neigh_str, sizeof (neigh));
output("Ignoring all packets with broadcast source IP (sender: %s)\n", neigh_str);
}
@@ -1116,7 +1205,7 @@ int batman()
}
- if (debug_level == 3) {
+ if (debug_level == 4) {
addr_to_string(in.orig, orig_str, sizeof (orig_str));
addr_to_string(neigh, neigh_str, sizeof (neigh_str));
@@ -1168,7 +1257,7 @@ int batman()
if ( in.version != BATMAN_VERSION ) {
- if (debug_level == 1)
+ if (debug_level == 3)
output( "Incompatible batman version (%i) - ignoring packet... \n", in.version );
} else if ( in.flags & UNIDIRECTIONAL ) {
@@ -1177,7 +1266,7 @@ int batman()
orig_neigh_node->last_reply = get_time();
- if (debug_level == 3)
+ if (debug_level == 4)
output("received my own packet from neighbour indicating bidirectional link, updating last_reply stamp \n");
}
@@ -1209,7 +1298,7 @@ int batman()
} else {
- if (debug_level == 3)
+ if (debug_level == 4)
output("Ignoring packet... \n");
}
@@ -1223,8 +1312,16 @@ int batman()
choose_gw();
purge();
- debug();
+
+ if ( debug_timeout + 1000 < get_time() ) {
+
+ debug_timeout = get_time();
+ debug();
+
+ }
+
time_count++;
+
}
if ( debug_level > 0 )
diff --git a/batman.h b/batman.h
index 59e0d44..fe6dbbd 100755
--- a/batman.h
+++ b/batman.h
@@ -42,7 +42,6 @@
-
extern int debug_level;
extern int orginator_interval;
extern int gateway_class;
@@ -93,6 +92,7 @@ struct neigh_node
{
struct list_head list;
unsigned int addr;
+ unsigned int packet_count; /* packets gathered from this neighbour */
unsigned short best_ttl; /* ttl of last packet */
struct list_head pack_list;
};
diff --git a/linux.c b/linux.c
index d5cb6d6..e2a5f4d 100755
--- a/linux.c
+++ b/linux.c
@@ -124,9 +124,9 @@ void add_del_route( unsigned int dest, unsigned int netmask, unsigned int router
route.rt_metric = 0;
- if ( debug_level == 1 ) {
+ if ( debug_level == 3 ) {
printf("%s default route via %s\n", del ? "Deleting" : "Adding", dev);
- } else if ( debug_level == 3 ) {
+ } else if ( debug_level == 4 ) {
output("%s default route via %s\n", del ? "Deleting" : "Adding", dev);
}
@@ -134,9 +134,9 @@ void add_del_route( unsigned int dest, unsigned int netmask, unsigned int router
route.rt_flags |= RTF_GATEWAY;
- if ( debug_level == 1 ) {
+ if ( debug_level == 3 ) {
printf("%s route to %s/%i via %s (%s)\n", del ? "Deleting" : "Adding", str1, netmask, str2, dev);
- } else if ( debug_level == 3 ) {
+ } else if ( debug_level == 4 ) {
output("%s route to %s/%i via %s (%s)\n", del ? "Deleting" : "Adding", str1, netmask, str2, dev);
}
@@ -144,9 +144,9 @@ void add_del_route( unsigned int dest, unsigned int netmask, unsigned int router
} else {
- if ( debug_level == 1 ) {
+ if ( debug_level == 3 ) {
printf("%s route to %s via 0.0.0.0 (%s)\n", del ? "Deleting" : "Adding", str1, dev);
- } else if ( debug_level == 3 ) {
+ } else if ( debug_level == 4 ) {
output("%s route to %s via 0.0.0.0 (%s)\n", del ? "Deleting" : "Adding", str1, dev);
}
diff --git a/posix.c b/posix.c
index f71796c..7620832 100644
--- a/posix.c
+++ b/posix.c
@@ -210,7 +210,7 @@ void *client_to_gw_tun( void *arg ) {
if ( write( curr_gateway_tcp_sock, keep_alive_string, sizeof( keep_alive_string ) ) < 0 ) {
- if ( debug_level == 1 )
+ if ( debug_level == 3 )
printf( "server_keepalive failed: no connect to server\n" );
gw_node->last_failure = get_time();
@@ -239,19 +239,19 @@ void *client_to_gw_tun( void *arg ) {
if ( status > 0 ) {
- if ( debug_level == 1 )
+ if ( debug_level == 3 )
printf( "server message ?\n" );
} else if ( status < 0 ) {
- if ( debug_level == 1 )
+ if ( debug_level == 3 )
printf( "Cannot read message from gateway: %s\n", strerror(errno) );
break;
} else if (status == 0) {
- if ( debug_level == 1 )
+ if ( debug_level == 3 )
printf( "Gateway closed connection - timeout ?\n" );
gw_node->last_failure = get_time();
@@ -383,6 +383,7 @@ int is_aborted()
void *alloc_memory(int len)
{
+
void *res = malloc(len);
if (res == NULL)
@@ -392,6 +393,7 @@ void *alloc_memory(int len)
}
return res;
+
}
void *realloc_memory(void *ptr, int len)
@@ -468,9 +470,13 @@ int receive_packet(unsigned char *packet_buff, int packet_buff_len, unsigned cha
}
}
- if (res == 0)
+ if ( res == 0 ) {
+
+ free_memory( buff );
return 0;
+ }
+
addr_len = sizeof (struct sockaddr_in);
list_for_each(if_pos, &if_list) {
@@ -497,6 +503,7 @@ int receive_packet(unsigned char *packet_buff, int packet_buff_len, unsigned cha
} else {
+ free_memory( buff );
return 0;
}
@@ -508,21 +515,36 @@ int receive_packet(unsigned char *packet_buff, int packet_buff_len, unsigned cha
}
+ free_memory( buff );
*neigh = addr.sin_addr.s_addr;
return 1;
+
}
int send_packet(unsigned char *buff, int len, struct sockaddr_in *broad, int sock)
{
+
if (sendto(sock, buff, len, 0, (struct sockaddr *)broad, sizeof (struct sockaddr_in)) < 0)
{
- do_log( "Error - can't send packet: %s\n", strerror(errno) );
+
+ if ( errno == 1 ) {
+
+ do_log( "Error - can't send packet: %s.\nDoes your Firewall allow outgoing UDP packets on port 1966 ?\n", strerror(errno) );
+
+ } else {
+
+ do_log( "Error - can't send packet: %s.\n", strerror(errno) );
+
+ }
+
return -1;
+
}
return 0;
+
}
static void handler(int sig)
@@ -605,7 +627,7 @@ void *gw_listen( void *arg ) {
list_add_tail(&gw_client->list, &batman_if->client_list);
- if ( debug_level == 1 ) {
+ if ( debug_level == 3 ) {
addr_to_string(gw_client->addr.sin_addr.s_addr, str2, sizeof (str2));
printf( "gateway: %s (%s) got connection from %s (internet via %s)\n", gw_addr, batman_if->dev, str2, tun_dev );
}
@@ -669,7 +691,7 @@ void *gw_listen( void *arg ) {
if ( gw_client->sock > max_sock )
max_sock = gw_client->sock;
- if ( debug_level == 1 ) {
+ if ( debug_level == 3 ) {
addr_to_string(gw_client->addr.sin_addr.s_addr, str2, sizeof (str2));
printf( "gateway: client %s sent keep alive on interface %s\n", str2, batman_if->dev );
}
@@ -682,7 +704,7 @@ void *gw_listen( void *arg ) {
} else {
- if ( debug_level == 1 )
+ if ( debug_level == 3 )
printf( "Client %s closed connection ...\n", str2 );
}
@@ -730,7 +752,7 @@ void *gw_listen( void *arg ) {
FD_CLR(gw_client->sock, &wait_sockets);
close( gw_client->sock );
- if ( debug_level == 1 ) {
+ if ( debug_level == 3 ) {
addr_to_string(gw_client->addr.sin_addr.s_addr, str2, sizeof (str2));
printf( "gateway: client %s timeout on interface %s\n", str2, batman_if->dev );
}
@@ -835,8 +857,8 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- if ( debug_level < 0 || debug_level > 3 ) {
- printf( "Invalid debug level: %i\nDebug level has to be between 0 and 3.\n", debug_level );
+ if ( debug_level < 0 || debug_level > 4 ) {
+ printf( "Invalid debug level: %i\nDebug level has to be between 0 and 4.\n", debug_level );
exit(EXIT_FAILURE);
}
@@ -983,7 +1005,6 @@ int main(int argc, char *argv[])
break;
case 0: /* child process - new daemon */
- openlog( "batmand", LOG_PID, LOG_DAEMON );
break;
case 1: /* parent process */
@@ -1000,6 +1021,25 @@ int main(int argc, char *argv[])
}
+ /* fork again for openwrt */
+ switch( pid = fork() ) {
+
+ case -1: /* error */
+ printf( "Error - can't fork to background: %s\n", strerror(errno) );
+ close_all_sockets();
+ exit(EXIT_FAILURE);
+ break;
+
+ case 0: /* child process - new daemon */
+ openlog( "batmand", LOG_PID, LOG_DAEMON );
+ break;
+
+ case 1: /* parent process */
+ exit( EXIT_SUCCESS );
+ break;
+
+ }
+
close( STDIN_FILENO );
close( STDOUT_FILENO );
close( STDERR_FILENO );
--
batman; test conversation