tcp_var.h
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:13k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* tcp_var.h - tcp variables header file */
  2. /* Copyright 1984 - 2002 Wind River Systems, Inc. */
  3. /*
  4.  * Copyright (c) 1982, 1986, 1993, 1994, 1995
  5.  * The Regents of the University of California.  All rights reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  * 1. Redistributions of source code must retain the above copyright
  11.  *    notice, this list of conditions and the following disclaimer.
  12.  * 2. Redistributions in binary form must reproduce the above copyright
  13.  *    notice, this list of conditions and the following disclaimer in the
  14.  *    documentation and/or other materials provided with the distribution.
  15.  * 3. All advertising materials mentioning features or use of this software
  16.  *    must display the following acknowledgement:
  17.  * This product includes software developed by the University of
  18.  * California, Berkeley and its contributors.
  19.  * 4. Neither the name of the University nor the names of its contributors
  20.  *    may be used to endorse or promote products derived from this software
  21.  *    without specific prior written permission.
  22.  *
  23.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  24.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  27.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  28.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  29.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  30.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  32.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  33.  * SUCH DAMAGE.
  34.  *
  35.  * @(#)tcp_var.h 8.4 (Berkeley) 5/24/95
  36.  */
  37. /*
  38. modification history
  39. --------------------
  40. 01g,05jun02,vvv  replaced TF_PREV_SMALL with TF_EOB (SPR #72213)
  41. 01f,06mar02,vvv  added new flag TF_PREV_SMALL (SPR #72213)
  42. 01e,10oct01,rae  merge from truestack ver 01f, base 01c
  43. 01d,10nov00,spm  merged from version 01d of tor3_x branch (SPR #31996 fix)
  44. 01c,31mar97,vin  added changes for pcb hashlookups.
  45. 01b,30oct96,vin  changed tcp_template to mbuf from tcp_iphdr so that dtom
  46.  wont be necessary.
  47. 01a,03mar96,vin  created from BSD4.4 stuff, integrated with 02p of tcp_var.h
  48. */
  49. #ifndef __INCtcp_varh
  50. #define __INCtcp_varh
  51. #ifdef __cplusplus
  52. extern "C" {
  53. #endif
  54. /* includes */
  55. #include "netinet/tcp_timer.h"
  56. #include "netinet/ip.h"
  57. #if ((CPU_FAMILY==I960) && (defined __GNUC__))
  58. #pragma align 1                 /* tell gcc960 not to optimize alignments */
  59. #endif /* CPU_FAMILY==I960 */
  60. /* Tcp control block, one per tcp; fields: */
  61. struct tcpcb
  62.     {
  63.     struct tcpiphdr *seg_next; /* sequencing queue */
  64.     struct tcpiphdr *seg_prev;
  65.     short t_state; /* state of this connection */
  66.     short t_timer[TCPT_NTIMERS]; /* tcp timers */
  67.     short t_rxtshift; /* log(2) of rexmt exp. backoff */
  68.     short t_rxtcur;               /* current retransmit value */
  69.     short t_dupacks;              /* consecutive dup acks recd */
  70.     u_short t_maxseg; /* maximum segment size */
  71.     char t_force; /* 1 if forcing out a byte */
  72.     u_short t_flags;
  73. #define TF_ACKNOW 0x0001 /* ack peer immediately */
  74. #define TF_DELACK 0x0002 /* ack, but try to delay it */
  75. #define TF_NODELAY 0x0004 /* don't delay packets to coalesce */
  76. #define TF_NOOPT 0x0008 /* don't use tcp options */
  77. #define TF_SENTFIN 0x0010 /* have sent FIN */
  78. #define TF_REQ_SCALE 0x0020 /* have/will request window scaling */
  79. #define TF_RCVD_SCALE 0x0040 /* other side has requested scaling */
  80. #define TF_REQ_TSTMP 0x0080 /* have/will request timestamps */
  81. #define TF_RCVD_TSTMP 0x0100 /* a timestamp was received in SYN */
  82. #define TF_SACK_PERMIT 0x0200 /* other side said I could SACK */
  83. #define TF_EOB          0x0400          /* for Nagle's - last chunk of  */
  84. /* a large data block?          */
  85. struct mbuf * t_template; /* skeletal packet for transmit */
  86. struct inpcb *t_inpcb; /* back pointer to internet pcb */
  87. /*
  88.  * The following fields are used as in the protocol specification.
  89.  * See RFC783, Dec. 1981, page 21.
  90.  */
  91. /* send sequence variables */
  92. tcp_seq snd_una; /* send unacknowledged */
  93. tcp_seq snd_nxt; /* send next */
  94. tcp_seq snd_up; /* send urgent pointer */
  95. tcp_seq snd_wl1; /* window update seg seq number */
  96. tcp_seq snd_wl2; /* window update seg ack number */
  97. tcp_seq iss; /* initial send sequence number */
  98. u_long snd_wnd; /* send window */
  99. /* receive sequence variables */
  100. u_long rcv_wnd; /* receive window */
  101. tcp_seq rcv_nxt; /* receive next */
  102. tcp_seq rcv_up; /* receive urgent pointer */
  103. tcp_seq irs; /* initial receive sequence number */
  104. /*
  105.  * Additional variables for this implementation.
  106.  */
  107. /* receive variables */
  108. tcp_seq rcv_adv; /* advertised window */
  109. /* retransmit variables */
  110. tcp_seq snd_max; /* highest sequence number sent;
  111.  * used to recognize retransmits
  112.  */
  113. /* congestion control (for slow start, source quench, retransmit after loss) */
  114. u_long snd_cwnd; /* congestion-controlled window */
  115. u_long snd_ssthresh; /* snd_cwnd size threshhold for
  116.  * for slow start exponential to
  117.  * linear switch
  118.  */
  119. /*
  120.  * transmit timing stuff.  See below for scale of srtt and rttvar.
  121.  * "Variance" is actually smoothed difference.
  122.  */
  123. u_short t_idle; /* inactivity time */
  124. short t_rtt; /* round trip time */
  125. tcp_seq t_rtseq; /* sequence number being timed */
  126. short t_srtt; /* smoothed round-trip time */
  127. short t_rttvar; /* variance in round-trip time */
  128. u_short t_rttmin; /* minimum rtt allowed */
  129. u_long max_sndwnd; /* largest window peer has offered */
  130. /* out-of-band data */
  131. char t_oobflags; /* have some */
  132. char t_iobc; /* input character */
  133. #define TCPOOB_HAVEDATA 0x01
  134. #define TCPOOB_HADDATA 0x02
  135. short t_softerror; /* possible error not yet reported */
  136. /* RFC 1323 variables */
  137. u_char snd_scale; /* window scaling for send window */
  138. u_char rcv_scale; /* window scaling for recv window */
  139. u_char request_r_scale; /* pending window scaling */
  140. u_char requested_s_scale;
  141. u_long ts_recent; /* timestamp echo data */
  142. u_long ts_recent_age; /* when last updated */
  143. tcp_seq last_ack_sent;
  144. /* Path MTU values */
  145.         u_int   t_maxsize;  /* max segment, ignoring send buffer */
  146. };
  147. #define intotcpcb(ip) ((struct tcpcb *)(ip)->inp_ppcb)
  148. #define sototcpcb(so) (intotcpcb(sotoinpcb(so)))
  149. /*
  150.  * The smoothed round-trip time and estimated variance
  151.  * are stored as fixed point numbers scaled by the values below.
  152.  * For convenience, these scales are also used in smoothing the average
  153.  * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed).
  154.  * With these scales, srtt has 3 bits to the right of the binary point,
  155.  * and thus an "ALPHA" of 0.875.  rttvar has 2 bits to the right of the
  156.  * binary point, and is smoothed with an ALPHA of 0.75.
  157.  */
  158. #define TCP_RTT_SCALE 8 /* multiplier for srtt; 3 bits frac. */
  159. #define TCP_RTT_SHIFT 3 /* shift for srtt; 3 bits frac. */
  160. #define TCP_RTTVAR_SCALE 4 /* multiplier for rttvar; 2 bits */
  161. #define TCP_RTTVAR_SHIFT 2 /* multiplier for rttvar; 2 bits */
  162. /*
  163.  * The initial retransmission should happen at rtt + 4 * rttvar.
  164.  * Because of the way we do the smoothing, srtt and rttvar
  165.  * will each average +1/2 tick of bias.  When we compute
  166.  * the retransmit timer, we want 1/2 tick of rounding and
  167.  * 1 extra tick because of +-1/2 tick uncertainty in the
  168.  * firing of the timer.  The bias will give us exactly the
  169.  * 1.5 tick we need.  But, because the bias is
  170.  * statistical, we have to test that we don't drop below
  171.  * the minimum feasible timer (which is 2 ticks).
  172.  * This macro assumes that the value of TCP_RTTVAR_SCALE
  173.  * is the same as the multiplier for rttvar.
  174.  */
  175. #define TCP_REXMTVAL(tp) 
  176. (((tp)->t_srtt >> TCP_RTT_SHIFT) + (tp)->t_rttvar)
  177. /* XXX
  178.  * We want to avoid doing m_pullup on incoming packets but that
  179.  * means avoiding dtom on the tcp reassembly code.  That in turn means
  180.  * keeping an mbuf pointer in the reassembly queue (since we might
  181.  * have a cluster).  As a quick hack, the source & destination
  182.  * port numbers (which are no longer needed once we've located the
  183.  * tcpcb) are overlayed with an mbuf pointer.
  184.  */
  185. #define REASS_MBUF(ti) (*(struct mbuf **)&((ti)->ti_t))
  186. /*
  187.  * TCP statistics.
  188.  * Many of these should be kept per connection,
  189.  * but that's inconvenient at the moment.
  190.  */
  191. struct tcpstat {
  192. u_long tcps_connattempt; /* connections initiated */
  193. u_long tcps_accepts; /* connections accepted */
  194. u_long tcps_connects; /* connections established */
  195. u_long tcps_drops; /* connections dropped */
  196. u_long tcps_conndrops; /* embryonic connections dropped */
  197. u_long tcps_closed; /* conn. closed (includes drops) */
  198. u_long tcps_segstimed; /* segs where we tried to get rtt */
  199. u_long tcps_rttupdated; /* times we succeeded */
  200. u_long tcps_delack; /* delayed acks sent */
  201. u_long tcps_timeoutdrop; /* conn. dropped in rxmt timeout */
  202. u_long tcps_rexmttimeo; /* retransmit timeouts */
  203. u_long tcps_persisttimeo; /* persist timeouts */
  204. u_long tcps_keeptimeo; /* keepalive timeouts */
  205. u_long tcps_keepprobe; /* keepalive probes sent */
  206. u_long tcps_keepdrops; /* connections dropped in keepalive */
  207. u_long tcps_sndtotal; /* total packets sent */
  208. u_long tcps_sndpack; /* data packets sent */
  209. u_long tcps_sndbyte; /* data bytes sent */
  210. u_long tcps_sndrexmitpack; /* data packets retransmitted */
  211. u_long tcps_sndrexmitbyte; /* data bytes retransmitted */
  212. u_long tcps_sndacks; /* ack-only packets sent */
  213. u_long tcps_sndprobe; /* window probes sent */
  214. u_long tcps_sndurg; /* packets sent with URG only */
  215. u_long tcps_sndwinup; /* window update-only packets sent */
  216. u_long tcps_sndctrl; /* control (SYN|FIN|RST) packets sent */
  217. u_long tcps_rcvtotal; /* total packets received */
  218. u_long tcps_rcvpack; /* packets received in sequence */
  219. u_long tcps_rcvbyte; /* bytes received in sequence */
  220. u_long tcps_rcvbadsum; /* packets received with ccksum errs */
  221. u_long tcps_rcvbadoff; /* packets received with bad offset */
  222. u_long tcps_rcvshort; /* packets received too short */
  223. u_long tcps_rcvduppack; /* duplicate-only packets received */
  224. u_long tcps_rcvdupbyte; /* duplicate-only bytes received */
  225. u_long tcps_rcvpartduppack; /* packets with some duplicate data */
  226. u_long tcps_rcvpartdupbyte; /* dup. bytes in part-dup. packets */
  227. u_long tcps_rcvoopack; /* out-of-order packets received */
  228. u_long tcps_rcvoobyte; /* out-of-order bytes received */
  229. u_long tcps_rcvpackafterwin; /* packets with data after window */
  230. u_long tcps_rcvbyteafterwin; /* bytes rcvd after window */
  231. u_long tcps_rcvafterclose; /* packets rcvd after "close" */
  232. u_long tcps_rcvwinprobe; /* rcvd window probe packets */
  233. u_long tcps_rcvdupack; /* rcvd duplicate acks */
  234. u_long tcps_rcvacktoomuch; /* rcvd acks for unsent data */
  235. u_long tcps_rcvackpack; /* rcvd ack packets */
  236. u_long tcps_rcvackbyte; /* bytes acked by rcvd acks */
  237. u_long tcps_rcvwinupd; /* rcvd window update packets */
  238. u_long tcps_pawsdrop; /* segments dropped due to PAWS */
  239. u_long tcps_predack; /* times hdr predict ok for acks */
  240. u_long tcps_preddat; /* times hdr predict ok for data pkts */
  241. u_long tcps_pcbcachemiss;
  242. u_long tcps_persistdrop; /* timeout in persist state */
  243. u_long tcps_badsyn; /* bogus SYN, e.g. premature ACK */
  244. };
  245. #if ((CPU_FAMILY==I960) && (defined __GNUC__))
  246. #pragma align 0                 /* turn off alignment requirement */
  247. #endif /* CPU_FAMILY==I960 */
  248. #ifndef VIRTUAL_STACK
  249. #define tcb tcpcb /* resolve the conflit tcb */
  250. extern long tcpOutRsts; /* MIB-II Variable */
  251. extern  struct inpcbhead tcb;           /* head of queue of active tcpcb's */
  252. extern  struct inpcbinfo tcbinfo;
  253. IMPORT struct tcpstat tcpstat; /* tcp statistics */
  254. extern u_long tcp_now; /* for RFC 1323 timestamps */
  255. #endif
  256. extern int tcp_attach (struct socket *);
  257. extern void tcp_canceltimers (struct tcpcb *);
  258. extern struct tcpcb * tcp_close (struct tcpcb *);
  259. extern void tcp_ctlinput (int, struct sockaddr *, struct ip *);
  260. extern int tcp_ctloutput (int, struct socket *, int, int, struct mbuf **);
  261. extern struct tcpcb * tcp_disconnect (struct tcpcb *);
  262. extern struct tcpcb * tcp_drop (struct tcpcb *, int);
  263. extern void tcp_dooptions (struct tcpcb *, u_char *, int, struct tcpiphdr *,
  264.    int *, u_long *, u_long *);
  265. extern void tcp_drain (void);
  266. extern void tcp_fasttimo (void);
  267. extern void tcp_init (void);
  268. extern void tcp_input (struct mbuf *, int);
  269. extern int tcp_mss (struct tcpcb *, u_int);
  270. extern struct tcpcb * tcp_newtcpcb (struct inpcb *);
  271. extern void tcp_notify (struct inpcb *, int);
  272. extern int tcp_output (struct tcpcb *);
  273. extern void tcp_pulloutofband (struct socket *, struct tcpiphdr *, 
  274.        struct mbuf *);
  275. extern void tcp_quench (struct inpcb *, int);
  276. extern void tcp_updatemtu (struct inpcb *, int);
  277. extern int tcp_reass (struct tcpcb *, struct tcpiphdr *, struct mbuf *);
  278. extern void tcp_respond (struct tcpcb *, struct tcpiphdr *, struct mbuf *,
  279.  u_long, u_long, int);
  280. extern void tcp_setpersist (struct tcpcb *);
  281. extern void tcp_slowtimo (void);
  282. extern int tcpRandHookAdd(FUNCPTR pTcpRandFunc);
  283. extern void tcpRandHookDelete(void);
  284. extern struct mbuf * tcp_template (struct tcpcb *);
  285. extern struct tcpcb * tcp_timers (struct tcpcb *, int);
  286. extern struct tcpcb * tcp_usrclosed (struct tcpcb *);
  287. extern int tcp_usrreq (struct socket *, int, struct mbuf *, struct mbuf *, 
  288.        struct mbuf *);
  289. extern void tcp_xmit_timer (struct tcpcb *, int);
  290. #ifdef __cplusplus
  291. }
  292. #endif
  293. #endif /* __INCtcp_varh */