mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 01:05:42 +00:00
- Added add and delete route primitives in tcpip/ninfo.c
- Changed signature of RouterRemoveRoute to better match the information provided at the time when we delete a route. - Changed signature of RouterCreateRoute for consistency. - Cleaned up ninfo, get route info a bit. Removed 'bad' case, not needed. Made magic 2 into TDI_ADDRESS_TYPE_IP, shortened code. - Added AddrWidenAddress to generate a network address from a target and netmask. - Changed the main mib to contain the number of fib entries, not the number of route cache entries. svn path=/trunk/; revision=11818
This commit is contained in:
parent
9eef3a6021
commit
b3c9021b8f
7 changed files with 151 additions and 81 deletions
|
@ -83,6 +83,18 @@ UINT AddrCountPrefixBits( PIP_ADDRESS Netmask ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VOID AddrWidenAddress( PIP_ADDRESS Network, PIP_ADDRESS Source,
|
||||||
|
PIP_ADDRESS Netmask ) {
|
||||||
|
if( Netmask->Type == IP_ADDRESS_V4 ) {
|
||||||
|
Network->Address.IPv4Address =
|
||||||
|
Source->Address.IPv4Address & Netmask->Address.IPv4Address;
|
||||||
|
} else {
|
||||||
|
TI_DbgPrint(DEBUG_DATALINK, ("Don't know address type %d\n",
|
||||||
|
Netmask->Type));
|
||||||
|
*Network = *Source;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
VOID IPAddressFree(
|
VOID IPAddressFree(
|
||||||
PVOID Object)
|
PVOID Object)
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -237,6 +237,7 @@ BOOLEAN IPRegisterInterface(
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
KIRQL OldIrql;
|
KIRQL OldIrql;
|
||||||
|
IP_ADDRESS NetworkAddress;
|
||||||
PROUTE_CACHE_NODE RCN;
|
PROUTE_CACHE_NODE RCN;
|
||||||
PNEIGHBOR_CACHE_ENTRY NCE;
|
PNEIGHBOR_CACHE_ENTRY NCE;
|
||||||
|
|
||||||
|
@ -254,12 +255,13 @@ BOOLEAN IPRegisterInterface(
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* NCE is already referenced */
|
AddrWidenAddress( &NetworkAddress, &IF->Unicast, &IF->Netmask );
|
||||||
if (!RouterAddRoute(&IF->Unicast, &IF->Netmask, NCE, 1)) {
|
|
||||||
|
if (!RouterAddRoute(&NetworkAddress, &IF->Netmask, NCE, 1)) {
|
||||||
TI_DbgPrint(MIN_TRACE, ("Could not add route due to insufficient resources.\n"));
|
TI_DbgPrint(MIN_TRACE, ("Could not add route due to insufficient resources.\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
RCN = RouteAddRouteToDestination(&IF->Unicast, IF, NCE);
|
RCN = RouteAddRouteToDestination(&NetworkAddress, IF, NCE);
|
||||||
if (!RCN) {
|
if (!RCN) {
|
||||||
TI_DbgPrint(MIN_TRACE, ("Could not create RCN.\n"));
|
TI_DbgPrint(MIN_TRACE, ("Could not create RCN.\n"));
|
||||||
TcpipReleaseSpinLock(&IF->Lock, OldIrql);
|
TcpipReleaseSpinLock(&IF->Lock, OldIrql);
|
||||||
|
|
|
@ -274,30 +274,61 @@ PNEIGHBOR_CACHE_ENTRY RouterGetRoute(PIP_ADDRESS Destination)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VOID RouterRemoveRoute(
|
NTSTATUS RouterRemoveRoute(PIP_ADDRESS Target, PIP_ADDRESS Router)
|
||||||
PFIB_ENTRY FIBE)
|
|
||||||
/*
|
/*
|
||||||
* FUNCTION: Removes a route from the Forward Information Base (FIB)
|
* FUNCTION: Removes a route from the Forward Information Base (FIB)
|
||||||
* ARGUMENTS:
|
* ARGUMENTS:
|
||||||
* FIBE = Pointer to FIB entry describing route
|
* Target: The machine or network targeted by the route
|
||||||
|
* Router: The router used to pass the packet to the destination
|
||||||
|
*
|
||||||
|
* Searches the FIB and removes a route matching the indicated parameters.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
KIRQL OldIrql;
|
KIRQL OldIrql;
|
||||||
|
PLIST_ENTRY CurrentEntry;
|
||||||
|
PLIST_ENTRY NextEntry;
|
||||||
|
PFIB_ENTRY Current;
|
||||||
|
BOOLEAN Found = FALSE;
|
||||||
|
PNEIGHBOR_CACHE_ENTRY NCE;
|
||||||
|
|
||||||
TI_DbgPrint(DEBUG_ROUTER, ("Called. FIBE (0x%X).\n", FIBE));
|
TI_DbgPrint(DEBUG_ROUTER, ("Called\n"));
|
||||||
|
|
||||||
TI_DbgPrint(DEBUG_ROUTER, ("FIBE (%s).\n", A2S(&FIBE->NetworkAddress)));
|
|
||||||
|
|
||||||
TcpipAcquireSpinLock(&FIBLock, &OldIrql);
|
TcpipAcquireSpinLock(&FIBLock, &OldIrql);
|
||||||
DestroyFIBE(FIBE);
|
|
||||||
|
CurrentEntry = FIBListHead.Flink;
|
||||||
|
while (CurrentEntry != &FIBListHead) {
|
||||||
|
NextEntry = CurrentEntry->Flink;
|
||||||
|
Current = CONTAINING_RECORD(CurrentEntry, FIB_ENTRY, ListEntry);
|
||||||
|
|
||||||
|
NCE = Current->Router;
|
||||||
|
|
||||||
|
if( AddrIsEqual( &Current->NetworkAddress, Target ) &&
|
||||||
|
AddrIsEqual( &NCE->Address, Router ) ) {
|
||||||
|
Found = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Current = NULL;
|
||||||
|
CurrentEntry = NextEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( Found ) {
|
||||||
|
TI_DbgPrint(DEBUG_ROUTER, ("Deleting route\n"));
|
||||||
|
DestroyFIBE( Current );
|
||||||
|
}
|
||||||
|
|
||||||
TcpipReleaseSpinLock(&FIBLock, OldIrql);
|
TcpipReleaseSpinLock(&FIBLock, OldIrql);
|
||||||
|
|
||||||
|
TI_DbgPrint(DEBUG_ROUTER, ("Leaving\n"));
|
||||||
|
|
||||||
|
return Found ? STATUS_NO_SUCH_FILE : STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PFIB_ENTRY RouterCreateRoute(
|
PFIB_ENTRY RouterCreateRoute(
|
||||||
IP_ADDRESS NetworkAddress,
|
PIP_ADDRESS NetworkAddress,
|
||||||
IP_ADDRESS Netmask,
|
PIP_ADDRESS Netmask,
|
||||||
IP_ADDRESS RouterAddress,
|
PIP_ADDRESS RouterAddress,
|
||||||
PIP_INTERFACE Interface,
|
PIP_INTERFACE Interface,
|
||||||
UINT Metric)
|
UINT Metric)
|
||||||
/*
|
/*
|
||||||
|
@ -319,7 +350,7 @@ PFIB_ENTRY RouterCreateRoute(
|
||||||
|
|
||||||
/* The NCE references RouterAddress. The NCE is referenced for us */
|
/* The NCE references RouterAddress. The NCE is referenced for us */
|
||||||
NCE = NBAddNeighbor(Interface,
|
NCE = NBAddNeighbor(Interface,
|
||||||
&RouterAddress,
|
RouterAddress,
|
||||||
NULL,
|
NULL,
|
||||||
Interface->AddressLength,
|
Interface->AddressLength,
|
||||||
NUD_PROBE);
|
NUD_PROBE);
|
||||||
|
@ -328,7 +359,7 @@ PFIB_ENTRY RouterCreateRoute(
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
FIBE = RouterAddRoute(&NetworkAddress, &Netmask, NCE, 1);
|
FIBE = RouterAddRoute(NetworkAddress, Netmask, NCE, 1);
|
||||||
if (!FIBE) {
|
if (!FIBE) {
|
||||||
/* Not enough free resources */
|
/* Not enough free resources */
|
||||||
NBRemoveNeighbor(NCE);
|
NBRemoveNeighbor(NCE);
|
||||||
|
@ -352,13 +383,6 @@ NTSTATUS RouterStartup(
|
||||||
InitializeListHead(&FIBListHead);
|
InitializeListHead(&FIBListHead);
|
||||||
TcpipInitializeSpinLock(&FIBLock);
|
TcpipInitializeSpinLock(&FIBLock);
|
||||||
|
|
||||||
#if 0
|
|
||||||
/* TEST: Create a test route */
|
|
||||||
/* Network is 10.0.0.0 */
|
|
||||||
/* Netmask is 255.0.0.0 */
|
|
||||||
/* Router is 10.0.0.1 */
|
|
||||||
RouterCreateRouteIPv4(0x0000000A, 0x000000FF, 0x0100000A, NTE?, 1);
|
|
||||||
#endif
|
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,9 @@ ULONG IPv4NToHl( ULONG Address );
|
||||||
|
|
||||||
UINT AddrCountPrefixBits( PIP_ADDRESS Netmask );
|
UINT AddrCountPrefixBits( PIP_ADDRESS Netmask );
|
||||||
|
|
||||||
|
VOID AddrWidenAddress( PIP_ADDRESS Network, PIP_ADDRESS Source,
|
||||||
|
PIP_ADDRESS Netmask );
|
||||||
|
|
||||||
#endif /* __ADDRESS_H */
|
#endif /* __ADDRESS_H */
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
|
@ -28,13 +28,12 @@ PFIB_ENTRY RouterAddRoute(
|
||||||
|
|
||||||
PNEIGHBOR_CACHE_ENTRY RouterGetRoute(PIP_ADDRESS Destination);
|
PNEIGHBOR_CACHE_ENTRY RouterGetRoute(PIP_ADDRESS Destination);
|
||||||
|
|
||||||
VOID RouterRemoveRoute(
|
NTSTATUS RouterRemoveRoute(PIP_ADDRESS Target, PIP_ADDRESS Router);
|
||||||
PFIB_ENTRY FIBE);
|
|
||||||
|
|
||||||
PFIB_ENTRY RouterCreateRoute(
|
PFIB_ENTRY RouterCreateRoute(
|
||||||
IP_ADDRESS NetworkAddress,
|
PIP_ADDRESS NetworkAddress,
|
||||||
IP_ADDRESS Netmask,
|
PIP_ADDRESS Netmask,
|
||||||
IP_ADDRESS RouterAddress,
|
PIP_ADDRESS RouterAddress,
|
||||||
PIP_INTERFACE Interface,
|
PIP_INTERFACE Interface,
|
||||||
UINT Metric);
|
UINT Metric);
|
||||||
|
|
||||||
|
|
|
@ -210,24 +210,18 @@ TDI_STATUS InfoTdiSetInformationEx
|
||||||
case INFO_TYPE_PROVIDER:
|
case INFO_TYPE_PROVIDER:
|
||||||
switch( ID->toi_id ) {
|
switch( ID->toi_id ) {
|
||||||
case IP_MIB_ROUTETABLE_ENTRY_ID:
|
case IP_MIB_ROUTETABLE_ENTRY_ID:
|
||||||
if( ID->toi_entity.tei_entity == CL_NL_ENTITY &&
|
return InfoNetworkLayerTdiSetEx
|
||||||
ID->toi_entity.tei_instance == TL_INSTANCE &&
|
( ID->toi_class,
|
||||||
BufferSize >= sizeof(IPROUTE_ENTRY) ) {
|
ID->toi_type,
|
||||||
/* Add route -- buffer is an IPRouteEntry */
|
ID->toi_id,
|
||||||
PIPROUTE_ENTRY ire = (PIPROUTE_ENTRY)Buffer;
|
NULL,
|
||||||
RouteFriendlyAddRoute( ire );
|
&ID->toi_entity,
|
||||||
} else {
|
Buffer,
|
||||||
return TDI_INVALID_PARAMETER;
|
BufferSize );
|
||||||
/* In my experience, we are being over
|
|
||||||
protective compared to windows */
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TDI_INVALID_PARAMETER;
|
return TDI_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,9 @@
|
||||||
|
|
||||||
#include "precomp.h"
|
#include "precomp.h"
|
||||||
|
|
||||||
|
#define IP_ROUTE_TYPE_ADD 3
|
||||||
|
#define IP_ROUTE_TYPE_DEL 2
|
||||||
|
|
||||||
TDI_STATUS InfoTdiQueryGetAddrTable( PNDIS_BUFFER Buffer,
|
TDI_STATUS InfoTdiQueryGetAddrTable( PNDIS_BUFFER Buffer,
|
||||||
PUINT BufferSize ) {
|
PUINT BufferSize ) {
|
||||||
|
|
||||||
|
@ -85,47 +88,42 @@ TDI_STATUS InfoTdiQueryGetRouteTable( PNDIS_BUFFER Buffer, PUINT BufferSize ) {
|
||||||
|
|
||||||
while( RtCurrent < RouteEntries + RtCount ) {
|
while( RtCurrent < RouteEntries + RtCount ) {
|
||||||
/* Copy Desitnation */
|
/* Copy Desitnation */
|
||||||
if( RCacheCur->Router ) {
|
RtlCopyMemory( &RtCurrent->Dest,
|
||||||
TI_DbgPrint(MAX_TRACE, ("%d: NA %08x NM %08x GW %08x MT %x\n",
|
&RCacheCur->NetworkAddress.Address,
|
||||||
RtCurrent - RouteEntries,
|
sizeof(RtCurrent->Dest) );
|
||||||
&RCacheCur->NetworkAddress.Address,
|
RtlCopyMemory( &RtCurrent->Mask,
|
||||||
&RCacheCur->Netmask.Address,
|
&RCacheCur->Netmask.Address,
|
||||||
RCacheCur->Router->Address.Address,
|
sizeof(RtCurrent->Mask) );
|
||||||
RCacheCur->Metric));
|
|
||||||
|
|
||||||
RtlCopyMemory( &RtCurrent->Dest,
|
if( RCacheCur->Router )
|
||||||
&RCacheCur->NetworkAddress.Address,
|
|
||||||
sizeof(RtCurrent->Dest) );
|
|
||||||
RtlCopyMemory( &RtCurrent->Mask,
|
|
||||||
&RCacheCur->Netmask.Address,
|
|
||||||
sizeof(RtCurrent->Mask) );
|
|
||||||
/* Currently, this address is stuffed into the pointer.
|
|
||||||
* That probably is not intended. */
|
|
||||||
RtlCopyMemory( &RtCurrent->Gw,
|
RtlCopyMemory( &RtCurrent->Gw,
|
||||||
&RCacheCur->Router->Address.Address,
|
&RCacheCur->Router->Address.Address,
|
||||||
sizeof(RtCurrent->Gw) );
|
sizeof(RtCurrent->Gw) );
|
||||||
RtCurrent->Metric1 = RCacheCur->Metric;
|
else
|
||||||
RtCurrent->Type = 2 /* PF_INET */;
|
RtlZeroMemory( &RtCurrent->Gw, sizeof(RtCurrent->Gw) );
|
||||||
|
|
||||||
TcpipAcquireSpinLock(&EntityListLock, &OldIrql);
|
RtCurrent->Metric1 = RCacheCur->Metric;
|
||||||
for( RtCurrent->Index = EntityCount;
|
RtCurrent->Type = TDI_ADDRESS_TYPE_IP;
|
||||||
RtCurrent->Index > 0 &&
|
|
||||||
RCacheCur->Router->Interface !=
|
TI_DbgPrint
|
||||||
EntityList[RtCurrent->Index - 1].context;
|
(MAX_TRACE,
|
||||||
RtCurrent->Index-- );
|
("%d: NA %08x NM %08x GW %08x MT %x\n",
|
||||||
|
RtCurrent - RouteEntries,
|
||||||
|
RtCurrent->Dest,
|
||||||
|
RtCurrent->Mask,
|
||||||
|
RtCurrent->Gw,
|
||||||
|
RtCurrent->Metric1 ));
|
||||||
|
|
||||||
|
TcpipAcquireSpinLock(&EntityListLock, &OldIrql);
|
||||||
|
for( RtCurrent->Index = EntityCount;
|
||||||
|
RtCurrent->Index > 0 &&
|
||||||
|
RCacheCur->Router->Interface !=
|
||||||
|
EntityList[RtCurrent->Index - 1].context;
|
||||||
|
RtCurrent->Index-- );
|
||||||
|
|
||||||
|
RtCurrent->Index = EntityList[RtCurrent->Index].tei_instance;
|
||||||
|
TcpipReleaseSpinLock(&EntityListLock, OldIrql);
|
||||||
|
|
||||||
RtCurrent->Index = EntityList[RtCurrent->Index].tei_instance;
|
|
||||||
TcpipReleaseSpinLock(&EntityListLock, OldIrql);
|
|
||||||
} else {
|
|
||||||
TI_DbgPrint(MAX_TRACE, ("%d: BAD: NA %08x NM %08x GW %08x MT %d\n",
|
|
||||||
RtCurrent - RouteEntries,
|
|
||||||
RCacheCur->NetworkAddress,
|
|
||||||
RCacheCur->Netmask,
|
|
||||||
RCacheCur->Router,
|
|
||||||
RCacheCur->Router ?
|
|
||||||
&RCacheCur->Router->Address : 0,
|
|
||||||
RCacheCur->Metric));
|
|
||||||
}
|
|
||||||
RtCurrent++; RCacheCur++;
|
RtCurrent++; RCacheCur++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +141,7 @@ TDI_STATUS InfoTdiQueryGetIPSnmpInfo( PNDIS_BUFFER Buffer,
|
||||||
PUINT BufferSize ) {
|
PUINT BufferSize ) {
|
||||||
IPSNMP_INFO SnmpInfo;
|
IPSNMP_INFO SnmpInfo;
|
||||||
UINT IfCount = CountInterfaces();
|
UINT IfCount = CountInterfaces();
|
||||||
UINT RouteCount = CountRouteNodes( NULL );
|
UINT RouteCount = CountFIBs( NULL );
|
||||||
TDI_STATUS Status = TDI_INVALID_REQUEST;
|
TDI_STATUS Status = TDI_INVALID_REQUEST;
|
||||||
|
|
||||||
TI_DbgPrint(MAX_TRACE, ("Called.\n"));
|
TI_DbgPrint(MAX_TRACE, ("Called.\n"));
|
||||||
|
@ -214,5 +212,43 @@ TDI_STATUS InfoNetworkLayerTdiSetEx( UINT InfoClass,
|
||||||
TDIEntityID *id,
|
TDIEntityID *id,
|
||||||
PCHAR Buffer,
|
PCHAR Buffer,
|
||||||
UINT BufferSize ) {
|
UINT BufferSize ) {
|
||||||
return STATUS_UNSUCCESSFUL;
|
NTSTATUS Status = TDI_INVALID_REQUEST;
|
||||||
|
IP_ADDRESS Address;
|
||||||
|
IP_ADDRESS Netmask;
|
||||||
|
IP_ADDRESS Router;
|
||||||
|
PNEIGHBOR_CACHE_ENTRY NCE;
|
||||||
|
|
||||||
|
TI_DbgPrint(MID_TRACE,("Called\n"));
|
||||||
|
|
||||||
|
OskitDumpBuffer( Buffer, BufferSize );
|
||||||
|
|
||||||
|
if( InfoClass == INFO_CLASS_PROTOCOL &&
|
||||||
|
InfoType == INFO_TYPE_PROVIDER &&
|
||||||
|
InfoId == IP_MIB_ROUTETABLE_ENTRY_ID &&
|
||||||
|
id->tei_entity == CL_NL_ENTITY ) { /* Add or delete a route */
|
||||||
|
PIPROUTE_ENTRY Route = (PIPROUTE_ENTRY)Buffer;
|
||||||
|
AddrInitIPv4( &Address, Route->Dest );
|
||||||
|
AddrInitIPv4( &Netmask, Route->Mask );
|
||||||
|
AddrInitIPv4( &Router, Route->Gw );
|
||||||
|
|
||||||
|
if( Route->Type == IP_ROUTE_TYPE_ADD ) { /* Add the route */
|
||||||
|
TI_DbgPrint(MID_TRACE,("Adding route (%s)\n", A2S(&Address)));
|
||||||
|
/* Find the existing route this belongs to */
|
||||||
|
NCE = RouterGetRoute( &Router );
|
||||||
|
/* Really add the route */
|
||||||
|
if( NCE &&
|
||||||
|
RouterCreateRoute( &Address, &Netmask, &Router,
|
||||||
|
NCE->Interface, Route->Metric1 ) )
|
||||||
|
Status = STATUS_SUCCESS;
|
||||||
|
else
|
||||||
|
Status = STATUS_UNSUCCESSFUL;
|
||||||
|
} else if( Route->Type == IP_ROUTE_TYPE_DEL ) {
|
||||||
|
TI_DbgPrint(MID_TRACE,("Removing route (%s)\n", A2S(&Address)));
|
||||||
|
Status = RouterRemoveRoute( &Address, &Router );
|
||||||
|
} else Status = TDI_INVALID_REQUEST;
|
||||||
|
}
|
||||||
|
|
||||||
|
TI_DbgPrint(MID_TRACE,("Returning %x\n", Status));
|
||||||
|
|
||||||
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue