148e64ca1SJose Luis Duran.\" $NetBSD: libblocklist.3,v 1.7 2025/02/05 20:14:30 christos Exp $ 248e64ca1SJose Luis Duran.\" 348e64ca1SJose Luis Duran.\" Copyright (c) 2015 The NetBSD Foundation, Inc. 448e64ca1SJose Luis Duran.\" All rights reserved. 548e64ca1SJose Luis Duran.\" 648e64ca1SJose Luis Duran.\" This code is derived from software contributed to The NetBSD Foundation 748e64ca1SJose Luis Duran.\" by Christos Zoulas. 848e64ca1SJose Luis Duran.\" 948e64ca1SJose Luis Duran.\" Redistribution and use in source and binary forms, with or without 1048e64ca1SJose Luis Duran.\" modification, are permitted provided that the following conditions 1148e64ca1SJose Luis Duran.\" are met: 1248e64ca1SJose Luis Duran.\" 1. Redistributions of source code must retain the above copyright 1348e64ca1SJose Luis Duran.\" notice, this list of conditions and the following disclaimer. 1448e64ca1SJose Luis Duran.\" 2. Redistributions in binary form must reproduce the above copyright 1548e64ca1SJose Luis Duran.\" notice, this list of conditions and the following disclaimer in the 1648e64ca1SJose Luis Duran.\" documentation and/or other materials provided with the distribution. 1748e64ca1SJose Luis Duran.\" 1848e64ca1SJose Luis Duran.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 1948e64ca1SJose Luis Duran.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2048e64ca1SJose Luis Duran.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2148e64ca1SJose Luis Duran.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 2248e64ca1SJose Luis Duran.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2348e64ca1SJose Luis Duran.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2448e64ca1SJose Luis Duran.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2548e64ca1SJose Luis Duran.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2648e64ca1SJose Luis Duran.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2748e64ca1SJose Luis Duran.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2848e64ca1SJose Luis Duran.\" POSSIBILITY OF SUCH DAMAGE. 2948e64ca1SJose Luis Duran.\" 3048e64ca1SJose Luis Duran.Dd February 5, 2025 3148e64ca1SJose Luis Duran.Dt LIBBLOCKLIST 3 3248e64ca1SJose Luis Duran.Os 3348e64ca1SJose Luis Duran.Sh NAME 3448e64ca1SJose Luis Duran.Nm blocklist_open , 3548e64ca1SJose Luis Duran.Nm blocklist_open2 , 3648e64ca1SJose Luis Duran.Nm blocklist_close , 3748e64ca1SJose Luis Duran.Nm blocklist_r , 3848e64ca1SJose Luis Duran.Nm blocklist , 3948e64ca1SJose Luis Duran.Nm blocklist_sa , 4048e64ca1SJose Luis Duran.Nm blocklist_sa_r 4148e64ca1SJose Luis Duran.Nd Blocklistd notification library 4248e64ca1SJose Luis Duran.Sh LIBRARY 4348e64ca1SJose Luis Duran.Lb libblocklist 4448e64ca1SJose Luis Duran.Sh SYNOPSIS 4548e64ca1SJose Luis Duran.In blocklist.h 4648e64ca1SJose Luis Duran.Ft struct blocklist * 4748e64ca1SJose Luis Duran.Fn blocklist_open "void" 4848e64ca1SJose Luis Duran.Ft struct blocklist * 4948e64ca1SJose Luis Duran.Fn blocklist_open2 "void (*logger)(int, struct syslog_data *, va_list)" 5048e64ca1SJose Luis Duran.Ft void 5148e64ca1SJose Luis Duran.Fn blocklist_close "struct blocklist *cookie" 5248e64ca1SJose Luis Duran.Ft int 5348e64ca1SJose Luis Duran.Fn blocklist "int action" "int fd" "const char *msg" 5448e64ca1SJose Luis Duran.Ft int 5548e64ca1SJose Luis Duran.Fn blocklist_r "struct blocklist *cookie" "int action" "int fd" "const char *msg" 5648e64ca1SJose Luis Duran.Ft int 5748e64ca1SJose Luis Duran.Fn blocklist_sa "int action" "int fd" "const struct sockaddr *sa" "socklen_t salen" "const char *msg" 5848e64ca1SJose Luis Duran.Ft int 5948e64ca1SJose Luis Duran.Fn blocklist_sa_r "struct blocklist *cookie" "int action" "int fd" "const struct sockaddr *sa" "socklen_t salen" "const char *msg" 6048e64ca1SJose Luis Duran.Sh DESCRIPTION 6148e64ca1SJose Luis DuranThese functions can be used by daemons to notify 6248e64ca1SJose Luis Duran.Xr blocklistd 8 6348e64ca1SJose Luis Duranabout successful and failed remote connections so that blocklistd can 6448e64ca1SJose Luis Duranblock or release port access to prevent Denial of Service attacks. 6548e64ca1SJose Luis Duran.Pp 6648e64ca1SJose Luis DuranThe function 6748e64ca1SJose Luis Duran.Fn blocklist_open 6848e64ca1SJose Luis Durancreates the necessary state to communicate with 6948e64ca1SJose Luis Duran.Xr blocklistd 8 7048e64ca1SJose Luis Duranand returns a pointer to it, or 7148e64ca1SJose Luis Duran.Dv NULL 7248e64ca1SJose Luis Duranon failure. 7348e64ca1SJose Luis Duran.Pp 7448e64ca1SJose Luis DuranThe function 7548e64ca1SJose Luis Duran.Fn blocklist_open2 7648e64ca1SJose Luis Duranis similar to 7748e64ca1SJose Luis Duran.Fn blocklist_open 7848e64ca1SJose Luis Duranbut allows a 7948e64ca1SJose Luis Duran.Fa logger 8048e64ca1SJose Luis Duranto be specified. 8148e64ca1SJose Luis DuranIf the 8248e64ca1SJose Luis Duran.Fa logger 8348e64ca1SJose Luis Duranis 8448e64ca1SJose Luis Duran.Dv NULL , 8548e64ca1SJose Luis Duranthen no logging is performed. 8648e64ca1SJose Luis Duran.Pp 8748e64ca1SJose Luis DuranThe 8848e64ca1SJose Luis Duran.Fn blocklist_close 8948e64ca1SJose Luis Duranfunction frees all memory and resources used. 9048e64ca1SJose Luis Duran.Pp 9148e64ca1SJose Luis DuranThe 9248e64ca1SJose Luis Duran.Fn blocklist 9348e64ca1SJose Luis Duranfunction sends a message to 9448e64ca1SJose Luis Duran.Xr blocklistd 8 , 9548e64ca1SJose Luis Duranwith an integer 9648e64ca1SJose Luis Duran.Ar action 9748e64ca1SJose Luis Duranargument specifying the type of notification, 9848e64ca1SJose Luis Durana file descriptor 9948e64ca1SJose Luis Duran.Ar fd 10048e64ca1SJose Luis Duranspecifying the accepted file descriptor connected to the client, 10148e64ca1SJose Luis Duranand an optional message in the 10248e64ca1SJose Luis Duran.Ar msg 10348e64ca1SJose Luis Duranargument. 10448e64ca1SJose Luis Duran.Pp 10548e64ca1SJose Luis DuranThe 10648e64ca1SJose Luis Duran.Ar action 10748e64ca1SJose Luis Duranparameter can take these values: 10848e64ca1SJose Luis Duran.Bl -tag -width ".Dv BLOCKLIST_ABUSIVE_BEHAVIOR" 109*4d56eb00SJose Luis Duran.It Dv BLOCKLIST_AUTH_FAIL 11048e64ca1SJose Luis DuranThere was an unsuccessful authentication attempt. 111*4d56eb00SJose Luis Duran.It Dv BLOCKLIST_AUTH_OK 112*4d56eb00SJose Luis DuranA user successfully authenticated. 113*4d56eb00SJose Luis Duran.It Dv BLOCKLIST_ABUSIVE_BEHAVIOR 114*4d56eb00SJose Luis DuranThe sending daemon has detected abusive behavior 115*4d56eb00SJose Luis Duranfrom the remote system. 116*4d56eb00SJose Luis DuranThe remote address should 117*4d56eb00SJose Luis Duranbe blocked as soon as possible. 118*4d56eb00SJose Luis Duran.It Dv BLOCKLIST_BAD_USER 119*4d56eb00SJose Luis DuranThe sending daemon has determined the username 120*4d56eb00SJose Luis Duranpresented for authentication is invalid. 121*4d56eb00SJose Luis DuranThe 122*4d56eb00SJose Luis Duran.Xr blocklistd 8 123*4d56eb00SJose Luis Durandaemon compares the username to a configured list of forbidden 124*4d56eb00SJose Luis Duranusernames and 125*4d56eb00SJose Luis Duranblocks the address immediately if a forbidden username matches. 126*4d56eb00SJose Luis Duran(The 127*4d56eb00SJose Luis Duran.Dv BLOCKLIST_BAD_USER 128*4d56eb00SJose Luis Duransupport is not currently available.) 12948e64ca1SJose Luis Duran.El 13048e64ca1SJose Luis Duran.Pp 13148e64ca1SJose Luis DuranThe 13248e64ca1SJose Luis Duran.Fn blocklist_r 13348e64ca1SJose Luis Duranfunction is more efficient because it keeps the blocklist state around. 13448e64ca1SJose Luis Duran.Pp 13548e64ca1SJose Luis DuranThe 13648e64ca1SJose Luis Duran.Fn blocklist_sa 13748e64ca1SJose Luis Duranand 13848e64ca1SJose Luis Duran.Fn blocklist_sa_r 13948e64ca1SJose Luis Duranfunctions can be used with unconnected sockets, where 14048e64ca1SJose Luis Duran.Xr getpeername 2 14148e64ca1SJose Luis Duranwill not work, the server will pass the peer name in the message. 14248e64ca1SJose Luis Duran.Pp 14348e64ca1SJose Luis DuranIn all cases the file descriptor passed in the 14448e64ca1SJose Luis Duran.Fa fd 14548e64ca1SJose Luis Duranargument must be pointing to a valid socket so that 14648e64ca1SJose Luis Duran.Xr blocklistd 8 14748e64ca1SJose Luis Durancan establish ownership of the local endpoint 14848e64ca1SJose Luis Duranusing 14948e64ca1SJose Luis Duran.Xr getsockname 2 . 15048e64ca1SJose Luis Duran.Pp 15148e64ca1SJose Luis DuranBy default, 15248e64ca1SJose Luis Duran.Xr syslogd 8 15348e64ca1SJose Luis Duranis used for message logging. 15448e64ca1SJose Luis DuranThe internal 15548e64ca1SJose Luis Duran.Fn bl_create 15648e64ca1SJose Luis Duranfunction can be used to create the required internal 15748e64ca1SJose Luis Duranstate and specify a custom logging function. 15848e64ca1SJose Luis Duran.Sh RETURN VALUES 15948e64ca1SJose Luis DuranThe function 16048e64ca1SJose Luis Duran.Fn blocklist_open 16148e64ca1SJose Luis Duranreturns a cookie on success and 16248e64ca1SJose Luis Duran.Dv NULL 16348e64ca1SJose Luis Duranon failure setting 16448e64ca1SJose Luis Duran.Dv errno 16548e64ca1SJose Luis Duranto an appropriate value. 16648e64ca1SJose Luis Duran.Pp 16748e64ca1SJose Luis DuranThe functions 16848e64ca1SJose Luis Duran.Fn blocklist , 16948e64ca1SJose Luis Duran.Fn blocklist_sa , 17048e64ca1SJose Luis Duranand 17148e64ca1SJose Luis Duran.Fn blocklist_sa_r 17248e64ca1SJose Luis Duranreturn 17348e64ca1SJose Luis Duran.Dv 0 17448e64ca1SJose Luis Duranon success and 17548e64ca1SJose Luis Duran.Dv \-1 17648e64ca1SJose Luis Duranon failure setting 17748e64ca1SJose Luis Duran.Dv errno 17848e64ca1SJose Luis Duranto an appropriate value. 17948e64ca1SJose Luis Duran.Sh SEE ALSO 18048e64ca1SJose Luis Duran.Xr blocklistd.conf 5 , 18148e64ca1SJose Luis Duran.Xr blocklistd 8 18248e64ca1SJose Luis Duran.Sh AUTHORS 18348e64ca1SJose Luis Duran.An Christos Zoulas 184