Changeset 0578271 in mainline
- Timestamp:
- 2010-11-06T00:17:58Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0b81cad0, 32efd86
- Parents:
- 376a7fd
- Location:
- uspace/srv/net/tl/tcp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/tcp/tcp.c
r376a7fd r0578271 47 47 #include <stdio.h> 48 48 #include <errno.h> 49 #include <err.h>50 49 51 50 #include <ipc/ipc.h> … … 235 234 int tcp_initialize(async_client_conn_t client_connection) 236 235 { 237 ERROR_DECLARE;236 int rc; 238 237 239 238 assert(client_connection); … … 246 245 tcp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_TCP, 247 246 SERVICE_TCP, client_connection); 248 if (tcp_globals.ip_phone < 0) 247 if (tcp_globals.ip_phone < 0) { 248 fibril_rwlock_write_unlock(&tcp_globals.lock); 249 249 return tcp_globals.ip_phone; 250 } 250 251 251 ERROR_PROPAGATE(socket_ports_initialize(&tcp_globals.sockets)); 252 if (ERROR_OCCURRED(packet_dimensions_initialize( 253 &tcp_globals.dimensions))) { 252 rc = socket_ports_initialize(&tcp_globals.sockets); 253 if (rc != EOK) 254 goto out; 255 256 rc = packet_dimensions_initialize(&tcp_globals.dimensions); 257 if (rc != EOK) { 254 258 socket_ports_destroy(&tcp_globals.sockets); 255 return ERROR_CODE;259 goto out; 256 260 } 257 261 258 262 tcp_globals.last_used_port = TCP_FREE_PORTS_START - 1; 263 264 out: 259 265 fibril_rwlock_write_unlock(&tcp_globals.lock); 260 261 return EOK; 266 return rc; 262 267 } 263 268 … … 266 271 services_t error) 267 272 { 268 ERROR_DECLARE;273 int rc; 269 274 270 275 if (receiver != SERVICE_TCP) … … 272 277 273 278 fibril_rwlock_write_lock(&tcp_globals.lock); 274 if (ERROR_OCCURRED(tcp_process_packet(device_id, packet, error))) 279 rc = tcp_process_packet(device_id, packet, error); 280 if (rc != EOK) 275 281 fibril_rwlock_write_unlock(&tcp_globals.lock); 276 282 277 printf("receive %d \n", ERROR_CODE);278 279 return ERROR_CODE;283 printf("receive %d \n", rc); 284 285 return rc; 280 286 } 281 287 282 288 int tcp_process_packet(device_id_t device_id, packet_t packet, services_t error) 283 289 { 284 ERROR_DECLARE;285 286 290 size_t length; 287 291 size_t offset; … … 299 303 struct sockaddr *dest; 300 304 size_t addrlen; 305 int rc; 301 306 302 307 switch (error) { … … 311 316 312 317 length = (size_t) result; 313 if (ERROR_OCCURRED(packet_trim(packet, length, 0))) 314 return tcp_release_and_return(packet, ERROR_CODE); 318 rc = packet_trim(packet, length, 0); 319 if (rc != EOK) 320 return tcp_release_and_return(packet, rc); 315 321 break; 316 322 default: … … 333 339 334 340 // trim all but TCP header 335 if (ERROR_OCCURRED(packet_trim(packet, offset, 0))) 336 return tcp_release_and_return(packet, ERROR_CODE); 341 rc = packet_trim(packet, offset, 0); 342 if (rc != EOK) 343 return tcp_release_and_return(packet, rc); 337 344 338 345 // get tcp header … … 350 357 addrlen = (size_t) result; 351 358 352 if (ERROR_OCCURRED(tl_set_address_port(src, addrlen,353 ntohs(header->source_port))))354 return tcp_release_and_return(packet, ERROR_CODE);359 rc = tl_set_address_port(src, addrlen, ntohs(header->source_port)); 360 if (rc != EOK) 361 return tcp_release_and_return(packet, rc); 355 362 356 363 // find the destination socket … … 413 420 } 414 421 415 if (ERROR_OCCURRED(ip_client_get_pseudo_header(IPPROTO_TCP, src, 416 addrlen, dest, addrlen, total_length, 417 &socket_data->pseudo_header, &socket_data->headerlen))) { 422 rc = ip_client_get_pseudo_header(IPPROTO_TCP, src, addrlen, 423 dest, addrlen, total_length, &socket_data->pseudo_header, 424 &socket_data->headerlen); 425 if (rc != EOK) { 418 426 fibril_rwlock_write_unlock(socket_data->local_lock); 419 return tcp_release_and_return(packet, ERROR_CODE); 420 } 421 422 } else if (ERROR_OCCURRED(ip_client_set_pseudo_header_data_length( 423 socket_data->pseudo_header, socket_data->headerlen, 424 total_length))) { 425 fibril_rwlock_write_unlock(socket_data->local_lock); 426 return tcp_release_and_return(packet, ERROR_CODE); 427 return tcp_release_and_return(packet, rc); 428 } 429 } else { 430 rc = ip_client_set_pseudo_header_data_length( 431 socket_data->pseudo_header, socket_data->headerlen, 432 total_length); 433 if (rc != EOK) { 434 fibril_rwlock_write_unlock(socket_data->local_lock); 435 return tcp_release_and_return(packet, rc); 436 } 427 437 } 428 438 … … 434 444 fibril_rwlock_write_unlock(socket_data->local_lock); 435 445 436 if (ERROR_NONE(tl_prepare_icmp_packet(tcp_globals.net_phone, 437 tcp_globals.icmp_phone, packet, error))) { 446 rc = tl_prepare_icmp_packet(tcp_globals.net_phone, 447 tcp_globals.icmp_phone, packet, error); 448 if (rc == EOK) { 438 449 // checksum error ICMP 439 450 icmp_parameter_problem_msg(tcp_globals.icmp_phone, … … 452 463 switch (socket_data->state) { 453 464 case TCP_SOCKET_LISTEN: 454 ERROR_CODE = tcp_process_listen(socket, socket_data, header,455 packet,src, dest, addrlen);465 rc = tcp_process_listen(socket, socket_data, header, packet, 466 src, dest, addrlen); 456 467 break; 457 468 case TCP_SOCKET_SYN_RECEIVED: 458 ERROR_CODE = tcp_process_syn_received(socket, socket_data,459 header,packet);469 rc = tcp_process_syn_received(socket, socket_data, header, 470 packet); 460 471 break; 461 472 case TCP_SOCKET_SYN_SENT: 462 ERROR_CODE = tcp_process_syn_sent(socket, socket_data, header, 463 packet); 473 rc = tcp_process_syn_sent(socket, socket_data, header, packet); 464 474 break; 465 475 case TCP_SOCKET_FIN_WAIT_1: … … 472 482 // ack releasing the socket gets processed later 473 483 case TCP_SOCKET_ESTABLISHED: 474 ERROR_CODE = tcp_process_established(socket, socket_data,475 header,packet, fragments, total_length);484 rc = tcp_process_established(socket, socket_data, header, 485 packet, fragments, total_length); 476 486 break; 477 487 default: … … 479 489 } 480 490 481 if (ERROR_CODE != EOK) { 482 printf("process %d\n", ERROR_CODE); 491 if (rc != EOK) { 483 492 fibril_rwlock_write_unlock(socket_data->local_lock); 493 printf("process %d\n", rc); 484 494 } 485 495 … … 491 501 tcp_header_ref header, packet_t packet, int fragments, size_t total_length) 492 502 { 493 ERROR_DECLARE;494 495 503 packet_t next_packet; 496 504 packet_t tmp_packet; … … 501 509 size_t offset; 502 510 uint32_t new_sequence_number; 511 int rc; 503 512 504 513 assert(socket); … … 541 550 } 542 551 543 if ((offset > 0) && (ERROR_OCCURRED(packet_trim(packet, 544 offset, 0)))) 545 return tcp_release_and_return(packet, ERROR_CODE); 552 if (offset > 0) { 553 rc = packet_trim(packet, offset, 0); 554 if (rc != EOK) 555 return tcp_release_and_return(packet, rc); 556 } 546 557 547 558 assert(new_sequence_number == socket_data->next_incoming); … … 575 586 if (length <= offset) 576 587 next_packet = pq_next(next_packet); 577 else if (ERROR_OCCURRED(packet_trim(next_packet, 0, 578 length - offset))) 579 return tcp_release_and_return(packet, 580 ERROR_CODE); 588 else { 589 rc = packet_trim(next_packet, 0, 590 length - offset)); 591 if (rc != EOK) 592 return tcp_release_and_return(packet, 593 rc); 594 } 581 595 offset -= length; 582 596 total_length -= length - offset; … … 603 617 // remove the header 604 618 total_length -= TCP_HEADER_LENGTH(header); 605 if (ERROR_OCCURRED(packet_trim(packet,606 TCP_HEADER_LENGTH(header), 0)))607 return tcp_release_and_return(packet, ERROR_CODE);619 rc = packet_trim(packet, TCP_HEADER_LENGTH(header), 0); 620 if (rc != EOK) 621 return tcp_release_and_return(packet, rc); 608 622 609 623 if (total_length) { 610 ERROR_PROPAGATE(tcp_queue_received_packet(socket, 611 socket_data, packet, fragments, total_length)); 624 rc = tcp_queue_received_packet(socket, socket_data, 625 packet, fragments, total_length); 626 if (rc != EOK) 627 return rc; 612 628 } else { 613 629 total_length = 1; … … 617 633 packet = socket_data->incoming; 618 634 while (packet) { 619 620 if (ERROR_OCCURRED(pq_get_order(socket_data->incoming, 621 &order, NULL))) { 635 rc = pq_get_order(socket_data->incoming, &order, NULL); 636 if (rc != EOK) { 622 637 // remove the corrupted packet 623 638 next_packet = pq_detach(packet); … … 656 671 socket_data->next_incoming) { 657 672 // queue received data 658 ERROR_PROPAGATE( 659 tcp_queue_received_packet(socket, 673 rc = tcp_queue_received_packet(socket, 660 674 socket_data, packet, 1, 661 packet_get_data_length(packet))); 675 packet_get_data_length(packet)); 676 if (rc != EOK) 677 return rc; 662 678 socket_data->next_incoming = 663 679 new_sequence_number; … … 677 693 new_sequence_number; 678 694 } 679 if (ERROR_NONE(packet_trim(packet,680 length, 0))) {695 rc = packet_trim(packet,length, 0); 696 if (rc == EOK) { 681 697 // queue received data 682 ERROR_PROPAGATE( 683 tcp_queue_received_packet( 698 rc = tcp_queue_received_packet( 684 699 socket, socket_data, packet, 685 700 1, packet_get_data_length( 686 packet))); 701 packet)); 702 if (rc != EOK) 703 return rc; 687 704 socket_data->next_incoming = 688 705 new_sequence_number; … … 709 726 // remove the header 710 727 total_length -= TCP_HEADER_LENGTH(header); 711 if (ERROR_OCCURRED(packet_trim(packet,712 TCP_HEADER_LENGTH(header), 0)))713 return tcp_release_and_return(packet, ERROR_CODE);728 rc = packet_trim(packet, TCP_HEADER_LENGTH(header), 0); 729 if (rc != EOK) 730 return tcp_release_and_return(packet, rc); 714 731 715 732 next_packet = pq_detach(packet); 716 733 length = packet_get_data_length(packet); 717 if (ERROR_OCCURRED(pq_add(&socket_data->incoming, packet, 718 new_sequence_number, length))) { 734 rc = pq_add(&socket_data->incoming, packet, new_sequence_number, 735 length); 736 if (rc != EOK) { 719 737 // remove the corrupted packets 720 738 pq_release_remote(tcp_globals.net_phone, … … 727 745 tmp_packet = pq_detach(next_packet); 728 746 length = packet_get_data_length(next_packet); 729 if (ERROR_OCCURRED(pq_set_order(next_packet, 730 new_sequence_number, length)) || 731 ERROR_OCCURRED(pq_insert_after(packet, 732 next_packet))) { 747 748 rc = pq_set_order(next_packet, 749 new_sequence_number, length); 750 if (rc != EOK) { 751 pq_release_remote(tcp_globals.net_phone, 752 packet_get_id(next_packet)); 753 } 754 rc = pq_insert_after(packet, next_packet); 755 if (rc != EOK) { 733 756 pq_release_remote(tcp_globals.net_phone, 734 757 packet_get_id(next_packet)); … … 762 785 if (!packet) { 763 786 // create the notification packet 764 ERROR_PROPAGATE(tcp_create_notification_packet(&packet, socket, 765 socket_data, 0, 0)); 766 ERROR_PROPAGATE(tcp_queue_prepare_packet(socket, socket_data, 767 packet, 1)); 787 rc = tcp_create_notification_packet(&packet, socket, 788 socket_data, 0, 0); 789 if (rc != EOK) 790 return rc; 791 rc = tcp_queue_prepare_packet(socket, socket_data, packet, 1); 792 if (rc != EOK) 793 return rc; 768 794 packet = tcp_send_prepare_packet(socket, socket_data, packet, 1, 769 795 socket_data->last_outgoing + 1); … … 783 809 size_t total_length) 784 810 { 785 ERROR_DECLARE;786 787 811 packet_dimension_ref packet_dimension; 812 int rc; 788 813 789 814 assert(socket); … … 795 820 796 821 // queue the received packet 797 if (ERROR_OCCURRED(dyn_fifo_push(&socket->received, 798 packet_get_id(packet), SOCKET_MAX_RECEIVED_SIZE)) || 799 ERROR_OCCURRED(tl_get_ip_packet_dimension(tcp_globals.ip_phone, 800 &tcp_globals.dimensions, socket_data->device_id, 801 &packet_dimension))) { 802 return tcp_release_and_return(packet, ERROR_CODE); 803 } 822 rc = dyn_fifo_push(&socket->received, packet_get_id(packet), 823 SOCKET_MAX_RECEIVED_SIZE); 824 if (rc != EOK) 825 return tcp_release_and_return(packet, rc); 826 rc = tl_get_ip_packet_dimension(tcp_globals.ip_phone, 827 &tcp_globals.dimensions, socket_data->device_id, &packet_dimension); 828 if (rc != EOK) 829 return tcp_release_and_return(packet, rc); 804 830 805 831 // decrease the window size … … 820 846 tcp_header_ref header, packet_t packet) 821 847 { 822 ERROR_DECLARE;823 824 848 packet_t next_packet; 849 int rc; 825 850 826 851 assert(socket); … … 844 869 } 845 870 // trim if longer than the header 846 if ((packet_get_data_length(packet) > sizeof(*header)) && 847 ERROR_OCCURRED(packet_trim(packet, 0, 848 packet_get_data_length(packet) - sizeof(*header)))) { 849 return tcp_release_and_return(packet, ERROR_CODE); 871 if (packet_get_data_length(packet) > sizeof(*header)) { 872 rc = packet_trim(packet, 0, 873 packet_get_data_length(packet) - sizeof(*header)); 874 if (rc != EOK) 875 return tcp_release_and_return(packet, rc); 850 876 } 851 877 tcp_prepare_operation_header(socket, socket_data, header, 0, 0); … … 876 902 size_t addrlen) 877 903 { 878 ERROR_DECLARE;879 880 904 packet_t next_packet; 881 905 socket_core_ref socket; … … 884 908 int listening_socket_id = listening_socket->socket_id; 885 909 int listening_port = listening_socket->port; 910 int rc; 886 911 887 912 assert(listening_socket); … … 913 938 memcpy(socket_data->addr, src, socket_data->addrlen); 914 939 socket_data->dest_port = ntohs(header->source_port); 915 if (ERROR_OCCURRED(tl_set_address_port(socket_data->addr, 916 socket_data->addrlen, socket_data->dest_port))) { 940 rc = tl_set_address_port(socket_data->addr, socket_data->addrlen, 941 socket_data->dest_port); 942 if (rc != EOK) { 917 943 free(socket_data->addr); 918 944 free(socket_data); 919 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 920 return ERROR_CODE; 945 return tcp_release_and_return(packet, rc); 921 946 } 922 947 923 948 // create a socket 924 949 socket_id = -1; 925 if (ERROR_OCCURRED(socket_create(socket_data->local_sockets, 926 listening_socket->phone, socket_data, &socket_id))) { 950 rc = socket_create(socket_data->local_sockets, listening_socket->phone, 951 socket_data, &socket_id); 952 if (rc != EOK) { 927 953 free(socket_data->addr); 928 954 free(socket_data); 929 return tcp_release_and_return(packet, ERROR_CODE);955 return tcp_release_and_return(packet, rc); 930 956 } 931 957 … … 964 990 assert(socket_data); 965 991 966 ERROR_CODE = socket_port_add(&tcp_globals.sockets, listening_port,967 socket,(const char *) socket_data->addr, socket_data->addrlen);992 rc = socket_port_add(&tcp_globals.sockets, listening_port, socket, 993 (const char *) socket_data->addr, socket_data->addrlen); 968 994 assert(socket == socket_port_find(&tcp_globals.sockets, listening_port, 969 995 (const char *) socket_data->addr, socket_data->addrlen)); 970 996 971 // ERROR_CODE= socket_bind_free_port(&tcp_globals.sockets, socket,997 // rc = socket_bind_free_port(&tcp_globals.sockets, socket, 972 998 // TCP_FREE_PORTS_START, TCP_FREE_PORTS_END, 973 999 // tcp_globals.last_used_port); 974 1000 // tcp_globals.last_used_port = socket->port; 975 1001 fibril_rwlock_write_unlock(&tcp_globals.lock); 976 if ( ERROR_CODE!= EOK) {1002 if (rc != EOK) { 977 1003 socket_destroy(tcp_globals.net_phone, socket->socket_id, 978 1004 socket_data->local_sockets, &tcp_globals.sockets, 979 1005 tcp_free_socket_data); 980 return tcp_release_and_return(packet, ERROR_CODE);1006 return tcp_release_and_return(packet, rc); 981 1007 } 982 1008 … … 992 1018 993 1019 // trim if longer than the header 994 if ((packet_get_data_length(packet) > sizeof(*header)) && 995 ERROR_OCCURRED(packet_trim(packet, 0, 996 packet_get_data_length(packet) - sizeof(*header)))) { 1020 if (packet_get_data_length(packet) > sizeof(*header)) { 1021 rc = packet_trim(packet, 0, 1022 packet_get_data_length(packet) - sizeof(*header)); 1023 if (rc != EOK) { 1024 socket_destroy(tcp_globals.net_phone, socket->socket_id, 1025 socket_data->local_sockets, &tcp_globals.sockets, 1026 tcp_free_socket_data); 1027 return tcp_release_and_return(packet, rc); 1028 } 1029 } 1030 1031 tcp_prepare_operation_header(socket, socket_data, header, 1, 0); 1032 1033 rc = tcp_queue_packet(socket, socket_data, packet, 1); 1034 if (rc != EOK) { 997 1035 socket_destroy(tcp_globals.net_phone, socket->socket_id, 998 1036 socket_data->local_sockets, &tcp_globals.sockets, 999 1037 tcp_free_socket_data); 1000 return tcp_release_and_return(packet, ERROR_CODE); 1001 } 1002 1003 tcp_prepare_operation_header(socket, socket_data, header, 1, 0); 1004 1005 if (ERROR_OCCURRED(tcp_queue_packet(socket, socket_data, packet, 1))) { 1006 socket_destroy(tcp_globals.net_phone, socket->socket_id, 1007 socket_data->local_sockets, &tcp_globals.sockets, 1008 tcp_free_socket_data); 1009 return ERROR_CODE; 1038 return rc; 1010 1039 } 1011 1040 … … 1031 1060 tcp_socket_data_ref socket_data, tcp_header_ref header, packet_t packet) 1032 1061 { 1033 ERROR_DECLARE;1034 1035 1062 socket_core_ref listening_socket; 1036 1063 tcp_socket_data_ref listening_socket_data; 1064 int rc; 1037 1065 1038 1066 assert(socket); … … 1059 1087 1060 1088 // queue the received packet 1061 if (ERROR_NONE(dyn_fifo_push(&listening_socket->accepted, 1062 (-1 * socket->socket_id), 1063 listening_socket_data->backlog))) { 1064 1089 rc = dyn_fifo_push(&listening_socket->accepted, 1090 (-1 * socket->socket_id), listening_socket_data->backlog); 1091 if (rc == EOK) { 1065 1092 // notify the destination socket 1066 1093 async_msg_5(socket->phone, NET_SOCKET_ACCEPTED, … … 1077 1104 1078 1105 // create the notification packet 1079 ERROR_PROPAGATE(tcp_create_notification_packet(&packet, socket, 1080 socket_data, 0, 1)); 1106 rc = tcp_create_notification_packet(&packet, socket, socket_data, 0, 1); 1107 if (rc != EOK) 1108 return rc; 1081 1109 1082 1110 // send the packet 1083 ERROR_PROPAGATE(tcp_queue_packet(socket, socket_data, packet, 1)); 1111 rc = tcp_queue_packet(socket, socket_data, packet, 1); 1112 if (rc != EOK) 1113 return rc; 1084 1114 1085 1115 // flush packets … … 1198 1228 ipc_call_t *answer, int *answer_count) 1199 1229 { 1200 ERROR_DECLARE;1201 1202 1230 packet_t packet; 1231 int rc; 1203 1232 1204 1233 assert(call); … … 1209 1238 switch (IPC_GET_METHOD(*call)) { 1210 1239 case NET_TL_RECEIVED: 1211 //fibril_rwlock_read_lock(&tcp_globals.lock); 1212 if (ERROR_NONE(packet_translate_remote(tcp_globals.net_phone, 1213 &packet, IPC_GET_PACKET(call)))) { 1214 ERROR_CODE = tcp_received_msg(IPC_GET_DEVICE(call), 1215 packet, SERVICE_TCP, IPC_GET_ERROR(call)); 1216 } 1217 //fibril_rwlock_read_unlock(&tcp_globals.lock); 1218 return ERROR_CODE; 1219 1240 // fibril_rwlock_read_lock(&tcp_globals.lock); 1241 rc = packet_translate_remote(tcp_globals.net_phone, &packet, 1242 IPC_GET_PACKET(call)); 1243 if (rc != EOK) { 1244 // fibril_rwlock_read_unlock(&tcp_globals.lock); 1245 return rc; 1246 } 1247 rc = tcp_received_msg(IPC_GET_DEVICE(call), packet, SERVICE_TCP, 1248 IPC_GET_ERROR(call)); 1249 // fibril_rwlock_read_unlock(&tcp_globals.lock); 1250 return rc; 1220 1251 case IPC_M_CONNECT_TO_ME: 1221 1252 return tcp_process_client_messages(callid, *call); … … 1662 1693 struct sockaddr *addr, socklen_t addrlen) 1663 1694 { 1664 ERROR_DECLARE;1665 1666 1695 socket_core_ref socket; 1696 int rc; 1667 1697 1668 1698 assert(local_sockets); … … 1675 1705 return ENOTSOCK; 1676 1706 1677 if (ERROR_OCCURRED(tcp_connect_core(socket, local_sockets, addr,1678 addrlen))) {1707 rc = tcp_connect_core(socket, local_sockets, addr, addrlen); 1708 if (rc != EOK) { 1679 1709 tcp_free_socket_data(socket); 1680 1710 // unbind if bound … … 1685 1715 } 1686 1716 } 1687 return ERROR_CODE;1717 return rc; 1688 1718 } 1689 1719 … … 1692 1722 struct sockaddr *addr, socklen_t addrlen) 1693 1723 { 1694 ERROR_DECLARE;1695 1696 1724 tcp_socket_data_ref socket_data; 1697 1725 packet_t packet; 1726 int rc; 1698 1727 1699 1728 assert(socket); … … 1711 1740 1712 1741 // get the destination port 1713 ERROR_PROPAGATE(tl_get_address_port(addr, addrlen, 1714 &socket_data->dest_port)); 1742 rc = tl_get_address_port(addr, addrlen, &socket_data->dest_port); 1743 if (rc != EOK) 1744 return rc; 1745 1715 1746 if (socket->port <= 0) { 1716 1747 // try to find a free port 1717 ERROR_PROPAGATE(socket_bind_free_port(&tcp_globals.sockets, 1718 socket, TCP_FREE_PORTS_START, TCP_FREE_PORTS_END, 1719 tcp_globals.last_used_port)); 1748 rc = socket_bind_free_port(&tcp_globals.sockets, socket, 1749 TCP_FREE_PORTS_START, TCP_FREE_PORTS_END, 1750 tcp_globals.last_used_port); 1751 if (rc != EOK) 1752 return rc; 1720 1753 // set the next port as the search starting port number 1721 1754 tcp_globals.last_used_port = socket->port; 1722 1755 } 1723 1756 1724 ERROR_PROPAGATE(ip_get_route_req(tcp_globals.ip_phone, IPPROTO_TCP,1757 rc = ip_get_route_req(tcp_globals.ip_phone, IPPROTO_TCP, 1725 1758 addr, addrlen, &socket_data->device_id, 1726 &socket_data->pseudo_header, &socket_data->headerlen)); 1759 &socket_data->pseudo_header, &socket_data->headerlen); 1760 if (rc != EOK) 1761 return rc; 1727 1762 1728 1763 // create the notification packet 1729 ERROR_PROPAGATE(tcp_create_notification_packet(&packet, socket, 1730 socket_data, 1, 0)); 1764 rc = tcp_create_notification_packet(&packet, socket, socket_data, 1, 0); 1765 if (rc != EOK) 1766 return rc; 1731 1767 1732 1768 // unlock the globals and wait for an operation … … 1736 1772 socket_data->addrlen = addrlen; 1737 1773 // send the packet 1738 if (ERROR_OCCURRED(tcp_queue_packet(socket, socket_data, packet, 1)) || 1739 ERROR_OCCURRED(tcp_prepare_timeout(tcp_timeout, socket, socket_data, 1740 0, TCP_SOCKET_INITIAL, NET_DEFAULT_TCP_INITIAL_TIMEOUT, false))) { 1774 1775 if (((rc = tcp_queue_packet(socket, socket_data, packet, 1)) != EOK) || 1776 ((rc = tcp_prepare_timeout(tcp_timeout, socket, socket_data, 0, 1777 TCP_SOCKET_INITIAL, NET_DEFAULT_TCP_INITIAL_TIMEOUT, false)) != 1778 EOK)) { 1741 1779 socket_data->addr = NULL; 1742 1780 socket_data->addrlen = 0; … … 1754 1792 fibril_condvar_wait(&socket_data->operation.condvar, 1755 1793 &socket_data->operation.mutex); 1756 ERROR_CODE= socket_data->operation.result;1757 if ( ERROR_CODE!= EOK) {1794 rc = socket_data->operation.result; 1795 if (rc != EOK) { 1758 1796 socket_data->addr = NULL; 1759 1797 socket_data->addrlen = 0; … … 1762 1800 socket_data->addr = NULL; 1763 1801 socket_data->addrlen = 0; 1764 ERROR_CODE= EINTR;1802 rc = EINTR; 1765 1803 } 1766 1804 } … … 1769 1807 1770 1808 // return the result 1771 return ERROR_CODE;1809 return rc; 1772 1810 } 1773 1811 … … 1776 1814 tcp_socket_data_ref socket_data, packet_t packet, size_t data_length) 1777 1815 { 1778 ERROR_DECLARE;1779 1780 1816 tcp_header_ref header; 1817 int rc; 1781 1818 1782 1819 assert(socket); … … 1793 1830 header->sequence_number = htonl(socket_data->next_outgoing); 1794 1831 1795 if (ERROR_OCCURRED(packet_set_addr(packet, NULL, 1796 (uint8_t *) socket_data->addr, socket_data->addrlen))) 1832 rc = packet_set_addr(packet, NULL, (uint8_t *) socket_data->addr, 1833 socket_data->addrlen); 1834 if (rc != EOK) 1797 1835 return tcp_release_and_return(packet, EINVAL); 1798 1836 … … 1808 1846 packet_t packet, size_t data_length) 1809 1847 { 1810 ERROR_DECLARE;1848 int rc; 1811 1849 1812 1850 assert(socket); … … 1814 1852 assert(socket->specific_data == socket_data); 1815 1853 1816 ERROR_PROPAGATE(tcp_queue_prepare_packet(socket, socket_data, packet, 1817 data_length)); 1818 1819 if (ERROR_OCCURRED(pq_add(&socket_data->outgoing, packet, 1820 socket_data->next_outgoing, data_length))) 1821 return tcp_release_and_return(packet, ERROR_CODE); 1854 rc = tcp_queue_prepare_packet(socket, socket_data, packet, data_length); 1855 if (rc != EOK) 1856 return rc; 1857 1858 rc = pq_add(&socket_data->outgoing, packet, socket_data->next_outgoing, 1859 data_length); 1860 if (rc != EOK) 1861 return tcp_release_and_return(packet, rc); 1822 1862 1823 1863 socket_data->next_outgoing += data_length; … … 1828 1868 tcp_get_packets_to_send(socket_core_ref socket, tcp_socket_data_ref socket_data) 1829 1869 { 1830 ERROR_DECLARE;1831 1832 1870 packet_t packet; 1833 1871 packet_t copy; … … 1835 1873 packet_t previous = NULL; 1836 1874 size_t data_length; 1875 int rc; 1837 1876 1838 1877 assert(socket); … … 1859 1898 if (!sending) { 1860 1899 sending = copy; 1861 } else if (ERROR_OCCURRED(pq_insert_after(previous, copy))) { 1862 pq_release_remote(tcp_globals.net_phone, 1863 packet_get_id(copy)); 1864 return sending; 1900 } else { 1901 rc = pq_insert_after(previous, copy); 1902 if (rc != EOK) { 1903 pq_release_remote(tcp_globals.net_phone, 1904 packet_get_id(copy)); 1905 return sending; 1906 } 1865 1907 } 1866 1908 … … 1884 1926 packet_t packet, size_t data_length, size_t sequence_number) 1885 1927 { 1886 ERROR_DECLARE;1887 1888 1928 tcp_header_ref header; 1889 1929 uint32_t checksum; 1930 int rc; 1890 1931 1891 1932 assert(socket); … … 1894 1935 1895 1936 // adjust the pseudo header 1896 if (ERROR_OCCURRED(ip_client_set_pseudo_header_data_length(1897 socket_data-> pseudo_header, socket_data->headerlen,1898 packet_get_data_length(packet)))) {1937 rc = ip_client_set_pseudo_header_data_length(socket_data->pseudo_header, 1938 socket_data->headerlen, packet_get_data_length(packet)); 1939 if (rc != EOK) { 1899 1940 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 1900 1941 return NULL; … … 1921 1962 checksum = compute_checksum(0, socket_data->pseudo_header, 1922 1963 socket_data->headerlen); 1923 checksum = compute_checksum(checksum, (uint8_t *) packet_get_data(packet), 1964 checksum = compute_checksum(checksum, 1965 (uint8_t *) packet_get_data(packet), 1924 1966 packet_get_data_length(packet)); 1925 1967 header->checksum = htons(flip_checksum(compact_checksum(checksum))); 1926 1968 1927 1969 // prepare the packet 1928 if (ERROR_OCCURRED(ip_client_prepare_packet(packet, IPPROTO_TCP, 0, 0, 1929 0, 0)) || ERROR_OCCURRED(tcp_prepare_timeout(tcp_timeout, socket, 1930 socket_data, sequence_number, socket_data->state, 1931 socket_data->timeout, true))) { 1970 rc = ip_client_prepare_packet(packet, IPPROTO_TCP, 0, 0, 0, 0); 1971 if (rc != EOK) { 1972 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 1973 return NULL; 1974 } 1975 rc = tcp_prepare_timeout(tcp_timeout, socket, socket_data, 1976 sequence_number, socket_data->state, socket_data->timeout, true); 1977 if (rc != EOK) { 1932 1978 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 1933 1979 return NULL; … … 2038 2084 size_t *addrlen) 2039 2085 { 2040 ERROR_DECLARE;2041 2042 2086 socket_core_ref socket; 2043 2087 tcp_socket_data_ref socket_data; … … 2045 2089 packet_t packet; 2046 2090 size_t length; 2091 int rc; 2047 2092 2048 2093 assert(local_sockets); … … 2066 2111 // send the source address if desired 2067 2112 if (addrlen) { 2068 ERROR_PROPAGATE(data_reply(socket_data->addr, 2069 socket_data->addrlen)); 2113 rc = data_reply(socket_data->addr, socket_data->addrlen); 2114 if (rc != EOK) 2115 return rc; 2070 2116 *addrlen = socket_data->addrlen; 2071 2117 } … … 2076 2122 return NO_DATA; 2077 2123 2078 ERROR_PROPAGATE(packet_translate_remote(tcp_globals.net_phone, &packet, 2079 packet_id)); 2124 rc = packet_translate_remote(tcp_globals.net_phone, &packet, packet_id); 2125 if (rc != EOK) 2126 return rc; 2080 2127 2081 2128 // reply the packets 2082 ERROR_PROPAGATE(socket_reply_packets(packet, &length)); 2129 rc = socket_reply_packets(packet, &length); 2130 if (rc != EOK) 2131 return rc; 2083 2132 2084 2133 // release the packet … … 2093 2142 size_t *data_fragment_size, int flags) 2094 2143 { 2095 ERROR_DECLARE;2096 2097 2144 socket_core_ref socket; 2098 2145 tcp_socket_data_ref socket_data; … … 2103 2150 int index; 2104 2151 int result; 2152 int rc; 2105 2153 2106 2154 assert(local_sockets); … … 2123 2171 return ENOTCONN; 2124 2172 2125 ERROR_PROPAGATE(tl_get_ip_packet_dimension(tcp_globals.ip_phone, 2126 &tcp_globals.dimensions, socket_data->device_id, &packet_dimension)); 2173 rc = tl_get_ip_packet_dimension(tcp_globals.ip_phone, 2174 &tcp_globals.dimensions, socket_data->device_id, &packet_dimension); 2175 if (rc != EOK) 2176 return rc; 2127 2177 2128 2178 *data_fragment_size = … … 2145 2195 2146 2196 tcp_prepare_operation_header(socket, socket_data, header, 0, 0); 2147 ERROR_PROPAGATE(tcp_queue_packet(socket, socket_data, packet, 2148 0)); 2197 rc = tcp_queue_packet(socket, socket_data, packet, 0); 2198 if (rc != EOK) 2199 return rc; 2149 2200 } 2150 2201 … … 2165 2216 tcp_close_message(socket_cores_ref local_sockets, int socket_id) 2166 2217 { 2167 ERROR_DECLARE;2168 2169 2218 socket_core_ref socket; 2170 2219 tcp_socket_data_ref socket_data; 2171 2220 packet_t packet; 2221 int rc; 2172 2222 2173 2223 // find the socket … … 2194 2244 default: 2195 2245 // just destroy 2196 if (ERROR_NONE(socket_destroy(tcp_globals.net_phone, socket_id,2246 rc = socket_destroy(tcp_globals.net_phone, socket_id, 2197 2247 local_sockets, &tcp_globals.sockets, 2198 tcp_free_socket_data))) { 2248 tcp_free_socket_data); 2249 if (rc == EOK) { 2199 2250 fibril_rwlock_write_unlock(socket_data->local_lock); 2200 2251 fibril_rwlock_write_unlock(&tcp_globals.lock); 2201 2252 } 2202 return ERROR_CODE;2253 return rc; 2203 2254 } 2204 2255 … … 2207 2258 2208 2259 // create the notification packet 2209 ERROR_PROPAGATE(tcp_create_notification_packet(&packet, socket, 2210 socket_data, 0, 1)); 2260 rc = tcp_create_notification_packet(&packet, socket, socket_data, 0, 1); 2261 if (rc != EOK) 2262 return rc; 2211 2263 2212 2264 // send the packet 2213 ERROR_PROPAGATE(tcp_queue_packet(socket, socket_data, packet, 1)); 2265 rc = tcp_queue_packet(socket, socket_data, packet, 1); 2266 if (rc != EOK) 2267 return rc; 2214 2268 2215 2269 // flush packets … … 2230 2284 tcp_socket_data_ref socket_data, int synchronize, int finalize) 2231 2285 { 2232 ERROR_DECLARE;2233 2234 2286 packet_dimension_ref packet_dimension; 2235 2287 tcp_header_ref header; 2288 int rc; 2236 2289 2237 2290 assert(packet); 2238 2291 2239 2292 // get the device packet dimension 2240 ERROR_PROPAGATE(tl_get_ip_packet_dimension(tcp_globals.ip_phone, 2241 &tcp_globals.dimensions, socket_data->device_id, 2242 &packet_dimension)); 2293 rc = tl_get_ip_packet_dimension(tcp_globals.ip_phone, 2294 &tcp_globals.dimensions, socket_data->device_id, &packet_dimension); 2295 if (rc != EOK) 2296 return rc; 2243 2297 2244 2298 // get a new packet … … 2265 2319 int new_socket_id, size_t *data_fragment_size, size_t *addrlen) 2266 2320 { 2267 ERROR_DECLARE;2268 2269 2321 socket_core_ref accepted; 2270 2322 socket_core_ref socket; 2271 2323 tcp_socket_data_ref socket_data; 2272 2324 packet_dimension_ref packet_dimension; 2325 int rc; 2273 2326 2274 2327 assert(local_sockets); … … 2304 2357 // TODO can it be in another state? 2305 2358 if (socket_data->state == TCP_SOCKET_ESTABLISHED) { 2306 ERROR_PROPAGATE(data_reply(socket_data->addr, 2307 socket_data->addrlen)); 2308 ERROR_PROPAGATE(tl_get_ip_packet_dimension( 2309 tcp_globals.ip_phone, &tcp_globals.dimensions, 2310 socket_data->device_id, &packet_dimension)); 2359 rc = data_reply(socket_data->addr, 2360 socket_data->addrlen); 2361 if (rc != EOK) 2362 return rc; 2363 rc = tl_get_ip_packet_dimension(tcp_globals.ip_phone, 2364 &tcp_globals.dimensions, socket_data->device_id, 2365 &packet_dimension); 2366 if (rc != EOK) 2367 return rc; 2311 2368 *addrlen = socket_data->addrlen; 2312 2369 … … 2318 2375 2319 2376 if (new_socket_id > 0) { 2320 ERROR_PROPAGATE(socket_cores_update( 2321 local_sockets, accepted->socket_id, 2322 new_socket_id)); 2377 rc = socket_cores_update(local_sockets, 2378 accepted->socket_id, new_socket_id); 2379 if (rc != EOK) 2380 return rc; 2323 2381 accepted->socket_id = new_socket_id; 2324 2382 } … … 2430 2488 main(int argc, char *argv[]) 2431 2489 { 2432 ERROR_DECLARE; 2433 2434 /* 2435 Start the module 2436 */ 2437 if (ERROR_OCCURRED(tl_module_start_standalone(tl_client_connection))) 2438 return ERROR_CODE; 2439 2440 return EOK; 2490 int rc; 2491 2492 rc = tl_module_start_standalone(tl_client_connection); 2493 return rc; 2441 2494 } 2442 2495 -
uspace/srv/net/tl/tcp/tcp_module.c
r376a7fd r0578271 44 44 #include <async.h> 45 45 #include <stdio.h> 46 #include <err .h>46 #include <errno.h> 47 47 #include <ipc/ipc.h> 48 48 #include <ipc/services.h> … … 61 61 int tl_module_start_standalone(async_client_conn_t client_connection) 62 62 { 63 ERROR_DECLARE; 64 63 ipcarg_t phonehash; 64 int rc; 65 65 66 async_set_client_connection(client_connection); 66 67 tcp_globals.net_phone = net_connect_module(); 67 ERROR_PROPAGATE(pm_init()); 68 69 ipcarg_t phonehash; 70 if (ERROR_OCCURRED(tcp_initialize(client_connection)) || 71 ERROR_OCCURRED(REGISTER_ME(SERVICE_TCP, &phonehash))) { 72 pm_destroy(); 73 return ERROR_CODE; 74 } 68 69 rc = pm_init(); 70 if (rc != EOK) 71 return rc; 72 73 rc = tcp_initialize(client_connection); 74 if (rc != EOK) 75 goto out; 76 77 rc = REGISTER_ME(SERVICE_TCP, &phonehash); 78 if (rc != EOK) 79 goto out; 75 80 76 81 async_manager(); 77 82 83 out: 78 84 pm_destroy(); 79 return EOK;85 return rc; 80 86 } 81 87
Note:
See TracChangeset
for help on using the changeset viewer.