16 #include <netlink-private/netlink.h> 17 #include <netlink/netfilter/nfnl.h> 18 #include <netlink/netfilter/log.h> 21 #define LOG_ATTR_GROUP (1UL << 0) 22 #define LOG_ATTR_COPY_MODE (1UL << 1) 23 #define LOG_ATTR_COPY_RANGE (1UL << 3) 24 #define LOG_ATTR_FLUSH_TIMEOUT (1UL << 4) 25 #define LOG_ATTR_ALLOC_SIZE (1UL << 5) 26 #define LOG_ATTR_QUEUE_THRESHOLD (1UL << 6) 30 static void nfnl_log_dump(
struct nl_object *a,
struct nl_dump_params *p)
32 struct nfnl_log *log = (
struct nfnl_log *) a;
37 if (log->ce_mask & LOG_ATTR_GROUP)
38 nl_dump(p,
"group=%u ", log->log_group);
40 if (log->ce_mask & LOG_ATTR_COPY_MODE)
42 nfnl_log_copy_mode2str(log->log_copy_mode,
45 if (log->ce_mask & LOG_ATTR_COPY_RANGE)
46 nl_dump(p,
"copy_range=%u ", log->log_copy_range);
48 if (log->ce_mask & LOG_ATTR_FLUSH_TIMEOUT)
49 nl_dump(p,
"flush_timeout=%u ", log->log_flush_timeout);
51 if (log->ce_mask & LOG_ATTR_ALLOC_SIZE)
52 nl_dump(p,
"alloc_size=%u ", log->log_alloc_size);
54 if (log->ce_mask & LOG_ATTR_QUEUE_THRESHOLD)
55 nl_dump(p,
"queue_threshold=%u ", log->log_queue_threshold);
60 static const struct trans_tbl copy_modes[] = {
61 __ADD(NFNL_LOG_COPY_NONE, none),
62 __ADD(NFNL_LOG_COPY_META, meta),
63 __ADD(NFNL_LOG_COPY_PACKET, packet),
66 char *nfnl_log_copy_mode2str(
enum nfnl_log_copy_mode copy_mode,
char *buf,
69 return __type2str(copy_mode, buf, len, copy_modes,
70 ARRAY_SIZE(copy_modes));
73 int nfnl_log_str2copy_mode(
const char *name)
75 return __str2type(name, copy_modes, ARRAY_SIZE(copy_modes));
83 struct nfnl_log *nfnl_log_alloc(
void)
88 void nfnl_log_get(
struct nfnl_log *log)
93 void nfnl_log_put(
struct nfnl_log *log)
105 void nfnl_log_set_group(
struct nfnl_log *log, uint16_t group)
107 log->log_group = group;
108 log->ce_mask |= LOG_ATTR_GROUP;
111 int nfnl_log_test_group(
const struct nfnl_log *log)
113 return !!(log->ce_mask & LOG_ATTR_GROUP);
116 uint16_t nfnl_log_get_group(
const struct nfnl_log *log)
118 return log->log_group;
121 void nfnl_log_set_copy_mode(
struct nfnl_log *log,
enum nfnl_log_copy_mode mode)
123 log->log_copy_mode = mode;
124 log->ce_mask |= LOG_ATTR_COPY_MODE;
127 int nfnl_log_test_copy_mode(
const struct nfnl_log *log)
129 return !!(log->ce_mask & LOG_ATTR_COPY_MODE);
132 enum nfnl_log_copy_mode nfnl_log_get_copy_mode(
const struct nfnl_log *log)
134 return log->log_copy_mode;
137 void nfnl_log_set_copy_range(
struct nfnl_log *log, uint32_t copy_range)
139 log->log_copy_range = copy_range;
140 log->ce_mask |= LOG_ATTR_COPY_RANGE;
143 int nfnl_log_test_copy_range(
const struct nfnl_log *log)
145 return !!(log->ce_mask & LOG_ATTR_COPY_RANGE);
148 uint32_t nfnl_log_get_copy_range(
const struct nfnl_log *log)
150 return log->log_copy_range;
153 void nfnl_log_set_flush_timeout(
struct nfnl_log *log, uint32_t timeout)
155 log->log_flush_timeout = timeout;
156 log->ce_mask |= LOG_ATTR_FLUSH_TIMEOUT;
159 int nfnl_log_test_flush_timeout(
const struct nfnl_log *log)
161 return !!(log->ce_mask & LOG_ATTR_FLUSH_TIMEOUT);
164 uint32_t nfnl_log_get_flush_timeout(
const struct nfnl_log *log)
166 return log->log_flush_timeout;
169 void nfnl_log_set_alloc_size(
struct nfnl_log *log, uint32_t alloc_size)
171 log->log_alloc_size = alloc_size;
172 log->ce_mask |= LOG_ATTR_ALLOC_SIZE;
175 int nfnl_log_test_alloc_size(
const struct nfnl_log *log)
177 return !!(log->ce_mask & LOG_ATTR_ALLOC_SIZE);
180 uint32_t nfnl_log_get_alloc_size(
const struct nfnl_log *log)
182 return log->log_alloc_size;
185 void nfnl_log_set_queue_threshold(
struct nfnl_log *log, uint32_t threshold)
187 log->log_queue_threshold = threshold;
188 log->ce_mask |= LOG_ATTR_QUEUE_THRESHOLD;
191 int nfnl_log_test_queue_threshold(
const struct nfnl_log *log)
193 return !!(log->ce_mask & LOG_ATTR_QUEUE_THRESHOLD);
196 uint32_t nfnl_log_get_queue_threshold(
const struct nfnl_log *log)
198 return log->log_queue_threshold;
206 void nfnl_log_set_flags(
struct nfnl_log *log,
unsigned int flags)
208 log->log_flags |= flags;
209 log->log_flag_mask |= flags;
212 void nfnl_log_unset_flags(
struct nfnl_log *log,
unsigned int flags)
214 log->log_flags &= ~flags;
215 log->log_flag_mask |= flags;
218 static const struct trans_tbl log_flags[] = {
219 __ADD(NFNL_LOG_FLAG_SEQ, seq),
220 __ADD(NFNL_LOG_FLAG_SEQ_GLOBAL, seq_global),
223 char *nfnl_log_flags2str(
unsigned int flags,
char *buf,
size_t len)
225 return __flags2str(flags, buf, len, log_flags, ARRAY_SIZE(log_flags));
228 unsigned int nfnl_log_str2flags(
const char *name)
230 return __str2flags(name, log_flags, ARRAY_SIZE(log_flags));
233 static uint64_t nfnl_log_compare(
struct nl_object *_a,
struct nl_object *_b,
234 uint64_t attrs,
int flags)
236 struct nfnl_log *a = (
struct nfnl_log *) _a;
237 struct nfnl_log *b = (
struct nfnl_log *) _b;
240 #define NFNL_LOG_DIFF(ATTR, EXPR) \ 241 ATTR_DIFF(attrs, LOG_ATTR_##ATTR, a, b, EXPR) 242 #define NFNL_LOG_DIFF_VAL(ATTR, FIELD) \ 243 NFNL_LOG_DIFF(ATTR, a->FIELD != b->FIELD) 245 diff |= NFNL_LOG_DIFF_VAL(GROUP, log_group);
246 diff |= NFNL_LOG_DIFF_VAL(COPY_MODE, log_copy_mode);
247 diff |= NFNL_LOG_DIFF_VAL(COPY_RANGE, log_copy_range);
248 diff |= NFNL_LOG_DIFF_VAL(FLUSH_TIMEOUT, log_flush_timeout);
249 diff |= NFNL_LOG_DIFF_VAL(ALLOC_SIZE, log_alloc_size);
250 diff |= NFNL_LOG_DIFF_VAL(QUEUE_THRESHOLD, log_queue_threshold);
253 #undef NFNL_LOG_DIFF_VAL 258 static const struct trans_tbl nfnl_log_attrs[] = {
259 __ADD(LOG_ATTR_GROUP, group),
260 __ADD(LOG_ATTR_COPY_MODE, copy_mode),
261 __ADD(LOG_ATTR_COPY_RANGE, copy_range),
262 __ADD(LOG_ATTR_FLUSH_TIMEOUT, flush_timeout),
263 __ADD(LOG_ATTR_ALLOC_SIZE, alloc_size),
264 __ADD(LOG_ATTR_QUEUE_THRESHOLD, queue_threshold),
267 static char *nfnl_log_attrs2str(
int attrs,
char *buf,
size_t len)
269 return __flags2str(attrs, buf, len, nfnl_log_attrs,
270 ARRAY_SIZE(nfnl_log_attrs));
275 struct nl_object_ops log_obj_ops = {
276 .oo_name =
"netfilter/log",
277 .oo_size =
sizeof(
struct nfnl_log),
283 .oo_compare = nfnl_log_compare,
284 .oo_attrs2str = nfnl_log_attrs2str,
285 .oo_id_attrs = LOG_ATTR_GROUP,
Dump object briefly on one line.
void nl_new_line(struct nl_dump_params *params)
Handle a new line while dumping.
struct nl_object * nl_object_alloc(struct nl_object_ops *ops)
Allocate a new object of kind specified by the operations handle.
void nl_object_get(struct nl_object *obj)
Acquire a reference on a object.
Dump all attributes but no statistics.
void nl_object_put(struct nl_object *obj)
Release a reference from an object.
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
Dump all attributes including statistics.