]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/netinet/tcp_ratelimit.h
sys/{x86,amd64}: remove one of doubled ;s
[FreeBSD/FreeBSD.git] / sys / netinet / tcp_ratelimit.h
1 /*-
2  *
3  * SPDX-License-Identifier: BSD-3-Clause
4  *
5  * Copyright (c) 2018-2019
6  *      Netflix Inc.
7  *      All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  * __FBSDID("$FreeBSD$");
30  *
31  */
32 /**
33  * Author: Randall Stewart <rrs@netflix.com>
34  */
35 #ifndef __tcp_ratelimit_h__
36 #define __tcp_ratelimit_h__
37
38 struct m_snd_tag;
39
40 /* Flags on an individual rate */
41 #define HDWRPACE_INITED         0x0001
42 #define HDWRPACE_TAGPRESENT     0x0002
43 #define HDWRPACE_IFPDEPARTED    0x0004
44 struct tcp_hwrate_limit_table {
45         const struct tcp_rate_set *ptbl;        /* Pointer to parent table */
46         struct m_snd_tag *tag;  /* Send tag if needed (chelsio) */
47         uint64_t rate;          /* Rate we get in Bytes per second (Bps) */
48         uint32_t time_between;  /* Time-Gap between packets at this rate */
49         uint32_t flags;
50 };
51
52 /* Rateset flags */
53 #define RS_IS_DEFF      0x0001  /* Its a lagg, do a double lookup */
54 #define RS_IS_INTF      0x0002  /* Its a plain interface */
55 #define RS_NO_PRE       0x0004  /* The interfacd has set rates */
56 #define RS_INT_TBL      0x0010  /*
57                                  * The table is the internal version
58                                  * which has special setup requirements.
59                                  */
60 #define RS_IS_DEAD      0x0020  /* The RS is dead list */
61 #define RS_FUNERAL_SCHD 0x0040  /* Is a epoch call scheduled to bury this guy?*/
62 #define RS_INTF_NO_SUP  0x0100  /* The interface does not support the ratelimiting */
63
64 struct tcp_rate_set {
65         struct sysctl_ctx_list sysctl_ctx;
66         CK_LIST_ENTRY(tcp_rate_set) next;
67         struct ifnet *rs_ifp;
68         struct tcp_hwrate_limit_table *rs_rlt;
69         uint64_t rs_flows_using;
70         uint64_t rs_flow_limit;
71         uint32_t rs_if_dunit;
72         int rs_rate_cnt;
73         int rs_min_seg;
74         int rs_highest_valid;
75         int rs_lowest_valid;
76         int rs_disable;
77         int rs_flags;
78         struct epoch_context rs_epoch_ctx;
79 };
80
81 CK_LIST_HEAD(head_tcp_rate_set, tcp_rate_set);
82
83 /* Request flags */
84 #define RS_PACING_EXACT_MATCH   0x0001  /* Need an exact match for rate */
85 #define RS_PACING_GT            0x0002  /* Greater than requested */
86 #define RS_PACING_GEQ           0x0004  /* Greater than or equal too */
87 #define RS_PACING_LT            0x0008  /* Less than requested rate */
88 #define RS_PACING_SUB_OK        0x0010  /* If a rate can't be found get the
89                                          * next best rate (highest or lowest). */
90 #ifdef RATELIMIT
91 #ifdef _KERNEL
92 #define DETAILED_RATELIMIT_SYSCTL 1     /*
93                                          * Undefine this if you don't want
94                                          * detailed rates to appear in
95                                          * net.inet.tcp.rl.
96                                          * With the defintion each rate
97                                          * shows up in your sysctl tree
98                                          * this can be big.
99                                          */
100
101 const struct tcp_hwrate_limit_table *
102 tcp_set_pacing_rate(struct tcpcb *tp, struct ifnet *ifp,
103     uint64_t bytes_per_sec, int flags, int *error);
104
105 const struct tcp_hwrate_limit_table *
106 tcp_chg_pacing_rate(const struct tcp_hwrate_limit_table *crte,
107     struct tcpcb *tp, struct ifnet *ifp,
108     uint64_t bytes_per_sec, int flags, int *error);
109 void
110 tcp_rel_pacing_rate(const struct tcp_hwrate_limit_table *crte,
111     struct tcpcb *tp);
112 #else
113 static inline const struct tcp_hwrate_limit_table *
114 tcp_set_pacing_rate(struct tcpcb *tp, struct ifnet *ifp,
115     uint64_t bytes_per_sec, int flags, int *error)
116 {
117         if (error)
118                 *error = EOPNOTSUPP;
119         return (NULL);
120 }
121
122 static inline const struct tcp_hwrate_limit_table *
123 tcp_chg_pacing_rate(const struct tcp_hwrate_limit_table *crte,
124     struct tcpcb *tp, struct ifnet *ifp,
125     uint64_t bytes_per_sec, int flags, int *error)
126 {
127         if (error)
128                 *error = EOPNOTSUPP;
129         return (NULL);
130 }
131
132 static inline void
133 tcp_rel_pacing_rate(const struct tcp_hwrate_limit_table *crte,
134     struct tcpcb *tp)
135 {
136         return;
137 }
138
139 #endif
140 #endif
141 #endif