Re: [B.A.T.M.A.N.] Problem with multi-radio, multi-channel in batman-adv

2012-04-18 Thread puyou.lu
Hi Simon,
I have tried again, and I think the problem is caused by the same ESSID, as you 
said. I used the same ESSID on every wireless cards of every nodes.When I use 
different ESSIDs in different channel, the problem seems diappeared.

Another question, does the two wireless cards(wlan0 and wlan1) of one node have 
any differences in receiving and forwarding unicast and broadcast package? Can 
a gw_client node get IP address from a dhcp server from both wireless cards?

 -Original Message-
 From: b.a.t.m.a.n-boun...@lists.open-mesh.org
 [mailto:b.a.t.m.a.n-boun...@lists.open-mesh.org] On Behalf Of Simon
 Wunderlich
 Sent: Tuesday, April 17, 2012 5:26 PM
 To: The list for a Better Approach To Mobile Ad-hoc Networking
 Subject: Re: [B.A.T.M.A.N.] Problem with multi-radio, multi-channel in
 batman-adv
 
 Hey Puyou,
 
 On Mon, Apr 16, 2012 at 06:35:04PM +0800, puyou.lu wrote:
  Hi guys.
    I’m trying to make a for nodes WMN using four devices with two wireless
 cards each. I would like to use three different channels to reduce the
 interference, like this:
    [Node A]  - channel 1 -  [Node B]  - channel 2 -  [Node C]  -
 channel 3 -  [Node D]
    First I configure eight wireless cards to the specific channel in ad-hoc
 mode using “iw dev wlan0 ibss join …”.
    Then, I think I should add wlan0 and wlan1 to the same batman-adv
 interface (that is bat0) in every device. So I need to configure four nodes
 with the same commands like:
      echo bat0  /sys/class/net/wlan0/batman_adv/mesh_iface
      echo bat0  /sys/class/net/wlan1/batman_adv/mesh_iface
    Last configure an IP address to each bat0. (Node A-10.0.0.1, Node
 B-10.0.0.2, Node C-10.0.0.3, Node D-10.0.0.4).
    But it seem Node A can reach Node B and Node C(using ping), but can’
 t for Node D.
 
    Am I following the right procedure?
    Sorry for my poor English. Any help would be appreciated.
 
 The procedure looks right in general. A few questions to debug:
 
  * do you use different ESSIDs for the IBSS-networks? ad-hoc devices joining
 may override the configured channel
and select another IBSS-network instead when it has the same ESSID.
  * have you confirmed that the WiFi connection works without batman-adv? just
 set up your WiFi, configure different
IP addresses and ping for each hop to test.
  * does the output of batctl originators helps you? Are the other nodes
 displayed on node 4?
 
 Cheers,
   Simon



Re: [B.A.T.M.A.N.] [PATCH 03/11] batman-adv: randomize initial seqno to avoid collision

2012-04-18 Thread Antonio Quartulli
On Tue, Apr 17, 2012 at 10:45:27 -0400, David Miller wrote:
 From: Antonio Quartulli or...@autistici.org
 Date: Tue, 17 Apr 2012 13:58:19 +0200
 
  @@ -33,6 +33,11 @@
   static void bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
   {
  struct batman_ogm_packet *batman_ogm_packet;
  +   unsigned long random_seqno;
  +
  +   /* randomize initial seqno to avoid collision */
  +   get_random_bytes(random_seqno, sizeof(unsigned long));
  +   atomic_set(hard_iface-seqno, (uint32_t)random_seqno);
 
 This is silly.
 
 Just use uint32_t for the type of random_seqno and the sizeof passed
 to get_random_bytes.
 
 And here comes the magic part.
 
 Amazing, no ugly and pointless casts needed!

I agree :-)
Thank you for the suggestion.

Cheers,

-- 
Antonio Quartulli

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


pgpnNiljRKHVb.pgp
Description: PGP signature


Re: [B.A.T.M.A.N.] [PATCH 05/11] batman-adv: handle routing code initialization properly

