Results 1 to 7 of 7
Hello,
I wrote a LKM that intercepts packets as they are coming into Netfilter (NF_IP_PRE_ROUTING). If the packets are of interest, I modify the skb and send it immediately back ...
- 07-27-2005 #1Just Joined!
- Join Date
- Jul 2005
- Posts
- 4
memory leaks when stealing packets from netfilter ??
Hello,
I wrote a LKM that intercepts packets as they are coming into Netfilter (NF_IP_PRE_ROUTING). If the packets are of interest, I modify the skb and send it immediately back out using dev_queue_xmit() and then return NF_STOLEN. It should be that simple, right? BUT for some reason, I am getting memory leaks - dev_queue_xmit() does not kfree the skb that I pass it.
Any ideas why the skb is not being freed ?
Thanks in advance for any advice.
Tom
- 07-28-2005 #2Linux Guru
- Join Date
- Oct 2001
- Location
- Täby, Sweden
- Posts
- 7,578
I don't really recall those parts of the kernel off hand, but don't skb's do refcounting? Do you put the skb's?
- 07-28-2005 #3Just Joined!
- Join Date
- Jul 2005
- Posts
- 4
Yes, there is a users/refcount field in the skb....
Another thing that I've tried is to make a copy of the skb, change some fields, send it out to dev_queue_xmit(), and return NF_DROP....but have the same memory problem with the new skb.
- 07-28-2005 #4Linux Guru
- Join Date
- Oct 2001
- Location
- Täby, Sweden
- Posts
- 7,578
Like I said, then, are you putting the skb's?
- 07-28-2005 #5Just Joined!
- Join Date
- Jul 2005
- Posts
- 4
Excuse my ignorance, but I don't understand what you mean by "putting the skbs".
- 07-28-2005 #6Linux Guru
- Join Date
- Oct 2001
- Location
- Täby, Sweden
- Posts
- 7,578
Oh, sorry. To "put" is used very often in the kernel in the name of the functions that decrease the refcount of various objects, such as `fput' for `struct file' pointers, kref_put for general krefs, dev_put for net devices, and so on. Generally, then, you "put" an object to indicate that you're no longer using it, so that the refcounting works as it should. I'm sorry for assuming that you knew that.
I'm not sure what function is used for putting skb's, though. I'll have a little peek through the kernel source and see if I can find it for you.
- 07-28-2005 #7Just Joined!
- Join Date
- Jul 2005
- Posts
- 4
Hmmm....I checked dev_queue_xmit() and it seems that I should not have to decrease the refcount before I pass the skb to it. dev_queue_xmit() kfrees the skb if the refcount is one, otherwise it decrements the refcount.


Reply With Quote
