ReactOS 0.4.15-dev-8102-g108db8f
rawip.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

NTSTATUS RawIPSendDatagram (PADDRESS_FILE AddrFile, PTDI_CONNECTION_INFORMATION ConnInfo, PCHAR Buffer, ULONG DataSize, PULONG DataUsed)
 
VOID RawIpReceive (PIP_INTERFACE Interface, PIP_PACKET IPPacket)
 
NTSTATUS RawIPStartup (VOID)
 
NTSTATUS RawIPShutdown (VOID)
 
NTSTATUS AddGenericHeaderIPv4 (PADDRESS_FILE AddrFile, PIP_ADDRESS RemoteAddress, USHORT RemotePort, PIP_ADDRESS LocalAddress, USHORT LocalPort, PIP_PACKET IPPacket, UINT DataLength, UINT Protocol, UINT ExtraLength, PVOID *NextHeader)
 
NTSTATUS BuildRawIpPacket (PADDRESS_FILE AddrFile, PIP_PACKET Packet, PIP_ADDRESS RemoteAddress, USHORT RemotePort, PIP_ADDRESS LocalAddress, USHORT LocalPort, PCHAR DataBuffer, UINT DataLen)
 

Function Documentation

◆ AddGenericHeaderIPv4()

NTSTATUS AddGenericHeaderIPv4 ( PADDRESS_FILE  AddrFile,
PIP_ADDRESS  RemoteAddress,
USHORT  RemotePort,
PIP_ADDRESS  LocalAddress,
USHORT  LocalPort,
PIP_PACKET  IPPacket,
UINT  DataLength,
UINT  Protocol,
UINT  ExtraLength,
PVOID NextHeader 
)

Definition at line 13 of file rawip.c.

34{
37
38 TI_DbgPrint(MID_TRACE, ("Packet: %x NdisPacket %x\n",
39 IPPacket, IPPacket->NdisPacket));
40
41 BufferSize = sizeof(IPv4_HEADER) + ExtraLength;
42
43 GetDataPtr( IPPacket->NdisPacket,
44 0,
45 (PCHAR *)&IPPacket->Header,
46 &IPPacket->TotalSize );
47 IPPacket->MappedHeader = TRUE;
48
49 IPPacket->HeaderSize = sizeof(IPv4_HEADER);
50
51 TI_DbgPrint(MAX_TRACE, ("Allocated %d bytes for headers at 0x%X.\n",
52 BufferSize, IPPacket->Header));
53 TI_DbgPrint(MAX_TRACE, ("Packet total length %d\n", IPPacket->TotalSize));
54
55 /* Build IPv4 header */
56 IPHeader = (PIPv4_HEADER)IPPacket->Header;
57 /* Version = 4, Length = 5 DWORDs */
58 IPHeader->VerIHL = 0x45;
59 /* Normal Type-of-Service */
60 IPHeader->Tos = 0;
61 /* Length of header and data */
62 IPHeader->TotalLength = WH2N((USHORT)IPPacket->TotalSize);
63 /* Identification */
64 IPHeader->Id = (USHORT)Random();
65 /* One fragment at offset 0 */
66 IPHeader->FlagsFragOfs = 0;
67 /* Time-to-Live */
68 IPHeader->Ttl = AddrFile->TTL;
69 /* Protocol */
70 IPHeader->Protocol = Protocol;
71 /* Checksum is 0 (for later calculation of this) */
72 IPHeader->Checksum = 0;
73 /* Source address */
74 IPHeader->SrcAddr = LocalAddress->Address.IPv4Address;
75 /* Destination address. FIXME: IPv4 only */
76 IPHeader->DstAddr = RemoteAddress->Address.IPv4Address;
77
78 /* Build RawIp header */
79 *NextHeader = (((PCHAR)IPHeader) + sizeof(IPv4_HEADER));
80 IPPacket->Data = ((PCHAR)*NextHeader) + ExtraLength;
81
82 return STATUS_SUCCESS;
83}
#define WH2N(w)
Definition: addrconv.c:40
#define MID_TRACE
Definition: debug.h:15
#define MAX_TRACE
Definition: debug.h:16
#define BufferSize
Definition: mmc.h:75
#define TRUE
Definition: types.h:120
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
struct IPv4_HEADER * PIPv4_HEADER
void GetDataPtr(PNDIS_PACKET Packet, UINT Offset, PCHAR *DataOut, PUINT Size)
Definition: routines.c:65
#define PCHAR
Definition: match.c:90
unsigned short USHORT
Definition: pedump.c:61
UINT Random(VOID)
Definition: routines.c:16
#define STATUS_SUCCESS
Definition: shellext.h:65
UCHAR TTL
Definition: titypes.h:122
PVOID Data
Definition: ip.h:85
BOOLEAN MappedHeader
Definition: ip.h:81
PNDIS_PACKET NdisPacket
Definition: ip.h:88
UINT HeaderSize
Definition: ip.h:84
PVOID Header
Definition: ip.h:83
UINT TotalSize
Definition: ip.h:86
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR LocalAddress
Definition: wsk.h:171
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR RemoteAddress
Definition: wsk.h:172

