13#include "nl-default.h"
17#include <linux/netfilter/nfnetlink_queue.h>
19#include <netlink/attr.h>
20#include <netlink/netfilter/nfnl.h>
21#include <netlink/netfilter/queue.h>
23#include "nl-priv-dynamic-core/nl-core.h"
24#include "nl-priv-dynamic-core/cache-api.h"
26struct nl_sock *nfnl_queue_socket_alloc(
void)
36static int send_queue_request(
struct nl_sock *sk,
struct nl_msg *msg)
45 return wait_for_ack(sk);
53static int build_queue_cmd_request(uint8_t family, uint16_t queuenum,
54 uint8_t command,
struct nl_msg **result)
57 struct nfqnl_msg_config_cmd cmd;
64 cmd.pf = htons(family);
66 cmd.command = command;
67 if (
nla_put(msg, NFQA_CFG_CMD,
sizeof(cmd), &cmd) < 0)
78int nfnl_queue_build_pf_bind(uint8_t pf,
struct nl_msg **result)
80 return build_queue_cmd_request(pf, 0, NFQNL_CFG_CMD_PF_BIND, result);
83int nfnl_queue_pf_bind(
struct nl_sock *nlh, uint8_t pf)
88 if ((err = nfnl_queue_build_pf_bind(pf, &msg)) < 0)
91 return send_queue_request(nlh, msg);
94int nfnl_queue_build_pf_unbind(uint8_t pf,
struct nl_msg **result)
96 return build_queue_cmd_request(pf, 0, NFQNL_CFG_CMD_PF_UNBIND, result);
99int nfnl_queue_pf_unbind(
struct nl_sock *nlh, uint8_t pf)
104 if ((err = nfnl_queue_build_pf_unbind(pf, &msg)) < 0)
107 return send_queue_request(nlh, msg);
110static int nfnl_queue_build_request(
const struct nfnl_queue *queue,
111 struct nl_msg **result)
115 if (!nfnl_queue_test_group(queue))
116 return -NLE_MISSING_ATTR;
119 0, nfnl_queue_get_group(queue));
123 if (nfnl_queue_test_maxlen(queue) &&
125 htonl(nfnl_queue_get_maxlen(queue))) < 0)
126 goto nla_put_failure;
131 if (nfnl_queue_test_copy_mode(queue)) {
132 struct nfqnl_msg_config_params params;
134 switch (nfnl_queue_get_copy_mode(queue)) {
135 case NFNL_QUEUE_COPY_NONE:
136 params.copy_mode = NFQNL_COPY_NONE;
138 case NFNL_QUEUE_COPY_META:
139 params.copy_mode = NFQNL_COPY_META;
141 case NFNL_QUEUE_COPY_PACKET:
142 params.copy_mode = NFQNL_COPY_PACKET;
145 params.copy_range = htonl(nfnl_queue_get_copy_range(queue));
147 if (
nla_put(msg, NFQA_CFG_PARAMS,
sizeof(params), ¶ms) < 0)
148 goto nla_put_failure;
159int nfnl_queue_build_create_request(
const struct nfnl_queue *queue,
160 struct nl_msg **result)
162 struct nfqnl_msg_config_cmd cmd;
165 if ((err = nfnl_queue_build_request(queue, result)) < 0)
170 cmd.command = NFQNL_CFG_CMD_BIND;
172 NLA_PUT(*result, NFQA_CFG_CMD,
sizeof(cmd), &cmd);
181int nfnl_queue_create(
struct nl_sock *nlh,
const struct nfnl_queue *queue)
186 if ((err = nfnl_queue_build_create_request(queue, &msg)) < 0)
189 return send_queue_request(nlh, msg);
192int nfnl_queue_build_change_request(
const struct nfnl_queue *queue,
193 struct nl_msg **result)
195 return nfnl_queue_build_request(queue, result);
198int nfnl_queue_change(
struct nl_sock *nlh,
const struct nfnl_queue *queue)
203 if ((err = nfnl_queue_build_change_request(queue, &msg)) < 0)
206 return send_queue_request(nlh, msg);
209int nfnl_queue_build_delete_request(
const struct nfnl_queue *queue,
210 struct nl_msg **result)
212 if (!nfnl_queue_test_group(queue))
213 return -NLE_MISSING_ATTR;
215 return build_queue_cmd_request(0, nfnl_queue_get_group(queue),
216 NFQNL_CFG_CMD_UNBIND, result);
219int nfnl_queue_delete(
struct nl_sock *nlh,
const struct nfnl_queue *queue)
224 if ((err = nfnl_queue_build_delete_request(queue, &msg)) < 0)
227 return send_queue_request(nlh, msg);
232static struct nl_cache_ops nfnl_queue_ops = {
233 .co_name =
"netfilter/queue",
234 .co_obj_ops = &queue_obj_ops,
236 END_OF_MSGTYPES_LIST,
240static void _nl_init nfnl_queue_init(
void)
245static void _nl_exit nfnl_queue_exit(
void)
int nla_put_u32(struct nl_msg *msg, int attrtype, uint32_t value)
Add 32 bit integer attribute to netlink message.
#define NLA_PUT(msg, attrtype, attrlen, data)
Add unspecific attribute to netlink message.
int nla_put(struct nl_msg *msg, int attrtype, int datalen, const void *data)
Add a unspecific attribute to netlink message.
int nl_cache_mngt_unregister(struct nl_cache_ops *ops)
Unregister a set of cache operations.
int nl_cache_mngt_register(struct nl_cache_ops *ops)
Register a set of cache operations.
void nlmsg_free(struct nl_msg *msg)
Release a reference from an netlink message.
struct nl_msg * nfnlmsg_alloc_simple(uint8_t subsys_id, uint8_t type, int flags, uint8_t family, uint16_t res_id)
Allocate a new netfilter netlink message.
int nl_send_auto_complete(struct nl_sock *sk, struct nl_msg *msg)
void nl_socket_disable_auto_ack(struct nl_sock *sk)
Disable automatic request for ACK.
struct nl_sock * nl_socket_alloc(void)
Allocate new netlink socket.