Changeset 3f0a7971 in mainline for uspace/srv/net/tl/udp/udp.c
- Timestamp:
- 2010-11-18T22:34:23Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 63b4f90
- Parents:
- c7137738 (diff), 45f04f8 (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/udp/udp.c
rc7137738 r3f0a7971 130 130 } 131 131 132 / / read default packet dimensions132 /* Read default packet dimensions */ 133 133 rc = ip_packet_size_req(udp_globals.ip_phone, -1, 134 134 &udp_globals.packet_dimension); … … 158 158 udp_globals.autobinding = NET_DEFAULT_UDP_AUTOBINDING; 159 159 160 / / get configuration160 /* Get configuration */ 161 161 configuration = &names[0]; 162 162 rc = net_get_conf_req(udp_globals.net_phone, &configuration, count, … … 217 217 * ip_client_process_packet() function. 218 218 */ 219 static int 220 udp_process_packet(device_id_t device_id, packet_t packet,services_t error)219 static int udp_process_packet(device_id_t device_id, packet_t packet, 220 services_t error) 221 221 { 222 222 size_t length; … … 242 242 break; 243 243 case SERVICE_ICMP: 244 / / ignore error244 /* Ignore error */ 245 245 // length = icmp_client_header_length(packet); 246 // process error 246 247 /* Process error */ 247 248 result = icmp_client_process_packet(packet, &type, 248 249 &code, NULL, NULL); … … 258 259 } 259 260 260 / / TODO process received ipopts?261 /* TODO process received ipopts? */ 261 262 result = ip_client_process_packet(packet, NULL, NULL, NULL, NULL, NULL); 262 263 if (result < 0) … … 270 271 return udp_release_and_return(packet, NO_DATA); 271 272 272 / / trim all but UDP header273 /* Trim all but UDP header */ 273 274 rc = packet_trim(packet, offset, 0); 274 275 if (rc != EOK) 275 276 return udp_release_and_return(packet, rc); 276 277 277 / / get udp header278 /* Get UDP header */ 278 279 header = (udp_header_ref) packet_get_data(packet); 279 280 if (!header) 280 281 return udp_release_and_return(packet, NO_DATA); 281 282 282 / / find the destination socket283 /* Find the destination socket */ 283 284 socket = socket_port_find(&udp_globals.sockets, 284 285 ntohs(header->destination_port), SOCKET_MAP_KEY_LISTENING, 0); … … 292 293 } 293 294 294 / / count the received packet fragments295 /* Count the received packet fragments */ 295 296 next_packet = packet; 296 297 fragments = 0; 297 298 total_length = ntohs(header->total_length); 298 299 299 / / compute header checksum if set300 /* Compute header checksum if set */ 300 301 if (header->checksum && !error) { 301 302 result = packet_get_addr(packet, (uint8_t **) &src, … … 310 311 } else { 311 312 checksum = compute_checksum(0, ip_header, length); 312 // the udp header checksum will be added with the first 313 // fragment later 313 /* 314 * The udp header checksum will be added with the first 315 * fragment later. 316 */ 314 317 free(ip_header); 315 318 } … … 330 333 return udp_release_and_return(packet, rc); 331 334 332 / / add partial checksum if set335 /* Add partial checksum if set */ 333 336 if (header->checksum) { 334 337 checksum = compute_checksum(checksum, … … 337 340 } 338 341 339 / / relese the rest of the packet fragments342 /* Relese the rest of the packet fragments */ 340 343 tmp_packet = pq_next(next_packet); 341 344 while (tmp_packet) { … … 346 349 } 347 350 348 / / exit the loop351 /* Exit the loop */ 349 352 break; 350 353 } 351 354 total_length -= length; 352 355 353 / / add partial checksum if set356 /* Add partial checksum if set */ 354 357 if (header->checksum) { 355 358 checksum = compute_checksum(checksum, … … 360 363 } while ((next_packet = pq_next(next_packet)) && (total_length > 0)); 361 364 362 / / check checksum365 /* Verify checksum */ 363 366 if (header->checksum) { 364 367 if (flip_checksum(compact_checksum(checksum)) != … … 366 369 if (tl_prepare_icmp_packet(udp_globals.net_phone, 367 370 udp_globals.icmp_phone, packet, error) == EOK) { 368 / / checksum error ICMP371 /* Checksum error ICMP */ 369 372 icmp_parameter_problem_msg( 370 373 udp_globals.icmp_phone, ICMP_PARAM_POINTER, … … 376 379 } 377 380 378 / / queue the received packet381 /* Queue the received packet */ 379 382 rc = dyn_fifo_push(&socket->received, packet_get_id(packet), 380 383 SOCKET_MAX_RECEIVED_SIZE); … … 387 390 return udp_release_and_return(packet, rc); 388 391 389 / / notify the destination socket392 /* Notify the destination socket */ 390 393 fibril_rwlock_write_unlock(&udp_globals.lock); 391 394 async_msg_5(socket->phone, NET_SOCKET_RECEIVED, … … 410 413 * udp_process_packet() function. 411 414 */ 412 static int 413 udp_received_msg(device_id_t device_id, packet_t packet, services_t receiver, 414 services_t error) 415 static int udp_received_msg(device_id_t device_id, packet_t packet, 416 services_t receiver, services_t error) 415 417 { 416 418 int result; … … 451 453 * function. 452 454 */ 453 static int 454 udp_sendto_message(socket_cores_ref local_sockets, int socket_id, 455 static int udp_sendto_message(socket_cores_ref local_sockets, int socket_id, 455 456 const struct sockaddr *addr, socklen_t addrlen, int fragments, 456 457 size_t *data_fragment_size, int flags) … … 480 481 481 482 if ((socket->port <= 0) && udp_globals.autobinding) { 482 / / bind the socket to a random free port if not bound483 /* Bind the socket to a random free port if not bound */ 483 484 rc = socket_bind_free_port(&udp_globals.sockets, socket, 484 485 UDP_FREE_PORTS_START, UDP_FREE_PORTS_END, … … 486 487 if (rc != EOK) 487 488 return rc; 488 / / set the next port as the search starting port number489 /* Set the next port as the search starting port number */ 489 490 udp_globals.last_used_port = socket->port; 490 491 } … … 495 496 if (rc != EOK) 496 497 return rc; 497 / / get the device packet dimension498 /* Get the device packet dimension */ 498 499 // rc = tl_get_ip_packet_dimension(udp_globals.ip_phone, 499 500 // &udp_globals.dimensions, device_id, &packet_dimension); … … 502 503 } 503 504 // } else { 504 / / do not ask all the time505 /* Do not ask all the time */ 505 506 rc = ip_packet_size_req(udp_globals.ip_phone, -1, 506 507 &udp_globals.packet_dimension); … … 510 511 // } 511 512 512 / / read the first packet fragment513 /* Read the first packet fragment */ 513 514 result = tl_socket_read_packet_data(udp_globals.net_phone, &packet, 514 515 UDP_HEADER_SIZE, packet_dimension, addr, addrlen); … … 523 524 checksum = 0; 524 525 525 / / prefix the udp header526 /* Prefix the UDP header */ 526 527 header = PACKET_PREFIX(packet, udp_header_t); 527 528 if (!header) … … 529 530 530 531 bzero(header, sizeof(*header)); 531 // read the rest of the packet fragments 532 533 /* Read the rest of the packet fragments */ 532 534 for (index = 1; index < fragments; index++) { 533 535 result = tl_socket_read_packet_data(udp_globals.net_phone, … … 548 550 } 549 551 550 / / set the udp header552 /* Set the UDP header */ 551 553 header->source_port = htons((socket->port > 0) ? socket->port : 0); 552 554 header->destination_port = htons(dest_port); 553 555 header->total_length = htons(total_length + sizeof(*header)); 554 556 header->checksum = 0; 557 555 558 if (udp_globals.checksum_computing) { 556 / / update the pseudo header559 /* Update the pseudo header */ 557 560 rc = ip_client_set_pseudo_header_data_length(ip_header, 558 561 headerlen, total_length + UDP_HEADER_SIZE); … … 562 565 } 563 566 564 / / finish the checksum computation567 /* Finish the checksum computation */ 565 568 checksum = compute_checksum(checksum, ip_header, headerlen); 566 569 checksum = compute_checksum(checksum, (uint8_t *) header, … … 573 576 } 574 577 575 / / prepare the first packet fragment578 /* Prepare the first packet fragment */ 576 579 rc = ip_client_prepare_packet(packet, IPPROTO_UDP, 0, 0, 0, 0); 577 580 if (rc != EOK) … … 581 584 fibril_rwlock_write_unlock(&udp_globals.lock); 582 585 583 / / send the packet586 /* Send the packet */ 584 587 ip_send_msg(udp_globals.ip_phone, device_id, packet, SERVICE_UDP, 0); 585 588 … … 606 609 * function. 607 610 */ 608 static int 609 udp_recvfrom_message(socket_cores_ref local_sockets, int socket_id, int flags, 610 size_t *addrlen) 611 static int udp_recvfrom_message(socket_cores_ref local_sockets, int socket_id, 612 int flags, size_t *addrlen) 611 613 { 612 614 socket_core_ref socket; … … 620 622 int rc; 621 623 622 / / find the socket624 /* Find the socket */ 623 625 socket = socket_cores_find(local_sockets, socket_id); 624 626 if (!socket) 625 627 return ENOTSOCK; 626 628 627 / / get the next received packet629 /* Get the next received packet */ 628 630 packet_id = dyn_fifo_value(&socket->received); 629 631 if (packet_id < 0) … … 636 638 } 637 639 638 / / get udp header640 /* Get UDP header */ 639 641 data = packet_get_data(packet); 640 642 if (!data) { … … 644 646 header = (udp_header_ref) data; 645 647 646 / / set the source address port648 /* Set the source address port */ 647 649 result = packet_get_addr(packet, (uint8_t **) &addr, NULL); 648 650 rc = tl_set_address_port(addr, result, ntohs(header->source_port)); … … 653 655 *addrlen = (size_t) result; 654 656 655 / / send the source address657 /* Send the source address */ 656 658 rc = data_reply(addr, *addrlen); 657 659 switch (rc) { … … 665 667 } 666 668 667 / / trim the header669 /* Trim the header */ 668 670 rc = packet_trim(packet, UDP_HEADER_SIZE, 0); 669 671 if (rc != EOK) { … … 672 674 } 673 675 674 / / reply the packets676 /* Reply the packets */ 675 677 rc = socket_reply_packets(packet, &length); 676 678 switch (rc) { … … 686 688 (void) dyn_fifo_pop(&socket->received); 687 689 688 / / release the packet and return the total length690 /* Release the packet and return the total length */ 689 691 return udp_release_and_return(packet, (int) length); 690 692 } … … 721 723 answer_count = 0; 722 724 723 // The client connection is only in one fibril and therefore no 724 // additional locks are needed. 725 /* 726 * The client connection is only in one fibril and therefore no 727 * additional locks are needed. 728 */ 725 729 726 730 socket_cores_initialize(&local_sockets); … … 728 732 while (keep_on_going) { 729 733 730 / / answer the call734 /* Answer the call */ 731 735 answer_call(callid, res, &answer, answer_count); 732 736 733 / / refresh data737 /* Refresh data */ 734 738 refresh_answer(&answer, &answer_count); 735 739 736 / / get the next call740 /* Get the next call */ 737 741 callid = async_get_call(&call); 738 742 739 / / process the call743 /* Process the call */ 740 744 switch (IPC_GET_METHOD(call)) { 741 745 case IPC_M_PHONE_HUNGUP: … … 831 835 } 832 836 833 / / release the application phone837 /* Release the application phone */ 834 838 ipc_hangup(app_phone); 835 839 836 / / release all local sockets840 /* Release all local sockets */ 837 841 socket_cores_release(udp_globals.net_phone, &local_sockets, 838 842 &udp_globals.sockets, NULL); … … 854 858 * @see IS_NET_UDP_MESSAGE() 855 859 */ 856 int 857 udp_message_standalone(ipc_callid_t callid, ipc_call_t *call, 860 int udp_message_standalone(ipc_callid_t callid, ipc_call_t *call, 858 861 ipc_call_t *answer, int *answer_count) 859 862 {
Note:
See TracChangeset
for help on using the changeset viewer.