ReactOS 0.4.16-dev-2491-g3dc6630
router.h File Reference
#include <neighbor.h>
Include dependency graph for router.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _FIB_ENTRY
 

Typedefs

typedef struct _FIB_ENTRY FIB_ENTRY
 
typedef struct _FIB_ENTRYPFIB_ENTRY
 

Functions

PFIB_ENTRY RouterAddRoute (PIP_ADDRESS NetworkAddress, PIP_ADDRESS Netmask, PNEIGHBOR_CACHE_ENTRY Router, UINT Metric)
 
PNEIGHBOR_CACHE_ENTRY RouterGetRoute (PIP_ADDRESS Destination)
 
NTSTATUS RouterRemoveRoute (PIP_ADDRESS Target, PIP_ADDRESS Router)
 
PFIB_ENTRY RouterCreateRoute (PIP_ADDRESS NetworkAddress, PIP_ADDRESS Netmask, PIP_ADDRESS RouterAddress, PIP_INTERFACE Interface)
 
NTSTATUS RouterStartup (VOID)
 
NTSTATUS RouterShutdown (VOID)
 
VOID RouterRemoveRoutesForInterface (PIP_INTERFACE Interface)
 
UINT CountFIBs (PIP_INTERFACE IF)
 
UINT CopyFIBs (PIP_INTERFACE IF, PFIB_ENTRY Target)
 
UINT ProcessAutoMetric (PIP_INTERFACE Interface)
 

Typedef Documentation

◆ FIB_ENTRY

◆ PFIB_ENTRY

Function Documentation

◆ CopyFIBs()

UINT CopyFIBs ( PIP_INTERFACE  IF,
PFIB_ENTRY  Target 
)

Definition at line 150 of file router.c.

150 {
151 UINT FibCount = 0;
152 PLIST_ENTRY CurrentEntry;
153 PLIST_ENTRY NextEntry;
154 PFIB_ENTRY Current;
155
156 CurrentEntry = FIBListHead.Flink;
157 while (CurrentEntry != &FIBListHead) {
158 NextEntry = CurrentEntry->Flink;
159 Current = CONTAINING_RECORD(CurrentEntry, FIB_ENTRY, ListEntry);
160 if (Current->Router->Interface == IF)
161 {
162 Target[FibCount] = *Current;
163 FibCount++;
164 }
165 CurrentEntry = NextEntry;
166 }
167
168 return FibCount;
169}
unsigned int UINT
Definition: ndis.h:50
LIST_ENTRY FIBListHead
Definition: router.c:17
PIP_INTERFACE Interface
Definition: neighbor.h:33
Definition: router.h:14
PNEIGHBOR_CACHE_ENTRY Router
Definition: router.h:19
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
_In_ WDFIOTARGET Target
Definition: wdfrequest.h:306

Referenced by InfoTdiQueryGetRouteTable().

◆ CountFIBs()

UINT CountFIBs ( PIP_INTERFACE  IF)

Definition at line 131 of file router.c.

131 {
132 UINT FibCount = 0;
133 PLIST_ENTRY CurrentEntry;
134 PLIST_ENTRY NextEntry;
135 PFIB_ENTRY Current;
136
137 CurrentEntry = FIBListHead.Flink;
138 while (CurrentEntry != &FIBListHead) {
139 NextEntry = CurrentEntry->Flink;
140 Current = CONTAINING_RECORD(CurrentEntry, FIB_ENTRY, ListEntry);
141 if (Current->Router->Interface == IF)
142 FibCount++;
143 CurrentEntry = NextEntry;
144 }
145
146 return FibCount;
147}

Referenced by InfoTdiQueryGetIPSnmpInfo(), and InfoTdiQueryGetRouteTable().

◆ ProcessAutoMetric()

UINT ProcessAutoMetric ( PIP_INTERFACE  Interface)

◆ RouterAddRoute()

PFIB_ENTRY RouterAddRoute ( PIP_ADDRESS  NetworkAddress,
PIP_ADDRESS  Netmask,
PNEIGHBOR_CACHE_ENTRY  Router,
UINT  Metric 
)

Definition at line 219 of file router.c.

