a52ae1fcf1ccfdc6c3a42a269cfa21c388acf5d6
[dragonfly.git] / share / man / man9 / accept_filter.9
1 .\"
2 .\" Copyright (c) 2000 Alfred Perlstein
3 .\"
4 .\" All rights reserved.
5 .\"
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
8 .\" are met:
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\"    notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\"    notice, this list of conditions and the following disclaimer in the
13 .\"    documentation and/or other materials provided with the distribution.
14 .\"
15 .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
16 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 .\"
26 .\" $FreeBSD: src/share/man/man9/accept_filter.9,v 1.13 2004/06/16 08:33:57 ru Exp $
27 .\" $DragonFly: src/share/man/man9/accept_filter.9,v 1.6 2007/09/26 19:18:30 swildner Exp $
28 .\"
29 .Dd June 25, 2000
30 .Os
31 .Dt ACCEPT_FILTER 9
32 .Sh NAME
33 .Nm accept_filter ,
34 .Nm accept_filt_add ,
35 .Nm accept_filt_del ,
36 .Nm accept_filt_generic_mod_event ,
37 .Nm accept_filt_get
38 .Nd filter incoming connections
39 .Sh SYNOPSIS
40 .In sys/types.h
41 .In sys/module.h
42 .In sys/socket.h
43 .Fd #define ACCEPT_FILTER_MOD
44 .In sys/socketvar.h
45 .Ft int
46 .Fn accept_filt_add "struct accept_filter *filt"
47 .Ft int
48 .Fn accept_filt_del "char *name"
49 .Ft int
50 .Fn accept_filt_generic_mod_event "module_t mod" "int event" "void *data"
51 .Ft struct accept_filter *
52 .Fn accept_filt_get "char *name"
53 .Sh DESCRIPTION
54 Accept filters allow an application to request
55 that the kernel pre-process incoming connections.
56 An accept filter is requested via the
57 .Xr setsockopt 2
58 system call, passing in an
59 .Fa optname
60 of
61 .Dv SO_ACCEPTFILTER .
62 .Sh IMPLEMENTATION NOTES
63 A module that wants to be an accept filter
64 must provide a
65 .Vt "struct accept_filter"
66 to the system:
67 .Bd -literal
68 struct accept_filter {
69         char    accf_name[16];
70         void    (*accf_callback)(struct socket *so, void *arg, int waitflag);
71         void *  (*accf_create)(struct socket *so, char *arg);
72         void    (*accf_destroy)(struct socket *so);
73         SLIST_ENTRY(accept_filter) accf_next;   /* next on the list */
74 };
75 .Ed
76 .Pp
77 The module should register it with the function
78 .Fn accept_filt_add ,
79 passing a pointer to a
80 .Vt "struct accept_filter" ,
81 allocated with
82 .Xr kmalloc 9
83 .Pp
84 The fields of
85 .Vt "struct accept_filter"
86 are as follows:
87 .Bl -tag -width ".Va accf_callback"
88 .It Fa accf_name
89 Name of the filter;
90 this is how it will be accessed from userland.
91 .It Fa accf_callback
92 The callback that the kernel will do
93 once the connection is established.
94 It is the same as a socket upcall
95 and will be called when the connection is established
96 and whenever new data arrives on the socket,
97 unless the callback modifies the socket's flags.
98 .It Fa accf_create
99 Called whenever a
100 .Xr setsockopt 2
101 installs the filter onto
102 a listening socket.
103 .It Fa accf_destroy
104 Called whenever the user removes the accept filter on the socket.
105 .El
106 .Pp
107 The
108 .Fn accept_filt_del
109 function passed the same string used in
110 .Fa accept_filter.accf_name
111 during registration with
112 .Fn accept_filt_add ,
113 the kernel will then disallow and further userland use of the filter.
114 .Pp
115 The
116 .Fn accept_filt_get
117 function is used internally to locate which accept filter to use via the
118 .Xr setsockopt 2
119 system call.
120 .Pp
121 The
122 .Fn accept_filt_generic_mod_event
123 function provides a simple way to avoid duplication of code
124 for accept filters which do not use the argument field to load
125 and unload themselves.
126 This function can be used in the
127 .Vt moduledata_t
128 struct for the
129 .Xr DECLARE_MODULE 9
130 macro.
131 .Sh SEE ALSO
132 .Xr setsockopt 2 ,
133 .Xr accf_data 9 ,
134 .Xr accf_http 9 ,
135 .Xr kmalloc 9
136 .Sh HISTORY
137 The accept filter mechanism was introduced in
138 .Fx 4.0 .
139 .Sh AUTHORS
140 .An -nosplit
141 This manual page was written by
142 .An Alfred Perlstein ,
143 .An Sheldon Hearn
144 and
145 .An Jeroen Ruigrok van der Werven .
146 .Pp
147 The accept filter concept was pioneered by
148 .An David Filo
149 at Yahoo!\&
150 and refined to be a loadable module system by
151 .An Alfred Perlstein .