Changeset 2f19103 in mainline for uspace/srv/net/tcp


Ignore:
Timestamp:
2015-05-22T07:21:37Z (10 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
58e9dec
Parents:
bf7587b0
Message:

TCP and UDP servers can make use of inet/endpoint.h types internally.

Location:
uspace/srv/net/tcp
Files:
16 edited

Legend:

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

    rbf7587b0 r2f19103  
    11/*
    2  * Copyright (c) 2011 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3838#include <stdbool.h>
    3939#include <errno.h>
     40#include <inet/endpoint.h>
    4041#include <io/log.h>
    4142#include <macros.h>
     
    6465/** Create new connection structure.
    6566 *
    66  * @param lsock         Local socket (will be deeply copied)
    67  * @param fsock         Foreign socket (will be deeply copied)
     67 * @param epp           Endpoint pair (will be deeply copied)
    6868 * @return              New connection or NULL
    6969 */
    70 tcp_conn_t *tcp_conn_new(tcp_sock_t *lsock, tcp_sock_t *fsock)
     70tcp_conn_t *tcp_conn_new(inet_ep2_t *epp)
    7171{
    7272        tcp_conn_t *conn = NULL;
     
    128128        conn->ap = ap_passive;
    129129        conn->fin_is_acked = false;
    130         conn->ident.local = *lsock;
    131         if (fsock != NULL)
    132                 conn->ident.foreign = *fsock;
     130        if (epp != NULL)
     131                conn->ident = *epp;
    133132
    134133        return conn;
     
    335334}
    336335
    337 /** Match socket with pattern. */
    338 static bool tcp_socket_match(tcp_sock_t *sock, tcp_sock_t *patt)
     336/** Match endpoint with pattern. */
     337static bool tcp_ep_match(inet_ep_t *ep, inet_ep_t *patt)
    339338{
    340339        log_msg(LOG_DEFAULT, LVL_DEBUG2,
    341             "tcp_socket_match(sock=(%u), pat=(%u))", sock->port, patt->port);
    342        
     340            "tcp_ep_match(ep=(%u), pat=(%u))", ep->port, patt->port);
     341
    343342        if ((!inet_addr_is_any(&patt->addr)) &&
    344             (!inet_addr_compare(&patt->addr, &sock->addr)))
     343            (!inet_addr_compare(&patt->addr, &ep->addr)))
    345344                return false;
    346345
    347346        if ((patt->port != TCP_PORT_ANY) &&
    348             (patt->port != sock->port))
     347            (patt->port != ep->port))
    349348                return false;
    350349
     
    354353}
    355354
    356 /** Match socket pair with pattern. */
    357 static bool tcp_sockpair_match(tcp_sockpair_t *sp, tcp_sockpair_t *pattern)
    358 {
    359         log_msg(LOG_DEFAULT, LVL_DEBUG2, "tcp_sockpair_match(%p, %p)", sp, pattern);
    360 
    361         if (!tcp_socket_match(&sp->local, &pattern->local))
     355/** Match endpoint pair with pattern. */
     356static bool tcp_ep2_match(inet_ep2_t *epp, inet_ep2_t *pattern)
     357{
     358        log_msg(LOG_DEFAULT, LVL_DEBUG2, "tcp_ep2_match(%p, %p)", epp, pattern);
     359
     360        if (!tcp_ep_match(&epp->local, &pattern->local))
    362361                return false;
    363362
    364         if (!tcp_socket_match(&sp->foreign, &pattern->foreign))
     363        if (!tcp_ep_match(&epp->remote, &pattern->remote))
    365364                return false;
    366365
     
    368367}
    369368
    370 /** Find connection structure for specified socket pair.
    371  *
    372  * A connection is uniquely identified by a socket pair. Look up our
    373  * connection map and return connection structure based on socket pair.
     369/** Find connection structure for specified endpoint pair.
     370 *
     371 * A connection is uniquely identified by a endpoint pair. Look up our
     372 * connection map and return connection structure based on endpoint pair.
    374373 * The connection reference count is bumped by one.
    375374 *
    376  * @param sp    Socket pair
     375 * @param epp   Endpoint pair
    377376 * @return      Connection structure or NULL if not found.
    378377 */
    379 tcp_conn_t *tcp_conn_find_ref(tcp_sockpair_t *sp)
    380 {
    381         log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_find_ref(%p)", sp);
    382        
     378tcp_conn_t *tcp_conn_find_ref(inet_ep2_t *epp)
     379{
     380        log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_find_ref(%p)", epp);
     381
    383382        log_msg(LOG_DEFAULT, LVL_DEBUG2, "compare conn (f:(%u), l:(%u))",
    384             sp->foreign.port, sp->local.port);
    385        
     383            epp->remote.port, epp->local.port);
     384
    386385        fibril_mutex_lock(&conn_list_lock);
    387        
     386
    388387        list_foreach(conn_list, link, tcp_conn_t, conn) {
    389                 tcp_sockpair_t *csp = &conn->ident;
    390                
     388                inet_ep2_t *cepp = &conn->ident;
     389
    391390                log_msg(LOG_DEFAULT, LVL_DEBUG2, " - with (f:(%u), l:(%u))",
    392                     csp->foreign.port, csp->local.port);
    393                
    394                 if (tcp_sockpair_match(sp, csp)) {
     391                    cepp->remote.port, cepp->local.port);
     392
     393                if (tcp_ep2_match(epp, cepp)) {
    395394                        tcp_conn_addref(conn);
    396395                        fibril_mutex_unlock(&conn_list_lock);
     
    398397                }
    399398        }
    400        
     399
    401400        fibril_mutex_unlock(&conn_list_lock);
    402401        return NULL;
     
    12701269}
    12711270
    1272 /** Handle unexpected segment received on a socket pair.
     1271/** Handle unexpected segment received on an endpoint pair.
    12731272 *
    12741273 * We reply with an RST unless the received segment has RST.
    12751274 *
    1276  * @param sp            Socket pair which received the segment
     1275 * @param sp            Endpoint pair which received the segment
    12771276 * @param seg           Unexpected segment
    12781277 */
    1279 void tcp_unexpected_segment(tcp_sockpair_t *sp, tcp_segment_t *seg)
    1280 {
    1281         log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_unexpected_segment(%p, %p)", sp, seg);
     1278void tcp_unexpected_segment(inet_ep2_t *epp, tcp_segment_t *seg)
     1279{
     1280        log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_unexpected_segment(%p, %p)", epp,
     1281            seg);
    12821282
    12831283        if ((seg->ctrl & CTL_RST) == 0)
    1284                 tcp_reply_rst(sp, seg);
    1285 }
    1286 
    1287 /** Compute flipped socket pair for response.
    1288  *
    1289  * Flipped socket pair has local and foreign sockets exchanged.
    1290  *
    1291  * @param sp            Socket pair
    1292  * @param fsp           Place to store flipped socket pair
    1293  */
    1294 void tcp_sockpair_flipped(tcp_sockpair_t *sp, tcp_sockpair_t *fsp)
    1295 {
    1296         fsp->local = sp->foreign;
    1297         fsp->foreign = sp->local;
     1284                tcp_reply_rst(epp, seg);
     1285}
     1286
     1287/** Compute flipped endpoint pair for response.
     1288 *
     1289 * Flipped endpoint pair has local and remote endpoints exchanged.
     1290 *
     1291 * @param epp           Endpoint pair
     1292 * @param fepp          Place to store flipped endpoint pair
     1293 */
     1294void tcp_ep2_flipped(inet_ep2_t *epp, inet_ep2_t *fepp)
     1295{
     1296        fepp->local = epp->remote;
     1297        fepp->remote = epp->local;
    12981298}
    12991299
    13001300/** Send RST in response to an incoming segment.
    13011301 *
    1302  * @param sp            Socket pair which received the segment
     1302 * @param epp           Endpoint pair which received the segment
    13031303 * @param seg           Incoming segment
    13041304 */
    1305 void tcp_reply_rst(tcp_sockpair_t *sp, tcp_segment_t *seg)
     1305void tcp_reply_rst(inet_ep2_t *epp, tcp_segment_t *seg)
    13061306{
    13071307        tcp_segment_t *rseg;
    13081308
    1309         log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_reply_rst(%p, %p)", sp, seg);
     1309        log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_reply_rst(%p, %p)", epp, seg);
    13101310
    13111311        rseg = tcp_segment_make_rst(seg);
    1312         tcp_transmit_segment(sp, rseg);
     1312        tcp_transmit_segment(epp, rseg);
    13131313}
    13141314
  • uspace/srv/net/tcp/conn.h

    rbf7587b0 r2f19103  
    11/*
    2  * Copyright (c) 2011 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3636#define CONN_H
    3737
     38#include <inet/endpoint.h>
    3839#include <stdbool.h>
    3940#include "tcp_type.h"
    4041
    41 extern tcp_conn_t *tcp_conn_new(tcp_sock_t *, tcp_sock_t *);
     42extern tcp_conn_t *tcp_conn_new(inet_ep2_t *);
    4243extern void tcp_conn_delete(tcp_conn_t *);
    4344extern void tcp_conn_add(tcp_conn_t *);
     
    4748extern void tcp_conn_fin_sent(tcp_conn_t *);
    4849extern void tcp_conn_ack_of_fin_rcvd(tcp_conn_t *);
    49 extern tcp_conn_t *tcp_conn_find_ref(tcp_sockpair_t *);
     50extern tcp_conn_t *tcp_conn_find_ref(inet_ep2_t *);
    5051extern void tcp_conn_addref(tcp_conn_t *);
    5152extern void tcp_conn_delref(tcp_conn_t *);
     
    5556extern void tcp_conn_segment_arrived(tcp_conn_t *, tcp_segment_t *);
    5657extern void tcp_conn_trim_seg_to_wnd(tcp_conn_t *, tcp_segment_t *);
    57 extern void tcp_unexpected_segment(tcp_sockpair_t *, tcp_segment_t *);
    58 extern void tcp_sockpair_flipped(tcp_sockpair_t *, tcp_sockpair_t *);
    59 extern void tcp_reply_rst(tcp_sockpair_t *, tcp_segment_t *);
     58extern void tcp_unexpected_segment(inet_ep2_t *, tcp_segment_t *);
     59extern void tcp_ep2_flipped(inet_ep2_t *, inet_ep2_t *);
     60extern void tcp_reply_rst(inet_ep2_t *, tcp_segment_t *);
    6061
    6162#endif
  • uspace/srv/net/tcp/ncsim.c

    rbf7587b0 r2f19103  
    11/*
    2  * Copyright (c) 2011 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4242#include <async.h>
    4343#include <errno.h>
     44#include <inet/endpoint.h>
    4445#include <io/log.h>
    4546#include <stdlib.h>
     
    6566/** Bounce segment through simulator into receive queue.
    6667 *
    67  * @param sp    Socket pair, oriented for transmission
     68 * @param epp   Endpoint pair, oriented for transmission
    6869 * @param seg   Segment
    6970 */
    70 void tcp_ncsim_bounce_seg(tcp_sockpair_t *sp, tcp_segment_t *seg)
     71void tcp_ncsim_bounce_seg(inet_ep2_t *epp, tcp_segment_t *seg)
    7172{
    7273        tcp_squeue_entry_t *sqe;
     
    7576
    7677        log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_ncsim_bounce_seg()");
    77         tcp_rqueue_bounce_seg(sp, seg);
     78        tcp_rqueue_bounce_seg(epp, seg);
    7879        return;
    7980
     
    9293
    9394        sqe->delay = random() % (1000 * 1000);
    94         sqe->sp = *sp;
     95        sqe->epp = *epp;
    9596        sqe->seg = seg;
    9697
     
    147148
    148149                log_msg(LOG_DEFAULT, LVL_DEBUG, "NCSim - End Sleep");
    149                 tcp_rqueue_bounce_seg(&sqe->sp, sqe->seg);
     150                tcp_rqueue_bounce_seg(&sqe->epp, sqe->seg);
    150151                free(sqe);
    151152        }
  • uspace/srv/net/tcp/ncsim.h

    rbf7587b0 r2f19103  
    11/*
    2  * Copyright (c) 2011 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3636#define NCSIM_H
    3737
     38#include <inet/endpoint.h>
    3839#include "tcp_type.h"
    3940
    4041extern void tcp_ncsim_init(void);
    41 extern void tcp_ncsim_bounce_seg(tcp_sockpair_t *, tcp_segment_t *);
     42extern void tcp_ncsim_bounce_seg(inet_ep2_t *, tcp_segment_t *);
    4243extern void tcp_ncsim_fibril_start(void);
    4344
  • uspace/srv/net/tcp/pdu.c

    rbf7587b0 r2f19103  
    11/*
    2  * Copyright (c) 2011 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3838#include <byteorder.h>
    3939#include <errno.h>
     40#include <inet/endpoint.h>
    4041#include <mem.h>
    4142#include <stdlib.h>
     
    125126}
    126127
    127 static void tcp_header_setup(tcp_sockpair_t *sp, tcp_segment_t *seg, tcp_header_t *hdr)
     128static void tcp_header_setup(inet_ep2_t *epp, tcp_segment_t *seg, tcp_header_t *hdr)
    128129{
    129130        uint16_t doff_flags;
    130131        uint16_t doff;
    131132
    132         hdr->src_port = host2uint16_t_be(sp->local.port);
    133         hdr->dest_port = host2uint16_t_be(sp->foreign.port);
     133        hdr->src_port = host2uint16_t_be(epp->local.port);
     134        hdr->dest_port = host2uint16_t_be(epp->remote.port);
    134135        hdr->seq = host2uint32_t_be(seg->seq);
    135136        hdr->ack = host2uint32_t_be(seg->ack);
     
    190191}
    191192
    192 static int tcp_header_encode(tcp_sockpair_t *sp, tcp_segment_t *seg,
     193static int tcp_header_encode(inet_ep2_t *epp, tcp_segment_t *seg,
    193194    void **header, size_t *size)
    194195{
     
    199200                return ENOMEM;
    200201
    201         tcp_header_setup(sp, seg, hdr);
     202        tcp_header_setup(epp, seg, hdr);
    202203        *header = hdr;
    203204        *size = sizeof(tcp_header_t);
     
    293294
    294295/** Decode incoming PDU */
    295 int tcp_pdu_decode(tcp_pdu_t *pdu, tcp_sockpair_t *sp, tcp_segment_t **seg)
     296int tcp_pdu_decode(tcp_pdu_t *pdu, inet_ep2_t *epp, tcp_segment_t **seg)
    296297{
    297298        tcp_segment_t *nseg;
     
    307308        hdr = (tcp_header_t *)pdu->header;
    308309
    309         sp->local.port = uint16_t_be2host(hdr->dest_port);
    310         sp->local.addr = pdu->dest;
    311         sp->foreign.port = uint16_t_be2host(hdr->src_port);
    312         sp->foreign.addr = pdu->src;
     310        epp->local.port = uint16_t_be2host(hdr->dest_port);
     311        epp->local.addr = pdu->dest;
     312        epp->remote.port = uint16_t_be2host(hdr->src_port);
     313        epp->remote.addr = pdu->src;
    313314
    314315        *seg = nseg;
     
    317318
    318319/** Encode outgoing PDU */
    319 int tcp_pdu_encode(tcp_sockpair_t *sp, tcp_segment_t *seg, tcp_pdu_t **pdu)
     320int tcp_pdu_encode(inet_ep2_t *epp, tcp_segment_t *seg, tcp_pdu_t **pdu)
    320321{
    321322        tcp_pdu_t *npdu;
     
    327328                return ENOMEM;
    328329
    329         npdu->src = sp->local.addr;
    330         npdu->dest = sp->foreign.addr;
    331         tcp_header_encode(sp, seg, &npdu->header, &npdu->header_size);
     330        npdu->src = epp->local.addr;
     331        npdu->dest = epp->remote.addr;
     332        tcp_header_encode(epp, seg, &npdu->header, &npdu->header_size);
    332333
    333334        text_size = tcp_segment_text_size(seg);
  • uspace/srv/net/tcp/pdu.h

    rbf7587b0 r2f19103  
    11/*
    2  * Copyright (c) 2011 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3636#define PDU_H
    3737
     38#include <inet/endpoint.h>
    3839#include <sys/types.h>
    3940#include "std.h"
     
    4243extern tcp_pdu_t *tcp_pdu_create(void *, size_t, void *, size_t);
    4344extern void tcp_pdu_delete(tcp_pdu_t *);
    44 extern int tcp_pdu_decode(tcp_pdu_t *, tcp_sockpair_t *, tcp_segment_t **);
    45 extern int tcp_pdu_encode(tcp_sockpair_t *, tcp_segment_t *, tcp_pdu_t **);
     45extern int tcp_pdu_decode(tcp_pdu_t *, inet_ep2_t *, tcp_segment_t **);
     46extern int tcp_pdu_encode(inet_ep2_t *, tcp_segment_t *, tcp_pdu_t **);
    4647
    4748#endif
  • uspace/srv/net/tcp/rqueue.c

    rbf7587b0 r2f19103  
    11/*
    2  * Copyright (c) 2011 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    6767 * This is for testing purposes only.
    6868 *
    69  * @param sp    Socket pair, oriented for transmission
     69 * @param sp    Endpoint pair, oriented for transmission
    7070 * @param seg   Segment
    7171 */
    72 void tcp_rqueue_bounce_seg(tcp_sockpair_t *sp, tcp_segment_t *seg)
     72void tcp_rqueue_bounce_seg(inet_ep2_t *epp, tcp_segment_t *seg)
    7373{
    74         tcp_sockpair_t rident;
     74        inet_ep2_t rident;
    7575
    7676        log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_rqueue_bounce_seg()");
     
    8080        tcp_segment_t *dseg;
    8181
    82         if (tcp_pdu_encode(sp, seg, &pdu) != EOK) {
     82        if (tcp_pdu_encode(epp, seg, &pdu) != EOK) {
    8383                log_msg(LOG_DEFAULT, LVL_WARN, "Not enough memory. Segment dropped.");
    8484                return;
     
    9797#else
    9898        /* Reverse the identification */
    99         tcp_sockpair_flipped(sp, &rident);
     99        tcp_ep2_flipped(epp, &rident);
    100100
    101101        /* Insert segment back into rqueue */
     
    106106/** Insert segment into receive queue.
    107107 *
    108  * @param sp    Socket pair, oriented for reception
     108 * @param epp   Endpoint pair, oriented for reception
    109109 * @param seg   Segment
    110110 */
    111 void tcp_rqueue_insert_seg(tcp_sockpair_t *sp, tcp_segment_t *seg)
     111void tcp_rqueue_insert_seg(inet_ep2_t *epp, tcp_segment_t *seg)
    112112{
    113113        tcp_rqueue_entry_t *rqe;
     
    122122        }
    123123
    124         rqe->sp = *sp;
     124        rqe->epp = *epp;
    125125        rqe->seg = seg;
    126126
     
    140140                rqe = list_get_instance(link, tcp_rqueue_entry_t, link);
    141141
    142                 tcp_as_segment_arrived(&rqe->sp, rqe->seg);
     142                tcp_as_segment_arrived(&rqe->epp, rqe->seg);
    143143                free(rqe);
    144144        }
  • uspace/srv/net/tcp/rqueue.h

    rbf7587b0 r2f19103  
    11/*
    2  * Copyright (c) 2011 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3636#define RQUEUE_H
    3737
     38#include <inet/endpoint.h>
    3839#include "tcp_type.h"
    3940
    4041extern void tcp_rqueue_init(void);
    41 extern void tcp_rqueue_bounce_seg(tcp_sockpair_t *, tcp_segment_t *);
    42 extern void tcp_rqueue_insert_seg(tcp_sockpair_t *, tcp_segment_t *);
     42extern void tcp_rqueue_bounce_seg(inet_ep2_t *, tcp_segment_t *);
     43extern void tcp_rqueue_insert_seg(inet_ep2_t *, tcp_segment_t *);
    4344extern void tcp_rqueue_handler(void *);
    4445extern void tcp_rqueue_fibril_start(void);
  • uspace/srv/net/tcp/service.c

    rbf7587b0 r2f19103  
    108108        tcp_clst_t *clst;
    109109        tcp_cconn_t *cconn;
     110        inet_ep2_t epp;
    110111        int rc;
    111112        tcp_error_t trc;
     
    145146        /* Replenish sentinel connection */
    146147
    147         trc = tcp_uc_open(&clst->elocal, NULL, ap_passive, tcp_open_nonblock,
     148        inet_ep2_init(&epp);
     149        epp.local = clst->elocal;
     150
     151        trc = tcp_uc_open(&epp, ap_passive, tcp_open_nonblock,
    148152            &conn);
    149153        if (trc != TCP_EOK) {
     
    331335        tcp_conn_t *conn;
    332336        tcp_cconn_t *cconn;
    333         tcp_sock_t local;
    334         tcp_sock_t remote;
    335         inet_addr_t local_addr;
     337        inet_ep2_t cepp;
    336338        int rc;
    337339        tcp_error_t trc;
     
    340342
    341343        log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_create_impl");
     344
     345        cepp = *epp;
    342346
    343347        /* Fill in local address? */
     
    345349                log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_create_impl: "
    346350                    "determine local address");
    347                 rc = inet_get_srcaddr(&epp->remote.addr, 0, &local_addr);
     351                rc = inet_get_srcaddr(&epp->remote.addr, 0, &cepp.local.addr);
    348352                if (rc != EOK) {
    349353                        log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_create_impl: "
     
    354358                log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_create_impl: "
    355359                    "local address specified");
    356                 local_addr = epp->local.addr;
    357360        }
    358361
    359362        /* Allocate local port? */
    360         if (epp->local.port == 0) {
    361                 epp->local.port = 49152; /* XXX */
    362         }
    363 
    364         local.addr = local_addr;
    365         local.port = epp->local.port;
    366         remote.addr = epp->remote.addr;
    367         remote.port = epp->remote.port;
    368 
    369         inet_addr_format(&local_addr, &slocal);
    370         inet_addr_format(&remote.addr, &sremote);
     363        if (cepp.local.port == 0) {
     364                cepp.local.port = 49152; /* XXX */
     365                log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_create_impl: "
     366                    "allocated local port %" PRIu16, cepp.local.port);
     367        } else {
     368                log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_create_impl: "
     369                    "local port %" PRIu16 " specified", cepp.local.port);
     370        }
     371
     372        inet_addr_format(&cepp.local.addr, &slocal);
     373        inet_addr_format(&cepp.remote.addr, &sremote);
    371374        log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_create: local=%s remote=%s",
    372375            slocal, sremote);
    373 
    374         trc = tcp_uc_open(&local, &remote, ap_active, tcp_open_nonblock, &conn);
     376        free(slocal);
     377        free(sremote);
     378
     379        trc = tcp_uc_open(&cepp, ap_active, tcp_open_nonblock, &conn);
    375380        if (trc != TCP_EOK)
    376381                return EIO;
     
    386391        tcp_uc_set_cb(conn, &tcp_service_cb, cconn);
    387392
    388 //      assoc->cb = &udp_cassoc_cb;
    389 //      assoc->cb_arg = cassoc;
    390 
    391393        *rconn_id = cconn->id;
    392394        return EOK;
     
    415417        tcp_conn_t *conn;
    416418        tcp_clst_t *clst;
    417         tcp_sock_t local;
     419        inet_ep2_t epp;
    418420        int rc;
    419421        tcp_error_t trc;
     
    421423        log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_listener_create_impl");
    422424
    423         local.addr = ep->addr;
    424         local.port = ep->port;
    425 
    426         trc = tcp_uc_open(&local, NULL, ap_passive, tcp_open_nonblock, &conn);
     425        inet_ep2_init(&epp);
     426        epp.local.addr = ep->addr;
     427        epp.local.port = ep->port;
     428
     429        trc = tcp_uc_open(&epp, ap_passive, tcp_open_nonblock, &conn);
    427430        if (trc != TCP_EOK)
    428431                return EIO;
     
    435438        }
    436439
    437         clst->elocal = local;
     440        clst->elocal = epp.local;
    438441
    439442        /* XXX Is there a race here (i.e. the connection is already active)? */
  • uspace/srv/net/tcp/tcp.c

    rbf7587b0 r2f19103  
    11/*
    2  * Copyright (c) 2012 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    160160{
    161161        tcp_segment_t *dseg;
    162         tcp_sockpair_t rident;
     162        inet_ep2_t rident;
    163163
    164164        log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_received_pdu()");
  • uspace/srv/net/tcp/tcp_type.h

    rbf7587b0 r2f19103  
    11/*
    2  * Copyright (c) 2011 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4343#include <sys/types.h>
    4444#include <inet/addr.h>
     45#include <inet/endpoint.h>
    4546
    4647struct tcp_conn;
     
    8990        /* Connection reset */
    9091        TCP_ERESET,
    91         /* Foreign socket unspecified */
     92        /* Remote endpoint unspecified */
    9293        TCP_EUNSPEC,
    9394        /* Insufficient resources */
     
    112113} tcp_control_t;
    113114
    114 typedef struct {
    115         inet_addr_t addr;
    116         uint16_t port;
    117 } tcp_sock_t;
    118 
    119115enum tcp_port {
    120116        TCP_PORT_ANY = 0
    121117};
    122 
    123 typedef struct {
    124         tcp_sock_t local;
    125         tcp_sock_t foreign;
    126 } tcp_sockpair_t;
    127118
    128119/** Connection incoming segments queue */
     
    171162        void *cb_arg;
    172163
    173         /** Connection identification (local and foreign socket) */
    174         tcp_sockpair_t ident;
     164        /** Connection identification (local and remote endpoint) */
     165        inet_ep2_t ident;
    175166
    176167        /** Active or passive connection */
     
    280271typedef struct {
    281272        link_t link;
    282         tcp_sockpair_t sp;
     273        inet_ep2_t epp;
    283274        tcp_segment_t *seg;
    284275} tcp_rqueue_entry_t;
     
    288279        link_t link;
    289280        suseconds_t delay;
    290         tcp_sockpair_t sp;
     281        inet_ep2_t epp;
    291282        tcp_segment_t *seg;
    292283} tcp_squeue_entry_t;
     
    339330typedef struct tcp_clst {
    340331        /** Local endpoint */
    341         tcp_sock_t elocal;
     332        inet_ep_t elocal;
    342333        /** Connection */
    343334        tcp_conn_t *conn;
     
    360351} tcp_client_t;
    361352
    362 #define TCP_SOCK_FRAGMENT_SIZE 1024
    363 
    364 typedef struct tcp_sockdata {
    365         /** Lock */
    366         fibril_mutex_t lock;
    367         /** Socket core */
    368 //      socket_core_t *sock_core;
    369         /** Client */
    370         tcp_client_t *client;
    371         /** Connection */
    372         tcp_conn_t *conn;
    373         /** Local address */
    374         inet_addr_t laddr;
    375         /** Backlog size */
    376         int backlog;
    377         /** Array of listening connections, @c backlog elements */
    378         struct tcp_sock_lconn **lconn;
    379         /** List of connections (from lconn) that are ready to be accepted */
    380         list_t ready;
    381         /** Receiving fibril */
    382         fid_t recv_fibril;
    383         uint8_t recv_buffer[TCP_SOCK_FRAGMENT_SIZE];
    384         size_t recv_buffer_used;
    385         fibril_mutex_t recv_buffer_lock;
    386         fibril_condvar_t recv_buffer_cv;
    387         tcp_error_t recv_error;
    388 } tcp_sockdata_t;
    389 
    390 typedef struct tcp_sock_lconn {
    391         tcp_conn_t *conn;
    392         tcp_sockdata_t *socket;
    393         int index;
    394         link_t ready_list;
    395 } tcp_sock_lconn_t;
    396 
    397353#endif
    398354
  • uspace/srv/net/tcp/test.c

    rbf7587b0 r2f19103  
    11/*
    2  * Copyright (c) 2011 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5050{
    5151        tcp_conn_t *conn;
    52         tcp_sock_t lsock;
    53         tcp_sock_t fsock;
     52        inet_ep2_t epp;
    5453        char rcv_buf[RCV_BUF_SIZE + 1];
    5554        size_t rcvd;
     
    5756
    5857        printf("test_srv()\n");
    59        
    60         inet_addr(&lsock.addr, 127, 0, 0, 1);
    61         lsock.port = 80;
    62        
    63         inet_addr(&fsock.addr, 127, 0, 0, 1);
    64         fsock.port = 1024;
    65        
     58
     59        inet_ep2_init(&epp);
     60
     61        inet_addr(&epp.local.addr, 127, 0, 0, 1);
     62        epp.local.port = 80;
     63
     64        inet_addr(&epp.remote.addr, 127, 0, 0, 1);
     65        epp.remote.port = 1024;
     66
    6667        printf("S: User open...\n");
    67         tcp_uc_open(&lsock, &fsock, ap_passive, 0, &conn);
     68        tcp_uc_open(&epp, ap_passive, 0, &conn);
    6869        conn->name = (char *) "S";
    6970
     
    9394{
    9495        tcp_conn_t *conn;
    95         tcp_sock_t lsock;
    96         tcp_sock_t fsock;
     96        inet_ep2_t epp;
    9797        const char *msg = "Hello World!";
    9898
    9999        printf("test_cli()\n");
    100        
    101         inet_addr(&lsock.addr, 127, 0, 0, 1);
    102         lsock.port = 1024;
    103        
    104         inet_addr(&fsock.addr, 127, 0, 0, 1);
    105         fsock.port = 80;
     100
     101        inet_ep2_init(&epp);
     102
     103        inet_addr(&epp.local.addr, 127, 0, 0, 1);
     104        epp.local.port = 1024;
     105
     106        inet_addr(&epp.remote.addr, 127, 0, 0, 1);
     107        epp.remote.port = 80;
    106108
    107109        async_usleep(1000*1000*3);
    108110        printf("C: User open...\n");
    109         tcp_uc_open(&lsock, &fsock, ap_active, 0, &conn);
     111        tcp_uc_open(&epp, ap_active, 0, &conn);
    110112        conn->name = (char *) "C";
    111113
  • uspace/srv/net/tcp/tqueue.c

    rbf7587b0 r2f19103  
    11/*
    2  * Copyright (c) 2011 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    282282}
    283283
    284 void tcp_transmit_segment(tcp_sockpair_t *sp, tcp_segment_t *seg)
     284void tcp_transmit_segment(inet_ep2_t *epp, tcp_segment_t *seg)
    285285{
    286286        log_msg(LOG_DEFAULT, LVL_DEBUG,
    287287            "tcp_transmit_segment(l:(%u),f:(%u), %p)",
    288             sp->local.port, sp->foreign.port, seg);
    289        
     288            epp->local.port, epp->remote.port, seg);
     289
    290290        log_msg(LOG_DEFAULT, LVL_DEBUG, "SEG.SEQ=%" PRIu32 ", SEG.WND=%" PRIu32,
    291291            seg->seq, seg->wnd);
     
    301301        tcp_pdu_t *pdu;
    302302
    303         if (tcp_pdu_encode(sp, seg, &pdu) != EOK) {
     303        if (tcp_pdu_encode(epp, seg, &pdu) != EOK) {
    304304                log_msg(LOG_DEFAULT, LVL_WARN, "Not enough memory. Segment dropped.");
    305305                return;
  • uspace/srv/net/tcp/tqueue.h

    rbf7587b0 r2f19103  
    11/*
    2  * Copyright (c) 2011 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3636#define TQUEUE_H
    3737
     38#include <inet/endpoint.h>
    3839#include "std.h"
    3940#include "tcp_type.h"
     
    4849extern void tcp_prepare_transmit_segment(tcp_conn_t *, tcp_segment_t *);
    4950extern void tcp_conn_transmit_segment(tcp_conn_t *, tcp_segment_t *);
    50 extern void tcp_transmit_segment(tcp_sockpair_t *, tcp_segment_t *);
     51extern void tcp_transmit_segment(inet_ep2_t *, tcp_segment_t *);
    5152extern void tcp_header_setup(tcp_conn_t *, tcp_segment_t *, tcp_header_t *);
    5253extern void tcp_phdr_setup(tcp_conn_t *, tcp_segment_t *, tcp_phdr_t *);
  • uspace/srv/net/tcp/ucall.c

    rbf7587b0 r2f19103  
    11/*
    2  * Copyright (c) 2011 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5050/** OPEN user call
    5151 *
    52  * @param lsock         Local socket
    53  * @param fsock         Foreign socket
     52 * @param epp           Endpoint pair
    5453 * @param acpass        Active/passive
    5554 * @param oflags        Open flags
     
    6564 * establishment.
    6665 */
    67 tcp_error_t tcp_uc_open(tcp_sock_t *lsock, tcp_sock_t *fsock, acpass_t acpass,
     66tcp_error_t tcp_uc_open(inet_ep2_t *epp, acpass_t acpass,
    6867    tcp_open_flags_t oflags, tcp_conn_t **conn)
    6968{
    7069        tcp_conn_t *nconn;
    7170
    72         log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_open(%p, %p, %s, %s, %p)",
    73             lsock, fsock, acpass == ap_active ? "active" : "passive",
     71        log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_open(%p, %s, %s, %p)",
     72            epp, acpass == ap_active ? "active" : "passive",
    7473            oflags == tcp_open_nonblock ? "nonblock" : "none", conn);
    7574
    76         nconn = tcp_conn_new(lsock, fsock);
     75        nconn = tcp_conn_new(epp);
    7776        tcp_conn_add(nconn);
    7877        tcp_conn_lock(nconn);
     
    315314
    316315/** Segment arrived */
    317 void tcp_as_segment_arrived(tcp_sockpair_t *sp, tcp_segment_t *seg)
     316void tcp_as_segment_arrived(inet_ep2_t *epp, tcp_segment_t *seg)
    318317{
    319318        tcp_conn_t *conn;
     
    321320        log_msg(LOG_DEFAULT, LVL_DEBUG,
    322321            "tcp_as_segment_arrived(f:(%u), l:(%u))",
    323             sp->foreign.port, sp->local.port);
    324 
    325         conn = tcp_conn_find_ref(sp);
     322            epp->remote.port, epp->local.port);
     323
     324        conn = tcp_conn_find_ref(epp);
    326325        if (conn == NULL) {
    327326                log_msg(LOG_DEFAULT, LVL_WARN, "No connection found.");
    328                 tcp_unexpected_segment(sp, seg);
     327                tcp_unexpected_segment(epp, seg);
    329328                return;
    330329        }
     
    334333        if (conn->cstate == st_closed) {
    335334                log_msg(LOG_DEFAULT, LVL_WARN, "Connection is closed.");
    336                 tcp_unexpected_segment(sp, seg);
     335                tcp_unexpected_segment(epp, seg);
    337336                tcp_conn_unlock(conn);
    338337                tcp_conn_delref(conn);
     
    340339        }
    341340
    342         if (inet_addr_is_any(&conn->ident.foreign.addr))
    343                 conn->ident.foreign.addr = sp->foreign.addr;
    344        
    345         if (conn->ident.foreign.port == TCP_PORT_ANY)
    346                 conn->ident.foreign.port = sp->foreign.port;
    347        
     341        if (inet_addr_is_any(&conn->ident.remote.addr))
     342                conn->ident.remote.addr = epp->remote.addr;
     343
     344        if (conn->ident.remote.port == TCP_PORT_ANY)
     345                conn->ident.remote.port = epp->remote.port;
     346
    348347        if (inet_addr_is_any(&conn->ident.local.addr))
    349                 conn->ident.local.addr = sp->local.addr;
     348                conn->ident.local.addr = epp->local.addr;
    350349
    351350        tcp_conn_segment_arrived(conn, seg);
  • uspace/srv/net/tcp/ucall.h

    rbf7587b0 r2f19103  
    11/*
    2  * Copyright (c) 2011 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3636#define UCALL_H
    3737
     38#include <inet/endpoint.h>
    3839#include <sys/types.h>
    3940#include "tcp_type.h"
     
    4243 * User calls
    4344 */
    44 extern tcp_error_t tcp_uc_open(tcp_sock_t *, tcp_sock_t *, acpass_t,
     45extern tcp_error_t tcp_uc_open(inet_ep2_t *, acpass_t,
    4546    tcp_open_flags_t, tcp_conn_t **);
    4647extern tcp_error_t tcp_uc_send(tcp_conn_t *, void *, size_t, xflags_t);
     
    5657 * Arriving segments
    5758 */
    58 extern void tcp_as_segment_arrived(tcp_sockpair_t *, tcp_segment_t *);
     59extern void tcp_as_segment_arrived(inet_ep2_t *, tcp_segment_t *);
    5960
    6061/*
Note: See TracChangeset for help on using the changeset viewer.