]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man9/tcp_functions.9
MFC r313854, r313963: Change the way MaxCmdSN is used.
[FreeBSD/FreeBSD.git] / share / man / man9 / tcp_functions.9
1 .\"
2 .\" Copyright (c) 2016 Jonathan Looney <jtl@FreeBSD.org>
3 .\" All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\"    notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\"    notice, this list of conditions and the following disclaimer in the
12 .\"    documentation and/or other materials provided with the distribution.
13 .\"
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
18 .\" ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 .\" SUCH DAMAGE.
25 .\"
26 .\" $FreeBSD$
27 .\"
28 .Dd June 28, 2016
29 .Dt TCP_FUNCTIONS 9
30 .Os
31 .Sh NAME
32 .Nm tcp_functions
33 .Nd Alternate TCP Stack Framework
34 .Sh SYNOPSIS
35 .In netinet/tcp.h
36 .In netinet/tcp_var.h
37 .Ft int
38 .Fn register_tcp_functions "struct tcp_function_block *blk" "int wait"
39 .Ft int
40 .Fn deregister_tcp_functions "struct tcp_function_block *blk"
41 .Sh DESCRIPTION
42 The
43 .Nm
44 framework allows a kernel developer to implement alternate TCP stacks.
45 The alternate stacks can be compiled in the kernel or can be implemented in
46 loadable kernel modules.
47 This functionality is intended to encourage experimentation with the TCP stack
48 and to allow alternate behaviors to be deployed for different TCP connections
49 on a single system.
50 .Pp
51 A system administrator can set a system default stack.
52 By default, all TCP connections will use the system default stack.
53 Additionally, users can specify a particular stack to use on a per-connection
54 basis.
55 (See
56 .Xr tcp 4
57 for details on setting the system default stack, or selecting a specific stack
58 for a given connection.)
59 .Pp
60 This man page treats "TCP stacks" as synonymous with "function blocks".
61 This is intentional.
62 A "TCP stack" is a collection of functions that implement a set of behavior.
63 Therefore, an alternate "function block" defines an alternate "TCP stack".
64 .Pp
65 .Nm
66 modules must call the
67 .Fn register_tcp_functions
68 function during initialization and successfully call the
69 .Fn deregister_tcp_functions
70 function prior to allowing the module to be unloaded.
71 .Pp
72 The
73 .Fn register_tcp_functions
74 function requests that the system add a specified function block to the system.
75 .Pp
76 The
77 .Fn deregister_tcp_functions
78 function requests that the system remove a specified function block from the
79 system.
80 If the call fails because sockets are still using the specified function block,
81 the system will mark the function block as being in the process of being
82 removed.
83 This will prevent additional sockets from using the specified function block.
84 However, it will not impact sockets that are already using the function block.
85 .Pp
86 The
87 .Fa blk
88 argument is a pointer to a
89 .Vt "struct tcp_function_block" ,
90 which is explained below (see
91 .Sx Function Block Structure ) .
92 The
93 .Fa wait
94 argument is used as the
95 .Fa flags
96 argument to
97 .Xr malloc 9 ,
98 and must be set to one of the valid values defined in that man page.
99 .Ss Function Block Structure
100 The
101 .Fa blk argument is a pointer to a
102 .Vt "struct tcp_function_block" ,
103 which has the following members:
104 .Bd -literal -offset indent
105 struct tcp_function_block {
106         char    tfb_tcp_block_name[TCP_FUNCTION_NAME_LEN_MAX];
107         int     (*tfb_tcp_output)(struct tcpcb *);
108         void    (*tfb_tcp_do_segment)(struct mbuf *, struct tcphdr *,
109                             struct socket *, struct tcpcb *,
110                             int, int, uint8_t,
111                             int);
112         int     (*tfb_tcp_ctloutput)(struct socket *so,
113                             struct sockopt *sopt,
114                             struct inpcb *inp, struct tcpcb *tp);
115         /* Optional memory allocation/free routine */
116         void    (*tfb_tcp_fb_init)(struct tcpcb *);
117         void    (*tfb_tcp_fb_fini)(struct tcpcb *);
118         /* Optional timers, must define all if you define one */
119         int     (*tfb_tcp_timer_stop_all)(struct tcpcb *);
120         void    (*tfb_tcp_timer_activate)(struct tcpcb *,
121                             uint32_t, u_int);
122         int     (*tfb_tcp_timer_active)(struct tcpcb *, uint32_t);
123         void    (*tfb_tcp_timer_stop)(struct tcpcb *, uint32_t);
124         void    (*tfb_tcp_rexmit_tmr)(struct tcpcb *);
125         volatile uint32_t tfb_refcnt;
126         uint32_t  tfb_flags;
127 };
128 .Ed
129 .Pp
130 The
131 .Va tfb_tcp_block_name
132 field identifies the unique name of the TCP stack, and should be no longer than
133 TCP_FUNCTION_NAME_LEN_MAX-1 characters in length.
134 .Pp
135 The
136 .Va tfb_tcp_output ,
137 .Va tfb_tcp_do_segment ,
138 and
139 .Va tfb_tcp_ctloutput
140 fields are pointers to functions that perform the equivalent actions
141 as the default
142 .Fn tcp_output ,
143 .Fn tcp_do_segment ,
144 and
145 .Fn tcp_default_ctloutput
146 functions, respectively.
147 Each of these function pointers must be non-NULL.
148 .Pp
149 If a TCP stack needs to initialize data when a socket first selects the TCP
150 stack (or, when the socket is first opened), it should set a non-NULL
151 pointer in the
152 .Va tfb_tcp_fb_init
153 field.
154 Likewise, if a TCP stack needs to cleanup data when a socket stops using the
155 TCP stack (or, when the socket is closed), it should set a non-NULL pointer
156 in the
157 .Va tfb_tcp_fb_fini
158 field.
159 .Pp
160 If the TCP stack implements additional timers, the TCP stack should set a
161 non-NULL pointer in the
162 .Va tfb_tcp_timer_stop_all ,
163 .Va tfb_tcp_timer_activate ,
164 .Va tfb_tcp_timer_active ,
165 and
166 .Va tfb_tcp_timer_stop
167 fields.
168 These fields should all be
169 .Dv NULL
170 or should all contain pointers to functions.
171 The
172 .Va tfb_tcp_timer_activate ,
173 .Va tfb_tcp_timer_active ,
174 and
175 .Va tfb_tcp_timer_stop
176 functions will be called when the
177 .Fn tcp_timer_activate ,
178 .Fn tcp_timer_active ,
179 and
180 .Fn tcp_timer_stop
181 functions, respectively, are called with a timer type other than the standard
182 types.
183 The functions defined by the TCP stack have the same semantics (both for
184 arguments and return values) as the normal timer functions they supplement.
185 .Pp
186 Additionally, a stack may define its own actions to take when the retransmit
187 timer fires by setting a non-NULL function pointer in the
188 .Va tfb_tcp_rexmit_tmr
189 field.
190 This function is called very early in the process of handling a retransmit
191 timer.
192 However, care must be taken to ensure the retransmit timer leaves the
193 TCP control block in a valid state for the remainder of the retransmit
194 timer logic.
195 .Pp
196 The
197 .Va tfb_refcnt
198 and
199 .Va tfb_flags
200 fields are used by the kernel's TCP code and will be initialized when the
201 TCP stack is registered.
202 .Ss Requirements for Alternate TCP Stacks
203 If the TCP stack needs to store data beyond what is stored in the default
204 TCP control block, the TCP stack can initialize its own per-connection storage.
205 The
206 .Va t_fb_ptr
207 field in the
208 .Vt "struct tcpcb"
209 control block structure has been reserved to hold a pointer to this
210 per-connection storage.
211 If the TCP stack uses this alternate storage, it should understand that the
212 value of the
213 .Va t_fb_ptr
214 pointer may not be initialized to
215 .Dv NULL .
216 Therefore, it should use a
217 .Va tfb_tcp_fb_init
218 function to initialize this field.
219 Additionally, it should use a
220 .Va tfb_tcp_fb_fini
221 function to deallocate storage when the socket is closed.
222 .Pp
223 It is understood that alternate TCP stacks may keep different sets of data.
224 However, in order to ensure that data is available to both the user and the
225 rest of the system in a standardized format, alternate TCP stacks must
226 update all fields in the TCP control block to the greatest extent practical.
227 .Sh RETURN VALUES
228 The
229 .Fn register_tcp_functions
230 and
231 .Fn deregister_tcp_functions
232 functions return zero on success and non-zero on failure.
233 In particular, the
234 .Fn deregister_tcp_functions
235 will return
236 .Er EBUSY
237 until no more connections are using the specified TCP stack.
238 A module calling
239 .Fn deregister_tcp_functions
240 must be prepared to wait until all connections have stopped using the
241 specified TCP stack.
242 .Sh ERRORS
243 The
244 .Fn register_tcp_functions
245 function will fail if:
246 .Bl -tag -width Er
247 .It Bq Er EINVAL
248 Any of the members of the
249 .Fa blk
250 argument are set incorrectly.
251 .It Bq Er ENOMEM
252 The function could not allocate memory for its internal data.
253 .It Bq Er EALREADY
254 A function block is already registered with the same name.
255 .El
256 The
257 .Fn deregister_tcp_functions
258 function will fail if:
259 .Bl -tag -width Er
260 .It Bq Er EPERM
261 The
262 .Fa blk
263 argument references the kernel's compiled-in default function block.
264 .It Bq Er EBUSY
265 The function block is still in use by one or more sockets, or is defined as
266 the current default function block.
267 .It Bq Er ENOENT
268 The
269 .Fa blk
270 argument references a function block that is not currently registered.
271 .Sh SEE ALSO
272 .Xr malloc 9 ,
273 .Xr tcp 4
274 .Sh HISTORY
275 This framework first appeared in
276 .Fx 11.0 .
277 .Sh AUTHORS
278 .An -nosplit
279 The
280 .Nm
281 framework was written by
282 .An Randall Stewart Aq Mt rrs@FreeBSD.org .
283 .Pp
284 This manual page was written by
285 .An Jonathan Looney Aq Mt jtl@FreeBSD.org .