--------------------- PatchSet 11868 Date: 2008/01/03 02:30:06 Author: hno Branch: SQUID_2_7 Tag: (none) Log: Author: serassio MFC: 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/main.c:1.403->1.403.2.1 src/protos.h:1.547->1.547.2.1 src/win32.c:1.18->1.18.2.1 Index: squid/src/main.c =================================================================== RCS file: /cvsroot/squid/squid/src/main.c,v retrieving revision 1.403 retrieving revision 1.403.2.1 diff -u -r1.403 -r1.403.2.1 --- squid/src/main.c 23 Nov 2007 11:06:47 -0000 1.403 +++ squid/src/main.c 3 Jan 2008 02:30:06 -0000 1.403.2.1 @@ -1,6 +1,6 @@ /* - * $Id: main.c,v 1.403 2007/11/23 11:06:47 hno Exp $ + * $Id: main.c,v 1.403.2.1 2008/01/03 02:30:06 hno Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -569,6 +569,9 @@ debug(1, 1) ("With %d CRT stdio descriptors available\n", _getmaxstdio()); if (WIN32_Socks_initialized) debug(1, 1) ("Windows sockets initialized\n"); + if (WIN32_OS_version > _WIN_OS_WINNT) { + WIN32_IpAddrChangeMonitorInit(); + } #endif comm_select_postinit(); Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid/squid/src/protos.h,v retrieving revision 1.547 retrieving revision 1.547.2.1 diff -u -r1.547 -r1.547.2.1 --- squid/src/protos.h 14 Dec 2007 20:05:24 -0000 1.547 +++ squid/src/protos.h 3 Jan 2008 02:30:06 -0000 1.547.2.1 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.547 2007/12/14 20:05:24 hno Exp $ + * $Id: protos.h,v 1.547.2.1 2008/01/03 02:30:06 hno Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -1406,6 +1406,9 @@ extern int WIN32_getrusage(int, struct rusage *); extern void WIN32_ExceptionHandlerInit(void); extern int SquidMain(int, char **); +#ifdef _SQUID_MSWIN_ +extern DWORD WIN32_IpAddrChangeMonitorInit(); +#endif #endif /* external_acl.c */ Index: squid/src/win32.c =================================================================== RCS file: /cvsroot/squid/squid/src/win32.c,v retrieving revision 1.18 retrieving revision 1.18.2.1 diff -u -r1.18 -r1.18.2.1 --- squid/src/win32.c 12 Aug 2007 10:09:46 -0000 1.18 +++ squid/src/win32.c 3 Jan 2008 02:30:06 -0000 1.18.2.1 @@ -1,6 +1,6 @@ /* - * $Id: win32.c,v 1.18 2007/08/12 10:09:46 serassio Exp $ + * $Id: win32.c,v 1.18.2.1 2008/01/03 02:30:06 hno Exp $ * * Windows support * AUTHOR: Guido Serassio @@ -67,6 +67,7 @@ extern LPCRITICAL_SECTION dbg_mutex; void WIN32_ExceptionHandlerCleanup(void); static LPTOP_LEVEL_EXCEPTION_FILTER Win32_Old_ExceptionHandler = NULL; +static HANDLE NotifyAddrChange_thread = INVALID_HANDLE_VALUE; #endif /* _SQUID_MSWIN_ */ #if USE_WIN32_SERVICE @@ -91,6 +92,9 @@ #else #define CHANGESERVICECONFIG2 "ChangeServiceConfig2A" #endif +#undef NotifyAddrChange +typedef DWORD(WINAPI * PFNotifyAddrChange) (OUT PHANDLE, IN LPOVERLAPPED); +#define NOTIFYADDRCHANGE "NotifyAddrChange" #if USE_WIN32_SERVICE static SC_ACTION Squid_SCAction[] = { @@ -359,6 +363,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_ @@ -376,10 +391,55 @@ if (dbg_mutex) 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) {