Skip site navigation (1)Skip section navigation (2)


| raw e-mail | index | archive | help
URL: https://cgit.FreeBSD.org/src/commit/?id=e2dcc9fc4d2e6722190cf15bc5bf5dc2e9132ab5

commit e2dcc9fc4d2e6722190cf15bc5bf5dc2e9132ab5
Author:     Jose Luis Duran <jlduran@FreeBSD.org>
AuthorDate: 2025-10-12 17:01:03 +0000
Commit:     Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2025-10-14 04:36:12 +0000

    MFV: Import blocklist 2025-04-28 (8aa81bf)
    
    Merge commit '70f30afd4e9af5a51ee324d97e4d8c5f2124ec15'
    
    Breaking changes:
    
    - Upstream commit 24932b6 ("blocklistd: log the conf file line number
      with bad protocol errors") breaks backward database compatibility.
      An error will be displayed:
          Key size mismatch 296 != 288
      A new and compatible database, with the new name, will be created when the
      service starts (committed separately).
    
    - Upstream commit ddf6d71 ("implement BLOCKLIST_BAD_USER as a
      "one-count" failure") introduced BLOCKLIST_BAD_USER with a one-count
      failure mechanism.  BLOCKLIST_AUTH_FAIL was implemented with a
      two-count failure mechanism.  Since we utilize BLOCKLIST_AUTH_FAIL, the
      number of failed attempts now doubles towards the maximum limit
      (nfails).  This commit will be reverted separately.
    
    Changes:
    
    https://github.com/zoulasc/blocklist/compare/7093cd9...8aa81bf
    
    Approved by:    re (cperciva)
    Approved by:    emaste (mentor)
    MFC after:      2 days
    Differential Revision:  https://reviews.freebsd.org/D52869
    
    (cherry picked from commit 48e64ca13d4f36795ac718911b805e3e9a726f1b)
    (cherry picked from commit 1a08326c6f503db5f0fb9201cdf55379bbe576e8)
---
 contrib/blocklist/Makefile                         |   2 +-
 contrib/blocklist/Makefile.inc                     |   7 +-
 contrib/blocklist/README                           |  52 ++--
 contrib/blocklist/TODO                             |  49 +++-
 contrib/blocklist/bin/Makefile                     |  12 +-
 .../bin/{blacklistctl.8 => blocklistctl.8}         |  69 +++++-
 .../bin/{blacklistctl.c => blocklistctl.c}         |   9 +-
 .../blocklist/bin/{blacklistd.8 => blocklistd.8}   |  75 +++---
 .../blocklist/bin/{blacklistd.c => blocklistd.c}   |  48 ++--
 .../bin/{blacklistd.conf.5 => blocklistd.conf.5}   |  82 ++++---
 contrib/blocklist/bin/conf.c                       | 200 ++++++++++++---
 contrib/blocklist/bin/conf.h                       |   3 +-
 contrib/blocklist/bin/internal.c                   |   8 +-
 contrib/blocklist/bin/internal.h                   |   8 +-
 contrib/blocklist/bin/run.c                        |   9 +-
 contrib/blocklist/bin/run.h                        |   2 +-
 contrib/blocklist/bin/state.c                      |   6 +-
 contrib/blocklist/bin/state.h                      |   2 +-
 contrib/blocklist/bin/support.c                    |  11 +-
 contrib/blocklist/bin/support.h                    |   7 +-
 contrib/blocklist/diff/ftpd.diff                   |  12 +-
 contrib/blocklist/diff/named.diff                  |  12 +-
 contrib/blocklist/diff/postfix.diff                |  98 ++++++++
 contrib/blocklist/diff/proftpd.diff                |  20 +-
 contrib/blocklist/diff/ssh.diff                    |  14 +-
 contrib/blocklist/etc/Makefile                     |  10 +-
 .../etc/{blacklistd.conf => blocklistd.conf}       |   7 +-
 contrib/blocklist/etc/ipf.conf                     |  45 ++++
 contrib/blocklist/etc/npf.conf                     |   4 +-
 contrib/blocklist/etc/rc.d/Makefile                |   4 +-
 .../blocklist/etc/rc.d/{blacklistd => blocklistd}  |  20 +-
 contrib/blocklist/include/Makefile                 |   4 +-
 contrib/blocklist/include/bl.h                     |  11 +-
 .../blocklist/include/{blacklist.h => blocklist.h} |  44 ++--
 contrib/blocklist/lib/Makefile                     |  20 +-
 contrib/blocklist/lib/bl.c                         | 112 +++++----
 contrib/blocklist/lib/{blacklist.c => blocklist.c} |  49 ++--
 .../lib/{libblacklist.3 => libblocklist.3}         | 124 +++++-----
 contrib/blocklist/lib/shlib_version                |   2 +-
 contrib/blocklist/libexec/Makefile                 |   4 +-
 contrib/blocklist/libexec/blacklistd-helper        | 134 ----------
 contrib/blocklist/libexec/blocklistd-helper        | 272 +++++++++++++++++++++
 contrib/blocklist/port/Makefile.am                 |  42 ++--
 contrib/blocklist/port/_strtoi.h                   |   2 +-
 contrib/blocklist/port/configure.ac                |  12 +-
 contrib/blocklist/port/fgetln.c                    |   2 +-
 contrib/blocklist/port/fparseln.c                  |   6 +-
 contrib/blocklist/port/pidfile.c                   |   6 +-
 contrib/blocklist/port/popenve.c                   |   6 +-
 contrib/blocklist/port/port.h                      |  32 ++-
 contrib/blocklist/port/sockaddr_snprintf.c         |   6 +-
 contrib/blocklist/port/strlcat.c                   |   7 +-
 contrib/blocklist/port/strlcpy.c                   |   7 +-
 contrib/blocklist/port/strtoi.c                    |   6 +-
 contrib/blocklist/port/vsyslog_r.c                 |  13 +
 contrib/blocklist/test/Makefile                    |   2 +-
 contrib/blocklist/test/cltest.c                    |   6 +-
 contrib/blocklist/test/srvtest.c                   |  42 +++-
 58 files changed, 1293 insertions(+), 587 deletions(-)

diff --git a/contrib/blocklist/Makefile b/contrib/blocklist/Makefile
index da4411d0ca75..899746d01431 100644
--- a/contrib/blocklist/Makefile
+++ b/contrib/blocklist/Makefile
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.2 2015/01/22 17:49:41 christos Exp $
+# $NetBSD: Makefile,v 1.1.1.1 2020/06/15 01:52:52 christos Exp $
 
 SUBDIR = lib .WAIT include bin etc libexec
 
diff --git a/contrib/blocklist/Makefile.inc b/contrib/blocklist/Makefile.inc
index 85c82783cd35..b22d4a801240 100644
--- a/contrib/blocklist/Makefile.inc
+++ b/contrib/blocklist/Makefile.inc
@@ -1,10 +1,11 @@
-#	$NetBSD: Makefile.inc,v 1.3 2015/01/23 03:57:22 christos Exp $
+#	$NetBSD: Makefile.inc,v 1.3 2025/02/11 17:48:30 christos Exp $
 
 WARNS=6
 .if !defined(LIB)
-LDADD+=	-lblacklist
-DPADD+= ${LIBBLACKLIST}
+LDADD+=	-lblocklist
+DPADD+= ${LIBBLOCKLIST}
 .endif
 CPPFLAGS+= -I${.CURDIR}/../include
 CPPFLAGS+=-DHAVE_STRUCT_SOCKADDR_SA_LEN -DHAVE_UTIL_H -DHAVE_DB_H
+CPPFLAGS+=-DHAVE_SYS_CDEFS_H
 
diff --git a/contrib/blocklist/README b/contrib/blocklist/README
index 7da3317a77fe..4b34138e01ec 100644
--- a/contrib/blocklist/README
+++ b/contrib/blocklist/README
@@ -1,21 +1,21 @@
-# $NetBSD: README,v 1.8 2017/04/13 17:59:34 christos Exp $
+# $NetBSD: README,v 1.3 2024/02/09 00:53:30 wiz Exp $
 
 This package contains library that can be used by network daemons to
 communicate with a packet filter via a daemon to enforce opening and
 closing ports dynamically based on policy.
 
-The interface to the packet filter is in libexec/blacklistd-helper
+The interface to the packet filter is in libexec/blocklistd-helper
 (this is currently designed for npf) and the configuration file
-(inspired from inetd.conf) is in etc/blacklistd.conf.
+(inspired from inetd.conf) is in etc/blocklistd.conf.
 
-On NetBSD you can find an example npf.conf and blacklistd.conf in
-/usr/share/examples/blacklistd; you need to adjust the interface
+On NetBSD you can find an example npf.conf and blocklistd.conf in
+/usr/share/examples/blocklistd; you need to adjust the interface
 in npf.conf and copy both files to /etc; then you just enable
-blacklistd=YES in /etc/rc.conf, start it up, and you are all set.
+blocklistd=YES in /etc/rc.conf, start it up, and you are all set.
 
-There is also a startup file in etc/rc.d/blacklistd
+There is also a startup file in etc/rc.d/blocklistd
 
-Patches to various daemons to add blacklisting capabilitiers are in the
+Patches to various daemons to add blocklisting capabilities are in the
 "diff" directory:
     - OpenSSH: diff/ssh.diff [tcp socket example]
     - Bind: diff/named.diff [both tcp and udp]
@@ -23,21 +23,21 @@ Patches to various daemons to add blacklisting capabilitiers are in the
 
 These patches have been applied to NetBSD-current.
 
-The network daemon (for example sshd) communicates to blacklistd, via
-a unix socket like syslog. The library calls are simple and everything
+The network daemon (for example sshd) communicates to blocklistd, via
+a Unix socket like syslog. The library calls are simple and everything
 is handled by the library. In the simplest form the only thing the
 daemon needs to do is to call:
 
-	blacklist(action, acceptedfd, message);
+	blocklist(action, acceptedfd, message);
 
 Where:
-	action = 0 -> successful login clear blacklist state
+	action = 0 -> successful login clear blocklist state
 		 1 -> failed login, add to the failed count
 	acceptedfd -> the file descriptor where the server is
 		      connected to the remote client. It is used
 		      to determine the listening socket, and the
 		      remote address. This allows any program to
-		      contact the blacklist daemon, since the verification
+		      contact the blocklist daemon, since the verification
 		      if the program has access to the listening
 		      socket is done by virtue that the port
 		      number is retrieved from the kernel.
@@ -46,13 +46,13 @@ Where:
 Unfortunately there is no way to get information about the "peer"
 from a udp socket, because there is no connection and that information
 is kept with the server. In that case the daemon can provide the
-peer information to blacklistd via:
+peer information to blocklistd via:
 
-	blacklist_sa(action, acceptedfd, sockaddr, sockaddr_len, message);
+	blocklist_sa(action, acceptedfd, sockaddr, sockaddr_len, message);
 
 The configuration file contains entries of the form:
 
-# Blacklist rule
+# Blocklist rule
 # host/Port	type	protocol	owner	name	nfail	disable
 192.168.1.1:ssh	stream	tcp		*	-int	10	1m
 8.8.8.8:ssh	stream	tcp		*	-ext	6	60m
@@ -60,18 +60,18 @@ ssh		stream	tcp6		*	*	6	60m
 http		stream	tcp		*	*	6	60m
 
 Here note that owner is * because the connection is done from the
-child ssh socket which runs with user privs. We treat ipv4 connections
+child ssh socket which runs with user privs. We treat IPv4 connections
 differently by maintaining two different rules one for the external
 interface and one from the internal We also register for both tcp
 and tcp6 since those are different listening sockets and addresses;
-we don't bother with ipv6 and separate rules. We use nfail = 6,
+we don't bother with IPv6 and separate rules. We use nfail = 6,
 because ssh allows 3 password attempts per connection, and this
 will let us have 2 connections before blocking. Finally we block
 for an hour; we could block forever too by specifying * in the
 duration column.
 
-blacklistd and the library use syslog(3) to report errors. The
-blacklist filter state is persisted automatically in /var/db/blacklistd.db
+blocklistd and the library use syslog(3) to report errors. The
+blocklist filter state is persisted automatically in /var/db/blocklistd.db
 so that if the daemon is restarted, it remembers what connections
 is currently handling. To start from a fresh state (if you restart
 npf too for example), you can use -f. To watch the daemon at work,
@@ -80,27 +80,27 @@ you can use -d.
 The current control file is designed for npf, and it uses the
 dynamic rule feature. You need to create a dynamic rule in your
 /etc/npf.conf on the group referring to the interface you want to block
-called blacklistd as follows:
+called blocklistd as follows:
 
 ext_if=bge0
 int_if=sk0
 	
 group "external" on $ext_if {
 	...
-        ruleset "blacklistd-ext" 
-        ruleset "blacklistd" 
+        ruleset "blocklistd-ext" 
+        ruleset "blocklistd" 
 	...
 }
 
 group "internal" on $int_if {
 	...
-        ruleset "blacklistd-int" 
+        ruleset "blocklistd-int" 
 	...
 }
 
-You can use 'blacklistctl dump -a' to list all the current entries
+You can use 'blocklistctl dump -a' to list all the current entries
 in the database; the ones that have nfail <c>/<t> where <c>urrent
->= <t>otal, should have an id assosiated with them; this means that
+>= <t>otal, should have an id associated with them; this means that
 there is a packet filter rule added for that entry. For npf, you
 can examine the packet filter dynamic rule entries using 'npfctl
 rule <rulename> list'.  The number of current entries can exceed
diff --git a/contrib/blocklist/TODO b/contrib/blocklist/TODO
index 9925020d54bb..d67111bd5139 100644
--- a/contrib/blocklist/TODO
+++ b/contrib/blocklist/TODO
@@ -1,4 +1,4 @@
-# $NetBSD: TODO,v 1.7 2015/01/23 21:34:01 christos Exp $
+# $NetBSD: TODO,v 1.3 2025/02/05 20:22:26 christos Exp $
 
 - don't poll periodically, find the next timeout
 - use the socket also for commands? Or separate socket?
@@ -17,5 +17,48 @@
 	-n
 	block
 	unblock
-- do we need an api in blacklistctl to perform maintenance
-- fix the blacklistctl output to be more user friendly
+- do we need an api in blocklistctl to perform maintenance
+- fix the blocklistctl output to be more user friendly
+
+- figure out some way to do distributed operation securely (perhaps with
+  a helper daemon that authenticates local sockets and then communicates
+  local DB changes to the central server over a secure channel --
+  perhaps blocklistd-helper can have a back-end that can send updates to
+  a central server)
+
+- add "blocklistd -l" to enable filter logging on all rules by default
+
+- add some new options in the config file
+
+	"/all"	- block both TCP and UDP (on the proto field?)
+
+	"/log"	- enable filter logging (if not the default) (on the name field?)
+	"/nolog"- disable filter logging (if not the default) (on the name field?)
+
+  The latter two probably require a new parameter for blocklistd-helper.
+
+- "blocklistd -f" should (also?) be a blocklistctl function!?!?!
+
+- if blocklistd was started with '-r' then a SIGHUP should also do a
+  "control flush $rulename" and then re-add all the filter rules?
+
+- should/could /etc/rc.conf.d/ipfilter be created with the following?
+
+	reload_postcmd=blocklistd_reload
+	start_postcmd=blocklistd_start
+	stop_precmd=blocklistd_stop
+	blocklistd_reload ()
+	{
+		/etc/rc.d/blocklistd reload	# IFF SIGHUP does flush/re-add
+		# /etc/rc.d/blocklistd restart
+	}
+	blocklistd_stop ()
+	{
+		/etc/rc.d/blocklistd stop
+	}
+	blocklistd_start ()
+	{
+		/etc/rc.d/blocklistd start
+	}
+
+  or is there a better way?
diff --git a/contrib/blocklist/bin/Makefile b/contrib/blocklist/bin/Makefile
index 280c72fd3af1..1856e2524f3c 100644
--- a/contrib/blocklist/bin/Makefile
+++ b/contrib/blocklist/bin/Makefile
@@ -1,12 +1,12 @@
-# $NetBSD: Makefile,v 1.11 2015/01/27 19:40:36 christos Exp $
+# $NetBSD: Makefile,v 1.1.1.1 2020/06/15 01:52:52 christos Exp $
 
 BINDIR=/sbin
 
-PROGS=blacklistd blacklistctl
-MAN.blacklistd=blacklistd.8 blacklistd.conf.5
-MAN.blacklistctl=blacklistctl.8
-SRCS.blacklistd = blacklistd.c conf.c run.c state.c support.c internal.c
-SRCS.blacklistctl = blacklistctl.c conf.c state.c support.c internal.c
+PROGS=blocklistd blocklistctl
+MAN.blocklistd=blocklistd.8 blocklistd.conf.5
+MAN.blocklistctl=blocklistctl.8
+SRCS.blocklistd = blocklistd.c conf.c run.c state.c support.c internal.c
+SRCS.blocklistctl = blocklistctl.c conf.c state.c support.c internal.c
 DBG=-g
 
 LDADD+=-lutil
diff --git a/contrib/blocklist/bin/blacklistctl.8 b/contrib/blocklist/bin/blocklistctl.8
similarity index 59%
rename from contrib/blocklist/bin/blacklistctl.8
rename to contrib/blocklist/bin/blocklistctl.8
index 7c6521117745..a98c16374f19 100644
--- a/contrib/blocklist/bin/blacklistctl.8
+++ b/contrib/blocklist/bin/blocklistctl.8
@@ -1,4 +1,4 @@
-.\" $NetBSD: blacklistctl.8,v 1.9 2016/06/08 12:48:37 wiz Exp $
+.\" $NetBSD: blocklistctl.8,v 1.4 2025/02/07 01:35:38 kre Exp $
 .\"
 .\" Copyright (c) 2015 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,27 +27,43 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd June 7, 2016
-.Dt BLACKLISTCTL 8
+.Dd January 27, 2025
+.Dt BLOCKLISTCTL 8
 .Os
 .Sh NAME
-.Nm blacklistctl
-.Nd display and change the state of blacklistd
+.Nm blocklistctl
+.Nd display and change the state of the blocklistd database
 .Sh SYNOPSIS
 .Nm
 .Cm dump
 .Op Fl abdnrw
+.Op Fl D Ar dbname
 .Sh DESCRIPTION
 .Nm
-is a program used to display the state of
-.Xr blacklistd 8
+is a program used to display and change the state of the
+.Xr blocklistd 8
+database.
+The following sub-commands are supported:
+.Ss dump
 .Pp
-The following options are available:
+The following options are available for the
+.Cm dump
+sub-command:
 .Bl -tag -width indent
 .It Fl a
-Show all database entries, by default it shows only the embryonic ones.
+Show all database entries, by default it shows only the active ones.
+Inactive entries will be shown with a last-access (or, with
+.Fl r ,
+the remaining) time of
+.Ql never .
 .It Fl b
 Show only the blocked entries.
+.It Fl D Ar dbname
+Specify the location of the
+.Ic blocklistd
+database file to use.
+The default is
+.Pa /var/db/blocklistd.db .
 .It Fl d
 Increase debugging level.
 .It Fl n
@@ -59,18 +75,47 @@ Normally the width of addresses is good for IPv4, the
 .Fl w
 flag, makes the display wide enough for IPv6 addresses.
 .El
+.Pp
+The output of the
+.Cm dump
+sub-command consists of a header (unless
+.Fl n
+was given) and one line for each record in the database, where each line
+has the following columns:
+.Bl -tag -width indent
+.It Ql address/ma:port
+The remote address, mask, and local port number of the client connection
+associated with the database entry.
+.It Ql id
+column will show the identifier for the packet filter rule associated
+with the database entry, though this may only be the word
+.Ql OK
+for packet filters which do not creat a unique identifier for each rule.
+.It Ql nfail
+The number of
+.Em failures
+reported for the client on the noted port, as well as the number of
+failures allowed before blocking (or, with
+.Fl a ,
+an asterisk
+.Aq * )
+.It So last access Sc | So remaining time Sc
+The last time a the client was reported as attempting access, or, with
+.Fl r ,
+the time remaining before the rule blocking the client will be removed.
+.El
 .Sh SEE ALSO
-.Xr blacklistd 8
+.Xr blocklistd 8
 .Sh NOTES
 Sometimes the reported number of failed attempts can exceed the number
 of attempts that
-.Xr blacklistd 8
+.Xr blocklistd 8
 is configured to block.
 This can happen either because the rule has been removed manually, or
 because there were more attempts in flight while the rule block was being
 added.
 This condition is normal; in that case
-.Xr blacklistd 8
+.Xr blocklistd 8
 will first attempt to remove the existing rule, and then it will re-add
 it to make sure that there is only one rule active.
 .Sh HISTORY
diff --git a/contrib/blocklist/bin/blacklistctl.c b/contrib/blocklist/bin/blocklistctl.c
similarity index 94%
rename from contrib/blocklist/bin/blacklistctl.c
rename to contrib/blocklist/bin/blocklistctl.c
index 89b72921caf5..8c75e0430c61 100644
--- a/contrib/blocklist/bin/blacklistctl.c
+++ b/contrib/blocklist/bin/blocklistctl.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: blacklistctl.c,v 1.23 2018/05/24 19:21:01 christos Exp $	*/
+/*	$NetBSD: blocklistctl.c,v 1.4 2025/02/11 17:48:30 christos Exp $	*/
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -32,8 +32,10 @@
 #include "config.h"
 #endif
 
+#ifdef HAVE_SYS_CDEFS_H
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: blacklistctl.c,v 1.23 2018/05/24 19:21:01 christos Exp $");
+#endif
+__RCSID("$NetBSD: blocklistctl.c,v 1.4 2025/02/11 17:48:30 christos Exp $");
 
 #include <stdio.h>
 #include <time.h>
@@ -63,7 +65,8 @@ usage(int c)
 		warnx("Missing/unknown command");
 	else if (c != '?')
 		warnx("Unknown option `%c'", (char)c);
-	fprintf(stderr, "Usage: %s dump [-abdnrw]\n", getprogname());
+	fprintf(stderr,
+	    "Usage: %s dump [-abdnrw] [-D dbname]\n", getprogname());
 	exit(EXIT_FAILURE);
 }
 
diff --git a/contrib/blocklist/bin/blacklistd.8 b/contrib/blocklist/bin/blocklistd.8
similarity index 85%
rename from contrib/blocklist/bin/blacklistd.8
rename to contrib/blocklist/bin/blocklistd.8
index 82e1f15f61c9..e0b9fb482cbd 100644
--- a/contrib/blocklist/bin/blacklistd.8
+++ b/contrib/blocklist/bin/blocklistd.8
@@ -1,4 +1,4 @@
-.\" $NetBSD: blacklistd.8,v 1.23 2020/04/21 13:57:12 christos Exp $
+.\" $NetBSD: blocklistd.8,v 1.8 2025/02/25 22:13:34 christos Exp $
 .\"
 .\" Copyright (c) 2015 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,11 +27,11 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd April 21, 2020
-.Dt BLACKLISTD 8
+.Dd February 25, 2025
+.Dt BLOCKLISTD 8
 .Os
 .Sh NAME
-.Nm blacklistd
+.Nm blocklistd
 .Nd block and release ports on demand to avoid DoS abuse
 .Sh SYNOPSIS
 .Nm
@@ -53,22 +53,35 @@ for notifications from other daemons about successful or failed connection
 attempts.
 If no such file is specified, then it only listens to the socket path
 specified by
-.Ar sockspath
+.Ar sockpath
 or if that is not specified to
-.Pa /var/run/blacklistd.sock .
+.Pa /var/run/blocklistd.sock .
 Each notification contains an (action, port, protocol, address, owner) tuple
 that identifies the remote connection and the action.
-This tuple is consulted against entries in
-.Ar configfile
-with syntax specified in
-.Xr blacklistd.conf 5 .
+This tuple is consulted against entries from the
+.Ar configfile ,
+with the syntax specified in
+.Xr blocklistd.conf 5 .
 If an entry is matched, a state entry is created for that tuple.
 Each entry contains a number of tries limit and a duration.
 .Pp
+If
+.Ar configfile
+is a directory, or a directory exists with the same name as
+.Ar configfile
+with
+.Qq .d
+appended to it, each file in the directory will be read as configuration file.
+If
+.Ar configfile
+exists as a file it will be processed before the contents of the
+.Ar configfile Ns .d
+directory if that also exists.
+.Pp
 The way
 .Nm
 does configuration entry matching is by having the client side pass the
-file descriptor associated with the connection the client wants to blacklist
+file descriptor associated with the connection the client wants to blocklist
 as well as passing socket credentials.
 .Pp
 The file descriptor is used to retrieve information (address and port)
@@ -116,7 +129,7 @@ specified by the arguments.
 The
 .Ar rulename
 argument can be set from the command line (default
-.Dv blacklistd ) .
+.Dv blocklistd ) .
 The script could print a numerical id to stdout as a handle for
 the rule that can be used later to remove that connection, but
 that is not required as all information to remove the rule is