2012-04-18 Thread Antonio Quartulli
On Tue, Apr 17, 2012 at 10:46:30 -0400, David Miller wrote:
 From: Antonio Quartulli or...@autistici.org
 Date: Tue, 17 Apr 2012 13:58:21 +0200
 
  @@ -30,10 +30,11 @@
   #include send.h
   #include bat_algo.h
   
  -static void bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
  +static int bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
   {
  struct batman_ogm_packet *batman_ogm_packet;
  unsigned long random_seqno;
  +   int res = -1;
   
  /* randomize initial seqno to avoid collision */
  get_random_bytes(random_seqno, sizeof(unsigned long));
 
 Use real error codes, even as a default, instead of meaningless
 values like -1.

Actually all these kind of return values are handled internally the batman-adv
code so we didn't care so much to use real error codes. However using real codes
will surely increase readability.

I will modify this patch and I'll try to suggest other developers to use real
codes too.

Thank you.

-- 
Antonio Quartulli

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


pgp1ISbWxy7n9.pgp
Description: PGP signature


Re: [B.A.T.M.A.N.] [PATCH 10/11] batman-adv: print OGM seq numbers as unsigned long

2012-04-18 Thread Antonio Quartulli
On Tue, Apr 17, 2012 at 10:47:46 -0400, David Miller wrote:
 From: Antonio Quartulli or...@autistici.org
 Date: Tue, 17 Apr 2012 13:58:26 +0200
 
  OGM sequence numbers are declared as uint32_t and so they have to printed
  using %u instead of %d in order to avoid wrong representations.
  
  Signed-off-by: Antonio Quartulli or...@autistici.org
 
 Fix this commit message subject, %u is unsigned int not
 unsigned long
 
 unsigned long would be %lu

Yap. The broken part is %u, because the data type we are going to print is
uint32_t. I'll fix it.

Thank you.

I'll send a new pull request once I'll have fixed these errors.


Cheers,

-- 
Antonio Quartulli

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


pgpSScsrLe00n.pgp
Description: PGP signature


Re: [B.A.T.M.A.N.] [PATCH 10/11] batman-adv: print OGM seq numbers as unsigned long

2012-04-18 Thread David Miller
From: Antonio Quartulli or...@autistici.org
Date: Wed, 18 Apr 2012 09:01:35 +0200

 On Wed, Apr 18, 2012 at 08:47:00AM +0200, Antonio Quartulli wrote:
 On Tue, Apr 17, 2012 at 10:47:46 -0400, David Miller wrote:
  From: Antonio Quartulli or...@autistici.org
  Date: Tue, 17 Apr 2012 13:58:26 +0200
  
   OGM sequence numbers are declared as uint32_t and so they have to printed
   using %u instead of %d in order to avoid wrong representations.
   
   Signed-off-by: Antonio Quartulli or...@autistici.org
  
  Fix this commit message subject, %u is unsigned int not
  unsigned long
  
  unsigned long would be %lu
 
 There is a problem here. On my machine (x86_64) I have:
 
 typedef unsigned int __u32;
 typedef __u32   uint32_t;
 
 
 So I should use %u to print my uint32_t variable (as I reported in my commit
 message).
 
 Probably this is not the case on each and every architecture?
 If so, how could I handle it?

The problem is not the patch, it's your commit message
you say print ... as unsigned long, you're not printing
it as unsigned long, you're printing it as unsigned int.


[B.A.T.M.A.N.] [PATCH] batman-adv: use uint32_t instead of unsigned long to avoid cast

2012-04-18 Thread Antonio Quartulli
Reported-by: David Miller da...@davemloft.net
Signed-off-by: Antonio Quartulli or...@autistici.org
---

This patch is for *next*. It solves a problem pointed out by David S. Miller.
This patch will be squashed with the one which introduced the issue and will be
sent out in the next pull request.

Cheers,


 bat_iv_ogm.c |6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/bat_iv_ogm.c b/bat_iv_ogm.c
index 994369d..ab2085c 100644
--- a/bat_iv_ogm.c
+++ b/bat_iv_ogm.c
@@ -58,12 +58,12 @@ out:
 static int bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
 {
struct batman_ogm_packet *batman_ogm_packet;
-   unsigned long random_seqno;
+   uint32_t random_seqno;
int res = -1;
 
/* randomize initial seqno to avoid collision */
-   get_random_bytes(random_seqno, sizeof(unsigned long));
-   atomic_set(hard_iface-seqno, (uint32_t)random_seqno);
+   get_random_bytes(random_seqno, sizeof(random_seqno));
+   atomic_set(hard_iface-seqno, random_seqno);
 
hard_iface-packet_len = BATMAN_OGM_HLEN;
hard_iface-packet_buff = kmalloc(hard_iface-packet_len, GFP_ATOMIC);
-- 
1.7.9.4



[B.A.T.M.A.N.] [PATCH] batman-adv: use real error codes instead of meaningless -1

2012-04-18 Thread Antonio Quartulli
Reported-by: David Miller da...@davemloft.net
Signed-off-by: Antonio Quartulli or...@autistici.org
---

This patch is for *next*. This patch fixes a problem pointed out by David S.
Miller.

Actually the idea is to use real error codes instead of meaningless -1, even if
this codes are only used internally to the batman-adv code. IMHO it is a good
idea. Most of the times we convert -1 to real error codes later, but I think it
is better to user real code directly. This patch will be squashed with a patch
which is going to be sent in the next pull request.
Another patch which fix the other error codes should follow.

Cheers,


 bat_iv_ogm.c |2 +-
 hard-interface.c |4 +---
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/bat_iv_ogm.c b/bat_iv_ogm.c
index ab2085c..2a1845e 100644
--- a/bat_iv_ogm.c
+++ b/bat_iv_ogm.c
@@ -59,7 +59,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/hard-interface.c b/hard-interface.c
index e647a43..843caa7 100644
--- a/hard-interface.c
+++ b/hard-interface.c
@@ -309,10 +309,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++;
-- 
1.7.9.4



Re: [B.A.T.M.A.N.] [PATCH 1/5] batman-adv: don't delay OGM information announcement

2012-04-18 Thread Martin Hundebøll

Hi Antonio,

One minor/trivial change below.

On 04/18/2012 12:27 AM, Antonio Quartulli wrote:

In the current implementation the OGM is built and filled at the moment it is
scheduled (1 originator interval before its sending). In this way, all the TT
changes happening between OGM(seqno=X) and OGM(seqno=X+1) will be attached to
OGM(seqno=X+2) (because when changes happened OGM(seqno=X+1) was already built).

The result of this strategy is that TT changes are not sent within the
very next OGM, but they are sent within the second OGM since they happened.
This mechanism will introduce a delay for table resync which could lead to
wrong state in case of multiple roamings.

This patch delays all the operations so that the OGM is filled and ultimated
just before being sent.

Signed-off-by: Antonio Quartullior...@autistici.org
---
  bat_iv_ogm.c |  108 ++
  send.c   |   75 ++--
  types.h  |6 ++--
  3 files changed, 99 insertions(+), 90 deletions(-)

diff --git a/bat_iv_ogm.c b/bat_iv_ogm.c
index ed743a4..377ee04 100644
--- a/bat_iv_ogm.c
+++ b/bat_iv_ogm.c
@@ -558,28 +558,97 @@ 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 realloc_packet_buffer(struct hard_iface *hard_iface,
+ int new_len)
  {
-   struct bat_priv *bat_priv = netdev_priv(hard_iface-soft_iface);
+   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 */


Better change that comment te end with */ on a newline, before sending to David 
:)

--
Kind Regards
Martin Hundebøll
Frederiks Allé 99A, 1.th
8000 Aarhus C
Denmark
+45 61 65 54 61
mar...@hundeboll.net


Re: [B.A.T.M.A.N.] [PATCH 1/5] batman-adv: don't delay OGM information announcement

2012-04-18 Thread Antonio Quartulli
On Wed, Apr 18, 2012 at 10:12:42AM +0200, Martin Hundebøll wrote:
 Hi Antonio,
 
 One minor/trivial change below.
 
 On 04/18/2012 12:27 AM, Antonio Quartulli wrote:
  +   /* if we have too many changes for one packet don't send any
  +* and wait for the tt table request which will be fragmented */
 
 Better change that comment te end with */ on a newline, before sending to 
 David :)

I definitely agree. Thank you. I would really like to see this check in
checkpatch.pl :(:(

Cheers,

-- 
Antonio Quartulli

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


pgpjyqtPg2vfG.pgp
Description: PGP signature


Re: [B.A.T.M.A.N.] [PATCH 2/5] batman-adv: clear ADD+DEL (and viceversa) events in the same orig-interval

2012-04-18 Thread Martin Hundebøll

Hi Antonio,

On 04/18/2012 12:27 AM, Antonio Quartulli wrote:

During an OGM-interval (time between two different OGM sendings) the same client
could roam away and then roam back to us. In this case the node would add two
events to the events list (that is going to be sent appended to the next OGM). A
DEL one and an ADD one. Obviously they will only increase the overhead (either 
in
the air and on the receiver side) and eventually trigger wrong states/events
without producing any real effect.

For this reason we can safely delete any ADD event with its related DEL one.

Signed-off-by: Antonio Quartullior...@autistici.org
---
  translation-table.c |   35 ++-
  1 file changed, 30 insertions(+), 5 deletions(-)

diff --git a/translation-table.c b/translation-table.c
index 88e4c8e..e02fa90 100644
--- a/translation-table.c
+++ b/translation-table.c
@@ -154,23 +154,48 @@ static void tt_orig_list_entry_free_ref(struct 
tt_orig_list_entry *orig_entry)
  static void tt_local_event(struct bat_priv *bat_priv, const uint8_t *addr,
   uint8_t flags)
  {
-   struct tt_change_node *tt_change_node;
+   struct tt_change_node *tt_change_node, *entry, *safe;
+   bool event_removed = false;

tt_change_node = kmalloc(sizeof(*tt_change_node), GFP_ATOMIC);
-
if (!tt_change_node)
return;
-
tt_change_node-change.flags = flags;
memcpy(tt_change_node-change.addr, addr, ETH_ALEN);

+   /* check for ADD+DEL or DEL+ADD events */
spin_lock_bh(bat_priv-tt_changes_list_lock);
+   list_for_each_entry_safe(entry, safe,bat_priv-tt_changes_list,
+list) {
+   if (!compare_eth(entry-change.addr, addr))
+   continue;


Please add an empty line here.


+   if (!(!(flags  TT_CLIENT_DEL)  /* ADD op */
+ entry-change.flags  TT_CLIENT_DEL)
+   !(flags  TT_CLIENT_DEL
+ !(entry-change.flags  TT_CLIENT_DEL))) /* ADD op */
+   continue;


This is messy and hard to unerstand. Couldn't you use some tmp vars like this:

int local_del = (flags  TT_CLIENT_DEL) == TT_CLIENT_DEL;
int change_del = (entry-change.flags  TT_CLIENT_DEL) == TT_CLIENT_DEL;

if (local_del == change_del)
continue;

I'm not 100% sure I understood the original if correctly, but that just proofs 
the need to rework it :)


+   /* DEL+ADD in the same orig interval have no effect and can be
+* removed to avoid silly behaviour on the receiver side. The
+* other way around (ADD+DEL) can happen in case of roaming of
+* a client still in the NEW state. Roaming of NEW clients is
+* now possible due to automatically recognition of temporary
+* clients */


Remember newline for */ :)

--
Kind Regards
Martin Hundebøll
Frederiks Allé 99A, 1.th
8000 Aarhus C
Denmark
+45 61 65 54 61
mar...@hundeboll.net


Re: [B.A.T.M.A.N.] [PATCH 1/5] batman-adv: don't delay OGM information announcement

2012-04-18 Thread Martin Hundebøll

On 04/18/2012 10:31 AM, Antonio Quartulli wrote:

On Wed, Apr 18, 2012 at 10:12:42AM +0200, Martin Hundebøll wrote:

Hi Antonio,

One minor/trivial change below.

On 04/18/2012 12:27 AM, Antonio Quartulli wrote:

+   /* if we have too many changes for one packet don't send any
+* and wait for the tt table request which will be fragmented */


Better change that comment te end with */ on a newline, before sending to David 
:)


I definitely agree. Thank you. I would really like to see this check in
checkpatch.pl :(:(


I think you are free to send a patch to checkpatch.pl :)

--
Kind Regards
Martin Hundebøll
Frederiks Allé 99A, 1.th
8000 Aarhus C
Denmark
+45 61 65 54 61
mar...@hundeboll.net


Re: [B.A.T.M.A.N.] [PATCH 2/5] batman-adv: clear ADD+DEL (and viceversa) events in the same orig-interval

2012-04-18 Thread Antonio Quartulli
On Wed, Apr 18, 2012 at 10:33:34AM +0200, Martin Hundebøll wrote:
 Hi Antonio,
 
 On 04/18/2012 12:27 AM, Antonio Quartulli wrote:
  +   /* check for ADD+DEL or DEL+ADD events */
  spin_lock_bh(bat_priv-tt_changes_list_lock);
  +   list_for_each_entry_safe(entry, safe,bat_priv-tt_changes_list,
  +list) {
  +   if (!compare_eth(entry-change.addr, addr))
  +   continue;
 
 Please add an empty line here.

Is this really needed for some specific reason?

 
  +   if (!(!(flags  TT_CLIENT_DEL)  /* ADD op */
  + entry-change.flags  TT_CLIENT_DEL)
  +   !(flags  TT_CLIENT_DEL
  + !(entry-change.flags  TT_CLIENT_DEL))) /* ADD op */
  +   continue;
 
 This is messy and hard to unerstand. Couldn't you use some tmp vars like this:
 
 int local_del = (flags  TT_CLIENT_DEL) == TT_CLIENT_DEL;
 int change_del = (entry-change.flags  TT_CLIENT_DEL) == TT_CLIENT_DEL;
 
 if (local_del == change_del)
   continue;
 
 I'm not 100% sure I understood the original if correctly, but that just 
 proofs the need to rework it :)

eheh, I know I like to mess up the code with boolean formulas :D
Thank you for your feedback, I will simplify it.

 
  +   /* DEL+ADD in the same orig interval have no effect and can be
  +* removed to avoid silly behaviour on the receiver side. The
  +* other way around (ADD+DEL) can happen in case of roaming of
  +* a client still in the NEW state. Roaming of NEW clients is
  +* now possible due to automatically recognition of temporary
  +* clients */
 
 Remember newline for */ :)

yes .-.


Thanks again!


-- 
Antonio Quartulli

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


pgpm8UhUxL87G.pgp
Description: PGP signature


Re: [B.A.T.M.A.N.] [PATCH 1/5] batman-adv: don't delay OGM information announcement

2012-04-18 Thread Antonio Quartulli
On Wed, Apr 18, 2012 at 10:35:44AM +0200, Martin Hundebøll wrote:
 On 04/18/2012 10:31 AM, Antonio Quartulli wrote:
  On Wed, Apr 18, 2012 at 10:12:42AM +0200, Martin Hundebøll wrote:
  Hi Antonio,
 
  One minor/trivial change below.
 
  On 04/18/2012 12:27 AM, Antonio Quartulli wrote:
  + /* if we have too many changes for one packet don't send any
  +  * and wait for the tt table request which will be fragmented */
 
  Better change that comment te end with */ on a newline, before sending to 
  David :)
 
  I definitely agree. Thank you. I would really like to see this check in
  checkpatch.pl :(:(
 
 I think you are free to send a patch to checkpatch.pl :)
 

Good answer :D


-- 
Antonio Quartulli

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


pgp9HWjNALQfq.pgp
Description: PGP signature


Re: [B.A.T.M.A.N.] [PATCH 2/5] batman-adv: clear ADD+DEL (and viceversa) events in the same orig-interval

2012-04-18 Thread Martin Hundebøll

On 04/18/2012 10:37 AM, Antonio Quartulli wrote:

On Wed, Apr 18, 2012 at 10:33:34AM +0200, Martin Hundebøll wrote:

Hi Antonio,

On 04/18/2012 12:27 AM, Antonio Quartulli wrote:

+   /* check for ADD+DEL or DEL+ADD events */
spin_lock_bh(bat_priv-tt_changes_list_lock);
+   list_for_each_entry_safe(entry, safe,bat_priv-tt_changes_list,
+list) {
+   if (!compare_eth(entry-change.addr, addr))
+   continue;


Please add an empty line here.


Is this really needed for some specific reason?


No, but I like it that way :)

--
Kind Regards
Martin Hundebøll
Frederiks Allé 99A, 1.th
8000 Aarhus C
Denmark
+45 61 65 54 61
mar...@hundeboll.net


Re: [B.A.T.M.A.N.] [PATCH 3/5] batman-adv: let tt_global_entry_has_orig() return the orig_entry or NULL instead of 1 or 0 only

2012-04-18 Thread Martin Hundebøll

Hi Antonio,

On 04/18/2012 12:27 AM, Antonio Quartulli wrote:

Instead of returning only 1 or 0 this function has to return the found
orig_entry (if any). In this way, operations that have to to modify the
found orig_entry structure will not need to reiterate over the list again to
find the wanted node.

Signed-off-by: Antonio Quartullior...@autistici.org
---
  translation-table.c |   16 
  1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/translation-table.c b/translation-table.c
index e02fa90..cd6c2dd 100644
--- a/translation-table.c
+++ b/translation-table.c
@@ -543,26 +543,26 @@ static void tt_changes_list_free(struct bat_priv 
*bat_priv)
  }

  /* find out if an orig_node is already in the list of a tt_global_entry.
- * returns 1 if found, 0 otherwise
- */
-static bool tt_global_entry_has_orig(const struct tt_global_entry *entry,
-const struct orig_node *orig_node)
+ * returns NULL if not found, the pointer to the orig_entry otherwise */
+static struct tt_orig_list_entry *tt_global_entry_has_orig(
+   const struct tt_global_entry *entry,
+   const struct orig_node *orig_node)
  {
struct tt_orig_list_entry *tmp_orig_entry;
const struct hlist_head *head;
struct hlist_node *node;
-   bool found = false;
+   struct tt_orig_list_entry *orig_entry = NULL;

rcu_read_lock();
head =entry-orig_list;
hlist_for_each_entry_rcu(tmp_orig_entry, node, head, list) {
if (tmp_orig_entry-orig_node == orig_node) {
-   found = true;
+   orig_entry = tmp_orig_entry;
break;
}
}
rcu_read_unlock();
-   return found;
+   return orig_entry;
  }

  static void tt_global_add_orig_entry(struct tt_global_entry *tt_global_entry,
@@ -1262,7 +1262,7 @@ static int tt_global_valid_entry(const void *entry_ptr, 
const void *data_ptr)
tt_global_entry = container_of(tt_common_entry, struct tt_global_entry,
   common);

-   return tt_global_entry_has_orig(tt_global_entry, orig_node);
+   return (size_t)tt_global_entry_has_orig(tt_global_entry, orig_node);
  }

  static struct sk_buff *tt_response_fill_table(uint16_t tt_len, uint8_t ttvn,


Again, I notice the lack of reference counting, but I guess you already are 
aware of that, and have it on your never ending todo-list :)

--
Kind Regards
Martin Hundebøll
Frederiks Allé 99A, 1.th
8000 Aarhus C
Denmark
+45 61 65 54 61
mar...@hundeboll.net


Re: [B.A.T.M.A.N.] [PATCH 4/5] batman-adv: update ttvn in case of client reannouncement

2012-04-18 Thread Martin Hundebøll

Hi,

On 04/18/2012 12:27 AM, Antonio Quartulli wrote:

in various scenarios it would be possible that a node receives an ADD event for
a client it already knows to belong to the advertiser. In this case the node has
to update the global entry ttvn with the one carried by the OGM.

Signed-off-by: Antonio Quartullior...@autistici.org
---
  translation-table.c |   11 ++-
  1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/translation-table.c b/translation-table.c
index cd6c2dd..ab295ee 100644
--- a/translation-table.c
+++ b/translation-table.c
@@ -593,6 +593,7 @@ int tt_global_add(struct bat_priv *bat_priv, struct 
orig_node *orig_node,
  bool wifi)
  {
struct tt_global_entry *tt_global_entry = NULL;
+   struct tt_orig_list_entry *orig_entry;
int ret = 0;
int hash_added;

@@ -640,9 +641,17 @@ int tt_global_add(struct bat_priv *bat_priv, struct 
orig_node *orig_node,
tt_global_entry-roam_at = 0;
}

-   if (!tt_global_entry_has_orig(tt_global_entry, orig_node))
+   orig_entry = tt_global_entry_has_orig(tt_global_entry,
+ orig_node);
+   if (!orig_entry)
tt_global_add_orig_entry(tt_global_entry, orig_node,
 ttvn);
+   else
+   /* if we are adding global entry, we may want to
+* update the ttvn anyway. Perhaps the global entry is
+* here with a wrong ttvn because it was temporary added
+* before */


One more bad-ending comment block :)

--
Kind Regards
Martin Hundebøll
Frederiks Allé 99A, 1.th
8000 Aarhus C
Denmark
+45 61 65 54 61
mar...@hundeboll.net


Re: [B.A.T.M.A.N.] [PATCH 5/5] batman-adv: beautify tt_global_add() argument list

2012-04-18 Thread Martin Hundebøll

Hi,

On 04/18/2012 12:27 AM, Antonio Quartulli wrote:

Instead of adding a new bool argument each time it is needed, it is
better (and simpler) to pass an 8bit flag argument which contains all the
needed flags

Signed-off-by: Antonio Quartullior...@autistici.org
---
  routing.c   |2 +-
  translation-table.c |   18 ++
  translation-table.h |3 +--
  3 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/routing.c b/routing.c
index 2181a91..22d67bb 100644
--- a/routing.c
+++ b/routing.c
@@ -684,7 +684,7 @@ int recv_roam_adv(struct sk_buff *skb, struct hard_iface 
*recv_if)
roam_adv_packet-src, roam_adv_packet-client);

