Skip to contentSkip to conversation

Implementation of some fields omitted by `ipulog_get_packet`.

PATCH Applied Jeremy Sowden 4 participants 16 messages Aug 28, 2021 – Sep 1, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Implementation of some fields omitted by `ipulog_get_packet`.

The first four patches contain some miscellaneous improvements, then the last two add code to retrieve time-stamps and interface names from packets.

Incidentally, I notice that the last release of libnetfilter_log was in 2012. Time for 1.0.2, perhaps?

Jeremy Sowden (6):
Add doxygen directory to .gitignore.
build: remove references to non-existent man-pages.
doc: fix typo's in example.
src: use calloc instead of malloc + memset.
libipulog: use correct index to find attribute in packet.
libipulog: fill in missing packet fields.

 .gitignore             |  1 +
 Makefile.am            |  4 +---
 src/libipulog_compat.c | 28 ++++++++++++++++++----------
 src/libnetfilter_log.c | 12 +++++-------
 utils/ulog_test.c      |  7 +++++++
 5 files changed, 32 insertions(+), 20 deletions(-)
Signature · 1 line
2.33.0
#1 lore raw

PATCH 1/6 Add doxygen directory to .gitignore.

---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)
.gitignore +1 -0
index f4938e98d7e9..5eaabe38a514 100644
@@ -13,5 +13,6 @@ Makefile.in
 /configure
 /libtool
 
+/doxygen/
 /doxygen.cfg
 /*.pc
Signature · 1 line
2.33.0
#2 lore raw

PATCH 2/6 build: remove references to non-existent man-pages.

In reply to Jeremy Sowden
---
 Makefile.am | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
Makefile.am +1 -3
index 9a1cbcb481f4..2a9cdd826dae 100644
@@ -2,9 +2,7 @@ SUBDIRS	= include src utils
 
 ACLOCAL_AMFLAGS = -I m4
 
-EXTRA_DIST = $(man_MANS) Make_global.am
-
-man_MANS = #nfnetlink_log.3 nfnetlink_log.7
+EXTRA_DIST = Make_global.am
 
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libnetfilter_log.pc
Signature · 1 line
2.33.0
#3 lore raw

PATCH 3/6 doc: fix typo's in example.

In reply to Jeremy Sowden

Use the right group number in nflog_bind_group example.

---
 src/libnetfilter_log.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
src/libnetfilter_log.c +3 -3
index 567049ccfb37..339f286f36bc 100644
@@ -182,10 +182,10 @@ struct nfnl_handle *nflog_nfnlh(struct nflog_handle *h)
  *
  * Here's a little code snippet that binds to the group 100:
  * \verbatim
-	printf("binding this socket to group 0\n");
-	qh = nflog_bind_group(h, 0);
+	printf("binding this socket to group 100\n");
+	qh = nflog_bind_group(h, 100);
 	if (!qh) {
-		fprintf(stderr, "no handle for grup 0\n");
+		fprintf(stderr, "no handle for group 100\n");
 		exit(1);
 	}
 
Signature · 1 line
2.33.0
#4 lore raw

PATCH 4/6 src: use calloc instead of malloc + memset.

In reply to Jeremy Sowden
---
 src/libipulog_compat.c | 3 +--
 src/libnetfilter_log.c | 6 ++----
 2 files changed, 3 insertions(+), 6 deletions(-)
src/libipulog_compat.c +1 -2
index 2d5b23a25c88..99cd86622d9b 100644
@@ -90,12 +90,11 @@ struct ipulog_handle *ipulog_create_handle(uint32_t gmask,
 	struct ipulog_handle *h;
 	unsigned int group = gmask2group(gmask);
 
-	h = malloc(sizeof(*h)+PAYLOAD_SIZE);
+	h = calloc(1, sizeof(*h)+PAYLOAD_SIZE);
 	if (! h) {
 		ipulog_errno = IPULOG_ERR_HANDLE;
 		return NULL;
 	}
-	memset(h, 0, sizeof(*h));
 	h->nfulh = nflog_open();
 	if (!h->nfulh)
 		goto out_free;
src/libnetfilter_log.c +2 -4
index 339f286f36bc..7d37570e70cb 100644
@@ -238,11 +238,10 @@ struct nflog_handle *nflog_open_nfnl(struct nfnl_handle *nfnlh)
 	struct nflog_handle *h;
 	int err;
 
-	h = malloc(sizeof(*h));
+	h = calloc(1, sizeof(*h));
 	if (!h)
 		return NULL;
 
-	memset(h, 0, sizeof(*h));
 	h->nfnlh = nfnlh;
 
 	h->nfnlssh = nfnl_subsys_open(h->nfnlh, NFNL_SUBSYS_ULOG, 
@@ -398,11 +397,10 @@ nflog_bind_group(struct nflog_handle *h, uint16_t num)
 	if (find_gh(h, num))
 		return NULL;
 	
-	gh = malloc(sizeof(*gh));
+	gh = calloc(1, sizeof(*gh));
 	if (!gh)
 		return NULL;
 
-	memset(gh, 0, sizeof(*gh));
 	gh->h = h;
 	gh->id = num;
 
Signature · 1 line
2.33.0
#5 lore raw

PATCH 5/6 libipulog: use correct index to find attribute in packet.

In reply to Jeremy Sowden

The time-stamp is at NFULA_TIMESTAMP-1 not NFULA_TIMESTAMP.

---
 src/libipulog_compat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/libipulog_compat.c +1 -1
index 99cd86622d9b..bf957274ca22 100644
@@ -158,7 +158,7 @@ next_msg:	printf("next\n");
 	else
 		h->upmsg.mark = 0;
 
-	if (tb[NFULA_TIMESTAMP]) {
+	if (tb[NFULA_TIMESTAMP-1]) {
 		/* FIXME: 64bit network-to-host */
 		h->upmsg.timestamp_sec = h->upmsg.timestamp_usec = 0;
 	} else
