12#include <linux/netfilter/nfnetlink_conntrack.h>
13#include <linux/netfilter/nf_conntrack_common.h>
15#include <linux/netfilter/nf_conntrack_tcp.h>
17#include <netlink/netfilter/nfnl.h>
18#include <netlink/netfilter/ct.h>
20#include "nl-priv-dynamic-core/object-api.h"
21#include "nl-netfilter.h"
22#include "nl-priv-dynamic-core/nl-core.h"
25#define CT_ATTR_FAMILY (1UL << 0)
26#define CT_ATTR_PROTO (1UL << 1)
28#define CT_ATTR_TCP_STATE (1UL << 2)
30#define CT_ATTR_STATUS (1UL << 3)
31#define CT_ATTR_TIMEOUT (1UL << 4)
32#define CT_ATTR_MARK (1UL << 5)
33#define CT_ATTR_USE (1UL << 6)
34#define CT_ATTR_ID (1UL << 7)
36#define CT_ATTR_ORIG_SRC (1UL << 8)
37#define CT_ATTR_ORIG_DST (1UL << 9)
38#define CT_ATTR_ORIG_SRC_PORT (1UL << 10)
39#define CT_ATTR_ORIG_DST_PORT (1UL << 11)
40#define CT_ATTR_ORIG_ICMP_ID (1UL << 12)
41#define CT_ATTR_ORIG_ICMP_TYPE (1UL << 13)
42#define CT_ATTR_ORIG_ICMP_CODE (1UL << 14)
43#define CT_ATTR_ORIG_PACKETS (1UL << 15)
44#define CT_ATTR_ORIG_BYTES (1UL << 16)
46#define CT_ATTR_REPL_SRC (1UL << 17)
47#define CT_ATTR_REPL_DST (1UL << 18)
48#define CT_ATTR_REPL_SRC_PORT (1UL << 19)
49#define CT_ATTR_REPL_DST_PORT (1UL << 20)
50#define CT_ATTR_REPL_ICMP_ID (1UL << 21)
51#define CT_ATTR_REPL_ICMP_TYPE (1UL << 22)
52#define CT_ATTR_REPL_ICMP_CODE (1UL << 23)
53#define CT_ATTR_REPL_PACKETS (1UL << 24)
54#define CT_ATTR_REPL_BYTES (1UL << 25)
55#define CT_ATTR_TIMESTAMP (1UL << 26)
56#define CT_ATTR_ZONE (1UL << 27)
59static void ct_free_data(
struct nl_object *c)
72static int ct_clone(
struct nl_object *_dst,
struct nl_object *_src)
78 dst->ct_orig.src = NULL;
79 dst->ct_orig.dst = NULL;
80 dst->ct_repl.src = NULL;
81 dst->ct_repl.dst = NULL;
83 if (src->ct_orig.src) {
87 dst->ct_orig.src = addr;
90 if (src->ct_orig.dst) {
94 dst->ct_orig.dst = addr;
97 if (src->ct_repl.src) {
101 dst->ct_repl.src = addr;
104 if (src->ct_repl.dst) {
108 dst->ct_repl.dst = addr;
114static void dump_addr(
struct nl_dump_params *p,
struct nl_addr *addr,
int port)
129 if (nfnl_ct_test_icmp_type(ct, reply))
130 nl_dump(p,
"icmp type %d ", nfnl_ct_get_icmp_type(ct, reply));
132 if (nfnl_ct_test_icmp_code(ct, reply))
133 nl_dump(p,
"code %d ", nfnl_ct_get_icmp_code(ct, reply));
135 if (nfnl_ct_test_icmp_id(ct, reply))
136 nl_dump(p,
"id %d ", nfnl_ct_get_icmp_id(ct, reply));
141 struct nl_addr *orig_src, *orig_dst, *reply_src, *reply_dst;
142 int orig_sport = 0, orig_dport = 0, reply_sport = 0, reply_dport = 0;
145 orig_src = nfnl_ct_get_src(ct, 0);
146 orig_dst = nfnl_ct_get_dst(ct, 0);
147 reply_src = nfnl_ct_get_src(ct, 1);
148 reply_dst = nfnl_ct_get_dst(ct, 1);
150 if (nfnl_ct_test_src_port(ct, 0))
151 orig_sport = nfnl_ct_get_src_port(ct, 0);
153 if (nfnl_ct_test_dst_port(ct, 0))
154 orig_dport = nfnl_ct_get_dst_port(ct, 0);
156 if (nfnl_ct_test_src_port(ct, 1))
157 reply_sport = nfnl_ct_get_src_port(ct, 1);
159 if (nfnl_ct_test_dst_port(ct, 1))
160 reply_dport = nfnl_ct_get_dst_port(ct, 1);
162 if (orig_src && orig_dst && reply_src && reply_dst &&
163 orig_sport == reply_dport && orig_dport == reply_sport &&
168 dump_addr(p, orig_src, orig_sport);
169 nl_dump(p, sync ?
"<-> " :
"-> ");
170 dump_addr(p, orig_dst, orig_dport);
174 dump_addr(p, reply_src, reply_sport);
176 dump_addr(p, reply_dst, reply_dport);
182static void ct_dump_line(
struct nl_object *a,
struct nl_dump_params *p)
189 if (nfnl_ct_test_proto(ct))
191 nl_ip_proto2str(nfnl_ct_get_proto(ct), buf,
sizeof(buf)));
193 if (nfnl_ct_test_tcp_state(ct))
195 nfnl_ct_tcp_state2str(nfnl_ct_get_tcp_state(ct),
198 ct_dump_tuples(ct, p);
200 if (nfnl_ct_test_mark(ct) && nfnl_ct_get_mark(ct))
201 nl_dump(p,
"mark %u ", nfnl_ct_get_mark(ct));
203 if (nfnl_ct_test_zone(ct))
204 nl_dump(p,
"zone %hu ", nfnl_ct_get_zone(ct));
206 if (nfnl_ct_test_timestamp(ct)) {
208 int64_t delta_time = tstamp->stop - tstamp->start;
211 delta_time /= NSEC_PER_SEC;
214 nl_dump(p,
"delta-time %llu ", (
long long unsigned)delta_time);
220static void ct_dump_details(
struct nl_object *a,
struct nl_dump_params *p)
228 nl_dump(p,
" id 0x%x ", ct->ct_id);
229 if (ct->ce_mask & CT_ATTR_FAMILY)
230 nl_dump_line(p,
"family %s ",
231 nl_af2str(ct->ct_family, buf,
sizeof(buf)));
233 if (nfnl_ct_test_use(ct))
234 nl_dump(p,
"refcnt %u ", nfnl_ct_get_use(ct));
236 if (nfnl_ct_test_timeout(ct)) {
237 uint64_t timeout_ms = nfnl_ct_get_timeout(ct) * 1000UL;
245#define PRINT_FLAG(str) \
246 { nl_dump(p, "%s%s", fp++ ? "," : "", (str)); }
248 if (ct->ct_status & IPS_EXPECTED)
249 PRINT_FLAG(
"EXPECTED");
250 if (!(ct->ct_status & IPS_SEEN_REPLY))
251 PRINT_FLAG(
"NOREPLY");
252 if (ct->ct_status & IPS_ASSURED)
253 PRINT_FLAG(
"ASSURED");
254 if (!(ct->ct_status & IPS_CONFIRMED))
255 PRINT_FLAG(
"NOTSENT");
256 if (ct->ct_status & IPS_SRC_NAT)
258 if (ct->ct_status & IPS_DST_NAT)
260 if (ct->ct_status & IPS_SEQ_ADJUST)
261 PRINT_FLAG(
"SEQADJUST");
262 if (!(ct->ct_status & IPS_SRC_NAT_DONE))
263 PRINT_FLAG(
"SNAT_INIT");
264 if (!(ct->ct_status & IPS_DST_NAT_DONE))
265 PRINT_FLAG(
"DNAT_INIT");
266 if (ct->ct_status & IPS_DYING)
268 if (ct->ct_status & IPS_FIXED_TIMEOUT)
269 PRINT_FLAG(
"FIXED_TIMEOUT");
277static void ct_dump_stats(
struct nl_object *a,
struct nl_dump_params *p)
283 const char *
const names[] = {
"rx",
"tx"};
286 ct_dump_details(a, p);
288 if (!nfnl_ct_test_bytes(ct, 0) ||
289 !nfnl_ct_test_packets(ct, 0) ||
290 !nfnl_ct_test_bytes(ct, 1) ||
291 !nfnl_ct_test_packets(ct, 1))
293 nl_dump_line(p,
" Statistics are not available.\n");
294 nl_dump_line(p,
" Please set sysctl net.netfilter.nf_conntrack_acct=1\n");
295 nl_dump_line(p,
" (Require kernel 2.6.27)\n");
299 nl_dump_line(p,
" # packets volume\n");
300 for (i=0; i<=1; i++) {
302 packets = nfnl_ct_get_packets(ct, i);
303 nl_dump_line(p,
" %s %10" PRIu64
" %7.2f %s\n", names[i], packets, res, unit);
307static uint64_t ct_compare(
struct nl_object *_a,
struct nl_object *_b,
308 uint64_t attrs,
int flags)
314#define _DIFF(ATTR, EXPR) ATTR_DIFF(attrs, ATTR, a, b, EXPR)
315#define _DIFF_VAL(ATTR, FIELD) _DIFF(ATTR, a->FIELD != b->FIELD)
316#define _DIFF_ADDR(ATTR, FIELD) \
317 ((flags & LOOSE_COMPARISON) ? \
318 _DIFF(ATTR, nl_addr_cmp_prefix(a->FIELD, b->FIELD)) : \
319 _DIFF(ATTR, nl_addr_cmp(a->FIELD, b->FIELD)))
320 diff |= _DIFF_VAL(CT_ATTR_FAMILY, ct_family);
321 diff |= _DIFF_VAL(CT_ATTR_PROTO, ct_proto);
322 diff |= _DIFF_VAL(CT_ATTR_TCP_STATE, ct_protoinfo.tcp.state);
323 diff |= _DIFF_VAL(CT_ATTR_TIMEOUT, ct_timeout);
324 diff |= _DIFF_VAL(CT_ATTR_MARK, ct_mark);
325 diff |= _DIFF_VAL(CT_ATTR_USE, ct_use);
326 diff |= _DIFF_VAL(CT_ATTR_ID, ct_id);
327 diff |= _DIFF_ADDR(CT_ATTR_ORIG_SRC, ct_orig.src);
328 diff |= _DIFF_ADDR(CT_ATTR_ORIG_DST, ct_orig.dst);
329 diff |= _DIFF_VAL(CT_ATTR_ORIG_SRC_PORT, ct_orig.proto.port.src);
330 diff |= _DIFF_VAL(CT_ATTR_ORIG_DST_PORT, ct_orig.proto.port.dst);
331 diff |= _DIFF_VAL(CT_ATTR_ORIG_ICMP_ID, ct_orig.proto.icmp.id);
332 diff |= _DIFF_VAL(CT_ATTR_ORIG_ICMP_TYPE, ct_orig.proto.icmp.type);
333 diff |= _DIFF_VAL(CT_ATTR_ORIG_ICMP_CODE, ct_orig.proto.icmp.code);
334 diff |= _DIFF_VAL(CT_ATTR_ORIG_PACKETS, ct_orig.packets);
335 diff |= _DIFF_VAL(CT_ATTR_ORIG_BYTES, ct_orig.bytes);
336 diff |= _DIFF_ADDR(CT_ATTR_REPL_SRC, ct_repl.src);
337 diff |= _DIFF_ADDR(CT_ATTR_REPL_DST, ct_repl.dst);
338 diff |= _DIFF_VAL(CT_ATTR_REPL_SRC_PORT, ct_repl.proto.port.src);
339 diff |= _DIFF_VAL(CT_ATTR_REPL_DST_PORT, ct_repl.proto.port.dst);
340 diff |= _DIFF_VAL(CT_ATTR_REPL_ICMP_ID, ct_repl.proto.icmp.id);
341 diff |= _DIFF_VAL(CT_ATTR_REPL_ICMP_TYPE, ct_repl.proto.icmp.type);
342 diff |= _DIFF_VAL(CT_ATTR_REPL_ICMP_CODE, ct_repl.proto.icmp.code);
343 diff |= _DIFF_VAL(CT_ATTR_REPL_PACKETS, ct_repl.packets);
344 diff |= _DIFF_VAL(CT_ATTR_REPL_BYTES, ct_repl.bytes);
346 if (flags & LOOSE_COMPARISON)
347 diff |= _DIFF(CT_ATTR_STATUS, (a->ct_status ^ b->ct_status) &
350 diff |= _DIFF(CT_ATTR_STATUS, a->ct_status != b->ct_status);
358static const struct trans_tbl ct_attrs[] = {
359 __ADD(CT_ATTR_FAMILY, family),
360 __ADD(CT_ATTR_PROTO, proto),
361 __ADD(CT_ATTR_TCP_STATE, tcpstate),
362 __ADD(CT_ATTR_STATUS, status),
363 __ADD(CT_ATTR_TIMEOUT, timeout),
364 __ADD(CT_ATTR_MARK, mark),
365 __ADD(CT_ATTR_USE, use),
366 __ADD(CT_ATTR_ID,
id),
367 __ADD(CT_ATTR_ORIG_SRC, origsrc),
368 __ADD(CT_ATTR_ORIG_DST, origdst),
369 __ADD(CT_ATTR_ORIG_SRC_PORT, origsrcport),
370 __ADD(CT_ATTR_ORIG_DST_PORT, origdstport),
371 __ADD(CT_ATTR_ORIG_ICMP_ID, origicmpid),
372 __ADD(CT_ATTR_ORIG_ICMP_TYPE, origicmptype),
373 __ADD(CT_ATTR_ORIG_ICMP_CODE, origicmpcode),
374 __ADD(CT_ATTR_ORIG_PACKETS, origpackets),
375 __ADD(CT_ATTR_ORIG_BYTES, origbytes),
376 __ADD(CT_ATTR_REPL_SRC, replysrc),
377 __ADD(CT_ATTR_REPL_DST, replydst),
378 __ADD(CT_ATTR_REPL_SRC_PORT, replysrcport),
379 __ADD(CT_ATTR_REPL_DST_PORT, replydstport),
380 __ADD(CT_ATTR_REPL_ICMP_ID, replyicmpid),
381 __ADD(CT_ATTR_REPL_ICMP_TYPE, replyicmptype),
382 __ADD(CT_ATTR_REPL_ICMP_CODE, replyicmpcode),
383 __ADD(CT_ATTR_REPL_PACKETS, replypackets),
384 __ADD(CT_ATTR_REPL_BYTES, replybytes),
387static char *ct_attrs2str(
int attrs,
char *buf,
size_t len)
389 return __flags2str(attrs, buf, len, ct_attrs, ARRAY_SIZE(ct_attrs));
397struct nfnl_ct *nfnl_ct_alloc(
void)
402void nfnl_ct_get(
struct nfnl_ct *ct)
407void nfnl_ct_put(
struct nfnl_ct *ct)
419void nfnl_ct_set_family(
struct nfnl_ct *ct, uint8_t family)
421 ct->ct_family = family;
422 ct->ce_mask |= CT_ATTR_FAMILY;
425uint8_t nfnl_ct_get_family(
const struct nfnl_ct *ct)
427 if (ct->ce_mask & CT_ATTR_FAMILY)
428 return ct->ct_family;
433void nfnl_ct_set_proto(
struct nfnl_ct *ct, uint8_t proto)
435 ct->ct_proto = proto;
436 ct->ce_mask |= CT_ATTR_PROTO;
439int nfnl_ct_test_proto(
const struct nfnl_ct *ct)
441 return !!(ct->ce_mask & CT_ATTR_PROTO);
444uint8_t nfnl_ct_get_proto(
const struct nfnl_ct *ct)
449void nfnl_ct_set_tcp_state(
struct nfnl_ct *ct, uint8_t state)
451 ct->ct_protoinfo.tcp.state = state;
452 ct->ce_mask |= CT_ATTR_TCP_STATE;
455int nfnl_ct_test_tcp_state(
const struct nfnl_ct *ct)
457 return !!(ct->ce_mask & CT_ATTR_TCP_STATE);
460uint8_t nfnl_ct_get_tcp_state(
const struct nfnl_ct *ct)
462 return ct->ct_protoinfo.tcp.state;
465static const struct trans_tbl tcp_states[] = {
466 __ADD(TCP_CONNTRACK_NONE,NONE),
467 __ADD(TCP_CONNTRACK_SYN_SENT,SYN_SENT),
468 __ADD(TCP_CONNTRACK_SYN_RECV,SYN_RECV),
469 __ADD(TCP_CONNTRACK_ESTABLISHED,ESTABLISHED),
470 __ADD(TCP_CONNTRACK_FIN_WAIT,FIN_WAIT),
471 __ADD(TCP_CONNTRACK_CLOSE_WAIT,CLOSE_WAIT),
472 __ADD(TCP_CONNTRACK_LAST_ACK,LAST_ACK),
473 __ADD(TCP_CONNTRACK_TIME_WAIT,TIME_WAIT),
474 __ADD(TCP_CONNTRACK_CLOSE,CLOSE),
475 __ADD(TCP_CONNTRACK_LISTEN,LISTEN),
478char *nfnl_ct_tcp_state2str(uint8_t state,
char *buf,
size_t len)
480 return __type2str(state, buf, len, tcp_states, ARRAY_SIZE(tcp_states));
483int nfnl_ct_str2tcp_state(
const char *name)
485 return __str2type(name, tcp_states, ARRAY_SIZE(tcp_states));
488void nfnl_ct_set_status(
struct nfnl_ct *ct, uint32_t status)
490 ct->ct_status_mask |= status;
491 ct->ct_status |= status;
492 ct->ce_mask |= CT_ATTR_STATUS;
495void nfnl_ct_unset_status(
struct nfnl_ct *ct, uint32_t status)
497 ct->ct_status_mask |= status;
498 ct->ct_status &= ~status;
499 ct->ce_mask |= CT_ATTR_STATUS;
502int nfnl_ct_test_status(
const struct nfnl_ct *ct)
504 return !!(ct->ce_mask & CT_ATTR_STATUS);
507uint32_t nfnl_ct_get_status(
const struct nfnl_ct *ct)
509 return ct->ct_status;
512static const struct trans_tbl status_flags[] = {
513 __ADD(IPS_EXPECTED, expected),
514 __ADD(IPS_SEEN_REPLY, seen_reply),
515 __ADD(IPS_ASSURED, assured),
516 __ADD(IPS_CONFIRMED, confirmed),
517 __ADD(IPS_SRC_NAT, snat),
518 __ADD(IPS_DST_NAT, dnat),
519 __ADD(IPS_SEQ_ADJUST, seqadjust),
520 __ADD(IPS_SRC_NAT_DONE, snat_done),
521 __ADD(IPS_DST_NAT_DONE, dnat_done),
522 __ADD(IPS_DYING, dying),
523 __ADD(IPS_FIXED_TIMEOUT, fixed_timeout),
526char * nfnl_ct_status2str(
int flags,
char *buf,
size_t len)
528 return __flags2str(flags, buf, len, status_flags,
529 ARRAY_SIZE(status_flags));
532int nfnl_ct_str2status(
const char *name)
534 return __str2flags(name, status_flags, ARRAY_SIZE(status_flags));
537void nfnl_ct_set_timeout(
struct nfnl_ct *ct, uint32_t timeout)
539 ct->ct_timeout = timeout;
540 ct->ce_mask |= CT_ATTR_TIMEOUT;
543int nfnl_ct_test_timeout(
const struct nfnl_ct *ct)
545 return !!(ct->ce_mask & CT_ATTR_TIMEOUT);
548uint32_t nfnl_ct_get_timeout(
const struct nfnl_ct *ct)
550 return ct->ct_timeout;
553void nfnl_ct_set_mark(
struct nfnl_ct *ct, uint32_t mark)
556 ct->ce_mask |= CT_ATTR_MARK;
559int nfnl_ct_test_mark(
const struct nfnl_ct *ct)
561 return !!(ct->ce_mask & CT_ATTR_MARK);
564uint32_t nfnl_ct_get_mark(
const struct nfnl_ct *ct)
569void nfnl_ct_set_use(
struct nfnl_ct *ct, uint32_t use)
572 ct->ce_mask |= CT_ATTR_USE;
575int nfnl_ct_test_use(
const struct nfnl_ct *ct)
577 return !!(ct->ce_mask & CT_ATTR_USE);
580uint32_t nfnl_ct_get_use(
const struct nfnl_ct *ct)
585void nfnl_ct_set_id(
struct nfnl_ct *ct, uint32_t
id)
588 ct->ce_mask |= CT_ATTR_ID;
591int nfnl_ct_test_id(
const struct nfnl_ct *ct)
593 return !!(ct->ce_mask & CT_ATTR_ID);
596uint32_t nfnl_ct_get_id(
const struct nfnl_ct *ct)
601void nfnl_ct_set_zone(
struct nfnl_ct *ct, uint16_t zone)
604 ct->ce_mask |= CT_ATTR_ZONE;
607int nfnl_ct_test_zone(
const struct nfnl_ct *ct)
609 return !!(ct->ce_mask & CT_ATTR_ZONE);
612uint16_t nfnl_ct_get_zone(
const struct nfnl_ct *ct)
617static int ct_set_addr(
struct nfnl_ct *ct,
struct nl_addr *addr,
618 int attr,
struct nl_addr ** ct_addr)
620 if (ct->ce_mask & CT_ATTR_FAMILY) {
621 if (addr->a_family != ct->ct_family)
622 return -NLE_AF_MISMATCH;
624 nfnl_ct_set_family(ct, addr->a_family);
636int nfnl_ct_set_src(
struct nfnl_ct *ct,
int repl,
struct nl_addr *addr)
638 struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
639 int attr = repl ? CT_ATTR_REPL_SRC : CT_ATTR_ORIG_SRC;
640 return ct_set_addr(ct, addr, attr, &dir->src);
643int nfnl_ct_set_dst(
struct nfnl_ct *ct,
int repl,
struct nl_addr *addr)
645 struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
646 int attr = repl ? CT_ATTR_REPL_DST : CT_ATTR_ORIG_DST;
647 return ct_set_addr(ct, addr, attr, &dir->dst);
650struct nl_addr *nfnl_ct_get_src(
const struct nfnl_ct *ct,
int repl)
652 const struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
653 int attr = repl ? CT_ATTR_REPL_SRC : CT_ATTR_ORIG_SRC;
654 if (!(ct->ce_mask & attr))
659struct nl_addr *nfnl_ct_get_dst(
const struct nfnl_ct *ct,
int repl)
661 const struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
662 int attr = repl ? CT_ATTR_REPL_DST : CT_ATTR_ORIG_DST;
663 if (!(ct->ce_mask & attr))
668void nfnl_ct_set_src_port(
struct nfnl_ct *ct,
int repl, uint16_t port)
670 struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
671 int attr = repl ? CT_ATTR_REPL_SRC_PORT : CT_ATTR_ORIG_SRC_PORT;
673 dir->proto.port.src = port;
677int nfnl_ct_test_src_port(
const struct nfnl_ct *ct,
int repl)
679 int attr = repl ? CT_ATTR_REPL_SRC_PORT : CT_ATTR_ORIG_SRC_PORT;
680 return !!(ct->ce_mask & attr);
683uint16_t nfnl_ct_get_src_port(
const struct nfnl_ct *ct,
int repl)
685 const struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
687 return dir->proto.port.src;
690void nfnl_ct_set_dst_port(
struct nfnl_ct *ct,
int repl, uint16_t port)
692 struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
693 int attr = repl ? CT_ATTR_REPL_DST_PORT : CT_ATTR_ORIG_DST_PORT;
695 dir->proto.port.dst = port;
699int nfnl_ct_test_dst_port(
const struct nfnl_ct *ct,
int repl)
701 int attr = repl ? CT_ATTR_REPL_DST_PORT : CT_ATTR_ORIG_DST_PORT;
702 return !!(ct->ce_mask & attr);
705uint16_t nfnl_ct_get_dst_port(
const struct nfnl_ct *ct,
int repl)
707 const struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
709 return dir->proto.port.dst;
712void nfnl_ct_set_icmp_id(
struct nfnl_ct *ct,
int repl, uint16_t
id)
714 struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
715 int attr = repl ? CT_ATTR_REPL_ICMP_ID : CT_ATTR_ORIG_ICMP_ID;
717 dir->proto.icmp.id = id;
721int nfnl_ct_test_icmp_id(
const struct nfnl_ct *ct,
int repl)
723 int attr = repl ? CT_ATTR_REPL_ICMP_ID : CT_ATTR_ORIG_ICMP_ID;
724 return !!(ct->ce_mask & attr);
727uint16_t nfnl_ct_get_icmp_id(
const struct nfnl_ct *ct,
int repl)
729 const struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
731 return dir->proto.icmp.id;
734void nfnl_ct_set_icmp_type(
struct nfnl_ct *ct,
int repl, uint8_t type)
736 struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
737 int attr = repl ? CT_ATTR_REPL_ICMP_TYPE : CT_ATTR_ORIG_ICMP_TYPE;
739 dir->proto.icmp.type = type;
743int nfnl_ct_test_icmp_type(
const struct nfnl_ct *ct,
int repl)
745 int attr = repl ? CT_ATTR_REPL_ICMP_TYPE : CT_ATTR_ORIG_ICMP_TYPE;
746 return !!(ct->ce_mask & attr);
749uint8_t nfnl_ct_get_icmp_type(
const struct nfnl_ct *ct,
int repl)
751 const struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
753 return dir->proto.icmp.type;
756void nfnl_ct_set_icmp_code(
struct nfnl_ct *ct,
int repl, uint8_t code)
758 struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
759 int attr = repl ? CT_ATTR_REPL_ICMP_CODE : CT_ATTR_ORIG_ICMP_CODE;
761 dir->proto.icmp.code = code;
765int nfnl_ct_test_icmp_code(
const struct nfnl_ct *ct,
int repl)
767 int attr = repl ? CT_ATTR_REPL_ICMP_CODE : CT_ATTR_ORIG_ICMP_CODE;
768 return !!(ct->ce_mask & attr);
771uint8_t nfnl_ct_get_icmp_code(
const struct nfnl_ct *ct,
int repl)
773 const struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
775 return dir->proto.icmp.code;
778void nfnl_ct_set_packets(
struct nfnl_ct *ct,
int repl, uint64_t packets)
780 struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
781 int attr = repl ? CT_ATTR_REPL_PACKETS : CT_ATTR_ORIG_PACKETS;
783 dir->packets = packets;
787int nfnl_ct_test_packets(
const struct nfnl_ct *ct,
int repl)
789 int attr = repl ? CT_ATTR_REPL_PACKETS : CT_ATTR_ORIG_PACKETS;
790 return !!(ct->ce_mask & attr);
793uint64_t nfnl_ct_get_packets(
const struct nfnl_ct *ct,
int repl)
795 const struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
800void nfnl_ct_set_bytes(
struct nfnl_ct *ct,
int repl, uint64_t bytes)
802 struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
803 int attr = repl ? CT_ATTR_REPL_BYTES : CT_ATTR_ORIG_BYTES;
809int nfnl_ct_test_bytes(
const struct nfnl_ct *ct,
int repl)
811 int attr = repl ? CT_ATTR_REPL_BYTES : CT_ATTR_ORIG_BYTES;
812 return !!(ct->ce_mask & attr);
815uint64_t nfnl_ct_get_bytes(
const struct nfnl_ct *ct,
int repl)
817 const struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
822void nfnl_ct_set_timestamp(
struct nfnl_ct *ct, uint64_t start, uint64_t stop)
824 ct->ct_tstamp.start = start;
825 ct->ct_tstamp.stop = stop;
826 ct->ce_mask |= CT_ATTR_TIMESTAMP;
829int nfnl_ct_test_timestamp(
const struct nfnl_ct *ct)
831 return !!(ct->ce_mask & CT_ATTR_TIMESTAMP);
836 return &ct->ct_tstamp;
841struct nl_object_ops ct_obj_ops = {
842 .oo_name =
"netfilter/ct",
843 .oo_size =
sizeof(
struct nfnl_ct),
844 .oo_free_data = ct_free_data,
845 .oo_clone = ct_clone,
851 .oo_compare = ct_compare,
852 .oo_attrs2str = ct_attrs2str,
struct nl_addr * nl_addr_get(struct nl_addr *addr)
Increase the reference counter of an abstract address.
int nl_addr_cmp(const struct nl_addr *a, const struct nl_addr *b)
Compare abstract addresses.
struct nl_addr * nl_addr_clone(const struct nl_addr *addr)
Clone existing abstract address object.
char * nl_addr2str(const struct nl_addr *addr, char *buf, size_t size)
Convert abstract address object to character string.
void nl_addr_put(struct nl_addr *addr)
Decrease the reference counter of an abstract address.
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.
double nl_cancel_down_bytes(unsigned long long l, char **unit)
Cancel down a byte counter.
void nl_new_line(struct nl_dump_params *params)
Handle a new line while dumping.
char * nl_msec2str(uint64_t msec, char *buf, size_t len)
Convert milliseconds to a character string.
@ 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.