@@ -152,8 +165,8 @@ The following options are available:
 .It Fl C Ar controlprog
 Use
 .Ar controlprog
-to communicate with the packet filter, usually
-.Pa /usr/libexec/blacklistd-helper .
+to communicate with the packet filter, instead of the default, which is
+.Pa /usr/libexec/blocklistd-helper .
 The following arguments are passed to the control program:
 .Bl -tag -width protocol
 .It action
@@ -161,7 +174,7 @@ The action to perform:
 .Dv add ,
 .Dv rem ,
 or
-.Dv flush
+.Dv flush ;
 to add, remove or flush a firewall rule.
 .It name
 The rule name.
@@ -183,13 +196,17 @@ identifier of the rule to be removed.
 The add command is expected to return the rule identifier string to stdout.
 .El
 .It Fl c Ar configuration
-The name of the configuration file to read, usually
-.Pa /etc/blacklistd.conf .
+The name of the configuration file to read.
+The default when
+.Fl c
+is not given is
+.Pa /etc/blocklistd.conf .
 .It Fl D Ar dbfile
 The Berkeley DB file where
 .Nm
-stores its state, usually
-.Pa /var/db/blacklistd.db .
+stores its state.
+It defaults to
+.Pa /var/db/blocklistd.db .
 .It Fl d
 Normally,
 .Nm
