1 /* libnfqnetlink.h: Header file for the Netfilter Queue library.
3 * (C) 2005 by Harald Welte <laforge@gnumonks.org>
7 * (2005/08/11) added parsing function (Eric Leblond <regit@inl.fr>)
9 * This software may be used and distributed according to the terms
10 * of the GNU General Public License, incorporated herein by reference.
13 #ifndef __LIBCTNETLINK_H
14 #define __LIBCTNETLINK_H
17 #include <libnfnetlink/libnfnetlink.h>
19 #include <libnetfilter_queue/linux_nfnetlink_queue.h>
31 extern struct nfnl_handle *nfq_nfnlh(struct nfq_handle *h);
32 extern int nfq_fd(struct nfq_handle *h);
34 typedef int nfq_callback(struct nfq_q_handle *gh, struct nfgenmsg *nfmsg,
35 struct nfq_data *nfad, void *data);
38 extern struct nfq_handle *nfq_open(void);
39 extern struct nfq_handle *nfq_open_nfnl(struct nfnl_handle *nfnlh);
40 extern int nfq_close(struct nfq_handle *h);
42 extern int nfq_bind_pf(struct nfq_handle *h, uint16_t pf);
43 extern int nfq_unbind_pf(struct nfq_handle *h, uint16_t pf);
45 extern struct nfq_q_handle *nfq_create_queue(struct nfq_handle *h,
49 extern int nfq_destroy_queue(struct nfq_q_handle *qh);
51 extern int nfq_handle_packet(struct nfq_handle *h, char *buf, int len);
53 extern int nfq_set_mode(struct nfq_q_handle *qh,
54 uint8_t mode, unsigned int len);
56 int nfq_set_queue_maxlen(struct nfq_q_handle *qh,
59 extern int nfq_set_queue_flags(struct nfq_q_handle *qh,
60 uint32_t mask, uint32_t flags);
62 extern int nfq_set_verdict(struct nfq_q_handle *qh,
66 const unsigned char *buf);
68 extern int nfq_set_verdict2(struct nfq_q_handle *qh,
73 const unsigned char *buf);
75 extern int nfq_set_verdict_batch(struct nfq_q_handle *qh,
79 extern int nfq_set_verdict_batch2(struct nfq_q_handle *qh,
84 extern __attribute__((deprecated))
85 int nfq_set_verdict_mark(struct nfq_q_handle *qh,
90 const unsigned char *buf);
92 /* message parsing function */
94 extern struct nfqnl_msg_packet_hdr *
95 nfq_get_msg_packet_hdr(struct nfq_data *nfad);
97 extern uint32_t nfq_get_nfmark(struct nfq_data *nfad);
99 extern int nfq_get_timestamp(struct nfq_data *nfad, struct timeval *tv);
101 /* return 0 if not set */
102 extern uint32_t nfq_get_indev(struct nfq_data *nfad);
103 extern uint32_t nfq_get_physindev(struct nfq_data *nfad);
104 extern uint32_t nfq_get_outdev(struct nfq_data *nfad);
105 extern uint32_t nfq_get_physoutdev(struct nfq_data *nfad);
106 extern int nfq_get_uid(struct nfq_data *nfad, uint32_t *uid);
107 extern int nfq_get_gid(struct nfq_data *nfad, uint32_t *gid);
108 extern int nfq_get_secctx(struct nfq_data *nfad, unsigned char **secdata);
110 extern int nfq_get_indev_name(struct nlif_handle *nlif_handle,
111 struct nfq_data *nfad, char *name);
112 extern int nfq_get_physindev_name(struct nlif_handle *nlif_handle,
113 struct nfq_data *nfad, char *name);
114 extern int nfq_get_outdev_name(struct nlif_handle *nlif_handle,
115 struct nfq_data *nfad, char *name);
116 extern int nfq_get_physoutdev_name(struct nlif_handle *nlif_handle,
117 struct nfq_data *nfad, char *name);
119 extern struct nfqnl_msg_packet_hw *nfq_get_packet_hw(struct nfq_data *nfad);
121 /* return -1 if problem, length otherwise */
122 extern int nfq_get_payload(struct nfq_data *nfad, unsigned char **data);
125 NFQ_XML_HW = (1 << 0),
126 NFQ_XML_MARK = (1 << 1),
127 NFQ_XML_DEV = (1 << 2),
128 NFQ_XML_PHYSDEV = (1 << 3),
129 NFQ_XML_PAYLOAD = (1 << 4),
130 NFQ_XML_TIME = (1 << 5),
131 NFQ_XML_UID = (1 << 6),
132 NFQ_XML_GID = (1 << 7),
133 NFQ_XML_SECCTX = (1 << 8),
137 extern int nfq_snprintf_xml(char *buf, size_t len, struct nfq_data *tb, int flags);
140 * New API based on libmnl
143 void nfq_nlmsg_cfg_put_cmd(struct nlmsghdr *nlh, uint16_t pf, uint8_t cmd);
144 void nfq_nlmsg_cfg_put_params(struct nlmsghdr *nlh, uint8_t mode, int range);
145 void nfq_nlmsg_cfg_put_qmaxlen(struct nlmsghdr *nlh, uint32_t qmaxlen);
147 void nfq_nlmsg_verdict_put(struct nlmsghdr *nlh, int id, int verdict);
148 void nfq_nlmsg_verdict_put_mark(struct nlmsghdr *nlh, uint32_t mark);
149 void nfq_nlmsg_verdict_put_pkt(struct nlmsghdr *nlh, const void *pkt, uint32_t pktlen);
151 int nfq_nlmsg_parse(const struct nlmsghdr *nlh, struct nlattr **pkt);
157 #endif /* __LIBNFQNETLINK_H */