4.4BSD snapshot (revision 8.1); add 1993 to copyright
[unix-history] / usr / src / sys / netinet / tcp_var.h
index 221bbfc..2e533c5 100644 (file)
@@ -1,10 +1,61 @@
 /*
 /*
- * Copyright (c) 1982, 1986 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * Copyright (c) 1982, 1986, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  *
- *     @(#)tcp_var.h   7.5 (Berkeley) %G%
+ * %sccs.include.redist.c%
+ *
+ *     @(#)tcp_var.h   8.1 (Berkeley) %G%
+ */
+
+/*
+ * TCP configuration:  This is a half-assed attempt to make TCP
+ * self-configure for a few varieties of 4.2 and 4.3-based unixes.
+ * If you don't have a) a 4.3bsd vax or b) a 3.x Sun (x<6), check
+ * this carefully (it's probably not right).  Please send me mail
+ * if you run into configuration problems.
+ *  - Van Jacobson (van@lbl-csam.arpa)
+ */
+
+#ifndef BSD
+#define BSD 42 /* if we're not 4.3, pretend we're 4.2 */
+#define OLDSTAT        /* set if we have to use old netstat binaries */
+#endif
+
+/* #define OLDSTAT     /* set if we have to use old netstat binaries */
+
+#if sun || BSD < 43
+#define TCP_COMPAT_42  /* set if we have to interop w/4.2 systems */
+#endif
+
+#ifndef SB_MAX
+#ifdef SB_MAXCOUNT
+#define        SB_MAX  SB_MAXCOUNT     /* Sun has to be a little bit different... */
+#else
+#define SB_MAX 32767           /* XXX */
+#endif SB_MAXCOUNT
+#endif SB_MAX
+
+/*
+ * Bill Nowicki pointed out that the page size (CLBYTES) has
+ * nothing to do with the mbuf cluster size.  So, we followed
+ * Sun's lead and made the new define MCLBYTES stand for the mbuf
+ * cluster size.  The following define makes up backwards compatible
+ * with 4.3 and 4.2.  If CLBYTES is >1024 on your machine, check
+ * this against the mbuf cluster definitions in /usr/include/sys/mbuf.h.
  */
  */
+#ifndef MCLBYTES
+#define        MCLBYTES CLBYTES        /* XXX */
+#endif
+
+/*
+ * The routine in_localaddr is broken in Sun's 3.4.  We redefine ours
+ * (in tcp_input.c) so we use can it but won't have a name conflict.
+ */
+#ifdef sun
+#define in_localaddr tcp_in_localaddr
+#endif
+
+/* --------------- end of TCP config ---------------- */
 
 /*
  * Kernel variables for tcp.
 
 /*
  * Kernel variables for tcp.
@@ -23,12 +74,18 @@ struct tcpcb {
        short   t_dupacks;              /* consecutive dup acks recd */
        u_short t_maxseg;               /* maximum segment size */
        char    t_force;                /* 1 if forcing out a byte */
        short   t_dupacks;              /* consecutive dup acks recd */
        u_short t_maxseg;               /* maximum segment size */
        char    t_force;                /* 1 if forcing out a byte */
-       u_char  t_flags;
-#define        TF_ACKNOW       0x01            /* ack peer immediately */
-#define        TF_DELACK       0x02            /* ack, but try to delay it */
-#define        TF_NODELAY      0x04            /* don't delay packets to coalesce */
-#define        TF_NOOPT        0x08            /* don't use tcp options */
-#define        TF_SENTFIN      0x10            /* have sent FIN */
+       u_short t_flags;
+#define        TF_ACKNOW       0x0001          /* ack peer immediately */
+#define        TF_DELACK       0x0002          /* ack, but try to delay it */
+#define        TF_NODELAY      0x0004          /* don't delay packets to coalesce */
+#define        TF_NOOPT        0x0008          /* don't use tcp options */
+#define        TF_SENTFIN      0x0010          /* have sent FIN */
+#define        TF_REQ_SCALE    0x0020          /* have/will request window scaling */
+#define        TF_RCVD_SCALE   0x0040          /* other side has requested scaling */
+#define        TF_REQ_TSTMP    0x0080          /* have/will request timestamps */
+#define        TF_RCVD_TSTMP   0x0100          /* a timestamp was received in SYN */
+#define        TF_SACK_PERMIT  0x0200          /* other side said I could SACK */
+
        struct  tcpiphdr *t_template;   /* skeletal packet for transmit */
        struct  inpcb *t_inpcb;         /* back pointer to internet pcb */
 /*
        struct  tcpiphdr *t_template;   /* skeletal packet for transmit */
        struct  inpcb *t_inpcb;         /* back pointer to internet pcb */
 /*
@@ -42,9 +99,9 @@ struct tcpcb {
        tcp_seq snd_wl1;                /* window update seg seq number */
        tcp_seq snd_wl2;                /* window update seg ack number */
        tcp_seq iss;                    /* initial send sequence number */
        tcp_seq snd_wl1;                /* window update seg seq number */
        tcp_seq snd_wl2;                /* window update seg ack number */
        tcp_seq iss;                    /* initial send sequence number */
