diff options
-rw-r--r-- | sys/netinet/tcp_input.c | 40 | ||||
-rw-r--r-- | sys/netinet/tcp_output.c | 50 | ||||
-rw-r--r-- | sys/netinet/tcp_subr.c | 13 | ||||
-rw-r--r-- | sys/netinet/tcp_timer.c | 12 | ||||
-rw-r--r-- | sys/netinet/tcp_timer.h | 17 | ||||
-rw-r--r-- | sys/netinet/tcp_usrreq.c | 6 |
6 files changed, 78 insertions, 60 deletions
diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c index 9432cce8453..47c560d68ac 100644 --- a/sys/netinet/tcp_input.c +++ b/sys/netinet/tcp_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_input.c,v 1.100 2001/07/07 22:22:04 provos Exp $ */ +/* $OpenBSD: tcp_input.c,v 1.101 2002/01/14 03:11:55 provos Exp $ */ /* $NetBSD: tcp_input.c,v 1.23 1996/02/13 23:43:44 christos Exp $ */ /* @@ -864,7 +864,7 @@ findpcb: */ tp->t_idle = 0; if (tp->t_state != TCPS_SYN_RECEIVED) - tp->t_timer[TCPT_KEEP] = tcp_keepidle; + TCP_TIMER_ARM(tp, TCPT_KEEP, tcp_keepidle); #ifdef TCP_SACK if (!tp->sack_disable) @@ -960,9 +960,9 @@ findpcb: * decide between more output or persist. */ if (tp->snd_una == tp->snd_max) - tp->t_timer[TCPT_REXMT] = 0; - else if (tp->t_timer[TCPT_PERSIST] == 0) - tp->t_timer[TCPT_REXMT] = tp->t_rxtcur; + TCP_TIMER_DISARM(tp, TCPT_REXMT); + else if (TCP_TIMER_ISARMED(tp, TCPT_PERSIST) == 0) + TCP_TIMER_ARM(tp, TCPT_REXMT, tp->t_rxtcur); if (sb_notify(&so->so_snd)) sowwakeup(so); @@ -1190,7 +1190,7 @@ findpcb: tcp_rcvseqinit(tp); tp->t_flags |= TF_ACKNOW; tp->t_state = TCPS_SYN_RECEIVED; - tp->t_timer[TCPT_KEEP] = tcptv_keep_init; + TCP_TIMER_ARM(tp, TCPT_KEEP, tcptv_keep_init); dropsocket = 0; /* committed to socket */ tcpstat.tcps_accepts++; goto trimthenstep6; @@ -1243,7 +1243,7 @@ findpcb: if (SEQ_LT(tp->snd_nxt, tp->snd_una)) tp->snd_nxt = tp->snd_una; } - tp->t_timer[TCPT_REXMT] = 0; + TCP_TIMER_DISARM(tp, TCPT_REXMT); tp->irs = th->th_seq; tcp_rcvseqinit(tp); tp->t_flags |= TF_ACKNOW; @@ -1593,7 +1593,7 @@ trimthenstep6: * to keep a constant cwnd packets in the * network. */ - if (tp->t_timer[TCPT_REXMT] == 0) + if (TCP_TIMER_ISARMED(tp, TCPT_REXMT) == 0) tp->t_dupacks = 0; #if defined(TCP_SACK) && defined(TCP_FACK) /* @@ -1630,7 +1630,7 @@ trimthenstep6: #endif #ifdef TCP_SACK if (!tp->sack_disable) { - tp->t_timer[TCPT_REXMT] = 0; + TCP_TIMER_DISARM(tp, TCPT_REXMT); tp->t_rtt = 0; tcpstat.tcps_sndrexmitfast++; #if defined(TCP_SACK) && defined(TCP_FACK) @@ -1653,7 +1653,7 @@ trimthenstep6: goto drop; } #endif /* TCP_SACK */ - tp->t_timer[TCPT_REXMT] = 0; + TCP_TIMER_DISARM(tp, TCPT_REXMT); tp->t_rtt = 0; tp->snd_nxt = th->th_ack; tp->snd_cwnd = tp->t_maxseg; @@ -1774,10 +1774,10 @@ trimthenstep6: * timer, using current (possibly backed-off) value. */ if (th->th_ack == tp->snd_max) { - tp->t_timer[TCPT_REXMT] = 0; + TCP_TIMER_DISARM(tp, TCPT_REXMT); needoutput = 1; - } else if (tp->t_timer[TCPT_PERSIST] == 0) - tp->t_timer[TCPT_REXMT] = tp->t_rxtcur; + } else if (TCP_TIMER_ISARMED(tp, TCPT_PERSIST) == 0) + TCP_TIMER_ARM(tp, TCPT_REXMT, tp->t_rxtcur); /* * When new data is acked, open the congestion window. * If the window gives us less than ssthresh packets @@ -1840,7 +1840,7 @@ trimthenstep6: */ if (so->so_state & SS_CANTRCVMORE) { soisdisconnected(so); - tp->t_timer[TCPT_2MSL] = tcp_maxidle; + TCP_TIMER_ARM(tp, TCPT_2MSL, tcp_maxidle); } tp->t_state = TCPS_FIN_WAIT_2; } @@ -1856,7 +1856,7 @@ trimthenstep6: if (ourfinisacked) { tp->t_state = TCPS_TIME_WAIT; tcp_canceltimers(tp); - tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL; + TCP_TIMER_ARM(tp, TCPT_2MSL, 2 * TCPTV_MSL); soisdisconnected(so); } break; @@ -1880,7 +1880,7 @@ trimthenstep6: * it and restart the finack timer. */ case TCPS_TIME_WAIT: - tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL; + TCP_TIMER_ARM(tp, TCPT_2MSL, 2 * TCPTV_MSL); goto dropafterack; } } @@ -2053,7 +2053,7 @@ dodata: /* XXX */ case TCPS_FIN_WAIT_2: tp->t_state = TCPS_TIME_WAIT; tcp_canceltimers(tp); - tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL; + TCP_TIMER_ARM(tp, TCPT_2MSL, 2 * TCPTV_MSL); soisdisconnected(so); break; @@ -2061,7 +2061,7 @@ dodata: /* XXX */ * In TIME_WAIT state restart the 2 MSL time_wait timer. */ case TCPS_TIME_WAIT: - tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL; + TCP_TIMER_ARM(tp, TCPT_2MSL, 2 * TCPTV_MSL); break; } } @@ -2659,7 +2659,7 @@ tcp_sack_partialack(tp, th) { if (SEQ_LT(th->th_ack, tp->snd_last)) { /* Turn off retx. timer (will start again next segment) */ - tp->t_timer[TCPT_REXMT] = 0; + TCP_TIMER_DISARM(tp, TCPT_REXMT); tp->t_rtt = 0; #ifndef TCP_FACK /* @@ -3080,7 +3080,7 @@ tcp_newreno(tp, th) */ tcp_seq onxt = tp->snd_nxt; u_long ocwnd = tp->snd_cwnd; - tp->t_timer[TCPT_REXMT] = 0; + TCP_TIMER_DISARM(tp, TCPT_REXMT); tp->t_rtt = 0; tp->snd_nxt = th->th_ack; /* diff --git a/sys/netinet/tcp_output.c b/sys/netinet/tcp_output.c index 261fe6efc4e..a93512e172f 100644 --- a/sys/netinet/tcp_output.c +++ b/sys/netinet/tcp_output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_output.c,v 1.44 2001/11/24 19:29:07 deraadt Exp $ */ +/* $OpenBSD: tcp_output.c,v 1.45 2002/01/14 03:11:55 provos Exp $ */ /* $NetBSD: tcp_output.c,v 1.16 1997/06/03 16:17:09 kml Exp $ */ /* @@ -335,7 +335,7 @@ again: flags &= ~TH_FIN; win = 1; } else { - tp->t_timer[TCPT_PERSIST] = 0; + TCP_TIMER_DISARM(tp, TCPT_PERSIST); tp->t_rxtshift = 0; } } @@ -372,10 +372,10 @@ again: */ len = 0; if (win == 0) { - tp->t_timer[TCPT_REXMT] = 0; + TCP_TIMER_DISARM(tp, TCPT_REXMT); tp->t_rxtshift = 0; tp->snd_nxt = tp->snd_una; - if (tp->t_timer[TCPT_PERSIST] == 0) + if (TCP_TIMER_ISARMED(tp, TCPT_PERSIST) == 0) tcp_setpersist(tp); } } @@ -462,9 +462,9 @@ again: * that the retransmission timer is set. */ if (SEQ_GT(tp->snd_max, tp->snd_una) && - tp->t_timer[TCPT_REXMT] == 0 && - tp->t_timer[TCPT_PERSIST] == 0) { - tp->t_timer[TCPT_REXMT] = tp->t_rxtcur; + TCP_TIMER_ISARMED(tp, TCPT_REXMT) == 0 && + TCP_TIMER_ISARMED(tp, TCPT_PERSIST) == 0) { + TCP_TIMER_ARM(tp, TCPT_REXMT, tp->t_rxtcur); return (0); } #endif /* TCP_SACK */ @@ -491,8 +491,8 @@ again: * if window is nonzero, transmit what we can, * otherwise force out a byte. */ - if (so->so_snd.sb_cc && tp->t_timer[TCPT_REXMT] == 0 && - tp->t_timer[TCPT_PERSIST] == 0) { + if (so->so_snd.sb_cc && TCP_TIMER_ISARMED(tp, TCPT_REXMT) == 0 && + TCP_TIMER_ISARMED(tp, TCPT_PERSIST) == 0) { tp->t_rxtshift = 0; tcp_setpersist(tp); } @@ -787,7 +787,7 @@ send: * case, since we know we aren't doing a retransmission. * (retransmit and persist are mutually exclusive...) */ - if (len || (flags & (TH_SYN|TH_FIN)) || tp->t_timer[TCPT_PERSIST]) + if (len || (flags & (TH_SYN|TH_FIN)) || TCP_TIMER_ISARMED(tp, TCPT_PERSIST)) th->th_seq = htonl(tp->snd_nxt); else th->th_seq = htonl(tp->snd_max); @@ -954,7 +954,7 @@ send: * In transmit state, time the transmission and arrange for * the retransmit. In persist state, just set snd_max. */ - if (tp->t_force == 0 || tp->t_timer[TCPT_PERSIST] == 0) { + if (tp->t_force == 0 || TCP_TIMER_ISARMED(tp, TCPT_PERSIST) == 0) { tcp_seq startseq = tp->snd_nxt; /* @@ -1000,21 +1000,21 @@ send: #ifdef TCP_SACK timer: if (!tp->sack_disable && sack_rxmit && - tp->t_timer[TCPT_REXMT] == 0 && + TCP_TIMER_ISARMED(tp, TCPT_REXMT) == 0 && tp->snd_nxt != tp->snd_max) { - tp->t_timer[TCPT_REXMT] = tp->t_rxtcur; - if (tp->t_timer[TCPT_PERSIST]) { - tp->t_timer[TCPT_PERSIST] = 0; + TCP_TIMER_ARM(tp, TCPT_REXMT, tp->t_rxtcur); + if (TCP_TIMER_ISARMED(tp, TCPT_PERSIST)) { + TCP_TIMER_DISARM(tp, TCPT_PERSIST); tp->t_rxtshift = 0; } } #endif - if (tp->t_timer[TCPT_REXMT] == 0 && + if (TCP_TIMER_ISARMED(tp, 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; + TCP_TIMER_ARM(tp, TCPT_REXMT, tp->t_rxtcur); + if (TCP_TIMER_ISARMED(tp, TCPT_PERSIST)) { + TCP_TIMER_DISARM(tp, TCPT_PERSIST); tp->t_rxtshift = 0; } } @@ -1131,21 +1131,21 @@ out: } void -tcp_setpersist(tp) - register struct tcpcb *tp; +tcp_setpersist(struct tcpcb *tp) { - register int t = ((tp->t_srtt >> 2) + tp->t_rttvar) >> 1; + int t = ((tp->t_srtt >> 2) + tp->t_rttvar) >> 1; + int nticks; - if (tp->t_timer[TCPT_REXMT]) + if (TCP_TIMER_ISARMED(tp, TCPT_REXMT)) panic("tcp_output REXMT"); /* * Start/restart persistance timer. */ if (t < tp->t_rttmin) t = tp->t_rttmin; - TCPT_RANGESET(tp->t_timer[TCPT_PERSIST], - t * tcp_backoff[tp->t_rxtshift], + TCPT_RANGESET(nticks, t * tcp_backoff[tp->t_rxtshift], TCPTV_PERSMIN, TCPTV_PERSMAX); + TCP_TIMER_ARM(tp, TCPT_PERSIST, nticks); if (tp->t_rxtshift < TCP_MAXRXTSHIFT) tp->t_rxtshift++; } diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c index 26835ef897d..d3a5aeeacbd 100644 --- a/sys/netinet/tcp_subr.c +++ b/sys/netinet/tcp_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_subr.c,v 1.52 2001/07/21 09:26:06 itojun Exp $ */ +/* $OpenBSD: tcp_subr.c,v 1.53 2002/01/14 03:11:55 provos Exp $ */ /* $NetBSD: tcp_subr.c,v 1.22 1996/02/13 23:44:00 christos Exp $ */ /* @@ -446,10 +446,10 @@ tcp_respond(tp, template, m, ack, seq, flags) * protocol control block. */ struct tcpcb * -tcp_newtcpcb(inp) - struct inpcb *inp; +tcp_newtcpcb(struct inpcb *inp) { - register struct tcpcb *tp; + struct tcpcb *tp; + int i; tp = malloc(sizeof(*tp), M_PCB, M_NOWAIT); if (tp == NULL) @@ -458,7 +458,10 @@ tcp_newtcpcb(inp) LIST_INIT(&tp->segq); tp->t_maxseg = tcp_mssdflt; tp->t_maxopd = 0; - + + for (i = 0; i < TCPT_NTIMERS; i++) + TCP_TIMER_INIT(tp, i); + #ifdef TCP_SACK tp->sack_disable = tcp_do_sack ? 0 : 1; #endif diff --git a/sys/netinet/tcp_timer.c b/sys/netinet/tcp_timer.c index 93b619eee07..5196633c70d 100644 --- a/sys/netinet/tcp_timer.c +++ b/sys/netinet/tcp_timer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_timer.c,v 1.23 2002/01/02 20:35:40 deraadt Exp $ */ +/* $OpenBSD: tcp_timer.c,v 1.24 2002/01/14 03:11:55 provos Exp $ */ /* $NetBSD: tcp_timer.c,v 1.14 1996/02/13 23:44:09 christos Exp $ */ /* @@ -154,7 +154,7 @@ tcp_canceltimers(tp) register int i; for (i = 0; i < TCPT_NTIMERS; i++) - tp->t_timer[i] = 0; + TCP_TIMER_DISARM(tp, i); } int tcp_backoff[TCP_MAXRXTSHIFT + 1] = @@ -203,7 +203,7 @@ tcp_timers(tp, timer) case TCPT_2MSL: if (tp->t_state != TCPS_TIME_WAIT && tp->t_idle <= tcp_maxidle) - tp->t_timer[TCPT_2MSL] = tcp_keepintvl; + TCP_TIMER_ARM(tp,TCPT_2MSL, tcp_keepintvl); else tp = tcp_close(tp); break; @@ -228,7 +228,7 @@ tcp_timers(tp, timer) TCPT_RANGESET((long) tp->t_rxtcur, rto * tcp_backoff[tp->t_rxtshift], tp->t_rttmin, TCPTV_REXMTMAX); - tp->t_timer[TCPT_REXMT] = tp->t_rxtcur; + TCP_TIMER_ARM(tp, TCPT_REXMT, tp->t_rxtcur); /* * If we are losing and we are trying path MTU discovery, @@ -416,9 +416,9 @@ tcp_timers(tp, timer) (struct mbuf *)NULL, tp->rcv_nxt, tp->snd_una - 1, 0); #endif - tp->t_timer[TCPT_KEEP] = tcp_keepintvl; + TCP_TIMER_ARM(tp, TCPT_KEEP, tcp_keepintvl); } else - tp->t_timer[TCPT_KEEP] = tcp_keepidle; + TCP_TIMER_ARM(tp, TCPT_KEEP, tcp_keepidle); break; dropit: tcpstat.tcps_keepdrops++; diff --git a/sys/netinet/tcp_timer.h b/sys/netinet/tcp_timer.h index d494fb964a6..781bc5a17e0 100644 --- a/sys/netinet/tcp_timer.h +++ b/sys/netinet/tcp_timer.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_timer.h,v 1.4 2001/06/09 07:03:43 angelos Exp $ */ +/* $OpenBSD: tcp_timer.h,v 1.5 2002/01/14 03:11:55 provos Exp $ */ /* $NetBSD: tcp_timer.h,v 1.6 1995/03/26 20:32:37 jtc Exp $ */ /* @@ -115,6 +115,21 @@ char *tcptimers[] = #endif /* TCPTIMERS */ /* + * Init, arm, disarm, and test TCP timers. + */ +#define TCP_TIMER_INIT(tp, timer) \ + (tp)->t_timer[(timer)] = 0 + +#define TCP_TIMER_ARM(tp, timer, nticks) \ + (tp)->t_timer[(timer)] = (nticks) + +#define TCP_TIMER_DISARM(tp, timer) \ + (tp)->t_timer[(timer)] = 0 + +#define TCP_TIMER_ISARMED(tp, timer) \ + &(tp)->t_timer[(timer)] + +/* * Force a time value to be in a certain range. */ #define TCPT_RANGESET(tv, value, tvmin, tvmax) { \ diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index cdca01c152d..b8add2d5c57 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_usrreq.c,v 1.54 2001/06/26 06:55:32 aaron Exp $ */ +/* $OpenBSD: tcp_usrreq.c,v 1.55 2002/01/14 03:11:55 provos Exp $ */ /* $NetBSD: tcp_usrreq.c,v 1.20 1996/02/13 23:44:16 christos Exp $ */ /* @@ -321,7 +321,7 @@ tcp_usrreq(so, req, m, nam, control) soisconnecting(so); tcpstat.tcps_connattempt++; tp->t_state = TCPS_SYN_SENT; - tp->t_timer[TCPT_KEEP] = tcptv_keep_init; + TCP_TIMER_ARM(tp, TCPT_KEEP, tcptv_keep_init); #ifdef TCP_COMPAT_42 tp->iss = tcp_iss; tcp_iss += TCP_ISSINCR/2; @@ -774,7 +774,7 @@ tcp_usrclosed(tp) * not left in FIN_WAIT_2 forever. */ if (tp->t_state == TCPS_FIN_WAIT_2) - tp->t_timer[TCPT_2MSL] = tcp_maxidle; + TCP_TIMER_ARM(tp, TCPT_2MSL, tcp_maxidle); } return (tp); } |