tcp_var.h revision d2ccf0a73e90713adb9e409b073c4af60325ad73
0N/A/*
5539N/A * Copyright (c) 1982, 1986, 1993, 1994
0N/A * The Regents of the University of California. All rights reserved.
0N/A *
0N/A * Redistribution and use in source and binary forms, with or without
0N/A * modification, are permitted provided that the following conditions
2362N/A * are met:
0N/A * 1. Redistributions of source code must retain the above copyright
2362N/A * notice, this list of conditions and the following disclaimer.
0N/A * 2. Redistributions in binary form must reproduce the above copyright
0N/A * notice, this list of conditions and the following disclaimer in the
0N/A * documentation and/or other materials provided with the distribution.
0N/A * 3. All advertising materials mentioning features or use of this software
0N/A * must display the following acknowledgement:
0N/A * This product includes software developed by the University of
0N/A * California, Berkeley and its contributors.
0N/A * 4. Neither the name of the University nor the names of its contributors
0N/A * may be used to endorse or promote products derived from this software
0N/A * without specific prior written permission.
0N/A *
2362N/A * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2362N/A * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2362N/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0N/A * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
0N/A * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
0N/A * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
0N/A * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
0N/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
0N/A * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
0N/A * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0N/A * SUCH DAMAGE.
0N/A *
0N/A * @(#)tcp_var.h 8.3 (Berkeley) 4/10/94
0N/A * tcp_var.h,v 1.3 1994/08/21 05:27:39 paul Exp
0N/A */
0N/A
0N/A#ifndef _TCP_VAR_H_
0N/A#define _TCP_VAR_H_
0N/A
0N/A#ifdef VBOX_WITH_BSD_REASS
0N/A#include "queue.h"
0N/A#endif /* VBOX_WITH_BSD_REASS */
0N/A
0N/A#include "tcpip.h"
0N/A#include "tcp_timer.h"
0N/A
0N/A#if SIZEOF_CHAR_P == 4
0N/A typedef struct tcpiphdr *tcpiphdrp_32;
0N/A# define u32ptr_done(pData, u32, ptr) do {} while (0)
0N/A# define ptr_to_u32(pData, ptr) (ptr)
0N/A# define u32_to_ptr(pData, u32, type) ((type)(u32))
0N/A#else
0N/A typedef u_int32_t tcpiphdrp_32;
0N/A# include <iprt/types.h>
0N/A# include <iprt/assert.h>
0N/A
0N/A#if defined(VBOX_WITH_BSD_REASS)
0N/A# define u32ptr_done(pData, u32, ptr) do {} while (0)
0N/A# define ptr_to_u32(pData, ptr) (ptr)
0N/A# define u32_to_ptr(pData, u32, type) ((type)(u32))
0N/A#else /* !VBOX_WITH_BSD_REASS */
0N/A# define u32ptr_done(pData, u32, ptr) VBoxU32PtrDone((pData), (ptr), (u32))
0N/A# define ptr_to_u32(pData, ptr) VBoxU32PtrHash((pData), (ptr))
0N/A# define u32_to_ptr(pData, u32, type) ((type)VBoxU32PtrLookup((pData), (u32)))
0N/A#endif /* !VBOX_WITH_BSD_REASS */
0N/A
0N/A#endif
0N/A
0N/A#ifdef VBOX_WITH_BSD_REASS
0N/A/* TCP segment queue entry */
0N/Astruct tseg_qent {
0N/A LIST_ENTRY(tseg_qent) tqe_q;
0N/A int tqe_len; /* TCP segment data length */
0N/A struct tcphdr *tqe_th; /* a pointer to tcp header */
0N/A struct mbuf *tqe_m; /* mbuf contains packet */
0N/A};
0N/ALIST_HEAD(tsegqe_head, tseg_qent);
0N/A#endif
0N/A
0N/A/*
0N/A * Tcp control block, one per tcp; fields:
0N/A */
0N/Astruct tcpcb {
0N/A#ifndef VBOX_WITH_BSD_REASS
0N/A tcpiphdrp_32 seg_next; /* sequencing queue */
0N/A tcpiphdrp_32 seg_prev;
0N/A#else /* VBOX_WITH_BSD_REASS */
0N/A LIST_ENTRY(tcpcb) t_list;
0N/A struct tsegqe_head t_segq; /* segment reassembly queue */
0N/A int t_segqlen; /* segment reassembly queue length */
0N/A#endif /* VBOX_WITH_BSD_REASS */
0N/A short t_state; /* state of this connection */
0N/A short t_timer[TCPT_NTIMERS]; /* tcp timers */
0N/A short t_rxtshift; /* log(2) of rexmt exp. backoff */
0N/A short t_rxtcur; /* current retransmit value */
0N/A short t_dupacks; /* consecutive dup acks recd */
0N/A u_short t_maxseg; /* maximum segment size */
0N/A char t_force; /* 1 if forcing out a byte */
0N/A u_short t_flags;
0N/A#define TF_ACKNOW 0x0001 /* ack peer immediately */
0N/A#define TF_DELACK 0x0002 /* ack, but try to delay it */
0N/A#define TF_NODELAY 0x0004 /* don't delay packets to coalesce */
0N/A#define TF_NOOPT 0x0008 /* don't use tcp options */
0N/A#define TF_SENTFIN 0x0010 /* have sent FIN */
0N/A#define TF_REQ_SCALE 0x0020 /* have/will request window scaling */
0N/A#define TF_RCVD_SCALE 0x0040 /* other side has requested scaling */
0N/A#define TF_REQ_TSTMP 0x0080 /* have/will request timestamps */
0N/A#define TF_RCVD_TSTMP 0x0100 /* a timestamp was received in SYN */
0N/A#define TF_SACK_PERMIT 0x0200 /* other side said I could SACK */
0N/A
0N/A /* Make it static for now */
0N/A/* struct tcpiphdr *t_template; / * skeletal packet for transmit */
0N/A struct tcpiphdr t_template;
0N/A
0N/A struct socket *t_socket; /* back pointer to socket */
0N/A/*
0N/A * The following fields are used as in the protocol specification.
0N/A * See RFC783, Dec. 1981, page 21.
0N/A */
0N/A/* send sequence variables */
0N/A tcp_seq snd_una; /* send unacknowledged */
0N/A tcp_seq snd_nxt; /* send next */
0N/A tcp_seq snd_up; /* send urgent pointer */
0N/A tcp_seq snd_wl1; /* window update seg seq number */
0N/A tcp_seq snd_wl2; /* window update seg ack number */
0N/A tcp_seq iss; /* initial send sequence number */
0N/A u_int32_t snd_wnd; /* send window */
0N/A/* receive sequence variables */
0N/A u_int32_t rcv_wnd; /* receive window */
0N/A tcp_seq rcv_nxt; /* receive next */
0N/A tcp_seq rcv_up; /* receive urgent pointer */
0N/A tcp_seq irs; /* initial receive sequence number */
0N/A/*
0N/A * Additional variables for this implementation.
0N/A */
0N/A/* receive variables */
0N/A tcp_seq rcv_adv; /* advertised window */
0N/A/* retransmit variables */
0N/A tcp_seq snd_max; /* highest sequence number sent;
0N/A * used to recognize retransmits
0N/A */
0N/A/* congestion control (for slow start, source quench, retransmit after loss) */
0N/A u_int32_t snd_cwnd; /* congestion-controlled window */
0N/A u_int32_t snd_ssthresh; /* snd_cwnd size threshold for
0N/A * for slow start exponential to
0N/A * linear switch
5539N/A */
5539N/A/*
5539N/A * transmit timing stuff. See below for scale of srtt and rttvar.
0N/A * "Variance" is actually smoothed difference.
0N/A */
0N/A short t_idle; /* inactivity time */
0N/A short t_rtt; /* round trip time */
0N/A tcp_seq t_rtseq; /* sequence number being timed */
0N/A short t_srtt; /* smoothed round-trip time */
0N/A short t_rttvar; /* variance in round-trip time */
0N/A u_short t_rttmin; /* minimum rtt allowed */
0N/A u_int32_t max_sndwnd; /* largest window peer has offered */
0N/A
0N/A/* out-of-band data */
0N/A char t_oobflags; /* have some */
0N/A char t_iobc; /* input character */
0N/A#define TCPOOB_HAVEDATA 0x01
0N/A#define TCPOOB_HADDATA 0x02
0N/A short t_softerror; /* possible error not yet reported */
0N/A
0N/A/* RFC 1323 variables */
0N/A u_char snd_scale; /* window scaling for send window */
0N/A u_char rcv_scale; /* window scaling for recv window */
0N/A u_char request_r_scale; /* pending window scaling */
0N/A u_char requested_s_scale;
0N/A u_int32_t ts_recent; /* timestamp echo data */
0N/A u_int32_t ts_recent_age; /* when last updated */
0N/A tcp_seq last_ack_sent;
0N/A
0N/A};
0N/A
0N/A#ifdef VBOX_WITH_BSD_REASS
0N/ALIST_HEAD(tcpcbhead, tcpcb);
0N/A#endif /* VBOX_WITH_BSD_REASS */
0N/A
0N/A#define sototcpcb(so) ((so)->so_tcpcb)
0N/A
0N/A/*
0N/A * The smoothed round-trip time and estimated variance
0N/A * are stored as fixed point numbers scaled by the values below.
0N/A * For convenience, these scales are also used in smoothing the average
0N/A * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed).
0N/A * With these scales, srtt has 3 bits to the right of the binary point,
0N/A * and thus an "ALPHA" of 0.875. rttvar has 2 bits to the right of the
0N/A * binary point, and is smoothed with an ALPHA of 0.75.
0N/A */
0N/A#define TCP_RTT_SCALE 8 /* multiplier for srtt; 3 bits frac. */
0N/A#define TCP_RTT_SHIFT 3 /* shift for srtt; 3 bits frac. */
0N/A#define TCP_RTTVAR_SCALE 4 /* multiplier for rttvar; 2 bits */
0N/A#define TCP_RTTVAR_SHIFT 2 /* multiplier for rttvar; 2 bits */
0N/A
0N/A/*
0N/A * The initial retransmission should happen at rtt + 4 * rttvar.
0N/A * Because of the way we do the smoothing, srtt and rttvar
0N/A * will each average +1/2 tick of bias. When we compute
0N/A * the retransmit timer, we want 1/2 tick of rounding and
0N/A * 1 extra tick because of +-1/2 tick uncertainty in the
0N/A * firing of the timer. The bias will give us exactly the
0N/A * 1.5 tick we need. But, because the bias is
0N/A * statistical, we have to test that we don't drop below
0N/A * the minimum feasible timer (which is 2 ticks).
0N/A * This macro assumes that the value of TCP_RTTVAR_SCALE
0N/A * is the same as the multiplier for rttvar.
0N/A */
0N/A#define TCP_REXMTVAL(tp) \
0N/A (((tp)->t_srtt >> TCP_RTT_SHIFT) + (tp)->t_rttvar)
0N/A
0N/A/* XXX
0N/A * We want to avoid doing m_pullup on incoming packets but that
0N/A * means avoiding dtom on the tcp reassembly code. That in turn means
0N/A * keeping an mbuf pointer in the reassembly queue (since we might
0N/A * have a cluster). As a quick hack, the source & destination
0N/A * port numbers (which are no longer needed once we've located the
0N/A * tcpcb) are overlayed with an mbuf pointer.
0N/A */
0N/A#if SIZEOF_CHAR_P == 4
0N/Atypedef struct mbuf *mbufp_32;
0N/A/* VBox change which is too much bother to #ifdef */
0N/A# define REASS_MBUF_SET(ti, p) (*(mbufp_32 *)&((ti)->ti_t)) = (p)
0N/A# define REASS_MBUF_GET(ti) ((struct mbuf *)(*(mbufp_32 *)&((ti)->ti_t)))
0N/A#else
0N/Atypedef u_int32_t mbufp_32;
0N/A/* VBox change which is too much bother to #ifdef */
0N/A# define REASS_MBUF_SET(ti, p) (*(mbufp_32 *)&((ti)->ti_t)) = ptr_to_u32(pData, p)
0N/A# define REASS_MBUF_GET(ti) u32_to_ptr(pData, (*(mbufp_32 *)&((ti)->ti_t)), struct mbuf *)
0N/A#endif
0N/A/*#define REASS_MBUF(ti) (*(mbufp_32 *)&((ti)->ti_t)) - replaced by REASS_MBUF_GET/SET */
0N/A
0N/A/*
0N/A * TCP statistics.
0N/A * Many of these should be kept per connection,
0N/A * but that's inconvenient at the moment.
0N/A */
0N/Astruct tcpstat_t {
0N/A u_long tcps_connattempt; /* connections initiated */
0N/A u_long tcps_accepts; /* connections accepted */
0N/A u_long tcps_connects; /* connections established */
0N/A u_long tcps_drops; /* connections dropped */
0N/A u_long tcps_conndrops; /* embryonic connections dropped */
0N/A u_long tcps_closed; /* conn. closed (includes drops) */
0N/A u_long tcps_segstimed; /* segs where we tried to get rtt */
0N/A u_long tcps_rttupdated; /* times we succeeded */
0N/A u_long tcps_delack; /* delayed acks sent */
0N/A u_long tcps_timeoutdrop; /* conn. dropped in rxmt timeout */
0N/A u_long tcps_rexmttimeo; /* retransmit timeouts */
0N/A u_long tcps_persisttimeo; /* persist timeouts */
0N/A u_long tcps_keeptimeo; /* keepalive timeouts */
0N/A u_long tcps_keepprobe; /* keepalive probes sent */
0N/A u_long tcps_keepdrops; /* connections dropped in keepalive */
0N/A
0N/A u_long tcps_sndtotal; /* total packets sent */
0N/A u_long tcps_sndpack; /* data packets sent */
0N/A u_long tcps_sndbyte; /* data bytes sent */
0N/A u_long tcps_sndrexmitpack; /* data packets retransmitted */
0N/A u_long tcps_sndrexmitbyte; /* data bytes retransmitted */
0N/A u_long tcps_sndacks; /* ack-only packets sent */
0N/A u_long tcps_sndprobe; /* window probes sent */
0N/A u_long tcps_sndurg; /* packets sent with URG only */
0N/A u_long tcps_sndwinup; /* window update-only packets sent */
0N/A u_long tcps_sndctrl; /* control (SYN|FIN|RST) packets sent */
0N/A
0N/A u_long tcps_rcvtotal; /* total packets received */
0N/A u_long tcps_rcvpack; /* packets received in sequence */
0N/A u_long tcps_rcvbyte; /* bytes received in sequence */
0N/A u_long tcps_rcvbadsum; /* packets received with ccksum errs */
0N/A u_long tcps_rcvbadoff; /* packets received with bad offset */
0N/A/* u_long tcps_rcvshort; */ /* packets received too short */
0N/A u_long tcps_rcvduppack; /* duplicate-only packets received */
0N/A u_long tcps_rcvdupbyte; /* duplicate-only bytes received */
0N/A u_long tcps_rcvpartduppack; /* packets with some duplicate data */
0N/A u_long tcps_rcvpartdupbyte; /* dup. bytes in part-dup. packets */
0N/A u_long tcps_rcvoopack; /* out-of-order packets received */
0N/A u_long tcps_rcvoobyte; /* out-of-order bytes received */
0N/A u_long tcps_rcvpackafterwin; /* packets with data after window */
0N/A u_long tcps_rcvbyteafterwin; /* bytes rcvd after window */
0N/A u_long tcps_rcvafterclose; /* packets rcvd after "close" */
0N/A u_long tcps_rcvwinprobe; /* rcvd window probe packets */
0N/A u_long tcps_rcvdupack; /* rcvd duplicate acks */
0N/A u_long tcps_rcvacktoomuch; /* rcvd acks for unsent data */
0N/A u_long tcps_rcvackpack; /* rcvd ack packets */
0N/A u_long tcps_rcvackbyte; /* bytes acked by rcvd acks */
0N/A u_long tcps_rcvwinupd; /* rcvd window update packets */
0N/A/* u_long tcps_pawsdrop; */ /* segments dropped due to PAWS */
0N/A u_long tcps_predack; /* times hdr predict ok for acks */
0N/A u_long tcps_preddat; /* times hdr predict ok for data pkts */
0N/A u_long tcps_socachemiss; /* tcp_last_so misses */
0N/A u_long tcps_didnuttin; /* Times tcp_output didn't do anything XXX */
0N/A#ifdef VBOX_WITH_BSD_REASS
0N/A u_long tcps_rcvmemdrop;
0N/A#endif /* VBOX_WITH_BSD_REASS */
0N/A};
0N/A
0N/A
0N/A#endif
0N/A