Ignore:
File:
1 edited

Legend:

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

    re526f08 r28a3e74  
    2828
    2929/** @addtogroup tcp
    30  *  @{
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  TCP module.
    35  */
    36 
    37 #ifndef __NET_TCP_H__
    38 #define __NET_TCP_H__
     34 * TCP module.
     35 */
     36
     37#ifndef NET_TCP_H_
     38#define NET_TCP_H_
    3939
    4040#include <fibril_synch.h>
     
    4646
    4747/** Type definition of the TCP global data.
    48  *  @see tcp_globals
    49  */
    50 typedef struct tcp_globals      tcp_globals_t;
     48 * @see tcp_globals
     49 */
     50typedef struct tcp_globals tcp_globals_t;
    5151
    5252/** Type definition of the TCP socket specific data.
    53  *  @see tcp_socket_data
    54  */
    55 typedef struct tcp_socket_data  tcp_socket_data_t;
    56 
    57 /** Type definition of the TCP socket specific data pointer.
    58  *  @see tcp_socket_data
    59  */
    60 typedef tcp_socket_data_t *     tcp_socket_data_ref;
     53 * @see tcp_socket_data
     54 */
     55typedef struct tcp_socket_data tcp_socket_data_t;
    6156
    6257/** Type definition of the TCP operation data.
    63  *  @see tcp_operation
    64  */
    65 typedef struct tcp_operation    tcp_operation_t;
    66 
    67 /** Type definition of the TCP operation data pointer.
    68  *  @see tcp_operation
    69  */
    70 typedef tcp_operation_t *       tcp_operation_ref;
     58 * @see tcp_operation
     59 */
     60typedef struct tcp_operation tcp_operation_t;
    7161
    7262/** TCP socket state type definition.
    73  *  @see tcp_socket_state
    74  */
    75 typedef enum tcp_socket_state   tcp_socket_state_t;
    76 
    77 /** TCP socket state.
    78  */
    79 enum tcp_socket_state{
     63 * @see tcp_socket_state
     64 */
     65typedef enum tcp_socket_state tcp_socket_state_t;
     66
     67/** TCP socket state. */
     68enum tcp_socket_state {
    8069        /** Initial.
    81          *  Not connected or bound.
     70         *
     71         * Not connected or bound.
    8272         */
    8373        TCP_SOCKET_INITIAL,
     74       
    8475        /** Listening.
    85          *  Awaiting a connection request from another TCP layer.
    86          *  When SYN is received a new bound socket in the TCP_SOCKET_SYN_RECEIVED state should be created.
     76         *
     77         * Awaiting a connection request from another TCP layer.
     78         * When SYN is received a new bound socket in the
     79         * TCP_SOCKET_SYN_RECEIVED state should be created.
    8780         */
    8881        TCP_SOCKET_LISTEN,
     82       
    8983        /** Connecting issued.
    90          *  A~SYN has been sent, and TCP is awaiting the response SYN.
    91          *  Should continue to the TCP_SOCKET_ESTABLISHED state.
     84         *
     85         * A SYN has been sent, and TCP is awaiting the response SYN.
     86         * Should continue to the TCP_SOCKET_ESTABLISHED state.
    9287         */
    9388        TCP_SOCKET_SYN_SENT,
     89       
    9490        /** Connecting received.
    95          *  A~SYN has been received, a~SYN has been sent, and TCP is awaiting an ACK.
    96          *  Should continue to the TCP_SOCKET_ESTABLISHED state.
     91         *
     92         * A SYN has been received, a SYN has been sent, and TCP is awaiting an
     93         * ACK. Should continue to the TCP_SOCKET_ESTABLISHED state.
    9794         */
    9895        TCP_SOCKET_SYN_RECEIVED,
     96       
    9997        /** Connected.
    100          *  The three-way handshake has been completed.
     98         *
     99         * The three-way handshake has been completed.
    101100         */
    102101        TCP_SOCKET_ESTABLISHED,
     102       
    103103        /** Closing started.
    104          *  The local application has issued a~CLOSE.
    105          *  TCP has sent a~FIN, and is awaiting an ACK or a~FIN.
    106          *  Should continue to the TCP_SOCKET_FIN_WAIT_2 state when an ACK is received.
    107          *  Should continue to the TCP_SOCKET_CLOSING state when a~FIN is received.
     104         *
     105         * The local application has issued a CLOSE.
     106         * TCP has sent a FIN, and is awaiting an ACK or a FIN.
     107         * Should continue to the TCP_SOCKET_FIN_WAIT_2 state when an ACK is
     108         * received.
     109         * Should continue to the TCP_SOCKET_CLOSING state when a FIN is
     110         * received.
    108111         */
    109112        TCP_SOCKET_FIN_WAIT_1,
     113       
    110114        /** Closing confirmed.
    111          *  A~FIN has been sent, and an ACK received.
    112          *  TCP is awaiting a~FIN from the remote TCP layer.
    113          *  Should continue to the TCP_SOCKET_CLOSING state.
     115         *
     116         * A FIN has been sent, and an ACK received.
     117         * TCP is awaiting a~FIN from the remote TCP layer.
     118         * Should continue to the TCP_SOCKET_CLOSING state.
    114119         */
    115120        TCP_SOCKET_FIN_WAIT_2,
     121       
    116122        /** Closing.
    117          *  A FIN has been sent, a FIN has been received, and an ACK has been sent.
    118          *  TCP is awaiting an ACK for the FIN that was sent.
    119          *  Should continue to the TCP_SOCKET_TIME_WAIT state.
     123         *
     124         * A FIN has been sent, a FIN has been received, and an ACK has been
     125         * sent.
     126         * TCP is awaiting an ACK for the FIN that was sent.
     127         * Should continue to the TCP_SOCKET_TIME_WAIT state.
    120128         */
    121129        TCP_SOCKET_CLOSING,
     130       
    122131        /** Closing received.
    123          *  TCP has received a~FIN, and has sent an ACK.
    124          *  It is awaiting a~close request from the local application before sending a~FIN.
    125          *  Should continue to the TCP_SOCKET_SOCKET_LAST_ACK state.
     132         *
     133         * TCP has received a FIN, and has sent an ACK.
     134         * It is awaiting a close request from the local application before
     135         * sending a FIN.
     136         * Should continue to the TCP_SOCKET_SOCKET_LAST_ACK state.
    126137         */
    127138        TCP_SOCKET_CLOSE_WAIT,
    128         /**
    129          *  A~FIN has been received, and an ACK and a~FIN have been sent.
    130          *  TCP is awaiting an ACK.
    131          *  Should continue to the TCP_SOCKET_TIME_WAIT state.
     139       
     140        /**
     141         * A FIN has been received, and an ACK and a FIN have been sent.
     142         * TCP is awaiting an ACK.
     143         * Should continue to the TCP_SOCKET_TIME_WAIT state.
    132144         */
    133145        TCP_SOCKET_LAST_ACK,
     146       
    134147        /** Closing finished.
    135          *  FINs have been received and ACK’d, and TCP is waiting two MSLs to remove the connection from the table.
     148         *
     149         * FINs have been received and ACK’d, and TCP is waiting two MSLs to
     150         * remove the connection from the table.
    136151         */
    137152        TCP_SOCKET_TIME_WAIT,
     153       
    138154        /** Closed.
    139          *  Imaginary, this indicates that a~connection has been removed from the connection table.
     155         *
     156         * Imaginary, this indicates that a connection has been removed from
     157         * the connection table.
    140158         */
    141159        TCP_SOCKET_CLOSED
    142160};
    143161
    144 /** TCP operation data.
    145  */
    146 struct tcp_operation{
    147         /** Operation result.
    148          */
     162/** TCP operation data. */
     163struct tcp_operation {
     164        /** Operation result. */
    149165        int result;
    150         /** Safety lock.
    151          */
     166        /** Safety lock. */
    152167        fibril_mutex_t mutex;
    153         /** Operation result signaling.
    154          */
     168        /** Operation result signaling. */
    155169        fibril_condvar_t condvar;
    156170};
    157171
    158 /** TCP socket specific data.
    159  */
    160 struct tcp_socket_data{
    161         /** TCP socket state.
    162          */
     172/** TCP socket specific data. */
     173struct tcp_socket_data {
     174        /** TCP socket state. */
    163175        tcp_socket_state_t state;
    164         /** Data fragment size.
    165          *  Sending optimalization.
     176       
     177        /**
     178         * Data fragment size.
     179         * Sending optimalization.
    166180         */
    167181        size_t data_fragment_size;
    168         /** Device identifier.
    169         */
     182       
     183        /** Device identifier. */
    170184        device_id_t device_id;
    171         /** Listening backlog.
    172          *  The maximal number of connected but not yet accepted sockets.
     185       
     186        /**
     187         * Listening backlog.
     188         * The maximal number of connected but not yet accepted sockets.
    173189         */
    174190        int backlog;
    175 //      /** Segment size.
    176 //       */
    177 //      size_t                  segment_size;
    178         /** Parent listening socket identifier.
    179          *  Set if this socket is an accepted one.
     191       
     192        /**
     193         * Parent listening socket identifier.
     194         * Set if this socket is an accepted one.
    180195         */
    181196        int listening_socket_id;
    182         /** Treshold size in bytes.
    183         */
     197       
     198        /** Treshold size in bytes. */
    184199        size_t treshold;
    185         /** Window size in bytes.
    186          */
     200        /** Window size in bytes. */
    187201        size_t window;
    188         /** Acknowledgement timeout.
    189          */
     202        /** Acknowledgement timeout. */
    190203        suseconds_t timeout;
    191         /** Last acknowledged byte.
    192          */
     204        /** Last acknowledged byte. */
    193205        uint32_t acknowledged;
    194         /** Next incoming sequence number.
    195          */
     206        /** Next incoming sequence number. */
    196207        uint32_t next_incoming;
    197         /** Incoming FIN.
    198          */
     208        /** Incoming FIN. */
    199209        uint32_t fin_incoming;
    200         /** Next outgoing sequence number.
    201          */
     210        /** Next outgoing sequence number. */
    202211        uint32_t next_outgoing;
    203         /** Last outgoing sequence number.
    204          */
     212        /** Last outgoing sequence number. */
    205213        uint32_t last_outgoing;
    206         /** Outgoing FIN.
    207          */
     214        /** Outgoing FIN. */
    208215        uint32_t fin_outgoing;
    209         /** Expected sequence number by the remote host.
    210          *  The sequence number the other host expects.
    211          *  The notification is sent only upon a packet reecival.
     216       
     217        /**
     218         * Expected sequence number by the remote host.
     219         * The sequence number the other host expects.
     220         * The notification is sent only upon a packet reecival.
    212221         */
    213222        uint32_t expected;
    214         /** Expected sequence number counter.
    215          *  Counts the number of received notifications for the same sequence number.
     223       
     224        /**
     225         * Expected sequence number counter.
     226         * Counts the number of received notifications for the same sequence
     227         * number.
    216228         */
    217229        int expected_count;
     230       
    218231        /** Incoming packet queue.
    219          *  Packets are buffered until received in the right order.
    220          *  The packets are excluded after successfully read.
    221          *  Packets are sorted by their starting byte.
    222          *  Packets metric is set as their data length.
    223          */
    224         packet_t incoming;
     232         *
     233         * Packets are buffered until received in the right order.
     234         * The packets are excluded after successfully read.
     235         * Packets are sorted by their starting byte.
     236         * Packets metric is set as their data length.
     237         */
     238        packet_t *incoming;
     239       
    225240        /** Outgoing packet queue.
    226          *  Packets are buffered until acknowledged by the remote host in the right order.
    227          *  The packets are excluded after acknowledged.
    228          *  Packets are sorted by their starting byte.
    229          *  Packets metric is set as their data length.
    230          */
    231         packet_t outgoing;
    232         /** IP pseudo header.
    233          */
     241         *
     242         * Packets are buffered until acknowledged by the remote host in the
     243         * right order.
     244         * The packets are excluded after acknowledged.
     245         * Packets are sorted by their starting byte.
     246         * Packets metric is set as their data length.
     247         */
     248        packet_t *outgoing;
     249       
     250        /** IP pseudo header. */
    234251        void *pseudo_header;
    235         /** IP pseudo header length.
    236          */
     252        /** IP pseudo header length. */
    237253        size_t headerlen;
    238         /** Remote host address.
    239          */
    240         struct sockaddr * addr;
    241         /** Remote host address length.
    242          */
     254        /** Remote host address. */
     255        struct sockaddr *addr;
     256        /** Remote host address length. */
    243257        socklen_t addrlen;
    244         /** Remote host port.
    245          */
     258        /** Remote host port. */
    246259        uint16_t dest_port;
    247         /** Parent local sockets.
    248          */
    249         socket_cores_ref local_sockets;
     260        /** Parent local sockets. */
     261        socket_cores_t *local_sockets;
     262       
    250263        /** Local sockets safety lock.
    251          *  May be locked for writing while holding the global lock for reading when changing the local sockets only.
    252          *  The global lock may to be locked only before locking the local lock.
    253          *  The global lock may be locked more weakly than the local lock.
    254          *  The global lock may be released before releasing the local lock.
    255          *  @see tcp_globals:lock
    256          */
    257         fibril_rwlock_t * local_lock;
    258         /** Pending operation data.
    259          */
     264         *
     265         * May be locked for writing while holding the global lock for reading
     266         * when changing the local sockets only.
     267         * The global lock may be locked only before locking the local lock.
     268         * The global lock may be locked more weakly than the local lock.
     269         * The global lock may be released before releasing the local lock.
     270         * @see tcp_globals:lock
     271         */
     272        fibril_rwlock_t *local_lock;
     273       
     274        /** Pending operation data. */
    260275        tcp_operation_t operation;
    261         /** Timeouts in a row counter.
    262          *  If TCP_MAX_TIMEOUTS is reached, the connection is lost.
     276       
     277        /**
     278         * Timeouts in a row counter.
     279         * If TCP_MAX_TIMEOUTS is reached, the connection is lost.
    263280         */
    264281        int timeout_count;
    265282};
    266283
    267 /** TCP global data.
    268  */
    269 struct  tcp_globals{
    270         /** Networking module phone.
    271          */
     284/** TCP global data. */
     285struct tcp_globals {
     286        /** Networking module phone. */
    272287        int net_phone;
    273         /** IP module phone.
    274          */
     288        /** IP module phone. */
    275289        int ip_phone;
    276         /** ICMP module phone.
    277          */
     290        /** ICMP module phone. */
    278291        int icmp_phone;
    279         /** Last used free port.
    280          */
     292        /** Last used free port. */
    281293        int last_used_port;
    282         /** Active sockets.
    283          */
     294        /** Active sockets. */
    284295        socket_ports_t sockets;
    285         /** Device packet dimensions.
    286          */
     296        /** Device packet dimensions. */
    287297        packet_dimensions_t dimensions;
    288         /** Safety lock.
    289          *  Write lock is used only for adding or removing socket ports.
     298       
     299        /**
     300         * Safety lock.
     301         * Write lock is used only for adding or removing socket ports.
    290302         */
    291303        fibril_rwlock_t lock;
     
    296308/** @}
    297309 */
    298 
Note: See TracChangeset for help on using the changeset viewer.