Internet Control Message Protocol (ICMP) Service
[Transport layer]


Files

file  icmp.c
 ICMP module implementation.

Data Structures

struct  icmp_reply_t
 ICMP reply data. More...

Defines

#define ICMP_CHECKSUM(header, length)   htons(ip_checksum((uint8_t *) (header), (length)))
 Compute the ICMP datagram checksum.
#define ICMP_ECHO_TEXT   "ICMP hello from HelenOS."
 An echo request datagrams pattern.
#define ICMP_KEEP_LENGTH   8
 Original datagram length in bytes transfered to the error notification message.
#define NAME   "icmp"
 ICMP module name.
#define REPLY_BUCKETS   1024
 Number of replies hash table buckets.
#define REPLY_KEYS   2
 Number of replies hash table keys.

Functions

static int icmp_destination_unreachable (icmp_code_t code, icmp_param_t mtu, packet_t *packet)
static int icmp_echo (icmp_param_t id, icmp_param_t sequence, size_t size, mseconds_t timeout, ip_ttl_t ttl, ip_tos_t tos, bool dont_fragment, const struct sockaddr *addr, socklen_t addrlen)
 Request an echo message.
static int icmp_parameter_problem (icmp_code_t code, icmp_param_t pointer, packet_t *packet)
static icmp_header_ticmp_prepare_packet (packet_t *packet)
 Prepare the ICMP error packet.
static void icmp_process_echo_reply (packet_t *packet, icmp_header_t *header, icmp_type_t type, icmp_code_t code)
 Try to set the pending reply result as the received message type.
static int icmp_process_packet (packet_t *packet, services_t error)
 Process the received ICMP packet.
static void icmp_receiver (ipc_callid_t iid, ipc_call_t *icall)
 Process IPC messages from the IP module.
static void icmp_release (packet_t *packet)
 Release the packet and return the result.
static int icmp_send_packet (icmp_type_t type, icmp_code_t code, packet_t *packet, icmp_header_t *header, services_t error, ip_ttl_t ttl, ip_tos_t tos, bool dont_fragment)
 Send the ICMP message.
static int icmp_source_quench (packet_t *packet)
static int icmp_time_exceeded (icmp_code_t code, packet_t *packet)
int main (int argc, char *argv[])
 Main entry point.
static int replies_compare (unsigned long key[], hash_count_t keys, link_t *item)
static hash_index_t replies_hash (unsigned long key[])
static void replies_remove_callback (link_t *item)
void tl_connection (void)
 Per-connection module initialization.
int tl_initialize (int net_phone)
 Module initialization.
int tl_message (ipc_callid_t callid, ipc_call_t *call, ipc_call_t *answer, size_t *count)
 Process the transport layer module message.

Variables

static bool echo_replying = true
static bool error_reporting = true
static atomic_t icmp_client
 ICMP client identification counter.
static packet_dimension_t icmp_dimension
static fibril_local icmp_param_t icmp_id
 ICMP identifier and sequence number (client-specific).
static fibril_local icmp_param_t icmp_seq
static int phone_ip = -1
static int phone_net = -1
 Global data.
static hash_table_t replies
static fibril_mutex_t reply_lock
 Reply hash table.
static hash_table_operations_t reply_ops

Define Documentation

#define ICMP_CHECKSUM ( header,
length   )     htons(ip_checksum((uint8_t *) (header), (length)))

Compute the ICMP datagram checksum.

Parameters:
[in,out] header ICMP datagram header.
[in] length Total datagram length.
Returns:
Computed checksum.

Definition at line 97 of file icmp.c.


Function Documentation

static int icmp_echo ( icmp_param_t  id,
icmp_param_t  sequence,
size_t  size,
mseconds_t  timeout,
ip_ttl_t  ttl,
ip_tos_t  tos,
bool  dont_fragment,
const struct sockaddr addr,
socklen_t  addrlen 
) [static]

Request an echo message.

Send a packet with specified parameters to the target host and wait for the reply upto the given timeout. Block the caller until the reply or the timeout occurs.

Parameters:
[in] id Message identifier.
[in] sequence Message sequence parameter.
[in] size Message data length in bytes.
[in] timeout Timeout in miliseconds.
[in] ttl Time to live.
[in] tos Type of service.
[in] dont_fragment Disable fragmentation.
[in] addr Target host address.
[in] addrlen Torget host address length.
Returns:
ICMP_ECHO on success.

ETIMEOUT if the reply has not arrived before the timeout.