238{
239 PFIB_ENTRY FIBE;
240
241 TI_DbgPrint(DEBUG_ROUTER, ("Called. NetworkAddress (0x%X) Netmask (0x%X) "
242 "Router (0x%X) Metric (%d).\n", NetworkAddress, Netmask, Router, Metric));
243
244 TI_DbgPrint(DEBUG_ROUTER, ("NetworkAddress (%s) Netmask (%s) Router (%s).\n",
246 A2S(Netmask),
247 A2S(&Router->Address)));
248
250 if (!FIBE) {
251 TI_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
252 return NULL;
253 }
254
256 sizeof(FIBE->NetworkAddress) );
257 RtlCopyMemory( &FIBE->Netmask, Netmask,
258 sizeof(FIBE->Netmask) );
259 FIBE->Router = Router;
260 FIBE->Metric = Metric;
261
262 /* Add FIB to the forward information base */
264
265 return FIBE;
266}
#define MIN_TRACE
Definition: debug.h:14
#define NULL
Definition: types.h:112
#define DEBUG_ROUTER
Definition: debug.h:30
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
VOID TcpipInterlockedInsertTailList(PLIST_ENTRY ListHead, PLIST_ENTRY Item, PKSPIN_LOCK Lock)
Definition: lock.c:34
#define FIB_TAG
Definition: tags.h:29
PCHAR A2S(PIP_ADDRESS Address)
Definition: address.c:17
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define NonPagedPool
Definition: env_spec_w32.h:307
_Must_inspect_result_ _Out_ PNDIS_STATUS _Outptr_result_bytebuffer_to_ NetworkAddressLength PVOID * NetworkAddress
Definition: ndis.h:3956
KSPIN_LOCK FIBLock
Definition: router.c:18
IP_ADDRESS Address
Definition: neighbor.h:36
LIST_ENTRY ListEntry
Definition: router.h:15
UINT Metric
Definition: router.h:20
IP_ADDRESS Netmask
Definition: router.h:18
IP_ADDRESS NetworkAddress
Definition: router.h:17
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263

Referenced by IPAddInterfaceRoute(), and RouterCreateRoute().

◆ RouterCreateRoute()

PFIB_ENTRY RouterCreateRoute ( PIP_ADDRESS  NetworkAddress,
PIP_ADDRESS  Netmask,
PIP_ADDRESS  RouterAddress,
PIP_INTERFACE  Interface 
)

Definition at line 451 of file router.c.

468{
470 PLIST_ENTRY CurrentEntry;
471 PLIST_ENTRY NextEntry;
472 PFIB_ENTRY Current;
474
476
477 CurrentEntry = FIBListHead.Flink;
478 while (CurrentEntry != &FIBListHead) {
479 NextEntry = CurrentEntry->Flink;
480 Current = CONTAINING_RECORD(CurrentEntry, FIB_ENTRY, ListEntry);
481
482 NCE = Current->Router;
483
485 AddrIsEqual(Netmask, &Current->Netmask) &&
486 NCE->Interface == Interface)
487 {
488 TI_DbgPrint(DEBUG_ROUTER,("Attempting to add duplicate route to %s\n", A2S(NetworkAddress)));
490 return NULL;
491 }
492
493 CurrentEntry = NextEntry;
494 }
495
497
498 /* The NCE references RouterAddress. The NCE is referenced for us */
499 NCE = NBFindOrCreateNeighbor(Interface, RouterAddress, TRUE);
500
501 if (!NCE) {
502 /* Not enough free resources */
503 return NULL;
504 }
505
507}
BOOLEAN AddrIsEqual(PIP_ADDRESS Address1, PIP_ADDRESS Address2)
Definition: address.c:221
#define TRUE
Definition: types.h:120
VOID TcpipReleaseSpinLock(PKSPIN_LOCK SpinLock, KIRQL Irql)
Definition: lock.c:26
VOID TcpipAcquireSpinLock(PKSPIN_LOCK SpinLock, PKIRQL Irql)
Definition: lock.c:18
UCHAR KIRQL
Definition: env_spec_w32.h:591
PNEIGHBOR_CACHE_ENTRY NBFindOrCreateNeighbor(PIP_INTERFACE Interface, PIP_ADDRESS Address, BOOLEAN NoTimeout)
Definition: neighbor.c:515
UINT ProcessAutoMetric(_In_ PIP_INTERFACE Interface)
Definition: router.c:21
PFIB_ENTRY RouterAddRoute(PIP_ADDRESS NetworkAddress, PIP_ADDRESS Netmask, PNEIGHBOR_CACHE_ENTRY Router, UINT Metric)
Definition: router.c:219
Definition: neighbor.h:28
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE Interface
Definition: wdffdo.h:465
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

Referenced by InfoTdiSetRoute(), and ReadIpConfiguration().

◆ RouterGetRoute()

PNEIGHBOR_CACHE_ENTRY RouterGetRoute ( PIP_ADDRESS  Destination)

Definition at line 269 of file router.c.

