ReactOS  0.4.13-dev-563-g0561610
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_HEADERPUDP_HEADER
 
typedef struct UDP_PSEUDO_HEADER UDP_PSEUDO_HEADER
 
typedef struct UDP_PSEUDO_HEADERPUDP_PSEUDO_HEADER
 
typedef struct UDP_STATISTICS UDP_STATISTICS
 
typedef struct UDP_STATISTICSPUDP_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 385 of file udp.c.

385  {
386  if( HintPort ) {
387  if( AllocatePort( &UDPPorts, HintPort ) ) return HintPort;
388  else return (UINT)-1;
389  } else return AllocatePortFromRange
392 }
PORT_SET UDPPorts
Definition: udp.c:14
BOOLEAN AllocatePort(PPORT_SET PortSet, ULONG Port)
Definition: ports.c:47
#define UDP_DYNAMIC_PORTS
Definition: udp.h:11
#define UDP_STARTING_PORT
Definition: udp.h:10
ULONG AllocatePortFromRange(PPORT_SET PortSet, ULONG Lowest, ULONG Highest)
Definition: ports.c:86
unsigned int UINT
Definition: ndis.h:50

Referenced by FileOpenAddress().

◆ UDPFreePort()

VOID UDPFreePort ( UINT  Port)

Definition at line 394 of file udp.c.

394  {
396 }
CPPORT Port[4]
Definition: headless.c:34
VOID DeallocatePort(PPORT_SET PortSet, ULONG Port)
Definition: ports.c:35
PORT_SET UDPPorts
Definition: udp.c:14

Referenced by AddrFileFree().

◆ UDPReceive()

VOID UDPReceive ( PIP_INTERFACE  Interface,
PIP_PACKET  IPPacket 
)

Definition at line 241 of file udp.c.