Referenced by AddUDPHeaderIPv4(), and BuildRawIpPacket().

◆ BuildRawIpPacket()

NTSTATUS BuildRawIpPacket ( PADDRESS_FILE  AddrFile,
PIP_PACKET  Packet,
PIP_ADDRESS  RemoteAddress,
USHORT  RemotePort,
PIP_ADDRESS  LocalAddress,
USHORT  LocalPort,
PCHAR  DataBuffer,
UINT  DataLen 
)

Definition at line 86 of file rawip.c.

105{
107 PCHAR Payload;
108
109 TI_DbgPrint(MAX_TRACE, ("Called.\n"));
110
111 /* FIXME: Assumes IPv4 */
113
114 Packet->TotalSize = sizeof(IPv4_HEADER) + DataLen;
115
116 /* Prepare packet */
117 Status = AllocatePacketWithBuffer( &Packet->NdisPacket,
118 NULL,
119 Packet->TotalSize );
120
121 if( !NT_SUCCESS(Status) ) return Status;
122
123 TI_DbgPrint(MID_TRACE, ("Allocated packet: %x\n", Packet->NdisPacket));
124 TI_DbgPrint(MID_TRACE, ("Local Addr : %s\n", A2S(LocalAddress)));
125 TI_DbgPrint(MID_TRACE, ("Remote Addr: %s\n", A2S(RemoteAddress)));
126
127 switch (RemoteAddress->Type) {
128 case IP_ADDRESS_V4:
130 (AddrFile, RemoteAddress, RemotePort,
131 LocalAddress, LocalPort, Packet, DataLen,
132 AddrFile->Protocol,
133 0, (PVOID *)&Payload );
134 break;
135 case IP_ADDRESS_V6:
136 /* FIXME: Support IPv6 */
138 TI_DbgPrint(MIN_TRACE, ("IPv6 RawIp datagrams are not supported.\n"));
139 break;
140
141 default:
143 TI_DbgPrint(MIN_TRACE, ("Bad Address Type %d\n", RemoteAddress->Type));
144 break;
145 }
146
147 if( !NT_SUCCESS(Status) ) {
148 TI_DbgPrint(MIN_TRACE, ("Cannot add header. Status = (0x%X)\n",
149 Status));
150 Packet->Free(Packet);
151 return Status;
152 }
153
154 TI_DbgPrint(MID_TRACE, ("Copying data (hdr %x data %x (%d))\n",
155 Packet->Header, Packet->Data,
156 (PCHAR)Packet->Data - (PCHAR)Packet->Header));
157
158 RtlCopyMemory( Packet->Data, DataBuffer, DataLen );
159
160 Packet->Flags |= IP_PACKET_FLAG_RAW;
161
162 TI_DbgPrint(MID_TRACE, ("Displaying packet\n"));
163
165
166 TI_DbgPrint(MID_TRACE, ("Leaving\n"));
167
168 return STATUS_SUCCESS;
169}
LONG NTSTATUS
Definition: precomp.h:26
#define MIN_TRACE
Definition: debug.h:14
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IP_PACKET_FLAG_RAW
Definition: ip.h:93
#define IP_ADDRESS_V6
Definition: ip.h:33
#define IP_ADDRESS_V4
Definition: ip.h:32
PIP_PACKET IPInitializePacket(PIP_PACKET IPPacket, ULONG Type)
Definition: ip.c:92
PCHAR A2S(PIP_ADDRESS Address)
Definition: address.c:17
Status
Definition: gdiplustypes.h:25
#define AllocatePacketWithBuffer(x, y, z)
Definition: memtrack.h:7
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1549
NTSTATUS AddGenericHeaderIPv4(PADDRESS_FILE AddrFile, PIP_ADDRESS RemoteAddress, USHORT RemotePort, PIP_ADDRESS LocalAddress, USHORT LocalPort, PIP_PACKET IPPacket, UINT DataLength, UINT Protocol, UINT ExtraLength, PVOID *NextHeader)
Definition: rawip.c:13
#define DISPLAY_IP_PACKET(x)
Definition: routines.h:69
USHORT Protocol
Definition: titypes.h:119
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

