batctl: Translate client mac to originator mac for ping/traceroute
PATCH v3 1/4 batctl: Translate client mac to originator mac for ping/traceroute
A user may want to check the path selected by batman-adv for any client when only the MAC of the device with the IPv4 is known, but not the originator address. batctl can assist the user by parsing the global translation table to automatically translate it for him.
The ping itself will only be done until the originator is reached and not until the actual client could be contacted because the client cannot understand batman-adv ping packets.
---
Fixed some printf-strings
README | 1 + debug.h | 1 + functions.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ functions.h | 1 + man/batctl.8 | 10 ++++--- ping.c | 11 +++++++- traceroute.c | 11 +++++++- 7 files changed, 111 insertions(+), 6 deletions(-)
README +1 -0
@@ -87,6 +87,7 @@ parameters: -h print this help -i interval in seconds -t timeout in seconds + -T don't try to translate mac to originator address -R record route Example:
debug.h +1 -0
@@ -22,6 +22,7 @@#define DEBUG_BATIF_PATH_FMT "%s/batman_adv/%s"#define DEBUG_VIS_DATA "vis_data" +#define DEBUG_TRANSTABLE_GLOBAL "transtable_global"#define DEBUG_LOG "log"enum batctl_debug_tables {
functions.c +82 -0
91 lines not on this page · raw message
functions.h +1 -0
@@ -37,6 +37,7 @@ int file_exists(const char *fpath);int read_file (char *dir,char *path,int read_opt,float orig_timeout,float watch_interval);int write_file (char *dir,char *fname,char *arg1,char *arg2); +struct ether_addr *translate_mac (char *mesh_iface,struct ether_addr *mac);extern char *line_ptr;
man/batctl.8 +6 -4
@@ -204,17 +204,19 @@ tt - translation table counters All counters without a prefix concern payload (pure user data) traffic. .RE .br -.IP "\fBping\fP|\fBp\fP [\fB\-c count\fP][\fB\-i interval\fP][\fB\-t time\fP][\fB\-R\fP] \fBMAC_address\fP|\fBbat\-host_name\fP" +.IP "\fBping\fP|\fBp\fP [\fB\-c count\fP][\fB\-i interval\fP][\fB\-t time\fP][\fB\-R\fP][\fB\-T\fP] \fBMAC_address\fP|\fBbat\-host_name\fP" Layer 2 ping of a MAC address or bat\-host name. batctl will try to find the bat\-host name if the given parameter was not a MAC address. The "\-c" option tells batctl how man pings should be sent before the program exits. Without the "\-c" option batctl will continue pinging without end. Use CTRL + C to stop it. With "\-i" and "\-t" you can set the default interval between pings and the timeout time for replies, both in seconds. When run with "\-R", the route taken by the ping -messages will be recorded. +messages will be recorded. With "\-T" you can disable the automatic translation of a client MAC address to the originator +address which is responsible for this client. .br -.IP "\fBtraceroute\fP|\fBtr\fP [\fB\-n\fP] \fBMAC_address\fP|\fBbat\-host_name\fP" +.IP "\fBtraceroute\fP|\fBtr\fP [\fB\-n\fP][\fB\-T\fP] \fBMAC_address\fP|\fBbat\-host_name\fP" Layer 2 traceroute to a MAC address or bat\-host name. batctl will try to find the bat\-host name if the given parameter was not a MAC address. batctl will send 3 packets to each host and display the response time. If "\-n" is given batctl will -not replace the MAC addresses with bat\-host names in the output. +not replace the MAC addresses with bat\-host names in the output. With "\-T" you can disable the automatic translation of a +client MAC address to the originator address which is responsible for this client. .br .IP "\fBtcpdump\fP|\fBtd\fP [\fB\-c\fP][\fB\-n\fP][\fB\-p filter\fP][\fB\-x filter\fP] \fBinterface ...\fP" batctl will display all packets that are seen on the given interface(s). A variety of options to filter the output
ping.c +10 -1
@@ -51,6 +51,7 @@ void ping_usage(void)printf (" \t -i interval in seconds\n" );printf (" \t -t timeout in seconds\n" );printf (" \t -R record route\n" ); +printf (" \t -T don't try to translate mac to originator address\n" ); }void sig_handler (int sig)
@@ -83,8 +84,9 @@ int ping(char *mesh_iface, int argc, char **argv)size_t packet_len;char *debugfs_mnt;char icmp_socket[MAX_PATH +1 ]; +int disable_translate_mac =0 ; -while ((optchar =getopt (argc, argv,"hc:i:t:R" )) !=-1 ) { +while ((optchar =getopt (argc, argv,"hc:i:t:RT" )) !=-1 ) {switch (optchar) {case 'c' : loop_count =strtol (optarg,NULL ,10 );
@@ -111,6 +113,10 @@ int ping(char *mesh_iface, int argc, char **argv) rr =1 ; found_args++;break ; +case 'T' : + disable_translate_mac =1 ; + found_args +=1 ; +break ;default :ping_usage ();return EXIT_FAILURE ;
@@ -139,6 +145,9 @@ int ping(char *mesh_iface, int argc, char **argv) } } +if (!disable_translate_mac) + dst_mac =translate_mac (mesh_iface, dst_mac); + mac_string =ether_ntoa_long (dst_mac);signal (SIGINT , sig_handler);signal (SIGTERM , sig_handler);
traceroute.c +10 -1
@@ -47,6 +47,7 @@ void traceroute_usage(void)printf ("parameters:\n" );printf (" \t -h print this help\n" );printf (" \t -n don't convert addresses to bat-host names\n" ); +printf (" \t -T don't try to translate mac to originator address\n" ); }int traceroute (char *mesh_iface,int argc,char **argv)
@@ -63,8 +64,9 @@ int traceroute(char *mesh_iface, int argc, char **argv)double time_delta[NUM_PACKETS ];char *debugfs_mnt;char icmp_socket[MAX_PATH +1 ]; +int disable_translate_mac =0 ; -while ((optchar =getopt (argc, argv,"hn" )) !=-1 ) { +while ((optchar =getopt (argc, argv,"hnT" )) !=-1 ) {switch (optchar) {case 'h' :traceroute_usage ();
@@ -73,6 +75,10 @@ int traceroute(char *mesh_iface, int argc, char **argv) read_opt &= ~USE_BAT_HOSTS ; found_args +=1 ;break ; +case 'T' : + disable_translate_mac =1 ; + found_args +=1 ; +break ;default :traceroute_usage ();return EXIT_FAILURE ;
@@ -101,6 +107,9 @@ int traceroute(char *mesh_iface, int argc, char **argv) } } +if (!disable_translate_mac) + dst_mac =translate_mac (mesh_iface, dst_mac); + mac_string =ether_ntoa_long (dst_mac); debugfs_mnt =debugfs_mount (NULL );
Signature · 1 line
1.7.10.4
PATCH v3 2/4 batctl: Allow to use IPv4 addresses for ping/traceroute
IPv4 addresses and hostnames are easier to remember than many MAC addresses. batctl can automatically resolve the MAC address of the target device when the IP is configured on top of the batman-adv device and the source and destination batman-adv interface are in the same IPv4 subnet.
---
Fixed some printf-strings
README | 4 +- functions.c | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ functions.h | 1 + man/batctl.8 | 18 ++++--- ping.c | 6 +-- traceroute.c | 6 +-- 6 files changed, 170 insertions(+), 14 deletions(-)
README +2 -2
@@ -81,7 +81,7 @@ batctl ping Sends a Layer 2 batman-adv ping to check round trip time and connectivity -Usage: batctl ping [parameters] mac|bat-host +Usage: batctl ping [parameters] mac|bat-host|host-name|IPv4-address parameters: -c ping packet count -h print this help
@@ -107,7 +107,7 @@ batctl traceroute Traceroute sends 3 packets to each hop, awaits the answers and prints out the response times. -Usage: batctl traceroute [parameters] mac|bat-host +Usage: batctl traceroute [parameters] mac|bat-host|host-name|IPv4-address Example:
functions.c +149 -0
158 lines not on this page · raw message
functions.h +1 -0
@@ -38,6 +38,7 @@ int read_file(char *dir, char *path, int read_opt, float orig_timeout, float watch_interval);int write_file (char *dir,char *fname,char *arg1,char *arg2);struct ether_addr *translate_mac (char *mesh_iface,struct ether_addr *mac); +struct ether_addr *resolve_mac (const char *asc);extern char *line_ptr;
man/batctl.8 +12 -6
@@ -204,19 +204,25 @@ tt - translation table counters All counters without a prefix concern payload (pure user data) traffic. .RE .br -.IP "\fBping\fP|\fBp\fP [\fB\-c count\fP][\fB\-i interval\fP][\fB\-t time\fP][\fB\-R\fP][\fB\-T\fP] \fBMAC_address\fP|\fBbat\-host_name\fP" +.IP "\fBping\fP|\fBp\fP [\fB\-c count\fP][\fB\-i interval\fP][\fB\-t time\fP][\fB\-R\fP][\fB\-T\fP] \fBMAC_address\fP|\fBbat\-host_name\fP|\fBhost_name\fP|\fBIPv4_address\fP" Layer 2 ping of a MAC address or bat\-host name. batctl will try to find the bat\-host name if the given parameter was -not a MAC address. The "\-c" option tells batctl how man pings should be sent before the program exits. Without the "\-c" +not a MAC address. It can also try to guess the MAC address using an IPv4 address or a hostname when +the IPv4 address was configured on top of the batman-adv interface of the destination device and both source and +destination devices are in the same IPv4 subnet. +The "\-c" option tells batctl how man pings should be sent before the program exits. Without the "\-c" option batctl will continue pinging without end. Use CTRL + C to stop it. With "\-i" and "\-t" you can set the default interval between pings and the timeout time for replies, both in seconds. When run with "\-R", the route taken by the ping messages will be recorded. With "\-T" you can disable the automatic translation of a client MAC address to the originator address which is responsible for this client. .br -.IP "\fBtraceroute\fP|\fBtr\fP [\fB\-n\fP][\fB\-T\fP] \fBMAC_address\fP|\fBbat\-host_name\fP" +.IP "\fBtraceroute\fP|\fBtr\fP [\fB\-n\fP][\fB\-T\fP] \fBMAC_address\fP|\fBbat\-host_name\fP|\fBhost_name\fP|\fBIPv4_address\fP" Layer 2 traceroute to a MAC address or bat\-host name. batctl will try to find the bat\-host name if the given parameter -was not a MAC address. batctl will send 3 packets to each host and display the response time. If "\-n" is given batctl will -not replace the MAC addresses with bat\-host names in the output. With "\-T" you can disable the automatic translation of a -client MAC address to the originator address which is responsible for this client. +was not a MAC address. It can also try to guess the MAC address using an IPv4 address or a hostname when +the IPv4 address was configured on top of the batman-adv interface of the destination device and both source and +destination devices are in the same IPv4 subnet. +batctl will send 3 packets to each host and display the response time. If "\-n" is given batctl will +not replace the MAC addresses with bat\-host names in the output. With "\-T" you can disable the automatic translation +of a client MAC address to the originator address which is responsible for this client. .br .IP "\fBtcpdump\fP|\fBtd\fP [\fB\-c\fP][\fB\-n\fP][\fB\-p filter\fP][\fB\-x filter\fP] \fBinterface ...\fP" batctl will display all packets that are seen on the given interface(s). A variety of options to filter the output
ping.c +3 -3
@@ -44,7 +44,7 @@ char is_aborted = 0;void ping_usage (void ) { -printf ("Usage: batctl [options] ping [parameters] mac|bat-host \n" ); +printf ("Usage: batctl [options] ping [parameters] mac|bat-host|host_name|IPv4_address \n" );printf ("parameters:\n" );printf (" \t -c ping packet count \n" );printf (" \t -h print this help\n" );
@@ -137,10 +137,10 @@ int ping(char *mesh_iface, int argc, char **argv) dst_mac = &bat_host->mac_addr;if (!dst_mac) { - dst_mac =ether_aton (dst_string); + dst_mac =resolve_mac (dst_string);if (!dst_mac) { -printf ("Error - the ping destination is not a mac address or bat-host name: %s\n" , dst_string); +printf ("Error - mac address of the ping destination could not be resolved and is not a bat-host name: %s\n" , dst_string); goto out; } }
traceroute.c +3 -3
@@ -43,7 +43,7 @@void traceroute_usage (void ) { -printf ("Usage: batctl [options] traceroute [parameters] mac|bat-host \n" ); +printf ("Usage: batctl [options] traceroute [parameters] mac|bat-host|host_name|IPv4_address \n" );printf ("parameters:\n" );printf (" \t -h print this help\n" );printf (" \t -n don't convert addresses to bat-host names\n" );
@@ -99,10 +99,10 @@ int traceroute(char *mesh_iface, int argc, char **argv) dst_mac = &bat_host->mac_addr;if (!dst_mac) { - dst_mac =ether_aton (dst_string); + dst_mac =resolve_mac (dst_string);if (!dst_mac) { -printf ("Error - the traceroute destination is not a mac address or bat-host name: %s\n" , dst_string); +printf ("Error - mac address of the ping destination could not be resolved and is not a bat-host name: %s\n" , dst_string); goto out; } }
Signature · 1 line
1.7.10.4
PATCH v3 3/4 batctl: Allow to skip header in debug table output
In reply to Sven Eckelmann---
Fixed some printf-strings
debug.c | 17 ++++++++++++++--- debug.h | 1 + functions.c | 7 ++++++- functions.h | 3 ++- main.c | 2 +- man/batctl.8 | 3 +++ sys.c | 14 +++++++------- 7 files changed, 34 insertions(+), 13 deletions(-)
debug.c +14 -3
@@ -38,31 +38,37 @@ const struct debug_table_data batctl_debug_tables[BATCTL_TABLE_NUM] = { .opt_long = "originators", .opt_short = "o", .debugfs_name = "originators", + .header_lines = 2, }, { .opt_long = "gateways", .opt_short = "gwl", .debugfs_name = "gateways", + .header_lines = 1, }, { .opt_long = "translocal", .opt_short = "tl", .debugfs_name = "transtable_local", + .header_lines = 1, }, { .opt_long = "transglobal", .opt_short = "tg", .debugfs_name = "transtable_global", + .header_lines = 2, }, { .opt_long = "claimtable", .opt_short = "cl", .debugfs_name = "bla_claim_table", + .header_lines = 2, }, { .opt_long = "backbonetable", .opt_short = "bbt", .debugfs_name = "bla_backbone_table", + .header_lines = 2, }, };
@@ -73,6 +79,7 @@ void debug_table_usage(int debug_table)printf ("parameters:\n" );printf (" \t -h print this help\n" );printf (" \t -n don't replace mac addresses with bat-host names\n" ); +printf (" \t -H don't show the header\n" );printf (" \t -w [interval] watch mode - refresh the table continuously\n" );if (debug_table ==BATCTL_TABLE_ORIGINATORS )
@@ -88,7 +95,7 @@ int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv)float watch_interval =1 ; opterr =0 ; -while ((optchar =getopt (argc, argv,"hnw:t:" )) !=-1 ) { +while ((optchar =getopt (argc, argv,"hnw:t:H" )) !=-1 ) {switch (optchar) {case 'h' :debug_table_usage (debug_table);
@@ -121,6 +128,9 @@ int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv)return EXIT_FAILURE ; }break ; +case 'H' : + read_opt |=SKIP_HEADER ; +break ;case '?' :if (optopt =='t' )printf ("Error - option '-t' needs a number as argument\n" );
@@ -147,7 +157,8 @@ int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv)debugfs_make_path (DEBUG_BATIF_PATH_FMT "/" , mesh_iface, full_path,sizeof (full_path));return read_file (full_path, (char *)batctl_debug_tables[debug_table].debugfs_name, - read_opt, orig_timeout, watch_interval); + read_opt, orig_timeout, watch_interval, + batctl_debug_tables[debug_table].header_lines); }static void log_usage (void )
@@ -185,6 +196,6 @@ int log_print(char *mesh_iface, int argc, char **argv) }debugfs_make_path (DEBUG_BATIF_PATH_FMT "/" , mesh_iface, full_path,sizeof (full_path)); - res =read_file (full_path,DEBUG_LOG , read_opt,0 ,0 ); + res =read_file (full_path,DEBUG_LOG , read_opt,0 ,0 ,0 );return res; }
debug.h +1 -0
@@ -39,6 +39,7 @@ struct debug_table_data {const char opt_long[OPT_LONG_MAX_LEN ];const char opt_short[OPT_SHORT_MAX_LEN ];const char debugfs_name[DEBUG_TABLE_PATH_MAX_LEN ]; +size_t header_lines; };extern const struct debug_table_data batctl_debug_tables[BATCTL_TABLE_NUM ];
functions.c +6 -1
@@ -160,7 +160,7 @@ static void file_open_problem_dbg(char *dir, char *fname, char *full_path) }int read_file (char *dir,char *fname,int read_opt, -float orig_timeout,float watch_interval) +float orig_timeout,float watch_interval,size_t header_lines) {struct ether_addr *mac_addr;struct bat_host *bat_host;
@@ -169,6 +169,7 @@ int read_file(char *dir, char *fname, int read_opt,char full_path[500 ], *buff_ptr, *space_ptr, extra_char;size_t len =0 ;FILE *fp =NULL ; +size_t line;if (read_opt &USE_BAT_HOSTS )bat_hosts_init (read_opt);
@@ -178,6 +179,7 @@ int read_file(char *dir, char *fname, int read_opt,strncat (full_path, fname,sizeof (full_path) -strlen (full_path)); open: + line =0 ; fp =fopen (full_path,"r" );if (!fp) {
@@ -193,6 +195,9 @@ open: read:while (getline (&line_ptr, &len, fp) !=-1 ) { +if (line++ < header_lines && read_opt &SKIP_HEADER ) +continue ; +/* the buffer will be handled elsewhere */ if (read_opt &USE_READ_BUFF )break ;
functions.h +2 -1
@@ -35,7 +35,7 @@ char *get_name_by_macaddr(struct ether_addr *mac_addr, int read_opt);char *get_name_by_macstr (char *mac_str,int read_opt);int file_exists (const char *fpath);int read_file (char *dir,char *path,int read_opt, -float orig_timeout,float watch_interval); +float orig_timeout,float watch_interval,size_t skip_lines);int write_file (char *dir,char *fname,char *arg1,char *arg2);struct ether_addr *translate_mac (char *mesh_iface,struct ether_addr *mac);struct ether_addr *resolve_mac (const char *asc);
@@ -52,4 +52,5 @@ enum {SILENCE_ERRORS =0x20 ,NO_OLD_ORIGS =0x40 ,COMPAT_FILTER =0x80 , + SKIP_HEADER = 0x100, };
main.c +1 -1
@@ -118,7 +118,7 @@ int main(int argc, char **argv)if (strcmp (argv[1 ],"-v" ) ==0 ) {printf ("batctl %s [batman-adv: " ,SOURCE_VERSION ); - ret =read_file ("" , module_ver_path,USE_READ_BUFF |SILENCE_ERRORS ,0 ,0 ); + ret =read_file ("" , module_ver_path,USE_READ_BUFF |SILENCE_ERRORS ,0 ,0 ,0 );if ((line_ptr) && (line_ptr[strlen (line_ptr) -1 ] =='\n' )) line_ptr[strlen (line_ptr) -1 ] ='\0' ;
man/batctl.8 +3 -0
@@ -163,6 +163,9 @@ All of the debug tables support the following options: .RS 10 \-n do not replace the MAC addresses with bat\-host names in the output .RE +.RS 10 +\-H do not show the header of the debug table +.RE .RS 7 The originator table also supports the "\-t" filter option to remove all originators from the output that have not been seen
sys.c +7 -7
@@ -130,7 +130,7 @@ static int print_interfaces(char *mesh_iface)while ((iface_dir =readdir (iface_base_dir)) !=NULL ) {snprintf (path_buff,PATH_BUFF_LEN ,SYS_MESH_IFACE_FMT , iface_dir->d_name); - res =read_file ("" , path_buff,USE_READ_BUFF |SILENCE_ERRORS ,0 ,0 ); + res =read_file ("" , path_buff,USE_READ_BUFF |SILENCE_ERRORS ,0 ,0 ,0 );if (res !=EXIT_SUCCESS )continue ;
@@ -147,7 +147,7 @@ static int print_interfaces(char *mesh_iface) line_ptr =NULL ;snprintf (path_buff,PATH_BUFF_LEN ,SYS_IFACE_STATUS_FMT , iface_dir->d_name); - res =read_file ("" , path_buff,USE_READ_BUFF |SILENCE_ERRORS ,0 ,0 ); + res =read_file ("" , path_buff,USE_READ_BUFF |SILENCE_ERRORS ,0 ,0 ,0 );if (res !=EXIT_SUCCESS ) {printf ("<error reading status>\n" );continue ;
@@ -309,7 +309,7 @@ int handle_loglevel(char *mesh_iface, int argc, char **argv) goto out; } - res =read_file (path_buff,SYS_LOG_LEVEL ,USE_READ_BUFF ,0 ,0 ); + res =read_file (path_buff,SYS_LOG_LEVEL ,USE_READ_BUFF ,0 ,0 ,0 );if (res !=EXIT_SUCCESS ) goto out;
@@ -371,7 +371,7 @@ int handle_sys_setting(char *mesh_iface, int setting, int argc, char **argv)if (argc ==1 ) { res =read_file (path_buff, (char *)batctl_settings[setting].sysfs_name, -NO_FLAGS ,0 ,0 ); +NO_FLAGS ,0 ,0 ,0 ); goto out; }
@@ -434,7 +434,7 @@ int handle_gw_setting(char *mesh_iface, int argc, char **argv)snprintf (path_buff,PATH_BUFF_LEN ,SYS_BATIF_PATH_FMT , mesh_iface);if (argc ==1 ) { - res =read_file (path_buff,SYS_GW_MODE ,USE_READ_BUFF ,0 ,0 ); + res =read_file (path_buff,SYS_GW_MODE ,USE_READ_BUFF ,0 ,0 ,0 );if (res !=EXIT_SUCCESS ) goto out;
@@ -454,10 +454,10 @@ int handle_gw_setting(char *mesh_iface, int argc, char **argv)switch (gw_mode) {case GW_MODE_CLIENT : - res =read_file (path_buff,SYS_GW_SEL ,USE_READ_BUFF ,0 ,0 ); + res =read_file (path_buff,SYS_GW_SEL ,USE_READ_BUFF ,0 ,0 ,0 );break ;case GW_MODE_SERVER : - res =read_file (path_buff,SYS_GW_BW ,USE_READ_BUFF ,0 ,0 ); + res =read_file (path_buff,SYS_GW_BW ,USE_READ_BUFF ,0 ,0 ,0 );break ;default :printf ("off\n" );
Signature · 1 line
1.7.10.4
PATCH v3 4/4 batctl: Add filter option for debug tables
In reply to Sven EckelmannUsers may only want to query information about specific originator or clients when looking at the debug tables. This can easily be done using a simple grep when the originator mac is known. More problematic are clients or IP addresses. The user has to perform the steps already done for ping/traceroute to get the correct MAC address.
This filter functionality can also be added as part of batctl since the functionality for mac translation is already in batctl. This even allows to keep the header of the debug output intact while grep'ing for a specific address.
This can for example be used to query the TQ of the path until the gateway originator for a specific IP is reached.
$ batctl o -H -F ${IP}|sed -e 's/).*$//' -e 's/^.*(//'---
Fixed some printf-strings
Makefile | 2 +- debug.c | 27 ++++++++-- filter.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ filter.h | 43 +++++++++++++++ functions.c | 5 ++ functions.h | 4 +- man/batctl.8 | 12 +++-- 7 files changed, 251 insertions(+), 10 deletions(-) create mode 100644 filter.c create mode 100644 filter.h
Makefile +1 -1
@@ -24,7 +24,7 @@ export CONFIG_BATCTL_BISECT=n # batctl build BINARY_NAME = batctl -OBJ = main.o bat-hosts.o functions.o sys.o debug.o ping.o traceroute.o tcpdump.o hash.o vis.o debugfs.o ioctl.o list-batman.o +OBJ = main.o bat-hosts.o functions.o sys.o debug.o ping.o traceroute.o tcpdump.o hash.o vis.o debugfs.o ioctl.o list-batman.o filter.o OBJ_BISECT = bisect_iv.o MANPAGE = man/batctl.8
debug.c +22 -5
@@ -32,6 +32,7 @@#include "debug.h" #include "debugfs.h" #include "functions.h" +#include "filter.h" const struct debug_table_data batctl_debug_tables[BATCTL_TABLE_NUM ] = { {
@@ -80,6 +81,8 @@ void debug_table_usage(int debug_table)printf (" \t -h print this help\n" );printf (" \t -n don't replace mac addresses with bat-host names\n" );printf (" \t -H don't show the header\n" ); +printf (" \t -F addr - add filter to only show lines about this address\n" ); +printf (" \t -T do not try to translate client mac addresses when adding filters\n" );printf (" \t -w [interval] watch mode - refresh the table continuously\n" );if (debug_table ==BATCTL_TABLE_ORIGINATORS )
@@ -88,14 +91,17 @@ void debug_table_usage(int debug_table)int handle_debug_table (char *mesh_iface,int debug_table,int argc,char **argv) { -int optchar, read_opt =USE_BAT_HOSTS ; +int optchar, read_opt =USE_BAT_HOSTS |TRANSLATE_MAC ;char full_path[MAX_PATH +1 ];char *debugfs_mnt;float orig_timeout;float watch_interval =1 ; +int ret; opterr =0 ; -while ((optchar =getopt (argc, argv,"hnw:t:H" )) !=-1 ) { +filter_init (); + +while ((optchar =getopt (argc, argv,"hnw:t:HTF:" )) !=-1 ) {switch (optchar) {case 'h' :debug_table_usage (debug_table);
@@ -131,6 +137,13 @@ int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv)case 'H' : read_opt |=SKIP_HEADER ;break ; +case 'T' : + read_opt &= ~TRANSLATE_MAC ; +break ; +case 'F' : + read_opt |=USE_FILTER ; +filter_add (mesh_iface, optarg, read_opt); +break ;case '?' :if (optopt =='t' )printf ("Error - option '-t' needs a number as argument\n" );
@@ -156,9 +169,13 @@ int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv) }debugfs_make_path (DEBUG_BATIF_PATH_FMT "/" , mesh_iface, full_path,sizeof (full_path)); -return read_file (full_path, (char *)batctl_debug_tables[debug_table].debugfs_name, - read_opt, orig_timeout, watch_interval, - batctl_debug_tables[debug_table].header_lines); + ret =read_file (full_path, (char *)batctl_debug_tables[debug_table].debugfs_name, + read_opt, orig_timeout, watch_interval, + batctl_debug_tables[debug_table].header_lines); + +filter_free (); + +return ret; }static void log_usage (void )
filter.c new file +168 -0
168 lines not on this page · raw message
filter.h new file +43 -0
43 lines not on this page · raw message
functions.c +5 -0
@@ -38,6 +38,7 @@#include "main.h" #include "functions.h" #include "bat-hosts.h" +#include "filter.h" #include "sys.h" #include "debug.h" #include "debugfs.h"
@@ -213,6 +214,10 @@ read:continue ; } +if (read_opt &USE_FILTER && line > header_lines && + !filter_match_line (line_ptr)) +continue ; +/* replace mac addresses with bat host names */ buff_ptr = line_ptr;
functions.h +3 -1
@@ -35,7 +35,7 @@ char *get_name_by_macaddr(struct ether_addr *mac_addr, int read_opt);char *get_name_by_macstr (char *mac_str,int read_opt);int file_exists (const char *fpath);int read_file (char *dir,char *path,int read_opt, -float orig_timeout,float watch_interval,size_t skip_lines); +float orig_timeout,float watch_interval,size_t header_lines);int write_file (char *dir,char *fname,char *arg1,char *arg2);struct ether_addr *translate_mac (char *mesh_iface,struct ether_addr *mac);struct ether_addr *resolve_mac (const char *asc);
@@ -53,4 +53,6 @@ enum {NO_OLD_ORIGS =0x40 ,COMPAT_FILTER =0x80 ,SKIP_HEADER =0x100 , +USE_FILTER =0x200 , + TRANSLATE_MAC = 0x400, };
man/batctl.8 +9 -3
@@ -158,13 +158,19 @@ mounted batctl will attempt to do this step for you. All of the debug tables support the following options: .RS 10 -\-w refresh the list every second or add a number to let it refresh at a custom interval in seconds (with optional decimal places) +\-w refresh the list every second or add a number to let it refresh at a custom interval in seconds (with optional decimal places) .RE .RS 10 -\-n do not replace the MAC addresses with bat\-host names in the output +\-n do not replace the MAC addresses with bat\-host names in the output .RE .RS 10 -\-H do not show the header of the debug table +\-H do not show the header of the debug table +.RE +.RS 10 +\-F addr add filter to only show lines about the address +.RE +.RS 10 +\-T do not try to translate client mac addresses when adding filters .RE .RS 7
Signature · 1 line
1.7.10.4