9#include <netlink-private/netlink.h>
10#include <netlink/netfilter/nfnl.h>
11#include <netlink/netfilter/log.h>
14#define LOG_ATTR_GROUP (1UL << 0)
15#define LOG_ATTR_COPY_MODE (1UL << 1)
16#define LOG_ATTR_COPY_RANGE (1UL << 3)
17#define LOG_ATTR_FLUSH_TIMEOUT (1UL << 4)
18#define LOG_ATTR_ALLOC_SIZE (1UL << 5)
19#define LOG_ATTR_QUEUE_THRESHOLD (1UL << 6)
23static void nfnl_log_dump(
struct nl_object *a,
struct nl_dump_params *p)
25 struct nfnl_log *log = (
struct nfnl_log *) a;
30 if (log->ce_mask & LOG_ATTR_GROUP)
31 nl_dump(p,
"group=%u ", log->log_group);
33 if (log->ce_mask & LOG_ATTR_COPY_MODE)
35 nfnl_log_copy_mode2str(log->log_copy_mode,
38 if (log->ce_mask & LOG_ATTR_COPY_RANGE)
39 nl_dump(p,
"copy_range=%u ", log->log_copy_range);
41 if (log->ce_mask & LOG_ATTR_FLUSH_TIMEOUT)
42 nl_dump(p,
"flush_timeout=%u ", log->log_flush_timeout);
44 if (log->ce_mask & LOG_ATTR_ALLOC_SIZE)
45 nl_dump(p,
"alloc_size=%u ", log->log_alloc_size);
47 if (log->ce_mask & LOG_ATTR_QUEUE_THRESHOLD)
48 nl_dump(p,
"queue_threshold=%u ", log->log_queue_threshold);
53static const struct trans_tbl copy_modes[] = {
54 __ADD(NFNL_LOG_COPY_NONE, none),
55 __ADD(NFNL_LOG_COPY_META, meta),
56 __ADD(NFNL_LOG_COPY_PACKET, packet),
59char *nfnl_log_copy_mode2str(
enum nfnl_log_copy_mode copy_mode,
char *buf,
62 return __type2str(copy_mode, buf, len, copy_modes,
63 ARRAY_SIZE(copy_modes));
66int nfnl_log_str2copy_mode(
const char *name)
68 return __str2type(name, copy_modes, ARRAY_SIZE(copy_modes));
76struct nfnl_log *nfnl_log_alloc(
void)
81void nfnl_log_get(
struct nfnl_log *log)
86void nfnl_log_put(
struct nfnl_log *log)
98void nfnl_log_set_group(
struct nfnl_log *log, uint16_t group)
100 log->log_group = group;
101 log->ce_mask |= LOG_ATTR_GROUP;
104int nfnl_log_test_group(
const struct nfnl_log *log)
106 return !!(log->ce_mask & LOG_ATTR_GROUP);
109uint16_t nfnl_log_get_group(
const struct nfnl_log *log)
111 return log->log_group;
114void nfnl_log_set_copy_mode(
struct nfnl_log *log,
enum nfnl_log_copy_mode mode)
116 log->log_copy_mode = mode;
117 log->ce_mask |= LOG_ATTR_COPY_MODE;
120int nfnl_log_test_copy_mode(
const struct nfnl_log *log)
122 return !!(log->ce_mask & LOG_ATTR_COPY_MODE);
125enum nfnl_log_copy_mode nfnl_log_get_copy_mode(
const struct nfnl_log *log)
127 return log->log_copy_mode;
130void nfnl_log_set_copy_range(
struct nfnl_log *log, uint32_t copy_range)
132 log->log_copy_range = copy_range;
133 log->ce_mask |= LOG_ATTR_COPY_RANGE;
136int nfnl_log_test_copy_range(
const struct nfnl_log *log)
138 return !!(log->ce_mask & LOG_ATTR_COPY_RANGE);
141uint32_t nfnl_log_get_copy_range(
const struct nfnl_log *log)
143 return log->log_copy_range;
146void nfnl_log_set_flush_timeout(
struct nfnl_log *log, uint32_t timeout)
148 log->log_flush_timeout = timeout;
149 log->ce_mask |= LOG_ATTR_FLUSH_TIMEOUT;
152int nfnl_log_test_flush_timeout(
const struct nfnl_log *log)
154 return !!(log->ce_mask & LOG_ATTR_FLUSH_TIMEOUT);
157uint32_t nfnl_log_get_flush_timeout(
const struct nfnl_log *log)
159 return log->log_flush_timeout;
162void nfnl_log_set_alloc_size(
struct nfnl_log *log, uint32_t alloc_size)
164 log->log_alloc_size = alloc_size;
165 log->ce_mask |= LOG_ATTR_ALLOC_SIZE;
168int nfnl_log_test_alloc_size(
const struct nfnl_log *log)
170 return !!(log->ce_mask & LOG_ATTR_ALLOC_SIZE);
173uint32_t nfnl_log_get_alloc_size(
const struct nfnl_log *log)
175 return log->log_alloc_size;
178void nfnl_log_set_queue_threshold(
struct nfnl_log *log, uint32_t threshold)
180 log->log_queue_threshold = threshold;
181 log->ce_mask |= LOG_ATTR_QUEUE_THRESHOLD;
184int nfnl_log_test_queue_threshold(
const struct nfnl_log *log)
186 return !!(log->ce_mask & LOG_ATTR_QUEUE_THRESHOLD);
189uint32_t nfnl_log_get_queue_threshold(
const struct nfnl_log *log)
191 return log->log_queue_threshold;
199void nfnl_log_set_flags(
struct nfnl_log *log,
unsigned int flags)
201 log->log_flags |= flags;
202 log->log_flag_mask |= flags;
205void nfnl_log_unset_flags(
struct nfnl_log *log,
unsigned int flags)
207 log->log_flags &= ~flags;
208 log->log_flag_mask |= flags;
211unsigned int nfnl_log_get_flags(
const struct nfnl_log *log)
213 return log->log_flags;
216static const struct trans_tbl log_flags[] = {
217 __ADD(NFNL_LOG_FLAG_SEQ, seq),
218 __ADD(NFNL_LOG_FLAG_SEQ_GLOBAL, seq_global),
219 __ADD(NFNL_LOG_FLAG_CONNTRACK, conntrack),
222char *nfnl_log_flags2str(
unsigned int flags,
char *buf,
size_t len)
224 return __flags2str(flags, buf, len, log_flags, ARRAY_SIZE(log_flags));
227unsigned int nfnl_log_str2flags(
const char *name)
229 return __str2flags(name, log_flags, ARRAY_SIZE(log_flags));
232static uint64_t nfnl_log_compare(
struct nl_object *_a,
struct nl_object *_b,
233 uint64_t attrs,
int flags)
235 struct nfnl_log *a = (
struct nfnl_log *) _a;
236 struct nfnl_log *b = (
struct nfnl_log *) _b;
239#define NFNL_LOG_DIFF(ATTR, EXPR) \
240 ATTR_DIFF(attrs, LOG_ATTR_##ATTR, a, b, EXPR)
241#define NFNL_LOG_DIFF_VAL(ATTR, FIELD) \
242 NFNL_LOG_DIFF(ATTR, a->FIELD != b->FIELD)
244 diff |= NFNL_LOG_DIFF_VAL(GROUP, log_group);
245 diff |= NFNL_LOG_DIFF_VAL(COPY_MODE, log_copy_mode);
246 diff |= NFNL_LOG_DIFF_VAL(COPY_RANGE, log_copy_range);
247 diff |= NFNL_LOG_DIFF_VAL(FLUSH_TIMEOUT, log_flush_timeout);
248 diff |= NFNL_LOG_DIFF_VAL(ALLOC_SIZE, log_alloc_size);
249 diff |= NFNL_LOG_DIFF_VAL(QUEUE_THRESHOLD, log_queue_threshold);
252#undef NFNL_LOG_DIFF_VAL
257static const struct trans_tbl nfnl_log_attrs[] = {
258 __ADD(LOG_ATTR_GROUP, group),
259 __ADD(LOG_ATTR_COPY_MODE, copy_mode),
260 __ADD(LOG_ATTR_COPY_RANGE, copy_range),
261 __ADD(LOG_ATTR_FLUSH_TIMEOUT, flush_timeout),
262 __ADD(LOG_ATTR_ALLOC_SIZE, alloc_size),
263 __ADD(LOG_ATTR_QUEUE_THRESHOLD, queue_threshold),
266static char *nfnl_log_attrs2str(
int attrs,
char *buf,
size_t len)
268 return __flags2str(attrs, buf, len, nfnl_log_attrs,
269 ARRAY_SIZE(nfnl_log_attrs));
274struct nl_object_ops log_obj_ops = {
275 .oo_name =
"netfilter/log",
276 .oo_size =
sizeof(
struct nfnl_log),
282 .oo_compare = nfnl_log_compare,
283 .oo_attrs2str = nfnl_log_attrs2str,
284 .oo_id_attrs = LOG_ATTR_GROUP,
void nl_object_put(struct nl_object *obj)
Release a reference from an object.
void nl_object_get(struct nl_object *obj)
Acquire a reference on a object.
struct nl_object * nl_object_alloc(struct nl_object_ops *ops)
Allocate a new object of kind specified by the operations handle.
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
void nl_new_line(struct nl_dump_params *params)
Handle a new line while dumping.
@ NL_DUMP_STATS
Dump all attributes including statistics.
@ NL_DUMP_LINE
Dump object briefly on one line.
@ NL_DUMP_DETAILS
Dump all attributes but no statistics.