2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS TCP/IP protocol driver
5 * PURPOSE: Network information
6 * PROGRAMMERS: Art Yerkes
8 * CSH 01/08-2000 Created
13 TDI_STATUS
InfoTdiQueryGetAddrTable( PNDIS_BUFFER Buffer
,
16 IF_LIST_ITER(CurrentIF
);
17 TDI_STATUS Status
= TDI_INVALID_REQUEST
;
19 UINT Count
= 1; /* Start adapter indices at 1 */
20 UINT IfCount
= CountInterfaces();
21 PIPADDR_ENTRY IpAddress
=
22 ExAllocatePool( NonPagedPool
, sizeof( IPADDR_ENTRY
) * IfCount
);
23 PIPADDR_ENTRY IpCurrent
= IpAddress
;
25 TI_DbgPrint(MAX_TRACE
, ("Called.\n"));
27 TcpipAcquireSpinLock(&InterfaceListLock
, &OldIrql
);
29 ForEachInterface(CurrentIF
) {
30 IpCurrent
->Index
= Count
;
32 IpCurrent
->BcastAddr
= 0;
35 /* Locate the diffrent addresses and put them the right place */
36 GetInterfaceIPv4Address( CurrentIF
,
39 GetInterfaceIPv4Address( CurrentIF
,
41 &IpAddress
->BcastAddr
);
42 GetInterfaceIPv4Address( CurrentIF
,
49 TcpipReleaseSpinLock(&InterfaceListLock
, OldIrql
);
51 Status
= InfoCopyOut( (PCHAR
)IpAddress
, sizeof(*IpAddress
) * Count
,
54 ExFreePool( IpAddress
);
56 TI_DbgPrint(MAX_TRACE
, ("Returning %08x\n", Status
));
61 /* Get IPRouteEntry s for each of the routes in the system */
62 TDI_STATUS
InfoTdiQueryGetRouteTable( PNDIS_BUFFER Buffer
, PUINT BufferSize
) {
65 UINT RtCount
= CountFIBs(),
66 Size
= sizeof( IPROUTE_ENTRY
) * RtCount
;
68 ExAllocatePool( NonPagedPool
, sizeof( FIB_ENTRY
) * RtCount
),
70 PIPROUTE_ENTRY RouteEntries
= ExAllocatePool( NonPagedPool
, Size
),
71 RtCurrent
= RouteEntries
;
73 TI_DbgPrint(MAX_TRACE
, ("Called, routes = %d, RCache = %08x\n",
76 if( !RCache
|| !RouteEntries
) {
77 if( RCache
) ExFreePool( RCache
);
78 if( RouteEntries
) ExFreePool( RouteEntries
);
79 return STATUS_NO_MEMORY
;
82 RtlZeroMemory( RouteEntries
, Size
);
84 RtCount
= CopyFIBs( RCache
);
86 while( RtCurrent
< RouteEntries
+ RtCount
) {
87 /* Copy Desitnation */
88 if( RCacheCur
->Router
) {
89 TI_DbgPrint(MAX_TRACE
, ("%d: NA %08x NM %08x GW %08x MT %x\n",
90 RtCurrent
- RouteEntries
,
91 &RCacheCur
->NetworkAddress
.Address
,
92 &RCacheCur
->Netmask
.Address
,
93 RCacheCur
->Router
->Address
.Address
,
96 RtlCopyMemory( &RtCurrent
->Dest
,
97 &RCacheCur
->NetworkAddress
.Address
,
98 sizeof(RtCurrent
->Dest
) );
99 RtlCopyMemory( &RtCurrent
->Mask
,
100 &RCacheCur
->Netmask
.Address
,
101 sizeof(RtCurrent
->Mask
) );
102 /* Currently, this address is stuffed into the pointer.
103 * That probably is not intended. */
104 RtlCopyMemory( &RtCurrent
->Gw
,
105 &RCacheCur
->Router
->Address
.Address
,
106 sizeof(RtCurrent
->Gw
) );
107 RtCurrent
->Metric1
= RCacheCur
->Metric
;
108 RtCurrent
->Type
= 2 /* PF_INET */;
110 TcpipAcquireSpinLock(&EntityListLock
, &OldIrql
);
111 for( RtCurrent
->Index
= EntityCount
;
112 RtCurrent
->Index
> 0 &&
113 RCacheCur
->Router
->Interface
!=
114 EntityList
[RtCurrent
->Index
- 1].context
;
115 RtCurrent
->Index
-- );
117 RtCurrent
->Index
= EntityList
[RtCurrent
->Index
].tei_instance
;
118 TcpipReleaseSpinLock(&EntityListLock
, OldIrql
);
120 TI_DbgPrint(MAX_TRACE
, ("%d: BAD: NA %08x NM %08x GW %08x MT %d\n",
121 RtCurrent
- RouteEntries
,
122 RCacheCur
->NetworkAddress
,
126 &RCacheCur
->Router
->Address
: 0,
129 RtCurrent
++; RCacheCur
++;
132 Status
= InfoCopyOut( (PCHAR
)RouteEntries
, Size
, Buffer
, BufferSize
);
134 ExFreePool( RouteEntries
);
135 ExFreePool( RCache
);
137 TI_DbgPrint(MAX_TRACE
, ("Returning %08x\n", Status
));
142 TDI_STATUS
InfoTdiQueryGetIPSnmpInfo( PNDIS_BUFFER Buffer
,
144 IPSNMP_INFO SnmpInfo
;
145 UINT IfCount
= CountInterfaces();
146 UINT RouteCount
= CountRouteNodes( NULL
);
147 TDI_STATUS Status
= TDI_INVALID_REQUEST
;
149 TI_DbgPrint(MAX_TRACE
, ("Called.\n"));
151 RtlZeroMemory(&SnmpInfo
, sizeof(IPSNMP_INFO
));
153 SnmpInfo
.NumIf
= IfCount
;
154 SnmpInfo
.NumAddr
= 1;
155 SnmpInfo
.NumRoutes
= RouteCount
;
157 Status
= InfoCopyOut( (PCHAR
)&SnmpInfo
, sizeof(SnmpInfo
),
158 Buffer
, BufferSize
);
160 TI_DbgPrint(MAX_TRACE
, ("Returning %08x\n", Status
));
165 TDI_STATUS
InfoNetworkLayerTdiQueryEx( UINT InfoClass
,
172 TDI_STATUS Status
= TDI_INVALID_REQUEST
;
174 TI_DbgPrint(MAX_TRACE
, ("Called.\n"));
176 switch( InfoClass
) {
177 case INFO_CLASS_GENERIC
:
178 if( InfoType
== INFO_TYPE_PROVIDER
&& InfoId
== ENTITY_TYPE_ID
) {
179 ULONG Return
= CL_NL_IP
;
180 Status
= InfoCopyOut( (PCHAR
)&Return
, sizeof(Return
),
181 Buffer
, BufferSize
);
185 case INFO_CLASS_PROTOCOL
:
187 case INFO_TYPE_PROVIDER
:
189 case IP_MIB_ADDRTABLE_ENTRY_ID
:
190 Status
= InfoTdiQueryGetAddrTable( Buffer
, BufferSize
);
193 case IP_MIB_ROUTETABLE_ENTRY_ID
:
194 Status
= InfoTdiQueryGetRouteTable( Buffer
, BufferSize
);
197 case IP_MIB_STATS_ID
:
198 Status
= InfoTdiQueryGetIPSnmpInfo( Buffer
, BufferSize
);
205 TI_DbgPrint(MAX_TRACE
, ("Returning %08x\n", Status
));
210 TDI_STATUS
InfoNetworkLayerTdiSetEx( UINT InfoClass
,
217 return STATUS_UNSUCCESSFUL
;