Skip to contentSkip to conversation

Staging: batman-adv for 2.6.37 (1)

B.A.T.M.A.N. New Sven Eckelmann 2 participants 23 messages Sep 4, 2010 – Sep 5, 2010 Staging

lore
Share & tools
lore
#0 lore raw

Hi,

I hope that the fever-induced dreams are over now. Otherwise I will try to write my mails also as little tales. ;)

Nevertheless, I would like to send some patches for 2.6.37. That is not 100% true. We would also like to see the revert
'Revert: "Staging: batman-adv: Adding netfilter-bridge hooks"' too in 2.6.36. It fixes a bug introduced by the commit we revert here.

The rest is more or less the usual stuff, but more feature patches this time. All patches we depend on are already part of 2.6.36-rc3.

I will try to sent a patch again to David S. Miller.

thanks,
Sven

Andreas Langer (1):
Staging: batman-adv: layer2 unicast packet fragmentation

Marek Lindner (4):
Staging: batman-adv: refactoring unicast payload code
Staging: batman-adv: register the batman-adv packet type per interface
Staging: batman-adv: attach each hard-interface to a soft-interface
Staging: batman-adv: multiple mesh clouds

Simon Wunderlich (2):
Staging: batman-adv: Count Ethernet header for incoming packets
Staging: batman-adv: move queue counters into bat_priv

Sven Eckelmann (14):
Revert: "Staging: batman-adv: Adding netfilter-bridge hooks"
Staging: batman-adv: Remove CHANGELOG
Staging: batman-adv: Start new development cycle
Staging: batman-adv: Calculate hamming weight using optimized kernel functions
Staging: batman-adv: Directly prepare icmp packets in socket buffer
Staging: batman-adv: Keep header writable and unshared
Staging: batman-adv: Only clone skb data for multiple broadcasts
Staging: batman-adv: Aggregate batman packets directly in skb
Staging: batman-adv: Prepare vis packets directly inside a skb
Staging: batman-adv: Create copy of skb with pre-allocated headroom
Staging: batman-adv: Provide full headers and packets as linear skb
Staging: batman-adv: Remove duplicate of attached device name
Staging: batman-adv: Don't inform about dropped packets in nodebug
Staging: batman-adv: Update mtu of bat device by changing mtu of slave device

 drivers/staging/batman-adv/CHANGELOG           |   63 ---
 drivers/staging/batman-adv/Makefile            |    2 +-
 drivers/staging/batman-adv/README              |   45 +--
 drivers/staging/batman-adv/TODO                |    3 -
 drivers/staging/batman-adv/aggregation.c       |   57 ++--
 drivers/staging/batman-adv/bat_sysfs.c         |  106 ++++--
 drivers/staging/batman-adv/bitarray.c          |   22 +-
 drivers/staging/batman-adv/bitarray.h          |    7 +-
 drivers/staging/batman-adv/hard-interface.c    |  237 +++++++-----
 drivers/staging/batman-adv/hard-interface.h    |    6 +-
 drivers/staging/batman-adv/hash.c              |    6 +-
 drivers/staging/batman-adv/hash.h              |    4 +-
 drivers/staging/batman-adv/icmp_socket.c       |   70 ++--
 drivers/staging/batman-adv/main.c              |  138 ++-----
 drivers/staging/batman-adv/main.h              |   28 +-
 drivers/staging/batman-adv/originator.c        |  166 +++++----
 drivers/staging/batman-adv/originator.h        |    8 +-
 drivers/staging/batman-adv/packet.h            |   26 +-
 drivers/staging/batman-adv/routing.c           |  440 ++++++++++++---------
 drivers/staging/batman-adv/routing.h           |   16 +-
 drivers/staging/batman-adv/send.c              |  174 ++++-----
 drivers/staging/batman-adv/send.h              |    7 +-
 drivers/staging/batman-adv/soft-interface.c    |  238 +++++++-----
 drivers/staging/batman-adv/soft-interface.h    |   13 +-
 drivers/staging/batman-adv/translation-table.c |  266 +++++++------
 drivers/staging/batman-adv/translation-table.h |   30 +-
 drivers/staging/batman-adv/types.h             |   98 ++++-
 drivers/staging/batman-adv/unicast.c           |  265 +++++++++++++
 drivers/staging/batman-adv/unicast.h           |   39 ++
 drivers/staging/batman-adv/vis.c               |  500 ++++++++++++++----------
 drivers/staging/batman-adv/vis.h               |   27 +--
 31 files changed, 1822 insertions(+), 1285 deletions(-)
#1 lore raw

PATCH 1/21 Revert: "Staging: batman-adv: Adding netfilter-bridge hooks"

This reverts commit 96d592ed599434d2d5f339a1d282871bc6377d2c.

The netfilter hook seems to be misused and may leak skbs in situations when NF_HOOK returns NF_STOLEN. It may not filter everything as expected. Also the ethernet bridge tables are not yet capable to understand batman-adv packet correctly.

It was only added for testing purposes and can be removed again.

---
 drivers/staging/batman-adv/hard-interface.c |   13 -------------
 drivers/staging/batman-adv/send.c           |    8 ++------
 2 files changed, 2 insertions(+), 19 deletions(-)
drivers/staging/batman-adv/hard-interface.c +0 -13
index baa8b05..6e973a7 100644
@@ -30,7 +30,6 @@
 #include "hash.h"
 
 #include <linux/if_arp.h>
-#include <linux/netfilter_bridge.h>
 
 #define MIN(x, y) ((x) < (y) ? (x) : (y))
 
@@ -431,11 +430,6 @@ out:
 	return NOTIFY_DONE;
 }
 
-static int batman_skb_recv_finish(struct sk_buff *skb)
-{
-	return NF_ACCEPT;
-}
-
 /* receive a packet with the batman ethertype coming on a hard
  * interface */
 int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
@@ -456,13 +450,6 @@ int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
 	if (atomic_read(&module_state) != MODULE_ACTIVE)
 		goto err_free;
 
-	/* if netfilter/ebtables wants to block incoming batman
-	 * packets then give them a chance to do so here */
-	ret = NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_IN, skb, dev, NULL,
-		      batman_skb_recv_finish);
-	if (ret != 1)
-		goto err_out;
-
 	/* packet should hold at least type and version */
 	if (unlikely(skb_headlen(skb) < 2))
 		goto err_free;
drivers/staging/batman-adv/send.c +2 -6
index 055edee..da3c82e 100644
@@ -29,7 +29,6 @@
 #include "vis.h"
 #include "aggregation.h"
 
-#include <linux/netfilter_bridge.h>
 
 static void send_outstanding_bcast_packet(struct work_struct *work);
 
@@ -92,12 +91,9 @@ int send_skb_packet(struct sk_buff *skb,
 
 	/* dev_queue_xmit() returns a negative result on error.	 However on
 	 * congestion and traffic shaping, it drops and returns NET_XMIT_DROP
-	 * (which is > 0). This will not be treated as an error.
-	 * Also, if netfilter/ebtables wants to block outgoing batman
-	 * packets then giving them a chance to do so here */
+	 * (which is > 0). This will not be treated as an error. */
 
-	return NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
-		       dev_queue_xmit);
+	return dev_queue_xmit(skb);
 send_skb_err:
 	kfree_skb(skb);
 	return NET_XMIT_DROP;
Signature · 1 line
1.7.1
#2 lore raw

PATCH 2/21 Staging: batman-adv: Remove CHANGELOG

In reply to Sven Eckelmann

The changelog is only generated on standalone releases. Thus it has no real value for the in-kernel version of batman-adv.

---
 drivers/staging/batman-adv/CHANGELOG |   63 ----------------------------------
 1 files changed, 0 insertions(+), 63 deletions(-)
 delete mode 100644 drivers/staging/batman-adv/CHANGELOG
drivers/staging/batman-adv/CHANGELOG deleted +0 -63
deleted file mode 100644
index 86450b4..0000000
@@ -1,63 +0,0 @@
-batman-adv 2010.0.0:
-
-* support latest kernels (2.6.21 - 2.6.35)
-* further code refactoring and cleaning for coding style
-* move from procfs based configuration to sysfs
-* reorganized sequence number handling
-* limit queue lengths for batman and broadcast packets
-* many bugs (endless loop and rogue packets on shutdown, wrong tcpdump output,
-  missing frees in error situations, sleeps in atomic contexts) squashed
-
- -- Fri, 18 Jun 2010 21:34:26 +0200
-
-batman-adv 0.2.1:
-
-* support latest kernels (2.6.20 - 2.6.33)
-* receive packets directly using skbs, remove old sockets and threads
-* fix various regressions in the vis server
-* don't disable interrupts while sending
-* replace internal logging mechanism with standard kernel logging
-* move vis formats into userland, one general format remains in the kernel
-* allow MAC address to be set, correctly initialize them
-* code refactoring and cleaning for coding style
-* many bugs (null pointers, locking, hash iterators) squashed
-
- -- Sun, 21 Mar 2010 20:46:47 +0100
-
-batman-adv 0.2:
-
-* support latest kernels (2.6.20 - 2.6.31)
-* temporary routing loops / TTL code bug / ghost entries in originator table fixed
-* internal packet queue for packet aggregation & transmission retry (ARQ)
-  for payload broadcasts added
-* interface detection converted to event based handling to avoid timers
-* major linux coding style adjustments applied
-* all kernel version compatibility functions has been moved to compat.h
-* use random ethernet address generator from the kernel
-* /sys/module/batman_adv/version to export kernel module version
-* vis: secondary interface export for dot draw format + JSON output format added
-* many bugs (alignment issues, race conditions, deadlocks, etc) squashed
-
- -- Sat, 07 Nov 2009 15:44:31 +0100
-
-batman-adv 0.1:
-
-* support latest kernels (2.6.20 - 2.6.28)
-* LOTS of cleanup: locking, stack usage, memory leaks
-* Change Ethertype from 0x0842 to 0x4305
-  unregistered at IEEE, if you want to sponsor an official Ethertype ($2500)
-  please contact us
-
- -- Sun, 28 Dec 2008 00:44:31 +0100
-
-batman-adv 0.1-beta:
-
-* layer 2 meshing based on BATMAN TQ algorithm in kernelland
-* operates on any ethernet like interface
-* supports IPv4, IPv6, DHCP, etc
-* is controlled via /proc/net/batman-adv/
-* bridging via brctl is supported
-* interface watchdog (interfaces can be (de)activated dynamically)
-* offers integrated vis server which meshes/syncs with other vis servers in range
-
- -- Mon, 05 May 2008 14:10:04 +0200
Signature · 1 line
1.7.1
#3 lore raw

PATCH 3/21 Staging: batman-adv: Start new development cycle

In reply to Sven Eckelmann

Version 2010.1.0 of the extra kernel module was released and thus the documentation should be updated and everything prepared for the the upcoming patchset.

---
 drivers/staging/batman-adv/README |   45 ++++++++++++++++++-------------------
 drivers/staging/batman-adv/main.h |    2 +-
 2 files changed, 23 insertions(+), 24 deletions(-)
drivers/staging/batman-adv/README +22 -23
index 7192b7f..3a975fc 100644
@@ -1,4 +1,4 @@
-[state: 12-06-2010]
+[state: 04-09-2010]
 
 BATMAN-ADV
 ----------
@@ -67,15 +67,21 @@ All  mesh  wide  settings  can be found in batman's own interface
 folder:
 
 #  ls  /sys/class/net/bat0/mesh/
-#  aggregate_ogm   originators        transtable_global  vis_mode
-#  orig_interval   transtable_local   vis_data
+#  aggregated_ogms  bonding  orig_interval  vis_mode
+
+
+There is a special folder for debugging informations:
+
+#  ls /sys/kernel/debug/batman_adv/bat0/
+#  originators  socket  transtable_global  transtable_local
+#  vis_data
 
 
 Some of the files contain all sort of status information  regard-
 ing  the  mesh  network.  For  example, you can view the table of
 originators (mesh participants) with:
 
-# cat /sys/class/net/bat0/mesh/originators
+# cat /sys/kernel/debug/batman_adv/bat0/originators
 
 Other files allow to change batman's behaviour to better fit your
 requirements.  For instance, you can check the current originator
@@ -83,7 +89,7 @@ interval (value in milliseconds which determines how often batman
 sends its broadcast packets):
 
 # cat /sys/class/net/bat0/mesh/orig_interval
-# status: 1000
+# 1000
 
 and also change its value:
 
@@ -137,7 +143,7 @@ at least very similar) data.
 When  configured  as  server,  you can get a topology snapshot of
 your mesh:
 
-# cat /sys/class/net/bat0/mesh/vis_data
+# cat /sys/kernel/debug/batman_adv/bat0/vis_data
 
 This raw output is intended to be easily parsable and convertable
 with  other tools. Have a look at the batctl README if you want a
@@ -181,32 +187,25 @@ enabled when compiling the batman-adv module. When building  bat-
 man-adv  as  part of kernel, use "make menuconfig" and enable the
 option "B.A.T.M.A.N. debugging".
 
+Those additional  debug messages can be accessed  using a special
+file in debugfs
+
+# cat /sys/kernel/debug/batman_adv/bat0/log
+
 The additional debug output is by default disabled. It can be en-
-abled  either  at kernel modules load time or during run time. To
-enable debug output at module load time, add the module parameter
-debug=<value>.  <value> can take one of four values.
+abled  during run time. Following log_levels are defined:
 
 0 - All  debug  output  disabled
 1 - Enable messages related to routing / flooding / broadcasting
 2 - Enable route or hna added / changed / deleted
 3 - Enable all messages
 
-e.g.
+The debug output can be changed at runtime  using  the  file
+/sys/class/net/bat0/mesh/log_level. e.g.
 
-# modprobe batman-adv debug=2
+# echo 2 > /sys/class/net/bat0/mesh/log_level
 
-will load the module and enable debug messages for when routes or
-HNAs change.
-
-The debug output can also be changed at runtime  using  the  file
-/sys/module/batman-adv/parameters/debug. e.g.
-
-# echo 2 > /sys/module/batman-adv/parameters/debug
-
-enables debug messages for when routes or HNAs
-
-The  debug  output  is sent to the kernel logs. So try dmesg, lo-
-gread, etc to see the debug messages.
+will enable debug messages for when routes or HNAs change.
 
 
 BATCTL
drivers/staging/batman-adv/main.h +1 -1
index 8513261..9b30eef 100644
@@ -30,7 +30,7 @@
 #define DRIVER_DESC   "B.A.T.M.A.N. advanced"
 #define DRIVER_DEVICE "batman-adv"
 
-#define SOURCE_VERSION "maint"
+#define SOURCE_VERSION "next"
 
 
 /* B.A.T.M.A.N. parameters */
Signature · 1 line
1.7.1
#4 lore raw

PATCH 4/21 Staging: batman-adv: Count Ethernet header for incoming packets

In reply to Sven Eckelmann

From: Simon Wunderlich <[email protected]>

The Ethernet header is counted when transmitting a packet, so it should also be counted when receiving a packet. With this patch, the rx_bytes and tx_bytes statistics behave like an ordinary Ethernet interface.

---
 drivers/staging/batman-adv/soft-interface.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/staging/batman-adv/soft-interface.c +1 -1
index 2ea97de..6f22e6e 100644
@@ -259,7 +259,7 @@ void interface_rx(struct sk_buff *skb, int hdr_size)
 	 * PACKET_OTHERHOST or PACKET_HOST */
 
 	priv->stats.rx_packets++;
-	priv->stats.rx_bytes += skb->len;
+	priv->stats.rx_bytes += skb->len + sizeof(struct ethhdr);
 
 	dev->last_rx = jiffies;
 
Signature · 1 line
1.7.1
#5 lore raw

PATCH 5/21 Staging: batman-adv: Calculate hamming weight using optimized kernel functions

In reply to Sven Eckelmann

The Kernighan algorithm is not able to calculate the number of set bits in parallel and the compiler cannot replace it with optimized instructions.

The kernel provides specialised functions for each cpu which can either use a software implementation or hardware instruction depending on the target cpu.

---
 drivers/staging/batman-adv/TODO       |    1 -
 drivers/staging/batman-adv/bitarray.c |   15 +++++----------
 drivers/staging/batman-adv/bitarray.h |    3 ++-
 3 files changed, 7 insertions(+), 12 deletions(-)
drivers/staging/batman-adv/TODO +0 -1
index 9c5aea2..d8bf845 100644
@@ -1,4 +1,3 @@
- * Use hweight* for hamming weight calculation
  * Save/cache packets direktly as skb instead of using a normal memory region
    and copying it in a skb using send_raw_packet and similar functions
  * Request a new review
drivers/staging/batman-adv/bitarray.c +5 -10
index dd4193c..9dbaf1e 100644
@@ -22,6 +22,8 @@
 #include "main.h"
 #include "bitarray.h"
 
