Skip to contentSkip to conversation

snprintf: print conntrack helper name, too

PATCH Applied Florian Westphal 2 participants 2 messages May 18, 2012 – May 20, 2012 netfilter

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 snprintf: print conntrack helper name, too

---
 src/conntrack/snprintf_default.c |   11 +++++++++++
 src/conntrack/snprintf_xml.c     |   16 ++++++++++++++++
 2 files changed, 27 insertions(+), 0 deletions(-)
src/conntrack/snprintf_default.c +11 -0
index 206b9c0..45d192d 100644
@@ -282,6 +282,12 @@ __snprintf_timestamp_delta(char *buf, unsigned int len,
 			(unsigned long long)delta_time));
 }
 
+static int
+__snprintf_helper_name(char *buf, unsigned int len, const struct nf_conntrack *ct)
+{
+	return (snprintf(buf, len, "helper=%s ", ct->helper_name));
+}
+
 int __snprintf_conntrack_default(char *buf, 
 				 unsigned int len,
 				 const struct nf_conntrack *ct,
@@ -415,6 +421,11 @@ int __snprintf_conntrack_default(char *buf,
 		BUFFER_SIZE(ret, size, len, offset);
 	}
 
+	if (test_bit(ATTR_HELPER_NAME, ct->head.set)) {
+		ret = __snprintf_helper_name(buf+offset, len, ct);
+		BUFFER_SIZE(ret, size, len, offset);
+	}
+
 	/* Delete the last blank space */
 	size--;
 
src/conntrack/snprintf_xml.c +16 -0
index 756d118..ad53075 100644
@@ -239,6 +239,18 @@ __snprintf_deltatime(char *buf, unsigned int len, const struct nf_conntrack *ct)
 	return size;
 }
 
+static int
+__snprintf_helper_name(char *buf, unsigned int len, const struct nf_conntrack *ct)
+{
+	int ret;
+	unsigned int size = 0, offset = 0;
+
+	ret = snprintf(buf+offset, len, "<helper>%s</helper>", ct->helper_name);
+	BUFFER_SIZE(ret, size, len, offset);
+
+	return size;
+}
+
 int
 __snprintf_localtime_xml(char *buf, unsigned int len, const struct tm *tm)
 {
@@ -522,6 +534,10 @@ int __snprintf_conntrack_xml(char *buf,
 		BUFFER_SIZE(ret, size, len, offset);
 	}
 
+	if (test_bit(ATTR_HELPER_NAME, ct->head.set)) {
+		ret = __snprintf_helper_name(buf+offset, len, ct);
+		BUFFER_SIZE(ret, size, len, offset);
+	}
 err_out:
 	ret = snprintf(buf+offset, len, "</flow>");
 	BUFFER_SIZE(ret, size, len, offset);
Signature · 1 line
1.7.3.4
maintainer Applied
#1 lore raw
Quoted 1 line · Florian Westphal

Applied, thanks Florian.

I've mangled this to move the helper=%s before id=%d and use=%d.

This breaks the output for applications parsing our text-based output.

Still, we provide XML output that remains consistent along updates. And, if people don't like XML (I would not blame them), they can still contribute some more easy to parse extension in CSKV format, or even some output in JSON format.