Skip to contentSkip to conversation

Three small bugfixes

PATCH New Corubba Smith 1 participant 4 messages Feb 16, 2025 netfilter

lore
Share & tools
lore
#0 lore raw

v2 cover Three small bugfixes

This patchset contains three small bugfixes for the NFCT, GPRINT and IPFIX plugins of ulogd2.

The first patch adds a missing newline to a log message of the NFCT input plugin. The seconds patch adds the missing comma separator after an ip address in the output of the GRPINT output plugin. The third patch fixes the timer in the IPFIX output plugin, which (I assume) is meant to ensure the messages are sent out in a timely manner.

The first two patches are pretty trivial and self-explanatory. The third patch is based on my interpretation of how the plugin is supposed to work, because this architectural detail isn't explained in the original patchset nor discussed in their mailinglist-threads [0] [1]. I was also unable to locate the original 2009 code from Holger Eitzenberger that this is based on for comparison. I may have drawn the wrong conclusion, so please feel free to form your own opinion if it is correct.

[0] https://lore.kernel.org/netfilter-devel/[email protected]/
[1] https://lore.kernel.org/netfilter-devel/[email protected]/

---
Changes in v2:
- Like OPRINT, GPRINT now uses an intermediate buffer (Jeremy Sowden)
- Reword/Reformat commit messages
- Link to v1: https://lore.kernel.org/netfilter-devel/[email protected]/

Corubba Smith (3):
nfct: add newline to reliable log message
gprint: fix comma after ip addresses
ipfix: re-arm send timer

 input/flow/ulogd_inpflow_NFCT.c   | 2 +-
 output/ipfix/ulogd_output_IPFIX.c | 8 ++++++--
 output/ulogd_output_GPRINT.c      | 7 +++++--
 3 files changed, 12 insertions(+), 5 deletions(-)

--
2.48.1

#1 lore raw

PATCH v2 1/3 nfct: add newline to reliable log message

Fixes 4bc3b22e426d ("NFCT: add `reliable' config option to enable reliable flow-based logging")
---
 input/flow/ulogd_inpflow_NFCT.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
input/flow/ulogd_inpflow_NFCT.c +1 -1
index 899b7e3..983c8d6 100644
@@ -1327,7 +1327,7 @@ static int constructor_nfct_events(struct ulogd_pluginstance *upi)
 		setsockopt(nfct_fd(cpi->cth), SOL_NETLINK,
 				NETLINK_NO_ENOBUFS, &on, sizeof(int));
 		ulogd_log(ULOGD_NOTICE, "NFCT reliable logging "
-					"has been enabled.");
+					"has been enabled.\n");
 	}
 	cpi->nfct_fd.fd = nfct_fd(cpi->cth);
 	cpi->nfct_fd.cb = &read_cb_nfct;

--
2.48.1

#2 lore raw

PATCH v2 2/3 gprint: fix comma after ip addresses

In reply to Corubba Smith

Do the same as the oprint plugin: let inet_ntop() write to a temporary buffer, and then write that buffer content and the trailing comma to the actual output buffer in one go.

Fixes f04bf6794d11 ("gprint, oprint: use inet_ntop to format ip addresses")
---
 output/ulogd_output_GPRINT.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
output/ulogd_output_GPRINT.c +5 -2
index 37829fa..20dd308 100644
@@ -155,6 +155,7 @@ static int gprint_interp(struct ulogd_pluginstance *upi)
 			size += ret;
 			break;
 		case ULOGD_RET_IPADDR: {
+			char addrbuf[INET6_ADDRSTRLEN + 1] = "";
 			struct in6_addr ipv6addr;
 			struct in_addr ipv4addr;
 			int family;
@@ -176,10 +177,12 @@ static int gprint_interp(struct ulogd_pluginstance *upi)
 				addr = &ipv4addr;
 				family = AF_INET;
 			}
-			if (!inet_ntop(family, addr, buf + size, rem))
+			if (!inet_ntop(family, addr, addrbuf, sizeof(addrbuf)))
 				break;
-			ret = strlen(buf + size);
 
+			ret = snprintf(buf+size, rem, "%s,", addrbuf);
+			if (ret < 0)
+				break;
 			rem -= ret;
 			size += ret;
 			break;

--
2.48.1

#3 lore raw

PATCH v2 3/3 ipfix: re-arm send timer

In reply to Corubba Smith

I am not sure what this timer was meant to do. My best guess is to send an ipfix message every second if there is data, as to make sure reports go out in a timely manner. Otherwise a message is only sent when adding another flow would go past the max mtu, which may take a while if there isn't much (filtered) traffic.

Timers in ulogd only fire once; if they should fire repeatedly (which I guess was the intention here), they need to be re-armed in the callback. Because that wasn't done, the timer only fired once 1 second after starting the plugin (when there is unlikely any data yet), and then never again.

The timer is now re-armed in the callback to make it fire repeatedly every second(ish). A macro is used to make sure the initial and re-arm time interval is the same.

Fixes 4f639231c83b ("IPFIX: Add IPFIX output plugin")
---
 output/ipfix/ulogd_output_IPFIX.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
output/ipfix/ulogd_output_IPFIX.c +6 -2
index 1c0f730..88e0035 100644
@@ -83,6 +83,8 @@ static const struct config_keyset ipfix_kset = {
 	}
 };
 
+#define SEND_TIMER_INTERVAL_SEC	1
+
 struct ipfix_priv {
 	struct ulogd_fd ufd;
 	uint32_t seqno;
@@ -259,6 +261,8 @@ static void ipfix_timer_cb(struct ulogd_timer *t, void *data)
 		priv->msg = NULL;
 		send_msgs(pi);
 	}
+
+	ulogd_add_timer(&priv->timer, SEND_TIMER_INTERVAL_SEC);
 }
 
 static int ipfix_configure(struct ulogd_pluginstance *pi, struct ulogd_pluginstance_stack *stack)
@@ -394,8 +398,8 @@ static int ipfix_start(struct ulogd_pluginstance *pi)
 	if (ulogd_register_fd(&priv->ufd) < 0)
 		return ULOGD_IRET_ERR;
 
-	/* Add a 1 second timer */
-	ulogd_add_timer(&priv->timer, 1);
+	/* Start the repeating send timer */
+	ulogd_add_timer(&priv->timer, SEND_TIMER_INTERVAL_SEC);
 
 	return ULOGD_IRET_OK;
 }

--
2.48.1