Project Home
Project Home
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - io-pkt pfil hook memory leak : (6 Items)
   
io-pkt pfil hook memory leak  
I have written a packet filter shared library using the pfil interface which I am mounting inside io-pkt-v4-hc : mount -
T io-pkt /home/libPacketfilter.so 

I have a outbound_hook which registers to the pfil interface and blocks any traffic on outbound port 80 to stop any http
 traffic . I am testing this with a script which repeatedly does http traffic by using the command : curl www.google.com
 . I see if my filter keeps on blocking the http traffic by returning value 1 back to io-pkt asking it to drop the 
packet , io-pkt memory constantly keeps on increasing ( heap memory information shown on the Momentics IDE) . 
If however packets are allowed , there is no memory leak . I am using the devn-pcnet.so driver to launch io-pkt-v4-hc on
 a Qnx 6.6 x86 Vm . 

Here is how my outgoing hook looks like : 

struct pfil_head *pfh_inet = NULL;
pfh_inet = pfil_head_get(PFIL_TYPE_AF, AF_INET);
pfil_add_hook(output_hook, NULL, PFIL_OUT | PFIL_WAITOK,pfh_inet);

static int output_hook(void *arg, struct mbuf **m,
                      struct ifnet *ifp, int dir)
{
	int block = 0; // don't block by default
    in_bytes += (*m)->m_len;

	struct mbuf* packet_buf = (*m);
	if(parse_mbuf(packet_buf,&outbound))
	{
		if(outbound.portremote == 80)
                    block = 1;
            
	}

	return block; // 0 means allow, 1 means block
}

I see that if i keep on blocking any tcp traffic such at http , io-pkt heap memory constantly rises .
If after processing the packet filter hook returns back 0 to io-pkt to allow the packet , no memory leak occurs.  
Is there any memory clean up required when I return back any non zero value from the pfil hook to io-pkt since I am 
asking io-pkt to drop the packet . Any help would be helpful .
Re: io-pkt pfil hook memory leak  
To avoid a memory leak on egress if dropping the packet you need to:

m_freem(packet_buf);
*m = NULL;
return 1;
Re: io-pkt pfil hook memory leak  
Hey Nick,
              Thanks for the reply . 
I introduced the m_freem(struct mbuf* ) call but I get an unresolved symbol as runtime . 
I am building my pfil.so and mounting it inside io-pkt . Do I need to link to any other lib/dll/.so to use this api in 
my pfil hooks . 

Also there is another similar api m_free(struct mbuf *) , can i use any of the two ?

Re: io-pkt pfil hook memory leak  
Also at compile time I get implicit declaration for m_freem() although I have included mbuf.h , but I havent defined 
_KERNEL since that throws up a lot of other errors . I also get similar warnings for the pfil_get_head & pfil_add_hook 
calls but they still work at runtime unlike this m_freem() call which crashes due to unresolved symbol when the packet 
drop code gets hit inside the pfil hook. 

What am I doing wrong ?

Re: io-pkt pfil hook memory leak  
You should be building an lsm with -D_KERNEL -EL -shared -DVARIANT_dll

Make sure you have a proper recursive QNX make file structure setup i.e. lsm-name/x86/dll with common.mk in lsm-name. 
addvariant should create this structure. 
Re: io-pkt pfil hook memory leak  
thanks a lot Nick .

I am able to build the lsm now as a kernel module and I c no more leaks in the io-pkt when the filter blocks traffic .