+/* RFC 3465 variables */
+ u_int32_t t_bytes_acked; /* ABC "bytes_acked" parameter */
+
+ int t_lastchain; /* amount of packets chained last time around */
+ u_int16_t t_unacksegs; /* received but unacked segments for delaying acks */
+ u_int8_t t_rexmtthresh; /* duplicate ack threshold for entering fast recovery */
+ u_int8_t t_rtimo_probes; /* number of adaptive rtimo probes sent */
+ u_int32_t t_persist_timeout; /* ZWP persistence limit as set by PERSIST_TIMEOUT */
+ u_int32_t t_persist_stop; /* persistence limit deadline if triggered by ZWP */
+ u_int32_t t_notsent_lowat; /* Low water for not sent data */
+
+/* Receiver state for stretch-ack algorithm */
+ u_int32_t rcv_unackwin; /* to measure win for stretching acks */
+ u_int32_t rcv_by_unackwin; /* bytes seen during the last ack-stretching win */
+ u_int32_t rcv_nostrack_ts; /* timestamp when stretch ack was disabled automatically */
+ u_int16_t rcv_waitforss; /* wait for packets during slow-start */
+ u_int16_t ecn_flags;
+#define TE_SETUPSENT 0x01 /* Indicate we have sent ECN-SETUP SYN or SYN-ACK */
+#define TE_SETUPRECEIVED 0x02 /* Indicate we have received ECN-SETUP SYN or SYN-ACK */
+#define TE_SENDIPECT 0x04 /* Indicate we haven't sent or received non-ECN-setup SYN or SYN-ACK */
+#define TE_SENDCWR 0x08 /* Indicate that the next non-retransmit should have the TCP CWR flag set */
+#define TE_SENDECE 0x10 /* Indicate that the next packet should have the TCP ECE flag set */
+#define TE_INRECOVERY 0x20 /* connection entered recovery after receiving ECE */
+#define TE_ECN_ON (TE_SETUPSENT | TE_SETUPRECEIVED) /* Indicate ECN was successfully negotiated on a connection) */
+
+/* state for bad retransmit recovery */
+ u_int32_t snd_cwnd_prev; /* cwnd prior to retransmit */
+ u_int32_t snd_ssthresh_prev; /* ssthresh prior to retransmit */
+ tcp_seq snd_recover_prev; /* snd_recover prior to retransmit */
+ int t_srtt_prev; /* srtt prior to retransmit */
+ int t_rttvar_prev; /* rttvar prior to retransmit */
+ u_int32_t t_badrexmt_time; /* bad rexmt detection time */
+
+/* Packet reordering metric */
+ u_int16_t t_reorderwin; /* Reordering late time offset */
+
+/* SACK related state */
+ int16_t snd_numholes; /* number of holes seen by sender */
+ TAILQ_HEAD(sackhole_head, sackhole) snd_holes;
+ /* SACK scoreboard (sorted) */
+ tcp_seq snd_fack; /* last seq number(+1) sack'd by rcv'r*/
+ int rcv_numsacks; /* # distinct sack blks present */
+ struct sackblk sackblks[MAX_SACK_BLKS]; /* seq nos. of sack blocks */
+ tcp_seq sack_newdata; /* New data xmitted in this recovery
+ episode starts at this seq number */
+ struct sackhint sackhint; /* SACK scoreboard hint */
+
+ u_int32_t t_pktlist_sentlen; /* total bytes in transmit chain */
+ struct mbuf *t_pktlist_head; /* First packet in transmit chain */
+ struct mbuf *t_pktlist_tail; /* Last packet in transmit chain */
+
+ u_int32_t t_keepidle; /* keepalive idle timer (override global if > 0) */
+ u_int32_t t_keepinit; /* connection timeout, i.e. idle time
+ in SYN_SENT or SYN_RECV state */
+ u_int32_t t_keepintvl; /* interval between keepalives */
+ u_int32_t t_keepcnt; /* number of keepalives before close */
+
+ u_int32_t tso_max_segment_size; /* TSO maximum segment unit for NIC */
+ u_int32_t t_pmtud_saved_maxopd; /* MSS saved before performing PMTU-D BlackHole detection */
+ u_int32_t t_pmtud_start_ts; /* Time of PMTUD blackhole detection */
+
+ struct
+ {
+ u_int32_t rxduplicatebytes;
+ u_int32_t rxoutoforderbytes;
+ u_int32_t txretransmitbytes;
+ u_int8_t synrxtshift;
+ u_int8_t unused;
+ u_int16_t unused_pad_to_8;
+ } t_stat;
+
+ /* Background congestion related state */
+ uint32_t rtt_hist[N_RTT_BASE]; /* history of minimum RTT */
+ uint32_t rtt_count; /* Number of RTT samples in recent base history */
+ uint32_t bg_ssthresh; /* Slow start threshold until delay increases */
+ uint32_t t_flagsext; /* Another field to accommodate more flags */
+#define TF_RXTFINDROP 0x1 /* Drop conn after retransmitting FIN 3 times */
+#define TF_RCVUNACK_WAITSS 0x2 /* set when the receiver should not stretch acks */
+#define TF_BWMEAS_INPROGRESS 0x4 /* Indicate BW meas is happening */
+#define TF_MEASURESNDBW 0x8 /* Measure send bw on this connection */
+#define TF_LRO_OFFLOADED 0x10 /* Connection LRO offloaded */
+#define TF_SACK_ENABLE 0x20 /* SACK is enabled */
+#define TF_RECOMPUTE_RTT 0x40 /* recompute RTT after spurious retransmit */
+#define TF_DETECT_READSTALL 0x80 /* Used to detect a stall during read operation */
+#define TF_RECV_THROTTLE 0x100 /* Input throttling active */
+#define TF_NOSTRETCHACK 0x200 /* ack every other packet */
+#define TF_STREAMEOW 0x400 /* Last packet was small indicating end of write */
+#define TF_NOTIMEWAIT 0x800 /* Avoid going into time-wait */
+#define TF_SENT_TLPROBE 0x1000 /* Sent data in PTO */
+#define TF_PKTS_REORDERED 0x2000 /* Detected reordering */
+#define TF_DELAY_RECOVERY 0x4000 /* delay fast recovery */
+#define TF_FORCE 0x8000 /* force 1 byte out */
+#define TF_DISABLE_STRETCHACK 0x10000 /* auto-disable stretch ack */
+#define TF_NOBLACKHOLE_DETECTION 0x20000 /* Disable PMTU blackhole detection */
+
+#if TRAFFIC_MGT
+ /* Inter-arrival jitter related state */
+ uint32_t iaj_rcv_ts; /* tcp clock when the first packet was received */
+ uint16_t iaj_size; /* Size of packet for iaj measurement */
+ uint16_t iaj_small_pkt; /* Count of packets smaller than iaj_size */
+ uint16_t iaj_pktcnt; /* packet count, to avoid throttling initially */
+ uint16_t acc_iaj; /* Accumulated iaj */
+ tcp_seq iaj_rwintop; /* recent max advertised window */
+ uint32_t avg_iaj; /* Mean */
+ uint32_t std_dev_iaj; /* Standard deviation */
+#endif /* TRAFFIC_MGT */
+ struct bwmeas *t_bwmeas; /* State for bandwidth measurement */
+ uint32_t t_lropktlen; /* Bytes in a LRO frame */
+ tcp_seq t_idleat; /* rcv_nxt at idle time */
+ TAILQ_ENTRY(tcpcb) t_twentry; /* link for time wait queue */
+ struct tcp_ccstate *t_ccstate; /* congestion control related state */
+/* Tail loss probe related state */
+ tcp_seq t_tlphighrxt; /* snd_nxt after PTO */
+ u_int32_t t_tlpstart; /* timestamp at PTO */
+#if MPTCP
+ u_int32_t t_mpflags; /* flags for multipath TCP */
+
+#define TMPF_PREESTABLISHED 0x00000001 /* conn in pre-established state */
+#define TMPF_SENT_KEYS 0x00000002 /* indicates that keys were sent */
+#define TMPF_MPTCP_TRUE 0x00000004 /* negotiated MPTCP successfully */
+#define TMPF_MPTCP_RCVD_KEY 0x00000008 /* state for 3-way handshake */
+#define TMPF_SND_MPPRIO 0x00000010 /* send priority of subflow */
+#define TMPF_SND_REM_ADDR 0x00000020 /* initiate address removal */
+#define TMPF_UNUSED 0x00000040 /* address addition acked by peer */
+#define TMPF_JOINED_FLOW 0x00000080 /* Indicates additional flow */
+#define TMPF_BACKUP_PATH 0x00000100 /* Indicates backup path */
+#define TMPF_MPTCP_ACKNOW 0x00000200 /* Send Data ACK */
+#define TMPF_SEND_DSN 0x00000400 /* Send DSN mapping */
+#define TMPF_SEND_DFIN 0x00000800 /* Send Data FIN */
+#define TMPF_RECV_DFIN 0x00001000 /* Recv Data FIN */
+#define TMPF_SENT_JOIN 0x00002000 /* Sent Join */
+#define TMPF_RECVD_JOIN 0x00004000 /* Received Join */
+#define TMPF_RESET 0x00008000 /* Send RST */
+#define TMPF_TCP_FALLBACK 0x00010000 /* Fallback to TCP */
+#define TMPF_FASTCLOSE 0x00020000 /* Send Fastclose option */
+#define TMPF_EMBED_DSN 0x00040000 /* tp has DSN mapping */
+#define TMPF_MPTCP_READY 0x00080000 /* Can send DSS options on data */
+#define TMPF_INFIN_SENT 0x00100000 /* Sent infinite mapping */
+#define TMPF_SND_MPFAIL 0x00200000 /* Received mapping csum failure */
+#define TMPF_FASTJOIN_SEND 0x00400000 /* Fast join early data send */
+#define TMPF_FASTJOINBY2_SEND 0x00800000 /* Fast join send after 3 WHS */
+
+ void *t_mptcb; /* pointer to MPTCP TCB */
+ tcp_seq t_mpuna; /* unacknowledged sequence */
+ struct mpt_dsn_map t_rcv_map; /* Receive mapping list */
+ u_int8_t t_local_aid; /* Addr Id for authentication */
+ u_int8_t t_rem_aid; /* Addr ID of another subflow */
+ u_int8_t t_mprxtshift; /* join retransmission */
+#endif /* MPTCP */
+};
+
+#define IN_FASTRECOVERY(tp) (tp->t_flags & TF_FASTRECOVERY)
+#define SACK_ENABLED(tp) (tp->t_flagsext & TF_SACK_ENABLE)
+
+/*
+ * If the connection is in a throttled state due to advisory feedback from
+ * the interface output queue, reset that state. We do this in favor
+ * of entering recovery because the data transfer during recovery
+ * should be just a trickle and it will help to improve performance.
+ * We also do not want to back off twice in the same RTT.
+ */
+#define ENTER_FASTRECOVERY(_tp_) do { \
+ (_tp_)->t_flags |= TF_FASTRECOVERY; \
+ if (INP_IS_FLOW_CONTROLLED((_tp_)->t_inpcb)) \
+ inp_reset_fc_state((_tp_)->t_inpcb); \
+} while(0)
+
+#define EXIT_FASTRECOVERY(_tp_) do { \
+ (_tp_)->t_flags &= ~TF_FASTRECOVERY; \
+ (_tp_)->t_dupacks = 0; \
+ (_tp_)->t_rexmtthresh = tcprexmtthresh; \
+ (_tp_)->t_bytes_acked = 0; \
+ (_tp_)->ecn_flags &= ~TE_INRECOVERY; \
+ (_tp_)->t_timer[TCPT_PTO] = 0; \
+} while(0)
+
+/*
+ * When the number of duplicate acks received is less than
+ * the retransmit threshold, use Limited Transmit algorithm
+ */
+extern int tcprexmtthresh;
+#define ALLOW_LIMITED_TRANSMIT(_tp_) \
+ ((_tp_)->t_dupacks > 0 && \
+ (_tp_)->t_dupacks < (_tp_)->t_rexmtthresh && \
+ ((_tp_)->t_flagsext & (TF_PKTS_REORDERED|TF_DELAY_RECOVERY)) \
+ != (TF_PKTS_REORDERED|TF_DELAY_RECOVERY))
+
+/*
+ * This condition is true is timestamp option is supported
+ * on a connection.
+ */
+#define TSTMP_SUPPORTED(_tp_) \
+ (((_tp_)->t_flags & (TF_REQ_TSTMP|TF_RCVD_TSTMP)) == \
+ (TF_REQ_TSTMP|TF_RCVD_TSTMP))
+
+/*
+ * Gives number of bytes acked by this ack
+ */
+#define BYTES_ACKED(_th_, _tp_) \
+ ((_th_)->th_ack - (_tp_)->snd_una)
+
+enum tcp_cc_event {
+ TCP_CC_CWND_INIT,
+ TCP_CC_INSEQ_ACK_RCVD,
+ TCP_CC_ACK_RCVD,
+ TCP_CC_ENTER_FASTRECOVERY,
+ TCP_CC_IN_FASTRECOVERY,
+ TCP_CC_EXIT_FASTRECOVERY,
+ TCP_CC_PARTIAL_ACK,
+ TCP_CC_IDLE_TIMEOUT,
+ TCP_CC_REXMT_TIMEOUT,
+ TCP_CC_ECN_RCVD,
+ TCP_CC_BAD_REXMT_RECOVERY,
+ TCP_CC_OUTPUT_ERROR,
+ TCP_CC_CHANGE_ALGO,
+ TCP_CC_FLOW_CONTROL,
+ TCP_CC_SUSPEND,
+ TCP_CC_LIMITED_TRANSMIT,
+ TCP_CC_EARLY_RETRANSMIT,
+ TCP_CC_TLP_RECOVERY,
+ TCP_CC_TLP_RECOVER_LASTPACKET,
+ TCP_CC_DELAY_FASTRECOVERY,
+ TCP_CC_TLP_IN_FASTRECOVERY