1*48e64ca1SJose Luis Duran.\" $NetBSD: libblocklist.3,v 1.7 2025/02/05 20:14:30 christos Exp $ 2*48e64ca1SJose Luis Duran.\" 3*48e64ca1SJose Luis Duran.\" Copyright (c) 2015 The NetBSD Foundation, Inc. 4*48e64ca1SJose Luis Duran.\" All rights reserved. 5*48e64ca1SJose Luis Duran.\" 6*48e64ca1SJose Luis Duran.\" This code is derived from software contributed to The NetBSD Foundation 7*48e64ca1SJose Luis Duran.\" by Christos Zoulas. 8*48e64ca1SJose Luis Duran.\" 9*48e64ca1SJose Luis Duran.\" Redistribution and use in source and binary forms, with or without 10*48e64ca1SJose Luis Duran.\" modification, are permitted provided that the following conditions 11*48e64ca1SJose Luis Duran.\" are met: 12*48e64ca1SJose Luis Duran.\" 1. Redistributions of source code must retain the above copyright 13*48e64ca1SJose Luis Duran.\" notice, this list of conditions and the following disclaimer. 14*48e64ca1SJose Luis Duran.\" 2. Redistributions in binary form must reproduce the above copyright 15*48e64ca1SJose Luis Duran.\" notice, this list of conditions and the following disclaimer in the 16*48e64ca1SJose Luis Duran.\" documentation and/or other materials provided with the distribution. 17*48e64ca1SJose Luis Duran.\" 18*48e64ca1SJose Luis Duran.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19*48e64ca1SJose Luis Duran.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20*48e64ca1SJose Luis Duran.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21*48e64ca1SJose Luis Duran.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22*48e64ca1SJose Luis Duran.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23*48e64ca1SJose Luis Duran.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24*48e64ca1SJose Luis Duran.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25*48e64ca1SJose Luis Duran.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26*48e64ca1SJose Luis Duran.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27*48e64ca1SJose Luis Duran.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28*48e64ca1SJose Luis Duran.\" POSSIBILITY OF SUCH DAMAGE. 29*48e64ca1SJose Luis Duran.\" 30*48e64ca1SJose Luis Duran.Dd February 5, 2025 31*48e64ca1SJose Luis Duran.Dt LIBBLOCKLIST 3 32*48e64ca1SJose Luis Duran.Os 33*48e64ca1SJose Luis Duran.Sh NAME 34*48e64ca1SJose Luis Duran.Nm blocklist_open , 35*48e64ca1SJose Luis Duran.Nm blocklist_open2 , 36*48e64ca1SJose Luis Duran.Nm blocklist_close , 37*48e64ca1SJose Luis Duran.Nm blocklist_r , 38*48e64ca1SJose Luis Duran.Nm blocklist , 39*48e64ca1SJose Luis Duran.Nm blocklist_sa , 40*48e64ca1SJose Luis Duran.Nm blocklist_sa_r 41*48e64ca1SJose Luis Duran.Nd Blocklistd notification library 42*48e64ca1SJose Luis Duran.Sh LIBRARY 43*48e64ca1SJose Luis Duran.Lb libblocklist 44*48e64ca1SJose Luis Duran.Sh SYNOPSIS 45*48e64ca1SJose Luis Duran.In blocklist.h 46*48e64ca1SJose Luis Duran.Ft struct blocklist * 47*48e64ca1SJose Luis Duran.Fn blocklist_open "void" 48*48e64ca1SJose Luis Duran.Ft struct blocklist * 49*48e64ca1SJose Luis Duran.Fn blocklist_open2 "void (*logger)(int, struct syslog_data *, va_list)" 50*48e64ca1SJose Luis Duran.Ft void 51*48e64ca1SJose Luis Duran.Fn blocklist_close "struct blocklist *cookie" 52*48e64ca1SJose Luis Duran.Ft int 53*48e64ca1SJose Luis Duran.Fn blocklist "int action" "int fd" "const char *msg" 54*48e64ca1SJose Luis Duran.Ft int 55*48e64ca1SJose Luis Duran.Fn blocklist_r "struct blocklist *cookie" "int action" "int fd" "const char *msg" 56*48e64ca1SJose Luis Duran.Ft int 57*48e64ca1SJose Luis Duran.Fn blocklist_sa "int action" "int fd" "const struct sockaddr *sa" "socklen_t salen" "const char *msg" 58*48e64ca1SJose Luis Duran.Ft int 59*48e64ca1SJose Luis Duran.Fn blocklist_sa_r "struct blocklist *cookie" "int action" "int fd" "const struct sockaddr *sa" "socklen_t salen" "const char *msg" 60*48e64ca1SJose Luis Duran.Sh DESCRIPTION 61*48e64ca1SJose Luis DuranThese functions can be used by daemons to notify 62*48e64ca1SJose Luis Duran.Xr blocklistd 8 63*48e64ca1SJose Luis Duranabout successful and failed remote connections so that blocklistd can 64*48e64ca1SJose Luis Duranblock or release port access to prevent Denial of Service attacks. 65*48e64ca1SJose Luis Duran.Pp 66*48e64ca1SJose Luis DuranThe function 67*48e64ca1SJose Luis Duran.Fn blocklist_open 68*48e64ca1SJose Luis Durancreates the necessary state to communicate with 69*48e64ca1SJose Luis Duran.Xr blocklistd 8 70*48e64ca1SJose Luis Duranand returns a pointer to it, or 71*48e64ca1SJose Luis Duran.Dv NULL 72*48e64ca1SJose Luis Duranon failure. 73*48e64ca1SJose Luis Duran.Pp 74*48e64ca1SJose Luis DuranThe function 75*48e64ca1SJose Luis Duran.Fn blocklist_open2 76*48e64ca1SJose Luis Duranis similar to 77*48e64ca1SJose Luis Duran.Fn blocklist_open 78*48e64ca1SJose Luis Duranbut allows a 79*48e64ca1SJose Luis Duran.Fa logger 80*48e64ca1SJose Luis Duranto be specified. 81*48e64ca1SJose Luis DuranIf the 82*48e64ca1SJose Luis Duran.Fa logger 83*48e64ca1SJose Luis Duranis 84*48e64ca1SJose Luis Duran.Dv NULL , 85*48e64ca1SJose Luis Duranthen no logging is performed. 86*48e64ca1SJose Luis Duran.Pp 87*48e64ca1SJose Luis DuranThe 88*48e64ca1SJose Luis Duran.Fn blocklist_close 89*48e64ca1SJose Luis Duranfunction frees all memory and resources used. 90*48e64ca1SJose Luis Duran.Pp 91*48e64ca1SJose Luis DuranThe 92*48e64ca1SJose Luis Duran.Fn blocklist 93*48e64ca1SJose Luis Duranfunction sends a message to 94*48e64ca1SJose Luis Duran.Xr blocklistd 8 , 95*48e64ca1SJose Luis Duranwith an integer 96*48e64ca1SJose Luis Duran.Ar action 97*48e64ca1SJose Luis Duranargument specifying the type of notification, 98*48e64ca1SJose Luis Durana file descriptor 99*48e64ca1SJose Luis Duran.Ar fd 100*48e64ca1SJose Luis Duranspecifying the accepted file descriptor connected to the client, 101*48e64ca1SJose Luis Duranand an optional message in the 102*48e64ca1SJose Luis Duran.Ar msg 103*48e64ca1SJose Luis Duranargument. 104*48e64ca1SJose Luis Duran.Pp 105*48e64ca1SJose Luis DuranThe 106*48e64ca1SJose Luis Duran.Ar action 107*48e64ca1SJose Luis Duranparameter can take these values: 108*48e64ca1SJose Luis Duran.Bl -tag -width ".Dv BLOCKLIST_ABUSIVE_BEHAVIOR" 109*48e64ca1SJose Luis Duran.It Va BLOCKLIST_BAD_USER 110*48e64ca1SJose Luis DuranThe sending daemon has determined the username presented for 111*48e64ca1SJose Luis Duranauthentication is invalid. 112*48e64ca1SJose Luis DuranThis is considered as one failure count. 113*48e64ca1SJose Luis Duran.It Va BLOCKLIST_AUTH_FAIL 114*48e64ca1SJose Luis DuranThere was an unsuccessful authentication attempt. 115*48e64ca1SJose Luis DuranThis is considered as two failure counts together. 116*48e64ca1SJose Luis Duran.It Va BLOCKLIST_ABUSIVE_BEHAVIOR 117*48e64ca1SJose Luis DuranThe sending daemon has detected abusive behavior from the remote system. 118*48e64ca1SJose Luis DuranThis is considered as a total immediate failure. 119*48e64ca1SJose Luis DuranThe remote address will be blocked as soon as possible. 120*48e64ca1SJose Luis Duran.It Va BLOCKLIST_AUTH_OK 121*48e64ca1SJose Luis DuranA valid user successfully authenticated. 122*48e64ca1SJose Luis DuranAny entry for the remote address will be removed as soon as possible. 123*48e64ca1SJose Luis Duran.El 124*48e64ca1SJose Luis Duran.Pp 125*48e64ca1SJose Luis DuranThe 126*48e64ca1SJose Luis Duran.Fn blocklist_r 127*48e64ca1SJose Luis Duranfunction is more efficient because it keeps the blocklist state around. 128*48e64ca1SJose Luis Duran.Pp 129*48e64ca1SJose Luis DuranThe 130*48e64ca1SJose Luis Duran.Fn blocklist_sa 131*48e64ca1SJose Luis Duranand 132*48e64ca1SJose Luis Duran.Fn blocklist_sa_r 133*48e64ca1SJose Luis Duranfunctions can be used with unconnected sockets, where 134*48e64ca1SJose Luis Duran.Xr getpeername 2 135*48e64ca1SJose Luis Duranwill not work, the server will pass the peer name in the message. 136*48e64ca1SJose Luis Duran.Pp 137*48e64ca1SJose Luis DuranIn all cases the file descriptor passed in the 138*48e64ca1SJose Luis Duran.Fa fd 139*48e64ca1SJose Luis Duranargument must be pointing to a valid socket so that 140*48e64ca1SJose Luis Duran.Xr blocklistd 8 141*48e64ca1SJose Luis Durancan establish ownership of the local endpoint 142*48e64ca1SJose Luis Duranusing 143*48e64ca1SJose Luis Duran.Xr getsockname 2 . 144*48e64ca1SJose Luis Duran.Pp 145*48e64ca1SJose Luis DuranBy default, 146*48e64ca1SJose Luis Duran.Xr syslogd 8 147*48e64ca1SJose Luis Duranis used for message logging. 148*48e64ca1SJose Luis DuranThe internal 149*48e64ca1SJose Luis Duran.Fn bl_create 150*48e64ca1SJose Luis Duranfunction can be used to create the required internal 151*48e64ca1SJose Luis Duranstate and specify a custom logging function. 152*48e64ca1SJose Luis Duran.Sh RETURN VALUES 153*48e64ca1SJose Luis DuranThe function 154*48e64ca1SJose Luis Duran.Fn blocklist_open 155*48e64ca1SJose Luis Duranreturns a cookie on success and 156*48e64ca1SJose Luis Duran.Dv NULL 157*48e64ca1SJose Luis Duranon failure setting 158*48e64ca1SJose Luis Duran.Dv errno 159*48e64ca1SJose Luis Duranto an appropriate value. 160*48e64ca1SJose Luis Duran.Pp 161*48e64ca1SJose Luis DuranThe functions 162*48e64ca1SJose Luis Duran.Fn blocklist , 163*48e64ca1SJose Luis Duran.Fn blocklist_sa , 164*48e64ca1SJose Luis Duranand 165*48e64ca1SJose Luis Duran.Fn blocklist_sa_r 166*48e64ca1SJose Luis Duranreturn 167*48e64ca1SJose Luis Duran.Dv 0 168*48e64ca1SJose Luis Duranon success and 169*48e64ca1SJose Luis Duran.Dv \-1 170*48e64ca1SJose Luis Duranon failure setting 171*48e64ca1SJose Luis Duran.Dv errno 172*48e64ca1SJose Luis Duranto an appropriate value. 173*48e64ca1SJose Luis Duran.Sh SEE ALSO 174*48e64ca1SJose Luis Duran.Xr blocklistd.conf 5 , 175*48e64ca1SJose Luis Duran.Xr blocklistd 8 176*48e64ca1SJose Luis Duran.Sh AUTHORS 177*48e64ca1SJose Luis Duran.An Christos Zoulas 178