Skip to contentSkip to conversation

Misc code cleaning

PATCH In review Eric Leblond 2 participants 7 messages Dec 29, 2008 – Dec 30, 2008 netfilter

lore
Share & tools
lore
#0 lore raw

cover Misc code cleaning

This small patchset cleans some part of the code of libnetfilter_log:
* Suppress reference to libnetfilter_queue which is the model of libnetfilter_log.
* Set nflog_errno as needed:
some FIXME were remaining, this patch fix this issue
* Suppress NFULNL_MSG_CONFIG callback registration:
last FIXME was about a not coded and not used feature. The patch disables it.

BR,
--
Eric Leblond <[email protected]>
INL: http://www.inl.fr/
NuFW: http://www.nufw.org/
EdenWall: http://www.edenwall.com/

Patchset statistics:

 src/libnetfilter_log.c |   38 +++++++++-----------------------------
 1 files changed, 9 insertions(+), 29 deletions(-)
#1 lore raw

PATCH 1/3 Suppress reference to libnetfilter_queue which is the model of libnetfilter_log.

This patch fixes the description of the file was the one of libnetfilter_queue.c and it suppresses indication through out the file that it is a copy of the queue module.

---
 src/libnetfilter_log.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)
src/libnetfilter_log.c +7 -7
index 216cdb8..ed92561 100644
@@ -1,4 +1,4 @@
-/* libnfqnetlink.c: generic library for access to nf_queue
+/* libnetfilter_log.c: generic library for access to NFLOG
  *
  * (C) 2005 by Harald Welte <[email protected]>
  *
@@ -104,7 +104,7 @@ static int __nflog_rcv_cmd(struct nlmsghdr *nlh, struct nfattr *nfa[],
 /* build a NFULNL_MSG_CONFIG message */
 static int
 __build_send_cfg_msg(struct nflog_handle *h, u_int8_t command,
-		     u_int16_t queuenum, u_int8_t pf)
+		     u_int16_t groupnum, u_int8_t pf)
 {
 	union {
 		char buf[NFNL_HEADER_LEN
@@ -113,7 +113,7 @@ __build_send_cfg_msg(struct nflog_handle *h, u_int8_t command,
 	} u;
 	struct nfulnl_msg_config_cmd cmd;
 
-	nfnl_fill_hdr(h->nfnlssh, &u.nmh, 0, pf, queuenum,
+	nfnl_fill_hdr(h->nfnlssh, &u.nmh, 0, pf, groupnum,
 		      NFULNL_MSG_CONFIG, NLM_F_REQUEST|NLM_F_ACK);
 
 	cmd.command = command;
@@ -242,19 +242,19 @@ int nflog_close(struct nflog_handle *h)
 	return ret;
 }
 
-/* bind nf_queue from a specific protocol family */
+/* bind nf_log from a specific protocol family */
 int nflog_bind_pf(struct nflog_handle *h, u_int16_t pf)
 {
 	return __build_send_cfg_msg(h, NFULNL_CFG_CMD_PF_BIND, 0, pf);
 }
 
-/* unbind nf_queue from a specific protocol family */
+/* unbind nf_log from a specific protocol family */
 int nflog_unbind_pf(struct nflog_handle *h, u_int16_t pf)
 {
 	return __build_send_cfg_msg(h, NFULNL_CFG_CMD_PF_UNBIND, 0, pf);
 }
 
-/* bind this socket to a specific queue number */
+/* bind this socket to a specific group number */
 struct nflog_g_handle *
 nflog_bind_group(struct nflog_handle *h, u_int16_t num)
 {
@@ -280,7 +280,7 @@ nflog_bind_group(struct nflog_handle *h, u_int16_t num)
 	return gh;
 }
 
-/* unbind this socket from a specific queue number */
+/* unbind this socket from a specific group number */
 int nflog_unbind_group(struct nflog_g_handle *gh)
 {
 	int ret = __build_send_cfg_msg(gh->h, NFULNL_CFG_CMD_UNBIND, gh->id, 0);
Signature · 1 line
1.5.6.3
#2 lore raw

Re: [libnetfilter_log 1/3] Suppress reference to libnetfilter_queue which is the model of libnetfilter_log.

Quoted 3 lines · Eric Leblond

This patch fixes the description of the file was the one of libnetfilter_queue.c and it suppresses indication through out the file that it is a copy of the queue module.

Please, apply this one by yourself. Thanks.

Signature · 1 line
"Los honestos son inadaptados sociales" -- Les Luthiers
#3 lore raw

PATCH 2/3 Set nflog_errno as needed.

In reply to Eric Leblond

Some FIXME were put to fix some issues related to nflog_errno not being set. In both case, this was related to error treatment of libnfnetlink function. As these functions are setting errno to the correct value, this patch simply copy errno to nflog_errno in libnetfilter_log.

---
 src/libnetfilter_log.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
src/libnetfilter_log.c +2 -2
index ed92561..9343f90 100644
@@ -178,7 +178,7 @@ struct nflog_handle *nflog_open_nfnl(struct nfnl_handle *nfnlh)
 	h->nfnlssh = nfnl_subsys_open(h->nfnlh, NFNL_SUBSYS_ULOG, 
 				      NFULNL_MSG_MAX, 0);
 	if (!h->nfnlssh) {
-		/* FIXME: nflog_errno */
+		nflog_errno = errno;
 		goto out_free;
 	}
 
@@ -210,7 +210,7 @@ struct nflog_handle *nflog_open(void)
 
 	nfnlh = nfnl_open();
 	if (!nfnlh) {
-		/* FIXME: nflog_errno */
+		nflog_errno = errno;
 		return NULL;
 	}
 
Signature · 1 line
1.5.6.3
#4 lore raw

Re: [libnetfilter_log 2/3] Set nflog_errno as needed.

Quoted 3 lines · Eric Leblond

Some FIXME were put to fix some issues related to nflog_errno not being set. In both case, this was related to error treatment of libnfnetlink function. As these functions are setting errno to the correct value, this patch simply copy errno to nflog_errno in libnetfilter_log.

I doubt that anyone if using nf*_errno at this moment since t is not of any help. We have no internal errno values different than those defined in errno.h. I think it's better to use errno instead, at least for this version of the API. See libnetfilter_conntrack.

For the upcoming version, we can introduce the nf*_errno again and define internal errors. Same applies for libnetfilter_queue.

Signature · 1 line
"Los honestos son inadaptados sociales" -- Les Luthiers
#5 lore raw

PATCH 3/3 Suppress NFULNL_MSG_CONFIG callback registration.

In reply to Eric Leblond

It seems there is no NFULNL_MSG_CONFIG message send from kernel space to userspace. Thus the registration of an nfnetlink callback for this type of messages is not necessary.

---
 src/libnetfilter_log.c |   20 --------------------
 1 files changed, 0 insertions(+), 20 deletions(-)
src/libnetfilter_log.c +0 -20
index 9343f90..2bbc875 100644
@@ -92,15 +92,6 @@ static struct nflog_g_handle *find_gh(struct nflog_handle *h, u_int16_t group)
 	return NULL;
 }
 
-static int __nflog_rcv_cmd(struct nlmsghdr *nlh, struct nfattr *nfa[],
-			    void *data)
-{
-	/* struct nflog_handle *h = data; */
-
-	/* FIXME: implement this */
-	return 0;
-}
-
 /* build a NFULNL_MSG_CONFIG message */
 static int
 __build_send_cfg_msg(struct nflog_handle *h, u_int8_t command,
@@ -141,11 +132,6 @@ static int __nflog_rcv_pkt(struct nlmsghdr *nlh, struct nfattr *nfa[],
 	return gh->cb(gh, nfmsg, &nfldata, gh->data);
 }
 
-static struct nfnl_callback cmd_cb = {
-	.call 		= &__nflog_rcv_cmd,
-	.attr_count 	= NFULA_CFG_MAX,
-};
-
 static struct nfnl_callback pkt_cb = {
 	.call 		= &__nflog_rcv_pkt,
 	.attr_count 	= NFULA_MAX,
@@ -182,12 +168,6 @@ struct nflog_handle *nflog_open_nfnl(struct nfnl_handle *nfnlh)
 		goto out_free;
 	}
 
-	cmd_cb.data = h;
-	err = nfnl_callback_register(h->nfnlssh, NFULNL_MSG_CONFIG, &cmd_cb);
-	if (err < 0) {
-		nflog_errno = err;
-		goto out_close;
-	}
 	pkt_cb.data = h;
 	err = nfnl_callback_register(h->nfnlssh, NFULNL_MSG_PACKET, &pkt_cb);
 	if (err < 0) {
Signature · 1 line
1.5.6.3
#6 lore raw

Re: [libnetfilter_log 3/3] Suppress NFULNL_MSG_CONFIG callback registration.

Quoted 3 lines · Eric Leblond

It seems there is no NFULNL_MSG_CONFIG message send from kernel space to userspace. Thus the registration of an nfnetlink callback for this type of messages is not necessary.

Please, also apply this one.

Signature · 1 line
"Los honestos son inadaptados sociales" -- Les Luthiers