Re: [B.A.T.M.A.N.] [PATCH] batman-adv: Remove declaration of only locally used functions

2012-02-07 Thread Marek Lindner
On Tuesday, February 07, 2012 06:11:53 Sven Eckelmann wrote:
 The blaII code removed references to two functions outside of the own
 source file. route_unicast_packet can be marked as static since
 9c11509d3bbf914060be1bcb4448ea69d571fcb9 and tt_global_del since
 7c5289cb52a5cecaeeddc719cd52b50bb17263dd

Applied in revision befb4bc.

Thanks,
Marek


[B.A.T.M.A.N.] B.A.T.M.A.N. V - the next steps

2012-02-07 Thread Marek Lindner

Hi folks,

after having the B.A.T.M.A.N. IV routing code moved into one single file, a 
preliminary routing protocol API and an easy to use routing protocol switch it 
is time to move forward with B.A.T.M.A.N. V.

B.A.T.M.A.N. V is going to split the various tasks handled by the B.A.T.M.A.N. 
IV OGM protocol into subprotocols which will allow us to optimize each 
protocol much better. The ELP protocol is the first of these subprotocols to 
come. The initial ideas surrounding this protocol type are more than 2-3 years 
old. At some point Linus was the driving force behind the protocol 
development. Thanks to him we have proper documentation[1] as well as some 
code in his repository[2] (still called ndp). I began rebasing and integrating 
his code [3]. It will take a couple of patch series to get the API and the old 
ELP code base into shape.

Cheers,
Marek

[1] http://www.open-mesh.org/wiki/batman-adv/ELP
[2] http://git.open-mesh.org/?p=t_x/batman-adv.git;a=summary
[3] http://git.open-mesh.org/?p=marek/batman-adv.git;a=summary


[B.A.T.M.A.N.] [PATCH 1/8] batman-adv: move ogm initialization into the proper function

2012-02-07 Thread Marek Lindner
Signed-of-by: Marek Lindner lindner_ma...@yahoo.de
---
 hard-interface.c |8 +++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/hard-interface.c b/hard-interface.c
index 612f2c8..e16c996 100644
--- a/hard-interface.c
+++ b/hard-interface.c
@@ -337,7 +337,6 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
hard_iface-batman_adv_ptype.dev = hard_iface-net_dev;
dev_add_pack(hard_iface-batman_adv_ptype);
 
-   atomic_set(hard_iface-seqno, 1);
atomic_set(hard_iface-frag_seqno, 1);
bat_info(hard_iface-soft_iface, Adding interface: %s\n,
 hard_iface-net_dev-name);
@@ -463,6 +462,13 @@ static struct hard_iface *hardif_add_interface(struct 
net_device *net_dev)
check_known_mac_addr(hard_iface-net_dev);
list_add_tail_rcu(hard_iface-list, hardif_list);
 
+   /**
+* This can't be called via a bat_priv callback because
+* we have no bat_priv yet.
+*/
+   atomic_set(hard_iface-seqno, 1);
+   hard_iface-packet_buff = NULL;
+
return hard_iface;
 
 free_if:
-- 
1.7.5.4



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

2012-02-07 Thread Marek Lindner
Signed-off-by: Marek Lindner lindner_ma...@yahoo.de
---
 bat_iv_ogm.c |7 +++
 hard-interface.c |3 +--
 main.c   |1 +
 types.h  |2 ++
 4 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/bat_iv_ogm.c b/bat_iv_ogm.c
index 4ac2d1d..98c41f5 100644
--- a/bat_iv_ogm.c
+++ b/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;
@@ -1186,6 +1192,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/hard-interface.c b/hard-interface.c
index 4052444..ec2f478 100644
--- a/hard-interface.c
+++ b/hard-interface.c
@@ -409,8 +409,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/main.c b/main.c
index 8bc27e1..c4a9b2b 100644
--- a/main.c
+++ b/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/types.h b/types.h
index c78b925..5e8de0e 100644
--- a/types.h
+++ b/types.h
@@ -371,6 +371,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.5.4



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

2012-02-07 Thread Marek Lindner
Signed-off-by: Marek Lindner lindner_ma...@yahoo.de
---
 bat_iv_ogm.c |   11 ++-
 hard-interface.c |   14 ++
 types.h  |2 +-
 3 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/bat_iv_ogm.c b/bat_iv_ogm.c
