xref: /csrg-svn/sys/netinet/tcp_timer.c (revision 5075)
1*5075Swnj /* tcp_timer.c 4.2 81/11/25 */
25069Swnj 
35069Swnj #include "../h/param.h"
45069Swnj #include "../h/systm.h"
55069Swnj #include "../h/mbuf.h"
65069Swnj #include "../h/socket.h"
75069Swnj #include "../h/socketvar.h"
85069Swnj #include "../h/protosw.h"
95069Swnj #include "../net/inet.h"
105069Swnj #include "../net/inet_pcb.h"
115069Swnj #include "../net/inet_systm.h"
125069Swnj #include "../net/if.h"
135069Swnj #include "../net/imp.h"
145069Swnj #include "../net/ip.h"
155069Swnj #include "../net/ip_var.h"
165069Swnj #include "../net/tcp.h"
175069Swnj #include "../net/tcp_fsm.h"
185069Swnj #include "../net/tcp_var.h"
195069Swnj #include "/usr/include/errno.h"
205069Swnj 
215069Swnj /*
225069Swnj  * Fast timeout routine for processing delayed acks
235069Swnj  */
245069Swnj tcp_fasttimo()
255069Swnj {
265069Swnj 
275069Swnj }
285069Swnj 
295069Swnj /*
305069Swnj  * Tcp protocol timeout routine called every 500 ms.
315069Swnj  * Updates the timers in all active tcb's and
325069Swnj  * causes finite state machine actions if timers expire.
335069Swnj  */
345069Swnj tcp_slowtimo()
355069Swnj {
365069Swnj 	register struct inpcb *ip;
375069Swnj 	register struct tcpcb *tp;
385069Swnj 	int s = splnet();
395069Swnj 	register short *tmp;
405069Swnj 	register int i;
415069Swnj COUNT(TCP_TIMEO);
425069Swnj 
435069Swnj 	/*
445069Swnj 	 * Search through tcb's and update active timers.
455069Swnj 	 */
465069Swnj 	for (ip = tcb.inp_next; ip != &tcb; ip = ip->inp_next) {
475069Swnj 		tp = intotcpcb(ip);
485069Swnj 		tmp = &tp->t_init;
49*5075Swnj 		for (i = 0; i < TCPT_NTIMERS; i++) {
505069Swnj 			if (*tmp && --*tmp == 0)
515069Swnj 				(void) tcp_usrreq(tp->t_inpcb->inp_socket,
525069Swnj 				    PRU_SLOWTIMO, (struct mbuf *)0,
535069Swnj 				    (caddr_t)i);
545069Swnj 			tmp++;
555069Swnj 		}
565069Swnj 		tp->t_xmt++;
575069Swnj 	}
58*5075Swnj 	tcp_iss += TCP_ISSINCR/PR_SLOWHZ;		/* increment iss */
595069Swnj 	splx(s);
605069Swnj }
615069Swnj 
625069Swnj /*
63*5075Swnj  * Cancel all timers for TCP tp.
645069Swnj  */
655069Swnj tcp_tcancel(tp)
665069Swnj 	struct tcpcb *tp;
675069Swnj {
685069Swnj 	register int i;
695069Swnj 
70*5075Swnj 	for (i = 0; i < TCPT_NTIMERS; i++)
71*5075Swnj 		tp->t_timer[i] = 0;
725069Swnj }
735069Swnj 
745069Swnj /*
755069Swnj  * TCP timer went off processing.
765069Swnj  */
77*5075Swnj tcp_timers(tp, timer)
785069Swnj 	register struct tcpcb *tp;
79*5075Swnj 	int timer;
805069Swnj {
815069Swnj 
825069Swnj COUNT(TCP_TIMERS);
835069Swnj 	switch (timertype) {
845069Swnj 
85*5075Swnj 	case TCPT_2MSL:
86*5075Swnj 		tcp_close(tp);
87*5075Swnj 		return;
885069Swnj 
89*5075Swnj 	case TCPT_REXMT:
90*5075Swnj 		tp->t_xmtime <<= 1;
91*5075Swnj 		if (tp->t_xmtime > TCPT_TOOLONG) {
92*5075Swnj 			tcp_drop(tp, ETIMEDOUT);
93*5075Swnj 			return;
945069Swnj 		}
95*5075Swnj 		tcp_output(tp);
96*5075Swnj 		return;
975069Swnj 
98*5075Swnj 	case TCPT_PERSIST:
99*5075Swnj 		if (tcp_output(tp) == 0)
100*5075Swnj 			tp->snd_wnd++, (void) tcp_output(tp), tp->snd_wnd--;
1015069Swnj 
102*5075Swnj 	case TCPT_KEEP:
103*5075Swnj 		return;
1045069Swnj 	}
1055069Swnj }
106