public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Emmanuel Guiton <emmanuel@netlab.hut.fi>
To: Muli Ben-Yehuda <mulix@mulix.org>
Cc: Duncan Sands <baldrick@free.fr>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: Freeing skbuff (was: Re: Sending built-by-hand packet and kernel panic.)
Date: Fri, 06 Feb 2004 08:58:27 +0200	[thread overview]
Message-ID: <40233B13.8050703@netlab.hut.fi> (raw)
In-Reply-To: 20040203094938.GE5212@actcom.co.il

Hi!

Well, my investigations led me to precise a bit more my problem. There 
is no problem with NF_HOOK as it returns 0 and the packet is sent on the 
wire.
Upper layers are not a problem neither, because I bypass them totally. 
However, handling myself the dtructor function seems to be definitely a 
must do.

Concerning what I noticed that was wrong in my code, there was this 
trick I used to initialize my socket:

struct socket *sending_socket;
struct sock *sk;

   if (sock_create(PF_INET, SOCK_RAW, IPPROTO_RAW, &sending_socket) < 0)
   {
       printk("Error socket creation.\n");
       sock_release(sending_socket);
       return -1;
   }
   sk = kmalloc(sizeof(struct sock), GFP_KERNEL);
   memcpy(&(sending_socket->sk), sk, sizeof(struct sock));

I noticed that the sock_create function increments the reference count 
by two. When I copy the sending_socket->sk field in my sk variable, sk 
still gets this ref count =2. Thus when destroying the skbuff the socket 
is not freed (the release function decreases the sk ref count by one, 
see that there is one left, and exit without freeing the socket).
I also now think that I was doing the operations the wrong way around: I 
was trying to initialize all the skbuff fields, amongst whose was the 
socket. I discovered in some other codes that it is usually the socket 
which is first initialized and then the skbuff is attached to it. At 
least I'm now following that idea but I haven't had much time recently 
to go deeper on the implementation.

Thanks for your help,

        Emmanuel


Muli Ben-Yehuda wrote:

>On Mon, Feb 02, 2004 at 07:51:47PM +0200, Emmanuel Guiton wrote:
>
>  
>
>>However, my overall problem is not solved. As far as my investigations 
>>led me, my sk_buff structure is never released after having been sent on 
>>the wire. So I guess I need an explicit destructor function in my 
>>sk_buff as the following is present in the definition of struct sk_buff:
>>void         (*destructor)(struct sk_buff *);    /* Destruct function  */
>>    
>>
>
>Note that depending on what you're doing, you might not be able to use
>the destructor, because the upper layers use it without regards to
>whether it was set before. To the best of my understanding, the rules
>for the destructor say that it is free for the use of whatever layer
>owns the skbuff at the moment. There are three ways around it - the
>first and obvious is to avoid relying on the destructor. The second is
>that you can use skb_clone() to get your own copy of the headers and
>the destructor (but that doesn't really help you because how does the
>layer that ends up freeing the skb know to use your version of the
>headers?) and the third is to use this patch,
>http://www.mulix.org/patches/skb-destructor-chaining-A2-2.6.1, to 
>allow more than destructor per skb. 
>
>Hope this helps, 
>Muli 
>  
>




  reply	other threads:[~2004-02-06  6:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-02 14:46 Sending built-by-hand packet and kernel panic Emmanuel Guiton
     [not found] ` <200402021602.56242.baldrick@free.fr>
2004-02-02 17:51   ` Freeing skbuff (was: Re: Sending built-by-hand packet and kernel panic.) Emmanuel Guiton
2004-02-03  9:49     ` Muli Ben-Yehuda
2004-02-06  6:58       ` Emmanuel Guiton [this message]
2004-02-04 10:27     ` Duncan Sands

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=40233B13.8050703@netlab.hut.fi \
    --to=emmanuel@netlab.hut.fi \
    --cc=baldrick@free.fr \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mulix@mulix.org \
    /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