Ignore:
File:
1 edited

Legend:

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

    r14f1db0 r6092b56e  
    4646#include <ipc/services.h>
    4747
    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>
     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"
    7374
    7475#include "tcp.h"
    7576#include "tcp_header.h"
    7677#include "tcp_module.h"
    77 
    78 /** TCP module name.
    79  */
    80 #define NAME    "TCP protocol"
    8178
    8279/** The TCP window default value.
     
    424421                        break;
    425422                default:
    426                         pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
     423                        pq_release(tcp_globals.net_phone, packet_get_id(packet));
    427424        }
    428425
     
    476473                        // release the acknowledged packets
    477474                        next_packet = pq_next(packet);
    478                         pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
     475                        pq_release(tcp_globals.net_phone, packet_get_id(packet));
    479476                        packet = next_packet;
    480477                        offset -= length;
     
    520517                        next_packet = pq_next(next_packet);
    521518                        pq_insert_after(tmp_packet, next_packet);
    522                         pq_release_remote(tcp_globals.net_phone, packet_get_id(tmp_packet));
     519                        pq_release(tcp_globals.net_phone, packet_get_id(tmp_packet));
    523520                }
    524521                assert(new_sequence_number + total_length == socket_data->next_incoming + socket_data->window);
     
    551548                                        socket_data->incoming = next_packet;
    552549                                }
    553                                 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
     550                                pq_release(tcp_globals.net_phone, packet_get_id(packet));
    554551                                packet = next_packet;
    555552                                continue;
     
    571568                                if(length <= 0){
    572569                                        // remove the empty packet
    573                                         pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
     570                                        pq_release(tcp_globals.net_phone, packet_get_id(packet));
    574571                                        packet = next_packet;
    575572                                        continue;
     
    598595                                }
    599596                                // remove the duplicit or corrupted packet
    600                                 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
     597                                pq_release(tcp_globals.net_phone, packet_get_id(packet));
    601598                                packet = next_packet;
    602599                                continue;
     
    620617                if(ERROR_OCCURRED(pq_add(&socket_data->incoming, packet, new_sequence_number, length))){
    621618                        // remove the corrupted packets
    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));
     619                        pq_release(tcp_globals.net_phone, packet_get_id(packet));
     620                        pq_release(tcp_globals.net_phone, packet_get_id(next_packet));
    624621                }else{
    625622                        while(next_packet){
     
    629626                                if(ERROR_OCCURRED(pq_set_order(next_packet, new_sequence_number, length))
    630627                                        || ERROR_OCCURRED(pq_insert_after(packet, next_packet))){
    631                                         pq_release_remote(tcp_globals.net_phone, packet_get_id(next_packet));
     628                                        pq_release(tcp_globals.net_phone, packet_get_id(next_packet));
    632629                                }
    633630                                next_packet = tmp_packet;
     
    637634                printf("unexpected\n");
    638635                // release duplicite or restricted
    639                 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
     636                pq_release(tcp_globals.net_phone, packet_get_id(packet));
    640637        }
    641638
     
    682679        // queue the received packet
    683680        if(ERROR_OCCURRED(dyn_fifo_push(&socket->received, packet_get_id(packet), SOCKET_MAX_RECEIVED_SIZE))
    684             || ERROR_OCCURRED(tl_get_ip_packet_dimension(tcp_globals.ip_phone, &tcp_globals.dimensions, socket_data->device_id, &packet_dimension))){
     681                || ERROR_OCCURRED(tl_get_ip_packet_dimension(tcp_globals.ip_phone, &tcp_globals.dimensions, socket_data->device_id, &packet_dimension))){
    685682                return tcp_release_and_return(packet, ERROR_CODE);
    686683        }
     
    713710                next_packet = pq_detach(packet);
    714711                if(next_packet){
    715                         pq_release_remote(tcp_globals.net_phone, packet_get_id(next_packet));
     712                        pq_release(tcp_globals.net_phone, packet_get_id(next_packet));
    716713                }
    717714                // trim if longer than the header
     
    783780                                free(socket_data->addr);
    784781                                free(socket_data);
    785                                 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
     782                                pq_release(tcp_globals.net_phone, packet_get_id(packet));
    786783                                return ERROR_CODE;
    787784                        }
     
    849846                        next_packet = pq_detach(packet);
    850847                        if(next_packet){
    851                                 pq_release_remote(tcp_globals.net_phone, packet_get_id(next_packet));
     848                                pq_release(tcp_globals.net_phone, packet_get_id(next_packet));
    852849                        }
    853850                        // trim if longer than the header
     
    898895
    899896                socket_data->next_incoming = ntohl(header->sequence_number);// + 1;
    900                 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
     897                pq_release(tcp_globals.net_phone, packet_get_id(packet));
    901898                socket_data->state = TCP_SOCKET_ESTABLISHED;
    902899                listening_socket = socket_cores_find(socket_data->local_sockets, socket_data->listening_socket_id);
     
    984981                                        // add to acknowledged or release
    985982                                        if(pq_add(&acknowledged, packet, 0, 0) != EOK){
    986                                                 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
     983                                                pq_release(tcp_globals.net_phone, packet_get_id(packet));
    987984                                        }
    988985                                        packet = next;
     
    993990                        // release acknowledged
    994991                        if(acknowledged){
    995                                 pq_release_remote(tcp_globals.net_phone, packet_get_id(acknowledged));
     992                                pq_release(tcp_globals.net_phone, packet_get_id(acknowledged));
    996993                        }
    997994                        return;
     
    10091006}
    10101007
    1011 int tcp_message_standalone(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
     1008int tcp_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
    10121009        ERROR_DECLARE;
    10131010
     
    10221019                case NET_TL_RECEIVED:
    10231020                        //fibril_rwlock_read_lock(&tcp_globals.lock);
    1024                         if(! ERROR_OCCURRED(packet_translate_remote(tcp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
     1021                        if(! ERROR_OCCURRED(packet_translate(tcp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
    10251022                                ERROR_CODE = tcp_received_msg(IPC_GET_DEVICE(call), packet, SERVICE_TCP, IPC_GET_ERROR(call));
    10261023                        }
     
    10651062        int socket_id;
    10661063        size_t addrlen;
    1067         size_t size;
    10681064        fibril_rwlock_t lock;
    10691065        ipc_call_t answer;
     
    11111107                                        socket_id = SOCKET_GET_SOCKET_ID(call);
    11121108                                        res = socket_create(&local_sockets, app_phone, socket_data, &socket_id);
    1113                                         SOCKET_SET_SOCKET_ID(answer, socket_id);
     1109                                        *SOCKET_SET_SOCKET_ID(answer) = socket_id;
    11141110                                        fibril_rwlock_write_unlock(&lock);
    11151111                                        if(res == EOK){
    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));
     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);
    11181114                                                }
    1119 //                                              SOCKET_SET_DATA_FRAGMENT_SIZE(answer, MAX_TCP_FRAGMENT_SIZE);
    1120                                                 SOCKET_SET_HEADER_SIZE(answer, TCP_HEADER_SIZE);
     1115//                                              *SOCKET_SET_DATA_FRAGMENT_SIZE(answer) = MAX_TCP_FRAGMENT_SIZE;
     1116                                                *SOCKET_SET_HEADER_SIZE(answer) = TCP_HEADER_SIZE;
    11211117                                                answer_count = 3;
    11221118                                        }else{
     
    11701166                                fibril_rwlock_read_lock(&tcp_globals.lock);
    11711167                                fibril_rwlock_write_lock(&lock);
    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);
     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);
    11741169                                fibril_rwlock_write_unlock(&lock);
    11751170                                fibril_rwlock_read_unlock(&tcp_globals.lock);
    11761171                                if(res > 0){
    1177                                         SOCKET_SET_SOCKET_ID(answer, res);
    1178                                         SOCKET_SET_ADDRESS_LENGTH(answer, addrlen);
     1172                                        *SOCKET_SET_SOCKET_ID(answer) = res;
     1173                                        *SOCKET_SET_ADDRESS_LENGTH(answer) = addrlen;
    11791174                                        answer_count = 3;
    11801175                                }
     
    11831178                                fibril_rwlock_read_lock(&tcp_globals.lock);
    11841179                                fibril_rwlock_write_lock(&lock);
    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);
     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));
    11871181                                if(res != EOK){
    11881182                                        fibril_rwlock_write_unlock(&lock);
     
    11971191                                        fibril_rwlock_read_lock(&tcp_globals.lock);
    11981192                                        fibril_rwlock_write_lock(&lock);
    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);
     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));
    12011194                                        if(res != EOK){
    12021195                                                fibril_rwlock_write_unlock(&lock);
     
    12151208                                fibril_rwlock_read_unlock(&tcp_globals.lock);
    12161209                                if(res > 0){
    1217                                         SOCKET_SET_READ_DATA_LENGTH(answer, res);
     1210                                        *SOCKET_SET_READ_DATA_LENGTH(answer) = res;
    12181211                                        answer_count = 1;
    12191212                                        res = EOK;
     
    12271220                                fibril_rwlock_read_unlock(&tcp_globals.lock);
    12281221                                if(res > 0){
    1229                                         SOCKET_SET_READ_DATA_LENGTH(answer, res);
    1230                                         SOCKET_SET_ADDRESS_LENGTH(answer, addrlen);
     1222                                        *SOCKET_SET_READ_DATA_LENGTH(answer) = res;
     1223                                        *SOCKET_SET_ADDRESS_LENGTH(answer) = addrlen;
    12311224                                        answer_count = 3;
    12321225                                        res = EOK;
     
    15681561                        }else{
    15691562                                if(ERROR_OCCURRED(pq_insert_after(previous, copy))){
    1570                                         pq_release_remote(tcp_globals.net_phone, packet_get_id(copy));
     1563                                        pq_release(tcp_globals.net_phone, packet_get_id(copy));
    15711564                                        return sending;
    15721565                                }
     
    16001593        // adjust the pseudo header
    16011594        if(ERROR_OCCURRED(ip_client_set_pseudo_header_data_length(socket_data->pseudo_header, socket_data->headerlen, packet_get_data_length(packet)))){
    1602                 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
     1595                pq_release(tcp_globals.net_phone, packet_get_id(packet));
    16031596                return NULL;
    16041597        }
     
    16071600        header = (tcp_header_ref) packet_get_data(packet);
    16081601        if(! header){
    1609                 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
     1602                pq_release(tcp_globals.net_phone, packet_get_id(packet));
    16101603                return NULL;
    16111604        }
     
    16281621        // prepare the timeout
    16291622                || ERROR_OCCURRED(tcp_prepare_timeout(tcp_timeout, socket, socket_data, sequence_number, socket_data->state, socket_data->timeout, true))){
    1630                 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
     1623                pq_release(tcp_globals.net_phone, packet_get_id(packet));
    16311624                return NULL;
    16321625        }
     
    17531746                return NO_DATA;
    17541747        }
    1755         ERROR_PROPAGATE(packet_translate_remote(tcp_globals.net_phone, &packet, packet_id));
     1748        ERROR_PROPAGATE(packet_translate(tcp_globals.net_phone, &packet, packet_id));
    17561749
    17571750        // reply the packets
     
    17601753        // release the packet
    17611754        dyn_fifo_pop(&socket->received);
    1762         pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
     1755        pq_release(tcp_globals.net_phone, packet_get_id(packet));
    17631756        // return the total length
    17641757        return (int) length;
     
    18921885        ERROR_PROPAGATE(tl_get_ip_packet_dimension(tcp_globals.ip_phone, &tcp_globals.dimensions, socket_data->device_id, &packet_dimension));
    18931886        // get a new packet
    1894         *packet = packet_get_4_remote(tcp_globals.net_phone, TCP_HEADER_SIZE, packet_dimension->addr_len, packet_dimension->prefix, packet_dimension->suffix);
     1887        *packet = packet_get_4(tcp_globals.net_phone, TCP_HEADER_SIZE, packet_dimension->addr_len, packet_dimension->prefix, packet_dimension->suffix);
    18951888        if(! * packet){
    18961889                return ENOMEM;
     
    19961989
    19971990int tcp_release_and_return(packet_t packet, int result){
    1998         pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
     1991        pq_release(tcp_globals.net_phone, packet_get_id(packet));
    19991992        return result;
    2000 }
    2001 
    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  */
    2008 static 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  */
    2049 int 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;
    20581993}
    20591994
Note: See TracChangeset for help on using the changeset viewer.