251 {
252  AF_SEARCH SearchContext;
253  PIPv4_HEADER IPv4Header;
254  PADDRESS_FILE AddrFile;
255  PUDP_HEADER UDPHeader;
256  PIP_ADDRESS DstAddress, SrcAddress;
257  UINT DataSize, i;
258 
259  TI_DbgPrint(MAX_TRACE, ("Called.\n"));
260 
261  switch (IPPacket->Type) {
262  /* IPv4 packet */
263  case IP_ADDRESS_V4:
264  IPv4Header = IPPacket->Header;
265  DstAddress = &IPPacket->DstAddr;
266  SrcAddress = &IPPacket->SrcAddr;
267  break;
268 
269  /* IPv6 packet */
270  case IP_ADDRESS_V6:
271  TI_DbgPrint(MIN_TRACE, ("Discarded IPv6 UDP datagram (%i bytes).\n", IPPacket->TotalSize));
272 
273  /* FIXME: IPv6 is not supported */
274  return;
275 
276  default:
277  return;
278  }
279 
280  UDPHeader = (PUDP_HEADER)IPPacket->Data;
281 
282  /* Calculate and validate UDP checksum */
283  i = UDPv4ChecksumCalculate(IPv4Header,
284  (PUCHAR)UDPHeader,
285  WH2N(UDPHeader->Length));
286  if (i != DH2N(0x0000FFFF) && UDPHeader->Checksum != 0)
287  {
288  TI_DbgPrint(MIN_TRACE, ("Bad checksum on packet received.\n"));
289  return;
290  }
291 
292  /* Sanity checks */
293  i = WH2N(UDPHeader->Length);
294  if ((i < sizeof(UDP_HEADER)) || (i > IPPacket->TotalSize - IPPacket->Position)) {
295  /* Incorrect or damaged packet received, discard it */
296  TI_DbgPrint(MIN_TRACE, ("Incorrect or damaged UDP packet received.\n"));
297  return;
298  }
299 
300  DataSize = i - sizeof(UDP_HEADER);
301 
302  /* Go to UDP data area */
303  IPPacket->Data = (PVOID)((ULONG_PTR)IPPacket->Data + sizeof(UDP_HEADER));
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  UDPHeader->DestPort,
312  IPPROTO_UDP,
313  &SearchContext);
314  if (AddrFile) {
315  do {
316  DGDeliverData(AddrFile,
317  SrcAddress,
318  DstAddress,
319  UDPHeader->SourcePort,
320  UDPHeader->DestPort,
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 UDP 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 TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
IPv4_RAW_ADDRESS IPv4Address
Definition: ip.h:26
struct UDP_HEADER UDP_HEADER
#define MID_TRACE
Definition: debug.h:15
USHORT DestPort
Definition: udp.h:17
unsigned char * PUCHAR
Definition: retypes.h:3
IP_ADDRESS SrcAddr
Definition: ip.h:89
#define WH2N(w)
Definition: addrconv.c:40
USHORT SourcePort
Definition: udp.h:16
VOID DGDeliverData(PADDRESS_FILE AddrFile, PIP_ADDRESS SrcAddress, PIP_ADDRESS DstAddress, USHORT SrcPort, USHORT DstPort, PIP_PACKET IPPacket, UINT DataSize)
Definition: datagram.c:52
ULONG UDPv4ChecksumCalculate(PIPv4_HEADER IPHeader, PUCHAR PacketBuffer, ULONG DataLength)
Definition: checksum.c:60
#define DereferenceObject(Object)
Definition: titypes.h:24
uint32_t ULONG_PTR
Definition: typedefs.h:63
PVOID Data
Definition: ip.h:85
Definition: ip.h:23
PADDRESS_FILE AddrSearchFirst(PIP_ADDRESS Address, USHORT Port, USHORT Protocol, PAF_SEARCH SearchContext)
Definition: fileobjs.c:38
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
#define IP_ADDRESS_V4
Definition: ip.h:32
PVOID Header
Definition: ip.h:83
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
#define IP_ADDRESS_V6
Definition: ip.h:33
USHORT Checksum
Definition: udp.h:19
Definition: udp.h:15
UINT Position
Definition: ip.h:87
UINT TotalSize
Definition: ip.h:86
UCHAR Type
Definition: ip.h:79
PADDRESS_FILE AddrSearchNext(PAF_SEARCH SearchContext)
Definition: fileobjs.c:231
USHORT Length
Definition: udp.h:18
#define MAX_TRACE
Definition: debug.h:16
struct UDP_HEADER * PUDP_HEADER
#define DN2H(dw)
Definition: addrconv.c:21
#define DH2N(dw)
Definition: addrconv.c:28
unsigned int UINT
Definition: ndis.h:50
Definition: ip.h:37
#define MIN_TRACE
Definition: debug.h:14
IP_ADDRESS DstAddr
Definition: ip.h:90
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4751
union IP_ADDRESS::@973 Address

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 150 of file udp.c.

166 {
168  PTA_IP_ADDRESS RemoteAddressTa = (PTA_IP_ADDRESS)ConnInfo->RemoteAddress;
171  USHORT RemotePort;
174  KIRQL OldIrql;
175 
176  LockObject(AddrFile, &OldIrql);
177 
178  TI_DbgPrint(MID_TRACE,("Sending Datagram(%x %x %x %d)\n",
179  AddrFile, ConnInfo, BufferData, DataSize));
180  TI_DbgPrint(MID_TRACE,("RemoteAddressTa: %x\n", RemoteAddressTa));
181 
182  switch( RemoteAddressTa->Address[0].AddressType ) {
183  case TDI_ADDRESS_TYPE_IP:
185  RemoteAddress.Address.IPv4Address =
186  RemoteAddressTa->Address[0].Address[0].in_addr;
187  RemotePort = RemoteAddressTa->Address[0].Address[0].sin_port;
188  break;
189 
190  default:
191  UnlockObject(AddrFile, OldIrql);
192  return STATUS_UNSUCCESSFUL;
193  }
194 
195  LocalAddress = AddrFile->Address;
197  {
198  /* If the local address is unspecified (0),
199  * then use the unicast address of the
200  * interface we're sending over
201  */
202  if(!(NCE = RouteGetRouteToDestination( &RemoteAddress ))) {
203  UnlockObject(AddrFile, OldIrql);
205  }
206 
207  LocalAddress = NCE->Interface->Unicast;
208  }
209  else
210  {
211  if(!(NCE = NBLocateNeighbor( &LocalAddress, NULL ))) {
212  UnlockObject(AddrFile, OldIrql);
214  }
215  }
216 
217  Status = BuildUDPPacket( AddrFile,
218  &Packet,
219  &RemoteAddress,
220  RemotePort,
221  &LocalAddress,
222  AddrFile->Port,
223  BufferData,
224  DataSize );
225 
226  UnlockObject(AddrFile, OldIrql);
227 
228  if( !NT_SUCCESS(Status) )
229  return Status;
230 
231  Status = IPSendDatagram(&Packet, NCE);
232  if (!NT_SUCCESS(Status))
233  return Status;
234 
235  *DataUsed = DataSize;
236 
237  return STATUS_SUCCESS;
238 }
BOOLEAN AddrIsUnspecified(PIP_ADDRESS Address)
Definition: address.c:113
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
#define MID_TRACE
Definition: debug.h:15
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
Definition: neighbor.h:28
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
struct _TA_ADDRESS_IP * PTA_IP_ADDRESS
LONG NTSTATUS
Definition: precomp.h:26
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 LockObject(Object, Irql)
Definition: titypes.h:34
Definition: ip.h:23
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define IP_ADDRESS_V4
Definition: ip.h:32
#define UnlockObject(Object, OldIrql)
Definition: titypes.h:54
NTSTATUS IPSendDatagram(PIP_PACKET IPPacket, PNEIGHBOR_CACHE_ENTRY NCE)
Definition: transmit.c:223
smooth NULL
Definition: ftsmooth.c:416
struct _TA_ADDRESS_IP::_AddrIp Address[1]
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define TDI_ADDRESS_TYPE_IP
Definition: tdi.h:345
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
unsigned short USHORT
Definition: pedump.c:61
IP_ADDRESS Address
Definition: titypes.h:136
Definition: ip.h:77
USHORT Port
Definition: titypes.h:139
return STATUS_SUCCESS
Definition: btrfs.c:2777
#define STATUS_NETWORK_UNREACHABLE
Definition: ntstatus.h:690
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4751
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR RemoteAddress
Definition: wsk.h:170
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR LocalAddress
Definition: wsk.h:170

Referenced by FileOpenAddress().

◆ UDPShutdown()

NTSTATUS UDPShutdown ( VOID  )

Definition at line 364 of file udp.c.

371 {
372  if (!UDPInitialized)
373  return STATUS_SUCCESS;
374 
376 
377  /* Deregister this protocol with IP layer */
379 
381 
382  return STATUS_SUCCESS;
383 }
VOID IPRegisterProtocol(UINT ProtocolNumber, IP_PROTOCOL_HANDLER Handler)
Definition: ip.c:390
PORT_SET UDPPorts
Definition: udp.c:14
smooth NULL
Definition: ftsmooth.c:416
BOOLEAN UDPInitialized
Definition: udp.c:13
VOID PortsShutdown(PPORT_SET PortSet)
Definition: ports.c:31
return STATUS_SUCCESS
Definition: btrfs.c:2777

Referenced by TiUnload().

◆ UDPStartup()

NTSTATUS UDPStartup ( VOID  )

Definition at line 337 of file udp.c.

344 {
346 
347 #ifdef __NTDRIVER__
349 #endif
350 
352 
353  if( !NT_SUCCESS(Status) ) return Status;
354 
355  /* Register this protocol with IP layer */
357 
359 
360  return STATUS_SUCCESS;
361 }
#define TRUE
Definition: types.h:120
NTSTATUS PortsStartup(PPORT_SET PortSet, UINT StartingPort, UINT PortsToManage)
Definition: ports.c:13
LONG NTSTATUS
Definition: precomp.h:26
VOID IPRegisterProtocol(UINT ProtocolNumber, IP_PROTOCOL_HANDLER Handler)
Definition: ip.c:390
PORT_SET UDPPorts
Definition: udp.c:14
VOID UDPReceive(PIP_INTERFACE Interface, PIP_PACKET IPPacket)
Definition: udp.c:241
#define UDP_DYNAMIC_PORTS
Definition: udp.h:11
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define UDP_STARTING_PORT
Definition: udp.h:10
BOOLEAN UDPInitialized
Definition: udp.c:13
UDP_STATISTICS UDPStats
Definition: main.c:26
Status
Definition: gdiplustypes.h:24
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
return STATUS_SUCCESS
Definition: btrfs.c:2777

Referenced by DriverEntry().

Variable Documentation

◆ UDPStats

UDP_STATISTICS UDPStats

Definition at line 26 of file main.c.

Referenced by RawIPStartup(), and UDPStartup().