Re: [B.A.T.M.A.N.] [PATCHv5 0/9] DAT: Distributed ARP Table

2012-02-10 Thread Marek Lindner
On Friday, February 10, 2012 07:41:33 Antonio Quartulli wrote:
 
 This is the **fifth** version of this patchset. The whole code has been
 reviewed after some discussions on irc and here in the ml in the previous
 threads. Several bugs have been spotted and fixed. Thanks Marek, Sven,
 Simon, Andrew and all the others for the comments/feedbacks.
 
 This patchset assumes that patch
 [PATCH] batman-adv: add biggest_unsigned_int(x) macro
 has already been applied
 

Please make sure your patchset is checkpatch clean.

Thanks,
Marek


[B.A.T.M.A.N.] [PATCH] batman-adv: Fix daily check regression in blaII

2012-02-10 Thread Sven Eckelmann
9fd6b0615b5499b270d39a92b8790e206cf75833 introduced some regressions in the
daily checks on open-mesh.org. Those were only visible when
CONFIG_BATMAN_ADV_BLA was disabled. The reason was the usage of defines to
replace the calls for not available functions. The actual c compiler is not
able to distinguish between the used and unused variables because it doesn't
see the function call anymore. The second problem was the use of simple
subscopes where do {} while(0) whould have been necessary.

Signed-off-by: Sven Eckelmann s...@narfation.org
---
 bridge_loop_avoidance.h |5 +++--
 soft-interface.c|4 ++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/bridge_loop_avoidance.h b/bridge_loop_avoidance.h
index 24d7f16..2758b8c 100644
--- a/bridge_loop_avoidance.h
+++ b/bridge_loop_avoidance.h
@@ -46,9 +46,10 @@ void bla_free(struct bat_priv *bat_priv);
 #define bla_claim_table_seq_print_text (0)
 #define bla_is_backbone_gw_orig(...)   (0)
 #define bla_check_bcast_duplist(...)   (0)
-#define bla_update_orig_address(...)   {}
+#define bla_update_orig_address(...)   do {} while (0)
 #define bla_init(...)  (1)
-#define bla_free(...)  {}
+#define bla_free(...)  do {} while (0)
+
 
 #endif /* ifdef CONFIG_BATMAN_ADV_BLA */
 
diff --git a/soft-interface.c b/soft-interface.c
index 8de8779..579f509 100644
--- a/soft-interface.c
+++ b/soft-interface.c
@@ -132,7 +132,7 @@ static int interface_tx(struct sk_buff *skb, struct 
net_device *soft_iface)
uint8_t stp_addr[ETH_ALEN] = {0x01, 0x80, 0xC2, 0x00, 0x00, 0x00};
unsigned int header_len = 0;
int data_len = skb-len, ret;
-   short vid = -1;
+   short vid __maybe_unused = -1;
bool do_bcast = false;
 
if (atomic_read(bat_priv-mesh_state) != MESH_ACTIVE)
@@ -253,7 +253,7 @@ void interface_rx(struct net_device *soft_iface,
struct bat_priv *bat_priv = netdev_priv(soft_iface);
struct ethhdr *ethhdr;
struct vlan_ethhdr *vhdr;
-   short vid = -1;
+   short vid __maybe_unused = -1;
 
/* check if enough space is available for pulling, and pull */
if (!pskb_may_pull(skb, hdr_size))
-- 
1.7.9



Re: [B.A.T.M.A.N.] [PATCHv5 4/9] batman-adv: Distributed ARP Table - add ARP parsing functions

2012-02-10 Thread Marek Lindner
On Friday, February 10, 2012 07:41:37 Antonio Quartulli wrote:
 +#define ARP_HW_SRC(skb) ((uint8_t *)(skb-data) + sizeof(struct ethhdr) +
 \ +   sizeof(struct arphdr))

You could replace all occurences of sizeof(struct ethhdr) with ETH_HLEN.

Cheers,
Marek


Re: [B.A.T.M.A.N.] [PATCHv5 5/9] batman-adv: Distributed ARP Table - add snooping functions for ARP messages