ICMP type of the received error notification.

EINVAL if the addrlen parameter is less or equal to zero.

ENOMEM if there is not enough memory left.

Definition at line 290 of file icmp.c.

static icmp_header_t* icmp_prepare_packet ( packet_t packet  )  [static]

Prepare the ICMP error packet.

Truncate the original packet if longer than ICMP_KEEP_LENGTH bytes. Prefix and return the ICMP header.

Parameters:
[in,out] packet Original packet.
Returns:
The prefixed ICMP header.

NULL on errors.

Definition at line 241 of file icmp.c.

static void icmp_process_echo_reply ( packet_t packet,
icmp_header_t header,
icmp_type_t  type,
icmp_code_t  code 
) [static]

Try to set the pending reply result as the received message type.

If the reply data is not present, the reply timed out and the other fibril is already awake. The packet is released.

Parameters:
[in] packet The received reply message.
[in] header The ICMP message header.
[in] type The received reply message type.
[in] code The received reply message code.

Definition at line 440 of file icmp.c.

static int icmp_process_packet ( packet_t packet,
services_t  error 
) [static]

Process the received ICMP packet.

Notify the destination socket application.

Parameters:
[in,out] packet Received packet.
[in] error Packet error reporting service to prefix the received packet.
Returns:
EOK on success.

EINVAL if the packet is not valid.

EINVAL if the stored packet address is not the an_addr_t.

EINVAL if the packet does not contain any data.

NO_DATA if the packet content is shorter than the user datagram header.

ENOMEM if there is not enough memory left.

EADDRNOTAVAIL if the destination socket does not exist.

Other error codes as defined for the ip_client_process_packet() function.

Definition at line 484 of file icmp.c.

static void icmp_receiver ( ipc_callid_t  iid,
ipc_call_t icall 
) [static]

Process IPC messages from the IP module.

Parameters:
[in] iid Message identifier.
[in,out] icall Message parameters.

Definition at line 612 of file icmp.c.

static void icmp_release ( packet_t packet  )  [static]

Release the packet and return the result.

Parameters:
[in] packet Packet queue to be released.

Definition at line 173 of file icmp.c.

static int icmp_send_packet ( icmp_type_t  type,
icmp_code_t  code,
packet_t packet,
icmp_header_t header,
services_t  error,
ip_ttl_t  ttl,
ip_tos_t  tos,
bool  dont_fragment 
) [static]

Send the ICMP message.

Set the message type and code and compute the checksum. Error messages are sent only if allowed in the configuration. Release the packet on errors.

Parameters:
[in] type Message type.
[in] code Message code.
[in] packet Message packet to be sent.
[in] header ICMP header.
[in] error Error service to be announced. Should be SERVICE_ICMP or zero.
[in] ttl Time to live.
[in] tos Type of service.
[in] dont_fragment Disable fragmentation.
Returns:
EOK on success.

EPERM if the error message is not allowed.

Definition at line 198 of file icmp.c.

int main ( int  argc,
char *  argv[] 
)

Main entry point.

Parameters:
[in] argc Nmber of arguments in argv vector (ignored).
[in] argv Cmdline argument vector (ignored).
Returns:
Error code.
Driver debug level is set here.

Definition at line 802 of file icmp.c.

void tl_connection ( void   ) 

Per-connection module initialization.

Initialize client-specific global variables.

Definition at line 709 of file icmp.c.

int tl_initialize ( int  net_phone  ) 

Module initialization.

Parameters:
[in] net_phone Network module phone.
Returns:
EOK on success.

ENOMEM if there is not enough memory left.

Definition at line 650 of file icmp.c.

int tl_message ( ipc_callid_t  callid,
ipc_call_t call,
ipc_call_t answer,
size_t count 
)

Process the transport layer module message.

Parameters:
[in] callid Message identifier.
[in] call Message parameters.
[out] answer Answer.
[out] count Number of arguments of the answer.
Returns:
EOK on success.

ENOTSUP if the message is not known.

Other error codes as defined for the packet_translate() function.

Other error codes as defined for the icmp_destination_unreachable() function.

Other error codes as defined for the icmp_source_quench() function.

Other error codes as defined for the icmp_time_exceeded() function.

Other error codes as defined for the icmp_parameter_problem() function.

See also:
icmp_remote.h

IS_NET_ICMP_MESSAGE()

Definition at line 739 of file icmp.c.


Generated on Thu Jun 2 07:45:55 2011 for HelenOS/USB by  doxygen 1.4.7