ReactOS 0.4.17-dev-966-gf06eace
udp.h File Reference
#include <pshpack1.h>
#include <poppack.h>
Include dependency graph for udp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  UDP_HEADER
 
struct  UDP_PSEUDO_HEADER
 
struct  UDP_STATISTICS
 

Macros

#define UDP_STARTING_PORT   0x8000
 
#define UDP_DYNAMIC_PORTS   0x8000
 

Typedefs

typedef struct UDP_HEADER UDP_HEADER
 
typedef struct UDP_HEADER * PUDP_HEADER
 
typedef struct UDP_PSEUDO_HEADER UDP_PSEUDO_HEADER
 
typedef struct UDP_PSEUDO_HEADER * PUDP_PSEUDO_HEADER
 
typedef struct UDP_STATISTICS UDP_STATISTICS
 
typedef struct UDP_STATISTICS * PUDP_STATISTICS
 

Functions

VOID UDPSend (PVOID Context, PDATAGRAM_SEND_REQUEST SendRequest)
 
NTSTATUS UDPSendDatagram (PADDRESS_FILE AddrFile, PTDI_CONNECTION_INFORMATION ConnInfo, PCHAR BufferData, ULONG DataSize, PULONG DataUsed)
 
VOID UDPReceive (PIP_INTERFACE Interface, PIP_PACKET IPPacket)
 
NTSTATUS UDPStartup (VOID)
 
NTSTATUS UDPShutdown (VOID)
 
UINT UDPAllocatePort (UINT HintPort)
 
VOID UDPFreePort (UINT Port)
 

Variables

UDP_STATISTICS UDPStats
 

Macro Definition Documentation

◆ UDP_DYNAMIC_PORTS

#define UDP_DYNAMIC_PORTS   0x8000

Definition at line 11 of file udp.h.

◆ UDP_STARTING_PORT

#define UDP_STARTING_PORT   0x8000

Definition at line 10 of file udp.h.

Typedef Documentation

◆ PUDP_HEADER

◆ PUDP_PSEUDO_HEADER

◆ PUDP_STATISTICS

◆ UDP_HEADER

◆ UDP_PSEUDO_HEADER

◆ UDP_STATISTICS

Function Documentation

◆ UDPAllocatePort()

UINT UDPAllocatePort ( UINT  HintPort)

Definition at line 452 of file udp.c.

452 {
453 if( HintPort ) {
454 if( AllocatePort( &UDPPorts, HintPort ) ) return HintPort;
455 else return (UINT)-1;
456 } else return AllocatePortFromRange
459}
BOOLEAN AllocatePort(PPORT_SET PortSet, ULONG Port)
Definition: ports.c:47
ULONG AllocatePortFromRange(PPORT_SET PortSet, ULONG Lowest, ULONG Highest)
Definition: ports.c:86
unsigned int UINT
Definition: sysinfo.c:13
#define UDP_STARTING_PORT
Definition: udp.h:10
#define UDP_DYNAMIC_PORTS
Definition: udp.h:11
PORT_SET UDPPorts
Definition: udp.c:14

Referenced by FileOpenAddress().

◆ UDPFreePort()

VOID UDPFreePort ( UINT  Port)

Definition at line 461 of file udp.c.

461 {
463}
VOID DeallocatePort(PPORT_SET PortSet, ULONG Port)
Definition: ports.c:35
CPPORT Port[4]
Definition: headless.c:38

Referenced by AddrFileFree().

◆ UDPReceive()

VOID UDPReceive ( PIP_INTERFACE  Interface,
PIP_PACKET  IPPacket 
)

Definition at line 310 of file udp.c.

