1 /* 2 * Copyright (c) 1982, 1986 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)tcp_var.h 7.11 (Berkeley) 01/08/93 8 */ 9 10 /* 11 * Kernel variables for tcp. 12 */ 13 14 /* 15 * Tcp control block, one per tcp; fields: 16 */ 17 struct tcpcb { 18 struct tcpiphdr *seg_next; /* sequencing queue */ 19 struct tcpiphdr *seg_prev; 20 short t_state; /* state of this connection */ 21 short t_timer[TCPT_NTIMERS]; /* tcp timers */ 22 short t_rxtshift; /* log(2) of rexmt exp. backoff */ 23 short t_rxtcur; /* current retransmit value */ 24 short t_dupacks; /* consecutive dup acks recd */ 25 u_short t_maxseg; /* maximum segment size */ 26 char t_force; /* 1 if forcing out a byte */ 27 u_short t_flags; 28 #define TF_ACKNOW 0x0001 /* ack peer immediately */ 29 #define TF_DELACK 0x0002 /* ack, but try to delay it */ 30 #define TF_NODELAY 0x0004 /* don't delay packets to coalesce */ 31 #define TF_NOOPT 0x0008 /* don't use tcp options */ 32 #define TF_SENTFIN 0x0010 /* have sent FIN */ 33 #define TF_REQ_SCALE 0x0020 /* have/will request window scaling */ 34 #define TF_RCVD_SCALE 0x0040 /* other side has requested scaling */ 35 #define TF_REQ_TSTMP 0x0080 /* have/will request timestamps */ 36 #define TF_RCVD_TSTMP 0x0100 /* a timestamp was received in SYN */ 37 #define TF_SACK_PERMIT 0x0200 /* other side said I could SACK */ 38 39 struct tcpiphdr *t_template; /* skeletal packet for transmit */ 40 struct inpcb *t_inpcb; /* back pointer to internet pcb */ 41 /* 42 * The following fields are used as in the protocol specification. 43 * See RFC783, Dec. 1981, page 21. 44 */ 45 /* send sequence variables */ 46 tcp_seq snd_una; /* send unacknowledged */ 47 tcp_seq snd_nxt; /* send next */ 48 tcp_seq snd_up; /* send urgent pointer */ 49 tcp_seq snd_wl1; /* window update seg seq number */ 50 tcp_seq snd_wl2; /* window update seg ack number */ 51 tcp_seq iss; /* initial send sequence number */ 52 u_long snd_wnd; /* send window */ 53 /* receive sequence variables */ 54 u_long rcv_wnd; /* receive window */ 55 tcp_seq rcv_nxt; /* receive next */ 56 tcp_seq rcv_up; /* receive urgent pointer */ 57 tcp_seq irs; /* initial receive sequence number */ 58 /* 59 * Additional variables for this implementation. 60 */ 61 /* receive variables */ 62 tcp_seq rcv_adv; /* advertised window */ 63 /* retransmit variables */ 64 tcp_seq snd_max; /* highest sequence number sent; 65 * used to recognize retransmits 66 */ 67 /* congestion control (for slow start, source quench, retransmit after loss) */ 68 u_long snd_cwnd; /* congestion-controlled window */ 69 u_long snd_ssthresh; /* snd_cwnd size threshhold for 70 * for slow start exponential to 71 * linear switch 72 */ 73 /* 74 * transmit timing stuff. See below for scale of srtt and rttvar. 75 * "Variance" is actually smoothed difference. 76 */ 77 short t_idle; /* inactivity time */ 78 short t_rtt; /* round trip time */ 79 tcp_seq t_rtseq; /* sequence number being timed */ 80 short t_srtt; /* smoothed round-trip time */ 81 short t_rttvar; /* variance in round-trip time */ 82 u_short t_rttmin; /* minimum rtt allowed */ 83 u_long max_sndwnd; /* largest window peer has offered */ 84 85 /* out-of-band data */ 86 char t_oobflags; /* have some */ 87 char t_iobc; /* input character */ 88 #define TCPOOB_HAVEDATA 0x01 89 #define TCPOOB_HADDATA 0x02 90 short t_softerror; /* possible error not yet reported */ 91 92 /* RFC 1323 variables */ 93 u_char snd_scale; /* window scaling for send window */ 94 u_char rcv_scale; /* window scaling for recv window */ 95 u_char request_r_scale; /* pending window scaling */ 96 u_char requested_s_scale; 97 u_long ts_recent; /* timestamp echo data */ 98 u_long ts_recent_age; /* when last updated */ 99 tcp_seq last_ack_sent; 100 }; 101 102 #define intotcpcb(ip) ((struct tcpcb *)(ip)->inp_ppcb) 103 #define sototcpcb(so) (intotcpcb(sotoinpcb(so))) 104 105 /* 106 * The smoothed round-trip time and estimated variance 107 * are stored as fixed point numbers scaled by the values below. 108 * For convenience, these scales are also used in smoothing the average 109 * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed). 110 * With these scales, srtt has 3 bits to the right of the binary point, 111 * and thus an "ALPHA" of 0.875. rttvar has 2 bits to the right of the 112 * binary point, and is smoothed with an ALPHA of 0.75. 113 */ 114 #define TCP_RTT_SCALE 8 /* multiplier for srtt; 3 bits frac. */ 115 #define TCP_RTT_SHIFT 3 /* shift for srtt; 3 bits frac. */ 116 #define TCP_RTTVAR_SCALE 4 /* multiplier for rttvar; 2 bits */ 117 #define TCP_RTTVAR_SHIFT 2 /* multiplier for rttvar; 2 bits */ 118 119 /* 120 * The initial retransmission should happen at rtt + 4 * rttvar. 121 * Because of the way we do the smoothing, srtt and rttvar 122 * will each average +1/2 tick of bias. When we compute 123 * the retransmit timer, we want 1/2 tick of rounding and 124 * 1 extra tick because of +-1/2 tick uncertainty in the 125 * firing of the timer. The bias will give us exactly the 126 * 1.5 tick we need. But, because the bias is 127 * statistical, we have to test that we don't drop below 128 * the minimum feasible timer (which is 2 ticks). 129 * This macro assumes that the value of TCP_RTTVAR_SCALE 130 * is the same as the multiplier for rttvar. 131 */ 132 #define TCP_REXMTVAL(tp) \ 133 (((tp)->t_srtt >> TCP_RTT_SHIFT) + (tp)->t_rttvar) 134 135 /* XXX 136 * We want to avoid doing m_pullup on incoming packets but that 137 * means avoiding dtom on the tcp reassembly code. That in turn means 138 * keeping an mbuf pointer in the reassembly queue (since we might 139 * have a cluster). As a quick hack, the source & destination 140 * port numbers (which are no longer needed once we've located the 141 * tcpcb) are overlayed with an mbuf pointer. 142 */ 143 #define REASS_MBUF(ti) (*(struct mbuf **)&((ti)->ti_t)) 144 145 /* 146 * TCP statistics. 147 * Many of these should be kept per connection, 148 * but that's inconvenient at the moment. 149 */ 150 struct tcpstat { 151 u_long tcps_connattempt; /* connections initiated */ 152 u_long tcps_accepts; /* connections accepted */ 153 u_long tcps_connects; /* connections established */ 154 u_long tcps_drops; /* connections dropped */ 155 u_long tcps_conndrops; /* embryonic connections dropped */ 156 u_long tcps_closed; /* conn. closed (includes drops) */ 157 u_long tcps_segstimed; /* segs where we tried to get rtt */ 158 u_long tcps_rttupdated; /* times we succeeded */ 159 u_long tcps_delack; /* delayed acks sent */ 160 u_long tcps_timeoutdrop; /* conn. dropped in rxmt timeout */ 161 u_long tcps_rexmttimeo; /* retransmit timeouts */ 162 u_long tcps_persisttimeo; /* persist timeouts */ 163 u_long tcps_keeptimeo; /* keepalive timeouts */ 164 u_long tcps_keepprobe; /* keepalive probes sent */ 165 u_long tcps_keepdrops; /* connections dropped in keepalive */ 166 167 u_long tcps_sndtotal; /* total packets sent */ 168 u_long tcps_sndpack; /* data packets sent */ 169 u_long tcps_sndbyte; /* data bytes sent */ 170 u_long tcps_sndrexmitpack; /* data packets retransmitted */ 171 u_long tcps_sndrexmitbyte; /* data bytes retransmitted */ 172 u_long tcps_sndacks; /* ack-only packets sent */ 173 u_long tcps_sndprobe; /* window probes sent */ 174 u_long tcps_sndurg; /* packets sent with URG only */ 175 u_long tcps_sndwinup; /* window update-only packets sent */ 176 u_long tcps_sndctrl; /* control (SYN|FIN|RST) packets sent */ 177 178 u_long tcps_rcvtotal; /* total packets received */ 179 u_long tcps_rcvpack; /* packets received in sequence */ 180 u_long tcps_rcvbyte; /* bytes received in sequence */ 181 u_long tcps_rcvbadsum; /* packets received with ccksum errs */ 182 u_long tcps_rcvbadoff; /* packets received with bad offset */ 183 u_long tcps_rcvshort; /* packets received too short */ 184 u_long tcps_rcvduppack; /* duplicate-only packets received */ 185 u_long tcps_rcvdupbyte; /* duplicate-only bytes received */ 186 u_long tcps_rcvpartduppack; /* packets with some duplicate data */ 187 u_long tcps_rcvpartdupbyte; /* dup. bytes in part-dup. packets */ 188 u_long tcps_rcvoopack; /* out-of-order packets received */ 189 u_long tcps_rcvoobyte; /* out-of-order bytes received */ 190 u_long tcps_rcvpackafterwin; /* packets with data after window */ 191 u_long tcps_rcvbyteafterwin; /* bytes rcvd after window */ 192 u_long tcps_rcvafterclose; /* packets rcvd after "close" */ 193 u_long tcps_rcvwinprobe; /* rcvd window probe packets */ 194 u_long tcps_rcvdupack; /* rcvd duplicate acks */ 195 u_long tcps_rcvacktoomuch; /* rcvd acks for unsent data */ 196 u_long tcps_rcvackpack; /* rcvd ack packets */ 197 u_long tcps_rcvackbyte; /* bytes acked by rcvd acks */ 198 u_long tcps_rcvwinupd; /* rcvd window update packets */ 199 u_long tcps_pawsdrop; /* segments dropped due to PAWS */ 200 }; 201 202 #ifdef KERNEL 203 struct inpcb tcb; /* head of queue of active tcpcb's */ 204 struct tcpstat tcpstat; /* tcp statistics */ 205 u_long tcp_now; /* for RFC 1323 timestamps */ 206 struct tcpiphdr *tcp_template(); 207 struct tcpcb *tcp_close(), *tcp_drop(); 208 struct tcpcb *tcp_timers(), *tcp_disconnect(), *tcp_usrclosed(); 209 #endif 210