Referenced by ICMPReply(), and RawIPSendDatagram().

◆ RawIpReceive()

VOID RawIpReceive ( PIP_INTERFACE  Interface,
PIP_PACKET  IPPacket 
)

Definition at line 266 of file rawip.c.

276{
277 AF_SEARCH SearchContext;
279 PADDRESS_FILE AddrFile;
280 PIP_ADDRESS DstAddress, SrcAddress;
282
283 TI_DbgPrint(MAX_TRACE, ("Called.\n"));
284
285 switch (IPPacket->Type) {
286 /* IPv4 packet */
287 case IP_ADDRESS_V4:
288 IPv4Header = IPPacket->Header;
289 DstAddress = &IPPacket->DstAddr;
290 SrcAddress = &IPPacket->SrcAddr;
291 DataSize = IPPacket->TotalSize;
292 break;
293
294 /* IPv6 packet */
295 case IP_ADDRESS_V6:
296 TI_DbgPrint(MIN_TRACE, ("Discarded IPv6 datagram (%i bytes).\n", IPPacket->TotalSize));
297
298 /* FIXME: IPv6 is not supported */
299 return;
300
301 default:
302 return;
303 }
304
305 /* Locate a receive request on destination address file object
306 and deliver the packet if one is found. If there is no receive
307 request on the address file object, call the associated receive
308 handler. If no receive handler is registered, drop the packet */
309
310 AddrFile = AddrSearchFirst(DstAddress,
311 0,
312 IPv4Header->Protocol,
313 &SearchContext);
314 if (AddrFile) {
315 do {
316 DGDeliverData(AddrFile,
317 SrcAddress,
318 DstAddress,
319 0,
320 0,
321 IPPacket,
322 DataSize);
323 DereferenceObject(AddrFile);
324 } while ((AddrFile = AddrSearchNext(&SearchContext)) != NULL);
325 } else {
326 /* There are no open address files that will take this datagram */
327 /* FIXME: IPv4 only */
328 TI_DbgPrint(MID_TRACE, ("Cannot deliver IPv4 raw datagram to address (0x%X).\n",
329 DN2H(DstAddress->Address.IPv4Address)));
330
331 /* FIXME: Send ICMP reply */
332 }
333 TI_DbgPrint(MAX_TRACE, ("Leaving.\n"));
334}
#define DN2H(dw)
Definition: addrconv.c:21
PADDRESS_FILE AddrSearchFirst(PIP_ADDRESS Address, USHORT Port, USHORT Protocol, PAF_SEARCH SearchContext)
Definition: fileobjs.c:38
PADDRESS_FILE AddrSearchNext(PAF_SEARCH SearchContext)
Definition: fileobjs.c:231
VOID DGDeliverData(PADDRESS_FILE AddrFile, PIP_ADDRESS SrcAddress, PIP_ADDRESS DstAddress, USHORT SrcPort, USHORT DstPort, PIP_PACKET IPPacket, UINT DataSize)
Definition: datagram.c:52
struct _tagIPv4Header IPv4Header
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4755
unsigned int UINT
Definition: ndis.h:50
Definition: ip.h:23
union IP_ADDRESS::@1008 Address
IPv4_RAW_ADDRESS IPv4Address
Definition: ip.h:26
UCHAR Type
Definition: ip.h:79
IP_ADDRESS SrcAddr
Definition: ip.h:89
IP_ADDRESS DstAddr
Definition: ip.h:90
#define DereferenceObject(Object)
Definition: titypes.h:24

Referenced by ICMPReceive(), and RawIPStartup().

◆ RawIPSendDatagram()

NTSTATUS RawIPSendDatagram ( PADDRESS_FILE  AddrFile,
PTDI_CONNECTION_INFORMATION  ConnInfo,
PCHAR  Buffer,
ULONG  DataSize,
PULONG  DataUsed 
)

Definition at line 171 of file rawip.c.

