ReactOS  0.4.13-dev-443-g10f00f8
icmp.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ICMP_HEADER
 

Macros

#define ICMP_TYPE_ECHO_REPLY   0 /* Echo reply */
 
#define ICMP_TYPE_DEST_UNREACH   3 /* Destination unreachable */
 
#define ICMP_TYPE_SOURCE_QUENCH   4 /* Source quench */
 
#define ICMP_TYPE_REDIRECT   5 /* Redirect */
 
#define ICMP_TYPE_ECHO_REQUEST   8 /* Echo request */
 
#define ICMP_TYPE_TIME_EXCEEDED   11 /* Time exceeded */
 
#define ICMP_TYPE_PARAMETER   12 /* Parameter problem */
 
#define ICMP_TYPE_TIMESTAMP_REQUEST   13 /* Timestamp request */
 
#define ICMP_TYPE_TIMESTAMP_REPLY   14 /* Timestamp reply */
 
#define ICMP_TYPE_INFO_REQUEST   15 /* Information request */
 
#define ICMP_TYPE_INFO_REPLY   16 /* Information reply */
 
#define ICMP_CODE_DU_NET_UNREACH   0 /* Network unreachable */
 
#define ICMP_CODE_DU_HOST_UNREACH   1 /* Host unreachable */
 
#define ICMP_CODE_DU_PROTOCOL_UNREACH   2 /* Protocol unreachable */
 
#define ICMP_CODE_DU_PORT_UNREACH   3 /* Port unreachable */
 
#define ICMP_CODE_DU_FRAG_DF_SET   4 /* Fragmentation needed and DF set */
 
#define ICMP_CODE_DU_SOURCE_ROUTE_FAILED   5 /* Source route failed */
 
#define ICMP_CODE_RD_NET   0 /* Redirect datagrams for the network */
 
#define ICMP_CODE_RD_HOST   1 /* Redirect datagrams for the host */
 
#define ICMP_CODE_RD_TOS_NET   2 /* Redirect datagrams for the Type of Service and network */
 
#define ICMP_CODE_RD_TOS_HOST   3 /* Redirect datagrams for the Type of Service and host */
 
#define ICMP_CODE_TE_TTL   0 /* Time to live exceeded in transit */
 
#define ICMP_CODE_TE_REASSEMBLY   1 /* Fragment reassembly time exceeded */
 
#define ICMP_CODE_TP_POINTER   1 /* Pointer indicates the error */
 

Typedefs

typedef struct ICMP_HEADER ICMP_HEADER
 
typedef struct ICMP_HEADERPICMP_HEADER
 

Functions

NTSTATUS ICMPSendDatagram (PADDRESS_FILE AddrFile, PTDI_CONNECTION_INFORMATION ConnInfo, PCHAR BufferData, ULONG DataSize, PULONG DataUsed)
 
NTSTATUS ICMPStartup (VOID)
 
NTSTATUS ICMPShutdown (VOID)
 
VOID ICMPReceive (PIP_INTERFACE Interface, PIP_PACKET IPPacket)
 
VOID ICMPTransmit (PIP_PACKET IPPacket, PIP_TRANSMIT_COMPLETE Complete, PVOID Context)
 
VOID ICMPReply (PIP_INTERFACE Interface, PIP_PACKET IPPacket, UCHAR Type, UCHAR Code)
 

Macro Definition Documentation

◆ ICMP_CODE_DU_FRAG_DF_SET

#define ICMP_CODE_DU_FRAG_DF_SET   4 /* Fragmentation needed and DF set */

Definition at line 35 of file icmp.h.

◆ ICMP_CODE_DU_HOST_UNREACH

#define ICMP_CODE_DU_HOST_UNREACH   1 /* Host unreachable */

Definition at line 32 of file icmp.h.

◆ ICMP_CODE_DU_NET_UNREACH

#define ICMP_CODE_DU_NET_UNREACH   0 /* Network unreachable */

Definition at line 31 of file icmp.h.

◆ ICMP_CODE_DU_PORT_UNREACH

#define ICMP_CODE_DU_PORT_UNREACH   3 /* Port unreachable */

Definition at line 34 of file icmp.h.

◆ ICMP_CODE_DU_PROTOCOL_UNREACH

#define ICMP_CODE_DU_PROTOCOL_UNREACH   2 /* Protocol unreachable */

Definition at line 33 of file icmp.h.

◆ ICMP_CODE_DU_SOURCE_ROUTE_FAILED

#define ICMP_CODE_DU_SOURCE_ROUTE_FAILED   5 /* Source route failed */

Definition at line 36 of file icmp.h.

