add AF_ISO
[unix-history] / usr / src / sys / netinet / tcp_var.h
index 6eebe05..61c672e 100644 (file)
-/*     tcp_var.h       4.6     81/11/24        */
-
 /*
 /*
- * Kernel variables for tcp.
+ * Copyright (c) 1982, 1986 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ *     @(#)tcp_var.h   7.8 (Berkeley) %G%
  */
 
 /*
  */
 
 /*
- * Tcp+ip header, after ip options removed.
+ * 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)
  */
  */
-struct tcpiphdr {
-       struct  ipovly ti_i;            /* overlaid ip structure */
-       struct  tcphdr ti_t;            /* tcp header */
-};
-#define        ti_next         ti_i.ih_next
-#define        ti_prev         ti_i.ih_prev
-#define        ti_x1           ti_i.ih_x1
-#define        ti_pr           ti_i.ih_pr
-#define        ti_len          ti_i.ih_len
-#define        ti_src          ti_i.ih_src
-#define        ti_dst          ti_i.ih_dst
-#define        ti_sport        ti_t.th_sport
-#define        ti_dport        ti_t.th_dport
-#define        ti_seq          ti_t.th_seq
-#define        ti_ackno        ti_t.th_ackno
-#define        ti_x2           ti_t.th_x2
-#define        ti_off          ti_t.th_off
-#define        ti_flags        ti_t.th_flags
-#define        ti_win          ti_t.th_win
-#define        ti_sum          ti_t.th_sum
-#define        ti_urp          ti_t.th_urp
+
+#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
+
+#ifndef IP_MAXPACKET
+#define        IP_MAXPACKET    65535           /* maximum packet size */
+#endif
 
 /*
 
 /*
- * Tcp control block.
+ * 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.
  */
  */
-struct tcpcb {
-       struct  tcpiphdr *seg_next,*seg_prev;   /* seq queue */
-       struct  tcpiphdr *t_template;   /* skeletal packet for transmit */
-       struct  inpcb *t_inpcb;
-       seq_t   iss;                    /* initial send seq # */
-       seq_t   irs;                    /* initial recv seq # */
-       seq_t   rcv_urp;                /* rcv urgent pointer */
-       seq_t   rcv_nxt;                /* next seq # to rcv */
-       seq_t   rcv_end;                /* rcv eol pointer */
-       seq_t   snd_off;                /* seq # of first datum in send buf */
-       seq_t   seq_fin;                /* seq # of FIN sent */
-       seq_t   snd_end;                /* send eol pointer */
-       seq_t   snd_urp;                /* snd urgent pointer */
-       seq_t   snd_lst;                /* seq # of last sent datum */
-       seq_t   snd_nxt;                /* seq # of next datum to send */
-       seq_t   snd_una;                /* seq # of first unacked datum */
-       seq_t   snd_wl;                 /* seq # of last sent window */
-       seq_t   snd_hi;                 /* highest seq # sent */
-       seq_t   snd_wnd;                /* send window max */
-       seq_t   t_rexmt_val;            /* val saved in rexmt timer */
-       seq_t   t_rtl_val;              /* val saved in rexmt too long timer */
-       seq_t   t_xmt_val;              /* seq # sent when xmt timer started */
-       seq_t   rcv_adv;                /* advertised window */
-       struct  mbuf *seg_unack;        /* unacked message queue */
-       short   seqcnt;
-       u_short tc_flags;               /* flags and state; see below */
-       u_short t_options;
-#define        TO_EOL          0x01            /* eol mode */
-#define        TO_URG          0x02            /* urgent mode */
-       u_char  t_state;                /* state of this connection */
-       u_char  t_xmtime;               /* current rexmt time */
-/* timers... must be in order */
-       short   t_init;                 /* init */
-       short   t_rexmt;                /* retransmission */
-       short   t_rexmttl;              /* retransmit too long */
-       short   t_persist;              /* retransmit persistance */
-       short   t_finack;               /* fin acknowledged */
-       short   t_xmt;                  /* round trip transmission time */
-/* end timers */
-};
+#ifndef MCLBYTES
+#define        MCLBYTES CLBYTES        /* XXX */
+#endif
 
 
-/* tc_flags values */
-#define        TC_ACK_DUE      0x0001          /* must we send ACK */
-#define        TC_CANCELLED    0x0002          /* retransmit timer cancelled */
-#define        TC_FIN_RCVD     0x0004          /* FIN received */
-#define        TC_FORCE_ONE    0x0008          /* force sending of one byte */
-#define        TC_NEW_WINDOW   0x0010          /* received new window size */
-#define        TC_REXMT        0x0020          /* this msg is a retransmission */
-#define        TC_SND_FIN      0x0040          /* FIN should be sent */
-#define        TC_SND_RST      0x0080          /* RST should be sent */
-#define        TC_SND_URG      0x0100          /* urgent data to send */
-#define        TC_SYN_ACKED    0x0200          /* SYN has been ACKed */
-#define        TC_SYN_RCVD     0x0400          /* SYN has been received */
-#define        TC_USR_CLOSED   0x0800          /* user has closed connection */
-#define        TC_USR_ABORT    0x1000          /* user has closed and does not expect
-                                          to receive any more data */
 /*
 /*
- * TCP timers.
+ * 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.
  */
  */
