All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick McHardy <kaber@trash.net>
To: Thomas Graf <tgraf@suug.ch>
Cc: "David S. Miller" <davem@redhat.com>,
	Rusty Russell <rusty@rustcorp.com.au>,
	Jamal Hadi Salim <hadi@cyberus.ca>,
	Netfilter Development Mailinglist
	<netfilter-devel@lists.netfilter.org>
Subject: Re: skb_ip_make_writable and skbs not owned by a socket
Date: Mon, 03 Jan 2005 02:36:35 +0100	[thread overview]
Message-ID: <41D8A1A3.3060308@trash.net> (raw)
In-Reply-To: <20050102235757.GA26856@postel.suug.ch>

[-- Attachment #1: Type: text/plain, Size: 2267 bytes --]

Thomas Graf wrote:

>* Patrick McHardy <41D86571.6070501@trash.net> 2005-01-02 22:19
>  
>
>>skb_ip_make_writable copies the packet as soon as the data area needs
>>to be touched. This is of course necessary for packets generated locally,
>>but can't we mangle the data area of skbs with skb->sk == NULL without
>>copying them ?
>>    
>>
>
>Theoretically there could be a driver for a S/G capable nic producing
>pskbs. I'm not aware of such a driver though. Assuming there is no
>such driver at the moment, the question is whether to make all the
>paths aware as a precaution (net/sched/ is not aware as of now). I
>think everyone would agree if there wasn't such ia high possible
>performance impact respectively saving. Thoughts?
>
I was refering to a different problem. skb_ip_make_writable copies
skbs when the data area needs to be mangled to avoid disturbing the
tcp retransmission queue. Not sure why it is done for UDP and ICMP.
My question is if we can asume it is safe to alter the data area of
a skb, if it is not shared, or cloned, in the linear range and
skb->sk == NULL. See the attached patch. A different question is
why we can't simply do this:

(cut-n-paste, I would cut at least one goto in a patch)

int skb_ip_make_writable(struct sk_buff **pskb, unsigned int writable_len)
{
        struct sk_buff *nskb;

        if (writable_len > (*pskb)->len)
                return 0;

        /* Not exclusive use of packet?  Must copy. */
        if (skb_shared(*pskb) || skb_cloned(*pskb))
                goto copy_skb;

        if (skb_headlen(skb) <= writable_len)
                return 1;
        goto pull_skb;

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;

pull_skb:
        return pskb_may_pull(*pskb, writable_len);
}

Packets cloned or shared with the TCP retransmission queue are
already caught by the second condition. This should avoid lots
of copies compared to the current code.

Regards
Patrick


[-- Attachment #2: x --]
[-- Type: text/plain, Size: 458 bytes --]

===== net/core/netfilter.c 1.37 vs edited =====
--- 1.37/net/core/netfilter.c	2004-11-13 14:41:07 +01:00
+++ edited/net/core/netfilter.c	2005-01-03 02:17:16 +01:00
@@ -691,6 +691,12 @@
 	if (writable_len <= (*pskb)->nh.iph->ihl*4)
 		return 1;
 
+	if (skb->sk == NULL) {
+		if (skb_headlen(skb) <= writable_len)
+			return 1;
+		goto pull_skb;
+	}
+
 	iplen = writable_len - (*pskb)->nh.iph->ihl*4;
 
 	/* DaveM says protocol headers are also modifiable. */

  reply	other threads:[~2005-01-03  1:36 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-02 21:19 skb_ip_make_writable and skbs not owned by a socket Patrick McHardy
2005-01-02 23:57 ` Thomas Graf
2005-01-03  1:36   ` Patrick McHardy [this message]
2005-01-03  1:53     ` Patrick McHardy
2005-01-03 14:55       ` jamal
2005-01-14  5:31 ` David S. Miller
2005-01-14  5:59   ` Patrick McHardy
2005-01-14  6:08     ` David S. Miller
2005-01-17 21:50     ` David S. Miller
2005-01-17 23:13       ` Patrick McHardy
2005-01-27  4:10         ` Patrick McHardy
2005-01-27  5:50           ` David S. Miller
2005-01-27 14:41             ` Patrick McHardy

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=41D8A1A3.3060308@trash.net \
    --to=kaber@trash.net \
    --cc=davem@redhat.com \
    --cc=hadi@cyberus.ca \
    --cc=netfilter-devel@lists.netfilter.org \
    --cc=rusty@rustcorp.com.au \
    --cc=tgraf@suug.ch \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.