320{
321 AF_SEARCH SearchContext;
323 PADDRESS_FILE AddrFile;
325 PIP_ADDRESS DstAddress, SrcAddress;
326 UINT DataSize, i;
327
328 TI_DbgPrint(MAX_TRACE, ("Called.\n"));
329
330 switch (IPPacket->Type) {
331 /* IPv4 packet */
332 case IP_ADDRESS_V4:
333 IPv4Header = IPPacket->Header;
334 DstAddress = &IPPacket->DstAddr;
335 SrcAddress = &IPPacket->SrcAddr;
336 break;
337
338 /* IPv6 packet */
339 case IP_ADDRESS_V6:
340 TI_DbgPrint(MIN_TRACE, ("Discarded IPv6 UDP datagram (%i bytes).\n", IPPacket->TotalSize));
341
342 /* FIXME: IPv6 is not supported */
343 return;
344
345 default:
346 return;
347 }
348
349 UDPHeader = (PUDP_HEADER)IPPacket->Data;
350
351 /* Calculate and validate UDP checksum */
354 WH2N(UDPHeader->Length));
355 if (i != DH2N(0x0000FFFF) && UDPHeader->Checksum != 0)
356 {
357 TI_DbgPrint(MIN_TRACE, ("Bad checksum on packet received.\n"));
358 return;
359 }
360
361 /* Sanity checks */
362 i = WH2N(UDPHeader->Length);
363 if ((i < sizeof(UDP_HEADER)) || (i > IPPacket->TotalSize - IPPacket->Position)) {
364 /* Incorrect or damaged packet received, discard it */
365 TI_DbgPrint(MIN_TRACE, ("Incorrect or damaged UDP packet received.\n"));
366 return;
367 }
368
369 DataSize = i - sizeof(UDP_HEADER);
370
371 /* Go to UDP data area */
372 IPPacket->Data = (PVOID)((ULONG_PTR)IPPacket->Data + sizeof(UDP_HEADER));
373
374 /* Locate a receive request on destination address file object
375 and deliver the packet if one is found. If there is no receive
376 request on the address file object, call the associated receive
377 handler. If no receive handler is registered, drop the packet */
378
379 AddrFile = AddrSearchFirst(DstAddress,
380 UDPHeader->DestPort,
382 &SearchContext);
383 if (AddrFile) {
384 do {
385 DGDeliverData(AddrFile,
386 SrcAddress,
387 DstAddress,
388 UDPHeader->SourcePort,
389 UDPHeader->DestPort,
390 IPPacket,
391 DataSize);
392 DereferenceObject(AddrFile);
393 } while ((AddrFile = AddrSearchNext(&SearchContext)) != NULL);
394 } else {
395 /* There are no open address files that will take this datagram */
396 /* FIXME: IPv4 only */
397 TI_DbgPrint(MID_TRACE, ("Cannot deliver IPv4 UDP datagram to address (0x%X).\n",
398 DN2H(DstAddress->Address.IPv4Address)));
399
400 /* FIXME: Send ICMP reply */
401 }
402 TI_DbgPrint(MAX_TRACE, ("Leaving.\n"));
403}
#define DH2N(dw)
Definition: addrconv.c:28
#define WH2N(w)
Definition: addrconv.c:40
#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
#define MIN_TRACE
Definition: debug.h:14
#define MID_TRACE
Definition: debug.h:15
#define MAX_TRACE
Definition: debug.h:16
ULONG UDPv4ChecksumCalculate(PIPv4_HEADER IPHeader, PUCHAR PacketBuffer, ULONG DataLength)
Definition: checksum.c:60
VOID DGDeliverData(PADDRESS_FILE AddrFile, PIP_ADDRESS SrcAddress, PIP_ADDRESS DstAddress, USHORT SrcPort, USHORT DstPort, PIP_PACKET IPPacket, UINT DataSize)
Definition: datagram.c:52
#define NULL
Definition: types.h:112
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
#define IP_ADDRESS_V6
Definition: ip.h:33
#define IP_ADDRESS_V4
Definition: ip.h:32
#define IPPROTO_UDP
Definition: ip.h:198
struct _tagUDPHeader UDPHeader
struct _tagIPv4Header IPv4Header
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
struct UDP_HEADER * PUDP_HEADER
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4755
Definition: ip.h:23
union IP_ADDRESS::@1204 Address
IPv4_RAW_ADDRESS IPv4Address
Definition: ip.h:26
Definition: udp.h:15
PVOID Data
Definition: ip.h:85
UCHAR Type
Definition: ip.h:79
IP_ADDRESS SrcAddr
Definition: ip.h:89
UINT Position
Definition: ip.h:87
PVOID Header
Definition: ip.h:83
IP_ADDRESS DstAddr
Definition: ip.h:90
UINT TotalSize
Definition: ip.h:86
#define DereferenceObject(Object)
Definition: titypes.h:24
void * PVOID
Definition: typedefs.h:50
uint32_t ULONG_PTR
Definition: typedefs.h:65
unsigned char * PUCHAR
Definition: typedefs.h:53

Referenced by UDPStartup().

◆ UDPSend()

VOID UDPSend ( PVOID  Context,
PDATAGRAM_SEND_REQUEST  SendRequest 
)

◆ UDPSendDatagram()

NTSTATUS UDPSendDatagram ( PADDRESS_FILE  AddrFile,
PTDI_CONNECTION_INFORMATION  ConnInfo,
PCHAR  BufferData,
ULONG  DataSize,
PULONG  DataUsed 
)

Definition at line 191 of file udp.c.

