libnl: /data/src/libnl/lib/netfilter/log_msg_obj.c Source File

libnl 3.12.0

log_msg_obj.c
1/* SPDX-License-Identifier: LGPL-2.1-only */
2/*
3 * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
4 * Copyright (c) 2007 Philip Craig <philipc@snapgear.com>
5 * Copyright (c) 2007 Secure Computing Corporation
6 */
7
8#include "nl-default.h"
9
10#include <netlink/netfilter/nfnl.h>
11#include <netlink/netfilter/netfilter.h>
12#include <netlink/netfilter/log_msg.h>
13#include <netlink/netfilter/ct.h>
14#include <netlink/route/link.h>
15
16#include "nl-priv-dynamic-core/object-api.h"
17#include "nl-netfilter.h"
18
19/** @cond SKIP */
20#define LOG_MSG_ATTR_FAMILY (1UL << 0)
21#define LOG_MSG_ATTR_HWPROTO (1UL << 1)
22#define LOG_MSG_ATTR_HOOK (1UL << 2)
23#define LOG_MSG_ATTR_MARK (1UL << 3)
24#define LOG_MSG_ATTR_TIMESTAMP (1UL << 4)
25#define LOG_MSG_ATTR_INDEV (1UL << 5)
26#define LOG_MSG_ATTR_OUTDEV (1UL << 6)
27#define LOG_MSG_ATTR_PHYSINDEV (1UL << 7)
28#define LOG_MSG_ATTR_PHYSOUTDEV (1UL << 8)
29#define LOG_MSG_ATTR_HWADDR (1UL << 9)
30#define LOG_MSG_ATTR_PAYLOAD (1UL << 10)
31#define LOG_MSG_ATTR_PREFIX (1UL << 11)
32#define LOG_MSG_ATTR_UID (1UL << 12)
33#define LOG_MSG_ATTR_GID (1UL << 13)
34#define LOG_MSG_ATTR_SEQ (1UL << 14)
35#define LOG_MSG_ATTR_SEQ_GLOBAL (1UL << 15)
36#define LOG_MSG_ATTR_HWTYPE (1UL << 16)
37#define LOG_MSG_ATTR_HWLEN (1UL << 17)
38#define LOG_MSG_ATTR_HWHEADER (1UL << 18)
39#define LOG_MSG_ATTR_VLAN_PROTO (1UL << 19)
40#define LOG_MSG_ATTR_VLAN_TAG (1UL << 20)
41#define LOG_MSG_ATTR_CT_INFO (1UL << 21)
42#define LOG_MSG_ATTR_CT (1UL << 22)
43/** @endcond */
44
45static void log_msg_free_data(struct nl_object *c)
46{
47 struct nfnl_log_msg *msg = (struct nfnl_log_msg *) c;
48
49 if (msg == NULL)
50 return;
51
52 free(msg->log_msg_payload);
53 free(msg->log_msg_prefix);
54 free(msg->log_msg_hwheader);
55 if (msg->log_msg_ct)
56 nfnl_ct_put(msg->log_msg_ct);
57}
58
59static int log_msg_clone(struct nl_object *_dst, struct nl_object *_src)
60{
61 struct nfnl_log_msg *dst = (struct nfnl_log_msg *) _dst;
62 struct nfnl_log_msg *src = (struct nfnl_log_msg *) _src;
63 int err;
64
65 dst->log_msg_payload = NULL;
66 dst->log_msg_payload_len = 0;
67 dst->log_msg_prefix = NULL;
68 dst->log_msg_hwheader = NULL;
69 dst->log_msg_hwheader_len = 0;
70 dst->log_msg_ct = NULL;
71
72 if (src->log_msg_payload) {
73 err = nfnl_log_msg_set_payload(dst, src->log_msg_payload,
74 src->log_msg_payload_len);
75 if (err < 0)
76 return err;
77 }
78
79 if (src->log_msg_prefix) {
80 err = nfnl_log_msg_set_prefix(dst, src->log_msg_prefix);
81 if (err < 0)
82 return err;
83 }
84
85 if (src->log_msg_hwheader) {
86 err = nfnl_log_msg_set_hwheader(dst, src->log_msg_hwheader,
87 src->log_msg_hwheader_len);
88 if (err < 0)
89 return err;
90 }
91
92 if (src->log_msg_ct) {
93 dst->log_msg_ct = (struct nfnl_ct *) nl_object_clone((struct nl_object *) src->log_msg_ct);
94 if (!dst->log_msg_ct) {
95 return -NLE_NOMEM;
96 }
97 }
98
99 return 0;
100}
101
102static void log_msg_dump(struct nl_object *a, struct nl_dump_params *p)
103{
104 struct nfnl_log_msg *msg = (struct nfnl_log_msg *) a;
105 struct nl_cache *link_cache;
106 char buf[64];
107
108 link_cache = nl_cache_mngt_require_safe("route/link");
109
110 nl_new_line(p);
111
112 if (msg->ce_mask & LOG_MSG_ATTR_PREFIX)
113 nl_dump(p, "%s", msg->log_msg_prefix);
114
115 if (msg->ce_mask & LOG_MSG_ATTR_INDEV) {
116 if (link_cache)
117 nl_dump(p, "IN=%s ",
118 rtnl_link_i2name(link_cache,
119 msg->log_msg_indev,
120 buf, sizeof(buf)));
121 else
122 nl_dump(p, "IN=%d ", msg->log_msg_indev);
123 }
124
125 if (msg->ce_mask & LOG_MSG_ATTR_PHYSINDEV) {
126 if (link_cache)
127 nl_dump(p, "PHYSIN=%s ",
128 rtnl_link_i2name(link_cache,
129 msg->log_msg_physindev,
130 buf, sizeof(buf)));
131 else
132 nl_dump(p, "PHYSIN=%d ", msg->log_msg_physindev);
133 }
134
135 if (msg->ce_mask & LOG_MSG_ATTR_OUTDEV) {
136 if (link_cache)
137 nl_dump(p, "OUT=%s ",
138 rtnl_link_i2name(link_cache,
139 msg->log_msg_outdev,
140 buf, sizeof(buf)));
141 else
142 nl_dump(p, "OUT=%d ", msg->log_msg_outdev);
143 }
144
145 if (msg->ce_mask & LOG_MSG_ATTR_PHYSOUTDEV) {
146 if (link_cache)
147 nl_dump(p, "PHYSOUT=%s ",
148 rtnl_link_i2name(link_cache,
149 msg->log_msg_physoutdev,
150 buf, sizeof(buf)));
151 else
152 nl_dump(p, "PHYSOUT=%d ", msg->log_msg_physoutdev);
153 }
154
155 if (msg->ce_mask & LOG_MSG_ATTR_HWADDR) {
156 int i;
157
158 nl_dump(p, "MAC");
159 for (i = 0; i < msg->log_msg_hwaddr_len; i++)
160 nl_dump(p, "%c%02x", i?':':'=', msg->log_msg_hwaddr[i]);
161 nl_dump(p, " ");
162 }
163
164 /* FIXME: parse the payload to get iptables LOG compatible format */
165
166 if (msg->ce_mask & LOG_MSG_ATTR_FAMILY)
167 nl_dump(p, "FAMILY=%s ",
168 nl_af2str(msg->log_msg_family, buf, sizeof(buf)));
169
170 if (msg->ce_mask & LOG_MSG_ATTR_HWPROTO)
171 nl_dump(p, "HWPROTO=%s ",
172 nl_ether_proto2str(ntohs(msg->log_msg_hwproto),
173 buf, sizeof(buf)));
174
175 if (msg->ce_mask & LOG_MSG_ATTR_HOOK)
176 nl_dump(p, "HOOK=%s ",
177 nfnl_inet_hook2str(msg->log_msg_hook,
178 buf, sizeof(buf)));
179
180 if (msg->ce_mask & LOG_MSG_ATTR_MARK)
181 nl_dump(p, "MARK=%u ", msg->log_msg_mark);
182
183 if (msg->ce_mask & LOG_MSG_ATTR_PAYLOAD)
184 nl_dump(p, "PAYLOADLEN=%d ", msg->log_msg_payload_len);
185
186 if (msg->ce_mask & LOG_MSG_ATTR_UID)
187 nl_dump(p, "UID=%u ", msg->log_msg_uid);
188
189 if (msg->ce_mask & LOG_MSG_ATTR_GID)
190 nl_dump(p, "GID=%u ", msg->log_msg_gid);
191
192 if (msg->ce_mask & LOG_MSG_ATTR_SEQ)
193 nl_dump(p, "SEQ=%d ", msg->log_msg_seq);
194
195 if (msg->ce_mask & LOG_MSG_ATTR_SEQ_GLOBAL)
196 nl_dump(p, "SEQGLOBAL=%d ", msg->log_msg_seq_global);
197
198 if (msg->ce_mask & LOG_MSG_ATTR_HWTYPE)
199 nl_dump(p, "HWTYPE=%u ", msg->log_msg_hwtype);
200
201 if (msg->ce_mask & LOG_MSG_ATTR_HWLEN)
202 nl_dump(p, "HWLEN=%u ", msg->log_msg_hwlen);
203
204 if (msg->ce_mask & LOG_MSG_ATTR_HWHEADER) {
205 int i;
206
207 nl_dump(p, "HWHEADER");
208 for (i = 0; i < msg->log_msg_hwheader_len; i++)
209 nl_dump(p, "%c%02x", i?':':'=', ((uint8_t*) msg->log_msg_hwheader) [i]);
210 nl_dump(p, " ");
211 }
212
213 if (msg->ce_mask & LOG_MSG_ATTR_VLAN_TAG)
214 nl_dump(p, "VLAN=%d CFI=%d PRIO=%d",
215 (int) nfnl_log_msg_get_vlan_id(msg),
216 (int) nfnl_log_msg_get_vlan_cfi(msg),
217 (int) nfnl_log_msg_get_vlan_prio(msg));
218
219 if (msg->ce_mask & LOG_MSG_ATTR_CT_INFO)
220 nl_dump(p, "CTINFO=%u ", msg->log_msg_ct_info);
221
222 nl_dump(p, "\n");
223
224 if (msg->ce_mask & LOG_MSG_ATTR_CT)
225 ct_obj_ops.oo_dump[NL_DUMP_LINE]((struct nl_object *)msg->log_msg_ct, p);
226
227 if (link_cache)
228 nl_cache_put(link_cache);
229}
230
231/**
232 * @name Allocation/Freeing
233 * @{
234 */
235
236struct nfnl_log_msg *nfnl_log_msg_alloc(void)
237{
238 return (struct nfnl_log_msg *) nl_object_alloc(&log_msg_obj_ops);
239}
240
241void nfnl_log_msg_get(struct nfnl_log_msg *msg)
242{
243 nl_object_get((struct nl_object *) msg);
244}
245
246void nfnl_log_msg_put(struct nfnl_log_msg *msg)
247{
248 nl_object_put((struct nl_object *) msg);
249}
250
251/** @} */
252
253/**
254 * @name Attributes
255 * @{
256 */
257
258void nfnl_log_msg_set_family(struct nfnl_log_msg *msg, uint8_t family)
259{
260 msg->log_msg_family = family;
261 msg->ce_mask |= LOG_MSG_ATTR_FAMILY;
262}
263
264uint8_t nfnl_log_msg_get_family(const struct nfnl_log_msg *msg)
265{
266 if (msg->ce_mask & LOG_MSG_ATTR_FAMILY)
267 return msg->log_msg_family;
268 else
269 return AF_UNSPEC;
270}
271
272void nfnl_log_msg_set_hwproto(struct nfnl_log_msg *msg, uint16_t hwproto)
273{
274 msg->log_msg_hwproto = hwproto;
275 msg->ce_mask |= LOG_MSG_ATTR_HWPROTO;
276}
277
278int nfnl_log_msg_test_hwproto(const struct nfnl_log_msg *msg)
279{
280 return !!(msg->ce_mask & LOG_MSG_ATTR_HWPROTO);
281}
282
283uint16_t nfnl_log_msg_get_hwproto(const struct nfnl_log_msg *msg)
284{
285 return msg->log_msg_hwproto;
286}
287
288void nfnl_log_msg_set_hook(struct nfnl_log_msg *msg, uint8_t hook)
289{
290 msg->log_msg_hook = hook;
291 msg->ce_mask |= LOG_MSG_ATTR_HOOK;
292}
293
294int nfnl_log_msg_test_hook(const struct nfnl_log_msg *msg)
295{
296 return !!(msg->ce_mask & LOG_MSG_ATTR_HOOK);
297}
298
299uint8_t nfnl_log_msg_get_hook(const struct nfnl_log_msg *msg)
300{
301 return msg->log_msg_hook;
302}
303
304void nfnl_log_msg_set_mark(struct nfnl_log_msg *msg, uint32_t mark)
305{
306 msg->log_msg_mark = mark;
307 msg->ce_mask |= LOG_MSG_ATTR_MARK;
308}
309
310int nfnl_log_msg_test_mark(const struct nfnl_log_msg *msg)
311{
312 return !!(msg->ce_mask & LOG_MSG_ATTR_MARK);
313}
314
315uint32_t nfnl_log_msg_get_mark(const struct nfnl_log_msg *msg)
316{
317 return msg->log_msg_mark;
318}
319
320void nfnl_log_msg_set_timestamp(struct nfnl_log_msg *msg, struct timeval *tv)
321{
322 msg->log_msg_timestamp.tv_sec = tv->tv_sec;
323 msg->log_msg_timestamp.tv_usec = tv->tv_usec;
324 msg->ce_mask |= LOG_MSG_ATTR_TIMESTAMP;
325}
326
327const struct timeval *nfnl_log_msg_get_timestamp(const struct nfnl_log_msg *msg)
328{
329 if (!(msg->ce_mask & LOG_MSG_ATTR_TIMESTAMP))
330 return NULL;
331 return &msg->log_msg_timestamp;
332}
333
334void nfnl_log_msg_set_indev(struct nfnl_log_msg *msg, uint32_t indev)
335{
336 msg->log_msg_indev = indev;
337 msg->ce_mask |= LOG_MSG_ATTR_INDEV;
338}
339
340uint32_t nfnl_log_msg_get_indev(const struct nfnl_log_msg *msg)
341{
342 return msg->log_msg_indev;
343}
344
345void nfnl_log_msg_set_outdev(struct nfnl_log_msg *msg, uint32_t outdev)
346{
347 msg->log_msg_outdev = outdev;
348 msg->ce_mask |= LOG_MSG_ATTR_OUTDEV;
349}
350
351uint32_t nfnl_log_msg_get_outdev(const struct nfnl_log_msg *msg)
352{
353 return msg->log_msg_outdev;
354}
355
356void nfnl_log_msg_set_physindev(struct nfnl_log_msg *msg, uint32_t physindev)
357{
358 msg->log_msg_physindev = physindev;
359 msg->ce_mask |= LOG_MSG_ATTR_PHYSINDEV;
360}
361
362uint32_t nfnl_log_msg_get_physindev(const struct nfnl_log_msg *msg)
363{
364 return msg->log_msg_physindev;
365}
366
367void nfnl_log_msg_set_physoutdev(struct nfnl_log_msg *msg, uint32_t physoutdev)
368{
369 msg->log_msg_physoutdev = physoutdev;
370 msg->ce_mask |= LOG_MSG_ATTR_PHYSOUTDEV;
371}
372
373uint32_t nfnl_log_msg_get_physoutdev(const struct nfnl_log_msg *msg)
374{
375 return msg->log_msg_physoutdev;
376}
377
378void nfnl_log_msg_set_hwaddr(struct nfnl_log_msg *msg, uint8_t *hwaddr, int len)
379{
380 if (len < 0)
381 len = 0;
382 else if (((unsigned)len) > sizeof(msg->log_msg_hwaddr))
383 len = sizeof(msg->log_msg_hwaddr);
384 msg->log_msg_hwaddr_len = len;
385 memcpy(msg->log_msg_hwaddr, hwaddr, len);
386 msg->ce_mask |= LOG_MSG_ATTR_HWADDR;
387}
388
389const uint8_t *nfnl_log_msg_get_hwaddr(const struct nfnl_log_msg *msg, int *len)
390{
391 if (!(msg->ce_mask & LOG_MSG_ATTR_HWADDR)) {
392 *len = 0;
393 return NULL;
394 }
395
396 *len = msg->log_msg_hwaddr_len;
397 return msg->log_msg_hwaddr;
398}
399
400int nfnl_log_msg_set_payload(struct nfnl_log_msg *msg, uint8_t *payload, int len)
401{
402 uint8_t *p = NULL;
403
404 if (len < 0)
405 return -NLE_INVAL;
406
407 p = _nl_memdup(payload, len);
408 if (!p && len > 0)
409 return -NLE_NOMEM;
410
411 free(msg->log_msg_payload);
412 msg->log_msg_payload = p;
413 msg->log_msg_payload_len = len;
414 if (len > 0)
415 msg->ce_mask |= LOG_MSG_ATTR_PAYLOAD;
416 else
417 msg->ce_mask &= ~LOG_MSG_ATTR_PAYLOAD;
418 return 0;
419}
420
421const void *nfnl_log_msg_get_payload(const struct nfnl_log_msg *msg, int *len)
422{
423 if (!(msg->ce_mask & LOG_MSG_ATTR_PAYLOAD)) {
424 *len = 0;
425 return NULL;
426 }
427
428 *len = msg->log_msg_payload_len;
429 return msg->log_msg_payload;
430}
431
432int nfnl_log_msg_set_prefix(struct nfnl_log_msg *msg, void *prefix)
433{
434 char *p = NULL;
435
436 if (prefix) {
437 p = strdup(prefix);
438 if (!p)
439 return -NLE_NOMEM;
440 }
441
442 free(msg->log_msg_prefix);
443 msg->log_msg_prefix = p;
444
445 if (p)
446 msg->ce_mask |= LOG_MSG_ATTR_PREFIX;
447 else
448 msg->ce_mask &= ~LOG_MSG_ATTR_PREFIX;
449 return 0;
450}
451
452const char *nfnl_log_msg_get_prefix(const struct nfnl_log_msg *msg)
453{
454 return msg->log_msg_prefix;
455}
456
457void nfnl_log_msg_set_uid(struct nfnl_log_msg *msg, uint32_t uid)
458{
459 msg->log_msg_uid = uid;
460 msg->ce_mask |= LOG_MSG_ATTR_UID;
461}
462
463int nfnl_log_msg_test_uid(const struct nfnl_log_msg *msg)
464{
465 return !!(msg->ce_mask & LOG_MSG_ATTR_UID);
466}
467
468uint32_t nfnl_log_msg_get_uid(const struct nfnl_log_msg *msg)
469{
470 return msg->log_msg_uid;
471}
472
473void nfnl_log_msg_set_gid(struct nfnl_log_msg *msg, uint32_t gid)
474{
475 msg->log_msg_gid = gid;
476 msg->ce_mask |= LOG_MSG_ATTR_GID;
477}
478
479int nfnl_log_msg_test_gid(const struct nfnl_log_msg *msg)
480{
481 return !!(msg->ce_mask & LOG_MSG_ATTR_GID);
482}
483
484uint32_t nfnl_log_msg_get_gid(const struct nfnl_log_msg *msg)
485{
486 return msg->log_msg_gid;
487}
488
489
490void nfnl_log_msg_set_seq(struct nfnl_log_msg *msg, uint32_t seq)
491{
492 msg->log_msg_seq = seq;
493 msg->ce_mask |= LOG_MSG_ATTR_SEQ;
494}
495
496int nfnl_log_msg_test_seq(const struct nfnl_log_msg *msg)
497{
498 return !!(msg->ce_mask & LOG_MSG_ATTR_SEQ);
499}
500
501uint32_t nfnl_log_msg_get_seq(const struct nfnl_log_msg *msg)
502{
503 return msg->log_msg_seq;
504}
505
506void nfnl_log_msg_set_seq_global(struct nfnl_log_msg *msg, uint32_t seq_global)
507{
508 msg->log_msg_seq_global = seq_global;
509 msg->ce_mask |= LOG_MSG_ATTR_SEQ_GLOBAL;
510}
511
512int nfnl_log_msg_test_seq_global(const struct nfnl_log_msg *msg)
513{
514 return !!(msg->ce_mask & LOG_MSG_ATTR_SEQ_GLOBAL);
515}
516
517uint32_t nfnl_log_msg_get_seq_global(const struct nfnl_log_msg *msg)
518{
519 return msg->log_msg_seq_global;
520}
521
522void nfnl_log_msg_set_hwtype(struct nfnl_log_msg *msg, uint16_t hwtype)
523{
524 msg->log_msg_hwtype = hwtype;
525 msg->ce_mask |= LOG_MSG_ATTR_HWTYPE;
526}
527
528int nfnl_log_msg_test_hwtype(const struct nfnl_log_msg *msg)
529{
530 return !!(msg->ce_mask & LOG_MSG_ATTR_HWTYPE);
531}
532
533uint16_t nfnl_log_msg_get_hwtype(const struct nfnl_log_msg *msg)
534{
535 return msg->log_msg_hwtype;
536}
537
538void nfnl_log_msg_set_hwlen(struct nfnl_log_msg *msg, uint16_t hwlen)
539{
540 msg->log_msg_hwlen = hwlen;
541 msg->ce_mask |= LOG_MSG_ATTR_HWLEN;
542}
543
544int nfnl_log_msg_test_hwlen(const struct nfnl_log_msg *msg)
545{
546 return !!(msg->ce_mask & LOG_MSG_ATTR_HWLEN);
547}
548
549uint16_t nfnl_log_msg_get_hwlen(const struct nfnl_log_msg *msg)
550{
551 return msg->log_msg_hwlen;
552}
553
554int nfnl_log_msg_set_hwheader(struct nfnl_log_msg *msg, void *data, int len)
555{
556 void *p = NULL;
557
558 if (len < 0)
559 return -NLE_INVAL;
560
561 p = _nl_memdup(data, len);
562 if (!p && len > 0)
563 return -NLE_NOMEM;
564
565 free(msg->log_msg_hwheader);
566 msg->log_msg_hwheader = p;
567 msg->log_msg_hwheader_len = len;
568 if (len > 0)
569 msg->ce_mask |= LOG_MSG_ATTR_HWHEADER;
570 else
571 msg->ce_mask &= ~LOG_MSG_ATTR_HWHEADER;
572 return 0;
573}
574
575int nfnl_log_msg_test_hwheader(const struct nfnl_log_msg *msg)
576{
577 return !!(msg->ce_mask & LOG_MSG_ATTR_HWHEADER);
578}
579
580const void *nfnl_log_msg_get_hwheader(const struct nfnl_log_msg *msg, int *len)
581{
582 if (!(msg->ce_mask & LOG_MSG_ATTR_HWHEADER)) {
583 *len = 0;
584 return NULL;
585 }
586
587 *len = msg->log_msg_hwheader_len;
588 return msg->log_msg_hwheader;
589}
590
591void nfnl_log_msg_set_vlan_proto(struct nfnl_log_msg *msg, uint16_t vlan_proto)
592{
593 msg->log_msg_vlan_proto = vlan_proto;
594 msg->ce_mask |= LOG_MSG_ATTR_VLAN_PROTO;
595}
596
597int nfnl_log_msg_test_vlan_proto(const struct nfnl_log_msg *msg)
598{
599 return !!(msg->ce_mask & LOG_MSG_ATTR_VLAN_PROTO);
600}
601
602uint16_t nfnl_log_msg_get_vlan_proto(const struct nfnl_log_msg *msg)
603{
604 return msg->log_msg_vlan_proto;
605}
606
607void nfnl_log_msg_set_vlan_tag(struct nfnl_log_msg *msg, uint16_t vlan_tag)
608{
609 msg->log_msg_vlan_tag = vlan_tag;
610 msg->ce_mask |= LOG_MSG_ATTR_VLAN_TAG;
611}
612
613int nfnl_log_msg_test_vlan_tag(const struct nfnl_log_msg *msg)
614{
615 return !!(msg->ce_mask & LOG_MSG_ATTR_VLAN_TAG);
616}
617
618uint16_t nfnl_log_msg_get_vlan_tag(const struct nfnl_log_msg *msg)
619{
620 return msg->log_msg_vlan_tag;
621}
622
623uint16_t nfnl_log_msg_get_vlan_id(const struct nfnl_log_msg *msg)
624{
625 return msg->log_msg_vlan_tag & 0x0fff;
626}
627
628uint16_t nfnl_log_msg_get_vlan_cfi(const struct nfnl_log_msg *msg)
629{
630 return !!(msg->log_msg_vlan_tag & 0x1000);
631}
632
633uint16_t nfnl_log_msg_get_vlan_prio(const struct nfnl_log_msg *msg)
634{
635 return (msg->log_msg_vlan_tag & 0xe000 ) >> 13;
636}
637
638void nfnl_log_msg_set_ct_info(struct nfnl_log_msg *msg, uint32_t ct_info)
639{
640 msg->log_msg_ct_info = ct_info;
641 msg->ce_mask |= LOG_MSG_ATTR_CT_INFO;
642}
643
644int nfnl_log_msg_test_ct_info(const struct nfnl_log_msg *msg)
645{
646 return !!(msg->ce_mask & LOG_MSG_ATTR_CT_INFO);
647}
648
649uint32_t nfnl_log_msg_get_ct_info(const struct nfnl_log_msg *msg)
650{
651 return msg->log_msg_ct_info;
652}
653
654void nfnl_log_msg_set_ct(struct nfnl_log_msg *msg, struct nfnl_ct *ct)
655{
656 msg->log_msg_ct = (struct nfnl_ct *) nl_object_clone((struct nl_object *)ct);
657 msg->ce_mask |= LOG_MSG_ATTR_CT;
658}
659
660int nfnl_log_msg_test_ct(const struct nfnl_log_msg *msg)
661{
662 return !!(msg->ce_mask & LOG_MSG_ATTR_CT);
663}
664
665struct nfnl_ct *nfnl_log_msg_get_ct(const struct nfnl_log_msg *msg)
666{
667 return msg->log_msg_ct;
668}
669
670/** @} */
671
672struct nl_object_ops log_msg_obj_ops = {
673 .oo_name = "netfilter/log_msg",
674 .oo_size = sizeof(struct nfnl_log_msg),
675 .oo_free_data = log_msg_free_data,
676 .oo_clone = log_msg_clone,
677 .oo_dump = {
678 [NL_DUMP_LINE] = log_msg_dump,
679 [NL_DUMP_DETAILS] = log_msg_dump,
680 [NL_DUMP_STATS] = log_msg_dump,
681 },
682};
683
684/** @} */
nl_cache_mngt_require_safe
struct nl_cache * nl_cache_mngt_require_safe(const char *name)
Return cache previously provided via nl_cache_mngt_provide()
Definition cache_mngt.c:430
rtnl_link_i2name
char * rtnl_link_i2name(struct nl_cache *cache, int ifindex, char *dst, size_t len)
Translate interface index to corresponding link name.
Definition link.c:1499
nl_object_clone
struct nl_object * nl_object_clone(struct nl_object *obj)
Allocate a new object and copy all data from an existing object.
Definition object.c:111
nl_object_put
void nl_object_put(struct nl_object *obj)
Release a reference from an object.
Definition object.c:221
nl_object_get
void nl_object_get(struct nl_object *obj)
Acquire a reference on a object.
Definition object.c:210
nl_object_alloc
struct nl_object * nl_object_alloc(struct nl_object_ops *ops)
Allocate a new object of kind specified by the operations handle.
Definition object.c:55
nl_dump
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
Definition utils.c:1015
nl_new_line
void nl_new_line(struct nl_dump_params *params)
Handle a new line while dumping.
Definition utils.c:966
NL_DUMP_STATS
@ NL_DUMP_STATS
Dump all attributes including statistics.
Definition types.h:22
NL_DUMP_LINE
@ NL_DUMP_LINE
Dump object briefly on one line.
Definition types.h:20
NL_DUMP_DETAILS
@ NL_DUMP_DETAILS
Dump all attributes but no statistics.
Definition types.h:21
nfnl_ct
Definition nl-netfilter.h:40
nfnl_log_msg
Definition nl-netfilter.h:104
nl_dump_params
Dumping parameters.
Definition types.h:32