Some quick code to use UDP-only (no TCP) with mBed. Echos received packets and sends packets when a button is pressed
Core/lwIP/core/tcp_out.c@0:a548a085de55, 2010-03-14 (annotated)
- Committer:
- pehrhovey
- Date:
- Sun Mar 14 00:54:12 2010 +0000
- Revision:
- 0:a548a085de55
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pehrhovey | 0:a548a085de55 | 1 | /** |
pehrhovey | 0:a548a085de55 | 2 | * @file |
pehrhovey | 0:a548a085de55 | 3 | * Transmission Control Protocol, outgoing traffic |
pehrhovey | 0:a548a085de55 | 4 | * |
pehrhovey | 0:a548a085de55 | 5 | * The output functions of TCP. |
pehrhovey | 0:a548a085de55 | 6 | * |
pehrhovey | 0:a548a085de55 | 7 | */ |
pehrhovey | 0:a548a085de55 | 8 | |
pehrhovey | 0:a548a085de55 | 9 | /* |
pehrhovey | 0:a548a085de55 | 10 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. |
pehrhovey | 0:a548a085de55 | 11 | * All rights reserved. |
pehrhovey | 0:a548a085de55 | 12 | * |
pehrhovey | 0:a548a085de55 | 13 | * Redistribution and use in source and binary forms, with or without modification, |
pehrhovey | 0:a548a085de55 | 14 | * are permitted provided that the following conditions are met: |
pehrhovey | 0:a548a085de55 | 15 | * |
pehrhovey | 0:a548a085de55 | 16 | * 1. Redistributions of source code must retain the above copyright notice, |
pehrhovey | 0:a548a085de55 | 17 | * this list of conditions and the following disclaimer. |
pehrhovey | 0:a548a085de55 | 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
pehrhovey | 0:a548a085de55 | 19 | * this list of conditions and the following disclaimer in the documentation |
pehrhovey | 0:a548a085de55 | 20 | * and/or other materials provided with the distribution. |
pehrhovey | 0:a548a085de55 | 21 | * 3. The name of the author may not be used to endorse or promote products |
pehrhovey | 0:a548a085de55 | 22 | * derived from this software without specific prior written permission. |
pehrhovey | 0:a548a085de55 | 23 | * |
pehrhovey | 0:a548a085de55 | 24 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
pehrhovey | 0:a548a085de55 | 25 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
pehrhovey | 0:a548a085de55 | 26 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT |
pehrhovey | 0:a548a085de55 | 27 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
pehrhovey | 0:a548a085de55 | 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
pehrhovey | 0:a548a085de55 | 29 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
pehrhovey | 0:a548a085de55 | 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
pehrhovey | 0:a548a085de55 | 31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
pehrhovey | 0:a548a085de55 | 32 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY |
pehrhovey | 0:a548a085de55 | 33 | * OF SUCH DAMAGE. |
pehrhovey | 0:a548a085de55 | 34 | * |
pehrhovey | 0:a548a085de55 | 35 | * This file is part of the lwIP TCP/IP stack. |
pehrhovey | 0:a548a085de55 | 36 | * |
pehrhovey | 0:a548a085de55 | 37 | * Author: Adam Dunkels <adam@sics.se> |
pehrhovey | 0:a548a085de55 | 38 | * |
pehrhovey | 0:a548a085de55 | 39 | */ |
pehrhovey | 0:a548a085de55 | 40 | |
pehrhovey | 0:a548a085de55 | 41 | #include "lwip/opt.h" |
pehrhovey | 0:a548a085de55 | 42 | |
pehrhovey | 0:a548a085de55 | 43 | #if LWIP_TCP /* don't build if not configured for use in lwipopts.h */ |
pehrhovey | 0:a548a085de55 | 44 | |
pehrhovey | 0:a548a085de55 | 45 | #include "lwip/tcp.h" |
pehrhovey | 0:a548a085de55 | 46 | #include "lwip/def.h" |
pehrhovey | 0:a548a085de55 | 47 | #include "lwip/mem.h" |
pehrhovey | 0:a548a085de55 | 48 | #include "lwip/memp.h" |
pehrhovey | 0:a548a085de55 | 49 | #include "lwip/sys.h" |
pehrhovey | 0:a548a085de55 | 50 | #include "lwip/ip_addr.h" |
pehrhovey | 0:a548a085de55 | 51 | #include "lwip/netif.h" |
pehrhovey | 0:a548a085de55 | 52 | #include "lwip/inet.h" |
pehrhovey | 0:a548a085de55 | 53 | #include "lwip/inet_chksum.h" |
pehrhovey | 0:a548a085de55 | 54 | #include "lwip/stats.h" |
pehrhovey | 0:a548a085de55 | 55 | #include "lwip/snmp.h" |
pehrhovey | 0:a548a085de55 | 56 | |
pehrhovey | 0:a548a085de55 | 57 | #include <string.h> |
pehrhovey | 0:a548a085de55 | 58 | |
pehrhovey | 0:a548a085de55 | 59 | /* Forward declarations.*/ |
pehrhovey | 0:a548a085de55 | 60 | static void tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb); |
pehrhovey | 0:a548a085de55 | 61 | |
pehrhovey | 0:a548a085de55 | 62 | static struct tcp_hdr * |
pehrhovey | 0:a548a085de55 | 63 | tcp_output_set_header(struct tcp_pcb *pcb, struct pbuf *p, int optlen, |
pehrhovey | 0:a548a085de55 | 64 | u32_t seqno_be /* already in network byte order */) |
pehrhovey | 0:a548a085de55 | 65 | { |
pehrhovey | 0:a548a085de55 | 66 | struct tcp_hdr *tcphdr = (struct tcp_hdr *)p->payload; |
pehrhovey | 0:a548a085de55 | 67 | tcphdr->src = htons(pcb->local_port); |
pehrhovey | 0:a548a085de55 | 68 | tcphdr->dest = htons(pcb->remote_port); |
pehrhovey | 0:a548a085de55 | 69 | tcphdr->seqno = seqno_be; |
pehrhovey | 0:a548a085de55 | 70 | tcphdr->ackno = htonl(pcb->rcv_nxt); |
pehrhovey | 0:a548a085de55 | 71 | TCPH_FLAGS_SET(tcphdr, TCP_ACK); |
pehrhovey | 0:a548a085de55 | 72 | tcphdr->wnd = htons(pcb->rcv_ann_wnd); |
pehrhovey | 0:a548a085de55 | 73 | tcphdr->urgp = 0; |
pehrhovey | 0:a548a085de55 | 74 | TCPH_HDRLEN_SET(tcphdr, (5 + optlen / 4)); |
pehrhovey | 0:a548a085de55 | 75 | tcphdr->chksum = 0; |
pehrhovey | 0:a548a085de55 | 76 | |
pehrhovey | 0:a548a085de55 | 77 | /* If we're sending a packet, update the announced right window edge */ |
pehrhovey | 0:a548a085de55 | 78 | pcb->rcv_ann_right_edge = pcb->rcv_nxt + pcb->rcv_ann_wnd; |
pehrhovey | 0:a548a085de55 | 79 | |
pehrhovey | 0:a548a085de55 | 80 | return tcphdr; |
pehrhovey | 0:a548a085de55 | 81 | } |
pehrhovey | 0:a548a085de55 | 82 | |
pehrhovey | 0:a548a085de55 | 83 | /** |
pehrhovey | 0:a548a085de55 | 84 | * Called by tcp_close() to send a segment including flags but not data. |
pehrhovey | 0:a548a085de55 | 85 | * |
pehrhovey | 0:a548a085de55 | 86 | * @param pcb the tcp_pcb over which to send a segment |
pehrhovey | 0:a548a085de55 | 87 | * @param flags the flags to set in the segment header |
pehrhovey | 0:a548a085de55 | 88 | * @return ERR_OK if sent, another err_t otherwise |
pehrhovey | 0:a548a085de55 | 89 | */ |
pehrhovey | 0:a548a085de55 | 90 | err_t |
pehrhovey | 0:a548a085de55 | 91 | tcp_send_ctrl(struct tcp_pcb *pcb, u8_t flags) |
pehrhovey | 0:a548a085de55 | 92 | { |
pehrhovey | 0:a548a085de55 | 93 | /* no data, no length, flags, copy=1, no optdata */ |
pehrhovey | 0:a548a085de55 | 94 | return tcp_enqueue(pcb, NULL, 0, flags, TCP_WRITE_FLAG_COPY, 0); |
pehrhovey | 0:a548a085de55 | 95 | } |
pehrhovey | 0:a548a085de55 | 96 | |
pehrhovey | 0:a548a085de55 | 97 | /** |
pehrhovey | 0:a548a085de55 | 98 | * Write data for sending (but does not send it immediately). |
pehrhovey | 0:a548a085de55 | 99 | * |
pehrhovey | 0:a548a085de55 | 100 | * It waits in the expectation of more data being sent soon (as |
pehrhovey | 0:a548a085de55 | 101 | * it can send them more efficiently by combining them together). |
pehrhovey | 0:a548a085de55 | 102 | * To prompt the system to send data now, call tcp_output() after |
pehrhovey | 0:a548a085de55 | 103 | * calling tcp_write(). |
pehrhovey | 0:a548a085de55 | 104 | * |
pehrhovey | 0:a548a085de55 | 105 | * @param pcb Protocol control block of the TCP connection to enqueue data for. |
pehrhovey | 0:a548a085de55 | 106 | * @param data pointer to the data to send |
pehrhovey | 0:a548a085de55 | 107 | * @param len length (in bytes) of the data to send |
pehrhovey | 0:a548a085de55 | 108 | * @param apiflags combination of following flags : |
pehrhovey | 0:a548a085de55 | 109 | * - TCP_WRITE_FLAG_COPY (0x01) data will be copied into memory belonging to the stack |
pehrhovey | 0:a548a085de55 | 110 | * - TCP_WRITE_FLAG_MORE (0x02) for TCP connection, PSH flag will be set on last segment sent, |
pehrhovey | 0:a548a085de55 | 111 | * @return ERR_OK if enqueued, another err_t on error |
pehrhovey | 0:a548a085de55 | 112 | * |
pehrhovey | 0:a548a085de55 | 113 | * @see tcp_write() |
pehrhovey | 0:a548a085de55 | 114 | */ |
pehrhovey | 0:a548a085de55 | 115 | err_t |
pehrhovey | 0:a548a085de55 | 116 | tcp_write(struct tcp_pcb *pcb, const void *data, u16_t len, u8_t apiflags) |
pehrhovey | 0:a548a085de55 | 117 | { |
pehrhovey | 0:a548a085de55 | 118 | LWIP_DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_write(pcb=%p, data=%p, len=%"U16_F", apiflags=%"U16_F")\n", (void *)pcb, |
pehrhovey | 0:a548a085de55 | 119 | data, len, (u16_t)apiflags)); |
pehrhovey | 0:a548a085de55 | 120 | /* connection is in valid state for data transmission? */ |
pehrhovey | 0:a548a085de55 | 121 | if (pcb->state == ESTABLISHED || |
pehrhovey | 0:a548a085de55 | 122 | pcb->state == CLOSE_WAIT || |
pehrhovey | 0:a548a085de55 | 123 | pcb->state == SYN_SENT || |
pehrhovey | 0:a548a085de55 | 124 | pcb->state == SYN_RCVD) { |
pehrhovey | 0:a548a085de55 | 125 | if (len > 0) { |
pehrhovey | 0:a548a085de55 | 126 | #if LWIP_TCP_TIMESTAMPS |
pehrhovey | 0:a548a085de55 | 127 | return tcp_enqueue(pcb, (void *)data, len, 0, apiflags, |
pehrhovey | 0:a548a085de55 | 128 | pcb->flags & TF_TIMESTAMP ? TF_SEG_OPTS_TS : 0); |
pehrhovey | 0:a548a085de55 | 129 | #else |
pehrhovey | 0:a548a085de55 | 130 | return tcp_enqueue(pcb, (void *)data, len, 0, apiflags, 0); |
pehrhovey | 0:a548a085de55 | 131 | #endif |
pehrhovey | 0:a548a085de55 | 132 | } |
pehrhovey | 0:a548a085de55 | 133 | return ERR_OK; |
pehrhovey | 0:a548a085de55 | 134 | } else { |
pehrhovey | 0:a548a085de55 | 135 | LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_STATE | 3, ("tcp_write() called in invalid state\n")); |
pehrhovey | 0:a548a085de55 | 136 | return ERR_CONN; |
pehrhovey | 0:a548a085de55 | 137 | } |
pehrhovey | 0:a548a085de55 | 138 | } |
pehrhovey | 0:a548a085de55 | 139 | |
pehrhovey | 0:a548a085de55 | 140 | /** |
pehrhovey | 0:a548a085de55 | 141 | * Enqueue data and/or TCP options for transmission |
pehrhovey | 0:a548a085de55 | 142 | * |
pehrhovey | 0:a548a085de55 | 143 | * Called by tcp_connect(), tcp_listen_input(), tcp_send_ctrl() and tcp_write(). |
pehrhovey | 0:a548a085de55 | 144 | * |
pehrhovey | 0:a548a085de55 | 145 | * @param pcb Protocol control block for the TCP connection to enqueue data for. |
pehrhovey | 0:a548a085de55 | 146 | * @param arg Pointer to the data to be enqueued for sending. |
pehrhovey | 0:a548a085de55 | 147 | * @param len Data length in bytes |
pehrhovey | 0:a548a085de55 | 148 | * @param flags tcp header flags to set in the outgoing segment |
pehrhovey | 0:a548a085de55 | 149 | * @param apiflags combination of following flags : |
pehrhovey | 0:a548a085de55 | 150 | * - TCP_WRITE_FLAG_COPY (0x01) data will be copied into memory belonging to the stack |
pehrhovey | 0:a548a085de55 | 151 | * - TCP_WRITE_FLAG_MORE (0x02) for TCP connection, PSH flag will be set on last segment sent, |
pehrhovey | 0:a548a085de55 | 152 | * @param optflags options to include in segment later on (see definition of struct tcp_seg) |
pehrhovey | 0:a548a085de55 | 153 | */ |
pehrhovey | 0:a548a085de55 | 154 | err_t |
pehrhovey | 0:a548a085de55 | 155 | tcp_enqueue(struct tcp_pcb *pcb, void *arg, u16_t len, |
pehrhovey | 0:a548a085de55 | 156 | u8_t flags, u8_t apiflags, u8_t optflags) |
pehrhovey | 0:a548a085de55 | 157 | { |
pehrhovey | 0:a548a085de55 | 158 | struct pbuf *p; |
pehrhovey | 0:a548a085de55 | 159 | struct tcp_seg *seg, *useg, *queue; |
pehrhovey | 0:a548a085de55 | 160 | u32_t seqno; |
pehrhovey | 0:a548a085de55 | 161 | u16_t left, seglen; |
pehrhovey | 0:a548a085de55 | 162 | void *ptr; |
pehrhovey | 0:a548a085de55 | 163 | u16_t queuelen; |
pehrhovey | 0:a548a085de55 | 164 | u8_t optlen; |
pehrhovey | 0:a548a085de55 | 165 | |
pehrhovey | 0:a548a085de55 | 166 | LWIP_DEBUGF(TCP_OUTPUT_DEBUG, |
pehrhovey | 0:a548a085de55 | 167 | ("tcp_enqueue(pcb=%p, arg=%p, len=%"U16_F", flags=%"X16_F", apiflags=%"U16_F")\n", |
pehrhovey | 0:a548a085de55 | 168 | (void *)pcb, arg, len, (u16_t)flags, (u16_t)apiflags)); |
pehrhovey | 0:a548a085de55 | 169 | LWIP_ERROR("tcp_enqueue: packet needs payload, options, or SYN/FIN (programmer violates API)", |
pehrhovey | 0:a548a085de55 | 170 | ((len != 0) || (optflags != 0) || ((flags & (TCP_SYN | TCP_FIN)) != 0)), |
pehrhovey | 0:a548a085de55 | 171 | return ERR_ARG;); |
pehrhovey | 0:a548a085de55 | 172 | LWIP_ERROR("tcp_enqueue: len != 0 || arg == NULL (programmer violates API)", |
pehrhovey | 0:a548a085de55 | 173 | ((len != 0) || (arg == NULL)), return ERR_ARG;); |
pehrhovey | 0:a548a085de55 | 174 | |
pehrhovey | 0:a548a085de55 | 175 | /* fail on too much data */ |
pehrhovey | 0:a548a085de55 | 176 | if (len > pcb->snd_buf) { |
pehrhovey | 0:a548a085de55 | 177 | LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 3, ("tcp_enqueue: too much data (len=%"U16_F" > snd_buf=%"U16_F")\n", len, pcb->snd_buf)); |
pehrhovey | 0:a548a085de55 | 178 | pcb->flags |= TF_NAGLEMEMERR; |
pehrhovey | 0:a548a085de55 | 179 | return ERR_MEM; |
pehrhovey | 0:a548a085de55 | 180 | } |
pehrhovey | 0:a548a085de55 | 181 | left = len; |
pehrhovey | 0:a548a085de55 | 182 | ptr = arg; |
pehrhovey | 0:a548a085de55 | 183 | |
pehrhovey | 0:a548a085de55 | 184 | optlen = LWIP_TCP_OPT_LENGTH(optflags); |
pehrhovey | 0:a548a085de55 | 185 | |
pehrhovey | 0:a548a085de55 | 186 | /* seqno will be the sequence number of the first segment enqueued |
pehrhovey | 0:a548a085de55 | 187 | * by the call to this function. */ |
pehrhovey | 0:a548a085de55 | 188 | seqno = pcb->snd_lbb; |
pehrhovey | 0:a548a085de55 | 189 | |
pehrhovey | 0:a548a085de55 | 190 | LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_enqueue: queuelen: %"U16_F"\n", (u16_t)pcb->snd_queuelen)); |
pehrhovey | 0:a548a085de55 | 191 | |
pehrhovey | 0:a548a085de55 | 192 | /* If total number of pbufs on the unsent/unacked queues exceeds the |
pehrhovey | 0:a548a085de55 | 193 | * configured maximum, return an error */ |
pehrhovey | 0:a548a085de55 | 194 | queuelen = pcb->snd_queuelen; |
pehrhovey | 0:a548a085de55 | 195 | /* check for configured max queuelen and possible overflow */ |
pehrhovey | 0:a548a085de55 | 196 | if ((queuelen >= TCP_SND_QUEUELEN) || (queuelen > TCP_SNDQUEUELEN_OVERFLOW)) { |
pehrhovey | 0:a548a085de55 | 197 | LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 3, ("tcp_enqueue: too long queue %"U16_F" (max %"U16_F")\n", queuelen, TCP_SND_QUEUELEN)); |
pehrhovey | 0:a548a085de55 | 198 | TCP_STATS_INC(tcp.memerr); |
pehrhovey | 0:a548a085de55 | 199 | pcb->flags |= TF_NAGLEMEMERR; |
pehrhovey | 0:a548a085de55 | 200 | return ERR_MEM; |
pehrhovey | 0:a548a085de55 | 201 | } |
pehrhovey | 0:a548a085de55 | 202 | if (queuelen != 0) { |
pehrhovey | 0:a548a085de55 | 203 | LWIP_ASSERT("tcp_enqueue: pbufs on queue => at least one queue non-empty", |
pehrhovey | 0:a548a085de55 | 204 | pcb->unacked != NULL || pcb->unsent != NULL); |
pehrhovey | 0:a548a085de55 | 205 | } else { |
pehrhovey | 0:a548a085de55 | 206 | LWIP_ASSERT("tcp_enqueue: no pbufs on queue => both queues empty", |
pehrhovey | 0:a548a085de55 | 207 | pcb->unacked == NULL && pcb->unsent == NULL); |
pehrhovey | 0:a548a085de55 | 208 | } |
pehrhovey | 0:a548a085de55 | 209 | |
pehrhovey | 0:a548a085de55 | 210 | /* First, break up the data into segments and tuck them together in |
pehrhovey | 0:a548a085de55 | 211 | * the local "queue" variable. */ |
pehrhovey | 0:a548a085de55 | 212 | useg = queue = seg = NULL; |
pehrhovey | 0:a548a085de55 | 213 | seglen = 0; |
pehrhovey | 0:a548a085de55 | 214 | while (queue == NULL || left > 0) { |
pehrhovey | 0:a548a085de55 | 215 | /* The segment length (including options) should be at most the MSS */ |
pehrhovey | 0:a548a085de55 | 216 | seglen = left > (pcb->mss - optlen) ? (pcb->mss - optlen) : left; |
pehrhovey | 0:a548a085de55 | 217 | |
pehrhovey | 0:a548a085de55 | 218 | /* Allocate memory for tcp_seg, and fill in fields. */ |
pehrhovey | 0:a548a085de55 | 219 | seg = (struct tcp_seg *)memp_malloc(MEMP_TCP_SEG); |
pehrhovey | 0:a548a085de55 | 220 | if (seg == NULL) { |
pehrhovey | 0:a548a085de55 | 221 | LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 2, |
pehrhovey | 0:a548a085de55 | 222 | ("tcp_enqueue: could not allocate memory for tcp_seg\n")); |
pehrhovey | 0:a548a085de55 | 223 | goto memerr; |
pehrhovey | 0:a548a085de55 | 224 | } |
pehrhovey | 0:a548a085de55 | 225 | seg->next = NULL; |
pehrhovey | 0:a548a085de55 | 226 | seg->p = NULL; |
pehrhovey | 0:a548a085de55 | 227 | |
pehrhovey | 0:a548a085de55 | 228 | /* first segment of to-be-queued data? */ |
pehrhovey | 0:a548a085de55 | 229 | if (queue == NULL) { |
pehrhovey | 0:a548a085de55 | 230 | queue = seg; |
pehrhovey | 0:a548a085de55 | 231 | } |
pehrhovey | 0:a548a085de55 | 232 | /* subsequent segments of to-be-queued data */ |
pehrhovey | 0:a548a085de55 | 233 | else { |
pehrhovey | 0:a548a085de55 | 234 | /* Attach the segment to the end of the queued segments */ |
pehrhovey | 0:a548a085de55 | 235 | LWIP_ASSERT("useg != NULL", useg != NULL); |
pehrhovey | 0:a548a085de55 | 236 | useg->next = seg; |
pehrhovey | 0:a548a085de55 | 237 | } |
pehrhovey | 0:a548a085de55 | 238 | /* remember last segment of to-be-queued data for next iteration */ |
pehrhovey | 0:a548a085de55 | 239 | useg = seg; |
pehrhovey | 0:a548a085de55 | 240 | |
pehrhovey | 0:a548a085de55 | 241 | /* If copy is set, memory should be allocated |
pehrhovey | 0:a548a085de55 | 242 | * and data copied into pbuf, otherwise data comes from |
pehrhovey | 0:a548a085de55 | 243 | * ROM or other static memory, and need not be copied. */ |
pehrhovey | 0:a548a085de55 | 244 | if (apiflags & TCP_WRITE_FLAG_COPY) { |
pehrhovey | 0:a548a085de55 | 245 | if ((seg->p = pbuf_alloc(PBUF_TRANSPORT, seglen + optlen, PBUF_RAM)) == NULL) { |
pehrhovey | 0:a548a085de55 | 246 | LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 2, |
pehrhovey | 0:a548a085de55 | 247 | ("tcp_enqueue : could not allocate memory for pbuf copy size %"U16_F"\n", seglen)); |
pehrhovey | 0:a548a085de55 | 248 | goto memerr; |
pehrhovey | 0:a548a085de55 | 249 | } |
pehrhovey | 0:a548a085de55 | 250 | LWIP_ASSERT("check that first pbuf can hold the complete seglen", |
pehrhovey | 0:a548a085de55 | 251 | (seg->p->len >= seglen + optlen)); |
pehrhovey | 0:a548a085de55 | 252 | queuelen += pbuf_clen(seg->p); |
pehrhovey | 0:a548a085de55 | 253 | if (arg != NULL) { |
pehrhovey | 0:a548a085de55 | 254 | MEMCPY((char *)seg->p->payload + optlen, ptr, seglen); |
pehrhovey | 0:a548a085de55 | 255 | } |
pehrhovey | 0:a548a085de55 | 256 | seg->dataptr = seg->p->payload; |
pehrhovey | 0:a548a085de55 | 257 | } |
pehrhovey | 0:a548a085de55 | 258 | /* do not copy data */ |
pehrhovey | 0:a548a085de55 | 259 | else { |
pehrhovey | 0:a548a085de55 | 260 | /* First, allocate a pbuf for the headers. */ |
pehrhovey | 0:a548a085de55 | 261 | if ((seg->p = pbuf_alloc(PBUF_TRANSPORT, optlen, PBUF_RAM)) == NULL) { |
pehrhovey | 0:a548a085de55 | 262 | LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 2, |
pehrhovey | 0:a548a085de55 | 263 | ("tcp_enqueue: could not allocate memory for header pbuf\n")); |
pehrhovey | 0:a548a085de55 | 264 | goto memerr; |
pehrhovey | 0:a548a085de55 | 265 | } |
pehrhovey | 0:a548a085de55 | 266 | queuelen += pbuf_clen(seg->p); |
pehrhovey | 0:a548a085de55 | 267 | |
pehrhovey | 0:a548a085de55 | 268 | /* Second, allocate a pbuf for holding the data. |
pehrhovey | 0:a548a085de55 | 269 | * since the referenced data is available at least until it is sent out on the |
pehrhovey | 0:a548a085de55 | 270 | * link (as it has to be ACKed by the remote party) we can safely use PBUF_ROM |
pehrhovey | 0:a548a085de55 | 271 | * instead of PBUF_REF here. |
pehrhovey | 0:a548a085de55 | 272 | */ |
pehrhovey | 0:a548a085de55 | 273 | if (left > 0) { |
pehrhovey | 0:a548a085de55 | 274 | if ((p = pbuf_alloc(PBUF_RAW, seglen, PBUF_ROM)) == NULL) { |
pehrhovey | 0:a548a085de55 | 275 | /* If allocation fails, we have to deallocate the header pbuf as well. */ |
pehrhovey | 0:a548a085de55 | 276 | pbuf_free(seg->p); |
pehrhovey | 0:a548a085de55 | 277 | seg->p = NULL; |
pehrhovey | 0:a548a085de55 | 278 | LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 2, |
pehrhovey | 0:a548a085de55 | 279 | ("tcp_enqueue: could not allocate memory for zero-copy pbuf\n")); |
pehrhovey | 0:a548a085de55 | 280 | goto memerr; |
pehrhovey | 0:a548a085de55 | 281 | } |
pehrhovey | 0:a548a085de55 | 282 | ++queuelen; |
pehrhovey | 0:a548a085de55 | 283 | /* reference the non-volatile payload data */ |
pehrhovey | 0:a548a085de55 | 284 | p->payload = ptr; |
pehrhovey | 0:a548a085de55 | 285 | seg->dataptr = ptr; |
pehrhovey | 0:a548a085de55 | 286 | |
pehrhovey | 0:a548a085de55 | 287 | /* Concatenate the headers and data pbufs together. */ |
pehrhovey | 0:a548a085de55 | 288 | pbuf_cat(seg->p/*header*/, p/*data*/); |
pehrhovey | 0:a548a085de55 | 289 | p = NULL; |
pehrhovey | 0:a548a085de55 | 290 | } |
pehrhovey | 0:a548a085de55 | 291 | } |
pehrhovey | 0:a548a085de55 | 292 | |
pehrhovey | 0:a548a085de55 | 293 | /* Now that there are more segments queued, we check again if the |
pehrhovey | 0:a548a085de55 | 294 | length of the queue exceeds the configured maximum or overflows. */ |
pehrhovey | 0:a548a085de55 | 295 | if ((queuelen > TCP_SND_QUEUELEN) || (queuelen > TCP_SNDQUEUELEN_OVERFLOW)) { |
pehrhovey | 0:a548a085de55 | 296 | LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_enqueue: queue too long %"U16_F" (%"U16_F")\n", queuelen, TCP_SND_QUEUELEN)); |
pehrhovey | 0:a548a085de55 | 297 | goto memerr; |
pehrhovey | 0:a548a085de55 | 298 | } |
pehrhovey | 0:a548a085de55 | 299 | |
pehrhovey | 0:a548a085de55 | 300 | seg->len = seglen; |
pehrhovey | 0:a548a085de55 | 301 | |
pehrhovey | 0:a548a085de55 | 302 | /* build TCP header */ |
pehrhovey | 0:a548a085de55 | 303 | if (pbuf_header(seg->p, TCP_HLEN)) { |
pehrhovey | 0:a548a085de55 | 304 | LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_enqueue: no room for TCP header in pbuf.\n")); |
pehrhovey | 0:a548a085de55 | 305 | TCP_STATS_INC(tcp.err); |
pehrhovey | 0:a548a085de55 | 306 | goto memerr; |
pehrhovey | 0:a548a085de55 | 307 | } |
pehrhovey | 0:a548a085de55 | 308 | seg->tcphdr = (struct tcp_hdr *)seg->p->payload; |
pehrhovey | 0:a548a085de55 | 309 | seg->tcphdr->src = htons(pcb->local_port); |
pehrhovey | 0:a548a085de55 | 310 | seg->tcphdr->dest = htons(pcb->remote_port); |
pehrhovey | 0:a548a085de55 | 311 | seg->tcphdr->seqno = htonl(seqno); |
pehrhovey | 0:a548a085de55 | 312 | seg->tcphdr->urgp = 0; |
pehrhovey | 0:a548a085de55 | 313 | TCPH_FLAGS_SET(seg->tcphdr, flags); |
pehrhovey | 0:a548a085de55 | 314 | /* don't fill in tcphdr->ackno and tcphdr->wnd until later */ |
pehrhovey | 0:a548a085de55 | 315 | |
pehrhovey | 0:a548a085de55 | 316 | seg->flags = optflags; |
pehrhovey | 0:a548a085de55 | 317 | |
pehrhovey | 0:a548a085de55 | 318 | /* Set the length of the header */ |
pehrhovey | 0:a548a085de55 | 319 | TCPH_HDRLEN_SET(seg->tcphdr, (5 + optlen / 4)); |
pehrhovey | 0:a548a085de55 | 320 | LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_TRACE, ("tcp_enqueue: queueing %"U32_F":%"U32_F" (0x%"X16_F")\n", |
pehrhovey | 0:a548a085de55 | 321 | ntohl(seg->tcphdr->seqno), |
pehrhovey | 0:a548a085de55 | 322 | ntohl(seg->tcphdr->seqno) + TCP_TCPLEN(seg), |
pehrhovey | 0:a548a085de55 | 323 | (u16_t)flags)); |
pehrhovey | 0:a548a085de55 | 324 | |
pehrhovey | 0:a548a085de55 | 325 | left -= seglen; |
pehrhovey | 0:a548a085de55 | 326 | seqno += seglen; |
pehrhovey | 0:a548a085de55 | 327 | ptr = (void *)((u8_t *)ptr + seglen); |
pehrhovey | 0:a548a085de55 | 328 | } |
pehrhovey | 0:a548a085de55 | 329 | |
pehrhovey | 0:a548a085de55 | 330 | /* Now that the data to be enqueued has been broken up into TCP |
pehrhovey | 0:a548a085de55 | 331 | segments in the queue variable, we add them to the end of the |
pehrhovey | 0:a548a085de55 | 332 | pcb->unsent queue. */ |
pehrhovey | 0:a548a085de55 | 333 | if (pcb->unsent == NULL) { |
pehrhovey | 0:a548a085de55 | 334 | useg = NULL; |
pehrhovey | 0:a548a085de55 | 335 | } |
pehrhovey | 0:a548a085de55 | 336 | else { |
pehrhovey | 0:a548a085de55 | 337 | for (useg = pcb->unsent; useg->next != NULL; useg = useg->next); |
pehrhovey | 0:a548a085de55 | 338 | } |
pehrhovey | 0:a548a085de55 | 339 | /* { useg is last segment on the unsent queue, NULL if list is empty } */ |
pehrhovey | 0:a548a085de55 | 340 | |
pehrhovey | 0:a548a085de55 | 341 | /* If there is room in the last pbuf on the unsent queue, |
pehrhovey | 0:a548a085de55 | 342 | chain the first pbuf on the queue together with that. */ |
pehrhovey | 0:a548a085de55 | 343 | if (useg != NULL && |
pehrhovey | 0:a548a085de55 | 344 | TCP_TCPLEN(useg) != 0 && |
pehrhovey | 0:a548a085de55 | 345 | !(TCPH_FLAGS(useg->tcphdr) & (TCP_SYN | TCP_FIN)) && |
pehrhovey | 0:a548a085de55 | 346 | !(flags & (TCP_SYN | TCP_FIN)) && |
pehrhovey | 0:a548a085de55 | 347 | /* fit within max seg size */ |
pehrhovey | 0:a548a085de55 | 348 | (useg->len + queue->len <= pcb->mss) && |
pehrhovey | 0:a548a085de55 | 349 | /* only concatenate segments with the same options */ |
pehrhovey | 0:a548a085de55 | 350 | (useg->flags == queue->flags) && |
pehrhovey | 0:a548a085de55 | 351 | /* segments are consecutive */ |
pehrhovey | 0:a548a085de55 | 352 | (ntohl(useg->tcphdr->seqno) + useg->len == ntohl(queue->tcphdr->seqno)) ) { |
pehrhovey | 0:a548a085de55 | 353 | /* Remove TCP header from first segment of our to-be-queued list */ |
pehrhovey | 0:a548a085de55 | 354 | if(pbuf_header(queue->p, -(TCP_HLEN + optlen))) { |
pehrhovey | 0:a548a085de55 | 355 | /* Can we cope with this failing? Just assert for now */ |
pehrhovey | 0:a548a085de55 | 356 | LWIP_ASSERT("pbuf_header failed\n", 0); |
pehrhovey | 0:a548a085de55 | 357 | TCP_STATS_INC(tcp.err); |
pehrhovey | 0:a548a085de55 | 358 | goto memerr; |
pehrhovey | 0:a548a085de55 | 359 | } |
pehrhovey | 0:a548a085de55 | 360 | if (queue->p->len == 0) { |
pehrhovey | 0:a548a085de55 | 361 | /* free the first (header-only) pbuf if it is now empty (contained only headers) */ |
pehrhovey | 0:a548a085de55 | 362 | struct pbuf *old_q = queue->p; |
pehrhovey | 0:a548a085de55 | 363 | queue->p = queue->p->next; |
pehrhovey | 0:a548a085de55 | 364 | old_q->next = NULL; |
pehrhovey | 0:a548a085de55 | 365 | queuelen--; |
pehrhovey | 0:a548a085de55 | 366 | pbuf_free(old_q); |
pehrhovey | 0:a548a085de55 | 367 | } |
pehrhovey | 0:a548a085de55 | 368 | LWIP_ASSERT("zero-length pbuf", (queue->p != NULL) && (queue->p->len > 0)); |
pehrhovey | 0:a548a085de55 | 369 | pbuf_cat(useg->p, queue->p); |
pehrhovey | 0:a548a085de55 | 370 | useg->len += queue->len; |
pehrhovey | 0:a548a085de55 | 371 | useg->next = queue->next; |
pehrhovey | 0:a548a085de55 | 372 | |
pehrhovey | 0:a548a085de55 | 373 | LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("tcp_enqueue: chaining segments, new len %"U16_F"\n", useg->len)); |
pehrhovey | 0:a548a085de55 | 374 | if (seg == queue) { |
pehrhovey | 0:a548a085de55 | 375 | seg = useg; |
pehrhovey | 0:a548a085de55 | 376 | seglen = useg->len; |
pehrhovey | 0:a548a085de55 | 377 | } |
pehrhovey | 0:a548a085de55 | 378 | memp_free(MEMP_TCP_SEG, queue); |
pehrhovey | 0:a548a085de55 | 379 | } |
pehrhovey | 0:a548a085de55 | 380 | else { |
pehrhovey | 0:a548a085de55 | 381 | /* empty list */ |
pehrhovey | 0:a548a085de55 | 382 | if (useg == NULL) { |
pehrhovey | 0:a548a085de55 | 383 | /* initialize list with this segment */ |
pehrhovey | 0:a548a085de55 | 384 | pcb->unsent = queue; |
pehrhovey | 0:a548a085de55 | 385 | } |
pehrhovey | 0:a548a085de55 | 386 | /* enqueue segment */ |
pehrhovey | 0:a548a085de55 | 387 | else { |
pehrhovey | 0:a548a085de55 | 388 | useg->next = queue; |
pehrhovey | 0:a548a085de55 | 389 | } |
pehrhovey | 0:a548a085de55 | 390 | } |
pehrhovey | 0:a548a085de55 | 391 | if ((flags & TCP_SYN) || (flags & TCP_FIN)) { |
pehrhovey | 0:a548a085de55 | 392 | ++len; |
pehrhovey | 0:a548a085de55 | 393 | } |
pehrhovey | 0:a548a085de55 | 394 | if (flags & TCP_FIN) { |
pehrhovey | 0:a548a085de55 | 395 | pcb->flags |= TF_FIN; |
pehrhovey | 0:a548a085de55 | 396 | } |
pehrhovey | 0:a548a085de55 | 397 | pcb->snd_lbb += len; |
pehrhovey | 0:a548a085de55 | 398 | |
pehrhovey | 0:a548a085de55 | 399 | pcb->snd_buf -= len; |
pehrhovey | 0:a548a085de55 | 400 | |
pehrhovey | 0:a548a085de55 | 401 | /* update number of segments on the queues */ |
pehrhovey | 0:a548a085de55 | 402 | pcb->snd_queuelen = queuelen; |
pehrhovey | 0:a548a085de55 | 403 | LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_enqueue: %"S16_F" (after enqueued)\n", pcb->snd_queuelen)); |
pehrhovey | 0:a548a085de55 | 404 | if (pcb->snd_queuelen != 0) { |
pehrhovey | 0:a548a085de55 | 405 | LWIP_ASSERT("tcp_enqueue: valid queue length", |
pehrhovey | 0:a548a085de55 | 406 | pcb->unacked != NULL || pcb->unsent != NULL); |
pehrhovey | 0:a548a085de55 | 407 | } |
pehrhovey | 0:a548a085de55 | 408 | |
pehrhovey | 0:a548a085de55 | 409 | /* Set the PSH flag in the last segment that we enqueued, but only |
pehrhovey | 0:a548a085de55 | 410 | if the segment has data (indicated by seglen > 0). */ |
pehrhovey | 0:a548a085de55 | 411 | if (seg != NULL && seglen > 0 && seg->tcphdr != NULL && ((apiflags & TCP_WRITE_FLAG_MORE)==0)) { |
pehrhovey | 0:a548a085de55 | 412 | TCPH_SET_FLAG(seg->tcphdr, TCP_PSH); |
pehrhovey | 0:a548a085de55 | 413 | } |
pehrhovey | 0:a548a085de55 | 414 | |
pehrhovey | 0:a548a085de55 | 415 | return ERR_OK; |
pehrhovey | 0:a548a085de55 | 416 | memerr: |
pehrhovey | 0:a548a085de55 | 417 | pcb->flags |= TF_NAGLEMEMERR; |
pehrhovey | 0:a548a085de55 | 418 | TCP_STATS_INC(tcp.memerr); |
pehrhovey | 0:a548a085de55 | 419 | |
pehrhovey | 0:a548a085de55 | 420 | if (queue != NULL) { |
pehrhovey | 0:a548a085de55 | 421 | tcp_segs_free(queue); |
pehrhovey | 0:a548a085de55 | 422 | } |
pehrhovey | 0:a548a085de55 | 423 | if (pcb->snd_queuelen != 0) { |
pehrhovey | 0:a548a085de55 | 424 | LWIP_ASSERT("tcp_enqueue: valid queue length", pcb->unacked != NULL || |
pehrhovey | 0:a548a085de55 | 425 | pcb->unsent != NULL); |
pehrhovey | 0:a548a085de55 | 426 | } |
pehrhovey | 0:a548a085de55 | 427 | LWIP_DEBUGF(TCP_QLEN_DEBUG | LWIP_DBG_STATE, ("tcp_enqueue: %"S16_F" (with mem err)\n", pcb->snd_queuelen)); |
pehrhovey | 0:a548a085de55 | 428 | return ERR_MEM; |
pehrhovey | 0:a548a085de55 | 429 | } |
pehrhovey | 0:a548a085de55 | 430 | |
pehrhovey | 0:a548a085de55 | 431 | |
pehrhovey | 0:a548a085de55 | 432 | #if LWIP_TCP_TIMESTAMPS |
pehrhovey | 0:a548a085de55 | 433 | /* Build a timestamp option (12 bytes long) at the specified options pointer) |
pehrhovey | 0:a548a085de55 | 434 | * |
pehrhovey | 0:a548a085de55 | 435 | * @param pcb tcp_pcb |
pehrhovey | 0:a548a085de55 | 436 | * @param opts option pointer where to store the timestamp option |
pehrhovey | 0:a548a085de55 | 437 | */ |
pehrhovey | 0:a548a085de55 | 438 | static void |
pehrhovey | 0:a548a085de55 | 439 | tcp_build_timestamp_option(struct tcp_pcb *pcb, u32_t *opts) |
pehrhovey | 0:a548a085de55 | 440 | { |
pehrhovey | 0:a548a085de55 | 441 | /* Pad with two NOP options to make everything nicely aligned */ |
pehrhovey | 0:a548a085de55 | 442 | opts[0] = htonl(0x0101080A); |
pehrhovey | 0:a548a085de55 | 443 | opts[1] = htonl(sys_now()); |
pehrhovey | 0:a548a085de55 | 444 | opts[2] = htonl(pcb->ts_recent); |
pehrhovey | 0:a548a085de55 | 445 | } |
pehrhovey | 0:a548a085de55 | 446 | #endif |
pehrhovey | 0:a548a085de55 | 447 | |
pehrhovey | 0:a548a085de55 | 448 | |
pehrhovey | 0:a548a085de55 | 449 | /** |
pehrhovey | 0:a548a085de55 | 450 | * Find out what we can send and send it |
pehrhovey | 0:a548a085de55 | 451 | * |
pehrhovey | 0:a548a085de55 | 452 | * @param pcb Protocol control block for the TCP connection to send data |
pehrhovey | 0:a548a085de55 | 453 | * @return ERR_OK if data has been sent or nothing to send |
pehrhovey | 0:a548a085de55 | 454 | * another err_t on error |
pehrhovey | 0:a548a085de55 | 455 | */ |
pehrhovey | 0:a548a085de55 | 456 | err_t |
pehrhovey | 0:a548a085de55 | 457 | tcp_output(struct tcp_pcb *pcb) |
pehrhovey | 0:a548a085de55 | 458 | { |
pehrhovey | 0:a548a085de55 | 459 | struct pbuf *p; |
pehrhovey | 0:a548a085de55 | 460 | struct tcp_hdr *tcphdr; |
pehrhovey | 0:a548a085de55 | 461 | struct tcp_seg *seg, *useg; |
pehrhovey | 0:a548a085de55 | 462 | u32_t wnd, snd_nxt; |
pehrhovey | 0:a548a085de55 | 463 | #if TCP_CWND_DEBUG |
pehrhovey | 0:a548a085de55 | 464 | s16_t i = 0; |
pehrhovey | 0:a548a085de55 | 465 | #endif /* TCP_CWND_DEBUG */ |
pehrhovey | 0:a548a085de55 | 466 | u8_t optlen = 0; |
pehrhovey | 0:a548a085de55 | 467 | |
pehrhovey | 0:a548a085de55 | 468 | /* First, check if we are invoked by the TCP input processing |
pehrhovey | 0:a548a085de55 | 469 | code. If so, we do not output anything. Instead, we rely on the |
pehrhovey | 0:a548a085de55 | 470 | input processing code to call us when input processing is done |
pehrhovey | 0:a548a085de55 | 471 | with. */ |
pehrhovey | 0:a548a085de55 | 472 | if (tcp_input_pcb == pcb) { |
pehrhovey | 0:a548a085de55 | 473 | return ERR_OK; |
pehrhovey | 0:a548a085de55 | 474 | } |
pehrhovey | 0:a548a085de55 | 475 | |
pehrhovey | 0:a548a085de55 | 476 | wnd = LWIP_MIN(pcb->snd_wnd, pcb->cwnd); |
pehrhovey | 0:a548a085de55 | 477 | |
pehrhovey | 0:a548a085de55 | 478 | seg = pcb->unsent; |
pehrhovey | 0:a548a085de55 | 479 | |
pehrhovey | 0:a548a085de55 | 480 | /* useg should point to last segment on unacked queue */ |
pehrhovey | 0:a548a085de55 | 481 | useg = pcb->unacked; |
pehrhovey | 0:a548a085de55 | 482 | if (useg != NULL) { |
pehrhovey | 0:a548a085de55 | 483 | for (; useg->next != NULL; useg = useg->next); |
pehrhovey | 0:a548a085de55 | 484 | } |
pehrhovey | 0:a548a085de55 | 485 | |
pehrhovey | 0:a548a085de55 | 486 | /* If the TF_ACK_NOW flag is set and no data will be sent (either |
pehrhovey | 0:a548a085de55 | 487 | * because the ->unsent queue is empty or because the window does |
pehrhovey | 0:a548a085de55 | 488 | * not allow it), construct an empty ACK segment and send it. |
pehrhovey | 0:a548a085de55 | 489 | * |
pehrhovey | 0:a548a085de55 | 490 | * If data is to be sent, we will just piggyback the ACK (see below). |
pehrhovey | 0:a548a085de55 | 491 | */ |
pehrhovey | 0:a548a085de55 | 492 | if (pcb->flags & TF_ACK_NOW && |
pehrhovey | 0:a548a085de55 | 493 | (seg == NULL || |
pehrhovey | 0:a548a085de55 | 494 | ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len > wnd)) { |
pehrhovey | 0:a548a085de55 | 495 | #if LWIP_TCP_TIMESTAMPS |
pehrhovey | 0:a548a085de55 | 496 | if (pcb->flags & TF_TIMESTAMP) |
pehrhovey | 0:a548a085de55 | 497 | optlen = LWIP_TCP_OPT_LENGTH(TF_SEG_OPTS_TS); |
pehrhovey | 0:a548a085de55 | 498 | #endif |
pehrhovey | 0:a548a085de55 | 499 | p = pbuf_alloc(PBUF_IP, TCP_HLEN + optlen, PBUF_RAM); |
pehrhovey | 0:a548a085de55 | 500 | if (p == NULL) { |
pehrhovey | 0:a548a085de55 | 501 | LWIP_DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_output: (ACK) could not allocate pbuf\n")); |
pehrhovey | 0:a548a085de55 | 502 | return ERR_BUF; |
pehrhovey | 0:a548a085de55 | 503 | } |
pehrhovey | 0:a548a085de55 | 504 | LWIP_DEBUGF(TCP_OUTPUT_DEBUG, |
pehrhovey | 0:a548a085de55 | 505 | ("tcp_output: sending ACK for %"U32_F"\n", pcb->rcv_nxt)); |
pehrhovey | 0:a548a085de55 | 506 | /* remove ACK flags from the PCB, as we send an empty ACK now */ |
pehrhovey | 0:a548a085de55 | 507 | pcb->flags &= ~(TF_ACK_DELAY | TF_ACK_NOW); |
pehrhovey | 0:a548a085de55 | 508 | |
pehrhovey | 0:a548a085de55 | 509 | tcphdr = tcp_output_set_header(pcb, p, optlen, htonl(pcb->snd_nxt)); |
pehrhovey | 0:a548a085de55 | 510 | |
pehrhovey | 0:a548a085de55 | 511 | /* NB. MSS option is only sent on SYNs, so ignore it here */ |
pehrhovey | 0:a548a085de55 | 512 | #if LWIP_TCP_TIMESTAMPS |
pehrhovey | 0:a548a085de55 | 513 | pcb->ts_lastacksent = pcb->rcv_nxt; |
pehrhovey | 0:a548a085de55 | 514 | |
pehrhovey | 0:a548a085de55 | 515 | if (pcb->flags & TF_TIMESTAMP) |
pehrhovey | 0:a548a085de55 | 516 | tcp_build_timestamp_option(pcb, (u32_t *)(tcphdr + 1)); |
pehrhovey | 0:a548a085de55 | 517 | #endif |
pehrhovey | 0:a548a085de55 | 518 | |
pehrhovey | 0:a548a085de55 | 519 | #if CHECKSUM_GEN_TCP |
pehrhovey | 0:a548a085de55 | 520 | tcphdr->chksum = inet_chksum_pseudo(p, &(pcb->local_ip), &(pcb->remote_ip), |
pehrhovey | 0:a548a085de55 | 521 | IP_PROTO_TCP, p->tot_len); |
pehrhovey | 0:a548a085de55 | 522 | #endif |
pehrhovey | 0:a548a085de55 | 523 | #if LWIP_NETIF_HWADDRHINT |
pehrhovey | 0:a548a085de55 | 524 | ip_output_hinted(p, &(pcb->local_ip), &(pcb->remote_ip), pcb->ttl, pcb->tos, |
pehrhovey | 0:a548a085de55 | 525 | IP_PROTO_TCP, &(pcb->addr_hint)); |
pehrhovey | 0:a548a085de55 | 526 | #else /* LWIP_NETIF_HWADDRHINT*/ |
pehrhovey | 0:a548a085de55 | 527 | ip_output(p, &(pcb->local_ip), &(pcb->remote_ip), pcb->ttl, pcb->tos, |
pehrhovey | 0:a548a085de55 | 528 | IP_PROTO_TCP); |
pehrhovey | 0:a548a085de55 | 529 | #endif /* LWIP_NETIF_HWADDRHINT*/ |
pehrhovey | 0:a548a085de55 | 530 | pbuf_free(p); |
pehrhovey | 0:a548a085de55 | 531 | |
pehrhovey | 0:a548a085de55 | 532 | return ERR_OK; |
pehrhovey | 0:a548a085de55 | 533 | } |
pehrhovey | 0:a548a085de55 | 534 | |
pehrhovey | 0:a548a085de55 | 535 | #if TCP_OUTPUT_DEBUG |
pehrhovey | 0:a548a085de55 | 536 | if (seg == NULL) { |
pehrhovey | 0:a548a085de55 | 537 | LWIP_DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_output: nothing to send (%p)\n", |
pehrhovey | 0:a548a085de55 | 538 | (void*)pcb->unsent)); |
pehrhovey | 0:a548a085de55 | 539 | } |
pehrhovey | 0:a548a085de55 | 540 | #endif /* TCP_OUTPUT_DEBUG */ |
pehrhovey | 0:a548a085de55 | 541 | #if TCP_CWND_DEBUG |
pehrhovey | 0:a548a085de55 | 542 | if (seg == NULL) { |
pehrhovey | 0:a548a085de55 | 543 | LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_output: snd_wnd %"U16_F |
pehrhovey | 0:a548a085de55 | 544 | ", cwnd %"U16_F", wnd %"U32_F |
pehrhovey | 0:a548a085de55 | 545 | ", seg == NULL, ack %"U32_F"\n", |
pehrhovey | 0:a548a085de55 | 546 | pcb->snd_wnd, pcb->cwnd, wnd, pcb->lastack)); |
pehrhovey | 0:a548a085de55 | 547 | } else { |
pehrhovey | 0:a548a085de55 | 548 | LWIP_DEBUGF(TCP_CWND_DEBUG, |
pehrhovey | 0:a548a085de55 | 549 | ("tcp_output: snd_wnd %"U16_F", cwnd %"U16_F", wnd %"U32_F |
pehrhovey | 0:a548a085de55 | 550 | ", effwnd %"U32_F", seq %"U32_F", ack %"U32_F"\n", |
pehrhovey | 0:a548a085de55 | 551 | pcb->snd_wnd, pcb->cwnd, wnd, |
pehrhovey | 0:a548a085de55 | 552 | ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len, |
pehrhovey | 0:a548a085de55 | 553 | ntohl(seg->tcphdr->seqno), pcb->lastack)); |
pehrhovey | 0:a548a085de55 | 554 | } |
pehrhovey | 0:a548a085de55 | 555 | #endif /* TCP_CWND_DEBUG */ |
pehrhovey | 0:a548a085de55 | 556 | /* data available and window allows it to be sent? */ |
pehrhovey | 0:a548a085de55 | 557 | while (seg != NULL && |
pehrhovey | 0:a548a085de55 | 558 | ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len <= wnd) { |
pehrhovey | 0:a548a085de55 | 559 | LWIP_ASSERT("RST not expected here!", |
pehrhovey | 0:a548a085de55 | 560 | (TCPH_FLAGS(seg->tcphdr) & TCP_RST) == 0); |
pehrhovey | 0:a548a085de55 | 561 | /* Stop sending if the nagle algorithm would prevent it |
pehrhovey | 0:a548a085de55 | 562 | * Don't stop: |
pehrhovey | 0:a548a085de55 | 563 | * - if tcp_enqueue had a memory error before (prevent delayed ACK timeout) or |
pehrhovey | 0:a548a085de55 | 564 | * - if FIN was already enqueued for this PCB (SYN is always alone in a segment - |
pehrhovey | 0:a548a085de55 | 565 | * either seg->next != NULL or pcb->unacked == NULL; |
pehrhovey | 0:a548a085de55 | 566 | * RST is no sent using tcp_enqueue/tcp_output. |
pehrhovey | 0:a548a085de55 | 567 | */ |
pehrhovey | 0:a548a085de55 | 568 | if((tcp_do_output_nagle(pcb) == 0) && |
pehrhovey | 0:a548a085de55 | 569 | ((pcb->flags & (TF_NAGLEMEMERR | TF_FIN)) == 0)){ |
pehrhovey | 0:a548a085de55 | 570 | break; |
pehrhovey | 0:a548a085de55 | 571 | } |
pehrhovey | 0:a548a085de55 | 572 | #if TCP_CWND_DEBUG |
pehrhovey | 0:a548a085de55 | 573 | LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_output: snd_wnd %"U16_F", cwnd %"U16_F", wnd %"U32_F", effwnd %"U32_F", seq %"U32_F", ack %"U32_F", i %"S16_F"\n", |
pehrhovey | 0:a548a085de55 | 574 | pcb->snd_wnd, pcb->cwnd, wnd, |
pehrhovey | 0:a548a085de55 | 575 | ntohl(seg->tcphdr->seqno) + seg->len - |
pehrhovey | 0:a548a085de55 | 576 | pcb->lastack, |
pehrhovey | 0:a548a085de55 | 577 | ntohl(seg->tcphdr->seqno), pcb->lastack, i)); |
pehrhovey | 0:a548a085de55 | 578 | ++i; |
pehrhovey | 0:a548a085de55 | 579 | #endif /* TCP_CWND_DEBUG */ |
pehrhovey | 0:a548a085de55 | 580 | |
pehrhovey | 0:a548a085de55 | 581 | pcb->unsent = seg->next; |
pehrhovey | 0:a548a085de55 | 582 | |
pehrhovey | 0:a548a085de55 | 583 | if (pcb->state != SYN_SENT) { |
pehrhovey | 0:a548a085de55 | 584 | TCPH_SET_FLAG(seg->tcphdr, TCP_ACK); |
pehrhovey | 0:a548a085de55 | 585 | pcb->flags &= ~(TF_ACK_DELAY | TF_ACK_NOW); |
pehrhovey | 0:a548a085de55 | 586 | } |
pehrhovey | 0:a548a085de55 | 587 | |
pehrhovey | 0:a548a085de55 | 588 | tcp_output_segment(seg, pcb); |
pehrhovey | 0:a548a085de55 | 589 | snd_nxt = ntohl(seg->tcphdr->seqno) + TCP_TCPLEN(seg); |
pehrhovey | 0:a548a085de55 | 590 | if (TCP_SEQ_LT(pcb->snd_nxt, snd_nxt)) { |
pehrhovey | 0:a548a085de55 | 591 | pcb->snd_nxt = snd_nxt; |
pehrhovey | 0:a548a085de55 | 592 | } |
pehrhovey | 0:a548a085de55 | 593 | /* put segment on unacknowledged list if length > 0 */ |
pehrhovey | 0:a548a085de55 | 594 | if (TCP_TCPLEN(seg) > 0) { |
pehrhovey | 0:a548a085de55 | 595 | seg->next = NULL; |
pehrhovey | 0:a548a085de55 | 596 | /* unacked list is empty? */ |
pehrhovey | 0:a548a085de55 | 597 | if (pcb->unacked == NULL) { |
pehrhovey | 0:a548a085de55 | 598 | pcb->unacked = seg; |
pehrhovey | 0:a548a085de55 | 599 | useg = seg; |
pehrhovey | 0:a548a085de55 | 600 | /* unacked list is not empty? */ |
pehrhovey | 0:a548a085de55 | 601 | } else { |
pehrhovey | 0:a548a085de55 | 602 | /* In the case of fast retransmit, the packet should not go to the tail |
pehrhovey | 0:a548a085de55 | 603 | * of the unacked queue, but rather somewhere before it. We need to check for |
pehrhovey | 0:a548a085de55 | 604 | * this case. -STJ Jul 27, 2004 */ |
pehrhovey | 0:a548a085de55 | 605 | if (TCP_SEQ_LT(ntohl(seg->tcphdr->seqno), ntohl(useg->tcphdr->seqno))){ |
pehrhovey | 0:a548a085de55 | 606 | /* add segment to before tail of unacked list, keeping the list sorted */ |
pehrhovey | 0:a548a085de55 | 607 | struct tcp_seg **cur_seg = &(pcb->unacked); |
pehrhovey | 0:a548a085de55 | 608 | while (*cur_seg && |
pehrhovey | 0:a548a085de55 | 609 | TCP_SEQ_LT(ntohl((*cur_seg)->tcphdr->seqno), ntohl(seg->tcphdr->seqno))) { |
pehrhovey | 0:a548a085de55 | 610 | cur_seg = &((*cur_seg)->next ); |
pehrhovey | 0:a548a085de55 | 611 | } |
pehrhovey | 0:a548a085de55 | 612 | seg->next = (*cur_seg); |
pehrhovey | 0:a548a085de55 | 613 | (*cur_seg) = seg; |
pehrhovey | 0:a548a085de55 | 614 | } else { |
pehrhovey | 0:a548a085de55 | 615 | /* add segment to tail of unacked list */ |
pehrhovey | 0:a548a085de55 | 616 | useg->next = seg; |
pehrhovey | 0:a548a085de55 | 617 | useg = useg->next; |
pehrhovey | 0:a548a085de55 | 618 | } |
pehrhovey | 0:a548a085de55 | 619 | } |
pehrhovey | 0:a548a085de55 | 620 | /* do not queue empty segments on the unacked list */ |
pehrhovey | 0:a548a085de55 | 621 | } else { |
pehrhovey | 0:a548a085de55 | 622 | tcp_seg_free(seg); |
pehrhovey | 0:a548a085de55 | 623 | } |
pehrhovey | 0:a548a085de55 | 624 | seg = pcb->unsent; |
pehrhovey | 0:a548a085de55 | 625 | } |
pehrhovey | 0:a548a085de55 | 626 | |
pehrhovey | 0:a548a085de55 | 627 | if (seg != NULL && pcb->persist_backoff == 0 && |
pehrhovey | 0:a548a085de55 | 628 | ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len > pcb->snd_wnd) { |
pehrhovey | 0:a548a085de55 | 629 | /* prepare for persist timer */ |
pehrhovey | 0:a548a085de55 | 630 | pcb->persist_cnt = 0; |
pehrhovey | 0:a548a085de55 | 631 | pcb->persist_backoff = 1; |
pehrhovey | 0:a548a085de55 | 632 | } |
pehrhovey | 0:a548a085de55 | 633 | |
pehrhovey | 0:a548a085de55 | 634 | pcb->flags &= ~TF_NAGLEMEMERR; |
pehrhovey | 0:a548a085de55 | 635 | return ERR_OK; |
pehrhovey | 0:a548a085de55 | 636 | } |
pehrhovey | 0:a548a085de55 | 637 | |
pehrhovey | 0:a548a085de55 | 638 | /** |
pehrhovey | 0:a548a085de55 | 639 | * Called by tcp_output() to actually send a TCP segment over IP. |
pehrhovey | 0:a548a085de55 | 640 | * |
pehrhovey | 0:a548a085de55 | 641 | * @param seg the tcp_seg to send |
pehrhovey | 0:a548a085de55 | 642 | * @param pcb the tcp_pcb for the TCP connection used to send the segment |
pehrhovey | 0:a548a085de55 | 643 | */ |
pehrhovey | 0:a548a085de55 | 644 | static void |
pehrhovey | 0:a548a085de55 | 645 | tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb) |
pehrhovey | 0:a548a085de55 | 646 | { |
pehrhovey | 0:a548a085de55 | 647 | u16_t len; |
pehrhovey | 0:a548a085de55 | 648 | struct netif *netif; |
pehrhovey | 0:a548a085de55 | 649 | u32_t *opts; |
pehrhovey | 0:a548a085de55 | 650 | |
pehrhovey | 0:a548a085de55 | 651 | /** @bug Exclude retransmitted segments from this count. */ |
pehrhovey | 0:a548a085de55 | 652 | snmp_inc_tcpoutsegs(); |
pehrhovey | 0:a548a085de55 | 653 | |
pehrhovey | 0:a548a085de55 | 654 | /* The TCP header has already been constructed, but the ackno and |
pehrhovey | 0:a548a085de55 | 655 | wnd fields remain. */ |
pehrhovey | 0:a548a085de55 | 656 | seg->tcphdr->ackno = htonl(pcb->rcv_nxt); |
pehrhovey | 0:a548a085de55 | 657 | |
pehrhovey | 0:a548a085de55 | 658 | /* advertise our receive window size in this TCP segment */ |
pehrhovey | 0:a548a085de55 | 659 | seg->tcphdr->wnd = htons(pcb->rcv_ann_wnd); |
pehrhovey | 0:a548a085de55 | 660 | |
pehrhovey | 0:a548a085de55 | 661 | pcb->rcv_ann_right_edge = pcb->rcv_nxt + pcb->rcv_ann_wnd; |
pehrhovey | 0:a548a085de55 | 662 | |
pehrhovey | 0:a548a085de55 | 663 | /* Add any requested options. NB MSS option is only set on SYN |
pehrhovey | 0:a548a085de55 | 664 | packets, so ignore it here */ |
pehrhovey | 0:a548a085de55 | 665 | opts = (u32_t *)(seg->tcphdr + 1); |
pehrhovey | 0:a548a085de55 | 666 | if (seg->flags & TF_SEG_OPTS_MSS) { |
pehrhovey | 0:a548a085de55 | 667 | TCP_BUILD_MSS_OPTION(*opts); |
pehrhovey | 0:a548a085de55 | 668 | opts += 1; |
pehrhovey | 0:a548a085de55 | 669 | } |
pehrhovey | 0:a548a085de55 | 670 | #if LWIP_TCP_TIMESTAMPS |
pehrhovey | 0:a548a085de55 | 671 | pcb->ts_lastacksent = pcb->rcv_nxt; |
pehrhovey | 0:a548a085de55 | 672 | |
pehrhovey | 0:a548a085de55 | 673 | if (seg->flags & TF_SEG_OPTS_TS) { |
pehrhovey | 0:a548a085de55 | 674 | tcp_build_timestamp_option(pcb, opts); |
pehrhovey | 0:a548a085de55 | 675 | opts += 3; |
pehrhovey | 0:a548a085de55 | 676 | } |
pehrhovey | 0:a548a085de55 | 677 | #endif |
pehrhovey | 0:a548a085de55 | 678 | |
pehrhovey | 0:a548a085de55 | 679 | /* If we don't have a local IP address, we get one by |
pehrhovey | 0:a548a085de55 | 680 | calling ip_route(). */ |
pehrhovey | 0:a548a085de55 | 681 | if (ip_addr_isany(&(pcb->local_ip))) { |
pehrhovey | 0:a548a085de55 | 682 | netif = ip_route(&(pcb->remote_ip)); |
pehrhovey | 0:a548a085de55 | 683 | if (netif == NULL) { |
pehrhovey | 0:a548a085de55 | 684 | return; |
pehrhovey | 0:a548a085de55 | 685 | } |
pehrhovey | 0:a548a085de55 | 686 | ip_addr_set(&(pcb->local_ip), &(netif->ip_addr)); |
pehrhovey | 0:a548a085de55 | 687 | } |
pehrhovey | 0:a548a085de55 | 688 | |
pehrhovey | 0:a548a085de55 | 689 | /* Set retransmission timer running if it is not currently enabled */ |
pehrhovey | 0:a548a085de55 | 690 | if(pcb->rtime == -1) |
pehrhovey | 0:a548a085de55 | 691 | pcb->rtime = 0; |
pehrhovey | 0:a548a085de55 | 692 | |
pehrhovey | 0:a548a085de55 | 693 | if (pcb->rttest == 0) { |
pehrhovey | 0:a548a085de55 | 694 | pcb->rttest = tcp_ticks; |
pehrhovey | 0:a548a085de55 | 695 | pcb->rtseq = ntohl(seg->tcphdr->seqno); |
pehrhovey | 0:a548a085de55 | 696 | |
pehrhovey | 0:a548a085de55 | 697 | LWIP_DEBUGF(TCP_RTO_DEBUG, ("tcp_output_segment: rtseq %"U32_F"\n", pcb->rtseq)); |
pehrhovey | 0:a548a085de55 | 698 | } |
pehrhovey | 0:a548a085de55 | 699 | LWIP_DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_output_segment: %"U32_F":%"U32_F"\n", |
pehrhovey | 0:a548a085de55 | 700 | htonl(seg->tcphdr->seqno), htonl(seg->tcphdr->seqno) + |
pehrhovey | 0:a548a085de55 | 701 | seg->len)); |
pehrhovey | 0:a548a085de55 | 702 | |
pehrhovey | 0:a548a085de55 | 703 | len = (u16_t)((u8_t *)seg->tcphdr - (u8_t *)seg->p->payload); |
pehrhovey | 0:a548a085de55 | 704 | |
pehrhovey | 0:a548a085de55 | 705 | seg->p->len -= len; |
pehrhovey | 0:a548a085de55 | 706 | seg->p->tot_len -= len; |
pehrhovey | 0:a548a085de55 | 707 | |
pehrhovey | 0:a548a085de55 | 708 | seg->p->payload = seg->tcphdr; |
pehrhovey | 0:a548a085de55 | 709 | |
pehrhovey | 0:a548a085de55 | 710 | seg->tcphdr->chksum = 0; |
pehrhovey | 0:a548a085de55 | 711 | #if CHECKSUM_GEN_TCP |
pehrhovey | 0:a548a085de55 | 712 | seg->tcphdr->chksum = inet_chksum_pseudo(seg->p, |
pehrhovey | 0:a548a085de55 | 713 | &(pcb->local_ip), |
pehrhovey | 0:a548a085de55 | 714 | &(pcb->remote_ip), |
pehrhovey | 0:a548a085de55 | 715 | IP_PROTO_TCP, seg->p->tot_len); |
pehrhovey | 0:a548a085de55 | 716 | #endif |
pehrhovey | 0:a548a085de55 | 717 | TCP_STATS_INC(tcp.xmit); |
pehrhovey | 0:a548a085de55 | 718 | |
pehrhovey | 0:a548a085de55 | 719 | #if LWIP_NETIF_HWADDRHINT |
pehrhovey | 0:a548a085de55 | 720 | ip_output_hinted(seg->p, &(pcb->local_ip), &(pcb->remote_ip), pcb->ttl, pcb->tos, |
pehrhovey | 0:a548a085de55 | 721 | IP_PROTO_TCP, &(pcb->addr_hint)); |
pehrhovey | 0:a548a085de55 | 722 | #else /* LWIP_NETIF_HWADDRHINT*/ |
pehrhovey | 0:a548a085de55 | 723 | ip_output(seg->p, &(pcb->local_ip), &(pcb->remote_ip), pcb->ttl, pcb->tos, |
pehrhovey | 0:a548a085de55 | 724 | IP_PROTO_TCP); |
pehrhovey | 0:a548a085de55 | 725 | #endif /* LWIP_NETIF_HWADDRHINT*/ |
pehrhovey | 0:a548a085de55 | 726 | } |
pehrhovey | 0:a548a085de55 | 727 | |
pehrhovey | 0:a548a085de55 | 728 | /** |
pehrhovey | 0:a548a085de55 | 729 | * Send a TCP RESET packet (empty segment with RST flag set) either to |
pehrhovey | 0:a548a085de55 | 730 | * abort a connection or to show that there is no matching local connection |
pehrhovey | 0:a548a085de55 | 731 | * for a received segment. |
pehrhovey | 0:a548a085de55 | 732 | * |
pehrhovey | 0:a548a085de55 | 733 | * Called by tcp_abort() (to abort a local connection), tcp_input() (if no |
pehrhovey | 0:a548a085de55 | 734 | * matching local pcb was found), tcp_listen_input() (if incoming segment |
pehrhovey | 0:a548a085de55 | 735 | * has ACK flag set) and tcp_process() (received segment in the wrong state) |
pehrhovey | 0:a548a085de55 | 736 | * |
pehrhovey | 0:a548a085de55 | 737 | * Since a RST segment is in most cases not sent for an active connection, |
pehrhovey | 0:a548a085de55 | 738 | * tcp_rst() has a number of arguments that are taken from a tcp_pcb for |
pehrhovey | 0:a548a085de55 | 739 | * most other segment output functions. |
pehrhovey | 0:a548a085de55 | 740 | * |
pehrhovey | 0:a548a085de55 | 741 | * @param seqno the sequence number to use for the outgoing segment |
pehrhovey | 0:a548a085de55 | 742 | * @param ackno the acknowledge number to use for the outgoing segment |
pehrhovey | 0:a548a085de55 | 743 | * @param local_ip the local IP address to send the segment from |
pehrhovey | 0:a548a085de55 | 744 | * @param remote_ip the remote IP address to send the segment to |
pehrhovey | 0:a548a085de55 | 745 | * @param local_port the local TCP port to send the segment from |
pehrhovey | 0:a548a085de55 | 746 | * @param remote_port the remote TCP port to send the segment to |
pehrhovey | 0:a548a085de55 | 747 | */ |
pehrhovey | 0:a548a085de55 | 748 | void |
pehrhovey | 0:a548a085de55 | 749 | tcp_rst(u32_t seqno, u32_t ackno, |
pehrhovey | 0:a548a085de55 | 750 | struct ip_addr *local_ip, struct ip_addr *remote_ip, |
pehrhovey | 0:a548a085de55 | 751 | u16_t local_port, u16_t remote_port) |
pehrhovey | 0:a548a085de55 | 752 | { |
pehrhovey | 0:a548a085de55 | 753 | struct pbuf *p; |
pehrhovey | 0:a548a085de55 | 754 | struct tcp_hdr *tcphdr; |
pehrhovey | 0:a548a085de55 | 755 | p = pbuf_alloc(PBUF_IP, TCP_HLEN, PBUF_RAM); |
pehrhovey | 0:a548a085de55 | 756 | if (p == NULL) { |
pehrhovey | 0:a548a085de55 | 757 | LWIP_DEBUGF(TCP_DEBUG, ("tcp_rst: could not allocate memory for pbuf\n")); |
pehrhovey | 0:a548a085de55 | 758 | return; |
pehrhovey | 0:a548a085de55 | 759 | } |
pehrhovey | 0:a548a085de55 | 760 | LWIP_ASSERT("check that first pbuf can hold struct tcp_hdr", |
pehrhovey | 0:a548a085de55 | 761 | (p->len >= sizeof(struct tcp_hdr))); |
pehrhovey | 0:a548a085de55 | 762 | |
pehrhovey | 0:a548a085de55 | 763 | tcphdr = (struct tcp_hdr *)p->payload; |
pehrhovey | 0:a548a085de55 | 764 | tcphdr->src = htons(local_port); |
pehrhovey | 0:a548a085de55 | 765 | tcphdr->dest = htons(remote_port); |
pehrhovey | 0:a548a085de55 | 766 | tcphdr->seqno = htonl(seqno); |
pehrhovey | 0:a548a085de55 | 767 | tcphdr->ackno = htonl(ackno); |
pehrhovey | 0:a548a085de55 | 768 | TCPH_FLAGS_SET(tcphdr, TCP_RST | TCP_ACK); |
pehrhovey | 0:a548a085de55 | 769 | tcphdr->wnd = htons(TCP_WND); |
pehrhovey | 0:a548a085de55 | 770 | tcphdr->urgp = 0; |
pehrhovey | 0:a548a085de55 | 771 | TCPH_HDRLEN_SET(tcphdr, 5); |
pehrhovey | 0:a548a085de55 | 772 | |
pehrhovey | 0:a548a085de55 | 773 | tcphdr->chksum = 0; |
pehrhovey | 0:a548a085de55 | 774 | #if CHECKSUM_GEN_TCP |
pehrhovey | 0:a548a085de55 | 775 | tcphdr->chksum = inet_chksum_pseudo(p, local_ip, remote_ip, |
pehrhovey | 0:a548a085de55 | 776 | IP_PROTO_TCP, p->tot_len); |
pehrhovey | 0:a548a085de55 | 777 | #endif |
pehrhovey | 0:a548a085de55 | 778 | TCP_STATS_INC(tcp.xmit); |
pehrhovey | 0:a548a085de55 | 779 | snmp_inc_tcpoutrsts(); |
pehrhovey | 0:a548a085de55 | 780 | /* Send output with hardcoded TTL since we have no access to the pcb */ |
pehrhovey | 0:a548a085de55 | 781 | ip_output(p, local_ip, remote_ip, TCP_TTL, 0, IP_PROTO_TCP); |
pehrhovey | 0:a548a085de55 | 782 | pbuf_free(p); |
pehrhovey | 0:a548a085de55 | 783 | LWIP_DEBUGF(TCP_RST_DEBUG, ("tcp_rst: seqno %"U32_F" ackno %"U32_F".\n", seqno, ackno)); |
pehrhovey | 0:a548a085de55 | 784 | } |
pehrhovey | 0:a548a085de55 | 785 | |
pehrhovey | 0:a548a085de55 | 786 | /** |
pehrhovey | 0:a548a085de55 | 787 | * Requeue all unacked segments for retransmission |
pehrhovey | 0:a548a085de55 | 788 | * |
pehrhovey | 0:a548a085de55 | 789 | * Called by tcp_slowtmr() for slow retransmission. |
pehrhovey | 0:a548a085de55 | 790 | * |
pehrhovey | 0:a548a085de55 | 791 | * @param pcb the tcp_pcb for which to re-enqueue all unacked segments |
pehrhovey | 0:a548a085de55 | 792 | */ |
pehrhovey | 0:a548a085de55 | 793 | void |
pehrhovey | 0:a548a085de55 | 794 | tcp_rexmit_rto(struct tcp_pcb *pcb) |
pehrhovey | 0:a548a085de55 | 795 | { |
pehrhovey | 0:a548a085de55 | 796 | struct tcp_seg *seg; |
pehrhovey | 0:a548a085de55 | 797 | |
pehrhovey | 0:a548a085de55 | 798 | if (pcb->unacked == NULL) { |
pehrhovey | 0:a548a085de55 | 799 | return; |
pehrhovey | 0:a548a085de55 | 800 | } |
pehrhovey | 0:a548a085de55 | 801 | |
pehrhovey | 0:a548a085de55 | 802 | /* Move all unacked segments to the head of the unsent queue */ |
pehrhovey | 0:a548a085de55 | 803 | for (seg = pcb->unacked; seg->next != NULL; seg = seg->next); |
pehrhovey | 0:a548a085de55 | 804 | /* concatenate unsent queue after unacked queue */ |
pehrhovey | 0:a548a085de55 | 805 | seg->next = pcb->unsent; |
pehrhovey | 0:a548a085de55 | 806 | /* unsent queue is the concatenated queue (of unacked, unsent) */ |
pehrhovey | 0:a548a085de55 | 807 | pcb->unsent = pcb->unacked; |
pehrhovey | 0:a548a085de55 | 808 | /* unacked queue is now empty */ |
pehrhovey | 0:a548a085de55 | 809 | pcb->unacked = NULL; |
pehrhovey | 0:a548a085de55 | 810 | |
pehrhovey | 0:a548a085de55 | 811 | /* increment number of retransmissions */ |
pehrhovey | 0:a548a085de55 | 812 | ++pcb->nrtx; |
pehrhovey | 0:a548a085de55 | 813 | |
pehrhovey | 0:a548a085de55 | 814 | /* Don't take any RTT measurements after retransmitting. */ |
pehrhovey | 0:a548a085de55 | 815 | pcb->rttest = 0; |
pehrhovey | 0:a548a085de55 | 816 | |
pehrhovey | 0:a548a085de55 | 817 | /* Do the actual retransmission */ |
pehrhovey | 0:a548a085de55 | 818 | tcp_output(pcb); |
pehrhovey | 0:a548a085de55 | 819 | } |
pehrhovey | 0:a548a085de55 | 820 | |
pehrhovey | 0:a548a085de55 | 821 | /** |
pehrhovey | 0:a548a085de55 | 822 | * Requeue the first unacked segment for retransmission |
pehrhovey | 0:a548a085de55 | 823 | * |
pehrhovey | 0:a548a085de55 | 824 | * Called by tcp_receive() for fast retramsmit. |
pehrhovey | 0:a548a085de55 | 825 | * |
pehrhovey | 0:a548a085de55 | 826 | * @param pcb the tcp_pcb for which to retransmit the first unacked segment |
pehrhovey | 0:a548a085de55 | 827 | */ |
pehrhovey | 0:a548a085de55 | 828 | void |
pehrhovey | 0:a548a085de55 | 829 | tcp_rexmit(struct tcp_pcb *pcb) |
pehrhovey | 0:a548a085de55 | 830 | { |
pehrhovey | 0:a548a085de55 | 831 | struct tcp_seg *seg; |
pehrhovey | 0:a548a085de55 | 832 | struct tcp_seg **cur_seg; |
pehrhovey | 0:a548a085de55 | 833 | |
pehrhovey | 0:a548a085de55 | 834 | if (pcb->unacked == NULL) { |
pehrhovey | 0:a548a085de55 | 835 | return; |
pehrhovey | 0:a548a085de55 | 836 | } |
pehrhovey | 0:a548a085de55 | 837 | |
pehrhovey | 0:a548a085de55 | 838 | /* Move the first unacked segment to the unsent queue */ |
pehrhovey | 0:a548a085de55 | 839 | /* Keep the unsent queue sorted. */ |
pehrhovey | 0:a548a085de55 | 840 | seg = pcb->unacked; |
pehrhovey | 0:a548a085de55 | 841 | pcb->unacked = seg->next; |
pehrhovey | 0:a548a085de55 | 842 | |
pehrhovey | 0:a548a085de55 | 843 | cur_seg = &(pcb->unsent); |
pehrhovey | 0:a548a085de55 | 844 | while (*cur_seg && |
pehrhovey | 0:a548a085de55 | 845 | TCP_SEQ_LT(ntohl((*cur_seg)->tcphdr->seqno), ntohl(seg->tcphdr->seqno))) { |
pehrhovey | 0:a548a085de55 | 846 | cur_seg = &((*cur_seg)->next ); |
pehrhovey | 0:a548a085de55 | 847 | } |
pehrhovey | 0:a548a085de55 | 848 | seg->next = *cur_seg; |
pehrhovey | 0:a548a085de55 | 849 | *cur_seg = seg; |
pehrhovey | 0:a548a085de55 | 850 | |
pehrhovey | 0:a548a085de55 | 851 | ++pcb->nrtx; |
pehrhovey | 0:a548a085de55 | 852 | |
pehrhovey | 0:a548a085de55 | 853 | /* Don't take any rtt measurements after retransmitting. */ |
pehrhovey | 0:a548a085de55 | 854 | pcb->rttest = 0; |
pehrhovey | 0:a548a085de55 | 855 | |
pehrhovey | 0:a548a085de55 | 856 | /* Do the actual retransmission. */ |
pehrhovey | 0:a548a085de55 | 857 | snmp_inc_tcpretranssegs(); |
pehrhovey | 0:a548a085de55 | 858 | tcp_output(pcb); |
pehrhovey | 0:a548a085de55 | 859 | } |
pehrhovey | 0:a548a085de55 | 860 | |
pehrhovey | 0:a548a085de55 | 861 | |
pehrhovey | 0:a548a085de55 | 862 | /** |
pehrhovey | 0:a548a085de55 | 863 | * Handle retransmission after three dupacks received |
pehrhovey | 0:a548a085de55 | 864 | * |
pehrhovey | 0:a548a085de55 | 865 | * @param pcb the tcp_pcb for which to retransmit the first unacked segment |
pehrhovey | 0:a548a085de55 | 866 | */ |
pehrhovey | 0:a548a085de55 | 867 | void |
pehrhovey | 0:a548a085de55 | 868 | tcp_rexmit_fast(struct tcp_pcb *pcb) |
pehrhovey | 0:a548a085de55 | 869 | { |
pehrhovey | 0:a548a085de55 | 870 | if (pcb->unacked != NULL && !(pcb->flags & TF_INFR)) { |
pehrhovey | 0:a548a085de55 | 871 | /* This is fast retransmit. Retransmit the first unacked segment. */ |
pehrhovey | 0:a548a085de55 | 872 | LWIP_DEBUGF(TCP_FR_DEBUG, |
pehrhovey | 0:a548a085de55 | 873 | ("tcp_receive: dupacks %"U16_F" (%"U32_F |
pehrhovey | 0:a548a085de55 | 874 | "), fast retransmit %"U32_F"\n", |
pehrhovey | 0:a548a085de55 | 875 | (u16_t)pcb->dupacks, pcb->lastack, |
pehrhovey | 0:a548a085de55 | 876 | ntohl(pcb->unacked->tcphdr->seqno))); |
pehrhovey | 0:a548a085de55 | 877 | tcp_rexmit(pcb); |
pehrhovey | 0:a548a085de55 | 878 | |
pehrhovey | 0:a548a085de55 | 879 | /* Set ssthresh to half of the minimum of the current |
pehrhovey | 0:a548a085de55 | 880 | * cwnd and the advertised window */ |
pehrhovey | 0:a548a085de55 | 881 | if (pcb->cwnd > pcb->snd_wnd) |
pehrhovey | 0:a548a085de55 | 882 | pcb->ssthresh = pcb->snd_wnd / 2; |
pehrhovey | 0:a548a085de55 | 883 | else |
pehrhovey | 0:a548a085de55 | 884 | pcb->ssthresh = pcb->cwnd / 2; |
pehrhovey | 0:a548a085de55 | 885 | |
pehrhovey | 0:a548a085de55 | 886 | /* The minimum value for ssthresh should be 2 MSS */ |
pehrhovey | 0:a548a085de55 | 887 | if (pcb->ssthresh < 2*pcb->mss) { |
pehrhovey | 0:a548a085de55 | 888 | LWIP_DEBUGF(TCP_FR_DEBUG, |
pehrhovey | 0:a548a085de55 | 889 | ("tcp_receive: The minimum value for ssthresh %"U16_F |
pehrhovey | 0:a548a085de55 | 890 | " should be min 2 mss %"U16_F"...\n", |
pehrhovey | 0:a548a085de55 | 891 | pcb->ssthresh, 2*pcb->mss)); |
pehrhovey | 0:a548a085de55 | 892 | pcb->ssthresh = 2*pcb->mss; |
pehrhovey | 0:a548a085de55 | 893 | } |
pehrhovey | 0:a548a085de55 | 894 | |
pehrhovey | 0:a548a085de55 | 895 | pcb->cwnd = pcb->ssthresh + 3 * pcb->mss; |
pehrhovey | 0:a548a085de55 | 896 | pcb->flags |= TF_INFR; |
pehrhovey | 0:a548a085de55 | 897 | } |
pehrhovey | 0:a548a085de55 | 898 | } |
pehrhovey | 0:a548a085de55 | 899 | |
pehrhovey | 0:a548a085de55 | 900 | |
pehrhovey | 0:a548a085de55 | 901 | /** |
pehrhovey | 0:a548a085de55 | 902 | * Send keepalive packets to keep a connection active although |
pehrhovey | 0:a548a085de55 | 903 | * no data is sent over it. |
pehrhovey | 0:a548a085de55 | 904 | * |
pehrhovey | 0:a548a085de55 | 905 | * Called by tcp_slowtmr() |
pehrhovey | 0:a548a085de55 | 906 | * |
pehrhovey | 0:a548a085de55 | 907 | * @param pcb the tcp_pcb for which to send a keepalive packet |
pehrhovey | 0:a548a085de55 | 908 | */ |
pehrhovey | 0:a548a085de55 | 909 | void |
pehrhovey | 0:a548a085de55 | 910 | tcp_keepalive(struct tcp_pcb *pcb) |
pehrhovey | 0:a548a085de55 | 911 | { |
pehrhovey | 0:a548a085de55 | 912 | struct pbuf *p; |
pehrhovey | 0:a548a085de55 | 913 | struct tcp_hdr *tcphdr; |
pehrhovey | 0:a548a085de55 | 914 | |
pehrhovey | 0:a548a085de55 | 915 | LWIP_DEBUGF(TCP_DEBUG, ("tcp_keepalive: sending KEEPALIVE probe to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", |
pehrhovey | 0:a548a085de55 | 916 | ip4_addr1(&pcb->remote_ip), ip4_addr2(&pcb->remote_ip), |
pehrhovey | 0:a548a085de55 | 917 | ip4_addr3(&pcb->remote_ip), ip4_addr4(&pcb->remote_ip))); |
pehrhovey | 0:a548a085de55 | 918 | |
pehrhovey | 0:a548a085de55 | 919 | LWIP_DEBUGF(TCP_DEBUG, ("tcp_keepalive: tcp_ticks %"U32_F" pcb->tmr %"U32_F" pcb->keep_cnt_sent %"U16_F"\n", |
pehrhovey | 0:a548a085de55 | 920 | tcp_ticks, pcb->tmr, pcb->keep_cnt_sent)); |
pehrhovey | 0:a548a085de55 | 921 | |
pehrhovey | 0:a548a085de55 | 922 | p = pbuf_alloc(PBUF_IP, TCP_HLEN, PBUF_RAM); |
pehrhovey | 0:a548a085de55 | 923 | |
pehrhovey | 0:a548a085de55 | 924 | if(p == NULL) { |
pehrhovey | 0:a548a085de55 | 925 | LWIP_DEBUGF(TCP_DEBUG, |
pehrhovey | 0:a548a085de55 | 926 | ("tcp_keepalive: could not allocate memory for pbuf\n")); |
pehrhovey | 0:a548a085de55 | 927 | return; |
pehrhovey | 0:a548a085de55 | 928 | } |
pehrhovey | 0:a548a085de55 | 929 | LWIP_ASSERT("check that first pbuf can hold struct tcp_hdr", |
pehrhovey | 0:a548a085de55 | 930 | (p->len >= sizeof(struct tcp_hdr))); |
pehrhovey | 0:a548a085de55 | 931 | |
pehrhovey | 0:a548a085de55 | 932 | tcphdr = tcp_output_set_header(pcb, p, 0, htonl(pcb->snd_nxt - 1)); |
pehrhovey | 0:a548a085de55 | 933 | |
pehrhovey | 0:a548a085de55 | 934 | #if CHECKSUM_GEN_TCP |
pehrhovey | 0:a548a085de55 | 935 | tcphdr->chksum = inet_chksum_pseudo(p, &pcb->local_ip, &pcb->remote_ip, |
pehrhovey | 0:a548a085de55 | 936 | IP_PROTO_TCP, p->tot_len); |
pehrhovey | 0:a548a085de55 | 937 | #endif |
pehrhovey | 0:a548a085de55 | 938 | TCP_STATS_INC(tcp.xmit); |
pehrhovey | 0:a548a085de55 | 939 | |
pehrhovey | 0:a548a085de55 | 940 | /* Send output to IP */ |
pehrhovey | 0:a548a085de55 | 941 | #if LWIP_NETIF_HWADDRHINT |
pehrhovey | 0:a548a085de55 | 942 | ip_output_hinted(p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, 0, IP_PROTO_TCP, |
pehrhovey | 0:a548a085de55 | 943 | &(pcb->addr_hint)); |
pehrhovey | 0:a548a085de55 | 944 | #else /* LWIP_NETIF_HWADDRHINT*/ |
pehrhovey | 0:a548a085de55 | 945 | ip_output(p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, 0, IP_PROTO_TCP); |
pehrhovey | 0:a548a085de55 | 946 | #endif /* LWIP_NETIF_HWADDRHINT*/ |
pehrhovey | 0:a548a085de55 | 947 | |
pehrhovey | 0:a548a085de55 | 948 | pbuf_free(p); |
pehrhovey | 0:a548a085de55 | 949 | |
pehrhovey | 0:a548a085de55 | 950 | LWIP_DEBUGF(TCP_DEBUG, ("tcp_keepalive: seqno %"U32_F" ackno %"U32_F".\n", |
pehrhovey | 0:a548a085de55 | 951 | pcb->snd_nxt - 1, pcb->rcv_nxt)); |
pehrhovey | 0:a548a085de55 | 952 | } |
pehrhovey | 0:a548a085de55 | 953 | |
pehrhovey | 0:a548a085de55 | 954 | |
pehrhovey | 0:a548a085de55 | 955 | /** |
pehrhovey | 0:a548a085de55 | 956 | * Send persist timer zero-window probes to keep a connection active |
pehrhovey | 0:a548a085de55 | 957 | * when a window update is lost. |
pehrhovey | 0:a548a085de55 | 958 | * |
pehrhovey | 0:a548a085de55 | 959 | * Called by tcp_slowtmr() |
pehrhovey | 0:a548a085de55 | 960 | * |
pehrhovey | 0:a548a085de55 | 961 | * @param pcb the tcp_pcb for which to send a zero-window probe packet |
pehrhovey | 0:a548a085de55 | 962 | */ |
pehrhovey | 0:a548a085de55 | 963 | void |
pehrhovey | 0:a548a085de55 | 964 | tcp_zero_window_probe(struct tcp_pcb *pcb) |
pehrhovey | 0:a548a085de55 | 965 | { |
pehrhovey | 0:a548a085de55 | 966 | struct pbuf *p; |
pehrhovey | 0:a548a085de55 | 967 | struct tcp_hdr *tcphdr; |
pehrhovey | 0:a548a085de55 | 968 | struct tcp_seg *seg; |
pehrhovey | 0:a548a085de55 | 969 | u16_t len; |
pehrhovey | 0:a548a085de55 | 970 | u8_t is_fin; |
pehrhovey | 0:a548a085de55 | 971 | |
pehrhovey | 0:a548a085de55 | 972 | LWIP_DEBUGF(TCP_DEBUG, |
pehrhovey | 0:a548a085de55 | 973 | ("tcp_zero_window_probe: sending ZERO WINDOW probe to %" |
pehrhovey | 0:a548a085de55 | 974 | U16_F".%"U16_F".%"U16_F".%"U16_F"\n", |
pehrhovey | 0:a548a085de55 | 975 | ip4_addr1(&pcb->remote_ip), ip4_addr2(&pcb->remote_ip), |
pehrhovey | 0:a548a085de55 | 976 | ip4_addr3(&pcb->remote_ip), ip4_addr4(&pcb->remote_ip))); |
pehrhovey | 0:a548a085de55 | 977 | |
pehrhovey | 0:a548a085de55 | 978 | LWIP_DEBUGF(TCP_DEBUG, |
pehrhovey | 0:a548a085de55 | 979 | ("tcp_zero_window_probe: tcp_ticks %"U32_F |
pehrhovey | 0:a548a085de55 | 980 | " pcb->tmr %"U32_F" pcb->keep_cnt_sent %"U16_F"\n", |
pehrhovey | 0:a548a085de55 | 981 | tcp_ticks, pcb->tmr, pcb->keep_cnt_sent)); |
pehrhovey | 0:a548a085de55 | 982 | |
pehrhovey | 0:a548a085de55 | 983 | seg = pcb->unacked; |
pehrhovey | 0:a548a085de55 | 984 | |
pehrhovey | 0:a548a085de55 | 985 | if(seg == NULL) |
pehrhovey | 0:a548a085de55 | 986 | seg = pcb->unsent; |
pehrhovey | 0:a548a085de55 | 987 | |
pehrhovey | 0:a548a085de55 | 988 | if(seg == NULL) |
pehrhovey | 0:a548a085de55 | 989 | return; |
pehrhovey | 0:a548a085de55 | 990 | |
pehrhovey | 0:a548a085de55 | 991 | is_fin = ((TCPH_FLAGS(seg->tcphdr) & TCP_FIN) != 0) && (seg->len == 0); |
pehrhovey | 0:a548a085de55 | 992 | len = is_fin ? TCP_HLEN : TCP_HLEN + 1; |
pehrhovey | 0:a548a085de55 | 993 | |
pehrhovey | 0:a548a085de55 | 994 | p = pbuf_alloc(PBUF_IP, len, PBUF_RAM); |
pehrhovey | 0:a548a085de55 | 995 | if(p == NULL) { |
pehrhovey | 0:a548a085de55 | 996 | LWIP_DEBUGF(TCP_DEBUG, ("tcp_zero_window_probe: no memory for pbuf\n")); |
pehrhovey | 0:a548a085de55 | 997 | return; |
pehrhovey | 0:a548a085de55 | 998 | } |
pehrhovey | 0:a548a085de55 | 999 | LWIP_ASSERT("check that first pbuf can hold struct tcp_hdr", |
pehrhovey | 0:a548a085de55 | 1000 | (p->len >= sizeof(struct tcp_hdr))); |
pehrhovey | 0:a548a085de55 | 1001 | |
pehrhovey | 0:a548a085de55 | 1002 | tcphdr = tcp_output_set_header(pcb, p, 0, seg->tcphdr->seqno); |
pehrhovey | 0:a548a085de55 | 1003 | |
pehrhovey | 0:a548a085de55 | 1004 | if (is_fin) { |
pehrhovey | 0:a548a085de55 | 1005 | /* FIN segment, no data */ |
pehrhovey | 0:a548a085de55 | 1006 | TCPH_FLAGS_SET(tcphdr, TCP_ACK | TCP_FIN); |
pehrhovey | 0:a548a085de55 | 1007 | } else { |
pehrhovey | 0:a548a085de55 | 1008 | /* Data segment, copy in one byte from the head of the unacked queue */ |
pehrhovey | 0:a548a085de55 | 1009 | *((char *)p->payload + sizeof(struct tcp_hdr)) = *(char *)seg->dataptr; |
pehrhovey | 0:a548a085de55 | 1010 | } |
pehrhovey | 0:a548a085de55 | 1011 | |
pehrhovey | 0:a548a085de55 | 1012 | #if CHECKSUM_GEN_TCP |
pehrhovey | 0:a548a085de55 | 1013 | tcphdr->chksum = inet_chksum_pseudo(p, &pcb->local_ip, &pcb->remote_ip, |
pehrhovey | 0:a548a085de55 | 1014 | IP_PROTO_TCP, p->tot_len); |
pehrhovey | 0:a548a085de55 | 1015 | #endif |
pehrhovey | 0:a548a085de55 | 1016 | TCP_STATS_INC(tcp.xmit); |
pehrhovey | 0:a548a085de55 | 1017 | |
pehrhovey | 0:a548a085de55 | 1018 | /* Send output to IP */ |
pehrhovey | 0:a548a085de55 | 1019 | #if LWIP_NETIF_HWADDRHINT |
pehrhovey | 0:a548a085de55 | 1020 | ip_output_hinted(p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, 0, IP_PROTO_TCP, |
pehrhovey | 0:a548a085de55 | 1021 | &(pcb->addr_hint)); |
pehrhovey | 0:a548a085de55 | 1022 | #else /* LWIP_NETIF_HWADDRHINT*/ |
pehrhovey | 0:a548a085de55 | 1023 | ip_output(p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, 0, IP_PROTO_TCP); |
pehrhovey | 0:a548a085de55 | 1024 | #endif /* LWIP_NETIF_HWADDRHINT*/ |
pehrhovey | 0:a548a085de55 | 1025 | |
pehrhovey | 0:a548a085de55 | 1026 | pbuf_free(p); |
pehrhovey | 0:a548a085de55 | 1027 | |
pehrhovey | 0:a548a085de55 | 1028 | LWIP_DEBUGF(TCP_DEBUG, ("tcp_zero_window_probe: seqno %"U32_F |
pehrhovey | 0:a548a085de55 | 1029 | " ackno %"U32_F".\n", |
pehrhovey | 0:a548a085de55 | 1030 | pcb->snd_nxt - 1, pcb->rcv_nxt)); |
pehrhovey | 0:a548a085de55 | 1031 | } |
pehrhovey | 0:a548a085de55 | 1032 | #endif /* LWIP_TCP */ |