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