Re: [B.A.T.M.A.N.] [PATCHv4] batman-adv: Add the backbone gateway list to debugfs

2012-06-18 Thread Sven Eckelmann
On Mon, Jun 18, 2012 at 12:21:32PM +0200, Simon Wunderlich wrote:
 + msecs = msecs % 1000;
 +
 +
 + is_own = batadv_compare_eth(backbone_gw-orig,

Why two empty lines?

 +static inline int batadv_bla_backbone_table_seq_print_text(struct seq_file 
 *seq,
 + void *offset)
 +{
 + return 0;
 +}
 +d

This also looks wrong aligned. 

Kind regards,
Sven


signature.asc
Description: Digital signature


[B.A.T.M.A.N.] [PATCH] batman-adv: fix race condition in TT full-table replacement

2012-06-18 Thread Antonio Quartulli
In the current TT code, when a TT_Response containing a full table is received
form an originator, the node first purges all the clients for that originator in
the global translation-table and then merges the new received table.
During the purging phase each client deletion is done by means of a call_rcu()
invocation and at the end the global entry counter for that originator is set to
0. However the invoked rcu function decreases by one the global entry counter
for that originator as well and since the rcu invocation is likely to be
postponed, the node will end up in first setting the counter to 0 and then
decreasing it one by one for each deleted client.
To solve this problem the counter is not explicitly set to 0 anymore and the
counter decrement is performed right before the invocation of call_rcu().

Signed-off-by: Antonio Quartulli or...@autistici.org
---
 translation-table.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/translation-table.c b/translation-table.c
index 2a6d7d6..b08cb76 100644
--- a/translation-table.c
+++ b/translation-table.c
@@ -145,7 +145,6 @@ static void batadv_tt_orig_list_entry_free_rcu(struct 
rcu_head *rcu)
struct batadv_tt_orig_list_entry *orig_entry;
 
orig_entry = container_of(rcu, struct batadv_tt_orig_list_entry, rcu);
-   atomic_dec(orig_entry-orig_node-tt_size);
batadv_orig_node_free_ref(orig_entry-orig_node);
kfree(orig_entry);
 }
@@ -153,6 +152,8 @@ static void batadv_tt_orig_list_entry_free_rcu(struct 
rcu_head *rcu)
 static void
 batadv_tt_orig_list_entry_free_ref(struct batadv_tt_orig_list_entry 
*orig_entry)
 {
+   /* to avoid race conditions, immediately decrease the tt counter */
+   atomic_dec(orig_entry-orig_node-tt_size);
call_rcu(orig_entry-rcu, batadv_tt_orig_list_entry_free_rcu);
 }
 
@@ -1025,7 +1026,6 @@ void batadv_tt_global_del_orig(struct batadv_priv 
*bat_priv,
}
spin_unlock_bh(list_lock);
}
-   atomic_set(orig_node-tt_size, 0);
orig_node-tt_initialised = false;
 }
 
-- 
1.7.9.4



[B.A.T.M.A.N.] [PATCHv5] batman-adv: Add the backbone gateway list to debugfs

2012-06-18 Thread Simon Wunderlich
This is especially useful if there are no claims yet, but we still want
to know which gateways are using bridge loop avoidance in the network.

Signed-off-by: Simon Wunderlich s...@hrz.tu-chemnitz.de
---
[EDITv2: forgot to rename the function ...]
[EDITv3: add README entry]
[EDITv4: fix style]
[EDITv5: some more style fixes]
---
 README  |7 ++---
 bridge_loop_avoidance.c |   65 +++
 bridge_loop_avoidance.h |8 ++
 debugfs.c   |   12 +
 4 files changed, 89 insertions(+), 3 deletions(-)

diff --git a/README b/README
index 8f3ae4a..a173d2a 100644
--- a/README
+++ b/README
@@ -75,9 +75,10 @@ folder:
 
 There is a special folder for debugging information:
 
-#  ls /sys/kernel/debug/batman_adv/bat0/
-# bla_claim_tablelogsocket transtable_local
-# gateways   originatorstranstable_global  vis_data
+# ls /sys/kernel/debug/batman_adv/bat0/
+# bla_backbone_table  log transtable_global
+# bla_claim_table originators transtable_local
+# gatewayssocket  vis_data
 
 Some of the files contain all sort of status information  regard-
 ing  the  mesh  network.  For  example, you can view the table of
diff --git a/bridge_loop_avoidance.c b/bridge_loop_avoidance.c
index 38aab1e..03fe5ea 100644
--- a/bridge_loop_avoidance.c
+++ b/bridge_loop_avoidance.c
@@ -1592,3 +1592,68 @@ out:
batadv_hardif_free_ref(primary_if);
return ret;
 }
+
+int batadv_bla_backbone_table_seq_print_text(struct seq_file *seq, void 
*offset)
+{
+   struct net_device *net_dev = (struct net_device *)seq-private;
+   struct batadv_priv *bat_priv = netdev_priv(net_dev);
+   struct batadv_hashtable *hash = bat_priv-backbone_hash;
+   struct batadv_backbone_gw *backbone_gw;
+   struct batadv_hard_iface *primary_if;
+   struct hlist_node *node;
+   struct hlist_head *head;
+   int secs, msecs;
+   uint32_t i;
+   bool is_own;
+   int ret = 0;
+   uint8_t *primary_addr;
+
+   primary_if = batadv_primary_if_get_selected(bat_priv);
+   if (!primary_if) {
+   ret = seq_printf(seq,
+BATMAN mesh %s disabled - please specify 
interfaces to enable it\n,
+net_dev-name);
+   goto out;
+   }
+
+   if (primary_if-if_status != BATADV_IF_ACTIVE) {
+   ret = seq_printf(seq,
+BATMAN mesh %s disabled - primary interface 
not active\n,
+net_dev-name);
+   goto out;
+   }
+
+   primary_addr = primary_if-net_dev-dev_addr;
+   seq_printf(seq,
+  Backbones announced for the mesh %s (orig %pM, group id 
%04x)\n,
+  net_dev-name, primary_addr,
+  ntohs(bat_priv-claim_dest.group));
+   seq_printf(seq,%-17s%-5s %-9s (%-4s)\n,
+  Originator, VID, last seen, CRC);
+   for (i = 0; i  hash-size; i++) {
+   head = hash-table[i];
+
+   rcu_read_lock();
+   hlist_for_each_entry_rcu(backbone_gw, node, head, hash_entry) {
+   msecs = jiffies_to_msecs(jiffies -
+backbone_gw-lasttime);
+   secs = msecs / 1000;
+   msecs = msecs % 1000;
+
+   is_own = batadv_compare_eth(backbone_gw-orig,
+   primary_addr);
+   if (is_own)
+   continue;
+
+   seq_printf(seq,
+   * %pM on % 5d % 4i.%03is (%04x)\n,
+  backbone_gw-orig, backbone_gw-vid,
+  secs, msecs, backbone_gw-crc);
+   }
+   rcu_read_unlock();
+   }
+out:
+   if (primary_if)
+   batadv_hardif_free_ref(primary_if);
+   return ret;
+}
diff --git a/bridge_loop_avoidance.h b/bridge_loop_avoidance.h
index 08d13cb..35d39e3 100644
--- a/bridge_loop_avoidance.h
+++ b/bridge_loop_avoidance.h
@@ -26,6 +26,8 @@ int batadv_bla_tx(struct batadv_priv *bat_priv, struct 
sk_buff *skb, short vid);
 int batadv_bla_is_backbone_gw(struct sk_buff *skb,
  struct batadv_orig_node *orig_node, int hdr_size);
 int batadv_bla_claim_table_seq_print_text(struct seq_file *seq, void *offset);
