summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author/C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=laforge/emailAddress=laforge@netfilter.org </C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=laforge/emailAddress=laforge@netfilter.org>2005-10-19 11:53:43 +0000
committer/C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=laforge/emailAddress=laforge@netfilter.org </C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=laforge/emailAddress=laforge@netfilter.org>2005-10-19 11:53:43 +0000
commit9afc0b6deead5a0192b1c7b5c9eff7949af56c59 (patch)
tree5bba01c1783e571fdb83b87a869300eece243383
parentf6c7bd5ef9bb00816aeeb86b121398d40d2647ef (diff)
- define structure nfnlhdr in libnfnetlink.h
- fix a problem with the attributes types. We have to use NFA_TYPE instead of reading from nfa->nfa_type now that your patch to see the highest bit of nfa_type has been pushed forward. - Implement __be_to_cpu64. I haven't found any implementation available at the moment. (Pablo Neira)
-rw-r--r--include/libnfnetlink/libnfnetlink.h32
-rw-r--r--src/libnfnetlink.c5
2 files changed, 36 insertions, 1 deletions
diff --git a/include/libnfnetlink/libnfnetlink.h b/include/libnfnetlink/libnfnetlink.h
index c41dad7..7a63d2f 100644
--- a/include/libnfnetlink/libnfnetlink.h
+++ b/include/libnfnetlink/libnfnetlink.h
@@ -23,6 +23,11 @@
#define NFNL_BUFFSIZE 8192
+struct nfnlhdr {
+ struct nlmsghdr nlh;
+ struct nfgenmsg nfmsg;
+};
+
struct nfnl_callback {
int (*call)(struct nlmsghdr *nlh, struct nfattr *nfa[], void *data);
void *data;
@@ -113,7 +118,7 @@ extern int nfnl_parse_attr(struct nfattr **, int, struct nfattr *, int);
nfnl_parse_attr((tb), (max), NFA_DATA((nfa)), NFA_PAYLOAD((nfa)))
#define nfnl_nest(nlh, bufsize, type) \
({ struct nfattr *__start = NLMSG_TAIL(nlh); \
- nfnl_addattr_l(nlh, bufsize, type, NULL, 0); \
+ nfnl_addattr_l(nlh, bufsize, (NFNL_NFA_NEST | type), NULL, 0); \
__start; })
#define nfnl_nest_end(nlh, tail) \
({ (tail)->nfa_len = (void *) NLMSG_TAIL(nlh) - (void *) tail; })
@@ -125,4 +130,29 @@ extern unsigned int nfnl_rcvbufsiz(struct nfnl_handle *h, unsigned int size);
extern void nfnl_dump_packet(struct nlmsghdr *, int, char *);
+
+/* Pablo: What is the equivalence of be64_to_cpu in userspace?
+ *
+ * Harald: Good question. I don't think there's a standard way [yet?],
+ * so I'd suggest manually implementing it by "#if little endian" bitshift
+ * operations in C (at least for now).
+ *
+ * All the payload of any nfattr will always be in network byte order.
+ * This would allow easy transport over a real network in the future
+ * (e.g. jamal's netlink2).
+ *
+ * Pablo: I've called it __be64_to_cpu instead of be64_to_cpu, since maybe
+ * there will one in the userspace headers someday. We don't want to
+ * pollute POSIX space naming,
+ */
+
+#include <byteswap.h>
+#if __BYTE_ORDER == __BIG_ENDIAN
+# define __be64_to_cpu(x) (x)
+# else
+# if __BYTE_ORDER == __LITTLE_ENDIAN
+# define __be64_to_cpu(x) __bswap_64(x)
+# endif
+#endif
+
#endif /* __LIBNFNETLINK_H */
diff --git a/src/libnfnetlink.c b/src/libnfnetlink.c
index 53f0bcc..2ddbc35 100644
--- a/src/libnfnetlink.c
+++ b/src/libnfnetlink.c
@@ -7,6 +7,11 @@
*
* this software may be used and distributed according to the terms
* of the gnu general public license, incorporated herein by reference.
+ *
+ * 2005-09-14 Pablo Neira Ayuso <pablo@netfilter.org>:
+ * Define structure nfnlhdr
+ * Added __be64_to_cpu function
+ * Use NFA_TYPE macro to get the attribute type
*/
#include <stdlib.h>