2 * lib/netfilter/queue_obj.c Netfilter Queue
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation version 2.1
9 * Copyright (c) 2007, 2008 Patrick McHardy <kaber@trash.net>
14 * @defgroup queue Queue
19 #include <netlink-local.h>
20 #include <netlink/netfilter/nfnl.h>
21 #include <netlink/netfilter/queue.h>
24 #define QUEUE_ATTR_GROUP (1UL << 0)
25 #define QUEUE_ATTR_MAXLEN (1UL << 1)
26 #define QUEUE_ATTR_COPY_MODE (1UL << 2)
27 #define QUEUE_ATTR_COPY_RANGE (1UL << 3)
31 static void nfnl_queue_dump(struct nl_object *a, struct nl_dump_params *p)
33 struct nfnl_queue *queue = (struct nfnl_queue *) a;
38 if (queue->ce_mask & QUEUE_ATTR_GROUP)
39 nl_dump(p, "group=%u ", queue->queue_group);
41 if (queue->ce_mask & QUEUE_ATTR_MAXLEN)
42 nl_dump(p, "maxlen=%u ", queue->queue_maxlen);
44 if (queue->ce_mask & QUEUE_ATTR_COPY_MODE)
45 nl_dump(p, "copy_mode=%s ",
46 nfnl_queue_copy_mode2str(queue->queue_copy_mode,
49 if (queue->ce_mask & QUEUE_ATTR_COPY_RANGE)
50 nl_dump(p, "copy_range=%u ", queue->queue_copy_range);
55 static struct trans_tbl copy_modes[] = {
56 __ADD(NFNL_QUEUE_COPY_NONE, none)
57 __ADD(NFNL_QUEUE_COPY_META, meta)
58 __ADD(NFNL_QUEUE_COPY_PACKET, packet)
61 char *nfnl_queue_copy_mode2str(enum nfnl_queue_copy_mode copy_mode, char *buf,
64 return __type2str(copy_mode, buf, len, copy_modes,
65 ARRAY_SIZE(copy_modes));
68 enum nfnl_queue_copy_mode nfnl_queue_str2copy_mode(const char *name)
70 return __str2type(name, copy_modes, ARRAY_SIZE(copy_modes));
74 * @name Allocation/Freeing
78 struct nfnl_queue *nfnl_queue_alloc(void)
80 return (struct nfnl_queue *) nl_object_alloc(&queue_obj_ops);
83 void nfnl_queue_get(struct nfnl_queue *queue)
85 nl_object_get((struct nl_object *) queue);
88 void nfnl_queue_put(struct nfnl_queue *queue)
90 nl_object_put((struct nl_object *) queue);
100 void nfnl_queue_set_group(struct nfnl_queue *queue, uint16_t group)
102 queue->queue_group = group;
103 queue->ce_mask |= QUEUE_ATTR_GROUP;
106 int nfnl_queue_test_group(const struct nfnl_queue *queue)
108 return !!(queue->ce_mask & QUEUE_ATTR_GROUP);
111 uint16_t nfnl_queue_get_group(const struct nfnl_queue *queue)
113 return queue->queue_group;
116 void nfnl_queue_set_maxlen(struct nfnl_queue *queue, uint32_t maxlen)
118 queue->queue_maxlen = maxlen;
119 queue->ce_mask |= QUEUE_ATTR_MAXLEN;
122 int nfnl_queue_test_maxlen(const struct nfnl_queue *queue)
124 return !!(queue->ce_mask & QUEUE_ATTR_MAXLEN);
127 uint32_t nfnl_queue_get_maxlen(const struct nfnl_queue *queue)
129 return queue->queue_maxlen;
132 void nfnl_queue_set_copy_mode(struct nfnl_queue *queue, enum nfnl_queue_copy_mode mode)
134 queue->queue_copy_mode = mode;
135 queue->ce_mask |= QUEUE_ATTR_COPY_MODE;
138 int nfnl_queue_test_copy_mode(const struct nfnl_queue *queue)
140 return !!(queue->ce_mask & QUEUE_ATTR_COPY_MODE);
143 enum nfnl_queue_copy_mode nfnl_queue_get_copy_mode(const struct nfnl_queue *queue)
145 return queue->queue_copy_mode;
148 void nfnl_queue_set_copy_range(struct nfnl_queue *queue, uint32_t copy_range)
150 queue->queue_copy_range = copy_range;
151 queue->ce_mask |= QUEUE_ATTR_COPY_RANGE;
154 int nfnl_queue_test_copy_range(const struct nfnl_queue *queue)
156 return !!(queue->ce_mask & QUEUE_ATTR_COPY_RANGE);
159 uint32_t nfnl_queue_get_copy_range(const struct nfnl_queue *queue)
161 return queue->queue_copy_range;
164 static int nfnl_queue_compare(struct nl_object *_a, struct nl_object *_b,
165 uint32_t attrs, int flags)
167 struct nfnl_queue *a = (struct nfnl_queue *) _a;
168 struct nfnl_queue *b = (struct nfnl_queue *) _b;
171 #define NFNL_QUEUE_DIFF(ATTR, EXPR) \
172 ATTR_DIFF(attrs, QUEUE_ATTR_##ATTR, a, b, EXPR)
173 #define NFNL_QUEUE_DIFF_VAL(ATTR, FIELD) \
174 NFNL_QUEUE_DIFF(ATTR, a->FIELD != b->FIELD)
176 diff |= NFNL_QUEUE_DIFF_VAL(GROUP, queue_group);
177 diff |= NFNL_QUEUE_DIFF_VAL(MAXLEN, queue_maxlen);
178 diff |= NFNL_QUEUE_DIFF_VAL(COPY_MODE, queue_copy_mode);
179 diff |= NFNL_QUEUE_DIFF_VAL(COPY_RANGE, queue_copy_range);
181 #undef NFNL_QUEUE_DIFF
182 #undef NFNL_QUEUE_DIFF_VAL
187 static struct trans_tbl nfnl_queue_attrs[] = {
188 __ADD(QUEUE_ATTR_GROUP, group)
189 __ADD(QUEUE_ATTR_MAXLEN, maxlen)
190 __ADD(QUEUE_ATTR_COPY_MODE, copy_mode)
191 __ADD(QUEUE_ATTR_COPY_RANGE, copy_range)
194 static char *nfnl_queue_attrs2str(int attrs, char *buf, size_t len)
196 return __flags2str(attrs, buf, len, nfnl_queue_attrs,
197 ARRAY_SIZE(nfnl_queue_attrs));
202 struct nl_object_ops queue_obj_ops = {
203 .oo_name = "netfilter/queue",
204 .oo_size = sizeof(struct nfnl_queue),
206 [NL_DUMP_LINE] = nfnl_queue_dump,
207 [NL_DUMP_DETAILS] = nfnl_queue_dump,
208 [NL_DUMP_STATS] = nfnl_queue_dump,
210 .oo_compare = nfnl_queue_compare,
211 .oo_attrs2str = nfnl_queue_attrs2str,
212 .oo_id_attrs = QUEUE_ATTR_GROUP,