index 98c41f5..d944a0b 100644
--- a/bat_iv_ogm.c
+++ b/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;
unsigned long random_seqno;
+   int res = -1;
 
/* randomize initial seqno to avoid collision */
get_random_bytes(random_seqno, sizeof(unsigned long));
@@ -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/hard-interface.c b/hard-interface.c
index ec2f478..d6b25e0 100644
--- a/hard-interface.c
+++ b/hard-interface.c
@@ -310,21 +310,17 @@ int hardif_enable_interface(struct hard_iface *hard_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;
@@ -375,6 +371,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/types.h b/types.h
index 5e8de0e..3df38df 100644
--- a/types.h
+++ b/types.h
@@ -370,7 +370,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.5.4



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

2012-02-07 Thread Marek Lindner
Signed-off-by: Marek Lindner lindner_ma...@yahoo.de
---
 bat_iv_ogm.c |4 ++--
 hard-interface.c |2 +-
 main.c   |2 +-
 types.h  |4 ++--
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/bat_iv_ogm.c b/bat_iv_ogm.c
index d944a0b..b82a772 100644
--- a/bat_iv_ogm.c
+++ b/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;
 
@@ -1202,7 +1202,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/hard-interface.c b/hard-interface.c
index d6b25e0..2a435ec 100644
--- a/hard-interface.c
+++ b/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/main.c b/main.c
index c4a9b2b..87b75a9 100644
--- a/main.c
+++ b/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/types.h b/types.h
index 3df38df..e3d2f1f 100644
--- a/types.h
+++ b/types.h
@@ -373,8 +373,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.5.4



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

2012-02-07 Thread Marek Lindner
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
---
 bat_iv_ogm.c |   12 ++--
 packet.h |2 +-
 routing.c|2 +-
 send.c   |   12 ++--
 4 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/bat_iv_ogm.c b/bat_iv_ogm.c
index b82a772..da93525 100644
--- a/bat_iv_ogm.c
+++ b/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(unsigned long));
atomic_set(hard_iface-seqno, (uint32_t)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);
@@ -163,7 +163,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 *)
@@ -544,7 +544,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());
 }
 
@@ -1184,12 +1184,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/packet.h b/packet.h
index caa12fe..ed16ec3 100644
--- a/packet.h
+++ b/packet.h
@@ -125,7 +125,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/routing.c b/routing.c
index 7b7fcbe..92fe20b 100644
--- a/routing.c
+++ b/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/send.c b/send.c
index 4137580..36e1d27 100644
--- a/send.c
+++ b/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 +
  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_LEN;
+   new_len = BATMAN_OGM_HLEN;
 
realloc_packet_buffer(hard_iface, new_len);
 
@@ -117,14 +117,14 @@ static int 

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

2012-02-07 Thread Marek Lindner
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
---
 bat_iv_ogm.c |4 ++--
 hard-interface.c |2 +-
 packet.h |4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/bat_iv_ogm.c b/bat_iv_ogm.c
index da93525..caa67e4 100644
--- a/bat_iv_ogm.c
+++ b/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;
@@ -942,7 +942,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/hard-interface.c b/hard-interface.c
index 2a435ec..30b1c07 100644
--- a/hard-interface.c
+++ b/hard-interface.c
@@ -617,7 +617,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/packet.h b/packet.h
index ed16ec3..7971a69 100644
--- a/packet.h
+++ b/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.5.4



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

2012-02-07 Thread Marek Lindner
On Tuesday, February 07, 2012 17:33:14 Martin Hundebøll wrote:
 On 2012-02-07 10:20, Marek Lindner wrote:
  Signed-off-by: Marek Lindnerlindner_ma...@yahoo.de
  ---
  
bat_iv_ogm.c |5 +
1 files changed, 5 insertions(+), 0 deletions(-)
  
  diff --git a/bat_iv_ogm.c b/bat_iv_ogm.c
  index 3eff7f0..4ac2d1d 100644
  --- a/bat_iv_ogm.c
  +++ b/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;
  
  +   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);
 
 Wouldn't it be better to cast unsigned long in the call to atomic_set()?

Why should it better ?

Regards,
Marek


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

2012-02-07 Thread Martin Hundebøll

On 2012-02-07 12:10, Marek Lindner wrote:

+   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);


  Wouldn't it be better to cast unsigned long in the call to atomic_set()?

