abstract 'nfattr' in 'nfnl_q_data'
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>
Sat, 5 Nov 2005 09:41:38 +0000 (09:41 +0000)
committerr.kubiak <r.kubiak@samsung.com>
Mon, 16 Nov 2015 13:12:05 +0000 (14:12 +0100)
include/libnetfilter_queue/libnetfilter_queue.h
src/libipq_compat.c
src/libnetfilter_queue.c
utils/nfqnl_test.c

index 9c2b40d..5b5f965 100644 (file)
@@ -20,6 +20,7 @@
 
 struct nfqnl_handle;
 struct nfqnl_q_handle;
+struct nfnl_q_data;
 
 extern int nfqnl_errno;
 
@@ -27,7 +28,7 @@ extern struct nfnl_handle *nfqnl_nfnlh(struct nfqnl_handle *h);
 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);
@@ -63,23 +64,23 @@ extern int nfqnl_set_verdict_mark(struct nfqnl_q_handle *qh,
 /* 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);
 
 
index 86481ac..099609b 100644 (file)
@@ -82,111 +82,6 @@ struct ipq_errmap_t {
 
 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)
index 03a770a..972de7e 100644 (file)
@@ -45,6 +45,9 @@ struct nfqnl_q_handle
        void *data;
 };
 
+struct nfnl_q_data {
+       struct nfattr **data;
+};
 
 int nfqnl_errno;
 
@@ -112,6 +115,7 @@ static int __nfqnl_rcv_pkt(struct nlmsghdr *nlh, struct nfattr *nfa[],
        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;
@@ -119,7 +123,9 @@ static int __nfqnl_rcv_pkt(struct nlmsghdr *nlh, struct nfattr *nfa[],
        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 = {
@@ -318,57 +324,57 @@ int nfqnl_set_verdict_mark(struct nfqnl_q_handle *qh, u_int32_t id,
  * 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;
index 26de1c5..ccb5eff 100644 (file)
@@ -8,7 +8,7 @@
 #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;
@@ -47,7 +47,7 @@ static u_int32_t print_pkt (struct nfattr *tb[])
        
 
 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");