All of lore.kernel.org
 help / color / mirror / Atom feed
From: Amin Azez <azez@ufomechanic.net>
To: Harald Welte <laforge@netfilter.org>
Cc: netfilter-devel@lists.netfilter.org, Patrick McHardy <kaber@trash.net>
Subject: Re: [PATCH 4/*] libnfnetlink fixes
Date: Mon, 05 Sep 2005 17:31:11 +0100	[thread overview]
Message-ID: <431C72CF.4060406@ufomechanic.net> (raw)
In-Reply-To: <20050828115013.GE4244@rama.de.gnumonks.org>

[-- Attachment #1: Type: text/plain, Size: 993 bytes --]

Attached, with explanatory notes in the function comment.

Sam

Harald Welte wrote:
> On Wed, Jul 13, 2005 at 09:23:56AM +0100, Amin Azez wrote:
> 
> 
>>It allows the application-supplied callback handler to signifiy in its
>>return code whether or not the nfnl_listen read-loop should terminate.
>>
>>If the handler returns a negative code, then nfnl_listen returns
>>immediately with the same return code.
>>
>>If the handler returns a postitive code, then nfnl_listen returns at the
>>next iteration of the while loop, which is when it finishes handing all
>>netlink messages in the current packet.
>>
>>This avois the need to duplicate most of nfnl_listen in a non-loop
>>context where the application needs control over the read and packet
>>decode process.
> 
> 
> I think this change is fine.  Would you mind to re-submit the patch
> against current svn?  Please also document the meaning of the return
> values, probably with a comment in the code or the header file?
> 
> Thanks!
> 


[-- Attachment #2: libnfnetlink.c.diff --]
[-- Type: text/x-patch, Size: 1691 bytes --]

Index: src/libnfnetlink.c
===================================================================
--- src/libnfnetlink.c	(revision 4254)
+++ src/libnfnetlink.c	(working copy)
@@ -257,6 +257,16 @@
  *
  * nfnhl: libnfnetlink handle
  * handler: callback function to be called for every netlink message
+ *          - the callback handler should normally return 0
+ *          - but may return a negative error code which will cause
+ *            nfnl_listen to return immediately with the same error code
+ *          - or return a postivie error code which will cause 
+ *            nfnl_listen to return after it has finished processing all
+ *            the netlink messages in the current packet
+ *          Thus a positive error code will terminate nfnl_listen "soon"
+ *          without any loss of data, a negative error code will terminate
+ *          nfnl_listen "very soon" and throw away data already read from
+ *          the netlink socket.
  * jarg: opaque argument passed on to callback
  *
  */
@@ -270,6 +280,7 @@
 	int remain;
 	struct nlmsghdr *h;
 	struct nlmsgerr *msgerr;
+	int quit=0;
 
 	struct msghdr msg = {
 		(void *)&nladdr, sizeof(nladdr),
@@ -283,7 +294,7 @@
 	iov.iov_base = buf;
 	iov.iov_len = sizeof(buf);
 
-	while (1) {
+	while (! quit) {
 		remain = recvmsg(nfnlh->fd, &msg, 0);
 		if (remain < 0) {
 			if (errno == EINTR)
@@ -332,6 +343,7 @@
 			err = handler(&nladdr, h, jarg);
 			if (err < 0)
 				return err;
+			quit |= err;
 		
 			/* FIXME: why not _NEXT macros, etc.? */
 			//h = NLMSG_NEXT(h, remain);
@@ -348,7 +360,7 @@
 		}
 	}
 
-	return 0;
+	return quit;
 }
 
 int nfnl_talk(struct nfnl_handle *nfnlh, struct nlmsghdr *n, pid_t peer,

  parent reply	other threads:[~2005-09-05 16:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-12 20:37 [PATCH 4/*] libnfnetlink fixes Pablo Neira
2005-07-13  8:23 ` Amin Azez
2005-08-28 11:50   ` Harald Welte
2005-09-02 16:12     ` Amin Azez
2005-09-10  9:09       ` Harald Welte
2005-09-12  8:03         ` Amin Azez
2005-09-13 13:17           ` Harald Welte
2005-09-05 16:31     ` Amin Azez [this message]
2005-07-18 21:25 ` Harald Welte

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=431C72CF.4060406@ufomechanic.net \
    --to=azez@ufomechanic.net \
    --cc=kaber@trash.net \
    --cc=laforge@netfilter.org \
    --cc=netfilter-devel@lists.netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.