-       u_short snd_wnd;                /* send window */
+       u_long  snd_wnd;                /* send window */
 /* receive sequence variables */
 /* receive sequence variables */
-       u_short rcv_wnd;                /* receive window */
+       u_long  rcv_wnd;                /* receive window */
        tcp_seq rcv_nxt;                /* receive next */
        tcp_seq rcv_up;                 /* receive urgent pointer */
        tcp_seq irs;                    /* initial receive sequence number */
        tcp_seq rcv_nxt;                /* receive next */
        tcp_seq rcv_up;                 /* receive urgent pointer */
        tcp_seq irs;                    /* initial receive sequence number */
@@ -54,18 +111,17 @@ struct tcpcb {
 /* receive variables */
        tcp_seq rcv_adv;                /* advertised window */
 /* retransmit variables */
 /* receive variables */
        tcp_seq rcv_adv;                /* advertised window */
 /* retransmit variables */
-       tcp_seq snd_max;                /* highest sequence number sent
+       tcp_seq snd_max;                /* highest sequence number sent;
                                         * used to recognize retransmits
                                         */
 /* congestion control (for slow start, source quench, retransmit after loss) */
                                         * used to recognize retransmits
                                         */
 /* congestion control (for slow start, source quench, retransmit after loss) */
-       u_short snd_cwnd;               /* congestion-controlled window */
-       u_short snd_ssthresh;           /* snd_cwnd size threshhold for
+       u_long  snd_cwnd;               /* congestion-controlled window */
+       u_long  snd_ssthresh;           /* snd_cwnd size threshhold for
                                         * for slow start exponential to
                                         * for slow start exponential to
-                                        * linear switch */
+                                        * linear switch
+                                        */
 /*
 /*
- * transmit timing stuff.
- * srtt and rttvar are stored as fixed point; for convenience in smoothing,
- * srtt has 3 bits to the right of the binary point, rttvar has 2.
+ * transmit timing stuff.  See below for scale of srtt and rttvar.
  * "Variance" is actually smoothed difference.
  */
        short   t_idle;                 /* inactivity time */
  * "Variance" is actually smoothed difference.
  */
        short   t_idle;                 /* inactivity time */
@@ -73,24 +129,94 @@ struct tcpcb {
        tcp_seq t_rtseq;                /* sequence number being timed */
        short   t_srtt;                 /* smoothed round-trip time */
        short   t_rttvar;               /* variance in round-trip time */
        tcp_seq t_rtseq;                /* sequence number being timed */
        short   t_srtt;                 /* smoothed round-trip time */
        short   t_rttvar;               /* variance in round-trip time */
-       u_short max_rcvd;               /* most peer has sent into window */
-       u_short max_sndwnd;             /* largest window peer has offered */
+       u_short t_rttmin;               /* minimum rtt allowed */
+       u_long  max_sndwnd;             /* largest window peer has offered */
+
 /* out-of-band data */
        char    t_oobflags;             /* have some */
        char    t_iobc;                 /* input character */
 #define        TCPOOB_HAVEDATA 0x01
 #define        TCPOOB_HADDATA  0x02
 /* out-of-band data */
        char    t_oobflags;             /* have some */
        char    t_iobc;                 /* input character */
 #define        TCPOOB_HAVEDATA 0x01
 #define        TCPOOB_HADDATA  0x02
+       short   t_softerror;            /* possible error not yet reported */
+
+/* RFC 1323 variables */
+       u_char  snd_scale;              /* window scaling for send window */
+       u_char  rcv_scale;              /* window scaling for recv window */
+       u_char  request_r_scale;        /* pending window scaling */
+       u_char  requested_s_scale;
+       u_long  ts_recent;              /* timestamp echo data */
+       u_long  ts_recent_age;          /* when last updated */
+       tcp_seq last_ack_sent;
+
+/* TUBA stuff */
+       caddr_t t_tuba_pcb;             /* next level down pcb for TCP over z */
 };
 
 #define        intotcpcb(ip)   ((struct tcpcb *)(ip)->inp_ppcb)
 #define        sototcpcb(so)   (intotcpcb(sotoinpcb(so)))
 
 };
 
 #define        intotcpcb(ip)   ((struct tcpcb *)(ip)->inp_ppcb)
 #define        sototcpcb(so)   (intotcpcb(sotoinpcb(so)))
 