207{
209 PTA_IP_ADDRESS RemoteAddressTa = (PTA_IP_ADDRESS)ConnInfo->RemoteAddress;
212 USHORT RemotePort;
215 IP_PACKET LoopPacket;
216 PNEIGHBOR_CACHE_ENTRY LoopNCE = NULL;
217
218 LockObject(AddrFile);
219
220 TI_DbgPrint(MID_TRACE,("Sending Datagram(%x %x %x %d)\n",
221 AddrFile, ConnInfo, BufferData, DataSize));
222 TI_DbgPrint(MID_TRACE,("RemoteAddressTa: %x\n", RemoteAddressTa));
223
224 switch( RemoteAddressTa->Address[0].AddressType ) {
227 RemoteAddress.Address.IPv4Address =
228 RemoteAddressTa->Address[0].Address[0].in_addr;
229 RemotePort = RemoteAddressTa->Address[0].Address[0].sin_port;
230 break;
231
232 default:
233 UnlockObject(AddrFile);
234 return STATUS_UNSUCCESSFUL;
235 }
236
237 LocalAddress = AddrFile->Address;
239 {
240 /* If the local address is unspecified (0),
241 * then use the unicast address of the
242 * interface we're sending over
243 */
245 UnlockObject(AddrFile);
247 }
248
249 LocalAddress = NCE->Interface->Unicast;
250 }
251 else
252 {
253 if(!(NCE = NBLocateNeighbor( &LocalAddress, NULL ))) {
254 UnlockObject(AddrFile);
256 }
257 }
258
259 Status = BuildUDPPacket( AddrFile,
260 &Packet,
262 RemotePort,
264 AddrFile->Port,
265 BufferData,
266 DataSize );
267
268 if (!NT_SUCCESS(Status))
269 {
270 UnlockObject(AddrFile);
271 return Status;
272 }
273
274 /* NDIS does not loop broadcasts back to the sender, so deliver a local copy */
275 if (Loopback != NULL &&
276 NCE->Interface != Loopback &&
278 {
280 if (LoopNCE != NULL &&
281 !NT_SUCCESS(BuildUDPPacket(AddrFile,
282 &LoopPacket,
284 RemotePort,
286 AddrFile->Port,
287 BufferData,
288 DataSize)))
289 {
290 LoopNCE = NULL;
291 }
292 }
293
294 UnlockObject(AddrFile);
295
297
298 if (LoopNCE != NULL)
299 IPSendDatagram(&LoopPacket, LoopNCE);
300
301 if (!NT_SUCCESS(Status))
302 return Status;
303
304 *DataUsed = DataSize;
305
306 return STATUS_SUCCESS;
307}
BOOLEAN AddrIsUnspecified(PIP_ADDRESS Address)
Definition: address.c:113
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
PNEIGHBOR_CACHE_ENTRY RouteGetRouteToDestination(PIP_ADDRESS Destination)
Definition: router.c:330
Status
Definition: gdiplustypes.h:24
NTSTATUS BuildUDPPacket(PADDRESS_FILE AddrFile, PIP_PACKET Packet, PIP_ADDRESS RemoteAddress, USHORT RemotePort, PIP_ADDRESS LocalAddress, USHORT LocalPort, PCHAR DataBuffer, UINT DataLen)
Definition: udp.c:78
static BOOLEAN UDPIsBroadcastAddress(_In_ PIP_ADDRESS Address)
Checks whether an address is the limited broadcast address or the directed broadcast address of a non...
Definition: udp.c:163
PIP_INTERFACE Loopback
Definition: loopback.c:13
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1549
PNEIGHBOR_CACHE_ENTRY NBLocateNeighbor(PIP_ADDRESS Address, PIP_INTERFACE Interface)
Definition: neighbor.c:424
#define STATUS_NETWORK_UNREACHABLE
Definition: ntstatus.h:826
unsigned short USHORT
Definition: pedump.c:61
#define STATUS_SUCCESS
Definition: shellext.h:65
Definition: neighbor.h:28
USHORT Port
Definition: titypes.h:120
IP_ADDRESS Address
Definition: titypes.h:117
IP_ADDRESS Unicast
Definition: ip.h:160
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
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_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 FileOpenAddress().

◆ UDPShutdown()

NTSTATUS UDPShutdown ( VOID  )

Definition at line 431 of file udp.c.

438{
439 if (!UDPInitialized)
440 return STATUS_SUCCESS;
441
443
444 /* Deregister this protocol with IP layer */
446
448
449 return STATUS_SUCCESS;
450}
#define FALSE
Definition: types.h:117
VOID IPRegisterProtocol(UINT ProtocolNumber, IP_PROTOCOL_HANDLER Handler)
Definition: ip.c:386
VOID PortsShutdown(PPORT_SET PortSet)
Definition: ports.c:31
BOOLEAN UDPInitialized
Definition: udp.c:13

Referenced by TiUnload().

◆ UDPStartup()

NTSTATUS UDPStartup ( VOID  )

Definition at line 406 of file udp.c.

413{
415
417
419
420 if( !NT_SUCCESS(Status) ) return Status;
421
422 /* Register this protocol with IP layer */
424
426
427 return STATUS_SUCCESS;
428}
#define TRUE
Definition: types.h:120
NTSTATUS PortsStartup(PPORT_SET PortSet, UINT StartingPort, UINT PortsToManage)
Definition: ports.c:13
UDP_STATISTICS UDPStats
Definition: main.c:30
VOID UDPReceive(PIP_INTERFACE Interface, PIP_PACKET IPPacket)
Definition: udp.c:310
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

Referenced by DriverEntry().

Variable Documentation

◆ UDPStats

UDP_STATISTICS UDPStats
extern

Definition at line 30 of file main.c.

Referenced by RawIPStartup(), and UDPStartup().