tt_global_add(bat_priv, orig_node, roam_adv_packet-client,
- atomic_read(orig_node-last_ttvn) + 1, true, false);
+ TT_CLIENT_ROAM, atomic_read(orig_node-last_ttvn) + 1);

/* Roaming phase starts: I have new information but the ttvn has not
 * been incremented yet. This flag will make me check all the incoming
diff --git a/translation-table.c b/translation-table.c
index ab295ee..00757ea 100644
--- a/translation-table.c
+++ b/translation-table.c
@@ -589,8 +589,7 @@ static void tt_global_add_orig_entry(struct tt_global_entry 
*tt_global_entry,

  /* caller must hold orig_node refcount */
  int tt_global_add(struct bat_priv *bat_priv, struct orig_node *orig_node,
- const unsigned char *tt_addr, uint8_t ttvn, bool roaming,
- bool wifi)
+ const unsigned char *tt_addr, uint8_t flags, uint8_t ttvn)
  {
struct tt_global_entry *tt_global_entry = NULL;
struct tt_orig_list_entry *orig_entry;
@@ -600,14 +599,12 @@ int tt_global_add(struct bat_priv *bat_priv, struct 
orig_node *orig_node,
tt_global_entry = tt_global_hash_find(bat_priv, tt_addr);

if (!tt_global_entry) {
-   tt_global_entry = kzalloc(sizeof(*tt_global_entry),
- GFP_ATOMIC);
+   tt_global_entry = kzalloc(sizeof(*tt_global_entry), GFP_ATOMIC);


This trivial style-fix doesn't really belong in this patch, does it? (Not that 
I mind...)


if (!tt_global_entry)
goto out;

memcpy(tt_global_entry-common.addr, tt_addr, ETH_ALEN);
-
-   tt_global_entry-common.flags = NO_FLAGS;
+   tt_global_entry-common.flags = flags;
tt_global_entry-roam_at = 0;
atomic_set(tt_global_entry-common.refcount, 2);

@@ -654,9 +651,6 @@ int tt_global_add(struct bat_priv *bat_priv, struct 
orig_node *orig_node,
orig_entry-ttvn = ttvn;
}

-   if (wifi)
-   tt_global_entry-common.flags |= TT_CLIENT_WIFI;
-
bat_dbg(DBG_TT, bat_priv,
Creating new global tt entry: %pM (via %pM)\n,
tt_global_entry-common.addr, orig_node-orig);
@@ -664,7 +658,7 @@ int tt_global_add(struct bat_priv *bat_priv, struct 
orig_node *orig_node,
  out_remove:
/* remove address from local hash if present */
tt_local_remove(bat_priv, tt_global_entry-common.addr,
-   global tt received, roaming);
+   global tt received, flags  TT_CLIENT_ROAM);
ret = 1;
  out:
if (tt_global_entry)
@@ -1678,9 +1672,9 @@ static void _tt_update_changes(struct bat_priv *bat_priv,
  (tt_change + i)-flags  TT_CLIENT_ROAM);
else
if (!tt_global_add(bat_priv, orig_node,
-  (tt_change + i)-addr, ttvn, false,
+  (tt_change + i)-addr,
   (tt_change + i)-flags
-   TT_CLIENT_WIFI))
+   TT_CLIENT_WIFI, ttvn))


If you use a temporary variable for tt_change + i, you can avoid the last 
indentation and make the code easier to read...

--
Kind Regards
Martin Hundebøll
Frederiks Allé 99A, 1.th
8000 Aarhus C
Denmark
+45 61 65 54 61
mar...@hundeboll.net


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

2012-04-18 Thread Marek Lindner
Reported-by: Andrew Lunn and...@lunn.ch
Signed-off-by: Marek Lindner lindner_ma...@yahoo.de
---
 bat_iv_ogm.c |2 +-
 main.c   |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/bat_iv_ogm.c b/bat_iv_ogm.c
index ed743a4..19da9d5 100644
--- a/bat_iv_ogm.c
+++ b/bat_iv_ogm.c
@@ -1233,7 +1233,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/main.c b/main.c
index 0757c2d..1d338a3 100644
--- a/main.c
+++ b/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.1



[B.A.T.M.A.N.] [PATCH] batman-adv: ignore trailing CR when comparing protocol names

2012-04-18 Thread Marek Lindner
Signed-off-by: Marek Lindner lindner_ma...@yahoo.de
---
 main.c |   11 ---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/main.c b/main.c
index 1d338a3..fa29234 100644
--- a/main.c
+++ b/main.c
@@ -378,14 +378,19 @@ int bat_algo_seq_print_text(struct seq_file *seq, void 
*offset)
 static int param_set_ra(const char *val, const struct kernel_param *kp)
 {
struct bat_algo_ops *bat_algo_ops;
+   char *algo_name = (char *)val;
+   size_t name_len = strlen(algo_name);
 
-   bat_algo_ops = bat_algo_get((char *)val);
+   if (algo_name[name_len - 1] == '\n')
+   algo_name[name_len - 1] = '\0';
+
+   bat_algo_ops = bat_algo_get(algo_name);
if (!bat_algo_ops) {
-   pr_err(Routing algorithm '%s' is not supported\n, val);
+   pr_err(Routing algorithm '%s' is not supported\n, algo_name);
return -EINVAL;
}
 
-   return param_set_copystring(val, kp);
+   return param_set_copystring(algo_name, kp);
 }
 
 static const struct kernel_param_ops param_ops_ra = {
-- 
1.7.9.1



Re: [B.A.T.M.A.N.] [PATCH] batman-adv: use uint32_t instead of unsigned long to avoid cast

2012-04-18 Thread Marek Lindner
On Wednesday, April 18, 2012 15:35:13 Antonio Quartulli wrote:
 Reported-by: David Miller da...@davemloft.net
 Signed-off-by: Antonio Quartulli or...@autistici.org
 ---
 
 This patch is for *next*. It solves a problem pointed out by David S.
 Miller. This patch will be squashed with the one which introduced the
 issue and will be sent out in the next pull request.

Applied in revision 69a69a4.

Thanks,
Marek


Re: [B.A.T.M.A.N.] [PATCH] batman-adv: use real error codes instead of meaningless -1

2012-04-18 Thread Marek Lindner
On Wednesday, April 18, 2012 15:40:40 Antonio Quartulli wrote:
 Reported-by: David Miller da...@davemloft.net
 Signed-off-by: Antonio Quartulli or...@autistici.org
 ---
 
 This patch is for *next*. This patch fixes a problem pointed out by David
 S. Miller.
 
 Actually the idea is to use real error codes instead of meaningless -1,
 even if this codes are only used internally to the batman-adv code. IMHO
 it is a good idea. Most of the times we convert -1 to real error codes
 later, but I think it is better to user real code directly. This patch
 will be squashed with a patch which is going to be sent in the next pull
 request.

Applied in revision a9f3b78.

Thanks,
Marek


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

2012-04-18 Thread Antonio Quartulli
Hello David,

this is the fixed version of my previous pull request (issued on 2012-04-17).
In this patchset the issues you reported have been fixed; moreover I'm
also including two new patches (1/13 and 2/13) which are respectively:

1/13) a fix for Al Viro's report about the missing htons()
2/13) a fix for a wrongly duplicated line in a comment