2012-02-10 Thread Marek Lindner
On Friday, February 10, 2012 07:41:38 Antonio Quartulli wrote:
  static inline void bat_dbg_arp(struct bat_priv *bat_priv,
struct sk_buff *skb, uint16_t type) {
 -   char buf[30];
 -   const char *type_str[] = { REQUEST, REPLY, RREQUEST,
 RREPLY, - InREQUEST, InREPLY,
 NAK }; -
 -   if (type = 1  type = ARRAY_SIZE(type_str))
 -   scnprintf(buf, sizeof(buf), %s, type_str[type - 1]);
 -   else
 -   scnprintf(buf, sizeof(buf), UNKNOWN (%hu), type);
 -
 -   bat_dbg(DBG_ARP, bat_priv, ARP message of type %s recognised 
 -   [src: %pM-%pI4 dst: %pM-%pI4]\n, buf, ARP_HW_SRC(skb),
 -   ARP_IP_SRC(skb), ARP_HW_DST(skb), ARP_IP_DST(skb));
 +   bat_dbg(DBG_ARP, bat_priv, ARP MSG = [src: %pM-%pI4 dst:
 %pM-%pI4]\n, +   ARP_HW_SRC(skb), ARP_IP_SRC(skb),
 ARP_HW_DST(skb), +   ARP_IP_DST(skb));
  }

Removing something that was just added in the previous patch is bad style and 
unlikely to be accepted.

Cheers,
Marek


Re: [B.A.T.M.A.N.] [PATCHv5 8/9] batman-adv: add UNICAST_4ADDR packet type

2012-02-10 Thread Marek Lindner
On Friday, February 10, 2012 07:41:41 Antonio Quartulli wrote:
 --- a/routing.c
 +++ b/routing.c
 @@ -960,14 +960,20 @@ int recv_unicast_packet(struct sk_buff *skb, struct
 hard_iface *recv_if) struct unicast_packet *unicast_packet;
   int hdr_size = sizeof(*unicast_packet);
 
 + unicast_packet = (struct unicast_packet *)skb-data;
 +
 + /* the caller function should have already pulled 2 bytes */
 + if (unicast_packet-header.packet_type == BAT_UNICAST)
 + hdr_size = sizeof(struct unicast_packet);
 + else if (unicast_packet-header.packet_type == BAT_UNICAST_4ADDR)
 + hdr_size = sizeof(struct unicast_4addr_packet);
 +

The first if statement should not be necessary given the default value of 
hdr_size. We also should stick to the general principle of using 
*variable_name instead of sizeof(). That was suggested in some of the kernel 
coding guidelines.


 +bool prepare_unicast_4addr_packet(struct bat_priv *bat_priv,
 +   struct sk_buff *skb,
 +   struct orig_node *orig_node)
 +{
 + struct hard_iface *primary_if;
 + struct unicast_4addr_packet *unicast_4addr_packet;
 + bool ret = false;
 +
 + primary_if = primary_if_get_selected(bat_priv);
 + if (!primary_if)
 + goto out;
 +
 + if (my_skb_head_push(skb, sizeof(*unicast_4addr_packet))  0)
 + goto out;
 +
 + unicast_4addr_packet = (struct unicast_4addr_packet *)skb-data;
 +
 + unicast_4addr_packet-u.header.version = COMPAT_VERSION;
 + /* batman packet type: unicast */
 + unicast_4addr_packet-u.header.packet_type = BAT_UNICAST_4ADDR;
 + /* set unicast ttl */
 + unicast_4addr_packet-u.header.ttl = TTL;
 + /* copy the destination for faster routing */
 + memcpy(unicast_4addr_packet-u.dest, orig_node-orig, ETH_ALEN);
 + /* set the destination tt version number */
 + unicast_4addr_packet-u.ttvn =
 + (uint8_t)atomic_read(orig_node-last_ttvn);
 + memcpy(unicast_4addr_packet-src, primary_if-net_dev-dev_addr,
 +ETH_ALEN);
 + ret = true;
 +out:
 + if (primary_if)
 + hardif_free_ref(primary_if);
 + return ret;
 +}