+int batadv_bla_backbone_table_seq_print_text(struct seq_file *seq,
+void *offset);
 int batadv_bla_is_backbone_gw_orig(struct batadv_priv *bat_priv, uint8_t 
*orig);
 int batadv_bla_check_bcast_duplist(struct batadv_priv *bat_priv,
   struct batadv_bcast_packet *bcast_packet,
@@ -64,6 +66,12 @@ static inline int 

Re: [B.A.T.M.A.N.] link alternation when radios are not on batman-adv router?

2012-06-18 Thread gtolon

Hi Simon, thanks for your reply!


El 15/06/2012 06:55 a.m., Simon Wunderlich escribió:

On Thu, Jun 14, 2012 at 04:51:01PM -0300, gto...@inti.gob.ar wrote:

Hi,

 we are interested too in interface alternating, so we made some
tests to understand how it works. As you can see on the attached
sketch.png, we connected two pair of routers using their ethernet
interfaces, E6 with E7, and E8 with E9. All of them have eth0, and
an ad hoc interface, wlan0-1, managed by batman. E6 and E8 are in
channel 11, whereas E7 and E9 are in channel 1. Besides we used two
other routers, E12 and E13, both in channel 11, with their tx power
set to just 0 dbm, to avoid a direct sight between them.

 Then we sent traffic from E12 to E13. We expected that packets
travelled from E12 to E6, and that E6 forwarded them to his eth0 to
use the interface alternating feature, making traffic flow to E7,
then E9, E8 and finally E13. But instead, we observed that the
actual path was E12--E6--E8--E13. The resulting routes for each
router are attached in a text file, and also the graph from the
batctl vd dot command.

 After this result, we read again the thread mentioned by Guido,
specially in this part:

https://lists.open-mesh.org/pipermail/b.a.t.m.a.n/2012-March/006344.html

And if we understand correctly, the alternation feature works
after the batman path has been selected. So in our case, E12 looks
at his table to know where to send a packet to E13, and finds E6.
Then E6 receives the packet and looks in his own table, finding that
the best path to reach E13 is E8. At this point, the alternating
should work, but there's only one interface directly connected to
E8, so the packet goes there, and so on. We think that if E6 and E7
were not two different routers running batman-adv but they were two
radios of the same batman-adv router, and the same for E8 and E9,
the alternating would work, because the unique router would choose
the best path, and then would find two possible interfaces to the
same next-hop, changing the interface.

This is entirely correct - batman-adv has only one link to choose from
(E6 -  E8) to reach its best nexthop E8, so there is no way to
alternate the interfaces.


 We'd like to know if this interpretation is correct, and in that
case, if it were possible to use interface alternating in a case
like this, with two routers connected to work together. Thanks!

Mhm, with the current implementation - no, unfortunately not. We would
need some kind of multipath routing to select between routes, this is
much more complex.


Ok, i understand.



An alternative might be to use the routers E7/E9 as secondary routers
without batman, but only forwarding traffic between Ethernet and
WiFi. Then the primary routers (E6 -  E8) would think they have
an alternative route via Ethernet (because they don't see the
intermediate hops E7/E9). This comes with some caveats however, e.g.
4-addr mode in Ad-Hoc, you need some very simple ethernet forwarder,
and most probably other things I forgot.


We had tried with something like that using ap and sta modes in E7 and 
E9, and it hadn't worked. Thanks to your suggestion we noticed the 
necessity of the 4-address mode, so we are now trying with wds:


http://wiki.openwrt.org/doc/recipes/atheroswds

Unfortunately, we haven't found yet a way to use 4-address mode in ad 
hoc. Apparentrly, it's not possible:


http://linuxwireless.org/en/users/Documentation/iw#Using_4-address_for_AP_and_client_mode

Best Regards

Gabriel


[B.A.T.M.A.N.] pull request: batman-adv 2012-06-18

2012-06-18 Thread Antonio Quartulli
Hello David,
here is our first set of changes intended for next-next/linux-3.6.

Patch 2 fixes a major bug in the TranslationTable code where the old value of
skb-data is used for memory access even if the data was relocated.
Patches 4, 10, 11, 13, 14 are endianess-related cleanups that we wrote thanks
to Al Viro's advice and help.
Thanks to Martin Hundebøll batman-adv now supports the ethtool API and can
export several counters that are specific to our module (patch 5).
Then patch 16 improves the routing protocol API by making part of the
TranslationTable code routing agnostic.
The rest are minor fixes and other cleanups.

Thank you very much,
Antonio



The following changes since commit 6fac262526ee91ee66210b8919a4297dcf7d544e:

  ipv4: Cap ADVMSS metric in the FIB rather than the routing cache. (2012-06-17 
19:47:34 -0700)

are available in the git repository at:

  git://git.open-mesh.org/linux-merge.git tags/batman-adv-for-davem

for you to fetch changes up to dafe94b278e052c3901b137fe6f666f8f92d839a:

  batman-adv: only store changed gw_bandwidth values (2012-06-18 18:01:07 +0200)


Included changes:

* major skb-data pointer usage fix
* interval version update
* added get_ethtool_stats() support
* endianess clean up
* routing protocol API improvement wrt TT commit code
* fix locking in hash table code
* minor cleanups and fixes


Al Viro (5):
  batman-adv: get rid of pointless cast in memcpy()
  batman-adv: trivial endianness annotations
  batman-adv: keep batman_ogm_packet -seqno net-endian all along
  batman-adv: don't bother flipping -tt_data
  batman-adv: don't bother flipping -tt_crc

Antonio Quartulli (3):
  batman-adv: fix skb-data assignment
  batman-adv: convert bat_priv-tt_crc from atomic_t to uint16_t
  batman-adv: use DBG_ALL in log_level sysfs definition

Marek Lindner (5):
  batman-adv: avoid characters requiring shell escapes in protocol names
  batman-adv: ignore trailing CR when comparing protocol names
  batman-adv: return added entries instead of number of possibly added 
entries
  batman-adv: turn tt commit code into routing protocol agnostic API
  batman-adv: only store changed gw_bandwidth values

Martin Hundebøll (1):
  batman-adv: Add get_ethtool_stats() support

Matthias Schiffer (2):
  batman-adv: fix visualization output without neighbors on the primary 
interface
  batman-adv: fix locking in hash_add()

Sven Eckelmann (3):
  batman-adv: update internal version number
  batman-adv: Initialize lockdep class keys for hashes
  batman-adv: Return error codes instead of -1 on failures

 Documentation/networking/batman-adv.txt |5 +
 net/batman-adv/bat_debugfs.c|   11 +-
 net/batman-adv/bat_iv_ogm.c |   63 ++--
 net/batman-adv/bat_sysfs.c  |4 +-
 net/batman-adv/bridge_loop_avoidance.c  |   27 +++--
 net/batman-adv/gateway_common.c |3 +
 net/batman-adv/hard-interface.c |4 +-
 net/batman-adv/hash.c   |9 ++
 net/batman-adv/hash.h   |   19 ++--
 net/batman-adv/icmp_socket.c|4 +-
 net/batman-adv/main.c   |   42 +---
 net/batman-adv/main.h   |   29 +-
 net/batman-adv/originator.c |   18 ++--
 net/batman-adv/packet.h |   18 ++--
 net/batman-adv/routing.c|   23 +++--
 net/batman-adv/send.c   |   74 +-
 net/batman-adv/soft-interface.c |   66 +++-
 net/batman-adv/translation-table.c  |  168 ---
 net/batman-adv/translation-table.h  |7 +-
 net/batman-adv/types.h  |   22 +++-
 net/batman-adv/vis.c|   29 --
 21 files changed, 420 insertions(+), 225 deletions(-)


[B.A.T.M.A.N.] [PATCH 01/19] batman-adv: update internal version number

2012-06-18 Thread Antonio Quartulli
From: Sven Eckelmann s...@narfation.org

Signed-off-by: Sven Eckelmann s...@narfation.org
Signed-off-by: Antonio Quartulli or...@autistici.org
---
 net/batman-adv/main.h |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h
index f4a3ec0..630bbe8 100644
--- a/net/batman-adv/main.h
+++ b/net/batman-adv/main.h
@@ -28,7 +28,7 @@
 #define DRIVER_DEVICE batman-adv
 
 #ifndef SOURCE_VERSION
-#define SOURCE_VERSION 2012.2.0
+#define SOURCE_VERSION 2012.3.0
 #endif
 
 /* B.A.T.M.A.N. parameters */
-- 
1.7.9.4



[B.A.T.M.A.N.] [PATCH 03/19] batman-adv: Initialize lockdep class keys for hashes

2012-06-18 Thread Antonio Quartulli
From: Sven Eckelmann s...@narfation.org

The hash for claim and backbone hash in the bridge loop avoidance code receive
the same key because they are getting initialized by hash_new with the same
key. Lockdep will create a backtrace when they are used recursively. This can
be avoided by reinitializing the key directly after the hash_new.

Signed-off-by: Sven Eckelmann s...@narfation.org
Signed-off-by: Antonio Quartulli or...@autistici.org
---
 net/batman-adv/bridge_loop_avoidance.c |   13 +
 net/batman-adv/hash.c  |9 +
 net/batman-adv/hash.h  |4 
 3 files changed, 26 insertions(+)

diff --git a/net/batman-adv/bridge_loop_avoidance.c 
b/net/batman-adv/bridge_loop_avoidance.c
index 8bf9751..5c1ac55 100644
--- a/net/batman-adv/bridge_loop_avoidance.c
+++ b/net/batman-adv/bridge_loop_avoidance.c
@@ -1127,6 +1127,14 @@ out:
bla_start_timer(bat_priv);
 }
 
