[B.A.T.M.A.N.] [PATCH] batman-adv: dirty hack to recompute mac_len in the rx path

2012-10-14 Thread Simon Wunderlich
It is possible that the mac_len is not properly exported because of
strange device configuration (this behaviour has been observed when
using batman-adv on top of a vlan interface). Therefore it is needed to
explicitly recompute it at the very beginning of the rx path.

This is done by appending the recompute function to the skb_share_mac()
function, hence the dirty hack in the subject. We expect this problem to
be fixed in linux 3.8 and above.

Reported-by: Antonio Quartulli or...@autistici.org
Signed-off-by: Simon Wunderlich s...@hrz.tu-chemnitz.de
---

this is a rewrite of Antonios patch
batman-adv: recompute mac_len at the beginning of the rx path. It is
intended to fix the issue for out-of-kernel releases, without hurting
the in-kernel code too much. Obviously, this patch won't go upstream
into the kernel.

This version includes Svens more sane version, and also has implements
skb_reset_mac_len() for kernels prior to 3.0.
---
 compat.h |   24 
 1 file changed, 24 insertions(+)

diff --git a/compat.h b/compat.h
index 14969e0..47223f5 100644
--- a/compat.h
+++ b/compat.h
@@ -137,6 +137,11 @@ void batadv_free_rcu_neigh_node(struct rcu_head *rcu);
 void batadv_free_rcu_tt_local_entry(struct rcu_head *rcu);
 void batadv_free_rcu_backbone_gw(struct rcu_head *rcu);
 
+static inline void skb_reset_mac_len(struct sk_buff *skb)
+{
+   skb-mac_len = skb-network_header - skb-mac_header;
+}
+
 #endif /*  KERNEL_VERSION(3, 0, 0) */
 
 
@@ -159,4 +164,23 @@ static inline void eth_hw_addr_random(struct net_device 
*dev)
 
 #endif /*  KERNEL_VERSION(3, 5, 0) */
 
+#if LINUX_VERSION_CODE  KERNEL_VERSION(3, 8, 0)
+
+/* hack for not correctly set mac_len. This may happen for some special
+ * configurations like batman-adv on VLANs.
+ *
+ * This is pretty dirty, but we only use skb_share_check() in main.c right
+ * before mac_len is checked, and the recomputation shouldn't hurt too much.
+ */
+#define skb_share_check(skb, b) \
+   ({ \
+   struct sk_buff *_t_skb; \
+   _t_skb = skb_share_check(skb, b); \
+   if (_t_skb) \
+   skb_reset_mac_len(_t_skb); \
+   _t_skb; \
+   })
+
+#endif /*  KERNEL_VERSION(3, 8, 0) */
+
 #endif /* _NET_BATMAN_ADV_COMPAT_H_ */
-- 
1.7.10



Re: [B.A.T.M.A.N.] [PATCH] batman-adv: Remove instant overwritten variable initialization

2012-10-14 Thread Marek Lindner
On Sunday, October 07, 2012 18:02:22 Sven Eckelmann wrote:
 Signed-off-by: Sven Eckelmann s...@narfation.org
 ---
  routing.c   |2 +-
  sysfs.c |2 +-
  translation-table.c |   20 ++--
  3 files changed, 12 insertions(+), 12 deletions(-)

Applied in revision af5ec5c.

Thanks,
Marek


Re: [B.A.T.M.A.N.] [PATCH] batman-adv: Mark best gateway in transtable_global debugfs

2012-10-14 Thread Marek Lindner
On Sunday, October 07, 2012 19:34:15 Sven Eckelmann wrote:
 The transtable_global debug file can show multiple entries for a single
 client when multiple gateways exist. The chosen gateway isn't marked in
 the list and therefore the user cannot easily debug the situation when
 there is a problem with the currently used gateway.
 
 The best gateway is now marked with * and secondary gateways are marked
 with +.
 
 Signed-off-by: Sven Eckelmann s...@narfation.org
 ---
  translation-table.c |   80
 +++ 1 file changed, 56
 insertions(+), 24 deletions(-)

Applied in revision 1421221.

Thanks,
Marek


[B.A.T.M.A.N.] [PATCHv5 1/3] batctl: add support for the DAT local table

2012-10-14 Thread Antonio Quartulli
With the introduction of DAT in batman-adv, another table is now exported
through debugfs. This patch adds the possibility to print it

Signed-off-by: Antonio Quartulli or...@autistici.org
---

