+struct bwmeas*
+tcp_bwmeas_alloc(struct tcpcb *tp)
+{
+ struct bwmeas *elm;
+ elm = zalloc(tcp_bwmeas_zone);
+ if (elm == NULL)
+ return(elm);
+
+ bzero(elm, bwmeas_elm_size);
+ elm->bw_minsizepkts = TCP_BWMEAS_BURST_MINSIZE;
+ elm->bw_maxsizepkts = TCP_BWMEAS_BURST_MAXSIZE;
+ elm->bw_minsize = elm->bw_minsizepkts * tp->t_maxseg;
+ elm->bw_maxsize = elm->bw_maxsizepkts * tp->t_maxseg;
+ return(elm);
+}
+
+void
+tcp_bwmeas_free(struct tcpcb* tp)
+{
+ zfree(tcp_bwmeas_zone, tp->t_bwmeas);
+ tp->t_bwmeas = NULL;
+ tp->t_flagsext &= ~(TF_MEASURESNDBW);
+}
+
+/*
+ * tcpcb_to_otcpcb copies specific bits of a tcpcb to a otcpcb format.
+ * The otcpcb data structure is passed to user space and must not change.
+ */
+static void
+tcpcb_to_otcpcb(struct tcpcb *tp, struct otcpcb *otp)
+{
+ int i;
+
+ otp->t_segq = (u_int32_t)(uintptr_t)tp->t_segq.lh_first;
+ otp->t_dupacks = tp->t_dupacks;
+ for (i = 0; i < TCPT_NTIMERS_EXT; i++)
+ otp->t_timer[i] = tp->t_timer[i];
+ otp->t_inpcb = (_TCPCB_PTR(struct inpcb *))(uintptr_t)tp->t_inpcb;
+ otp->t_state = tp->t_state;
+ otp->t_flags = tp->t_flags;
+ otp->t_force = tp->t_force;
+ otp->snd_una = tp->snd_una;
+ otp->snd_max = tp->snd_max;
+ otp->snd_nxt = tp->snd_nxt;
+ otp->snd_up = tp->snd_up;
+ otp->snd_wl1 = tp->snd_wl1;
+ otp->snd_wl2 = tp->snd_wl2;
+ otp->iss = tp->iss;
+ otp->irs = tp->irs;
+ otp->rcv_nxt = tp->rcv_nxt;
+ otp->rcv_adv = tp->rcv_adv;
+ otp->rcv_wnd = tp->rcv_wnd;
+ otp->rcv_up = tp->rcv_up;
+ otp->snd_wnd = tp->snd_wnd;
+ otp->snd_cwnd = tp->snd_cwnd;
+ otp->snd_ssthresh = tp->snd_ssthresh;
+ otp->t_maxopd = tp->t_maxopd;
+ otp->t_rcvtime = tp->t_rcvtime;
+ otp->t_starttime = tp->t_starttime;
+ otp->t_rtttime = tp->t_rtttime;
+ otp->t_rtseq = tp->t_rtseq;
+ otp->t_rxtcur = tp->t_rxtcur;
+ otp->t_maxseg = tp->t_maxseg;
+ otp->t_srtt = tp->t_srtt;
+ otp->t_rttvar = tp->t_rttvar;
+ otp->t_rxtshift = tp->t_rxtshift;
+ otp->t_rttmin = tp->t_rttmin;
+ otp->t_rttupdated = tp->t_rttupdated;
+ otp->max_sndwnd = tp->max_sndwnd;
+ otp->t_softerror = tp->t_softerror;
+ otp->t_oobflags = tp->t_oobflags;
+ otp->t_iobc = tp->t_iobc;
+ otp->snd_scale = tp->snd_scale;
+ otp->rcv_scale = tp->rcv_scale;
+ otp->request_r_scale = tp->request_r_scale;
+ otp->requested_s_scale = tp->requested_s_scale;
+ otp->ts_recent = tp->ts_recent;
+ otp->ts_recent_age = tp->ts_recent_age;
+ otp->last_ack_sent = tp->last_ack_sent;
+ otp->cc_send = tp->cc_send;
+ otp->cc_recv = tp->cc_recv;
+ otp->snd_recover = tp->snd_recover;
+ otp->snd_cwnd_prev = tp->snd_cwnd_prev;
+ otp->snd_ssthresh_prev = tp->snd_ssthresh_prev;
+ otp->t_badrxtwin = 0;
+}
+