FreeBSD kernel IPv4 code
tcp_ratelimit.h
Go to the documentation of this file.
1/*-
2 *
3 * SPDX-License-Identifier: BSD-3-Clause
4 *
5 * Copyright (c) 2018-2020
6 * Netflix Inc.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 * __FBSDID("$FreeBSD$");
29 *
30 */
34#ifndef __tcp_ratelimit_h__
35#define __tcp_ratelimit_h__
36
37struct m_snd_tag;
38
39/* Flags on an individual rate */
40#define HDWRPACE_INITED 0x0001
41#define HDWRPACE_TAGPRESENT 0x0002
42#define HDWRPACE_IFPDEPARTED 0x0004
44 const struct tcp_rate_set *ptbl; /* Pointer to parent table */
45 struct m_snd_tag *tag; /* Send tag if needed (chelsio) */
46 long rate; /* Rate we get in Bytes per second (Bps) */
47 long using; /* How many flows are using this hdwr rate. */
49 uint32_t time_between; /* Time-Gap between packets at this rate */
51};
52
53/* Rateset flags */
54#define RS_IS_DEFF 0x0001 /* Its a lagg, do a double lookup */
55#define RS_IS_INTF 0x0002 /* Its a plain interface */
56#define RS_NO_PRE 0x0004 /* The interfacd has set rates */
57#define RS_INT_TBL 0x0010 /*
58 * The table is the internal version
59 * which has special setup requirements.
60 */
61#define RS_IS_DEAD 0x0020 /* The RS is dead list */
62#define RS_FUNERAL_SCHD 0x0040 /* Is a epoch call scheduled to bury this guy?*/
63#define RS_INTF_NO_SUP 0x0100 /* The interface does not support the ratelimiting */
66 struct sysctl_ctx_list sysctl_ctx;
68 struct ifnet *rs_ifp;
71 uint64_t rs_flow_limit;
77 int rs_disable;
78 int rs_flags;
79 struct epoch_context rs_epoch_ctx;
80};
81
82CK_LIST_HEAD(head_tcp_rate_set, tcp_rate_set);
84/* Request flags */
85#define RS_PACING_EXACT_MATCH 0x0001 /* Need an exact match for rate */
86#define RS_PACING_GT 0x0002 /* Greater than requested */
87#define RS_PACING_GEQ 0x0004 /* Greater than or equal too */
88#define RS_PACING_LT 0x0008 /* Less than requested rate */
89#define RS_PACING_SUB_OK 0x0010 /* If a rate can't be found get the
90 * next best rate (highest or lowest). */
91#ifdef _KERNEL
92#ifndef ETHERNET_SEGMENT_SIZE
93#define ETHERNET_SEGMENT_SIZE 1514
94#endif
95#ifdef RATELIMIT
96#define DETAILED_RATELIMIT_SYSCTL 1 /*
97 * Undefine this if you don't want
98 * detailed rates to appear in
99 * net.inet.tcp.rl.
100 * With the defintion each rate
101 * shows up in your sysctl tree
102 * this can be big.
103 */
104uint64_t inline
106{
107 return (rle->ptbl->rs_rlt[rle->ptbl->rs_highest_valid].rate);
108}
109
110uint64_t
111tcp_hw_highest_rate_ifp(struct ifnet *ifp, struct inpcb *inp);
112
113const struct tcp_hwrate_limit_table *
114tcp_set_pacing_rate(struct tcpcb *tp, struct ifnet *ifp,
115 uint64_t bytes_per_sec, int flags, int *error, uint64_t *lower_rate);
116
117const struct tcp_hwrate_limit_table *
119 struct tcpcb *tp, struct ifnet *ifp,
120 uint64_t bytes_per_sec, int flags, int *error, uint64_t *lower_rate);
121void
123 struct tcpcb *tp);
124#else
125static inline const struct tcp_hwrate_limit_table *
126tcp_set_pacing_rate(struct tcpcb *tp, struct ifnet *ifp,
127 uint64_t bytes_per_sec, int flags, int *error, uint64_t *lower_rate)
128{
129 if (error)
130 *error = EOPNOTSUPP;
131 return (NULL);
132}
133
134static inline const struct tcp_hwrate_limit_table *
136 struct tcpcb *tp, struct ifnet *ifp,
137 uint64_t bytes_per_sec, int flags, int *error, uint64_t *lower_rate)
138{
139 if (error)
140 *error = EOPNOTSUPP;
141 return (NULL);
142}
143
144static inline void
146 struct tcpcb *tp)
147{
148 return;
149}
150
151static uint64_t inline
153{
154 return (0);
155}
156
157static uint64_t inline
158tcp_hw_highest_rate_ifp(struct ifnet *ifp, struct inpcb *inp)
159{
160 return (0);
161}
162
163
164#endif
165/*
166 * Given a b/w and a segsiz, and optional hardware
167 * rate limit, return the ideal size to burst
168 * out at once. Note the parameter can_use_1mss
169 * dictates if the transport will tolerate a 1mss
170 * limit, if not it will bottom out at 2mss (think
171 * delayed ack).
172 */
174tcp_get_pacing_burst_size(struct tcpcb *tp, uint64_t bw, uint32_t segsiz, int can_use_1mss,
175 const struct tcp_hwrate_limit_table *te, int *err);
176
177
178void
180
181#endif
182#endif
__uint32_t uint32_t
Definition: in.h:62
ipfw_dyn_rule * next
Definition: ip_fw.h:0
Definition: in_pcb.h:217
struct m_snd_tag * tag
Definition: tcp_ratelimit.h:45
const struct tcp_rate_set * ptbl
Definition: tcp_ratelimit.h:44
CK_LIST_ENTRY(tcp_rate_set) next
int rs_highest_valid
Definition: tcp_ratelimit.h:72
struct epoch_context rs_epoch_ctx
Definition: tcp_ratelimit.h:76
uint32_t rs_if_dunit
Definition: tcp_ratelimit.h:69
struct ifnet * rs_ifp
Definition: tcp_ratelimit.h:65
struct tcp_hwrate_limit_table * rs_rlt
Definition: tcp_ratelimit.h:66
uint64_t rs_flow_limit
Definition: tcp_ratelimit.h:68
struct sysctl_ctx_list sysctl_ctx
Definition: tcp_ratelimit.h:63
uint64_t rs_flows_using
Definition: tcp_ratelimit.h:67
Definition: tcp_var.h:132
void tcp_rl_log_enobuf(const struct tcp_hwrate_limit_table *rte)
static uint64_t tcp_hw_highest_rate(const struct tcp_hwrate_limit_table *rle)
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)
static 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)
CK_LIST_HEAD(head_tcp_rate_set, tcp_rate_set)
static 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)
static uint64_t tcp_hw_highest_rate_ifp(struct ifnet *ifp, struct inpcb *inp)
static void tcp_rel_pacing_rate(const struct tcp_hwrate_limit_table *crte, struct tcpcb *tp)