It is currently Wed Jun 19, 2013 12:58 pm



Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Server Network freeze when I use WinpkFilter
PostPosted: Thu Nov 03, 2011 8:17 pm 
Offline

Joined: Sat Oct 29, 2011 2:38 pm
Posts: 8
I modify gretunnel to just monitor incoming packet without do anything, but when I send just 5000 UDP packet with 200 byte size, I loose server connection for 2 min! I will be useless for me in such case.

My server is Windows 2008 R2 x64 on HyperV
My code compiled as 32 bit application
My network is 2Mbit internet connection
If I dont run the code I have not such issue, it mean there is not relate to firewall or routers
I am using the latest version of WinpkFilter 3.0.8.0

Code:
int main(int argc, char* argv[])
{
 Test(5, 100);
}

void Test(int index, int counter)
{
   ETH_REQUEST         Request;
   INTERMEDIATE_BUFFER PacketBuffer;
   ether_header*      pEthHeader = NULL;
   iphdr*            pIpHeader = NULL;

   if(!api.IsDriverLoaded())
   {
      printf ("Driver not installed on this system of failed to load.\n");
      return;
   }
   
   api.GetTcpipBoundAdaptersInfo ( &AdList );

   if ( iIndex + 1 > AdList.m_nAdapterCount )
   {
      printf("There is no network interface with such index on this system.\n");
      return;
   }

   
   ADAPTER_MODE Mode;
   Mode.dwFlags = MSTCP_FLAG_SENT_TUNNEL|MSTCP_FLAG_RECV_TUNNEL;
   Mode.hAdapterHandle = (HANDLE)AdList.m_nAdapterHandle[iIndex];

   // Create notification event
   hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

   // Set event for helper driver
   if ((!hEvent)||(!api.SetPacketEvent((HANDLE)AdList.m_nAdapterHandle[iIndex], hEvent)))
   {
      printf ("Failed to create notification event or set it for driver.\n");
      return;
   }

   atexit (ReleaseInterface);
   
   // Initialize Request
   ZeroMemory ( &Request, sizeof(ETH_REQUEST) );
   ZeroMemory ( &PacketBuffer, sizeof(INTERMEDIATE_BUFFER) );
   Request.EthPacket.Buffer = &PacketBuffer;
   Request.hAdapterHandle = (HANDLE)AdList.m_nAdapterHandle[iIndex];
      
   api.SetAdapterMode(&Mode);

   while (counter != 0)
   {
      WaitForSingleObject ( hEvent, INFINITE );
      
      while(api.ReadPacket(&Request))
      {
         bool send = PacketBuffer.m_dwDeviceFlags == PACKET_FLAG_ON_SEND;
         //ether_header_ptr ethHeader = (ether_header*)Request.EthPacket.Buffer->m_IBuffer;

         counter--;
         if (counter%100==0)
            printf("Counter:%d\n", counter);

         if (send)
         {
            // Place packet on the network interface
            api.SendPacketToAdapter(&Request);
         }
         else
         {
            // Indicate packet to MSTCP
            api.SendPacketToMstcp(&Request);
         }

         if (counter == 0)
         {
            printf ("Filtering complete\n");
            break;
         }
      }

      ResetEvent(hEvent);
   }
}


Top
 Profile  
 
 Post subject: Re: Server Network freeze when I use WinpkFilter
PostPosted: Fri Nov 04, 2011 10:43 pm 
Offline

Joined: Wed Oct 19, 2011 2:25 pm
Posts: 5
Maybe there is something with your packet queue?

Manual says that if you don't read packets from the queue (with CNdisApi::ReadPacket) or release the queued packets directly by calling CNdisApi::FlushAdapterPacketQueue then after the queue reaches it's maximum limit all network activities will be frozen.


Top
 Profile  
 
 Post subject: Re: Server Network freeze when I use WinpkFilter
PostPosted: Tue Nov 08, 2011 11:49 pm 
Offline

Joined: Sat Oct 29, 2011 2:38 pm
Posts: 8
Tanks for your reply.
Would you tell me whats wrongs in my code? The code is so simple and it even does not process that packet but it got frozen.
Would you help me?
Regards


Top
 Profile  
 
 Post subject: Re: Server Network freeze when I use WinpkFilter
PostPosted: Wed Nov 09, 2011 3:50 am 
Offline
Site Admin

Joined: Wed Jul 26, 2006 12:22 pm
Posts: 509
I can't see if your filter application really does anything except console output. However, please note that console output is relatively slow thing and if you call it for every packet this cause a serious delay for each packet processing, thus causing slower reading packets from the queue. May be this was a problem in you case, however, I have not been expecting your code thoroughly. Why you just don't use the tha passthru sample instead compiled with no console output?


Top
 Profile  
 
 Post subject: Re: Server Network freeze when I use WinpkFilter
PostPosted: Wed Nov 09, 2011 8:45 am 
Offline

Joined: Sat Oct 29, 2011 2:38 pm
Posts: 8
Hi
I know console is slow so I just print one counter per 100 packet:
Code:
if (counter%100==0)


Actually the system network frozen for 1 min or more and when it back i see it even does not process much packet; it doesn't print much message too.
Actually the code is same ass passthru, as you say i check passthru sample too and I remark all printf output, but still same issue when I send many packet (10000 UDP packets) from client site.
I really going to corporate with you to solve this issue, I can also send you my server admin password to you to check this issue yourself.


Top
 Profile  
 
 Post subject: Re: Server Network freeze when I use WinpkFilter
PostPosted: Wed Nov 09, 2011 12:34 pm 
Offline
Site Admin

Joined: Wed Jul 26, 2006 12:22 pm
Posts: 509
WinpkFilter driver by default has 500 buffers for queing packets. When you send a large amount of packets on the network interface which is in the tunnel mode then driver internal queue is overloaded and network will be frozen until your user mode application process all these packets. So the reason is the application which does not process packets fast enough. May be it just does get enough CPU time. Try to assign packet filtering application a higher priority than your UDP sending application has. However, I don't think that your network is really frozen, you rather expirience a huge packet drops because of massive UDP spoofing and this causes TCP resends and etc...


Top
 Profile  
 
 Post subject: Re: Server Network freeze when I use WinpkFilter
PostPosted: Wed Nov 09, 2011 12:35 pm 
Offline
Site Admin

Joined: Wed Jul 26, 2006 12:22 pm
Posts: 509
P.S. You can also try PackThru sample which reads/writes blocks of packets from/to the driver and thus faster processes the queue.


Top
 Profile  
 
 Post subject: Re: Server Network freeze when I use WinpkFilter
PostPosted: Wed Nov 09, 2011 12:41 pm 
Offline
Site Admin

Joined: Wed Jul 26, 2006 12:22 pm
Posts: 509
P.P.S. If you plan UDP spoofing on the network interface using large amounts of packets then it also may have sense to create a special WinpkFilter driver build with larger amount of packets buffers.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Theme designed by stylerbb.net © 2008
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All times are UTC + 2 hours