[B.A.T.M.A.N.] [RFC] batman-adv: Set special lockdep classes to avoid lockdep warning

2012-08-19 Thread Sven Eckelmann
[text will be added after I am awake... maybe]

[Should be fix the problem found in bug 162... formerly known as 161. code
stolen from macvlan... this is just a reimplementation of a solution proposed
by Simon Wunderlich]

Reported-by: Linus Lüssing linus.luess...@web.de
Signed-off-by: Sven Eckelmann s...@narfation.org
---
 soft-interface.c |   29 +
 1 file changed, 29 insertions(+)

diff --git a/soft-interface.c b/soft-interface.c
index 1aee7db..588c6f6 100644
--- a/soft-interface.c
+++ b/soft-interface.c
@@ -344,7 +344,36 @@ out:
return;
 }
 
+/*
+ * batman-adv network devices have devices nesting below it and are a special
+ * super class of normal network devices; split their locks off into a
+ * separate class since they always nest.
+ */
+static struct lock_class_key batadv_netdev_xmit_lock_key;
+static struct lock_class_key batadv_netdev_addr_lock_key;
+
+static void batadv_set_lockdep_class_one(struct net_device *dev,
+struct netdev_queue *txq,
+void *_unused)
+{
+   lockdep_set_class(txq-_xmit_lock, batadv_netdev_xmit_lock_key);
+}
+
+static void batadv_set_lockdep_class(struct net_device *dev)
+{
+   lockdep_set_class(dev-addr_list_lock, batadv_netdev_addr_lock_key);
+   netdev_for_each_tx_queue(dev, batadv_set_lockdep_class_one, NULL);
+}
+
+static int batadv_softif_init(struct net_device *dev)
+{
+   batadv_set_lockdep_class(dev);
+
+   return 0;
+}
+
 static const struct net_device_ops batadv_netdev_ops = {
+   .ndo_init = batadv_softif_init,
.ndo_open = batadv_interface_open,
.ndo_stop = batadv_interface_release,
.ndo_get_stats = batadv_interface_stats,
-- 
1.7.10.4



Re: [B.A.T.M.A.N.] [RFC] batman-adv: Set special lockdep classes to avoid lockdep warning

2012-08-19 Thread Simon Wunderlich
Hey Sven,

it works in my QEMU machines (and I could reproduce the bug report from 162).

Acked-by: Simon Wunderlich s...@hrz.tu-chemnitz.de
(provided you add some sane commit message. ;] )


Cheers,
Simon


