linux-old/net/ipv4/tcp_output.c
<<
>>
Prefs
   1/*
   2 * INET         An implementation of the TCP/IP protocol suite for the LINUX
   3 *              operating system.  INET is implemented using the  BSD Socket
   4 *              interface as the means of communication with the user level.
   5 *
   6 *              Implementation of the Transmission Control Protocol(TCP).
   7 *
   8 * Version:     $Id: tcp_output.c,v 1.106 1999/03/12 03:43:51 davem Exp $
   9 *
  10 * Authors:     Ross Biro, <bir7@leland.Stanford.Edu>
  11 *              Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  12 *              Mark Evans, <evansmp@uhura.aston.ac.uk>
  13 *              Corey Minyard <wf-rch!minyard@relay.EU.net>
  14 *              Florian La Roche, <flla@stud.uni-sb.de>
  15 *              Charles Hedrick, <hedrick@klinzhai.rutgers.edu>
  16 *              Linus Torvalds, <torvalds@cs.helsinki.fi>
  17 *              Alan Cox, <gw4pts@gw4pts.ampr.org>
  18 *              Matthew Dillon, <dillon@apollo.west.oic.com>
  19 *              Arnt Gulbrandsen, <agulbra@nvg.unit.no>
  20 *              Jorge Cwik, <jorge@laser.satlink.net>
  21 */
  22
  23/*
  24 * Changes:     Pedro Roque     :       Retransmit queue handled by TCP.
  25 *                              :       Fragmentation on mtu decrease
  26 *                              :       Segment collapse on retransmit
  27 *                              :       AF independence
  28 *
  29 *              Linus Torvalds  :       send_delayed_ack
  30 *              David S. Miller :       Charge memory using the right skb
  31 *                                      during syn/ack processing.
  32 *              David S. Miller :       Output engine completely rewritten.
  33 *              Andrea Arcangeli:       SYNACK carry ts_recent in tsecr.
  34 *
  35 */
  36
  37#include <net/tcp.h>
  38
  39extern int sysctl_tcp_timestamps;
  40extern int sysctl_tcp_window_scaling;
  41extern int sysctl_tcp_sack;
  42
  43/* People can turn this off for buggy TCP's found in printers etc. */
  44int sysctl_tcp_retrans_collapse = 1;
  45
  46/* Get rid of any delayed acks, we sent one already.. */
  47static __inline__ void clear_delayed_acks(struct sock * sk)
  48{
  49        struct tcp_opt *tp = &(sk->tp_pinfo.af_tcp);
  50
  51        tp->delayed_acks = 0;
  52        if(tcp_in_quickack_mode(tp))
  53                tcp_exit_quickack_mode(tp);
  54        tcp_clear_xmit_timer(sk, TIME_DACK);
  55}
  56
  57static __inline__ void update_send_head(struct sock *sk)
  58{
  59        struct tcp_opt *tp = &sk->tp_pinfo.af_tcp;
  60        
  61        tp->send_head = tp->send_head->next;
  62        if (tp->send_head == (struct sk_buff *) &sk->write_queue)
  63                tp->send_head = NULL;
  64}
  65
  66/* This routine actually transmits TCP packets queued in by
  67 * tcp_do_sendmsg().  This is used by both the initial
  68 * transmission and possible later retransmissions.
  69 * All SKB's seen here are completely headerless.  It is our
  70 * job to build the TCP header, and pass the packet down to
  71 * IP so it can do the same plus pass the packet off to the
  72 * device.
  73 *
  74 * We are working here with either a clone of the original
  75 * SKB, or a fresh unique copy made by the retransmit engine.
  76 */
  77void tcp_transmit_skb(struct sock *sk, struct sk_buff *skb)
  78{
  79        if(skb != NULL) {
  80                struct tcp_opt *tp = &(sk->tp_pinfo.af_tcp);
  81                struct tcp_skb_cb *tcb = TCP_SKB_CB(skb);
  82                int tcp_header_size = tp->tcp_header_len;
  83                struct tcphdr *th;
  84                int sysctl_flags;
  85
  86#define SYSCTL_FLAG_TSTAMPS     0x1
  87#define SYSCTL_FLAG_WSCALE      0x2
  88#define SYSCTL_FLAG_SACK        0x4
  89
  90                sysctl_flags = 0;
  91                if(tcb->flags & TCPCB_FLAG_SYN) {
  92                        tcp_header_size = sizeof(struct tcphdr) + TCPOLEN_MSS;
  93                        if(sysctl_tcp_timestamps) {
  94                                tcp_header_size += TCPOLEN_TSTAMP_ALIGNED;
  95                                sysctl_flags |= SYSCTL_FLAG_TSTAMPS;
  96                        }
  97                        if(sysctl_tcp_window_scaling) {
  98                                tcp_header_size += TCPOLEN_WSCALE_ALIGNED;
  99                                sysctl_flags |= SYSCTL_FLAG_WSCALE;
 100                        }
 101                        if(sysctl_tcp_sack) {
 102                                sysctl_flags |= SYSCTL_FLAG_SACK;
 103                                if(!(sysctl_flags & SYSCTL_FLAG_TSTAMPS))
 104                                        tcp_header_size += TCPOLEN_SACKPERM_ALIGNED;
 105                        }
 106                } else if(tp->sack_ok && tp->num_sacks) {
 107                        /* A SACK is 2 pad bytes, a 2 byte header, plus
 108                         * 2 32-bit sequence numbers for each SACK block.
 109                         */
 110                        tcp_header_size += (TCPOLEN_SACK_BASE_ALIGNED +
 111                                            (tp->num_sacks * TCPOLEN_SACK_PERBLOCK));
 112                }
 113                th = (struct tcphdr *) skb_push(skb, tcp_header_size);
 114                skb->h.th = th;
 115                skb_set_owner_w(skb, sk);
 116
 117                /* Build TCP header and checksum it. */
 118                th->source              = sk->sport;
 119                th->dest                = sk->dport;
 120                th->seq                 = htonl(TCP_SKB_CB(skb)->seq);
 121                th->ack_seq             = htonl(tp->rcv_nxt);
 122                th->doff                = (tcp_header_size >> 2);
 123                th->res1                = 0;
 124                *(((__u8 *)th) + 13)    = tcb->flags;
 125                if(!(tcb->flags & TCPCB_FLAG_SYN))
 126                        th->window      = htons(tcp_select_window(sk));
 127                th->check               = 0;
 128                th->urg_ptr             = ntohs(tcb->urg_ptr);
 129                if(tcb->flags & TCPCB_FLAG_SYN) {
 130                        /* RFC1323: The window in SYN & SYN/ACK segments
 131                         * is never scaled.
 132                         */
 133                        th->window      = htons(tp->rcv_wnd);
 134                        tcp_syn_build_options((__u32 *)(th + 1), tp->mss_clamp,
 135                                              (sysctl_flags & SYSCTL_FLAG_TSTAMPS),
 136                                              (sysctl_flags & SYSCTL_FLAG_SACK),
 137                                              (sysctl_flags & SYSCTL_FLAG_WSCALE),
 138                                              tp->rcv_wscale,
 139                                              TCP_SKB_CB(skb)->when,
 140                                              tp->ts_recent);
 141                } else {
 142                        tcp_build_and_update_options((__u32 *)(th + 1),
 143                                                     tp, TCP_SKB_CB(skb)->when);
 144                }
 145                tp->af_specific->send_check(sk, th, skb->len, skb);
 146
 147                clear_delayed_acks(sk);
 148                tp->last_ack_sent = tp->rcv_nxt;
 149                tcp_statistics.TcpOutSegs++;
 150                tp->af_specific->queue_xmit(skb);
 151        }
 152#undef SYSCTL_FLAG_TSTAMPS
 153#undef SYSCTL_FLAG_WSCALE
 154#undef SYSCTL_FLAG_SACK
 155}
 156
 157/* This is the main buffer sending routine. We queue the buffer
 158 * and decide whether to queue or transmit now.
 159 */
 160void tcp_send_skb(struct sock *sk, struct sk_buff *skb, int force_queue)
 161{
 162        struct tcp_opt *tp = &(sk->tp_pinfo.af_tcp);
 163
 164        /* Advance write_seq and place onto the write_queue. */
 165        tp->write_seq += (TCP_SKB_CB(skb)->end_seq - TCP_SKB_CB(skb)->seq);
 166        __skb_queue_tail(&sk->write_queue, skb);
 167
 168        if (!force_queue && tp->send_head == NULL && tcp_snd_test(sk, skb)) {
 169                /* Send it out now. */
 170                TCP_SKB_CB(skb)->when = jiffies;
 171                tp->snd_nxt = TCP_SKB_CB(skb)->end_seq;
 172                tp->packets_out++;
 173                tcp_transmit_skb(sk, skb_clone(skb, GFP_KERNEL));
 174                if(!tcp_timer_is_set(sk, TIME_RETRANS))
 175                        tcp_reset_xmit_timer(sk, TIME_RETRANS, tp->rto);
 176        } else {
 177                /* Queue it, remembering where we must start sending. */
 178                if (tp->send_head == NULL)
 179                        tp->send_head = skb;
 180                if (!force_queue && tp->packets_out == 0 && !tp->pending) {
 181                        tp->pending = TIME_PROBE0;
 182                        tcp_reset_xmit_timer(sk, TIME_PROBE0, tp->rto);
 183                }
 184        }
 185}
 186
 187/* Function to create two new TCP segments.  Shrinks the given segment
 188 * to the specified size and appends a new segment with the rest of the
 189 * packet to the list.  This won't be called frequently, I hope. 
 190 * Remember, these are still headerless SKBs at this point.
 191 */
 192static int tcp_fragment(struct sock *sk, struct sk_buff *skb, u32 len)
 193{
 194        struct sk_buff *buff;
 195        int nsize = skb->len - len;
 196        u16 flags;
 197
 198        /* Get a new skb... force flag on. */
 199        buff = sock_wmalloc(sk,
 200                            (nsize + MAX_HEADER + sk->prot->max_header),
 201                            1, GFP_ATOMIC);
 202        if (buff == NULL)
 203                return -1; /* We'll just try again later. */
 204
 205        /* Reserve space for headers. */
 206        skb_reserve(buff, MAX_HEADER + sk->prot->max_header);
 207                
 208        /* Correct the sequence numbers. */
 209        TCP_SKB_CB(buff)->seq = TCP_SKB_CB(skb)->seq + len;
 210        TCP_SKB_CB(buff)->end_seq = TCP_SKB_CB(skb)->end_seq;
 211        
 212        /* PSH and FIN should only be set in the second packet. */
 213        flags = TCP_SKB_CB(skb)->flags;
 214        TCP_SKB_CB(skb)->flags = flags & ~(TCPCB_FLAG_FIN | TCPCB_FLAG_PSH);
 215        if(flags & TCPCB_FLAG_URG) {
 216                u16 old_urg_ptr = TCP_SKB_CB(skb)->urg_ptr;
 217
 218                /* Urgent data is always a pain in the ass. */
 219                if(old_urg_ptr > len) {
 220                        TCP_SKB_CB(skb)->flags &= ~(TCPCB_FLAG_URG);
 221                        TCP_SKB_CB(skb)->urg_ptr = 0;
 222                        TCP_SKB_CB(buff)->urg_ptr = old_urg_ptr - len;
 223                } else {
 224                        flags &= ~(TCPCB_FLAG_URG);
 225                }
 226        }
 227        if(!(flags & TCPCB_FLAG_URG))
 228                TCP_SKB_CB(buff)->urg_ptr = 0;
 229        TCP_SKB_CB(buff)->flags = flags;
 230        TCP_SKB_CB(buff)->sacked = 0;
 231
 232        /* Copy and checksum data tail into the new buffer. */
 233        buff->csum = csum_partial_copy(skb->data + len, skb_put(buff, nsize),
 234                                       nsize, 0);
 235
 236        /* This takes care of the FIN sequence number too. */
 237        TCP_SKB_CB(skb)->end_seq = TCP_SKB_CB(buff)->seq;
 238        skb_trim(skb, len);
 239
 240        /* Rechecksum original buffer. */
 241        skb->csum = csum_partial(skb->data, skb->len, 0);
 242
 243        /* Link BUFF into the send queue. */
 244        __skb_append(skb, buff);
 245
 246        return 0;
 247}
 248
 249/* This function synchronize snd mss to current pmtu/exthdr set.
 250
 251   tp->user_mss is mss set by user by TCP_MAXSEG. It does NOT counts
 252   for TCP options, but includes only bare TCP header.
 253
 254   tp->mss_clamp is mss negotiated at connection setup.
 255   It is minumum of user_mss and mss received with SYN.
 256   It also does not include TCP options.
 257
 258   tp->pmtu_cookie is last pmtu, seen by this function.
 259
 260   tp->mss_cache is current effective sending mss, including
 261   all tcp options except for SACKs. It is evaluated,
 262   taking into account current pmtu, but never exceeds
 263   tp->mss_clamp.
 264
 265   NOTE1. rfc1122 clearly states that advertised MSS
 266   DOES NOT include either tcp or ip options.
 267
 268   NOTE2. tp->pmtu_cookie and tp->mss_cache are READ ONLY outside
 269   this function.                       --ANK (980731)
 270 */
 271
 272int tcp_sync_mss(struct sock *sk, u32 pmtu)
 273{
 274        struct tcp_opt *tp = &sk->tp_pinfo.af_tcp;
 275        int mss_now;
 276
 277        /* Calculate base mss without TCP options:
 278           It is MMS_S - sizeof(tcphdr) of rfc1122
 279        */
 280        mss_now = pmtu - tp->af_specific->net_header_len - sizeof(struct tcphdr);
 281
 282        /* Clamp it (mss_clamp does not include tcp options) */
 283        if (mss_now > tp->mss_clamp)
 284                mss_now = tp->mss_clamp;
 285
 286        /* Now subtract TCP options size, not including SACKs */
 287        mss_now -= tp->tcp_header_len - sizeof(struct tcphdr);
 288
 289        /* Now subtract optional transport overhead */
 290        mss_now -= tp->ext_header_len;
 291
 292        /* It we got too small (or even negative) value,
 293           clamp it by 8 from below. Why 8 ?
 294           Well, it could be 1 with the same success,
 295           but if IP accepted segment of length 1,
 296           it would love 8 even more 8)         --ANK (980731)
 297         */
 298        if (mss_now < 8)
 299                mss_now = 8;
 300
 301        /* And store cached results */
 302        tp->pmtu_cookie = pmtu;
 303        tp->mss_cache = mss_now;
 304        return mss_now;
 305}
 306
 307
 308/* This routine writes packets to the network.  It advances the
 309 * send_head.  This happens as incoming acks open up the remote
 310 * window for us.
 311 */
 312void tcp_write_xmit(struct sock *sk)
 313{
 314        struct tcp_opt *tp = &(sk->tp_pinfo.af_tcp);
 315        unsigned int mss_now;
 316
 317        /* Account for SACKS, we may need to fragment due to this.
 318         * It is just like the real MSS changing on us midstream.
 319         * We also handle things correctly when the user adds some
 320         * IP options mid-stream.  Silly to do, but cover it.
 321         */
 322        mss_now = tcp_current_mss(sk); 
 323
 324        /* If we are zapped, the bytes will have to remain here.
 325         * In time closedown will empty the write queue and all
 326         * will be happy.
 327         */
 328        if(!sk->zapped) {
 329                struct sk_buff *skb;
 330                int sent_pkts = 0;
 331
 332                /* Anything on the transmit queue that fits the window can
 333                 * be added providing we are:
 334                 *
 335                 * a) following SWS avoidance [and Nagle algorithm]
 336                 * b) not exceeding our congestion window.
 337                 * c) not retransmitting [Nagle]
 338                 */
 339                while((skb = tp->send_head) && tcp_snd_test(sk, skb)) {
 340                        if (skb->len > mss_now) {
 341                                if (tcp_fragment(sk, skb, mss_now))
 342                                        break;
 343                        }
 344
 345                        /* Advance the send_head.  This one is going out. */
 346                        update_send_head(sk);
 347                        TCP_SKB_CB(skb)->when = jiffies;
 348                        tp->snd_nxt = TCP_SKB_CB(skb)->end_seq;
 349                        tp->packets_out++;
 350                        tcp_transmit_skb(sk, skb_clone(skb, GFP_ATOMIC));
 351                        sent_pkts = 1;
 352                }
 353
 354                /* If we sent anything, make sure the retransmit
 355                 * timer is active.
 356                 */
 357                if (sent_pkts && !tcp_timer_is_set(sk, TIME_RETRANS))
 358                        tcp_reset_xmit_timer(sk, TIME_RETRANS, tp->rto);
 359        }
 360}
 361
 362/* This function returns the amount that we can raise the
 363 * usable window based on the following constraints
 364 *  
 365 * 1. The window can never be shrunk once it is offered (RFC 793)
 366 * 2. We limit memory per socket
 367 *
 368 * RFC 1122:
 369 * "the suggested [SWS] avoidance algorithm for the receiver is to keep
 370 *  RECV.NEXT + RCV.WIN fixed until:
 371 *  RCV.BUFF - RCV.USER - RCV.WINDOW >= min(1/2 RCV.BUFF, MSS)"
 372 *
 373 * i.e. don't raise the right edge of the window until you can raise
 374 * it at least MSS bytes.
 375 *
 376 * Unfortunately, the recommended algorithm breaks header prediction,
 377 * since header prediction assumes th->window stays fixed.
 378 *
 379 * Strictly speaking, keeping th->window fixed violates the receiver
 380 * side SWS prevention criteria. The problem is that under this rule
 381 * a stream of single byte packets will cause the right side of the
 382 * window to always advance by a single byte.
 383 * 
 384 * Of course, if the sender implements sender side SWS prevention
 385 * then this will not be a problem.
 386 * 
 387 * BSD seems to make the following compromise:
 388 * 
 389 *      If the free space is less than the 1/4 of the maximum
 390 *      space available and the free space is less than 1/2 mss,
 391 *      then set the window to 0.
 392 *      Otherwise, just prevent the window from shrinking
 393 *      and from being larger than the largest representable value.
 394 *
 395 * This prevents incremental opening of the window in the regime
 396 * where TCP is limited by the speed of the reader side taking
 397 * data out of the TCP receive queue. It does nothing about
 398 * those cases where the window is constrained on the sender side
 399 * because the pipeline is full.
 400 *
 401 * BSD also seems to "accidentally" limit itself to windows that are a
 402 * multiple of MSS, at least until the free space gets quite small.
 403 * This would appear to be a side effect of the mbuf implementation.
 404 * Combining these two algorithms results in the observed behavior
 405 * of having a fixed window size at almost all times.
 406 *
 407 * Below we obtain similar behavior by forcing the offered window to
 408 * a multiple of the mss when it is feasible to do so.
 409 *
 410 * Note, we don't "adjust" for TIMESTAMP or SACK option bytes.
 411 */
 412u32 __tcp_select_window(struct sock *sk)
 413{
 414        struct tcp_opt *tp = &sk->tp_pinfo.af_tcp;
 415        unsigned int mss = tp->mss_cache;
 416        int free_space;
 417        u32 window;
 418
 419        /* Sometimes free_space can be < 0. */
 420        free_space = (sk->rcvbuf - atomic_read(&sk->rmem_alloc)) / 2;
 421        if (tp->window_clamp) {
 422                if (free_space > ((int) tp->window_clamp))
 423                        free_space = tp->window_clamp;
 424                mss = min(tp->window_clamp, mss);
 425        } else {
 426                printk("tcp_select_window: tp->window_clamp == 0.\n");
 427        }
 428
 429        if (mss < 1) {
 430                mss = 1;
 431                printk("tcp_select_window: sk->mss fell to 0.\n");
 432        }
 433        
 434        if ((free_space < (sk->rcvbuf/4)) && (free_space < ((int) (mss/2)))) {
 435                window = 0;
 436                tp->pred_flags = 0; 
 437        } else {
 438                /* Get the largest window that is a nice multiple of mss.
 439                 * Window clamp already applied above.
 440                 * If our current window offering is within 1 mss of the
 441                 * free space we just keep it. This prevents the divide
 442                 * and multiply from happening most of the time.
 443                 * We also don't do any window rounding when the free space
 444                 * is too small.
 445                 */
 446                window = tp->rcv_wnd;
 447                if ((((int) window) <= (free_space - ((int) mss))) ||
 448                                (((int) window) > free_space))
 449                        window = (((unsigned int) free_space)/mss)*mss;
 450        }
 451        return window;
 452}
 453
 454/* Attempt to collapse two adjacent SKB's during retransmission. */
 455static void tcp_retrans_try_collapse(struct sock *sk, struct sk_buff *skb, int mss_now)
 456{
 457        struct sk_buff *next_skb = skb->next;
 458
 459        /* The first test we must make is that neither of these two
 460         * SKB's are still referenced by someone else.
 461         */
 462        if(!skb_cloned(skb) && !skb_cloned(next_skb)) {
 463                int skb_size = skb->len, next_skb_size = next_skb->len;
 464                u16 flags = TCP_SKB_CB(skb)->flags;
 465
 466                /* Punt if the first SKB has URG set. */
 467                if(flags & TCPCB_FLAG_URG)
 468                        return;
 469        
 470                /* Also punt if next skb has been SACK'd. */
 471                if(TCP_SKB_CB(next_skb)->sacked & TCPCB_SACKED_ACKED)
 472                        return;
 473
 474                /* Punt if not enough space exists in the first SKB for
 475                 * the data in the second, or the total combined payload
 476                 * would exceed the MSS.
 477                 */
 478                if ((next_skb_size > skb_tailroom(skb)) ||
 479                    ((skb_size + next_skb_size) > mss_now))
 480                        return;
 481
 482                /* Ok.  We will be able to collapse the packet. */
 483                __skb_unlink(next_skb, next_skb->list);
 484
 485                if(skb->len % 4) {
 486                        /* Must copy and rechecksum all data. */
 487                        memcpy(skb_put(skb, next_skb_size), next_skb->data, next_skb_size);
 488                        skb->csum = csum_partial(skb->data, skb->len, 0);
 489                } else {
 490                        /* Optimize, actually we could also combine next_skb->csum
 491                         * to skb->csum using a single add w/carry operation too.
 492                         */
 493                        skb->csum = csum_partial_copy(next_skb->data,
 494                                                      skb_put(skb, next_skb_size),
 495                                                      next_skb_size, skb->csum);
 496                }
 497        
 498                /* Update sequence range on original skb. */
 499                TCP_SKB_CB(skb)->end_seq = TCP_SKB_CB(next_skb)->end_seq;
 500
 501                /* Merge over control information. */
 502                flags |= TCP_SKB_CB(next_skb)->flags; /* This moves PSH/FIN etc. over */
 503                if(flags & TCPCB_FLAG_URG) {
 504                        u16 urgptr = TCP_SKB_CB(next_skb)->urg_ptr;
 505                        TCP_SKB_CB(skb)->urg_ptr = urgptr + skb_size;
 506                }
 507                TCP_SKB_CB(skb)->flags = flags;
 508
 509                /* All done, get rid of second SKB and account for it so
 510                 * packet counting does not break.
 511                 */
 512                kfree_skb(next_skb);
 513                sk->tp_pinfo.af_tcp.packets_out--;
 514        }
 515}
 516
 517/* Do a simple retransmit without using the backoff mechanisms in
 518 * tcp_timer. This is used for path mtu discovery. 
 519 * The socket is already locked here.
 520 */ 
 521void tcp_simple_retransmit(struct sock *sk)
 522{
 523        struct tcp_opt *tp = &(sk->tp_pinfo.af_tcp);
 524        struct sk_buff *skb; 
 525        unsigned int mss = tcp_current_mss(sk); 
 526
 527        /* Don't muck with the congestion window here. */
 528        tp->dup_acks = 0;
 529        tp->high_seq = tp->snd_nxt;
 530        tp->retrans_head = NULL; 
 531
 532        /* Input control flow will see that this was retransmitted
 533         * and not use it for RTT calculation in the absence of
 534         * the timestamp option.
 535         */
 536        for (skb = skb_peek(&sk->write_queue);
 537             ((skb != tp->send_head) &&
 538              (skb != (struct sk_buff *)&sk->write_queue));
 539             skb = skb->next) 
 540                if (skb->len > mss)
 541                        tcp_retransmit_skb(sk, skb); 
 542}
 543
 544static __inline__ void update_retrans_head(struct sock *sk)
 545{
 546        struct tcp_opt *tp = &sk->tp_pinfo.af_tcp;
 547        
 548        tp->retrans_head = tp->retrans_head->next;
 549        if((tp->retrans_head == tp->send_head) ||
 550           (tp->retrans_head == (struct sk_buff *) &sk->write_queue)) {
 551                tp->retrans_head = NULL;
 552                tp->rexmt_done = 1;
 553        }
 554}
 555
 556/* This retransmits one SKB.  Policy decisions and retransmit queue
 557 * state updates are done by the caller.  Returns non-zero if an
 558 * error occurred which prevented the send.
 559 */
 560int tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb)
 561{
 562        struct tcp_opt *tp = &(sk->tp_pinfo.af_tcp);
 563        unsigned int cur_mss = tcp_current_mss(sk);
 564
 565        if(skb->len > cur_mss) {
 566                if(tcp_fragment(sk, skb, cur_mss))
 567                        return 1; /* We'll try again later. */
 568
 569                /* New SKB created, account for it. */
 570                tp->packets_out++;
 571        }
 572
 573        /* Collapse two adjacent packets if worthwhile and we can. */
 574        if(!(TCP_SKB_CB(skb)->flags & TCPCB_FLAG_SYN) &&
 575           (skb->len < (cur_mss >> 1)) &&
 576           (skb->next != tp->send_head) &&
 577           (skb->next != (struct sk_buff *)&sk->write_queue) &&
 578           (sysctl_tcp_retrans_collapse != 0))
 579                tcp_retrans_try_collapse(sk, skb, cur_mss);
 580
 581        if(tp->af_specific->rebuild_header(sk))
 582                return 1; /* Routing failure or similar. */
 583
 584        /* Some Solaris stacks overoptimize and ignore the FIN on a
 585         * retransmit when old data is attached.  So strip it off
 586         * since it is cheap to do so and saves bytes on the network.
 587         */
 588        if(skb->len > 0 &&
 589           (TCP_SKB_CB(skb)->flags & TCPCB_FLAG_FIN) &&
 590           tp->snd_una == (TCP_SKB_CB(skb)->end_seq - 1)) {
 591                TCP_SKB_CB(skb)->seq = TCP_SKB_CB(skb)->end_seq - 1;
 592                skb_trim(skb, 0);
 593                skb->csum = 0;
 594        }
 595
 596        /* Ok, we're gonna send it out, update state. */
 597        TCP_SKB_CB(skb)->sacked |= TCPCB_SACKED_RETRANS;
 598        tp->retrans_out++;
 599
 600        /* Make a copy, if the first transmission SKB clone we made
 601         * is still in somebody's hands, else make a clone.
 602         */
 603        TCP_SKB_CB(skb)->when = jiffies;
 604        if(skb_cloned(skb))
 605                skb = skb_copy(skb, GFP_ATOMIC);
 606        else
 607                skb = skb_clone(skb, GFP_ATOMIC);
 608
 609        tcp_transmit_skb(sk, skb);
 610
 611        /* Update global TCP statistics and return success. */
 612        sk->prot->retransmits++;
 613        tcp_statistics.TcpRetransSegs++;
 614
 615        return 0;
 616}
 617
 618/* This gets called after a retransmit timeout, and the initially
 619 * retransmitted data is acknowledged.  It tries to continue
 620 * resending the rest of the retransmit queue, until either
 621 * we've sent it all or the congestion window limit is reached.
 622 * If doing SACK, the first ACK which comes back for a timeout
 623 * based retransmit packet might feed us FACK information again.
 624 * If so, we use it to avoid unnecessarily retransmissions.
 625 */
 626void tcp_xmit_retransmit_queue(struct sock *sk)
 627{
 628        struct tcp_opt *tp = &(sk->tp_pinfo.af_tcp);
 629        struct sk_buff *skb;
 630
 631        if (tp->retrans_head == NULL &&
 632            tp->rexmt_done == 0)
 633                tp->retrans_head = skb_peek(&sk->write_queue);
 634        if (tp->retrans_head == tp->send_head)
 635                tp->retrans_head = NULL;
 636
 637        /* Each time, advance the retrans_head if we got
 638         * a packet out or we skipped one because it was
 639         * SACK'd.  -DaveM
 640         */
 641        while ((skb = tp->retrans_head) != NULL) {
 642                /* If it has been ack'd by a SACK block, we don't
 643                 * retransmit it.
 644                 */
 645                if(!(TCP_SKB_CB(skb)->sacked & TCPCB_SACKED_ACKED)) {
 646                        /* Send it out, punt if error occurred. */
 647                        if(tcp_retransmit_skb(sk, skb))
 648                                break;
 649
 650                        update_retrans_head(sk);
 651                
 652                        /* Stop retransmitting if we've hit the congestion
 653                         * window limit.
 654                         */
 655                        if (tp->retrans_out >= tp->snd_cwnd)
 656                                break;
 657                } else {
 658                        update_retrans_head(sk);
 659                }
 660        }
 661}
 662
 663/* Using FACK information, retransmit all missing frames at the receiver
 664 * up to the forward most SACK'd packet (tp->fackets_out) if the packet
 665 * has not been retransmitted already.
 666 */
 667void tcp_fack_retransmit(struct sock *sk)
 668{
 669        struct tcp_opt *tp = &(sk->tp_pinfo.af_tcp);
 670        struct sk_buff *skb = skb_peek(&sk->write_queue);
 671        int packet_cnt = 0;
 672
 673        while((skb != NULL) &&
 674              (skb != tp->send_head) &&
 675              (skb != (struct sk_buff *)&sk->write_queue)) {
 676                __u8 sacked = TCP_SKB_CB(skb)->sacked;
 677
 678                if(sacked & (TCPCB_SACKED_ACKED | TCPCB_SACKED_RETRANS))
 679                        goto next_packet;
 680
 681                /* Ok, retransmit it. */
 682                if(tcp_retransmit_skb(sk, skb))
 683                        break;
 684
 685                if(tcp_packets_in_flight(tp) >= tp->snd_cwnd)
 686                        break;
 687next_packet:
 688                packet_cnt++;
 689                if(packet_cnt >= tp->fackets_out)
 690                        break;
 691                skb = skb->next;
 692        }
 693}
 694
 695/* Send a fin.  The caller locks the socket for us.  This cannot be
 696 * allowed to fail queueing a FIN frame under any circumstances.
 697 */
 698void tcp_send_fin(struct sock *sk)
 699{
 700        struct tcp_opt *tp = &(sk->tp_pinfo.af_tcp);    
 701        struct sk_buff *skb = skb_peek_tail(&sk->write_queue);
 702        unsigned int mss_now;
 703        
 704        /* Optimization, tack on the FIN if we have a queue of
 705         * unsent frames.  But be careful about outgoing SACKS
 706         * and IP options.
 707         */
 708        mss_now = tcp_current_mss(sk); 
 709
 710        if((tp->send_head != NULL) && (skb->len < mss_now)) {
 711                /* tcp_write_xmit() takes care of the rest. */
 712                TCP_SKB_CB(skb)->flags |= TCPCB_FLAG_FIN;
 713                TCP_SKB_CB(skb)->end_seq++;
 714                tp->write_seq++;
 715
 716                /* Special case to avoid Nagle bogosity.  If this
 717                 * segment is the last segment, and it was queued
 718                 * due to Nagle/SWS-avoidance, send it out now.
 719                 */
 720                if(tp->send_head == skb &&
 721                   !sk->nonagle &&
 722                   skb->len < (tp->mss_cache >> 1) &&
 723                   tp->packets_out &&
 724                   !(TCP_SKB_CB(skb)->flags & TCPCB_FLAG_URG)) {
 725                        update_send_head(sk);
 726                        TCP_SKB_CB(skb)->when = jiffies;
 727                        tp->snd_nxt = TCP_SKB_CB(skb)->end_seq;
 728                        tp->packets_out++;
 729                        tcp_transmit_skb(sk, skb_clone(skb, GFP_ATOMIC));
 730                        if(!tcp_timer_is_set(sk, TIME_RETRANS))
 731                                tcp_reset_xmit_timer(sk, TIME_RETRANS, tp->rto);
 732                }
 733        } else {
 734                /* Socket is locked, keep trying until memory is available. */
 735                do {
 736                        skb = sock_wmalloc(sk,
 737                                           (MAX_HEADER +
 738                                            sk->prot->max_header),
 739                                           1, GFP_KERNEL);
 740                } while (skb == NULL);
 741
 742                /* Reserve space for headers and prepare control bits. */
 743                skb_reserve(skb, MAX_HEADER + sk->prot->max_header);
 744                skb->csum = 0;
 745                TCP_SKB_CB(skb)->flags = (TCPCB_FLAG_ACK | TCPCB_FLAG_FIN);
 746                TCP_SKB_CB(skb)->sacked = 0;
 747                TCP_SKB_CB(skb)->urg_ptr = 0;
 748
 749                /* FIN eats a sequence byte, write_seq advanced by tcp_send_skb(). */
 750                TCP_SKB_CB(skb)->seq = tp->write_seq;
 751                TCP_SKB_CB(skb)->end_seq = TCP_SKB_CB(skb)->seq + 1;
 752                tcp_send_skb(sk, skb, 0);
 753        }
 754}
 755
 756/* We get here when a process closes a file descriptor (either due to
 757 * an explicit close() or as a byproduct of exit()'ing) and there
 758 * was unread data in the receive queue.  This behavior is recommended
 759 * by draft-ietf-tcpimpl-prob-03.txt section 3.10.  -DaveM
 760 */
 761void tcp_send_active_reset(struct sock *sk)
 762{
 763        struct tcp_opt *tp = &(sk->tp_pinfo.af_tcp);
 764        struct sk_buff *skb;
 765
 766        /* NOTE: No TCP options attached and we never retransmit this. */
 767        skb = alloc_skb(MAX_HEADER + sk->prot->max_header, GFP_KERNEL);
 768        if (!skb)
 769                return;
 770
 771        /* Reserve space for headers and prepare control bits. */
 772        skb_reserve(skb, MAX_HEADER + sk->prot->max_header);
 773        skb->csum = 0;
 774        TCP_SKB_CB(skb)->flags = (TCPCB_FLAG_ACK | TCPCB_FLAG_RST);
 775        TCP_SKB_CB(skb)->sacked = 0;
 776        TCP_SKB_CB(skb)->urg_ptr = 0;
 777
 778        /* Send it off. */
 779        TCP_SKB_CB(skb)->seq = tp->write_seq;
 780        TCP_SKB_CB(skb)->end_seq = TCP_SKB_CB(skb)->seq;
 781        TCP_SKB_CB(skb)->when = jiffies;
 782        tcp_transmit_skb(sk, skb);
 783}
 784
 785/* WARNING: This routine must only be called when we have already sent
 786 * a SYN packet that crossed the incoming SYN that caused this routine
 787 * to get called. If this assumption fails then the initial rcv_wnd
 788 * and rcv_wscale values will not be correct.
 789 */
 790int tcp_send_synack(struct sock *sk)
 791{
 792        struct tcp_opt* tp = &(sk->tp_pinfo.af_tcp);
 793        struct sk_buff* skb;    
 794        
 795        skb = sock_wmalloc(sk, (MAX_HEADER + sk->prot->max_header),
 796                           1, GFP_ATOMIC);
 797        if (skb == NULL) 
 798                return -ENOMEM;
 799
 800        /* Reserve space for headers and prepare control bits. */
 801        skb_reserve(skb, MAX_HEADER + sk->prot->max_header);
 802        skb->csum = 0;
 803        TCP_SKB_CB(skb)->flags = (TCPCB_FLAG_ACK | TCPCB_FLAG_SYN);
 804        TCP_SKB_CB(skb)->sacked = 0;
 805        TCP_SKB_CB(skb)->urg_ptr = 0;
 806
 807        /* SYN eats a sequence byte. */
 808        TCP_SKB_CB(skb)->seq = tp->snd_una;
 809        TCP_SKB_CB(skb)->end_seq = TCP_SKB_CB(skb)->seq + 1;
 810        __skb_queue_tail(&sk->write_queue, skb);
 811        TCP_SKB_CB(skb)->when = jiffies;
 812        tp->packets_out++;
 813        tcp_transmit_skb(sk, skb_clone(skb, GFP_ATOMIC));
 814        return 0;
 815}
 816
 817/*
 818 * Prepare a SYN-ACK.
 819 */
 820struct sk_buff * tcp_make_synack(struct sock *sk, struct dst_entry *dst,
 821                                 struct open_request *req, int mss)
 822{
 823        struct tcphdr *th;
 824        int tcp_header_size;
 825        struct sk_buff *skb;
 826
 827        skb = sock_wmalloc(sk, MAX_HEADER + sk->prot->max_header, 1, GFP_ATOMIC);
 828        if (skb == NULL)
 829                return NULL;
 830
 831        /* Reserve space for headers. */
 832        skb_reserve(skb, MAX_HEADER + sk->prot->max_header);
 833
 834        skb->dst = dst_clone(dst);
 835
 836        /* Don't offer more than they did.
 837         * This way we don't have to memorize who said what.
 838         * FIXME: maybe this should be changed for better performance
 839         * with syncookies.
 840         */
 841        req->mss = min(mss, req->mss);
 842        if (req->mss < 8) {
 843                printk(KERN_DEBUG "initial req->mss below 8\n");
 844                req->mss = 8;
 845        }
 846
 847        tcp_header_size = (sizeof(struct tcphdr) + TCPOLEN_MSS +
 848                           (req->tstamp_ok ? TCPOLEN_TSTAMP_ALIGNED : 0) +
 849                           (req->wscale_ok ? TCPOLEN_WSCALE_ALIGNED : 0) +
 850                           /* SACK_PERM is in the place of NOP NOP of TS */
 851                           ((req->sack_ok && !req->tstamp_ok) ? TCPOLEN_SACKPERM_ALIGNED : 0));
 852        skb->h.th = th = (struct tcphdr *) skb_push(skb, tcp_header_size);
 853
 854        memset(th, 0, sizeof(struct tcphdr));
 855        th->syn = 1;
 856        th->ack = 1;
 857        th->source = sk->sport;
 858        th->dest = req->rmt_port;
 859        TCP_SKB_CB(skb)->seq = req->snt_isn;
 860        TCP_SKB_CB(skb)->end_seq = TCP_SKB_CB(skb)->seq + 1;
 861        th->seq = htonl(TCP_SKB_CB(skb)->seq);
 862        th->ack_seq = htonl(req->rcv_isn + 1);
 863        if (req->rcv_wnd == 0) { /* ignored for retransmitted syns */
 864                __u8 rcv_wscale; 
 865                /* Set this up on the first call only */
 866                req->window_clamp = skb->dst->window;
 867                tcp_select_initial_window(sock_rspace(sk)/2,req->mss,
 868                        &req->rcv_wnd,
 869                        &req->window_clamp,
 870                        req->wscale_ok,
 871                        &rcv_wscale);
 872                req->rcv_wscale = rcv_wscale; 
 873        }
 874
 875        /* RFC1323: The window in SYN & SYN/ACK segments is never scaled. */
 876        th->window = htons(req->rcv_wnd);
 877
 878        TCP_SKB_CB(skb)->when = jiffies;
 879        tcp_syn_build_options((__u32 *)(th + 1), req->mss, req->tstamp_ok,
 880                              req->sack_ok, req->wscale_ok, req->rcv_wscale,
 881                              TCP_SKB_CB(skb)->when,
 882                              req->ts_recent);
 883
 884        skb->csum = 0;
 885        th->doff = (tcp_header_size >> 2);
 886        tcp_statistics.TcpOutSegs++; 
 887        return skb;
 888}
 889
 890void tcp_connect(struct sock *sk, struct sk_buff *buff, int mtu)
 891{
 892        struct dst_entry *dst = sk->dst_cache;
 893        struct tcp_opt *tp = &(sk->tp_pinfo.af_tcp);
 894
 895        /* Reserve space for headers. */
 896        skb_reserve(buff, MAX_HEADER + sk->prot->max_header);
 897
 898        tp->snd_wnd = 0;
 899        tp->snd_wl1 = 0;
 900        tp->snd_wl2 = tp->write_seq;
 901        tp->snd_una = tp->write_seq;
 902        tp->rcv_nxt = 0;
 903
 904        sk->err = 0;
 905        
 906        /* We'll fix this up when we get a response from the other end.
 907         * See tcp_input.c:tcp_rcv_state_process case TCP_SYN_SENT.
 908         */
 909        tp->tcp_header_len = sizeof(struct tcphdr) +
 910                (sysctl_tcp_timestamps ? TCPOLEN_TSTAMP_ALIGNED : 0);
 911
 912        /* If user gave his TCP_MAXSEG, record it to clamp */
 913        if (tp->user_mss)
 914                tp->mss_clamp = tp->user_mss;
 915        tcp_sync_mss(sk, mtu);
 916
 917        /* Now unpleasant action: if initial pmtu is too low
 918           set lower clamp. I am not sure that it is good.
 919           To be more exact, I do not think that clamping at value, which
 920           is apparently transient and may improve in future is good idea.
 921           It would be better to wait until peer will returns its MSS
 922           (probably 65535 too) and now advertise something sort of 65535
 923           or at least first hop device mtu. Is it clear, what I mean?
 924           We should tell peer what maximal mss we expect to RECEIVE,
 925           it has nothing to do with pmtu.
 926           I am afraid someone will be confused by such huge value.
 927                                                           --ANK (980731)
 928         */
 929        if (tp->mss_cache + tp->tcp_header_len - sizeof(struct tcphdr) < tp->mss_clamp )
 930                tp->mss_clamp = tp->mss_cache + tp->tcp_header_len - sizeof(struct tcphdr);
 931
 932        TCP_SKB_CB(buff)->flags = TCPCB_FLAG_SYN;
 933        TCP_SKB_CB(buff)->sacked = 0;
 934        TCP_SKB_CB(buff)->urg_ptr = 0;
 935        buff->csum = 0;
 936        TCP_SKB_CB(buff)->seq = tp->write_seq++;
 937        TCP_SKB_CB(buff)->end_seq = tp->write_seq;
 938        tp->snd_nxt = TCP_SKB_CB(buff)->end_seq;
 939
 940        tp->window_clamp = dst->window;
 941        tcp_select_initial_window(sock_rspace(sk)/2,tp->mss_clamp,
 942                &tp->rcv_wnd,
 943                &tp->window_clamp,
 944                sysctl_tcp_window_scaling,
 945                &tp->rcv_wscale);
 946        /* Ok, now lock the socket before we make it visible to
 947         * the incoming packet engine.
 948         */
 949        lock_sock(sk);
 950
 951        /* Socket identity change complete, no longer
 952         * in TCP_CLOSE, so enter ourselves into the
 953         * hash tables.
 954         */
 955        tcp_set_state(sk,TCP_SYN_SENT);
 956        sk->prot->hash(sk);
 957
 958        tp->rto = dst->rtt;
 959        tcp_init_xmit_timers(sk);
 960        tp->retransmits = 0;
 961        tp->fackets_out = 0;
 962        tp->retrans_out = 0;
 963
 964        /* Send it off. */
 965        __skb_queue_tail(&sk->write_queue, buff);
 966        TCP_SKB_CB(buff)->when = jiffies;
 967        tp->packets_out++;
 968        tcp_transmit_skb(sk, skb_clone(buff, GFP_KERNEL));
 969        tcp_statistics.TcpActiveOpens++;
 970
 971        /* Timer for repeating the SYN until an answer. */
 972        tcp_reset_xmit_timer(sk, TIME_RETRANS, tp->rto);
 973
 974        /* Now, it is safe to release the socket. */
 975        release_sock(sk);
 976}
 977
 978/* Send out a delayed ack, the caller does the policy checking
 979 * to see if we should even be here.  See tcp_input.c:tcp_ack_snd_check()
 980 * for details.
 981 */
 982void tcp_send_delayed_ack(struct tcp_opt *tp, int max_timeout)
 983{
 984        unsigned long timeout;
 985
 986        /* Stay within the limit we were given */
 987        timeout = tp->ato;
 988        if (timeout > max_timeout)
 989                timeout = max_timeout;
 990        timeout += jiffies;
 991
 992        /* Use new timeout only if there wasn't a older one earlier. */
 993        if (!tp->delack_timer.prev) {
 994                tp->delack_timer.expires = timeout;
 995                add_timer(&tp->delack_timer);
 996        } else {
 997                if (time_before(timeout, tp->delack_timer.expires))
 998                        mod_timer(&tp->delack_timer, timeout);
 999        }
1000}
1001
1002/* This routine sends an ack and also updates the window. */
1003void tcp_send_ack(struct sock *sk)
1004{
1005        /* If we have been reset, we may not send again. */
1006        if(!sk->zapped) {
1007                struct tcp_opt *tp = &(sk->tp_pinfo.af_tcp);
1008                struct sk_buff *buff;
1009
1010                /* We are not putting this on the write queue, so
1011                 * tcp_transmit_skb() will set the ownership to this
1012                 * sock.
1013                 */
1014                buff = alloc_skb(MAX_HEADER + sk->prot->max_header, GFP_ATOMIC);
1015                if (buff == NULL) {
1016                        /* Force it to send an ack. We don't have to do this
1017                         * (ACK is unreliable) but it's much better use of
1018                         * bandwidth on slow links to send a spare ack than
1019                         * resend packets.
1020                         *
1021                         * This is the one possible way that we can delay an
1022                         * ACK and have tp->ato indicate that we are in
1023                         * quick ack mode, so clear it.
1024                         */
1025                        if(tcp_in_quickack_mode(tp))
1026                                tcp_exit_quickack_mode(tp);
1027                        tcp_send_delayed_ack(tp, HZ/2);
1028                        return;
1029                }
1030
1031                /* Reserve space for headers and prepare control bits. */
1032                skb_reserve(buff, MAX_HEADER + sk->prot->max_header);
1033                buff->csum = 0;
1034                TCP_SKB_CB(buff)->flags = TCPCB_FLAG_ACK;
1035                TCP_SKB_CB(buff)->sacked = 0;
1036                TCP_SKB_CB(buff)->urg_ptr = 0;
1037
1038                /* Send it off, this clears delayed acks for us. */
1039                TCP_SKB_CB(buff)->seq = TCP_SKB_CB(buff)->end_seq = tp->snd_nxt;
1040                TCP_SKB_CB(buff)->when = jiffies;
1041                tcp_transmit_skb(sk, buff);
1042        }
1043}
1044
1045/* This routine sends a packet with an out of date sequence
1046 * number. It assumes the other end will try to ack it.
1047 */
1048void tcp_write_wakeup(struct sock *sk)
1049{
1050        /* After a valid reset we can send no more. */
1051        if (!sk->zapped) {
1052                struct tcp_opt *tp = &(sk->tp_pinfo.af_tcp);
1053                struct sk_buff *skb;
1054
1055                /* Write data can still be transmitted/retransmitted in the
1056                 * following states.  If any other state is encountered, return.
1057                 * [listen/close will never occur here anyway]
1058                 */
1059                if ((1 << sk->state) &
1060                    ~(TCPF_ESTABLISHED|TCPF_CLOSE_WAIT|TCPF_FIN_WAIT1|
1061                      TCPF_LAST_ACK|TCPF_CLOSING))
1062                        return;
1063
1064                if (before(tp->snd_nxt, tp->snd_una + tp->snd_wnd) &&
1065                    ((skb = tp->send_head) != NULL)) {
1066                        unsigned long win_size;
1067
1068                        /* We are probing the opening of a window
1069                         * but the window size is != 0
1070                         * must have been a result SWS avoidance ( sender )
1071                         */
1072                        win_size = tp->snd_wnd - (tp->snd_nxt - tp->snd_una);
1073                        if (win_size < TCP_SKB_CB(skb)->end_seq - TCP_SKB_CB(skb)->seq) {
1074                                if (tcp_fragment(sk, skb, win_size))
1075                                        return; /* Let a retransmit get it. */
1076                        }
1077                        update_send_head(sk);
1078                        TCP_SKB_CB(skb)->when = jiffies;
1079                        tp->snd_nxt = TCP_SKB_CB(skb)->end_seq;
1080                        tp->packets_out++;
1081                        tcp_transmit_skb(sk, skb_clone(skb, GFP_ATOMIC));
1082                        if (!tcp_timer_is_set(sk, TIME_RETRANS))
1083                                tcp_reset_xmit_timer(sk, TIME_RETRANS, tp->rto);
1084                } else {
1085                        /* We don't queue it, tcp_transmit_skb() sets ownership. */
1086                        skb = alloc_skb(MAX_HEADER + sk->prot->max_header,
1087                                        GFP_ATOMIC);
1088                        if (skb == NULL) 
1089                                return;
1090
1091                        /* Reserve space for headers and set control bits. */
1092                        skb_reserve(skb, MAX_HEADER + sk->prot->max_header);
1093                        skb->csum = 0;
1094                        TCP_SKB_CB(skb)->flags = TCPCB_FLAG_ACK;
1095                        TCP_SKB_CB(skb)->sacked = 0;
1096                        TCP_SKB_CB(skb)->urg_ptr = 0;
1097
1098                        /* Use a previous sequence.  This should cause the other
1099                         * end to send an ack.  Don't queue or clone SKB, just
1100                         * send it.
1101                         */
1102                        TCP_SKB_CB(skb)->seq = tp->snd_nxt - 1;
1103                        TCP_SKB_CB(skb)->end_seq = TCP_SKB_CB(skb)->seq;
1104                        TCP_SKB_CB(skb)->when = jiffies;
1105                        tcp_transmit_skb(sk, skb);
1106                }
1107        }
1108}
1109
1110/* A window probe timeout has occurred.  If window is not closed send
1111 * a partial packet else a zero probe.
1112 */
1113void tcp_send_probe0(struct sock *sk)
1114{
1115        struct tcp_opt *tp = &(sk->tp_pinfo.af_tcp);
1116
1117        tcp_write_wakeup(sk);
1118        tp->pending = TIME_PROBE0;
1119        tp->backoff++;
1120        tp->probes_out++;
1121        tcp_reset_xmit_timer (sk, TIME_PROBE0, 
1122                              min(tp->rto << tp->backoff, 120*HZ));
1123}
1124
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.