Author: cgutman
Date: Fri Oct 9 04:40:38 2009
New Revision: 43338
URL:
http://svn.reactos.org/svn/reactos?rev=43338&view=rev
Log:
- Rewrite IOCTL_TCP_QUERY_INFORMATION_EX/IOCTL_TCP_SET_INFORMATION_EX handling
- Remove duplicate defines for the same IOCTL
- Remove unneeded code
- Fix a completely wrong implementation of ENTITY_TYPE_ID
- Perform parameter checking
- Remove several hacks in iphlpapi that worked around bugs in the previous
implementation
- We now support retrieving interface-specific routing tables and ARP tables
Modified:
trunk/reactos/dll/win32/iphlpapi/ifenum_reactos.c
trunk/reactos/dll/win32/iphlpapi/iphlpapi_private.h
trunk/reactos/dll/win32/iphlpapi/ipstats_reactos.c
trunk/reactos/dll/win32/iphlpapi/route_reactos.c
trunk/reactos/drivers/network/tcpip/include/info.h
trunk/reactos/drivers/network/tcpip/include/tcpip.h
trunk/reactos/drivers/network/tcpip/tcpip/iinfo.c
trunk/reactos/drivers/network/tcpip/tcpip/info.c
trunk/reactos/drivers/network/tcpip/tcpip/main.c
trunk/reactos/drivers/network/tcpip/tcpip/ninfo.c
Modified: trunk/reactos/dll/win32/iphlpapi/ifenum_reactos.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/iphlpapi/ifenum_…
==============================================================================
--- trunk/reactos/dll/win32/iphlpapi/ifenum_reactos.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/iphlpapi/ifenum_reactos.c [iso-8859-1] Fri Oct 9 04:40:38
2009
@@ -323,36 +323,8 @@
loop_maybe,
&entryInfo );
- return NT_SUCCESS(status) && (!entryInfo.ent.if_type ||
- entryInfo.ent.if_type == IFENT_SOFTWARE_LOOPBACK);
-}
-
-NTSTATUS tdiGetEntityType( HANDLE tcpFile, TDIEntityID *ent, PULONG type ) {
- TCP_REQUEST_QUERY_INFORMATION_EX req = TCP_REQUEST_QUERY_INFORMATION_INIT;
- NTSTATUS status = STATUS_SUCCESS;
- DWORD returnSize;
-
- TRACE("TdiGetEntityType(tcpFile %x,entityId %x)\n",
- (DWORD)tcpFile, ent->tei_instance);
-
- req.ID.toi_class = INFO_CLASS_GENERIC;
- req.ID.toi_type = INFO_TYPE_PROVIDER;
- req.ID.toi_id = ENTITY_TYPE_ID;
- req.ID.toi_entity.tei_entity = ent->tei_entity;
- req.ID.toi_entity.tei_instance = ent->tei_instance;
-
- status = DeviceIoControl( tcpFile,
- IOCTL_TCP_QUERY_INFORMATION_EX,
- &req,
- sizeof(req),
- type,
- sizeof(*type),
- &returnSize,
- NULL );
-
- TRACE("TdiGetEntityType() => %08x %08x\n", *type, status);
-
- return (status ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL);
+ return NT_SUCCESS(status) &&
+ (entryInfo.ent.if_type == IFENT_SOFTWARE_LOOPBACK);
}
BOOL hasArp( HANDLE tcpFile, TDIEntityID *arp_maybe ) {
@@ -374,9 +346,9 @@
sizeof(type),
&returnSize,
NULL );
-
if( !NT_SUCCESS(status) ) return FALSE;
- return type == AT_ENTITY;
+
+ return (type & AT_ARP);
}
static NTSTATUS getInterfaceInfoSet( HANDLE tcpFile,
@@ -386,7 +358,6 @@
TDIEntityID *entIDSet = 0;
NTSTATUS status = tdiGetEntityIDSet( tcpFile, &entIDSet, &numEntities );
IFInfo *infoSetInt = 0;
- BOOL interfaceInfoComplete;
int curInterf = 0, i;
if (!NT_SUCCESS(status)) {
@@ -412,8 +383,7 @@
TDIEntityID ip_ent;
int j;
- interfaceInfoComplete = FALSE;
- status = getNthIpEntity( tcpFile, 0, &ip_ent );
+ status = getNthIpEntity( tcpFile, curInterf, &ip_ent );
if( NT_SUCCESS(status) )
status = tdiGetIpAddrsForIpEntity
( tcpFile, &ip_ent, &addrs, &numAddrs );
Modified: trunk/reactos/dll/win32/iphlpapi/iphlpapi_private.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/iphlpapi/iphlpap…
==============================================================================
--- trunk/reactos/dll/win32/iphlpapi/iphlpapi_private.h [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/iphlpapi/iphlpapi_private.h [iso-8859-1] Fri Oct 9 04:40:38
2009
@@ -59,8 +59,6 @@
#define TCP_REQUEST_QUERY_INFORMATION_INIT { { { 0 } } }
#define TCP_REQUEST_SET_INFORMATION_INIT { { 0 } }
-
-#define IP_MIB_ROUTETABLE_ENTRY_ID 0x101
// As in the mib from RFC 1213
Modified: trunk/reactos/dll/win32/iphlpapi/ipstats_reactos.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/iphlpapi/ipstats…
==============================================================================
--- trunk/reactos/dll/win32/iphlpapi/ipstats_reactos.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/iphlpapi/ipstats_reactos.c [iso-8859-1] Fri Oct 9 04:40:38
2009
@@ -62,30 +62,8 @@
#endif
BOOL isIpEntity( HANDLE tcpFile, TDIEntityID *ent ) {
- DWORD entityType, returnedLen;
- NTSTATUS status;
- TCP_REQUEST_QUERY_INFORMATION_EX req;
-
- req.ID.toi_class = INFO_CLASS_GENERIC;
- req.ID.toi_type = INFO_TYPE_PROVIDER;
- req.ID.toi_id = ENTITY_TYPE_ID;
- req.ID.toi_entity = *ent;
-
- status =
- DeviceIoControl
- ( tcpFile,
- IOCTL_TCP_QUERY_INFORMATION_EX,
- &req,
- sizeof(req),
- &entityType,
- sizeof(entityType),
- &returnedLen,
- NULL );
-
- TRACE("Ent: %04x:d -> %04x\n",
- ent->tei_entity, ent->tei_instance, entityType );
-
- return NT_SUCCESS(status) && entityType == CL_NL_IP;
+ return (ent->tei_entity == CL_NL_ENTITY ||
+ ent->tei_entity == CO_NL_ENTITY);
}
NTSTATUS getNthIpEntity( HANDLE tcpFile, DWORD index, TDIEntityID *ent ) {
@@ -182,9 +160,9 @@
status = tdiGetSetOfThings( tcpFile,
INFO_CLASS_PROTOCOL,
INFO_TYPE_PROVIDER,
- IP_MIB_ROUTETABLE_ENTRY_ID,
- ent->tei_entity,
- 0,
+ IP_MIB_ARPTABLE_ENTRY_ID,
+ CL_NL_ENTITY,
+ ent->tei_instance,
0,
sizeof(IPRouteEntry),
(PVOID *)routes,
@@ -204,8 +182,8 @@
INFO_CLASS_PROTOCOL,
INFO_TYPE_PROVIDER,
IP_MIB_ADDRTABLE_ENTRY_ID,
- ent->tei_entity,
- 0,
+ CL_NL_ENTITY,
+ ent->tei_instance,
0,
sizeof(IPAddrEntry),
(PVOID *)addrs,
Modified: trunk/reactos/dll/win32/iphlpapi/route_reactos.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/iphlpapi/route_r…
==============================================================================
--- trunk/reactos/dll/win32/iphlpapi/route_reactos.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/iphlpapi/route_reactos.c [iso-8859-1] Fri Oct 9 04:40:38
2009
@@ -69,8 +69,9 @@
if( NT_SUCCESS(status) ) {
req.Req.ID.toi_class = INFO_CLASS_PROTOCOL;
req.Req.ID.toi_type = INFO_TYPE_PROVIDER;
- req.Req.ID.toi_id = IP_MIB_ROUTETABLE_ENTRY_ID;
- req.Req.ID.toi_entity = id;
+ req.Req.ID.toi_id = IP_MIB_ARPTABLE_ENTRY_ID;
+ req.Req.ID.toi_entity.tei_instance = id.tei_instance;
+ req.Req.ID.toi_entity.tei_instance = CL_NL_ENTITY;
req.Req.BufferSize = sizeof(*rte);
rte =
(IPRouteEntry *)&req.Req.Buffer[0];
@@ -133,8 +134,9 @@
if( NT_SUCCESS(status) ) {
req.Req.ID.toi_class = INFO_CLASS_PROTOCOL;
req.Req.ID.toi_type = INFO_TYPE_PROVIDER;
- req.Req.ID.toi_id = IP_MIB_ROUTETABLE_ENTRY_ID;
- req.Req.ID.toi_entity = id;
+ req.Req.ID.toi_id = IP_MIB_ARPTABLE_ENTRY_ID;
+ req.Req.ID.toi_entity.tei_instance = id.tei_instance;
+ req.Req.ID.toi_entity.tei_entity = CL_NL_ENTITY;
req.Req.BufferSize = sizeof(*rte);
rte =
(IPRouteEntry *)&req.Req.Buffer[0];
Modified: trunk/reactos/drivers/network/tcpip/include/info.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/tcpip/incl…
==============================================================================
--- trunk/reactos/drivers/network/tcpip/include/info.h [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/tcpip/include/info.h [iso-8859-1] Fri Oct 9 04:40:38
2009
@@ -6,6 +6,8 @@
*/
#ifndef __INFO_H
#define __INFO_H
+
+#include <tcpioctl.h>
#define MAX_PHYSADDR_LEN 8
#define MAX_IFDESCR_LEN 256
@@ -100,23 +102,6 @@
ULONG DescrLen;
} IFENTRY, *PIFENTRY;
-#define IP_MIB_STATS_ID 1
-#define IF_MIB_STATS_ID 1
-
-#ifndef IP_MIB_ROUTETABLE_ENTRY_ID
-#define IP_MIB_ROUTETABLE_ENTRY_ID 0x101
-#endif
-#ifndef IP_MIB_ADDRTABLE_ENTRY_ID
-#define IP_MIB_ADDRTABLE_ENTRY_ID 0x102
-#endif
-#ifndef IP_MIB_ARPTABLE_ENTRY_ID
-#define IP_MIB_ARPTABLE_ENTRY_ID 0x101
-#endif
-#ifndef MAX_PHYSADDR_SIZE
-#define MAX_PHYSADDR_SIZE 8
-#endif
-
-
/* Only UDP is supported */
#define TDI_SERVICE_FLAGS (TDI_SERVICE_CONNECTIONLESS_MODE | \
TDI_SERVICE_BROADCAST_SUPPORTED)
@@ -157,54 +142,28 @@
PVOID Buffer,
UINT BufferSize);
-/* Network layer info functions */
-TDI_STATUS InfoNetworkLayerTdiQueryEx( UINT InfoClass,
- UINT InfoType,
- UINT InfoId,
- PVOID Context,
- TDIEntityID *id,
+TDI_STATUS InfoTdiQueryGetAddrTable(TDIEntityID ID,
+ PNDIS_BUFFER Buffer,
+ PUINT BufferSize);
+
+TDI_STATUS InfoTdiQueryGetInterfaceMIB(TDIEntityID ID,
+ PIP_INTERFACE Interface,
PNDIS_BUFFER Buffer,
- PUINT BufferSize );
+ PUINT BufferSize);
-TDI_STATUS InfoNetworkLayerTdiSetEx( UINT InfoClass,
- UINT InfoType,
- UINT InfoId,
- PVOID Context,
- TDIEntityID *id,
- PCHAR Buffer,
- UINT BufferSize );
+TDI_STATUS InfoTdiQueryGetIPSnmpInfo( TDIEntityID ID,
+ PNDIS_BUFFER Buffer,
+ PUINT BufferSize );
-TDI_STATUS InfoTransportLayerTdiQueryEx( UINT InfoClass,
- UINT InfoType,
- UINT InfoId,
- PVOID Context,
- TDIEntityID *id,
- PNDIS_BUFFER Buffer,
- PUINT BufferSize );
+TDI_STATUS InfoTdiQueryGetRouteTable( PNDIS_BUFFER Buffer,
+ PUINT BufferSize );
-TDI_STATUS InfoTransportLayerTdiSetEx( UINT InfoClass,
- UINT InfoType,
- UINT InfoId,
- PVOID Context,
- TDIEntityID *id,
- PCHAR Buffer,
- UINT BufferSize );
+TDI_STATUS InfoTdiSetRoute(PIPROUTE_ENTRY Route);
-TDI_STATUS InfoInterfaceTdiQueryEx( UINT InfoClass,
- UINT InfoType,
- UINT InfoId,
- PVOID Context,
- TDIEntityID *id,
- PNDIS_BUFFER Buffer,
- PUINT BufferSize );
-
-TDI_STATUS InfoInterfaceTdiSetEx( UINT InfoClass,
- UINT InfoType,
- UINT InfoId,
- PVOID Context,
- TDIEntityID *id,
- PCHAR Buffer,
- UINT BufferSize );
+TDI_STATUS InfoTdiQueryGetArptableMIB(TDIEntityID ID,
+ PIP_INTERFACE Interface,
+ PNDIS_BUFFER Buffer,
+ PUINT BufferSize);
/* Insert and remove interface entities */
VOID InsertTDIInterfaceEntity( PIP_INTERFACE Interface );
Modified: trunk/reactos/drivers/network/tcpip/include/tcpip.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/tcpip/incl…
==============================================================================
--- trunk/reactos/drivers/network/tcpip/include/tcpip.h [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/tcpip/include/tcpip.h [iso-8859-1] Fri Oct 9 04:40:38
2009
@@ -149,29 +149,12 @@
char sa_data[14];
};
-typedef TDI_STATUS (*InfoRequest_f)( UINT InfoClass,
- UINT InfoType,
- UINT InfoId,
- PVOID Context,
- TDIEntityID *id,
- PNDIS_BUFFER Buffer,
- PUINT BufferSize );
-
-typedef TDI_STATUS (*InfoSet_f)( UINT InfoClass,
- UINT InfoType,
- UINT InfoId,
- PVOID Context,
- TDIEntityID *id,
- PCHAR Buffer,
- UINT BufferSize );
-
/* Sufficient information to manage the entity list */
typedef struct {
UINT tei_entity;
UINT tei_instance;
PVOID context;
- InfoRequest_f info_req;
- InfoSet_f info_set;
+ UINT flags;
} TDIEntityInfo;
#ifndef htons
Modified: trunk/reactos/drivers/network/tcpip/tcpip/iinfo.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/tcpip/tcpi…
==============================================================================
--- trunk/reactos/drivers/network/tcpip/tcpip/iinfo.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/tcpip/tcpip/iinfo.c [iso-8859-1] Fri Oct 9 04:40:38
2009
@@ -10,21 +10,26 @@
#include "precomp.h"
-TDI_STATUS InfoTdiQueryGetInterfaceMIB(TDIEntityID *ID,
+TDI_STATUS InfoTdiQueryGetInterfaceMIB(TDIEntityID ID,
PIP_INTERFACE Interface,
PNDIS_BUFFER Buffer,
PUINT BufferSize) {
TDI_STATUS Status = TDI_INVALID_REQUEST;
PIFENTRY OutData;
- PLAN_ADAPTER IF = (PLAN_ADAPTER)Interface->Context;
+ PLAN_ADAPTER IF;
PCHAR IFDescr;
ULONG Size;
UINT DescrLenMax = MAX_IFDESCR_LEN - 1;
NDIS_STATUS NdisStatus;
+ if (!Interface)
+ return TDI_INVALID_PARAMETER;
+
+ IF = (PLAN_ADAPTER)Interface->Context;
+
TI_DbgPrint(DEBUG_INFO,
("Getting IFEntry MIB (IF %08x LA %08x) (%04x:%d)\n",
- Interface, IF, ID->tei_entity, ID->tei_instance));
+ Interface, IF, ID.tei_entity, ID.tei_instance));
OutData =
(PIFENTRY)exAllocatePool( NonPagedPool,
@@ -91,7 +96,7 @@
Size = IFDescr - (PCHAR)OutData + 1;
TI_DbgPrint(DEBUG_INFO, ("Finished IFEntry MIB (%04x:%d) size %d\n",
- ID->tei_entity, ID->tei_instance, Size));
+ ID.tei_entity, ID.tei_instance, Size));
Status = InfoCopyOut( (PCHAR)OutData, Size, Buffer, BufferSize );
exFreePool( OutData );
@@ -101,7 +106,7 @@
return Status;
}
-TDI_STATUS InfoTdiQueryGetArptableMIB(TDIEntityID *ID,
+TDI_STATUS InfoTdiQueryGetArptableMIB(TDIEntityID ID,
PIP_INTERFACE Interface,
PNDIS_BUFFER Buffer,
PUINT BufferSize) {
@@ -122,58 +127,106 @@
return Status;
}
-TDI_STATUS InfoTdiQueryGetArpCapability(TDIEntityID *ID,
- PIP_INTERFACE Interface,
- PNDIS_BUFFER Buffer,
- PUINT BufferSize) {
- NTSTATUS Status;
- ULONG Capability = 0x280;
-
- TI_DbgPrint(MID_TRACE,("Copying out %d bytes (AT_ENTITY capability)\n",
- sizeof(Capability)));
- Status = InfoCopyOut
- ( (PVOID)&Capability, sizeof(Capability), Buffer, BufferSize );
-
- return Status;
-}
-
-TDI_STATUS InfoInterfaceTdiQueryEx( UINT InfoClass,
- UINT InfoType,
- UINT InfoId,
- PVOID Context,
- TDIEntityID *id,
- PNDIS_BUFFER Buffer,
- PUINT BufferSize ) {
- if( InfoClass == INFO_CLASS_GENERIC &&
- InfoType == INFO_TYPE_PROVIDER &&
- InfoId == ENTITY_TYPE_ID &&
- id->tei_entity == AT_ENTITY ) {
- return InfoTdiQueryGetArpCapability( id, Context, Buffer, BufferSize );
- } else if( InfoClass == INFO_CLASS_PROTOCOL &&
- InfoType == INFO_TYPE_PROVIDER &&
- InfoId == IF_MIB_STATS_ID ) {
- return InfoTdiQueryGetInterfaceMIB( id, Context, Buffer, BufferSize );
- } else if( InfoClass == INFO_CLASS_GENERIC &&
- InfoType == INFO_TYPE_PROVIDER &&
- InfoId == ENTITY_TYPE_ID ) {
- ULONG Temp = IF_MIB;
- return InfoCopyOut( (PCHAR)&Temp, sizeof(Temp), Buffer, BufferSize );
- } else if( InfoClass == INFO_CLASS_PROTOCOL &&
- InfoType == INFO_TYPE_PROVIDER &&
- InfoId == IP_MIB_ARPTABLE_ENTRY_ID ) {
- return InfoTdiQueryGetArptableMIB( id, Context, Buffer, BufferSize );
- } else
- return TDI_INVALID_REQUEST;
-}
-
-TDI_STATUS InfoInterfaceTdiSetEx( UINT InfoClass,
- UINT InfoType,
- UINT InfoId,
- PVOID Context,
- TDIEntityID *id,
- PCHAR Buffer,
- UINT BufferSize ) {
- TI_DbgPrint(DEBUG_INFO, ("Got Request: Class %x Type %x Id %x, EntityID
%x:%x\n",
- InfoClass, InfoId, id->tei_entity, id->tei_instance));
- return TDI_INVALID_REQUEST;
-}
+VOID InsertTDIInterfaceEntity( PIP_INTERFACE Interface ) {
+ KIRQL OldIrql;
+ UINT IFCount = 0, CLNLCount = 0, CLTLCount = 0, COTLCount = 0, ATCount = 0, ERCount =
0, i;
+
+ TI_DbgPrint(DEBUG_INFO,
+ ("Inserting interface %08x (%d entities already)\n",
+ Interface, EntityCount));
+
+ TcpipAcquireSpinLock( &EntityListLock, &OldIrql );
+
+ /* Count IP Entities */
+ for( i = 0; i < EntityCount; i++ )
+ switch( EntityList[i].tei_entity )
+ {
+ case IF_ENTITY:
+ IFCount++;
+ break;
+
+ case CL_NL_ENTITY:
+ CLNLCount++;
+ break;
+
+ case CL_TL_ENTITY:
+ CLTLCount++;
+ break;
+
+ case CO_TL_ENTITY:
+ COTLCount++;
+ break;
+
+ case AT_ENTITY:
+ ATCount++;
+ break;
+
+ case ER_ENTITY:
+ ERCount++;
+ break;
+
+ default:
+ break;
+ }
+
+ EntityList[EntityCount].tei_entity = IF_ENTITY;
+ EntityList[EntityCount].tei_instance = IFCount;
+ EntityList[EntityCount].context = Interface;
+ EntityList[EntityCount].flags = IF_MIB;
+ EntityCount++;
+ EntityList[EntityCount].tei_entity = CL_NL_ENTITY;
+ EntityList[EntityCount].tei_instance = CLNLCount;
+ EntityList[EntityCount].context = Interface;
+ EntityList[EntityCount].flags = CL_NL_IP;
+ EntityCount++;
+ EntityList[EntityCount].tei_entity = CL_TL_ENTITY;
+ EntityList[EntityCount].tei_instance = CLTLCount;
+ EntityList[EntityCount].context = Interface;
+ EntityList[EntityCount].flags = CL_TL_UDP;
+ EntityCount++;
+ EntityList[EntityCount].tei_entity = CO_TL_ENTITY;
+ EntityList[EntityCount].tei_instance = COTLCount;
+ EntityList[EntityCount].context = Interface;
+ EntityList[EntityCount].flags = CO_TL_TCP;
+ EntityCount++;
+ EntityList[EntityCount].tei_entity = ER_ENTITY;
+ EntityList[EntityCount].tei_instance = ERCount;
+ EntityList[EntityCount].context = Interface;
+ EntityList[EntityCount].flags = ER_ICMP;
+ EntityCount++;
+ EntityList[EntityCount].tei_entity = AT_ENTITY;
+ EntityList[EntityCount].tei_instance = ATCount;
+ EntityList[EntityCount].context = Interface;
+ EntityList[EntityCount].flags = AT_ARP;
+ EntityCount++;
+
+ TcpipReleaseSpinLock( &EntityListLock, OldIrql );
+}
+
+VOID RemoveTDIInterfaceEntity( PIP_INTERFACE Interface ) {
+ KIRQL OldIrql;
+ UINT i;
+
+ TI_DbgPrint(DEBUG_INFO,("Removing TDI entry 0x%x\n", Interface));
+
+ TcpipAcquireSpinLock( &EntityListLock, &OldIrql );
+
+ /* Remove entities that have this interface as context
+ * In the future, this might include AT_ENTITY types, too
+ */
+ for( i = 0; i < EntityCount; i++ ) {
+ TI_DbgPrint(DEBUG_INFO,("--> examining TDI entry 0x%x\n",
EntityList[i].context));
+ if( EntityList[i].context == Interface ) {
+ if( i != EntityCount-1 ) {
+ memcpy( &EntityList[i],
+ &EntityList[--EntityCount],
+ sizeof(EntityList[i]) );
+ } else {
+ EntityCount--;
+ }
+ }
+ }
+
+ TcpipReleaseSpinLock( &EntityListLock, OldIrql );
+}
+
Modified: trunk/reactos/drivers/network/tcpip/tcpip/info.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/tcpip/tcpi…
==============================================================================
--- trunk/reactos/drivers/network/tcpip/tcpip/info.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/tcpip/tcpip/info.c [iso-8859-1] Fri Oct 9 04:40:38
2009
@@ -12,6 +12,35 @@
#include <debug.h>
#include <route.h>
+PVOID GetContext(TDIEntityID ID)
+{
+ UINT i;
+ KIRQL OldIrql;
+ PVOID Context;
+
+ TcpipAcquireSpinLock(&EntityListLock, &OldIrql);
+
+ for (i = 0; i < EntityCount; i++)
+ {
+ if (EntityList[i].tei_entity == ID.tei_entity &&
+ EntityList[i].tei_instance == ID.tei_instance)
+ break;
+ }
+
+ if (i == EntityCount)
+ {
+ TcpipReleaseSpinLock(&EntityListLock, OldIrql);
+ DbgPrint("WARNING: Unable to get context for %d %d\n", ID.tei_entity,
ID.tei_instance);
+ return NULL;
+ }
+
+ Context = EntityList[i].context;
+
+ TcpipReleaseSpinLock(&EntityListLock, OldIrql);
+
+ return Context;
+}
+
TDI_STATUS InfoCopyOut( PCHAR DataOut, UINT SizeOut,
PNDIS_BUFFER ClientBuf, PUINT ClientBufSize ) {
UINT RememberedCBSize = *ClientBufSize;
@@ -27,60 +56,38 @@
}
}
-VOID InsertTDIInterfaceEntity( PIP_INTERFACE Interface ) {
+TDI_STATUS InfoTdiQueryEntityType(TDIEntityID ID,
+ PNDIS_BUFFER Buffer,
+ PUINT BufferSize)
+{
KIRQL OldIrql;
- UINT Count = 0, i;
-
- TI_DbgPrint(DEBUG_INFO,
- ("Inserting interface %08x (%d entities already)\n",
- Interface, EntityCount));
-
- TcpipAcquireSpinLock( &EntityListLock, &OldIrql );
-
- /* Count IP Entities */
- for( i = 0; i < EntityCount; i++ )
- if( EntityList[i].tei_entity == IF_ENTITY ) {
- Count++;
- TI_DbgPrint(DEBUG_INFO, ("Entity %d is an IF. Found %d\n",
- i, Count));
- }
-
- EntityList[EntityCount].tei_entity = IF_ENTITY;
- EntityList[EntityCount].tei_instance = Count;
- EntityList[EntityCount].context = Interface;
- EntityList[EntityCount].info_req = InfoInterfaceTdiQueryEx;
- EntityList[EntityCount].info_set = InfoInterfaceTdiSetEx;
-
- EntityCount++;
-
- TcpipReleaseSpinLock( &EntityListLock, OldIrql );
-}
-
-VOID RemoveTDIInterfaceEntity( PIP_INTERFACE Interface ) {
- KIRQL OldIrql;
- UINT i;
-
- TI_DbgPrint(DEBUG_INFO,("Removing TDI entry 0x%x\n", Interface));
-
- TcpipAcquireSpinLock( &EntityListLock, &OldIrql );
-
- /* Remove entities that have this interface as context
- * In the future, this might include AT_ENTITY types, too
- */
- for( i = 0; i < EntityCount; i++ ) {
- TI_DbgPrint(DEBUG_INFO,("--> examining TDI entry 0x%x\n",
EntityList[i].context));
- if( EntityList[i].context == Interface ) {
- if( i != EntityCount-1 ) {
- memcpy( &EntityList[i],
- &EntityList[--EntityCount],
- sizeof(EntityList[i]) );
- } else {
- EntityCount--;
- }
- }
- }
-
- TcpipReleaseSpinLock( &EntityListLock, OldIrql );
+ UINT i, Flags = 0;
+
+ TcpipAcquireSpinLock(&EntityListLock, &OldIrql);
+
+ for (i = 0; i < EntityCount; i++)
+ {
+ if (EntityList[i].tei_entity == ID.tei_entity &&
+ EntityList[i].tei_instance == ID.tei_instance)
+ break;
+ }
+
+ if (i == EntityCount)
+ {
+ TcpipReleaseSpinLock(&EntityListLock, OldIrql);
+ return TDI_INVALID_PARAMETER;
+ }
+
+ Flags = EntityList[i].flags;
+
+ InfoCopyOut((PCHAR)&Flags,
+ sizeof(ULONG),
+ Buffer,
+ BufferSize);
+
+ TcpipReleaseSpinLock(&EntityListLock, OldIrql);
+
+ return TDI_SUCCESS;
}
TDI_STATUS InfoTdiQueryListEntities(PNDIS_BUFFER Buffer,
@@ -139,12 +146,7 @@
* Status of operation
*/
{
- KIRQL OldIrql;
- UINT i;
- PVOID context = NULL;
- NTSTATUS Status = TDI_INVALID_PARAMETER;
- BOOLEAN FoundEntity = FALSE;
- InfoRequest_f InfoRequest = NULL;
+ PVOID EntityListContext;
TI_DbgPrint(DEBUG_INFO,
("InfoEx Req: %x %x %x!%04x:%d\n",
@@ -154,79 +156,83 @@
ID->toi_entity.tei_entity,
ID->toi_entity.tei_instance));
- /* Check wether it is a query for a list of entities */
- if (ID->toi_entity.tei_entity == GENERIC_ENTITY)
- {
- if ((ID->toi_class != INFO_CLASS_GENERIC) ||
- (ID->toi_type != INFO_TYPE_PROVIDER) ||
- (ID->toi_id != ENTITY_LIST_ID)) {
- TI_DbgPrint(DEBUG_INFO,("Invalid parameter\n"));
- Status = TDI_INVALID_PARAMETER;
- } else
- Status = InfoTdiQueryListEntities(Buffer, BufferSize);
- } else if (ID->toi_entity.tei_entity == AT_ENTITY) {
- TcpipAcquireSpinLock( &EntityListLock, &OldIrql );
-
- for( i = 0; i < EntityCount; i++ ) {
- if( EntityList[i].tei_entity == IF_ENTITY &&
- EntityList[i].tei_instance == ID->toi_entity.tei_instance ) {
- InfoRequest = EntityList[i].info_req;
- context = EntityList[i].context;
- FoundEntity = TRUE;
- break;
- }
- }
-
- TcpipReleaseSpinLock( &EntityListLock, OldIrql );
-
- if( FoundEntity ) {
- TI_DbgPrint(DEBUG_INFO,
- ("Calling AT Entity %d (%04x:%d) InfoEx (%x,%x,%x)\n",
- i, ID->toi_entity.tei_entity,
- ID->toi_entity.tei_instance,
- ID->toi_class, ID->toi_type, ID->toi_id));
- Status = InfoRequest( ID->toi_class,
- ID->toi_type,
- ID->toi_id,
- context,
- &ID->toi_entity,
- Buffer,
- BufferSize );
- }
- } else {
- TcpipAcquireSpinLock( &EntityListLock, &OldIrql );
-
- for( i = 0; i < EntityCount; i++ ) {
- if( EntityList[i].tei_entity == ID->toi_entity.tei_entity &&
- EntityList[i].tei_instance == ID->toi_entity.tei_instance ) {
- InfoRequest = EntityList[i].info_req;
- context = EntityList[i].context;
- FoundEntity = TRUE;
- break;
- }
- }
-
- TcpipReleaseSpinLock( &EntityListLock, OldIrql );
-
- if( FoundEntity ) {
- TI_DbgPrint(DEBUG_INFO,
- ("Calling Entity %d (%04x:%d) InfoEx (%x,%x,%x)\n",
- i, ID->toi_entity.tei_entity,
- ID->toi_entity.tei_instance,
- ID->toi_class, ID->toi_type, ID->toi_id));
- Status = InfoRequest( ID->toi_class,
- ID->toi_type,
- ID->toi_id,
- context,
- &ID->toi_entity,
- Buffer,
- BufferSize );
- }
- }
-
- TI_DbgPrint(DEBUG_INFO,("Status: %08x\n", Status));
-
- return Status;
+ switch (ID->toi_class)
+ {
+ case INFO_CLASS_GENERIC:
+ switch (ID->toi_id)
+ {
+ case ENTITY_LIST_ID:
+ if (ID->toi_type != INFO_TYPE_PROVIDER)
+ return TDI_INVALID_PARAMETER;
+
+ return InfoTdiQueryListEntities(Buffer, BufferSize);
+
+ case ENTITY_TYPE_ID:
+ if (ID->toi_type != INFO_TYPE_PROVIDER)
+ return TDI_INVALID_PARAMETER;
+
+ return InfoTdiQueryEntityType(ID->toi_entity, Buffer, BufferSize);
+
+ default:
+ return TDI_INVALID_REQUEST;
+ }
+
+ case INFO_CLASS_PROTOCOL:
+ switch (ID->toi_id)
+ {
+ case IF_MIB_STATS_ID:
+ if (ID->toi_entity.tei_entity == IF_ENTITY)
+ if ((EntityListContext = GetContext(ID->toi_entity)))
+ return InfoTdiQueryGetInterfaceMIB(ID->toi_entity,
EntityListContext, Buffer, BufferSize);
+ else
+ return TDI_INVALID_PARAMETER;
+ else if (ID->toi_entity.tei_entity == CL_NL_ENTITY ||
+ ID->toi_entity.tei_entity == CO_NL_ENTITY)
+ return InfoTdiQueryGetIPSnmpInfo(ID->toi_entity, Buffer,
BufferSize);
+ else
+ return TDI_INVALID_PARAMETER;
+
+ case IP_MIB_ADDRTABLE_ENTRY_ID:
+ if (ID->toi_entity.tei_entity != CL_NL_ENTITY &&
+ ID->toi_entity.tei_entity != CO_NL_ENTITY)
+ return TDI_INVALID_PARAMETER;
+
+ if (ID->toi_type != INFO_TYPE_PROVIDER)
+ return TDI_INVALID_PARAMETER;
+
+ return InfoTdiQueryGetAddrTable(ID->toi_entity, Buffer, BufferSize);
+
+ case IP_MIB_ARPTABLE_ENTRY_ID:
+ if (ID->toi_type != INFO_TYPE_PROVIDER)
+ return TDI_INVALID_PARAMETER;
+
+ if (ID->toi_entity.tei_entity == AT_ENTITY)
+ if ((EntityListContext = GetContext(ID->toi_entity)))
+ return InfoTdiQueryGetArptableMIB(ID->toi_entity,
EntityListContext,
+ Buffer, BufferSize);
+ else
+ return TDI_INVALID_PARAMETER;
+ else if (ID->toi_entity.tei_entity == CO_NL_ENTITY ||
+ ID->toi_entity.tei_entity == CL_NL_ENTITY)
+ return InfoTdiQueryGetRouteTable(Buffer, BufferSize);
+ else
+ return TDI_INVALID_PARAMETER;
+
+#if 0
+ case IP_INTFC_INFO_ID:
+ if (ID->toi_type != INFO_TYPE_PROVIDER)
+ return TDI_INVALID_PARAMETER;
+
+ return InfoTdiQueryGetIFInfo(Context, Buffer, BufferSize);
+#endif
+
+ default:
+ return TDI_INVALID_REQUEST;
+ }
+
+ default:
+ return TDI_INVALID_REQUEST;
+ }
}
TDI_STATUS InfoTdiSetInformationEx
@@ -245,24 +251,26 @@
* Status of operation
*/
{
- switch( ID->toi_class ) {
- case INFO_CLASS_PROTOCOL:
- switch( ID->toi_type ) {
- case INFO_TYPE_PROVIDER:
- switch( ID->toi_id ) {
- case IP_MIB_ROUTETABLE_ENTRY_ID:
- return InfoNetworkLayerTdiSetEx
- ( ID->toi_class,
- ID->toi_type,
- ID->toi_id,
- NULL,
- &ID->toi_entity,
- Buffer,
- BufferSize );
- }
- }
- break;
- }
-
- return TDI_INVALID_PARAMETER;
-}
+ switch (ID->toi_class)
+ {
+ case INFO_CLASS_PROTOCOL:
+ switch (ID->toi_id)
+ {
+ case IP_MIB_ARPTABLE_ENTRY_ID:
+ if (ID->toi_id != INFO_TYPE_PROVIDER)
+ return TDI_INVALID_PARAMETER;
+
+ if (ID->toi_entity.tei_entity != CL_NL_ENTITY &&
+ ID->toi_entity.tei_entity != CO_NL_ENTITY)
+ return TDI_INVALID_PARAMETER;
+
+ return InfoTdiSetRoute((PIPROUTE_ENTRY)Buffer);
+
+ default:
+ return TDI_INVALID_REQUEST;
+ }
+
+ default:
+ return TDI_INVALID_REQUEST;
+ }
+}
Modified: trunk/reactos/drivers/network/tcpip/tcpip/main.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/tcpip/tcpi…
==============================================================================
--- trunk/reactos/drivers/network/tcpip/tcpip/main.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/tcpip/tcpip/main.c [iso-8859-1] Fri Oct 9 04:40:38
2009
@@ -699,17 +699,7 @@
return STATUS_INSUFFICIENT_RESOURCES;
}
- EntityList[0].tei_entity = CL_NL_ENTITY;
- EntityList[0].tei_instance = 0;
- EntityList[0].context = 0;
- EntityList[0].info_req = InfoNetworkLayerTdiQueryEx;
- EntityList[0].info_set = InfoNetworkLayerTdiSetEx;
- EntityList[1].tei_entity = CL_TL_ENTITY;
- EntityList[1].tei_instance = 0;
- EntityList[1].context = 0;
- EntityList[1].info_req = InfoTransportLayerTdiQueryEx;
- EntityList[1].info_set = InfoTransportLayerTdiSetEx;
- EntityCount = 2;
+ EntityCount = 0;
EntityMax = MAX_TDI_ENTITIES;
/* Allocate NDIS packet descriptors */
Modified: trunk/reactos/drivers/network/tcpip/tcpip/ninfo.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/tcpip/tcpi…
==============================================================================
--- trunk/reactos/drivers/network/tcpip/tcpip/ninfo.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/tcpip/tcpip/ninfo.c [iso-8859-1] Fri Oct 9 04:40:38
2009
@@ -13,57 +13,7 @@
#define IP_ROUTE_TYPE_ADD 3
#define IP_ROUTE_TYPE_DEL 2
-TDI_STATUS InfoTdiQueryGetAddrTable( PNDIS_BUFFER Buffer,
- PUINT BufferSize ) {
-
- TDI_STATUS Status = TDI_INVALID_REQUEST;
- KIRQL OldIrql;
- UINT Count = 0;
- UINT IfCount = CountInterfaces();
- PIPADDR_ENTRY IpAddress =
- exAllocatePool( NonPagedPool, sizeof( IPADDR_ENTRY ) * IfCount );
- PIPADDR_ENTRY IpCurrent = IpAddress;
- IF_LIST_ITER(CurrentIF);
-
- TI_DbgPrint(DEBUG_INFO, ("Called.\n"));
-
- if (!IpAddress)
- return TDI_NO_RESOURCES;
-
- TcpipAcquireSpinLock(&InterfaceListLock, &OldIrql);
-
- ForEachInterface(CurrentIF) {
- IpCurrent->Index = CurrentIF->Index;
- IpCurrent->Addr = 0;
- IpCurrent->BcastAddr = 0;
- IpCurrent->Mask = 0;
-
- /* Locate the diffrent addresses and put them the right place */
- GetInterfaceIPv4Address( CurrentIF,
- ADE_UNICAST,
- &IpCurrent->Addr );
- GetInterfaceIPv4Address( CurrentIF,
- ADE_BROADCAST,
- &IpCurrent->BcastAddr );
- GetInterfaceIPv4Address( CurrentIF,
- ADE_ADDRMASK,
- &IpCurrent->Mask );
- IpCurrent++;
- Count++;
- } EndFor(CurrentIF);
- ASSERT( Count == IfCount );
-
- TcpipReleaseSpinLock(&InterfaceListLock, OldIrql);
-
- Status = InfoCopyOut( (PCHAR)IpAddress, sizeof(*IpAddress) * IfCount,
- Buffer, BufferSize );
-
- exFreePool( IpAddress );
-
- TI_DbgPrint(DEBUG_INFO, ("Returning %08x\n", Status));
-
- return Status;
-}
+
/* Get IPRouteEntry s for each of the routes in the system */
TDI_STATUS InfoTdiQueryGetRouteTable( PNDIS_BUFFER Buffer, PUINT BufferSize ) {
@@ -138,7 +88,65 @@
return Status;
}
-TDI_STATUS InfoTdiQueryGetIPSnmpInfo( PNDIS_BUFFER Buffer,
+TDI_STATUS InfoTdiQueryGetAddrTable(TDIEntityID ID,
+ PNDIS_BUFFER Buffer,
+ PUINT BufferSize)
+{
+ KIRQL OldIrql;
+ PIPADDR_ENTRY IPEntry;
+ PIP_INTERFACE CurrentIF;
+ UINT i;
+
+ TI_DbgPrint(DEBUG_INFO, ("Called.\n"));
+
+
+ TcpipAcquireSpinLock(&EntityListLock, &OldIrql);
+
+ for (i = 0; i < EntityCount; i++)
+ {
+ if (EntityList[i].tei_entity == ID.tei_entity &&
+ EntityList[i].tei_instance == ID.tei_instance)
+ break;
+ }
+
+ if (i == EntityCount)
+ {
+ TcpipReleaseSpinLock(&EntityListLock, OldIrql);
+ return TDI_INVALID_PARAMETER;
+ }
+
+ IPEntry = exAllocatePool(NonPagedPool, sizeof(IPADDR_ENTRY));
+ if (!IPEntry)
+ {
+ TcpipReleaseSpinLock(&EntityListLock, OldIrql);
+ return TDI_NO_RESOURCES;
+ }
+
+ CurrentIF = EntityList[i].context;
+
+ IPEntry->Index = CurrentIF->Index;
+ GetInterfaceIPv4Address(CurrentIF,
+ ADE_UNICAST,
+ &IPEntry->Addr);
+ GetInterfaceIPv4Address(CurrentIF,
+ ADE_ADDRMASK,
+ &IPEntry->Mask);
+ GetInterfaceIPv4Address(CurrentIF,
+ ADE_BROADCAST,
+ &IPEntry->BcastAddr);
+
+ TcpipReleaseSpinLock(&EntityListLock, OldIrql);
+
+ InfoCopyOut((PCHAR)IPEntry, sizeof(IPADDR_ENTRY),
+ Buffer, BufferSize);
+
+ exFreePool(IPEntry);
+
+ return TDI_SUCCESS;
+}
+
+TDI_STATUS InfoTdiQueryGetIPSnmpInfo( TDIEntityID ID,
+ PNDIS_BUFFER Buffer,
PUINT BufferSize ) {
IPSNMP_INFO SnmpInfo;
UINT IfCount = CountInterfaces();
@@ -161,95 +169,35 @@
return Status;
}
-TDI_STATUS InfoNetworkLayerTdiQueryEx( UINT InfoClass,
- UINT InfoType,
- UINT InfoId,
- PVOID Context,
- TDIEntityID *id,
- PNDIS_BUFFER Buffer,
- PUINT BufferSize ) {
- TDI_STATUS Status = TDI_INVALID_REQUEST;
-
- TI_DbgPrint(DEBUG_INFO, ("Called.\n"));
-
- switch( InfoClass ) {
- case INFO_CLASS_GENERIC:
- if( InfoType == INFO_TYPE_PROVIDER && InfoId == ENTITY_TYPE_ID ) {
- ULONG Return = CL_NL_IP;
- Status = InfoCopyOut( (PCHAR)&Return, sizeof(Return),
- Buffer, BufferSize );
- }
- break;
-
- case INFO_CLASS_PROTOCOL:
- switch( InfoType ) {
- case INFO_TYPE_PROVIDER:
- switch( InfoId ) {
- case IP_MIB_ADDRTABLE_ENTRY_ID:
- Status = InfoTdiQueryGetAddrTable( Buffer, BufferSize );
- break;
-
- case IP_MIB_ROUTETABLE_ENTRY_ID:
- Status = InfoTdiQueryGetRouteTable( Buffer, BufferSize );
- break;
-
- case IP_MIB_STATS_ID:
- Status = InfoTdiQueryGetIPSnmpInfo( Buffer, BufferSize );
- break;
- }
- break;
- }
- }
-
- TI_DbgPrint(DEBUG_INFO, ("Returning %08x\n", Status));
-
- return Status;
-}
-
-TDI_STATUS InfoNetworkLayerTdiSetEx( UINT InfoClass,
- UINT InfoType,
- UINT InfoId,
- PVOID Context,
- TDIEntityID *id,
- PCHAR Buffer,
- UINT BufferSize ) {
- NTSTATUS Status = TDI_INVALID_REQUEST;
- IP_ADDRESS Address;
- IP_ADDRESS Netmask;
- IP_ADDRESS Router;
+TDI_STATUS InfoTdiSetRoute(PIPROUTE_ENTRY Route)
+{
+ IP_ADDRESS Address, Netmask, Router;
PNEIGHBOR_CACHE_ENTRY NCE;
- TI_DbgPrint(DEBUG_INFO,("Called\n"));
-
- //OskitDumpBuffer( (OSK_PCHAR)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(DEBUG_INFO,("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(DEBUG_INFO,("Removing route (%s)\n", A2S(&Address)));
- Status = RouterRemoveRoute( &Address, &Router );
- } else Status = TDI_INVALID_REQUEST;
- }
-
- TI_DbgPrint(DEBUG_INFO,("Returning %x\n", Status));
-
- return Status;
-}
+ AddrInitIPv4( &Address, Route->Dest );
+ AddrInitIPv4( &Netmask, Route->Mask );
+ AddrInitIPv4( &Router, Route->Gw );
+
+ if( Route->Type == IP_ROUTE_TYPE_ADD ) { /* Add the route */
+ TI_DbgPrint(DEBUG_INFO,("Adding route (%s)\n", A2S(&Address)));
+ /* Find the existing route this belongs to */
+ NCE = RouterGetRoute( &Router );
+ if (!NCE) return TDI_INVALID_PARAMETER;
+
+ /* Really add the route */
+ if (!RouterCreateRoute( &Address, &Netmask, &Router,
+ NCE->Interface, Route->Metric1))
+ return TDI_NO_RESOURCES;
+
+ return TDI_SUCCESS;
+ } else if( Route->Type == IP_ROUTE_TYPE_DEL ) {
+ TI_DbgPrint(DEBUG_INFO,("Removing route (%s)\n", A2S(&Address)));
+ if (NT_SUCCESS(RouterRemoveRoute( &Address, &Router )))
+ return TDI_SUCCESS;
+ else
+ return TDI_INVALID_PARAMETER;
+ }
+
+ return TDI_INVALID_REQUEST;
+}
+