-#define        TINIT           0
-#define        TREXMT          1
-#define        TREXMTTL        2
-#define        TPERSIST        3
-#define        TFINACK         4
-#define        TNTIMERS        5
+#ifdef sun
+#define in_localaddr tcp_in_localaddr
+#endif
 
 
-#define        intotcpcb(ip)   ((struct tcpcb *)(ip)->inp_ppcb)
-#define        sototcpcb(so)   (intotcpcb(sotoinpcb(so)))
+/* --------------- end of TCP config ---------------- */
 
 /*
 
 /*
- * Tcp machine predicates
+ * 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)
  */
  */
-#define        ack_ok(x, y) \
-    (((y)->ti_flags&TH_ACK)==0 || \
-      ((x)->iss < (y)->ti_ackno && (y)->ti_ackno <= (x)->snd_hi))
 
 
-#define        syn_ok(x, y) \
-    ((y)->ti_flags&TH_SYN)
+#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        ack_fin(x, y) \
-    ((x)->seq_fin > (x)->iss && (y)->ti_ackno > (x)->seq_fin)
+/* #define OLDSTAT     /* set if we have to use old netstat binaries */
 
 
-#define        rcv_empty(x) \
-    (((x)->tc_flags&TC_USR_ABORT) || \
-      ((x)->t_inpcb->inp_socket->so_rcv.sb_mb == NULL && \
-       (x)->seg_next == (x)->seg_prev))
+#if sun || BSD < 43
+#define TCP_COMPAT_42  /* set if we have to interop w/4.2 systems */
+#endif
 
 
-#define        ISSINCR         128             /* increment for iss each second */
-#define        TCPSIZE         20              /* size of TCP leader (bytes) */
+#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
 
 /*
 
 /*
- * THESE NEED TO BE JUSTIFIED!
- *
- * *2 here is because slow timeout routine called every 1/2 second.
+ * 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.
  */
  */
-#define        T_INIT          (30*2)
-#define        T_2ML           (10*2)          /* 2*maximum packet lifetime */
-#define        T_PERS          (5*2)           /* persist time */
-#define        T_REXMT         (1*2)           /* base for retransmission time */
-#define        T_REXMTTL       (30*2)          /* retransmit too long timeout */
-#define        T_REMAX         (30*2)          /* maximum retransmission time */
+#ifdef sun
+#define in_localaddr tcp_in_localaddr
+#endif
 
 
-struct tcpstat {
-       int     tcps_badsum;
-       int     tcps_badoff;
-       int     tcps_hdrops;
-       int     tcps_badsegs;
-       int     tcps_unack;
-};
+/* --------------- end of TCP config ---------------- */
 
 
-#ifdef TCPDEBUG
-#define        TDBSIZE         50
 /*
 /*
- * Tcp debugging record.
+ * Kernel variables for tcp.
+ */
+
+/*
+ * Tcp control block, one per tcp; fields:
+ */
+struct tcpcb {
+       struct  tcpiphdr *seg_next;     /* sequencing queue */
+       struct  tcpiphdr *seg_prev;
+       short   t_state;                /* state of this connection */
+       short   t_timer[TCPT_NTIMERS];  /* tcp timers */
+       short   t_rxtshift;             /* log(2) of rexmt exp. backoff */
+       short   t_rxtcur;               /* current retransmit value */
+       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 */
+       struct  tcpiphdr *t_template;   /* skeletal packet for transmit */
+       struct  inpcb *t_inpcb;         /* back pointer to internet pcb */
+/*
+ * The following fields are used as in the protocol specification.
+ * See RFC783, Dec. 1981, page 21.
  */
  */
-struct tcp_debug {
-       long    td_tod;                 /* time of day */
-       struct  tcbcb *td_tcb;          /* -> tcb */
-       char    td_old;                 /* old state */
-       char    td_inp;                 /* input */
-       char    td_tim;                 /* timer id */
-       char    td_new;                 /* new state */
-       seq_t   td_sno;                 /* seq_t number */
-       seq_t   td_ano;                 /* acknowledgement */
-       u_short td_wno;                 /* window */
-       u_short td_lno;                 /* length */
-       u_char  td_flg;                 /* message flags */
+/* send sequence variables */
+       tcp_seq snd_una;                /* send unacknowledged */
+       tcp_seq snd_nxt;                /* send next */
+       tcp_seq snd_up;                 /* send urgent pointer */
+       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 */
+/* receive sequence variables */
+       u_short rcv_wnd;                /* receive window */
+       tcp_seq rcv_nxt;                /* receive next */
+       tcp_seq rcv_up;                 /* receive urgent pointer */
+       tcp_seq irs;                    /* initial receive sequence number */
+/*
+ * Additional variables for this implementation.
+ */
+/* receive variables */
+       tcp_seq rcv_adv;                /* advertised window */
+/* retransmit variables */
+       tcp_seq snd_max;                /* highest sequence number sent
+                                        * 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
+                                        * for slow start exponential to
+                                        * 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.
+ * "Variance" is actually smoothed difference.
+ */
+       short   t_idle;                 /* inactivity time */
+       short   t_rtt;                  /* 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 */
+/* out-of-band data */
+       char    t_oobflags;             /* have some */
+       char    t_iobc;                 /* input character */
+#define        TCPOOB_HAVEDATA 0x01
+#define        TCPOOB_HADDATA  0x02
 };
 };