On Sun, Aug 19, 2012 at 09:29:53AM +0200, Sven Eckelmann wrote:
 [text will be added after I am awake... maybe]
 
 [Should be fix the problem found in bug 162... formerly known as 161. code
 stolen from macvlan... this is just a reimplementation of a solution proposed
 by Simon Wunderlich]
 
 Reported-by: Linus Lüssing linus.luess...@web.de
 Signed-off-by: Sven Eckelmann s...@narfation.org
 ---
  soft-interface.c |   29 +
  1 file changed, 29 insertions(+)
 
 diff --git a/soft-interface.c b/soft-interface.c
 index 1aee7db..588c6f6 100644
 --- a/soft-interface.c
 +++ b/soft-interface.c
 @@ -344,7 +344,36 @@ out:
   return;
  }
  
 +/*
 + * batman-adv network devices have devices nesting below it and are a special
 + * super class of normal network devices; split their locks off into a
 + * separate class since they always nest.
 + */
 +static struct lock_class_key batadv_netdev_xmit_lock_key;
 +static struct lock_class_key batadv_netdev_addr_lock_key;
 +
 +static void batadv_set_lockdep_class_one(struct net_device *dev,
 +  struct netdev_queue *txq,
 +  void *_unused)
 +{
 + lockdep_set_class(txq-_xmit_lock, batadv_netdev_xmit_lock_key);
 +}
 +
 +static void batadv_set_lockdep_class(struct net_device *dev)
 +{
 + lockdep_set_class(dev-addr_list_lock, batadv_netdev_addr_lock_key);
 + netdev_for_each_tx_queue(dev, batadv_set_lockdep_class_one, NULL);
 +}
 +
 +static int batadv_softif_init(struct net_device *dev)
 +{
 + batadv_set_lockdep_class(dev);
 +
 + return 0;
 +}
 +
  static const struct net_device_ops batadv_netdev_ops = {
 + .ndo_init = batadv_softif_init,
   .ndo_open = batadv_interface_open,
   .ndo_stop = batadv_interface_release,
   .ndo_get_stats = batadv_interface_stats,
 -- 
 1.7.10.4
 
 


signature.asc
Description: Digital signature


[B.A.T.M.A.N.] [RFC] batman-adv: don't allow ECTP traffic on batman-adv

2012-08-19 Thread Simon Wunderlich
We have seen this to break networks when used with bridge loop
avoidance. As we can't see any benefit from sending these ancient frames
via our mesh, we just drop them.

Signed-off-by: Simon Wunderlich s...@hrz.tu-chemnitz.de
---
 soft-interface.c |   12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/soft-interface.c b/soft-interface.c
index 1aee7db..f04a605 100644
--- a/soft-interface.c
+++ b/soft-interface.c
@@ -143,8 +143,10 @@ static int batadv_interface_tx(struct sk_buff *skb,
struct batadv_bcast_packet *bcast_packet;
struct vlan_ethhdr *vhdr;
__be16 ethertype = __constant_htons(BATADV_ETH_P_BATMAN);
-   static const uint8_t stp_addr[ETH_ALEN] = {0x01, 0x80, 0xC2, 0x00, 0x00,
-  0x00};
+   static const uint8_t stp_addr[ETH_ALEN] = {0x01, 0x80, 0xC2, 0x00,
+  0x00, 0x00};
+   static const uint8_t ectp_addr[ETH_ALEN] = {0xCF, 0x00, 0x00, 0x00,
+   0x00, 0x00};
unsigned int header_len = 0;
int data_len = skb-len, ret;
short vid __maybe_unused = -1;
@@ -177,10 +179,16 @@ static int batadv_interface_tx(struct sk_buff *skb,
 
/* don't accept stp packets. STP does not help in meshes.
 * better use the bridge loop avoidance ...
+*
+* The same goes for ECTP sent at least by some Cisco Switches,
+* it might confuse the mesh when used with bridge loop avoidance.
 */
if (batadv_compare_eth(ethhdr-h_dest, stp_addr))
goto dropped;
 
+   if (batadv_compare_eth(ethhdr-h_dest, ectp_addr))
+   goto dropped;
+
if (is_multicast_ether_addr(ethhdr-h_dest)) {
do_bcast = true;
 
-- 
1.7.10



[B.A.T.M.A.N.] editing the routing information

2012-08-19 Thread Dominic Follett-Smith
Hi all,

I am using the batmand release and I trying to edit where batman keeps
a statistic of next best hops to a destination node. I want to change
the metric in some way to alter the choices that batman makes when
routing a packet to its destination. However I am rather stuck, and
would appreciate some direction on where the updating of this
statistic of next best hops for a destination is done in the batman
code.

Many Thanks
Dominic


[B.A.T.M.A.N.] [PATCHv2] batctl: Clear screen using ANSI escape codes

2012-08-19 Thread Sven Eckelmann
It is not necessary to call an external binary to clear the screen of a default
unix terminal emulator. The external call using system(clear) may be used by
an attacker to get untrusted code called with an higher privilege because
batctl has to be run as using uid 0.

Reported-by: Antonio Quartulli or...@autistici.org
Signed-off-by: Sven Eckelmann s...@narfation.org
---
Add comment

 functions.c |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/functions.c b/functions.c
index c78e408..e095fd0 100644
--- a/functions.c
+++ b/functions.c
@@ -184,7 +184,8 @@ open:
}
 
if (read_opt  CLR_CONT_READ)
-   system(clear);
+   /* clear screen, set cursor back to 0,0 */
+   printf(\033[2J\033[0;0f);
 
 read:
while (getline(line_ptr, len, fp) != -1) {
-- 
1.7.10.4



[B.A.T.M.A.N.] [PATCH] batman-adv: Set special lockdep classes to avoid lockdep warning

2012-08-19 Thread Sven Eckelmann
Transmissions over batman-adv devices always start another nested transmission
over devices attached to the batman-adv interface. These devices usually use
the ethernet lockdep class for the tx_queue lock which is also set by default
for all batman-adv devices. Lockdep will detect a nested locking attempt of two
locks with the same class and warn about a possible deadlock.

This is the default and expected behavior and should not alarm the locking
correctness prove mechanism. Therefore, the locks for all netdevice specific
lock get a special batman-adv lock class to avoid a false positive for each
transmission.

Reported-by: Linus Lüssing linus.luess...@web.de
Signed-off-by: Sven Eckelmann s...@narfation.org
---
 soft-interface.c |   22 ++
 1 file changed, 22 insertions(+)

diff --git a/soft-interface.c b/soft-interface.c
index 1aee7db..513d50a 100644
--- a/soft-interface.c
+++ b/soft-interface.c
@@ -354,6 +354,27 @@ static const struct net_device_ops batadv_netdev_ops = {
.ndo_validate_addr = eth_validate_addr
 };
 
+/*
+ * batman-adv network devices have devices nesting below it and are a special
+ * super class of normal network devices; split their locks off into a
+ * separate class since they always nest.
+ */
+static struct lock_class_key batadv_netdev_xmit_lock_key;
+static struct lock_class_key batadv_netdev_addr_lock_key;
+
+static void batadv_set_lockdep_class_one(struct net_device *dev,
+struct netdev_queue *txq,
+void *_unused)
+{
+   lockdep_set_class(txq-_xmit_lock, batadv_netdev_xmit_lock_key);
+}
+
+static void batadv_set_lockdep_class(struct net_device *dev)
+{
+   lockdep_set_class(dev-addr_list_lock, batadv_netdev_addr_lock_key);
+   netdev_for_each_tx_queue(dev, batadv_set_lockdep_class_one, NULL);
+}
+
 static void batadv_interface_setup(struct net_device *dev)
 {
struct batadv_priv *priv = netdev_priv(dev);
@@ -363,6 +384,7 @@ static void batadv_interface_setup(struct net_device *dev)
dev-netdev_ops = batadv_netdev_ops;
dev-destructor = free_netdev;
dev-tx_queue_len = 0;
+   batadv_set_lockdep_class(dev);
 
/* can't call min_mtu, because the needed variables
 * have not been initialized yet
-- 
1.7.10.4