Skip to contentSkip to conversation

memory related question w/ netfilter

DISCUSSION Ramnath R Iyer 2 participants 2 messages Apr 21, 2007 – Apr 24, 2007 netfilter

lore
Share & tools
lore
#0 lore raw

Hello,

I have a question regarding the way memory works with netfilter. I am writing a kernel-module that uses netfilter hooks to process certain kinds of messages.

Suppose my application handles an incoming packet at the NF_PRE_ROUTING hook. netfilter passes to the input handling function a /struct sk_buff **/. So suppose I need to queue up the data in the buffer in my own application, and return NF_STOLEN, which of the following scenarios is applicable?

(a) The sk_buff memory is subsequently unallocated, so I should copy the data into a new buffer before returning NF_STOLEN, or

(b) The sk_buff memory remains allocated, so I should call kfree on the pointer to unallocate it when I'm done using the data, or

(c) Something else

**Please** CC your response directly to me, since I'm not subscribed to the list. Thank you.

--
Ramnath R Iyer
DA-IICT, India

#1 lore raw

sön 2007-04-22 klockan 03:00 +0530 skrev Ramnath R Iyer:

Quoted 11 lines

/struct sk_buff **/. So suppose I need to queue up the data in the buffer in my own application, and return NF_STOLEN, which of the following scenarios is applicable?

(a) The sk_buff memory is subsequently unallocated, so I should copy the data into a new buffer before returning NF_STOLEN, or

(b) The sk_buff memory remains allocated, so I should call kfree on the pointer to unallocate it when I'm done using the data, or

(c) Something else

sk_buff's is reference counted. When you return NF_STOLEN you tell the kernel that you have taken over the reference to this sk_buff.

sk_buff references is managed using skb_get/kfree_skb.

If you need to modify the contents of the sk_buff, remember to mangle the reference via skb_share_check to make sure you have a private copy..

Note: If you need to inject the packets back to the kernel after you are done with them it's better to use NF_QUEUE instead.

Regards
Henrik