279{
281 PLIST_ENTRY CurrentEntry;
282 PLIST_ENTRY NextEntry;
283 PFIB_ENTRY Current;
284 UCHAR State;
285 UINT Length, BestLength = 0, MaskLength;
286 PNEIGHBOR_CACHE_ENTRY NCE, BestNCE = NULL;
287
288 TI_DbgPrint(DEBUG_ROUTER, ("Called. Destination (0x%X)\n", Destination));
289
290 TI_DbgPrint(DEBUG_ROUTER, ("Destination (%s)\n", A2S(Destination)));
291
293
294 CurrentEntry = FIBListHead.Flink;
295 while (CurrentEntry != &FIBListHead) {
296 NextEntry = CurrentEntry->Flink;
297 Current = CONTAINING_RECORD(CurrentEntry, FIB_ENTRY, ListEntry);
298
299 NCE = Current->Router;
300 State = NCE->State;
301
303 MaskLength = AddrCountPrefixBits(&Current->Netmask);
304
305 TI_DbgPrint(DEBUG_ROUTER,("This-Route: %s (Sharing %d bits)\n",
306 A2S(&NCE->Address), Length));
307
308 if(Length >= MaskLength && (Length > BestLength || !BestNCE) &&
309 ((!(State & NUD_STALE) && !(State & NUD_INCOMPLETE)) || !BestNCE)) {
310 /* This seems to be a better router */
311 BestNCE = NCE;
312 BestLength = Length;
313 TI_DbgPrint(DEBUG_ROUTER,("Route selected\n"));
314 }
315
316 CurrentEntry = NextEntry;
317 }
318
320
321 if( BestNCE ) {
322 TI_DbgPrint(DEBUG_ROUTER,("Routing to %s\n", A2S(&BestNCE->Address)));
323 } else {
324 TI_DbgPrint(DEBUG_ROUTER,("Packet won't be routed\n"));
325 }
326
327 return BestNCE;
328}
UINT AddrCountPrefixBits(PIP_ADDRESS Netmask)
Definition: address.c:64
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:3051
#define NUD_INCOMPLETE
Definition: neighbor.h:41
#define NUD_STALE
Definition: neighbor.h:43
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
UINT CommonPrefixLength(PIP_ADDRESS Address1, PIP_ADDRESS Address2)
Definition: router.c:172
UCHAR State
Definition: neighbor.h:30
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by RouteGetRouteToDestination().

◆ RouterRemoveRoute()

NTSTATUS RouterRemoveRoute ( PIP_ADDRESS  Target,
PIP_ADDRESS  Router 
)

Definition at line 394 of file router.c.

403{
405 PLIST_ENTRY CurrentEntry;
406 PLIST_ENTRY NextEntry;
407 PFIB_ENTRY Current;
410
411 TI_DbgPrint(DEBUG_ROUTER, ("Called\n"));
412 TI_DbgPrint(DEBUG_ROUTER, ("Deleting Route From: %s\n", A2S(Router)));
413 TI_DbgPrint(DEBUG_ROUTER, (" To: %s\n", A2S(Target)));
414
416
418
419 CurrentEntry = FIBListHead.Flink;
420 while (CurrentEntry != &FIBListHead) {
421 NextEntry = CurrentEntry->Flink;
422 Current = CONTAINING_RECORD(CurrentEntry, FIB_ENTRY, ListEntry);
423
424 NCE = Current->Router;
425
426 if( AddrIsEqual( &Current->NetworkAddress, Target ) &&
427 AddrIsEqual( &NCE->Address, Router ) ) {
428 Found = TRUE;
429 break;
430 }
431
432 Current = NULL;
433 CurrentEntry = NextEntry;
434 }
435
436 if( Found ) {
437 TI_DbgPrint(DEBUG_ROUTER, ("Deleting route\n"));
438 DestroyFIBE( Current );
439 }
440
442
444
445 TI_DbgPrint(DEBUG_ROUTER, ("Leaving\n"));
446
448}
unsigned char BOOLEAN
Definition: actypes.h:127
return Found
Definition: dirsup.c:1270
#define FALSE
Definition: types.h:117
VOID DestroyFIBE(PFIB_ENTRY FIBE)
Definition: router.c:87
VOID RouterDumpRoutes(VOID)
Definition: router.c:49
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

Referenced by InfoTdiSetRoute(), and IPRemoveInterfaceRoute().

◆ RouterRemoveRoutesForInterface()

VOID RouterRemoveRoutesForInterface ( PIP_INTERFACE  Interface)

Definition at line 371 of file router.c.

372{
374 PLIST_ENTRY CurrentEntry;
375 PLIST_ENTRY NextEntry;
376 PFIB_ENTRY Current;
377
379
380 CurrentEntry = FIBListHead.Flink;
381 while (CurrentEntry != &FIBListHead) {
382 NextEntry = CurrentEntry->Flink;
383 Current = CONTAINING_RECORD(CurrentEntry, FIB_ENTRY, ListEntry);
384
385 if (Interface == Current->Router->Interface)
386 DestroyFIBE(Current);
387
388 CurrentEntry = NextEntry;
389 }
390
392}

Referenced by ReconfigureAdapter().

◆ RouterShutdown()

NTSTATUS RouterShutdown ( VOID  )

Definition at line 528 of file router.c.

535{
537
538 TI_DbgPrint(DEBUG_ROUTER, ("Called.\n"));
539
540 /* Clear Forward Information Base */
542 DestroyFIBEs();
544
545 return STATUS_SUCCESS;
546}
VOID DestroyFIBEs(VOID)
Definition: router.c:107

Referenced by IPShutdown().

◆ RouterStartup()

NTSTATUS RouterStartup ( VOID  )

Definition at line 510 of file router.c.

517{
518 TI_DbgPrint(DEBUG_ROUTER, ("Called.\n"));
519
520 /* Initialize the Forward Information Base */
523
524 return STATUS_SUCCESS;
525}
VOID TcpipInitializeSpinLock(PKSPIN_LOCK SpinLock)
Definition: lock.c:14
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944

Referenced by IPStartup().