b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven.eckelmann@gmx.de>
To: greg@kroah.com
Cc: b.a.t.m.a.n@lists.open-mesh.net
Subject: [B.A.T.M.A.N.] [PATCH 11/21] Staging: batman-adv: Keep header writable and unshared
Date: Sun,  5 Sep 2010 01:58:28 +0200	[thread overview]
Message-ID: <1283644718-653-12-git-send-email-sven.eckelmann@gmx.de> (raw)
In-Reply-To: <1283644718-653-1-git-send-email-sven.eckelmann@gmx.de>

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.

Reported-by: Marek Lindner <lindner_marek@yahoo.de>
Signed-off-by: Sven Eckelmann <sven.eckelmann@gmx.de>
---
 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(-)

diff --git a/drivers/staging/batman-adv/send.c b/drivers/staging/batman-adv/send.c
index e874cae..b39c67b 100644
--- a/drivers/staging/batman-adv/send.c
+++ b/drivers/staging/batman-adv/send.c
@@ -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);
diff --git a/drivers/staging/batman-adv/soft-interface.c b/drivers/staging/batman-adv/soft-interface.c
index d60b1a8..e8be209 100644
--- a/drivers/staging/batman-adv/soft-interface.c
+++ b/drivers/staging/batman-adv/soft-interface.c
@@ -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;
diff --git a/drivers/staging/batman-adv/soft-interface.h b/drivers/staging/batman-adv/soft-interface.h
index 6364854..9dbf5fc 100644
--- a/drivers/staging/batman-adv/soft-interface.h
+++ b/drivers/staging/batman-adv/soft-interface.h
@@ -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[];
 
diff --git a/drivers/staging/batman-adv/unicast.c b/drivers/staging/batman-adv/unicast.c
index 153914e..61ebd38 100644
--- a/drivers/staging/batman-adv/unicast.c
+++ b/drivers/staging/batman-adv/unicast.c
@@ -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;
-- 
1.7.1


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

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

Reply instructions:

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

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

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

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

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

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

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