15 #include <netlink-private/netlink.h> 16 #include <netlink/netfilter/nfnl.h> 17 #include <netlink/netfilter/log.h> 20 #define LOG_ATTR_GROUP (1UL << 0) 21 #define LOG_ATTR_COPY_MODE (1UL << 1) 22 #define LOG_ATTR_COPY_RANGE (1UL << 3) 23 #define LOG_ATTR_FLUSH_TIMEOUT (1UL << 4) 24 #define LOG_ATTR_ALLOC_SIZE (1UL << 5) 25 #define LOG_ATTR_QUEUE_THRESHOLD (1UL << 6) 29 static void nfnl_log_dump(
struct nl_object *a,
struct nl_dump_params *p)
31 struct nfnl_log *log = (
struct nfnl_log *) a;
36 if (log->ce_mask & LOG_ATTR_GROUP)
37 nl_dump(p,
"group=%u ", log->log_group);
39 if (log->ce_mask & LOG_ATTR_COPY_MODE)
41 nfnl_log_copy_mode2str(log->log_copy_mode,
44 if (log->ce_mask & LOG_ATTR_COPY_RANGE)
45 nl_dump(p,
"copy_range=%u ", log->log_copy_range);
47 if (log->ce_mask & LOG_ATTR_FLUSH_TIMEOUT)
48 nl_dump(p,
"flush_timeout=%u ", log->log_flush_timeout);
50 if (log->ce_mask & LOG_ATTR_ALLOC_SIZE)
51 nl_dump(p,
"alloc_size=%u ", log->log_alloc_size);
53 if (log->ce_mask & LOG_ATTR_QUEUE_THRESHOLD)
54 nl_dump(p,
"queue_threshold=%u ", log->log_queue_threshold);
59 static const struct trans_tbl copy_modes[] = {
60 __ADD(NFNL_LOG_COPY_NONE, none),
61 __ADD(NFNL_LOG_COPY_META, meta),
62 __ADD(NFNL_LOG_COPY_PACKET, packet),
65 char *nfnl_log_copy_mode2str(
enum nfnl_log_copy_mode copy_mode,
char *buf,
68 return __type2str(copy_mode, buf, len, copy_modes,
69 ARRAY_SIZE(copy_modes));
72 int nfnl_log_str2copy_mode(
const char *name)
74 return __str2type(name, copy_modes, ARRAY_SIZE(copy_modes));
82 struct nfnl_log *nfnl_log_alloc(
void)
87 void nfnl_log_get(
struct nfnl_log *log)
92 void nfnl_log_put(
struct nfnl_log *log)
104 void nfnl_log_set_group(
struct nfnl_log *log, uint16_t group)
106 log->log_group = group;
107 log->ce_mask |= LOG_ATTR_GROUP;
110 int nfnl_log_test_group(
const struct nfnl_log *log)
112 return !!(log->ce_mask & LOG_ATTR_GROUP);
115 uint16_t nfnl_log_get_group(
const struct nfnl_log *log)
117 return log->log_group;
120 void nfnl_log_set_copy_mode(
struct nfnl_log *log,
enum nfnl_log_copy_mode mode)
122 log->log_copy_mode = mode;
123 log->ce_mask |= LOG_ATTR_COPY_MODE;
126 int nfnl_log_test_copy_mode(
const struct nfnl_log *log)
128 return !!(log->ce_mask & LOG_ATTR_COPY_MODE);
131 enum nfnl_log_copy_mode nfnl_log_get_copy_mode(
const struct nfnl_log *log)
133 return log->log_copy_mode;
136 void nfnl_log_set_copy_range(
struct nfnl_log *log, uint32_t copy_range)
138 log->log_copy_range = copy_range;
139 log->ce_mask |= LOG_ATTR_COPY_RANGE;
142 int nfnl_log_test_copy_range(
const struct nfnl_log *log)
144 return !!(log->ce_mask & LOG_ATTR_COPY_RANGE);
147 uint32_t nfnl_log_get_copy_range(
const struct nfnl_log *log)
149 return log->log_copy_range;
152 void nfnl_log_set_flush_timeout(
struct nfnl_log *log, uint32_t timeout)
154 log->log_flush_timeout = timeout;
155 log->ce_mask |= LOG_ATTR_FLUSH_TIMEOUT;
158 int nfnl_log_test_flush_timeout(
const struct nfnl_log *log)
160 return !!(log->ce_mask & LOG_ATTR_FLUSH_TIMEOUT);
163 uint32_t nfnl_log_get_flush_timeout(
const struct nfnl_log *log)
165 return log->log_flush_timeout;
168 void nfnl_log_set_alloc_size(
struct nfnl_log *log, uint32_t alloc_size)
170 log->log_alloc_size = alloc_size;
171 log->ce_mask |= LOG_ATTR_ALLOC_SIZE;
174 int nfnl_log_test_alloc_size(
const struct nfnl_log *log)
176 return !!(log->ce_mask & LOG_ATTR_ALLOC_SIZE);
179 uint32_t nfnl_log_get_alloc_size(
const struct nfnl_log *log)
181 return log->log_alloc_size;
184 void nfnl_log_set_queue_threshold(
struct nfnl_log *log, uint32_t threshold)
186 log->log_queue_threshold = threshold;
187 log->ce_mask |= LOG_ATTR_QUEUE_THRESHOLD;
190 int nfnl_log_test_queue_threshold(
const struct nfnl_log *log)
192 return !!(log->ce_mask & LOG_ATTR_QUEUE_THRESHOLD);
195 uint32_t nfnl_log_get_queue_threshold(
const struct nfnl_log *log)
197 return log->log_queue_threshold;
205 void nfnl_log_set_flags(
struct nfnl_log *log,
unsigned int flags)
207 log->log_flags |= flags;
208 log->log_flag_mask |= flags;
211 void nfnl_log_unset_flags(
struct nfnl_log *log,
unsigned int flags)
213 log->log_flags &= ~flags;
214 log->log_flag_mask |= flags;
217 static const struct trans_tbl log_flags[] = {
218 __ADD(NFNL_LOG_FLAG_SEQ, seq),
219 __ADD(NFNL_LOG_FLAG_SEQ_GLOBAL, seq_global),
222 char *nfnl_log_flags2str(
unsigned int flags,
char *buf,
size_t len)
224 return __flags2str(flags, buf, len, log_flags, ARRAY_SIZE(log_flags));
227 unsigned int nfnl_log_str2flags(
const char *name)
229 return __str2flags(name, log_flags, ARRAY_SIZE(log_flags));
232 static 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 257 static 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),
266 static 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));
274 struct 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,
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.