+#if TRAFFIC_MGT
+ if (so->so_traffic_mgt_flags & TRAFFIC_MGT_SO_BACKGROUND) {
+ tcpstat.tcps_bg_rcvtotal++;
+
+ /* Take snapshots of pkts recv;
+ * tcpcb should have been initialized to 0 when allocated,
+ * so if 0 then this is the first time we're doing this
+ */
+ if (!tp->tot_recv_snapshot) {
+ tp->tot_recv_snapshot = tcpstat.tcps_rcvtotal;
+ }
+ if (!tp->bg_recv_snapshot) {
+ tp->bg_recv_snapshot = tcpstat.tcps_bg_rcvtotal;
+ }
+ }
+#endif /* TRAFFIC_MGT */
+
+ /*
+ Explicit Congestion Notification - Flag that we need to send ECT if
+ + The IP Congestion experienced flag was set.
+ + Socket is in established state
+ + We negotiated ECN in the TCP setup
+ + This isn't a pure ack (tlen > 0)
+ + The data is in the valid window
+
+ TE_SENDECE will be cleared when we receive a packet with TH_CWR set.
+ */
+ if (ip_ecn == IPTOS_ECN_CE && tp->t_state == TCPS_ESTABLISHED &&
+ (tp->ecn_flags & (TE_SETUPSENT | TE_SETUPRECEIVED)) ==
+ (TE_SETUPSENT | TE_SETUPRECEIVED) && tlen > 0 &&
+ SEQ_GEQ(th->th_seq, tp->last_ack_sent) &&
+ SEQ_LT(th->th_seq, tp->last_ack_sent + tp->rcv_wnd)) {
+ tp->ecn_flags |= TE_SENDECE;
+ }
+
+ /*
+ Clear TE_SENDECE if TH_CWR is set. This is harmless, so we don't
+ bother doing extensive checks for state and whatnot.
+ */
+ if ((thflags & TH_CWR) == TH_CWR) {
+ tp->ecn_flags &= ~TE_SENDECE;
+ }
+