b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven.eckelmann@gmx.de>
To: greg@kroah.com
Cc: Marek Lindner <lindner_marek@yahoo.de>, b.a.t.m.a.n@lists.open-mesh.net
Subject: [B.A.T.M.A.N.] [PATCH 07/21] Staging: batman-adv: refactoring unicast payload code
Date: Sun,  5 Sep 2010 01:58:24 +0200	[thread overview]
Message-ID: <1283644718-653-8-git-send-email-sven.eckelmann@gmx.de> (raw)
In-Reply-To: <1283644718-653-1-git-send-email-sven.eckelmann@gmx.de>

From: Marek Lindner <lindner_marek@yahoo.de>

Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
[sven.eckelmann@gmx.de: Rework on top of current version]
Signed-off-by: Sven Eckelmann <sven.eckelmann@gmx.de>
---
 drivers/staging/batman-adv/Makefile         |    2 +-
 drivers/staging/batman-adv/soft-interface.c |   74 ++++-------------------
 drivers/staging/batman-adv/unicast.c        |   87 +++++++++++++++++++++++++++
 drivers/staging/batman-adv/unicast.h        |   27 ++++++++
 4 files changed, 128 insertions(+), 62 deletions(-)
 create mode 100644 drivers/staging/batman-adv/unicast.c
 create mode 100644 drivers/staging/batman-adv/unicast.h

diff --git a/drivers/staging/batman-adv/Makefile b/drivers/staging/batman-adv/Makefile
index e9817b5..4b5c434 100644
--- a/drivers/staging/batman-adv/Makefile
+++ b/drivers/staging/batman-adv/Makefile
@@ -19,4 +19,4 @@
 #
 
 obj-$(CONFIG_BATMAN_ADV) += batman-adv.o
-batman-adv-objs := main.o bat_debugfs.o bat_sysfs.o send.o routing.o soft-interface.o icmp_socket.o translation-table.o bitarray.o hash.o ring_buffer.o vis.o hard-interface.o aggregation.o originator.o
+batman-adv-objs := main.o bat_debugfs.o bat_sysfs.o send.o routing.o soft-interface.o icmp_socket.o translation-table.o bitarray.o hash.o ring_buffer.o vis.o hard-interface.o aggregation.o originator.o unicast.o
diff --git a/drivers/staging/batman-adv/soft-interface.c b/drivers/staging/batman-adv/soft-interface.c
index 6f22e6e..315fdeb 100644
--- a/drivers/staging/batman-adv/soft-interface.c
+++ b/drivers/staging/batman-adv/soft-interface.c
@@ -22,14 +22,12 @@
 #include "main.h"
 #include "soft-interface.h"
 #include "hard-interface.h"
-#include "routing.h"
-#include "send.h"
 #include "translation-table.h"
-#include "types.h"
-#include "hash.h"
+#include "send.h"
 #include <linux/slab.h>
 #include <linux/ethtool.h>
 #include <linux/etherdevice.h>
+#include "unicast.h"
 
 static uint32_t bcast_seqno = 1; /* give own bcast messages seq numbers to avoid
 				  * broadcast storms */
@@ -127,24 +125,14 @@ static int interface_change_mtu(struct net_device *dev, int new_mtu)
 
 int interface_tx(struct sk_buff *skb, struct net_device *dev)
 {
-	struct unicast_packet *unicast_packet;
-	struct bcast_packet *bcast_packet;
-	struct orig_node *orig_node;
-	struct neigh_node *router;
 	struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
-	struct bat_priv *priv = netdev_priv(dev);
-	struct batman_if *batman_if;
-	struct bat_priv *bat_priv;
-	uint8_t dstaddr[6];
-	int data_len = skb->len;
-	unsigned long flags;
+	struct bat_priv *bat_priv = netdev_priv(dev);
+	struct bcast_packet *bcast_packet;
+	int data_len = skb->len, ret;
 
 	if (atomic_read(&module_state) != MODULE_ACTIVE)
 		goto dropped;
 
-	/* FIXME: each batman_if will be attached to a softif */
-	bat_priv = netdev_priv(soft_device);
-
 	dev->trans_start = jiffies;
 	/* TODO: check this for locks */
 	hna_local_add(ethhdr->h_source);
@@ -179,55 +167,19 @@ int interface_tx(struct sk_buff *skb, struct net_device *dev)
 
 	/* unicast packet */
 	} else {
-		spin_lock_irqsave(&orig_hash_lock, flags);
-		/* get routing information */
-		orig_node = ((struct orig_node *)hash_find(orig_hash,
-							   ethhdr->h_dest));
-
-		/* check for hna host */
-		if (!orig_node)
-			orig_node = transtable_search(ethhdr->h_dest);
-
-		router = find_router(orig_node, NULL);
-
-		if (!router)
-			goto unlock;
-
-		/* don't lock while sending the packets ... we therefore
-		 * copy the required data before sending */
-
-		batman_if = router->if_incoming;
-		memcpy(dstaddr, router->addr, ETH_ALEN);
-
-		spin_unlock_irqrestore(&orig_hash_lock, flags);
-
-		if (batman_if->if_status != IF_ACTIVE)
-			goto dropped;
-
-		if (my_skb_push(skb, sizeof(struct unicast_packet)) < 0)
-			goto dropped;
-
-		unicast_packet = (struct unicast_packet *)skb->data;
-
-		unicast_packet->version = COMPAT_VERSION;
-		/* batman packet type: unicast */
-		unicast_packet->packet_type = BAT_UNICAST;
-		/* set unicast ttl */
-		unicast_packet->ttl = TTL;
-		/* copy the destination for faster routing */
-		memcpy(unicast_packet->dest, orig_node->orig, ETH_ALEN);
-
-		send_skb_packet(skb, batman_if, dstaddr);
+		ret = unicast_send_skb(skb, bat_priv);
+		if (ret != 0) {
+			bat_priv->stats.tx_dropped++;
+			goto end;
+		}
 	}
 