The following changes since commit ecffe75f934b4e3c5301fe5db278068e0efb0d6b:

  hippi: fix printk format in rrunner.c (2012-04-16 23:48:38 -0400)

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 1e5cc266dbc401d11aefb966ad35e651c2f67414:

  batman-adv: skip the window protection test when the originator has no 
neighbours (2012-04-18 09:54:02 +0200)


Included changes:
* remove duplicated line in comment
* add htons() invocation for tt_crc as suggested by Al Viro
* OriGinator Message seqno initial value is now random
* some cleanups and fixes


Antonio Quartulli (5):
  batman-adv: convert the tt_crc to network order
  batman-adv: remove duplicated line in comment
  batman-adv: use ETH_HLEN instead of sizeof(struct ethhdr)
  batman-adv: print OGM seq numbers as unsigned int
  batman-adv: skip the window protection test when the originator has no 
neighbours

Marek Lindner (8):
  batman-adv: move ogm initialization into the proper function
  batman-adv: refactoring API: find generalized name for bat_ogm_init 
callback
  batman-adv: randomize initial seqno to avoid collision
  batman-adv: add iface_disable() callback to routing API
  batman-adv: handle routing code initialization properly
  batman-adv: refactoring API: find generalized name for 
bat_ogm_init_primary callback
  batman-adv: rename BATMAN_OGM_LEN to BATMAN_OGM_HLEN
  batman-adv: mark existing ogm variables as batman iv

 net/batman-adv/bat_iv_ogm.c|   63 +---
 net/batman-adv/bridge_loop_avoidance.c |   11 ++
 net/batman-adv/hard-interface.c|   33 +
 net/batman-adv/icmp_socket.c   |4 +-
 net/batman-adv/main.c  |5 ++-
 net/batman-adv/packet.h|6 +--
 net/batman-adv/routing.c   |   10 ++---
 net/batman-adv/send.c  |   14 +++
 net/batman-adv/soft-interface.c|2 +-
 net/batman-adv/translation-table.c |2 +-
 net/batman-adv/types.h |   12 +++---
 net/batman-adv/vis.c   |8 ++--
 12 files changed, 96 insertions(+), 74 deletions(-)


[B.A.T.M.A.N.] [PATCH 01/13] batman-adv: convert the tt_crc to network order

2012-04-18 Thread Antonio Quartulli
Before sending out a TT_Request packet we must convert the tt_crc field value
to network order (since it is 16bits long).