v5:
- long option renamed from 'datcache' to dat_cache'


 README   | 18 ++
 debug.c  |  5 +
 debug.h  |  1 +
 functions.c  |  1 +
 man/batctl.8 |  3 +++
 5 files changed, 28 insertions(+)

diff --git a/README b/README
index 03d36c4..5e58452 100644
--- a/README
+++ b/README
@@ -408,6 +408,24 @@ where:
 
 If any of the flags is not enabled, a '.' will substitute its symbol.
 
+batctl dat_cache
+=
+
+display the local D.A.T. cache
+
+Usage batctl dat_cache|dc
+
+Example:
+
+Distributed ARP Table (bat0):
+  IPv4 MAC   last-seen
+ * 172.100.0.1 b6:9b:d0:ea:b1:13  0:00
+
+where:
+- IPv4 is the IP address of a client in the mesh network
+- MAC is the MAC address associated to that IP
+- last-seen is the amount of time since last refresh of this entry
+
 batctl vis_mode
 =
 
diff --git a/debug.c b/debug.c
index 9b5146f..a230a12 100644
--- a/debug.c
+++ b/debug.c
@@ -64,6 +64,11 @@ const struct debug_table_data 
batctl_debug_tables[BATCTL_TABLE_NUM] = {
.opt_short = bbt,
.debugfs_name = bla_backbone_table,
},
+   {
+   .opt_long = dat_cache,
+   .opt_short = dc,
+   .debugfs_name = dat_cache,
+   },
 };
 
 void debug_table_usage(int debug_table)
diff --git a/debug.h b/debug.h
index 6068c2c..4e935cb 100644
--- a/debug.h
+++ b/debug.h
@@ -31,6 +31,7 @@ enum batctl_debug_tables {
BATCTL_TABLE_TRANSGLOBAL,
BATCTL_TABLE_BLA_CLAIMS,
BATCTL_TABLE_BLA_BACKBONES,
+   BATCTL_TABLE_DAT,
BATCTL_TABLE_NUM,
 };
 
diff --git a/functions.c b/functions.c
index e095fd0..0d88137 100644
--- a/functions.c
+++ b/functions.c
@@ -48,6 +48,7 @@ const char *fs_compile_out_param[] = {
batctl_settings[BATCTL_SETTINGS_BLA].sysfs_name,
batctl_debug_tables[BATCTL_TABLE_BLA_CLAIMS].debugfs_name,
batctl_debug_tables[BATCTL_TABLE_BLA_BACKBONES].debugfs_name,
+   batctl_debug_tables[BATCTL_TABLE_DAT].debugfs_name,
NULL,
 };
 
diff --git a/man/batctl.8 b/man/batctl.8
index ab02e9a..310b43f 100644
--- a/man/batctl.8
+++ b/man/batctl.8
@@ -187,6 +187,9 @@ List of debug tables:
 .RS 10
 \- backbonetable|bbt (compile time option)
 .RE
+.RS 10
+\- datcache|dc (compile time option)
+.RE
 .RE
 .br
 .IP \fBstatistics\fP|\fBs\fP
-- 
1.7.12.3



[B.A.T.M.A.N.] [PATCHv5 2/3] batctl: add support for the DAT log level

2012-10-14 Thread Antonio Quartulli
Signed-off-by: Antonio Quartulli or...@autistici.org
---

v5:
- noop.

 README   | 1 +
 man/batctl.8 | 7 ---
 sys.c| 7 ++-
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/README b/README
index 5e58452..0958fcb 100644
--- a/README
+++ b/README
@@ -342,6 +342,7 @@ $  batctl loglevel
 [ ] messages related to route added / changed / deleted (routes)
 [ ] messages related to translation table operations (tt)
 [ ] messages related to bridge loop avoidance (bla)
+[ ] messages related to arp snooping and distributetd arp table (dat)
 
 batctl aggregation
 ==
diff --git a/man/batctl.8 b/man/batctl.8
index 310b43f..250e461 100644
--- a/man/batctl.8
+++ b/man/batctl.8
@@ -85,9 +85,10 @@ disable fragmentation.
 If no parameter is given the current log level settings are displayed 
otherwise the parameter(s) is/are used to set the log
 level. Level 'none' disables all verbose logging. Level 'batman' enables 
messages related to routing / flooding / broadcasting.
 Level 'routes' enables messages related to routes being added / changed / 
