From: Amin Azez <azez@ufomechanic.net>
To: netfilter-devel@lists.netfilter.org
Cc: Harald Welte <laforge@netfilter.org>, Patrick McHardy <kaber@trash.net>
Subject: Re: [PATCH 4/*] libnfnetlink fixes
Date: Wed, 13 Jul 2005 09:23:56 +0100 [thread overview]
Message-ID: <42D4CF9C.2000304@ufomechanic.net> (raw)
In-Reply-To: <42D429F9.7000707@eurodev.net>
[-- Attachment #1: Type: text/plain, Size: 793 bytes --]
Here is a patch I propose for libnfnetlink.c
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 use it to break out of the loop when a signal handler sets a flag,
once the loop has broken I then do some per-signal processing and
re-enter the loop.
Sam
[-- Attachment #2: libnfnetlink.c.diff --]
[-- Type: text/x-patch, Size: 924 bytes --]
Index: /opt/KERNEL/SVN/libnfnetlink/libnfnetlink.c
===================================================================
--- /opt/KERNEL/SVN/libnfnetlink/libnfnetlink.c (revision 3897)
+++ /opt/KERNEL/SVN/libnfnetlink/libnfnetlink.c (working copy)
@@ -184,6 +193,7 @@
int remain;
struct nlmsghdr *h;
struct nlmsgerr *msgerr;
+ int quit=0;
struct msghdr msg = {
(void *)&nladdr, sizeof(nladdr),
@@ -197,7 +207,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)
@@ -243,6 +253,7 @@
err = handler(&nladdr, h, jarg);
if (err < 0)
return err;
+ quit |= err;
/* FIXME: why not _NEXT macros, etc.? */
//h = NLMSG_NEXT(h, remain);
@@ -259,7 +270,7 @@
}
}
- return 0;
+ return quit;
}
int nfnl_talk(struct nfnl_handle *nfnlh, struct nlmsghdr *n, pid_t peer,
next prev parent reply other threads:[~2005-07-13 8:23 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 [this message]
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
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=42D4CF9C.2000304@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.