Why should it better ?


Maybe not better, but at least it is consistent with the type of random_seqno, 
which is unsigned long. I know the two types are identical, but nevertheless, I 
like to use the same type of type :)

--
Med venlig hilsen
Martin Hundebøll
Nordborggade 57, 2. 1
8000 Aarhus C

+45 61 65 54 61
mar...@hundeboll.net


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

2012-02-07 Thread Marek Lindner
On Tuesday, February 07, 2012 19:13:27 Martin Hundebøll wrote:
 On 2012-02-07 12:10, Marek Lindner wrote:
  + 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);

Wouldn't it be better to cast unsigned long in the call to
atomic_set()?
  
  Why should it better ?
 
 Maybe not better, but at least it is consistent with the type of
 random_seqno, which is unsigned long. I know the two types are identical,
 but nevertheless, I like to use the same type of type :)

You lost me somewhere. Yes, random_seqno is unsigned long. If we wanted to 
store unsigned long we would not need a cast. 
However, in my kernel the second argument for atomic_set() is int and not 
unsigned long which why we have a cast there.

Regards,
Marek


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

2012-02-07 Thread Andrew Lunn
On Tue, Feb 07, 2012 at 05:20:46PM +0800, Marek Lindner wrote:
 Signed-off-by: Marek Lindner lindner_ma...@yahoo.de
 ---
  bat_iv_ogm.c |5 +
  1 files changed, 5 insertions(+), 0 deletions(-)
 
 diff --git a/bat_iv_ogm.c b/bat_iv_ogm.c
 index 3eff7f0..4ac2d1d 100644
 --- a/bat_iv_ogm.c
 +++ b/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;
 + 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);

Hi Marek

Does this sequence number have any security relevance? Does it make
sense to use the TCP sequence number generation code?

  Andrew


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

2012-02-07 Thread Marek Lindner
On Tuesday, February 07, 2012 20:12:00 Andrew Lunn wrote:
 Does this sequence number have any security relevance? Does it make
 sense to use the TCP sequence number generation code?

There is no security relevance I know of. The idea was simply to start with 
random number. Random is a bit better than 1.  ;-)

Where can I find the TCP sequence number code you are referring to ?

Regards,
Marek


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

2012-02-07 Thread Andrew Lunn
On Tue, Feb 07, 2012 at 08:21:55PM +0800, Marek Lindner wrote:
 On Tuesday, February 07, 2012 20:12:00 Andrew Lunn wrote:
  Does this sequence number have any security relevance? Does it make
  sense to use the TCP sequence number generation code?
 
 There is no security relevance I know of. The idea was simply to start with 
 random number. Random is a bit better than 1.  ;-)
 
 Where can I find the TCP sequence number code you are referring to ?

I had to go find it, since i've never looked at it before.

net/core/secure_seq.c:

__u32 secure_tcp_sequence_number(__be32 saddr, __be32 daddr,
 __be16 sport, __be16 dport)

but it does not look very re-usable, since it takes all these
addresses. What might be usable is:

__u32 secure_ip_id(__be32 daddr)
{
u32 hash[MD5_DIGEST_WORDS];

hash[0] = (__force __u32) daddr;
hash[1] = net_secret[13];
hash[2] = net_secret[14];
hash[3] = net_secret[15];

md5_transform(hash, net_secret);

return hash[0];
}

passing it the last four bytes of the originator MAC address?

Andrew


[B.A.T.M.A.N.] [PATCH] batctl: add bridge loop avoidance code and remove softif_neigh stuff

2012-02-07 Thread Simon Wunderlich
Signed-off-by: Simon Wunderlich s...@hrz.tu-chemnitz.de
---
 debug.c  |6 +++---
 debug.h  |4 ++--
 main.c   |   50 --
 man/batctl.8 |7 +--
 sys.c|   12 
 sys.h|2 ++
 6 files changed, 52 insertions(+), 29 deletions(-)

diff --git a/debug.c b/debug.c
index 6a553ff..155f499 100644
--- a/debug.c
+++ b/debug.c
@@ -61,13 +61,13 @@ void trans_global_usage(void)
printf( \t -w [interval] watch mode - refresh the global translation 
table continuously\n);
 }
 
