Changeset 2989c7e in mainline for uspace/srv/net/tcp


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

Association map / portrange prototype.

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

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/tcp/Makefile

    r58e9dec r2989c7e  
    2828
    2929USPACE_PREFIX = ../../..
     30
     31LIBS = \
     32        $(LIBNETTL_PREFIX)/libnettl.a
     33
     34EXTRA_CFLAGS += \
     35        -I$(LIBNETTL_PREFIX)/include
     36
    3037BINARY = tcp
    3138
  • uspace/srv/net/tcp/conn.c

    r58e9dec r2989c7e  
    3636
    3737#include <adt/list.h>
    38 #include <stdbool.h>
    3938#include <errno.h>
    4039#include <inet/endpoint.h>
    4140#include <io/log.h>
    4241#include <macros.h>
     42#include <nettl/amap.h>
     43#include <stdbool.h>
    4344#include <stdlib.h>
    4445#include "conn.h"
     
    5657#define TIME_WAIT_TIMEOUT       (2*MAX_SEGMENT_LIFETIME)
    5758
    58 LIST_INITIALIZE(conn_list);
    59 FIBRIL_MUTEX_INITIALIZE(conn_list_lock);
     59static LIST_INITIALIZE(conn_list);
     60static FIBRIL_MUTEX_INITIALIZE(conn_list_lock);
     61static amap_t *amap;
    6062
    6163static void tcp_conn_seg_process(tcp_conn_t *conn, tcp_segment_t *seg);
    6264static void tcp_conn_tw_timer_set(tcp_conn_t *conn);
    6365static void tcp_conn_tw_timer_clear(tcp_conn_t *conn);
     66
     67/** Initialize connections. */
     68int tcp_conns_init(void)
     69{
     70        int rc;
     71
     72        rc = amap_create(&amap);
     73        if (rc != EOK) {
     74                assert(rc == ENOMEM);
     75                return ENOMEM;
     76        }
     77
     78        return EOK;
     79}
    6480
    6581/** Create new connection structure.
     
    246262 * Add connection to the connection map.
    247263 */
    248 void tcp_conn_add(tcp_conn_t *conn)
    249 {
     264int tcp_conn_add(tcp_conn_t *conn)
     265{
     266        inet_ep2_t aepp;
     267        int rc;
     268
    250269        tcp_conn_addref(conn);
    251270        fibril_mutex_lock(&conn_list_lock);
     271
     272        rc = amap_insert(amap, &conn->ident, conn, af_allow_system, &aepp);
     273        if (rc != EOK) {
     274                tcp_conn_delref(conn);
     275                fibril_mutex_unlock(&conn_list_lock);
     276                return rc;
     277        }
     278
     279        conn->ident = aepp;
    252280        list_append(&conn->link, &conn_list);
    253281        fibril_mutex_unlock(&conn_list_lock);
     282
     283        return EOK;
    254284}
    255285
     
    261291{
    262292        fibril_mutex_lock(&conn_list_lock);
     293        amap_remove(amap, &conn->ident);
    263294        list_remove(&conn->link);
    264295        fibril_mutex_unlock(&conn_list_lock);
  • uspace/srv/net/tcp/conn.h

    r58e9dec r2989c7e  
    4040#include "tcp_type.h"
    4141
     42extern int tcp_conns_init(void);
    4243extern tcp_conn_t *tcp_conn_new(inet_ep2_t *);
    4344extern void tcp_conn_delete(tcp_conn_t *);
    44 extern void tcp_conn_add(tcp_conn_t *);
     45extern int tcp_conn_add(tcp_conn_t *);
    4546extern void tcp_conn_remove(tcp_conn_t *);
    4647extern void tcp_conn_reset(tcp_conn_t *conn);
  • uspace/srv/net/tcp/service.c

    r58e9dec r2989c7e  
    335335        tcp_conn_t *conn;
    336336        tcp_cconn_t *cconn;
    337         inet_ep2_t cepp;
    338337        int rc;
    339338        tcp_error_t trc;
     
    343342        log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_create_impl");
    344343
    345         cepp = *epp;
    346 
    347         /* Fill in local address? */
    348         if (inet_addr_is_any(&epp->local.addr)) {
    349                 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_create_impl: "
    350                     "determine local address");
    351                 rc = inet_get_srcaddr(&epp->remote.addr, 0, &cepp.local.addr);
    352                 if (rc != EOK) {
    353                         log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_create_impl: "
    354                             "cannot determine local address");
    355                         return rc;
    356                 }
    357         } else {
    358                 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_create_impl: "
    359                     "local address specified");
    360         }
    361 
    362         /* Allocate local port? */
    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);
     344        inet_addr_format(&epp->local.addr, &slocal);
     345        inet_addr_format(&epp->remote.addr, &sremote);
    374346        log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_create: local=%s remote=%s",
    375347            slocal, sremote);
     
    377349        free(sremote);
    378350
    379         trc = tcp_uc_open(&cepp, ap_active, tcp_open_nonblock, &conn);
     351        trc = tcp_uc_open(epp, ap_active, tcp_open_nonblock, &conn);
    380352        if (trc != TCP_EOK)
    381353                return EIO;
  • uspace/srv/net/tcp/tcp.c

    r58e9dec r2989c7e  
    4545#include <task.h>
    4646
     47#include "conn.h"
    4748#include "ncsim.h"
    4849#include "pdu.h"
     
    179180        log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_init()");
    180181
     182        rc = tcp_conns_init();
     183        if (rc != EOK) {
     184                assert(rc == ENOMEM);
     185                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing connections");
     186                return ENOMEM;
     187        }
     188
    181189        tcp_rqueue_init();
    182190        tcp_rqueue_fibril_start();
  • uspace/srv/net/tcp/ucall.c

    r58e9dec r2989c7e  
    3535 */
    3636
     37#include <errno.h>
    3738#include <fibril_synch.h>
    3839#include <io/log.h>
     
    6869{
    6970        tcp_conn_t *nconn;
     71        int rc;
    7072
    7173        log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_open(%p, %s, %s, %p)",
     
    7476
    7577        nconn = tcp_conn_new(epp);
    76         tcp_conn_add(nconn);
     78        rc = tcp_conn_add(nconn);
     79        if (rc != EOK) {
     80                tcp_conn_delete(nconn);
     81                return TCP_EEXISTS;
     82        }
     83
    7784        tcp_conn_lock(nconn);
    7885
Note: See TracChangeset for help on using the changeset viewer.