netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Graf <tgraf@suug.ch>
To: "David S. Miller" <davem@davemloft.net>
Cc: netdev@oss.sgi.com
Subject: [PATCH] PKT_SCHED: dsmark must take care of shared/cloned skbs
Date: Sat, 18 Dec 2004 18:00:17 +0100	[thread overview]
Message-ID: <20041218170017.GH17998@postel.suug.ch> (raw)

Dave,

Correctly handle shared and cloned skbs by copying them before writing
and dequeue unwriteable skbs unchanged. Assumes that IP/IPv6 header
is always linear so no pulling required.

Signed-off-by: Thomas Graf <tgraf@suug.ch>

--- linux-2.6.10-rc3-bk12.orig/net/sched/sch_dsmark.c	2004-12-18 15:16:29.000000000 +0100
+++ linux-2.6.10-rc3-bk12/net/sched/sch_dsmark.c	2004-12-18 16:24:58.000000000 +0100
@@ -195,7 +195,8 @@
 
 	D2PRINTK("dsmark_enqueue(skb %p,sch %p,[qdisc %p])\n",skb,sch,p);
 	if (p->set_tc_index) {
-		/* FIXME: Safe with non-linear skbs? --RR */
+		/* Safe with non-linear skbs? --RR
+		   IP/IPv6 header is always linear --TGR */
 		switch (skb->protocol) {
 			case __constant_htons(ETH_P_IP):
 				skb->tc_index = ipv4_get_dsfield(skb->nh.iph);
@@ -250,6 +251,34 @@
 	return ret;
 }
 
+static inline int
+dsmark_make_writeable(struct sk_buff **pskb, int offset)
+{
+	struct sk_buff *nskb;
+
+	if ((offset + (*pskb)->mac_len) > (*pskb)->len)
+		return 0;
+
+	if (skb_shared(*pskb) || skb_cloned(*pskb))
+		goto copy_skb;
+
+	/* IP/IPv6 header is always linear, no need to pull */
+	return 1;
+
+copy_skb:
+	nskb = skb_copy(*pskb, GFP_ATOMIC);
+	if (!nskb)
+		return 0;
+	BUG_ON(skb_is_nonlinear(nskb));
+
+	/* Rest of kernel will get very unhappy if we pass it a
+	   suddenly-orphaned skbuff */
+	if ((*pskb)->sk)
+		skb_set_owner_w(nskb, (*pskb)->sk);
+	kfree_skb(*pskb);
+	*pskb = nskb;
+	return 1;
+}
 
 static struct sk_buff *dsmark_dequeue(struct Qdisc *sch)
 {
@@ -266,10 +295,14 @@
 	D2PRINTK("index %d->%d\n",skb->tc_index,index);
 	switch (skb->protocol) {
 		case __constant_htons(ETH_P_IP):
+			if (!dsmark_make_writeable(&skb, sizeof(struct iphdr)))
+				goto unwriteable;
 			ipv4_change_dsfield(skb->nh.iph,
 			    p->mask[index],p->value[index]);
 			break;
 		case __constant_htons(ETH_P_IPV6):
+			if (!dsmark_make_writeable(&skb, sizeof(struct ipv6hdr)))
+				goto unwriteable;
 			ipv6_change_dsfield(skb->nh.ipv6h,
 			    p->mask[index],p->value[index]);
 			break;
@@ -280,12 +313,17 @@
 			 * and don't need yet another qdisc as a bypass.
 			 */
 			if (p->mask[index] != 0xff || p->value[index])
-				printk(KERN_WARNING "dsmark_dequeue: "
-				       "unsupported protocol %d\n",
-				       htons(skb->protocol));
+				if (net_ratelimit())
+					printk(KERN_WARNING "dsmark_dequeue: "
+					       "unsupported protocol %d\n",
+					       htons(skb->protocol));
 			break;
 	};
 	return skb;
+unwriteable:
+	if (net_ratelimit())
+		printk(KERN_WARNING "dsmark_dequeue: skb not writable\n");
+	return skb;
 }
 
 

             reply	other threads:[~2004-12-18 17:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-18 17:00 Thomas Graf [this message]
2004-12-18 21:00 ` [PATCH] PKT_SCHED: dsmark must take care of shared/cloned skbs Thomas Graf
2004-12-19 20:23 ` jamal
2004-12-19 20:36   ` Thomas Graf
2004-12-19 22:53     ` jamal
2004-12-19 23:18       ` Thomas Graf
2004-12-20  8:06     ` Patrick McHardy
2004-12-20 14:13       ` jamal
2004-12-21  1:02         ` David S. Miller
2004-12-22 13:14           ` jamal
2004-12-22 13:50             ` Thomas Graf

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=20041218170017.GH17998@postel.suug.ch \
    --to=tgraf@suug.ch \
    --cc=davem@davemloft.net \
    --cc=netdev@oss.sgi.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).