-void softif_neigh_usage(void)
+void bla_claim_table_usage(void)
 {
-   printf(Usage: batctl [options] softif_neigh \n);
+   printf(Usage: batctl [options] claimtable \n);
printf(options:\n);
printf( \t -h print this help\n);
printf( \t -n don't replace mac addresses with bat-host names\n);
-   printf( \t -w [interval] watch mode - refresh the soft-interface 
neighbor table continuously\n);
+   printf( \t -w [interval] watch mode - refresh the bridge loop 
avoidance claim table continuously\n);
 }
 
 void gateways_usage(void)
diff --git a/debug.h b/debug.h
index 939f281..50d0e24 100644
--- a/debug.h
+++ b/debug.h
@@ -24,7 +24,7 @@
 #define DEBUG_ORIGINATORS originators
 #define DEBUG_TRANSTABLE_LOCAL transtable_local
 #define DEBUG_TRANSTABLE_GLOBAL transtable_global
-#define DEBUG_SOFTIF_NEIGH softif_neigh
+#define DEBUG_BLA_CLAIM_TABLE bla_claim_table
 #define DEBUG_GATEWAYS gateways
 #define DEBUG_VIS_DATA vis_data
 #define DEBUG_LOG log
@@ -32,7 +32,7 @@
 void originators_usage(void);
 void trans_local_usage(void);
 void trans_global_usage(void);
-void softif_neigh_usage(void);
+void bla_claim_table_usage(void);
 void gateways_usage(void);
 int handle_debug_table(char *mesh_iface, int argc, char **argv,
   char *file_path, void table_usage(void));
diff --git a/main.c b/main.c
index 0dfdb8e..86e2078 100644
--- a/main.c
+++ b/main.c
@@ -45,27 +45,28 @@ char module_ver_path[] = /sys/module/batman_adv/version;
 void print_usage(void) {
printf(Usage: batctl [options] commands \n);
printf(commands:\n);
-   printf( \tinterface|if[add|del iface(s)]\tdisplay or modify the 
interface settings\n);
-   printf( \toriginators|o \tdisplay the originator 
table\n);
-   printf( \tinterval|it [orig_interval]   \tdisplay or modify the 
originator interval (in ms)\n);
-   printf( \tloglevel|ll [level]   \tdisplay or modify the 
log level\n);
-   printf( \tlog|l \tread the log produced by 
the kernel module\n);
-   printf( \tgw_mode|gw  [mode]\tdisplay or modify the 
gateway mode\n);
-   printf( \tgateways|gwl  \tdisplay the gateway 
server list\n);
-   printf( \ttranslocal|tl \tdisplay the local 
translation table\n);
-   printf( \ttransglobal|tg\tdisplay the global 
translation table\n);
-   printf( \tsoftif_neigh|sn   \tdisplay the 
soft-interface neighbor table\n);
-   printf( \tvis_mode|vm [mode]\tdisplay or modify the 
status of the VIS server\n);
-   printf( \tvis_data|vd [dot|JSON]\tdisplay the VIS data in 
dot or JSON format\n);
-   printf( \taggregation|ag  [0|1] \tdisplay or modify the 
packet aggregation setting\n);
-   printf( \tbonding|b   [0|1] \tdisplay or modify the 
bonding mode setting\n);
-   printf( \tfragmentation|f [0|1] \tdisplay or modify the 
fragmentation mode setting\n);
-   printf( \tap_isolation|ap [0|1] \tdisplay or modify the ap 
isolation mode setting\n);
+   printf( \tinterface|if   [add|del iface(s)]\tdisplay or 
modify the interface settings\n);
+   printf( \toriginators|o\tdisplay the 
originator table\n);
+   printf( \tinterval|it[orig_interval]   \tdisplay or 
modify the originator interval (in ms)\n);
+   printf( \tloglevel|ll[level]   \tdisplay or 
modify the log level\n);
+   printf( \tlog|l\tread the log 
produced by the kernel module\n);
+   printf( \tgw_mode|gw [mode]\tdisplay or 
modify the gateway mode\n);
+   printf( \tgateways|gwl \tdisplay the 
gateway server list\n);
+   printf( \ttranslocal|tl\tdisplay the 
local translation table\n);
+   printf( \ttransglobal|tg   \tdisplay the 
global translation table\n);
+   printf( \tclaimtable|cl\tdisplay the 
bridge loop avoidance claim table\n);
+   printf( \tvis_mode|vm[mode]\tdisplay or 
modify the status of the VIS server\n);
+   printf(