- if ((t = tp->t_ucb->uc_template) == 0)
- return (0);
- MGET(m, 0);
- if (m == 0)
- return (0);
- m->m_off = MMAXOFF - sizeof(struct th);
- m->m_len = sizeof (struct th);
- m->m_next = dat;
- if (flags & TH_SYN)
- len--;
- if (flags & TH_FIN)
- len--;
- bcopy((caddr_t)t, mtod(m, caddr_t), sizeof (struct th));
- t = mtod(m, struct th *);
- if (tp->tc_flags&TC_SND_RST) {
- flags &= ~TH_SYN;
- flags |= TH_RST;
- }
- if (tp->tc_flags&TC_SYN_RCVD)
- flags |= TH_ACK;
- t->th_flags = flags;
- if (flags & TH_URG)
- t->t_urp = htons(tp->snd_urp);
- t->t_win =
- tp->t_ucb->uc_rhiwat - (tp->t_ucb->uc_rcc + tp->seqcnt);
- if (tp->rcv_nxt + t->t_win > tp->rcv_adv)
- tp->rcv_adv = tp->rcv_nxt + t->t_win;
- if (len)
- t->t_len = htons(len + TCPSIZE);
- t->t_win = htons(t->t_win);
-#ifdef TCPDEBUG
- if ((tp->t_ucb->uc_flags & UDEBUG) || tcpconsdebug) {
- t->t_seq = tp->snd_nxt;
- t->t_ackno = tp->rcv_nxt;
- tdb_setup(tp, t, INSEND, &tdb);
- tdb_stuff(&tdb, -2);
- }
-#endif
- t->t_seq = htonl(tp->snd_nxt);
- t->t_ackno = htonl(tp->rcv_nxt);
- t->t_sum = 0; /* gratuitous? */
- CKSUM_TCPSET(m, t, r9, sizeof (struct th) + len);
- ip = (struct ip *)t;
- ip->ip_v = IPVERSION;
- ip->ip_hl = 5;
- ip->ip_tos = 0;
- ip->ip_len = len + sizeof(struct th);
- ip->ip_id = ip_id++;
- ip->ip_off = 0;
- ip->ip_ttl = MAXTTL;
- i = ip_send(ip);
- return(i);
-}
+ /*
+ * Set retransmit timer if not currently set,
+ * and not doing an ack or a keep-alive probe.
+ * Initial value for retransmit timer is smoothed
+ * round-trip time + 2 * round-trip time variance.
+ * Initialize shift counter which is used for backoff
+ * of retransmit time.
+ */
+ if (tp->t_timer[TCPT_REXMT] == 0 &&
+ tp->snd_nxt != tp->snd_una) {
+ tp->t_timer[TCPT_REXMT] = tp->t_rxtcur;
+ if (tp->t_timer[TCPT_PERSIST]) {
+ tp->t_timer[TCPT_PERSIST] = 0;
+ tp->t_rxtshift = 0;
+ }
+ }
+ } else
+ if (SEQ_GT(tp->snd_nxt + len, tp->snd_max))
+ tp->snd_max = tp->snd_nxt + len;