◆ ICMP_CODE_RD_HOST

#define ICMP_CODE_RD_HOST   1 /* Redirect datagrams for the host */

Definition at line 40 of file icmp.h.

◆ ICMP_CODE_RD_NET

#define ICMP_CODE_RD_NET   0 /* Redirect datagrams for the network */

Definition at line 39 of file icmp.h.

◆ ICMP_CODE_RD_TOS_HOST

#define ICMP_CODE_RD_TOS_HOST   3 /* Redirect datagrams for the Type of Service and host */

Definition at line 42 of file icmp.h.

◆ ICMP_CODE_RD_TOS_NET

#define ICMP_CODE_RD_TOS_NET   2 /* Redirect datagrams for the Type of Service and network */

Definition at line 41 of file icmp.h.

◆ ICMP_CODE_TE_REASSEMBLY

#define ICMP_CODE_TE_REASSEMBLY   1 /* Fragment reassembly time exceeded */

Definition at line 46 of file icmp.h.

◆ ICMP_CODE_TE_TTL

#define ICMP_CODE_TE_TTL   0 /* Time to live exceeded in transit */

Definition at line 45 of file icmp.h.

◆ ICMP_CODE_TP_POINTER

#define ICMP_CODE_TP_POINTER   1 /* Pointer indicates the error */

Definition at line 49 of file icmp.h.

◆ ICMP_TYPE_DEST_UNREACH

#define ICMP_TYPE_DEST_UNREACH   3 /* Destination unreachable */

Definition at line 19 of file icmp.h.

◆ ICMP_TYPE_ECHO_REPLY

#define ICMP_TYPE_ECHO_REPLY   0 /* Echo reply */

Definition at line 18 of file icmp.h.

◆ ICMP_TYPE_ECHO_REQUEST

#define ICMP_TYPE_ECHO_REQUEST   8 /* Echo request */

Definition at line 22 of file icmp.h.

◆ ICMP_TYPE_INFO_REPLY

#define ICMP_TYPE_INFO_REPLY   16 /* Information reply */

Definition at line 28 of file icmp.h.

◆ ICMP_TYPE_INFO_REQUEST

#define ICMP_TYPE_INFO_REQUEST   15 /* Information request */

Definition at line 27 of file icmp.h.

◆ ICMP_TYPE_PARAMETER

#define ICMP_TYPE_PARAMETER   12 /* Parameter problem */

Definition at line 24 of file icmp.h.

◆ ICMP_TYPE_REDIRECT

#define ICMP_TYPE_REDIRECT   5 /* Redirect */

Definition at line 21 of file icmp.h.

◆ ICMP_TYPE_SOURCE_QUENCH

#define ICMP_TYPE_SOURCE_QUENCH   4 /* Source quench */

Definition at line 20 of file icmp.h.

◆ ICMP_TYPE_TIME_EXCEEDED

#define ICMP_TYPE_TIME_EXCEEDED   11 /* Time exceeded */

Definition at line 23 of file icmp.h.

◆ ICMP_TYPE_TIMESTAMP_REPLY

#define ICMP_TYPE_TIMESTAMP_REPLY   14 /* Timestamp reply */

Definition at line 26 of file icmp.h.

◆ ICMP_TYPE_TIMESTAMP_REQUEST

#define ICMP_TYPE_TIMESTAMP_REQUEST   13 /* Timestamp request */

Definition at line 25 of file icmp.h.

Typedef Documentation

◆ ICMP_HEADER

◆ PICMP_HEADER

Function Documentation

◆ ICMPReceive()

VOID ICMPReceive ( PIP_INTERFACE  Interface,
PIP_PACKET  IPPacket 
)

Definition at line 211 of file icmp.c.

