Rev 4743 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4743 | Rev 4756 | ||
---|---|---|---|
Line 94... | Line 94... | ||
94 | /** Free identifier numbers pool end. |
94 | /** Free identifier numbers pool end. |
95 | */ |
95 | */ |
96 | #define ICMP_FREE_IDS_END MAX_UINT16 |
96 | #define ICMP_FREE_IDS_END MAX_UINT16 |
97 | 97 | ||
98 | /** Computes the ICMP datagram checksum. |
98 | /** Computes the ICMP datagram checksum. |
99 | * @param header The ICMP datagram header. Input/output parameter. |
99 | * @param[in,out] header The ICMP datagram header. |
100 | * @param length The total datagram length. Input parameter. |
100 | * @param[in] length The total datagram length. |
101 | * @returns The computed checksum. |
101 | * @returns The computed checksum. |
102 | */ |
102 | */ |
103 | #define ICMP_CHECKSUM( header, length ) htons( ip_checksum(( uint8_t * ) ( header ), ( length ))) |
103 | #define ICMP_CHECKSUM( header, length ) htons( ip_checksum(( uint8_t * ) ( header ), ( length ))) |
104 | 104 | ||
105 | /** An echo request datagrams pattern. |
105 | /** An echo request datagrams pattern. |
106 | */ |
106 | */ |
107 | #define ICMP_ECHO_TEXT "Hello from HelenOS." |
107 | #define ICMP_ECHO_TEXT "Hello from HelenOS." |
108 | 108 | ||
109 | /** Computes an ICMP reply data key. |
109 | /** Computes an ICMP reply data key. |
110 | * @param id The message identifier. Input parameter. |
110 | * @param[in] id The message identifier. |
111 | * @param sequence The message sequence number. Input parameter. |
111 | * @param[in] sequence The message sequence number. |
112 | * @returns The computed ICMP reply data key. |
112 | * @returns The computed ICMP reply data key. |
113 | */ |
113 | */ |
114 | #define ICMP_GET_REPLY_KEY( id, sequence ) ((( id ) << 16 ) | ( sequence & 0xFFFF )) |
114 | #define ICMP_GET_REPLY_KEY( id, sequence ) ((( id ) << 16 ) | ( sequence & 0xFFFF )) |
115 | 115 | ||
116 | /** Type definition of the ICMP reply timeout. |
116 | /** Type definition of the ICMP reply timeout. |
Line 138... | Line 138... | ||
138 | 138 | ||
139 | /** Processes the received ICMP packet. |
139 | /** Processes the received ICMP packet. |
140 | * Is used as an entry point from the underlying IP module. |
140 | * Is used as an entry point from the underlying IP module. |
141 | * Releases the packet on error. |
141 | * Releases the packet on error. |
142 | * @param device_id The device identifier. Ignored parameter. |
142 | * @param device_id The device identifier. Ignored parameter. |
143 | * @param packet The received packet. Input/output parameter. |
143 | * @param[in,out] packet The received packet. |
144 | * @param receiver The target service. Ignored parameter. |
144 | * @param receiver The target service. Ignored parameter. |
145 | * @param error The packet error reporting service. Prefixes the received packet. Input parameter. |
145 | * @param[in] error The packet error reporting service. Prefixes the received packet. |
146 | * @returns EOK on success. |
146 | * @returns EOK on success. |
147 | * @returns Other error codes as defined for the icmp_process_packet() function. |
147 | * @returns Other error codes as defined for the icmp_process_packet() function. |
148 | */ |
148 | */ |
149 | int icmp_received_msg( device_id_t device_id, packet_t packet, services_t receiver, services_t error ); |
149 | int icmp_received_msg( device_id_t device_id, packet_t packet, services_t receiver, services_t error ); |
150 | 150 | ||
151 | /** Processes the received ICMP packet. |
151 | /** Processes the received ICMP packet. |
152 | * Notifies the destination socket application. |
152 | * Notifies the destination socket application. |
153 | * @param packet The received packet. Input/output parameter. |
153 | * @param[in,out] packet The received packet. |
154 | * @param error The packet error reporting service. Prefixes the received packet. Input parameter. |
154 | * @param[in] error The packet error reporting service. Prefixes the received packet. |
155 | * @returns EOK on success. |
155 | * @returns EOK on success. |
156 | * @returns EINVAL if the packet is not valid. |
156 | * @returns EINVAL if the packet is not valid. |
157 | * @returns EINVAL if the stored packet address is not the an_addr_t. |
157 | * @returns EINVAL if the stored packet address is not the an_addr_t. |
158 | * @returns EINVAL if the packet does not contain any data. |
158 | * @returns EINVAL if the packet does not contain any data. |
159 | * @returns NO_DATA if the packet content is shorter than the user datagram header. |
159 | * @returns NO_DATA if the packet content is shorter than the user datagram header. |
Line 164... | Line 164... | ||
164 | int icmp_process_packet( packet_t packet, services_t error ); |
164 | int icmp_process_packet( packet_t packet, services_t error ); |
165 | 165 | ||
166 | /** Processes the client messages. |
166 | /** Processes the client messages. |
167 | * Remembers the assigned identifier and sequence numbers. |
167 | * Remembers the assigned identifier and sequence numbers. |
168 | * Runs until the client module disconnects. |
168 | * Runs until the client module disconnects. |
169 | * @param callid The message identifier. Input parameter. |
169 | * @param[in] callid The message identifier. |
170 | * @param call The message parameters. Input parameter. |
170 | * @param[in] call The message parameters. |
171 | * @returns EOK. |
171 | * @returns EOK. |
172 | * @see icmp_interface.h |
172 | * @see icmp_interface.h |
173 | * @see icmp_api.h |
173 | * @see icmp_api.h |
174 | */ |
174 | */ |
175 | int icmp_process_client_messages( ipc_callid_t callid, ipc_call_t call ); |
175 | int icmp_process_client_messages( ipc_callid_t callid, ipc_call_t call ); |
176 | 176 | ||
177 | /** Processes the generic client messages. |
177 | /** Processes the generic client messages. |
178 | * @param call The message parameters. Input parameter. |
178 | * @param[in] call The message parameters. |
179 | * @returns EOK on success. |
179 | * @returns EOK on success. |
180 | * @returns ENOTSUP if the message is not known. |
180 | * @returns ENOTSUP if the message is not known. |
181 | * @returns Other error codes as defined for the packet_translate() function. |
181 | * @returns Other error codes as defined for the packet_translate() function. |
182 | * @returns Other error codes as defined for the icmp_destination_unreachable_msg() function. |
182 | * @returns Other error codes as defined for the icmp_destination_unreachable_msg() function. |
183 | * @returns Other error codes as defined for the icmp_source_quench_msg() function. |
183 | * @returns Other error codes as defined for the icmp_source_quench_msg() function. |
Line 186... | Line 186... | ||
186 | * @see icmp_interface.h |
186 | * @see icmp_interface.h |
187 | */ |
187 | */ |
188 | int icmp_process_message( ipc_call_t * call ); |
188 | int icmp_process_message( ipc_call_t * call ); |
189 | 189 | ||
190 | /** Releases the packet and returns the result. |
190 | /** Releases the packet and returns the result. |
191 | * @param packet The packet queue to be released. Input parameter. |
191 | * @param[in] packet The packet queue to be released. |
192 | * @param result The result to be returned. Input parameter. |
192 | * @param[in] result The result to be returned. |
193 | * @returns The result parameter. |
193 | * @returns The result parameter. |
194 | */ |
194 | */ |
195 | int icmp_release_and_return( packet_t packet, int result ); |
195 | int icmp_release_and_return( packet_t packet, int result ); |
196 | 196 | ||
197 | /** Requests an echo message. |
197 | /** Requests an echo message. |
198 | * Sends a packet with specified parameters to the target host and waits for the reply upto the given timeout. |
198 | * Sends a packet with specified parameters to the target host and waits for the reply upto the given timeout. |
199 | * Blocks the caller until the reply or the timeout occurres. |
199 | * Blocks the caller until the reply or the timeout occurres. |
200 | * @param id The message identifier. Input parameter. |
200 | * @param[in] id The message identifier. |
201 | * @param sequence The message sequence parameter. Input parameter. |
201 | * @param[in] sequence The message sequence parameter. |
202 | * @param size The message data length in bytes. Input parameter. |
202 | * @param[in] size The message data length in bytes. |
203 | * @param timeout The timeout in miliseconds. Input parameter. |
203 | * @param[in] timeout The timeout in miliseconds. |
204 | * @param ttl The time to live. Input parameter. |
204 | * @param[in] ttl The time to live. |
205 | * @param tos The type of service. Input parameter. |
205 | * @param[in] tos The type of service. |
206 | * @param dont_fragment The value indicating whether the datagram must not be fragmented. Is used as a MTU discovery. Input parameter. |
206 | * @param[in] dont_fragment The value indicating whether the datagram must not be fragmented. Is used as a MTU discovery. |
207 | * @param addr The target host address. Input parameter. |
207 | * @param[in] addr The target host address. |
208 | * @param addrlen The torget host address length. Input parameter. |
208 | * @param[in] addrlen The torget host address length. |
209 | * @returns ICMP_ECHO on success. |
209 | * @returns ICMP_ECHO on success. |
210 | * @returns ETIMEOUT if the reply has not arrived before the timeout. |
210 | * @returns ETIMEOUT if the reply has not arrived before the timeout. |
211 | * @returns ICMP type of the received error notification. |
211 | * @returns ICMP type of the received error notification. |
212 | * @returns EINVAL if the addrlen parameter is less or equal to zero (<=0). |
212 | * @returns EINVAL if the addrlen parameter is less or equal to zero (<=0). |
213 | * @returns ENOMEM if there is not enough memory left. |
213 | * @returns ENOMEM if there is not enough memory left. |
Line 216... | Line 216... | ||
216 | 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, int dont_fragment, const struct sockaddr * addr, socklen_t addrlen ); |
216 | 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, int dont_fragment, const struct sockaddr * addr, socklen_t addrlen ); |
217 | 217 | ||
218 | /** Prepares the ICMP error packet. |
218 | /** Prepares the ICMP error packet. |
219 | * Truncates the original packet if longer than ICMP_KEEP_LENGTH bytes. |
219 | * Truncates the original packet if longer than ICMP_KEEP_LENGTH bytes. |
220 | * Prefixes and returns the ICMP header. |
220 | * Prefixes and returns the ICMP header. |
221 | * @param packet The original packet. Input/output parameter. |
221 | * @param[in,out] packet The original packet. |
222 | * @returns The prefixed ICMP header. |
222 | * @returns The prefixed ICMP header. |
223 | * @returns NULL on errors. |
223 | * @returns NULL on errors. |
224 | */ |
224 | */ |
225 | icmp_header_ref icmp_prepare_packet( packet_t packet ); |
225 | icmp_header_ref icmp_prepare_packet( packet_t packet ); |
226 | 226 | ||
227 | /** Sends the ICMP message. |
227 | /** Sends the ICMP message. |
228 | * Sets the message type and code and computes the checksum. |
228 | * Sets the message type and code and computes the checksum. |
229 | * Error messages are sent only if allowed in the configuration. |
229 | * Error messages are sent only if allowed in the configuration. |
230 | * Releases the packet on errors. |
230 | * Releases the packet on errors. |
231 | * @param type The message type. Input parameter. |
231 | * @param[in] type The message type. |
232 | * @param code The message code. Input parameter. |
232 | * @param[in] code The message code. |
233 | * @param packet The message packet to be sent. Input parameter. |
233 | * @param[in] packet The message packet to be sent. |
234 | * @param header The ICMP header. Input parameter. |
234 | * @param[in] header The ICMP header. |
235 | * @param error The error service to be announced. Should be SERVICE_ICMP or zero (0). Input parametr. |
235 | * @param[in] error The error service to be announced. Should be SERVICE_ICMP or zero (0). |
236 | * @param ttl The time to live. Input parameter. |
236 | * @param[in] ttl The time to live. |
237 | * @param tos The type of service. Input parameter. |
237 | * @param[in] tos The type of service. |
238 | * @param dont_fragment The value indicating whether the datagram must not be fragmented. Is used as a MTU discovery. Input parameter. |
238 | * @param[in] dont_fragment The value indicating whether the datagram must not be fragmented. Is used as a MTU discovery. |
239 | * @returns EOK on success. |
239 | * @returns EOK on success. |
240 | * @returns EPERM if the error message is not allowed. |
240 | * @returns EPERM if the error message is not allowed. |
241 | */ |
241 | */ |
242 | int icmp_send_packet( icmp_type_t type, icmp_code_t code, packet_t packet, icmp_header_ref header, services_t error, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment ); |
242 | int icmp_send_packet( icmp_type_t type, icmp_code_t code, packet_t packet, icmp_header_ref header, services_t error, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment ); |
243 | 243 | ||
244 | /** Tries to set the pending reply result as the received message type. |
244 | /** Tries to set the pending reply result as the received message type. |
245 | * If the reply data are still present, the reply timeouted and the parent fibril is awaken. |
245 | * If the reply data are still present, the reply timeouted and the parent fibril is awaken. |
246 | * The global lock is not released in this case to be reused by the parent fibril. |
246 | * The global lock is not released in this case to be reused by the parent fibril. |
247 | * Releases the packet. |
247 | * Releases the packet. |
248 | * @param packet The received reply message. Input parameter. |
248 | * @param[in] packet The received reply message. |
249 | * @param header The ICMP message header. Input parameter. |
249 | * @param[in] header The ICMP message header. |
250 | * @param type The received reply message type. Input parameter. |
250 | * @param[in] type The received reply message type. |
251 | * @param code The received reply message code. Input parameter. |
251 | * @param[in] code The received reply message code. |
252 | * @returns EOK. |
252 | * @returns EOK. |
253 | */ |
253 | */ |
254 | int icmp_process_echo_reply( packet_t packet, icmp_header_ref header, icmp_type_t type, icmp_code_t code ); |
254 | int icmp_process_echo_reply( packet_t packet, icmp_header_ref header, icmp_type_t type, icmp_code_t code ); |
255 | 255 | ||
256 | /** Tries to set the pending reply result as timeouted. |
256 | /** Tries to set the pending reply result as timeouted. |
257 | * Sleeps the timeout period of time and then tries to obtain and set the pending reply result as timeouted and signals the reply result. |
257 | * Sleeps the timeout period of time and then tries to obtain and set the pending reply result as timeouted and signals the reply result. |
258 | * If the reply data are still present, the reply timeouted and the parent fibril is awaken. |
258 | * If the reply data are still present, the reply timeouted and the parent fibril is awaken. |
259 | * The global lock is not released in this case to be reused by the parent fibril. |
259 | * The global lock is not released in this case to be reused by the parent fibril. |
260 | * Should run in a searate fibril. |
260 | * Should run in a searate fibril. |
261 | * @param data The icmp_reply_timeout structure. Input parameter. |
261 | * @param[in] data The icmp_reply_timeout structure. |
262 | * @returns EOK on success. |
262 | * @returns EOK on success. |
263 | * @returns EINVAL if the data parameter is NULL. |
263 | * @returns EINVAL if the data parameter is NULL. |
264 | */ |
264 | */ |
265 | int icmp_timeout_for_reply( void * data ); |
265 | int icmp_timeout_for_reply( void * data ); |
266 | 266 | ||
267 | /** Assigns a new identifier for the connection. |
267 | /** Assigns a new identifier for the connection. |
268 | * Fills the echo data parameter with the assigned values. |
268 | * Fills the echo data parameter with the assigned values. |
269 | * @param echo_data The echo data to be bound. Input/output parameter. |
269 | * @param[in,out] echo_data The echo data to be bound. |
270 | * @returns Index of the inserted echo data. |
270 | * @returns Index of the inserted echo data. |
271 | * @returns EBADMEM if the echo_data parameter is NULL. |
271 | * @returns EBADMEM if the echo_data parameter is NULL. |
272 | * @returns ENOTCONN if no free identifier have been found. |
272 | * @returns ENOTCONN if no free identifier have been found. |
273 | */ |
273 | */ |
274 | int icmp_bind_free_id( icmp_echo_ref echo_data ); |
274 | int icmp_bind_free_id( icmp_echo_ref echo_data ); |