deleted. Level 'tt' enables messages related to
-translation table operations. Level 'bla' enables messages related to the 
bridge loop avoidance. Level 'all' enables all
-messages. The messages are sent to the batman-adv debug log. Use \fBbatctl 
log\fP to retrieve it. Make sure to have debugging
-output enabled when compiling the module otherwise the output as well as the 
loglevel options won't be available.
+translation table operations. Level 'bla' enables messages related to the 
bridge loop avoidance. Level 'dat' enables
+messages related to ARP snooping and the Distributed Arp Table. Level 'all' 
enables all messages. The messages are sent
+to the batman-adv debug log. Use \fBbatctl log\fP to retrieve it. Make sure to 
have debugging output enabled when compiling
+the module otherwise the output as well as the loglevel options won't be 
available.
 .br
 .IP \fBlog\fP|\fBl\fP [\fB\-n\fP]\fP
 batctl will read the batman-adv debug log which has to be compiled into the 
kernel module. If \-n is given batctl will not
diff --git a/sys.c b/sys.c
index 6f94483..815ff88 100644
--- a/sys.c
+++ b/sys.c
@@ -258,6 +258,7 @@ static void log_level_usage(void)
printf( \t routes  Messages related to route added / changed / 
deleted\n);
printf( \t tt  Messages related to translation table 
operations\n);
printf( \t bla Messages related to bridge loop avoidance\n);
+   printf( \t dat Messages related to arp snooping and distributed 
arp table\n);
 }
 
 int handle_loglevel(char *mesh_iface, int argc, char **argv)
@@ -288,7 +289,7 @@ int handle_loglevel(char *mesh_iface, int argc, char **argv)
log_level = 0;
break;
} else if (strcmp(argv[i], all) == 0) {
-   log_level = 15;
+   log_level = 31;
break;
} else if (strcmp(argv[i], batman) == 0)
log_level |= BIT(0);
@@ -298,6 +299,8 @@ int handle_loglevel(char *mesh_iface, int argc, char **argv)
log_level |= BIT(2);
else if (strcmp(argv[i], bla) == 0)
log_level |= BIT(3);
+   else if (strcmp(argv[i], dat) == 0)
+   log_level |= BIT(4);
else {
log_level_usage();
goto out;
@@ -327,6 +330,8 @@ int handle_loglevel(char *mesh_iface, int argc, char **argv)
   messages related to translation table operations, tt);
printf([%c] %s (%s)\n, (log_level  BIT(3)) ? 'x' : ' ',
   messages related to bridge loop avoidance, bla);
+   printf([%c] %s (%s)\n, (log_level  BIT(4)) ? 'x' : ' ',
+  messages related to arp snooping and distributed arp table, 
dat);
 
 out:
free(path_buff);
-- 
1.7.12.3



[B.A.T.M.A.N.] [PATCHv5 3/3] batctl: add DAT runtime switch support

2012-10-14 Thread Antonio Quartulli
Signed-off-by: Antonio Quartulli or...@autistici.org
---

v5:
- noop.

 functions.c  | 1 +
 man/batctl.8 | 4 
 sys.c| 6 ++
 sys.h| 1 +
 4 files changed, 12 insertions(+)

