ACCEPT_FILTER(9)
π ACCEPT_FILTER(9) β the kernel dev manual, but make it cute π
okay so bestie, welcome to ACCEPT_FILTER(9), aka the page where the kernel lets apps pre-chew incoming connections before they even hit userspace. it's giving bouncer-at-the-club energy, fr fr. π«Ά
β¨ NAME β¨
accept_filter, accept_filt_add, accept_filt_del, accept_filt_generic_mod_event, accept_filt_get β filter incoming connections π
πΈ SYNOPSIS πΈ
#include <sys/types.h>
#include <sys/module.h>
#include <sys/socket.h>
#define ACCEPT_FILTER_MOD
#include <sys/socketvar.h>
int
accept_filt_add(struct accept_filter *filt);
int
accept_filt_del(char *name);
int
accept_filt_generic_mod_event(module_t mod, int event, void *data);
struct accept_filter *
accept_filt_get(char *name);
like yes, that's the whole cast of characters, and yes they all showed up dressed correctly π
π¦ DESCRIPTION π¦
So the whole vibe here: accept filters let an application ask the kernel to pre-process incoming connections for it. no cap. the app requests one through the setsockopt(2) system call, and it passes in an optname of SO_ACCEPTFILTER. that's the secret handshake. π€
π IMPLEMENTATION NOTES π
okay so if a module wants to BE an accept filter (main character behavior), it has to hand the system a struct accept_filter:
struct accept_filter {
char accf_name[16];
void (*accf_callback)(struct socket *so, void *arg, int waitflag);
void * (*accf_create)(struct socket *so, char *arg);
void (*accf_destroy)(struct socket *so);
SLIST_ENTRY(accept_filter) accf_next; /* next on the list */
};
then the module registers it with the accept_filt_add() function, passing a pointer to a struct accept_filter that was allocated with malloc(9). (yes, you gotta malloc(9) it. the kernel is not your mom, it will not allocate for you. π)
and here's the field-by-field breakdown, because every single one matters:
accf_nameβ the name of the filter; this is literally how it gets accessed from userland. so pick something cute but, like, legal.accf_callbackβ the callback the kernel does once the connection is established. it's the same thing as a socket upcall, and it gets called when the connection is established and whenever new data arrives on the socket β unless the callback modifies the socket's flags. so, like, don't go changing flags and then act surprised. πaccf_createβ called wheneversetsockopt(2)installs the filter onto a listening socket.accf_destroyβ called whenever the user removes the accept filter on the socket. bye bestie π
Now, the accept_filt_del() function: you pass it the same string that you used in accept_filter.accf_name during registration with accept_filt_add(), and then the kernel disallows any further userland use of the filter. periodt. that filter is done. π
The accept_filt_get() function is used internally to locate which accept filter to use via the setsockopt(2) system call. it's the matchmaker. iykyk.
And the accept_filt_generic_mod_event() function gives you a simple way to avoid duplicating code for accept filters that don't use the argument field to load and unload themselves. you can use this function in the moduledata_t struct for the DECLARE_MODULE(9) macro. efficiency? slay. β¨
π₯ SEE ALSO π₯
setsockopt(2), accf_data(9), accf_dns(9), accf_http(9), malloc(9)
go read those too, bestie, they're all in the friend group π
π HISTORY π
The accept filter mechanism was introduced in FreeBSD 4.0. an icon, a legend, and the moment is still iconic. β
π AUTHORS π
This manual page was written by Alfred Perlstein, Sheldon Hearn and Jeroen Ruigrok van der Werven. absolute queens of documentation. π
The accept filter concept was pioneered by David Filo at Yahoo! and refined to be a loadable module system by Alfred Perlstein. two icons, one legend of a feature. π§
and that's the whole page!! mwah π
this one came to you from the Debian edition of the page, dated June 25, 2000 β so yeah, it's vintage, but it ATE and left no crumbs. π take care of your accept filters and they'll take care of you. byeeee π¦β¨
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2000 Alfred Perlstein
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms