#ifndef __tcp_ratelimit_h__
#define __tcp_ratelimit_h__
struct m_snd_tag;
#define RL_MIN_DIVISOR 50
#define RL_DEFAULT_DIVISOR 1000
#define HDWRPACE_INITED 0x0001
#define HDWRPACE_TAGPRESENT 0x0002
#define HDWRPACE_IFPDEPARTED 0x0004
struct tcp_hwrate_limit_table {
const struct tcp_rate_set *ptbl;
struct m_snd_tag *tag;
long rate;
long using;
long rs_num_enobufs;
uint32_t time_between;
uint32_t flags;
};
#define RS_IS_DEFF 0x0001
#define RS_IS_INTF 0x0002
#define RS_NO_PRE 0x0004
#define RS_INT_TBL 0x0010
#define RS_IS_DEAD 0x0020
#define RS_FUNERAL_SCHD 0x0040
#define RS_INTF_NO_SUP 0x0100
struct tcp_rate_set {
struct sysctl_ctx_list sysctl_ctx;
CK_LIST_ENTRY(tcp_rate_set) next;
struct ifnet *rs_ifp;
struct tcp_hwrate_limit_table *rs_rlt;
uint64_t rs_flows_using;
uint64_t rs_flow_limit;
uint32_t rs_if_dunit;
int rs_rate_cnt;
int rs_min_seg;
int rs_highest_valid;
int rs_lowest_valid;
int rs_disable;
int rs_flags;
struct epoch_context rs_epoch_ctx;
};
CK_LIST_HEAD(head_tcp_rate_set, tcp_rate_set);
#define RS_PACING_EXACT_MATCH 0x0001
#define RS_PACING_GT 0x0002
#define RS_PACING_GEQ 0x0004
#define RS_PACING_LT 0x0008
#define RS_PACING_SUB_OK 0x0010
#ifdef _KERNEL
#ifndef ETHERNET_SEGMENT_SIZE
#define ETHERNET_SEGMENT_SIZE 1514
#endif
struct tcpcb;
#ifdef RATELIMIT
#define DETAILED_RATELIMIT_SYSCTL 1
uint64_t inline
tcp_hw_highest_rate(const struct tcp_hwrate_limit_table *rle)
{
return (rle->ptbl->rs_rlt[rle->ptbl->rs_highest_valid].rate);
}
uint64_t
tcp_hw_highest_rate_ifp(struct ifnet *ifp, struct inpcb *inp);
const struct tcp_hwrate_limit_table *
tcp_set_pacing_rate(struct tcpcb *tp, struct ifnet *ifp,
uint64_t bytes_per_sec, int flags, int *error, uint64_t *lower_rate);
const struct tcp_hwrate_limit_table *
tcp_chg_pacing_rate(const struct tcp_hwrate_limit_table *crte,
struct tcpcb *tp, struct ifnet *ifp,
uint64_t bytes_per_sec, int flags, int *error, uint64_t *lower_rate);
void
tcp_rel_pacing_rate(const struct tcp_hwrate_limit_table *crte,
struct tcpcb *tp);
uint32_t
tcp_get_pacing_burst_size_w_divisor(struct tcpcb *tp, uint64_t bw, uint32_t segsiz, int can_use_1mss,
const struct tcp_hwrate_limit_table *te, int *err, int divisor);
void
tcp_rl_log_enobuf(const struct tcp_hwrate_limit_table *rte);
void
tcp_rl_release_ifnet(struct ifnet *ifp);
#else
static inline const struct tcp_hwrate_limit_table *
tcp_set_pacing_rate(struct tcpcb *tp, struct ifnet *ifp,
uint64_t bytes_per_sec, int flags, int *error, uint64_t *lower_rate)
{
if (error)
*error = EOPNOTSUPP;
return (NULL);
}
static inline const struct tcp_hwrate_limit_table *
tcp_chg_pacing_rate(const struct tcp_hwrate_limit_table *crte,
struct tcpcb *tp, struct ifnet *ifp,
uint64_t bytes_per_sec, int flags, int *error, uint64_t *lower_rate)
{
if (error)
*error = EOPNOTSUPP;
return (NULL);
}
static inline void
tcp_rel_pacing_rate(const struct tcp_hwrate_limit_table *crte,
struct tcpcb *tp)
{
return;
}
static uint64_t inline
tcp_hw_highest_rate(const struct tcp_hwrate_limit_table *rle)
{
return (0);
}
static uint64_t inline
tcp_hw_highest_rate_ifp(struct ifnet *ifp, struct inpcb *inp)
{
return (0);
}
static inline uint32_t
tcp_get_pacing_burst_size_w_divisor(struct tcpcb *tp, uint64_t bw, uint32_t segsiz, int can_use_1mss,
const struct tcp_hwrate_limit_table *te, int *err, int divisor)
{
uint64_t bytes;
uint32_t new_tso, min_tso_segs;
if ((divisor == 0) ||
(divisor < RL_MIN_DIVISOR)) {
bytes = bw / RL_DEFAULT_DIVISOR;
} else
bytes = bw / divisor;
if (bytes > 0xffff) {
bytes = 0xffff;
}
new_tso = (bytes + segsiz - 1) / segsiz;
if (can_use_1mss)
min_tso_segs = 1;
else
min_tso_segs = 2;
if (new_tso < min_tso_segs)
new_tso = min_tso_segs;
new_tso *= segsiz;
return (new_tso);
}
static inline void
tcp_rl_log_enobuf(const struct tcp_hwrate_limit_table *rte)
{
}
static inline void
tcp_rl_release_ifnet(struct ifnet *ifp)
{
}
#endif
static inline uint32_t
tcp_get_pacing_burst_size(struct tcpcb *tp, uint64_t bw, uint32_t segsiz, int can_use_1mss,
const struct tcp_hwrate_limit_table *te, int *err)
{
return (tcp_get_pacing_burst_size_w_divisor(tp, bw, segsiz,
can_use_1mss,
te, err, 0));
}
#endif
#endif