This function looks like code duplication we coudl avoid. 
prepare_unicast_packet() does the same thing except for 2-3 fields ..


 +
 +int unicast_4addr_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv)
 +{
 + struct ethhdr *ethhdr = (struct ethhdr *)skb-data;
 + struct unicast_4addr_packet *unicast_4addr_packet;
 + struct orig_node *orig_node;
 + struct neigh_node *neigh_node;
 + int data_len = skb-len;
 + int ret = 1;
 +
 + /* get routing information */
 + if (is_multicast_ether_addr(ethhdr-h_dest)) {
 + orig_node = gw_get_selected_orig(bat_priv);
 + if (orig_node)
 + goto find_router;
 + }
 +
 + /* check for tt host - increases orig_node refcount.
 +  * returns NULL in case of AP isolation */
 + orig_node = transtable_search(bat_priv, ethhdr-h_source,
 +   ethhdr-h_dest);
 +
 +find_router:
 + /**
 +  * find_router():
 +  *  - if orig_node is NULL it returns NULL
 +  *  - increases neigh_nodes refcount if found.
 +  */
 + neigh_node = find_router(bat_priv, orig_node, NULL);
 +
 + if (!neigh_node)
 + goto out;
 +
 + if (!prepare_unicast_4addr_packet(bat_priv, skb, orig_node))
 + goto out;
 +
 + unicast_4addr_packet = (struct unicast_4addr_packet *)skb-data;
 +
 + if (atomic_read(bat_priv-fragmentation) 
 + data_len + sizeof(*unicast_4addr_packet) 
 + neigh_node-if_incoming-net_dev-mtu) {
 + /* send frag skb decreases ttl */
 + unicast_4addr_packet-u.header.ttl++;
 + ret = frag_send_skb(skb, bat_priv,
 + neigh_node-if_incoming, neigh_node-addr);
 + goto out;
 + }
 +
 + send_skb_packet(skb, neigh_node-if_incoming, neigh_node-addr);
 + ret = 0;
 + goto out;
 +
 +out:
 + if (neigh_node)
 + neigh_node_free_ref(neigh_node);
 + if (orig_node)
 + orig_node_free_ref(orig_node);
 + if (ret == 1)
 + kfree_skb(skb);
 + return ret;
 +}

Same here. Isn't it possible to let function handle the difference in packet 
type without having the same function twice ? 

Regards,
Marek


[B.A.T.M.A.N.] [RFCv2] batman-adv: Add blocking of one hop OGM messages

2012-02-10 Thread Martin Hundebøll
For testing purposes, forcing specific paths in a network where all
nodes are within reach, can be useful. This patch allows the user to
enter addresses from which direct OGMs should be ignored or not dropped.

The blocking of OGM is controlled through a file in debugfs:
/sys/kernel/debug/batman-adv/bat0/block_ogm.

The list of currently handled addresses is exported through that file.
An addresses is added by echoing it, together with an action, into the
file, e.g.:
echo de:ad:be:ef:ca:fe drop   block_ogm
echo de:ad:be:ef:ca:fe allow  block_ogm
echo de:ad:be:ef:ca:fe delblock_ogm

The drop action leads to dropping all OGMs received directly from this
address. The allow action leads to dropping all OGMs *not* from this
(or other allowed) addresses. The del action deletes the address from
the blocking list.

Addresses and actions are stored in a doubly linked list. When new
addresses are added, the list of originators is searched, and an
possible existing originator is updated. When new originators are created,
the list of addresses is searched and orig_node-block_action is set
accordingly.

The filtering is performed by checking the value of member
orig_node-block_action together with a count of addresses with the
allow action. The orig_node struct is found using the Ethernet source of
the OGM message in question. If orig_node-block_action is equal 2. If
the count of addresses with the allow action is non-zero, and
orig_node-block_action is not 3, the OGM is dropped.

v2: This is almost a complete rewrite of the previous patch to allow
adding addresses of unknown originators and the allow-only feature.

Signed-off-by: Martin Hundebøll mar...@hundeboll.net
---
 Makefile   |2 +
 Makefile.kbuild|1 +
 bat_debugfs.c  |3 +
 block_ogm.c|  394 
 block_ogm.h|   59 +++
 compat.c   |8 +
 compat.h   |1 +
 gen-compat-autoconf.sh |1 +
 main.c |2 +
 originator.c   |2 +
 routing.c  |5 +
 soft-interface.c   |1 +
 types.h|   12 ++
 13 files changed, 491 insertions(+), 0 deletions(-)
 create mode 100644 block_ogm.c
 create mode 100644 block_ogm.h

