1 /* tcp_var.h 4.5 81/11/18 */ 2 3 /* 4 * Kernel variables for tcp. 5 */ 6 7 /* 8 * Tcp+ip header, after ip options removed. 9 */ 10 struct tcpiphdr { 11 struct ipovly ti_i; /* overlaid ip structure */ 12 struct tcphdr ti_t; /* tcp header */ 13 }; 14 #define ti_next ti_i.ih_next 15 #define ti_prev ti_i.ih_prev 16 #define ti_x1 ti_i.ih_x1 17 #define ti_pr ti_i.ih_pr 18 #define ti_len ti_i.ih_len 19 #define ti_src ti_i.ih_src 20 #define ti_dst ti_i.ih_dst 21 #define ti_sport ti_t.th_sport 22 #define ti_dport ti_t.th_dport 23 #define ti_seq ti_t.th_seq 24 #define ti_ackno ti_t.th_ackno 25 #define ti_x2 ti_t.th_x2 26 #define ti_off ti_t.th_off 27 #define ti_flags ti_t.th_flags 28 #define ti_win ti_t.th_win 29 #define ti_sum ti_t.th_sum 30 #define ti_urp ti_t.th_urp 31 32 /* 33 * Tcp control block. 34 */ 35 struct tcpcb { 36 struct tcpiphdr *seg_next,*seg_prev; /* seq queue */ 37 struct tcpiphdr *t_template; /* skeletal packet for transmit */ 38 struct inpcb *t_inpcb; 39 seq_t iss; /* initial send seq # */ 40 seq_t irs; /* initial recv seq # */ 41 seq_t rcv_urp; /* rcv urgent pointer */ 42 seq_t rcv_nxt; /* next seq # to rcv */ 43 seq_t rcv_end; /* rcv eol pointer */ 44 seq_t snd_off; /* seq # of first datum in send buf */ 45 seq_t seq_fin; /* seq # of FIN sent */ 46 seq_t snd_end; /* send eol pointer */ 47 seq_t snd_urp; /* snd urgent pointer */ 48 seq_t snd_lst; /* seq # of last sent datum */ 49 seq_t snd_nxt; /* seq # of next datum to send */ 50 seq_t snd_una; /* seq # of first unacked datum */ 51 seq_t snd_wl; /* seq # of last sent window */ 52 seq_t snd_hi; /* highest seq # sent */ 53 seq_t snd_wnd; /* send window max */ 54 seq_t t_rexmt_val; /* val saved in rexmt timer */ 55 seq_t t_rtl_val; /* val saved in rexmt too long timer */ 56 seq_t t_xmt_val; /* seq # sent when xmt timer started */ 57 seq_t rcv_adv; /* advertised window */ 58 struct mbuf *seg_unack; /* unacked message queue */ 59 short seqcnt; 60 u_short tc_flags; /* flags and state; see below */ 61 u_short t_options; 62 #define TO_EOL 0x01 /* eol mode */ 63 #define TO_URG 0x02 /* urgent mode */ 64 u_char t_state; /* state of this connection */ 65 u_char t_xmtime; /* current rexmt time */ 66 /* timers... must be in order */ 67 short t_init; /* init */ 68 short t_rexmt; /* retransmission */ 69 short t_rexmttl; /* retransmit too long */ 70 short t_persist; /* retransmit persistance */ 71 short t_finack; /* fin acknowledged */ 72 short t_xmt; /* round trip transmission time */ 73 /* end timers */ 74 }; 75 76 /* tc_flags values */ 77 #define TC_ACK_DUE 0x0001 /* must we send ACK */ 78 #define TC_CANCELLED 0x0002 /* retransmit timer cancelled */ 79 /* ... */ 80 #define TC_FIN_RCVD 0x0008 /* FIN received */ 81 #define TC_FORCE_ONE 0x0010 /* force sending of one byte */ 82 #define TC_NEW_WINDOW 0x0020 /* received new window size */ 83 #define TC_REXMT 0x0040 /* this msg is a retransmission */ 84 #define TC_SND_FIN 0x0080 /* FIN should be sent */ 85 #define TC_SND_RST 0x0100 /* RST should be sent */ 86 #define TC_SND_URG 0x0200 /* urgent data to send */ 87 #define TC_SYN_ACKED 0x0400 /* SYN has been ACKed */ 88 #define TC_SYN_RCVD 0x0800 /* SYN has been received */ 89 #define TC_USR_CLOSED 0x1000 /* user has closed connection */ 90 #define TC_WAITED_2_ML 0x2000 /* wait time for FIN ACK is up */ 91 #define TC_NET_KEEP 0x4000 /* don't free this net input */ 92 #define TC_USR_ABORT 0x8000 /* user has closed and does not expect 93 to receive any more data */ 94 /* 95 * TCP timers. 96 */ 97 #define TINIT 0 98 #define TREXMT 1 99 #define TREXMTTL 2 100 #define TPERSIST 3 101 #define TFINACK 4 102 #define TNTIMERS 5 103 104 #define intotcpcb(ip) ((struct tcpcb *)(ip)->inp_ppcb) 105 #define sototcpcb(so) (intotcpcb(sotoinpcb(so))) 106 107 /* 108 * Tcp machine predicates 109 */ 110 #define ack_ok(x, y) \ 111 (((y)->ti_flags&TH_ACK)==0 || \ 112 ((x)->iss < (y)->ti_ackno && (y)->ti_ackno <= (x)->snd_hi)) 113 114 #define syn_ok(x, y) \ 115 ((y)->ti_flags&TH_SYN) 116 117 #define ack_fin(x, y) \ 118 ((x)->seq_fin > (x)->iss && (y)->ti_ackno > (x)->seq_fin) 119 120 #define rcv_empty(x) \ 121 (((x)->tc_flags&TC_USR_ABORT) || \ 122 ((x)->t_inpcb->inp_socket->so_rcv.sb_mb == NULL && \ 123 (x)->seg_next == (x)->seg_prev)) 124 125 #define ISSINCR 128 /* increment for iss each second */ 126 #define TCPSIZE 20 /* size of TCP leader (bytes) */ 127 128 /* 129 * THESE NEED TO BE JUSTIFIED! 130 * 131 * *2 here is because slow timeout routine called every 1/2 second. 132 */ 133 #define T_INIT (30*2) 134 #define T_2ML (10*2) /* 2*maximum packet lifetime */ 135 #define T_PERS (5*2) /* persist time */ 136 #define T_REXMT (1*2) /* base for retransmission time */ 137 #define T_REXMTTL (30*2) /* retransmit too long timeout */ 138 #define T_REMAX (30*2) /* maximum retransmission time */ 139 140 struct tcpstat { 141 int tcps_badsum; 142 int tcps_badoff; 143 int tcps_hdrops; 144 int tcps_badsegs; 145 int tcps_unack; 146 }; 147 148 #ifdef TCPDEBUG 149 #define TDBSIZE 50 150 /* 151 * Tcp debugging record. 152 */ 153 struct tcp_debug { 154 long td_tod; /* time of day */ 155 struct tcbcb *td_tcb; /* -> tcb */ 156 char td_old; /* old state */ 157 char td_inp; /* input */ 158 char td_tim; /* timer id */ 159 char td_new; /* new state */ 160 seq_t td_sno; /* seq_t number */ 161 seq_t td_ano; /* acknowledgement */ 162 u_short td_wno; /* window */ 163 u_short td_lno; /* length */ 164 u_char td_flg; /* message flags */ 165 }; 166 #endif 167 168 #ifdef KERNEL 169 seq_t tcp_iss; /* tcp initial send seq # */ 170 struct inpcb tcb; 171 struct tcpstat tcpstat; 172 #ifdef TCPDEBUG 173 int tcpconsdebug; /* set to 1 traces on console */ 174 struct tcp_debug tcp_debug[TDBSIZE]; 175 int tdbx; /* rotating index into tcp_debug */ 176 #endif 177 struct tcpiphdr *tcp_template(); 178 #endif 179 180 #define SEQ_LT(a,b) ((int)((a)-(b)) < 0) 181 #define SEQ_LEQ(a,b) ((int)((a)-(b)) <= 0) 182 #define SEQ_GT(a,b) ((int)((a)-(b)) > 0) 183 #define SEQ_GEQ(a,b) ((int)((a)-(b)) >= 0) 184