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_t * | icmp_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 ICMP_CHECKSUM | ( | header, | |||
length | ) | htons(ip_checksum((uint8_t *) (header), (length))) |
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.
[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. |
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.
static icmp_header_t* icmp_prepare_packet | ( | packet_t * | packet | ) | [static] |
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.
[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. |
static int icmp_process_packet | ( | packet_t * | packet, | |
services_t | error | |||
) | [static] |
Process the received ICMP packet.
Notify the destination socket application.
[in,out] | packet | Received packet. |
[in] | error | Packet error reporting service to prefix the received packet. |
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.
static void icmp_receiver | ( | ipc_callid_t | iid, | |
ipc_call_t * | icall | |||
) | [static] |
static void icmp_release | ( | packet_t * | packet | ) | [static] |
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.
[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. |
EPERM if the error message is not allowed.
int main | ( | int | argc, | |
char * | argv[] | |||
) |
void tl_connection | ( | void | ) |
int tl_initialize | ( | int | net_phone | ) |
int tl_message | ( | ipc_callid_t | callid, | |
ipc_call_t * | call, | |||
ipc_call_t * | answer, | |||
size_t * | count | |||
) |
Process the transport layer module message.
[in] | callid | Message identifier. |
[in] | call | Message parameters. |
[out] | answer | Answer. |
[out] | count | Number of arguments of the answer. |
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.