1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
|
/*++
Copyright (c) 1995 Microsoft Corporation
Module Name:
ntos\tdi\isn\fwd\tables.h
Abstract:
IPX Forwarder Driver Tables
Author:
Vadim Eydelman
Revision History:
--*/
#ifndef _IPXFWD_TABLES_
#define _IPXFWD_TABLES_
// Ranges and defaults for registry configurable parameters
#define MIN_ROUTE_SEGMENT_SIZE PAGE_SIZE
#define MAX_ROUTE_SEGMENT_SIZE (PAGE_SIZE*8)
#define DEF_ROUTE_SEGMENT_SIZE MIN_ROUTE_SEGMENT_SIZE
#define MIN_INTERFACE_HASH_SIZE 31
#define MAX_INTERFACE_HASH_SIZE 257
#define DEF_INTERFACE_HASH_SIZE MAX_INTERFACE_HASH_SIZE
#define MIN_CLIENT_HASH_SIZE 31
#define MAX_CLIENT_HASH_SIZE 257
#define DEF_CLIENT_HASH_SIZE MAX_CLIENT_HASH_SIZE
#define MIN_NB_ROUTE_HASH_SIZE 31
#define MAX_NB_ROUTE_HASH_SIZE 1023
#define DEF_NB_ROUTE_HASH_SIZE 257
#define MAX_SEND_PKTS_QUEUED 256 // No defined range
#define NUM_INTERFACES_PER_SEGMENT 16 // Not configurable currently
#define NUM_NB_ROUTES_PER_SEGMENT 16 // Not configurable currently
// Special number reserved for routes that point to
// client on global net
#define GLOBAL_INTERFACE_REFERENCE ((PINTERFACE_CB)-1)
// All types of WAN are emulated as ETHERNET by NDIS
#define WAN_PACKET_SIZE 1500
#define INVALID_NETWORK_NUMBER 0xFFFFFFFF
#define INVALID_NIC_ID 0xFFFF
// Interface control block
struct _INTERFACE_CB;
typedef struct _INTERFACE_CB INTERFACE_CB, *PINTERFACE_CB;
struct _FWD_ROUTE;
typedef struct _FWD_ROUTE FWD_ROUTE, *PFWD_ROUTE;
struct _NB_ROUTE;
typedef struct _NB_ROUTE NB_ROUTE, *PNB_ROUTE;
struct _FWD_ROUTE {
ULONG FR_Network; // Dest network
USHORT FR_TickCount; // Route params
USHORT FR_HopCount; //
UCHAR FR_NextHopAddress[6]; // Next hop router
PINTERFACE_CB FR_InterfaceReference; // Associated if CB
// or NULL if global
// network for clients
LONG FR_ReferenceCount; // Number of external
// references for this
// block (must keep the
// it till all of them
// are released
PFWD_ROUTE FR_Next; // Next route in the
// table
};
struct _INTERFACE_CB {
ULONG ICB_Index; // Unique ID
ULONG ICB_Network; // Network we boud to
union {
ULONGLONG ICB_ClientNode64[1];// For clients on
// global net (faster
// comparisons and
// hashing using 64
// bit support)
UCHAR ICB_RemoteNode[6]; // Peer node for demand
// dial connections
};
UCHAR ICB_LocalNode[6]; // Node we bound to
USHORT ICB_Flags;
#define FWD_IF_ENABLED 0x0001
#define SET_IF_ENABLED(ifCB) ifCB->ICB_Flags |= FWD_IF_ENABLED;
#define SET_IF_DISABLED(ifCB) ifCB->ICB_Flags &= ~FWD_IF_ENABLED;
#define IS_IF_ENABLED(ifCB) (ifCB->ICB_Flags&FWD_IF_ENABLED)
#define FWD_IF_CONNECTING 0x0002
#define SET_IF_CONNECTING(ifCB) ifCB->ICB_Flags |= FWD_IF_CONNECTING;
#define SET_IF_NOT_CONNECTING(ifCB) ifCB->ICB_Flags &= ~FWD_IF_CONNECTING;
#define IS_IF_CONNECTING(ifCB) (ifCB->ICB_Flags&FWD_IF_CONNECTING)
USHORT ICB_NicId; // Nic id we bound to
UCHAR ICB_InterfaceType;
UCHAR ICB_NetbiosDeliver;
BOOLEAN ICB_NetbiosAccept;
PNB_ROUTE ICB_NBRoutes; // Array of associated
// NB routes
ULONG ICB_NBRouteCount; // Number of nb routes
LONGLONG ICB_DisconnectTime; // Time when if was disconnected
FWD_IF_STATS ICB_Stats; // Accumulated
PFWD_ROUTE ICB_CashedRoute; // MRU dest route
PINTERFACE_CB ICB_CashedInterface;// MRU dest if
NIC_HANDLE ICB_AdapterContext; // IPX stack supplied
PVOID ICB_FilterInContext;
PVOID ICB_FilterOutContext;
LONG ICB_PendingQuota; // Remaining quota of
// packets that can be
// pending on
// the interface
LIST_ENTRY ICB_ExternalQueue; // Queue of external (received)
// packets
LIST_ENTRY ICB_InternalQueue; // Queue of internal (send)
// requests
#if DBG
LIST_ENTRY ICB_InSendQueue; // packets being
// sent by ipx
#endif
INT ICB_PacketListId; // ID of the packet list
// (for the max frame size
// on this interface)
LIST_ENTRY ICB_IndexHashLink; // Link in interface idx hash
LIST_ENTRY ICB_ConnectionLink; // Link in connection queue
PNDIS_PACKET ICB_ConnectionPacket; // Packet that caused connection
// request
PUCHAR ICB_ConnectionData; // Pointer into packet to
// place where actual data
// (header) starts
PINTERFACE_CB ICB_NodeHashLink; // Link in client node hash
ULONG ICB_ReferenceCount; // Number of routes that
// point to this CB
KSPIN_LOCK ICB_Lock; // Protects state,
// queues
};
#define InitICB(ifCB,IfIndex,IfType,NbAccept,NbDeliver) { \
(ifCB)->ICB_Index = IfIndex; \
(ifCB)->ICB_Network = INVALID_NETWORK_NUMBER; \
(ifCB)->ICB_Flags = 0; \
(ifCB)->ICB_NicId = INVALID_NIC_ID; \
(ifCB)->ICB_InterfaceType = IfType; \
(ifCB)->ICB_NetbiosAccept = NbAccept; \
(ifCB)->ICB_NetbiosDeliver = NbDeliver; \
memset (&(ifCB)->ICB_Stats, 0, sizeof (FWD_IF_STATS));\
KeInitializeSpinLock (&(ifCB)->ICB_Lock); \
(ifCB)->ICB_CashedInterface = NULL; \
(ifCB)->ICB_CashedRoute = NULL; \
(ifCB)->ICB_ReferenceCount = 0; \
(ifCB)->ICB_FilterInContext = NULL; \
(ifCB)->ICB_FilterOutContext = NULL; \
(ifCB)->ICB_ClientNode64[0] = 0; \
(ifCB)->ICB_NBRoutes = NULL; \
(ifCB)->ICB_PacketListId = -1; \
InitializeListHead (&(ifCB)->ICB_InternalQueue); \
InitializeListHead (&(ifCB)->ICB_ExternalQueue); \
(ifCB)->ICB_PendingQuota = MaxSendPktsQueued; \
switch ((ifCB)->ICB_InterfaceType) { \
case FWD_IF_PERMANENT: \
(ifCB)->ICB_Stats.OperationalState = FWD_OPER_STATE_DOWN;\
break; \
case FWD_IF_DEMAND_DIAL: \
case FWD_IF_LOCAL_WORKSTATION: \
case FWD_IF_REMOTE_WORKSTATION: \
(ifCB)->ICB_Stats.OperationalState = FWD_OPER_STATE_SLEEPING;\
KeQuerySystemTime ((PLARGE_INTEGER)&(ifCB)->ICB_DisconnectTime);\
(ifCB)->ICB_DisconnectTime -= (LONGLONG)SpoofingTimeout*10000000;\
break; \
} \
}
// Routes for netbios names (staticly seeded to reduce
// internet broadcast traffic)
struct _NB_ROUTE {
union {
ULONGLONG NBR_Name128[2];
UCHAR NBR_Name[16]; // Netbios name of destination
};
PINTERFACE_CB NBR_Destination; // Interface to send to
PNB_ROUTE NBR_Next; // Next route in the name list
};
// List used to allocate packets destined to WAN interfaces
extern INT WanPacketListId;
// Max number of outstanding sends
extern ULONG MaxSendPktsQueued;
// Segment sizes
extern ULONG RouteSegmentSize;
extern ULONG InterfaceSegmentSize;
extern ULONG NBNameSegementSize;
// Sizes of hash tables
extern ULONG RouteHashSize;
extern ULONG InterfaceHashSize;
extern ULONG ClientHashSize;
extern ULONG NBRouteHashSize;
// Number of global client network
extern ULONG GlobalNetwork;
// Interface reserved for internal network
extern PINTERFACE_CB InternalInterface;
/*++
*******************************************************************
C r e a t e T a b l e s
Routine Description:
Allocates and intializes all hash tables and related structures
Arguments:
None
Return Value:
STATUS_SUCCESS - tables were created ok
STATUS_INSUFFICIENT_RESOURCES - resource allocation failed
*******************************************************************
--*/
NTSTATUS
CreateTables (
void
);
/*++
*******************************************************************
D e l e t e T a b l e s
Routine Description:
Releases resources allocated for all hash tables
Arguments:
None
Return Value:
STATUS_SUCCESS - tables were freed ok
*******************************************************************
--*/
NTSTATUS
DeleteTables (
void
);
/*++
*******************************************************************
F r e e I n t e r f a c e
Routine Description:
Releases memory allocated for interface to interface memory
zone.
Arguments:
fwRoute - route block to release
Return Value:
None
*******************************************************************
--*/
VOID
FreeInterface (
PINTERFACE_CB ifCB
);
/*++
*******************************************************************
F r e e R o u t e
Routine Description:
Releases memory allocated for route to route memory
zone.
Arguments:
fwRoute - route block to release
Return Value:
None
*******************************************************************
--*/
VOID
FreeRoute (
PFWD_ROUTE fwRoute
);
/*++
*******************************************************************
A c q u i r e I n t e r f a c e R e f e r e n c e
Routine Description:
Increments refernce count of interface control block
ICB can't be freed until all references to it are released.
The caller of this routine should have already had a reference
to the interface or must hold an InterfaceLock
Arguments:
ifCB - interface control block to reference
Return Value:
None
*******************************************************************
--*/
//VOID
//AcquireInterfaceReference (
// PINTERFACE_CB ifCB
// );
#if DBG
#define AcquireInterfaceReference(ifCB) \
do { \
ASSERTMSG ("Referenced ifCB is dead ", \
InterlockedIncrement(&ifCB->ICB_ReferenceCount)>0); \
} while (0)
#else
#define AcquireInterfaceReference(ifCB) \
InterlockedIncrement(&ifCB->ICB_ReferenceCount)
#endif
/*++
*******************************************************************
R e l e a s e I n t e r f a c e R e f e r e n c e
Routine Description:
Decrements refernce count of interface control block
Arguments:
ifCB - interface control block to release
Return Value:
None
*******************************************************************
--*/
//PINTERFACE_CB
//ReleaseInterfaceReference (
// PINTERFACE_CB ifCB
// );
// if it drops below 0, it has alredy been removed from the table
#define ReleaseInterfaceReference(ifCB) ( \
(InterlockedDecrement (&ifCB->ICB_ReferenceCount)>=0) \
? ifCB \
: (FreeInterface (ifCB), (ifCB = NULL)) \
)
/*++
*******************************************************************
I n t e r f a c e C o n t e x t T o R e f e r e n c e
Routine Description:
Verifies that context supplied by the IPX stack is a valid
interface block and is still bound to the adapter with which
it is associated in the IPX stack
Arguments:
ifCB - interface control block to reference
NicId - id of the adapter to which interface is bound
Return Value:
None
*******************************************************************
--*/
//PINTERFACE_CB
//InterfaceContextToReference (
// PVOID Context
// );
#define InterfaceContextToReference(Context,NicId) ( \
(InterlockedIncrement(&((PINTERFACE_CB)Context)->ICB_ReferenceCount)>0) \
? ((NicId==((PINTERFACE_CB)Context)->ICB_NicId) \
? (PINTERFACE_CB)Context \
: (ReleaseInterfaceReference(((PINTERFACE_CB)Context)), NULL)) \
: NULL \
)
/*++
*******************************************************************
G e t I n t e r f a c e R e f e r e n c e
Routine Description:
Returns reference interface based on its index
Arguments:
InterfaceIndex - unique id of the interface
Return Value:
Pointer to interface control block if there is one in the table
NULL otherwise
*******************************************************************
--*/
PINTERFACE_CB
GetInterfaceReference (
ULONG InterfaceIndex
);
/*++
*******************************************************************
G e t N e x t I n t e r f a c e R e f e r e n c e
Routine Description:
Returns reference to the next interface in the table
Reference to the provided interface is released
Arguments:
ifCB - interface to start with or NULL to start from the
beginning of the interface table
Return Value:
Pointer to interface control block if thare are any more interfaces
in the table
NULL otherwise
*******************************************************************
--*/
PINTERFACE_CB
GetNextInterfaceReference (
PINTERFACE_CB ifCB
);
/*++
*******************************************************************
A d d I n t e r f a c e
Routine Description:
Adds interface control block to the table.
Arguments:
InterfaceIndex - unique if of the interface
Info - interface paramters
Return Value:
STATUS_SUCCESS - interface added ok
STATUS_UNSUCCESSFULL - interface is already in the table
STATUS_INSUFFICIENT_RESOURCES - can't allocate memory for
interface CB
*******************************************************************
--*/
NTSTATUS
AddInterface (
ULONG InterfaceIndex,
UCHAR InterfaceType,
BOOLEAN NetbiosAccept,
UCHAR NetbiosDeliver
);
/*++
*******************************************************************
A d d G l o b a l N e t C l i e n t
Routine Description:
Adds interface control block to the table of
clients on the global network (should be done when
client connects)
Arguments:
ifCB - interface control block to add to the table
Return Value:
STATUS_SUCCESS - interface was added ok
STATUS_UNSUCCESSFULL - another interface with the same
node address is already in the table
*******************************************************************
--*/
NTSTATUS
AddGlobalNetClient (
PINTERFACE_CB ifCB
);
/*++
*******************************************************************
D e l e t e G l o b a l N e t C l i e n t
Routine Description:
Removes interface control block from the table of
clients on the global network (should be done when
client disconnects)
Arguments:
ifCB - interface control block to remove from the table
Return Value:
STATUS_SUCCESS - interface was removed ok
*******************************************************************
--*/
NTSTATUS
DeleteGlobalNetClient (
PINTERFACE_CB ifCB
);
/*++
*******************************************************************
D e l e t e I n t e r f a c e
Routine Description:
Deletes interface control block (the block is not actually
disposed of until all references to it are released).
Arguments:
InterfaceIndex - unique if of the interface
Return Value:
STATUS_SUCCESS - interface info retreived ok
STATUS_UNSUCCESSFULL - interface is not in the table
*******************************************************************
--*/
NTSTATUS
DeleteInterface (
ULONG InterfaceIndex
);
/*++
*******************************************************************
A d d R o u t e
Routine Description:
Adds route to the hash table and finds and stores the reference
to the associated interface control block in the route.
Arguments:
Network - route's destination network
NextHopAddress - mac address of next hop router if network is not
directly connected
TickCount - ticks to reach the destination net
HopCount - hopss to reach the destination net
InterfaceIndex - index of the associated interface (through which
packets destined to the network are to be sent)
Return Value:
STATUS_SUCCESS - route was added ok
STATUS_UNSUCCESSFUL - route is already in the table
STATUS_INSUFFICIENT_RESOURCES - can't allocate memory for
route block
*******************************************************************
--*/
NTSTATUS
AddRoute (
ULONG Network,
UCHAR *NextHopAddress,
USHORT TickCount,
USHORT HopCount,
ULONG InterfaceIndex
);
/*++
*******************************************************************
D e l e t e R o u t e
Routine Description:
Deletes route from the hash table and releases the reference
to the interface control block associated with the route.
Arguments:
Network - route's destination network
Return Value:
STATUS_SUCCESS - route was deleted ok
STATUS_UNSUCCESSFUL - route is not in the table
*******************************************************************
--*/
NTSTATUS
DeleteRoute (
ULONG Network
);
/*++
*******************************************************************
U p d a t e R o u t e
Routine Description:
Updates route in the hash table
Arguments:
Network - route's destination network
NextHopAddress - mac address of next hop router if network is not
directly connected
TickCount - ticks to reach the destination net
HopCount - hopss to reach the destination net
InterfaceIndex - index of the associated interface (through which
packets destined to the network are to be sent)
Return Value:
STATUS_SUCCESS - interface info retreived ok
STATUS_UNSUCCESSFUL - interface is not in the table
*******************************************************************
--*/
NTSTATUS
UpdateRoute (
ULONG Network,
UCHAR *NextHopAddress,
USHORT TickCount,
USHORT HopCount,
ULONG InterfaceIndex
);
/*++
*******************************************************************
F i n d D e s t i n a t i o n
Routine Description:
Finds destination interface for IPX address and
returns reference to its control block.
Arguments:
Network - destination network
Node - destination node (needed in case of global client)
Route - buffer to place route reference
Return Value:
Reference to destination interface CB
NULL if route it not found
*******************************************************************
--*/
PINTERFACE_CB
FindDestination (
IN ULONG Network,
IN PUCHAR Node,
OUT PFWD_ROUTE *Route
);
/*++
*******************************************************************
A c q u i r e R o u t e R e f e r e n c e
Routine Description:
Increments refernce count of the route block
Route block can't be freed until all references to it are released.
The caller of this routine should have already had a reference
to the route or must hold an TableWriteLock
Arguments:
fwRoute - route block to reference
Return Value:
None
*******************************************************************
--*/
//VOID
//AcquireRouteReference (
// PFW+ROUTE fwRoute
// );
#define AcquireRouteReference(fwRoute) \
InterlockedIncrement(&fwRoute->FR_ReferenceCount)
/*++
*******************************************************************
R e l e a s e R o u t e R e f e r e n c e
Routine Description:
Decrements refernce count of route block
Arguments:
fwRoute - route block to release
Return Value:
None
*******************************************************************
--*/
//VOID
//ReleaseRouteReference (
// PFW_ROUTE fwRoute
// );
// if it drops below 0, it has alredy been removed from the table
#define ReleaseRouteReference(fwRoute) { \
if (InterlockedDecrement (&fwRoute->FR_ReferenceCount)<0) { \
FreeRoute (fwRoute); \
fwRoute = NULL; \
} \
}
/*++
*******************************************************************
A d d N B R o u t e s
Routine Description:
Adds netbios names associated with interface to netbios
route hash table
Arguments:
ifCB - interface with which names are associated
Names - array of names
Count - number of names in the array
routeArray - buffer to place pointer to allocated array of routes
Return Value:
STATUS_SUCCESS - names were added ok
STATUS_UNSUCCESSFUL - one of the names is already in the table
STATUS_INSUFFICIENT_RESOURCES - can't allocate memory for
route array
*******************************************************************
--*/
NTSTATUS
AddNBRoutes (
PINTERFACE_CB ifCB,
FWD_NB_NAME Names[],
ULONG Count,
PNB_ROUTE *routeArray
);
/*++
*******************************************************************
D e l e t e N B R o u t e s
Routine Description:
Deletes nb routes in the array from the route table and frees
the array
Arguments:
nbRoutes - array of routes
Count - number of routes in the array
Return Value:
STATUS_SUCCESS - route was deleted ok
STATUS_UNSUCCESSFUL - route is not in the table
*******************************************************************
--*/
NTSTATUS
DeleteNBRoutes (
PNB_ROUTE nbRoutes,
ULONG Count
);
/*++
*******************************************************************
F i n d N B D e s t i n a t i o n
Routine Description:
Finds destination interface for nb name and
returns reference to its control block.
Arguments:
Name - name to look for
Return Value:
Reference to destination interface CB
NULL if route it not found
*******************************************************************
--*/
PINTERFACE_CB
FindNBDestination (
IN PUCHAR Name
);
#endif
|