/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* @(#)COPYRIGHT 1.1 (NRL) 17 January 1995
*
* NRL grants permission for redistribution and use in source and binary
* forms, with or without modification, of the software and documentation
* created at NRL provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgements:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* This product includes software developed at the Information
* Technology Division, US Naval Research Laboratory.
* 4. Neither the name of the NRL nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THE SOFTWARE PROVIDED BY NRL IS PROVIDED BY NRL AND CONTRIBUTORS ``AS
* IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NRL OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
* official policies, either expressed or implied, of the US Naval
* Research Laboratory (NRL).
*/
/*-
* Copyright (c) 1997, 1998, 1999, 2001, 2005 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
* NASA Ames Research Center.
* This code is derived from software contributed to The NetBSD Foundation
* by Charles M. Hannum.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Copyright (c) 1982, 1986, 1993, 1994, 1995
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)tcp_var.h 8.4 (Berkeley) 5/24/95
*/
#ifdef TCP_SIGNATURE
/*
* Defines which are needed by the xform_tcp module and tcp_[in|out]put
* for SADB verification and lookup.
*/
#define TCP_SIGLEN 16 /* length of computed digest in bytes */
#define TCP_KEYLEN_MIN 1 /* minimum length of TCP-MD5 key */
#define TCP_KEYLEN_MAX 80 /* maximum length of TCP-MD5 key */
/*
* Only a single SA per host may be specified at this time. An SPI is
* needed in order for the KEY_LOOKUP_SA() lookup to work.
*/
#define TCP_SIG_SPI 0x1000
#endif /* TCP_SIGNATURE */
/*
* Tcp control block, one per tcp; fields:
*/
struct tcpcb {
int t_family; /* address family on the wire */
struct ipqehead segq; /* sequencing queue */
int t_segqlen; /* length of the above */
callout_t t_timer[TCPT_NTIMERS];/* tcp timers */
short t_state; /* state of this connection */
short t_rxtshift; /* log(2) of rexmt exp. backoff */
uint32_t t_rxtcur; /* current retransmit value */
short t_dupacks; /* consecutive dup acks recd */
/*
* t_partialacks:
* <0 not in fast recovery.
* ==0 in fast recovery. has not received partial acks
* >0 in fast recovery. has received partial acks
*/
short t_partialacks; /* partials acks during fast rexmit */
u_short t_peermss; /* peer's maximum segment size */
u_short t_ourmss; /* our's maximum segment size */
u_short t_segsz; /* current segment size in use */
char t_force; /* 1 if forcing out a byte */
u_int 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_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 */
#define TF_SYN_REXMT 0x0400 /* rexmit timer fired on SYN */
#define TF_WILL_SACK 0x0800 /* try to use SACK */
#define TF_REASSEMBLING 0x1000 /* we're busy reassembling */
#define TF_DEAD 0x2000 /* dead and to-be-released */
#define TF_PMTUD_PEND 0x4000 /* Path MTU Discovery pending */
#define TF_ECN_PERMIT 0x10000 /* other side said is ECN-ready */
#define TF_ECN_SND_CWR 0x20000 /* ECN CWR in queue */
#define TF_ECN_SND_ECE 0x40000 /* ECN ECE in queue */
#define TF_SIGNATURE 0x400000 /* require MD5 digests (RFC2385) */
struct mbuf *t_template; /* skeletal packet for transmit */
struct inpcb *t_inpcb; /* back pointer to internet pcb */
callout_t t_delack_ch; /* delayed ACK callout */
/*
* The following fields are used as in the protocol specification.
* See RFC793, Dec. 1981, page 21.
*/
/* 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_long snd_wnd; /* send window */
/*
* snd_recover
* it's basically same as the "recover" variable in RFC 2852 (NewReno).
* when entering fast retransmit, it's set to snd_max.
* newreno uses this to detect partial ack.
* snd_high
* it's basically same as the "send_high" variable in RFC 2852 (NewReno).
* on each RTO, it's set to snd_max.
* newreno uses this to avoid false fast retransmits.
*/
tcp_seq snd_recover;
tcp_seq snd_high;
/* receive sequence variables */
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 */
/*
* Additional variables for this implementation.
*/
/* receive variables */
tcp_seq rcv_adv; /* advertised window */
/*
* retransmit variables
*
* snd_max
* the highest sequence number we've ever sent.
* used to recognize retransmits.
*/
tcp_seq snd_max;
/* congestion control (for slow start, source quench, retransmit after loss) */
u_long snd_cwnd; /* congestion-controlled window */
u_long snd_ssthresh; /* snd_cwnd size threshold for
* for slow start exponential to
* linear switch
*/
/* auto-sizing variables */
u_int rfbuf_cnt; /* recv buffer autoscaling byte count */
uint32_t rfbuf_ts; /* recv buffer autoscaling timestamp */
/*
* transmit timing stuff. See below for scale of srtt and rttvar.
* "Variance" is actually smoothed difference.
*/
uint32_t t_rcvtime; /* time last segment received */
uint32_t t_rtttime; /* time we started measuring rtt */
tcp_seq t_rtseq; /* sequence number being timed */
int32_t t_srtt; /* smoothed round-trip time */
int32_t t_rttvar; /* variance in round-trip time */
uint32_t 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
short t_softerror; /* possible error not yet reported */
/* SACK stuff */
#define TCP_SACK_MAX 3
#define TCPSACK_NONE 0
#define TCPSACK_HAVED 1
u_char rcv_sack_flags; /* SACK flags. */
struct sackblk rcv_dsack_block; /* RX D-SACK block. */
struct ipqehead timeq; /* time sequenced queue. */
struct sackhead snd_holes; /* TX SACK holes. */
int snd_numholes; /* Number of TX SACK holes. */
tcp_seq rcv_lastsack; /* last seq number(+1) sack'd by rcv'r*/
tcp_seq sack_newdata; /* New data xmitted in this recovery
episode starts at this seq number*/
tcp_seq snd_fack; /* FACK TCP. Forward-most data held by
peer. */
/* CUBIC variables */
ulong snd_cubic_wmax; /* W_max */
ulong snd_cubic_wmax_last; /* Used for fast convergence */
ulong snd_cubic_ctime; /* Last congestion time */
/* pointer for syn cache entries*/
LIST_HEAD(, syn_cache) t_sc; /* list of entries by this tcb */
/* prediction of next mbuf when using large window sizes */
struct mbuf *t_lastm; /* last mbuf that data was sent from */
int t_inoff; /* data offset in previous mbuf */
int t_lastoff; /* last data address in mbuf chain */
int t_lastlen; /* last length read from mbuf chain */
/* Path-MTU discovery blackhole detection */
int t_mtudisc; /* perform mtudisc for this tcb */
/* Path-MTU Discovery Information */
u_int t_pmtud_mss_acked; /* MSS acked, lower bound for MTU */
u_int t_pmtud_mtu_sent; /* MTU used, upper bound for MTU */
tcp_seq t_pmtud_th_seq; /* TCP SEQ from ICMP payload */
u_int t_pmtud_nextmtu; /* Advertised Next-Hop MTU from ICMP */
u_short t_pmtud_ip_len; /* IP length from ICMP payload */
u_short t_pmtud_ip_hl; /* IP header length from ICMP payload */
uint8_t t_ecn_retries; /* # of ECN setup retries */
const struct tcp_congctl *t_congctl; /* per TCB congctl algorithm */
/* maintain a few stats per connection: */
uint32_t t_rcvoopack; /* out-of-order packets received */
uint32_t t_sndrexmitpack; /* retransmit packets sent */
uint32_t t_sndzerowin; /* zero-window updates sent */
};
/*
* Macros to aid ECN TCP.
*/
#define TCP_ECN_ALLOWED(tp) (tp->t_flags & TF_ECN_PERMIT)
static __inline int
tcp_reass_lock_try(struct tcpcb *tp)
{
int s;
/*
* Use splvm() -- we're blocking things that would cause
* mbuf allocation.
*/
s = splvm();
if (tp->t_flags & TF_REASSEMBLING) {
splx(s);
return (0);
}
tp->t_flags |= TF_REASSEMBLING;
splx(s);
return (1);
}
static __inline void
tcp_reass_unlock(struct tcpcb *tp)
{
int s;
/*
* See RFC2988 for a discussion of RTO calculation; comments assume
* familiarity with that document.
*
* The smoothed round-trip time and estimated variance are stored as
* fixed point numbers. Historically, srtt was scaled by
* TCP_RTT_SHIFT bits, and rttvar by TCP_RTTVAR_SHIFT bits. Because
* the values coincide with the alpha and beta parameters suggested
* for RTO calculation (1/8 for srtt, 1/4 for rttvar), the combination
* of computing 1/8 of the new value and transforming it to the
* fixed-point representation required zero instructions. However,
* the storage representations no longer coincide with the alpha/beta
* shifts; instead, more fractional bits are present.
*
* The storage representation of srtt is 1/32 slow ticks, or 1/64 s.
* (The assumption that a slow tick is 500 ms should not be present in
* the code.)
*
* The storage representation of rttvar is 1/16 slow ticks, or 1/32 s.
* There may be some confusion about this in the code.
*
* For historical reasons, these scales are also used in smoothing the
* average (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed).
* This results in alpha of 0.125 and beta of 0.25, following RFC2988
* section 2.3
*
* XXX Change SHIFT values to LGWEIGHT and REP_SHIFT, and adjust
* the code to use the correct ones.
*/
#define TCP_RTT_SHIFT 3 /* shift for srtt; 3 bits frac. */
#define TCP_RTTVAR_SHIFT 2 /* multiplier for rttvar; 2 bits */
/*
* Compute TCP retransmission timer, following RFC2988.
* This macro returns a value in slow timeout ticks.
*
* Section 2.2 requires that the RTO value be
* srtt + max(G, 4*RTTVAR)
* where G is the clock granularity.
*
* This comment has not necessarily been updated for the new storage
* representation:
*
* 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 1<<TCP_RTTVAR_SHIFT
* is the same as the multiplier for rttvar.
*
* This macro appears to be wrong; it should be checking rttvar*4 in
* ticks and making sure we use 1 instead if rttvar*4 rounds to 0. It
* appears to be treating srtt as being in the old storage
* representation, resulting in a factor of 4 extra.
*/
#define TCP_REXMTVAL(tp) \
((((tp)->t_srtt >> TCP_RTT_SHIFT) + (tp)->t_rttvar) >> 2)
extern struct inpcbtable tcbtable; /* head of queue of active tcpcb's */
extern const struct pr_usrreqs tcp_usrreqs;
extern u_int32_t tcp_now; /* for RFC 1323 timestamps */
extern int tcp_do_rfc1323; /* enabled/disabled? */
extern int tcp_do_sack; /* SACK enabled/disabled? */
extern int tcp_do_win_scale; /* RFC1323 window scaling enabled/disabled? */
extern int tcp_do_timestamps; /* RFC1323 timestamps enabled/disabled? */
extern int tcp_mssdflt; /* default seg size */
extern int tcp_minmss; /* minimal seg size */
extern int tcp_msl; /* max segment life */
extern int tcp_init_win; /* initial window */
extern int tcp_init_win_local; /* initial window for local nets */
extern int tcp_init_win_max[11];/* max sizes for values of tcp_init_win_* */
extern int tcp_mss_ifmtu; /* take MSS from interface, not in_maxmtu */
extern int tcp_cwm; /* enable Congestion Window Monitoring */
extern int tcp_cwm_burstsize; /* burst size allowed by CWM */
extern int tcp_ack_on_push; /* ACK immediately on PUSH */
extern int tcp_log_refused; /* log refused connections */
extern int tcp_do_ecn; /* TCP ECN enabled/disabled? */
extern int tcp_ecn_maxretries; /* Max ECN setup retries */
extern int tcp_do_rfc1948; /* ISS by cryptographic hash */
extern int tcp_sack_tp_maxholes; /* Max holes per connection. */
extern int tcp_sack_globalmaxholes; /* Max holes per system. */
extern int tcp_sack_globalholes; /* Number of holes present. */
extern int tcp_do_abc; /* RFC3465 ABC enabled/disabled? */
extern int tcp_abc_aggressive; /* 1: L=2*SMSS 0: L=1*SMSS */
extern int tcp_msl_enable; /* enable TIME_WAIT truncation */
extern int tcp_msl_loop; /* MSL for loopback */
extern int tcp_msl_local; /* MSL for 'local' */
extern int tcp_msl_remote; /* MSL otherwise */
extern int tcp_msl_remote_threshold; /* RTT threshold */
extern int tcp_rttlocal; /* Use RTT to decide who's 'local' */
extern int tcp4_vtw_enable;
extern int tcp6_vtw_enable;
extern int tcp_vtw_was_enabled;
extern int tcp_vtw_entries;
extern int tcp_rst_ppslim;
extern int tcp_ackdrop_ppslim;
extern int tcp_do_autorcvbuf;
extern int tcp_autorcvbuf_inc;
extern int tcp_autorcvbuf_max;
extern int tcp_do_autosndbuf;
extern int tcp_autosndbuf_inc;
extern int tcp_autosndbuf_max;