Signature · 1 line
2.33.0
#6 lore raw

PATCH 6/6 libipulog: fill in missing packet fields.

In reply to Jeremy Sowden

Retrieval of time-stamp, input- and output-device fields had not been implemented in ipulog_get_packet.

---
 src/libipulog_compat.c | 23 ++++++++++++++++-------
 utils/ulog_test.c      |  7 +++++++
 2 files changed, 23 insertions(+), 7 deletions(-)
src/libipulog_compat.c +16 -7
index bf957274ca22..85f7cf59c2fc 100644
@@ -4,6 +4,7 @@
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <net/if.h>
 #include <netinet/in.h>
 #include <libnfnetlink/libnfnetlink.h>
 #include <libnetfilter_log/libnetfilter_log.h>
@@ -159,20 +160,29 @@ next_msg:	printf("next\n");
 		h->upmsg.mark = 0;
 
 	if (tb[NFULA_TIMESTAMP-1]) {
-		/* FIXME: 64bit network-to-host */
-		h->upmsg.timestamp_sec = h->upmsg.timestamp_usec = 0;
+		struct nfulnl_msg_packet_timestamp *ts;
+		ts = NFA_DATA(tb[NFULA_TIMESTAMP-1]);
+
+		h->upmsg.timestamp_sec  = __be64_to_cpu(ts->sec);
+		h->upmsg.timestamp_usec = __be64_to_cpu(ts->usec);
 	} else
 		h->upmsg.timestamp_sec = h->upmsg.timestamp_usec = 0;
 
 	if (tb[NFULA_IFINDEX_INDEV-1]) {
-		/* FIXME: ifindex lookup */	
-		h->upmsg.indev_name[0] = '\0';
+		void *indev_ptr = NFA_DATA(tb[NFULA_IFINDEX_INDEV-1]);
+		uint32_t indev_idx = ntohl(*(uint32_t *)indev_ptr);
+
+		if (!if_indextoname(indev_idx, h->upmsg.indev_name))
+			h->upmsg.indev_name[0] = '\0';
 	} else
 		h->upmsg.indev_name[0] = '\0';
 
 	if (tb[NFULA_IFINDEX_OUTDEV-1]) {
-		/* FIXME: ifindex lookup */	
-		h->upmsg.outdev_name[0] = '\0';
+		void *outdev_ptr = NFA_DATA(tb[NFULA_IFINDEX_OUTDEV-1]);
+		uint32_t outdev_idx = ntohl(*(uint32_t *)outdev_ptr);
+
+		if (!if_indextoname(outdev_idx, h->upmsg.outdev_name))
+			h->upmsg.outdev_name[0] = '\0';
 	} else
 		h->upmsg.outdev_name[0] = '\0';
 