220 {
221  PICMP_HEADER ICMPHeader;
222 
223  TI_DbgPrint(DEBUG_ICMP, ("Called.\n"));
224 
225  ICMPHeader = (PICMP_HEADER)IPPacket->Data;
226 
227  TI_DbgPrint(DEBUG_ICMP, ("Size (%d).\n", IPPacket->TotalSize));
228 
229  TI_DbgPrint(DEBUG_ICMP, ("HeaderSize (%d).\n", IPPacket->HeaderSize));
230 
231  TI_DbgPrint(DEBUG_ICMP, ("Type (%d).\n", ICMPHeader->Type));
232 
233  TI_DbgPrint(DEBUG_ICMP, ("Code (%d).\n", ICMPHeader->Code));
234 
235  TI_DbgPrint(DEBUG_ICMP, ("Checksum (0x%X).\n", ICMPHeader->Checksum));
236 
237  /* Checksum ICMP header and data */
238  if (!IPv4CorrectChecksum(IPPacket->Data, IPPacket->TotalSize - IPPacket->HeaderSize)) {
239  TI_DbgPrint(DEBUG_ICMP, ("Bad ICMP checksum.\n"));
240  /* Discard packet */
241  return;
242  }
243 
244  RawIpReceive(Interface, IPPacket);
245 
246  switch (ICMPHeader->Type) {
248  ICMPReply( Interface, IPPacket, ICMP_TYPE_ECHO_REPLY, 0 );
249  break;
250 
252  break;
253 
254  default:
256  ("Discarded ICMP datagram of unknown type %d.\n",
257  ICMPHeader->Type));
258  /* Discard packet */
259  break;
260  }
261 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
VOID ICMPReply(PIP_INTERFACE Interface, PIP_PACKET IPPacket, UCHAR Type, UCHAR Code)
Definition: icmp.c:296
PVOID Data
Definition: ip.h:85
#define DEBUG_ICMP
Definition: debug.h:29
UCHAR Type
Definition: icmp.h:11
#define ICMP_TYPE_ECHO_REQUEST
Definition: icmp.h:22
IN PVOID IN PVOID IN USHORT IN USHORT IN PINTERFACE Interface
Definition: pci.h:359
#define ICMP_TYPE_ECHO_REPLY
Definition: icmp.h:18
UINT TotalSize
Definition: ip.h:86
UCHAR Code
Definition: icmp.h:12
UINT HeaderSize
Definition: ip.h:84
VOID RawIpReceive(PIP_INTERFACE Interface, PIP_PACKET IPPacket)
Definition: rawip.c:267
struct ICMP_HEADER * PICMP_HEADER
USHORT Checksum
Definition: icmp.h:13
#define IPv4CorrectChecksum(Data, Count)
Definition: checksum.h:38

Referenced by ICMPStartup().

◆ ICMPReply()

VOID ICMPReply ( PIP_INTERFACE  Interface,
PIP_PACKET  IPPacket,
UCHAR  Type,
UCHAR  Code 
)

Definition at line 296 of file icmp.c.