diff --git a/Makefile b/Makefile
index 08f8c39..b60a47f 100644
--- a/Makefile
+++ b/Makefile
@@ -23,6 +23,8 @@
 export CONFIG_BATMAN_ADV_DEBUG=n
 # B.A.T.M.A.N. bridge loop avoidance:
 export CONFIG_BATMAN_ADV_BLA=y
+# B.A.T.M.A.N. OGM packet filtering:
+export CONFIG_BATMAN_ADV_BLOCK_OGM=y
 
 PWD:=$(shell pwd)
 KERNELPATH ?= /lib/modules/$(shell uname -r)/build
diff --git a/Makefile.kbuild b/Makefile.kbuild
index 6d5c194..8262811 100644
--- a/Makefile.kbuild
+++ b/Makefile.kbuild
@@ -24,6 +24,7 @@ batman-adv-y += bat_iv_ogm.o
 batman-adv-y += bat_sysfs.o
 batman-adv-y += bitarray.o
 batman-adv-$(CONFIG_BATMAN_ADV_BLA) += bridge_loop_avoidance.o
+batman-adv-$(CONFIG_BATMAN_ADV_BLOCK_OGM) += block_ogm.o
 batman-adv-y += gateway_client.o
 batman-adv-y += gateway_common.o
 batman-adv-y += hard-interface.o
diff --git a/bat_debugfs.c b/bat_debugfs.c
index 916380c..863f59b 100644
--- a/bat_debugfs.c
+++ b/bat_debugfs.c
@@ -33,6 +33,7 @@
 #include vis.h
 #include icmp_socket.h
 #include bridge_loop_avoidance.h
+#include block_ogm.h
 
 static struct dentry *bat_debugfs;
 
@@ -350,6 +351,7 @@ int debugfs_add_meshif(struct net_device *dev)
 
bat_socket_setup(bat_priv);
debug_log_setup(bat_priv);
+   block_file_setup(bat_priv);
 
for (bat_debug = mesh_debuginfos; *bat_debug; ++bat_debug) {
file = debugfs_create_file(((*bat_debug)-attr).name,
@@ -380,6 +382,7 @@ void debugfs_del_meshif(struct net_device *dev)
struct bat_priv *bat_priv = netdev_priv(dev);
 
debug_log_cleanup(bat_priv);
+   block_file_cleanup(bat_priv);
 
if (bat_debugfs) {
debugfs_remove_recursive(bat_priv-debug_dir);
diff --git a/block_ogm.c b/block_ogm.c
new file mode 100644
index 000..3df385e
--- /dev/null
+++ b/block_ogm.c
@@ -0,0 +1,394 @@
+/*
+ * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors:
+ *
+ * Martin Hundebøll mar...@hundeboll.net
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ *
+ */
+
+#include linux/debugfs.h
+#include main.h
+#include block_ogm.h
+#include originator.h
+
+/* 

Re: [B.A.T.M.A.N.] [RFCv2] batman-adv: Add blocking of one hop OGM messages

2012-02-10 Thread Martin Hundebøll

On 2012-02-10 15:53, Martin Hundebøll wrote:

For testing purposes, forcing specific paths in a network where all
nodes are within reach, can be useful. This patch allows the user to
enter addresses from which direct OGMs should be ignored or not dropped.


The code/patch is also available in the git repositorie:
http://git.open-mesh.org/?p=hundeboll/batman-adv.git;h=refs/heads/filter

--
Kind Regards,
Martin Hundebøll
Nordborggade 57, 2. 1
8000 Aarhus C

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


[B.A.T.M.A.N.] batman openwrt

2012-02-10 Thread Gioacchino Mazzurco
Hi!

After upgrading to latest batman version on openwt batman stopped adding 
ethernet or bridge interfaces at start...

it add only wireless interfaces

I am using backfire for the core and trunk for packages the problem is related 
to that?