The following commit has been merged in the master branch: commit 25800e186bd450a0f4459192e88f6783b70fbc19 Author: Axel Neumann neumann@cgws.de Date: Thu Dec 14 02:02:23 2006 +0100
rp_filter patch
diff --git a/batman.c b/batman.c index 585889d..2ac5de1 100644 --- a/batman.c +++ b/batman.c @@ -1176,6 +1176,7 @@ int batman() unsigned char in[1501], *hna_recv_buff; static char orig_str[ADDR_STR_LEN], neigh_str[ADDR_STR_LEN]; int forward_old, res, hna_buff_len, hna_buff_count; + int if_rp_filter_all_old, if_rp_filter_default_old; int is_my_addr, is_my_orig, is_broadcast, is_duplicate, is_bidirectional, forward_duplicate_packet; int time_count = 0, curr_time;
@@ -1209,9 +1210,16 @@ int batman() batman_if->out.seqno = 0; batman_if->out.gwflags = gateway_class; batman_if->out.version = BATMAN_VERSION; - + batman_if->if_rp_filter_old = get_rp_filter( batman_if->dev ); + set_rp_filter( 0 , batman_if->dev ); }
+ if_rp_filter_all_old = get_rp_filter( "all" ); + if_rp_filter_default_old = get_rp_filter( "default" ); + + set_rp_filter( 0, "all" ); + set_rp_filter( 0, "default" ); + forward_old = get_forwarding(); set_forwarding(1);
@@ -1495,6 +1503,15 @@ int batman()
set_forwarding( forward_old );
+ list_for_each(if_pos, &if_list) { + batman_if = list_entry(if_pos, struct batman_if, list); + set_rp_filter( batman_if->if_rp_filter_old , batman_if->dev ); + } + + set_rp_filter( if_rp_filter_all_old, "all" ); + set_rp_filter( if_rp_filter_default_old, "default" ); + + checkLeak();
return 0; diff --git a/batman.h b/batman.h index 4ff893b..5355996 100644 --- a/batman.h +++ b/batman.h @@ -142,6 +142,7 @@ struct batman_if int tcp_gw_sock; int tunnel_sock; int if_num; + int if_rp_filter_old; pthread_t listen_thread_id; struct sockaddr_in addr; struct sockaddr_in broad; diff --git a/linux.c b/linux.c index e2a5f4d..937b097 100644 --- a/linux.c +++ b/linux.c @@ -42,6 +42,36 @@ #include "os.h" #include "batman.h"
+void set_rp_filter(int state, char* dev) +{ + FILE *f; + char filename[100]; + sprintf( filename, "/proc/sys/net/ipv4/conf/%s/rp_filter", dev); + + + if((f = fopen(filename, "w")) == NULL) + return; + + fprintf(f, "%d", state); + fclose(f); +} + +int get_rp_filter(char *dev) +{ + FILE *f; + int state = 0; + char filename[100]; + sprintf( filename, "/proc/sys/net/ipv4/conf/%s/rp_filter", dev); + + if((f = fopen(filename, "r")) == NULL) + return 0; + + fscanf(f, "%d", &state); + fclose(f); + + return state; +} + void set_forwarding(int state) { FILE *f; diff --git a/os.h b/os.h index 82b28a7..12f361d 100644 --- a/os.h +++ b/os.h @@ -25,6 +25,11 @@ 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); + + + void output(char *format, ...); void add_del_route( unsigned int dest, unsigned int netmask, unsigned int router, int del, char *dev, int sock ); int is_aborted();