1 diff -ubwrp original_passthru/miniport.c kipfw/miniport.c
2 --- original_passthru/miniport.c 2012-08-01 14:34:15.096679600 +0200
3 +++ kipfw/miniport.c 2012-08-01 14:34:11.377929600 +0200
4 @@ -223,6 +223,7 @@ Return Value:
6 // Use NDIS 5.1 packet stacking:
\r
8 + if (0) // XXX IPFW - make sure we don't go in here
10 PNDIS_PACKET_STACK pStack;
\r
12 @@ -347,6 +348,25 @@ Return Value:
14 MediaSpecificInfoSize);
\r
16 +#if 1 /* IPFW: query the firewall */
17 + /* if dummynet keeps the packet, we mimic success.
18 + * otherwise continue as usual.
21 + int ret = ipfw2_qhandler_w32(MyPacket, OUTGOING,
22 + MiniportAdapterContext);
25 + return NDIS_STATUS_FAILURE;
26 + else { //dummynet kept the packet
28 + NdisIMCopySendCompletePerPacketInfo (Packet, MyPacket);
30 + return NDIS_STATUS_SUCCESS; //otherwise simply continue
34 +#endif /* end of IPFW code */
37 pAdapt->BindingHandle,
\r
38 diff -ubwrp original_passthru/passthru.c kipfw/passthru.c
39 --- original_passthru/passthru.c 2012-08-01 14:34:15.268554600 +0200
40 +++ kipfw/passthru.c 2012-08-01 14:34:11.534179600 +0200
41 @@ -47,8 +47,15 @@ NDIS_HANDLE NdisWrapperHandle;
42 // To support ioctls from user-mode:
\r
45 -#define LINKNAME_STRING L"\\DosDevices\\Passthru"
\r
46 -#define NTDEVICE_STRING L"\\Device\\Passthru"
\r
48 +#define STR(x) STR2(x)
49 +#define DOSPREFIX "\\DosDevices\\"
50 +#define NTPREFIX "\\Device\\"
51 +#define WIDEN2(x) L ## x
52 +#define WIDEN(x) WIDEN2(x)
53 +#define LINKNAME_STRING WIDEN(DOSPREFIX) WIDEN(STR(MODULENAME))
54 +#define NTDEVICE_STRING WIDEN(NTPREFIX) WIDEN(STR(MODULENAME))
55 +#define PROTOCOLNAME_STRING WIDEN(STR(MODULENAME))
57 NDIS_HANDLE NdisDeviceHandle = NULL;
\r
58 PDEVICE_OBJECT ControlDeviceObject = NULL;
\r
59 @@ -136,8 +143,8 @@ Return Value:
60 // Either the Send or the SendPackets handler should be specified.
\r
61 // If SendPackets handler is specified, SendHandler is ignored
\r
63 - MChars.SendHandler = NULL; // MPSend;
\r
64 - MChars.SendPacketsHandler = MPSendPackets;
\r
65 + MChars.SendHandler = MPSend; // IPFW: use MPSend, not SendPackets
66 + MChars.SendPacketsHandler = NULL;
68 Status = NdisIMRegisterLayeredMiniport(NdisWrapperHandle,
\r
70 @@ -165,7 +172,7 @@ Return Value:
71 // This is needed to ensure that NDIS can correctly determine
\r
72 // the binding and call us to bind to miniports below.
\r
74 - NdisInitUnicodeString(&Name, L"Passthru"); // Protocol name
\r
75 + NdisInitUnicodeString(&Name, PROTOCOLNAME_STRING); // Protocol name
77 PChars.OpenAdapterCompleteHandler = PtOpenAdapterComplete;
\r
78 PChars.CloseAdapterCompleteHandler = PtCloseAdapterComplete;
\r
79 @@ -205,6 +212,8 @@ Return Value:
80 NdisTerminateWrapper(NdisWrapperHandle, NULL);
\r
83 + ipfw_module_init(); // IPFW - start the system
88 @@ -276,7 +285,8 @@ Return Value:
89 DispatchTable[IRP_MJ_CREATE] = PtDispatch;
\r
90 DispatchTable[IRP_MJ_CLEANUP] = PtDispatch;
\r
91 DispatchTable[IRP_MJ_CLOSE] = PtDispatch;
\r
92 - DispatchTable[IRP_MJ_DEVICE_CONTROL] = PtDispatch;
\r
93 + // IPFW we use DevIoControl ?
94 + DispatchTable[IRP_MJ_DEVICE_CONTROL] = DevIoControl;
97 NdisInitUnicodeString(&DeviceName, NTDEVICE_STRING);
\r
98 @@ -453,6 +463,7 @@ PtUnload(
100 NdisFreeSpinLock(&GlobalLock);
\r
102 + ipfw_module_exit(); // IPFW unloading dummynet
104 DBGPRINT(("PtUnload: done!\n"));
\r
107 diff -ubwrp original_passthru/passthru.h kipfw/passthru.h
108 --- original_passthru/passthru.h 2012-08-01 14:34:15.049804600 +0200
109 +++ kipfw/passthru.h 2012-08-01 14:34:11.362304600 +0200
110 @@ -61,6 +61,13 @@ PtDispatch(
114 +DRIVER_DISPATCH DevIoControl;
\r
117 + IN PDEVICE_OBJECT pDeviceObject,
\r
124 @@ -366,6 +373,7 @@ PtDereferenceAdapt(
125 typedef struct _SEND_RSVD
\r
127 PNDIS_PACKET OriginalPkt;
\r
128 + struct mbuf* pMbuf; // IPFW extension, reference to the mbuf
\r
129 } SEND_RSVD, *PSEND_RSVD;
\r
132 @@ -376,6 +384,7 @@ typedef struct _SEND_RSVD
133 typedef struct _RECV_RSVD
\r
135 PNDIS_PACKET OriginalPkt;
\r
136 + struct mbuf* pMbuf; // IPFW extension, reference to the mbuf
\r
137 } RECV_RSVD, *PRECV_RSVD;
\r
139 C_ASSERT(sizeof(RECV_RSVD) <= sizeof(((PNDIS_PACKET)0)->MiniportReserved));
\r
140 @@ -475,3 +484,17 @@ IsIMDeviceStateOn(
142 #define IsIMDeviceStateOn(_pP) ((_pP)->MPDeviceState == NdisDeviceStateD0 && (_pP)->PTDeviceState == NdisDeviceStateD0 )
\r
144 +#include "winmissing.h"
\r
146 +int ipfw_module_init(void);
\r
147 +void ipfw_module_exit(void);
\r
148 +int ipfw2_qhandler_w32(PNDIS_PACKET pNdisPacket, int direction,
\r
149 + NDIS_HANDLE Context);
\r
150 +int ipfw2_qhandler_w32_oldstyle(int direction, NDIS_HANDLE ProtocolBindingContext,
\r
151 + unsigned char* HeaderBuffer, unsigned int HeaderBufferSize,
\r
152 + unsigned char* LookAheadBuffer, unsigned int LookAheadBufferSize,
\r
153 + unsigned int PacketSize);
\r
154 +void CleanupReinjected(PNDIS_PACKET Packet, struct mbuf* m, PADAPT pAdapt);
\r
155 +void hexdump(PUCHAR,int, const char *);
\r
158 \ Manca newline alla fine del file
159 Solo in original_passthru: passthru.htm
160 Solo in original_passthru: passthru.rc
161 diff -ubwrp original_passthru/protocol.c kipfw/protocol.c
162 --- original_passthru/protocol.c 2012-08-01 14:34:15.112304600 +0200
163 +++ kipfw/protocol.c 2012-08-01 14:34:11.409179600 +0200
164 @@ -841,6 +841,14 @@ Return Value:
165 SendRsvd = (PSEND_RSVD)(Packet->ProtocolReserved);
\r
166 Pkt = SendRsvd->OriginalPkt;
\r
168 +#if 1 // IPFW - new code
169 + //DbgPrint("SendComplete: packet %p pkt %p\n", Packet, Pkt);
170 + if (Pkt == NULL) { //this is a reinjected packet, with no 'father'
171 + CleanupReinjected(Packet, SendRsvd->pMbuf, pAdapt);
177 NdisIMCopySendCompletePerPacketInfo (Pkt, Packet);
\r
179 @@ -1021,6 +1029,13 @@ Return Value:
181 if (pAdapt->MiniportHandle != NULL)
\r
183 +#if 1 /* IPFW: query the firewall */
185 + ret = ipfw2_qhandler_w32(MyPacket, INCOMING,
186 + ProtocolBindingContext);
188 + return 0; //otherwise simply continue
189 +#endif /* end of IPFW code */
190 NdisMIndicateReceivePacket(pAdapt->MiniportHandle, &MyPacket, 1);
\r
193 @@ -1055,6 +1070,13 @@ Return Value:
195 case NdisMedium802_3:
\r
196 case NdisMediumWan:
\r
197 + //DbgPrint("EthIndicateReceive context %p, header at %p len %u, lookahead at %p len %u, packetsize %u\n",ProtocolBindingContext,HeaderBuffer,HeaderBufferSize,LookAheadBuffer,LookAheadBufferSize,PacketSize);
198 + //hexdump(HeaderBuffer,HeaderBufferSize+LookAheadBufferSize,"EthIndicateReceive");
200 + int ret = ipfw2_qhandler_w32_oldstyle(INCOMING, ProtocolBindingContext, HeaderBuffer, HeaderBufferSize, LookAheadBuffer, LookAheadBufferSize, PacketSize);
202 + return NDIS_STATUS_SUCCESS;
204 NdisMEthIndicateReceive(pAdapt->MiniportHandle,
\r
207 @@ -1120,6 +1142,21 @@ Return Value:
208 PADAPT pAdapt =(PADAPT)ProtocolBindingContext;
\r
209 ULONG Proc = KeGetCurrentProcessorNumber();
\r
211 + /* Warning: this is a poor implementation of the PtReceiveComplete
212 + * made by MS, and it's a well known (but never fixed) issue.
213 + * Since the ProcessorNumber here can be different from the one
214 + * that processed the PtReceive, sometimes NdisMEthIndicateReceiveComplete
215 + * will not be called, causing poor performance in the incoming traffic.
216 + * In our driver, PtReceive is called for IP packets ONLY by particulary
217 + * old NIC drivers, and the poor performance can be seen even
218 + * in traffic not handled by ipfw or dummynet.
219 + * Fortunately, this is quite rare, all the incoming IP packets
220 + * will arrive through PtReceivePacket, and this callback will never
221 + * be called. For reinjected traffic, a workaround is done
222 + * commuting the ReceivedIndicationFlag and calling
223 + * NdisMEthIndicateReceiveComplete manually for each packet.
226 if (((pAdapt->MiniportHandle != NULL)
\r
227 && (pAdapt->MPDeviceState == NdisDeviceStateD0))
\r
228 && (pAdapt->ReceivedIndicationFlags[Proc]))
\r
229 @@ -1199,7 +1236,7 @@ Return Value:
230 // See also: PtReceive().
\r
232 (VOID)NdisIMGetCurrentPacketStack(Packet, &Remaining);
\r
234 + if (0 && Remaining)
237 // We can reuse "Packet". Indicate it up and be done with it.
\r
238 @@ -1247,6 +1284,13 @@ Return Value:
240 if (pAdapt->MiniportHandle != NULL)
\r
242 +#if 1 /* IPFW: query the firewall */
244 + ret = ipfw2_qhandler_w32(MyPacket, INCOMING,
245 + ProtocolBindingContext);
247 + return 0; //otherwise simply continue
248 +#endif /* end of IPFW code */
249 NdisMIndicateReceivePacket(pAdapt->MiniportHandle, &MyPacket, 1);
\r