Changeset 9e2e715 in mainline for uspace/srv/net/tl/icmp/icmp.c
- Timestamp:
- 2010-11-14T14:08:29Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a9db9b8, d52b0044, eb522e8
- Parents:
- 71e3289 (diff), fb04cba8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/icmp/icmp.c
r71e3289 r9e2e715 155 155 * @returns EPERM if the error message is not allowed. 156 156 */ 157 static int 158 icmp_send_packet(icmp_type_t type, icmp_code_t code, packet_t packet, 157 static int icmp_send_packet(icmp_type_t type, icmp_code_t code, packet_t packet, 159 158 icmp_header_ref header, services_t error, ip_ttl_t ttl, ip_tos_t tos, 160 159 int dont_fragment) … … 162 161 int rc; 163 162 164 / / do not send an error if disabled163 /* Do not send an error if disabled */ 165 164 if (error && !icmp_globals.error_reporting) 166 165 return icmp_release_and_return(packet, EPERM); … … 204 203 return NULL; 205 204 206 / / truncate if longer than 64 bits (without the IP header)205 /* Truncate if longer than 64 bits (without the IP header) */ 207 206 if ((total_length > header_length + ICMP_KEEP_LENGTH) && 208 207 (packet_trim(packet, 0, … … 244 243 * @returns EPARTY if there was an internal error. 245 244 */ 246 static int 247 icmp_echo(icmp_param_t id, icmp_param_t sequence, size_t size, 245 static int icmp_echo(icmp_param_t id, icmp_param_t sequence, size_t size, 248 246 mseconds_t timeout, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment, 249 247 const struct sockaddr * addr, socklen_t addrlen) … … 262 260 263 261 length = (size_t) addrlen; 264 / / TODO do not ask all the time262 /* TODO do not ask all the time */ 265 263 rc = ip_packet_size_req(icmp_globals.ip_phone, -1, 266 264 &icmp_globals.packet_dimension); … … 275 273 return ENOMEM; 276 274 277 // prepare the requesting packet 278 // set the destination address 275 /* Prepare the requesting packet, set the destination address. */ 279 276 rc = packet_set_addr(packet, NULL, (const uint8_t *) addr, length); 280 277 if (rc != EOK) 281 278 return icmp_release_and_return(packet, rc); 282 279 283 / / allocate space in the packet280 /* Allocate space in the packet */ 284 281 data = (uint8_t *) packet_suffix(packet, size); 285 282 if (!data) 286 283 return icmp_release_and_return(packet, ENOMEM); 287 284 288 / / fill the data285 /* Fill the data */ 289 286 length = 0; 290 287 while (size > length + sizeof(ICMP_ECHO_TEXT)) { … … 294 291 memcpy(data + length, ICMP_ECHO_TEXT, size - length); 295 292 296 / / prefix the header293 /* Prefix the header */ 297 294 header = PACKET_PREFIX(packet, icmp_header_t); 298 295 if (!header) … … 303 300 header->un.echo.sequence_number = sequence; 304 301 305 / / prepare the reply structure302 /* Prepare the reply structure */ 306 303 reply = malloc(sizeof(*reply)); 307 304 if (!reply) … … 319 316 } 320 317 321 / / unlock the globals so that we can wait for the reply318 /* Unlock the globals so that we can wait for the reply */ 322 319 fibril_rwlock_write_unlock(&icmp_globals.lock); 323 320 324 / / send the request321 /* Send the request */ 325 322 icmp_send_packet(ICMP_ECHO, 0, packet, header, 0, ttl, tos, 326 323 dont_fragment); 327 324 328 // wait for the reply 329 // timeout in microseconds 325 /* Wait for the reply. Timeout in microseconds. */ 330 326 rc = fibril_condvar_wait_timeout(&reply->condvar, &reply->mutex, 331 327 timeout * 1000); … … 333 329 rc = reply->result; 334 330 335 / / drop the reply mutex before locking the globals again331 /* Drop the reply mutex before locking the globals again */ 336 332 fibril_mutex_unlock(&reply->mutex); 337 333 fibril_rwlock_write_lock(&icmp_globals.lock); 338 334 339 / / destroy the reply structure335 /* Destroy the reply structure */ 340 336 icmp_replies_exclude_index(&icmp_globals.replies, index); 341 337 … … 343 339 } 344 340 345 static int 346 icmp_destination_unreachable_msg_local(int icmp_phone, icmp_code_t code, 347 icmp_param_t mtu, packet_t packet) 341 static int icmp_destination_unreachable_msg_local(int icmp_phone, 342 icmp_code_t code, icmp_param_t mtu, packet_t packet) 348 343 { 349 344 icmp_header_ref header; … … 372 367 } 373 368 374 static int 375 icmp_time_exceeded_msg_local(int icmp_phone, icmp_code_t code,packet_t packet)369 static int icmp_time_exceeded_msg_local(int icmp_phone, icmp_code_t code, 370 packet_t packet) 376 371 { 377 372 icmp_header_ref header; … … 385 380 } 386 381 387 static int 388 icmp_parameter_problem_msg_local(int icmp_phone, icmp_code_t code, 382 static int icmp_parameter_problem_msg_local(int icmp_phone, icmp_code_t code, 389 383 icmp_param_t pointer, packet_t packet) 390 384 { … … 449 443 icmp_globals.echo_replying = NET_DEFAULT_ICMP_ECHO_REPLYING; 450 444 451 / / get configuration445 /* Get configuration */ 452 446 configuration = &names[0]; 453 447 rc = net_get_conf_req(icmp_globals.net_phone, &configuration, count, … … 485 479 * @param[in] code The received reply message code. 486 480 */ 487 static void 488 icmp_process_echo_reply(packet_t packet, icmp_header_ref header, 481 static void icmp_process_echo_reply(packet_t packet, icmp_header_ref header, 489 482 icmp_type_t type, icmp_code_t code) 490 483 { … … 492 485 icmp_reply_ref reply; 493 486 494 / / compute the reply key487 /* Compute the reply key */ 495 488 reply_key = ICMP_GET_REPLY_KEY(header->un.echo.identifier, 496 489 header->un.echo.sequence_number); 497 490 pq_release_remote(icmp_globals.net_phone, packet_get_id(packet)); 498 491 492 /* Find the pending reply */ 499 493 fibril_rwlock_write_lock(&icmp_globals.lock); 500 // find the pending reply501 494 reply = icmp_replies_find(&icmp_globals.replies, reply_key); 502 495 if (reply) { … … 541 534 break; 542 535 case SERVICE_ICMP: 543 / / process error536 /* Process error */ 544 537 result = icmp_client_process_packet(packet, &type, &code, NULL, 545 538 NULL); … … 547 540 return result; 548 541 length = (size_t) result; 549 / / remove the error header542 /* Remove the error header */ 550 543 rc = packet_trim(packet, length, 0); 551 544 if (rc != EOK) … … 556 549 } 557 550 558 / / get rid of the ip header551 /* Get rid of the IP header */ 559 552 length = ip_client_header_length(packet); 560 553 rc = packet_trim(packet, length, 0); … … 573 566 return EINVAL; 574 567 575 / / get icmp header568 /* Get ICMP header */ 576 569 header = (icmp_header_ref) data; 577 570 578 571 if (header->checksum) { 579 572 while (ICMP_CHECKSUM(header, length) != IP_CHECKSUM_ZERO) { 580 // set the original message type on error notification 581 // type swap observed in Qemu 573 /* 574 * Set the original message type on error notification. 575 * Type swap observed in Qemu. 576 */ 582 577 if (error) { 583 578 switch (header->type) { … … 606 601 } 607 602 608 / / do not send a reply if disabled603 /* Do not send a reply if disabled */ 609 604 if (icmp_globals.echo_replying) { 610 605 addrlen = packet_get_addr(packet, &src, NULL); 611 606 612 // set both addresses to the source one (avoids the 613 // source address deletion before setting the 614 // destination one) 607 /* 608 * Set both addresses to the source one (avoids the 609 * source address deletion before setting the 610 * destination one). 611 */ 615 612 if ((addrlen > 0) && (packet_set_addr(packet, src, src, 616 613 (size_t) addrlen) == EOK)) { 617 / / send the reply614 /* Send the reply */ 618 615 icmp_send_packet(ICMP_ECHOREPLY, 0, packet, 619 616 header, 0, 0, 0, 0); … … 661 658 * icmp_process_packet() function. 662 659 */ 663 static int 664 icmp_received_msg_local(device_id_t device_id, packet_t packet, 660 static int icmp_received_msg_local(device_id_t device_id, packet_t packet, 665 661 services_t receiver, services_t error) 666 662 { … … 746 742 return EBADMEM; 747 743 748 / / from the last used one744 /* From the last used one */ 749 745 index = icmp_globals.last_used_id; 750 746 do { 751 747 index++; 752 / / til the range end748 /* til the range end */ 753 749 if (index >= ICMP_FREE_IDS_END) { 754 / / start from the range beginning750 /* start from the range beginning */ 755 751 index = ICMP_FREE_IDS_START - 1; 756 752 do { 757 753 index++; 758 / / til the last used one754 /* til the last used one */ 759 755 if (index >= icmp_globals.last_used_id) { 760 / / none found756 /* none found */ 761 757 return ENOTCONN; 762 758 } … … 764 760 index) != NULL); 765 761 766 / / found, break immediately762 /* Found, break immediately */ 767 763 break; 768 764 } … … 808 804 return ENOMEM; 809 805 810 / / assign a new identifier806 /* Assign a new identifier */ 811 807 fibril_rwlock_write_lock(&icmp_globals.lock); 812 808 rc = icmp_bind_free_id(echo_data); … … 818 814 819 815 while (keep_on_going) { 820 / / answer the call816 /* Answer the call */ 821 817 answer_call(callid, rc, &answer, answer_count); 822 818 823 / / refresh data819 /* Refresh data */ 824 820 refresh_answer(&answer, &answer_count); 825 821 826 / / get the next call822 /* Get the next call */ 827 823 callid = async_get_call(&call); 828 824 829 / / process the call825 /* Process the call */ 830 826 switch (IPC_GET_METHOD(call)) { 831 827 case IPC_M_PHONE_HUNGUP: … … 876 872 } 877 873 878 / / release the identifier874 /* Release the identifier */ 879 875 fibril_rwlock_write_lock(&icmp_globals.lock); 880 876 icmp_echo_data_exclude(&icmp_globals.echo_data, echo_data->identifier); … … 897 893 * @see IS_NET_ICMP_MESSAGE() 898 894 */ 899 int 900 icmp_message_standalone(ipc_callid_t callid, ipc_call_t *call, 895 int icmp_message_standalone(ipc_callid_t callid, ipc_call_t *call, 901 896 ipc_call_t *answer, int *answer_count) 902 897 {
Note:
See TracChangeset
for help on using the changeset viewer.