1*4808Swnj /* tcp_var.h 4.1 81/11/08 */ 2*4808Swnj 3*4808Swnj /* 4*4808Swnj * Kernel variables for tcp. 5*4808Swnj */ 6*4808Swnj 7*4808Swnj /* 8*4808Swnj * Tcp control block. 9*4808Swnj */ 10*4808Swnj struct tcb { 11*4808Swnj struct tcb_hd { 12*4808Swnj struct th *seg_next,*seg_prev; /* seq queue */ 13*4808Swnj struct tcb *tcb_next,*tcb_prev; /* other tcb's */ 14*4808Swnj } tcb_hd; 15*4808Swnj struct th *t_template; /* skeletal packet for transmit */ 16*4808Swnj struct socket *t_socket; /* back pointer to socket */ 17*4808Swnj struct mbuf *seg_unack; /* unacked message queue */ 18*4808Swnj struct host *t_host; 19*4808Swnj short seqcnt; 20*4808Swnj short xxx; 21*4808Swnj seq_t iss; /* initial send seq # */ 22*4808Swnj seq_t irs; /* initial recv seq # */ 23*4808Swnj seq_t rcv_urp; /* rcv urgent pointer */ 24*4808Swnj seq_t rcv_nxt; /* next seq # to rcv */ 25*4808Swnj seq_t rcv_end; /* rcv eol pointer */ 26*4808Swnj seq_t snd_off; /* seq # of first datum in send buf */ 27*4808Swnj seq_t seq_fin; /* seq # of FIN sent */ 28*4808Swnj seq_t snd_end; /* send eol pointer */ 29*4808Swnj seq_t snd_urp; /* snd urgent pointer */ 30*4808Swnj seq_t snd_lst; /* seq # of last sent datum */ 31*4808Swnj seq_t snd_nxt; /* seq # of next datum to send */ 32*4808Swnj seq_t snd_una; /* seq # of first unacked datum */ 33*4808Swnj seq_t snd_wl; /* seq # of last sent window */ 34*4808Swnj seq_t snd_hi; /* highest seq # sent */ 35*4808Swnj seq_t snd_wnd; /* send window max */ 36*4808Swnj seq_t t_rexmt_val; /* val saved in rexmt timer */ 37*4808Swnj seq_t t_rtl_val; /* val saved in rexmt too long timer */ 38*4808Swnj seq_t t_xmt_val; /* seq # sent when xmt timer started */ 39*4808Swnj seq_t rcv_adv; /* advertised window */ 40*4808Swnj u_short tc_flags; /* flags and state; see below */ 41*4808Swnj u_short t_options; 42*4808Swnj #define TO_EOL 0x01 /* eol mode */ 43*4808Swnj #define TO_URG 0x02 /* urgent mode */ 44*4808Swnj u_short t_lport; /* local port */ 45*4808Swnj u_short t_fport; /* foreign port */ 46*4808Swnj u_char t_state; /* state of this connection */ 47*4808Swnj u_char t_xmtime; /* current rexmt time */ 48*4808Swnj /* timers... must be in order */ 49*4808Swnj short t_init; /* initialization too long */ 50*4808Swnj short t_rexmt; /* retransmission */ 51*4808Swnj short t_rexmttl; /* retransmit too long */ 52*4808Swnj short t_persist; /* retransmit persistance */ 53*4808Swnj short t_finack; /* fin acknowledged */ 54*4808Swnj short t_xmt; /* round trip transmission time */ 55*4808Swnj /* end timers */ 56*4808Swnj }; 57*4808Swnj 58*4808Swnj /* tc_flags values */ 59*4808Swnj #define TC_ACK_DUE 0x0001 /* must we send ACK */ 60*4808Swnj #define TC_CANCELLED 0x0002 /* retransmit timer cancelled */ 61*4808Swnj #define TC_DROPPED_TXT 0x0004 /* dropped incoming data */ 62*4808Swnj #define TC_FIN_RCVD 0x0008 /* FIN received */ 63*4808Swnj #define TC_FORCE_ONE 0x0010 /* force sending of one byte */ 64*4808Swnj #define TC_NEW_WINDOW 0x0020 /* received new window size */ 65*4808Swnj #define TC_REXMT 0x0040 /* this msg is a retransmission */ 66*4808Swnj #define TC_SND_FIN 0x0080 /* FIN should be sent */ 67*4808Swnj #define TC_SND_RST 0x0100 /* RST should be sent */ 68*4808Swnj #define TC_SND_URG 0x0200 /* urgent data to send */ 69*4808Swnj #define TC_SYN_ACKED 0x0400 /* SYN has been ACKed */ 70*4808Swnj #define TC_SYN_RCVD 0x0800 /* SYN has been received */ 71*4808Swnj #define TC_USR_CLOSED 0x1000 /* user has closed connection */ 72*4808Swnj #define TC_WAITED_2_ML 0x2000 /* wait time for FIN ACK is up */ 73*4808Swnj #define TC_NET_KEEP 0x4000 /* don't free this net input */ 74*4808Swnj #define TC_USR_ABORT 0x8000 /* user has closed and does not expect 75*4808Swnj to receive any more data */ 76*4808Swnj /* 77*4808Swnj * TCP timers. 78*4808Swnj */ 79*4808Swnj #define TINIT 0 80*4808Swnj #define TREXMT 1 81*4808Swnj #define TREXMTTL 2 82*4808Swnj #define TPERSIST 3 83*4808Swnj #define TFINACK 4 84*4808Swnj #define TNTIMERS 5 85*4808Swnj 86*4808Swnj /* 87*4808Swnj * Tcp machine predicates 88*4808Swnj */ 89*4808Swnj #define ack_ok(x, y) \ 90*4808Swnj (((y)->th_flags&TH_ACK)==0 || \ 91*4808Swnj ((x)->iss < (y)->t_ackno && (y)->t_ackno <= (x)->snd_hi)) 92*4808Swnj 93*4808Swnj #define syn_ok(x, y) \ 94*4808Swnj ((y)->th_flags&TH_SYN) 95*4808Swnj 96*4808Swnj #define ack_fin(x, y) \ 97*4808Swnj ((x)->seq_fin > (x)->iss && (y)->t_ackno > (x)->seq_fin) 98*4808Swnj 99*4808Swnj #define rcv_empty(x) \ 100*4808Swnj (((x)->tc_flags&TC_USR_ABORT) || \ 101*4808Swnj ((x)->t_socket->so_rcv.sb_mb == NULL && \ 102*4808Swnj (x)->tcb_hd.seg_next == (x)->tcb_hd.seg_prev)) 103*4808Swnj 104*4808Swnj #define ISSINCR 128 /* increment for iss each second */ 105*4808Swnj #define TCPSIZE 20 /* size of TCP leader (bytes) */ 106*4808Swnj 107*4808Swnj /* 108*4808Swnj * THESE NEED TO BE JUSTIFIED! 109*4808Swnj * 110*4808Swnj * *2 here is because slow timeout routine called every 1/2 second. 111*4808Swnj */ 112*4808Swnj #define T_2ML (10*2) /* 2*maximum packet lifetime */ 113*4808Swnj #define T_PERS (5*2) /* persist time */ 114*4808Swnj #define T_REXMT (1*2) /* base for retransmission time */ 115*4808Swnj #define T_REXMTTL (30*2) /* retransmit too long timeout */ 116*4808Swnj #define T_REMAX (30*2) /* maximum retransmission time */ 117*4808Swnj 118*4808Swnj #ifdef TCPDEBUG 119*4808Swnj #define TDBSIZE 50 120*4808Swnj /* 121*4808Swnj * Tcp debugging record. 122*4808Swnj */ 123*4808Swnj struct tcp_debug { 124*4808Swnj long td_tod; /* time of day */ 125*4808Swnj struct tcb *td_tcb; /* -> tcb */ 126*4808Swnj char td_old; /* old state */ 127*4808Swnj char td_inp; /* input */ 128*4808Swnj char td_tim; /* timer id */ 129*4808Swnj char td_new; /* new state */ 130*4808Swnj seq_t td_sno; /* seq_t number */ 131*4808Swnj seq_t td_ano; /* acknowledgement */ 132*4808Swnj u_short td_wno; /* window */ 133*4808Swnj u_short td_lno; /* length */ 134*4808Swnj u_char td_flg; /* message flags */ 135*4808Swnj }; 136*4808Swnj #endif 137*4808Swnj 138*4808Swnj #ifdef KERNEL 139*4808Swnj struct tcb_hd tcb; /* tcp tcb list head */ 140*4808Swnj seq_t tcp_iss; /* tcp initial send seq # */ 141*4808Swnj int tcpconsdebug; /* set to 1 traces on console */ 142*4808Swnj #ifdef TCPDEBUG 143*4808Swnj struct tcp_debug tcp_debug[TDBSIZE]; 144*4808Swnj #endif 145*4808Swnj int tdbx; /* rotating index into tcp_debug */ 146*4808Swnj struct th *tcp_template(); 147*4808Swnj #endif 148*4808Swnj 149*4808Swnj #define SEQ_LT(a,b) ((int)((a)-(b)) < 0) 150*4808Swnj #define SEQ_LEQ(a,b) ((int)((a)-(b)) <= 0) 151*4808Swnj #define SEQ_GT(a,b) ((int)((a)-(b)) > 0) 152*4808Swnj #define SEQ_GEQ(a,b) ((int)((a)-(b)) >= 0) 153*4808Swnj struct th *tcp_template(); 154