Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/tl/tcp/tcp.c

    r6092b56e r14f1db0  
    4646#include <ipc/services.h>
    4747
    48 #include "../../err.h"
    49 #include "../../messages.h"
    50 #include "../../modules.h"
    51 
    52 #include "../../structures/dynamic_fifo.h"
    53 #include "../../structures/packet/packet_client.h"
    54 
    55 #include "../../include/checksum.h"
    56 #include "../../include/in.h"
    57 #include "../../include/in6.h"
    58 #include "../../include/inet.h"
    59 #include "../../include/ip_client.h"
    60 #include "../../include/ip_interface.h"
    61 #include "../../include/ip_protocols.h"
    62 #include "../../include/icmp_client.h"
    63 #include "../../include/icmp_interface.h"
    64 #include "../../include/net_interface.h"
    65 #include "../../include/socket_codes.h"
    66 #include "../../include/socket_errno.h"
    67 #include "../../include/tcp_codes.h"
    68 
    69 #include "../../socket/socket_core.h"
    70 #include "../../socket/socket_messages.h"
    71 
    72 #include "../tl_common.h"
    73 #include "../tl_messages.h"
     48#include <net_err.h>
     49#include <net_messages.h>
     50#include <net_modules.h>
     51#include <adt/dynamic_fifo.h>
     52#include <packet/packet_client.h>
     53#include <packet_remote.h>
     54#include <net_checksum.h>
     55#include <in.h>
     56#include <in6.h>
     57#include <inet.h>
     58#include <ip_client.h>
     59#include <ip_interface.h>
     60#include <ip_protocols.h>
     61#include <icmp_client.h>
     62#include <icmp_interface.h>
     63#include <net_interface.h>
     64#include <socket_codes.h>
     65#include <socket_errno.h>
     66#include <tcp_codes.h>
     67#include <socket_core.h>
     68#include <socket_messages.h>
     69#include <tl_common.h>
     70#include <tl_messages.h>
     71#include <tl_local.h>
     72#include <tl_interface.h>
    7473
    7574#include "tcp.h"
    7675#include "tcp_header.h"
    7776#include "tcp_module.h"
     77
     78/** TCP module name.
     79 */
     80#define NAME    "TCP protocol"
    7881
    7982/** The TCP window default value.
     
    421424                        break;
    422425                default:
    423                         pq_release(tcp_globals.net_phone, packet_get_id(packet));
     426                        pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
    424427        }
    425428
     
    473476                        // release the acknowledged packets
    474477                        next_packet = pq_next(packet);
    475                         pq_release(tcp_globals.net_phone, packet_get_id(packet));
     478                        pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
    476479                        packet = next_packet;
    477480                        offset -= length;
     
    517520                        next_packet = pq_next(next_packet);
    518521                        pq_insert_after(tmp_packet, next_packet);
    519                         pq_release(tcp_globals.net_phone, packet_get_id(tmp_packet));
     522                        pq_release_remote(tcp_globals.net_phone, packet_get_id(tmp_packet));
    520523                }
    521524                assert(new_sequence_number + total_length == socket_data->next_incoming + socket_data->window);
     
    548551                                        socket_data->incoming = next_packet;
    549552                                }
    550                                 pq_release(tcp_globals.net_phone, packet_get_id(packet));
     553                                pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
    551554                                packet = next_packet;
    552555                                continue;
     
    568571                                if(length <= 0){
    569572                                        // remove the empty packet
    570                                         pq_release(tcp_globals.net_phone, packet_get_id(packet));
     573                                        pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
    571574                                        packet = next_packet;
    572575                                        continue;
     
    595598                                }
    596599                                // remove the duplicit or corrupted packet
    597                                 pq_release(tcp_globals.net_phone, packet_get_id(packet));
     600                                pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
    598601                                packet = next_packet;
    599602                                continue;
     
    617620                if(ERROR_OCCURRED(pq_add(&socket_data->incoming, packet, new_sequence_number, length))){
    618621                        // remove the corrupted packets
    619                         pq_release(tcp_globals.net_phone, packet_get_id(packet));
    620                         pq_release(tcp_globals.net_phone, packet_get_id(next_packet));
     622                        pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
     623                        pq_release_remote(tcp_globals.net_phone, packet_get_id(next_packet));
    621624                }else{
    622625                        while(next_packet){
     
    626629                                if(ERROR_OCCURRED(pq_set_order(next_packet, new_sequence_number, length))
    627630                                        || ERROR_OCCURRED(pq_insert_after(packet, next_packet))){
    628                                         pq_release(tcp_globals.net_phone, packet_get_id(next_packet));
     631                                        pq_release_remote(tcp_globals.net_phone, packet_get_id(next_packet));
    629632                                }
    630633                                next_packet = tmp_packet;
     
    634637                printf("unexpected\n");
    635638                // release duplicite or restricted
    636                 pq_release(tcp_globals.net_phone, packet_get_id(packet));
     639                pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
    637640        }
    638641
     
    679682        // queue the received packet
    680683        if(ERROR_OCCURRED(dyn_fifo_push(&socket->received, packet_get_id(packet), SOCKET_MAX_RECEIVED_SIZE))
    681                 || ERROR_OCCURRED(tl_get_ip_packet_dimension(tcp_globals.ip_phone, &tcp_globals.dimensions, socket_data->device_id, &packet_dimension))){
     684            || ERROR_OCCURRED(tl_get_ip_packet_dimension(tcp_globals.ip_phone, &tcp_globals.dimensions, socket_data->device_id, &packet_dimension))){
    682685                return tcp_release_and_return(packet, ERROR_CODE);
    683686        }
     
    710713                next_packet = pq_detach(packet);
    711714                if(next_packet){
    712                         pq_release(tcp_globals.net_phone, packet_get_id(next_packet));
     715                        pq_release_remote(tcp_globals.net_phone, packet_get_id(next_packet));
    713716                }
    714717                // trim if longer than the header
     
    780783                                free(socket_data->addr);
    781784                                free(socket_data);
    782                                 pq_release(tcp_globals.net_phone, packet_get_id(packet));
     785                                pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
    783786                                return ERROR_CODE;
    784787                        }
     
    846849                        next_packet = pq_detach(packet);
    847850                        if(next_packet){
    848                                 pq_release(tcp_globals.net_phone, packet_get_id(next_packet));
     851                                pq_release_remote(tcp_globals.net_phone, packet_get_id(next_packet));
    849852                        }
    850853                        // trim if longer than the header
     
    895898
    896899                socket_data->next_incoming = ntohl(header->sequence_number);// + 1;
    897                 pq_release(tcp_globals.net_phone, packet_get_id(packet));
     900                pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
    898901                socket_data->state = TCP_SOCKET_ESTABLISHED;
    899902                listening_socket = socket_cores_find(socket_data->local_sockets, socket_data->listening_socket_id);
     
    981984                                        // add to acknowledged or release
    982985                                        if(pq_add(&acknowledged, packet, 0, 0) != EOK){
    983                                                 pq_release(tcp_globals.net_phone, packet_get_id(packet));
     986                                                pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
    984987                                        }
    985988                                        packet = next;
     
    990993                        // release acknowledged
    991994                        if(acknowledged){
    992                                 pq_release(tcp_globals.net_phone, packet_get_id(acknowledged));
     995                                pq_release_remote(tcp_globals.net_phone, packet_get_id(acknowledged));
    993996                        }
    994997                        return;
     
    10061009}
    10071010
    1008 int tcp_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
     1011int tcp_message_standalone(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
    10091012        ERROR_DECLARE;
    10101013
     
    10191022                case NET_TL_RECEIVED:
    10201023                        //fibril_rwlock_read_lock(&tcp_globals.lock);
    1021                         if(! ERROR_OCCURRED(packet_translate(tcp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
     1024                        if(! ERROR_OCCURRED(packet_translate_remote(tcp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
    10221025                                ERROR_CODE = tcp_received_msg(IPC_GET_DEVICE(call), packet, SERVICE_TCP, IPC_GET_ERROR(call));
    10231026                        }
     
    10621065        int socket_id;
    10631066        size_t addrlen;
     1067        size_t size;
    10641068        fibril_rwlock_t lock;
    10651069        ipc_call_t answer;
     
    11071111                                        socket_id = SOCKET_GET_SOCKET_ID(call);
    11081112                                        res = socket_create(&local_sockets, app_phone, socket_data, &socket_id);
    1109                                         *SOCKET_SET_SOCKET_ID(answer) = socket_id;
     1113                                        SOCKET_SET_SOCKET_ID(answer, socket_id);
    11101114                                        fibril_rwlock_write_unlock(&lock);
    11111115                                        if(res == EOK){
    1112                                                 if(tl_get_ip_packet_dimension(tcp_globals.ip_phone, &tcp_globals.dimensions, DEVICE_INVALID_ID, &packet_dimension) == EOK){
    1113                                                         *SOCKET_SET_DATA_FRAGMENT_SIZE(answer) = ((packet_dimension->content < socket_data->data_fragment_size) ? packet_dimension->content : socket_data->data_fragment_size);
     1116                                                if (tl_get_ip_packet_dimension(tcp_globals.ip_phone, &tcp_globals.dimensions, DEVICE_INVALID_ID, &packet_dimension) == EOK){
     1117                                                        SOCKET_SET_DATA_FRAGMENT_SIZE(answer, ((packet_dimension->content < socket_data->data_fragment_size) ? packet_dimension->content : socket_data->data_fragment_size));
    11141118                                                }
    1115 //                                              *SOCKET_SET_DATA_FRAGMENT_SIZE(answer) = MAX_TCP_FRAGMENT_SIZE;
    1116                                                 *SOCKET_SET_HEADER_SIZE(answer) = TCP_HEADER_SIZE;
     1119//                                              SOCKET_SET_DATA_FRAGMENT_SIZE(answer, MAX_TCP_FRAGMENT_SIZE);
     1120                                                SOCKET_SET_HEADER_SIZE(answer, TCP_HEADER_SIZE);
    11171121                                                answer_count = 3;
    11181122                                        }else{
     
    11661170                                fibril_rwlock_read_lock(&tcp_globals.lock);
    11671171                                fibril_rwlock_write_lock(&lock);
    1168                                 res = tcp_accept_message(&local_sockets, SOCKET_GET_SOCKET_ID(call), SOCKET_GET_NEW_SOCKET_ID(call), SOCKET_SET_DATA_FRAGMENT_SIZE(answer), &addrlen);
     1172                                res = tcp_accept_message(&local_sockets, SOCKET_GET_SOCKET_ID(call), SOCKET_GET_NEW_SOCKET_ID(call), &size, &addrlen);
     1173                                SOCKET_SET_DATA_FRAGMENT_SIZE(answer, size);
    11691174                                fibril_rwlock_write_unlock(&lock);
    11701175                                fibril_rwlock_read_unlock(&tcp_globals.lock);
    11711176                                if(res > 0){
    1172                                         *SOCKET_SET_SOCKET_ID(answer) = res;
    1173                                         *SOCKET_SET_ADDRESS_LENGTH(answer) = addrlen;
     1177                                        SOCKET_SET_SOCKET_ID(answer, res);
     1178                                        SOCKET_SET_ADDRESS_LENGTH(answer, addrlen);
    11741179                                        answer_count = 3;
    11751180                                }
     
    11781183                                fibril_rwlock_read_lock(&tcp_globals.lock);
    11791184                                fibril_rwlock_write_lock(&lock);
    1180                                 res = tcp_send_message(&local_sockets, SOCKET_GET_SOCKET_ID(call), SOCKET_GET_DATA_FRAGMENTS(call), SOCKET_SET_DATA_FRAGMENT_SIZE(answer), SOCKET_GET_FLAGS(call));
     1185                                res = tcp_send_message(&local_sockets, SOCKET_GET_SOCKET_ID(call), SOCKET_GET_DATA_FRAGMENTS(call), &size, SOCKET_GET_FLAGS(call));
     1186                                SOCKET_SET_DATA_FRAGMENT_SIZE(answer, size);
    11811187                                if(res != EOK){
    11821188                                        fibril_rwlock_write_unlock(&lock);
     
    11911197                                        fibril_rwlock_read_lock(&tcp_globals.lock);
    11921198                                        fibril_rwlock_write_lock(&lock);
    1193                                         res = tcp_send_message(&local_sockets, SOCKET_GET_SOCKET_ID(call), SOCKET_GET_DATA_FRAGMENTS(call), SOCKET_SET_DATA_FRAGMENT_SIZE(answer), SOCKET_GET_FLAGS(call));
     1199                                        res = tcp_send_message(&local_sockets, SOCKET_GET_SOCKET_ID(call), SOCKET_GET_DATA_FRAGMENTS(call), &size, SOCKET_GET_FLAGS(call));
     1200                                        SOCKET_SET_DATA_FRAGMENT_SIZE(answer, size);
    11941201                                        if(res != EOK){
    11951202                                                fibril_rwlock_write_unlock(&lock);
     
    12081215                                fibril_rwlock_read_unlock(&tcp_globals.lock);
    12091216                                if(res > 0){
    1210                                         *SOCKET_SET_READ_DATA_LENGTH(answer) = res;
     1217                                        SOCKET_SET_READ_DATA_LENGTH(answer, res);
    12111218                                        answer_count = 1;
    12121219                                        res = EOK;
     
    12201227                                fibril_rwlock_read_unlock(&tcp_globals.lock);
    12211228                                if(res > 0){
    1222                                         *SOCKET_SET_READ_DATA_LENGTH(answer) = res;
    1223                                         *SOCKET_SET_ADDRESS_LENGTH(answer) = addrlen;
     1229                                        SOCKET_SET_READ_DATA_LENGTH(answer, res);
     1230                                        SOCKET_SET_ADDRESS_LENGTH(answer, addrlen);
    12241231                                        answer_count = 3;
    12251232                                        res = EOK;
     
    15611568                        }else{
    15621569                                if(ERROR_OCCURRED(pq_insert_after(previous, copy))){
    1563                                         pq_release(tcp_globals.net_phone, packet_get_id(copy));
     1570                                        pq_release_remote(tcp_globals.net_phone, packet_get_id(copy));
    15641571                                        return sending;
    15651572                                }
     
    15931600        // adjust the pseudo header
    15941601        if(ERROR_OCCURRED(ip_client_set_pseudo_header_data_length(socket_data->pseudo_header, socket_data->headerlen, packet_get_data_length(packet)))){
    1595                 pq_release(tcp_globals.net_phone, packet_get_id(packet));
     1602                pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
    15961603                return NULL;
    15971604        }
     
    16001607        header = (tcp_header_ref) packet_get_data(packet);
    16011608        if(! header){
    1602                 pq_release(tcp_globals.net_phone, packet_get_id(packet));
     1609                pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
    16031610                return NULL;
    16041611        }
     
    16211628        // prepare the timeout
    16221629                || ERROR_OCCURRED(tcp_prepare_timeout(tcp_timeout, socket, socket_data, sequence_number, socket_data->state, socket_data->timeout, true))){
    1623                 pq_release(tcp_globals.net_phone, packet_get_id(packet));
     1630                pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
    16241631                return NULL;
    16251632        }
     
    17461753                return NO_DATA;
    17471754        }
    1748         ERROR_PROPAGATE(packet_translate(tcp_globals.net_phone, &packet, packet_id));
     1755        ERROR_PROPAGATE(packet_translate_remote(tcp_globals.net_phone, &packet, packet_id));
    17491756
    17501757        // reply the packets
     
    17531760        // release the packet
    17541761        dyn_fifo_pop(&socket->received);
    1755         pq_release(tcp_globals.net_phone, packet_get_id(packet));
     1762        pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
    17561763        // return the total length
    17571764        return (int) length;
     
    18851892        ERROR_PROPAGATE(tl_get_ip_packet_dimension(tcp_globals.ip_phone, &tcp_globals.dimensions, socket_data->device_id, &packet_dimension));
    18861893        // get a new packet
    1887         *packet = packet_get_4(tcp_globals.net_phone, TCP_HEADER_SIZE, packet_dimension->addr_len, packet_dimension->prefix, packet_dimension->suffix);
     1894        *packet = packet_get_4_remote(tcp_globals.net_phone, TCP_HEADER_SIZE, packet_dimension->addr_len, packet_dimension->prefix, packet_dimension->suffix);
    18881895        if(! * packet){
    18891896                return ENOMEM;
     
    19891996
    19901997int tcp_release_and_return(packet_t packet, int result){
    1991         pq_release(tcp_globals.net_phone, packet_get_id(packet));
     1998        pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
    19921999        return result;
    19932000}
    19942001
     2002/** Default thread for new connections.
     2003 *
     2004 *  @param[in] iid The initial message identifier.
     2005 *  @param[in] icall The initial message call structure.
     2006 *
     2007 */
     2008static void tl_client_connection(ipc_callid_t iid, ipc_call_t * icall)
     2009{
     2010        /*
     2011         * Accept the connection
     2012         *  - Answer the first IPC_M_CONNECT_ME_TO call.
     2013         */
     2014        ipc_answer_0(iid, EOK);
     2015       
     2016        while(true) {
     2017                ipc_call_t answer;
     2018                int answer_count;
     2019               
     2020                /* Clear the answer structure */
     2021                refresh_answer(&answer, &answer_count);
     2022               
     2023                /* Fetch the next message */
     2024                ipc_call_t call;
     2025                ipc_callid_t callid = async_get_call(&call);
     2026               
     2027                /* Process the message */
     2028                int res = tl_module_message_standalone(callid, &call, &answer,
     2029                    &answer_count);
     2030               
     2031                /* End if said to either by the message or the processing result */
     2032                if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP))
     2033                        return;
     2034               
     2035                /* Answer the message */
     2036                answer_call(callid, res, &answer, answer_count);
     2037        }
     2038}
     2039
     2040/** Starts the module.
     2041 *
     2042 *  @param argc The count of the command line arguments. Ignored parameter.
     2043 *  @param argv The command line parameters. Ignored parameter.
     2044 *
     2045 *  @returns EOK on success.
     2046 *  @returns Other error codes as defined for each specific module start function.
     2047 *
     2048 */
     2049int main(int argc, char *argv[])
     2050{
     2051        ERROR_DECLARE;
     2052       
     2053        /* Start the module */
     2054        if (ERROR_OCCURRED(tl_module_start_standalone(tl_client_connection)))
     2055                return ERROR_CODE;
     2056       
     2057        return EOK;
     2058}
     2059
    19952060/** @}
    19962061 */
Note: See TracChangeset for help on using the changeset viewer.