@@ -222,4 +232,3 @@ void ipulog_perror(const char *s)
 		fprintf(stderr, ": %s", strerror(errno));
 	fputc('\n', stderr);
 }
-
utils/ulog_test.c +7 -0
index f3adec2daf2e..20f61630d2ef 100644
@@ -27,6 +27,13 @@ void handle_packet(ulog_packet_msg_t *pkt)
 	       pkt->hook, pkt->mark, pkt->data_len);
 	if (strlen(pkt->prefix))
 		printf("Prefix=%s ", pkt->prefix);
+	if (strlen(pkt->indev_name))
+		printf("Input device=%s ", pkt->indev_name);
+	if (strlen(pkt->outdev_name))
+		printf("Output device=%s ", pkt->outdev_name);
+	if (pkt->timestamp_sec || pkt->timestamp_usec)
+		printf("Timestamp=%ld.%06lds ",
+		       pkt->timestamp_sec, pkt->timestamp_usec);
 	
 	if (pkt->mac_len)
 	{
Signature · 1 line
2.33.0
#7 lore raw
In reply to Jeremy Sowden
Quoted 7 lines · Jeremy Sowden

Jeremy Sowden (6):
Add doxygen directory to .gitignore.
build: remove references to non-existent man-pages.
doc: fix typo's in example.
src: use calloc instead of malloc + memset.
libipulog: use correct index to find attribute in packet.
libipulog: fill in missing packet fields.

Subjects are not full sentences, as such they should never contain trailing periods.

#8 lore raw
Quoted 11 lines · Jan Engelhardt
Quoted 7 lines · Jeremy Sowden

Jeremy Sowden (6):
Add doxygen directory to .gitignore.
build: remove references to non-existent man-pages.
doc: fix typo's in example.
src: use calloc instead of malloc + memset.
libipulog: use correct index to find attribute in packet.
libipulog: fill in missing packet fields.

Subjects are not full sentences, as such they should never contain trailing periods.

The ones above were certainly intended to be full sentences, but I see that the kernel docuemntation talks about "summary phrases" in subjects, so I take your point.

J.

maintainer Applied
#9 lore raw
In reply to Jeremy Sowden
Quoted 3 lines · Jeremy Sowden

The first four patches contain some miscellaneous improvements, then the last two add code to retrieve time-stamps and interface names from packets.

Applied, thanks.

Quoted 2 lines

Incidentally, I notice that the last release of libnetfilter_log was in 2012. Time for 1.0.2, perhaps?

I'll prepare for release, thanks for signalling.

#10 lore raw
Quoted 11 lines · Pablo Neira Ayuso
Quoted 3 lines · Jeremy Sowden

The first four patches contain some miscellaneous improvements, then the last two add code to retrieve time-stamps and interface names from packets.

Applied, thanks.

Quoted 2 lines

Incidentally, I notice that the last release of libnetfilter_log was in 2012. Time for 1.0.2, perhaps?

I'll prepare for release, thanks for signalling.

With man pages?

Cheers ... Duncan.

#11 lore raw
Quoted 6 lines · Duncan Roe
Quoted 5 lines · Pablo Neira Ayuso
Quoted 3 lines · Jeremy Sowden

The first four patches contain some miscellaneous improvements, then the last two add code to retrieve time-stamps and interface names from packets.

Quoted 8 lines
Quoted 6 lines

Applied, thanks.

Quoted 2 lines

Incidentally, I notice that the last release of libnetfilter_log was in 2012. Time for 1.0.2, perhaps?

I'll prepare for release, thanks for signalling.

With man pages?

I was waiting for you and Pablo to finalize the changes to libnetfilter_queue with the intention of then looking at porting them to libnetfilter_log. :)

