From: Pablo Neira <pablo@eurodev.net>
To: Netfilter Development Mailinglist <netfilter-devel@lists.netfilter.org>
Cc: Harald Welte <laforge@netfilter.org>, Patrick McHardy <kaber@trash.net>
Subject: [PATCH 4/*] libnfnetlink fixes
Date: Tue, 12 Jul 2005 22:37:13 +0200 [thread overview]
Message-ID: <42D429F9.7000707@eurodev.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 369 bytes --]
This fixes:
a) Check for bad file descriptor, otherwise this can result in a
infinite loop during event display cancelation.
b) Return 0 on success. -100 is ugly and we this since we use explicit
ACK confirmation (NLM_F_ACK) since it's cleaner.
c) nfnl_nest and nfnl_nest_end to build up nested attributes.
d) NLMSG_TAIL introduced in recent rtnetlinkv2 changes.
[-- Attachment #2: 04libnfnetlink.patch --]
[-- Type: text/x-patch, Size: 2305 bytes --]
Index: libnfnetlink.c
===================================================================
--- libnfnetlink.c (revision 4067)
+++ libnfnetlink.c (working copy)
@@ -108,10 +108,11 @@
*/
int nfnl_close(struct nfnl_handle *nfnlh)
{
- if (nfnlh->fd)
- close(nfnlh->fd);
+ int err;
+
+ err = close(nfnlh->fd);
- return 0;
+ return err;
}
/**
@@ -202,6 +203,9 @@
if (remain < 0) {
if (errno == EINTR)
continue;
+ /* Bad file descriptor */
+ if (errno == EBADF)
+ break;
nfnl_error("recvmsg overrun");
continue;
}
@@ -231,7 +235,7 @@
/* end of messages reached, let's return */
if (h->nlmsg_type == NLMSG_DONE)
- return -100;
+ return 0;
/* Break the loop if success is explicitely
* reported via NLM_F_ACK flag set */
@@ -400,12 +404,11 @@
return -1;
}
- nfa = (struct nfattr *)(((char *)n) + NLMSG_ALIGN(n->nlmsg_len));
+ nfa = NLMSG_TAIL(n);
nfa->nfa_type = type;
nfa->nfa_len = len;
memcpy(NFA_DATA(nfa), data, alen);
- n->nlmsg_len = (NLMSG_ALIGN(n->nlmsg_len) + len);
-
+ n->nlmsg_len = (NLMSG_ALIGN(n->nlmsg_len) + NFA_ALIGN(len));
return 0;
}
@@ -482,7 +485,7 @@
{
while (NFA_OK(nfa, len)) {
if (nfa->nfa_type <= max)
- tb[nfa->nfa_type] = nfa;
+ tb[nfa->nfa_type-1] = nfa;
nfa = NFA_NEXT(nfa,len);
}
if (len)
Index: libnfnetlink.h
===================================================================
--- libnfnetlink.h (revision 4067)
+++ libnfnetlink.h (working copy)
@@ -10,6 +10,9 @@
#include <linux/netlink.h>
#include <linux/netfilter/nfnetlink.h>
+#define NLMSG_TAIL(nlh) \
+ ((void *) (nlh)) + NLMSG_ALIGN((nlh)->nlmsg_len)
+
#define NFNL_BUFFSIZE 8192
struct nfnl_handle {
@@ -45,6 +48,12 @@
extern int nfnl_nfa_addattr_l(struct nfattr *, int, int, void *, int);
extern int nfnl_nfa_addattr32(struct nfattr *, int, int, u_int32_t);
extern int nfnl_parse_attr(struct nfattr **, int, struct nfattr *, int);
+#define nfnl_nest(nlh, bufsize, type) \
+({ struct nfattr *__start = NLMSG_TAIL(nlh); \
+ nfnl_addattr_l(nlh, bufsize, type, NULL, 0); \
+ __start; })
+#define nfnl_nest_end(nlh, tail) \
+({ (tail)->nfa_len = (void *) NLMSG_TAIL(nlh) - (void *) tail; })
extern void nfnl_dump_packet(struct nlmsghdr *, int, char *);
#endif /* __LIBNFNETLINK_H */
next reply other threads:[~2005-07-12 20:37 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-07-12 20:37 Pablo Neira [this message]
2005-07-13 8:23 ` [PATCH 4/*] libnfnetlink fixes 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
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=42D429F9.7000707@eurodev.net \
--to=pablo@eurodev.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.