- Fix some typos from my last commit
[reactos.git] / reactos / lib / drivers / ip / network / router.c
index 8e4c62c..c2b79a2 100644 (file)
@@ -51,7 +51,7 @@ VOID FreeFIB(
  *     Object = Pointer to an forward information base structure
  */
 {
-    PoolFreeBuffer(Object);
+    exFreePool(Object);
 }
 
 
@@ -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;
@@ -213,13 +217,13 @@ PFIB_ENTRY RouterAddRoute(
                               A2S(Netmask),
                               A2S(&Router->Address)));
 
-    FIBE = PoolAllocateBuffer(sizeof(FIB_ENTRY));
+    FIBE = exAllocatePool(NonPagedPool, sizeof(FIB_ENTRY));
     if (!FIBE) {
         TI_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
         return NULL;
     }
 
-    INIT_TAG(Router, TAG('R','O','U','T'));
+    INIT_TAG(Router, 'TUOR');
 
     RtlCopyMemory( &FIBE->NetworkAddress, NetworkAddress,
                   sizeof(FIBE->NetworkAddress) );
@@ -274,7 +278,8 @@ PNEIGHBOR_CACHE_ENTRY RouterGetRoute(PIP_ADDRESS Destination)
        TI_DbgPrint(DEBUG_ROUTER,("This-Route: %s (Sharing %d bits)\n",
                                  A2S(&NCE->Address), Length));
 
-       if(Length >= MaskLength && (Length > BestLength || !BestLength)) {
+       if(Length >= MaskLength && (Length > BestLength || !BestNCE) &&
+           (!(State & NUD_STALE) || !BestNCE)) {
            /* This seems to be a better router */
            BestNCE    = NCE;
            BestLength = Length;
@@ -390,7 +395,7 @@ NTSTATUS RouterRemoveRoute(PIP_ADDRESS Target, PIP_ADDRESS Router)
 
     TI_DbgPrint(DEBUG_ROUTER, ("Leaving\n"));
 
-    return Found ? STATUS_NO_SUCH_FILE : STATUS_SUCCESS;
+    return Found ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL;
 }
 
 
@@ -415,7 +420,6 @@ PFIB_ENTRY RouterCreateRoute(
  */
 {
     KIRQL OldIrql;
-    PFIB_ENTRY FIBE;
     PLIST_ENTRY CurrentEntry;
     PLIST_ENTRY NextEntry;
     PFIB_ENTRY Current;
@@ -450,13 +454,7 @@ PFIB_ENTRY RouterCreateRoute(
         return NULL;
     }
 
-    FIBE = RouterAddRoute(NetworkAddress, Netmask, NCE, Metric);
-    if (!FIBE) {
-        /* Not enough free resources */
-        NBRemoveNeighbor(NCE);
-    }
-
-    return FIBE;
+    return RouterAddRoute(NetworkAddress, Netmask, NCE, Metric);
 }