13#include "nl-default.h"
15#include <netlink/netfilter/nfnl.h>
16#include <netlink/netfilter/queue.h>
18#include "nl-priv-dynamic-core/object-api.h"
19#include "nl-priv-dynamic-core/nl-core.h"
26 uint32_t queue_maxlen;
27 uint32_t queue_copy_range;
28 uint8_t queue_copy_mode;
31#define QUEUE_ATTR_GROUP (1UL << 0)
32#define QUEUE_ATTR_MAXLEN (1UL << 1)
33#define QUEUE_ATTR_COPY_MODE (1UL << 2)
34#define QUEUE_ATTR_COPY_RANGE (1UL << 3)
38static void nfnl_queue_dump(
struct nl_object *a,
struct nl_dump_params *p)
40 struct nfnl_queue *queue = (
struct nfnl_queue *) a;
45 if (queue->ce_mask & QUEUE_ATTR_GROUP)
46 nl_dump(p,
"group=%u ", queue->queue_group);
48 if (queue->ce_mask & QUEUE_ATTR_MAXLEN)
49 nl_dump(p,
"maxlen=%u ", queue->queue_maxlen);
51 if (queue->ce_mask & QUEUE_ATTR_COPY_MODE)
53 nfnl_queue_copy_mode2str(queue->queue_copy_mode,
56 if (queue->ce_mask & QUEUE_ATTR_COPY_RANGE)
57 nl_dump(p,
"copy_range=%u ", queue->queue_copy_range);
62static const struct trans_tbl copy_modes[] = {
63 __ADD(NFNL_QUEUE_COPY_NONE, none),
64 __ADD(NFNL_QUEUE_COPY_META, meta),
65 __ADD(NFNL_QUEUE_COPY_PACKET, packet),
68char *nfnl_queue_copy_mode2str(
enum nfnl_queue_copy_mode copy_mode,
char *buf,
71 return __type2str(copy_mode, buf, len, copy_modes,
72 ARRAY_SIZE(copy_modes));
75int nfnl_queue_str2copy_mode(
const char *name)
77 return __str2type(name, copy_modes, ARRAY_SIZE(copy_modes));
85struct nfnl_queue *nfnl_queue_alloc(
void)
90void nfnl_queue_get(
struct nfnl_queue *queue)
95void nfnl_queue_put(
struct nfnl_queue *queue)
107void nfnl_queue_set_group(
struct nfnl_queue *queue, uint16_t group)
109 queue->queue_group = group;
110 queue->ce_mask |= QUEUE_ATTR_GROUP;
113int nfnl_queue_test_group(
const struct nfnl_queue *queue)
115 return !!(queue->ce_mask & QUEUE_ATTR_GROUP);
118uint16_t nfnl_queue_get_group(
const struct nfnl_queue *queue)
120 return queue->queue_group;
123void nfnl_queue_set_maxlen(
struct nfnl_queue *queue, uint32_t maxlen)
125 queue->queue_maxlen = maxlen;
126 queue->ce_mask |= QUEUE_ATTR_MAXLEN;
129int nfnl_queue_test_maxlen(
const struct nfnl_queue *queue)
131 return !!(queue->ce_mask & QUEUE_ATTR_MAXLEN);
134uint32_t nfnl_queue_get_maxlen(
const struct nfnl_queue *queue)
136 return queue->queue_maxlen;
139void nfnl_queue_set_copy_mode(
struct nfnl_queue *queue,
enum nfnl_queue_copy_mode mode)
141 queue->queue_copy_mode = mode;
142 queue->ce_mask |= QUEUE_ATTR_COPY_MODE;
145int nfnl_queue_test_copy_mode(
const struct nfnl_queue *queue)
147 return !!(queue->ce_mask & QUEUE_ATTR_COPY_MODE);
150enum nfnl_queue_copy_mode nfnl_queue_get_copy_mode(
const struct nfnl_queue *queue)
152 return queue->queue_copy_mode;
155void nfnl_queue_set_copy_range(
struct nfnl_queue *queue, uint32_t copy_range)
157 queue->queue_copy_range = copy_range;
158 queue->ce_mask |= QUEUE_ATTR_COPY_RANGE;
161int nfnl_queue_test_copy_range(
const struct nfnl_queue *queue)
163 return !!(queue->ce_mask & QUEUE_ATTR_COPY_RANGE);
166uint32_t nfnl_queue_get_copy_range(
const struct nfnl_queue *queue)
168 return queue->queue_copy_range;
171static uint64_t nfnl_queue_compare(
struct nl_object *_a,
struct nl_object *_b,
172 uint64_t attrs,
int flags)
174 struct nfnl_queue *a = (
struct nfnl_queue *) _a;
175 struct nfnl_queue *b = (
struct nfnl_queue *) _b;
178#define _DIFF(ATTR, EXPR) ATTR_DIFF(attrs, ATTR, a, b, EXPR)
179#define _DIFF_VAL(ATTR, FIELD) _DIFF(ATTR, a->FIELD != b->FIELD)
180 diff |= _DIFF_VAL(QUEUE_ATTR_GROUP, queue_group);
181 diff |= _DIFF_VAL(QUEUE_ATTR_MAXLEN, queue_maxlen);
182 diff |= _DIFF_VAL(QUEUE_ATTR_COPY_MODE, queue_copy_mode);
183 diff |= _DIFF_VAL(QUEUE_ATTR_COPY_RANGE, queue_copy_range);
190static const struct trans_tbl nfnl_queue_attrs[] = {
191 __ADD(QUEUE_ATTR_GROUP, group),
192 __ADD(QUEUE_ATTR_MAXLEN, maxlen),
193 __ADD(QUEUE_ATTR_COPY_MODE, copy_mode),
194 __ADD(QUEUE_ATTR_COPY_RANGE, copy_range),
197static char *nfnl_queue_attrs2str(
int attrs,
char *buf,
size_t len)
199 return __flags2str(attrs, buf, len, nfnl_queue_attrs,
200 ARRAY_SIZE(nfnl_queue_attrs));
205struct nl_object_ops queue_obj_ops = {
206 .oo_name =
"netfilter/queue",
207 .oo_size =
sizeof(
struct nfnl_queue),
213 .oo_compare = nfnl_queue_compare,
214 .oo_attrs2str = nfnl_queue_attrs2str,
215 .oo_id_attrs = QUEUE_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.