2000-07-10 17:23:53 +00:00
|
|
|
.\"
|
|
|
|
.\" Copyright (c) 2000 Alfred Perlstein
|
|
|
|
.\"
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
.\"
|
|
|
|
.\" $FreeBSD$
|
|
|
|
.\" "
|
|
|
|
.Dd June 25, 2000
|
|
|
|
.Dt ACCEPT_FILTER 9
|
2010-04-14 19:08:06 +00:00
|
|
|
.Os
|
2000-07-10 17:23:53 +00:00
|
|
|
.Sh NAME
|
|
|
|
.Nm accept_filter ,
|
|
|
|
.Nm accept_filt_add ,
|
|
|
|
.Nm accept_filt_del ,
|
|
|
|
.Nm accept_filt_generic_mod_event ,
|
|
|
|
.Nm accept_filt_get
|
|
|
|
.Nd filter incoming connections
|
|
|
|
.Sh SYNOPSIS
|
2001-10-01 16:09:29 +00:00
|
|
|
.In sys/types.h
|
|
|
|
.In sys/module.h
|
|
|
|
.In sys/socket.h
|
2001-02-15 11:58:38 +00:00
|
|
|
.Fd #define ACCEPT_FILTER_MOD
|
2001-10-01 16:09:29 +00:00
|
|
|
.In sys/socketvar.h
|
2000-07-10 17:23:53 +00:00
|
|
|
.Ft int
|
|
|
|
.Fn accept_filt_add "struct accept_filter *filt"
|
|
|
|
.Ft int
|
|
|
|
.Fn accept_filt_del "char *name"
|
|
|
|
.Ft int
|
|
|
|
.Fn accept_filt_generic_mod_event "module_t mod" "int event" "void *data"
|
|
|
|
.Ft struct accept_filter *
|
|
|
|
.Fn accept_filt_get "char *name"
|
|
|
|
.Sh DESCRIPTION
|
|
|
|
Accept filters allow an application to request
|
|
|
|
that the kernel pre-process incoming connections.
|
|
|
|
An accept filter is requested via the
|
|
|
|
.Xr setsockopt 2
|
|
|
|
system call, passing in an
|
|
|
|
.Fa optname
|
|
|
|
of
|
|
|
|
.Dv SO_ACCEPTFILTER .
|
|
|
|
.Sh IMPLEMENTATION NOTES
|
|
|
|
A module that wants to be an accept filter
|
2003-10-23 05:01:30 +00:00
|
|
|
must provide a
|
2004-06-16 08:33:57 +00:00
|
|
|
.Vt "struct accept_filter"
|
2003-10-23 05:01:30 +00:00
|
|
|
to the system:
|
2000-07-10 17:23:53 +00:00
|
|
|
.Bd -literal
|
|
|
|
struct accept_filter {
|
|
|
|
char accf_name[16];
|
2002-10-10 00:32:55 +00:00
|
|
|
void (*accf_callback)(struct socket *so, void *arg, int waitflag);
|
|
|
|
void * (*accf_create)(struct socket *so, char *arg);
|
|
|
|
void (*accf_destroy)(struct socket *so);
|
2000-07-10 17:23:53 +00:00
|
|
|
SLIST_ENTRY(accept_filter) accf_next; /* next on the list */
|
|
|
|
};
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
The module should register it with the function
|
|
|
|
.Fn accept_filt_add ,
|
2003-10-23 05:01:30 +00:00
|
|
|
passing a pointer to a
|
2004-06-16 08:33:57 +00:00
|
|
|
.Vt "struct accept_filter" ,
|
2003-10-23 05:01:30 +00:00
|
|
|
allocated with
|
2004-06-16 08:33:57 +00:00
|
|
|
.Xr malloc 9 .
|
2000-07-10 17:23:53 +00:00
|
|
|
.Pp
|
|
|
|
The fields of
|
2004-06-16 08:33:57 +00:00
|
|
|
.Vt "struct accept_filter"
|
2000-07-10 17:23:53 +00:00
|
|
|
are as follows:
|
2004-06-16 08:33:57 +00:00
|
|
|
.Bl -tag -width ".Va accf_callback"
|
|
|
|
.It Va accf_name
|
2000-07-10 17:23:53 +00:00
|
|
|
Name of the filter;
|
|
|
|
this is how it will be accessed from userland.
|
2004-06-16 08:33:57 +00:00
|
|
|
.It Va accf_callback
|
2000-07-10 17:23:53 +00:00
|
|
|
The callback that the kernel will do
|
|
|
|
once the connection is established.
|
|
|
|
It is the same as a socket upcall
|
|
|
|
and will be called when the connection is established
|
|
|
|
and whenever new data arrives on the socket,
|
|
|
|
unless the callback modifies the socket's flags.
|
2004-06-16 08:33:57 +00:00
|
|
|
.It Va accf_create
|
2000-07-10 17:23:53 +00:00
|
|
|
Called whenever a
|
|
|
|
.Xr setsockopt 2
|
|
|
|
installs the filter onto
|
|
|
|
a listening socket.
|
2004-06-16 08:33:57 +00:00
|
|
|
.It Va accf_destroy
|
2000-07-10 17:23:53 +00:00
|
|
|
Called whenever the user removes the accept filter on the socket.
|
|
|
|
.El
|
|
|
|
.Pp
|
2003-10-23 05:01:30 +00:00
|
|
|
The
|
2000-07-10 17:23:53 +00:00
|
|
|
.Fn accept_filt_del
|
2003-10-23 05:01:30 +00:00
|
|
|
function
|
|
|
|
passed the same string used in
|
|
|
|
.Va accept_filter.accf_name
|
|
|
|
during registration with
|
2000-07-10 17:23:53 +00:00
|
|
|
.Fn accept_filt_add ,
|
|
|
|
the kernel will then disallow and further userland use of the filter.
|
|
|
|
.Pp
|
2003-10-23 05:01:30 +00:00
|
|
|
The
|
2000-07-10 17:23:53 +00:00
|
|
|
.Fn accept_filt_get
|
2003-10-23 05:01:30 +00:00
|
|
|
function is used internally to locate which accept filter to use via the
|
2004-06-16 08:33:57 +00:00
|
|
|
.Xr setsockopt 2
|
2003-10-23 05:01:30 +00:00
|
|
|
system call.
|
2000-07-10 17:23:53 +00:00
|
|
|
.Pp
|
2003-10-23 05:01:30 +00:00
|
|
|
The
|
2000-07-10 17:23:53 +00:00
|
|
|
.Fn accept_filt_generic_mod_event
|
2003-10-23 05:01:30 +00:00
|
|
|
function provides a simple way to avoid duplication of code
|
2004-06-16 08:33:57 +00:00
|
|
|
for accept filters which do not use the argument field to load
|
2003-10-23 05:01:30 +00:00
|
|
|
and unload themselves.
|
|
|
|
This function can be used in the
|
|
|
|
.Vt moduledata_t
|
|
|
|
struct for the
|
|
|
|
.Xr DECLARE_MODULE 9
|
2000-07-10 17:23:53 +00:00
|
|
|
macro.
|
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr setsockopt 2 ,
|
2001-07-06 16:46:48 +00:00
|
|
|
.Xr accf_data 9 ,
|
2008-07-18 14:46:01 +00:00
|
|
|
.Xr accf_dns 9 ,
|
2001-07-06 16:46:48 +00:00
|
|
|
.Xr accf_http 9 ,
|
2000-07-10 17:23:53 +00:00
|
|
|
.Xr malloc 9
|
|
|
|
.Sh HISTORY
|
|
|
|
The accept filter mechanism was introduced in
|
|
|
|
.Fx 4.0 .
|
|
|
|
.Sh AUTHORS
|
2000-08-15 15:23:46 +00:00
|
|
|
This manual page was written by
|
2003-10-23 05:01:30 +00:00
|
|
|
.An -nosplit
|
2000-07-10 19:20:08 +00:00
|
|
|
.An Alfred Perlstein ,
|
2003-10-23 05:01:30 +00:00
|
|
|
.An Sheldon Hearn
|
|
|
|
and
|
2020-12-19 09:40:05 +00:00
|
|
|
.An Jeroen Ruigrok van der Werven .
|
2003-10-23 05:01:30 +00:00
|
|
|
.Pp
|
|
|
|
The accept filter concept was pioneered by
|
|
|
|
.An David Filo
|
2004-06-16 08:33:57 +00:00
|
|
|
at Yahoo!\&
|
2003-10-23 05:01:30 +00:00
|
|
|
and refined to be a loadable module system by
|
2004-06-16 08:33:57 +00:00
|
|
|
.An Alfred Perlstein .
|