11#include <netlink/netfilter/nfnl.h>
12#include <netlink/netfilter/log.h>
14#include "nl-priv-dynamic-core/object-api.h"
15#include "nl-priv-dynamic-core/cache-api.h"
16#include "nl-priv-dynamic-core/nl-core.h"
23 uint8_t log_copy_mode;
24 uint32_t log_copy_range;
25 uint32_t log_flush_timeout;
26 uint32_t log_alloc_size;
27 uint32_t log_queue_threshold;
29 uint32_t log_flag_mask;
32#define LOG_ATTR_GROUP (1UL << 0)
33#define LOG_ATTR_COPY_MODE (1UL << 1)
34#define LOG_ATTR_COPY_RANGE (1UL << 3)
35#define LOG_ATTR_FLUSH_TIMEOUT (1UL << 4)
36#define LOG_ATTR_ALLOC_SIZE (1UL << 5)
37#define LOG_ATTR_QUEUE_THRESHOLD (1UL << 6)
41static void nfnl_log_dump(
struct nl_object *a,
struct nl_dump_params *p)
43 struct nfnl_log *log = (
struct nfnl_log *) a;
48 if (log->ce_mask & LOG_ATTR_GROUP)
49 nl_dump(p,
"group=%u ", log->log_group);
51 if (log->ce_mask & LOG_ATTR_COPY_MODE)
53 nfnl_log_copy_mode2str(log->log_copy_mode,
56 if (log->ce_mask & LOG_ATTR_COPY_RANGE)
57 nl_dump(p,
"copy_range=%u ", log->log_copy_range);
59 if (log->ce_mask & LOG_ATTR_FLUSH_TIMEOUT)
60 nl_dump(p,
"flush_timeout=%u ", log->log_flush_timeout);
62 if (log->ce_mask & LOG_ATTR_ALLOC_SIZE)
63 nl_dump(p,
"alloc_size=%u ", log->log_alloc_size);
65 if (log->ce_mask & LOG_ATTR_QUEUE_THRESHOLD)
66 nl_dump(p,
"queue_threshold=%u ", log->log_queue_threshold);
71static const struct trans_tbl copy_modes[] = {
72 __ADD(NFNL_LOG_COPY_NONE, none),
73 __ADD(NFNL_LOG_COPY_META, meta),
74 __ADD(NFNL_LOG_COPY_PACKET, packet),
77char *nfnl_log_copy_mode2str(
enum nfnl_log_copy_mode copy_mode,
char *buf,
80 return __type2str(copy_mode, buf, len, copy_modes,
81 ARRAY_SIZE(copy_modes));
84int nfnl_log_str2copy_mode(
const char *name)
86 return __str2type(name, copy_modes, ARRAY_SIZE(copy_modes));
94struct nfnl_log *nfnl_log_alloc(
void)
99void nfnl_log_get(
struct nfnl_log *log)
104void nfnl_log_put(
struct nfnl_log *log)
116void nfnl_log_set_group(
struct nfnl_log *log, uint16_t group)
118 log->log_group = group;
119 log->ce_mask |= LOG_ATTR_GROUP;
122int nfnl_log_test_group(
const struct nfnl_log *log)
124 return !!(log->ce_mask & LOG_ATTR_GROUP);
127uint16_t nfnl_log_get_group(
const struct nfnl_log *log)
129 return log->log_group;
132void nfnl_log_set_copy_mode(
struct nfnl_log *log,
enum nfnl_log_copy_mode mode)
134 log->log_copy_mode = mode;
135 log->ce_mask |= LOG_ATTR_COPY_MODE;
138int nfnl_log_test_copy_mode(
const struct nfnl_log *log)
140 return !!(log->ce_mask & LOG_ATTR_COPY_MODE);
143enum nfnl_log_copy_mode nfnl_log_get_copy_mode(
const struct nfnl_log *log)
145 return log->log_copy_mode;
148void nfnl_log_set_copy_range(
struct nfnl_log *log, uint32_t copy_range)
150 log->log_copy_range = copy_range;
151 log->ce_mask |= LOG_ATTR_COPY_RANGE;
154int nfnl_log_test_copy_range(
const struct nfnl_log *log)
156 return !!(log->ce_mask & LOG_ATTR_COPY_RANGE);
159uint32_t nfnl_log_get_copy_range(
const struct nfnl_log *log)
161 return log->log_copy_range;
164void nfnl_log_set_flush_timeout(
struct nfnl_log *log, uint32_t timeout)
166 log->log_flush_timeout = timeout;
167 log->ce_mask |= LOG_ATTR_FLUSH_TIMEOUT;
170int nfnl_log_test_flush_timeout(
const struct nfnl_log *log)
172 return !!(log->ce_mask & LOG_ATTR_FLUSH_TIMEOUT);
175uint32_t nfnl_log_get_flush_timeout(
const struct nfnl_log *log)
177 return log->log_flush_timeout;
180void nfnl_log_set_alloc_size(
struct nfnl_log *log, uint32_t alloc_size)
182 log->log_alloc_size = alloc_size;
183 log->ce_mask |= LOG_ATTR_ALLOC_SIZE;
186int nfnl_log_test_alloc_size(
const struct nfnl_log *log)
188 return !!(log->ce_mask & LOG_ATTR_ALLOC_SIZE);
191uint32_t nfnl_log_get_alloc_size(
const struct nfnl_log *log)
193 return log->log_alloc_size;
196void nfnl_log_set_queue_threshold(
struct nfnl_log *log, uint32_t threshold)
198 log->log_queue_threshold = threshold;
199 log->ce_mask |= LOG_ATTR_QUEUE_THRESHOLD;
202int nfnl_log_test_queue_threshold(
const struct nfnl_log *log)
204 return !!(log->ce_mask & LOG_ATTR_QUEUE_THRESHOLD);
207uint32_t nfnl_log_get_queue_threshold(
const struct nfnl_log *log)
209 return log->log_queue_threshold;
217void nfnl_log_set_flags(
struct nfnl_log *log,
unsigned int flags)
219 log->log_flags |= flags;
220 log->log_flag_mask |= flags;
223void nfnl_log_unset_flags(
struct nfnl_log *log,
unsigned int flags)
225 log->log_flags &= ~flags;
226 log->log_flag_mask |= flags;
229unsigned int nfnl_log_get_flags(
const struct nfnl_log *log)
231 return log->log_flags;
234static const struct trans_tbl log_flags[] = {
235 __ADD(NFNL_LOG_FLAG_SEQ, seq),
236 __ADD(NFNL_LOG_FLAG_SEQ_GLOBAL, seq_global),
237 __ADD(NFNL_LOG_FLAG_CONNTRACK, conntrack),
240char *nfnl_log_flags2str(
unsigned int flags,
char *buf,
size_t len)
242 return __flags2str(flags, buf, len, log_flags, ARRAY_SIZE(log_flags));
245unsigned int nfnl_log_str2flags(
const char *name)
247 return __str2flags(name, log_flags, ARRAY_SIZE(log_flags));
250static uint64_t nfnl_log_compare(
struct nl_object *_a,
struct nl_object *_b,
251 uint64_t attrs,
int flags)
253 struct nfnl_log *a = (
struct nfnl_log *) _a;
254 struct nfnl_log *b = (
struct nfnl_log *) _b;
257#define NFNL_LOG_DIFF(ATTR, EXPR) \
258 ATTR_DIFF(attrs, ATTR, a, b, EXPR)
259#define NFNL_LOG_DIFF_VAL(ATTR, FIELD) \
260 NFNL_LOG_DIFF(ATTR, a->FIELD != b->FIELD)
261 diff |= NFNL_LOG_DIFF_VAL(LOG_ATTR_GROUP, log_group);
262 diff |= NFNL_LOG_DIFF_VAL(LOG_ATTR_COPY_MODE, log_copy_mode);
263 diff |= NFNL_LOG_DIFF_VAL(LOG_ATTR_COPY_RANGE, log_copy_range);
264 diff |= NFNL_LOG_DIFF_VAL(LOG_ATTR_FLUSH_TIMEOUT, log_flush_timeout);
265 diff |= NFNL_LOG_DIFF_VAL(LOG_ATTR_ALLOC_SIZE, log_alloc_size);
266 diff |= NFNL_LOG_DIFF_VAL(LOG_ATTR_QUEUE_THRESHOLD, log_queue_threshold);
268#undef NFNL_LOG_DIFF_VAL
273static const struct trans_tbl nfnl_log_attrs[] = {
274 __ADD(LOG_ATTR_GROUP, group),
275 __ADD(LOG_ATTR_COPY_MODE, copy_mode),
276 __ADD(LOG_ATTR_COPY_RANGE, copy_range),
277 __ADD(LOG_ATTR_FLUSH_TIMEOUT, flush_timeout),
278 __ADD(LOG_ATTR_ALLOC_SIZE, alloc_size),
279 __ADD(LOG_ATTR_QUEUE_THRESHOLD, queue_threshold),
282static char *nfnl_log_attrs2str(
int attrs,
char *buf,
size_t len)
284 return __flags2str(attrs, buf, len, nfnl_log_attrs,
285 ARRAY_SIZE(nfnl_log_attrs));
290struct nl_object_ops log_obj_ops = {
291 .oo_name =
"netfilter/log",
292 .oo_size =
sizeof(
struct nfnl_log),
298 .oo_compare = nfnl_log_compare,
299 .oo_attrs2str = nfnl_log_attrs2str,
300 .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.