@@ -203,14 +220,14 @@ are deleted by invoking the control script as:
 .Bd -literal -offset indent
 control flush <rulename>
 .Ed
-.It Fl P Ar sockspathsfile
+.It Fl P Ar sockpathsfile
 A file containing a list of pathnames, one per line that
 .Nm
 will create sockets to listen to.
 This is useful for chrooted environments.
 .It Fl R Ar rulename
 Specify the default rule name for the packet filter rules, usually
-.Dv blacklistd .
+.Dv blocklistd .
 .It Fl r
 Re-read the firewall rules from the internal database, then
 remove and re-add them.
@@ -256,19 +273,21 @@ This signal tells
 to decrease the internal debugging level by 1.
 .El
 .Sh FILES
-.Bl -tag -width /usr/libexec/blacklistd-helper -compact
-.It Pa /usr/libexec/blacklistd-helper
+.Bl -tag -width /usr/libexec/blocklistd-helper -compact
+.It Pa /usr/libexec/blocklistd-helper
 Shell script invoked to interface with the packet filter.
-.It Pa /etc/blacklistd.conf
+.It Pa /etc/blocklistd.conf
 Configuration file.
-.It Pa /var/db/blacklistd.db
+.It Pa /var/db/blocklistd.db
 Database of current connection entries.
