Changeset 704586fb in mainline for uspace/srv/net/tl/tcp/conn.c


Ignore:
Timestamp:
2011-12-01T19:28:49Z (14 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().

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.