-	priv->stats.tx_packets++;
-	priv->stats.tx_bytes += data_len;
+	bat_priv->stats.tx_packets++;
+	bat_priv->stats.tx_bytes += data_len;
 	goto end;
 
-unlock:
-	spin_unlock_irqrestore(&orig_hash_lock, flags);
 dropped:
-	priv->stats.tx_dropped++;
+	bat_priv->stats.tx_dropped++;
 	kfree_skb(skb);
 end:
 	return NETDEV_TX_OK;
diff --git a/drivers/staging/batman-adv/unicast.c b/drivers/staging/batman-adv/unicast.c
new file mode 100644
index 0000000..27c4abb
--- /dev/null
+++ b/drivers/staging/batman-adv/unicast.c
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2010 B.A.T.M.A.N. contributors:
+ *
+ * Andreas Langer
+ *
+ * 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 "main.h"
+#include "unicast.h"
+#include "send.h"
+#include "soft-interface.h"
+#include "hash.h"
+#include "translation-table.h"
+#include "routing.h"
+#include "hard-interface.h"
+
+int unicast_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv)
+{
+	struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
+	struct unicast_packet *unicast_packet;
+	struct orig_node *orig_node;
+	struct batman_if *batman_if;
+	struct neigh_node *router;
+	uint8_t dstaddr[6];
+	unsigned long flags;
+
+	spin_lock_irqsave(&orig_hash_lock, flags);
+
+	/* get routing information */
+	orig_node = ((struct orig_node *)hash_find(orig_hash, ethhdr->h_dest));
+
+	/* check for hna host */
+	if (!orig_node)
+		orig_node = transtable_search(ethhdr->h_dest);
+
+	router = find_router(orig_node, NULL);
+
+	if (!router)
+		goto unlock;
+
+	/* don't lock while sending the packets ... we therefore
+		* copy the required data before sending */
+
+	batman_if = router->if_incoming;
+	memcpy(dstaddr, router->addr, ETH_ALEN);
+
+	spin_unlock_irqrestore(&orig_hash_lock, flags);
+
+	if (batman_if->if_status != IF_ACTIVE)
+		goto dropped;
+
+	if (my_skb_push(skb, sizeof(struct unicast_packet)) < 0)
+		goto dropped;
+
+	unicast_packet = (struct unicast_packet *)skb->data;
+
+	unicast_packet->version = COMPAT_VERSION;
+	/* batman packet type: unicast */
+	unicast_packet->packet_type = BAT_UNICAST;
+	/* set unicast ttl */
+	unicast_packet->ttl = TTL;
+	/* copy the destination for faster routing */
+	memcpy(unicast_packet->dest, orig_node->orig, ETH_ALEN);
+
+	send_skb_packet(skb, batman_if, dstaddr);
+	return 0;
+
+unlock:
+	spin_unlock_irqrestore(&orig_hash_lock, flags);
+dropped:
+	kfree_skb(skb);
+	return 1;
+}
diff --git a/drivers/staging/batman-adv/unicast.h b/drivers/staging/batman-adv/unicast.h
new file mode 100644
index 0000000..dd00703
--- /dev/null
+++ b/drivers/staging/batman-adv/unicast.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2010 B.A.T.M.A.N. contributors:
+ *
+ * Andreas Langer
+ *
+ * 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
+ *
+ */
+
+#ifndef _NET_BATMAN_ADV_UNICAST_H_
+#define _NET_BATMAN_ADV_UNICAST_H_
+
+int unicast_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv);
+
+#endif /* _NET_BATMAN_ADV_UNICAST_H_ */
-- 
1.7.1


  parent reply	other threads:[~2010-09-04 23:58 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-04 23:58 [B.A.T.M.A.N.] Staging: batman-adv for 2.6.37 (1) Sven Eckelmann
2010-09-04 23:58 ` [B.A.T.M.A.N.] [PATCH 01/21] Revert: "Staging: batman-adv: Adding netfilter-bridge hooks" Sven Eckelmann
2010-09-04 23:58 ` [B.A.T.M.A.N.] [PATCH 02/21] Staging: batman-adv: Remove CHANGELOG Sven Eckelmann
2010-09-04 23:58 ` [B.A.T.M.A.N.] [PATCH 03/21] Staging: batman-adv: Start new development cycle Sven Eckelmann
2010-09-04 23:58 ` [B.A.T.M.A.N.] [PATCH 04/21] Staging: batman-adv: Count Ethernet header for incoming packets Sven Eckelmann
2010-09-04 23:58 ` [B.A.T.M.A.N.] [PATCH 05/21] Staging: batman-adv: Calculate hamming weight using optimized kernel functions Sven Eckelmann
2010-09-04 23:58 ` [B.A.T.M.A.N.] [PATCH 06/21] Staging: batman-adv: move queue counters into bat_priv Sven Eckelmann
2010-09-04 23:58 ` Sven Eckelmann [this message]
2010-09-04 23:58 ` [B.A.T.M.A.N.] [PATCH 08/21] Staging: batman-adv: layer2 unicast packet fragmentation Sven Eckelmann
2010-09-04 23:58 ` [B.A.T.M.A.N.] [PATCH 09/21] Staging: batman-adv: Directly prepare icmp packets in socket buffer Sven Eckelmann
2010-09-04 23:58 ` [B.A.T.M.A.N.] [PATCH 10/21] Staging: batman-adv: register the batman-adv packet type per interface Sven Eckelmann
2010-09-04 23:58 ` [B.A.T.M.A.N.] [PATCH 11/21] Staging: batman-adv: Keep header writable and unshared Sven Eckelmann
2010-09-04 23:58 ` [B.A.T.M.A.N.] [PATCH 12/21] Staging: batman-adv: Only clone skb data for multiple broadcasts Sven Eckelmann
2010-09-04 23:58 ` [B.A.T.M.A.N.] [PATCH 13/21] Staging: batman-adv: Aggregate batman packets directly in skb Sven Eckelmann
2010-09-04 23:58 ` [B.A.T.M.A.N.] [PATCH 14/21] Staging: batman-adv: Prepare vis packets directly inside a skb Sven Eckelmann
2010-09-04 23:58 ` [B.A.T.M.A.N.] [PATCH 15/21] Staging: batman-adv: Create copy of skb with pre-allocated headroom Sven Eckelmann
2010-09-04 23:58 ` [B.A.T.M.A.N.] [PATCH 16/21] Staging: batman-adv: Provide full headers and packets as linear skb Sven Eckelmann
2010-09-04 23:58 ` [B.A.T.M.A.N.] [PATCH 17/21] Staging: batman-adv: attach each hard-interface to a soft-interface Sven Eckelmann
2010-09-04 23:58 ` [B.A.T.M.A.N.] [PATCH 18/21] Staging: batman-adv: multiple mesh clouds Sven Eckelmann
2010-09-04 23:58 ` [B.A.T.M.A.N.] [PATCH 19/21] Staging: batman-adv: Remove duplicate of attached device name Sven Eckelmann
2010-09-04 23:58 ` [B.A.T.M.A.N.] [PATCH 20/21] Staging: batman-adv: Don't inform about dropped packets in nodebug Sven Eckelmann
2010-09-04 23:58 ` [B.A.T.M.A.N.] [PATCH 21/21] Staging: batman-adv: Update mtu of bat device by changing mtu of slave device Sven Eckelmann
2010-09-05  7:33 ` [B.A.T.M.A.N.] Staging: batman-adv for 2.6.37 (1) Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1283644718-653-8-git-send-email-sven.eckelmann@gmx.de \
    --to=sven.eckelmann@gmx.de \
    --cc=b.a.t.m.a.n@lists.open-mesh.net \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    --cc=greg@kroah.com \
    --cc=lindner_marek@yahoo.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).