+/* The hash for claim and backbone hash receive the same key because they
+ * are getting initialized by hash_new with the same key. Reinitializing
+ * them with to different keys to allow nested locking without generating
+ * lockdep warnings
+ */
+static struct lock_class_key claim_hash_lock_class_key;
+static struct lock_class_key backbone_hash_lock_class_key;
+
 /* initialize all bla structures */
 int bla_init(struct bat_priv *bat_priv)
 {
@@ -1164,6 +1172,11 @@ int bla_init(struct bat_priv *bat_priv)
if (!bat_priv-claim_hash || !bat_priv-backbone_hash)
return -1;
 
+   batadv_hash_set_lock_class(bat_priv-claim_hash,
+  claim_hash_lock_class_key);
+   batadv_hash_set_lock_class(bat_priv-backbone_hash,
+  backbone_hash_lock_class_key);
+
bat_dbg(DBG_BLA, bat_priv, bla hashes initialized\n);
 
bla_start_timer(bat_priv);
diff --git a/net/batman-adv/hash.c b/net/batman-adv/hash.c
index 117687b..5b2eabe 100644
--- a/net/batman-adv/hash.c
+++ b/net/batman-adv/hash.c
@@ -69,3 +69,12 @@ free_hash:
kfree(hash);
return NULL;
 }
