- Fix some typos from my last commit
authorCameron Gutman <aicommander@gmail.com>
Fri, 9 Oct 2009 05:18:35 +0000 (05:18 +0000)
committerCameron Gutman <aicommander@gmail.com>
Fri, 9 Oct 2009 05:18:35 +0000 (05:18 +0000)
 - Remove more hacks from iphlpapi

svn path=/trunk/; revision=43339

reactos/dll/win32/iphlpapi/ipstats_reactos.c
reactos/dll/win32/iphlpapi/route_reactos.c
reactos/drivers/network/tcpip/include/info.h
reactos/drivers/network/tcpip/include/router.h
reactos/drivers/network/tcpip/tcpip/info.c
reactos/drivers/network/tcpip/tcpip/ninfo.c
reactos/lib/drivers/ip/network/router.c

index 4a41866..7fb7cbf 100644 (file)
@@ -423,7 +423,6 @@ RouteTable *getRouteTable(void)
 {
     RouteTable *out_route_table;
     DWORD numRoutes = getNumRoutes(), routesAdded = 0;
-    IPSNMPInfo snmpInfo;
     TDIEntityID ent;
     HANDLE tcpFile;
     NTSTATUS status = openTcpFile( &tcpFile );
@@ -444,31 +443,28 @@ RouteTable *getRouteTable(void)
 
     out_route_table->numRoutes = numRoutes;
 
-    for( i = 0; routesAdded < numRoutes; i++ ) {
+    for( i = 0; routesAdded < out_route_table->numRoutes; i++ ) {
         int j;
         IPRouteEntry *route_set;
 
         getNthIpEntity( tcpFile, i, &ent );
-        tdiGetMibForIpEntity( tcpFile, &ent, &snmpInfo );
-
-        TRACE( "%d routes in instance %d\n", snmpInfo.ipsi_numroutes, i );
 
         tdiGetRoutesForIpEntity( tcpFile, &ent, &route_set, &numRoutes );
-
+        
         if( !route_set ) {
             closeTcpFile( tcpFile );
             HeapFree( GetProcessHeap(), 0, out_route_table );
             return 0;
         }
 
-        TRACE("Route set returned\n");
+        TRACE( "%d routes in instance %d\n", numRoutes, i );
 #if 0
         HexDump( route_set,
                  sizeof( IPRouteEntry ) *
                  snmpInfo.ipsi_numroutes );
 #endif
 
-        for( j = 0; j < snmpInfo.ipsi_numroutes; j++ ) {
+        for( j = 0; j < numRoutes; j++ ) {
             int routeNum = j + routesAdded;
             out_route_table->routes[routeNum].dest =
                 route_set[j].ire_dest;
@@ -484,7 +480,7 @@ RouteTable *getRouteTable(void)
 
         if( route_set ) tdiFreeThingSet( route_set );
 
-        routesAdded += snmpInfo.ipsi_numroutes;
+        routesAdded += numRoutes;
     }
 
     closeTcpFile( tcpFile );
index 84ee77e..ef6b639 100644 (file)
@@ -64,14 +64,14 @@ DWORD createIpForwardEntry( PMIB_IPFORWARDROW pRoute ) {
     TRACE("Called.\n");
 
     if( NT_SUCCESS(status) ) {
-        status = getNthIpEntity( tcpFile, 0, &id );
+        status = getNthIpEntity( tcpFile, pRoute->dwForwardIfIndex, &id );
 
         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_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.ID.toi_entity.tei_entity    = CL_NL_ENTITY;
             req.Req.BufferSize                  = sizeof(*rte);
             rte                                 =
                 (IPRouteEntry *)&req.Req.Buffer[0];
@@ -129,7 +129,7 @@ DWORD deleteIpForwardEntry( PMIB_IPFORWARDROW pRoute ) {
     TRACE("Called.\n");
 
     if( NT_SUCCESS(status) ) {
-        status = getNthIpEntity( tcpFile, 0, &id );
+        status = getNthIpEntity( tcpFile, pRoute->dwForwardIfIndex, &id );
 
         if( NT_SUCCESS(status) ) {
             req.Req.ID.toi_class                = INFO_CLASS_PROTOCOL;
index 432d953..efae370 100644 (file)
@@ -152,13 +152,15 @@ TDI_STATUS InfoTdiQueryGetInterfaceMIB(TDIEntityID ID,
                                       PUINT BufferSize);
 
 TDI_STATUS InfoTdiQueryGetIPSnmpInfo( TDIEntityID ID,
+                                      PIP_INTERFACE IF,
                                      PNDIS_BUFFER Buffer,
                                      PUINT BufferSize );
 
-TDI_STATUS InfoTdiQueryGetRouteTable( PNDIS_BUFFER Buffer,
+TDI_STATUS InfoTdiQueryGetRouteTable( PIP_INTERFACE IF,
+                                      PNDIS_BUFFER Buffer,
                                       PUINT BufferSize );
 
-TDI_STATUS InfoTdiSetRoute(PIPROUTE_ENTRY Route);
+TDI_STATUS InfoTdiSetRoute(PIP_INTERFACE IF, PIPROUTE_ENTRY Route);
 
 TDI_STATUS InfoTdiQueryGetArptableMIB(TDIEntityID ID,
                                      PIP_INTERFACE Interface,
index 92ff35e..73d2409 100644 (file)
@@ -43,9 +43,9 @@ NTSTATUS RouterStartup(
 NTSTATUS RouterShutdown(
     VOID);
 
-UINT CountFIBs(VOID);
+UINT CountFIBs(PIP_INTERFACE IF);
 
-UINT CopyFIBs( PFIB_ENTRY Target );
+UINT CopyFIBs( PIP_INTERFACE IF, PFIB_ENTRY Target );
 
 #endif /* __ROUTER_H */
 
index 3cb29e9..8a83303 100644 (file)
@@ -188,7 +188,10 @@ TDI_STATUS InfoTdiQueryInformationEx(
                          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);
+                     if ((EntityListContext = GetContext(ID->toi_entity)))
+                         return InfoTdiQueryGetIPSnmpInfo(ID->toi_entity, EntityListContext, Buffer, BufferSize);
+                     else
+                         return TDI_INVALID_PARAMETER;
                  else
                      return TDI_INVALID_PARAMETER;
 
@@ -214,7 +217,10 @@ TDI_STATUS InfoTdiQueryInformationEx(
                          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);
+                     if ((EntityListContext = GetContext(ID->toi_entity)))
+                         return InfoTdiQueryGetRouteTable(EntityListContext, Buffer, BufferSize);
+                     else
+                         return TDI_INVALID_PARAMETER;
                  else
                      return TDI_INVALID_PARAMETER;
 
@@ -251,20 +257,25 @@ TDI_STATUS InfoTdiSetInformationEx
  *   Status of operation
  */
 {
+    PVOID EntityListContext;
+
     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)
+                 if (ID->toi_type != 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);
+                 if ((EntityListContext = GetContext(ID->toi_entity)))
+                    return InfoTdiSetRoute(EntityListContext, (PIPROUTE_ENTRY)Buffer);
+                 else
+                     return TDI_INVALID_PARAMETER;
 
               default:
                 return TDI_INVALID_REQUEST;
index 352d8cf..968fe5c 100644 (file)
 
 
 /* Get IPRouteEntry s for each of the routes in the system */
-TDI_STATUS InfoTdiQueryGetRouteTable( PNDIS_BUFFER Buffer, PUINT BufferSize ) {
+TDI_STATUS InfoTdiQueryGetRouteTable( PIP_INTERFACE IF, PNDIS_BUFFER Buffer, PUINT BufferSize ) {
     TDI_STATUS Status;
     KIRQL OldIrql;
-    UINT RtCount = CountFIBs();
+    UINT RtCount = CountFIBs(IF);
     UINT Size = sizeof( IPROUTE_ENTRY ) * RtCount;
     PFIB_ENTRY RCache =
        exAllocatePool( NonPagedPool, sizeof( FIB_ENTRY ) * RtCount ),
        RCacheCur = RCache;
     PIPROUTE_ENTRY RouteEntries = exAllocatePool( NonPagedPool, Size ),
        RtCurrent = RouteEntries;
+    UINT i;
 
     TI_DbgPrint(DEBUG_INFO, ("Called, routes = %d, RCache = %08x\n",
                            RtCount, RCache));
@@ -38,7 +39,7 @@ TDI_STATUS InfoTdiQueryGetRouteTable( PNDIS_BUFFER Buffer, PUINT BufferSize ) {
 
     RtlZeroMemory( RouteEntries, Size );
 
-    RtCount = CopyFIBs( RCache );
+    RtCount = CopyFIBs( IF, RCache );
 
     while( RtCurrent < RouteEntries + RtCount ) {
        ASSERT(RCacheCur->Router);
@@ -66,13 +67,15 @@ TDI_STATUS InfoTdiQueryGetRouteTable( PNDIS_BUFFER Buffer, PUINT BufferSize ) {
              RtCurrent->Metric1 ));
 
        TcpipAcquireSpinLock(&EntityListLock, &OldIrql);
-       for( RtCurrent->Index = EntityCount;
-            RtCurrent->Index > 0 &&
-                RCacheCur->Router->Interface !=
-                EntityList[RtCurrent->Index - 1].context;
-            RtCurrent->Index-- );
+       for (i = 0; i < EntityCount; i++)
+             if (EntityList[i].context == IF)
+                 break;
+
+        if (i < EntityCount)
+            RtCurrent->Index = EntityList[i].tei_instance;
+        else
+            RtCurrent->Index = 0;
 
-        RtCurrent->Index = EntityList[RtCurrent->Index - 1].tei_instance;
        TcpipReleaseSpinLock(&EntityListLock, OldIrql);
 
        RtCurrent++; RCacheCur++;
@@ -146,11 +149,12 @@ TDI_STATUS InfoTdiQueryGetAddrTable(TDIEntityID ID,
 }
 
 TDI_STATUS InfoTdiQueryGetIPSnmpInfo( TDIEntityID ID,
+                                      PIP_INTERFACE IF,
                                      PNDIS_BUFFER Buffer,
                                      PUINT BufferSize ) {
     IPSNMP_INFO SnmpInfo;
     UINT IfCount = CountInterfaces();
-    UINT RouteCount = CountFIBs();
+    UINT RouteCount = CountFIBs(IF);
     TDI_STATUS Status = TDI_INVALID_REQUEST;
 
     TI_DbgPrint(DEBUG_INFO, ("Called.\n"));
@@ -169,10 +173,9 @@ TDI_STATUS InfoTdiQueryGetIPSnmpInfo( TDIEntityID ID,
     return Status;
 }
 
-TDI_STATUS InfoTdiSetRoute(PIPROUTE_ENTRY Route)
+TDI_STATUS InfoTdiSetRoute(PIP_INTERFACE IF, PIPROUTE_ENTRY Route)
 {
     IP_ADDRESS Address, Netmask, Router;
-    PNEIGHBOR_CACHE_ENTRY NCE;
 
     AddrInitIPv4( &Address, Route->Dest );
     AddrInitIPv4( &Netmask, Route->Mask );
@@ -180,13 +183,8 @@ TDI_STATUS InfoTdiSetRoute(PIPROUTE_ENTRY Route)
 
     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))
+                              IF, Route->Metric1))
            return TDI_NO_RESOURCES;
 
         return TDI_SUCCESS;
index a220db8..c2b79a2 100644 (file)
@@ -99,37 +99,41 @@ VOID DestroyFIBEs(
 }
 
 
-UINT CountFIBs() {
+UINT CountFIBs(PIP_INTERFACE IF) {
     UINT FibCount = 0;
     PLIST_ENTRY CurrentEntry;
     PLIST_ENTRY NextEntry;
+    PFIB_ENTRY Current;
 
-    /* Search the list and remove every FIB entry we find */
     CurrentEntry = FIBListHead.Flink;
     while (CurrentEntry != &FIBListHead) {
         NextEntry = CurrentEntry->Flink;
+        Current = CONTAINING_RECORD(CurrentEntry, FIB_ENTRY, ListEntry);
+        if (Current->Router->Interface == IF)
+           FibCount++;
         CurrentEntry = NextEntry;
-       FibCount++;
     }
 
     return FibCount;
 }
 
 
-UINT CopyFIBs( PFIB_ENTRY Target ) {
+UINT CopyFIBs( PIP_INTERFACE IF, PFIB_ENTRY Target ) {
     UINT FibCount = 0;
     PLIST_ENTRY CurrentEntry;
     PLIST_ENTRY NextEntry;
     PFIB_ENTRY Current;
 
-    /* Search the list and remove every FIB entry we find */
     CurrentEntry = FIBListHead.Flink;
     while (CurrentEntry != &FIBListHead) {
         NextEntry = CurrentEntry->Flink;
        Current = CONTAINING_RECORD(CurrentEntry, FIB_ENTRY, ListEntry);
-       Target[FibCount] = *Current;
+        if (Current->Router->Interface == IF)
+        {
+           Target[FibCount] = *Current;
+           FibCount++;
+        }
         CurrentEntry = NextEntry;
-       FibCount++;
     }
 
     return FibCount;