struct nfqnl_handle;
struct nfqnl_q_handle;
+struct nfnl_q_data;
extern int nfqnl_errno;
extern int nfqnl_fd(struct nfqnl_handle *h);
typedef int nfqnl_callback(struct nfqnl_q_handle *gh, struct nfgenmsg *nfmsg,
- struct nfattr *nfa[], void *data);
+ struct nfnl_q_data *nfad, void *data);
extern struct nfqnl_handle *nfqnl_open(void);
/* message parsing function */
extern struct nfqnl_msg_packet_hdr *
- nfqnl_get_msg_packet_hdr(struct nfattr *nfa[]);
+ nfqnl_get_msg_packet_hdr(struct nfnl_q_data *nfad);
-extern u_int32_t nfqnl_get_nfmark(struct nfattr *nfa[]);
+extern u_int32_t nfqnl_get_nfmark(struct nfnl_q_data *nfad);
extern struct nfqnl_msg_packet_timestamp *
- nfqnl_get_timestamp(struct nfattr *nfa[]);
+ nfqnl_get_timestamp(struct nfnl_q_data *nfad);
/* return 0 if not set */
-extern u_int32_t nfqnl_get_indev(struct nfattr *nfa[]);
-extern u_int32_t nfqnl_get_physindev(struct nfattr *nfa[]);
-extern u_int32_t nfqnl_get_outdev(struct nfattr *nfa[]);
-extern u_int32_t nfqnl_get_physoutdev(struct nfattr *nfa[]);
+extern u_int32_t nfqnl_get_indev(struct nfnl_q_data *nfad);
+extern u_int32_t nfqnl_get_physindev(struct nfnl_q_data *nfad);
+extern u_int32_t nfqnl_get_outdev(struct nfnl_q_data *nfad);
+extern u_int32_t nfqnl_get_physoutdev(struct nfnl_q_data *nfad);
-extern struct nfqnl_msg_packet_hw *nfqnl_get_packet_hw(struct nfattr *nfa[]);
+extern struct nfqnl_msg_packet_hw *nfqnl_get_packet_hw(struct nfnl_q_data *nfad);
/* return 0 if problem */
-extern int nfqnl_get_payload(struct nfattr *nfa[],
+extern int nfqnl_get_payload(struct nfnl_q_data *nfad,
char ** data, unsigned int* datalen);
static int ipq_errno = IPQ_ERR_NONE;
-#if 0
-static ssize_t ipq_netlink_sendto(const struct ipq_handle *h,
- const void *msg, size_t len);
-
-static ssize_t ipq_netlink_recvfrom(const struct ipq_handle *h,
- unsigned char *buf, size_t len,
- int timeout);
-
-static ssize_t ipq_netlink_sendmsg(const struct ipq_handle *h,
- const struct msghdr *msg,
- unsigned int flags);
-
-static char *ipq_strerror(int errcode);
-
-static ssize_t ipq_netlink_sendto(const struct ipq_handle *h,
- const void *msg, size_t len)
-{
- int status = sendto(h->fd, msg, len, 0,
- (struct sockaddr *)&h->peer, sizeof(h->peer));
- if (status < 0)
- ipq_errno = IPQ_ERR_SEND;
- return status;
-}
-
-static ssize_t ipq_netlink_sendmsg(const struct ipq_handle *h,
- const struct msghdr *msg,
- unsigned int flags)
-{
- int status = sendmsg(h->fd, msg, flags);
- if (status < 0)
- ipq_errno = IPQ_ERR_SEND;
- return status;
-}
-
-static ssize_t ipq_netlink_recvfrom(const struct ipq_handle *h,
- unsigned char *buf, size_t len,
- int timeout)
-{
- unsigned int addrlen;
- int status;
- struct nlmsghdr *nlh;
-
- if (len < sizeof(struct nlmsgerr)) {
- ipq_errno = IPQ_ERR_RECVBUF;
- return -1;
- }
- addrlen = sizeof(h->peer);
-
- if (timeout != 0) {
- int ret;
- struct timeval tv;
- fd_set read_fds;
-
- if (timeout < 0) {
- /* non-block non-timeout */
- tv.tv_sec = 0;
- tv.tv_usec = 0;
- } else {
- tv.tv_sec = timeout / 1000000;
- tv.tv_usec = timeout % 1000000;
- }
-
- FD_ZERO(&read_fds);
- FD_SET(h->fd, &read_fds);
- ret = select(h->fd+1, &read_fds, NULL, NULL, &tv);
- if (ret < 0) {
- if (errno == EINTR) {
- return 0;
- } else {
- ipq_errno = IPQ_ERR_RECV;
- return -1;
- }
- }
- if (!FD_ISSET(h->fd, &read_fds)) {
- ipq_errno = IPQ_ERR_TIMEOUT;
- return 0;
- }
- }
- status = recvfrom(h->fd, buf, len, 0,
- (struct sockaddr *)&h->peer, &addrlen);
- if (status < 0) {
- ipq_errno = IPQ_ERR_RECV;
- return status;
- }
- if (addrlen != sizeof(h->peer)) {
- ipq_errno = IPQ_ERR_RECV;
- return -1;
- }
- if (h->peer.nl_pid != 0) {
- ipq_errno = IPQ_ERR_RECV;
- return -1;
- }
- if (status == 0) {
- ipq_errno = IPQ_ERR_NLEOF;
- return -1;
- }
- nlh = (struct nlmsghdr *)buf;
- if (nlh->nlmsg_flags & MSG_TRUNC || nlh->nlmsg_len > status) {
- ipq_errno = IPQ_ERR_RTRUNC;
- return -1;
- }
- return status;
-}
-#endif
-
static char *ipq_strerror(int errcode)
{
if (errcode < 0 || errcode > IPQ_MAXERR)
void *data;
};
+struct nfnl_q_data {
+ struct nfattr **data;
+};
int nfqnl_errno;
struct nfqnl_handle *h = data;
u_int16_t queue_num = ntohs(nfmsg->res_id);
struct nfqnl_q_handle *qh = find_qh(h, queue_num);
+ struct nfnl_q_data nfqa;
if (!qh)
return -ENODEV;
if (!qh->cb)
return -ENODEV;
- return qh->cb(qh, nfmsg, nfa, qh->data);
+ nfqa.data = nfa;
+
+ return qh->cb(qh, nfmsg, &nfqa, qh->data);
}
static struct nfnl_callback pkt_cb = {
* Message parsing functions
*************************************************************/
-struct nfqnl_msg_packet_hdr *nfqnl_get_msg_packet_hdr(struct nfattr *nfa[])
+struct nfqnl_msg_packet_hdr *nfqnl_get_msg_packet_hdr(struct nfnl_q_data *nfad)
{
- return nfnl_get_pointer_to_data(nfa, NFQA_PACKET_HDR,
+ return nfnl_get_pointer_to_data(nfad->data, NFQA_PACKET_HDR,
struct nfqnl_msg_packet_hdr);
}
-uint32_t nfqnl_get_nfmark(struct nfattr *nfa[])
+uint32_t nfqnl_get_nfmark(struct nfnl_q_data *nfad)
{
- return ntohl(nfnl_get_data(nfa, NFQA_MARK, u_int32_t));
+ return ntohl(nfnl_get_data(nfad->data, NFQA_MARK, u_int32_t));
}
-struct nfqnl_msg_packet_timestamp *nfqnl_get_timestamp(struct nfattr *nfa[])
+struct nfqnl_msg_packet_timestamp *nfqnl_get_timestamp(struct nfnl_q_data *nfad)
{
- return nfnl_get_pointer_to_data(nfa, NFQA_TIMESTAMP,
+ return nfnl_get_pointer_to_data(nfad->data, NFQA_TIMESTAMP,
struct nfqnl_msg_packet_timestamp);
}
/* all nfqnl_get_*dev() functions return 0 if not set, since linux only allows
* ifindex >= 1, see net/core/dev.c:2600 (in 2.6.13.1) */
-u_int32_t nfqnl_get_indev(struct nfattr *nfa[])
+u_int32_t nfqnl_get_indev(struct nfnl_q_data *nfad)
{
- return ntohl(nfnl_get_data(nfa, NFQA_IFINDEX_INDEV, u_int32_t));
+ return ntohl(nfnl_get_data(nfad->data, NFQA_IFINDEX_INDEV, u_int32_t));
}
-u_int32_t nfqnl_get_physindev(struct nfattr *nfa[])
+u_int32_t nfqnl_get_physindev(struct nfnl_q_data *nfad)
{
- return ntohl(nfnl_get_data(nfa, NFQA_IFINDEX_PHYSINDEV, u_int32_t));
+ return ntohl(nfnl_get_data(nfad->data, NFQA_IFINDEX_PHYSINDEV, u_int32_t));
}
-u_int32_t nfqnl_get_outdev(struct nfattr *nfa[])
+u_int32_t nfqnl_get_outdev(struct nfnl_q_data *nfad)
{
- return ntohl(nfnl_get_data(nfa, NFQA_IFINDEX_OUTDEV, u_int32_t));
+ return ntohl(nfnl_get_data(nfad->data, NFQA_IFINDEX_OUTDEV, u_int32_t));
}
-u_int32_t nfqnl_get_physoutdev(struct nfattr *nfa[])
+u_int32_t nfqnl_get_physoutdev(struct nfnl_q_data *nfad)
{
- return ntohl(nfnl_get_data(nfa, NFQA_IFINDEX_PHYSOUTDEV, u_int32_t));
+ return ntohl(nfnl_get_data(nfad->data, NFQA_IFINDEX_PHYSOUTDEV, u_int32_t));
}
-struct nfqnl_msg_packet_hw *nfqnl_get_packet_hw(struct nfattr *nfa[])
+struct nfqnl_msg_packet_hw *nfqnl_get_packet_hw(struct nfnl_q_data *nfad)
{
- return nfnl_get_pointer_to_data(nfa, NFQA_HWADDR,
+ return nfnl_get_pointer_to_data(nfad->data, NFQA_HWADDR,
struct nfqnl_msg_packet_hw);
}
-int nfqnl_get_payload(struct nfattr *nfa[], char **data,
+int nfqnl_get_payload(struct nfnl_q_data *nfad, char **data,
unsigned int *datalen)
{
- *data = nfnl_get_pointer_to_data(nfa, NFQA_PAYLOAD, char);
+ *data = nfnl_get_pointer_to_data(nfad->data, NFQA_PAYLOAD, char);
if (*data) {
- *datalen = NFA_PAYLOAD(nfa[NFQA_PAYLOAD-1]);
+ *datalen = NFA_PAYLOAD(nfad->data[NFQA_PAYLOAD-1]);
return 1;
}
return 0;
#include <libnetfilter_queue/libnetfilter_queue.h>
/* returns packet id */
-static u_int32_t print_pkt (struct nfattr *tb[])
+static u_int32_t print_pkt (struct nfnl_q_data *tb)
{
int id = 0;
struct nfqnl_msg_packet_hdr *ph;
static int cb(struct nfqnl_q_handle *qh, struct nfgenmsg *nfmsg,
- struct nfattr *nfa[], void *data)
+ struct nfnl_q_data *nfa, void *data)
{
u_int32_t id = print_pkt(nfa);
printf("entering callback\n");