netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Corubba Smith <corubba@gmx.de>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH ulogd2 7/8] ulogd: default configure implementation
Date: Sat, 8 Mar 2025 23:38:16 +0100	[thread overview]
Message-ID: <33fac502-d6b6-42c7-94e5-a78adc0dc86d@gmx.de> (raw)
In-Reply-To: <ca5581f5-5e54-47f5-97c8-bcc788c77781@gmx.de>

Provide a default implementation for the configure hook which simply
calls ulogd_parse_configfile(), so simple plugins only need to provide
the config_keyset. This also triggers an "unknown key" error if a
plugin defines no config_keyset (aka it has no options), but the config
file contains directives for it.

Signed-off-by: Corubba Smith <corubba@gmx.de>
---
 src/conffile.c |  7 ++++++-
 src/ulogd.c    | 21 ++++++++++++++-------
 2 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/src/conffile.c b/src/conffile.c
index f412804..b9027da 100644
--- a/src/conffile.c
+++ b/src/conffile.c
@@ -158,7 +158,12 @@ int config_parse_file(const char *section, struct config_keyset *kset)
 	}

 	if (!found) {
-		err = -ERRSECTION;
+		if (kset->num_ces == 0) {
+			/* If there are no options, then no section isnt an error. */
+			err = 0;
+		} else {
+			err = -ERRSECTION;
+		}
 		goto cpf_error;
 	}

diff --git a/src/ulogd.c b/src/ulogd.c
index 96cea8a..d72ede5 100644
--- a/src/ulogd.c
+++ b/src/ulogd.c
@@ -869,15 +869,22 @@ create_stack_resolve_keys(struct ulogd_pluginstance_stack *stack)
 			  pi_cur->plugin->name);
 		/* call plugin to tell us which keys it requires in
 		 * given configuration */
+		int ret;
 		if (pi_cur->plugin->configure) {
-			int ret = pi_cur->plugin->configure(pi_cur,
-							    stack);
-			if (ret < 0) {
-				ulogd_log(ULOGD_ERROR, "error during "
-					  "configure of plugin %s\n",
-					  pi_cur->plugin->name);
-				return ret;
+			ret = pi_cur->plugin->configure(pi_cur, stack);
+		} else {
+			struct config_keyset empty_kset = {.num_ces=0};
+			struct config_keyset *kset = &empty_kset;
+			if (pi_cur->config_kset) {
+				kset = pi_cur->config_kset;
 			}
+			ret = ulogd_parse_configfile(pi_cur->id, kset);
+		}
+		if (ret < 0) {
+			ulogd_log(ULOGD_ERROR, "error during "
+				  "configure of plugin %s\n",
+				  pi_cur->plugin->name);
+			return ret;
 		}
 	}

--
2.48.1


  parent reply	other threads:[~2025-03-08 22:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-08 22:32 [PATCH ulogd2 1/8] ulogd: fix config file fd leak Corubba Smith
2025-03-08 22:33 ` [PATCH ulogd2 2/8] ulogd: add ulogd_parse_configfile public function Corubba Smith
2025-03-12  7:47   ` Florian Westphal
2025-03-08 22:34 ` [PATCH ulogd2 3/8] all: use config_parse_file function in all plugins Corubba Smith
2025-03-08 22:35 ` [PATCH ulogd2 4/8] ulogd: raise error on unknown config key Corubba Smith
2025-03-08 22:36 ` [PATCH ulogd2 5/8] ulogd: ignore malformed config directives Corubba Smith
2025-03-08 22:37 ` [PATCH ulogd2 6/8] ulogd: improve integer option parsing Corubba Smith
2025-03-08 22:38 ` Corubba Smith [this message]
2025-03-08 22:39 ` [PATCH ulogd2 8/8] all: remove trivial configure hooks Corubba Smith

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=33fac502-d6b6-42c7-94e5-a78adc0dc86d@gmx.de \
    --to=corubba@gmx.de \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).