diff --git a/functions.c b/functions.c
index 0d88137..1cde235 100644
--- a/functions.c
+++ b/functions.c
@@ -46,6 +46,7 @@ const char *fs_compile_out_param[] = {
SYS_LOG,
SYS_LOG_LEVEL,
batctl_settings[BATCTL_SETTINGS_BLA].sysfs_name,
+   batctl_settings[BATCTL_SETTINGS_DAT].sysfs_name,
batctl_debug_tables[BATCTL_TABLE_BLA_CLAIMS].debugfs_name,
batctl_debug_tables[BATCTL_TABLE_BLA_BACKBONES].debugfs_name,
batctl_debug_tables[BATCTL_TABLE_DAT].debugfs_name,
diff --git a/man/batctl.8 b/man/batctl.8
index 250e461..4359411 100644
--- a/man/batctl.8
+++ b/man/batctl.8
@@ -66,6 +66,10 @@ If no parameter is given the current bridge loop avoidance 
setting is displayed.
 or disable the bridge loop avoidance. Bridge loop avoidance support has to be 
enabled when compiling the module otherwise
 this option won't be available.
 .br
+.IP \fBdistributed_arp_table\fP|\fBdat\fP [\fB0\fP|\fB1\fP]
+If no parameter is given the current distributed arp table setting is 
displayed. Otherwise the parameter is used to
+enable or disable the distributed arp table.
+.br
 .IP \fBvis_mode|vm\fP [\fBclient|server\fP]\fP
 If no parameter is given the current vis mode is displayed otherwise the 
parameter is used to set the vis mode.
 .br
diff --git a/sys.c b/sys.c
index 815ff88..3d5e129 100644
--- a/sys.c
+++ b/sys.c
@@ -69,6 +69,12 @@ const struct settings_data 
batctl_settings[BATCTL_SETTINGS_NUM] = {
.params = sysfs_param_enable,
},
{
+   .opt_long = distributed_arp_table,
+   .opt_short = dat,
+   .sysfs_name = distributed_arp_table,
+   .params = sysfs_param_enable,
+   },
+   {
.opt_long = vis_mode,
.opt_short = vm,
.sysfs_name = vis_mode,
diff --git a/sys.h b/sys.h
index 1fc473e..40b64b1 100644
--- a/sys.h
+++ b/sys.h
@@ -35,6 +35,7 @@ enum batctl_settings_list {
BATCTL_SETTINGS_ORIG_INTERVAL,
BATCTL_SETTINGS_AP_ISOLATION,
BATCTL_SETTINGS_BLA,
+   BATCTL_SETTINGS_DAT,
BATCTL_SETTINGS_VIS_MODE,
BATCTL_SETTINGS_AGGREGATION,
BATCTL_SETTINGS_BONDING,
-- 
1.7.12.3



Re: [B.A.T.M.A.N.] [PATCH] batman-adv: fix DAT packet counting

2012-10-14 Thread Marek Lindner
On Tuesday, October 09, 2012 21:00:11 Antonio Quartulli wrote:
 DAT packets must be counted before any batadv_dat_snoop_incoming_*
 invocation otherwise the code flow can jump the counters increment at all
 
 Signed-off-by: Antonio Quartulli or...@autistici.org
 ---
  routing.c | 8 
  1 file changed, 4 insertions(+), 4 deletions(-)

Applied in revision 2b105ca.

Thanks,
Marek


Re: [B.A.T.M.A.N.] [PATCH] batman-adv: enable fast client detection using unicast_4addr packets

2012-10-14 Thread Marek Lindner
On Tuesday, October 09, 2012 21:04:47 Antonio Quartulli wrote:
 @@ -1061,9 +1063,12 @@ int batadv_recv_unicast_packet(struct sk_buff *skb,
  
 /* packet for me */
 if (batadv_is_my_mac(unicast_packet-dest)) {
 -   if (is4addr)
 +   if (is4addr) {
 batadv_dat_inc_counter(bat_priv,
unicast_4addr_packet-subtyp
 e); +   orig_addr = unicast_4addr_packet-src;
 +   orig_node = batadv_orig_hash_find(bat_priv,
 orig_addr); +   }

Last time I checked batadv_orig_hash_find() increased a refcounter ...

Cheers,
Marek


Re: [B.A.T.M.A.N.] [PATCHv5 1/3] batctl: add support for the DAT local table

2012-10-14 Thread Marek Lindner
On Sunday, October 14, 2012 22:54:31 Antonio Quartulli wrote:
 With the introduction of DAT in batman-adv, another table is now exported
 through debugfs. This patch adds the possibility to print it
 
 Signed-off-by: Antonio Quartulli or...@autistici.org
 ---
 
 v5:
 - long option renamed from 'datcache' to dat_cache'
 
 
  README   | 18 ++
  debug.c  |  5 +
  debug.h  |  1 +
  functions.c  |  1 +
  man/batctl.8 |  3 +++
  5 files changed, 28 insertions(+)

Applied in revision 167c37a.

Thanks,
Marek


[B.A.T.M.A.N.] [PATCHv2] batman-adv: enable fast client detection using unicast_4addr packets

2012-10-14 Thread Antonio Quartulli
The early client detection mechanism can be extended to find new clients by
means of unicast_4addr packets.

The unicast_4addr packet contains as well as the broadcast packet (which is
currently used in this mechanism) the address of the originating node and can
therefore be used to install new entries in the Global Translation Table

Signed-off-by: Antonio Quartulli or...@autistici.org
---

v2:
- fixed refcounting

 routing.c | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/routing.c b/routing.c
index 96375c5..2615f91 100644
--- a/routing.c
+++ b/routing.c
@@ -1042,6 +1042,8 @@ int batadv_recv_unicast_packet(struct sk_buff *skb,
struct batadv_priv *bat_priv = netdev_priv(recv_if-soft_iface);
struct batadv_unicast_packet *unicast_packet;
struct batadv_unicast_4addr_packet *unicast_4addr_packet;
+   uint8_t *orig_addr;
+   struct batadv_orig_node *orig_node = NULL;
int hdr_size = sizeof(*unicast_packet);
bool is4addr;
 
@@ -1061,9 +1063,12 @@ int batadv_recv_unicast_packet(struct sk_buff *skb,
 
/* packet for me */
if (batadv_is_my_mac(unicast_packet-dest)) {
-   if (is4addr)
+   if (is4addr) {
batadv_dat_inc_counter(bat_priv,
   unicast_4addr_packet-subtype);
+   orig_addr = unicast_4addr_packet-src;
+   orig_node = batadv_orig_hash_find(bat_priv, orig_addr);
+   }
 
if (batadv_dat_snoop_incoming_arp_request(bat_priv, skb,
  hdr_size))
@@ -1073,7 +1078,9 @@ int batadv_recv_unicast_packet(struct sk_buff *skb,
goto rx_success;
 
batadv_interface_rx(recv_if-soft_iface, skb, recv_if, hdr_size,
-   NULL);
+   orig_node);
+   if (orig_node)
+   batadv_orig_node_free_ref(orig_node);
 
 rx_success:
return NET_RX_SUCCESS;
-- 
1.7.12.3



Re: [B.A.T.M.A.N.] [PATCHv5 2/3] batctl: add support for the DAT log level

2012-10-14 Thread Marek Lindner
On Sunday, October 14, 2012 22:54:32 Antonio Quartulli wrote:
 Signed-off-by: Antonio Quartulli or...@autistici.org
 ---
 
 v5:
 - noop.
 
  README   | 1 +
  man/batctl.8 | 7 ---
  sys.c| 7 ++-
  3 files changed, 11 insertions(+), 4 deletions(-)

Applied in revision ac27265.

Thanks,
Marek


Re: [B.A.T.M.A.N.] [PATCHv5 3/3] batctl: add DAT runtime switch support

2012-10-14 Thread Marek Lindner
On Sunday, October 14, 2012 22:54:33 Antonio Quartulli wrote:
 Signed-off-by: Antonio Quartulli or...@autistici.org
 ---
 
 v5:
 - noop.
 
  functions.c  | 1 +
  man/batctl.8 | 4 
  sys.c| 6 ++
  sys.h| 1 +
  4 files changed, 12 insertions(+)

Applied in revision f395fb7.

Thanks,
Marek


[B.A.T.M.A.N.] [PATCHv3] batman-adv: enable fast client detection using unicast_4addr packets

2012-10-14 Thread Antonio Quartulli
The early client detection mechanism can be extended to find new clients by
means of unicast_4addr packets.

The unicast_4addr packet contains as well as the broadcast packet (which is
currently used in this mechanism) the address of the originating node and can
therefore be used to install new entries in the Global Translation Table

Signed-off-by: Antonio Quartulli or...@autistici.org
---

v3:
- fixed refcounting (again)

 routing.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/routing.c b/routing.c
index 96375c5..c2c4de3 100644
--- a/routing.c
+++ b/routing.c
@@ -1042,6 +1042,8 @@ int batadv_recv_unicast_packet(struct sk_buff *skb,
struct batadv_priv *bat_priv = netdev_priv(recv_if-soft_iface);
struct batadv_unicast_packet *unicast_packet;
struct batadv_unicast_4addr_packet *unicast_4addr_packet;
+   uint8_t *orig_addr;
+   struct batadv_orig_node *orig_node = NULL;
int hdr_size = sizeof(*unicast_packet);
bool is4addr;
 
@@ -1061,9 +1063,12 @@ int batadv_recv_unicast_packet(struct sk_buff *skb,
 
/* packet for me */
if (batadv_is_my_mac(unicast_packet-dest)) {
-   if (is4addr)
+   if (is4addr) {
batadv_dat_inc_counter(bat_priv,
   unicast_4addr_packet-subtype);
+   orig_addr = unicast_4addr_packet-src;
+   orig_node = batadv_orig_hash_find(bat_priv, orig_addr);
+   }
 
if (batadv_dat_snoop_incoming_arp_request(bat_priv, skb,
  hdr_size))
@@ -1073,9 +1078,12 @@ int batadv_recv_unicast_packet(struct sk_buff *skb,
goto rx_success;
 
batadv_interface_rx(recv_if-soft_iface, skb, recv_if, hdr_size,
-   NULL);
+   orig_node);
 
 rx_success:
+   if (orig_node)
+   batadv_orig_node_free_ref(orig_node);
+
return NET_RX_SUCCESS;
}
 
-- 
1.7.12.3



Re: [B.A.T.M.A.N.] [PATCHv3] batman-adv: enable fast client detection using unicast_4addr packets

2012-10-14 Thread Marek Lindner
On Sunday, October 14, 2012 23:19:19 Antonio Quartulli wrote:
 The early client detection mechanism can be extended to find new clients
 by means of unicast_4addr packets.
 
 The unicast_4addr packet contains as well as the broadcast packet (which is
 currently used in this mechanism) the address of the originating node and
 can therefore be used to install new entries in the Global Translation
 Table
 
 Signed-off-by: Antonio Quartulli or...@autistici.org
 ---
 
 v3:
 - fixed refcounting (again)
 
  routing.c | 12 ++--
  1 file changed, 10 insertions(+), 2 deletions(-)

Applied in revision d7cc20f.

Thanks,
Marek


Re: [B.A.T.M.A.N.] [PATCH] batman-adv: dirty hack to recompute mac_len in the rx path

2012-10-14 Thread Marek Lindner
On Sunday, October 14, 2012 20:46:57 Simon Wunderlich wrote:
 It is possible that the mac_len is not properly exported because of
 strange device configuration (this behaviour has been observed when
 using batman-adv on top of a vlan interface). Therefore it is needed to
 explicitly recompute it at the very beginning of the rx path.
 
 This is done by appending the recompute function to the skb_share_mac()
 function, hence the dirty hack in the subject. We expect this problem to
 be fixed in linux 3.8 and above.
 
 Reported-by: Antonio Quartulli or...@autistici.org
 Signed-off-by: Simon Wunderlich s...@hrz.tu-chemnitz.de
 ---
 
 this is a rewrite of Antonios patch
 batman-adv: recompute mac_len at the beginning of the rx path. It is
 intended to fix the issue for out-of-kernel releases, without hurting
 the in-kernel code too much. Obviously, this patch won't go upstream
 into the kernel.
 
 This version includes Svens more sane version, and also has implements
 skb_reset_mac_len() for kernels prior to 3.0.
 ---
  compat.h |   24 
  1 file changed, 24 insertions(+)

Applied in revision a6ad857.

Thanks,
Marek


[B.A.T.M.A.N.] [PATCH 1/2] batman-adv: support array of debugfs general attributes

2012-10-14 Thread Antonio Quartulli
This patch adds support for an array of debugfs general (not soft_iface
specific) attributes. With this change it will be possible to add more general
attributes by simply appending them to the array without touching the rest of
the code.

Signed-off-by: Antonio Quartulli or...@autistici.org
---
 debugfs.c | 34 +-
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/debugfs.c b/debugfs.c
index 61c7d4d..43e0fde 100644
--- a/debugfs.c
+++ b/debugfs.c
@@ -328,7 +328,17 @@ struct batadv_debuginfo batadv_debuginfo_##_name = {   
\
}   \
 };
 
+/* the following attributes are general and therefore they will be directly
+ * placed in the BATADV_DEBUGFS_SUBDIR subdirectory of debugfs
+ */
 static BATADV_DEBUGINFO(routing_algos, S_IRUGO, batadv_algorithms_open);
+
+static struct batadv_debuginfo *batadv_general_debuginfos[] = {
+   batadv_debuginfo_routing_algos,
+   NULL,
+};
+
+/* The following attributes are per soft interface */
 static BATADV_DEBUGINFO(originators, S_IRUGO, batadv_originators_open);
 static BATADV_DEBUGINFO(gateways, S_IRUGO, batadv_gateways_open);
 static BATADV_DEBUGINFO(transtable_global, S_IRUGO,
@@ -363,7 +373,7 @@ static struct batadv_debuginfo *batadv_mesh_debuginfos[] = {
 
 void batadv_debugfs_init(void)
 {
-   struct batadv_debuginfo *bat_debug;
+   struct batadv_debuginfo **bat_debug;
struct dentry *file;
 
batadv_debugfs = debugfs_create_dir(BATADV_DEBUGFS_SUBDIR, NULL);
@@ -371,17 +381,23 @@ void batadv_debugfs_init(void)
batadv_debugfs = NULL;
 
if (!batadv_debugfs)
-   goto out;
+   goto err;
 
-   bat_debug = batadv_debuginfo_routing_algos;
-   file = debugfs_create_file(bat_debug-attr.name,
-  S_IFREG | bat_debug-attr.mode,
-  batadv_debugfs, NULL, bat_debug-fops);
-   if (!file)
-   pr_err(Can't add debugfs file: %s\n, bat_debug-attr.name);
+   for (bat_debug = batadv_general_debuginfos; *bat_debug; ++bat_debug) {
+   file = debugfs_create_file(((*bat_debug)-attr).name,
+  S_IFREG | ((*bat_debug)-attr).mode,
+  batadv_debugfs, NULL,
+  (*bat_debug)-fops);
+   if (!file) {
+   pr_err(Can't add general debugfs file: %s\n,
+  ((*bat_debug)-attr).name);
+   goto err;
+   }
+   }
 
-out:
return;
+err:
+   debugfs_remove_recursive(batadv_debugfs);
 }
 
 void batadv_debugfs_destroy(void)
-- 
1.7.12.3



Re: [B.A.T.M.A.N.] [PATCH 2/2] batman-adv: export compatibility version via debugfs

2012-10-14 Thread Antonio Quartulli
On Sun, Oct 14, 2012 at 10:03:01PM +0200, Antonio Quartulli wrote:
 Different versions of the batman-adv module may use the same compatibility
 version, but this is not understandable at runtime (the only way is to parse 
 the
 kernel log and fetch the batman-adv advertisement message on loading). The 
 user
 may want to know whether two nodes using different versions can communicate or
 not. For this purpose the module has to export this value through debugfs.
 
 Reported-by: Moritz Warning moritzwarn...@web.de
 Signed-off-by: Antonio Quartulli or...@autistici.org

2/2 intended to be v2 of a patch with the same name sent some days
ago over the ml. This PATCHv2 is based on the array of general attributes
introduced with 1/2.

Cheers,

-- 
Antonio Quartulli

..each of us alone is worth nothing..
Ernesto Che Guevara


pgpD0k0075Vdu.pgp
Description: PGP signature


[B.A.T.M.A.N.] [PATCHv4 1/4] batctl: Translate client mac to originator mac for ping/traceroute

2012-10-14 Thread Sven Eckelmann
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 s...@narfation.org
---
rebased on DAT

 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..04a6e66 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 

[B.A.T.M.A.N.] [PATCHv4 2/4] batctl: Allow to use IPv4 addresses for ping/traceroute

2012-10-14 Thread Sven Eckelmann
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.

Signed-off-by: Sven Eckelmann s...@narfation.org
---
rebased on DAT

 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(-)

diff --git a/README b/README
index 04a6e66..cefcf24 100644
--- a/README
+++ b/README
@@ -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:
 
diff --git a/functions.c b/functions.c
index 7875716..a500444 100644
--- a/functions.c
+++ b/functions.c
@@ -22,6 +22,9 @@
 
 #define _GNU_SOURCE
 #include netinet/ether.h
+#include arpa/inet.h
+#include sys/socket.h
+#include netdb.h
 #include sys/types.h
 #include sys/stat.h
 #include unistd.h
@@ -402,3 +405,149 @@ out:
free(line);
return mac_result;
 }
+
+static uint32_t resolve_ipv4(const char *asc)
+{
+   int ret;
+   struct addrinfo hints;
+   struct addrinfo *res;
+   struct sockaddr_in *inet4;
+   uint32_t addr = 0;
+
+   memset(hints, 0, sizeof(hints));
+   hints.ai_family = AF_INET;
+   ret = getaddrinfo(asc, NULL, hints, res);
+   if (ret)
+   return 0;
+
+   if (res) {
+   inet4 = (struct sockaddr_in *)res-ai_addr;
+   addr = inet4-sin_addr.s_addr;
+   }
+
+   freeaddrinfo(res);
+   return addr;
+}
+
+static void request_arp(uint32_t ipv4_addr)
+{
+   struct sockaddr_in inet4;
+   int sock;
+   char t = 0;
+
+   memset(inet4, 0, sizeof(inet4));
+   sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+   if (sock  0)
+   return;
+
+   inet4.sin_family = AF_INET;
+   inet4.sin_port = htons(9);
+   inet4.sin_addr.s_addr = ipv4_addr;
+   sendto(sock, t, sizeof(t), 0, (const struct sockaddr *)inet4,
+  sizeof(inet4));
+   close(sock);
+}
+
+static struct ether_addr *resolve_mac_from_arp(uint32_t ipv4_addr)
+{
+   struct ether_addr mac_empty;
+   struct ether_addr *mac_result = NULL, *mac_tmp;
+   struct sockaddr_in inet4;
+   int ret;
+   FILE *f;
+   size_t len = 0;
+   char *line = NULL;
+   int skip_line = 1;
+   size_t column;
+   char *token, *input, *saveptr;
+   int line_invalid;
+
+   memset(mac_empty, 0, sizeof(mac_empty));
+
+   f = fopen(/proc/net/arp, r);
+   if (!f)
+   return NULL;
+
+   while (getline(line, len, f) != -1) {
+   if (skip_line) {
+   skip_line = 0;
+   continue;
+   }
+
+   line_invalid = 0;
+   column = 0;
+   input = line;
+   while ((token = strtok_r(input,  \t, saveptr))) {
+   input = NULL;
+
+   if (column == 0) {
+   ret = inet_pton(AF_INET, token, 
inet4.sin_addr);
+   if (ret != 1) {
+   line_invalid = 1;
+   break;
+   }
+   }
+
+   if (column == 3) {
+   mac_tmp = ether_aton(token);
+   if (!mac_tmp || memcmp(mac_tmp, mac_empty,
+  sizeof(mac_empty)) == 0) 
{
+   line_invalid = 1;
+   break;
+   }
+   }
+
+   column++;
+   }
+
+   if (column  4)
+   line_invalid = 1;
+
+   if (line_invalid)
+   continue;
+
+   if (ipv4_addr == inet4.sin_addr.s_addr) {
+   mac_result = mac_tmp;
+   break;
+   }
+   }
+
+   free(line);
+   fclose(f);
+   return mac_result;
+}
+
+static struct ether_addr *resolve_mac_from_ipv4(const char *asc)
+{
+   uint32_t ipv4_addr;
+   int retries = 5;
+   struct ether_addr *mac_result = NULL;
+
+   

[B.A.T.M.A.N.] [PATCHv4 3/4] batctl: Allow to skip header in debug table output

2012-10-14 Thread Sven Eckelmann
Signed-off-by: Sven Eckelmann s...@narfation.org
---
rebased on DAT

 debug.c  |   18 +++---
 debug.h  |1 +
 functions.c  |7 ++-
 functions.h  |3 ++-
 main.c   |2 +-
 man/batctl.8 |3 +++
 sys.c|   14 +++---
 7 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/debug.c b/debug.c
index a230a12..260448b 100644
--- a/debug.c
+++ b/debug.c
@@ -38,36 +38,43 @@ 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,
},
{
.opt_long = dat_cache,
.opt_short = dc,
.debugfs_name = dat_cache,
+   .header_lines = 2,
},
 };
 
@@ -78,6 +85,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)
@@ -93,7 +101,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);
@@ -126,6 +134,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);
@@ -152,7 +163,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)
@@ -190,6 +202,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;
 }
diff --git a/debug.h b/debug.h
index 5bd7f3e..3fa2830 100644
--- a/debug.h
+++ b/debug.h
@@ -40,6 +40,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];
diff --git a/functions.c b/functions.c
index a500444..57c2bba 100644
--- a/functions.c
+++ b/functions.c
@@ -162,7 +162,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;
@@ -171,6 +171,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)

[B.A.T.M.A.N.] [PATCHv4 4/4] batctl: Add filter option for debug tables

2012-10-14 Thread Sven Eckelmann
Users 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/^.*(//'

Signed-off-by: Sven Eckelmann s...@narfation.org
---
rebased on DAT

 Makefile |2 +-
 debug.c  |   27 --
 filter.c |  168 ++
 filter.h |   43 +++
 functions.c  |5 ++
 functions.h  |2 +
 man/batctl.8 |   12 +++--
 7 files changed, 250 insertions(+), 9 deletions(-)
 create mode 100644 filter.c
 create mode 100644 filter.h

diff --git a/Makefile b/Makefile
index 4379837..a4b6c11 100755
--- a/Makefile
+++ b/Makefile
@@ -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
 
diff --git a/debug.c b/debug.c
index 260448b..d939eaa 100644
--- a/debug.c
+++ b/debug.c
@@ -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] = {
{
@@ -86,6 +87,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)
@@ -94,14 +97,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);
@@ -137,6 +143,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);
@@ -162,9 +175,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)
diff --git a/filter.c b/filter.c
new file mode 100644
index 000..88dd425
--- /dev/null
+++ b/filter.c
@@ -0,0 +1,168 @@
+/*
+ * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors:
+ *
+ * Andreas Langer an.lan...@gmx.de, Marek Lindner lindner_ma...@yahoo.de
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free