The most recent Debian release included a -doc package with the HTML doc's in it, and the next one will include the test programmes as examples, but I think the man-pages need a bit of work first.

J.

#12 lore raw
Quoted 12 lines · Jeremy Sowden
Quoted 11 lines · Duncan Roe
Quoted 10 lines · Pablo Neira Ayuso
Quoted 3 lines · Jeremy Sowden

The first four patches contain some miscellaneous improvements, then the last two add code to retrieve time-stamps and interface names from packets.

Applied, thanks.

Quoted 2 lines

Incidentally, I notice that the last release of libnetfilter_log was in 2012. Time for 1.0.2, perhaps?

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

I'll prepare for release, thanks for signalling.

With man pages?

I was waiting for you and Pablo to finalize the changes to libnetfilter_queue with the intention of then looking at porting them to libnetfilter_log. :)

The are at least 3 areas which could be worked on in the meantime:
1. Fix the remaining doxygen warnings (attached)
2. Insert the SYNOPSIS sections with required #include stmts. I've found that to be a bit of a black art e.g. pktb_alloc() doesn't actually need libmnl.h but if you leave it out then you need stdint.h which libmnl.h drags in. So specify libmnl.h because other functions in the program will need it anyway.
3. The doxygen code will need a bit of "tightening" so man pages look better:

    ensure all functions that return something have a \returns;
    add \sa (see also) where appropriate;
    list possible errno values in an Errors paragraph (or detail the underlying
    system calls that might set errno);
    maybe clarify wording where appropriate.
Quoted 4 lines

The most recent Debian release included a -doc package with the HTML doc's in it, and the next one will include the test programmes as examples, but I think the man-pages need a bit of work first.

Yes the 3 items above should be most of it.
I'm happy to work on them or would you rather?

Quoted 2 lines

J.

Cheers ... Duncan.

Fix the following doxygen warnings:
src/libnetfilter_log.c:888: warning: missing title after \defgroup Printing
src/libnetfilter_log.c:216: warning: argument 'log' of command @param is not found in the argument list of nflog_fd(struct nflog_handle *h) src/libnetfilter_log.c:216: warning: The following parameters of nflog_fd(struct nflog_handle *h) are not documented:
parameter 'h'
src/libnetfilter_log.c:443: warning: argument 'qh' of command @param is not found in the argument list of nflog_set_mode(struct nflog_g_handle *gh, uint8_t mode, uint32_t range) src/libnetfilter_log.c:443: warning: The following parameters of nflog_set_mode(struct nflog_g_handle *gh, uint8_t mode, uint32_t range) are not documented:
parameter 'gh'
src/libnetfilter_log.c:824: warning: The following parameters of nflog_get_gid(struct nflog_data *nfad, uint32_t *gid) are not documented:
parameter 'gid'
src/libnetfilter_log.c:839: warning: The following parameters of nflog_get_seq(struct nflog_data *nfad, uint32_t *seq) are not documented:
parameter 'seq'
src/libnetfilter_log.c:856: warning: The following parameters of nflog_get_seq_global(struct nflog_data *nfad, uint32_t *seq) are not documented:
parameter 'seq'
src/libnetfilter_log.c:809: warning: The following parameters of nflog_get_uid(struct nflog_data *nfad, uint32_t *uid) are not documented:
parameter 'uid'

#13 lore raw
Quoted 35 lines · Duncan Roe
Quoted 12 lines · Jeremy Sowden
Quoted 11 lines · Duncan Roe
Quoted 10 lines · Pablo Neira Ayuso
Quoted 3 lines · Jeremy Sowden

The first four patches contain some miscellaneous improvements, then the last two add code to retrieve time-stamps and interface names from packets.

Applied, thanks.

Quoted 2 lines

Incidentally, I notice that the last release of libnetfilter_log was in 2012. Time for 1.0.2, perhaps?

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

I'll prepare for release, thanks for signalling.

With man pages?

I was waiting for you and Pablo to finalize the changes to libnetfilter_queue with the intention of then looking at porting them to libnetfilter_log. :)

