Changeset 704586fb in mainline


Ignore:
Timestamp:
2011-12-01T19:28:49Z (12 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3aa2642a
Parents:
26ec91c
Message:

Fix RST to refuse connection and handle it properly in connect().

Location:
uspace/srv/net/tl/tcp
Files:
5 edited

Legend:

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

    r26ec91c r704586fb  
    5959static void tcp_conn_seg_process(tcp_conn_t *conn, tcp_segment_t *seg);
    6060static void tcp_conn_tw_timer_set(tcp_conn_t *conn);
     61static void tcp_conn_tw_timer_clear(tcp_conn_t *conn);
    6162
    6263/** Create new segment structure.
     
    255256        list_foreach(conn_list, link) {
    256257                tcp_conn_t *conn = list_get_instance(link, tcp_conn_t, link);
    257                 if (tcp_sockpair_match(sp, &conn->ident)) {
     258                tcp_sockpair_t *csp = &conn->ident;
     259                log_msg(LVL_DEBUG, "compare with conn (f:(%x,%u), l:(%x,%u))",
     260                    csp->foreign.addr.ipv4, csp->foreign.port,
     261                    csp->local.addr.ipv4, csp->local.port);
     262                if (tcp_sockpair_match(sp, csp)) {
    258263                        return conn;
    259264                }
     
    261266
    262267        return NULL;
     268}
     269
     270/** Reset connection.
     271 *
     272 * @param conn  Connection
     273 */
     274static void tcp_conn_reset(tcp_conn_t *conn)
     275{
     276        log_msg(LVL_DEBUG, "%s: tcp_conn_reset()", conn->name);
     277        tcp_conn_state_set(conn, st_closed);
     278        tcp_conn_tw_timer_clear(conn);
     279        tcp_tqueue_clear(&conn->retransmit);
    263280}
    264281
     
    370387                log_msg(LVL_DEBUG, "%s: Connection reset. -> Closed",
    371388                    conn->name);
    372                 /* XXX Signal user error */
    373                 tcp_conn_state_set(conn, st_closed);
     389                /* Reset connection */
     390                tcp_conn_reset(conn);
    374391                /* XXX delete connection */
    375392                return;
     
    10031020
    10041021        log_msg(LVL_DEBUG, "tw_timeout_func(%p)", conn);
     1022
     1023        if (conn->cstate == st_closed) {
     1024                log_msg(LVL_DEBUG, "Connection already closed.");
     1025                return;
     1026        }
     1027
    10051028        log_msg(LVL_DEBUG, "%s: TW Timeout -> Closed", conn->name);
    1006 
    10071029        tcp_conn_remove(conn);
    10081030        tcp_conn_state_set(conn, st_closed);
     
    10191041}
    10201042
     1043/** Clear the Time-Wait timeout.
     1044 *
     1045 * @param conn          Connection
     1046 */
     1047void tcp_conn_tw_timer_clear(tcp_conn_t *conn)
     1048{
     1049        fibril_timer_clear(conn->tw_timer);
     1050}
     1051
    10211052/** Trim segment to the receive window.
    10221053 *
     
    10671098void tcp_reply_rst(tcp_sockpair_t *sp, tcp_segment_t *seg)
    10681099{
    1069         tcp_sockpair_t rsp;
    10701100        tcp_segment_t *rseg;
    10711101
    10721102        log_msg(LVL_DEBUG, "tcp_reply_rst(%p, %p)", sp, seg);
    10731103
    1074         tcp_sockpair_flipped(sp, &rsp);
    10751104        rseg = tcp_segment_make_rst(seg);
    1076         tcp_transmit_segment(&rsp, rseg);
     1105        tcp_transmit_segment(sp, rseg);
    10771106}
    10781107
  • uspace/srv/net/tl/tcp/sock.c

    r26ec91c r704586fb  
    248248
    249249        trc = tcp_uc_open(lport, &fsocket, ap_active, &socket->conn);
    250         socket->conn->name = (char *)"C";
     250
     251        if (socket->conn != NULL)
     252                socket->conn->name = (char *)"C";
    251253
    252254        switch (trc) {
     
    307309
    308310        trc = tcp_uc_open(sock_core->port, &fsocket, ap_passive, &conn);
    309         conn->name = (char *)"S";
     311        if (conn != NULL)
     312                conn->name = (char *)"S";
    310313
    311314        log_msg(LVL_DEBUG, " - decode TCP return code");
  • uspace/srv/net/tl/tcp/tqueue.c

    r26ec91c r704586fb  
    7171}
    7272
     73void tcp_tqueue_clear(tcp_tqueue_t *tqueue)
     74{
     75        tcp_tqueue_timer_clear(tqueue->conn);
     76}
     77
    7378void tcp_tqueue_fini(tcp_tqueue_t *tqueue)
    7479{
     
    267272void tcp_transmit_segment(tcp_sockpair_t *sp, tcp_segment_t *seg)
    268273{
    269         log_msg(LVL_DEBUG, "tcp_transmit_segment(%p, %p)", sp, seg);
     274        log_msg(LVL_DEBUG, "tcp_transmit_segment(f:(%x,%u),l:(%x,%u), %p)",
     275            sp->foreign.addr.ipv4, sp->foreign.port,
     276            sp->local.addr.ipv4, sp->local.port, seg);
    270277
    271278        log_msg(LVL_DEBUG, "SEG.SEQ=%" PRIu32 ", SEG.WND=%" PRIu32,
     
    299306
    300307        log_msg(LVL_DEBUG, "### %s: retransmit_timeout_func(%p)", conn->name, conn);
     308
     309        if (conn->cstate == st_closed) {
     310                log_msg(LVL_DEBUG, "Connection already closed.");
     311                return;
     312        }
     313
    301314        link = list_first(&conn->retransmit.list);
    302315        if (link == NULL) {
  • uspace/srv/net/tl/tcp/tqueue.h

    r26ec91c r704586fb  
    4040
    4141extern int tcp_tqueue_init(tcp_tqueue_t *, tcp_conn_t *);
     42extern void tcp_tqueue_clear(tcp_tqueue_t *);
    4243extern void tcp_tqueue_fini(tcp_tqueue_t *);
    4344extern void tcp_tqueue_ctrl_seg(tcp_conn_t *, tcp_control_t);
  • uspace/srv/net/tl/tcp/ucall.c

    r26ec91c r704586fb  
    9191
    9292        if (nconn->cstate != st_established) {
    93                 fibril_mutex_unlock(&nconn->cstate_lock);
    94 
    9593                log_msg(LVL_DEBUG, "tcp_uc_open: Connection was reset.");
    9694                assert(nconn->cstate == st_closed);
     
    238236        tcp_conn_t *conn;
    239237
    240         log_msg(LVL_DEBUG, "tcp_as_segment_arrived()");
     238        log_msg(LVL_DEBUG, "tcp_as_segment_arrived(f:(%x,%u), l:(%x,%u))",
     239            sp->foreign.addr.ipv4, sp->foreign.port,
     240            sp->local.addr.ipv4, sp->local.port);
    241241
    242242        conn = tcp_conn_find(sp);
Note: See TracChangeset for help on using the changeset viewer.