From: Simon Wunderlich simon@open-mesh.com
Check if the interface supplied by -m (or bat0 by default) is actually a batman interface. The check is performed by testing if the sysfs path is available.
This change is required since debugfs now contains originator tables per hard interface. This might be confusing for users as batctl -m eth0 o will now (accidently) print these tables without eth0 beeing a batman interface, assuming eth0 is a hard interface used by batman-adv.
Some reordering of commands were required to first allow commands which don't depend on a (correctly set up) mesh interface, like bisect or interface.
Signed-off-by: Simon Wunderlich simon@open-mesh.com --- Changes to PATCHv2:
* fix VLAN check, this is now similar to the sysfs handling code --- main.c | 32 +++++++++++++++++--------------- sys.c | 30 ++++++++++++++++++++++++++++++ sys.h | 1 + 3 files changed, 48 insertions(+), 15 deletions(-)
diff --git a/main.c b/main.c index a37c0b7..44cf49b 100644 --- a/main.c +++ b/main.c @@ -137,7 +137,23 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); }
- if ((strcmp(argv[1], "ping") == 0) || (strcmp(argv[1], "p") == 0)) { + if ((strcmp(argv[1], "interface") == 0) || (strcmp(argv[1], "if") == 0)) { + + ret = interface(mesh_iface, argc - 1, argv + 1); + + } else if ((strcmp(argv[1], "tcpdump") == 0) || (strcmp(argv[1], "td") == 0)) { + + ret = tcpdump(argc - 1, argv + 1); + +#ifdef BATCTL_BISECT + } else if ((strcmp(argv[1], "bisect_iv") == 0)) { + + ret = bisect_iv(argc - 1, argv + 1); +#endif + } else if (check_mesh_iface(mesh_iface) < 0) { + fprintf(stderr, "Error - interface %s is not present or not a batman-adv interface\n", mesh_iface); + exit(EXIT_FAILURE); + } else if ((strcmp(argv[1], "ping") == 0) || (strcmp(argv[1], "p") == 0)) {
ret = ping(mesh_iface, argc - 1, argv + 1);
@@ -145,14 +161,6 @@ int main(int argc, char **argv)
ret = traceroute(mesh_iface, argc - 1, argv + 1);
- } else if ((strcmp(argv[1], "tcpdump") == 0) || (strcmp(argv[1], "td") == 0)) { - - ret = tcpdump(argc - 1, argv + 1); - - } else if ((strcmp(argv[1], "interface") == 0) || (strcmp(argv[1], "if") == 0)) { - - ret = interface(mesh_iface, argc - 1, argv + 1); - } else if ((strcmp(argv[1], "loglevel") == 0) || (strcmp(argv[1], "ll") == 0)) {
ret = handle_loglevel(mesh_iface, argc - 1, argv + 1); @@ -179,12 +187,6 @@ int main(int argc, char **argv)
ret = translate(mesh_iface, argc - 1, argv + 1);
-#ifdef BATCTL_BISECT - } else if ((strcmp(argv[1], "bisect_iv") == 0)) { - - ret = bisect_iv(argc - 1, argv + 1); -#endif - } else {
for (i = 0; i < BATCTL_SETTINGS_NUM; i++) { diff --git a/sys.c b/sys.c index fd6e107..0b98d82 100644 --- a/sys.c +++ b/sys.c @@ -566,3 +566,33 @@ out: free(path_buff); return res; } + +int check_mesh_iface(char *mesh_iface) +{ + char *base_dev = NULL; + char path_buff[PATH_BUFF_LEN]; + int ret = -1, vid; + DIR *dir; + + /* use the parent interface if this is a VLAN */ + vid = vlan_get_link(mesh_iface, &base_dev); + if (vid >= 0) + snprintf(path_buff, PATH_BUFF_LEN, SYS_VLAN_PATH, base_dev, vid); + else + snprintf(path_buff, PATH_BUFF_LEN, SYS_BATIF_PATH_FMT, mesh_iface); + path_buff[PATH_BUFF_LEN - 1] = '\0'; + + /* try to open the mesh sys directory */ + dir = opendir(path_buff); + if (!dir) + goto out; + + closedir(dir); + + ret = 0; +out: + if (base_dev) + free(base_dev); + + return ret; +} diff --git a/sys.h b/sys.h index 5633822..5aec020 100644 --- a/sys.h +++ b/sys.h @@ -71,5 +71,6 @@ int interface(char *mesh_iface, int argc, char **argv); int handle_loglevel(char *mesh_iface, int argc, char **argv); int handle_sys_setting(char *mesh_iface, int setting, int argc, char **argv); int handle_gw_setting(char *mesh_iface, int argc, char **argv); +int check_mesh_iface(char *mesh_iface);
#endif
From: Simon Wunderlich simon@open-mesh.com
This patch adds batctl support for the recently introduced mesh wide multi interface optimization in batman-adv.
Signed-off-by: Simon Wunderlich simon@open-mesh.com --- Changes to PATCHv1:
* check if the supplied interface actually belongs to the interface * add README and manpage descriptions --- README | 25 +++++++++++++++++++++++++ debug.c | 32 ++++++++++++++++++++++++++------ man/batctl.8 | 4 +++- sys.c | 28 ++++++++++++++++++++++++++++ sys.h | 1 + 5 files changed, 83 insertions(+), 7 deletions(-)
diff --git a/README b/README index a4507b7..facc82e 100644 --- a/README +++ b/README @@ -305,6 +305,31 @@ fe:fe:00:00:06:01 0.830s (213) fe:fe:00:00:02:01 [ eth0]: fe:fe:00:00: fe:fe:00:00:02:01 0.240s (255) fe:fe:00:00:02:01 [ eth0]: fe:fe:00:00:03:01 ( 81) fe:fe:00:00:02:01 (255) fe:fe:00:00:07:01 0.670s (200) fe:fe:00:00:02:01 [ eth0]: fe:fe:00:00:03:01 ( 68) fe:fe:00:00:02:01 (200)
+Since 2014.1.0, each batman interface has an individual originator table as well which is only used for routing. +These table explain to which neighbor a packet is forwarded when the packet is received on the specified interface. + +Example: + +$ batctl originators -i eth0 +[B.A.T.M.A.N. adv master-b82b9b2, IF/MAC: eth0/fe:f0:00:00:02:01 (bat0 BATMAN_IV)] + Originator last-seen (#/255) Nexthop [outgoingIF]: Potential nexthops ... +fe:f1:00:00:03:01 0.170s (255) fe:f1:00:00:03:01 [ eth1]: fe:f1:00:00:03:01 (255) +fe:f1:00:00:01:01 0.510s (253) fe:f1:00:00:01:01 [ eth1]: fe:f1:00:00:01:01 (253) +fe:f0:00:00:05:01 0.660s (222) fe:f1:00:00:03:01 [ eth1]: fe:f0:00:00:03:01 (198) fe:f1:00:00:03:01 (222) +fe:f0:00:00:03:01 0.560s (252) fe:f1:00:00:03:01 [ eth1]: fe:f1:00:00:03:01 (252) fe:f0:00:00:03:01 (240) +fe:f0:00:00:04:01 0.250s (240) fe:f1:00:00:03:01 [ eth1]: fe:f1:00:00:03:01 (240) fe:f0:00:00:03:01 (211) +fe:f0:00:00:01:01 0.850s (255) fe:f1:00:00:01:01 [ eth1]: fe:f1:00:00:01:01 (255) fe:f0:00:00:01:01 (238) +$ batctl originators -i eth1 +[B.A.T.M.A.N. adv master-b82b9b2, IF/MAC: eth1/fe:f1:00:00:02:01 (bat0 BATMAN_IV)] + Originator last-seen (#/255) Nexthop [outgoingIF]: Potential nexthops ... +fe:f1:00:00:03:01 0.880s (240) fe:f1:00:00:03:01 [ eth1]: fe:f1:00:00:03:01 (240) +fe:f1:00:00:01:01 0.250s (239) fe:f1:00:00:01:01 [ eth1]: fe:f1:00:00:01:01 (239) +fe:f0:00:00:05:01 0.340s (211) fe:f1:00:00:03:01 [ eth1]: fe:f0:00:00:03:01 (210) fe:f1:00:00:03:01 (211) +fe:f0:00:00:03:01 0.260s (253) fe:f0:00:00:03:01 [ eth0]: fe:f1:00:00:03:01 (240) fe:f0:00:00:03:01 (253) +fe:f0:00:00:04:01 0.010s (225) fe:f0:00:00:03:01 [ eth0]: fe:f1:00:00:03:01 (224) fe:f0:00:00:03:01 (225) +fe:f0:00:00:01:01 0.510s (255) fe:f0:00:00:01:01 [ eth0]: fe:f1:00:00:01:01 (240) fe:f0:00:00:01:01 (255) + + batctl interface ================
diff --git a/debug.c b/debug.c index 6836857..04b2c6d 100644 --- a/debug.c +++ b/debug.c @@ -27,6 +27,7 @@ #include "debug.h" #include "debugfs.h" #include "functions.h" +#include "sys.h"
const struct debug_table_data batctl_debug_tables[BATCTL_TABLE_NUM] = { { @@ -89,8 +90,10 @@ static void debug_table_usage(int debug_table) fprintf(stderr, " \t -H don't show the header\n"); fprintf(stderr, " \t -w [interval] watch mode - refresh the table continuously\n");
- if (debug_table == BATCTL_TABLE_ORIGINATORS) + if (debug_table == BATCTL_TABLE_ORIGINATORS) { fprintf(stderr, " \t -t timeout interval - don't print originators not seen for x.y seconds \n"); + fprintf(stderr, " \t -i [interface] - show multiif originator table for a specific interface\n"); + } }
int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv) @@ -98,11 +101,12 @@ int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv) int optchar, read_opt = USE_BAT_HOSTS; char full_path[MAX_PATH+1]; char *debugfs_mnt; + char *orig_iface = NULL; float orig_timeout; float watch_interval = 1; opterr = 0;
- while ((optchar = getopt(argc, argv, "hnw:t:H")) != -1) { + while ((optchar = getopt(argc, argv, "hnw:t:Hi:")) != -1) { switch (optchar) { case 'h': debug_table_usage(debug_table); @@ -138,11 +142,24 @@ int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv) case 'H': read_opt |= SKIP_HEADER; break; + case 'i': + if (debug_table != BATCTL_TABLE_ORIGINATORS) { + fprintf(stderr, "Error - unrecognised option '-%c'\n", optchar); + debug_table_usage(debug_table); + return EXIT_FAILURE; + } + + if (check_mesh_iface_ownership(mesh_iface, optarg) != EXIT_SUCCESS) + return EXIT_FAILURE; + + orig_iface = optarg; + break; case '?': - if (optopt == 't') + if (optopt == 't') { fprintf(stderr, "Error - option '-t' needs a number as argument\n"); - - else if (optopt == 'w') { + } else if (optopt == 'i') { + fprintf(stderr, "Error - option '-i' needs an interface as argument\n"); + } else if (optopt == 'w') { read_opt |= CLR_CONT_READ; break; } @@ -162,7 +179,10 @@ int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv) return EXIT_FAILURE; }
- debugfs_make_path(DEBUG_BATIF_PATH_FMT "/", mesh_iface, full_path, sizeof(full_path)); + if (orig_iface) + debugfs_make_path(DEBUG_BATIF_PATH_FMT "/", orig_iface, full_path, sizeof(full_path)); + else + 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); diff --git a/man/batctl.8 b/man/batctl.8 index b808293..8ef1123 100644 --- a/man/batctl.8 +++ b/man/batctl.8 @@ -192,7 +192,9 @@ All of the debug tables support the following options:
.RS 7 The originator table also supports the "-t" filter option to remove all originators from the output that have not been seen -for the specified amount of seconds (with optional decimal places). +for the specified amount of seconds (with optional decimal places). It furthermore supports the "-i" parameter to specify an +interface for which the originator table should be printed. If this parameter is not supplied, the default originator table +is printed.
List of debug tables: .RS 10 diff --git a/sys.c b/sys.c index 0b98d82..14c3cf5 100644 --- a/sys.c +++ b/sys.c @@ -596,3 +596,31 @@ out:
return ret; } + +int check_mesh_iface_ownership(char *mesh_iface, char *hard_iface) +{ + char path_buff[PATH_BUFF_LEN]; + int res; + + /* check if this device actually belongs to the mesh interface */ + snprintf(path_buff, sizeof(path_buff), SYS_MESH_IFACE_FMT, hard_iface); + path_buff[sizeof(path_buff) - 1] = '\0'; + res = read_file("", path_buff, USE_READ_BUFF | SILENCE_ERRORS, 0, 0, 0); + if (res != EXIT_SUCCESS) { + fprintf(stderr, "Error - the directory '%s' could not be read: %s\n", + path_buff, strerror(errno)); + fprintf(stderr, "Is the batman-adv module loaded and sysfs mounted ?\n"); + return EXIT_FAILURE; + } + + if (line_ptr[strlen(line_ptr) - 1] == '\n') + line_ptr[strlen(line_ptr) - 1] = '\0'; + + if (strcmp(line_ptr, mesh_iface) != 0) { + fprintf(stderr, "Error - interface %s is part of batman network %s, not %s\n", + hard_iface, line_ptr, mesh_iface); + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} diff --git a/sys.h b/sys.h index 5aec020..8296bd4 100644 --- a/sys.h +++ b/sys.h @@ -72,5 +72,6 @@ int handle_loglevel(char *mesh_iface, int argc, char **argv); int handle_sys_setting(char *mesh_iface, int setting, int argc, char **argv); int handle_gw_setting(char *mesh_iface, int argc, char **argv); int check_mesh_iface(char *mesh_iface); +int check_mesh_iface_ownership(char *mesh_iface, char *hard_iface);
#endif
On Wednesday 12 March 2014 17:04:48 Simon Wunderlich wrote:
From: Simon Wunderlich simon@open-mesh.com
This patch adds batctl support for the recently introduced mesh wide multi interface optimization in batman-adv.
Signed-off-by: Simon Wunderlich simon@open-mesh.com
Changes to PATCHv1:
- check if the supplied interface actually belongs to the interface
- add README and manpage descriptions
README | 25 +++++++++++++++++++++++++ debug.c | 32 ++++++++++++++++++++++++++------ man/batctl.8 | 4 +++- sys.c | 28 ++++++++++++++++++++++++++++ sys.h | 1 + 5 files changed, 83 insertions(+), 7 deletions(-)
Applied in revision 62f87ce.
Thanks, Marek
On Wednesday 12 March 2014 17:04:47 Simon Wunderlich wrote:
From: Simon Wunderlich simon@open-mesh.com
Check if the interface supplied by -m (or bat0 by default) is actually a batman interface. The check is performed by testing if the sysfs path is available.
This change is required since debugfs now contains originator tables per hard interface. This might be confusing for users as batctl -m eth0 o will now (accidently) print these tables without eth0 beeing a batman interface, assuming eth0 is a hard interface used by batman-adv.
Some reordering of commands were required to first allow commands which don't depend on a (correctly set up) mesh interface, like bisect or interface.
Signed-off-by: Simon Wunderlich simon@open-mesh.com
Changes to PATCHv2:
- fix VLAN check, this is now similar to the sysfs handling code
main.c | 32 +++++++++++++++++--------------- sys.c | 30 ++++++++++++++++++++++++++++++ sys.h | 1 + 3 files changed, 48 insertions(+), 15 deletions(-)
Applied in revision da65d62.
Thanks, Marek
b.a.t.m.a.n@lists.open-mesh.org