+
+#define        intotcpcb(ip)   ((struct tcpcb *)(ip)->inp_ppcb)
+#define        sototcpcb(so)   (intotcpcb(sotoinpcb(so)))
+
+/*
+ * 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
+#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_drops;             /* connections dropped */
+       u_long  tcps_conndrops;         /* embryonic connections dropped */
+       u_long  tcps_closed;            /* conn. closed (includes drops) */
+       u_long  tcps_segstimed;         /* segs where we tried to get rtt */
+       u_long  tcps_rttupdated;        /* times we succeeded */
+       u_long  tcps_delack;            /* delayed acks sent */
+       u_long  tcps_timeoutdrop;       /* conn. dropped in rxmt timeout */
+       u_long  tcps_rexmttimeo;        /* retransmit timeouts */
+       u_long  tcps_persisttimeo;      /* persist timeouts */
+       u_long  tcps_keeptimeo;         /* keepalive timeouts */
+       u_long  tcps_keepprobe;         /* keepalive probes sent */
+       u_long  tcps_keepdrops;         /* connections dropped in keepalive */
+
+       u_long  tcps_sndtotal;          /* total packets sent */
+       u_long  tcps_sndpack;           /* data packets sent */
+       u_long  tcps_sndbyte;           /* data bytes sent */
+       u_long  tcps_sndrexmitpack;     /* data packets retransmitted */
+       u_long  tcps_sndrexmitbyte;     /* data bytes retransmitted */
+       u_long  tcps_sndacks;           /* ack-only packets sent */
+       u_long  tcps_sndprobe;          /* window probes sent */
+       u_long  tcps_sndurg;            /* packets sent with URG only */
+       u_long  tcps_sndwinup;          /* window update-only packets sent */
+       u_long  tcps_sndctrl;           /* control (SYN|FIN|RST) packets sent */
+
+       u_long  tcps_rcvtotal;          /* total packets received */
+       u_long  tcps_rcvpack;           /* packets received in sequence */
+       u_long  tcps_rcvbyte;           /* bytes received in sequence */
+#ifndef OLDSTAT
+#ifndef OLDSTAT
+       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
 #endif
 #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_rcvpartdupbyte;    /* dup. bytes in part-dup. packets */
+       u_long  tcps_rcvoopack;         /* out-of-order packets received */
+       u_long  tcps_rcvoobyte;         /* out-of-order bytes received */
+       u_long  tcps_rcvpackafterwin;   /* packets with data after window */
+       u_long  tcps_rcvbyteafterwin;   /* bytes rcvd after window */
+       u_long  tcps_rcvafterclose;     /* packets rcvd after "close" */
+       u_long  tcps_rcvwinprobe;       /* rcvd window probe packets */
+       u_long  tcps_rcvdupack;         /* rcvd duplicate acks */
+       u_long  tcps_rcvacktoomuch;     /* rcvd acks for unsent data */
+       u_long  tcps_rcvackpack;        /* rcvd ack packets */
+       u_long  tcps_rcvackbyte;        /* bytes acked by rcvd acks */
+       u_long  tcps_rcvwinupd;         /* rcvd window update packets */
+};
 
 #ifdef KERNEL
 
 #ifdef KERNEL
-seq_t  tcp_iss;                        /* tcp initial send seq # */
-struct inpcb tcb;
-struct tcpstat tcpstat;
-#ifdef TCPDEBUG
-int    tcpconsdebug;                   /* set to 1 traces on console */
-struct tcp_debug tcp_debug[TDBSIZE];
-int    tdbx;                   /* rotating index into tcp_debug */
-#endif
+struct inpcb tcb;              /* head of queue of active tcpcb's */
+struct tcpstat tcpstat;        /* tcp statistics */
 struct tcpiphdr *tcp_template();
 struct tcpiphdr *tcp_template();
+struct tcpcb *tcp_close(), *tcp_drop();
+struct tcpcb *tcp_timers(), *tcp_disconnect(), *tcp_usrclosed();
 #endif
 #endif
-
-#define        SEQ_LT(a,b)     ((int)((a)-(b)) < 0)
-#define        SEQ_LEQ(a,b)    ((int)((a)-(b)) <= 0)
-#define        SEQ_GT(a,b)     ((int)((a)-(b)) > 0)
-#define        SEQ_GEQ(a,b)    ((int)((a)-(b)) >= 0)