Skip to contentSkip to conversation

Three small bugfixes

PATCH Superseded corubba 3 participants 9 messages Feb 8, 2025 netfilter

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

corubba

author
#0 lore raw

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]/

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      | 6 ++++++
 3 files changed, 13 insertions(+), 3 deletions(-)

--
2.48.1

author
#1 lore raw

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

Missing since 4bc3b22e.

---
 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

author
#2 lore raw

PATCH 2/3 gprint: fix comma after ip addresses

In reply to corubba

Gone missing in f04bf679.

---
 output/ulogd_output_GPRINT.c | 6 ++++++
 1 file changed, 6 insertions(+)
output/ulogd_output_GPRINT.c +6 -0
index 37829fa..d95ca9d 100644
@@ -179,9 +179,15 @@ static int gprint_interp(struct ulogd_pluginstance *upi)
 			if (!inet_ntop(family, addr, buf + size, rem))
 				break;
 			ret = strlen(buf + size);
+			rem -= ret;
+			size += ret;
 
+			ret = snprintf(buf+size, rem, ",");
+			if (ret < 0)
+				break;
 			rem -= ret;
 			size += ret;
+
 			break;
 		}
 		default:

--
2.48.1

#3 lore raw

Re: [PATCH ulogd2 2/3] gprint: fix comma after ip addresses

Quoted 1 line · corubba

Gone missing in f04bf679.

ulogd2$ git show f04bf679
fatal: ambiguous argument 'f04bf679': unknown revision or path not in the working tree.

???

Quoted 29 lines
---
 output/ulogd_output_GPRINT.c | 6 ++++++
 1 file changed, 6 insertions(+)
output/ulogd_output_GPRINT.c +6 -1
index 37829fa..d95ca9d 100644
@@ -179,9 +179,15 @@ static int gprint_interp(struct ulogd_pluginstance *upi)
 			if (!inet_ntop(family, addr, buf + size, rem))
 				break;
 			ret = strlen(buf + size);
+			rem -= ret;
+			size += ret;
 
+			ret = snprintf(buf+size, rem, ",");
+			if (ret < 0)
+				break;
 			rem -= ret;
 			size += ret;
+
 			break;
 		}
 		default:
--

2.48.1

author
#4 lore raw

Re: [PATCH ulogd2 2/3] gprint: fix comma after ip addresses

Quoted 7 lines · Pablo Neira Ayuso
Quoted 1 line · corubba

Gone missing in f04bf679.

ulogd2$ git show f04bf679
fatal: ambiguous argument 'f04bf679': unknown revision or path not in the working tree.

???

The full commit id is f04bf6794d1153abd2c3b0bfededd9403d79acf6, which does exist [0]. And that git show command works in my local clone of the repo, showing the commit in question.

[0] https://git.netfilter.org/ulogd2/commit/?id=f04bf679

Quoted 31 lines
Quoted 30 lines
---
 output/ulogd_output_GPRINT.c | 6 ++++++
 1 file changed, 6 insertions(+)
output/ulogd_output_GPRINT.c +6 -1
index 37829fa..d95ca9d 100644
@@ -179,9 +179,15 @@ static int gprint_interp(struct ulogd_pluginstance *upi)
 			if (!inet_ntop(family, addr, buf + size, rem))
 				break;
 			ret = strlen(buf + size);
+			rem -= ret;
+			size += ret;
 
+			ret = snprintf(buf+size, rem, ",");
+			if (ret < 0)
+				break;
 			rem -= ret;
 			size += ret;
+
 			break;
 		}
 		default:
--

2.48.1

#5 lore raw

Re: [PATCH ulogd2 2/3] gprint: fix comma after ip addresses

Quoted 7 lines · corubba
Quoted 6 lines · Pablo Neira Ayuso
Quoted 1 line · corubba

Gone missing in f04bf679.

ulogd2$ git show f04bf679
fatal: ambiguous argument 'f04bf679': unknown revision or path not in the working tree.

Quoted 7 lines
Quoted 1 line