+#include <linux/bitops.h>
+
 /* returns true if the corresponding bit in the given seq_bits indicates true
  * and curr_seqno is within range of last_seqno */
 uint8_t get_bit_status(TYPE_OF_WORD *seq_bits, uint32_t last_seqno,
@@ -187,21 +189,14 @@ char bit_get_packet(TYPE_OF_WORD *seq_bits, int32_t seq_num_diff,
 }
 
 /* count the hamming weight, how many good packets did we receive? just count
- * the 1's. The inner loop uses the Kernighan algorithm, see
- * http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetKernighan
+ * the 1's.
  */
 int bit_packet_count(TYPE_OF_WORD *seq_bits)
 {
 	int i, hamming = 0;
-	TYPE_OF_WORD word;
 
-	for (i = 0; i < NUM_WORDS; i++) {
-		word = seq_bits[i];
+	for (i = 0; i < NUM_WORDS; i++)
+		hamming += hweight_long(seq_bits[i]);
 
-		while (word) {
-			word &= word-1;
-			hamming++;
-		}
-	}
 	return hamming;
 }
drivers/staging/batman-adv/bitarray.h +2 -1
index 01897d6..c0c1730 100644
@@ -22,7 +22,8 @@
 #ifndef _NET_BATMAN_ADV_BITARRAY_H_
 #define _NET_BATMAN_ADV_BITARRAY_H_
 
-/* you should choose something big, if you don't want to waste cpu */
+/* you should choose something big, if you don't want to waste cpu
+ * and keep the type in sync with bit_packet_count */
 #define TYPE_OF_WORD unsigned long
 #define WORD_BIT_SIZE (sizeof(TYPE_OF_WORD) * 8)
 
Signature · 1 line
1.7.1
#6 lore raw

PATCH 6/21 Staging: batman-adv: move queue counters into bat_priv

In reply to Sven Eckelmann

From: Simon Wunderlich <[email protected]>

to support multiple mesh devices later, we need to move global variables like the queues into corresponding private structs bat_priv of the soft devices.

Note that this patch still has a lot of FIXMEs and depends on the global soft_device variable. This should be resolved later, e.g. by referencing the parent soft device in batman_if.

[[email protected]: Rework on top of current version]
---
 drivers/staging/batman-adv/aggregation.c |    6 +++---
 drivers/staging/batman-adv/bat_sysfs.c   |    2 ++
 drivers/staging/batman-adv/main.c        |    6 ------
 drivers/staging/batman-adv/main.h        |    2 --
 drivers/staging/batman-adv/send.c        |   12 ++++++++----
 drivers/staging/batman-adv/types.h       |    2 ++
 6 files changed, 15 insertions(+), 15 deletions(-)
drivers/staging/batman-adv/aggregation.c +3 -3
index 9862d16..d738b7a 100644
@@ -111,7 +111,7 @@ static void new_aggregated_packet(unsigned char *packet_buff,
 
 	/* own packet should always be scheduled */
 	if (!own_packet) {
-		if (!atomic_dec_not_zero(&batman_queue_left)) {
+		if (!atomic_dec_not_zero(&bat_priv->batman_queue_left)) {
 			bat_dbg(DBG_BATMAN, bat_priv,
 				"batman packet queue full\n");
 			return;
@@ -121,7 +121,7 @@ static void new_aggregated_packet(unsigned char *packet_buff,
 	forw_packet_aggr = kmalloc(sizeof(struct forw_packet), GFP_ATOMIC);
 	if (!forw_packet_aggr) {
 		if (!own_packet)
-			atomic_inc(&batman_queue_left);
+			atomic_inc(&bat_priv->batman_queue_left);
 		return;
 	}
 
@@ -129,7 +129,7 @@ static void new_aggregated_packet(unsigned char *packet_buff,
 						GFP_ATOMIC);
 	if (!forw_packet_aggr->packet_buff) {
 		if (!own_packet)
-			atomic_inc(&batman_queue_left);
+			atomic_inc(&bat_priv->batman_queue_left);
 		kfree(forw_packet_aggr);
 		return;
 	}
drivers/staging/batman-adv/bat_sysfs.c +2 -0
index 05ca15a..d49adde 100644
@@ -311,6 +311,8 @@ int sysfs_add_meshif(struct net_device *dev)
 	atomic_set(&bat_priv->vis_mode, VIS_TYPE_CLIENT_UPDATE);
 	atomic_set(&bat_priv->orig_interval, 1000);
 	atomic_set(&bat_priv->log_level, 0);
+	atomic_set(&bat_priv->bcast_queue_left, BCAST_QUEUE_LEN);
+	atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
 
 	bat_priv->primary_if = NULL;
 	bat_priv->num_ifaces = 0;
drivers/staging/batman-adv/main.c +0 -6
index ef7c20a..c0a3373 100644
@@ -42,9 +42,6 @@ DEFINE_SPINLOCK(orig_hash_lock);
 DEFINE_SPINLOCK(forw_bat_list_lock);
 DEFINE_SPINLOCK(forw_bcast_list_lock);
 
-atomic_t bcast_queue_left;
-atomic_t batman_queue_left;
-
 int16_t num_hna;
 
 struct net_device *soft_device;
@@ -69,9 +66,6 @@ static int __init batman_init(void)
 
 	atomic_set(&module_state, MODULE_INACTIVE);
 
-	atomic_set(&bcast_queue_left, BCAST_QUEUE_LEN);
-	atomic_set(&batman_queue_left, BATMAN_QUEUE_LEN);
-
 	/* the name should not be longer than 10 chars - see
 	 * http://lwn.net/Articles/23634/ */
 	bat_event_workqueue = create_singlethread_workqueue("bat_events");
drivers/staging/batman-adv/main.h +0 -2
index 9b30eef..2d364e0 100644
@@ -136,8 +136,6 @@ extern spinlock_t orig_hash_lock;
 extern spinlock_t forw_bat_list_lock;
 extern spinlock_t forw_bcast_list_lock;
 
-extern atomic_t bcast_queue_left;
-extern atomic_t batman_queue_left;
 extern int16_t num_hna;
 
 extern struct net_device *soft_device;
drivers/staging/batman-adv/send.c +8 -4
index da3c82e..e874cae 100644
@@ -404,7 +404,7 @@ int add_bcast_packet_to_list(struct sk_buff *skb)
 	/* FIXME: each batman_if will be attached to a softif */
 	struct bat_priv *bat_priv = netdev_priv(soft_device);
 
-	if (!atomic_dec_not_zero(&bcast_queue_left)) {
+	if (!atomic_dec_not_zero(&bat_priv->bcast_queue_left)) {
 		bat_dbg(DBG_BATMAN, bat_priv, "bcast packet queue full\n");
 		goto out;
 	}
@@ -436,7 +436,7 @@ int add_bcast_packet_to_list(struct sk_buff *skb)
 packet_free:
 	kfree(forw_packet);
 out_and_inc:
-	atomic_inc(&bcast_queue_left);
+	atomic_inc(&bat_priv->bcast_queue_left);
 out:
 	return NETDEV_TX_BUSY;
 }
@@ -450,6 +450,8 @@ static void send_outstanding_bcast_packet(struct work_struct *work)
 		container_of(delayed_work, struct forw_packet, delayed_work);
 	unsigned long flags;
 	struct sk_buff *skb1;
+	/* FIXME: each batman_if will be attached to a softif */
+	struct bat_priv *bat_priv = netdev_priv(soft_device);
 
 	spin_lock_irqsave(&forw_bcast_list_lock, flags);
 	hlist_del(&forw_packet->list);
@@ -479,7 +481,7 @@ static void send_outstanding_bcast_packet(struct work_struct *work)
 
 out:
 	forw_packet_free(forw_packet);
-	atomic_inc(&bcast_queue_left);
+	atomic_inc(&bat_priv->bcast_queue_left);
 }
 
 void send_outstanding_bat_packet(struct work_struct *work)
@@ -489,6 +491,8 @@ void send_outstanding_bat_packet(struct work_struct *work)
 	struct forw_packet *forw_packet =
 		container_of(delayed_work, struct forw_packet, delayed_work);
 	unsigned long flags;
+	/* FIXME: each batman_if will be attached to a softif */
+	struct bat_priv *bat_priv = netdev_priv(soft_device);
 
 	spin_lock_irqsave(&forw_bat_list_lock, flags);
 	hlist_del(&forw_packet->list);
@@ -510,7 +514,7 @@ void send_outstanding_bat_packet(struct work_struct *work)
 out:
 	/* don't count own packet */
 	if (!forw_packet->own)
-		atomic_inc(&batman_queue_left);
+		atomic_inc(&bat_priv->batman_queue_left);
 
 	forw_packet_free(forw_packet);
 }
drivers/staging/batman-adv/types.h +2 -0
index 9aa9d36..67bf4db 100644
@@ -113,6 +113,8 @@ struct bat_priv {
 	atomic_t vis_mode;
 	atomic_t orig_interval;
 	atomic_t log_level;
+	atomic_t bcast_queue_left;
+	atomic_t batman_queue_left;
 	char num_ifaces;
 	struct debug_log *debug_log;
 	struct batman_if *primary_if;
Signature · 1 line
1.7.1
#7 lore raw

PATCH 7/21 Staging: batman-adv: refactoring unicast payload code

In reply to Sven Eckelmann

From: Marek Lindner <[email protected]>

[[email protected]: Rework on top of current version]
---
 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
drivers/staging/batman-adv/Makefile +1 -1
index e9817b5..4b5c434 100644
@@ -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
drivers/staging/batman-adv/soft-interface.c +13 -61

106 lines not on this page · raw message

drivers/staging/batman-adv/unicast.c new file +87 -0

87 lines not on this page · raw message

drivers/staging/batman-adv/unicast.h new file +27 -0
new file mode 100644
index 0000000..dd00703
@@ -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_ */
Signature · 1 line
1.7.1
#8 lore raw

PATCH 8/21 Staging: batman-adv: layer2 unicast packet fragmentation

In reply to Sven Eckelmann

From: Andreas Langer <[email protected]>

This patch implements a simple layer2 fragmentation to allow traffic exchange over network interfaces with a MTU smaller than 1500 bytes. The fragmentation splits the big packets into two parts and marks the frames accordingly. The receiving end buffers the packets to reassemble the orignal packet before passing it to the higher layers. This feature makes it necessary to modify the batman-adv encapsulation for unicast packets by adding a sequence number, flags and the originator address. This modifcation is part of a seperate packet type for fragemented packets to keep the original overhead as low as possible. This patch enables the feature by default to ensure the data traffic can travel through the network. But it also prints a warning to notify the user about the performance implications.

Note: Fragmentation should be avoided at all costs since it has a dramatic impact on the performance, especially when it comes wifi networks. Instead of a single packet, 2 packets have to be sent! Not only valuable airtime is wasted but also packetloss decreases the throughput. A link with 50% packetloss and fragmentation enabled is pretty much unusable.

[[email protected]: Rework on top of current version]
---
 drivers/staging/batman-adv/bat_sysfs.c      |   55 ++++++++
 drivers/staging/batman-adv/hard-interface.c |   34 +++++-
 drivers/staging/batman-adv/originator.c     |   10 ++
 drivers/staging/batman-adv/packet.h         |   26 +++-
 drivers/staging/batman-adv/routing.c        |  115 ++++++++++++++---
 drivers/staging/batman-adv/routing.h        |    1 +
 drivers/staging/batman-adv/soft-interface.c |    4 +-
 drivers/staging/batman-adv/types.h          |   10 ++
 drivers/staging/batman-adv/unicast.c        |  177 +++++++++++++++++++++++++++
 drivers/staging/batman-adv/unicast.h        |   12 ++
 10 files changed, 416 insertions(+), 28 deletions(-)
drivers/staging/batman-adv/bat_sysfs.c +55 -0
index d49adde..b9fe391 100644
@@ -134,6 +134,58 @@ static ssize_t store_bond(struct kobject *kobj, struct attribute *attr,
 	return count;
 }
 
+static ssize_t show_frag(struct kobject *kobj, struct attribute *attr,
+			     char *buff)
+{
+	struct device *dev = to_dev(kobj->parent);
+	struct bat_priv *bat_priv = netdev_priv(to_net_dev(dev));
+	int frag_status = atomic_read(&bat_priv->frag_enabled);
+
+	return sprintf(buff, "%s\n",
+		       frag_status == 0 ? "disabled" : "enabled");
+}
+
+static ssize_t store_frag(struct kobject *kobj, struct attribute *attr,
+			  char *buff, size_t count)
+{
+	struct device *dev = to_dev(kobj->parent);
+	struct net_device *net_dev = to_net_dev(dev);
+	struct bat_priv *bat_priv = netdev_priv(net_dev);
+	int frag_enabled_tmp = -1;
+
+	if (((count == 2) && (buff[0] == '1')) ||
+	    (strncmp(buff, "enable", 6) == 0))
+		frag_enabled_tmp = 1;
+
+	if (((count == 2) && (buff[0] == '0')) ||
+	    (strncmp(buff, "disable", 7) == 0))
+		frag_enabled_tmp = 0;
+
+	if (frag_enabled_tmp < 0) {
+		if (buff[count - 1] == '\n')
+			buff[count - 1] = '\0';
+
+		bat_err(net_dev,
+			"Invalid parameter for 'fragmentation' setting on mesh"
+			"received: %s\n", buff);
+		return -EINVAL;
+	}
+
+	if (atomic_read(&bat_priv->frag_enabled) == frag_enabled_tmp)
+		return count;
+
+	bat_info(net_dev, "Changing fragmentation from: %s to: %s\n",
+		 atomic_read(&bat_priv->frag_enabled) == 1 ?
+		 "enabled" : "disabled",
+		 frag_enabled_tmp == 1 ? "enabled" : "disabled");
+
+	atomic_set(&bat_priv->frag_enabled, (unsigned)frag_enabled_tmp);
+
+	update_min_mtu();
+
+	return count;
+}
+
 static ssize_t show_vis_mode(struct kobject *kobj, struct attribute *attr,
 			     char *buff)
 {
@@ -279,6 +331,7 @@ static ssize_t store_log_level(struct kobject *kobj, struct attribute *attr,
 static BAT_ATTR(aggregated_ogms, S_IRUGO | S_IWUSR,
 		show_aggr_ogms, store_aggr_ogms);
 static BAT_ATTR(bonding, S_IRUGO | S_IWUSR, show_bond, store_bond);
+static BAT_ATTR(fragmentation, S_IRUGO | S_IWUSR, show_frag, store_frag);
 static BAT_ATTR(vis_mode, S_IRUGO | S_IWUSR, show_vis_mode, store_vis_mode);
 static BAT_ATTR(orig_interval, S_IRUGO | S_IWUSR,
 		show_orig_interval, store_orig_interval);
@@ -289,6 +342,7 @@ static BAT_ATTR(log_level, S_IRUGO | S_IWUSR, show_log_level, store_log_level);
 static struct bat_attribute *mesh_attrs[] = {
 	&bat_attr_aggregated_ogms,
 	&bat_attr_bonding,
+	&bat_attr_fragmentation,
 	&bat_attr_vis_mode,
 	&bat_attr_orig_interval,
 #ifdef CONFIG_BATMAN_ADV_DEBUG
@@ -308,6 +362,7 @@ int sysfs_add_meshif(struct net_device *dev)
 		  routine as soon as we have it */
 	atomic_set(&bat_priv->aggregation_enabled, 1);
 	atomic_set(&bat_priv->bonding_enabled, 0);
+	atomic_set(&bat_priv->frag_enabled, 1);
 	atomic_set(&bat_priv->vis_mode, VIS_TYPE_CLIENT_UPDATE);
 	atomic_set(&bat_priv->orig_interval, 1000);
 	atomic_set(&bat_priv->log_level, 0);
drivers/staging/batman-adv/hard-interface.c +33 -1
index 6e973a7..82d3d55 100644
@@ -166,6 +166,11 @@ int hardif_min_mtu(void)
 	/* allow big frames if all devices are capable to do so
 	 * (have MTU > 1500 + BAT_HEADER_LEN) */
 	int min_mtu = ETH_DATA_LEN;
+	/* FIXME: each batman_if will be attached to a softif */
+	struct bat_priv *bat_priv = netdev_priv(soft_device);
+
+	if (atomic_read(&bat_priv->frag_enabled))
+		goto out;
 
 	rcu_read_lock();
 	list_for_each_entry_rcu(batman_if, &if_list, list) {
@@ -175,7 +180,7 @@ int hardif_min_mtu(void)
 				      min_mtu);
 	}
 	rcu_read_unlock();
-
+out:
 	return min_mtu;
 }
 
@@ -261,8 +266,30 @@ int hardif_enable_interface(struct batman_if *batman_if)
 	orig_hash_add_if(batman_if, bat_priv->num_ifaces);
 
 	atomic_set(&batman_if->seqno, 1);
+	atomic_set(&batman_if->frag_seqno, 1);
 	bat_info(soft_device, "Adding interface: %s\n", batman_if->dev);
 
+	if (atomic_read(&bat_priv->frag_enabled) && batman_if->net_dev->mtu <
+		ETH_DATA_LEN + BAT_HEADER_LEN)
+		bat_info(soft_device,
+			"The MTU of interface %s is too small (%i) to handle "
+			"the transport of batman-adv packets. Packets going "
+			"over this interface will be fragmented on layer2 "
+			"which could impact the performance. Setting the MTU "
+			"to %zi would solve the problem.\n",
+			batman_if->dev, batman_if->net_dev->mtu,
+			ETH_DATA_LEN + BAT_HEADER_LEN);
+
+	if (!atomic_read(&bat_priv->frag_enabled) && batman_if->net_dev->mtu <
+		ETH_DATA_LEN + BAT_HEADER_LEN)
+		bat_info(soft_device,
+			"The MTU of interface %s is too small (%i) to handle "
+			"the transport of batman-adv packets. If you experience"
+			" problems getting traffic through try increasing the "
+			"MTU to %zi.\n",
+			batman_if->dev, batman_if->net_dev->mtu,
+			ETH_DATA_LEN + BAT_HEADER_LEN);
+
 	if (hardif_is_iface_up(batman_if))
 		hardif_activate_interface(soft_device, bat_priv, batman_if);
 	else
@@ -495,6 +522,11 @@ int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
 		ret = recv_unicast_packet(skb, batman_if);
 		break;
 
+		/* fragmented unicast packet */
+	case BAT_UNICAST_FRAG:
+		ret = recv_ucast_frag_packet(skb, batman_if);
+		break;
+
 		/* broadcast packet */
 	case BAT_BCAST:
 		ret = recv_bcast_packet(skb);
drivers/staging/batman-adv/originator.c +10 -0
index de5a8c1..b51a13e 100644
@@ -27,6 +27,7 @@
 #include "translation-table.h"
 #include "routing.h"
 #include "hard-interface.h"
+#include "unicast.h"
 
 static DECLARE_DELAYED_WORK(purge_orig_wq, purge_orig);
 
@@ -95,6 +96,7 @@ static void free_orig_node(void *data)
 		kfree(neigh_node);
 	}
 
+	frag_list_free(&orig_node->frag_list);
 	hna_global_del_orig(orig_node, "originator timed out");
 
 	kfree(orig_node->bcast_own);
@@ -157,6 +159,10 @@ struct orig_node *get_orig_node(uint8_t *addr)
 
 	size = bat_priv->num_ifaces * sizeof(uint8_t);
 	orig_node->bcast_own_sum = kzalloc(size, GFP_ATOMIC);
+
+	INIT_LIST_HEAD(&orig_node->frag_list);
+	orig_node->last_frag_packet = 0;
+
 	if (!orig_node->bcast_own_sum)
 		goto free_bcast_own;
 
@@ -271,6 +277,10 @@ void purge_orig(struct work_struct *work)
 			hash_remove_bucket(orig_hash, &hashit);
 			free_orig_node(orig_node);
 		}
+
+		if (time_after(jiffies, (orig_node->last_frag_packet +
+			msecs_to_jiffies(FRAG_TIMEOUT))))
+			frag_list_free(&orig_node->frag_list);
 	}
 
 	spin_unlock_irqrestore(&orig_hash_lock, flags);
drivers/staging/batman-adv/packet.h +20 -6
index abb5e46..44de1bf 100644
@@ -24,14 +24,15 @@
 
 #define ETH_P_BATMAN  0x4305	/* unofficial/not registered Ethertype */
 
-#define BAT_PACKET    0x01
-#define BAT_ICMP      0x02
-#define BAT_UNICAST   0x03
-#define BAT_BCAST     0x04
-#define BAT_VIS       0x05
+#define BAT_PACKET       0x01
+#define BAT_ICMP         0x02
+#define BAT_UNICAST      0x03
+#define BAT_BCAST        0x04
+#define BAT_VIS          0x05
+#define BAT_UNICAST_FRAG 0x06
 
 /* this file is included by batctl which needs these defines */
-#define COMPAT_VERSION 11
+#define COMPAT_VERSION 13
 #define DIRECTLINK 0x40
 #define VIS_SERVER 0x20
 #define PRIMARIES_FIRST_HOP 0x10
@@ -47,6 +48,9 @@
 #define VIS_TYPE_SERVER_SYNC		0
 #define VIS_TYPE_CLIENT_UPDATE		1
 
+/* fragmentation defines */
+#define UNI_FRAG_HEAD 0x01
+
 struct batman_packet {
 	uint8_t  packet_type;
 	uint8_t  version;  /* batman version field */
@@ -96,6 +100,16 @@ struct unicast_packet {
 	uint8_t  ttl;
 } __attribute__((packed));
 
+struct unicast_frag_packet {
+	uint8_t  packet_type;
+	uint8_t  version;  /* batman version field */
+	uint8_t  dest[6];
+	uint8_t  ttl;
+	uint8_t  flags;
+	uint8_t  orig[6];
+	uint16_t seqno;
+} __attribute__((packed));
+
 struct bcast_packet {
 	uint8_t  packet_type;
 	uint8_t  version;  /* batman version field */
drivers/staging/batman-adv/routing.c +95 -20

157 lines not on this page · raw message

drivers/staging/batman-adv/routing.h +1 -0
index 3eac64e..81c684f 100644
@@ -34,6 +34,7 @@ void update_routes(struct orig_node *orig_node,
 				unsigned char *hna_buff, int hna_buff_len);
 int recv_icmp_packet(struct sk_buff *skb);
 int recv_unicast_packet(struct sk_buff *skb, struct batman_if *recv_if);
+int recv_ucast_frag_packet(struct sk_buff *skb, struct batman_if *recv_if);
 int recv_bcast_packet(struct sk_buff *skb);
 int recv_vis_packet(struct sk_buff *skb);
 int recv_bat_packet(struct sk_buff *skb,
drivers/staging/batman-adv/soft-interface.c +3 -1
index 315fdeb..d60b1a8 100644
@@ -249,7 +249,9 @@ void interface_setup(struct net_device *dev)
 #endif
 	dev->destructor = free_netdev;
 
-	dev->mtu = hardif_min_mtu();
+	dev->mtu = ETH_DATA_LEN;	/* can't call min_mtu, because the
+					 * needed variables have not been
+					 * initialized yet */
 	dev->hard_header_len = BAT_HEADER_LEN; /* reserve more space in the
 						* skbuff for our header */
 
drivers/staging/batman-adv/types.h +10 -0
index 67bf4db..ac16575 100644
@@ -41,6 +41,7 @@ struct batman_if {
 	char addr_str[ETH_STR_LEN];
 	struct net_device *net_dev;
 	atomic_t seqno;
+	atomic_t frag_seqno;
 	unsigned char *packet_buff;
 	int packet_len;
 	struct kobject *hardif_obj;
@@ -81,6 +82,8 @@ struct orig_node {
 	TYPE_OF_WORD bcast_bits[NUM_WORDS];
 	uint32_t last_bcast_seqno;
 	struct list_head neigh_list;
+	struct list_head frag_list;
+	unsigned long last_frag_packet;
 	struct {
 		uint8_t candidates;
 		struct neigh_node *selected;
@@ -110,6 +113,7 @@ struct bat_priv {
 	struct net_device_stats stats;
 	atomic_t aggregation_enabled;
 	atomic_t bonding_enabled;
+	atomic_t frag_enabled;
 	atomic_t vis_mode;
 	atomic_t orig_interval;
 	atomic_t log_level;
@@ -183,4 +187,10 @@ struct debug_log {
 	wait_queue_head_t queue_wait;
 };
 
+struct frag_packet_list_entry {
+	struct list_head list;
+	uint16_t seqno;
+	struct sk_buff *skb;
+};
+
 #endif /* _NET_BATMAN_ADV_TYPES_H_ */
drivers/staging/batman-adv/unicast.c +177 -0

195 lines not on this page · raw message

drivers/staging/batman-adv/unicast.h +12 -0
index dd00703..1d5cbeb 100644
@@ -22,6 +22,18 @@
 #ifndef _NET_BATMAN_ADV_UNICAST_H_
 #define _NET_BATMAN_ADV_UNICAST_H_
 
+#define FRAG_TIMEOUT 10000	/* purge frag list entrys after time in ms */
+#define FRAG_BUFFER_SIZE 6	/* number of list elements in buffer */
+
+struct sk_buff *merge_frag_packet(struct list_head *head,
+	struct frag_packet_list_entry *tfp,
+	struct sk_buff *skb);
+
+void create_frag_entry(struct list_head *head, struct sk_buff *skb);
+void create_frag_buffer(struct list_head *head);
+struct frag_packet_list_entry *search_frag_packet(struct list_head *head,
+	struct unicast_frag_packet *up);
+void frag_list_free(struct list_head *head);
 int unicast_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv);
 
 #endif /* _NET_BATMAN_ADV_UNICAST_H_ */
Signature · 1 line
1.7.1
#9 lore raw

PATCH 9/21 Staging: batman-adv: Directly prepare icmp packets in socket buffer

In reply to Sven Eckelmann

It is unnecessary to generate an icmp packet in an extra memory region and than copying it to a new allocated skb.

This also resolved the problem that we do inform the user that we couldn't send the packet because we couldn't allocate the socket buffer.

---
 drivers/staging/batman-adv/icmp_socket.c |   60 +++++++++++++++++++-----------
 1 files changed, 38 insertions(+), 22 deletions(-)
drivers/staging/batman-adv/icmp_socket.c +38 -22
index 3ae7dd2..8e986a1 100644
@@ -154,7 +154,8 @@ static ssize_t bat_socket_write(struct file *file, const char __user *buff,
 {
 	struct socket_client *socket_client = file->private_data;
 	struct bat_priv *bat_priv = socket_client->bat_priv;
-	struct icmp_packet_rr icmp_packet;
+	struct sk_buff *skb;
+	struct icmp_packet_rr *icmp_packet;
 	struct orig_node *orig_node;
 	struct batman_if *batman_if;
 	size_t packet_len = sizeof(struct icmp_packet);
@@ -174,40 +175,53 @@ 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);
 
-	if (!access_ok(VERIFY_READ, buff, packet_len))
-		return -EFAULT;
+	skb = dev_alloc_skb(packet_len + sizeof(struct ethhdr));
+	if (!skb)
+		return -ENOMEM;
 
-	if (__copy_from_user(&icmp_packet, buff, packet_len))
-		return -EFAULT;
+	skb_reserve(skb, sizeof(struct ethhdr));
+	icmp_packet = (struct icmp_packet_rr *)skb_put(skb, packet_len);
 
-	if (icmp_packet.packet_type != BAT_ICMP) {
+	if (!access_ok(VERIFY_READ, buff, packet_len)) {
+		len = -EFAULT;
+		goto free_skb;
+	}
+
+	if (__copy_from_user(icmp_packet, buff, packet_len)) {
+		len = -EFAULT;
+		goto free_skb;
+	}
+
+	if (icmp_packet->packet_type != BAT_ICMP) {
 		bat_dbg(DBG_BATMAN, bat_priv,
 			"Error - can't send packet from char device: "
 			"got bogus packet type (expected: BAT_ICMP)\n");
-		return -EINVAL;
+		len = -EINVAL;
+		goto free_skb;
 	}
 
-	if (icmp_packet.msg_type != ECHO_REQUEST) {
+	if (icmp_packet->msg_type != ECHO_REQUEST) {
 		bat_dbg(DBG_BATMAN, bat_priv,
 			"Error - can't send packet from char device: "
 			"got bogus message type (expected: ECHO_REQUEST)\n");
-		return -EINVAL;
+		len = -EINVAL;
+		goto free_skb;
 	}
 
-	icmp_packet.uid = socket_client->index;
+	icmp_packet->uid = socket_client->index;
 
-	if (icmp_packet.version != COMPAT_VERSION) {
-		icmp_packet.msg_type = PARAMETER_PROBLEM;
-		icmp_packet.ttl = COMPAT_VERSION;
-		bat_socket_add_packet(socket_client, &icmp_packet, packet_len);
-		goto out;
+	if (icmp_packet->version != COMPAT_VERSION) {
+		icmp_packet->msg_type = PARAMETER_PROBLEM;
+		icmp_packet->ttl = COMPAT_VERSION;
+		bat_socket_add_packet(socket_client, icmp_packet, packet_len);
+		goto free_skb;
 	}
 
 	if (atomic_read(&module_state) != MODULE_ACTIVE)
 		goto dst_unreach;
 
 	spin_lock_irqsave(&orig_hash_lock, flags);
-	orig_node = ((struct orig_node *)hash_find(orig_hash, icmp_packet.dst));
+	orig_node = (struct orig_node *)hash_find(orig_hash, icmp_packet->dst);
 
 	if (!orig_node)
 		goto unlock;
@@ -226,22 +240,24 @@ static ssize_t bat_socket_write(struct file *file, const char __user *buff,
 	if (batman_if->if_status != IF_ACTIVE)
 		goto dst_unreach;
 
-	memcpy(icmp_packet.orig,
+	memcpy(icmp_packet->orig,
 	       bat_priv->primary_if->net_dev->dev_addr, ETH_ALEN);
 
 	if (packet_len == sizeof(struct icmp_packet_rr))
-		memcpy(icmp_packet.rr, batman_if->net_dev->dev_addr, ETH_ALEN);
+		memcpy(icmp_packet->rr, batman_if->net_dev->dev_addr, ETH_ALEN);
 
-	send_raw_packet((unsigned char *)&icmp_packet,
-			packet_len, batman_if, dstaddr);
+
+	send_skb_packet(skb, batman_if, dstaddr);
 
 	goto out;
 
 unlock:
 	spin_unlock_irqrestore(&orig_hash_lock, flags);
 dst_unreach:
-	icmp_packet.msg_type = DESTINATION_UNREACHABLE;
-	bat_socket_add_packet(socket_client, &icmp_packet, packet_len);
+	icmp_packet->msg_type = DESTINATION_UNREACHABLE;
+	bat_socket_add_packet(socket_client, icmp_packet, packet_len);
+free_skb:
+	kfree_skb(skb);
 out:
 	return len;
 }
Signature · 1 line
1.7.1
#10 lore raw

PATCH 10/21 Staging: batman-adv: register the batman-adv packet type per interface

In reply to Sven Eckelmann

From: Marek Lindner <[email protected]>

Batman-adv globally registered the batman-adv packet type and installed a hook to batman_skb_recv(). Each interface receiving a packet with that type would end up in this function which then had to loop through all batman-adv internal interface structures to find the its meta data. The more interfaces a system had the longer the loops might take. Each and every packet goes through this function making it a performance critical loop.

This patch installs the hook for each activated interface. The called batman_skb_recv() can distinguish these calls, therefore avoiding the loop through the interface structures.

[[email protected]: Rework on top of current version]
---
 drivers/staging/batman-adv/hard-interface.c |   12 ++++++++----
 drivers/staging/batman-adv/main.c           |   10 ----------
 drivers/staging/batman-adv/types.h          |    2 +-
 3 files changed, 9 insertions(+), 15 deletions(-)
drivers/staging/batman-adv/hard-interface.c +8 -4
index 82d3d55..f33c73f 100644
@@ -265,6 +265,11 @@ int hardif_enable_interface(struct batman_if *batman_if)
 	batman_if->if_status = IF_INACTIVE;
 	orig_hash_add_if(batman_if, bat_priv->num_ifaces);
 
+	batman_if->batman_adv_ptype.type = __constant_htons(ETH_P_BATMAN);
+	batman_if->batman_adv_ptype.func = batman_skb_recv;
+	batman_if->batman_adv_ptype.dev = batman_if->net_dev;
+	dev_add_pack(&batman_if->batman_adv_ptype);
+
 	atomic_set(&batman_if->seqno, 1);
 	atomic_set(&batman_if->frag_seqno, 1);
 	bat_info(soft_device, "Adding interface: %s\n", batman_if->dev);
@@ -319,6 +324,8 @@ void hardif_disable_interface(struct batman_if *batman_if)
 		return;
 
 	bat_info(soft_device, "Removing interface: %s\n", batman_if->dev);
+	dev_remove_pack(&batman_if->batman_adv_ptype);
+
 	bat_priv->num_ifaces--;
 	orig_hash_del_if(batman_if, bat_priv->num_ifaces);
 
@@ -468,6 +475,7 @@ int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
 	struct batman_if *batman_if;
 	int ret;
 
+	batman_if = container_of(ptype, struct batman_if, batman_adv_ptype);
 	skb = skb_share_check(skb, GFP_ATOMIC);
 
 	/* skb was released by skb_share_check() */
@@ -486,10 +494,6 @@ int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
 				|| !skb_mac_header(skb)))
 		goto err_free;
 
-	batman_if = get_batman_if_by_netdev(skb->dev);
-	if (!batman_if)
-		goto err_free;
-
 	/* discard frames on not active interfaces */
 	if (batman_if->if_status != IF_ACTIVE)
 		goto err_free;
drivers/staging/batman-adv/main.c +0 -10
index c0a3373..eb0bfbe 100644
@@ -49,11 +49,6 @@ struct net_device *soft_device;
 unsigned char broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
 atomic_t module_state;
 
-static struct packet_type batman_adv_packet_type __read_mostly = {
-	.type = __constant_htons(ETH_P_BATMAN),
-	.func = batman_skb_recv,
-};
-
 struct workqueue_struct *bat_event_workqueue;
 
 static int __init batman_init(void)
@@ -103,7 +98,6 @@ static int __init batman_init(void)
 		goto unreg_sysfs;
 
 	register_netdevice_notifier(&hard_if_notifier);
-	dev_add_pack(&batman_adv_packet_type);
 
 	pr_info("B.A.T.M.A.N. advanced %s%s (compatibility version %i) "
 		"loaded\n", SOURCE_VERSION, REVISION_VERSION_STR,
@@ -140,8 +134,6 @@ static void __exit batman_exit(void)
 		soft_device = NULL;
 	}
 
-	dev_remove_pack(&batman_adv_packet_type);
-
 	destroy_workqueue(bat_event_workqueue);
 	bat_event_workqueue = NULL;
 }
@@ -185,8 +177,6 @@ void deactivate_module(void)
 
 	vis_quit();
 
-	/* TODO: unregister BATMAN pack */
-
 	originator_free();
 
 	hna_local_free();
drivers/staging/batman-adv/types.h +1 -1
index ac16575..2b06944 100644
@@ -46,7 +46,7 @@ struct batman_if {
 	int packet_len;
 	struct kobject *hardif_obj;
 	struct rcu_head rcu;
-
+	struct packet_type batman_adv_ptype;
 };
 
 /**
Signature · 1 line
1.7.1
#11 lore raw

PATCH 11/21 Staging: batman-adv: Keep header writable and unshared

In reply to Sven Eckelmann

my_skb_push provided an easy way to allocate enough headroom in situation were we don't have enough space left and move the data pointer to the new position, but we didn't checked wether we are allowed to write to the new pushed header. This is for example a problem when the skb was cloned and thus doesn't have a private data part.

my_skb_head_push now replaces my_skb_push by using skb_cow_head to provide only a large enough, writable header without testing for the rest of the (maybe shared) data. It will also move the data pointer using skb_push when skb_cow_head doesn't fail.

This should give us enough flexibility in situation were skbs will be queued by underlying layers and still doesn't unnecessarily copy the data in situations when the skb was consumed right away during dev_queue_xmit.

---
 drivers/staging/batman-adv/send.c           |    2 +-
 drivers/staging/batman-adv/soft-interface.c |   26 ++++++++++++++------------
 drivers/staging/batman-adv/soft-interface.h |    2 +-
 drivers/staging/batman-adv/unicast.c        |    6 +++---
 4 files changed, 19 insertions(+), 17 deletions(-)
drivers/staging/batman-adv/send.c +1 -1
index e874cae..b39c67b 100644
@@ -73,7 +73,7 @@ int send_skb_packet(struct sk_buff *skb,
 	}
 
 	/* push to the ethernet header. */
-	if (my_skb_push(skb, sizeof(struct ethhdr)) < 0)
+	if (my_skb_head_push(skb, sizeof(struct ethhdr)) < 0)
 		goto send_skb_err;
 
 	skb_reset_mac_header(skb);
drivers/staging/batman-adv/soft-interface.c +14 -12
index d60b1a8..e8be209 100644
@@ -31,8 +31,6 @@
 
 static uint32_t bcast_seqno = 1; /* give own bcast messages seq numbers to avoid
 				  * broadcast storms */
-static int32_t skb_packets;
-static int32_t skb_bad_packets;
 
 unsigned char main_if_addr[ETH_ALEN];
 static int bat_get_settings(struct net_device *dev, struct ethtool_cmd *cmd);
@@ -59,18 +57,22 @@ void set_main_if_addr(uint8_t *addr)
 	memcpy(main_if_addr, addr, ETH_ALEN);
 }
 
-int my_skb_push(struct sk_buff *skb, unsigned int len)
+int my_skb_head_push(struct sk_buff *skb, unsigned int len)
 {
-	int result = 0;
+	int result;
 
-	skb_packets++;
-	if (skb_headroom(skb) < len) {
-		skb_bad_packets++;
-		result = pskb_expand_head(skb, len, 0, GFP_ATOMIC);
+	/**
+	 * TODO: We must check if we can release all references to non-payload
+	 * data using skb_header_release in our skbs to allow skb_cow_header to
+	 * work optimally. This means that those skbs are not allowed to read
+	 * or write any data which is before the current position of skb->data
+	 * after that call and thus allow other skbs with the same data buffer
+	 * to write freely in that area.
+	 */
+	result = skb_cow_head(skb, len);
 
-		if (result < 0)
-			return result;
-	}
+	if (result < 0)
+		return result;
 
 	skb_push(skb, len);
 	return 0;
@@ -140,7 +142,7 @@ int interface_tx(struct sk_buff *skb, struct net_device *dev)
 	/* ethernet packet should be broadcasted */
 	if (is_bcast(ethhdr->h_dest) || is_mcast(ethhdr->h_dest)) {
 
-		if (my_skb_push(skb, sizeof(struct bcast_packet)) < 0)
+		if (my_skb_head_push(skb, sizeof(struct bcast_packet)) < 0)
 			goto dropped;
 
 		bcast_packet = (struct bcast_packet *)skb->data;
drivers/staging/batman-adv/soft-interface.h +1 -1
index 6364854..9dbf5fc 100644
@@ -26,7 +26,7 @@ void set_main_if_addr(uint8_t *addr);
 void interface_setup(struct net_device *dev);
 int interface_tx(struct sk_buff *skb, struct net_device *dev);
 void interface_rx(struct sk_buff *skb, int hdr_size);
-int my_skb_push(struct sk_buff *skb, unsigned int len);
+int my_skb_head_push(struct sk_buff *skb, unsigned int len);
 
 extern unsigned char main_if_addr[];
 
drivers/staging/batman-adv/unicast.c +3 -3
index 153914e..61ebd38 100644
@@ -163,8 +163,8 @@ static int unicast_send_frag_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
 	frag_skb = dev_alloc_skb(data_len - (data_len / 2) + hdr_len);
 	skb_split(skb, frag_skb, data_len / 2);
 
-	if (my_skb_push(frag_skb, hdr_len) < 0 ||
-	    my_skb_push(skb, hdr_len) < 0)
+	if (my_skb_head_push(frag_skb, hdr_len) < 0 ||
+	    my_skb_head_push(skb, hdr_len) < 0)
 		goto drop_frag;
 
 	ucast_frag1 = (struct unicast_frag_packet *)skb->data;
@@ -240,7 +240,7 @@ int unicast_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv)
 		return unicast_send_frag_skb(skb, bat_priv, batman_if,
 					     dstaddr, orig_node);
 
-	if (my_skb_push(skb, sizeof(struct unicast_packet)) < 0)
+	if (my_skb_head_push(skb, sizeof(struct unicast_packet)) < 0)
 		goto dropped;
 
 	unicast_packet = (struct unicast_packet *)skb->data;
Signature · 1 line
1.7.1
#12 lore raw

PATCH 12/21 Staging: batman-adv: Only clone skb data for multiple broadcasts

In reply to Sven Eckelmann

batman-adv tries to resend broadcasts on all interfaces up to three times. For each round and each interface it must provide a skb which gets consumed by the sending function.

It is unnecessary to copy the data of each broadcast because the actual data is either not shared or already copied by add_bcast_packet_to_list. So it is enough to just copy the skb control data

---
 drivers/staging/batman-adv/send.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/staging/batman-adv/send.c +1 -1
index b39c67b..8dd9dd4 100644
@@ -464,7 +464,7 @@ static void send_outstanding_bcast_packet(struct work_struct *work)
 	rcu_read_lock();
 	list_for_each_entry_rcu(batman_if, &if_list, list) {
 		/* send a copy of the saved skb */
-		skb1 = skb_copy(forw_packet->skb, GFP_ATOMIC);
+		skb1 = skb_clone(forw_packet->skb, GFP_ATOMIC);
 		if (skb1)
 			send_skb_packet(skb1,
 				batman_if, broadcast_addr);
Signature · 1 line
1.7.1
#13 lore raw

PATCH 13/21 Staging: batman-adv: Aggregate batman packets directly in skb

In reply to Sven Eckelmann

All originator messages are send through aggregation buffers. Those buffers can directly be allocated as skb to reduce the cost of allocation an extra buffer and copying them to a new allocated skb directly before it gets send.

Now only the skb must be cloned in case of send_packet_to_if as it gets called by send_packet for each interface. Non-primary ogms must not cloned at all because they will only send once and the forward_packet structure is freed by send_outstanding_bat_packet afterwards.

---
 drivers/staging/batman-adv/aggregation.c |   22 ++++++++++++----------
 drivers/staging/batman-adv/send.c        |   24 ++++++++++++------------
 drivers/staging/batman-adv/types.h       |    1 -
 3 files changed, 24 insertions(+), 23 deletions(-)
drivers/staging/batman-adv/aggregation.c +12 -10
index d738b7a..5896cf2 100644
@@ -39,7 +39,7 @@ static bool can_aggregate_with(struct batman_packet *new_batman_packet,
 			       struct forw_packet *forw_packet)
 {
 	struct batman_packet *batman_packet =
-		(struct batman_packet *)forw_packet->packet_buff;
+		(struct batman_packet *)forw_packet->skb->data;
 	int aggregated_bytes = forw_packet->packet_len + packet_len;
 
 	/**
@@ -106,6 +106,7 @@ static void new_aggregated_packet(unsigned char *packet_buff,
 {
 	struct forw_packet *forw_packet_aggr;
 	unsigned long flags;
+	unsigned char *skb_buff;
 	/* FIXME: each batman_if will be attached to a softif */
 	struct bat_priv *bat_priv = netdev_priv(soft_device);
 
@@ -125,23 +126,22 @@ static void new_aggregated_packet(unsigned char *packet_buff,
 		return;
 	}
 
-	forw_packet_aggr->packet_buff = kmalloc(MAX_AGGREGATION_BYTES,
-						GFP_ATOMIC);
-	if (!forw_packet_aggr->packet_buff) {
+	forw_packet_aggr->skb = dev_alloc_skb(MAX_AGGREGATION_BYTES +
+					      sizeof(struct ethhdr));
+	if (!forw_packet_aggr->skb) {
 		if (!own_packet)
 			atomic_inc(&bat_priv->batman_queue_left);
 		kfree(forw_packet_aggr);
 		return;
 	}
+	skb_reserve(forw_packet_aggr->skb, sizeof(struct ethhdr));
 
 	INIT_HLIST_NODE(&forw_packet_aggr->list);
 
+	skb_buff = skb_put(forw_packet_aggr->skb, packet_len);
 	forw_packet_aggr->packet_len = packet_len;
-	memcpy(forw_packet_aggr->packet_buff,
-	       packet_buff,
-	       forw_packet_aggr->packet_len);
+	memcpy(skb_buff, packet_buff, packet_len);
 
-	forw_packet_aggr->skb = NULL;
 	forw_packet_aggr->own = own_packet;
 	forw_packet_aggr->if_incoming = if_incoming;
 	forw_packet_aggr->num_packets = 0;
@@ -171,8 +171,10 @@ static void aggregate(struct forw_packet *forw_packet_aggr,
 		      int packet_len,
 		      bool direct_link)
 {
-	memcpy((forw_packet_aggr->packet_buff + forw_packet_aggr->packet_len),
-	       packet_buff, packet_len);
+	unsigned char *skb_buff;
+
+	skb_buff = skb_put(forw_packet_aggr->skb, packet_len);
+	memcpy(skb_buff, packet_buff, packet_len);
 	forw_packet_aggr->packet_len += packet_len;
 	forw_packet_aggr->num_packets++;
 
drivers/staging/batman-adv/send.c +12 -12
index 8dd9dd4..6b138b9 100644
@@ -126,14 +126,14 @@ static void send_packet_to_if(struct forw_packet *forw_packet,
 	uint8_t packet_num;
 	int16_t buff_pos;
 	struct batman_packet *batman_packet;
+	struct sk_buff *skb;
 
 	if (batman_if->if_status != IF_ACTIVE)
 		return;
 
 	packet_num = 0;
 	buff_pos = 0;
-	batman_packet = (struct batman_packet *)
-		(forw_packet->packet_buff);
+	batman_packet = (struct batman_packet *)forw_packet->skb->data;
 
 	/* adjust all flags and log packets */
 	while (aggregated_packet(buff_pos,
@@ -165,12 +165,13 @@ static void send_packet_to_if(struct forw_packet *forw_packet,
 			(batman_packet->num_hna * ETH_ALEN);
 		packet_num++;
 		batman_packet = (struct batman_packet *)
-			(forw_packet->packet_buff + buff_pos);
+			(forw_packet->skb->data + buff_pos);
 	}
 
-	send_raw_packet(forw_packet->packet_buff,
-			forw_packet->packet_len,
-			batman_if, broadcast_addr);
+	/* create clone because function is called more than once */
+	skb = skb_clone(forw_packet->skb, GFP_ATOMIC);
+	if (skb)
+		send_skb_packet(skb, batman_if, broadcast_addr);
 }
 
 /* send a batman packet */
@@ -180,7 +181,7 @@ static void send_packet(struct forw_packet *forw_packet)
 	struct bat_priv *bat_priv = netdev_priv(soft_device);
 	struct batman_if *batman_if;
 	struct batman_packet *batman_packet =
-		(struct batman_packet *)(forw_packet->packet_buff);
+		(struct batman_packet *)(forw_packet->skb->data);
 	unsigned char directlink = (batman_packet->flags & DIRECTLINK ? 1 : 0);
 
 	if (!forw_packet->if_incoming) {
@@ -206,10 +207,11 @@ static void send_packet(struct forw_packet *forw_packet)
 			batman_packet->ttl, forw_packet->if_incoming->dev,
 			forw_packet->if_incoming->addr_str);
 
-		send_raw_packet(forw_packet->packet_buff,
-				forw_packet->packet_len,
-				forw_packet->if_incoming,
+		/* skb is only used once and than forw_packet is free'd */
+		send_skb_packet(forw_packet->skb, forw_packet->if_incoming,
 				broadcast_addr);
+		forw_packet->skb = NULL;
+
 		return;
 	}
 
@@ -366,7 +368,6 @@ static void forw_packet_free(struct forw_packet *forw_packet)
 {
 	if (forw_packet->skb)
 		kfree_skb(forw_packet->skb);
-	kfree(forw_packet->packet_buff);
 	kfree(forw_packet);
 }
 
@@ -425,7 +426,6 @@ int add_bcast_packet_to_list(struct sk_buff *skb)
 	skb_reset_mac_header(skb);
 
 	forw_packet->skb = skb;
-	forw_packet->packet_buff = NULL;
 
 	/* how often did we send the bcast packet ? */
 	forw_packet->num_packets = 0;
drivers/staging/batman-adv/types.h +0 -1
index 2b06944..4b2e832 100644
@@ -161,7 +161,6 @@ struct forw_packet {
 	unsigned long send_time;
 	uint8_t own;
 	struct sk_buff *skb;
-	unsigned char *packet_buff;
 	uint16_t packet_len;
 	uint32_t direct_link_flags;
 	uint8_t num_packets;
Signature · 1 line
1.7.1
#14 lore raw

PATCH 14/21 Staging: batman-adv: Prepare vis packets directly inside a skb

In reply to Sven Eckelmann

The vis information structure is used in a way that it can be transfered directly as packet. It still had to be copied into a skb because of an extra buffer used for the actual preparation of the data. This is unnecessary and can be replaced by a simple clone instead of an full copy before each send.

This makes also the send_raw_packet function obsolete.

---
 drivers/staging/batman-adv/TODO   |    2 -
 drivers/staging/batman-adv/send.c |   17 ---
 drivers/staging/batman-adv/send.h |    2 -
 drivers/staging/batman-adv/vis.c  |  206 ++++++++++++++++++++++++-------------
 drivers/staging/batman-adv/vis.h  |    2 +-
 5 files changed, 133 insertions(+), 96 deletions(-)
drivers/staging/batman-adv/TODO +0 -2
index d8bf845..1457c7f 100644
@@ -1,5 +1,3 @@
- * Save/cache packets direktly as skb instead of using a normal memory region
-   and copying it in a skb using send_raw_packet and similar functions
  * Request a new review
  * Process the comments from the review
  * Move into mainline proper
drivers/staging/batman-adv/send.c +0 -17
index 6b138b9..aebd6c3 100644
@@ -99,23 +99,6 @@ send_skb_err:
 	return NET_XMIT_DROP;
 }
 
-/* sends a raw packet. */
-void send_raw_packet(unsigned char *pack_buff, int pack_buff_len,
-		     struct batman_if *batman_if, uint8_t *dst_addr)
-{
-	struct sk_buff *skb;
-	char *data;
-
-	skb = dev_alloc_skb(pack_buff_len + sizeof(struct ethhdr));
-	if (!skb)
-		return;
-	data = skb_put(skb, pack_buff_len + sizeof(struct ethhdr));
-	memcpy(data + sizeof(struct ethhdr), pack_buff, pack_buff_len);
-	/* pull back to the batman "network header" */
-	skb_pull(skb, sizeof(struct ethhdr));
-	send_skb_packet(skb, batman_if, dst_addr);
-}
-
 /* Send a packet to a given interface */
 static void send_packet_to_if(struct forw_packet *forw_packet,
 			      struct batman_if *batman_if)
drivers/staging/batman-adv/send.h +0 -2
index b64c627..0cfe027 100644
@@ -27,8 +27,6 @@
 int send_skb_packet(struct sk_buff *skb,
 				struct batman_if *batman_if,
 				uint8_t *dst_addr);
-void send_raw_packet(unsigned char *pack_buff, int pack_buff_len,
-		     struct batman_if *batman_if, uint8_t *dst_addr);
 void schedule_own_packet(struct batman_if *batman_if);
 void schedule_forward_packet(struct orig_node *orig_node,
 			     struct ethhdr *ethhdr,
drivers/staging/batman-adv/vis.c +132 -74

492 lines not on this page · raw message

drivers/staging/batman-adv/vis.h +1 -1
index bb13bf1..19dc325 100644
@@ -32,7 +32,7 @@ struct vis_info {
 	struct list_head send_list;
 	struct kref refcount;
 	/* this packet might be part of the vis send queue. */
-	struct vis_packet packet;
+	struct sk_buff *skb_packet;
 	/* vis_info may follow here*/
 } __attribute__((packed));
 
Signature · 1 line
1.7.1
#15 lore raw

PATCH 15/21 Staging: batman-adv: Create copy of skb with pre-allocated headroom

In reply to Sven Eckelmann

We can use skb_cow instead of a handwritten function to test and create a writable skb buffer. This also allows us to pre-allocate headroom to be able to send the data without re-allocating the buffer again to add the ethernet header.

---
 drivers/staging/batman-adv/routing.c |   77 ++++++++++-----------------------
 1 files changed, 24 insertions(+), 53 deletions(-)
drivers/staging/batman-adv/routing.c +24 -53
index d8e77ac..7e993a2 100644
@@ -742,7 +742,6 @@ int recv_bat_packet(struct sk_buff *skb,
 {
 	struct ethhdr *ethhdr;
 	unsigned long flags;
-	struct sk_buff *skb_old;
 
 	/* drop packet if it has not necessary minimum size */
 	if (skb_headlen(skb) < sizeof(struct batman_packet))
@@ -758,18 +757,11 @@ int recv_bat_packet(struct sk_buff *skb,
 	if (is_bcast(ethhdr->h_source))
 		return NET_RX_DROP;
 
-	/* TODO: we use headlen instead of "length", because
-	 * only this data is paged in. */
-
 	/* create a copy of the skb, if needed, to modify it. */
-	if (!skb_clone_writable(skb, skb_headlen(skb))) {
-		skb_old = skb;
-		skb = skb_copy(skb, GFP_ATOMIC);
-		if (!skb)
-			return NET_RX_DROP;
-		ethhdr = (struct ethhdr *)skb_mac_header(skb);
-		kfree_skb(skb_old);
-	}
+	if (skb_cow(skb, 0) < 0)
+		return NET_RX_DROP;
+
+	ethhdr = (struct ethhdr *)skb_mac_header(skb);
 
 	spin_lock_irqsave(&orig_hash_lock, flags);
 	receive_aggr_bat_packet(ethhdr,
@@ -789,7 +781,6 @@ static int recv_my_icmp_packet(struct sk_buff *skb, size_t icmp_len)
 	struct orig_node *orig_node;
 	struct icmp_packet_rr *icmp_packet;
 	struct ethhdr *ethhdr;
-	struct sk_buff *skb_old;
 	struct batman_if *batman_if;
 	int ret;
 	unsigned long flags;
@@ -824,16 +815,11 @@ static int recv_my_icmp_packet(struct sk_buff *skb, size_t icmp_len)
 		spin_unlock_irqrestore(&orig_hash_lock, flags);
 
 		/* create a copy of the skb, if needed, to modify it. */
-		skb_old = NULL;
-		if (!skb_clone_writable(skb, icmp_len)) {
-			skb_old = skb;
-			skb = skb_copy(skb, GFP_ATOMIC);
-			if (!skb)
-				return NET_RX_DROP;
-			icmp_packet = (struct icmp_packet_rr *)skb->data;
-			ethhdr = (struct ethhdr *)skb_mac_header(skb);
-			kfree_skb(skb_old);
-		}
+		if (skb_cow(skb, sizeof(struct ethhdr)) < 0)
+			return NET_RX_DROP;
+
+		icmp_packet = (struct icmp_packet_rr *)skb->data;
+		ethhdr = (struct ethhdr *)skb_mac_header(skb);
 
 		memcpy(icmp_packet->dst, icmp_packet->orig, ETH_ALEN);
 		memcpy(icmp_packet->orig,
@@ -857,7 +843,6 @@ static int recv_icmp_ttl_exceeded(struct sk_buff *skb, size_t icmp_len)
 	struct orig_node *orig_node;
 	struct icmp_packet *icmp_packet;
 	struct ethhdr *ethhdr;
-	struct sk_buff *skb_old;
 	struct batman_if *batman_if;
 	int ret;
 	unsigned long flags;
@@ -893,15 +878,11 @@ static int recv_icmp_ttl_exceeded(struct sk_buff *skb, size_t icmp_len)
 		spin_unlock_irqrestore(&orig_hash_lock, flags);
 
 		/* create a copy of the skb, if needed, to modify it. */
-		if (!skb_clone_writable(skb, icmp_len)) {
-			skb_old = skb;
-			skb = skb_copy(skb, GFP_ATOMIC);
-			if (!skb)
-				return NET_RX_DROP;
-			icmp_packet = (struct icmp_packet *) skb->data;
-			ethhdr = (struct ethhdr *)skb_mac_header(skb);
-			kfree_skb(skb_old);
-		}
+		if (skb_cow(skb, sizeof(struct ethhdr)) < 0)
+			return NET_RX_DROP;
+
+		icmp_packet = (struct icmp_packet *) skb->data;
+		ethhdr = (struct ethhdr *)skb_mac_header(skb);
 
 		memcpy(icmp_packet->dst, icmp_packet->orig, ETH_ALEN);
 		memcpy(icmp_packet->orig,
@@ -924,7 +905,6 @@ int recv_icmp_packet(struct sk_buff *skb)
 	struct icmp_packet_rr *icmp_packet;
 	struct ethhdr *ethhdr;
 	struct orig_node *orig_node;
-	struct sk_buff *skb_old;
 	struct batman_if *batman_if;
 	int hdr_size = sizeof(struct icmp_packet);
 	int ret;
@@ -990,15 +970,11 @@ int recv_icmp_packet(struct sk_buff *skb)
 		spin_unlock_irqrestore(&orig_hash_lock, flags);
 
 		/* create a copy of the skb, if needed, to modify it. */
-		if (!skb_clone_writable(skb, hdr_size)) {
-			skb_old = skb;
-			skb = skb_copy(skb, GFP_ATOMIC);
-			if (!skb)
-				return NET_RX_DROP;
-			icmp_packet = (struct icmp_packet_rr *)skb->data;
-			ethhdr = (struct ethhdr *)skb_mac_header(skb);
-			kfree_skb(skb_old);
-		}
+		if (skb_cow(skb, sizeof(struct ethhdr)) < 0)
+			return NET_RX_DROP;
+
+		icmp_packet = (struct icmp_packet_rr *)skb->data;
+		ethhdr = (struct ethhdr *)skb_mac_header(skb);
 
 		/* decrement ttl */
 		icmp_packet->ttl--;
@@ -1137,7 +1113,6 @@ static int route_unicast_packet(struct sk_buff *skb, struct batman_if *recv_if,
 	struct orig_node *orig_node;
 	struct neigh_node *router;
 	struct batman_if *batman_if;
-	struct sk_buff *skb_old;
 	uint8_t dstaddr[ETH_ALEN];
 	unsigned long flags;
 	struct unicast_packet *unicast_packet =
@@ -1173,15 +1148,11 @@ static int route_unicast_packet(struct sk_buff *skb, struct batman_if *recv_if,
 	spin_unlock_irqrestore(&orig_hash_lock, flags);
 
 	/* create a copy of the skb, if needed, to modify it. */
-	if (!skb_clone_writable(skb, hdr_size)) {
-		skb_old = skb;
-		skb = skb_copy(skb, GFP_ATOMIC);
-		if (!skb)
-			return NET_RX_DROP;
-		unicast_packet = (struct unicast_packet *) skb->data;
-		ethhdr = (struct ethhdr *)skb_mac_header(skb);
-		kfree_skb(skb_old);
-	}
+	if (skb_cow(skb, sizeof(struct ethhdr)) < 0)
+		return NET_RX_DROP;
+
+	unicast_packet = (struct unicast_packet *) skb->data;
+	ethhdr = (struct ethhdr *)skb_mac_header(skb);
 
 	/* decrement ttl */
 	unicast_packet->ttl--;
Signature · 1 line
1.7.1
#16 lore raw

PATCH 16/21 Staging: batman-adv: Provide full headers and packets as linear skb

In reply to Sven Eckelmann

We must ensure that all interesting data is linear and not paged out to access all information in a header or a full batman-adv related packet. Otherwise we may drop packets which have non-linear headers but which hold valid data.

This doesn't affect non-linear skbs which have all headers in a linear head unless we must process the whole packet like in ogms or vis packets.

---
 drivers/staging/batman-adv/hard-interface.c |    2 +-
 drivers/staging/batman-adv/routing.c        |   22 ++++++++++++++--------
 2 files changed, 15 insertions(+), 9 deletions(-)
drivers/staging/batman-adv/hard-interface.c +1 -1
index f33c73f..c1863d2 100644
@@ -486,7 +486,7 @@ int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
 		goto err_free;
 
 	/* packet should hold at least type and version */
-	if (unlikely(skb_headlen(skb) < 2))
+	if (unlikely(!pskb_may_pull(skb, 2)))
 		goto err_free;
 
 	/* expect a valid ethernet header here. */
drivers/staging/batman-adv/routing.c +14 -8
index 7e993a2..6009adc 100644
@@ -744,7 +744,7 @@ int recv_bat_packet(struct sk_buff *skb,
 	unsigned long flags;
 
 	/* drop packet if it has not necessary minimum size */
-	if (skb_headlen(skb) < sizeof(struct batman_packet))
+	if (unlikely(!pskb_may_pull(skb, sizeof(struct batman_packet))))
 		return NET_RX_DROP;
 
 	ethhdr = (struct ethhdr *)skb_mac_header(skb);
@@ -761,6 +761,10 @@ int recv_bat_packet(struct sk_buff *skb,
 	if (skb_cow(skb, 0) < 0)
 		return NET_RX_DROP;
 
+	/* keep skb linear */
+	if (skb_linearize(skb) < 0)
+		return NET_RX_DROP;
+
 	ethhdr = (struct ethhdr *)skb_mac_header(skb);
 
 	spin_lock_irqsave(&orig_hash_lock, flags);
@@ -914,11 +918,11 @@ int recv_icmp_packet(struct sk_buff *skb)
 	/**
 	 * we truncate all incoming icmp packets if they don't match our size
 	 */
-	if (skb_headlen(skb) >= sizeof(struct icmp_packet_rr))
+	if (skb->len >= sizeof(struct icmp_packet_rr))
 		hdr_size = sizeof(struct icmp_packet_rr);
 
 	/* drop packet if it has not necessary minimum size */
-	if (skb_headlen(skb) < hdr_size)
+	if (unlikely(!pskb_may_pull(skb, hdr_size)))
 		return NET_RX_DROP;
 
 	ethhdr = (struct ethhdr *)skb_mac_header(skb);
@@ -1087,7 +1091,7 @@ static int check_unicast_packet(struct sk_buff *skb, int hdr_size)
 	struct ethhdr *ethhdr;
 
 	/* drop packet if it has not necessary minimum size */
-	if (skb_headlen(skb) < hdr_size)
+	if (unlikely(!pskb_may_pull(skb, hdr_size)))
 		return -1;
 
 	ethhdr = (struct ethhdr *) skb_mac_header(skb);
@@ -1247,7 +1251,7 @@ int recv_bcast_packet(struct sk_buff *skb)
 	unsigned long flags;
 
 	/* drop packet if it has not necessary minimum size */
-	if (skb_headlen(skb) < hdr_size)
+	if (unlikely(!pskb_may_pull(skb, hdr_size)))
 		return NET_RX_DROP;
 
 	ethhdr = (struct ethhdr *)skb_mac_header(skb);
@@ -1320,7 +1324,11 @@ int recv_vis_packet(struct sk_buff *skb)
 	struct bat_priv *bat_priv;
 	int hdr_size = sizeof(struct vis_packet);
 
-	if (skb_headlen(skb) < hdr_size)
+	/* keep skb linear */
+	if (skb_linearize(skb) < 0)
+		return NET_RX_DROP;
+
+	if (unlikely(!pskb_may_pull(skb, hdr_size)))
 		return NET_RX_DROP;
 
 	vis_packet = (struct vis_packet *) skb->data;
@@ -1342,13 +1350,11 @@ int recv_vis_packet(struct sk_buff *skb)
 
 	switch (vis_packet->vis_type) {
 	case VIS_TYPE_SERVER_SYNC:
-		/* TODO: handle fragmented skbs properly */
 		receive_server_sync_packet(bat_priv, vis_packet,
 					   skb_headlen(skb));
 		break;
 
 	case VIS_TYPE_CLIENT_UPDATE:
-		/* TODO: handle fragmented skbs properly */
 		receive_client_update_packet(bat_priv, vis_packet,
 					     skb_headlen(skb));
 		break;
Signature · 1 line
1.7.1
#17 lore raw

PATCH 17/21 Staging: batman-adv: attach each hard-interface to a soft-interface

In reply to Sven Eckelmann

From: Marek Lindner <[email protected]>

This patch replaces the static bat0 interface with a dynamic/abstracted approach. It is now possible to create multiple batX interfaces by assigning hard interfaces to them. Each batX interface acts as an independent mesh network. A soft interface is removed once no hard interface references it any longer.

[[email protected]: Rework on top of current version]
---
 drivers/staging/batman-adv/aggregation.c       |   13 +-
 drivers/staging/batman-adv/bat_sysfs.c         |   67 ++++------
 drivers/staging/batman-adv/bitarray.c          |    7 +-
 drivers/staging/batman-adv/bitarray.h          |    4 +-
 drivers/staging/batman-adv/hard-interface.c    |  131 ++++++++++++-------
 drivers/staging/batman-adv/hard-interface.h    |    6 +-
 drivers/staging/batman-adv/hash.c              |    6 +-
 drivers/staging/batman-adv/hash.h              |    4 +-
 drivers/staging/batman-adv/icmp_socket.c       |    1 +
 drivers/staging/batman-adv/main.c              |   54 +--------
 drivers/staging/batman-adv/main.h              |    2 -
 drivers/staging/batman-adv/originator.c        |   39 +++---
 drivers/staging/batman-adv/originator.h        |    2 +-
 drivers/staging/batman-adv/routing.c           |  163 +++++++++++++-----------
 drivers/staging/batman-adv/routing.h           |   12 +-
 drivers/staging/batman-adv/send.c              |   48 ++++----
 drivers/staging/batman-adv/send.h              |    2 +-
 drivers/staging/batman-adv/soft-interface.c    |  118 ++++++++++++++---
 drivers/staging/batman-adv/soft-interface.h    |    8 +-
 drivers/staging/batman-adv/translation-table.c |   57 +++++----
 drivers/staging/batman-adv/translation-table.h |   13 +-
 drivers/staging/batman-adv/types.h             |    1 +
 drivers/staging/batman-adv/vis.c               |   13 +-
 23 files changed, 419 insertions(+), 352 deletions(-)
drivers/staging/batman-adv/aggregation.c +5 -8
index 5896cf2..6e10fe5 100644
@@ -97,18 +97,15 @@ static bool can_aggregate_with(struct batman_packet *new_batman_packet,
 
 #define atomic_dec_not_zero(v)          atomic_add_unless((v), -1, 0)
 /* create a new aggregated packet and add this packet to it */
-static void new_aggregated_packet(unsigned char *packet_buff,
-			   int packet_len,
-			   unsigned long send_time,
-			   bool direct_link,
-			   struct batman_if *if_incoming,
-			   int own_packet)
+static void new_aggregated_packet(unsigned char *packet_buff, int packet_len,
+				  unsigned long send_time, bool direct_link,
+				  struct batman_if *if_incoming,
+				  int own_packet)
 {
 	struct forw_packet *forw_packet_aggr;
 	unsigned long flags;
 	unsigned char *skb_buff;
-	/* FIXME: each batman_if will be attached to a softif */
-	struct bat_priv *bat_priv = netdev_priv(soft_device);
+	struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
 
 	/* own packet should always be scheduled */
 	if (!own_packet) {
drivers/staging/batman-adv/bat_sysfs.c +29 -38

90 lines not on this page · raw message

drivers/staging/batman-adv/bitarray.c +3 -4
index 9dbaf1e..814274f 100644
@@ -127,11 +127,10 @@ static void bit_reset_window(TYPE_OF_WORD *seq_bits)
  *  1 if the window was moved (either new or very old)
  *  0 if the window was not moved/shifted.
  */
-char bit_get_packet(TYPE_OF_WORD *seq_bits, int32_t seq_num_diff,
-		    int8_t set_mark)
+char bit_get_packet(void *priv, TYPE_OF_WORD *seq_bits,
+		    int32_t seq_num_diff, int8_t set_mark)
 {
-	/* FIXME: each orig_node->batman_if will be attached to a softif */
-	struct bat_priv *bat_priv = netdev_priv(soft_device);
+	struct bat_priv *bat_priv = (struct bat_priv *)priv;
 
 	/* sequence number is slightly older. We already got a sequence number
 	 * higher than this one, so we just mark it. */
drivers/staging/batman-adv/bitarray.h +2 -2
index c0c1730..d961d56 100644
@@ -38,8 +38,8 @@ void bit_mark(TYPE_OF_WORD *seq_bits, int32_t n);
 
 /* receive and process one packet, returns 1 if received seq_num is considered
  * new, 0 if old  */
-char bit_get_packet(TYPE_OF_WORD *seq_bits, int32_t seq_num_diff,
-					int8_t set_mark);
+char bit_get_packet(void *priv, TYPE_OF_WORD *seq_bits,
+		    int32_t seq_num_diff, int8_t set_mark);
 
 /* count the hamming weight, how many good packets did we receive? */
 int  bit_packet_count(TYPE_OF_WORD *seq_bits);
drivers/staging/batman-adv/hard-interface.c +81 -50

308 lines not on this page · raw message

drivers/staging/batman-adv/hard-interface.h +3 -3
index d5640b0..4b49527 100644
@@ -32,14 +32,14 @@
 extern struct notifier_block hard_if_notifier;
 
 struct batman_if *get_batman_if_by_netdev(struct net_device *net_dev);
-int hardif_enable_interface(struct batman_if *batman_if);
+int hardif_enable_interface(struct batman_if *batman_if, char *iface_name);
 void hardif_disable_interface(struct batman_if *batman_if);
 void hardif_remove_interfaces(void);
 int batman_skb_recv(struct sk_buff *skb,
 				struct net_device *dev,
 				struct packet_type *ptype,
 				struct net_device *orig_dev);
-int hardif_min_mtu(void);
-void update_min_mtu(void);
+int hardif_min_mtu(struct net_device *soft_iface);
+void update_min_mtu(struct net_device *soft_iface);
 
 #endif /* _NET_BATMAN_ADV_HARD_INTERFACE_H_ */
drivers/staging/batman-adv/hash.c +3 -3
index 1286f8f..8ef26eb 100644
@@ -36,7 +36,7 @@ static void hash_init(struct hashtable_t *hash)
 /* remove the hash structure. if hashdata_free_cb != NULL, this function will be
  * called to remove the elements inside of the hash.  if you don't remove the
  * elements, memory might be leaked. */
-void hash_delete(struct hashtable_t *hash, hashdata_free_cb free_cb)
+void hash_delete(struct hashtable_t *hash, hashdata_free_cb free_cb, void *arg)
 {
 	struct element_t *bucket, *last_bucket;
 	int i;
@@ -46,7 +46,7 @@ void hash_delete(struct hashtable_t *hash, hashdata_free_cb free_cb)
 
 		while (bucket != NULL) {
 			if (free_cb != NULL)
-				free_cb(bucket->data);
+				free_cb(bucket->data, arg);
 
 			last_bucket = bucket;
 			bucket = bucket->next;
@@ -300,7 +300,7 @@ struct hashtable_t *hash_resize(struct hashtable_t *hash, int size)
 
 	/* remove hash and eventual overflow buckets but not the content
 	 * itself. */
-	hash_delete(hash, NULL);
+	hash_delete(hash, NULL, NULL);
 
 	return new_hash;
 }
drivers/staging/batman-adv/hash.h +2 -2
index c483e11..2c8e176 100644
@@ -30,7 +30,7 @@
 
 typedef int (*hashdata_compare_cb)(void *, void *);
 typedef int (*hashdata_choose_cb)(void *, int);
-typedef void (*hashdata_free_cb)(void *);
+typedef void (*hashdata_free_cb)(void *, void *);
 
 struct element_t {
 	void *data;		/* pointer to the data */
@@ -70,7 +70,7 @@ void *hash_remove_bucket(struct hashtable_t *hash, struct hash_it_t *hash_it_t);
 /* remove the hash structure. if hashdata_free_cb != NULL, this function will be
  * called to remove the elements inside of the hash.  if you don't remove the
  * elements, memory might be leaked. */
-void hash_delete(struct hashtable_t *hash, hashdata_free_cb free_cb);
+void hash_delete(struct hashtable_t *hash, hashdata_free_cb free_cb, void *arg);
 
 /* free only the hashtable and the hash itself. */
 void hash_destroy(struct hashtable_t *hash);
drivers/staging/batman-adv/icmp_socket.c +1 -0
index 8e986a1..2a1d3dd 100644
@@ -156,6 +156,7 @@ static ssize_t bat_socket_write(struct file *file, const char __user *buff,
 	struct bat_priv *bat_priv = socket_client->bat_priv;
 	struct sk_buff *skb;
 	struct icmp_packet_rr *icmp_packet;
+
 	struct orig_node *orig_node;
 	struct batman_if *batman_if;
 	size_t packet_len = sizeof(struct icmp_packet);
drivers/staging/batman-adv/main.c +2 -52

94 lines not on this page · raw message

drivers/staging/batman-adv/main.h +0 -2
index 2d364e0..2309d82 100644
@@ -138,8 +138,6 @@ extern spinlock_t forw_bcast_list_lock;
 
 extern int16_t num_hna;
 
-extern struct net_device *soft_device;
-
 extern unsigned char broadcast_addr[];
 extern atomic_t module_state;
 extern struct workqueue_struct *bat_event_workqueue;
drivers/staging/batman-adv/originator.c +19 -20
index b51a13e..7ed3266 100644
@@ -61,8 +61,7 @@ struct neigh_node *
 create_neighbor(struct orig_node *orig_node, struct orig_node *orig_neigh_node,
 		uint8_t *neigh, struct batman_if *if_incoming)
 {
-	/* FIXME: each orig_node->batman_if will be attached to a softif */
-	struct bat_priv *bat_priv = netdev_priv(soft_device);
+	struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
 	struct neigh_node *neigh_node;
 
 	bat_dbg(DBG_BATMAN, bat_priv,
@@ -82,11 +81,12 @@ create_neighbor(struct orig_node *orig_node, struct orig_node *orig_neigh_node,
 	return neigh_node;
 }
 
-static void free_orig_node(void *data)
+static void free_orig_node(void *data, void *arg)
 {
 	struct list_head *list_pos, *list_pos_tmp;
 	struct neigh_node *neigh_node;
 	struct orig_node *orig_node = (struct orig_node *)data;
+	struct bat_priv *bat_priv = (struct bat_priv *)arg;
 
 	/* for all neighbors towards this originator ... */
 	list_for_each_safe(list_pos, list_pos_tmp, &orig_node->neigh_list) {
@@ -97,7 +97,7 @@ static void free_orig_node(void *data)
 	}
 
 	frag_list_free(&orig_node->frag_list);
-	hna_global_del_orig(orig_node, "originator timed out");
+	hna_global_del_orig(bat_priv, orig_node, "originator timed out");
 
 	kfree(orig_node->bcast_own);
 	kfree(orig_node->bcast_own_sum);
@@ -114,17 +114,15 @@ void originator_free(void)
 	cancel_delayed_work_sync(&purge_orig_wq);
 
 	spin_lock_irqsave(&orig_hash_lock, flags);
-	hash_delete(orig_hash, free_orig_node);
+	/*hash_delete(orig_hash, free_orig_node, bat_priv);*/
 	orig_hash = NULL;
 	spin_unlock_irqrestore(&orig_hash_lock, flags);
 }
 
 /* this function finds or creates an originator entry for the given
  * address if it does not exits */
-struct orig_node *get_orig_node(uint8_t *addr)
+struct orig_node *get_orig_node(struct bat_priv *bat_priv, uint8_t *addr)
 {
-	/* FIXME: each batman_if will be attached to a softif */
-	struct bat_priv *bat_priv = netdev_priv(soft_device);
 	struct orig_node *orig_node;
 	struct hashtable_t *swaphash;
 	int size;
@@ -173,7 +171,7 @@ struct orig_node *get_orig_node(uint8_t *addr)
 		swaphash = hash_resize(orig_hash, orig_hash->size * 2);
 
 		if (swaphash == NULL)
-			bat_err(soft_device,
+			bat_dbg(DBG_BATMAN, bat_priv,
 				"Couldn't resize orig hash table\n");
 		else
 			orig_hash = swaphash;
@@ -189,11 +187,10 @@ free_orig_node:
 	return NULL;
 }
 
-static bool purge_orig_neighbors(struct orig_node *orig_node,
+static bool purge_orig_neighbors(struct bat_priv *bat_priv,
+				 struct orig_node *orig_node,
 				 struct neigh_node **best_neigh_node)
 {
-	/* FIXME: each orig_node->batman_if will be attached to a softif */
-	struct bat_priv *bat_priv = netdev_priv(soft_device);
 	struct list_head *list_pos, *list_pos_tmp;
 	struct neigh_node *neigh_node;
 	bool neigh_purged = false;
@@ -235,10 +232,9 @@ static bool purge_orig_neighbors(struct orig_node *orig_node,
 	return neigh_purged;
 }
 
-static bool purge_orig_node(struct orig_node *orig_node)
+static bool purge_orig_node(struct bat_priv *bat_priv,
+			    struct orig_node *orig_node)
 {
-	/* FIXME: each batman_if will be attached to a softif */
-	struct bat_priv *bat_priv = netdev_priv(soft_device);
 	struct neigh_node *best_neigh_node;
 
 	if (time_after(jiffies,
@@ -249,8 +245,10 @@ static bool purge_orig_node(struct orig_node *orig_node)
 			orig_node->orig, (orig_node->last_valid / HZ));
 		return true;
 	} else {
-		if (purge_orig_neighbors(orig_node, &best_neigh_node)) {
-			update_routes(orig_node, best_neigh_node,
+		if (purge_orig_neighbors(bat_priv, orig_node,
+							&best_neigh_node)) {
+			update_routes(bat_priv, orig_node,
+				      best_neigh_node,
 				      orig_node->hna_buff,
 				      orig_node->hna_buff_len);
 			/* update bonding candidates, we could have lost
@@ -273,13 +271,14 @@ void purge_orig(struct work_struct *work)
 	/* for all origins... */
 	while (hash_iterate(orig_hash, &hashit)) {
 		orig_node = hashit.bucket->data;
-		if (purge_orig_node(orig_node)) {
+
+		/*if (purge_orig_node(bat_priv, orig_node)) {
 			hash_remove_bucket(orig_hash, &hashit);
 			free_orig_node(orig_node);
-		}
+		}*/
 
 		if (time_after(jiffies, (orig_node->last_frag_packet +
-			msecs_to_jiffies(FRAG_TIMEOUT))))
+					msecs_to_jiffies(FRAG_TIMEOUT))))
 			frag_list_free(&orig_node->frag_list);
 	}
 
drivers/staging/batman-adv/originator.h +1 -1
index e88411d..bc47c68 100644
@@ -25,7 +25,7 @@
 int originator_init(void);
 void originator_free(void);
 void purge_orig(struct work_struct *work);
-struct orig_node *get_orig_node(uint8_t *addr);
+struct orig_node *get_orig_node(struct bat_priv *bat_priv, uint8_t *addr);
 struct neigh_node *
 create_neighbor(struct orig_node *orig_node, struct orig_node *orig_neigh_node,
 		uint8_t *neigh, struct batman_if *if_incoming);
drivers/staging/batman-adv/routing.c +89 -74

442 lines not on this page · raw message

drivers/staging/batman-adv/routing.h +6 -6
index 81c684f..55995e4 100644
@@ -29,14 +29,14 @@ void receive_bat_packet(struct ethhdr *ethhdr,
 				struct batman_packet *batman_packet,
 				unsigned char *hna_buff, int hna_buff_len,
 				struct batman_if *if_incoming);
-void update_routes(struct orig_node *orig_node,
-				struct neigh_node *neigh_node,
-				unsigned char *hna_buff, int hna_buff_len);
-int recv_icmp_packet(struct sk_buff *skb);
+void update_routes(struct bat_priv *bat_priv, struct orig_node *orig_node,
+		   struct neigh_node *neigh_node, unsigned char *hna_buff,
+		   int hna_buff_len);
+int recv_icmp_packet(struct sk_buff *skb, struct batman_if *recv_if);
 int recv_unicast_packet(struct sk_buff *skb, struct batman_if *recv_if);
 int recv_ucast_frag_packet(struct sk_buff *skb, struct batman_if *recv_if);
-int recv_bcast_packet(struct sk_buff *skb);
-int recv_vis_packet(struct sk_buff *skb);
+int recv_bcast_packet(struct sk_buff *skb, struct batman_if *recv_if);
+int recv_vis_packet(struct sk_buff *skb, struct batman_if *recv_if);
 int recv_bat_packet(struct sk_buff *skb,
 				struct batman_if *batman_if);
 struct neigh_node *find_router(struct orig_node *orig_node,
drivers/staging/batman-adv/send.c +24 -24

122 lines not on this page · raw message

drivers/staging/batman-adv/send.h +1 -1
index 0cfe027..39a3426 100644
@@ -33,7 +33,7 @@ void schedule_forward_packet(struct orig_node *orig_node,
 			     struct batman_packet *batman_packet,
 			     uint8_t directlink, int hna_buff_len,
 			     struct batman_if *if_outgoing);
-int  add_bcast_packet_to_list(struct sk_buff *skb);
+int add_bcast_packet_to_list(struct bat_priv *bat_priv, struct sk_buff *skb);
 void send_outstanding_bat_packet(struct work_struct *work);
 void purge_outstanding_packets(struct batman_if *batman_if);
 
drivers/staging/batman-adv/soft-interface.c +98 -20

206 lines not on this page · raw message

drivers/staging/batman-adv/soft-interface.h +5 -3
index 9dbf5fc..04f04b4 100644
@@ -23,10 +23,12 @@
 #define _NET_BATMAN_ADV_SOFT_INTERFACE_H_
 
 void set_main_if_addr(uint8_t *addr);
-void interface_setup(struct net_device *dev);
-int interface_tx(struct sk_buff *skb, struct net_device *dev);
-void interface_rx(struct sk_buff *skb, int hdr_size);
 int my_skb_head_push(struct sk_buff *skb, unsigned int len);
+int interface_tx(struct sk_buff *skb, struct net_device *soft_iface);
+void interface_rx(struct net_device *soft_iface,
+		  struct sk_buff *skb, int hdr_size);
+struct net_device *softif_create(char *name);
+void softif_destroy(struct net_device *soft_iface);
 
 extern unsigned char main_if_addr[];
 
drivers/staging/batman-adv/translation-table.c +30 -27

167 lines not on this page · raw message

drivers/staging/batman-adv/translation-table.h +8 -5
index fa93e37..af7a59c 100644
@@ -25,16 +25,19 @@
 #include "types.h"
 
 int hna_local_init(void);
-void hna_local_add(uint8_t *addr);
-void hna_local_remove(uint8_t *addr, char *message);
+void hna_local_add(struct net_device *soft_iface, uint8_t *addr);
+void hna_local_remove(struct bat_priv *bat_priv,
+		      uint8_t *addr, char *message);
 int hna_local_fill_buffer(unsigned char *buff, int buff_len);
 int hna_local_seq_print_text(struct seq_file *seq, void *offset);
 void hna_local_free(void);
 int hna_global_init(void);
-void hna_global_add_orig(struct orig_node *orig_node, unsigned char *hna_buff,
-			 int hna_buff_len);
+void hna_global_add_orig(struct bat_priv *bat_priv,
+			 struct orig_node *orig_node,
+			 unsigned char *hna_buff, int hna_buff_len);
 int hna_global_seq_print_text(struct seq_file *seq, void *offset);
-void hna_global_del_orig(struct orig_node *orig_node, char *message);
+void hna_global_del_orig(struct bat_priv *bat_priv,
+			 struct orig_node *orig_node, char *message);
 void hna_global_free(void);
 struct orig_node *transtable_search(uint8_t *addr);
 
drivers/staging/batman-adv/types.h +1 -0
index 4b2e832..c5b738d 100644
@@ -47,6 +47,7 @@ struct batman_if {
 	struct kobject *hardif_obj;
 	struct rcu_head rcu;
 	struct packet_type batman_adv_ptype;
+	struct net_device *soft_iface;
 };
 
 /**
drivers/staging/batman-adv/vis.c +6 -7
index e89a710..ad899fe 100644
@@ -745,17 +745,16 @@ static void send_vis_packets(struct work_struct *work)
 {
 	struct vis_info *info, *temp;
 	unsigned long flags;
-	/* FIXME: each batman_if will be attached to a softif */
-	struct bat_priv *bat_priv = netdev_priv(soft_device);
+	/* struct bat_priv *bat_priv = netdev_priv(soft_device); */
 
 	spin_lock_irqsave(&vis_hash_lock, flags);
 
 	purge_vis_packets();
 
-	if (generate_vis_packet(bat_priv) == 0) {
+	/* if (generate_vis_packet(bat_priv) == 0) {*/
 		/* schedule if generation was successful */
-		send_list_add(my_vis_info);
-	}
+		/*send_list_add(my_vis_info);
+	} */
 
 	list_for_each_entry_safe(info, temp, &send_list, send_list) {
 
@@ -842,7 +841,7 @@ err:
 }
 
 /* Decrease the reference count on a hash item info */
-static void free_info_ref(void *data)
+static void free_info_ref(void *data, void *arg)
 {
 	struct vis_info *info = data;
 
@@ -861,7 +860,7 @@ void vis_quit(void)
 
 	spin_lock_irqsave(&vis_hash_lock, flags);
 	/* properly remove, kill timers ... */
-	hash_delete(vis_hash, free_info_ref);
+	hash_delete(vis_hash, free_info_ref, NULL);
 	vis_hash = NULL;
 	my_vis_info = NULL;
 	spin_unlock_irqrestore(&vis_hash_lock, flags);
Signature · 1 line
1.7.1
#18 lore raw

PATCH 18/21 Staging: batman-adv: multiple mesh clouds

In reply to Sven Eckelmann

From: Marek Lindner <[email protected]>

This patch removes all remaining global variables and includes the necessary bits into the bat_priv structure. It is the last remaining piece to allow multiple concurrent mesh clouds on the same device.
A few global variables have been rendered obsolete during the process and have been removed entirely.

[[email protected]: Rework on top of current version]
---
 drivers/staging/batman-adv/aggregation.c       |   22 +-
 drivers/staging/batman-adv/bat_sysfs.c         |    2 +-
 drivers/staging/batman-adv/hard-interface.c    |   48 ++--
 drivers/staging/batman-adv/icmp_socket.c       |   11 +-
 drivers/staging/batman-adv/main.c              |   74 +++---
 drivers/staging/batman-adv/main.h              |   22 +--
 drivers/staging/batman-adv/originator.c        |  119 +++++----
 drivers/staging/batman-adv/originator.h        |    6 +-
 drivers/staging/batman-adv/routing.c           |  115 +++++----
 drivers/staging/batman-adv/routing.h           |    3 +-
 drivers/staging/batman-adv/send.c              |  110 +++++----
 drivers/staging/batman-adv/send.h              |    3 +-
 drivers/staging/batman-adv/soft-interface.c    |   48 ++--
 drivers/staging/batman-adv/soft-interface.h    |    3 -
 drivers/staging/batman-adv/translation-table.c |  219 ++++++++--------
 drivers/staging/batman-adv/translation-table.h |   17 +-
 drivers/staging/batman-adv/types.h             |   81 +++++--
 drivers/staging/batman-adv/unicast.c           |   17 +-
 drivers/staging/batman-adv/vis.c               |  333 +++++++++++++-----------
 drivers/staging/batman-adv/vis.h               |   27 +--
 20 files changed, 680 insertions(+), 600 deletions(-)
drivers/staging/batman-adv/aggregation.c +11 -11
index 6e10fe5..46b9c2b 100644
@@ -102,10 +102,10 @@ static void new_aggregated_packet(unsigned char *packet_buff, int packet_len,
 				  struct batman_if *if_incoming,
 				  int own_packet)
 {
-	struct forw_packet *forw_packet_aggr;
-	unsigned long flags;
-	unsigned char *skb_buff;
 	struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
+	struct forw_packet *forw_packet_aggr;
+	unsigned long flags;
+	unsigned char *skb_buff;
 
 	/* own packet should always be scheduled */
 	if (!own_packet) {
@@ -150,9 +150,9 @@ static void new_aggregated_packet(unsigned char *packet_buff, int packet_len,
 		forw_packet_aggr->direct_link_flags |= 1;
 
 	/* add new packet to packet list */
-	spin_lock_irqsave(&forw_bat_list_lock, flags);
-	hlist_add_head(&forw_packet_aggr->list, &forw_bat_list);
-	spin_unlock_irqrestore(&forw_bat_list_lock, flags);
+	spin_lock_irqsave(&bat_priv->forw_bat_list_lock, flags);
+	hlist_add_head(&forw_packet_aggr->list, &bat_priv->forw_bat_list);
+	spin_unlock_irqrestore(&bat_priv->forw_bat_list_lock, flags);
 
 	/* start timer for this packet */
 	INIT_DELAYED_WORK(&forw_packet_aggr->delayed_work,
@@ -198,11 +198,11 @@ void add_bat_packet_to_list(struct bat_priv *bat_priv,
 	unsigned long flags;
 
 	/* find position for the packet in the forward queue */
-	spin_lock_irqsave(&forw_bat_list_lock, flags);
+	spin_lock_irqsave(&bat_priv->forw_bat_list_lock, flags);
 	/* own packets are not to be aggregated */
 	if ((atomic_read(&bat_priv->aggregation_enabled)) && (!own_packet)) {
-		hlist_for_each_entry(forw_packet_pos, tmp_node, &forw_bat_list,
-				     list) {
+		hlist_for_each_entry(forw_packet_pos, tmp_node,
+				     &bat_priv->forw_bat_list, list) {
 			if (can_aggregate_with(batman_packet,
 					       packet_len,
 					       send_time,
@@ -219,7 +219,7 @@ void add_bat_packet_to_list(struct bat_priv *bat_priv,
 	 * suitable aggregation packet found */
 	if (forw_packet_aggr == NULL) {
 		/* the following section can run without the lock */
-		spin_unlock_irqrestore(&forw_bat_list_lock, flags);
+		spin_unlock_irqrestore(&bat_priv->forw_bat_list_lock, flags);
 
 		/**
 		 * if we could not aggregate this packet with one of the others
@@ -237,7 +237,7 @@ void add_bat_packet_to_list(struct bat_priv *bat_priv,
 		aggregate(forw_packet_aggr,
 			  packet_buff, packet_len,
 			  direct_link);
-		spin_unlock_irqrestore(&forw_bat_list_lock, flags);
+		spin_unlock_irqrestore(&bat_priv->forw_bat_list_lock, flags);
 	}
 }
 
drivers/staging/batman-adv/bat_sysfs.c +1 -1
index 052f9e8..0610169 100644
@@ -411,7 +411,7 @@ static ssize_t show_mesh_iface(struct kobject *kobj, struct attribute *attr,
 
 	return sprintf(buff, "%s\n",
 		       batman_if->if_status == IF_NOT_IN_USE ?
-							"none" : "bat0");
+					"none" : batman_if->soft_iface->name);
 }
 
 static ssize_t store_mesh_iface(struct kobject *kobj, struct attribute *attr,
drivers/staging/batman-adv/hard-interface.c +27 -21

124 lines not on this page · raw message

drivers/staging/batman-adv/icmp_socket.c +6 -5
index 2a1d3dd..24627be 100644
@@ -218,11 +218,12 @@ static ssize_t bat_socket_write(struct file *file, const char __user *buff,
 		goto free_skb;
 	}
 
-	if (atomic_read(&module_state) != MODULE_ACTIVE)
+	if (atomic_read(&bat_priv->mesh_state) != MESH_ACTIVE)
 		goto dst_unreach;
 
-	spin_lock_irqsave(&orig_hash_lock, flags);
-	orig_node = (struct orig_node *)hash_find(orig_hash, icmp_packet->dst);
+	spin_lock_irqsave(&bat_priv->orig_hash_lock, flags);
+	orig_node = ((struct orig_node *)hash_find(bat_priv->orig_hash,
+						   icmp_packet->dst));
 
 	if (!orig_node)
 		goto unlock;
@@ -233,7 +234,7 @@ static ssize_t bat_socket_write(struct file *file, const char __user *buff,
 	batman_if = orig_node->router->if_incoming;
 	memcpy(dstaddr, orig_node->router->addr, ETH_ALEN);
 
-	spin_unlock_irqrestore(&orig_hash_lock, flags);
+	spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
 
 	if (!batman_if)
 		goto dst_unreach;
@@ -253,7 +254,7 @@ static ssize_t bat_socket_write(struct file *file, const char __user *buff,
 	goto out;
 
 unlock:
-	spin_unlock_irqrestore(&orig_hash_lock, flags);
+	spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
 dst_unreach:
 	icmp_packet->msg_type = DESTINATION_UNREACHABLE;
 	bat_socket_add_packet(socket_client, icmp_packet, packet_len);
drivers/staging/batman-adv/main.c +37 -37

129 lines not on this page · raw message

drivers/staging/batman-adv/main.h +6 -16
index 2309d82..ca97589 100644
@@ -76,9 +76,9 @@
 #define EXPECTED_SEQNO_RANGE	65536
 /* don't reset again within 30 seconds */
 
-#define MODULE_INACTIVE 0
-#define MODULE_ACTIVE 1
-#define MODULE_DEACTIVATING 2
+#define MESH_INACTIVE 0
+#define MESH_ACTIVE 1
+#define MESH_DEACTIVATING 2
 
 #define BCAST_QUEUE_LEN		256
 #define BATMAN_QUEUE_LEN	256
@@ -128,22 +128,12 @@
 #endif
 
 extern struct list_head if_list;
-extern struct hlist_head forw_bat_list;
-extern struct hlist_head forw_bcast_list;
-extern struct hashtable_t *orig_hash;
-
-extern spinlock_t orig_hash_lock;
-extern spinlock_t forw_bat_list_lock;
-extern spinlock_t forw_bcast_list_lock;
-
-extern int16_t num_hna;
 
 extern unsigned char broadcast_addr[];
-extern atomic_t module_state;
 extern struct workqueue_struct *bat_event_workqueue;
 
-void activate_module(void);
-void deactivate_module(void);
+int mesh_init(struct net_device *soft_iface);
+void mesh_free(struct net_device *soft_iface);
 void inc_module_count(void);
 void dec_module_count(void);
 int addr_to_string(char *buff, uint8_t *addr);
@@ -154,7 +144,7 @@ int is_bcast(uint8_t *addr);
 int is_mcast(uint8_t *addr);
 
 #ifdef CONFIG_BATMAN_ADV_DEBUG
-extern int debug_log(struct bat_priv *bat_priv, char *fmt, ...);
+int debug_log(struct bat_priv *bat_priv, char *fmt, ...);
 
 #define bat_dbg(type, bat_priv, fmt, arg...)			\
 	do {							\
drivers/staging/batman-adv/originator.c +69 -50

260 lines not on this page · raw message

drivers/staging/batman-adv/originator.h +3 -3
index bc47c68..a97c400 100644
@@ -22,9 +22,9 @@
 #ifndef _NET_BATMAN_ADV_ORIGINATOR_H_
 #define _NET_BATMAN_ADV_ORIGINATOR_H_
 
-int originator_init(void);
-void originator_free(void);
-void purge_orig(struct work_struct *work);
+int originator_init(struct bat_priv *bat_priv);
+void originator_free(struct bat_priv *bat_priv);
+void purge_orig_ref(struct bat_priv *bat_priv);
 struct orig_node *get_orig_node(struct bat_priv *bat_priv, uint8_t *addr);
 struct neigh_node *
 create_neighbor(struct orig_node *orig_node, struct orig_node *orig_neigh_node,
drivers/staging/batman-adv/routing.c +59 -56

354 lines not on this page · raw message

drivers/staging/batman-adv/routing.h +1 -2
index 55995e4..06ea99d 100644
@@ -37,8 +37,7 @@ int recv_unicast_packet(struct sk_buff *skb, struct batman_if *recv_if);
 int recv_ucast_frag_packet(struct sk_buff *skb, struct batman_if *recv_if);
 int recv_bcast_packet(struct sk_buff *skb, struct batman_if *recv_if);
 int recv_vis_packet(struct sk_buff *skb, struct batman_if *recv_if);
-int recv_bat_packet(struct sk_buff *skb,
-				struct batman_if *batman_if);
+int recv_bat_packet(struct sk_buff *skb, struct batman_if *recv_if);
 struct neigh_node *find_router(struct orig_node *orig_node,
 		struct batman_if *recv_if);
 void update_bonding_candidates(struct bat_priv *bat_priv,
drivers/staging/batman-adv/send.c +59 -51

250 lines not on this page · raw message

drivers/staging/batman-adv/send.h +2 -1
index 39a3426..c4cefa8 100644
@@ -35,6 +35,7 @@ void schedule_forward_packet(struct orig_node *orig_node,
 			     struct batman_if *if_outgoing);
 int add_bcast_packet_to_list(struct bat_priv *bat_priv, struct sk_buff *skb);
 void send_outstanding_bat_packet(struct work_struct *work);
-void purge_outstanding_packets(struct batman_if *batman_if);
+void purge_outstanding_packets(struct bat_priv *bat_priv,
+			       struct batman_if *batman_if);
 
 #endif /* _NET_BATMAN_ADV_SEND_H_ */
drivers/staging/batman-adv/soft-interface.c +24 -24

138 lines not on this page · raw message

drivers/staging/batman-adv/soft-interface.h +0 -3
index 04f04b4..843a7ec 100644
@@ -22,7 +22,6 @@
 #ifndef _NET_BATMAN_ADV_SOFT_INTERFACE_H_
 #define _NET_BATMAN_ADV_SOFT_INTERFACE_H_
 
-void set_main_if_addr(uint8_t *addr);
 int my_skb_head_push(struct sk_buff *skb, unsigned int len);
 int interface_tx(struct sk_buff *skb, struct net_device *soft_iface);
 void interface_rx(struct net_device *soft_iface,
@@ -30,6 +29,4 @@ void interface_rx(struct net_device *soft_iface,
 struct net_device *softif_create(char *name);
 void softif_destroy(struct net_device *soft_iface);
 
-extern unsigned char main_if_addr[];
-
 #endif /* _NET_BATMAN_ADV_SOFT_INTERFACE_H_ */
drivers/staging/batman-adv/translation-table.c +112 -107

470 lines not on this page · raw message

drivers/staging/batman-adv/translation-table.h +7 -10
index af7a59c..10c4c5c 100644
@@ -24,25 +24,22 @@
 
 #include "types.h"
 
-int hna_local_init(void);
+int hna_local_init(struct bat_priv *bat_priv);
 void hna_local_add(struct net_device *soft_iface, uint8_t *addr);
 void hna_local_remove(struct bat_priv *bat_priv,
 		      uint8_t *addr, char *message);
-int hna_local_fill_buffer(unsigned char *buff, int buff_len);
+int hna_local_fill_buffer(struct bat_priv *bat_priv,
+			  unsigned char *buff, int buff_len);
 int hna_local_seq_print_text(struct seq_file *seq, void *offset);
-void hna_local_free(void);
-int hna_global_init(void);
+void hna_local_free(struct bat_priv *bat_priv);
+int hna_global_init(struct bat_priv *bat_priv);
 void hna_global_add_orig(struct bat_priv *bat_priv,
 			 struct orig_node *orig_node,
 			 unsigned char *hna_buff, int hna_buff_len);
 int hna_global_seq_print_text(struct seq_file *seq, void *offset);
 void hna_global_del_orig(struct bat_priv *bat_priv,
 			 struct orig_node *orig_node, char *message);
-void hna_global_free(void);
-struct orig_node *transtable_search(uint8_t *addr);
-
-extern spinlock_t hna_local_hash_lock;
-extern struct hashtable_t *hna_local_hash;
-extern atomic_t hna_local_changed;
+void hna_global_free(struct bat_priv *bat_priv);
+struct orig_node *transtable_search(struct bat_priv *bat_priv, uint8_t *addr);
 
 #endif /* _NET_BATMAN_ADV_TRANSLATION_TABLE_H_ */
drivers/staging/batman-adv/types.h +65 -16

121 lines not on this page · raw message

drivers/staging/batman-adv/unicast.c +9 -8
index 61ebd38..f951abc 100644
@@ -34,7 +34,7 @@ struct sk_buff *merge_frag_packet(struct list_head *head,
 				  struct sk_buff *skb)
 {
 	struct unicast_frag_packet *up =
-		(struct unicast_frag_packet *) skb->data;
+		(struct unicast_frag_packet *)skb->data;
 	struct sk_buff *tmp_skb;
 
 	/* set skb to the first part and tmp_skb to the second part */
@@ -66,7 +66,7 @@ void create_frag_entry(struct list_head *head, struct sk_buff *skb)
 {
 	struct frag_packet_list_entry *tfp;
 	struct unicast_frag_packet *up =
-		(struct unicast_frag_packet *) skb->data;
+		(struct unicast_frag_packet *)skb->data;
 
 	/* free and oldest packets stand at the end */
 	tfp = list_entry((head)->prev, typeof(*tfp), list);
@@ -115,7 +115,7 @@ struct frag_packet_list_entry *search_frag_packet(struct list_head *head,
 		if (tfp->seqno == ntohs(up->seqno))
 			goto mov_tail;
 
-		tmp_up = (struct unicast_frag_packet *) tfp->skb->data;
+		tmp_up = (struct unicast_frag_packet *)tfp->skb->data;
 
 		if (tfp->seqno == search_seqno) {
 
@@ -210,14 +210,15 @@ int unicast_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv)
 	uint8_t dstaddr[6];
 	unsigned long flags;
 
-	spin_lock_irqsave(&orig_hash_lock, flags);
+	spin_lock_irqsave(&bat_priv->orig_hash_lock, flags);
 
 	/* get routing information */
-	orig_node = ((struct orig_node *)hash_find(orig_hash, ethhdr->h_dest));
+	orig_node = ((struct orig_node *)hash_find(bat_priv->orig_hash,
+						   ethhdr->h_dest));
 
 	/* check for hna host */
 	if (!orig_node)
-		orig_node = transtable_search(ethhdr->h_dest);
+		orig_node = transtable_search(bat_priv, ethhdr->h_dest);
 
 	router = find_router(orig_node, NULL);
 
@@ -230,7 +231,7 @@ int unicast_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv)
 	batman_if = router->if_incoming;
 	memcpy(dstaddr, router->addr, ETH_ALEN);
 
-	spin_unlock_irqrestore(&orig_hash_lock, flags);
+	spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
 
 	if (batman_if->if_status != IF_ACTIVE)
 		goto dropped;
@@ -257,7 +258,7 @@ int unicast_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv)
 	return 0;
 
 unlock:
-	spin_unlock_irqrestore(&orig_hash_lock, flags);
+	spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
 dropped:
 	kfree_skb(skb);
 	return 1;
drivers/staging/batman-adv/vis.c +180 -153

700 lines not on this page · raw message

drivers/staging/batman-adv/vis.h +2 -25
index 19dc325..2c3b330 100644
@@ -24,29 +24,6 @@
 
 #define VIS_TIMEOUT		200	/* timeout of vis packets in seconds */
 
-struct vis_info {
-	unsigned long       first_seen;
-	struct list_head    recv_list;
-			    /* list of server-neighbors we received a vis-packet
-			     * from.  we should not reply to them. */
-	struct list_head send_list;
-	struct kref refcount;
-	/* this packet might be part of the vis send queue. */
-	struct sk_buff *skb_packet;
-	/* vis_info may follow here*/
-} __attribute__((packed));
-
-struct vis_info_entry {
-	uint8_t  src[ETH_ALEN];
-	uint8_t  dest[ETH_ALEN];
-	uint8_t  quality;	/* quality = 0 means HNA */
-} __attribute__((packed));
-
-struct recvlist_node {
-	struct list_head list;
-	uint8_t mac[ETH_ALEN];
-};
-
 int vis_seq_print_text(struct seq_file *seq, void *offset);
 void receive_server_sync_packet(struct bat_priv *bat_priv,
 				struct vis_packet *vis_packet,
@@ -54,7 +31,7 @@ void receive_server_sync_packet(struct bat_priv *bat_priv,
 void receive_client_update_packet(struct bat_priv *bat_priv,
 				  struct vis_packet *vis_packet,
 				  int vis_info_len);
-int vis_init(void);
-void vis_quit(void);
+int vis_init(struct bat_priv *bat_priv);
+void vis_quit(struct bat_priv *bat_priv);
 
 #endif /* _NET_BATMAN_ADV_VIS_H_ */
Signature · 1 line
1.7.1
#19 lore raw

PATCH 19/21 Staging: batman-adv: Remove duplicate of attached device name

In reply to Sven Eckelmann

batman_if has the name of the net_dev as extra string in its own structure, but also holds a reference to the actual net_device structure which always has the current name of the device. This makes it unneccessary and also more complex because we must update the name in situations when we receive a NETDEV_CHANGENAME event.

---
 drivers/staging/batman-adv/hard-interface.c |   29 +++++++++-----------------
 drivers/staging/batman-adv/originator.c     |    8 +++---
 drivers/staging/batman-adv/routing.c        |    9 ++++---
 drivers/staging/batman-adv/send.c           |    9 ++++---
 drivers/staging/batman-adv/types.h          |    1 -
 5 files changed, 24 insertions(+), 32 deletions(-)
drivers/staging/batman-adv/hard-interface.c +10 -19
index 6b8ec28..a58a89a 100644
@@ -158,7 +158,7 @@ static void check_known_mac_addr(uint8_t *addr)
 			continue;
 
 		pr_warning("The newly added mac address (%pM) already exists "
-			   "on: %s\n", addr, batman_if->dev);
+			   "on: %s\n", addr, batman_if->net_dev->name);
 		pr_warning("It is strongly recommended to keep mac addresses "
 			   "unique to avoid problems!\n");
 	}
@@ -223,7 +223,7 @@ static void hardif_activate_interface(struct batman_if *batman_if)
 		set_primary_if(bat_priv, batman_if);
 
 	bat_info(batman_if->soft_iface, "Interface activated: %s\n",
-		 batman_if->dev);
+		 batman_if->net_dev->name);
 
 	update_min_mtu(batman_if->soft_iface);
 	return;
@@ -238,7 +238,7 @@ static void hardif_deactivate_interface(struct batman_if *batman_if)
 	batman_if->if_status = IF_INACTIVE;
 
 	bat_info(batman_if->soft_iface, "Interface deactivated: %s\n",
-		 batman_if->dev);
+		 batman_if->net_dev->name);
 
 	update_min_mtu(batman_if->soft_iface);
 }
@@ -269,7 +269,7 @@ int hardif_enable_interface(struct batman_if *batman_if, char *iface_name)
 
 	if (!batman_if->packet_buff) {
 		bat_err(batman_if->soft_iface, "Can't add interface packet "
-			"(%s): out of memory\n", batman_if->dev);
+			"(%s): out of memory\n", batman_if->net_dev->name);
 		goto err;
 	}
 
@@ -294,7 +294,7 @@ int hardif_enable_interface(struct batman_if *batman_if, char *iface_name)
 	atomic_set(&batman_if->seqno, 1);
 	atomic_set(&batman_if->frag_seqno, 1);
 	bat_info(batman_if->soft_iface, "Adding interface: %s\n",
-		 batman_if->dev);
+		 batman_if->net_dev->name);
 
 	if (atomic_read(&bat_priv->frag_enabled) && batman_if->net_dev->mtu <
 		ETH_DATA_LEN + BAT_HEADER_LEN)
@@ -304,7 +304,7 @@ int hardif_enable_interface(struct batman_if *batman_if, char *iface_name)
 			"over this interface will be fragmented on layer2 "
 			"which could impact the performance. Setting the MTU "
 			"to %zi would solve the problem.\n",
-			batman_if->dev, batman_if->net_dev->mtu,
+			batman_if->net_dev->name, batman_if->net_dev->mtu,
 			ETH_DATA_LEN + BAT_HEADER_LEN);
 
 	if (!atomic_read(&bat_priv->frag_enabled) && batman_if->net_dev->mtu <
@@ -314,7 +314,7 @@ int hardif_enable_interface(struct batman_if *batman_if, char *iface_name)
 			"the transport of batman-adv packets. If you experience"
 			" problems getting traffic through try increasing the "
 			"MTU to %zi.\n",
-			batman_if->dev, batman_if->net_dev->mtu,
+			batman_if->net_dev->name, batman_if->net_dev->mtu,
 			ETH_DATA_LEN + BAT_HEADER_LEN);
 
 	if (hardif_is_iface_up(batman_if))
@@ -322,7 +322,7 @@ int hardif_enable_interface(struct batman_if *batman_if, char *iface_name)
 	else
 		bat_err(batman_if->soft_iface, "Not using interface %s "
 			"(retrying later): interface not active\n",
-			batman_if->dev);
+			batman_if->net_dev->name);
 
 	/* begin scheduling originator messages on that interface */
 	schedule_own_packet(batman_if);
@@ -345,7 +345,7 @@ void hardif_disable_interface(struct batman_if *batman_if)
 		return;
 
 	bat_info(batman_if->soft_iface, "Removing interface: %s\n",
-		 batman_if->dev);
+		 batman_if->net_dev->name);
 	dev_remove_pack(&batman_if->batman_adv_ptype);
 
 	bat_priv->num_ifaces--;
@@ -389,13 +389,9 @@ static struct batman_if *hardif_add_interface(struct net_device *net_dev)
 		goto release_dev;
 	}
 
-	batman_if->dev = kstrdup(net_dev->name, GFP_ATOMIC);
-	if (!batman_if->dev)
-		goto free_if;
-
 	ret = sysfs_add_hardif(&batman_if->hardif_obj, net_dev);
 	if (ret)
-		goto free_dev;
+		goto free_if;
 
 	batman_if->if_num = -1;
 	batman_if->net_dev = net_dev;
@@ -407,8 +403,6 @@ static struct batman_if *hardif_add_interface(struct net_device *net_dev)
 	list_add_tail_rcu(&batman_if->list, &if_list);
 	return batman_if;
 
-free_dev:
-	kfree(batman_if->dev);
 free_if:
 	kfree(batman_if);
 release_dev:
@@ -421,7 +415,6 @@ static void hardif_free_interface(struct rcu_head *rcu)
 {
 	struct batman_if *batman_if = container_of(rcu, struct batman_if, rcu);
 
-	kfree(batman_if->dev);
 	kfree(batman_if);
 }
 
@@ -476,8 +469,6 @@ static int hard_if_event(struct notifier_block *this,
 	case NETDEV_UNREGISTER:
 		hardif_remove_interface(batman_if);
 		break;
-	case NETDEV_CHANGENAME:
-		break;
 	case NETDEV_CHANGEADDR:
 		if (batman_if->if_status == IF_NOT_IN_USE)
 			goto out;
drivers/staging/batman-adv/originator.c +4 -4
index d20721b..f25d7fd 100644
@@ -214,7 +214,7 @@ static bool purge_orig_neighbors(struct bat_priv *bat_priv,
 					"neighbor purge: originator %pM, "
 					"neighbor: %pM, iface: %s\n",
 					orig_node->orig, neigh_node->addr,
-					neigh_node->if_incoming->dev);
+					neigh_node->if_incoming->net_dev->name);
 			else
 				bat_dbg(DBG_BATMAN, bat_priv,
 					"neighbor timeout: originator %pM, "
@@ -332,8 +332,8 @@ int orig_seq_print_text(struct seq_file *seq, void *offset)
 	rcu_read_lock();
 	seq_printf(seq, "[B.A.T.M.A.N. adv %s%s, MainIF/MAC: %s/%s (%s)]\n",
 		   SOURCE_VERSION, REVISION_VERSION_STR,
-		   bat_priv->primary_if->dev, bat_priv->primary_if->addr_str,
-		   net_dev->name);
+		   bat_priv->primary_if->net_dev->name,
+		   bat_priv->primary_if->addr_str, net_dev->name);
 	seq_printf(seq, "  %-15s %s (%s/%i) %17s [%10s]: %20s ...\n",
 		   "Originator", "last-seen", "#", TQ_MAX_VALUE, "Nexthop",
 		   "outgoingIF", "Potential nexthops");
@@ -361,7 +361,7 @@ int orig_seq_print_text(struct seq_file *seq, void *offset)
 		seq_printf(seq, "%-17s %4i.%03is   (%3i) %17s [%10s]:",
 			   orig_str, last_seen_secs, last_seen_msecs,
 			   orig_node->router->tq_avg, router_str,
-			   orig_node->router->if_incoming->dev);
+			   orig_node->router->if_incoming->net_dev->name);
 
 		list_for_each_entry(neigh_node, &orig_node->neigh_list, list) {
 			addr_to_string(orig_str, neigh_node->addr);
drivers/staging/batman-adv/routing.c +5 -4
index 34cc321..eda08b5 100644
@@ -557,10 +557,11 @@ void receive_bat_packet(struct ethhdr *ethhdr,
 		"Received BATMAN packet via NB: %pM, IF: %s [%s] "
 		"(from OG: %pM, via prev OG: %pM, seqno %d, tq %d, "
 		"TTL %d, V %d, IDF %d)\n",
-		ethhdr->h_source, if_incoming->dev, if_incoming->addr_str,
-		batman_packet->orig, batman_packet->prev_sender,
-		batman_packet->seqno, batman_packet->tq, batman_packet->ttl,
-		batman_packet->version, has_directlink_flag);
+		ethhdr->h_source, if_incoming->net_dev->name,
+		if_incoming->addr_str, batman_packet->orig,
+		batman_packet->prev_sender, batman_packet->seqno,
+		batman_packet->tq, batman_packet->ttl, batman_packet->version,
+		has_directlink_flag);
 
 	list_for_each_entry_rcu(batman_if, &if_list, list) {
 		if (batman_if->if_status != IF_ACTIVE)
drivers/staging/batman-adv/send.c +5 -4
index e9980ef..5d57ef5 100644
@@ -68,7 +68,7 @@ int send_skb_packet(struct sk_buff *skb,
 
 	if (!(batman_if->net_dev->flags & IFF_UP)) {
 		pr_warning("Interface %s is not up - can't send packet via "
-			   "that interface!\n", batman_if->dev);
+			   "that interface!\n", batman_if->net_dev->name);
 		goto send_skb_err;
 	}
 
@@ -141,7 +141,7 @@ static void send_packet_to_if(struct forw_packet *forw_packet,
 			batman_packet->tq, batman_packet->ttl,
 			(batman_packet->flags & DIRECTLINK ?
 			 "on" : "off"),
-			batman_if->dev, batman_if->addr_str);
+			batman_if->net_dev->name, batman_if->addr_str);
 
 		buff_pos += sizeof(struct batman_packet) +
 			(batman_packet->num_hna * ETH_ALEN);
@@ -186,7 +186,8 @@ static void send_packet(struct forw_packet *forw_packet)
 			"on interface %s [%s]\n",
 			(forw_packet->own ? "Sending own" : "Forwarding"),
 			batman_packet->orig, ntohl(batman_packet->seqno),
-			batman_packet->ttl, forw_packet->if_incoming->dev,
+			batman_packet->ttl,
+			forw_packet->if_incoming->net_dev->name,
 			forw_packet->if_incoming->addr_str);
 
 		/* skb is only used once and than forw_packet is free'd */
@@ -521,7 +522,7 @@ void purge_outstanding_packets(struct bat_priv *bat_priv,
 	if (batman_if)
 		bat_dbg(DBG_BATMAN, bat_priv,
 			"purge_outstanding_packets(): %s\n",
-			batman_if->dev);
+			batman_if->net_dev->name);
 	else
 		bat_dbg(DBG_BATMAN, bat_priv,
 			"purge_outstanding_packets()\n");
drivers/staging/batman-adv/types.h +0 -1
index b4f2b0c..e779c4a 100644
@@ -36,7 +36,6 @@
 struct batman_if {
 	struct list_head list;
 	int16_t if_num;
-	char *dev;
 	char if_status;
 	char addr_str[ETH_STR_LEN];
 	struct net_device *net_dev;
Signature · 1 line
1.7.1
#20 lore raw

PATCH 20/21 Staging: batman-adv: Don't inform about dropped packets in nodebug

In reply to Sven Eckelmann

Information about dropped packets are usually only interesting for debugging purposes and otherwise open the possibility to flood the logs of the target machine with useless information.

pr_debug will not output those information on a nodebug kernel.

---
 drivers/staging/batman-adv/routing.c |   15 +++++++--------
 drivers/staging/batman-adv/vis.c     |    2 +-
 2 files changed, 8 insertions(+), 9 deletions(-)
drivers/staging/batman-adv/routing.c +7 -8
index eda08b5..e12fd99 100644
@@ -859,9 +859,9 @@ static int recv_icmp_ttl_exceeded(struct bat_priv *bat_priv,
 
 	/* send TTL exceeded if packet is an echo request (traceroute) */
 	if (icmp_packet->msg_type != ECHO_REQUEST) {
-		pr_warning("Warning - can't forward icmp packet from %pM to "
-			   "%pM: ttl exceeded\n", icmp_packet->orig,
-			   icmp_packet->dst);
+		pr_debug("Warning - can't forward icmp packet from %pM to "
+			 "%pM: ttl exceeded\n", icmp_packet->orig,
+			 icmp_packet->dst);
 		return NET_RX_DROP;
 	}
 
@@ -1141,9 +1141,9 @@ static int route_unicast_packet(struct sk_buff *skb,
 
 	/* TTL exceeded */
 	if (unicast_packet->ttl < 2) {
-		pr_warning("Warning - can't forward unicast packet from %pM to "
-			   "%pM: ttl exceeded\n", ethhdr->h_source,
-			   unicast_packet->dest);
+		pr_debug("Warning - can't forward unicast packet from %pM to "
+			 "%pM: ttl exceeded\n", ethhdr->h_source,
+			 unicast_packet->dest);
 		return NET_RX_DROP;
 	}
 
@@ -1224,8 +1224,7 @@ int recv_ucast_frag_packet(struct sk_buff *skb, struct batman_if *recv_if)
 			hash_find(bat_priv->orig_hash, unicast_packet->orig));
 
 		if (!orig_node) {
-			pr_warning("couldn't find orig node for "
-				"fragmentation\n");
+			pr_debug("couldn't find orig node for fragmentation\n");
 			spin_unlock_irqrestore(&bat_priv->orig_hash_lock,
 					       flags);
 			return NET_RX_DROP;
drivers/staging/batman-adv/vis.c +1 -1
index 071d3b7..b2cec8e 100644
@@ -745,7 +745,7 @@ static void send_vis_packet(struct bat_priv *bat_priv, struct vis_info *info)
 
 	packet = (struct vis_packet *)info->skb_packet->data;
 	if (packet->ttl < 2) {
-		pr_warning("Error - can't send vis packet: ttl exceeded\n");
+		pr_debug("Error - can't send vis packet: ttl exceeded\n");
 		return;
 	}
 
Signature · 1 line
1.7.1
#21 lore raw

PATCH 21/21 Staging: batman-adv: Update mtu of bat device by changing mtu of slave device

In reply to Sven Eckelmann

We must reduce our own mtu when we reduce the mtu of any device we use to transfer our packets. Otherwise we may accept to large packets which gets dropped by the actual device.

---
 drivers/staging/batman-adv/hard-interface.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
drivers/staging/batman-adv/hard-interface.c +4 -0
index a58a89a..a587da9 100644
@@ -469,6 +469,10 @@ static int hard_if_event(struct notifier_block *this,
 	case NETDEV_UNREGISTER:
 		hardif_remove_interface(batman_if);
 		break;
+	case NETDEV_CHANGEMTU:
+		if (batman_if->soft_iface)
+			update_min_mtu(batman_if->soft_iface);
+		break;
 	case NETDEV_CHANGEADDR:
 		if (batman_if->if_status == IF_NOT_IN_USE)
 			goto out;
Signature · 1 line
1.7.1
#22 lore raw
In reply to Sven Eckelmann
Quoted 9 lines · Sven Eckelmann

Hi,

I hope that the fever-induced dreams are over now. Otherwise I will try to write my mails also as little tales. ;)

Nevertheless, I would like to send some patches for 2.6.37. That is not 100% true. We would also like to see the revert
'Revert: "Staging: batman-adv: Adding netfilter-bridge hooks"' too in 2.6.36. It fixes a bug introduced by the commit we revert here.

Ok, I've applied this to both trees to make everything work properly.

Quoted 2 lines

The rest is more or less the usual stuff, but more feature patches this time. All patches we depend on are already part of 2.6.36-rc3.

All queued up now, thanks.

greg k-h