15 #include <libmnl/libmnl.h> 17 #ifndef __aligned_be64 18 #define __aligned_be64 __be64 __attribute__((aligned(8))) 19 #define __aligned_le64 __le64 __attribute__((aligned(8))) 22 #include <linux/netfilter/nfnetlink_queue.h> 24 #include <libnetfilter_queue/libnetfilter_queue.h> 74 struct nfqnl_msg_verdict_hdr vh = {
75 .verdict = htonl(verdict),
78 mnl_attr_put(nlh, NFQA_VERDICT_HDR,
sizeof(vh), &vh);
93 mnl_attr_put_u32(nlh, NFQA_MARK, htonl(mark));
133 mnl_attr_put(nlh, NFQA_PAYLOAD, plen, pkt);
168 struct nfqnl_msg_config_cmd command = {
172 mnl_attr_put(nlh, NFQA_CFG_CMD,
sizeof(command), &command);
184 struct nfqnl_msg_config_params params = {
185 .copy_range = htonl(range),
188 mnl_attr_put(nlh, NFQA_CFG_PARAMS,
sizeof(params), ¶ms);
199 mnl_attr_put_u32(nlh, NFQA_CFG_QUEUE_MAXLEN, htonl(queue_maxlen));
211 static int nfq_pkt_parse_attr_cb(
const struct nlattr *attr,
void *data)
213 const struct nlattr **tb = data;
214 int type = mnl_attr_get_type(attr);
217 if (mnl_attr_type_valid(attr, NFQA_MAX) < 0)
222 case NFQA_IFINDEX_INDEV:
223 case NFQA_IFINDEX_OUTDEV:
224 case NFQA_IFINDEX_PHYSINDEV:
225 case NFQA_IFINDEX_PHYSOUTDEV:
232 if (mnl_attr_validate(attr, MNL_TYPE_U32) < 0)
236 if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC,
237 sizeof(
struct nfqnl_msg_packet_timestamp)) < 0) {
242 if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC,
243 sizeof(
struct nfqnl_msg_packet_hw)) < 0) {
247 case NFQA_PACKET_HDR:
248 if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC,
249 sizeof(
struct nfqnl_msg_packet_hdr)) < 0) {
271 return mnl_attr_parse(nlh,
sizeof(
struct nfgenmsg),
272 nfq_pkt_parse_attr_cb, attr);
285 struct nlmsghdr *nlh = mnl_nlmsg_put_header(buf);
286 nlh->nlmsg_type = (NFNL_SUBSYS_QUEUE << 8) | type;
287 nlh->nlmsg_flags = NLM_F_REQUEST;
289 struct nfgenmsg *nfg = mnl_nlmsg_put_extra_header(nlh,
sizeof(*nfg));
290 nfg->nfgen_family = AF_UNSPEC;
291 nfg->version = NFNETLINK_V0;
292 nfg->res_id = htons(queue_num);
void nfq_nlmsg_cfg_put_cmd(struct nlmsghdr *nlh, uint16_t pf, uint8_t cmd)
void nfq_nlmsg_verdict_put(struct nlmsghdr *nlh, int id, int verdict)
struct nlmsghdr * nfq_nlmsg_put(char *buf, int type, uint32_t queue_num)
int nfq_nlmsg_parse(const struct nlmsghdr *nlh, struct nlattr **attr)
void nfq_nlmsg_cfg_put_params(struct nlmsghdr *nlh, uint8_t mode, int range)
void nfq_nlmsg_cfg_put_qmaxlen(struct nlmsghdr *nlh, uint32_t queue_maxlen)
void nfq_nlmsg_verdict_put_mark(struct nlmsghdr *nlh, uint32_t mark)
void nfq_nlmsg_verdict_put_pkt(struct nlmsghdr *nlh, const void *pkt, uint32_t plen)