Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 6896409c in mainline


Ignore:
Timestamp:
2011-11-21T22:46:37Z (10 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master
Children:
1812a0d
Parents:
eea65f4
Message:

Fix off-by-one bug in BIT_V.
Fix FIN being sent too early.
Fix FIN not being sent.
Fix seg→len from decoded PDU.
Add segment dumps.

Location:
uspace
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/include/bitops.h

    reea65f4 r6896409c  
    4040/** Mask with bit @a n set. */
    4141#define BIT_V(type, n) \
    42     ((type)1 << ((n) - 1))
     42    ((type)1 << (n))
    4343
    4444/** Mask with rightmost @a n bits set. */
    4545#define BIT_RRANGE(type, n) \
    46     (BIT_V(type, (n) + 1) - 1)
     46    (BIT_V(type, (n)) - 1)
    4747
    4848/** Mask with bits @a hi .. @a lo set. @a hi >= @a lo. */
  • uspace/srv/net/tl/tcp/conn.c

    reea65f4 r6896409c  
    190190        case st_syn_received:
    191191        case st_established:
    192                 log_msg(LVL_DEBUG, "FIN sent -> Fin-Wait-1");
     192                log_msg(LVL_DEBUG, "%s: FIN sent -> Fin-Wait-1", conn->name);
    193193                tcp_conn_state_set(conn, st_fin_wait_1);
    194194                break;
    195195        case st_close_wait:
    196                 log_msg(LVL_DEBUG, "FIN sent -> Last-Ack");
     196                log_msg(LVL_DEBUG, "%s: FIN sent -> Last-Ack", conn->name);
    197197                tcp_conn_state_set(conn, st_last_ack);
    198198                break;
    199199        default:
    200                 log_msg(LVL_ERROR, "Connection state %d", conn->cstate);
     200                log_msg(LVL_ERROR, "%s: Connection state %d", conn->name,
     201                    conn->cstate);
    201202                assert(false);
    202203        }
     
    367368
    368369        if ((seg->ctrl & CTL_RST) != 0) {
    369                 log_msg(LVL_DEBUG, "Connection reset. -> Closed");
     370                log_msg(LVL_DEBUG, "%s: Connection reset. -> Closed",
     371                    conn->name);
    370372                /* XXX Signal user error */
    371373                tcp_conn_state_set(conn, st_closed);
     
    408410
    409411        if (seq_no_syn_acked(conn)) {
    410                 log_msg(LVL_DEBUG, " syn acked -> Established");
     412                log_msg(LVL_DEBUG, "%s: syn acked -> Established", conn->name);
    411413                tcp_conn_state_set(conn, st_established);
    412414                tcp_tqueue_ctrl_seg(conn, CTL_ACK /* XXX */);
    413415        } else {
    414                 log_msg(LVL_DEBUG, " syn not acked -> Syn-Received");
     416                log_msg(LVL_DEBUG, "%s: syn not acked -> Syn-Received",
     417                    conn->name);
    415418                tcp_conn_state_set(conn, st_syn_received);
    416419                tcp_tqueue_ctrl_seg(conn, CTL_SYN | CTL_ACK /* XXX */);
     
    527530        }
    528531
    529         log_msg(LVL_DEBUG, "SYN ACKed -> Established");
     532        log_msg(LVL_DEBUG, "%s: SYN ACKed -> Established", conn->name);
    530533
    531534        tcp_conn_state_set(conn, st_established);
     
    601604
    602605        if (conn->fin_is_acked) {
    603                 log_msg(LVL_DEBUG, " FIN acked -> Fin-Wait-2");
     606                log_msg(LVL_DEBUG, "%s: FIN acked -> Fin-Wait-2", conn->name);
    604607                tcp_conn_state_set(conn, st_fin_wait_2);
    605608        }
     
    666669
    667670        if (conn->fin_is_acked) {
    668                 log_msg(LVL_DEBUG, " FIN acked -> Closed");
     671                log_msg(LVL_DEBUG, "%s: FIN acked -> Closed", conn->name);
    669672                tcp_conn_remove(conn);
    670673                tcp_conn_state_set(conn, st_closed);
     
    815818                tcp_conn_trim_seg_to_wnd(conn, seg);
    816819        } else {
     820                log_msg(LVL_DEBUG, "%s: Nothing left in segment, dropping "
     821                    "(xfer_size=%zu, SEG.LEN=%zu, seg->ctrl=%u)",
     822                    conn->name, xfer_size, seg->len, (unsigned)seg->ctrl);
    817823                /* Nothing left in segment */
    818824                tcp_segment_delete(seg);
     
    855861                case st_syn_received:
    856862                case st_established:
    857                         log_msg(LVL_DEBUG, "FIN received -> Close-Wait");
     863                        log_msg(LVL_DEBUG, "%s: FIN received -> Close-Wait",
     864                            conn->name);
    858865                        tcp_conn_state_set(conn, st_close_wait);
    859866                        break;
    860867                case st_fin_wait_1:
    861                         log_msg(LVL_DEBUG, "FIN received -> Closing");
     868                        log_msg(LVL_DEBUG, "%s: FIN received -> Closing",
     869                            conn->name);
    862870                        tcp_conn_state_set(conn, st_closing);
    863871                        break;
    864872                case st_fin_wait_2:
    865                         log_msg(LVL_DEBUG, "FIN received -> Time-Wait");
     873                        log_msg(LVL_DEBUG, "%s: FIN received -> Time-Wait",
     874                            conn->name);
    866875                        tcp_conn_state_set(conn, st_time_wait);
    867876                        /* Start the Time-Wait timer */
     
    904913{
    905914        log_msg(LVL_DEBUG, "tcp_conn_seg_process(%p, %p)", conn, seg);
     915        tcp_segment_dump(seg);
    906916
    907917        /* Check whether segment is acceptable */
     
    989999
    9901000        log_msg(LVL_DEBUG, "tw_timeout_func(%p)", conn);
    991         log_msg(LVL_DEBUG, " TW Timeout -> Closed");
     1001        log_msg(LVL_DEBUG, "%s: TW Timeout -> Closed", conn->name);
    9921002
    9931003        tcp_conn_remove(conn);
  • uspace/srv/net/tl/tcp/header.c

    reea65f4 r6896409c  
    3535 */
    3636
     37#include <bitops.h>
    3738#include <byteorder.h>
    3839#include <errno.h>
     
    4142#include "header.h"
    4243#include "segment.h"
     44#include "seq_no.h"
    4345#include "std.h"
    4446#include "tcp_type.h"
     
    7375        ctl = 0;
    7476
    75         if ((doff_flags & DF_URG) != 0)
     77        if ((doff_flags & BIT_V(uint16_t, DF_URG)) != 0)
    7678                ctl |= 0 /* XXX */;
    77         if ((doff_flags & DF_ACK) != 0)
     79        if ((doff_flags & BIT_V(uint16_t, DF_ACK)) != 0)
    7880                ctl |= CTL_ACK;
    79         if ((doff_flags & DF_PSH) != 0)
     81        if ((doff_flags & BIT_V(uint16_t, DF_PSH)) != 0)
    8082                ctl |= 0 /* XXX */;
    81         if ((doff_flags & DF_RST) != 0)
     83        if ((doff_flags & BIT_V(uint16_t, DF_RST)) != 0)
    8284                ctl |= CTL_RST;
    83         if ((doff_flags & DF_SYN) != 0)
     85        if ((doff_flags & BIT_V(uint16_t, DF_SYN)) != 0)
    8486                ctl |= CTL_SYN;
    85         if ((doff_flags & DF_FIN) != 0)
     87        if ((doff_flags & BIT_V(uint16_t, DF_FIN)) != 0)
    8688                ctl |= CTL_FIN;
    8789
     
    9799
    98100        if ((ctl & CTL_ACK) != 0)
    99                 doff_flags |= DF_ACK;
     101                doff_flags |= BIT_V(uint16_t, DF_ACK);
    100102        if ((ctl & CTL_RST) != 0)
    101                 doff_flags |= DF_RST;
     103                doff_flags |= BIT_V(uint16_t, DF_RST);
    102104        if ((ctl & CTL_SYN) != 0)
    103                 doff_flags |= DF_SYN;
     105                doff_flags |= BIT_V(uint16_t, DF_SYN);
    104106        if ((ctl & CTL_FIN) != 0)
    105                 doff_flags |= DF_FIN;
     107                doff_flags |= BIT_V(uint16_t, DF_FIN);
    106108
    107109        *rdoff_flags = doff_flags;
     
    203205
    204206        tcp_header_decode(pdu->header, nseg);
     207        nseg->len += seq_no_control_len(nseg->ctrl);
    205208
    206209        hdr = (tcp_header_t *)pdu->header;
  • uspace/srv/net/tl/tcp/rqueue.c

    reea65f4 r6896409c  
    114114        log_msg(LVL_DEBUG, "tcp_rqueue_insert_seg()");
    115115
     116        tcp_segment_dump(seg);
     117
    116118        rqe = calloc(1, sizeof(tcp_rqueue_entry_t));
    117119        if (rqe == NULL) {
  • uspace/srv/net/tl/tcp/segment.c

    reea65f4 r6896409c  
    3535 */
    3636
     37#include <io/log.h>
    3738#include <mem.h>
    3839#include <stdlib.h>
     
    235236}
    236237
     238/** Dump segment contents to log.
     239 *
     240 * @param seg   Segment
     241 */
     242void tcp_segment_dump(tcp_segment_t *seg)
     243{
     244        log_msg(LVL_DEBUG, "Segment dump:");
     245        log_msg(LVL_DEBUG, " - ctrl = %u", (unsigned)seg->ctrl);
     246        log_msg(LVL_DEBUG, " - seq = % " PRIu32, seg->seq);
     247        log_msg(LVL_DEBUG, " - ack = % " PRIu32, seg->ack);
     248        log_msg(LVL_DEBUG, " - len = % " PRIu32, seg->len);
     249        log_msg(LVL_DEBUG, " - wnd = % " PRIu32, seg->wnd);
     250        log_msg(LVL_DEBUG, " - up = % " PRIu32, seg->up);
     251}
     252
    237253/**
    238254 * @}
  • uspace/srv/net/tl/tcp/segment.h

    reea65f4 r6896409c  
    4848extern void tcp_segment_text_copy(tcp_segment_t *, void *, size_t);
    4949extern size_t tcp_segment_text_size(tcp_segment_t *);
     50extern void tcp_segment_dump(tcp_segment_t *);
     51
    5052
    5153
  • uspace/srv/net/tl/tcp/test.c

    reea65f4 r6896409c  
    6666                tcp_uc_receive(conn, rcv_buf, RCV_BUF_SIZE, &rcvd, &xflags);
    6767                if (rcvd == 0) {
    68                         printf("End of data reached.\n");
     68                        printf("S: End of data reached.\n");
    6969                        break;
    7070                }
  • uspace/srv/net/tl/tcp/tqueue.c

    reea65f4 r6896409c  
    152152        size_t data_size;
    153153        tcp_control_t ctrl;
     154        bool send_fin;
    154155
    155156        tcp_segment_t *seg;
    156157
    157         log_msg(LVL_DEBUG, "tcp_tqueue_new_data()");
     158        log_msg(LVL_DEBUG, "%s: tcp_tqueue_new_data()", conn->name);
    158159
    159160        /* Number of free sequence numbers in send window */
     
    162163
    163164        xfer_seqlen = min(snd_buf_seqlen, avail_wnd);
    164         log_msg(LVL_DEBUG, "snd_buf_seqlen = %zu, SND.WND = %zu, "
    165             "xfer_seqlen = %zu", snd_buf_seqlen, conn->snd_wnd,
     165        log_msg(LVL_DEBUG, "%s: snd_buf_seqlen = %zu, SND.WND = %zu, "
     166            "xfer_seqlen = %zu", conn->name, snd_buf_seqlen, conn->snd_wnd,
    166167            xfer_seqlen);
    167168
     
    171172        /* XXX Do not always send immediately */
    172173
    173         data_size = xfer_seqlen - (conn->snd_buf_fin ? 1 : 0);
    174         if (conn->snd_buf_fin && data_size + 1 == xfer_seqlen) {
     174        send_fin = conn->snd_buf_fin && xfer_seqlen == snd_buf_seqlen;
     175        data_size = xfer_seqlen - (send_fin ? 1 : 0);
     176
     177        if (send_fin) {
     178                log_msg(LVL_DEBUG, "%s: Sending out FIN.", conn->name);
    175179                /* We are sending out FIN */
    176180                ctrl = CTL_FIN;
     
    190194            conn->snd_buf_used - data_size);
    191195        conn->snd_buf_used -= data_size;
    192         conn->snd_buf_fin = false;
     196
     197        if (send_fin)
     198                conn->snd_buf_fin = false;
    193199
    194200        tcp_tqueue_seg(conn, seg);
     
    261267        log_msg(LVL_DEBUG, "SEG.SEQ=%" PRIu32 ", SEG.WND=%" PRIu32,
    262268            seg->seq, seg->wnd);
     269
     270        tcp_segment_dump(seg);
    263271/*
    264272        tcp_pdu_prepare(conn, seg, &data, &len);
Note: See TracChangeset for help on using the changeset viewer.