Author: janderwald
Date: Wed Oct 29 09:12:29 2008
New Revision: 37059
URL:
http://svn.reactos.org/svn/reactos?rev=37059&view=rev
Log:
- Delete Gateway Address from TcpipSettings when the gateway has been removed
- Correctly check if there is Gateway set when initializing
- Delete all old routes when applying changes
- Add new gateway when applying changes
Modified:
trunk/reactos/dll/win32/netcfgx/tcpipconf_notify.c
Modified: trunk/reactos/dll/win32/netcfgx/tcpipconf_notify.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/netcfgx/tcpipcon…
==============================================================================
--- trunk/reactos/dll/win32/netcfgx/tcpipconf_notify.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/netcfgx/tcpipconf_notify.c [iso-8859-1] Wed Oct 29 09:12:29
2008
@@ -2174,6 +2174,15 @@
/* store default gateway */
This->pCurrentConfig->Gw->IpAddress = dwIpAddr;
}
+ else
+ {
+ if (This->pCurrentConfig->Gw)
+ {
+ IP_ADDR * pNextGw = This->pCurrentConfig->Gw->Next;
+ CoTaskMemFree(This->pCurrentConfig->Gw);
+ This->pCurrentConfig->Gw = pNextGw;
+ }
+ }
}
else
{
@@ -2304,7 +2313,7 @@
/* set current hostmask */
SendDlgItemMessageA(hwndDlg, IDC_SUBNETMASK, IPM_SETADDRESS, 0,
(LPARAM)pCurSettings->Ip->u.Subnetmask);
}
- if (pCurSettings->Gw->IpAddress)
+ if (pCurSettings->Gw && pCurSettings->Gw->IpAddress)
{
/* set current gateway */
SendDlgItemMessageA(hwndDlg, IDC_DEFGATEWAY, IPM_SETADDRESS, 0,
(LPARAM)pCurSettings->Gw->IpAddress);
@@ -3211,38 +3220,82 @@
}
}
- pStr = CreateMultiSzString(pCurrentConfig->Gw, IPADDR, &dwSize,
FALSE);
- if(pStr)
- {
- RegSetValueExW(hKey, L"DefaultGateway", 0, REG_MULTI_SZ,
(LPBYTE)pStr, dwSize);
- CoTaskMemFree(pStr);
- }
-
- pStr = CreateMultiSzString(pCurrentConfig->Gw, METRIC, &dwSize,
FALSE);
- if(pStr)
- {
- RegSetValueExW(hKey, L"DefaultGatewayMetric", 0, REG_MULTI_SZ,
(LPBYTE)pStr, dwSize);
- CoTaskMemFree(pStr);
- }
- }
-
- if (!pCurrentConfig->Ns || pCurrentConfig->AutoconfigActive)
- {
- RegSetValueExW(hKey, L"NameServer", 0, REG_SZ,
(LPBYTE)L"", 1 * sizeof(WCHAR));
- }
- else
- {
- pStr = CreateMultiSzString(pCurrentConfig->Ns, IPADDR, &dwSize,
TRUE);
- if(pStr)
- {
- RegSetValueExW(hKey, L"NameServer", 0, REG_SZ, (LPBYTE)pStr,
dwSize);
- RegDeleteValueW(hKey, L"DhcpNameServer");
- CoTaskMemFree(pStr);
- }
- }
- RegCloseKey(hKey);
- }
-
+ if (pOldConfig->Gw)
+ {
+ dwSize = 0;
+ if (GetIpForwardTable(NULL, &dwSize, FALSE) ==
ERROR_INSUFFICIENT_BUFFER)
+ {
+ DWORD Index;
+ PMIB_IPFORWARDTABLE pIpForwardTable =
(PMIB_IPFORWARDTABLE)CoTaskMemAlloc(dwSize);
+ if (pIpForwardTable)
+ {
+ if (GetIpForwardTable(pIpForwardTable, &dwSize, FALSE) ==
NO_ERROR)
+ {
+ for (Index = 0; Index < pIpForwardTable->dwNumEntries;
Index++)
+ {
+ if (pIpForwardTable->table[Index].dwForwardIfIndex ==
pOldConfig->Index)
+ {
+
DeleteIpForwardEntry(&pIpForwardTable->table[Index]);
+ }
+ }
+ }
+ CoTaskMemFree(pIpForwardTable);
+ }
+ }
+ }
+
+ if (pCurrentConfig->Gw)
+ {
+ MIB_IPFORWARDROW RouterMib;
+ ZeroMemory(&RouterMib, sizeof(MIB_IPFORWARDROW));
+
+ RouterMib.dwForwardMetric1 = 1;
+ RouterMib.dwForwardIfIndex = pOldConfig->Index;
+ RouterMib.dwForwardNextHop = htonl(pCurrentConfig->Gw->IpAddress);
+
+ //TODO
+ // add multiple gw addresses when required
+
+ if (CreateIpForwardEntry(&RouterMib) == NO_ERROR)
+ {
+ pStr = CreateMultiSzString(pCurrentConfig->Gw, IPADDR,
&dwSize, FALSE);
+ if(pStr)
+ {
+ RegSetValueExW(hKey, L"DefaultGateway", 0,
REG_MULTI_SZ, (LPBYTE)pStr, dwSize);
+ CoTaskMemFree(pStr);
+ }
+
+ pStr = CreateMultiSzString(pCurrentConfig->Gw, METRIC,
&dwSize, FALSE);
+ if(pStr)
+ {
+ RegSetValueExW(hKey, L"DefaultGatewayMetric", 0,
REG_MULTI_SZ, (LPBYTE)pStr, dwSize);
+ CoTaskMemFree(pStr);
+ }
+ }
+ }
+ else
+ {
+ RegSetValueExW(hKey, L"DefaultGateway", 0, REG_MULTI_SZ,
(LPBYTE)L"", 1 * sizeof(WCHAR));
+ RegSetValueExW(hKey, L"DefaultGatewayMetric", 0, REG_MULTI_SZ,
(LPBYTE)L"\0", sizeof(WCHAR) * 2);
+ }
+
+ if (!pCurrentConfig->Ns || pCurrentConfig->AutoconfigActive)
+ {
+ RegSetValueExW(hKey, L"NameServer", 0, REG_SZ,
(LPBYTE)L"", 1 * sizeof(WCHAR));
+ }
+ else
+ {
+ pStr = CreateMultiSzString(pCurrentConfig->Ns, IPADDR, &dwSize,
TRUE);
+ if(pStr)
+ {
+ RegSetValueExW(hKey, L"NameServer", 0, REG_SZ,
(LPBYTE)pStr, dwSize);
+ RegDeleteValueW(hKey, L"DhcpNameServer");
+ CoTaskMemFree(pStr);
+ }
+ }
+ RegCloseKey(hKey);
+ }
+ }
return S_OK;
}