Microsoft Internet Security and Acceleration Server 2000 |
The best practices provided here will help you create more efficient application filters.
For example, there may be a race between calls to Detach (IFWXDataFilter::Detach, or IFWXSessionFilter::Detach) and other methods. Data filters receive IFWXSocket interfaces when the IFWXDataFilter::SetSockets API is called. Because the Firewall service is multithreaded, more than one thread can use the same IFWXSocket interface simultaneously. Furthermore, one thread may call Detach to release the IFWXSocket interface, while the other thread still attempts to access the interface, perhaps while doing a data-pump. Access to the interface should be protected by a locking mechanism, such as a critical section. Because of locking by the Firewall service, deadlock situations may arise; for example, the following code can lead to a deadlock situation:
Lock(); HRESULT hr = spSocket->Close(FALSE); Unlock();
To avoid the deadlock, use this code:
// Copy member pointer to interface to a local "smart" pointer // while the object is locked CComPtr<IFWXSocket> spSocket; Lock(); spSocket = m_InternalSocket; Unlock(); // lock released to avoid deadlocks // Must verify that interface was not released by Detach() if (spSocket != NULL) { // Here it is safe to send, receive or close the socket. HRESULT hr = spSocket->Close(FALSE); }
There are situations in which an application filter is responsible for limiting what IP addresses are allowed access to, including:
For security purposes, the application filter has to define a range of IP addresses for which a particular connection is allowed. Define that range of IP addresses by using the IFWXIpFilter interface.
Note If you set the range of IP addresses equal to NULL, you are allowing all addresses to connect.