15#include "nl-default.h"
19#include <linux/netfilter/nfnetlink_log.h>
21#include <netlink/attr.h>
22#include <netlink/netfilter/nfnl.h>
23#include <netlink/netfilter/log.h>
25#include "nl-priv-dynamic-core/nl-core.h"
26#include "nl-priv-dynamic-core/cache-api.h"
33static int build_log_cmd_request(uint8_t family, uint16_t queuenum,
34 uint8_t command,
struct nl_msg **result)
37 struct nfulnl_msg_config_cmd cmd;
44 cmd.command = command;
45 if (
nla_put(msg, NFULA_CFG_CMD,
sizeof(cmd), &cmd) < 0)
56static int send_log_request(
struct nl_sock *sk,
struct nl_msg *msg)
65 return wait_for_ack(sk);
68int nfnl_log_build_pf_bind(uint8_t pf,
struct nl_msg **result)
70 return build_log_cmd_request(pf, 0, NFULNL_CFG_CMD_PF_BIND, result);
73int nfnl_log_pf_bind(
struct nl_sock *nlh, uint8_t pf)
78 if ((err = nfnl_log_build_pf_bind(pf, &msg)) < 0)
81 return send_log_request(nlh, msg);
84int nfnl_log_build_pf_unbind(uint8_t pf,
struct nl_msg **result)
86 return build_log_cmd_request(pf, 0, NFULNL_CFG_CMD_PF_UNBIND, result);
89int nfnl_log_pf_unbind(
struct nl_sock *nlh, uint8_t pf)
94 if ((err = nfnl_log_build_pf_unbind(pf, &msg)) < 0)
97 return send_log_request(nlh, msg);
100static int nfnl_log_build_request(
const struct nfnl_log *log,
101 struct nl_msg **result)
105 if (!nfnl_log_test_group(log))
106 return -NLE_MISSING_ATTR;
109 0, nfnl_log_get_group(log));
116 if (nfnl_log_test_copy_mode(log)) {
117 struct nfulnl_msg_config_mode mode;
119 switch (nfnl_log_get_copy_mode(log)) {
120 case NFNL_LOG_COPY_NONE:
121 mode.copy_mode = NFULNL_COPY_NONE;
123 case NFNL_LOG_COPY_META:
124 mode.copy_mode = NFULNL_COPY_META;
126 case NFNL_LOG_COPY_PACKET:
127 mode.copy_mode = NFULNL_COPY_PACKET;
130 mode.copy_range = htonl(nfnl_log_get_copy_range(log));
133 if (
nla_put(msg, NFULA_CFG_MODE,
sizeof(mode), &mode) < 0)
134 goto nla_put_failure;
137 if (nfnl_log_test_flush_timeout(log) &&
139 htonl(nfnl_log_get_flush_timeout(log))) < 0)
140 goto nla_put_failure;
142 if (nfnl_log_test_alloc_size(log) &&
144 htonl(nfnl_log_get_alloc_size(log))) < 0)
145 goto nla_put_failure;
147 if (nfnl_log_test_queue_threshold(log) &&
149 htonl(nfnl_log_get_queue_threshold(log))) < 0)
150 goto nla_put_failure;
152 if (nfnl_log_get_flags(log) &&
154 htons(nfnl_log_get_flags(log))) < 0)
155 goto nla_put_failure;
165int nfnl_log_build_create_request(
const struct nfnl_log *log,
166 struct nl_msg **result)
168 struct nfulnl_msg_config_cmd cmd;
171 if ((err = nfnl_log_build_request(log, result)) < 0)
174 cmd.command = NFULNL_CFG_CMD_BIND;
176 if (
nla_put(*result, NFULA_CFG_CMD,
sizeof(cmd), &cmd) < 0)
177 goto nla_put_failure;
186int nfnl_log_create(
struct nl_sock *nlh,
const struct nfnl_log *log)
191 if ((err = nfnl_log_build_create_request(log, &msg)) < 0)
194 return send_log_request(nlh, msg);
197int nfnl_log_build_change_request(
const struct nfnl_log *log,
198 struct nl_msg **result)
200 return nfnl_log_build_request(log, result);
203int nfnl_log_change(
struct nl_sock *nlh,
const struct nfnl_log *log)
208 if ((err = nfnl_log_build_change_request(log, &msg)) < 0)
211 return send_log_request(nlh, msg);
214int nfnl_log_build_delete_request(
const struct nfnl_log *log,
215 struct nl_msg **result)
217 if (!nfnl_log_test_group(log))
218 return -NLE_MISSING_ATTR;
220 return build_log_cmd_request(0, nfnl_log_get_group(log),
221 NFULNL_CFG_CMD_UNBIND, result);
224int nfnl_log_delete(
struct nl_sock *nlh,
const struct nfnl_log *log)
229 if ((err = nfnl_log_build_delete_request(log, &msg)) < 0)
232 return send_log_request(nlh, msg);
237static struct nl_cache_ops nfnl_log_ops = {
238 .co_name =
"netfilter/log",
239 .co_obj_ops = &log_obj_ops,
241 END_OF_MSGTYPES_LIST,
245static void _nl_init log_init(
void)
250static void _nl_exit log_exit(
void)
int nla_put_u16(struct nl_msg *msg, int attrtype, uint16_t value)
Add 16 bit integer attribute to netlink message.
int nla_put_u32(struct nl_msg *msg, int attrtype, uint32_t value)
Add 32 bit integer 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)