20 #include <netlink-private/netlink.h> 21 #include <netlink/netfilter/nfnl.h> 22 #include <netlink/netfilter/queue.h> 25 #define QUEUE_ATTR_GROUP (1UL << 0) 26 #define QUEUE_ATTR_MAXLEN (1UL << 1) 27 #define QUEUE_ATTR_COPY_MODE (1UL << 2) 28 #define QUEUE_ATTR_COPY_RANGE (1UL << 3) 32 static void nfnl_queue_dump(
struct nl_object *a,
struct nl_dump_params *p)
34 struct nfnl_queue *queue = (
struct nfnl_queue *) a;
39 if (queue->ce_mask & QUEUE_ATTR_GROUP)
40 nl_dump(p,
"group=%u ", queue->queue_group);
42 if (queue->ce_mask & QUEUE_ATTR_MAXLEN)
43 nl_dump(p,
"maxlen=%u ", queue->queue_maxlen);
45 if (queue->ce_mask & QUEUE_ATTR_COPY_MODE)
47 nfnl_queue_copy_mode2str(queue->queue_copy_mode,
50 if (queue->ce_mask & QUEUE_ATTR_COPY_RANGE)
51 nl_dump(p,
"copy_range=%u ", queue->queue_copy_range);
56 static const struct trans_tbl copy_modes[] = {
57 __ADD(NFNL_QUEUE_COPY_NONE, none),
58 __ADD(NFNL_QUEUE_COPY_META, meta),
59 __ADD(NFNL_QUEUE_COPY_PACKET, packet),
62 char *nfnl_queue_copy_mode2str(
enum nfnl_queue_copy_mode copy_mode,
char *buf,
65 return __type2str(copy_mode, buf, len, copy_modes,
66 ARRAY_SIZE(copy_modes));
69 int nfnl_queue_str2copy_mode(
const char *name)
71 return __str2type(name, copy_modes, ARRAY_SIZE(copy_modes));
79 struct nfnl_queue *nfnl_queue_alloc(
void)
84 void nfnl_queue_get(
struct nfnl_queue *queue)
89 void nfnl_queue_put(
struct nfnl_queue *queue)
101 void nfnl_queue_set_group(
struct nfnl_queue *queue, uint16_t group)
103 queue->queue_group = group;
104 queue->ce_mask |= QUEUE_ATTR_GROUP;
107 int nfnl_queue_test_group(
const struct nfnl_queue *queue)
109 return !!(queue->ce_mask & QUEUE_ATTR_GROUP);
112 uint16_t nfnl_queue_get_group(
const struct nfnl_queue *queue)
114 return queue->queue_group;
117 void nfnl_queue_set_maxlen(
struct nfnl_queue *queue, uint32_t maxlen)
119 queue->queue_maxlen = maxlen;
120 queue->ce_mask |= QUEUE_ATTR_MAXLEN;
123 int nfnl_queue_test_maxlen(
const struct nfnl_queue *queue)
125 return !!(queue->ce_mask & QUEUE_ATTR_MAXLEN);
128 uint32_t nfnl_queue_get_maxlen(
const struct nfnl_queue *queue)
130 return queue->queue_maxlen;
133 void nfnl_queue_set_copy_mode(
struct nfnl_queue *queue,
enum nfnl_queue_copy_mode mode)
135 queue->queue_copy_mode = mode;
136 queue->ce_mask |= QUEUE_ATTR_COPY_MODE;
139 int nfnl_queue_test_copy_mode(
const struct nfnl_queue *queue)
141 return !!(queue->ce_mask & QUEUE_ATTR_COPY_MODE);
144 enum nfnl_queue_copy_mode nfnl_queue_get_copy_mode(
const struct nfnl_queue *queue)
146 return queue->queue_copy_mode;
149 void nfnl_queue_set_copy_range(
struct nfnl_queue *queue, uint32_t copy_range)
151 queue->queue_copy_range = copy_range;
152 queue->ce_mask |= QUEUE_ATTR_COPY_RANGE;
155 int nfnl_queue_test_copy_range(
const struct nfnl_queue *queue)
157 return !!(queue->ce_mask & QUEUE_ATTR_COPY_RANGE);
160 uint32_t nfnl_queue_get_copy_range(
const struct nfnl_queue *queue)
162 return queue->queue_copy_range;
165 static uint64_t nfnl_queue_compare(
struct nl_object *_a,
struct nl_object *_b,
166 uint64_t attrs,
int flags)
168 struct nfnl_queue *a = (
struct nfnl_queue *) _a;
169 struct nfnl_queue *b = (
struct nfnl_queue *) _b;
172 #define NFNL_QUEUE_DIFF(ATTR, EXPR) \ 173 ATTR_DIFF(attrs, QUEUE_ATTR_##ATTR, a, b, EXPR) 174 #define NFNL_QUEUE_DIFF_VAL(ATTR, FIELD) \ 175 NFNL_QUEUE_DIFF(ATTR, a->FIELD != b->FIELD) 177 diff |= NFNL_QUEUE_DIFF_VAL(GROUP, queue_group);
178 diff |= NFNL_QUEUE_DIFF_VAL(MAXLEN, queue_maxlen);
179 diff |= NFNL_QUEUE_DIFF_VAL(COPY_MODE, queue_copy_mode);
180 diff |= NFNL_QUEUE_DIFF_VAL(COPY_RANGE, queue_copy_range);
182 #undef NFNL_QUEUE_DIFF 183 #undef NFNL_QUEUE_DIFF_VAL 188 static const struct trans_tbl nfnl_queue_attrs[] = {
189 __ADD(QUEUE_ATTR_GROUP, group),
190 __ADD(QUEUE_ATTR_MAXLEN, maxlen),
191 __ADD(QUEUE_ATTR_COPY_MODE, copy_mode),
192 __ADD(QUEUE_ATTR_COPY_RANGE, copy_range),
195 static char *nfnl_queue_attrs2str(
int attrs,
char *buf,
size_t len)
197 return __flags2str(attrs, buf, len, nfnl_queue_attrs,
198 ARRAY_SIZE(nfnl_queue_attrs));
203 struct nl_object_ops queue_obj_ops = {
204 .oo_name =
"netfilter/queue",
205 .oo_size =
sizeof(
struct nfnl_queue),
211 .oo_compare = nfnl_queue_compare,
212 .oo_attrs2str = nfnl_queue_attrs2str,
213 .oo_id_attrs = QUEUE_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.