1*5276Swnj /* tcp_timer.c 4.9 81/12/20 */ 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" 95089Swnj #include "../net/in.h" 105089Swnj #include "../net/in_pcb.h" 115089Swnj #include "../net/in_systm.h" 125069Swnj #include "../net/if.h" 135069Swnj #include "../net/ip.h" 145069Swnj #include "../net/ip_var.h" 155069Swnj #include "../net/tcp.h" 165069Swnj #include "../net/tcp_fsm.h" 175089Swnj #include "../net/tcp_seq.h" 185089Swnj #include "../net/tcp_timer.h" 195069Swnj #include "../net/tcp_var.h" 205089Swnj #include "../net/tcpip.h" 215112Swnj #include "../errno.h" 225069Swnj 235069Swnj /* 245069Swnj * Fast timeout routine for processing delayed acks 255069Swnj */ 265069Swnj tcp_fasttimo() 275069Swnj { 285069Swnj 295089Swnj COUNT(TCP_FASTTIMO); 305069Swnj } 315069Swnj 325069Swnj /* 335069Swnj * Tcp protocol timeout routine called every 500 ms. 345069Swnj * Updates the timers in all active tcb's and 355069Swnj * causes finite state machine actions if timers expire. 365069Swnj */ 375069Swnj tcp_slowtimo() 385069Swnj { 395069Swnj register struct inpcb *ip; 405069Swnj register struct tcpcb *tp; 415069Swnj int s = splnet(); 425069Swnj register int i; 435089Swnj COUNT(TCP_SLOWTIMO); 445069Swnj 455069Swnj /* 465069Swnj * Search through tcb's and update active timers. 475069Swnj */ 485245Sroot ip = tcb.inp_next; 495245Sroot if (ip == 0) { 505245Sroot splx(s); 515245Sroot return; 525245Sroot } 535245Sroot for (; ip != &tcb; ip = ip->inp_next) { 545069Swnj tp = intotcpcb(ip); 555260Swnj if (tp == 0) 565260Swnj continue; 575075Swnj for (i = 0; i < TCPT_NTIMERS; i++) { 585089Swnj if (tp->t_timer[i] && --tp->t_timer[i] == 0) 595069Swnj (void) tcp_usrreq(tp->t_inpcb->inp_socket, 605069Swnj PRU_SLOWTIMO, (struct mbuf *)0, 615069Swnj (caddr_t)i); 625069Swnj } 635165Swnj tp->t_idle++; 645165Swnj if (tp->t_rtt) 655165Swnj tp->t_rtt++; 665069Swnj } 675075Swnj tcp_iss += TCP_ISSINCR/PR_SLOWHZ; /* increment iss */ 685069Swnj splx(s); 695069Swnj } 705069Swnj 715069Swnj /* 725075Swnj * Cancel all timers for TCP tp. 735069Swnj */ 745089Swnj tcp_canceltimers(tp) 755069Swnj struct tcpcb *tp; 765069Swnj { 775069Swnj register int i; 785069Swnj 795089Swnj COUNT(TCP_CANCELTIMERS); 805075Swnj for (i = 0; i < TCPT_NTIMERS; i++) 815075Swnj tp->t_timer[i] = 0; 825069Swnj } 835069Swnj 845069Swnj /* 855165Swnj * TCP timer processing. 865069Swnj */ 875075Swnj tcp_timers(tp, timer) 885069Swnj register struct tcpcb *tp; 895075Swnj int timer; 905069Swnj { 915069Swnj 925069Swnj COUNT(TCP_TIMERS); 935089Swnj switch (timer) { 945069Swnj 955165Swnj /* 965165Swnj * 2 MSL timeout in shutdown went off. Delete connection 975165Swnj * control block. 985165Swnj */ 995075Swnj case TCPT_2MSL: 1005075Swnj tcp_close(tp); 1015075Swnj return; 1025069Swnj 1035165Swnj /* 1045165Swnj * Retransmission timer went off. Message has not 1055165Swnj * been acked within retransmit interval. Back off 1065165Swnj * to a longer retransmit interval and retransmit all 1075165Swnj * unacknowledged messages in the window. 1085165Swnj */ 1095075Swnj case TCPT_REXMT: 1105165Swnj tp->t_rxtshift++; 1115165Swnj TCPT_RANGESET(tp->t_timer[TCPT_REXMT], 1125165Swnj ((int)(2 * tp->t_srtt)) << tp->t_rxtshift, 1135165Swnj TCPTV_MIN, TCPTV_MAX); 114*5276Swnj printf("rexmt set to %d\n", tp->t_timer[TCPT_REXMT]); 1155165Swnj tp->snd_nxt = tp->snd_una; 1165165Swnj /* this only transmits one segment! */ 1175165Swnj (void) tcp_output(tp); 1185075Swnj return; 1195069Swnj 1205165Swnj /* 1215165Swnj * Persistance timer into zero window. 1225165Swnj * Force a byte to be output, if possible. 1235165Swnj */ 1245075Swnj case TCPT_PERSIST: 1255165Swnj tp->t_force = 1; 1265165Swnj (void) tcp_output(tp); 1275165Swnj tp->t_force = 0; 1285165Swnj TCPT_RANGESET(tp->t_timer[TCPT_PERSIST], 1295165Swnj 2 * tp->t_srtt, TCPTV_PERSMIN, TCPTV_MAX); 1305089Swnj return; 1315069Swnj 1325165Swnj /* 1335165Swnj * Keep-alive timer went off; send something 1345165Swnj * or drop connection if idle for too long. 1355165Swnj */ 1365075Swnj case TCPT_KEEP: 1375165Swnj if (tp->t_state < TCPS_ESTABLISHED || 1385165Swnj tp->t_idle >= TCPTV_MAXIDLE) { 1395165Swnj tcp_drop(tp, ETIMEDOUT); 1405165Swnj return; 1415165Swnj } 1425165Swnj tcp_respond(tp->t_template, tp->rcv_nxt, tp->snd_una-1, 0); 1435165Swnj tp->t_timer[TCPT_KEEP] = TCPTV_KEEP; 1445075Swnj return; 1455069Swnj } 1465069Swnj } 147