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
|
/*++
Copyright (c) 1995 Microsoft Corporation
Module Name:
ntos\tdi\isn\fwd\ddreqs.c
Abstract:
Management of demand dial request queues
Author:
Vadim Eydelman
Revision History:
--*/
#include "precomp.h"
LIST_ENTRY ConnectionIrpQueue;
LIST_ENTRY ConnectionRequestQueue;
/*++
Q u e u e C o n n e c t i o n R e q u e s t
Routine Description:
Adds request to connected the interface to the queue
Arguments:
ifCB - control block of the interface that needs to be
connected
packet - packet that prompted the connection request
data - pointer to actual data in the packet
oldIRQL - IRQL at which interface lock was acquired
Return Value:
None
Note that interface lock must be acquired before calling this
routine which will release it
--*/
VOID
QueueConnectionRequest (
PINTERFACE_CB ifCB,
PNDIS_PACKET packet,
PUCHAR data,
KIRQL oldIRQL
) {
KIRQL cancelIRQL;
IoAcquireCancelSpinLock (&cancelIRQL);
SET_IF_CONNECTING (ifCB);
if (!IsListEmpty (&ConnectionIrpQueue)) {
PIRP irp = CONTAINING_RECORD (
ConnectionIrpQueue.Flink,
IRP,
Tail.Overlay.ListEntry);
PIO_STACK_LOCATION irpStack=IoGetCurrentIrpStackLocation(irp);
RemoveEntryList (&irp->Tail.Overlay.ListEntry);
ASSERT (irpStack->Parameters.DeviceIoControl.IoControlCode
==IOCTL_FWD_GET_DIAL_REQUEST);
ASSERT ((irpStack->Parameters.DeviceIoControl.IoControlCode&3)
==METHOD_BUFFERED);
IoSetCancelRoutine (irp, NULL);
IoReleaseCancelSpinLock (cancelIRQL);
FillConnectionRequest (
ifCB->ICB_Index,
packet,
data,
(PFWD_DIAL_REQUEST)irp->AssociatedIrp.SystemBuffer,
irpStack->Parameters.DeviceIoControl.OutputBufferLength,
&irp->IoStatus.Information);
irp->IoStatus.Status = STATUS_SUCCESS;
KeReleaseSpinLock (&ifCB->ICB_Lock, oldIRQL);
IpxFwdDbgPrint (DBG_DIALREQS, DBG_WARNING,
("IpxFwd: Passing dial request for if %ld (icb:%08lx) with %d bytes of data.\n",
ifCB->ICB_Index, ifCB, irp->IoStatus.Information));
IoCompleteRequest (irp, IO_NO_INCREMENT);
}
else {
InsertTailList (&ConnectionRequestQueue, &ifCB->ICB_ConnectionLink);
IoReleaseCancelSpinLock (cancelIRQL);
ifCB->ICB_ConnectionPacket = packet;
ifCB->ICB_ConnectionData = data;
KeReleaseSpinLock (&ifCB->ICB_Lock, oldIRQL);
}
}
/*++
D e q u e u e C o n n e c t i o n R e q u e s t
Routine Description:
Removes conection requset for the interface from the queue
Arguments:
ifCB - control block of the interface that needs to be
removed
Return Value:
None
--*/
VOID
DequeueConnectionRequest (
PINTERFACE_CB ifCB
) {
KIRQL cancelIRQL;
IoAcquireCancelSpinLock (&cancelIRQL);
if (IsListEntry (&ifCB->ICB_ConnectionLink)) {
RemoveEntryList (&ifCB->ICB_ConnectionLink);
InitializeListEntry (&ifCB->ICB_ConnectionLink);
}
IoReleaseCancelSpinLock (cancelIRQL);
}
/*++
F i l l C o n n e c t i o n R e q u e s t
Routine Description:
Fills the provided buffer with index of interface that needs
to be connected and packet that prompted the request
Arguments:
index - if index
packet - packet that prompted the request
data - pointer to IPX data (IPX header) inside of the packet
request - request buffer to fill
reqSize - size of request buffer
bytesCopied - bytesCopied into the request buffer
Return Value:
STATUS_SUCCESS - array was filled successfully
This routine assumes that there it is called only when there
are outstanding requests in the request queue
--*/
VOID
FillConnectionRequest (
IN ULONG index,
IN PNDIS_PACKET packet,
IN PUCHAR data,
IN OUT PFWD_DIAL_REQUEST request,
IN ULONG reqSize,
OUT PULONG bytesCopied
) {
PNDIS_BUFFER buf;
*bytesCopied = 0;
request->IfIndex = index;
NdisQueryPacket (packet, NULL, NULL, &buf, NULL);
do {
PVOID va;
UINT length;
NdisQueryBuffer (buf, &va, &length);
if (((PUCHAR)va<=data)
&& ((PUCHAR)va+length>data)) {
TdiCopyMdlToBuffer (buf,
data-(PUCHAR)va,
request,
FIELD_OFFSET (FWD_DIAL_REQUEST, Packet),
reqSize,
bytesCopied);
*bytesCopied += FIELD_OFFSET (FWD_DIAL_REQUEST, Packet);
break;
}
NdisGetNextBuffer (buf, &buf);
}
while (buf!=NULL);
}
/*++
F a i l C o n n e c t i o n R e q u e s t s
Routine Description:
Cleans up on connection request failure
Arguments:
InterfaceIndex - index of interface that could not be connected
Return Value:
STATUS_SUCCESS - clean up was successfull
STATUS_UNSUCCESSFUL - interface with this index does not exist
--*/
NTSTATUS
FailConnectionRequest (
IN ULONG InterfaceIndex
) {
PINTERFACE_CB ifCB;
KIRQL oldIRQL;
ASSERT (InterfaceIndex!=FWD_INTERNAL_INTERFACE_INDEX);
ifCB = GetInterfaceReference (InterfaceIndex);
if (ifCB!=NULL) {
IpxFwdDbgPrint (DBG_DIALREQS, DBG_WARNING,
("IpxFwd: Dial request failed for if %ld (icb:%08lx).\n",
ifCB->ICB_Index, ifCB));
ProcessInternalQueue (ifCB);
ProcessExternalQueue (ifCB);
KeAcquireSpinLock (&ifCB->ICB_Lock, &oldIRQL);
if (IS_IF_CONNECTING (ifCB)) {
SET_IF_NOT_CONNECTING (ifCB);
DequeueConnectionRequest (ifCB);
}
KeReleaseSpinLock (&ifCB->ICB_Lock, oldIRQL);
ReleaseInterfaceReference (ifCB);
return STATUS_SUCCESS;
}
else
return STATUS_UNSUCCESSFUL;
}
|