Reported-by: Al Viro v...@zeniv.linux.org.uk
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 e16a369..a38d315 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -1339,7 +1339,7 @@ static int send_tt_request(struct bat_priv *bat_priv,
memcpy(tt_request-dst, dst_orig_node-orig, ETH_ALEN);
tt_request-header.ttl = TTL;
tt_request-ttvn = ttvn;
-   tt_request-tt_data = tt_crc;
+   tt_request-tt_data = htons(tt_crc);
tt_request-flags = TT_REQUEST;
 
if (full_table)
-- 
1.7.9.4



[B.A.T.M.A.N.] [PATCH 02/13] batman-adv: remove duplicated line in comment

2012-04-18 Thread Antonio Quartulli
Remove an accidentally added duplicated line in a function comment

Signed-off-by: Antonio Quartulli or...@autistici.org
---
 net/batman-adv/bridge_loop_avoidance.c |1 -
 1 file changed, 1 deletion(-)

diff --git a/net/batman-adv/bridge_loop_avoidance.c 
b/net/batman-adv/bridge_loop_avoidance.c
index 1cf18ac..c8642b5 100644
--- a/net/batman-adv/bridge_loop_avoidance.c
+++ b/net/batman-adv/bridge_loop_avoidance.c
@@ -735,7 +735,6 @@ static int handle_claim(struct bat_priv *bat_priv,
 
 /**
  * @bat_priv: the bat priv with all the soft interface information
- * @bat_priv: the bat priv with all the soft interface information
  * @hw_src: the Hardware source in the ARP Header
  * @hw_dst: the Hardware destination in the ARP Header
  * @ethhdr: pointer to the Ethernet header of the claim frame
-- 
1.7.9.4



[B.A.T.M.A.N.] [PATCH 04/13] batman-adv: refactoring API: find generalized name for bat_ogm_init callback

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

Signed-off-by: Marek Lindner lindner_ma...@yahoo.de
Signed-off-by: Antonio Quartulli or...@autistici.org
---
 net/batman-adv/bat_iv_ogm.c |4 ++--
 net/batman-adv/hard-interface.c |2 +-
 net/batman-adv/main.c   |2 +-
 net/batman-adv/types.h  |4 ++--
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index fab1071..117b831 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -30,7 +30,7 @@
 #include send.h
 #include bat_algo.h
 
-static void bat_iv_ogm_init(struct hard_iface *hard_iface)
+static void bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
 {
struct batman_ogm_packet *batman_ogm_packet;
 
@@ -1169,7 +1169,7 @@ static void bat_iv_ogm_receive(struct hard_iface 
*if_incoming,
 
 static struct bat_algo_ops batman_iv __read_mostly = {
.name = BATMAN IV,
-   .bat_ogm_init = bat_iv_ogm_init,
+   .bat_iface_enable = bat_iv_ogm_iface_enable,
.bat_ogm_init_primary = bat_iv_ogm_init_primary,
.bat_ogm_update_mac = bat_iv_ogm_update_mac,
.bat_ogm_schedule = bat_iv_ogm_schedule,
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index f152007..4d9b85d 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -312,7 +312,7 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
hard_iface-soft_iface = soft_iface;
bat_priv = netdev_priv(hard_iface-soft_iface);
 
-   bat_priv-bat_algo_ops-bat_ogm_init(hard_iface);
+   bat_priv-bat_algo_ops-bat_iface_enable(hard_iface);
 
if (!hard_iface-packet_buff) {
bat_err(hard_iface-soft_iface,
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index e67ca96..ca8f395 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -208,7 +208,7 @@ int bat_algo_register(struct bat_algo_ops *bat_algo_ops)
}
 
/* all algorithms must implement all ops (for now) */
-   if (!bat_algo_ops-bat_ogm_init ||
+   if (!bat_algo_ops-bat_iface_enable ||
!bat_algo_ops-bat_ogm_init_primary ||
!bat_algo_ops-bat_ogm_update_mac ||
!bat_algo_ops-bat_ogm_schedule ||
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index a5b1a63..4b92248 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -377,8 +377,8 @@ struct recvlist_node {
 struct bat_algo_ops {
struct hlist_node list;
char *name;
-   /* init OGM when hard-interface is enabled */
-   void (*bat_ogm_init)(struct hard_iface *hard_iface);
+   /* init routing info when hard-interface is enabled */
+   void (*bat_iface_enable)(struct hard_iface *hard_iface);
/* init primary OGM when primary interface is selected */
void (*bat_ogm_init_primary)(struct hard_iface *hard_iface);
/* init mac addresses of the OGM belonging to this hard-interface */
-- 
1.7.9.4



[B.A.T.M.A.N.] [PATCH 05/13] batman-adv: randomize initial seqno to avoid collision

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

Signed-off-by: Marek Lindner lindner_ma...@yahoo.de
Signed-off-by: Antonio Quartulli or...@autistici.org
---
 net/batman-adv/bat_iv_ogm.c |5 +
 1 file changed, 5 insertions(+)

diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 117b831..95bfc59 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -33,6 +33,11 @@
 static void bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
 {
struct batman_ogm_packet *batman_ogm_packet;
+   uint32_t random_seqno;
+
+   /* randomize initial seqno to avoid collision */
+   get_random_bytes(random_seqno, sizeof(random_seqno));
+   atomic_set(hard_iface-seqno, random_seqno);
 
hard_iface-packet_len = BATMAN_OGM_LEN;
hard_iface-packet_buff = kmalloc(hard_iface-packet_len, GFP_ATOMIC);
-- 
1.7.9.4



[B.A.T.M.A.N.] [PATCH 06/13] batman-adv: add iface_disable() callback to routing API

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

Signed-off-by: Marek Lindner lindner_ma...@yahoo.de
Signed-off-by: Antonio Quartulli or...@autistici.org
---
 net/batman-adv/bat_iv_ogm.c |7 +++
 net/batman-adv/hard-interface.c |3 +--
 net/batman-adv/main.c   |1 +
 net/batman-adv/types.h  |2 ++
 4 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 95bfc59..4cc66db 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -52,6 +52,12 @@ static void bat_iv_ogm_iface_enable(struct hard_iface 
*hard_iface)
batman_ogm_packet-ttvn = 0;
 }
 
+static void bat_iv_ogm_iface_disable(struct hard_iface *hard_iface)
+{
+   kfree(hard_iface-packet_buff);
+   hard_iface-packet_buff = NULL;
+}
+
 static void bat_iv_ogm_init_primary(struct hard_iface *hard_iface)
 {
struct batman_ogm_packet *batman_ogm_packet;
@@ -1175,6 +1181,7 @@ static void bat_iv_ogm_receive(struct hard_iface 
*if_incoming,
 static struct bat_algo_ops batman_iv __read_mostly = {
.name = BATMAN IV,
.bat_iface_enable = bat_iv_ogm_iface_enable,
+   .bat_iface_disable = bat_iv_ogm_iface_disable,
.bat_ogm_init_primary = bat_iv_ogm_init_primary,
.bat_ogm_update_mac = bat_iv_ogm_update_mac,
.bat_ogm_schedule = bat_iv_ogm_schedule,
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index 4d9b85d..fd9715e 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -397,8 +397,7 @@ void hardif_disable_interface(struct hard_iface *hard_iface)
hardif_free_ref(new_if);
}
 
-   kfree(hard_iface-packet_buff);
-   hard_iface-packet_buff = NULL;
+   bat_priv-bat_algo_ops-bat_iface_disable(hard_iface);
hard_iface-if_status = IF_NOT_IN_USE;
 
/* delete all references to this hard_iface */
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index ca8f395..a47a6ce 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -209,6 +209,7 @@ int bat_algo_register(struct bat_algo_ops *bat_algo_ops)
 
/* all algorithms must implement all ops (for now) */
if (!bat_algo_ops-bat_iface_enable ||
+   !bat_algo_ops-bat_iface_disable ||
!bat_algo_ops-bat_ogm_init_primary ||
!bat_algo_ops-bat_ogm_update_mac ||
!bat_algo_ops-bat_ogm_schedule ||
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index 4b92248..b034cf2 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -379,6 +379,8 @@ struct bat_algo_ops {
char *name;
/* init routing info when hard-interface is enabled */
void (*bat_iface_enable)(struct hard_iface *hard_iface);
+   /* de-init routing info when hard-interface is disabled */
+   void (*bat_iface_disable)(struct hard_iface *hard_iface);
/* init primary OGM when primary interface is selected */
void (*bat_ogm_init_primary)(struct hard_iface *hard_iface);
/* init mac addresses of the OGM belonging to this hard-interface */
-- 
1.7.9.4



[B.A.T.M.A.N.] [PATCH 07/13] batman-adv: handle routing code initialization properly

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

Signed-off-by: Marek Lindner lindner_ma...@yahoo.de
Signed-off-by: Antonio Quartulli or...@autistici.org
---
 net/batman-adv/bat_iv_ogm.c |   11 ++-
 net/batman-adv/hard-interface.c |   15 ++-
 net/batman-adv/types.h  |2 +-
 3 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 4cc66db..2714670 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -30,10 +30,11 @@
 #include send.h
 #include bat_algo.h
 
-static void bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
+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;
 
/* randomize initial seqno to avoid collision */
get_random_bytes(random_seqno, sizeof(random_seqno));
@@ -42,6 +43,9 @@ static void bat_iv_ogm_iface_enable(struct hard_iface 
*hard_iface)
hard_iface-packet_len = BATMAN_OGM_LEN;
hard_iface-packet_buff = kmalloc(hard_iface-packet_len, GFP_ATOMIC);
 
+   if (!hard_iface-packet_buff)
+   goto out;
+
batman_ogm_packet = (struct batman_ogm_packet *)hard_iface-packet_buff;
batman_ogm_packet-header.packet_type = BAT_OGM;
batman_ogm_packet-header.version = COMPAT_VERSION;
@@ -50,6 +54,11 @@ static void bat_iv_ogm_iface_enable(struct hard_iface 
*hard_iface)
batman_ogm_packet-tq = TQ_MAX_VALUE;
batman_ogm_packet-tt_num_changes = 0;
batman_ogm_packet-ttvn = 0;
+
+   res = 0;
+
+out:
+   return res;
 }
 
 static void bat_iv_ogm_iface_disable(struct hard_iface *hard_iface)
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index fd9715e..3b391fd 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -304,22 +304,17 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
if (!softif_is_valid(soft_iface)) {
pr_err(Can't create batman mesh interface %s: already exists 
as regular interface\n,
   soft_iface-name);
-   dev_put(soft_iface);
ret = -EINVAL;
-   goto err;
+   goto err_dev;
}
 
hard_iface-soft_iface = soft_iface;
bat_priv = netdev_priv(hard_iface-soft_iface);
 
-   bat_priv-bat_algo_ops-bat_iface_enable(hard_iface);
-
-   if (!hard_iface-packet_buff) {
-   bat_err(hard_iface-soft_iface,
-   Can't add interface packet (%s): out of memory\n,
-   hard_iface-net_dev-name);
+   ret = bat_priv-bat_algo_ops-bat_iface_enable(hard_iface);
+   if (ret  0) {
ret = -ENOMEM;
-   goto err;
+   goto err_dev;
}
 
hard_iface-if_num = bat_priv-num_ifaces;
@@ -363,6 +358,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
 out:
return 0;
 
+err_dev:
+   dev_put(soft_iface);
 err:
hardif_free_ref(hard_iface);
return ret;
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index b034cf2..dd78023 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -378,7 +378,7 @@ struct bat_algo_ops {
struct hlist_node list;
char *name;
/* init routing info when hard-interface is enabled */
-   void (*bat_iface_enable)(struct hard_iface *hard_iface);
+   int (*bat_iface_enable)(struct hard_iface *hard_iface);
/* de-init routing info when hard-interface is disabled */
void (*bat_iface_disable)(struct hard_iface *hard_iface);
/* init primary OGM when primary interface is selected */
-- 
1.7.9.4



[B.A.T.M.A.N.] [PATCH 08/13] batman-adv: refactoring API: find generalized name for bat_ogm_init_primary callback

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

Signed-off-by: Marek Lindner lindner_ma...@yahoo.de
Signed-off-by: Antonio Quartulli or...@autistici.org
---
 net/batman-adv/bat_iv_ogm.c |4 ++--
 net/batman-adv/hard-interface.c |2 +-
 net/batman-adv/main.c   |2 +-
 net/batman-adv/types.h  |4 ++--
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 2714670..c0bdb90 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -67,7 +67,7 @@ static void bat_iv_ogm_iface_disable(struct hard_iface 
*hard_iface)
hard_iface-packet_buff = NULL;
 }
 
-static void bat_iv_ogm_init_primary(struct hard_iface *hard_iface)
+static void bat_iv_ogm_primary_iface_set(struct hard_iface *hard_iface)
 {
struct batman_ogm_packet *batman_ogm_packet;
 
@@ -1191,7 +1191,7 @@ static struct bat_algo_ops batman_iv __read_mostly = {
.name = BATMAN IV,
.bat_iface_enable = bat_iv_ogm_iface_enable,
.bat_iface_disable = bat_iv_ogm_iface_disable,
-   .bat_ogm_init_primary = bat_iv_ogm_init_primary,
+   .bat_primary_iface_set = bat_iv_ogm_primary_iface_set,
.bat_ogm_update_mac = bat_iv_ogm_update_mac,
.bat_ogm_schedule = bat_iv_ogm_schedule,
.bat_ogm_emit = bat_iv_ogm_emit,
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index 3b391fd..75a555b 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -146,7 +146,7 @@ static void primary_if_select(struct bat_priv *bat_priv,
if (!new_hard_iface)
goto out;
 
-   bat_priv-bat_algo_ops-bat_ogm_init_primary(new_hard_iface);
+   bat_priv-bat_algo_ops-bat_primary_iface_set(new_hard_iface);
primary_if_update_addr(bat_priv, curr_hard_iface);
 
 out:
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index a47a6ce..7913272 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -210,7 +210,7 @@ int bat_algo_register(struct bat_algo_ops *bat_algo_ops)
/* all algorithms must implement all ops (for now) */
if (!bat_algo_ops-bat_iface_enable ||
!bat_algo_ops-bat_iface_disable ||
-   !bat_algo_ops-bat_ogm_init_primary ||
+   !bat_algo_ops-bat_primary_iface_set ||
!bat_algo_ops-bat_ogm_update_mac ||
!bat_algo_ops-bat_ogm_schedule ||
!bat_algo_ops-bat_ogm_emit ||
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index dd78023..4d93aad 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -381,8 +381,8 @@ struct bat_algo_ops {
int (*bat_iface_enable)(struct hard_iface *hard_iface);
/* de-init routing info when hard-interface is disabled */
void (*bat_iface_disable)(struct hard_iface *hard_iface);
-   /* init primary OGM when primary interface is selected */
-   void (*bat_ogm_init_primary)(struct hard_iface *hard_iface);
+   /* called when primary interface is selected / changed */
+   void (*bat_primary_iface_set)(struct hard_iface *hard_iface);
/* init mac addresses of the OGM belonging to this hard-interface */
void (*bat_ogm_update_mac)(struct hard_iface *hard_iface);
/* prepare a new outgoing OGM for the send queue */
-- 
1.7.9.4



[B.A.T.M.A.N.] [PATCH 09/13] batman-adv: rename BATMAN_OGM_LEN to BATMAN_OGM_HLEN

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

Using BATMAN_OGM_LEN leaves one with the impression that this is
the full packet size which is not the case. Therefore the variable
is renamed.

Signed-off-by: Marek Lindner lindner_ma...@yahoo.de
Signed-off-by: Antonio Quartulli or...@autistici.org
---
 net/batman-adv/bat_iv_ogm.c |   12 ++--
 net/batman-adv/packet.h |2 +-
 net/batman-adv/routing.c|2 +-
 net/batman-adv/send.c   |   12 ++--
 4 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index c0bdb90..a2af289 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -40,7 +40,7 @@ static int bat_iv_ogm_iface_enable(struct hard_iface 
*hard_iface)
get_random_bytes(random_seqno, sizeof(random_seqno));
atomic_set(hard_iface-seqno, random_seqno);
 
-   hard_iface-packet_len = BATMAN_OGM_LEN;
+   hard_iface-packet_len = BATMAN_OGM_HLEN;
hard_iface-packet_buff = kmalloc(hard_iface-packet_len, GFP_ATOMIC);
 
if (!hard_iface-packet_buff)
@@ -112,7 +112,7 @@ static uint8_t hop_penalty(uint8_t tq, const struct 
bat_priv *bat_priv)
 static int bat_iv_ogm_aggr_packet(int buff_pos, int packet_len,
  int tt_num_changes)
 {
-   int next_buff_pos = buff_pos + BATMAN_OGM_LEN + tt_len(tt_num_changes);
+   int next_buff_pos = buff_pos + BATMAN_OGM_HLEN + tt_len(tt_num_changes);
 
return (next_buff_pos = packet_len) 
(next_buff_pos = MAX_AGGREGATION_BYTES);
@@ -162,7 +162,7 @@ static void bat_iv_ogm_send_to_if(struct forw_packet 
*forw_packet,
batman_ogm_packet-ttvn, hard_iface-net_dev-name,
hard_iface-net_dev-dev_addr);
 
-   buff_pos += BATMAN_OGM_LEN +
+   buff_pos += BATMAN_OGM_HLEN +
tt_len(batman_ogm_packet-tt_num_changes);
packet_num++;
batman_ogm_packet = (struct batman_ogm_packet *)
@@ -540,7 +540,7 @@ static void bat_iv_ogm_forward(struct orig_node *orig_node,
batman_ogm_packet-flags = ~DIRECTLINK;
 
bat_iv_ogm_queue_add(bat_priv, (unsigned char *)batman_ogm_packet,
-BATMAN_OGM_LEN + tt_len(tt_num_changes),
+BATMAN_OGM_HLEN + tt_len(tt_num_changes),
 if_incoming, 0, bat_iv_ogm_fwd_send_time());
 }
 
@@ -1173,12 +1173,12 @@ static void bat_iv_ogm_receive(struct hard_iface 
*if_incoming,
batman_ogm_packet-seqno = ntohl(batman_ogm_packet-seqno);
batman_ogm_packet-tt_crc = ntohs(batman_ogm_packet-tt_crc);
 
-   tt_buff = packet_buff + buff_pos + BATMAN_OGM_LEN;
+   tt_buff = packet_buff + buff_pos + BATMAN_OGM_HLEN;
 
bat_iv_ogm_process(ethhdr, batman_ogm_packet,
   tt_buff, if_incoming);
 
-   buff_pos += BATMAN_OGM_LEN +
+   buff_pos += BATMAN_OGM_HLEN +
tt_len(batman_ogm_packet-tt_num_changes);
 
batman_ogm_packet = (struct batman_ogm_packet *)
diff --git a/net/batman-adv/packet.h b/net/batman-adv/packet.h
index 59800e8..59dec0a 100644
--- a/net/batman-adv/packet.h
+++ b/net/batman-adv/packet.h
@@ -126,7 +126,7 @@ struct batman_ogm_packet {
uint16_t tt_crc;
 } __packed;
 
-#define BATMAN_OGM_LEN sizeof(struct batman_ogm_packet)
+#define BATMAN_OGM_HLEN sizeof(struct batman_ogm_packet)
 
 struct icmp_packet {
struct batman_header header;
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index 78eddc9..ac13a6a 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -254,7 +254,7 @@ int recv_bat_ogm_packet(struct sk_buff *skb, struct 
hard_iface *hard_iface)
struct ethhdr *ethhdr;
 
/* drop packet if it has not necessary minimum size */
-   if (unlikely(!pskb_may_pull(skb, BATMAN_OGM_LEN)))
+   if (unlikely(!pskb_may_pull(skb, BATMAN_OGM_HLEN)))
return NET_RX_DROP;
 
ethhdr = (struct ethhdr *)skb_mac_header(skb);
diff --git a/net/batman-adv/send.c b/net/batman-adv/send.c
index af7a674..b5f078c 100644
--- a/net/batman-adv/send.c
+++ b/net/batman-adv/send.c
@@ -87,7 +87,7 @@ static void realloc_packet_buffer(struct hard_iface 
*hard_iface,
/* keep old buffer if kmalloc should fail */
if (new_buff) {
memcpy(new_buff, hard_iface-packet_buff,
-  BATMAN_OGM_LEN);
+  BATMAN_OGM_HLEN);
 
kfree(hard_iface-packet_buff);
hard_iface-packet_buff = new_buff;
@@ -101,13 +101,13 @@ static int prepare_packet_buffer(struct bat_priv 
*bat_priv,
 {
int new_len;
 
-   new_len = BATMAN_OGM_LEN +
+   new_len = BATMAN_OGM_HLEN +
  

[B.A.T.M.A.N.] [PATCH 10/13] batman-adv: mark existing ogm variables as batman iv

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

The coming protocol changes also will have a part called OGM. That
makes it necessary to introduce a distinction in the code base.

Signed-off-by: Marek Lindner lindner_ma...@yahoo.de
Signed-off-by: Antonio Quartulli or...@autistici.org
---
 net/batman-adv/bat_iv_ogm.c |4 ++--
 net/batman-adv/hard-interface.c |2 +-
 net/batman-adv/packet.h |4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index a2af289..98f7182 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -47,7 +47,7 @@ static int bat_iv_ogm_iface_enable(struct hard_iface 
*hard_iface)
goto out;
 
batman_ogm_packet = (struct batman_ogm_packet *)hard_iface-packet_buff;
-   batman_ogm_packet-header.packet_type = BAT_OGM;
+   batman_ogm_packet-header.packet_type = BAT_IV_OGM;
batman_ogm_packet-header.version = COMPAT_VERSION;
batman_ogm_packet-header.ttl = 2;
batman_ogm_packet-flags = NO_FLAGS;
@@ -934,7 +934,7 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
 * packet in an aggregation.  Here we expect that the padding
 * is always zero (or not 0x01)
 */
-   if (batman_ogm_packet-header.packet_type != BAT_OGM)
+   if (batman_ogm_packet-header.packet_type != BAT_IV_OGM)
return;
 
/* could be changed by schedule_own_packet() */
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index 75a555b..e8c5da3 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -604,7 +604,7 @@ static int batman_skb_recv(struct sk_buff *skb, struct 
net_device *dev,
 
switch (batman_ogm_packet-header.packet_type) {
/* batman originator packet */
-   case BAT_OGM:
+   case BAT_IV_OGM:
ret = recv_bat_ogm_packet(skb, hard_iface);
break;
 
diff --git a/net/batman-adv/packet.h b/net/batman-adv/packet.h
index 59dec0a..f54969c 100644
--- a/net/batman-adv/packet.h
+++ b/net/batman-adv/packet.h
@@ -25,7 +25,7 @@
 #define ETH_P_BATMAN  0x4305   /* unofficial/not registered Ethertype */
 
 enum bat_packettype {
-   BAT_OGM  = 0x01,
+   BAT_IV_OGM   = 0x01,
BAT_ICMP = 0x02,
BAT_UNICAST  = 0x03,
BAT_BCAST= 0x04,
@@ -38,7 +38,7 @@ enum bat_packettype {
 /* this file is included by batctl which needs these defines */
 #define COMPAT_VERSION 14
 
-enum batman_flags {
+enum batman_iv_flags {
PRIMARIES_FIRST_HOP = 1  4,
VIS_SERVER  = 1  5,
DIRECTLINK  = 1  6
-- 
1.7.9.4



[B.A.T.M.A.N.] [PATCH 13/13] batman-adv: skip the window protection test when the originator has no neighbours

2012-04-18 Thread Antonio Quartulli
When we receive an OGM from from a node for the first time, the last_real_seqno
field of the orig_node structure has not been initialised yet. The value of this
field is used to compute the current ogm-seqno window and therefore the
protection mechanism will probably drop the packet due to an out-of-window 
error.
To avoid this situation this patch adds a check to skip the window protection
mechanism if no neighbour nodes have already been added. When the first
neighbour node is added, the last_real_seqno field is initialised too.

Reported-by: Marek Lindner lindner_ma...@yahoo.de
Signed-off-by: Antonio Quartulli or...@autistici.org
---
 net/batman-adv/bat_iv_ogm.c |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 1014210..8b2db2e 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -861,7 +861,8 @@ static int bat_iv_ogm_update_seqnos(const struct ethhdr 
*ethhdr,
seq_diff = batman_ogm_packet-seqno - orig_node-last_real_seqno;
 
/* signalize caller that the packet is to be dropped. */
-   if (window_protected(bat_priv, seq_diff,
+   if (!hlist_empty(orig_node-neigh_list) 
+   window_protected(bat_priv, seq_diff,
 orig_node-batman_seqno_reset))
goto out;
 
-- 
1.7.9.4



[B.A.T.M.A.N.] [PATCH 11/13] batman-adv: use ETH_HLEN instead of sizeof(struct ethhdr)

2012-04-18 Thread Antonio Quartulli
Instead of using sizeof(struct ethhdr) it is strongly recommended to use the
kernel macro ETH_HLEN. This patch substitute each occurrence of the former
expressione with the latter one.

Signed-off-by: Antonio Quartulli or...@autistici.org
---
 net/batman-adv/bat_iv_ogm.c|7 +++
 net/batman-adv/bridge_loop_avoidance.c |   10 --
 net/batman-adv/hard-interface.c|3 +--
 net/batman-adv/icmp_socket.c   |4 ++--
 net/batman-adv/routing.c   |8 
 net/batman-adv/send.c  |2 +-
 net/batman-adv/soft-interface.c|2 +-
 net/batman-adv/types.h |2 +-
 net/batman-adv/vis.c   |8 
 9 files changed, 21 insertions(+), 25 deletions(-)

diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 98f7182..d7fa8af 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -355,10 +355,9 @@ static void bat_iv_ogm_aggregate_new(const unsigned char 
*packet_buff,
if ((atomic_read(bat_priv-aggregated_ogms)) 
(packet_len  MAX_AGGREGATION_BYTES))
forw_packet_aggr-skb = dev_alloc_skb(MAX_AGGREGATION_BYTES +
- sizeof(struct ethhdr));
+ ETH_HLEN);
else
-   forw_packet_aggr-skb = dev_alloc_skb(packet_len +
- sizeof(struct ethhdr));
+   forw_packet_aggr-skb = dev_alloc_skb(packet_len + ETH_HLEN);
 
if (!forw_packet_aggr-skb) {
if (!own_packet)
@@ -366,7 +365,7 @@ static void bat_iv_ogm_aggregate_new(const unsigned char 
*packet_buff,
kfree(forw_packet_aggr);
goto out;
}
-   skb_reserve(forw_packet_aggr-skb, sizeof(struct ethhdr));
+   skb_reserve(forw_packet_aggr-skb, ETH_HLEN);
 
INIT_HLIST_NODE(forw_packet_aggr-list);
 
diff --git a/net/batman-adv/bridge_loop_avoidance.c 
b/net/batman-adv/bridge_loop_avoidance.c
index c8642b5..ad394c6 100644
--- a/net/batman-adv/bridge_loop_avoidance.c
+++ b/net/batman-adv/bridge_loop_avoidance.c
@@ -290,9 +290,7 @@ static void bla_send_claim(struct bat_priv *bat_priv, 
uint8_t *mac,
goto out;
 
ethhdr = (struct ethhdr *)skb-data;
-   hw_src = (uint8_t *)ethhdr +
-sizeof(struct ethhdr) +
-sizeof(struct arphdr);
+   hw_src = (uint8_t *)ethhdr + ETH_HLEN + sizeof(struct arphdr);
 
/* now we pretend that the client would have sent this ... */
switch (claimtype) {
@@ -340,7 +338,7 @@ static void bla_send_claim(struct bat_priv *bat_priv, 
uint8_t *mac,
skb_reset_mac_header(skb);
skb-protocol = eth_type_trans(skb, soft_iface);
bat_priv-stats.rx_packets++;
-   bat_priv-stats.rx_bytes += skb-len + sizeof(struct ethhdr);
+   bat_priv-stats.rx_bytes += skb-len + ETH_HLEN;
soft_iface-last_rx = jiffies;
 
netif_rx(skb);
@@ -844,7 +842,7 @@ static int bla_process_claim(struct bat_priv *bat_priv,
headlen = sizeof(*vhdr);
} else {
proto = ntohs(ethhdr-h_proto);
-   headlen = sizeof(*ethhdr);
+   headlen = ETH_HLEN;
}
 
if (proto != ETH_P_ARP)
@@ -1302,7 +1300,7 @@ int bla_is_backbone_gw(struct sk_buff *skb,
return 0;
 
/* first, find out the vid. */
-   if (!pskb_may_pull(skb, hdr_size + sizeof(struct ethhdr)))
+   if (!pskb_may_pull(skb, hdr_size + ETH_HLEN))
return 0;
 
ethhdr = (struct ethhdr *)(((uint8_t *)skb-data) + hdr_size);
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index e8c5da3..47c79d7 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -574,8 +574,7 @@ static int batman_skb_recv(struct sk_buff *skb, struct 
net_device *dev,
goto err_free;
 
/* expect a valid ethernet header here. */
-   if (unlikely(skb-mac_len != sizeof(struct ethhdr) ||
-!skb_mac_header(skb)))
+   if (unlikely(skb-mac_len != ETH_HLEN || !skb_mac_header(skb)))
goto err_free;
 
if (!hard_iface-soft_iface)
diff --git a/net/batman-adv/icmp_socket.c b/net/batman-adv/icmp_socket.c
index b87518e..2e98a57 100644
--- a/net/batman-adv/icmp_socket.c
+++ b/net/batman-adv/icmp_socket.c
@@ -175,13 +175,13 @@ static ssize_t bat_socket_write(struct file *file, const 
char __user *buff,
if (len = sizeof(struct icmp_packet_rr))
packet_len = sizeof(struct icmp_packet_rr);
 
-   skb = dev_alloc_skb(packet_len + sizeof(struct ethhdr));
+   skb = dev_alloc_skb(packet_len + ETH_HLEN);
if (!skb) {
len = -ENOMEM;
goto out;
}
 
-   skb_reserve(skb, sizeof(struct ethhdr));
+   skb_reserve(skb, 

Re: [B.A.T.M.A.N.] Problem with multi-radio, multi-channel in batman-adv

2012-04-18 Thread Simon Wunderlich
Hi Puyou,

On Wed, Apr 18, 2012 at 02:15:19PM +0800, puyou.lu wrote:
 Hi Simon,
 I have tried again, and I think the problem is caused by the same ESSID, as 
 you said. I used the same ESSID on every wireless cards of every nodes.When I 
 use different ESSIDs in different channel, the problem seems diappeared.
 
 Another question, does the two wireless cards(wlan0 and wlan1) of one node 
 have any differences in receiving and forwarding unicast and broadcast 
 package? Can a gw_client node get IP address from a dhcp server from both 
 wireless cards?

Yes, you use the virtual bat0 interface. Whether the data is transported via 
wlan0 or wlan1 does not matter,
you will always receive the data on bat0.

There is no difference in the usage, and which interface is used is up to 
batman-adv to decide. Please make
sure that you configure all your services like IP addresses, DHCP, etc on bat0 
(or even on bridges above it),
not the wlanX interfaces.

http://www.open-mesh.org/wiki/batman-adv/Quick-start-guide

Cheers,
Simon 


 
  -Original Message-
  From: b.a.t.m.a.n-boun...@lists.open-mesh.org
  [mailto:b.a.t.m.a.n-boun...@lists.open-mesh.org] On Behalf Of Simon
  Wunderlich
  Sent: Tuesday, April 17, 2012 5:26 PM
  To: The list for a Better Approach To Mobile Ad-hoc Networking
  Subject: Re: [B.A.T.M.A.N.] Problem with multi-radio, multi-channel in
  batman-adv
  
  Hey Puyou,
  
  On Mon, Apr 16, 2012 at 06:35:04PM +0800, puyou.lu wrote:
   Hi guys.
     I’m trying to make a for nodes WMN using four devices with two wireless
  cards each. I would like to use three different channels to reduce the
  interference, like this:
     [Node A]  - channel 1 -  [Node B]  - channel 2 -  [Node C]  -
  channel 3 -  [Node D]
     First I configure eight wireless cards to the specific channel in ad-hoc
  mode using “iw dev wlan0 ibss join …”.
     Then, I think I should add wlan0 and wlan1 to the same batman-adv
  interface (that is bat0) in every device. So I need to configure four nodes
  with the same commands like:
       echo bat0  /sys/class/net/wlan0/batman_adv/mesh_iface
       echo bat0  /sys/class/net/wlan1/batman_adv/mesh_iface
     Last configure an IP address to each bat0. (Node A-10.0.0.1, Node
  B-10.0.0.2, Node C-10.0.0.3, Node D-10.0.0.4).
     But it seem Node A can reach Node B and Node C(using ping), but can’
  t for Node D.
  
     Am I following the right procedure?
     Sorry for my poor English. Any help would be appreciated.
  
  The procedure looks right in general. A few questions to debug:
  
   * do you use different ESSIDs for the IBSS-networks? ad-hoc devices joining
  may override the configured channel
 and select another IBSS-network instead when it has the same ESSID.
   * have you confirmed that the WiFi connection works without batman-adv? 
  just
  set up your WiFi, configure different
 IP addresses and ping for each hop to test.
   * does the output of batctl originators helps you? Are the other nodes
  displayed on node 4?
  
  Cheers,
  Simon
 
 


signature.asc
Description: Digital signature


[B.A.T.M.A.N.] [PATCHv3] batman-adv: Add get_ethtool_stats() support

2012-04-18 Thread Martin Hundebøll
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
 management packets (OGMs at this point)
 translation table packets
 distributed arp table packets

I would like you all to check if the increments are added at the right
locations and also if more counters would be relevant. (E.g. in bridge
loop avoidance code?)

This is the reworked approach from the previous stat counters patch I
send, where ethtool stats was suggested.

v2: Changed to per_cpu variables. Added ifdefs for optional submodules.
v3: Change from struct bat_stats to uint64_t array.

Signed-off-by: Martin Hundebøll mar...@hundeboll.net
---
 bat_iv_ogm.c|6 -
 distributed-arp-table.c |8 +-
 main.h  |   24 +
 routing.c   |9 +++
 soft-interface.c|   67 +--
 translation-table.c |8 ++
 types.h |   20 ++
 7 files changed, 138 insertions(+), 4 deletions(-)

diff --git a/bat_iv_ogm.c b/bat_iv_ogm.c
index 994369d..5758a21 100644
--- a/bat_iv_ogm.c
+++ b/bat_iv_ogm.c
@@ -196,8 +196,10 @@ 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) {
+   inc_counter(bat_priv, BAT_CNT_MGMT_TX);
send_skb_packet(skb, hard_iface, broadcast_addr);
+   }
 }
 
 /* send a batman ogm packet */
@@ -956,6 +958,8 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
if (batman_ogm_packet-header.packet_type != BAT_IV_OGM)
return;
 
+   inc_counter(bat_priv, BAT_CNT_MGMT_RX);
+
/* could be changed by schedule_own_packet() */
if_incoming_seqno = atomic_read(if_incoming-seqno);
 
diff --git a/distributed-arp-table.c b/distributed-arp-table.c
index b43bece..a2d3821 100644
--- a/distributed-arp-table.c
+++ b/distributed-arp-table.c
@@ -395,9 +395,11 @@ bool dat_snoop_outgoing_arp_request(struct bat_priv 
*bat_priv,
 
netif_rx(skb_new);
bat_dbg(DBG_DAT, bat_priv, ARP request replied locally\n);
-   } else
+   } else {
/* Send the request on the DHT */
+   inc_counter(bat_priv, BAT_CNT_DAT_REQUEST_TX);
ret = dht_send_data(bat_priv, skb, ip_dst, BAT_P_DAT_DHT_GET);
+   }
 out:
if (n)
neigh_release(n);
@@ -450,6 +452,8 @@ bool dat_snoop_incoming_arp_request(struct bat_priv 
*bat_priv,
if (!skb_new)
goto out;
 
+   inc_counter(bat_priv, BAT_CNT_DAT_REPLY_TX);
+
unicast_4addr_send_skb(skb_new, bat_priv, BAT_P_DAT_CACHE_REPLY);
 
ret = true;
@@ -488,6 +492,8 @@ bool dat_snoop_outgoing_arp_reply(struct bat_priv *bat_priv,
arp_neigh_update(bat_priv, ip_src, hw_src);
arp_neigh_update(bat_priv, ip_dst, hw_dst);
 
+   inc_counter(bat_priv, BAT_CNT_DAT_REPLY_TX);
+
/* Send the ARP reply to the candidates for both the IP addresses we
 * fetched from the ARP reply */
dht_send_data(bat_priv, skb, ip_src, BAT_P_DAT_DHT_PUT);
diff --git a/main.h b/main.h
index c8bfe28..bb4baa1 100644
--- a/main.h
+++ b/main.h
@@ -150,6 +150,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
@@ -259,4 +260,27 @@ 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 inc_counter(struct bat_priv *bat_priv, size_t idx)
+{
+   int cpu = get_cpu();
+   per_cpu_ptr(bat_priv-bat_counters, cpu)[idx]++;
+   put_cpu();
+}
+
+/* Sum and return the cpu-local counters for index 'idx' */
+static inline uint64_t 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/routing.c b/routing.c
index 795d3af..c984cc3 100644
--- a/routing.c
+++ b/routing.c
@@ -600,6 +600,8 @@ int recv_tt_query(struct sk_buff *skb, struct hard_iface 
*recv_if)
 
switch (tt_query-flags  TT_QUERY_TYPE_MASK) {
case TT_REQUEST:
+   inc_counter(bat_priv, BAT_CNT_TT_REQUEST_RX);
+
/* If we cannot provide an answer the 

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

2012-04-18 Thread David Miller
From: Antonio Quartulli or...@autistici.org
Date: Wed, 18 Apr 2012 11:59:57 +0200

 this is the fixed version of my previous pull request (issued on 2012-04-17).
 In this patchset the issues you reported have been fixed; moreover I'm
 also including two new patches (1/13 and 2/13) which are respectively:
 
 1/13) a fix for Al Viro's report about the missing htons()
 2/13) a fix for a wrongly duplicated line in a comment
 
 The following changes since commit ecffe75f934b4e3c5301fe5db278068e0efb0d6b:
 
   hippi: fix printk format in rrunner.c (2012-04-16 23:48:38 -0400)
 
 are available in the git repository at:
 
   git://git.open-mesh.org/linux-merge.git tags/batman-adv-for-davem

This looks a lot better, pulled, thanks!


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

2012-04-18 Thread Al Viro
On Wed, Apr 18, 2012 at 11:59:57AM +0200, Antonio Quartulli wrote:
 Hello David,
 
 this is the fixed version of my previous pull request (issued on 2012-04-17).
 In this patchset the issues you reported have been fixed; moreover I'm
 also including two new patches (1/13 and 2/13) which are respectively:
 
 1/13) a fix for Al Viro's report about the missing htons()

Speaking of endianness stuff: here's a series of 4 patches on top of
your merge.git/master, hopefully getting all that stuff endian-clean,
at least from the sparse POV.  And AFAICS all on-the-wire stuff is
correctly annotated...


[B.A.T.M.A.N.] [PATCH 1/4] batman: don't bother flipping -tt_data

2012-04-18 Thread Al Viro
just keep it net-endian all along

Signed-off-by: Al Viro v...@zeniv.linux.org.uk
---
 net/batman-adv/packet.h|2 +-
 net/batman-adv/routing.c   |6 +-
 net/batman-adv/translation-table.c |8 
 3 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/net/batman-adv/packet.h b/net/batman-adv/packet.h
index 307dbb3..9157f7c 100644
--- a/net/batman-adv/packet.h
+++ b/net/batman-adv/packet.h
@@ -220,7 +220,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 2181a91..4310cfe 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -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:
/* If we cannot provide an answer the tt_request is
@@ -607,7 +605,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;
@@ -618,7 +615,7 @@ int recv_tt_query(struct sk_buff *skb, struct hard_iface 
*recv_if)
if (skb_linearize(skb)  0)
goto out;
 
-   tt_len = tt_query-tt_data * sizeof(struct tt_change);
+   tt_len = ntohs(tt_query-tt_data) * sizeof(struct 
tt_change);
 
/* Ensure we have all the claimed data */
if (unlikely(skb_headlen(skb) 
@@ -631,7 +628,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 88e4c8e..a9c2b59 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -1416,7 +1416,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 */
@@ -1672,7 +1672,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);
@@ -1727,7 +1727,7 @@ 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 */
@@ -1741,7 +1741,7 @@ void handle_tt_response(struct bat_priv *bat_priv,
if (tt_response-flags  TT_FULL_TABLE)
tt_fill_gtable(bat_priv, tt_response);
else
-   tt_update_changes(bat_priv, orig_node, tt_response-tt_data,
+   tt_update_changes(bat_priv, orig_node, 
ntohs(tt_response-tt_data),
  tt_response-ttvn,
  (struct tt_change *)(tt_response + 1));
 
-- 
1.7.2.5



[B.A.T.M.A.N.] [PATCH 2/4] batman: don't bother flipping -tt_crc

2012-04-18 Thread Al Viro
Again, keep -tt_crc in batman_ogv_packet net-endian

Signed-off-by: Al Viro v...@zeniv.linux.org.uk
---
 net/batman-adv/bat_iv_ogm.c |6 ++
 net/batman-adv/packet.h |2 +-
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index ab2085c..5aa8861 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -544,7 +544,6 @@ static void bat_iv_ogm_forward(struct orig_node *orig_node,
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 */
batman_ogm_packet-flags = ~PRIMARIES_FIRST_HOP;
@@ -722,7 +721,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,
@@ -969,7 +968,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, 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);
@@ -1214,7 +1213,6 @@ static int bat_iv_ogm_receive(struct sk_buff *skb,
/* network to host order for our 32bit seqno and the
   orig_interval */
batman_ogm_packet-seqno = ntohl(batman_ogm_packet-seqno);
-   batman_ogm_packet-tt_crc = ntohs(batman_ogm_packet-tt_crc);
 
tt_buff = packet_buff + buff_pos + BATMAN_OGM_HLEN;
 
diff --git a/net/batman-adv/packet.h b/net/batman-adv/packet.h
index 9157f7c..61a7fe0 100644
--- a/net/batman-adv/packet.h
+++ b/net/batman-adv/packet.h
@@ -132,7 +132,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.2.5



[B.A.T.M.A.N.] batman: keep batman_ogm_packet -seqno net-endian all along

2012-04-18 Thread Al Viro
Ditto for its -seqno...

Signed-off-by: Al Viro v...@zeniv.linux.org.uk
---
 net/batman-adv/bat_iv_ogm.c |   25 ++---
 net/batman-adv/packet.h |2 +-
 2 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 5aa8861..cc6d4c3 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -34,11 +34,11 @@ 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 = neigh_node_new(hard_iface, neigh_addr, seqno);
+   neigh_node = neigh_node_new(hard_iface, neigh_addr, ntohl(seqno));
if (!neigh_node)
goto out;
 
@@ -543,8 +543,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);
-
/* switch of primaries first hop flag when forwarding */
batman_ogm_packet-flags = ~PRIMARIES_FIRST_HOP;
if (is_single_hop_neigh)
@@ -868,13 +866,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) 
@@ -888,7 +887,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))
@@ -910,8 +909,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;
@@ -967,7 +966,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, ntohs(batman_ogm_packet-tt_crc),
batman_ogm_packet-tt_num_changes, batman_ogm_packet-tq,
batman_ogm_packet-header.ttl,
@@ -1039,7 +1038,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);
@@ -1132,7 +1131,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 == ntohl(batman_ogm_packet-seqno)) 
  (orig_node-last_ttl - 3 = batman_ogm_packet-header.ttl
bat_iv_ogm_orig_update(bat_priv, orig_node, 

[B.A.T.M.A.N.] batman: trivial endianness annotations

2012-04-18 Thread Al Viro
Missing endianness annotations - on-the-wire data and ip addresses.
BTW, casting memcpy() arguments to (uint8_t *) is cargo-cult programming -
they are void *, which is precisely take any pointer to object...

Signed-off-by: Al Viro v...@zeniv.linux.org.uk
---
 net/batman-adv/bridge_loop_avoidance.c |8 
 net/batman-adv/distributed-arp-table.c |   16 
 net/batman-adv/distributed-arp-table.h |4 ++--
 net/batman-adv/packet.h|   12 ++--
 4 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/net/batman-adv/bridge_loop_avoidance.c 
b/net/batman-adv/bridge_loop_avoidance.c
index 8bf9751..d51288b 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,11 +506,11 @@ 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);
-   memcpy(mac[4], (uint8_t *)crc, 2);
+   memcpy(mac[4], crc, 2);
 
bla_send_claim(bat_priv, mac, backbone_gw-vid, CLAIM_TYPE_ANNOUNCE);
 
@@ -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/distributed-arp-table.c 
b/net/batman-adv/distributed-arp-table.c
index b43bece..d87f914 100644
--- a/net/batman-adv/distributed-arp-table.c
+++ b/net/batman-adv/distributed-arp-table.c
@@ -192,7 +192,7 @@ static void choose_next_candidate(struct bat_priv *bat_priv,
  *
  * return an array of size DHT_CANDIDATES_NUM */
 static struct dht_candidate *dht_select_candidates(struct bat_priv *bat_priv,
-  uint32_t ip_dst)
+  __be32 ip_dst)
 {
int select;
dat_addr_t last_max = DAT_ADDR_MAX, ip_key;
@@ -224,7 +224,7 @@ static struct dht_candidate *dht_select_candidates(struct 
bat_priv *bat_priv,
  * If the packet is successfully sent to at least one candidate, then this
  * function returns true */
 static bool dht_send_data(struct bat_priv *bat_priv, struct sk_buff *skb,
- uint32_t ip, int packet_subtype)
+ __be32 ip, int packet_subtype)
 {
int i;
bool ret = false;
@@ -270,7 +270,7 @@ out:
 /* Update the neighbour entry corresponding to the IP passed as parameter with
  * the hw address hw. If the neighbour entry doesn't exists, then it will be
  * created */
-static void arp_neigh_update(struct bat_priv *bat_priv, uint32_t ip,
+static void arp_neigh_update(struct bat_priv *bat_priv, __be32 ip,
 uint8_t *hw)
 {
struct neighbour *n = NULL;
@@ -299,7 +299,7 @@ static uint16_t arp_get_type(struct bat_priv *bat_priv, 
struct sk_buff *skb,
 {
struct arphdr *arphdr;
struct ethhdr *ethhdr;
-   uint32_t ip_src, ip_dst;
+   __be32 ip_src, ip_dst;
uint16_t type = 0;
 
/* pull the ethernet header */
@@ -352,7 +352,7 @@ bool dat_snoop_outgoing_arp_request(struct bat_priv 
*bat_priv,
struct sk_buff *skb)
 {
uint16_t type = 0;
-   uint32_t ip_dst, ip_src;
+   __be32 ip_dst, ip_src;
uint8_t *hw_src;
bool ret = false;
struct neighbour *n = NULL;
@@ -414,7 +414,7 @@ bool dat_snoop_incoming_arp_request(struct bat_priv 
*bat_priv,
struct sk_buff *skb, int hdr_size)
 {
uint16_t type;
-   uint32_t ip_src, ip_dst;
+   __be32 ip_src, ip_dst;
uint8_t *hw_src;
struct hard_iface *primary_if = NULL;
struct sk_buff *skb_new;
@@ -470,7 +470,7 @@ bool dat_snoop_outgoing_arp_reply(struct bat_priv *bat_priv,
  struct sk_buff *skb)
 {
uint16_t type;
-   uint32_t ip_src, ip_dst;
+   __be32 ip_src, ip_dst;
uint8_t *hw_src, *hw_dst;
bool ret = false;
 
@@ -503,7 +503,7 @@ bool dat_snoop_incoming_arp_reply(struct bat_priv *bat_priv,
  struct sk_buff *skb, int hdr_size)
 {
uint16_t type;
-   uint32_t ip_src, ip_dst;
+   __be32 ip_src, ip_dst;
uint8_t *hw_src, *hw_dst;
bool ret = false;
 
diff --git 

Re: [B.A.T.M.A.N.] batman: keep batman_ogm_packet -seqno net-endian all along

2012-04-18 Thread Al Viro
grr... this one would be 3/4 and the last (trivial endianness annotations) -
4/4.  My apologies...


Re: [B.A.T.M.A.N.] Problem with multi-radio, multi-channel in batman-adv

2012-04-18 Thread Guido Iribarren
Hi!
I guess you're planning a two.radio mesh to improve troughput.
I recently went trough a similar experience and learnt thanks to this list,
turns out, this might sound counterintuitive at first, but in some
setups, using just 2 channels, spaced further apart, will avoid
interference better than 3 ('almost') overlapping channels.
I.e. Using channel 1 and 11 works better than 1 and 6.

I'm assuming you're not using 5.8g , etc

I suggest you to check a thread on this list last month archives,
'bandwidth degradation on p2p links', there are some interesting
references to read on the subject.

On 4/16/12, puyou.lu puyou...@gmail.com wrote:
 Hi guys.
   I’m trying to make a for nodes WMN using four devices with two wireless
 cards each. I would like to use three different channels to reduce the
 interference, like this:
   [Node A]  - channel 1 -  [Node B]  - channel 2 -  [Node C]  - channel
 3 -  [Node D]
   First I configure eight wireless cards to the specific channel in ad-hoc
 mode using “iw dev wlan0 ibss join …”.
   Then, I think I should add wlan0 and wlan1 to the same batman-adv
 interface (that is bat0) in every device. So I need to configure four nodes
 with the same commands like:
     echo bat0  /sys/class/net/wlan0/batman_adv/mesh_iface
     echo bat0  /sys/class/net/wlan1/batman_adv/mesh_iface
   Last configure an IP address to each bat0. (Node A-10.0.0.1, Node
 B-10.0.0.2, Node C-10.0.0.3, Node D-10.0.0.4).
   But it seem Node A can reach Node B and Node C(using ping), but can’t for
 Node D.

   Am I following the right procedure?
   Sorry for my poor English. Any help would be appreciated.

 Puyou Lu.





Re: [B.A.T.M.A.N.] Determining on which node a client is connected to

2012-04-18 Thread Mitar
Hi!

Thank you all for all your answers. They really help me a lot!

On Tue, Apr 17, 2012 at 2:22 PM, Antonio Quartulli or...@autistici.org wrote:
 However, I didn't get why you need the node MAC.

I think there was some misunderstand. I would just like to know on
which node a client is connected to. And as I understand, this is
globally shared between all nodes so I can just inspect this on one
node through global translation table. But for client I begin with the
IP. So with DHCP, I can get client's MAC, and from there I look into
global translation table. This tells me where the client is.


Mitar


Re: [B.A.T.M.A.N.] [PATCH 2/4] batman: don't bother flipping -tt_crc

2012-04-18 Thread Antonio Quartulli
On Wed, Apr 18, 2012 at 07:10:58 +0100, Al Viro wrote:
 @@ -722,7 +721,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 we don't need to flip tt_crc, wy are you introducing ntohs here? Am I
overlooking something?

 @@ -969,7 +968,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, 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,

The same here..I am not understanding..

Thank you for your patches!

Cheers,


-- 
Antonio Quartulli

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


pgp9M82l1pMNf.pgp
Description: PGP signature


Re: [B.A.T.M.A.N.] [PATCH 2/4] batman: don't bother flipping -tt_crc

2012-04-18 Thread Antonio Quartulli
On Thu, Apr 19, 2012 at 07:41:14AM +0200, Antonio Quartulli wrote:
 On Wed, Apr 18, 2012 at 07:10:58 +0100, Al Viro wrote:
  @@ -722,7 +721,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 we don't need to flip tt_crc, wy are you introducing ntohs here? Am I
 overlooking something?

Ok. I was missing the correct meaning of __be16. Now everything is clear.


Cheers,

-- 
Antonio Quartulli

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


pgp38pKtieWUs.pgp
Description: PGP signature