187{
189 PTA_IP_ADDRESS RemoteAddressTa = (PTA_IP_ADDRESS)ConnInfo->RemoteAddress;
191 USHORT RemotePort;
194
195 LockObject(AddrFile);
196
197 TI_DbgPrint(MID_TRACE,("Sending Datagram(%x %x %x %d)\n",
198 AddrFile, ConnInfo, BufferData, DataSize));
199 TI_DbgPrint(MID_TRACE,("RemoteAddressTa: %x\n", RemoteAddressTa));
200
201 switch( RemoteAddressTa->Address[0].AddressType ) {
204 RemoteAddress.Address.IPv4Address =
205 RemoteAddressTa->Address[0].Address[0].in_addr;
206 RemotePort = RemoteAddressTa->Address[0].Address[0].sin_port;
207 break;
208
209 default:
210 UnlockObject(AddrFile);
211 return STATUS_UNSUCCESSFUL;
212 }
213
214 TI_DbgPrint(MID_TRACE,("About to get route to destination\n"));
215
216 LocalAddress = AddrFile->Address;
218 {
219 /* If the local address is unspecified (0),
220 * then use the unicast address of the
221 * interface we're sending over
222 */
224 UnlockObject(AddrFile);
226 }
227
228 LocalAddress = NCE->Interface->Unicast;
229 }
230 else
231 {
232 if(!(NCE = NBLocateNeighbor( &LocalAddress, NULL ))) {
233 UnlockObject(AddrFile);
235 }
236 }
237
238 Status = BuildRawIpPacket( AddrFile,
239 &Packet,
241 RemotePort,
243 AddrFile->Port,
244 BufferData,
245 DataSize );
246
247 UnlockObject(AddrFile);
248
249 if( !NT_SUCCESS(Status) )
250 return Status;
251
252 TI_DbgPrint(MID_TRACE,("About to send datagram\n"));
253
255 if (!NT_SUCCESS(Status))
256 return Status;
257
258 *DataUsed = DataSize;
259
260 TI_DbgPrint(MID_TRACE,("Leaving\n"));
261
262 return STATUS_SUCCESS;
263}
BOOLEAN AddrIsUnspecified(PIP_ADDRESS Address)
Definition: address.c:113
PNEIGHBOR_CACHE_ENTRY RouteGetRouteToDestination(PIP_ADDRESS Destination)
Definition: router.c:300
PNEIGHBOR_CACHE_ENTRY NBLocateNeighbor(PIP_ADDRESS Address, PIP_INTERFACE Interface)
Definition: neighbor.c:417
#define STATUS_NETWORK_UNREACHABLE
Definition: ntstatus.h:704
NTSTATUS BuildRawIpPacket(PADDRESS_FILE AddrFile, PIP_PACKET Packet, PIP_ADDRESS RemoteAddress, USHORT RemotePort, PIP_ADDRESS LocalAddress, USHORT LocalPort, PCHAR DataBuffer, UINT DataLen)
Definition: rawip.c:86
Definition: neighbor.h:28
USHORT Port
Definition: titypes.h:120
IP_ADDRESS Address
Definition: titypes.h:117
Definition: ip.h:77
struct _TA_ADDRESS_IP::_AddrIp Address[1]
struct _TA_ADDRESS_IP * PTA_IP_ADDRESS
#define TDI_ADDRESS_TYPE_IP
Definition: tdi.h:345
#define UnlockObject(Object)
Definition: titypes.h:44
#define LockObject(Object)
Definition: titypes.h:34
NTSTATUS IPSendDatagram(PIP_PACKET IPPacket, PNEIGHBOR_CACHE_ENTRY NCE)
Definition: transmit.c:223
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135

Referenced by FileOpenAddress(), and ICMPSendDatagram().

◆ RawIPShutdown()

NTSTATUS RawIPShutdown ( VOID  )

Definition at line 353 of file rawip.c.

359{
360 /* Deregister this protocol with IP layer */
362
363 return STATUS_SUCCESS;
364}
#define IPPROTO_RAW
Definition: ip.h:192
VOID IPRegisterProtocol(UINT ProtocolNumber, IP_PROTOCOL_HANDLER Handler)
Definition: ip.c:386

Referenced by TiUnload().

◆ RawIPStartup()

NTSTATUS RawIPStartup ( VOID  )

Definition at line 337 of file rawip.c.

343{
345
346 /* Register this protocol with IP layer */
348
349 return STATUS_SUCCESS;
350}
UDP_STATISTICS UDPStats
Definition: main.c:30
VOID RawIpReceive(PIP_INTERFACE Interface, PIP_PACKET IPPacket)
Definition: rawip.c:266
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

Referenced by DriverEntry().