batmand: Debian patches for 0.3.2+51+g1e275d9-1
Hi,
different patches [1] were aggregated in the Debian package of batmand 0.3.2+51+g1e275d9-1.
Kind regards,
Sven
PATCH 1/13 batmand: Disable strict-aliasing rules
There are different aliasing problems in posix/tunnel.c and maybe other files. This can lead to wrongly generated code when the compiler assumes strict aliasing rules.
--- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
@@ -37,7 +37,7 @@ MANPAGE = man/batmand.8 #NO_POLICY_ROUTING = -DNO_POLICY_ROUTING # batmand flags and options -CFLAGS += -pedantic -Wall -W -std=gnu99 -MD +CFLAGS += -pedantic -Wall -W -std=gnu99 -MD -fno-strict-aliasing CPPFLAGS += -DDEBUG_MALLOC -DMEMORY_USAGE -DPROFILE_DATA $(NO_POLICY_ROUTING) LDLIBS += -lpthread
Signature · 1 line
1.8.4.rc3
PATCH 2/13 batmand: Add CFLAGS to the linker step
In reply to Sven EckelmannThe GCC manual states for different parameters that the options for compilation must also be used when linking. The options for compilation are stored in CFLAGS and added to LINK.o to fix the behavior.
Option which need this are for example -fPIC/-fPIE or -flto.
--- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
@@ -57,7 +57,7 @@ RM ?= rm -f INSTALL ?= install MKDIR ?= mkdir -p COMPILE.c = $(Q_CC)$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -LINK.o = $(Q_LD)$(CC) $(LDFLAGS) $(TARGET_ARCH) +LINK.o = $(Q_LD)$(CC) $(CFLAGS) $(LDFLAGS) $(TARGET_ARCH) # standard install paths PREFIX = /usr/local
Signature · 1 line
1.8.4.rc3
PATCH 3/13 batmand: Don't fail rebuild when header is removed
In reply to Sven EckelmannThe *.d depends files for make just list the files used when building an object file. Removing a file listed in such a dependency file causes make to search for a way to recreate it. This usually cannot work because these files aren't autogenerated.
The gcc option -MP can be used to generate empty rule for these files. Removing a file in a dependency list will then execute this empty rule and continue with the execution of the creation of the object file. This compilation process will then automatically correct the dependency file.
--- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
@@ -37,7 +37,7 @@ MANPAGE = man/batmand.8 #NO_POLICY_ROUTING = -DNO_POLICY_ROUTING # batmand flags and options -CFLAGS += -pedantic -Wall -W -std=gnu99 -MD -fno-strict-aliasing +CFLAGS += -pedantic -Wall -W -std=gnu99 -MD -MP -fno-strict-aliasing CPPFLAGS += -DDEBUG_MALLOC -DMEMORY_USAGE -DPROFILE_DATA $(NO_POLICY_ROUTING) LDLIBS += -lpthread
Signature · 1 line
1.8.4.rc3
PATCH 4/13 batmand: Add include guards to avoid redundant declarations or include loops
In reply to Sven Eckelmann--- allocate.h | 6 +++--- batman.h | 4 ++-- bitarray.h | 4 +++- hash.h | 4 ++-- hna.h | 5 ++++- originator.h | 4 +++- os.h | 4 ++-- packet.h | 5 +++++ profile.h | 5 ++++- ring_buffer.h | 5 ++++- schedule.h | 4 ++++ types.h | 4 ++-- 12 files changed, 38 insertions(+), 16 deletions(-)
allocate.h +3 -3
@@ -20,10 +20,10 @@*/ -#ifndef _ALLOCATE_H -#define _ALLOCATE_H 1 -#include <stdint.h> +#ifndef _BATMAND_ALLOCATE_H +#define _BATMAND_ALLOCATE_H +#include <stdint.h> void checkIntegrity (void );
batman.h +2 -2
@@ -21,8 +21,8 @@ -#ifndef _BATMAN_BATMAN_H -#define _BATMAN_BATMAN_H +#ifndef _BATMAND_BATMAN_H +#define _BATMAND_BATMAN_H#include <sys/types.h> #include <netinet/in.h>
bitarray.h +3 -1
@@ -19,7 +19,8 @@* */ - +#ifndef _BATMAND_BITARRAY_H +#define _BATMAND_BITARRAY_H#include "batman.h" #define WORD_BIT_SIZE ( sizeof(TYPE_OF_WORD) * 8 )
@@ -34,3 +35,4 @@ char bit_get_packet( TYPE_OF_WORD *seq_bits, int16_t seq_num_diff, int8_t set_maint bit_packet_count (TYPE_OF_WORD *seq_bits );uint8_t bit_count (int32_t to_count ); +#endif
hash.h +2 -2
@@ -18,8 +18,8 @@* 02110-1301, USA * */ -#ifndef _BATMAN_HASH_H -#define _BATMAN_HASH_H +#ifndef _BATMAND_HASH_H +#define _BATMAND_HASH_H
hna.h +4 -1
@@ -19,7 +19,8 @@* */ - +#ifndef _BATMAND_HNA_H +#define _BATMAND_HNA_H#include "batman.h"
@@ -82,3 +83,5 @@ void hna_global_update(struct orig_node *orig_node, unsigned char *new_hna, int16_t new_hna_len, struct neigh_node *old_router);void hna_global_check_tq (struct orig_node *orig_node);void hna_global_del (struct orig_node *orig_node); + +#endif
originator.h +3 -1
@@ -19,7 +19,8 @@* */ - +#ifndef _BATMAND_ORIGINATOR_H +#define _BATMAND_ORIGINATOR_H#include "batman.h" #include "types.h"
@@ -33,3 +34,4 @@ void update_orig( struct orig_node *orig_node, struct bat_packet *in, uint32_t nvoid purge_orig (uint32_t curr_time );void debug_orig (void ); +#endif
os.h +2 -2
@@ -19,8 +19,8 @@* */ -#ifndef _BATMAN_OS_H -#define _BATMAN_OS_H +#ifndef _BATMAND_OS_H +#define _BATMAND_OS_H#include "batman.h"
packet.h +5 -0
@@ -19,6 +19,9 @@* */ +#ifndef _BATMAND_PACKET_H +#define _BATMAND_PACKET_H +#define COMPAT_VERSION 5#define VIS_COMPAT_VERSION 23
@@ -57,3 +60,5 @@ struct vis_data {uint8_t data;uint32_t ip; } __attribute__((packed)); + +#endif
profile.h +4 -1
@@ -19,7 +19,8 @@* */ - +#ifndef _BATMAND_PROFILE_H +#define _BATMAND_PROFILE_H enum {
@@ -51,3 +52,5 @@ void prof_init(int32_t index, char *name);void prof_start (int32_t index);void prof_stop (int32_t index);void prof_print (void ); + +#endif
ring_buffer.h +4 -1
@@ -19,7 +19,8 @@* */ - +#ifndef _BATMAND_RING_BUFFER_H +#define _BATMAND_RING_BUFFER_H#include <stdint.h> #include "batman.h"
@@ -28,3 +29,5 @@void ring_buffer_set (uint8_t tq_recv[],uint8_t *tq_index,uint8_t value);uint8_t ring_buffer_avg (uint8_t tq_recv[]); + +#endif
schedule.h +4 -0
@@ -19,7 +19,11 @@* */ +#ifndef _BATMAND_SCHEDULE_H +#define _BATMAND_SCHEDULE_Hvoid schedule_own_packet (struct batman_if *batman_if );void schedule_forward_packet (struct orig_node *orig_node,struct bat_packet *in,uint32_t neigh,uint8_t directlink,int16_t hna_buff_len,struct batman_if *if_outgoing,uint32_t curr_time);void send_outstanding_packets (uint32_t curr_time); + +#endif
types.h +2 -2
@@ -19,8 +19,8 @@* */ -#ifndef TYPES_H -#define TYPES_H +#ifndef _BATMAND_TYPES_H +#define _BATMAND_TYPES_H#include "packet.h"
Signature · 1 line
1.8.4.rc3
PATCH 5/13 batmand: Avoid assigning const buffer to non-const pointer
In reply to Sven EckelmannStrings in C are tried to be saved in the .rodata by the compiler/linker. This section is readonly as the name suggests. Pointer to these strings should therefore be const.
--- allocate.c | 2 +- hna.c | 4 ++-- linux/kernel.c | 10 +++++----- linux/route.c | 8 ++++---- linux/tun.c | 4 ++-- os.h | 16 ++++++++-------- posix/posix.c | 2 +- posix/unix_socket.c | 2 +- profile.c | 2 +- profile.h | 4 ++-- 10 files changed, 27 insertions(+), 27 deletions(-)
allocate.c +1 -1
@@ -67,7 +67,7 @@ struct memoryUsage }; -static size_t getHeaderPad () { +static size_t getHeaderPad (void ) {size_t alignwith, pad;if (sizeof (TYPE_OF_WORD ) >sizeof (void *))
hna.c +2 -2
@@ -39,12 +39,12 @@ struct list_head_first hna_chg_list;static pthread_mutex_t hna_chg_list_mutex;static struct hashtable_t *hna_global_hash =NULL ; -int compare_hna (void *data1,void *data2) +static int compare_hna (void *data1,void *data2) {return (memcmp (data1, data2,5 ) ==0 ?1 :0 ); } -int choose_hna (void *data,int32_t size) +static int choose_hna (void *data,int32_t size) {unsigned char *key= data;uint32_t hash =0 ;
linux/kernel.c +5 -5
@@ -70,7 +70,7 @@ static void set_integer_file(const char* filename, int32_t integer)fclose (f); } -void set_rp_filter (int32_t state,char * dev) +void set_rp_filter (int32_t state,const char * dev) {char filename[100 ], *colon_ptr;
@@ -85,7 +85,7 @@ void set_rp_filter(int32_t state, char* dev) *colon_ptr =':' ; } -int32_t get_rp_filter (char *dev) +int32_t get_rp_filter (const char *dev) {int32_t state =0 ;char filename[100 ], *colon_ptr;
@@ -103,7 +103,7 @@ int32_t get_rp_filter(char *dev)return state; } -void set_send_redirects (int32_t state,char * dev) +void set_send_redirects (int32_t state,const char * dev) {char filename[100 ], *colon_ptr;
@@ -118,7 +118,7 @@ void set_send_redirects(int32_t state, char* dev) *colon_ptr =':' ; } -int32_t get_send_redirects (char *dev) +int32_t get_send_redirects (const char *dev) {int32_t state =0 ;char filename[100 ], *colon_ptr;
@@ -146,7 +146,7 @@ int32_t get_forwarding(void)return get_integer_file ("/proc/sys/net/ipv4/ip_forward" ); } -int8_t bind_to_iface (int32_t sock,char *dev) +int8_t bind_to_iface (int32_t sock,const char *dev) {char *colon_ptr;
linux/route.c +4 -4
@@ -73,7 +73,7 @@ static const char *rule_type_to_string_script[] = {#include <net/route.h> -void add_del_route (uint32_t dest,uint8_t netmask,uint32_t router,uint32_t src_ip,int32_t ifi,char *dev,uint8_t rt_table,int8_t route_type,int8_t route_action) +void add_del_route (uint32_t dest,uint8_t netmask,uint32_t router,uint32_t src_ip,int32_t ifi,const char *dev,uint8_t rt_table,int8_t route_type,int8_t route_action) {struct rtentry route;struct sockaddr_in *addr;
@@ -152,7 +152,7 @@ void add_del_route(uint32_t dest, uint8_t netmask, uint32_t router, uint32_t srcclose (sock); } -void add_del_rule (uint32_t BATMANUNUSED (network ),uint8_t BATMANUNUSED (netmask ),int8_t BATMANUNUSED (rt_table ),uint32_t BATMANUNUSED (prio ),char *BATMANUNUSED (iif ),int8_t BATMANUNUSED (rule_type ),int8_t BATMANUNUSED (rule_action )) +void add_del_rule (uint32_t BATMANUNUSED (network ),uint8_t BATMANUNUSED (netmask ),int8_t BATMANUNUSED (rt_table ),uint32_t BATMANUNUSED (prio ),const char *BATMANUNUSED (iif ),int8_t BATMANUNUSED (rule_type ),int8_t BATMANUNUSED (rule_action )) {return ; }
@@ -169,7 +169,7 @@ int flush_routes_rules(int8_t BATMANUNUSED(is_rule))#else -void add_del_route (uint32_t dest,uint8_t netmask,uint32_t router,uint32_t src_ip,int32_t ifi,char *dev,uint8_t rt_table,int8_t route_type,int8_t route_action) +void add_del_route (uint32_t dest,uint8_t netmask,uint32_t router,uint32_t src_ip,int32_t ifi,const char *dev,uint8_t rt_table,int8_t route_type,int8_t route_action) {int netlink_sock;size_t len;
@@ -354,7 +354,7 @@ void add_del_route(uint32_t dest, uint8_t netmask, uint32_t router, uint32_t src* ***/ -void add_del_rule (uint32_t network,uint8_t netmask,int8_t rt_table,uint32_t prio,char *iif,int8_t rule_type,int8_t rule_action) +void add_del_rule (uint32_t network,uint8_t netmask,int8_t rt_table,uint32_t prio,const char *iif,int8_t rule_type,int8_t rule_action) {int netlink_sock;size_t len;
linux/tun.c +2 -2
@@ -47,7 +47,7 @@#define IPTABLES_DEL_ACC "iptables -t nat -D POSTROUTING -s %s/%i -j ACCEPT" -int run_cmd (char *cmd) { +static int run_cmd (const char *cmd) {int error, pipes[2 ], stderr =-1 , ret =0 ;char error_log[256 ];
@@ -90,7 +90,7 @@ int probe_nat_tool(void) {return run_cmd ("which iptables > /dev/null" ); } -void exec_iptables_rule (char *cmd,int8_t route_action) { +static void exec_iptables_rule (const char *cmd,int8_t route_action) {if (disable_client_nat)return ;
os.h +8 -8
@@ -44,8 +44,8 @@ void segmentation_fault(int32_t sig) NO_RETURN; void restore_and_exit(uint8_t is_sigsegv) NO_RETURN;/* route.c */ -void add_del_route (uint32_t dest,uint8_t netmask,uint32_t router,uint32_t src_ip,int32_t ifi,char *dev,uint8_t rt_table,int8_t route_type,int8_t del ); -void add_del_rule (uint32_t network,uint8_t netmask,int8_t rt_table,uint32_t prio,char *iif,int8_t dst_rule,int8_t del ); +void add_del_route (uint32_t dest,uint8_t netmask,uint32_t router,uint32_t src_ip,int32_t ifi,const char *dev,uint8_t rt_table,int8_t route_type,int8_t del ); +void add_del_rule (uint32_t network,uint8_t netmask,int8_t rt_table,uint32_t prio,const char *iif,int8_t dst_rule,int8_t del );int add_del_interface_rules (int8_t del );int flush_routes_rules (int8_t rt_table );
@@ -69,13 +69,13 @@ void init_interface_gw(void);void interface_listen_sockets (void );/* kernel.c */ -void set_rp_filter (int32_t state,char * dev ); -int32_t get_rp_filter (char *dev ); -void set_send_redirects (int32_t state,char * dev ); -int32_t get_send_redirects (char *dev ); +void set_rp_filter (int32_t state,const char * dev ); +int32_t get_rp_filter (const char *dev ); +void set_send_redirects (int32_t state,const char * dev ); +int32_t get_send_redirects (const char *dev );void set_forwarding (int32_t state );int32_t get_forwarding (void ); -int8_t bind_to_iface (int32_t sock,char *dev ); +int8_t bind_to_iface (int32_t sock,const char *dev );int is_wifi_interface (char *dev,int fd);/* posix.c */
@@ -96,7 +96,7 @@ void *client_to_gw_tun( void *arg );/* unix_sokcet.c */ void *unix_listen (void *arg );void internal_output (uint32_t sock); -void debug_output (int8_t debug_prio,char *format, ... ); +void debug_output (int8_t debug_prio,const char *format, ... );#endif
posix/posix.c +1 -1
@@ -125,7 +125,7 @@ uint64_t get_time_msec64(void) }/* batman animation */ -static void sym_print (char x,char y,char *z ) { +static void sym_print (char x,char y,const char *z ) {char i =0 ,Z ;
posix/unix_socket.c +1 -1
@@ -39,7 +39,7 @@#include "../hna.h" -void debug_output (int8_t debug_prio,char *format, ...) { +void debug_output (int8_t debug_prio,const char *format, ...) {struct list_head *debug_pos;struct debug_level_info *debug_level_info;
profile.c +1 -1
@@ -33,7 +33,7 @@ static struct prof_container prof_container[PROF_COUNT]; -void prof_init (int32_t index,char *name) { +void prof_init (int32_t index,const char *name) { prof_container[index].total_time =0 ; prof_container[index].calls =0 ;
profile.h +2 -2
@@ -42,13 +42,13 @@ struct prof_container {clock_t start_time;clock_t total_time; -char *name; +const char *name;uint64_t calls; }; -void prof_init (int32_t index,char *name); +void prof_init (int32_t index,const char *name);void prof_start (int32_t index);void prof_stop (int32_t index);void prof_print (void );
Signature · 1 line
1.8.4.rc3
PATCH 6/13 batmand: Fix preprocessor check for defined NO_POLICY_ROUTING
In reply to Sven Eckelmann--- linux/route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
linux/route.c +1 -1
@@ -69,7 +69,7 @@ static const char *rule_type_to_string_script[] = {* ***/ -#if NO_POLICY_ROUTING +#ifdef NO_POLICY_ROUTING #include <net/route.h>
Signature · 1 line
1.8.4.rc3
PATCH 7/13 batmand: Fix printf format strings
In reply to Sven EckelmannThe types for the format string did not always match the type of the parameter. This can lead to wrong output or crashes. There is also no '' format string but a thousand format string. But this thousand ' is not ISO C and doesn't work with all libc implementations. And the thousand ' is not supported for strings.
--- allocate.c | 2 +- originator.c | 12 ++++++------ os.h | 2 +- posix/unix_socket.c | 2 +- profile.c | 3 ++- 5 files changed, 11 insertions(+), 10 deletions(-)
allocate.c +1 -1
@@ -210,7 +210,7 @@ void checkIntegrity(void)for ( memoryWalker = memoryList; memoryWalker !=NULL ; memoryWalker = memoryWalker->next ) {if ( memoryWalker->counter !=0 ) -debug_output (5 ," tag: %''4i, num malloc: %4i, bytes per malloc: %''4i, total: %6i\n" , memoryWalker->tag, memoryWalker->counter, memoryWalker->length, memoryWalker->counter * memoryWalker->length ); +debug_output (5 ," tag: %4i, num malloc: %4i, bytes per malloc: %4i, total: %6i\n" , memoryWalker->tag, memoryWalker->counter, memoryWalker->length, memoryWalker->counter * memoryWalker->length ); }pthread_mutex_unlock (&memory_mutex);
originator.c +6 -6
@@ -423,7 +423,7 @@ void debug_orig(void) { uptime_sec = (uint64_t )(get_time_msec64 () /1000 );debug_output (2 ,"BOD\n" ); -debug_output (2 ,"%''12s (%s/%i) %''15s [%10s], gw_class ... [B.A.T.M.A.N. %s, MainIF/IP: %s/%s, UT: %id%2ih%2im] \n" ,"Gateway" ,"#" ,TQ_MAX_VALUE ,"Nexthop" ,"outgoingIF" ,SOURCE_VERSION , ((struct batman_if *)if_list.next)->dev, orig_str, (uint32_t )(uptime_sec/86400 ), (uint32_t )((uptime_sec%86400 )/3600 ), (uint32_t )((uptime_sec%3600 )/60 )); +debug_output (2 ,"%12s (%s/%i) %15s [%10s], gw_class ... [B.A.T.M.A.N. %s, MainIF/IP: %s/%s, UT: %id%2ih%2im] \n" ,"Gateway" ,"#" ,TQ_MAX_VALUE ,"Nexthop" ,"outgoingIF" ,SOURCE_VERSION , ((struct batman_if *)if_list.next)->dev, orig_str, (uint32_t )(uptime_sec/86400 ), (uint32_t )((uptime_sec%86400 )/3600 ), (uint32_t )((uptime_sec%3600 )/60 ));if (list_empty ( &gw_list ) ) {
@@ -446,7 +446,7 @@ void debug_orig(void) {get_gw_speeds ( gw_node->orig_node->gwflags, &download_speed, &upload_speed ); -debug_output (2 ,"%s %-15s (%3i) %''15s [%10s], gw_class %3i - %i%s/%i%s, gateway failures: %i \n" , ( curr_gateway == gw_node ?"=>" :" " ), str, gw_node->orig_node->router->tq_avg, str2, gw_node->orig_node->router->if_incoming->dev, gw_node->orig_node->gwflags, (download_speed >2048 ? download_speed /1024 : download_speed), (download_speed >2048 ?"MBit" :"KBit" ), (upload_speed >2048 ? upload_speed /1024 : upload_speed), (upload_speed >2048 ?"MBit" :"KBit" ), gw_node->gw_failure); +debug_output (2 ,"%s %-15s (%3i) %15s [%10s], gw_class %3i - %i%s/%i%s, gateway failures: %i \n" , ( curr_gateway == gw_node ?"=>" :" " ), str, gw_node->orig_node->router->tq_avg, str2, gw_node->orig_node->router->if_incoming->dev, gw_node->orig_node->gwflags, (download_speed >2048 ? download_speed /1024 : download_speed), (download_speed >2048 ?"MBit" :"KBit" ), (upload_speed >2048 ? upload_speed /1024 : upload_speed), (upload_speed >2048 ?"MBit" :"KBit" ), gw_node->gw_failure); batman_count++;
@@ -467,7 +467,7 @@ void debug_orig(void) { uptime_sec = (uint64_t )(get_time_msec64 () /1000 );debug_output (1 ,"BOD \n" ); -debug_output (1 ," %-11s (%s/%i) %''15s [%10s]: %''20s ... [B.A.T.M.A.N. %s, MainIF/IP: %s/%s, UT: %id%2ih%2im] \n" ,"Originator" ,"#" ,TQ_MAX_VALUE ,"Nexthop" ,"outgoingIF" ,"Potential nexthops" ,SOURCE_VERSION , ((struct batman_if *)if_list.next)->dev, orig_str, (uint32_t )(uptime_sec/86400 ), (uint32_t )((uptime_sec%86400 )/3600 ), (uint32_t )((uptime_sec%3600 )/60 )); +debug_output (1 ," %-11s (%s/%i) %15s [%10s]: %20s ... [B.A.T.M.A.N. %s, MainIF/IP: %s/%s, UT: %id%2ih%2im] \n" ,"Originator" ,"#" ,TQ_MAX_VALUE ,"Nexthop" ,"outgoingIF" ,"Potential nexthops" ,SOURCE_VERSION , ((struct batman_if *)if_list.next)->dev, orig_str, (uint32_t )(uptime_sec/86400 ), (uint32_t )((uptime_sec%86400 )/3600 ), (uint32_t )((uptime_sec%3600 )/60 ));if ( debug_clients.clients_num[3 ] >0 ) {
@@ -481,7 +481,7 @@ void debug_orig(void) { }debug_output (4 ,"Originator list \n" ); -debug_output (4 ," %-11s (%s/%i) %''15s [%10s]: %''20s\n" ,"Originator" ,"#" ,TQ_MAX_VALUE ,"Nexthop" ,"outgoingIF" ,"Potential nexthops" ); +debug_output (4 ," %-11s (%s/%i) %15s [%10s]: %20s\n" ,"Originator" ,"#" ,TQ_MAX_VALUE ,"Nexthop" ,"outgoingIF" ,"Potential nexthops" ); }
@@ -497,8 +497,8 @@ void debug_orig(void) {addr_to_string ( orig_node->orig, str,sizeof (str) );addr_to_string ( orig_node->router->addr, str2,sizeof (str2) ); -debug_output (1 ,"%-15s (%3i) %''15s [%10s]:" , str, orig_node->router->tq_avg, str2, orig_node->router->if_incoming->dev ); -debug_output (4 ,"%''15s (%3i) %''15s [%10s], last_valid: %u: \n" , str, orig_node->router->tq_avg, str2, orig_node->router->if_incoming->dev, orig_node->last_valid ); +debug_output (1 ,"%-15s (%3i) %15s [%10s]:" , str, orig_node->router->tq_avg, str2, orig_node->router->if_incoming->dev ); +debug_output (4 ,"%15s (%3i) %15s [%10s], last_valid: %u: \n" , str, orig_node->router->tq_avg, str2, orig_node->router->if_incoming->dev, orig_node->last_valid ); debug_out_size =0 ;
os.h +1 -1
@@ -96,7 +96,7 @@ void *client_to_gw_tun( void *arg );/* unix_sokcet.c */ void *unix_listen (void *arg );void internal_output (uint32_t sock); -void debug_output (int8_t debug_prio,const char *format, ... ); +void debug_output (int8_t debug_prio,const char *format, ... ) __attribute__ ((format (printf,2 ,3 )));#endif
posix/unix_socket.c +1 -1
@@ -347,7 +347,7 @@ void *unix_listen(void * BATMANUNUSED(arg)) { }else if ( buff[0 ] =='q' ) {if ( status >2 ) { -debug_output (3 ,"Unix socket: changing purge timeout from: %i to: %i\n" , purge_timeout,strtol (buff +2 ,NULL ,10 )); +debug_output (3 ,"Unix socket: changing purge timeout from: %i to: %li\n" , purge_timeout,strtol (buff +2 ,NULL ,10 )); purge_timeout =strtol (buff +2 ,NULL ,10 ); }
profile.c +2 -1
@@ -23,6 +23,7 @@#include "os.h" #include "batman.h" +#include <inttypes.h>
@@ -67,7 +68,7 @@ void prof_print(void) {for ( index =0 ; index <PROF_COUNT ; index++ ) { -debug_output (5 ," %''30s: cpu time = %10.3f, calls = %''10i, avg time per call = %4.10f \n" , prof_container[index].name, (float )prof_container[index].total_time/CLOCKS_PER_SEC , prof_container[index].calls, ( prof_container[index].calls ==0 ?0.0 : ( ( (float )prof_container[index].total_time/CLOCKS_PER_SEC ) / (float )prof_container[index].calls ) ) ); +debug_output (5 ," %30s: cpu time = %10.3f, calls = %10" PRId64", avg time per call = %4.10f \n" , prof_container[index].name, (float )prof_container[index].total_time/CLOCKS_PER_SEC , prof_container[index].calls, ( prof_container[index].calls ==0 ?0.0 : ( ( (float )prof_container[index].total_time/CLOCKS_PER_SEC ) / (float )prof_container[index].calls ) ) ); }
Signature · 1 line
1.8.4.rc3
PATCH 8/13 batmand: Clear screen using ANSI escape codes
In reply to Sven EckelmannIt is not necessary to call an external binary to clear the screen of a default unix terminal emulator. The external call using system("clear") may be used by an attacker to get untrusted code called with an higher privilege because batmand has to be run using uid 0.
--- posix/init.c | 3 ++- posix/posix.c | 3 ++- posix/unix_socket.c | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-)
posix/init.c +2 -1
@@ -719,7 +719,8 @@ more_hna: }else if (strncmp ( buff_ptr,"BOD" ,3 ) ==0 ) {if ( !batch_mode ) -system ("clear" ); +/* clear screen, set cursor back to 0,0 */ +printf ("\033[2J\033[0;0f" ); }else {
posix/posix.c +2 -1
@@ -181,7 +181,8 @@ static void bat_wait( int32_t T, int32_t t ) {void print_animation (void ) { -system ("clear" ); +/* clear screen, set cursor back to 0,0 */ +printf ("\033[2J\033[0;0f" );BAT_LOGO_END (0 ,50 );sym_print (0 ,3 ,"." );
posix/unix_socket.c +2 -1
@@ -100,7 +100,8 @@ void debug_output(int8_t debug_prio, const char *format, ...) {dprintf (debug_level_info->fd,"[%10u] " ,get_time_msec ());if (((debug_level ==1 ) || (debug_level ==2 )) && (debug_level_info->fd ==1 ) && (strncmp (format,"BOD" ,3 ) ==0 )) -system ("clear" ); +/* clear screen, set cursor back to 0,0 */ +printf ("\033[2J\033[0;0f" );if (((debug_level !=1 ) && (debug_level !=2 )) || (debug_level_info->fd !=1 ) || (strncmp (format,"EOD" ,3 ) !=0 ))vdprintf (debug_level_info->fd, format, args);
Signature · 1 line
1.8.4.rc3
PATCH 9/13 batmand: Use POSIX daemon function instead of self-written one
In reply to Sven Eckelmann--- posix/init.c | 45 ++------------------------------------------- 1 file changed, 2 insertions(+), 43 deletions(-)
posix/init.c +2 -43
@@ -35,6 +35,7 @@#include <arpa/inet.h> #include <fcntl.h> #include <getopt.h> +#include <unistd.h> #include "../os.h"
@@ -44,48 +45,6 @@int8_t stop; - -static int my_daemon (void ) { - -int fd; - -switch (fork () ) { - -case -1 : -return -1 ; - -case 0 : -break ; - -default : -exit (EXIT_SUCCESS ); - - } - -if (setsid () ==-1 ) -return (-1 ); - -/* Make certain we are not a session leader, or else we might reacquire a controlling terminal */ -if (fork () ) -exit (EXIT_SUCCESS ); - -chdir ("/" ); - -if ( ( fd =open (_PATH_DEVNULL,O_RDWR ,0 ) ) !=-1 ) { - -dup2 (fd,STDIN_FILENO ); -dup2 (fd,STDOUT_FILENO ); -dup2 (fd,STDERR_FILENO ); - -if ( fd >2 ) -close (fd); - - } - -return 0 ; - -} -static void create_routing_pipe (void ) {int fd[2 ], pipe_opts;
@@ -534,7 +493,7 @@ void apply_init_args( int argc, char *argv[] ) {/* daemonize */ if (debug_level ==0 ) { -if (my_daemon () <0 ) { +if (daemon (0 ,0 ) <0 ) {printf ("Error - can't fork to background: %s\n" ,strerror (errno));restore_defaults ();
Signature · 1 line
1.8.4.rc3
PATCH 10/13 batmand: Add missing includes and remove unused includes
In reply to Sven Eckelmann--- allocate.c | 1 - batman.c | 7 ++++++- batman.h | 17 ++++++++--------- bitarray.c | 3 --- bitarray.h | 1 + hna.c | 10 ++++++++++ hna.h | 2 ++ linux/kernel.c | 7 ++----- linux/route.c | 8 ++++++++ linux/tun.c | 6 +++++- list-batman.h | 2 -- originator.c | 10 +++++++++- originator.h | 3 ++- os.h | 7 ++++++- packet.h | 2 ++ posix/init.c | 12 ++++++++++-- posix/posix.c | 14 ++++++++++++-- posix/tunnel.c | 16 +++++++++++----- posix/unix_socket.c | 11 ++++++++++- profile.c | 9 ++++++--- profile.h | 3 +++ ring_buffer.c | 2 +- ring_buffer.h | 3 --- schedule.c | 9 +++++++++ schedule.h | 3 +++ types.h | 7 +++++++ 26 files changed, 133 insertions(+), 42 deletions(-)
allocate.c +0 -1
@@ -23,7 +23,6 @@#include <stdio.h> #include <stdlib.h> -#include <string.h> #include "os.h" #include "allocate.h"
batman.c +6 -1
@@ -25,7 +25,7 @@#include <stdlib.h> #include <string.h> #include <stdio.h> -#include <errno.h> +#include <netinet/in.h> #include "os.h" #include "batman.h"
@@ -33,6 +33,11 @@#include "schedule.h" #include "hna.h" #include "types.h" +#include "profile.h" +#include "allocate.h" +#include "hash.h" +#include "bitarray.h" +#include "packet.h" uint8_t debug_level =0 ;
batman.h +8 -9
@@ -25,20 +25,15 @@#define _BATMAND_BATMAN_H#include <sys/types.h> -#include <netinet/in.h> #include <pthread.h> -#include <sys/un.h> #include <stdint.h> -#include <stdio.h> +#include <sys/select.h> +#include <sys/un.h> +#include <netinet/in.h> #define TYPE_OF_WORD uintmax_t/* you should choose something big, if you don't want to waste cpu */ #include "list-batman.h" -#include "bitarray.h" -#include "hash.h" -#include "allocate.h" -#include "profile.h" -#include "ring_buffer.h" #ifndef SOURCE_VERSION #define SOURCE_VERSION "0.4"
@@ -192,7 +187,11 @@ extern uint8_t local_win_size;extern uint8_t num_words;extern uint8_t aggregation_enabled; -#include "types.h" // can be removed as soon as these function have been cleaned up +/* fwd declarations */ +struct batman_if ; +struct orig_node ; +struct neigh_node ; +int8_t batman (void );void usage (void );void verbose_usage (void );
bitarray.c +0 -3
@@ -20,9 +20,6 @@*/ - -#include <stdio.h> /* printf() */ -#include "bitarray.h" #include "os.h"
bitarray.h +1 -0
@@ -22,6 +22,7 @@#ifndef _BATMAND_BITARRAY_H#define _BATMAND_BITARRAY_H +#include <stdint.h> #include "batman.h" #define WORD_BIT_SIZE ( sizeof(TYPE_OF_WORD) * 8 )
hna.c +10 -0
@@ -21,13 +21,23 @@ +#include "allocate.h" #include "hna.h" #include "os.h" #include "hash.h" +#include "packet.h" +#include "types.h" #include <errno.h> +#include <stdio.h> #include <stdlib.h> #include <arpa/inet.h> +#include <netinet/in.h> +#include <pthread.h> +#include <stddef.h> +#include <string.h> +#include <sys/socket.h> +unsigned char *hna_buff_local =NULL ;
hna.h +2 -0
@@ -22,6 +22,8 @@#ifndef _BATMAND_HNA_H#define _BATMAND_HNA_H +#include <stdint.h> +#include "list-batman.h" #include "batman.h"
linux/kernel.c +2 -5
@@ -22,17 +22,14 @@#include <stdio.h> -#include <fcntl.h> -#include <errno.h> -#include <unistd.h> +#include <stdint.h> #include <sys/ioctl.h> #include <sys/socket.h> #include <inttypes.h> #include <net/if.h> +#include <string.h> #include "../os.h" -#include "../batman.h" -#define IOCGETNWDEV 1
linux/route.c +8 -0
@@ -29,6 +29,14 @@#include <linux/netlink.h> #include <linux/rtnetlink.h> #include <sys/socket.h> +#include <netinet/in.h> +#include <stddef.h> +#include <stdint.h> +#include <stdio.h> +#include <string.h> +#include <sys/uio.h> +#include "../allocate.h" +#include "../bitarray.h" #include "../os.h" #include "../batman.h"
linux/tun.c +5 -1
@@ -26,16 +26,20 @@#include <errno.h> #include <sys/ioctl.h> #include <arpa/inet.h> /* inet_ntop() */ -#include <netinet/ip.h> /* iph */ +#include <netinet/in.h> #include <linux/if_tun.h> /* TUNSETPERSIST, ... */ #include <linux/if.h> /* ifr_if, ifr_tun */ #include <sys/socket.h> #include <stdio.h> #include <stdlib.h> /* system() */ #include <sys/wait.h> /* WEXITSTATUS */ +#include <stddef.h> +#include <stdint.h> +#include <string.h> #include "../os.h" #include "../batman.h" +#include "../types.h" #define IPTABLES_ADD_MASQ "iptables -t nat -A POSTROUTING -o %s -j MASQUERADE"#define IPTABLES_DEL_MASQ "iptables -t nat -D POSTROUTING -o %s -j MASQUERADE"
list-batman.h +0 -2
@@ -20,8 +20,6 @@*/ -#include <stddef.h> /* offsetof() */ -#ifndef _LINUX_LIST_H#define _LINUX_LIST_H
originator.c +9 -1
@@ -22,12 +22,20 @@#include <string.h> -#include <stdlib.h> #include <stdio.h> +#include <netinet/in.h> +#include <stddef.h> + +#include "list-batman.h" +#include "packet.h" #include "os.h" #include "batman.h" #include "originator.h" #include "hna.h" +#include "hash.h" +#include "profile.h" +#include "allocate.h" +#include "ring_buffer.h" #include "types.h" struct neigh_node *create_neighbor (struct orig_node *orig_node,struct orig_node *orig_neigh_node,uint32_t neigh,struct batman_if *if_incoming) {
originator.h +2 -1
@@ -22,7 +22,8 @@#ifndef _BATMAND_ORIGINATOR_H#define _BATMAND_ORIGINATOR_H -#include "batman.h" +#include <stdint.h> +#include "types.h"
os.h +6 -1
@@ -22,7 +22,12 @@#ifndef _BATMAND_OS_H#define _BATMAND_OS_H -#include "batman.h" +#include <stddef.h> +#include <stdint.h> +#include <netinet/in.h> + + +#include "types.h" #ifdef __GNUC_MINOR__#define NO_RETURN __attribute__ ((__noreturn__))
packet.h +2 -0
@@ -22,6 +22,8 @@#ifndef _BATMAND_PACKET_H#define _BATMAND_PACKET_H +#include <stdint.h> +#define COMPAT_VERSION 5#define VIS_COMPAT_VERSION 23
posix/init.c +10 -2
@@ -21,13 +21,13 @@ +#include <stdint.h> #include <stdlib.h> #include <unistd.h> #include <stdio.h> #include <syslog.h> #include <errno.h> #include <signal.h> -#include <paths.h> #include <string.h> #include <sys/ioctl.h> #include <sys/socket.h>
@@ -35,12 +35,20 @@#include <arpa/inet.h> #include <fcntl.h> #include <getopt.h> -#include <unistd.h> +#include <netinet/in.h> +#include <pthread.h> +#include <sys/select.h> +#include <sys/un.h> #include "../os.h" #include "../batman.h" #include "../hna.h" +#include "../allocate.h" +#include "../bitarray.h" +#include "../list-batman.h" +#include "../packet.h" +#include "../types.h" int8_t stop;
posix/posix.c +12 -2
@@ -31,13 +31,23 @@#include <syslog.h> #include <sys/socket.h> #include <sys/times.h> -#include <sys/ioctl.h> #include <sys/wait.h> -#include <net/if.h> +#include <netinet/in.h> +#include <pthread.h> +#include <stdint.h> +#include <sys/select.h> +#include <sys/time.h> +#include <time.h> +#include "../os.h" #include "../batman.h" #include "../hna.h" +#include "../allocate.h" +#include "../hash.h" +#include "../packet.h" +#include "../types.h" +#include "../list-batman.h" #define BAT_LOGO_PRINT (x,y,z) printf( "\x1B[%i;%iH%c", y + 1, x, z )/* write char 'z' into column 'x', row 'y' */
posix/tunnel.c +11 -5
@@ -23,21 +23,27 @@#include <errno.h> #include <unistd.h> -#include <stdlib.h> #include <string.h> -#include <arpa/inet.h> -#include <sys/ioctl.h> #include <sys/socket.h> -#include <netinet/in_systm.h> #include <netinet/ip.h> #include <netinet/udp.h> -#include <netinet/tcp.h> #include <net/if.h> #include <fcntl.h> /* open(), O_RDWR */ +#include <netinet/in.h> +#include <stddef.h> +#include <stdint.h> +#include <sys/select.h> +#include <sys/time.h> +#include <sys/types.h> #include "../os.h" #include "../batman.h" +#include "../allocate.h" +#include "../hash.h" +#include "../list-batman.h" +#include "../packet.h" +#include "../types.h"
posix/unix_socket.c +10 -1
@@ -32,11 +32,20 @@#include <unistd.h> #include <sys/socket.h> #include <arpa/inet.h> - +#include <netinet/in.h> +#include <pthread.h> +#include <stdint.h> +#include <sys/select.h> +#include <sys/un.h> +#include <sys/types.h> #include "../os.h" #include "../batman.h" #include "../hna.h" +#include "../allocate.h" +#include "../list-batman.h" +#include "../packet.h" +#include "../types.h" void debug_output (int8_t debug_prio,const char *format, ...) {
profile.c +6 -3
@@ -21,9 +21,12 @@ -#include "os.h" -#include "batman.h" #include <inttypes.h> +#include <stdint.h> +#include <time.h> + +#include "profile.h" +#include "os.h"
@@ -78,7 +81,7 @@ void prof_print(void) {#else -void prof_init (int32_t index,char *name ) { +void prof_init (int32_t index,const char *name ) { }
profile.h +3 -0
@@ -22,6 +22,9 @@#ifndef _BATMAND_PROFILE_H#define _BATMAND_PROFILE_H +#include <stdint.h> +#include <time.h> +enum { PROF_choose_gw,
ring_buffer.c +1 -1
@@ -20,7 +20,7 @@*/ - +#include "batman.h" #include "ring_buffer.h"
ring_buffer.h +0 -3
@@ -23,9 +23,6 @@#define _BATMAND_RING_BUFFER_H#include <stdint.h> -#include "batman.h" - -void ring_buffer_set (uint8_t tq_recv[],uint8_t *tq_index,uint8_t value);uint8_t ring_buffer_avg (uint8_t tq_recv[]);
schedule.c +9 -0
@@ -23,6 +23,15 @@#include <string.h> #include <stdlib.h> +#include <netinet/in.h> + +#include "list-batman.h" +#include "packet.h" +#include "types.h" +#include "allocate.h" +#include "hash.h" +#include "profile.h" +#include "bitarray.h" #include "os.h" #include "batman.h" #include "schedule.h"
schedule.h +3 -0
@@ -22,6 +22,9 @@#ifndef _BATMAND_SCHEDULE_H#define _BATMAND_SCHEDULE_H +#include <stdint.h> +#include "types.h" +void schedule_own_packet (struct batman_if *batman_if );void schedule_forward_packet (struct orig_node *orig_node,struct bat_packet *in,uint32_t neigh,uint8_t directlink,int16_t hna_buff_len,struct batman_if *if_outgoing,uint32_t curr_time);void send_outstanding_packets (uint32_t curr_time);
types.h +7 -0
@@ -22,7 +22,14 @@ #ifndef _BATMAND_TYPES_H #define _BATMAND_TYPES_H +#include <stdint.h> +#include <pthread.h> +#include <sys/un.h> +#include <netinet/in.h> + +#include "list-batman.h" #include "packet.h" +#include "batman.h" struct orig_node { /* structure for orig_list maintaining nodes of mesh */ uint32_t orig;
Signature · 1 line
1.8.4.rc3
PATCH 11/13 batmand: Mark unused parameter in dummy functions
In reply to Sven Eckelmann--- allocate.c | 4 +++- profile.c | 7 ++++--- 2 files changed, 7 insertions(+), 4 deletions(-)
allocate.c +3 -1
@@ -421,6 +421,8 @@ void debugFree(void *memoryParameter, int tag)#else +#include "batman.h" +void checkIntegrity (void ) { }
@@ -459,7 +461,7 @@ void *debugRealloc(void *memory, uint32_t length, int32_t tag)return result; } -void debugFree (void *memory,int32_t tag) +void debugFree (void *memory,int32_t BATMANUNUSED (tag )) {free (memory); }
profile.c +4 -3
@@ -80,20 +80,21 @@ void prof_print(void) {#else +#include "batman.h" -void prof_init (int32_t index,const char *name ) { +void prof_init (int32_t BATMANUNUSED (index ),const char *BATMANUNUSED (name ) ) { } -void prof_start (int32_t index ) { +void prof_start (int32_t BATMANUNUSED (index ) ) { } -void prof_stop (int32_t index ) { +void prof_stop (int32_t BATMANUNUSED (index ) ) { }
Signature · 1 line
1.8.4.rc3
PATCH 12/13 batmand: Fix preprocessor check for defined DEBUG_MALLOC && MEMORY_USAGE
In reply to Sven Eckelmann--- batman.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
batman.c +1 -1
@@ -47,7 +47,7 @@ uint8_t debug_level = 0;uint8_t debug_level_max =5 ; -#elif DEBUG_MALLOC &&MEMORY_USAGE +#elif definedDEBUG_MALLOC && definedMEMORY_USAGE uint8_t debug_level_max =5 ;
Signature · 1 line
1.8.4.rc3
PATCH 13/13 batmand: Add error for MEMORY_USAGE dependency
In reply to Sven EckelmannPrint error during build when MEMORY_USAGE is requested but the build is done without DEBUG_MALLOC.
--- allocate.c | 4 ++++ 1 file changed, 4 insertions(+)
allocate.c +4 -0
@@ -32,6 +32,10 @@#if definedDEBUG_MALLOC +#ifndef MEMORY_USAGE +#error DEBUG_MALLOC can only be used together with MEMORY_USAGE +#endif +static pthread_mutex_t chunk_mutex =PTHREAD_MUTEX_INITIALIZER ;struct chunkHeader *chunkList =NULL ;
Signature · 1 line
1.8.4.rc3
Elektra
AppliedHello –
applied in a27537a...
Thanks for your kind support.
Cheers,
Elektra
Signature · 1 line
Elektra <[email protected]>