The are at least 3 areas which could be worked on in the meantime:
1. Fix the remaining doxygen warnings (attached)
2. Insert the SYNOPSIS sections with required #include stmts. I've found that to be a bit of a black art e.g. pktb_alloc() doesn't actually need libmnl.h but if you leave it out then you need stdint.h which libmnl.h drags in. So specify libmnl.h because other functions in the program will need it anyway.
3. The doxygen code will need a bit of "tightening" so man pages look
better: ensure all functions that return something have a \returns; add \sa (see also) where appropriate; list possible errno values in an Errors paragraph (or detail the underlying system calls that might set errno); maybe clarify wording where appropriate.

Quoted 1 line
Quoted 6 lines
Quoted 3 lines

The most recent Debian release included a -doc package with the HTML doc's in it, and the next one will include the test programmes as examples, but I think the man-pages need a bit of work first.

Yes the 3 items above should be most of it. I'm happy to work on them or would you rather?

I dare say that the work will probably go more quickly if you do it.

J.

#14 lore raw
In reply to Pablo Neira Ayuso
Quoted 11 lines · Pablo Neira Ayuso
Quoted 3 lines · Jeremy Sowden

The first four patches contain some miscellaneous improvements, then the last two add code to retrieve time-stamps and interface names from packets.

Applied, thanks.

Quoted 2 lines

Incidentally, I notice that the last release of libnetfilter_log was in 2012. Time for 1.0.2, perhaps?

I'll prepare for release, thanks for signalling.

Thanks. Here's a patch to create a LIBVERSION variable for libnetfilter_log_libipulog.

J.

From f41fb8baa5993e21dbe21ad9ad52c8af2fae4d98 Mon Sep 17 00:00:00 2001
From: Jeremy Sowden <[email protected]>
Date: Sun, 29 Aug 2021 11:40:13 +0100
Subject: [PATCH] build: add LIBVERSION variable for ipulog

Replace hard-coded version-info in LDFLAGS.

---
 src/Makefile.am | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
src/Makefile.am +6 -5
index 335c393f760a..815d9d31cfc0 100644
@@ -18,13 +18,14 @@
 # set age to 0.
 # </snippet>
 #
-LIBVERSION=2:0:1
+LIBVERSION = 2:0:1
+IPULOG_LIBVERSION = 1:0:0
 
 include ${top_srcdir}/Make_global.am
 
 lib_LTLIBRARIES = libnetfilter_log.la
 
-libnetfilter_log_la_LDFLAGS = -Wc,-nostartfiles	\
+libnetfilter_log_la_LDFLAGS = -Wc,-nostartfiles \
 			      -version-info $(LIBVERSION)
 libnetfilter_log_la_SOURCES = libnetfilter_log.c nlmsg.c
 libnetfilter_log_la_LIBADD  = ${LIBNFNETLINK_LIBS} ${LIBMNL_LIBS}
@@ -32,8 +33,8 @@ libnetfilter_log_la_LIBADD  = ${LIBNFNETLINK_LIBS} ${LIBMNL_LIBS}
 if BUILD_IPULOG
 lib_LTLIBRARIES += libnetfilter_log_libipulog.la
 
-libnetfilter_log_libipulog_la_LDFLAGS = -Wc,-nostartfiles	\
-					-version-info 1:0:0
-libnetfilter_log_libipulog_la_LIBADD = libnetfilter_log.la ${LIBNFNETLINK_LIBS}
+libnetfilter_log_libipulog_la_LDFLAGS = -Wc,-nostartfiles \
+					-version-info $(IPULOG_LIBVERSION)
+libnetfilter_log_libipulog_la_LIBADD  = libnetfilter_log.la ${LIBNFNETLINK_LIBS}
 libnetfilter_log_libipulog_la_SOURCES = libipulog_compat.c
 endif
Signature · 1 line
2.33.0
maintainer Applied
#15 lore raw
Quoted 6 lines · Jeremy Sowden

From f41fb8baa5993e21dbe21ad9ad52c8af2fae4d98 Mon Sep 17 00:00:00 2001
From: Jeremy Sowden <[email protected]>
Date: Sun, 29 Aug 2021 11:40:13 +0100
Subject: [PATCH] build: add LIBVERSION variable for ipulog

Replace hard-coded version-info in LDFLAGS.

Applied, thanks.