From 18e80ceb11b35ba838286024119ce6dd0ee4b801 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Mon, 17 Nov 2025 01:08:57 +0100 Subject: [PATCH] confd: extend syslogd support with hostname-based filtering Signed-off-by: Joachim Wiberg --- .../skeleton/etc/default/sysklogd | 6 ++++-- src/confd/src/ietf-syslog.c | 14 ++++++++++++++ src/confd/yang/confd.inc | 2 +- src/confd/yang/confd/infix-syslog.yang | 11 +++++++++++ ...024-07-19.yang => infix-syslog@2025-11-17.yang} | 0 5 files changed, 30 insertions(+), 3 deletions(-) rename src/confd/yang/confd/{infix-syslog@2024-07-19.yang => infix-syslog@2025-11-17.yang} (100%) diff --git a/package/skeleton-init-finit/skeleton/etc/default/sysklogd b/package/skeleton-init-finit/skeleton/etc/default/sysklogd index dba36fc2..81ddfc36 100644 --- a/package/skeleton-init-finit/skeleton/etc/default/sysklogd +++ b/package/skeleton-init-finit/skeleton/etc/default/sysklogd @@ -1,5 +1,7 @@ -# -l :: Keep kernel looging to console +# -H :: Log remote messages using hostname from the message +# -l :: Keep kernel logging to console # -m0 :: Disable periodic syslog MARK entries +# -n :: Disable DNS query for every request, trust hostname in message # -s :: Enable secure mode, don't listen to remote logs # -r 1M:5 :: Log rotation every 1 MiB and keep 5 rotated ones -SYSLOGD_ARGS="-l -m0" +SYSLOGD_ARGS="-H -l -m0" diff --git a/src/confd/src/ietf-syslog.c b/src/confd/src/ietf-syslog.c index d563f076..d3c3d320 100644 --- a/src/confd/src/ietf-syslog.c +++ b/src/confd/src/ietf-syslog.c @@ -104,6 +104,20 @@ static size_t selector(sr_session_ctx_t *session, struct action *act) char *pattern; int rc; + /* Check for hostname-filter (infix-syslog augment) */ + snprintf(xpath, sizeof(xpath), "%s/infix-syslog:hostname-filter", act->xpath); + rc = sr_get_items(session, xpath, 0, 0, &list, &count); + if (rc == SR_ERR_OK && count > 0) { + fprintf(act->fp, "+"); + for (size_t i = 0; i < count; i++) + fprintf(act->fp, "%s%s", i ? "," : "", list[i].data.string_val); + fprintf(act->fp, "\n"); + + sr_free_values(list, count); + list = NULL; + count = 0; + } + /* Check for pattern-match (select-match feature) */ pattern = srx_get_str(session, "%s/pattern-match", act->xpath); if (pattern) { diff --git a/src/confd/yang/confd.inc b/src/confd/yang/confd.inc index b2648aff..3e102c98 100644 --- a/src/confd/yang/confd.inc +++ b/src/confd/yang/confd.inc @@ -19,7 +19,7 @@ MODULES=( # NOTE: ietf-tls-client must be version matched with ietf-tls-server, used by netopeer2! "ietf-tls-client@2023-12-28.yang" "ietf-syslog@2024-03-21.yang -e file-action -e file-limit-size -e remote-action -e select-adv-compare -e select-match" - "infix-syslog@2024-07-19.yang" + "infix-syslog@2025-11-17.yang" "iana-hardware@2018-03-13.yang" "ietf-hardware@2018-03-13.yang -e hardware-state -e hardware-sensor" "infix-hardware@2025-10-30.yang" diff --git a/src/confd/yang/confd/infix-syslog.yang b/src/confd/yang/confd/infix-syslog.yang index 1d895d03..72d5124f 100644 --- a/src/confd/yang/confd/infix-syslog.yang +++ b/src/confd/yang/confd/infix-syslog.yang @@ -16,6 +16,11 @@ module infix-syslog { contact "kernelkit@googlegroups.com"; description "Infix augments and deviations to ietf-syslog, draft 32."; + revision 2025-11-17 { + description "Add hostname-filter support."; + reference "internal"; + } + revision 2024-07-19 { description "Initial revision, based on IETF syslog YANG draft 32. The following changes have been made in this model: @@ -164,6 +169,12 @@ module infix-syslog { } } } + + leaf-list hostname-filter { + type inet:domain-name; + description "Filter messages by hostname. Messages from the listed + hostnames will be logged to this file."; + } } augment "/syslog:syslog/syslog:actions/syslog:remote/syslog:destination" { diff --git a/src/confd/yang/confd/infix-syslog@2024-07-19.yang b/src/confd/yang/confd/infix-syslog@2025-11-17.yang similarity index 100% rename from src/confd/yang/confd/infix-syslog@2024-07-19.yang rename to src/confd/yang/confd/infix-syslog@2025-11-17.yang