From c68622792c7f76c5388d0d350a1c1338081f46c7 Mon Sep 17 00:00:00 2001 From: Art Yerkes Date: Sat, 13 May 2006 06:41:23 +0000 Subject: [PATCH] - Live update of static IP address from ctl panel. - Fix removing adapter route on IP address delete. svn path=/trunk/; revision=21899 --- reactos/dll/cpl/ncpa/tcpip_properties.c | 22 ++++++++++++- .../drivers/network/tcpip/tcpip/dispatch.c | 1 + reactos/lib/drivers/ip/network/ip.c | 7 +++- reactos/lib/drivers/ip/network/router.c | 32 ++++++++++++++++++- 4 files changed, 59 insertions(+), 3 deletions(-) diff --git a/reactos/dll/cpl/ncpa/tcpip_properties.c b/reactos/dll/cpl/ncpa/tcpip_properties.c index 38616050654..1680c89f677 100644 --- a/reactos/dll/cpl/ncpa/tcpip_properties.c +++ b/reactos/dll/cpl/ncpa/tcpip_properties.c @@ -71,6 +71,7 @@ ManualDNS(HWND Dlg, BOOL Enabled) { if (! Enabled) { SendDlgItemMessage(Dlg, IDC_DNS1, IPM_CLEARADDRESS, 0, 0); SendDlgItemMessage(Dlg, IDC_DNS2, IPM_CLEARADDRESS, 0, 0); + } } @@ -132,10 +133,13 @@ static BOOL ValidateAndStore(HWND Dlg, PTCPIP_PROPERTIES_DATA DlgData) { DWORD IpAddress; + MIB_IPFORWARDROW RowToAdd = { 0 }, RowToRem = { 0 }; DlgData->DhcpEnabled = (BST_CHECKED == IsDlgButtonChecked(Dlg, IDC_USEDHCP)); if (! DlgData->DhcpEnabled) { + DhcpReleaseIpAddressLease( DlgData->AdapterIndex ); + if (4 != SendMessageW(GetDlgItem(Dlg, IDC_IPADDR), IPM_GETADDRESS, 0, (LPARAM) &IpAddress)) { ShowError(Dlg, IDS_ENTER_VALID_IPADDRESS); @@ -156,11 +160,26 @@ ValidateAndStore(HWND Dlg, PTCPIP_PROPERTIES_DATA DlgData) } else { DlgData->Gateway = htonl(IpAddress); } + DhcpStaticRefreshParams + ( DlgData->AdapterIndex, DlgData->IpAddress, DlgData->SubnetMask ); + + RowToRem.dwForwardMask = 0; + RowToRem.dwForwardMetric1 = 1; + RowToRem.dwForwardNextHop = DlgData->OldGateway; + + DeleteIpForwardEntry( &RowToRem ); + + RowToAdd.dwForwardMask = 0; + RowToAdd.dwForwardMetric1 = 1; + RowToAdd.dwForwardNextHop = DlgData->Gateway; + + CreateIpForwardEntry( &RowToAdd ); ASSERT(BST_CHECKED == IsDlgButtonChecked(Dlg, IDC_FIXEDDNS)); } else { DlgData->IpAddress = INADDR_NONE; DlgData->SubnetMask = INADDR_NONE; DlgData->Gateway = INADDR_NONE; + DhcpLeaseIpAddress( DlgData->AdapterIndex ); } if (BST_CHECKED == IsDlgButtonChecked(Dlg, IDC_FIXEDDNS)) { @@ -251,7 +270,8 @@ InternTCPIPSettings(HWND Dlg, PTCPIP_PROPERTIES_DATA DlgData) { goto cleanup; } - MessageBox(NULL, TEXT("You need to reboot before the new parameters take effect."), TEXT("Reboot required"), MB_OK | MB_ICONWARNING); + // arty ... Not needed anymore ... We update the address live now + //MessageBox(NULL, TEXT("You need to reboot before the new parameters take effect."), TEXT("Reboot required"), MB_OK | MB_ICONWARNING); ret = TRUE; cleanup: diff --git a/reactos/drivers/network/tcpip/tcpip/dispatch.c b/reactos/drivers/network/tcpip/tcpip/dispatch.c index a5f4a159533..0c7b111588f 100644 --- a/reactos/drivers/network/tcpip/tcpip/dispatch.c +++ b/reactos/drivers/network/tcpip/tcpip/dispatch.c @@ -1548,6 +1548,7 @@ NTSTATUS DispTdiDeleteIPAddress( PIRP Irp, PIO_STACK_LOCATION IrpSp ) { ForEachInterface(IF) { if( IF->Index == *NteIndex ) { + IPRemoveInterfaceRoute( IF ); IF->Unicast.Type = IP_ADDRESS_V4; IF->Unicast.Address.IPv4Address = 0; IF->Netmask.Type = IP_ADDRESS_V4; diff --git a/reactos/lib/drivers/ip/network/ip.c b/reactos/lib/drivers/ip/network/ip.c index 8bb2b6ba853..4daf364151b 100644 --- a/reactos/lib/drivers/ip/network/ip.c +++ b/reactos/lib/drivers/ip/network/ip.c @@ -305,14 +305,19 @@ VOID IPRemoveInterfaceRoute( PIP_INTERFACE IF ) { TCPDisposeInterfaceData( IF->TCPContext ); IF->TCPContext = NULL; + TI_DbgPrint(DEBUG_IP,("Removing interface Addr %s\n", A2S(&IF->Unicast))); + TI_DbgPrint(DEBUG_IP,(" Mask %s\n", A2S(&IF->Netmask))); + AddrWidenAddress(&GeneralRoute,&IF->Unicast,&IF->Netmask); + RouterRemoveRoute(&GeneralRoute, &IF->Unicast); /* Remove permanent NCE, but first we have to find it */ NCE = NBLocateNeighbor(&IF->Unicast); if (NCE) NBRemoveNeighbor(NCE); - + else + TI_DbgPrint(DEBUG_IP, ("Could not delete IF route (0x%X)\n", IF)); } VOID IPUnregisterInterface( diff --git a/reactos/lib/drivers/ip/network/router.c b/reactos/lib/drivers/ip/network/router.c index dfa33315911..319ea3c0bdf 100644 --- a/reactos/lib/drivers/ip/network/router.c +++ b/reactos/lib/drivers/ip/network/router.c @@ -18,6 +18,30 @@ LIST_ENTRY FIBListHead; KSPIN_LOCK FIBLock; +void RouterDumpRoutes() { + PLIST_ENTRY CurrentEntry; + PLIST_ENTRY NextEntry; + PFIB_ENTRY Current; + PNEIGHBOR_CACHE_ENTRY NCE; + + TI_DbgPrint(DEBUG_ROUTER,("Dumping Routes\n")); + + CurrentEntry = FIBListHead.Flink; + while (CurrentEntry != &FIBListHead) { + NextEntry = CurrentEntry->Flink; + Current = CONTAINING_RECORD(CurrentEntry, FIB_ENTRY, ListEntry); + + NCE = Current->Router; + + TI_DbgPrint(DEBUG_ROUTER,("Examining FIBE %x\n", Current)); + TI_DbgPrint(DEBUG_ROUTER,("... NetworkAddress %s\n", A2S(&Current->NetworkAddress))); + TI_DbgPrint(DEBUG_ROUTER,("... NCE->Address . %s\n", A2S(&NCE->Address))); + + CurrentEntry = NextEntry; + } + + TI_DbgPrint(DEBUG_ROUTER,("Dumping Routes ... Done\n")); +} VOID FreeFIB( PVOID Object) @@ -331,13 +355,17 @@ NTSTATUS RouterRemoveRoute(PIP_ADDRESS Target, PIP_ADDRESS Router) PNEIGHBOR_CACHE_ENTRY NCE; TI_DbgPrint(DEBUG_ROUTER, ("Called\n")); + TI_DbgPrint(DEBUG_ROUTER, ("Deleting Route From: %s\n", A2S(Router))); + TI_DbgPrint(DEBUG_ROUTER, (" To: %s\n", A2S(Target))); TcpipAcquireSpinLock(&FIBLock, &OldIrql); + RouterDumpRoutes(); + CurrentEntry = FIBListHead.Flink; while (CurrentEntry != &FIBListHead) { NextEntry = CurrentEntry->Flink; - Current = CONTAINING_RECORD(CurrentEntry, FIB_ENTRY, ListEntry); + Current = CONTAINING_RECORD(CurrentEntry, FIB_ENTRY, ListEntry); NCE = Current->Router; @@ -356,6 +384,8 @@ NTSTATUS RouterRemoveRoute(PIP_ADDRESS Target, PIP_ADDRESS Router) DestroyFIBE( Current ); } + RouterDumpRoutes(); + TcpipReleaseSpinLock(&FIBLock, OldIrql); TI_DbgPrint(DEBUG_ROUTER, ("Leaving\n"));