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
->NetworkAddress
&& RCacheCur
->Netmask
&&
90 TI_DbgPrint(MAX_TRACE
, ("%d: NA %08x NM %08x GW %08x MT %d\n",
91 RtCurrent
- RouteEntries
,
92 RCacheCur
->NetworkAddress
->Address
,
93 RCacheCur
->Netmask
->Address
,
94 RCacheCur
->Router
->Address
.Address
,
97 RtlCopyMemory( &RtCurrent
->Dest
,
98 &RCacheCur
->NetworkAddress
->Address
,
99 sizeof(RtCurrent
->Dest
) );
100 RtlCopyMemory( &RtCurrent
->Mask
,
101 &RCacheCur
->Netmask
->Address
,
102 sizeof(RtCurrent
->Mask
) );
103 /* Currently, this address is stuffed into the pointer.
104 * That probably is not intended. */
105 RtlCopyMemory( &RtCurrent
->Gw
,
106 &RCacheCur
->Router
->Address
.Address
,
107 sizeof(RtCurrent
->Gw
) );
108 RtCurrent
->Metric1
= RCacheCur
->Metric
;
109 RtCurrent
->Type
= 2 /* PF_INET */;
111 TcpipAcquireSpinLock(&EntityListLock
, &OldIrql
);
112 for( RtCurrent
->Index
= EntityCount
- 1;
113 RtCurrent
->Index
>= 0 &&
114 RCacheCur
->Router
->Interface
!=
115 EntityList
[RtCurrent
->Index
].context
;
116 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
,
145 IF_LIST_ITER(CurrentIF
);
146 IPSNMP_INFO SnmpInfo
;
147 UINT IfCount
= CountInterfaces();
149 UINT RouteCount
= CountRouteNodes( NULL
);
150 TDI_STATUS Status
= TDI_INVALID_REQUEST
;
152 TI_DbgPrint(MAX_TRACE
, ("Called.\n"));
154 RtlZeroMemory(&SnmpInfo
, sizeof(IPSNMP_INFO
));
156 /* Count number of addresses */
158 TcpipAcquireSpinLock(&InterfaceListLock
, &OldIrql
);
160 ForEachInterface(CurrentIF
) {
161 CurrentIF
= CONTAINING_RECORD(CurrentIFEntry
, IP_INTERFACE
, ListEntry
);
162 AddrCount
+= CountInterfaceAddresses( CurrentIF
);
165 TcpipReleaseSpinLock(&InterfaceListLock
, OldIrql
);
167 SnmpInfo
.NumIf
= IfCount
;
168 SnmpInfo
.NumAddr
= AddrCount
;
169 SnmpInfo
.NumRoutes
= RouteCount
;
171 Status
= InfoCopyOut( (PCHAR
)&SnmpInfo
, sizeof(SnmpInfo
),
172 Buffer
, BufferSize
);
174 TI_DbgPrint(MAX_TRACE
, ("Returning %08x\n", Status
));
179 TDI_STATUS
InfoNetworkLayerTdiQueryEx( UINT InfoClass
,
186 TDI_STATUS Status
= TDI_INVALID_REQUEST
;
188 TI_DbgPrint(MAX_TRACE
, ("Called.\n"));
190 switch( InfoClass
) {
191 case INFO_CLASS_GENERIC
:
192 if( InfoType
== INFO_TYPE_PROVIDER
&& InfoId
== ENTITY_TYPE_ID
) {
193 ULONG Return
= CL_NL_IP
;
194 Status
= InfoCopyOut( (PCHAR
)&Return
, sizeof(Return
),
195 Buffer
, BufferSize
);
199 case INFO_CLASS_PROTOCOL
:
201 case INFO_TYPE_PROVIDER
:
203 case IP_MIB_ADDRTABLE_ENTRY_ID
:
204 Status
= InfoTdiQueryGetAddrTable( Buffer
, BufferSize
);
207 case IP_MIB_ROUTETABLE_ENTRY_ID
:
208 Status
= InfoTdiQueryGetRouteTable( Buffer
, BufferSize
);
211 case IP_MIB_STATS_ID
:
212 Status
= InfoTdiQueryGetIPSnmpInfo( Buffer
, BufferSize
);
219 TI_DbgPrint(MAX_TRACE
, ("Returning %08x\n", Status
));
224 TDI_STATUS
InfoNetworkLayerTdiSetEx( UINT InfoClass
,
231 TDI_STATUS Status
= TDI_INVALID_REQUEST
;