Project Home
Project Home
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - mbuf Memory Management in pfil Hook: (2 Items)
   
mbuf Memory Management in pfil Hook  
I've read the Filtering Wiki and the io-net migration guide and despite the note in these references saying there are 
many places on the web with information about mbuf's, I haven't been able to find anything about mbuf memory management 
in hooks. In our case, we have a protocol running above Ethernet. We register a PFIL_IN hook to collect packets off the 
wire. From the filtering wiki, it looks like our hook routine should return a non-zero value if we consume a packet and 
zero if packet processing should continue. It would make sense that we are responsible for freeing an mbuf if we consume
 a packet. Is that true? Similarly, we should not free the mbuf if our input hook returns 0, correct?

On the send side, we allocate an mbuf and call if_output to send the packet. Are we correct in assuming the driver will 
free this outgoing mbuf when it is no longer needed? We currently free the mbuf if if_output returns a non-zero value. 
Is that correct? Thanks.

Mark
Re: mbuf Memory Management in pfil Hook  
Hi Mark:

Looks like the NetBSD man pages have a bit more information:

http://netbsd.gw.com/cgi-bin/man-cgi?pfil_add_hook++NetBSD-4.0

Note the line:
"If the packet processing is to stop, it is the responsibility of the filter to free the packet." (and, conversely, if 
you don't block the packet, you don't free it since it has to continue on up the stack).

Not 100% sure about the outgoing stage, but given that the filter has no way of knowing when the driver has consumed the
 packet, I'd say that the driver doing the free would be the only way that makes sense.

   Hope that helps,
      Robert.