+
+void batadv_hash_set_lock_class(struct hashtable_t *hash,
+   struct lock_class_key *key)
+{
+   uint32_t i;
+
+   for (i = 0; i  hash-size; i++)
+   lockdep_set_class(hash-list_locks[i], key);
+}
diff --git a/net/batman-adv/hash.h b/net/batman-adv/hash.h
index d4bd786..93b3c71 100644
--- a/net/batman-adv/hash.h
+++ b/net/batman-adv/hash.h
@@ -45,6 +45,10 @@ struct hashtable_t {
 /* allocates and clears the hash */
 struct hashtable_t *hash_new(uint32_t size);
 
+/* set class key for all locks */
+void batadv_hash_set_lock_class(struct hashtable_t *hash,
+   struct lock_class_key *key);
+
 /* free only the hashtable and the hash itself. */
 void hash_destroy(struct hashtable_t *hash);
 
-- 
1.7.9.4



[B.A.T.M.A.N.] [PATCH 04/19] batman-adv: convert bat_priv-tt_crc from atomic_t to uint16_t

2012-06-18 Thread Antonio Quartulli
In the code we neever need to atomically check and set the bat_priv-tt_crc
field value. It is simply set and read once in different pieces of the code.
Therefore this field can be safely be converted from atomic_t to uint16_t.

Reported-by: Al Viro v...@zeniv.linux.org.uk
Signed-off-by: Antonio Quartulli or...@autistici.org
Signed-off-by: Sven Eckelmann s...@narfation.org
---
 net/batman-adv/bat_iv_ogm.c |3 +--
 net/batman-adv/send.c   |2 +-
 net/batman-adv/types.h  |2 +-
 3 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index dc53798..ec35119 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -575,8 +575,7 @@ static void bat_iv_ogm_schedule(struct hard_iface 
*hard_iface,
htonl((uint32_t)atomic_read(hard_iface-seqno));
 
batman_ogm_packet-ttvn = atomic_read(bat_priv-ttvn);
-   batman_ogm_packet-tt_crc = htons((uint16_t)
-   atomic_read(bat_priv-tt_crc));
+   batman_ogm_packet-tt_crc = htons(bat_priv-tt_crc);
if (tt_num_changes = 0)
batman_ogm_packet-tt_num_changes = tt_num_changes;
 
diff --git a/net/batman-adv/send.c b/net/batman-adv/send.c
index f47299f..f5ff364 100644
--- a/net/batman-adv/send.c
+++ b/net/batman-adv/send.c
@@ -111,7 +111,7 @@ static int prepare_packet_buffer(struct bat_priv *bat_priv,
 
realloc_packet_buffer(hard_iface, new_len);
 
-   atomic_set(bat_priv-tt_crc, tt_local_crc(bat_priv));
+   bat_priv-tt_crc = tt_local_crc(bat_priv);
 
/* reset the sending counter */
atomic_set(bat_priv-tt_ogm_append_cnt, TT_OGM_APPEND_MAX);
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index 61308e8..547dc33 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -210,7 +210,7 @@ struct bat_priv {
spinlock_t vis_list_lock; /* protects vis_info::recv_list */
atomic_t num_local_tt;
/* Checksum of the local table, recomputed before sending a new OGM */
-   atomic_t tt_crc;
+   uint16_t tt_crc;
unsigned char *tt_buff;
int16_t tt_buff_len;
spinlock_t tt_buff_lock; /* protects tt_buff */
-- 
1.7.9.4



[B.A.T.M.A.N.] [PATCH 05/19] batman-adv: Add get_ethtool_stats() support

2012-06-18 Thread Antonio Quartulli
From: Martin Hundebøll mar...@hundeboll.net

Added additional counters in a bat_stats structure, which are exported
through the ethtool api. The counters are specific to batman-adv and
includes:
 forwarded packets and bytes
 management packets and bytes (aggregated OGMs at this point)
 translation table packets

New counters are added by extending enum bat_counters in types.h and
adding corresponding  descriptive string(s) to bat_counters_strings in
soft-iface.c.

Counters are increased by calling batadv_add_counter() and incremented
by one by calling batadv_inc_counter().

Signed-off-by: Martin Hundebøll mar...@hundeboll.net
Signed-off-by: Sven Eckelmann s...@narfation.org
Signed-off-by: Antonio Quartulli or...@autistici.org
---
 Documentation/networking/batman-adv.txt |5 +++
 net/batman-adv/bat_iv_ogm.c |   10 -
 net/batman-adv/main.c   |2 +
 net/batman-adv/main.h   |   27 +
 net/batman-adv/routing.c|   11 ++
 net/batman-adv/soft-interface.c |   66 ++-
 net/batman-adv/translation-table.c  |8 
 net/batman-adv/types.h  |   17 
 8 files changed, 143 insertions(+), 3 deletions(-)

diff --git a/Documentation/networking/batman-adv.txt 
b/Documentation/networking/batman-adv.txt
index 75a5923..8f3ae4a 100644
--- a/Documentation/networking/batman-adv.txt
+++ b/Documentation/networking/batman-adv.txt
@@ -211,6 +211,11 @@ The debug output can be changed at runtime  using  the  
file
 
 will enable debug messages for when routes change.
 
+Counters for different types of packets entering and leaving the
+batman-adv module are available through ethtool:
+
+# ethtool --statistics bat0
+
 
 BATCTL
 --
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index ec35119..99ec218 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -196,8 +196,12 @@ static void bat_iv_ogm_send_to_if(struct forw_packet 
*forw_packet,
 
/* create clone because function is called more than once */
skb = skb_clone(forw_packet-skb, GFP_ATOMIC);
-   if (skb)
+   if (skb) {
+   batadv_inc_counter(bat_priv, BAT_CNT_MGMT_TX);
+   batadv_add_counter(bat_priv, BAT_CNT_MGMT_TX_BYTES,
+  skb-len + ETH_HLEN);
send_skb_packet(skb, hard_iface, broadcast_addr);
+   }
 }
 
 /* send a batman ogm packet */
@@ -1203,6 +1207,10 @@ static int bat_iv_ogm_receive(struct sk_buff *skb,
if (bat_priv-bat_algo_ops-bat_ogm_emit != bat_iv_ogm_emit)
return NET_RX_DROP;
 
+   batadv_inc_counter(bat_priv, BAT_CNT_MGMT_RX);
+   batadv_add_counter(bat_priv, BAT_CNT_MGMT_RX_BYTES,
+  skb-len + ETH_HLEN);
+
packet_len = skb_headlen(skb);
ethhdr = (struct ethhdr *)skb_mac_header(skb);
packet_buff = skb-data;
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index 083a299..bd83aa4 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -153,6 +153,8 @@ void mesh_free(struct net_device *soft_iface)
 
bla_free(bat_priv);
 
+   free_percpu(bat_priv-bat_counters);
+
atomic_set(bat_priv-mesh_state, MESH_INACTIVE);
 }
 
diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h
index 630bbe8..6e0cbdc 100644
--- a/net/batman-adv/main.h
+++ b/net/batman-adv/main.h
@@ -138,6 +138,7 @@ enum dbg_level {
 #include linux/kthread.h /* kernel threads */
 #include linux/pkt_sched.h   /* schedule types */
 #include linux/workqueue.h   /* workqueue */
+#include linux/percpu.h
 #include linux/slab.h
 #include net/sock.h  /* struct sock */
 #include linux/jiffies.h
@@ -242,4 +243,30 @@ static inline bool has_timed_out(unsigned long timestamp, 
unsigned int timeout)
  _dummy  smallest_signed_int(_dummy); })
 #define seq_after(x, y) seq_before(y, x)
 
+/* Stop preemption on local cpu while incrementing the counter */
+static inline void batadv_add_counter(struct bat_priv *bat_priv, size_t idx,
+ size_t count)
+{
+   int cpu = get_cpu();
+   per_cpu_ptr(bat_priv-bat_counters, cpu)[idx] += count;
+   put_cpu();
+}
+
+#define batadv_inc_counter(b, i) batadv_add_counter(b, i, 1)
+
+/* Sum and return the cpu-local counters for index 'idx' */
+static inline uint64_t batadv_sum_counter(struct bat_priv *bat_priv, size_t 
idx)
+{
+   uint64_t *counters;
+   int cpu;
+   int sum = 0;
+
+   for_each_possible_cpu(cpu) {
+   counters = per_cpu_ptr(bat_priv-bat_counters, cpu);
+   sum += counters[idx];
+   }
+
+   return sum;
+}
+
 #endif /* _NET_BATMAN_ADV_MAIN_H_ */
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index 015471d..369604c 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -600,6 +600,8 @@ int recv_tt_query(struct 

[B.A.T.M.A.N.] [PATCH 06/19] batman-adv: avoid characters requiring shell escapes in protocol names

2012-06-18 Thread Antonio Quartulli
From: Marek Lindner lindner_ma...@yahoo.de

Reported-by: Andrew Lunn and...@lunn.ch
Signed-off-by: Marek Lindner lindner_ma...@yahoo.de
Signed-off-by: Sven Eckelmann s...@narfation.org
Signed-off-by: Antonio Quartulli or...@autistici.org
---
 net/batman-adv/bat_iv_ogm.c |2 +-
 net/batman-adv/main.c   |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 99ec218..e94ac0b 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -1241,7 +1241,7 @@ static int bat_iv_ogm_receive(struct sk_buff *skb,
 }
 
 static struct bat_algo_ops batman_iv __read_mostly = {
-   .name = BATMAN IV,
+   .name = BATMAN_IV,
.bat_iface_enable = bat_iv_ogm_iface_enable,
.bat_iface_disable = bat_iv_ogm_iface_disable,
.bat_iface_update_mac = bat_iv_ogm_iface_update_mac,
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index bd83aa4..65b4f08 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -40,7 +40,7 @@
  * list traversals just rcu-locked */
 struct list_head hardif_list;
 static int (*recv_packet_handler[256])(struct sk_buff *, struct hard_iface *);
-char bat_routing_algo[20] = BATMAN IV;
+char bat_routing_algo[20] = BATMAN_IV;
 static struct hlist_head bat_algo_list;
 
 unsigned char broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
-- 
1.7.9.4



[B.A.T.M.A.N.] [PATCH 08/19] batman-adv: return added entries instead of number of possibly added entries

2012-06-18 Thread Antonio Quartulli
From: Marek Lindner lindner_ma...@yahoo.de

Signed-off-by: Marek Lindner lindner_ma...@yahoo.de
Acked-by: Antonio Quartulli or...@autistici.org
Signed-off-by: Sven Eckelmann s...@narfation.org
Signed-off-by: Antonio Quartulli or...@autistici.org
---
 net/batman-adv/translation-table.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/batman-adv/translation-table.c 
b/net/batman-adv/translation-table.c
index ca53542..f9675b7 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -319,7 +319,7 @@ int tt_changes_fill_buffer(struct bat_priv *bat_priv,
}
spin_unlock_bh(bat_priv-tt_buff_lock);
 
-   return tot_changes;
+   return count;
 }
 
 int tt_local_seq_print_text(struct seq_file *seq, void *offset)
-- 
1.7.9.4



[B.A.T.M.A.N.] [PATCH 09/19] batman-adv: get rid of pointless cast in memcpy()

2012-06-18 Thread Antonio Quartulli
From: Al Viro v...@zeniv.linux.org.uk

memcpy() arguments are void *, precisely to avoid that kind of pointless
casts.

Signed-off-by: Al Viro v...@zeniv.linux.org.uk
Signed-off-by: Sven Eckelmann s...@narfation.org
Signed-off-by: Antonio Quartulli or...@autistici.org
---
 net/batman-adv/bridge_loop_avoidance.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/batman-adv/bridge_loop_avoidance.c 
b/net/batman-adv/bridge_loop_avoidance.c
index 5c1ac55..89e2b1c 100644
--- a/net/batman-adv/bridge_loop_avoidance.c
+++ b/net/batman-adv/bridge_loop_avoidance.c
@@ -510,7 +510,7 @@ static void bla_send_announce(struct bat_priv *bat_priv,
 
memcpy(mac, announce_mac, 4);
crc = htons(backbone_gw-crc);
-   memcpy(mac[4], (uint8_t *)crc, 2);
+   memcpy(mac[4], crc, 2);
 
bla_send_claim(bat_priv, mac, backbone_gw-vid, CLAIM_TYPE_ANNOUNCE);
 
-- 
1.7.9.4



[B.A.T.M.A.N.] [PATCH 10/19] batman-adv: trivial endianness annotations

2012-06-18 Thread Antonio Quartulli
From: Al Viro v...@zeniv.linux.org.uk

Signed-off-by: Al Viro v...@zeniv.linux.org.uk
Signed-off-by: Sven Eckelmann s...@narfation.org
Signed-off-by: Antonio Quartulli or...@autistici.org
---
 net/batman-adv/bridge_loop_avoidance.c |6 +++---
 net/batman-adv/packet.h|   12 ++--
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/net/batman-adv/bridge_loop_avoidance.c 
b/net/batman-adv/bridge_loop_avoidance.c
index 89e2b1c..0355c48 100644
--- a/net/batman-adv/bridge_loop_avoidance.c
+++ b/net/batman-adv/bridge_loop_avoidance.c
@@ -258,7 +258,7 @@ static void bla_send_claim(struct bat_priv *bat_priv, 
uint8_t *mac,
struct net_device *soft_iface;
uint8_t *hw_src;
struct bla_claim_dst local_claim_dest;
-   uint32_t zeroip = 0;
+   __be32 zeroip = 0;
 
primary_if = primary_if_get_selected(bat_priv);
if (!primary_if)
@@ -506,7 +506,7 @@ static void bla_send_announce(struct bat_priv *bat_priv,
  struct backbone_gw *backbone_gw)
 {
uint8_t mac[ETH_ALEN];
-   uint16_t crc;
+   __be16 crc;
 
memcpy(mac, announce_mac, 4);
crc = htons(backbone_gw-crc);
@@ -627,7 +627,7 @@ static int handle_announce(struct bat_priv *bat_priv,
 
/* handle as ANNOUNCE frame */
backbone_gw-lasttime = jiffies;
-   crc = ntohs(*((uint16_t *)(an_addr[4])));
+   crc = ntohs(*((__be16 *)(an_addr[4])));
 
bat_dbg(DBG_BLA, bat_priv,
handle_announce(): ANNOUNCE vid %d (sent by %pM)... CRC = 
%04x\n,
diff --git a/net/batman-adv/packet.h b/net/batman-adv/packet.h
index 0ee1af7..eaa6028 100644
--- a/net/batman-adv/packet.h
+++ b/net/batman-adv/packet.h
@@ -105,7 +105,7 @@ enum bla_claimframe {
 struct bla_claim_dst {
uint8_t magic[3];   /* FF:43:05 */
uint8_t type;   /* bla_claimframe */
-   uint16_t group; /* group id */
+   __be16 group;   /* group id */
 } __packed;
 
 struct batman_header {
@@ -134,7 +134,7 @@ struct icmp_packet {
uint8_t  msg_type; /* see ICMP message types above */
uint8_t  dst[ETH_ALEN];
uint8_t  orig[ETH_ALEN];
-   uint16_t seqno;
+   __be16   seqno;
uint8_t  uid;
uint8_t  reserved;
 } __packed;
@@ -148,7 +148,7 @@ struct icmp_packet_rr {
uint8_t  msg_type; /* see ICMP message types above */
uint8_t  dst[ETH_ALEN];
uint8_t  orig[ETH_ALEN];
-   uint16_t seqno;
+   __be16   seqno;
uint8_t  uid;
uint8_t  rr_cur;
uint8_t  rr[BAT_RR_LEN][ETH_ALEN];
@@ -167,20 +167,20 @@ struct unicast_frag_packet {
uint8_t  flags;
uint8_t  align;
uint8_t  orig[ETH_ALEN];
-   uint16_t seqno;
+   __be16   seqno;
 } __packed;
 
 struct bcast_packet {
struct batman_header header;
uint8_t  reserved;
-   uint32_t seqno;
+   __be32   seqno;
uint8_t  orig[ETH_ALEN];
 } __packed;
 
 struct vis_packet {
struct batman_header header;
uint8_t  vis_type;   /* which type of vis-participant sent this? */
-   uint32_t seqno;  /* sequence number */
+   __be32   seqno;  /* sequence number */
uint8_t  entries;/* number of entries behind this struct */
uint8_t  reserved;
uint8_t  vis_orig[ETH_ALEN];/* originator reporting its neighbors */
-- 
1.7.9.4



[B.A.T.M.A.N.] [PATCH 11/19] batman-adv: keep batman_ogm_packet -seqno net-endian all along

2012-06-18 Thread Antonio Quartulli
From: Al Viro v...@zeniv.linux.org.uk

Signed-off-by: Al Viro v...@zeniv.linux.org.uk
Signed-off-by: Sven Eckelmann s...@narfation.org
Signed-off-by: Antonio Quartulli or...@autistici.org
---
 net/batman-adv/bat_iv_ogm.c |   22 +++---
 net/batman-adv/packet.h |2 +-
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index e94ac0b..56b6d78 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -34,11 +34,12 @@ static struct neigh_node *bat_iv_ogm_neigh_new(struct 
hard_iface *hard_iface,
   const uint8_t *neigh_addr,
   struct orig_node *orig_node,
   struct orig_node *orig_neigh,
-  uint32_t seqno)
+  __be32 seqno)
 {
struct neigh_node *neigh_node;
 
-   neigh_node = batadv_neigh_node_new(hard_iface, neigh_addr, seqno);
+   neigh_node = batadv_neigh_node_new(hard_iface, neigh_addr,
+  ntohl(seqno));
if (!neigh_node)
goto out;
 
@@ -546,7 +547,6 @@ static void bat_iv_ogm_forward(struct orig_node *orig_node,
Forwarding packet: tq: %i, ttl: %i\n,
batman_ogm_packet-tq, batman_ogm_packet-header.ttl);
 
-   batman_ogm_packet-seqno = htonl(batman_ogm_packet-seqno);
batman_ogm_packet-tt_crc = htons(batman_ogm_packet-tt_crc);
 
/* switch of primaries first hop flag when forwarding */
@@ -871,13 +871,14 @@ static int bat_iv_ogm_update_seqnos(const struct ethhdr 
*ethhdr,
int32_t seq_diff;
int need_update = 0;
int set_mark, ret = -1;
+   uint32_t seqno = ntohl(batman_ogm_packet-seqno);
 
orig_node = get_orig_node(bat_priv, batman_ogm_packet-orig);
if (!orig_node)
return 0;
 
spin_lock_bh(orig_node-ogm_cnt_lock);
-   seq_diff = batman_ogm_packet-seqno - orig_node-last_real_seqno;
+   seq_diff = seqno - orig_node-last_real_seqno;
 
/* signalize caller that the packet is to be dropped. */
if (!hlist_empty(orig_node-neigh_list) 
@@ -891,7 +892,7 @@ static int bat_iv_ogm_update_seqnos(const struct ethhdr 
*ethhdr,
 
is_duplicate |= bat_test_bit(tmp_neigh_node-real_bits,
 orig_node-last_real_seqno,
-batman_ogm_packet-seqno);
+seqno);
 
if (compare_eth(tmp_neigh_node-addr, ethhdr-h_source) 
(tmp_neigh_node-if_incoming == if_incoming))
@@ -913,8 +914,8 @@ static int bat_iv_ogm_update_seqnos(const struct ethhdr 
*ethhdr,
if (need_update) {
bat_dbg(DBG_BATMAN, bat_priv,
updating last_seqno: old %u, new %u\n,
-   orig_node-last_real_seqno, batman_ogm_packet-seqno);
-   orig_node-last_real_seqno = batman_ogm_packet-seqno;
+   orig_node-last_real_seqno, seqno);
+   orig_node-last_real_seqno = seqno;
}
 
ret = is_duplicate;
@@ -970,7 +971,7 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
Received BATMAN packet via NB: %pM, IF: %s [%pM] (from OG: 
%pM, via prev OG: %pM, seqno %u, ttvn %u, crc %u, changes %u, td %d, TTL %d, V 
%d, IDF %d)\n,
ethhdr-h_source, if_incoming-net_dev-name,
if_incoming-net_dev-dev_addr, batman_ogm_packet-orig,
-   batman_ogm_packet-prev_sender, batman_ogm_packet-seqno,
+   batman_ogm_packet-prev_sender, ntohl(batman_ogm_packet-seqno),
batman_ogm_packet-ttvn, batman_ogm_packet-tt_crc,
batman_ogm_packet-tt_num_changes, batman_ogm_packet-tq,
batman_ogm_packet-header.ttl,
@@ -1042,7 +1043,7 @@ static void bat_iv_ogm_process(const struct ethhdr 
*ethhdr,
word = (orig_neigh_node-bcast_own[offset]);
bat_set_bit(word,
if_incoming_seqno -
-   batman_ogm_packet-seqno - 2);
+   ntohl(batman_ogm_packet-seqno) - 2);
orig_neigh_node-bcast_own_sum[if_incoming-if_num] =
bitmap_weight(word, TQ_LOCAL_WINDOW_SIZE);
spin_unlock_bh(orig_neigh_node-ogm_cnt_lock);
@@ -1135,7 +1136,7 @@ static void bat_iv_ogm_process(const struct ethhdr 
*ethhdr,
 * seqno and similar ttl as the non-duplicate */
if (is_bidirectional 
(!is_duplicate ||
-((orig_node-last_real_seqno == batman_ogm_packet-seqno) 
+((orig_node-last_real_seqno == 

[B.A.T.M.A.N.] [PATCH 12/19] batman-adv: Return error codes instead of -1 on failures

2012-06-18 Thread Antonio Quartulli
From: Sven Eckelmann s...@narfation.org

Signed-off-by: Sven Eckelmann s...@narfation.org
Signed-off-by: Antonio Quartulli or...@autistici.org
---
 net/batman-adv/bat_debugfs.c   |   11 +++
 net/batman-adv/bat_iv_ogm.c|2 +-
 net/batman-adv/bat_sysfs.c |2 +-
 net/batman-adv/bridge_loop_avoidance.c |6 +++---
 net/batman-adv/hard-interface.c|4 +---
 net/batman-adv/icmp_socket.c   |4 ++--
 net/batman-adv/main.c  |   27 ---
 net/batman-adv/originator.c|   18 +-
 net/batman-adv/translation-table.c |   24 ++--
 net/batman-adv/vis.c   |8 
 10 files changed, 58 insertions(+), 48 deletions(-)

diff --git a/net/batman-adv/bat_debugfs.c b/net/batman-adv/bat_debugfs.c
index 3b588f8..db8273c 100644
--- a/net/batman-adv/bat_debugfs.c
+++ b/net/batman-adv/bat_debugfs.c
@@ -195,13 +195,13 @@ static int debug_log_setup(struct bat_priv *bat_priv)
 
d = debugfs_create_file(log, S_IFREG | S_IRUSR,
bat_priv-debug_dir, bat_priv, log_fops);
-   if (d)
+   if (!d)
goto err;
 
return 0;
 
 err:
-   return 1;
+   return -ENOMEM;
 }
 
 static void debug_log_cleanup(struct bat_priv *bat_priv)
@@ -348,8 +348,11 @@ int debugfs_add_meshif(struct net_device *dev)
if (!bat_priv-debug_dir)
goto out;
 
-   bat_socket_setup(bat_priv);
-   debug_log_setup(bat_priv);
+   if (bat_socket_setup(bat_priv)  0)
+   goto rem_attr;
+
+   if (debug_log_setup(bat_priv)  0)
+   goto rem_attr;
 
for (bat_debug = mesh_debuginfos; *bat_debug; ++bat_debug) {
file = debugfs_create_file(((*bat_debug)-attr).name,
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 56b6d78..896287e 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -60,7 +60,7 @@ static int bat_iv_ogm_iface_enable(struct hard_iface 
*hard_iface)
 {
struct batman_ogm_packet *batman_ogm_packet;
uint32_t random_seqno;
-   int res = -1;
+   int res = -ENOMEM;
 
/* randomize initial seqno to avoid collision */
get_random_bytes(random_seqno, sizeof(random_seqno));
diff --git a/net/batman-adv/bat_sysfs.c b/net/batman-adv/bat_sysfs.c
index 5bc7b66..62f4f6c 100644
--- a/net/batman-adv/bat_sysfs.c
+++ b/net/batman-adv/bat_sysfs.c
@@ -680,7 +680,7 @@ void sysfs_del_hardif(struct kobject **hardif_obj)
 int throw_uevent(struct bat_priv *bat_priv, enum uev_type type,
 enum uev_action action, const char *data)
 {
-   int ret = -1;
+   int ret = -ENOMEM;
struct hard_iface *primary_if = NULL;
struct kobject *bat_kobj;
char *uevent_env[4] = { NULL, NULL, NULL, NULL };
diff --git a/net/batman-adv/bridge_loop_avoidance.c 
b/net/batman-adv/bridge_loop_avoidance.c
index 0355c48..314e37b 100644
--- a/net/batman-adv/bridge_loop_avoidance.c
+++ b/net/batman-adv/bridge_loop_avoidance.c
@@ -1164,13 +1164,13 @@ int bla_init(struct bat_priv *bat_priv)
bat_priv-bcast_duplist_curr = 0;
 
if (bat_priv-claim_hash)
-   return 1;
+   return 0;
 
bat_priv-claim_hash = hash_new(128);
bat_priv-backbone_hash = hash_new(32);
 
if (!bat_priv-claim_hash || !bat_priv-backbone_hash)
-   return -1;
+   return -ENOMEM;
 
batadv_hash_set_lock_class(bat_priv-claim_hash,
   claim_hash_lock_class_key);
@@ -1180,7 +1180,7 @@ int bla_init(struct bat_priv *bat_priv)
bat_dbg(DBG_BLA, bat_priv, bla hashes initialized\n);
 
bla_start_timer(bat_priv);
-   return 1;
+   return 0;
 }
 
 /**
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index dc334fa..ce78c6d 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -306,10 +306,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
bat_priv = netdev_priv(hard_iface-soft_iface);
 
ret = bat_priv-bat_algo_ops-bat_iface_enable(hard_iface);
-   if (ret  0) {
-   ret = -ENOMEM;
+   if (ret  0)
goto err_dev;
-   }
 
hard_iface-if_num = bat_priv-num_ifaces;
bat_priv-num_ifaces++;
diff --git a/net/batman-adv/icmp_socket.c b/net/batman-adv/icmp_socket.c
index 2e98a57..d27db81 100644
--- a/net/batman-adv/icmp_socket.c
+++ b/net/batman-adv/icmp_socket.c
@@ -285,13 +285,13 @@ int bat_socket_setup(struct bat_priv *bat_priv)
 
d = debugfs_create_file(ICMP_SOCKET, S_IFREG | S_IWUSR | S_IRUSR,
bat_priv-debug_dir, bat_priv, fops);
-   if (d)
+   if (!d)
goto err;
 
return 0;
 
 err:
-   return 1;
+   return -ENOMEM;
 }
 
 static void 

[B.A.T.M.A.N.] [PATCH 13/19] batman-adv: don't bother flipping -tt_data

2012-06-18 Thread Antonio Quartulli
From: Al Viro v...@zeniv.linux.org.uk

just keep it net-endian all along

Signed-off-by: Al Viro v...@zeniv.linux.org.uk
[lindner_ma...@yahoo.de: fix checkpatch warnings]
Signed-off-by: Marek Lindner lindner_ma...@yahoo.de
Signed-off-by: Sven Eckelmann s...@narfation.org
Signed-off-by: Antonio Quartulli or...@autistici.org
---
 net/batman-adv/packet.h|2 +-
 net/batman-adv/routing.c   |   10 +++---
 net/batman-adv/translation-table.c |   10 ++
 3 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/net/batman-adv/packet.h b/net/batman-adv/packet.h
index 5bf567b..372fc88 100644
--- a/net/batman-adv/packet.h
+++ b/net/batman-adv/packet.h
@@ -206,7 +206,7 @@ struct tt_query_packet {
 * if TT_REQUEST: crc associated with the
 *ttvn
 * if TT_RESPONSE: table_size */
-   uint16_t tt_data;
+   __be16   tt_data;
 } __packed;
 
 struct roam_adv_packet {
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index 369604c..9cfd23c 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -573,7 +573,7 @@ int recv_tt_query(struct sk_buff *skb, struct hard_iface 
*recv_if)
 {
struct bat_priv *bat_priv = netdev_priv(recv_if-soft_iface);
struct tt_query_packet *tt_query;
-   uint16_t tt_len;
+   uint16_t tt_size;
struct ethhdr *ethhdr;
 
/* drop packet if it has not necessary minimum size */
@@ -596,8 +596,6 @@ int recv_tt_query(struct sk_buff *skb, struct hard_iface 
*recv_if)
 
tt_query = (struct tt_query_packet *)skb-data;
 
-   tt_query-tt_data = ntohs(tt_query-tt_data);
-
switch (tt_query-flags  TT_QUERY_TYPE_MASK) {
case TT_REQUEST:
batadv_inc_counter(bat_priv, BAT_CNT_TT_REQUEST_RX);
@@ -609,7 +607,6 @@ int recv_tt_query(struct sk_buff *skb, struct hard_iface 
*recv_if)
Routing TT_REQUEST to %pM [%c]\n,
tt_query-dst,
(tt_query-flags  TT_FULL_TABLE ? 'F' : '.'));
-   tt_query-tt_data = htons(tt_query-tt_data);
return route_unicast_packet(skb, recv_if);
}
break;
@@ -624,11 +621,11 @@ int recv_tt_query(struct sk_buff *skb, struct hard_iface 
*recv_if)
/* skb_linearize() possibly changed skb-data */
tt_query = (struct tt_query_packet *)skb-data;
 
-   tt_len = tt_query-tt_data * sizeof(struct tt_change);
+   tt_size = tt_len(ntohs(tt_query-tt_data));
 
/* Ensure we have all the claimed data */
if (unlikely(skb_headlen(skb) 
-sizeof(struct tt_query_packet) + tt_len))
+sizeof(struct tt_query_packet) + tt_size))
goto out;
 
handle_tt_response(bat_priv, tt_query);
@@ -637,7 +634,6 @@ int recv_tt_query(struct sk_buff *skb, struct hard_iface 
*recv_if)
Routing TT_RESPONSE to %pM [%c]\n,
tt_query-dst,
(tt_query-flags  TT_FULL_TABLE ? 'F' : '.'));
-   tt_query-tt_data = htons(tt_query-tt_data);
return route_unicast_packet(skb, recv_if);
}
break;
diff --git a/net/batman-adv/translation-table.c 
b/net/batman-adv/translation-table.c
index 24e691d..88cfe2a 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -1418,7 +1418,7 @@ static bool send_other_tt_response(struct bat_priv 
*bat_priv,
 
/* I don't have the requested data */
if (orig_ttvn != req_ttvn ||
-   tt_request-tt_data != req_dst_orig_node-tt_crc)
+   tt_request-tt_data != htons(req_dst_orig_node-tt_crc))
goto out;
 
/* If the full table has been explicitly requested */
@@ -1678,7 +1678,7 @@ static void tt_fill_gtable(struct bat_priv *bat_priv,
 
_tt_update_changes(bat_priv, orig_node,
   (struct tt_change *)(tt_response + 1),
-  tt_response-tt_data, tt_response-ttvn);
+  ntohs(tt_response-tt_data), tt_response-ttvn);
 
spin_lock_bh(orig_node-tt_buff_lock);
kfree(orig_node-tt_buff);
@@ -1733,7 +1733,8 @@ void handle_tt_response(struct bat_priv *bat_priv,
 
bat_dbg(DBG_TT, bat_priv,
Received TT_RESPONSE from %pM for ttvn %d t_size: %d [%c]\n,
-   tt_response-src, tt_response-ttvn, tt_response-tt_data,
+   tt_response-src, tt_response-ttvn,
+   ntohs(tt_response-tt_data),
(tt_response-flags  TT_FULL_TABLE ? 'F' : '.'));
 
/* we should have never asked a backbone gw */
@@ -1747,7 +1748,8 @@ void 

[B.A.T.M.A.N.] [PATCH 14/19] batman-adv: don't bother flipping -tt_crc

2012-06-18 Thread Antonio Quartulli
From: Al Viro v...@zeniv.linux.org.uk

Keep it net-endian

Signed-off-by: Al Viro v...@zeniv.linux.org.uk
Signed-off-by: Sven Eckelmann s...@narfation.org
Signed-off-by: Antonio Quartulli or...@autistici.org
---
 net/batman-adv/bat_iv_ogm.c |   10 ++
 net/batman-adv/packet.h |2 +-
 2 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 896287e..ec3542c 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -547,8 +547,6 @@ static void bat_iv_ogm_forward(struct orig_node *orig_node,
Forwarding packet: tq: %i, ttl: %i\n,
batman_ogm_packet-tq, batman_ogm_packet-header.ttl);
 
-   batman_ogm_packet-tt_crc = htons(batman_ogm_packet-tt_crc);
-
/* switch of primaries first hop flag when forwarding */
batman_ogm_packet-flags = ~PRIMARIES_FIRST_HOP;
if (is_single_hop_neigh)
@@ -724,7 +722,7 @@ update_tt:
tt_update_orig(bat_priv, orig_node, tt_buff,
   batman_ogm_packet-tt_num_changes,
   batman_ogm_packet-ttvn,
-  batman_ogm_packet-tt_crc);
+  ntohs(batman_ogm_packet-tt_crc));
 
if (orig_node-gw_flags != batman_ogm_packet-gw_flags)
gw_node_update(bat_priv, orig_node,
@@ -972,7 +970,7 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
ethhdr-h_source, if_incoming-net_dev-name,
if_incoming-net_dev-dev_addr, batman_ogm_packet-orig,
batman_ogm_packet-prev_sender, ntohl(batman_ogm_packet-seqno),
-   batman_ogm_packet-ttvn, batman_ogm_packet-tt_crc,
+   batman_ogm_packet-ttvn, ntohs(batman_ogm_packet-tt_crc),
batman_ogm_packet-tt_num_changes, batman_ogm_packet-tq,
batman_ogm_packet-header.ttl,
batman_ogm_packet-header.version, has_directlink_flag);
@@ -1219,10 +1217,6 @@ static int bat_iv_ogm_receive(struct sk_buff *skb,
 
/* unpack the aggregated packets and process them one by one */
do {
-   /* network to host order for our 32bit seqno and the
-  orig_interval */
-   batman_ogm_packet-tt_crc = ntohs(batman_ogm_packet-tt_crc);
-
tt_buff = packet_buff + buff_pos + BATMAN_OGM_HLEN;
 
bat_iv_ogm_process(ethhdr, batman_ogm_packet,
diff --git a/net/batman-adv/packet.h b/net/batman-adv/packet.h
index 372fc88..033d994 100644
--- a/net/batman-adv/packet.h
+++ b/net/batman-adv/packet.h
@@ -124,7 +124,7 @@ struct batman_ogm_packet {
uint8_t  tq;
uint8_t  tt_num_changes;
uint8_t  ttvn; /* translation table version number */
-   uint16_t tt_crc;
+   __be16   tt_crc;
 } __packed;
 
 #define BATMAN_OGM_HLEN sizeof(struct batman_ogm_packet)
-- 
1.7.9.4



[B.A.T.M.A.N.] [PATCH 15/19] batman-adv: fix visualization output without neighbors on the primary interface

2012-06-18 Thread Antonio Quartulli
From: Matthias Schiffer mschif...@universe-factory.net

The primary entry and the corresponding secondary entries are missing when there
are no neighbors on the primary interface. This also causes the TT entries to
miss and makes nodes with multiply secondary interface fall apart since there
is no way to see they are related without a primary entry.

Fix this by always emitting a primary entry.

Signed-off-by: Matthias Schiffer mschif...@universe-factory.net
Signed-off-by: Sven Eckelmann s...@narfation.org
Signed-off-by: Antonio Quartulli or...@autistici.org
---
 net/batman-adv/vis.c |   21 ++---
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/net/batman-adv/vis.c b/net/batman-adv/vis.c
index 411c0e1..01d5da5 100644
--- a/net/batman-adv/vis.c
+++ b/net/batman-adv/vis.c
@@ -207,7 +207,6 @@ int vis_seq_print_text(struct seq_file *seq, void *offset)
int vis_server = atomic_read(bat_priv-vis_mode);
size_t buff_pos, buf_size;
char *buff;
-   int compare;
 
primary_if = primary_if_get_selected(bat_priv);
if (!primary_if)
@@ -228,14 +227,18 @@ int vis_seq_print_text(struct seq_file *seq, void *offset)
entries = (struct vis_info_entry *)
((char *)packet + sizeof(*packet));
 
+   vis_data_insert_interface(packet-vis_orig,
+ vis_if_list, true);
+
for (j = 0; j  packet-entries; j++) {
if (entries[j].quality == 0)
continue;
-   compare =
-compare_eth(entries[j].src, packet-vis_orig);
+   if (compare_eth(entries[j].src,
+   packet-vis_orig))
+   continue;
vis_data_insert_interface(entries[j].src,
  vis_if_list,
- compare);
+ false);
}
 
hlist_for_each_entry(entry, pos, vis_if_list, list) {
@@ -276,14 +279,18 @@ int vis_seq_print_text(struct seq_file *seq, void *offset)
entries = (struct vis_info_entry *)
((char *)packet + sizeof(*packet));
 
+   vis_data_insert_interface(packet-vis_orig,
+ vis_if_list, true);
+
for (j = 0; j  packet-entries; j++) {
if (entries[j].quality == 0)
continue;
-   compare =
-compare_eth(entries[j].src, packet-vis_orig);
+   if (compare_eth(entries[j].src,
+   packet-vis_orig))
+   continue;
vis_data_insert_interface(entries[j].src,
  vis_if_list,
- compare);
+ false);
}
 
hlist_for_each_entry(entry, pos, vis_if_list, list) {
-- 
1.7.9.4



[B.A.T.M.A.N.] [PATCH 16/19] batman-adv: turn tt commit code into routing protocol agnostic API

2012-06-18 Thread Antonio Quartulli
From: Marek Lindner lindner_ma...@yahoo.de

Prior to this patch the translation table code made assumptions about how
the routing protocol works and where its buffers are stored (to directly
modify them).
Each protocol now calls the tt code with the relevant pointers, thereby
abstracting the code.

Signed-off-by: Marek Lindner lindner_ma...@yahoo.de
Acked-by: Antonio Quartulli or...@autistici.org
Signed-off-by: Sven Eckelmann s...@narfation.org
Signed-off-by: Antonio Quartulli or...@autistici.org
---
 net/batman-adv/bat_iv_ogm.c|   14 ++--
 net/batman-adv/send.c  |   74 +
 net/batman-adv/translation-table.c |  124 ++--
 net/batman-adv/translation-table.h |7 +-
 net/batman-adv/types.h |3 +-
 5 files changed, 118 insertions(+), 104 deletions(-)

diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index ec3542c..6e0859f 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -559,22 +559,28 @@ static void bat_iv_ogm_forward(struct orig_node 
*orig_node,
 if_incoming, 0, bat_iv_ogm_fwd_send_time());
 }
 
-static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
-   int tt_num_changes)
+static void bat_iv_ogm_schedule(struct hard_iface *hard_iface)
 {
struct bat_priv *bat_priv = netdev_priv(hard_iface-soft_iface);
struct batman_ogm_packet *batman_ogm_packet;
struct hard_iface *primary_if;
-   int vis_server;
+   int vis_server, tt_num_changes = 0;
 
vis_server = atomic_read(bat_priv-vis_mode);
primary_if = primary_if_get_selected(bat_priv);
 
+   if (hard_iface == primary_if)
+   tt_num_changes = batadv_tt_append_diff(bat_priv,
+  hard_iface-packet_buff,
+  hard_iface-packet_len,
+  BATMAN_OGM_HLEN);
+
batman_ogm_packet = (struct batman_ogm_packet *)hard_iface-packet_buff;
 
/* change sequence number to network order */
batman_ogm_packet-seqno =
htonl((uint32_t)atomic_read(hard_iface-seqno));
+   atomic_inc(hard_iface-seqno);
 
batman_ogm_packet-ttvn = atomic_read(bat_priv-ttvn);
batman_ogm_packet-tt_crc = htons(bat_priv-tt_crc);
@@ -593,8 +599,6 @@ static void bat_iv_ogm_schedule(struct hard_iface 
*hard_iface,
else
batman_ogm_packet-gw_flags = NO_FLAGS;
 
-   atomic_inc(hard_iface-seqno);
-
slide_own_bcast_window(hard_iface);
bat_iv_ogm_queue_add(bat_priv, hard_iface-packet_buff,
 hard_iface-packet_len, hard_iface, 1,
diff --git a/net/batman-adv/send.c b/net/batman-adv/send.c
index f5ff364..79f8973 100644
--- a/net/batman-adv/send.c
+++ b/net/batman-adv/send.c
@@ -77,62 +77,9 @@ send_skb_err:
return NET_XMIT_DROP;
 }
 
-static void realloc_packet_buffer(struct hard_iface *hard_iface,
- int new_len)
-{
-   unsigned char *new_buff;
-
-   new_buff = kmalloc(new_len, GFP_ATOMIC);
-
-   /* keep old buffer if kmalloc should fail */
-   if (new_buff) {
-   memcpy(new_buff, hard_iface-packet_buff,
-  BATMAN_OGM_HLEN);
-
-   kfree(hard_iface-packet_buff);
-   hard_iface-packet_buff = new_buff;
-   hard_iface-packet_len = new_len;
-   }
-}
-
-/* when calling this function (hard_iface == primary_if) has to be true */
-static int prepare_packet_buffer(struct bat_priv *bat_priv,
- struct hard_iface *hard_iface)
-{
-   int new_len;
-
-   new_len = BATMAN_OGM_HLEN +
- tt_len((uint8_t)atomic_read(bat_priv-tt_local_changes));
-
-   /* if we have too many changes for one packet don't send any
-* and wait for the tt table request which will be fragmented */
-   if (new_len  hard_iface-soft_iface-mtu)
-   new_len = BATMAN_OGM_HLEN;
-
-   realloc_packet_buffer(hard_iface, new_len);
-
-   bat_priv-tt_crc = tt_local_crc(bat_priv);
-
-   /* reset the sending counter */
-   atomic_set(bat_priv-tt_ogm_append_cnt, TT_OGM_APPEND_MAX);
-
-   return tt_changes_fill_buffer(bat_priv,
- hard_iface-packet_buff + BATMAN_OGM_HLEN,
- hard_iface-packet_len - BATMAN_OGM_HLEN);
-}
-
-static int reset_packet_buffer(struct bat_priv *bat_priv,
-   struct hard_iface *hard_iface)
-{
-   realloc_packet_buffer(hard_iface, BATMAN_OGM_HLEN);
-   return 0;
-}
-
 void schedule_bat_ogm(struct hard_iface *hard_iface)
 {
struct bat_priv *bat_priv = netdev_priv(hard_iface-soft_iface);
-   struct hard_iface *primary_if;
-   int tt_num_changes = -1;
 
if 

[B.A.T.M.A.N.] [PATCH 17/19] batman-adv: use DBG_ALL in log_level sysfs definition

2012-06-18 Thread Antonio Quartulli
Each time a new log level is added the developer must change either the DBG_ALL
enum definition and the hard coded value in the bat_sysfs.c for the log_level
attribute max value. This is extremely error prone.
With this patch the code directly uses DBG_ALL in the sysfs definition

Signed-off-by: Antonio Quartulli or...@autistici.org
Signed-off-by: Sven Eckelmann s...@narfation.org
---
 net/batman-adv/bat_sysfs.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/batman-adv/bat_sysfs.c b/net/batman-adv/bat_sysfs.c
index 62f4f6c..dc1edbe 100644
--- a/net/batman-adv/bat_sysfs.c
+++ b/net/batman-adv/bat_sysfs.c
@@ -445,7 +445,7 @@ BAT_ATTR_SIF_UINT(gw_sel_class, S_IRUGO | S_IWUSR, 1, 
TQ_MAX_VALUE,
 static BAT_ATTR(gw_bandwidth, S_IRUGO | S_IWUSR, show_gw_bwidth,
store_gw_bwidth);
 #ifdef CONFIG_BATMAN_ADV_DEBUG
-BAT_ATTR_SIF_UINT(log_level, S_IRUGO | S_IWUSR, 0, 15, NULL);
+BAT_ATTR_SIF_UINT(log_level, S_IRUGO | S_IWUSR, 0, DBG_ALL, NULL);
 #endif
 
 static struct bat_attribute *mesh_attrs[] = {
-- 
1.7.9.4



[B.A.T.M.A.N.] [PATCH 19/19] batman-adv: only store changed gw_bandwidth values

2012-06-18 Thread Antonio Quartulli
From: Marek Lindner lindner_ma...@yahoo.de

Signed-off-by: Marek Lindner lindner_ma...@yahoo.de
Signed-off-by: Sven Eckelmann s...@narfation.org
Signed-off-by: Antonio Quartulli or...@autistici.org
---
 net/batman-adv/gateway_common.c |3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/batman-adv/gateway_common.c b/net/batman-adv/gateway_common.c
index ca57ac7..6e3b052 100644
--- a/net/batman-adv/gateway_common.c
+++ b/net/batman-adv/gateway_common.c
@@ -162,6 +162,9 @@ ssize_t gw_bandwidth_set(struct net_device *net_dev, char 
*buff, size_t count)
 **/
gw_bandwidth_to_kbit((uint8_t)gw_bandwidth_tmp, down, up);
 
+   if (atomic_read(bat_priv-gw_bandwidth) == gw_bandwidth_tmp)
+   return count;
+
gw_deselect(bat_priv);
bat_info(net_dev,
 Changing gateway bandwidth from: '%i' to: '%ld' (propagating: 
%d%s/%d%s)\n,
-- 
1.7.9.4



Re: [B.A.T.M.A.N.] pull request: batman-adv 2012-06-18

2012-06-18 Thread David Miller
From: Antonio Quartulli or...@autistici.org
Date: Mon, 18 Jun 2012 22:39:04 +0200

 Hello David,
   here is our first set of changes intended for next-next/linux-3.6.
 
 Patch 2 fixes a major bug in the TranslationTable code where the old value of
 skb-data is used for memory access even if the data was relocated.
 Patches 4, 10, 11, 13, 14 are endianess-related cleanups that we wrote thanks
 to Al Viro's advice and help.
 Thanks to Martin Hundebøll batman-adv now supports the ethtool API and can
 export several counters that are specific to our module (patch 5).
 Then patch 16 improves the routing protocol API by making part of the
 TranslationTable code routing agnostic.
 The rest are minor fixes and other cleanups.

Pulled, thanks.