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