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