-.It Pa /var/run/blacklistd.sock
+.It Pa /var/run/blocklistd.sock
 Socket to receive connection notifications.
 .El
 .Sh SEE ALSO
-.Xr blacklistd.conf 5 ,
-.Xr blacklistctl 8 ,
+.Xr blocklistd.conf 5 ,
+.Xr blocklistctl 8 ,
+.Xr ipf 8 ,
+.Xr ipfw 8 ,
 .Xr pfctl 8 ,
 .Xr syslogd 8
 .Sh HISTORY
diff --git a/contrib/blocklist/bin/blacklistd.c b/contrib/blocklist/bin/blocklistd.c
similarity index 91%
rename from contrib/blocklist/bin/blacklistd.c
rename to contrib/blocklist/bin/blocklistd.c
index 714abcbcaf0e..4846b507c8d1 100644
--- a/contrib/blocklist/bin/blacklistd.c
+++ b/contrib/blocklist/bin/blocklistd.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: blacklistd.c,v 1.38 2019/02/27 02:20:18 christos Exp $	*/
+/*	$NetBSD: blocklistd.c,v 1.10 2025/03/26 17:09:35 christos Exp $	*/
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -31,8 +31,11 @@
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
+
+#ifdef HAVE_SYS_CDEFS_H
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: blacklistd.c,v 1.38 2019/02/27 02:20:18 christos Exp $");
+#endif
+__RCSID("$NetBSD: blocklistd.c,v 1.10 2025/03/26 17:09:35 christos Exp $");
 
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -175,6 +178,8 @@ process(bl_t bl)
 	struct dbinfo dbi;
 	struct timespec ts;
 
