Repository : ssh://git@open-mesh.org/batctl
On branch : master
>---------------------------------------------------------------
commit de4b7a2e716b414fa7f39121addb28f332401b1f
Author: Sven Eckelmann <sven(a)narfation.org>
Date: Sun Oct 14 22:20:52 2012 +0200
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.
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
Signed-off-by: Marek Lindner <lindner_marek(a)yahoo.de>
>---------------------------------------------------------------
de4b7a2e716b414fa7f39121addb28f332401b1f
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(-)
diff --git a/README b/README
index 22ad616..ad4fc44 100644
--- a/README
+++ b/README
@@ -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:
diff --git a/debug.h b/debug.h
index 4e935cb..5bd7f3e 100644
--- a/debug.h
+++ b/debug.h
@@ -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 {
diff --git a/functions.c b/functions.c
index 1cde235..7875716 100644
--- a/functions.c
+++ b/functions.c
@@ -37,6 +37,7 @@
#include "bat-hosts.h"
#include "sys.h"
#include "debug.h"
+#include "debugfs.h"
static struct timeval start_time;
static char *host_name;
@@ -320,3 +321,84 @@ out:
close(fd);
return res;
}
+
+struct ether_addr *translate_mac(char *mesh_iface, struct ether_addr *mac)
+{
+ enum {
+ tg_start,
+ tg_mac,
+ tg_via,
+ tg_originator,
+ } pos;
+ char full_path[MAX_PATH+1];
+ char *debugfs_mnt;
+ static struct ether_addr in_mac;
+ struct ether_addr *mac_result, *mac_tmp;
+ FILE *f = NULL;
+ size_t len = 0;
+ char *line = NULL;
+ char *input, *saveptr, *token;
+ int line_invalid;
+
+ memcpy(&in_mac, mac, sizeof(in_mac));
+ mac_result = &in_mac;
+
+ debugfs_mnt = debugfs_mount(NULL);
+ if (!debugfs_mnt)
+ goto out;
+
+ debugfs_make_path(DEBUG_BATIF_PATH_FMT "/" DEBUG_TRANSTABLE_GLOBAL, mesh_iface, full_path, sizeof(full_path));
+
+ f = fopen(full_path, "r");
+ if (!f)
+ goto out;
+
+ while (getline(&line, &len, f) != -1) {
+ line_invalid = 0;
+ pos = tg_start;
+ input = line;
+
+ while ((token = strtok_r(input, " \t", &saveptr))) {
+ input = NULL;
+
+ switch (pos) {
+ case tg_start:
+ if (strcmp(token, "*") != 0)
+ line_invalid = 1;
+ else
+ pos = tg_mac;
+ break;
+ case tg_mac:
+ mac_tmp = ether_aton(token);
+ if (!mac_tmp || memcmp(mac_tmp, &in_mac,
+ sizeof(in_mac)) != 0)
+ line_invalid = 1;
+ else
+ pos = tg_via;
+ break;
+ case tg_via:
+ if (strcmp(token, "via") == 0)
+ pos = tg_originator;
+ break;
+ case tg_originator:
+ mac_tmp = ether_aton(token);
+ if (!mac_tmp) {
+ line_invalid = 1;
+ } else {
+ mac_result = mac_tmp;
+ goto out;
+ }
+ break;
+ }
+
+ if (line_invalid)
+ break;
+ }
+ }
+
+out:
+ if (f)
+ fclose(f);
+ free(line);
+ return mac_result;
+}
diff --git a/functions.h b/functions.h
index 92d6ae5..a59bb24 100644
--- a/functions.h
+++ b/functions.h
@@ -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;
diff --git a/man/batctl.8 b/man/batctl.8
index fdc788e..369be20 100644
--- a/man/batctl.8
+++ b/man/batctl.8
@@ -212,17 +212,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
diff --git a/ping.c b/ping.c
index ce8f457..02132f4 100644
--- a/ping.c
+++ b/ping.c
@@ -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);
diff --git a/traceroute.c b/traceroute.c
index 75ff2b3..4e42419 100644
--- a/traceroute.c
+++ b/traceroute.c
@@ -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);
Repository : ssh://git@open-mesh.org/batman-adv
On branch : master
>---------------------------------------------------------------
commit 516b20dab54404a199963fca9ac43e152cd856a6
Author: Antonio Quartulli <ordex(a)autistici.org>
Date: Tue Oct 16 08:16:10 2012 +0200
batman-adv: fix kernel-doc for batadv_dat_entry
In the batadv_dat_entry structure last_update was lonely and was missing its own
kernel-doc. This patch adds it.
This was introduced with ("batman-adv: Distributed ARP Table - implement local
storage")
Reported-by: Marek Lindner <lindner_marek(a)yahoo.de>
Signed-off-by: Antonio Quartulli <ordex(a)autistici.org>
Signed-off-by: Marek Lindner <lindner_marek(a)yahoo.de>
>---------------------------------------------------------------
516b20dab54404a199963fca9ac43e152cd856a6
types.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/types.h b/types.h
index 1519ae3..8a5d84c 100644
--- a/types.h
+++ b/types.h
@@ -484,6 +484,7 @@ struct batadv_algo_ops {
* is used to stored ARP entries needed for the global DAT cache
* @ip: the IPv4 corresponding to this DAT/ARP entry
* @mac_addr: the MAC address associated to the stored IPv4
+ * @last_update: time in jiffies when this entry was refreshed last time
* @hash_entry: hlist node for batadv_priv_dat::hash
* @refcount: number of contexts the object is used
* @rcu: struct used for freeing in an RCU-safe manner
Repository : ssh://git@open-mesh.org/batman-adv
On branch : master
>---------------------------------------------------------------
commit e65e75c756d325d3b8a6af51d07cbed236c5ad96
Author: Antonio Quartulli <ordex(a)autistici.org>
Date: Tue Oct 16 08:12:33 2012 +0200
batman-adv: fix ifdef for DAT in types.h
It is better to fully enclose the batadv_priv_dat struct in the #ifdef/endif
block instead of the enclosing only the field which would not compile while DAT
is off.
This was introduced with ("batman-adv: Distributed ARP Table - add compile
option")
Reported-by: Marek Lindner <lindner_marek(a)yahoo.de>
Signed-off-by: Antonio Quartulli <ordex(a)autistici.org>
Signed-off-by: Marek Lindner <lindner_marek(a)yahoo.de>
>---------------------------------------------------------------
e65e75c756d325d3b8a6af51d07cbed236c5ad96
types.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/types.h b/types.h
index b1c261b..1519ae3 100644
--- a/types.h
+++ b/types.h
@@ -255,13 +255,13 @@ struct batadv_priv_vis {
* @hash: hashtable representing the local ARP cache
* @work: work queue callback item for cache purging
*/
-struct batadv_priv_dat {
#ifdef CONFIG_BATMAN_ADV_DAT
+struct batadv_priv_dat {
batadv_dat_addr_t addr;
-#endif
struct batadv_hashtable *hash;
struct delayed_work work;
};
+#endif
struct batadv_priv {
atomic_t mesh_state;
The following commit has been merged in the merge/master branch:
commit dec7a30b71cfba8fb8323cc1ed8ea7a49daead50
Author: Linus Lüssing <linus.luessing(a)web.de>
Date: Fri Sep 14 00:40:54 2012 +0000
batman-adv: make batadv_test_bit() return 0 or 1 only
On some architectures test_bit() can return other values than 0 or 1:
With a generic x86 OpenWrt image in a kvm setup (batadv_)test_bit()
frequently returns -1 for me, leading to batadv_iv_ogm_update_seqnos()
wrongly signaling a protected seqno window.
This patch tries to fix this issue by making batadv_test_bit() return 0
or 1 only.
Signed-off-by: Linus Lüssing <linus.luessing(a)web.de>
Acked-by: Sven Eckelmann <sven(a)narfation.org>
Signed-off-by: Antonio Quartulli <ordex(a)autistici.org>
Signed-off-by: David S. Miller <davem(a)davemloft.net>
diff --git a/net/batman-adv/bitarray.h b/net/batman-adv/bitarray.h
index a081ce1..cebaae7 100644
--- a/net/batman-adv/bitarray.h
+++ b/net/batman-adv/bitarray.h
@@ -20,8 +20,8 @@
#ifndef _NET_BATMAN_ADV_BITARRAY_H_
#define _NET_BATMAN_ADV_BITARRAY_H_
-/* returns true if the corresponding bit in the given seq_bits indicates true
- * and curr_seqno is within range of last_seqno
+/* Returns 1 if the corresponding bit in the given seq_bits indicates true
+ * and curr_seqno is within range of last_seqno. Otherwise returns 0.
*/
static inline int batadv_test_bit(const unsigned long *seq_bits,
uint32_t last_seqno, uint32_t curr_seqno)
@@ -32,7 +32,7 @@ static inline int batadv_test_bit(const unsigned long *seq_bits,
if (diff < 0 || diff >= BATADV_TQ_LOCAL_WINDOW_SIZE)
return 0;
else
- return test_bit(diff, seq_bits);
+ return test_bit(diff, seq_bits) != 0;
}
/* turn corresponding bit on, so we can remember that we got the packet */
--
linux integration