6#include <netlink-private/netlink.h>
7#include <netlink/netfilter/nfnl.h>
8#include <netlink/netfilter/netfilter.h>
9#include <netlink/netfilter/queue_msg.h>
10#include <linux/netfilter.h>
13#define QUEUE_MSG_ATTR_GROUP (1UL << 0)
14#define QUEUE_MSG_ATTR_FAMILY (1UL << 1)
15#define QUEUE_MSG_ATTR_PACKETID (1UL << 2)
16#define QUEUE_MSG_ATTR_HWPROTO (1UL << 3)
17#define QUEUE_MSG_ATTR_HOOK (1UL << 4)
18#define QUEUE_MSG_ATTR_MARK (1UL << 5)
19#define QUEUE_MSG_ATTR_TIMESTAMP (1UL << 6)
20#define QUEUE_MSG_ATTR_INDEV (1UL << 7)
21#define QUEUE_MSG_ATTR_OUTDEV (1UL << 8)
22#define QUEUE_MSG_ATTR_PHYSINDEV (1UL << 9)
23#define QUEUE_MSG_ATTR_PHYSOUTDEV (1UL << 10)
24#define QUEUE_MSG_ATTR_HWADDR (1UL << 11)
25#define QUEUE_MSG_ATTR_PAYLOAD (1UL << 12)
26#define QUEUE_MSG_ATTR_VERDICT (1UL << 13)
29static void nfnl_queue_msg_free_data(
struct nl_object *c)
31 struct nfnl_queue_msg *msg = (
struct nfnl_queue_msg *) c;
36 free(msg->queue_msg_payload);
39static int nfnl_queue_msg_clone(
struct nl_object *_dst,
struct nl_object *_src)
41 struct nfnl_queue_msg *dst = (
struct nfnl_queue_msg *) _dst;
42 struct nfnl_queue_msg *src = (
struct nfnl_queue_msg *) _src;
45 dst->queue_msg_payload = NULL;
46 dst->queue_msg_payload_len = 0;
48 if (src->queue_msg_payload) {
49 err = nfnl_queue_msg_set_payload(dst, src->queue_msg_payload,
50 src->queue_msg_payload_len);
58static void nfnl_queue_msg_dump(
struct nl_object *a,
struct nl_dump_params *p)
60 struct nfnl_queue_msg *msg = (
struct nfnl_queue_msg *) a;
61 struct nl_cache *link_cache;
68 if (msg->ce_mask & QUEUE_MSG_ATTR_GROUP)
69 nl_dump(p,
"GROUP=%u ", msg->queue_msg_group);
71 if (msg->ce_mask & QUEUE_MSG_ATTR_INDEV) {
78 nl_dump(p,
"IN=%d ", msg->queue_msg_indev);
81 if (msg->ce_mask & QUEUE_MSG_ATTR_PHYSINDEV) {
85 msg->queue_msg_physindev,
88 nl_dump(p,
"IN=%d ", msg->queue_msg_physindev);
91 if (msg->ce_mask & QUEUE_MSG_ATTR_OUTDEV) {
95 msg->queue_msg_outdev,
98 nl_dump(p,
"OUT=%d ", msg->queue_msg_outdev);
101 if (msg->ce_mask & QUEUE_MSG_ATTR_PHYSOUTDEV) {
105 msg->queue_msg_physoutdev,
108 nl_dump(p,
"PHYSOUT=%d ", msg->queue_msg_physoutdev);
111 if (msg->ce_mask & QUEUE_MSG_ATTR_HWADDR) {
115 for (i = 0; i < msg->queue_msg_hwaddr_len; i++)
116 nl_dump(p,
"%c%02x", i?
':':
'=',
117 msg->queue_msg_hwaddr[i]);
121 if (msg->ce_mask & QUEUE_MSG_ATTR_FAMILY)
123 nl_af2str(msg->queue_msg_family, buf,
sizeof(buf)));
125 if (msg->ce_mask & QUEUE_MSG_ATTR_HWPROTO)
127 nl_ether_proto2str(ntohs(msg->queue_msg_hwproto),
130 if (msg->ce_mask & QUEUE_MSG_ATTR_HOOK)
132 nfnl_inet_hook2str(msg->queue_msg_hook,
135 if (msg->ce_mask & QUEUE_MSG_ATTR_MARK)
136 nl_dump(p,
"MARK=%d ", msg->queue_msg_mark);
138 if (msg->ce_mask & QUEUE_MSG_ATTR_PAYLOAD)
139 nl_dump(p,
"PAYLOADLEN=%d ", msg->queue_msg_payload_len);
141 if (msg->ce_mask & QUEUE_MSG_ATTR_PACKETID)
142 nl_dump(p,
"PACKETID=%u ", msg->queue_msg_packetid);
144 if (msg->ce_mask & QUEUE_MSG_ATTR_VERDICT)
146 nfnl_verdict2str(msg->queue_msg_verdict,
152 nl_cache_put(link_cache);
160struct nfnl_queue_msg *nfnl_queue_msg_alloc(
void)
165void nfnl_queue_msg_get(
struct nfnl_queue_msg *msg)
170void nfnl_queue_msg_put(
struct nfnl_queue_msg *msg)
182void nfnl_queue_msg_set_group(
struct nfnl_queue_msg *msg, uint16_t group)
184 msg->queue_msg_group = group;
185 msg->ce_mask |= QUEUE_MSG_ATTR_GROUP;
188int nfnl_queue_msg_test_group(
const struct nfnl_queue_msg *msg)
190 return !!(msg->ce_mask & QUEUE_MSG_ATTR_GROUP);
193uint16_t nfnl_queue_msg_get_group(
const struct nfnl_queue_msg *msg)
195 return msg->queue_msg_group;
203void nfnl_queue_msg_set_family(
struct nfnl_queue_msg *msg, uint8_t family)
205 msg->queue_msg_family = family;
206 msg->ce_mask |= QUEUE_MSG_ATTR_FAMILY;
209int nfnl_queue_msg_test_family(
const struct nfnl_queue_msg *msg)
211 return !!(msg->ce_mask & QUEUE_MSG_ATTR_FAMILY);
214uint8_t nfnl_queue_msg_get_family(
const struct nfnl_queue_msg *msg)
216 if (msg->ce_mask & QUEUE_MSG_ATTR_FAMILY)
217 return msg->queue_msg_family;
222void nfnl_queue_msg_set_packetid(
struct nfnl_queue_msg *msg, uint32_t packetid)
224 msg->queue_msg_packetid = packetid;
225 msg->ce_mask |= QUEUE_MSG_ATTR_PACKETID;
228int nfnl_queue_msg_test_packetid(
const struct nfnl_queue_msg *msg)
230 return !!(msg->ce_mask & QUEUE_MSG_ATTR_PACKETID);
233uint32_t nfnl_queue_msg_get_packetid(
const struct nfnl_queue_msg *msg)
235 return msg->queue_msg_packetid;
238void nfnl_queue_msg_set_hwproto(
struct nfnl_queue_msg *msg, uint16_t hwproto)
240 msg->queue_msg_hwproto = hwproto;
241 msg->ce_mask |= QUEUE_MSG_ATTR_HWPROTO;
244int nfnl_queue_msg_test_hwproto(
const struct nfnl_queue_msg *msg)
246 return !!(msg->ce_mask & QUEUE_MSG_ATTR_HWPROTO);
249uint16_t nfnl_queue_msg_get_hwproto(
const struct nfnl_queue_msg *msg)
251 return msg->queue_msg_hwproto;
254void nfnl_queue_msg_set_hook(
struct nfnl_queue_msg *msg, uint8_t hook)
256 msg->queue_msg_hook = hook;
257 msg->ce_mask |= QUEUE_MSG_ATTR_HOOK;
260int nfnl_queue_msg_test_hook(
const struct nfnl_queue_msg *msg)
262 return !!(msg->ce_mask & QUEUE_MSG_ATTR_HOOK);
265uint8_t nfnl_queue_msg_get_hook(
const struct nfnl_queue_msg *msg)
267 return msg->queue_msg_hook;
270void nfnl_queue_msg_set_mark(
struct nfnl_queue_msg *msg, uint32_t mark)
272 msg->queue_msg_mark = mark;
273 msg->ce_mask |= QUEUE_MSG_ATTR_MARK;
276int nfnl_queue_msg_test_mark(
const struct nfnl_queue_msg *msg)
278 return !!(msg->ce_mask & QUEUE_MSG_ATTR_MARK);
281uint32_t nfnl_queue_msg_get_mark(
const struct nfnl_queue_msg *msg)
283 return msg->queue_msg_mark;
286void nfnl_queue_msg_set_timestamp(
struct nfnl_queue_msg *msg,
289 msg->queue_msg_timestamp.tv_sec = tv->tv_sec;
290 msg->queue_msg_timestamp.tv_usec = tv->tv_usec;
291 msg->ce_mask |= QUEUE_MSG_ATTR_TIMESTAMP;
294int nfnl_queue_msg_test_timestamp(
const struct nfnl_queue_msg *msg)
296 return !!(msg->ce_mask & QUEUE_MSG_ATTR_TIMESTAMP);
299const struct timeval *nfnl_queue_msg_get_timestamp(
const struct nfnl_queue_msg *msg)
301 if (!(msg->ce_mask & QUEUE_MSG_ATTR_TIMESTAMP))
303 return &msg->queue_msg_timestamp;
306void nfnl_queue_msg_set_indev(
struct nfnl_queue_msg *msg, uint32_t indev)
308 msg->queue_msg_indev = indev;
309 msg->ce_mask |= QUEUE_MSG_ATTR_INDEV;
312int nfnl_queue_msg_test_indev(
const struct nfnl_queue_msg *msg)
314 return !!(msg->ce_mask & QUEUE_MSG_ATTR_INDEV);
317uint32_t nfnl_queue_msg_get_indev(
const struct nfnl_queue_msg *msg)
319 return msg->queue_msg_indev;
322void nfnl_queue_msg_set_outdev(
struct nfnl_queue_msg *msg, uint32_t outdev)
324 msg->queue_msg_outdev = outdev;
325 msg->ce_mask |= QUEUE_MSG_ATTR_OUTDEV;
328int nfnl_queue_msg_test_outdev(
const struct nfnl_queue_msg *msg)
330 return !!(msg->ce_mask & QUEUE_MSG_ATTR_OUTDEV);
333uint32_t nfnl_queue_msg_get_outdev(
const struct nfnl_queue_msg *msg)
335 return msg->queue_msg_outdev;
338void nfnl_queue_msg_set_physindev(
struct nfnl_queue_msg *msg,
341 msg->queue_msg_physindev = physindev;
342 msg->ce_mask |= QUEUE_MSG_ATTR_PHYSINDEV;
345int nfnl_queue_msg_test_physindev(
const struct nfnl_queue_msg *msg)
347 return !!(msg->ce_mask & QUEUE_MSG_ATTR_PHYSINDEV);
350uint32_t nfnl_queue_msg_get_physindev(
const struct nfnl_queue_msg *msg)
352 return msg->queue_msg_physindev;
355void nfnl_queue_msg_set_physoutdev(
struct nfnl_queue_msg *msg,
358 msg->queue_msg_physoutdev = physoutdev;
359 msg->ce_mask |= QUEUE_MSG_ATTR_PHYSOUTDEV;
362int nfnl_queue_msg_test_physoutdev(
const struct nfnl_queue_msg *msg)
364 return !!(msg->ce_mask & QUEUE_MSG_ATTR_PHYSOUTDEV);
367uint32_t nfnl_queue_msg_get_physoutdev(
const struct nfnl_queue_msg *msg)
369 return msg->queue_msg_physoutdev;
372void nfnl_queue_msg_set_hwaddr(
struct nfnl_queue_msg *msg, uint8_t *hwaddr,
375 if (len >
sizeof(msg->queue_msg_hwaddr))
376 len =
sizeof(msg->queue_msg_hwaddr);
378 msg->queue_msg_hwaddr_len = len;
379 memcpy(msg->queue_msg_hwaddr, hwaddr, len);
380 msg->ce_mask |= QUEUE_MSG_ATTR_HWADDR;
383int nfnl_queue_msg_test_hwaddr(
const struct nfnl_queue_msg *msg)
385 return !!(msg->ce_mask & QUEUE_MSG_ATTR_HWADDR);
388const uint8_t *nfnl_queue_msg_get_hwaddr(
const struct nfnl_queue_msg *msg,
391 if (!(msg->ce_mask & QUEUE_MSG_ATTR_HWADDR)) {
396 *len = msg->queue_msg_hwaddr_len;
397 return msg->queue_msg_hwaddr;
400int nfnl_queue_msg_set_payload(
struct nfnl_queue_msg *msg, uint8_t *payload,
408 p = _nl_memdup(payload, len);
412 free(msg->queue_msg_payload);
413 msg->queue_msg_payload = p;
414 msg->queue_msg_payload_len = len;
416 msg->ce_mask |= QUEUE_MSG_ATTR_PAYLOAD;
418 msg->ce_mask &= ~QUEUE_MSG_ATTR_PAYLOAD;
422int nfnl_queue_msg_test_payload(
const struct nfnl_queue_msg *msg)
424 return !!(msg->ce_mask & QUEUE_MSG_ATTR_PAYLOAD);
427const void *nfnl_queue_msg_get_payload(
const struct nfnl_queue_msg *msg,
int *len)
429 if (!(msg->ce_mask & QUEUE_MSG_ATTR_PAYLOAD)) {
434 *len = msg->queue_msg_payload_len;
435 return msg->queue_msg_payload;
443void nfnl_queue_msg_set_verdict(
struct nfnl_queue_msg *msg,
444 unsigned int verdict)
446 msg->queue_msg_verdict = verdict;
447 msg->ce_mask |= QUEUE_MSG_ATTR_VERDICT;
450int nfnl_queue_msg_test_verdict(
const struct nfnl_queue_msg *msg)
452 return !!(msg->ce_mask & QUEUE_MSG_ATTR_VERDICT);
455unsigned int nfnl_queue_msg_get_verdict(
const struct nfnl_queue_msg *msg)
457 return msg->queue_msg_verdict;
460static const struct trans_tbl nfnl_queue_msg_attrs[] = {
461 __ADD(QUEUE_MSG_ATTR_GROUP, group),
462 __ADD(QUEUE_MSG_ATTR_FAMILY, family),
463 __ADD(QUEUE_MSG_ATTR_PACKETID, packetid),
464 __ADD(QUEUE_MSG_ATTR_HWPROTO, hwproto),
465 __ADD(QUEUE_MSG_ATTR_HOOK, hook),
466 __ADD(QUEUE_MSG_ATTR_MARK, mark),
467 __ADD(QUEUE_MSG_ATTR_TIMESTAMP, timestamp),
468 __ADD(QUEUE_MSG_ATTR_INDEV, indev),
469 __ADD(QUEUE_MSG_ATTR_OUTDEV, outdev),
470 __ADD(QUEUE_MSG_ATTR_PHYSINDEV, physindev),
471 __ADD(QUEUE_MSG_ATTR_PHYSOUTDEV, physoutdev),
472 __ADD(QUEUE_MSG_ATTR_HWADDR, hwaddr),
473 __ADD(QUEUE_MSG_ATTR_PAYLOAD, payload),
474 __ADD(QUEUE_MSG_ATTR_VERDICT, verdict),
477static char *nfnl_queue_msg_attrs2str(
int attrs,
char *buf,
size_t len)
479 return __flags2str(attrs, buf, len, nfnl_queue_msg_attrs,
480 ARRAY_SIZE(nfnl_queue_msg_attrs));
485struct nl_object_ops queue_msg_obj_ops = {
486 .oo_name =
"netfilter/queuemsg",
487 .oo_size =
sizeof(
struct nfnl_queue_msg),
488 .oo_free_data = nfnl_queue_msg_free_data,
489 .oo_clone = nfnl_queue_msg_clone,
495 .oo_attrs2str = nfnl_queue_msg_attrs2str,
struct nl_cache * nl_cache_mngt_require_safe(const char *name)
Return cache previously provided via nl_cache_mngt_provide()
char * rtnl_link_i2name(struct nl_cache *cache, int ifindex, char *dst, size_t len)
Translate interface index to corresponding link name.
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.