1 /* tcp.h 1.13 81/11/04 */ 2 3 /* 4 * Tcp header. Fits over the ip header after option removed. 5 * 6 * SHOULD MAKE A CLEAN HEADER FOR USE BY USERS. 7 */ 8 struct th { 9 struct th *t_next; /* -> next tcp on rcv chain */ 10 struct th *t_prev; /* -> prev tcp on rcv chain */ 11 u_char t_x1; /* (unused) */ 12 u_char t_pr; /* protocol */ 13 /* by rights, t_len should be a u_short, but this makes operations */ 14 /* on it very dangerous as comparisons become unsigned and comparing */ 15 /* against negative numbers then fails... we don't expect any > 32767 */ 16 /* byte segments, so pragmatically delcare it to be a short */ 17 short t_len; /* seg length */ 18 struct socket t_s; /* source internet address */ 19 struct socket t_d; /* destination internet address */ 20 u_short t_src; /* source port */ 21 u_short t_dst; /* destination port */ 22 seq_t t_seq; /* sequence number */ 23 seq_t t_ackno; /* acknowledgement number */ 24 #define t_end(x) (x->t_seq + x->t_len - 1) 25 u_char 26 t_x2:4, /* (unused) */ 27 t_off:4; /* data offset */ 28 u_char th_flags; 29 #define TH_FIN 001 30 #define TH_SYN 002 31 #define TH_RST 004 32 #define TH_EOL 010 33 #define TH_ACK 020 34 #define TH_URG 040 35 u_short t_win; /* window */ 36 u_short t_sum; /* checksum */ 37 u_short t_urp; /* urgent pointer */ 38 }; 39 40 /* 41 * Tcp control block. 42 */ 43 struct tcb { 44 /* first four elements of this struct must match tcphead below */ 45 struct th *t_rcv_next; /* first el on rcv queue */ 46 struct th *t_rcv_prev; /* last el on rcv queue */ 47 struct tcb *tcb_next; /* next tcb */ 48 struct tcb *tcb_prev; /* next tcb */ 49 /* end must match */ 50 struct th *t_template; /* skeletal packet for transmit */ 51 struct ucb *t_ucb; /* ucb */ 52 struct mbuf *t_rcv_unack; /* unacked message queue */ 53 short seqcnt; 54 short xxx; 55 seq_t iss; /* initial send seq # */ 56 seq_t irs; /* initial recv seq # */ 57 seq_t rcv_urp; /* rcv urgent pointer */ 58 seq_t rcv_nxt; /* next seq # to rcv */ 59 seq_t rcv_end; /* rcv eol pointer */ 60 seq_t snd_off; /* seq # of first datum in send buf */ 61 seq_t seq_fin; /* seq # of FIN sent */ 62 seq_t snd_end; /* send eol pointer */ 63 seq_t snd_urp; /* snd urgent pointer */ 64 seq_t snd_lst; /* seq # of last sent datum */ 65 seq_t snd_nxt; /* seq # of next datum to send */ 66 seq_t snd_una; /* seq # of first unacked datum */ 67 seq_t snd_wl; /* seq # of last sent window */ 68 seq_t snd_hi; /* highest seq # sent */ 69 seq_t snd_wnd; /* send window max */ 70 seq_t t_rexmt_val; /* val saved in rexmt timer */ 71 seq_t t_rtl_val; /* val saved in rexmt too long timer */ 72 seq_t t_xmt_val; /* seq # sent when xmt timer started */ 73 74 /* various flags and state variables */ 75 76 u_short tc_flags; 77 #define TC_ACK_DUE 0x0001 /* must we send ACK */ 78 #define TC_CANCELLED 0x0002 /* retransmit timer cancelled */ 79 #define TC_DROPPED_TXT 0x0004 /* dropped incoming data */ 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 u_short t_lport; /* local port */ 96 u_short t_fport; /* foreign port */ 97 u_char t_state; /* state of this connection */ 98 u_char t_xmtime; /* current rexmt time */ 99 100 /* timers */ 101 102 u_char t_init; /* initialization too long */ 103 u_char t_rexmt; /* retransmission */ 104 u_char t_rexmttl; /* retransmit too long */ 105 u_char t_persist; /* retransmit persistance */ 106 u_char t_finack; /* fin acknowledged */ 107 u_char t_xmt; /* round trip transmission time */ 108 109 seq_t rcv_adv; /* advertised window */ 110 }; 111 struct tcbhead { 112 struct th *t_rcv_next,*t_rcv_prev; 113 struct tcb *tcb_next,*tcb_prev; 114 }; 115 116 /* 117 * TCP timers. 118 */ 119 #define TINIT 0 120 #define TREXMT 1 121 #define TREXMTTL 2 122 #define TPERSIST 3 123 #define TFINACK 4 124 #define TNTIMERS 5 125 126 /* 127 * Tcp machine predicates 128 */ 129 #define ack_ok(x, y) \ 130 (((y)->th_flags&TH_ACK)==0 || \ 131 ((x)->iss < (y)->t_ackno && (y)->t_ackno <= (x)->snd_hi)) 132 133 #define syn_ok(x, y) \ 134 ((y)->th_flags&TH_SYN) 135 136 #define ack_fin(x, y) \ 137 ((x)->seq_fin > (x)->iss && (y)->t_ackno > (x)->seq_fin) 138 139 #define rcv_empty(x) \ 140 (((x)->tc_flags&TC_USR_ABORT) || \ 141 ((x)->t_ucb->uc_rbuf == NULL && (x)->t_rcv_next == (x)->t_rcv_prev)) 142 143 #define ISSINCR 128 /* increment for iss each second */ 144 #define TCPSIZE 20 /* size of TCP leader (bytes) */ 145 146 /* 147 * THESE NEED TO BE JUSTIFIED! 148 */ 149 #define T_2ML 10 /* 2*maximum packet lifetime */ 150 #define T_PERS 5 /* persist time */ 151 #define T_INIT 30 /* init too long timeout */ 152 #define T_REXMT 1 /* base for retransmission time */ 153 #define T_REXMTTL 30 /* retransmit too long timeout */ 154 #define T_REMAX 30 /* maximum retransmission time */ 155 156 #define ACTIVE 1 /* active open */ 157 #define PASSIVE 0 /* passive open */ 158 159 #ifdef TCPDEBUG 160 #define TDBSIZE 50 161 /* 162 * Tcp debugging record. 163 */ 164 struct tcp_debug { 165 long td_tod; /* time of day */ 166 struct tcb *td_tcb; /* -> tcb */ 167 char td_old; /* old state */ 168 char td_inp; /* input */ 169 char td_tim; /* timer id */ 170 char td_new; /* new state */ 171 seq_t td_sno; /* seq_t number */ 172 seq_t td_ano; /* acknowledgement */ 173 u_short td_wno; /* window */ 174 u_short td_lno; /* length */ 175 u_char td_flg; /* message flags */ 176 }; 177 #endif 178 179 #ifdef KERNEL 180 struct tcbhead tcb; /* tcp tcb list head */ 181 seq_t tcp_iss; /* tcp initial send seq # */ 182 int tcpconsdebug; /* set to 1 traces on console */ 183 #ifdef TCPDEBUG 184 struct tcp_debug tcp_debug[TDBSIZE]; 185 #endif 186 int tdbx; /* rotating index into tcp_debug */ 187 struct th *tcp_template(); 188 #endif 189 190 #define SEQ_LT(a,b) ((int)((a)-(b)) < 0) 191 #define SEQ_LEQ(a,b) ((int)((a)-(b)) <= 0) 192 #define SEQ_GT(a,b) ((int)((a)-(b)) > 0) 193 #define SEQ_GEQ(a,b) ((int)((a)-(b)) >= 0) 194 struct th *tcp_template(); 195