???

The full commit id is f04bf6794d1153abd2c3b0bfededd9403d79acf6, which does exist [0]. And that git show command works in my local clone of the repo, showing the commit in question.

[0] https://git.netfilter.org/ulogd2/commit/?id=f04bf679

My fault, I was quickly checking on a stale working copy of ulogd2, apologies.

#6 lore raw

Re: [PATCH ulogd2 2/3] gprint: fix comma after ip addresses

In reply to Pablo Neira Ayuso
Quoted 7 lines · Pablo Neira Ayuso
Quoted 1 line · corubba

Gone missing in f04bf679.

ulogd2$ git show f04bf679
fatal: ambiguous argument 'f04bf679': unknown revision or path not in the working tree.

???

f04bf6794d11 ("gprint, oprint: use inet_ntop to format ip addresses"). It includes this change:

- ret = snprintf(buf+size, rem, "%u.%u.%u.%u,",
- NIPQUAD(key->u.value.ui32));

-                       if (ret < 0)
+                       ipv4addr.s_addr = key->u.value.ui32;
+                       if (!inet_ntop(AF_INET, &ipv4addr, buf + size, rem))
                                break;

+ ret = strlen(buf + size);
+

The snprintf appends a comma after the IP address.

Quoted 16 lines
Quoted 16 lines
---
 output/ulogd_output_GPRINT.c | 6 ++++++
 1 file changed, 6 insertions(+)
output/ulogd_output_GPRINT.c +2 -0
index 37829fa..d95ca9d 100644
@@ -179,9 +179,15 @@ static int gprint_interp(struct ulogd_pluginstance *upi)
 			if (!inet_ntop(family, addr, buf + size, rem))
 				break;
 			ret = strlen(buf + size);
+			rem -= ret;
+			size += ret;
 
Quoted 14 lines
Quoted 10 lines
output/ulogd_output_GPRINT.c +4 -1
+			ret = snprintf(buf+size, rem, ",");
+			if (ret < 0)
+				break;
 			rem -= ret;
 			size += ret;
+
 			break;
 		}
 		default:
--
Quoted 3 lines

2.48.1

J.

#7 lore raw

Re: [PATCH ulogd2 2/3] gprint: fix comma after ip addresses

In reply to corubba
Quoted 17 lines · corubba

Gone missing in f04bf679.

---
 output/ulogd_output_GPRINT.c | 6 ++++++
 1 file changed, 6 insertions(+)
output/ulogd_output_GPRINT.c +2 -0
index 37829fa..d95ca9d 100644
@@ -179,9 +179,15 @@ static int gprint_interp(struct ulogd_pluginstance *upi)
 			if (!inet_ntop(family, addr, buf + size, rem))
 				break;
 			ret = strlen(buf + size);
+			rem -= ret;
+			size += ret;

output/ulogd_output_GPRINT.c static int gprint_interp(struct ulogd_pluginstance *upi) · line 193

Quoted 10 lines
output/ulogd_output_GPRINT.c +4 -0
 
+			ret = snprintf(buf+size, rem, ",");
+			if (ret < 0)
+				break;
 			rem -= ret;
 			size += ret;
+
 			break;
 		}
 		default:

My suggestion would be to follow ulgod_output_OPRINT.c (completely untested):

output/ulogd_output_GPRINT.c +5 -3
index 37829fa49e9d..b18fe3a0838c 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,11 @@ 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 = snprintf(buf + size, rem, "%s,", addrbuf);
+                       if (ret < 0)
                                break;
-                       ret = strlen(buf + size);
-
                        rem -= ret;
                        size += ret;
                        break;

J.

author
#8 lore raw

PATCH 3/3 ipfix: re-arm send timer

In reply to corubba

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 you want them to fire repeatedly (which I guess was the intention here), you need to re-arm them 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.

Broken since 4f639231.

---
 output/ipfix/ulogd_output_IPFIX.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
output/ipfix/ulogd_output_IPFIX.c +6 -2
index 1c0f730..c1fe1ab 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