314 {
315  UINT DataSize;
316  IP_PACKET NewPacket;
317 
318  TI_DbgPrint(DEBUG_ICMP, ("Called. Type (%d) Code (%d).\n", Type, Code));
319 
320  DataSize = IPPacket->TotalSize - IPPacket->HeaderSize;
321 
322  if( !PrepareICMPPacket(NULL, Interface, &NewPacket, &IPPacket->SrcAddr,
323  IPPacket->Data, DataSize) ) return;
324 
325  ((PICMP_HEADER)NewPacket.Data)->Type = Type;
326  ((PICMP_HEADER)NewPacket.Data)->Code = Code;
327  ((PICMP_HEADER)NewPacket.Data)->Checksum = 0;
328 
329  ICMPTransmit(&NewPacket, NULL, NULL);
330 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
Type
Definition: Type.h:6
IP_ADDRESS SrcAddr
Definition: ip.h:89
PVOID Data
Definition: ip.h:85
smooth NULL
Definition: ftsmooth.c:416
#define DEBUG_ICMP
Definition: debug.h:29
#define Code
Definition: deflate.h:80
IN PVOID IN PVOID IN USHORT IN USHORT IN PINTERFACE Interface
Definition: pci.h:359
VOID ICMPTransmit(PIP_PACKET IPPacket, PIP_TRANSMIT_COMPLETE Complete, PVOID Context)
Definition: icmp.c:264
UINT TotalSize
Definition: ip.h:86
UINT HeaderSize
Definition: ip.h:84
unsigned int UINT
Definition: ndis.h:50
struct ICMP_HEADER * PICMP_HEADER
Definition: ip.h:77
BOOLEAN PrepareICMPPacket(PADDRESS_FILE AddrFile, PIP_INTERFACE Interface, PIP_PACKET IPPacket, PIP_ADDRESS Destination, PCHAR Data, UINT DataSize)
Definition: icmp.c:29
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4751

Referenced by ICMPReceive().

◆ ICMPSendDatagram()

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

Definition at line 118 of file icmp.c.

134 {
136  PTA_IP_ADDRESS RemoteAddressTa = (PTA_IP_ADDRESS)ConnInfo->RemoteAddress;
140  KIRQL OldIrql;
141 
142  TI_DbgPrint(MID_TRACE,("Sending Datagram(%x %x %x %d)\n",
143  AddrFile, ConnInfo, BufferData, DataSize));
144  TI_DbgPrint(MID_TRACE,("RemoteAddressTa: %x\n", RemoteAddressTa));
145 
146  switch( RemoteAddressTa->Address[0].AddressType ) {
147  case TDI_ADDRESS_TYPE_IP:
149  RemoteAddress.Address.IPv4Address =
150  RemoteAddressTa->Address[0].Address[0].in_addr;
151  break;
152 
153  default:
154  return STATUS_UNSUCCESSFUL;
155  }
156 
157  TI_DbgPrint(MID_TRACE,("About to get route to destination\n"));
158 
159  LockObject(AddrFile, &OldIrql);
160 
161  LocalAddress = AddrFile->Address;
163  {
164  /* If the local address is unspecified (0),
165  * then use the unicast address of the
166  * interface we're sending over
167  */
169  {
170  UnlockObject(AddrFile, OldIrql);
172  }
173 
174  LocalAddress = NCE->Interface->Unicast;
175  }
176  else
177  {
178  if(!(NCE = NBLocateNeighbor( &LocalAddress, NULL )))
179  {
180  UnlockObject(AddrFile, OldIrql);
182  }
183  }
184 
185  Status = PrepareICMPPacket( AddrFile,
186  NCE->Interface,
187  &Packet,
188  &RemoteAddress,
189  BufferData,
190  DataSize );
191 
192  UnlockObject(AddrFile, OldIrql);
193 
194  if( !NT_SUCCESS(Status) )
195  return Status;
196 
197  TI_DbgPrint(MID_TRACE,("About to send datagram\n"));
198 
199  Status = IPSendDatagram(&Packet, NCE);
200  if (!NT_SUCCESS(Status))
201  return Status;
202 
203  *DataUsed = DataSize;
204 
205  TI_DbgPrint(MID_TRACE,("Leaving\n"));
206 
207  return STATUS_SUCCESS;
208 }
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
IP_ADDRESS Address
Definition: titypes.h:136
Definition: ip.h:77
BOOLEAN PrepareICMPPacket(PADDRESS_FILE AddrFile, PIP_INTERFACE Interface, PIP_PACKET IPPacket, PIP_ADDRESS Destination, PCHAR Data, UINT DataSize)
Definition: icmp.c:29
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().

◆ ICMPShutdown()

NTSTATUS ICMPShutdown ( VOID  )

Referenced by TiUnload().

◆ ICMPStartup()

NTSTATUS ICMPStartup ( VOID  )

Referenced by DriverEntry().

◆ ICMPTransmit()

VOID ICMPTransmit ( PIP_PACKET  IPPacket,
PIP_TRANSMIT_COMPLETE  Complete,
PVOID  Context 
)

Definition at line 264 of file icmp.c.

274 {
276 
277  TI_DbgPrint(DEBUG_ICMP, ("Called.\n"));
278 
279  /* Calculate checksum of ICMP header and data */
280  ((PICMP_HEADER)IPPacket->Data)->Checksum = (USHORT)
281  IPv4Checksum(IPPacket->Data, IPPacket->TotalSize - IPPacket->HeaderSize, 0);
282 
283  /* Get a route to the destination address */
284  if ((NCE = RouteGetRouteToDestination(&IPPacket->DstAddr))) {
285  /* Send the packet */
286  IPSendDatagram(IPPacket, NCE);
287  } else {
288  /* No route to destination (or no free resources) */
289  TI_DbgPrint(DEBUG_ICMP, ("No route to destination address 0x%X.\n",
290  IPPacket->DstAddr.Address.IPv4Address));
291  IPPacket->Free(IPPacket);
292  }
293 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
IPv4_RAW_ADDRESS IPv4Address
Definition: ip.h:26
Definition: neighbor.h:28
PNEIGHBOR_CACHE_ENTRY RouteGetRouteToDestination(PIP_ADDRESS Destination)
Definition: router.c:300
OBJECT_FREE_ROUTINE Free
Definition: ip.h:78
PVOID Data
Definition: ip.h:85
union IP_ADDRESS::@970 Address
NTSTATUS IPSendDatagram(PIP_PACKET IPPacket, PNEIGHBOR_CACHE_ENTRY NCE)
Definition: transmit.c:223
#define IPv4Checksum(Data, Count, Seed)
Definition: checksum.h:30
#define DEBUG_ICMP
Definition: debug.h:29
UINT TotalSize
Definition: ip.h:86
UINT HeaderSize
Definition: ip.h:84
unsigned short USHORT
Definition: pedump.c:61
struct ICMP_HEADER * PICMP_HEADER
IP_ADDRESS DstAddr
Definition: ip.h:90

Referenced by ICMPReply().