--------------------- PatchSet 6712 Date: 2008/01/24 19:16:18 Author: serassio Branch: nt Tag: (none) Log: Windows port: Handle notification of IP address changes for dial-up connections On Windows 2000 and later, the NotifyAddrChange() function allow a process to be notified of the changes in the system IP addresses table. This patch generate a reconfigure request after any notification, this allow the hot addition/reconfiguration of network interfaces without manually restart/reconfigure Squid. Members: src/WinSvc.cc:1.1.2.5->1.1.2.6 src/main.cc:1.15.2.86->1.15.2.87 src/protos.h:1.19.2.72->1.19.2.73 Index: squid3/src/WinSvc.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/WinSvc.cc,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -u -r1.1.2.5 -r1.1.2.6 --- squid3/src/WinSvc.cc 29 Apr 2007 10:16:00 -0000 1.1.2.5 +++ squid3/src/WinSvc.cc 24 Jan 2008 19:16:18 -0000 1.1.2.6 @@ -1,6 +1,6 @@ /* - * $Id: WinSvc.cc,v 1.1.2.5 2007/04/29 10:16:00 serassio Exp $ + * $Id: WinSvc.cc,v 1.1.2.6 2008/01/24 19:16:18 serassio Exp $ * * Windows support * AUTHOR: Guido Serassio @@ -69,6 +69,11 @@ #endif static int Squid_Aborting = 0; +static HANDLE NotifyAddrChange_thread = INVALID_HANDLE_VALUE; + +#undef NotifyAddrChange +typedef DWORD(WINAPI * PFNotifyAddrChange) (OUT PHANDLE, IN LPOVERLAPPED); +#define NOTIFYADDRCHANGE "NotifyAddrChange" #if USE_WIN32_SERVICE static SERVICE_STATUS svcStatus; @@ -386,6 +391,17 @@ } void +WIN32_IpAddrChangeMonitorExit() +{ + DWORD status = ERROR_SUCCESS; + + if (NotifyAddrChange_thread == INVALID_HANDLE_VALUE) { + TerminateThread(NotifyAddrChange_thread, status); + CloseHandle(NotifyAddrChange_thread); + } +} + +void WIN32_Exit() { #ifdef _SQUID_MSWIN_ @@ -406,12 +422,57 @@ DeleteCriticalSection(dbg_mutex); WIN32_ExceptionHandlerCleanup(); + WIN32_IpAddrChangeMonitorExit(); #endif _exit(0); } +#ifdef _SQUID_MSWIN_ +static DWORD WINAPI +WIN32_IpAddrChangeMonitor(LPVOID lpParam) +{ + DWORD Result; + HMODULE IPHLPAPIHandle; + PFNotifyAddrChange NotifyAddrChange; + + if ((IPHLPAPIHandle = GetModuleHandle("IPHLPAPI")) == NULL) + IPHLPAPIHandle = LoadLibrary("IPHLPAPI"); + NotifyAddrChange = (PFNotifyAddrChange) GetProcAddress(IPHLPAPIHandle, NOTIFYADDRCHANGE); + + while (1) { + Result = NotifyAddrChange(NULL, NULL); + if (Result != NO_ERROR) { + debug(1, 1) ("NotifyAddrChange error %ld\n", Result); + return 1; + } + debug(1, 1) ("Notification of IP address change received, requesting Squid reconfiguration ...\n"); + reconfigure(SIGHUP); + } + return 0; +} + +DWORD +WIN32_IpAddrChangeMonitorInit() +{ + DWORD status = ERROR_SUCCESS; + DWORD threadID = 0, ThrdParam = 0; + + if (WIN32_run_mode == _WIN_SQUID_RUN_MODE_SERVICE) { + NotifyAddrChange_thread = CreateThread(NULL, 0, WIN32_IpAddrChangeMonitor, + &ThrdParam, 0, &threadID); + if (NotifyAddrChange_thread == NULL) { + status = GetLastError(); + NotifyAddrChange_thread = INVALID_HANDLE_VALUE; + debug(1, 1) ("Failed to start IP monitor thread.\n"); + } else + debug(1, 2) ("Starting IP monitor thread [%li] ...\n", threadID); + } + return status; +} +#endif + int WIN32_Subsystem_Init(int * argc, char *** argv) { #if defined(_MSC_VER) /* Microsoft C Compiler ONLY */ Index: squid3/src/main.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/main.cc,v retrieving revision 1.15.2.86 retrieving revision 1.15.2.87 diff -u -r1.15.2.86 -r1.15.2.87 --- squid3/src/main.cc 22 Jan 2008 20:31:09 -0000 1.15.2.86 +++ squid3/src/main.cc 24 Jan 2008 19:16:18 -0000 1.15.2.87 @@ -1,6 +1,6 @@ /* - * $Id: main.cc,v 1.15.2.86 2008/01/22 20:31:09 serassio Exp $ + * $Id: main.cc,v 1.15.2.87 2008/01/24 19:16:18 serassio Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -828,6 +828,10 @@ if (WIN32_Socks_initialized) debugs(1, 1, "Windows sockets initialized"); + if (WIN32_OS_version > _WIN_OS_WINNT) { + WIN32_IpAddrChangeMonitorInit(); + } + #endif if (!configured_once) Index: squid3/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/protos.h,v retrieving revision 1.19.2.72 retrieving revision 1.19.2.73 diff -u -r1.19.2.72 -r1.19.2.73 --- squid3/src/protos.h 22 Jan 2008 11:12:02 -0000 1.19.2.72 +++ squid3/src/protos.h 24 Jan 2008 19:16:19 -0000 1.19.2.73 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.19.2.72 2008/01/22 11:12:02 serassio Exp $ + * $Id: protos.h,v 1.19.2.73 2008/01/24 19:16:19 serassio Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -770,8 +770,8 @@ SQUIDCEXTERN int WIN32_getrusage(int, struct rusage *); SQUIDCEXTERN void WIN32_ExceptionHandlerInit(void); -SQUIDCEXTERN int Win32__WSAFDIsSet(int fd, fd_set* set - ); +SQUIDCEXTERN int Win32__WSAFDIsSet(int fd, fd_set* set); +SQUIDCEXTERN DWORD WIN32_IpAddrChangeMonitorInit(); #endif