libnfnetlink-0.0.39-3

This commit is contained in:
Paul P Komkoff Jr 2008-11-16 13:12:55 +00:00
parent 5757f9dd3f
commit 7907007cd7
4 changed files with 110 additions and 270 deletions

View File

@ -1,156 +0,0 @@
diff --git a/configure.in b/configure.in
index fbcbd61..6a71da3 100644
--- a/configure.in
+++ b/configure.in
@@ -4,7 +4,7 @@ AC_INIT
AC_CANONICAL_SYSTEM
-AM_INIT_AUTOMAKE(libnfnetlink, 0.0.30)
+AM_INIT_AUTOMAKE(libnfnetlink, 0.0.33)
AC_PROG_CC
AC_EXEEXT
diff --git a/include/libnfnetlink/libnfnetlink.h b/include/libnfnetlink/libnfnetlink.h
index de77caa..37fa663 100644
--- a/include/libnfnetlink/libnfnetlink.h
+++ b/include/libnfnetlink/libnfnetlink.h
@@ -56,6 +56,9 @@ extern struct nfnl_subsys_handle *nfnl_subsys_open(struct nfnl_handle *,
unsigned int);
extern void nfnl_subsys_close(struct nfnl_subsys_handle *);
+/* set receive buffer size (for nfnl_catch) */
+extern void nfnl_set_rcv_buffer_size(struct nfnl_handle *h, unsigned int size);
+
/* sending of data */
extern int nfnl_send(struct nfnl_handle *, struct nlmsghdr *);
extern int nfnl_sendmsg(const struct nfnl_handle *, const struct msghdr *msg,
@@ -170,7 +173,8 @@ extern int nfnl_parse_attr(struct nfattr **, int, struct nfattr *, int);
extern void nfnl_build_nfa_iovec(struct iovec *iov, struct nfattr *nfa,
u_int16_t type, u_int32_t len,
unsigned char *val);
-extern unsigned int nfnl_rcvbufsiz(struct nfnl_handle *h, unsigned int size);
+extern unsigned int nfnl_rcvbufsiz(const struct nfnl_handle *h,
+ unsigned int size);
extern void nfnl_dump_packet(struct nlmsghdr *, int, char *);
diff --git a/src/libnfnetlink.c b/src/libnfnetlink.c
index 6cbc43e..6b91631 100644
--- a/src/libnfnetlink.c
+++ b/src/libnfnetlink.c
@@ -85,6 +85,7 @@ struct nfnl_handle {
u_int32_t subscriptions;
u_int32_t seq;
u_int32_t dump;
+ u_int32_t rcv_buffer_size; /* for nfnl_catch */
struct nlmsghdr *last_nlhdr;
struct nfnl_subsys_handle subsys[NFNL_MAX_SUBSYS+1];
};
@@ -184,6 +185,7 @@ struct nfnl_handle *nfnl_open(void)
goto err_close;
}
nfnlh->seq = time(NULL);
+ nfnlh->rcv_buffer_size = NFNL_BUFFSIZE;
/* don't set pid here, only first socket of process has real pid !!!
* binding to pid '0' will default */
@@ -211,6 +213,19 @@ err_free:
}
/**
+ * nfnl_set_rcv_buffer_size - set the size of the receive buffer
+ * @h: libnfnetlink handler
+ * @size: buffer size
+ *
+ * This function sets the size of the receive buffer size, i.e. the size
+ * of the buffer used by nfnl_recv. Default value is 4096 bytes.
+ */
+void nfnl_set_rcv_buffer_size(struct nfnl_handle *h, unsigned int size)
+{
+ h->rcv_buffer_size = size;
+}
+
+/**
* nfnl_subsys_open - open a netlink subsystem
* @nfnlh: libnfnetlink handle
* @subsys_id: which nfnetlink subsystem we are interested in
@@ -943,7 +958,7 @@ void nfnl_build_nfa_iovec(struct iovec *iov, struct nfattr *nfa,
*
* This function returns the new size of the socket buffer.
*/
-unsigned int nfnl_rcvbufsiz(struct nfnl_handle *h, unsigned int size)
+unsigned int nfnl_rcvbufsiz(const struct nfnl_handle *h, unsigned int size)
{
int status;
socklen_t socklen = sizeof(size);
@@ -1129,6 +1144,7 @@ int nfnl_check_attributes(const struct nfnl_handle *h,
* the kernel which we don't understand
* yet. We have to silently ignore this
* for the sake of future compatibility */
+ attr = NFA_NEXT(attr, attrlen);
continue;
}
nfa[flavor - 1] = attr;
@@ -1190,6 +1206,7 @@ int nfnl_handle_packet(struct nfnl_handle *h, char *buf, int len)
return -1;
len -= rlen;
+ buf += rlen;
}
return 0;
}
@@ -1453,52 +1470,11 @@ int nfnl_iterator_next(const struct nfnl_handle *h, struct nfnl_iterator *it)
int nfnl_catch(struct nfnl_handle *h)
{
int ret;
- unsigned int size = NFNL_BUFFSIZE;
assert(h);
- /*
- * Since nfqueue can send big packets, we don't know how big
- * must be the buffer that have to store the received data.
- */
- {
- unsigned char buf[size];
- struct sockaddr_nl peer;
- struct iovec iov = {
- .iov_len = size,
- };
- struct msghdr msg = {
- .msg_name = (void *) &peer,
- .msg_namelen = sizeof(peer),
- .msg_iov = &iov,
- .msg_iovlen = 1,
- .msg_control = NULL,
- .msg_controllen = 0,
- .msg_flags = 0
- };
-
- memset(&peer, 0, sizeof(peer));
- peer.nl_family = AF_NETLINK;
- iov.iov_base = buf;
- iov.iov_len = size;
-
-retry: ret = recvmsg(h->fd, &msg, MSG_PEEK);
- if (ret == -1) {
- /* interrupted syscall must retry */
- if (errno == EINTR)
- goto retry;
- /* otherwise give up */
- return -1;
- }
-
- if (msg.msg_flags & MSG_TRUNC)
- /* maximum size of data received from netlink */
- size = 65535;
- }
-
- /* now, receive data from netlink */
while (1) {
- unsigned char buf[size];
+ unsigned char buf[h->rcv_buffer_size];
ret = nfnl_recv(h, buf, sizeof(buf));
if (ret == -1) {

View File

@ -1,14 +1,14 @@
diff --git a/include/libnfnetlink/Makefile.am b/include/libnfnetlink/Makefile.am
index 81e14c8..ad946f0 100644
index 76128c8..ecd451a 100644
--- a/include/libnfnetlink/Makefile.am
+++ b/include/libnfnetlink/Makefile.am
@@ -1,3 +1,3 @@
@@ -1,3 +1,2 @@
-pkginclude_HEADERS = libnfnetlink.h linux_nfnetlink.h
-pkginclude_HEADERS = libnfnetlink.h linux_nfnetlink.h linux_nfnetlink_compat.h
-
+pkginclude_HEADERS = libnfnetlink.h
diff --git a/include/libnfnetlink/libnfnetlink.h b/include/libnfnetlink/libnfnetlink.h
index 37fa663..d8b9516 100644
index 83874e3..2c29ba9 100644
--- a/include/libnfnetlink/libnfnetlink.h
+++ b/include/libnfnetlink/libnfnetlink.h
@@ -17,7 +17,7 @@
@ -22,23 +22,14 @@ index 37fa663..d8b9516 100644
#define NETLINK_NETFILTER 12
diff --git a/include/libnfnetlink/linux_nfnetlink.h b/include/libnfnetlink/linux_nfnetlink.h
deleted file mode 100644
index 0f9311d..0000000
index 76a8550..0000000
--- a/include/libnfnetlink/linux_nfnetlink.h
+++ /dev/null
@@ -1,163 +0,0 @@
@@ -1,85 +0,0 @@
-#ifndef _NFNETLINK_H
-#define _NFNETLINK_H
-#include <linux/types.h>
-
-#ifndef __KERNEL__
-/* nfnetlink groups: Up to 32 maximum - backwards compatibility for userspace */
-#define NF_NETLINK_CONNTRACK_NEW 0x00000001
-#define NF_NETLINK_CONNTRACK_UPDATE 0x00000002
-#define NF_NETLINK_CONNTRACK_DESTROY 0x00000004
-#define NF_NETLINK_CONNTRACK_EXP_NEW 0x00000008
-#define NF_NETLINK_CONNTRACK_EXP_UPDATE 0x00000010
-#define NF_NETLINK_CONNTRACK_EXP_DESTROY 0x00000020
-#endif
-#include <libnfnetlink/linux_nfnetlink_compat.h>
-
-enum nfnetlink_groups {
- NFNLGRP_NONE,
@ -59,6 +50,86 @@ index 0f9311d..0000000
-};
-#define NFNLGRP_MAX (__NFNLGRP_MAX - 1)
-
-/* General form of address family dependent message.
- */
-struct nfgenmsg {
- u_int8_t nfgen_family; /* AF_xxx */
- u_int8_t version; /* nfnetlink version */
- u_int16_t res_id; /* resource id */
-};
-
-#define NFNETLINK_V0 0
-
-/* netfilter netlink message types are split in two pieces:
- * 8 bit subsystem, 8bit operation.
- */
-
-#define NFNL_SUBSYS_ID(x) ((x & 0xff00) >> 8)
-#define NFNL_MSG_TYPE(x) (x & 0x00ff)
-
-/* No enum here, otherwise __stringify() trick of MODULE_ALIAS_NFNL_SUBSYS()
- * won't work anymore */
-#define NFNL_SUBSYS_NONE 0
-#define NFNL_SUBSYS_CTNETLINK 1
-#define NFNL_SUBSYS_CTNETLINK_EXP 2
-#define NFNL_SUBSYS_QUEUE 3
-#define NFNL_SUBSYS_ULOG 4
-#define NFNL_SUBSYS_COUNT 5
-
-#ifdef __KERNEL__
-
-#include <linux/netlink.h>
-#include <linux/capability.h>
-#include <net/netlink.h>
-
-struct nfnl_callback
-{
- int (*call)(struct sock *nl, struct sk_buff *skb,
- struct nlmsghdr *nlh, struct nlattr *cda[]);
- const struct nla_policy *policy; /* netlink attribute policy */
- const u_int16_t attr_count; /* number of nlattr's */
-};
-
-struct nfnetlink_subsystem
-{
- const char *name;
- __u8 subsys_id; /* nfnetlink subsystem ID */
- __u8 cb_count; /* number of callbacks */
- const struct nfnl_callback *cb; /* callback for individual types */
-};
-
-extern int nfnetlink_subsys_register(const struct nfnetlink_subsystem *n);
-extern int nfnetlink_subsys_unregister(const struct nfnetlink_subsystem *n);
-
-extern int nfnetlink_has_listeners(unsigned int group);
-extern int nfnetlink_send(struct sk_buff *skb, u32 pid, unsigned group,
- int echo);
-extern int nfnetlink_unicast(struct sk_buff *skb, u_int32_t pid, int flags);
-
-#define MODULE_ALIAS_NFNL_SUBSYS(subsys) \
- MODULE_ALIAS("nfnetlink-subsys-" __stringify(subsys))
-
-#endif /* __KERNEL__ */
-#endif /* _NFNETLINK_H */
diff --git a/include/libnfnetlink/linux_nfnetlink_compat.h b/include/libnfnetlink/linux_nfnetlink_compat.h
deleted file mode 100644
index e145176..0000000
--- a/include/libnfnetlink/linux_nfnetlink_compat.h
+++ /dev/null
@@ -1,61 +0,0 @@
-#ifndef _NFNETLINK_COMPAT_H
-#define _NFNETLINK_COMPAT_H
-#ifndef __KERNEL__
-/* Old nfnetlink macros for userspace */
-
-/* nfnetlink groups: Up to 32 maximum */
-#define NF_NETLINK_CONNTRACK_NEW 0x00000001
-#define NF_NETLINK_CONNTRACK_UPDATE 0x00000002
-#define NF_NETLINK_CONNTRACK_DESTROY 0x00000004
-#define NF_NETLINK_CONNTRACK_EXP_NEW 0x00000008
-#define NF_NETLINK_CONNTRACK_EXP_UPDATE 0x00000010
-#define NF_NETLINK_CONNTRACK_EXP_DESTROY 0x00000020
-
-/* Generic structure for encapsulation optional netfilter information.
- * It is reminiscent of sockaddr, but with sa_family replaced
- * with attribute type.
@ -101,91 +172,9 @@ index 0f9311d..0000000
- skb_trim(skb, (unsigned char *) (start) - (skb)->data); \
- -1; })
-
-/* General form of address family dependent message.
- */
-struct nfgenmsg {
- u_int8_t nfgen_family; /* AF_xxx */
- u_int8_t version; /* nfnetlink version */
- __be16 res_id; /* resource id */
-};
-
-#define NFNETLINK_V0 0
-
-#define NFM_NFA(n) ((struct nfattr *)(((char *)(n)) \
- + NLMSG_ALIGN(sizeof(struct nfgenmsg))))
-#define NFM_PAYLOAD(n) NLMSG_PAYLOAD(n, sizeof(struct nfgenmsg))
-
-/* netfilter netlink message types are split in two pieces:
- * 8 bit subsystem, 8bit operation.
- */
-
-#define NFNL_SUBSYS_ID(x) ((x & 0xff00) >> 8)
-#define NFNL_MSG_TYPE(x) (x & 0x00ff)
-
-/* No enum here, otherwise __stringify() trick of MODULE_ALIAS_NFNL_SUBSYS()
- * won't work anymore */
-#define NFNL_SUBSYS_NONE 0
-#define NFNL_SUBSYS_CTNETLINK 1
-#define NFNL_SUBSYS_CTNETLINK_EXP 2
-#define NFNL_SUBSYS_QUEUE 3
-#define NFNL_SUBSYS_ULOG 4
-#define NFNL_SUBSYS_COUNT 5
-
-#ifdef __KERNEL__
-
-#include <linux/netlink.h>
-#include <linux/capability.h>
-
-struct nfnl_callback
-{
- int (*call)(struct sock *nl, struct sk_buff *skb,
- struct nlmsghdr *nlh, struct nfattr *cda[]);
- u_int16_t attr_count; /* number of nfattr's */
-};
-
-struct nfnetlink_subsystem
-{
- const char *name;
- __u8 subsys_id; /* nfnetlink subsystem ID */
- __u8 cb_count; /* number of callbacks */
- struct nfnl_callback *cb; /* callback for individual types */
-};
-
-extern void __nfa_fill(struct sk_buff *skb, int attrtype,
- int attrlen, const void *data);
-#define NFA_PUT(skb, attrtype, attrlen, data) \
-({ if (skb_tailroom(skb) < (int)NFA_SPACE(attrlen)) goto nfattr_failure; \
- __nfa_fill(skb, attrtype, attrlen, data); })
-
-extern int nfnetlink_subsys_register(struct nfnetlink_subsystem *n);
-extern int nfnetlink_subsys_unregister(struct nfnetlink_subsystem *n);
-
-extern void nfattr_parse(struct nfattr *tb[], int maxattr,
- struct nfattr *nfa, int len);
-
-#define nfattr_parse_nested(tb, max, nfa) \
- nfattr_parse((tb), (max), NFA_DATA((nfa)), NFA_PAYLOAD((nfa)))
-
-#define nfattr_bad_size(tb, max, cta_min) \
-({ int __i, __res = 0; \
- for (__i=0; __i<max; __i++) { \
- if (!cta_min[__i]) \
- continue; \
- if (tb[__i] && NFA_PAYLOAD(tb[__i]) < cta_min[__i]){ \
- __res = 1; \
- break; \
- } \
- } \
- __res; \
-})
-
-extern int nfnetlink_has_listeners(unsigned int group);
-extern int nfnetlink_send(struct sk_buff *skb, u32 pid, unsigned group,
- int echo);
-extern int nfnetlink_unicast(struct sk_buff *skb, u_int32_t pid, int flags);
-
-#define MODULE_ALIAS_NFNL_SUBSYS(subsys) \
- MODULE_ALIAS("nfnetlink-subsys-" __stringify(subsys))
-
-#endif /* __KERNEL__ */
-#endif /* _NFNETLINK_H */
-#endif /* ! __KERNEL__ */
-#endif /* _NFNETLINK_COMPAT_H */

View File

@ -1,17 +1,16 @@
%define rev 7211
%define basever 0.0.30
# %define rev 7211
# %define basever 0.0.30
Name: libnfnetlink
Version: 0.0.33
Release: 0.1.svn%{rev}%{?dist}
Version: 0.0.39
Release: 3%{?dist}
Summary: Netfilter netlink userspace library
Group: System Environment/Libraries
License: GPL
License: GPLv2
URL: http://netfilter.org
Source0: http://netfilter.org/projects/libnfnetlink/files/%{name}-%{basever}.tar.bz2
Source0: http://netfilter.org/projects/libnfnetlink/files/%{name}-%{version}.tar.bz2
Source1: http://www.gnu.org/licenses/gpl.txt
Patch0: libnfnetlink-%{version}-svn%{rev}.patch
Patch1: libnfnetlink-sysheader.patch
Patch0: libnfnetlink-sysheader.patch
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
BuildRequires: kernel-headers
BuildRequires: automake autoconf libtool
@ -35,10 +34,9 @@ subsystem specific libraries such as libnfnetlink_conntrack, libnfnetlink_log
and libnfnetlink_queue.
%prep
%setup -q -n %{name}-%{basever}
%setup -q
cp %{SOURCE1} LICENSE
%patch -p1
%patch1 -p1
%patch0 -p1
autoreconf -i --force
@ -71,6 +69,15 @@ rm -rf $RPM_BUILD_ROOT
%{_includedir}/libnfnetlink/*.h
%changelog
* Sun Sep 21 2008 Ville Skyttä <ville.skytta at iki.fi> - 0.0.39-3
- Fix Patch0:/%%patch mismatch.
* Thu Aug 7 2008 Tom "spot" Callaway <tcallawa@redhat.com> - 0.0.39-2
- fix license tag
* Fri Jul 4 2008 Paul P. Komkoff Jr <i@stingr.net> - 0.0.39
- grab latest upstream release
* Fri Feb 22 2008 Paul P. Komkoff Jr <i@stingr.net> - 0.0.33-0.1.svn7211
- grab latest upstream changes and fixes, along with new version number
- do not mess with bundled nfnetlink.h, use <linux/netfilter/nfnetlink.h>

View File

@ -1 +1 @@
7fd3c8ddc03d42fa9f0177a17a38f163 libnfnetlink-0.0.30.tar.bz2
348fed8c1edbe5b873ffc7b192140093 libnfnetlink-0.0.39.tar.bz2