+/*
+ * The smoothed round-trip time and estimated variance
+ * are stored as fixed point numbers scaled by the values below.
+ * For convenience, these scales are also used in smoothing the average
+ * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed).
+ * With these scales, srtt has 3 bits to the right of the binary point,
+ * and thus an "ALPHA" of 0.875.  rttvar has 2 bits to the right of the
+ * binary point, and is smoothed with an ALPHA of 0.75.
+ */
+#define        TCP_RTT_SCALE           8       /* multiplier for srtt; 3 bits frac. */
+#define        TCP_RTT_SHIFT           3       /* shift for srtt; 3 bits frac. */
+#define        TCP_RTTVAR_SCALE        4       /* multiplier for rttvar; 2 bits */
+#define        TCP_RTTVAR_SHIFT        2       /* multiplier for rttvar; 2 bits */
+
+/*
+ * The initial retransmission should happen at rtt + 4 * rttvar.
+ * Because of the way we do the smoothing, srtt and rttvar
+ * will each average +1/2 tick of bias.  When we compute
+ * the retransmit timer, we want 1/2 tick of rounding and
+ * 1 extra tick because of +-1/2 tick uncertainty in the
+ * firing of the timer.  The bias will give us exactly the
+ * 1.5 tick we need.  But, because the bias is
+ * statistical, we have to test that we don't drop below
+ * the minimum feasible timer (which is 2 ticks).
+ * This macro assumes that the value of TCP_RTTVAR_SCALE
+ * is the same as the multiplier for rttvar.
+ */
+#define        TCP_REXMTVAL(tp) \
+       (((tp)->t_srtt >> TCP_RTT_SHIFT) + (tp)->t_rttvar)
+
+/* XXX
+ * We want to avoid doing m_pullup on incoming packets but that
+ * means avoiding dtom on the tcp reassembly code.  That in turn means
+ * keeping an mbuf pointer in the reassembly queue (since we might
+ * have a cluster).  As a quick hack, the source & destination
+ * port numbers (which are no longer needed once we've located the
+ * tcpcb) are overlayed with an mbuf pointer.
+ */
+#define REASS_MBUF(ti) (*(struct mbuf **)&((ti)->ti_t))
+
 /*
  * TCP statistics.
  * Many of these should be kept per connection,
  * but that's inconvenient at the moment.
  */
 struct tcpstat {
 /*
  * TCP statistics.
  * Many of these should be kept per connection,
  * but that's inconvenient at the moment.
  */
 struct tcpstat {
+#ifdef OLDSTAT
+       /*
+        * Declare statistics the same as in 4.3
+        * at the start of tcpstat (same size and
+        * position) for netstat.
+        */
+       int     tcps_rcvbadsum;
+       int     tcps_rcvbadoff;
+       int     tcps_rcvshort;
+       int     tcps_badsegs;
+       int     tcps_unack;
+#define        tcps_badsum     tcps_rcvbadsum
+#define        tcps_badoff     tcps_rcvbadoff
+#define        tcps_hdrops     tcps_rcvshort
+
+#endif OLDSTAT
        u_long  tcps_connattempt;       /* connections initiated */
        u_long  tcps_accepts;           /* connections accepted */
        u_long  tcps_connects;          /* connections established */
        u_long  tcps_connattempt;       /* connections initiated */
        u_long  tcps_accepts;           /* connections accepted */
        u_long  tcps_connects;          /* connections established */
@@ -124,6 +250,7 @@ struct      tcpstat {
        u_long  tcps_rcvbadsum;         /* packets received with ccksum errs */
        u_long  tcps_rcvbadoff;         /* packets received with bad offset */
        u_long  tcps_rcvshort;          /* packets received too short */
        u_long  tcps_rcvbadsum;         /* packets received with ccksum errs */
        u_long  tcps_rcvbadoff;         /* packets received with bad offset */
        u_long  tcps_rcvshort;          /* packets received too short */
+#endif
        u_long  tcps_rcvduppack;        /* duplicate-only packets received */
        u_long  tcps_rcvdupbyte;        /* duplicate-only bytes received */
        u_long  tcps_rcvpartduppack;    /* packets with some duplicate data */
        u_long  tcps_rcvduppack;        /* duplicate-only packets received */
        u_long  tcps_rcvdupbyte;        /* duplicate-only bytes received */
        u_long  tcps_rcvpartduppack;    /* packets with some duplicate data */
@@ -139,12 +266,51 @@ struct    tcpstat {
        u_long  tcps_rcvackpack;        /* rcvd ack packets */
        u_long  tcps_rcvackbyte;        /* bytes acked by rcvd acks */
        u_long  tcps_rcvwinupd;         /* rcvd window update packets */
        u_long  tcps_rcvackpack;        /* rcvd ack packets */
        u_long  tcps_rcvackbyte;        /* bytes acked by rcvd acks */
        u_long  tcps_rcvwinupd;         /* rcvd window update packets */
+       u_long  tcps_pawsdrop;          /* segments dropped due to PAWS */
 };
 
 #ifdef KERNEL
 struct inpcb tcb;              /* head of queue of active tcpcb's */
 struct tcpstat tcpstat;        /* tcp statistics */
 };
 
 #ifdef KERNEL
 struct inpcb tcb;              /* head of queue of active tcpcb's */
 struct tcpstat tcpstat;        /* tcp statistics */
-struct tcpiphdr *tcp_template();
-struct tcpcb *tcp_close(), *tcp_drop();
-struct tcpcb *tcp_timers(), *tcp_disconnect(), *tcp_usrclosed();
+u_long tcp_now;                /* for RFC 1323 timestamps */
+
+int     tcp_attach __P((struct socket *));
+void    tcp_canceltimers __P((struct tcpcb *));
+struct tcpcb *
+        tcp_close __P((struct tcpcb *));
+void    tcp_ctlinput __P((int, struct sockaddr *, struct ip *));
+int     tcp_ctloutput __P((int, struct socket *, int, int, struct mbuf **));
+struct tcpcb *
+        tcp_disconnect __P((struct tcpcb *));
+struct tcpcb *
+        tcp_drop __P((struct tcpcb *, int));
+void    tcp_dooptions __P((struct tcpcb *,
+           u_char *, int, struct tcpiphdr *, int *, u_long *, u_long *));
+void    tcp_drain __P((void));
+void    tcp_fasttimo __P((void));
+void    tcp_init __P((void));
+void    tcp_input __P((struct mbuf *, int));
+int     tcp_mass __P((struct tcpcb *, u_int));
+struct tcpcb *
+        tcp_newtcpcb __P((struct inpcb *));
+void    tcp_notify __P((struct inpcb *, int));
+int     tcp_output __P((struct tcpcb *));
+void    tcp_pulloutofband __P((struct socket *,
+           struct tcpiphdr *, struct mbuf *));
+void    tcp_quench __P((struct inpcb *, int));
+int     tcp_reass __P((struct tcpcb *, struct tcpiphdr *, struct mbuf *));
+void    tcp_respond __P((struct tcpcb *,
+           struct tcpiphdr *, struct mbuf *, u_long, u_long, int));
+void    tcp_setpersist __P((struct tcpcb *));
+void    tcp_slowtimo __P((void));
+struct tcpiphdr *
+        tcp_template __P((struct tcpcb *));
+struct tcpcb *
+        tcp_timers __P((struct tcpcb *, int));
+void    tcp_trace __P((int, int, struct tcpcb *, struct tcpiphdr *, int));
+struct tcpcb *
+        tcp_usrclosed __P((struct tcpcb *));
+int     tcp_usrreq __P((struct socket *,
+           int, struct mbuf *, struct mbuf *, struct mbuf *));
+void    tcp_xmit_timer __P((struct tcpcb *, int));
 #endif
 #endif