+	memset(&dbi, 0, sizeof(dbi));
+	memset(&c, 0, sizeof(c));
 	if (clock_gettime(CLOCK_REALTIME, &ts) == -1) {
 		(*lfun)(LOG_ERR, "clock_gettime failed (%m)");
 		return;
@@ -188,10 +193,11 @@ process(bl_t bl)
 	if (getremoteaddress(bi, &rss, &rsl) == -1)
 		goto out;
 
-	if (debug) {
+	if (debug || bi->bi_msg[0]) {
 		sockaddr_snprintf(rbuf, sizeof(rbuf), "%a:%p", (void *)&rss);
-		(*lfun)(LOG_DEBUG, "processing type=%d fd=%d remote=%s msg=%s"
-		    " uid=%lu gid=%lu", bi->bi_type, bi->bi_fd, rbuf,
+		(*lfun)(bi->bi_msg[0] ? LOG_INFO : LOG_DEBUG,
+		    "processing type=%d fd=%d remote=%s msg=%s uid=%lu gid=%lu",
+		    bi->bi_type, bi->bi_fd, rbuf,
 		    bi->bi_msg, (unsigned long)bi->bi_uid,
 		    (unsigned long)bi->bi_gid);
 	}
@@ -216,16 +222,19 @@ process(bl_t bl)
 	switch (bi->bi_type) {
 	case BL_ABUSE:
 		/*
-		 * If the application has signaled abusive behavior,
-		 * set the number of fails to be one less than the
-		 * configured limit.  Fallthrough to the normal BL_ADD
-		 * processing, which will increment the failure count
-		 * to the threshhold, and block the abusive address.
+		 * If the application has signaled abusive behavior, set the
+		 * number of fails to be two less than the configured limit.
+		 * Fall through to the normal BL_ADD and BL_BADUSER processing,
+		 * which will increment the failure count to the threshhold, and
+		 * block the abusive address.
 		 */
 		if (c.c_nfail != -1)
-			dbi.count = c.c_nfail - 1;
+			dbi.count = c.c_nfail - 2;
 		/*FALLTHROUGH*/
 	case BL_ADD:
+		dbi.count++;		/* will become += 2 */
+		/*FALLTHROUGH*/
+	case BL_BADUSER:
 		dbi.count++;
 		dbi.last = ts.tv_sec;
 		if (c.c_nfail != -1 && dbi.count >= c.c_nfail) {
@@ -254,9 +263,6 @@ process(bl_t bl)
 		dbi.count = 0;
 		dbi.last = 0;
 		break;
-	case BL_BADUSER:
-		/* ignore for now */
-		break;
 	default:
 		(*lfun)(LOG_ERR, "unknown message %d", bi->bi_type);
 	}
@@ -334,7 +340,7 @@ static void
 addfd(struct pollfd **pfdp, bl_t **blp, size_t *nfd, size_t *maxfd,
     const char *path)
 {
-	bl_t bl = bl_create(true, path, vflag ? vdlog : vsyslog);
+	bl_t bl = bl_create(true, path, vflag ? vdlog : vsyslog_r);
 	if (bl == NULL || !bl_isconnected(bl))
 		exit(EXIT_FAILURE);
 	if (*nfd >= *maxfd) {
@@ -395,15 +401,25 @@ rules_flush(void)
 static void
 rules_restore(void)
 {
+	DB *db;
 	struct conf c;
 	struct dbinfo dbi;
 	unsigned int f;
 
-	for (f = 1; state_iterate(state, &c, &dbi, f) == 1; f = 0) {
+	db = state_open(dbfile, O_RDONLY, 0);
+	if (db == NULL) {
+		(*lfun)(LOG_ERR, "Can't open `%s' to restore state (%m)",
+			dbfile);
+		return;
+	}
+	for (f = 1; state_iterate(db, &c, &dbi, f) == 1; f = 0) {
 		if (dbi.id[0] == '\0')
 			continue;
 		(void)run_change("add", &c, dbi.id, sizeof(dbi.id));
+		state_put(state, &c, &dbi);
 	}
+	state_close(db);
+	state_sync(state);
 }
 
 int
diff --git a/contrib/blocklist/bin/blacklistd.conf.5 b/contrib/blocklist/bin/blocklistd.conf.5
similarity index 83%
rename from contrib/blocklist/bin/blacklistd.conf.5
rename to contrib/blocklist/bin/blocklistd.conf.5
index 70036441eb4b..3a7dbfc07f58 100644
--- a/contrib/blocklist/bin/blacklistd.conf.5
+++ b/contrib/blocklist/bin/blocklistd.conf.5
@@ -1,6 +1,6 @@
-.\" $NetBSD: blacklistd.conf.5,v 1.9 2019/11/06 20:33:30 para Exp $
+.\" $NetBSD: blocklistd.conf.5,v 1.7 2025/02/11 17:47:05 christos Exp $
 .\"
-.\" Copyright (c) 2015 The NetBSD Foundation, Inc.
+.\" Copyright (c) 2015, 2025 The NetBSD Foundation, Inc.
 .\" All rights reserved.
 .\"
 .\" This code is derived from software contributed to The NetBSD Foundation
@@ -27,17 +27,17 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd May 18, 2020
-.Dt BLACKLISTD.CONF 5
+.Dd February 5, 2025
+.Dt BLOCKLISTD.CONF 5
 .Os
 .Sh NAME
-.Nm blacklistd.conf
-.Nd configuration file format for blacklistd
+.Nm blocklistd.conf
+.Nd configuration file format for blocklistd
 .Sh DESCRIPTION
 The
 .Nm
 file contains configuration entries for
-.Xr blacklistd 8
+.Xr blocklistd 8
 in a fashion similar to
 .Xr inetd.conf 5 .
 Only one entry per line is permitted.
@@ -48,34 +48,34 @@ Comments are denoted by a
 at the beginning of a line.
 .Pp
 There are two kinds of configuration lines,
-.Va local
+.Va [local]
 and
-.Va remote .
+.Va [remote] .
 By default, configuration lines are
-.Va local ,
+.Va [local] ,
 i.e. the address specified refers to the addresses on the local machine.
 To switch to between
-.Va local
+.Va [local]
 and
-.Va remote
+.Va [remote]
 configuration lines you can specify the stanzas:
 .Dq [local]
 and
 .Dq [remote] .
 .Pp
 On
-.Va local
+.Va [local]
 and
-.Va remote
+.Va [remote]
 lines
 .Dq *
 means use the default, or wildcard match.
 In addition, for
-.Va remote
+.Va [remote]
 lines
 .Dq =
 means use the values from the matched
-.Va local
+.Va [local]
 configuration line.
 .Pp
 The first four fields,
@@ -85,9 +85,9 @@ The first four fields,
 and
 .Va owner
 are used to match the
-.Va local
+.Va [local]
 or
-.Va remote
+.Va [remote]
 addresses, whereas the last 3 fields
 .Va name ,
 .Va nfail ,
@@ -110,8 +110,8 @@ The
 can be an IPv4 address in numeric format, an IPv6 address
 in numeric format and enclosed by square brackets, or an interface name.
 Mask modifiers are not allowed on interfaces because interfaces
-can have multiple addresses in different protocols where the mask has a different
-size.
+can have multiple addresses in different protocols where the mask has a
+different size.
 .Pp
 The
 .Dv mask
@@ -143,8 +143,8 @@ The
 field, is the name of the packet filter rule to be used.
 If the
 .Va name
-starts with a
-.Dq - ,
+starts with a hyphen
+.Pq Dq - ,
 then the default rulename is prepended to the given name.
 If the
 .Dv name
@@ -160,13 +160,13 @@ field contains the number of failed attempts before access is blocked,
 defaulting to
 .Dq *
 meaning never, and the last field
-.Va disable
+.Va duration
 specifies the amount of time since the last access that the blocking
 rule should be active, defaulting to
 .Dq *
 meaning forever.
 The default unit for
-.Va disable
+.Va duration
 is seconds, but one can specify suffixes for different units, such as
 .Dq m
 for minutes
@@ -176,28 +176,34 @@ for hours and
 for days.
 .Pp
 Matching is done first by checking the
-.Va local
+.Va [local]
 rules individually, in the order of the most specific to the least specific.
-If a match is found, then the
-.Va remote
+If a match is found, then the matching
+.Va [remote]
 rules are applied.
 The
 .Va name ,
 .Va nfail ,
 and
-.Va disable
+.Va duration
 fields can be altered by the
-.Va remote
+.Va [remote]
 rule that matched.
 .Pp
 The
-.Va remote
+.Va [remote]
 rules can be used for allowing specific addresses, changing the mask
-size, the rule that the packet filter uses, the number of failed attempts,
-or the block duration.
+size (via
+.Va name ) ,
+the rule that the packet filter uses (also via
+.Va name ) ,
+the number of failed attempts (via
+.Va nfail ) ,
+or the duration to block (via
+.Va duration ) .
 .Sh FILES
-.Bl -tag -width /etc/blacklistd.conf -compact
-.It Pa /etc/blacklistd.conf
+.Bl -tag -width /etc/blocklistd.conf -compact
+.It Pa /etc/blocklistd.conf
 Configuration file.
 .El
 .Sh EXAMPLES
@@ -209,13 +215,15 @@ bnx0:ssh	*	*	*	*	3	6h
 [remote]
 # Never block 1.2.3.4
 1.2.3.4:ssh	*	*	*	*	*	*
-# For addresses coming from 8.8.0.0/16 block whole /24 networks instead of
+# Never block the example IPv6 subnet either
+[2001:db8::]/32:ssh	*	*	*	*	*	*
+# For addresses coming from 8.8.0.0/16 block whole /24 networks instead
 # individual hosts, but keep the rest of the blocking parameters the same.
 8.8.0.0/16:ssh	*	*	*	/24	=	=
 .Ed
 .Sh SEE ALSO
-.Xr blacklistctl 8 ,
-.Xr blacklistd 8
+.Xr blocklistctl 8 ,
+.Xr blocklistd 8
 .Sh HISTORY
*** 2792 LINES SKIPPED ***



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?>