14 #include <sys/types.h>
15 #include <linux/netfilter/nfnetlink_conntrack.h>
16 #include <linux/netfilter/nf_conntrack_common.h>
17 #include <linux/netfilter/nf_conntrack_tcp.h>
19 #include <netlink-local.h>
20 #include <netlink/netfilter/nfnl.h>
21 #include <netlink/netfilter/ct.h>
24 #define CT_ATTR_FAMILY (1UL << 0)
25 #define CT_ATTR_PROTO (1UL << 1)
27 #define CT_ATTR_TCP_STATE (1UL << 2)
29 #define CT_ATTR_STATUS (1UL << 3)
30 #define CT_ATTR_TIMEOUT (1UL << 4)
31 #define CT_ATTR_MARK (1UL << 5)
32 #define CT_ATTR_USE (1UL << 6)
33 #define CT_ATTR_ID (1UL << 7)
35 #define CT_ATTR_ORIG_SRC (1UL << 8)
36 #define CT_ATTR_ORIG_DST (1UL << 9)
37 #define CT_ATTR_ORIG_SRC_PORT (1UL << 10)
38 #define CT_ATTR_ORIG_DST_PORT (1UL << 11)
39 #define CT_ATTR_ORIG_ICMP_ID (1UL << 12)
40 #define CT_ATTR_ORIG_ICMP_TYPE (1UL << 13)
41 #define CT_ATTR_ORIG_ICMP_CODE (1UL << 14)
42 #define CT_ATTR_ORIG_PACKETS (1UL << 15)
43 #define CT_ATTR_ORIG_BYTES (1UL << 16)
45 #define CT_ATTR_REPL_SRC (1UL << 17)
46 #define CT_ATTR_REPL_DST (1UL << 18)
47 #define CT_ATTR_REPL_SRC_PORT (1UL << 19)
48 #define CT_ATTR_REPL_DST_PORT (1UL << 20)
49 #define CT_ATTR_REPL_ICMP_ID (1UL << 21)
50 #define CT_ATTR_REPL_ICMP_TYPE (1UL << 22)
51 #define CT_ATTR_REPL_ICMP_CODE (1UL << 23)
52 #define CT_ATTR_REPL_PACKETS (1UL << 24)
53 #define CT_ATTR_REPL_BYTES (1UL << 25)
56 static void ct_free_data(
struct nl_object *c)
58 struct nfnl_ct *ct = (
struct nfnl_ct *) c;
63 nl_addr_put(ct->ct_orig.src);
64 nl_addr_put(ct->ct_orig.dst);
65 nl_addr_put(ct->ct_repl.src);
66 nl_addr_put(ct->ct_repl.dst);
71 struct nfnl_ct *dst = (
struct nfnl_ct *) _dst;
72 struct nfnl_ct *src = (
struct nfnl_ct *) _src;
75 if (src->ct_orig.src) {
79 dst->ct_orig.src = addr;
82 if (src->ct_orig.dst) {
86 dst->ct_orig.dst = addr;
89 if (src->ct_repl.src) {
93 dst->ct_repl.src = addr;
96 if (src->ct_repl.dst) {
100 dst->ct_repl.dst = addr;
106 static void dump_addr(
struct nl_dump_params *p,
struct nl_addr *addr,
int port)
119 static void dump_icmp(
struct nl_dump_params *p,
struct nfnl_ct *ct,
int reply)
121 if (nfnl_ct_test_icmp_type(ct, reply))
122 nl_dump(p,
"icmp type %d ", nfnl_ct_get_icmp_type(ct, reply));
124 if (nfnl_ct_test_icmp_code(ct, reply))
125 nl_dump(p,
"code %d ", nfnl_ct_get_icmp_code(ct, reply));
127 if (nfnl_ct_test_icmp_id(ct, reply))
128 nl_dump(p,
"id %d ", nfnl_ct_get_icmp_id(ct, reply));
131 static void ct_dump_tuples(
struct nfnl_ct *ct,
struct nl_dump_params *p)
133 struct nl_addr *orig_src, *orig_dst, *reply_src, *reply_dst;
134 int orig_sport = 0, orig_dport = 0, reply_sport = 0, reply_dport = 0;
137 orig_src = nfnl_ct_get_src(ct, 0);
138 orig_dst = nfnl_ct_get_dst(ct, 0);
139 reply_src = nfnl_ct_get_src(ct, 1);
140 reply_dst = nfnl_ct_get_dst(ct, 1);
142 if (nfnl_ct_test_src_port(ct, 0))
143 orig_sport = nfnl_ct_get_src_port(ct, 0);
145 if (nfnl_ct_test_dst_port(ct, 0))
146 orig_dport = nfnl_ct_get_dst_port(ct, 0);
148 if (nfnl_ct_test_src_port(ct, 1))
149 reply_sport = nfnl_ct_get_src_port(ct, 1);
151 if (nfnl_ct_test_dst_port(ct, 1))
152 reply_dport = nfnl_ct_get_dst_port(ct, 1);
154 if (orig_src && orig_dst && reply_src && reply_dst &&
155 orig_sport == reply_dport && orig_dport == reply_sport &&
160 dump_addr(p, orig_src, orig_sport);
161 nl_dump(p, sync ?
"<-> " :
"-> ");
162 dump_addr(p, orig_dst, orig_dport);
166 dump_addr(p, reply_src, reply_sport);
168 dump_addr(p, reply_dst, reply_dport);
176 struct nfnl_ct *ct = (
struct nfnl_ct *) a;
181 if (nfnl_ct_test_proto(ct))
183 nl_ip_proto2str(nfnl_ct_get_proto(ct), buf,
sizeof(buf)));
185 if (nfnl_ct_test_tcp_state(ct))
187 nfnl_ct_tcp_state2str(nfnl_ct_get_tcp_state(ct),
190 ct_dump_tuples(ct, p);
192 if (nfnl_ct_test_mark(ct) && nfnl_ct_get_mark(ct))
193 nl_dump(p,
"mark %u ", nfnl_ct_get_mark(ct));
200 struct nfnl_ct *ct = (
struct nfnl_ct *) a;
206 nl_dump(p,
" id 0x%x ", ct->ct_id);
207 nl_dump_line(p,
"family %s ",
208 nl_af2str(ct->ct_family, buf,
sizeof(buf)));
210 if (nfnl_ct_test_use(ct))
211 nl_dump(p,
"refcnt %u ", nfnl_ct_get_use(ct));
213 if (nfnl_ct_test_timeout(ct)) {
214 uint64_t timeout_ms = nfnl_ct_get_timeout(ct) * 1000UL;
222 #define PRINT_FLAG(str) \
223 { nl_dump(p, "%s%s", fp++ ? "," : "", (str)); }
225 if (ct->ct_status & IPS_EXPECTED)
226 PRINT_FLAG(
"EXPECTED");
227 if (!(ct->ct_status & IPS_SEEN_REPLY))
228 PRINT_FLAG(
"NOREPLY");
229 if (ct->ct_status & IPS_ASSURED)
230 PRINT_FLAG(
"ASSURED");
231 if (!(ct->ct_status & IPS_CONFIRMED))
232 PRINT_FLAG(
"NOTSENT");
233 if (ct->ct_status & IPS_SRC_NAT)
235 if (ct->ct_status & IPS_DST_NAT)
237 if (ct->ct_status & IPS_SEQ_ADJUST)
238 PRINT_FLAG(
"SEQADJUST");
239 if (!(ct->ct_status & IPS_SRC_NAT_DONE))
240 PRINT_FLAG(
"SNAT_INIT");
241 if (!(ct->ct_status & IPS_DST_NAT_DONE))
242 PRINT_FLAG(
"DNAT_INIT");
243 if (ct->ct_status & IPS_DYING)
245 if (ct->ct_status & IPS_FIXED_TIMEOUT)
246 PRINT_FLAG(
"FIXED_TIMEOUT");
256 struct nfnl_ct *ct = (
struct nfnl_ct *) a;
260 const char *
const names[] = {
"rx",
"tx"};
263 ct_dump_details(a, p);
265 if (!nfnl_ct_test_bytes(ct, 0) ||
266 !nfnl_ct_test_packets(ct, 0) ||
267 !nfnl_ct_test_bytes(ct, 1) ||
268 !nfnl_ct_test_packets(ct, 1))
270 nl_dump_line(p,
" Statistics are not available.\n");
271 nl_dump_line(p,
" Please set sysctl net.netfilter.nf_conntrack_acct=1\n");
272 nl_dump_line(p,
" (Require kernel 2.6.27)\n");
276 nl_dump_line(p,
" # packets volume\n");
277 for (i=0; i<=1; i++) {
279 packets = nfnl_ct_get_packets(ct, i);
280 nl_dump_line(p,
" %s %10" PRIu64
" %7.2f %s\n", names[i], packets, res, unit);
285 uint32_t attrs,
int flags)
287 struct nfnl_ct *a = (
struct nfnl_ct *) _a;
288 struct nfnl_ct *b = (
struct nfnl_ct *) _b;
291 #define CT_DIFF(ATTR, EXPR) ATTR_DIFF(attrs, CT_ATTR_##ATTR, a, b, EXPR)
292 #define CT_DIFF_VAL(ATTR, FIELD) CT_DIFF(ATTR, a->FIELD != b->FIELD)
293 #define CT_DIFF_ADDR(ATTR, FIELD) \
294 ((flags & LOOSE_COMPARISON) \
295 ? CT_DIFF(ATTR, nl_addr_cmp_prefix(a->FIELD, b->FIELD)) \
296 : CT_DIFF(ATTR, nl_addr_cmp(a->FIELD, b->FIELD)))
298 diff |= CT_DIFF_VAL(FAMILY, ct_family);
299 diff |= CT_DIFF_VAL(PROTO, ct_proto);
300 diff |= CT_DIFF_VAL(TCP_STATE, ct_protoinfo.tcp.state);
301 diff |= CT_DIFF_VAL(TIMEOUT, ct_timeout);
302 diff |= CT_DIFF_VAL(MARK, ct_mark);
303 diff |= CT_DIFF_VAL(USE, ct_use);
304 diff |= CT_DIFF_VAL(ID, ct_id);
305 diff |= CT_DIFF_ADDR(ORIG_SRC, ct_orig.src);
306 diff |= CT_DIFF_ADDR(ORIG_DST, ct_orig.dst);
307 diff |= CT_DIFF_VAL(ORIG_SRC_PORT, ct_orig.proto.port.src);
308 diff |= CT_DIFF_VAL(ORIG_DST_PORT, ct_orig.proto.port.dst);
309 diff |= CT_DIFF_VAL(ORIG_ICMP_ID, ct_orig.proto.icmp.id);
310 diff |= CT_DIFF_VAL(ORIG_ICMP_TYPE, ct_orig.proto.icmp.type);
311 diff |= CT_DIFF_VAL(ORIG_ICMP_CODE, ct_orig.proto.icmp.code);
312 diff |= CT_DIFF_VAL(ORIG_PACKETS, ct_orig.packets);
313 diff |= CT_DIFF_VAL(ORIG_BYTES, ct_orig.bytes);
314 diff |= CT_DIFF_ADDR(REPL_SRC, ct_repl.src);
315 diff |= CT_DIFF_ADDR(REPL_DST, ct_repl.dst);
316 diff |= CT_DIFF_VAL(REPL_SRC_PORT, ct_repl.proto.port.src);
317 diff |= CT_DIFF_VAL(REPL_DST_PORT, ct_repl.proto.port.dst);
318 diff |= CT_DIFF_VAL(REPL_ICMP_ID, ct_repl.proto.icmp.id);
319 diff |= CT_DIFF_VAL(REPL_ICMP_TYPE, ct_repl.proto.icmp.type);
320 diff |= CT_DIFF_VAL(REPL_ICMP_CODE, ct_repl.proto.icmp.code);
321 diff |= CT_DIFF_VAL(REPL_PACKETS, ct_repl.packets);
322 diff |= CT_DIFF_VAL(REPL_BYTES, ct_repl.bytes);
324 if (flags & LOOSE_COMPARISON)
325 diff |= CT_DIFF(STATUS, (a->ct_status ^ b->ct_status) &
328 diff |= CT_DIFF(STATUS, a->ct_status != b->ct_status);
337 static const struct trans_tbl ct_attrs[] = {
338 __ADD(CT_ATTR_FAMILY, family)
339 __ADD(CT_ATTR_PROTO, proto)
340 __ADD(CT_ATTR_TCP_STATE, tcpstate)
341 __ADD(CT_ATTR_STATUS, status)
342 __ADD(CT_ATTR_TIMEOUT, timeout)
343 __ADD(CT_ATTR_MARK, mark)
344 __ADD(CT_ATTR_USE, use)
345 __ADD(CT_ATTR_ID,
id)
346 __ADD(CT_ATTR_ORIG_SRC, origsrc)
347 __ADD(CT_ATTR_ORIG_DST, origdst)
348 __ADD(CT_ATTR_ORIG_SRC_PORT, origsrcport)
349 __ADD(CT_ATTR_ORIG_DST_PORT, origdstport)
350 __ADD(CT_ATTR_ORIG_ICMP_ID, origicmpid)
351 __ADD(CT_ATTR_ORIG_ICMP_TYPE, origicmptype)
352 __ADD(CT_ATTR_ORIG_ICMP_CODE, origicmpcode)
353 __ADD(CT_ATTR_ORIG_PACKETS, origpackets)
354 __ADD(CT_ATTR_ORIG_BYTES, origbytes)
355 __ADD(CT_ATTR_REPL_SRC, replysrc)
356 __ADD(CT_ATTR_REPL_DST, replydst)
357 __ADD(CT_ATTR_REPL_SRC_PORT, replysrcport)
358 __ADD(CT_ATTR_REPL_DST_PORT, replydstport)
359 __ADD(CT_ATTR_REPL_ICMP_ID, replyicmpid)
360 __ADD(CT_ATTR_REPL_ICMP_TYPE, replyicmptype)
361 __ADD(CT_ATTR_REPL_ICMP_CODE, replyicmpcode)
362 __ADD(CT_ATTR_REPL_PACKETS, replypackets)
363 __ADD(CT_ATTR_REPL_BYTES, replybytes)
366 static
char *ct_attrs2str(
int attrs,
char *buf,
size_t len)
368 return __flags2str(attrs, buf, len, ct_attrs, ARRAY_SIZE(ct_attrs));
376 struct nfnl_ct *nfnl_ct_alloc(
void)
381 void nfnl_ct_get(
struct nfnl_ct *ct)
386 void nfnl_ct_put(
struct nfnl_ct *ct)
398 void nfnl_ct_set_family(
struct nfnl_ct *ct, uint8_t family)
400 ct->ct_family = family;
401 ct->ce_mask |= CT_ATTR_FAMILY;
404 uint8_t nfnl_ct_get_family(
const struct nfnl_ct *ct)
406 if (ct->ce_mask & CT_ATTR_FAMILY)
407 return ct->ct_family;
412 void nfnl_ct_set_proto(
struct nfnl_ct *ct, uint8_t proto)
414 ct->ct_proto = proto;
415 ct->ce_mask |= CT_ATTR_PROTO;
418 int nfnl_ct_test_proto(
const struct nfnl_ct *ct)
420 return !!(ct->ce_mask & CT_ATTR_PROTO);
423 uint8_t nfnl_ct_get_proto(
const struct nfnl_ct *ct)
428 void nfnl_ct_set_tcp_state(
struct nfnl_ct *ct, uint8_t state)
430 ct->ct_protoinfo.tcp.state = state;
431 ct->ce_mask |= CT_ATTR_TCP_STATE;
434 int nfnl_ct_test_tcp_state(
const struct nfnl_ct *ct)
436 return !!(ct->ce_mask & CT_ATTR_TCP_STATE);
439 uint8_t nfnl_ct_get_tcp_state(
const struct nfnl_ct *ct)
441 return ct->ct_protoinfo.tcp.state;
444 static const struct trans_tbl tcp_states[] = {
445 __ADD(TCP_CONNTRACK_NONE,NONE)
446 __ADD(TCP_CONNTRACK_SYN_SENT,SYN_SENT)
447 __ADD(TCP_CONNTRACK_SYN_RECV,SYN_RECV)
448 __ADD(TCP_CONNTRACK_ESTABLISHED,ESTABLISHED)
449 __ADD(TCP_CONNTRACK_FIN_WAIT,FIN_WAIT)
450 __ADD(TCP_CONNTRACK_CLOSE_WAIT,CLOSE_WAIT)
451 __ADD(TCP_CONNTRACK_LAST_ACK,LAST_ACK)
452 __ADD(TCP_CONNTRACK_TIME_WAIT,TIME_WAIT)
453 __ADD(TCP_CONNTRACK_CLOSE,CLOSE)
454 __ADD(TCP_CONNTRACK_LISTEN,LISTEN)
457 char *nfnl_ct_tcp_state2str(uint8_t state,
char *buf,
size_t len)
459 return __type2str(state, buf, len, tcp_states, ARRAY_SIZE(tcp_states));
462 int nfnl_ct_str2tcp_state(
const char *name)
464 return __str2type(name, tcp_states, ARRAY_SIZE(tcp_states));
467 void nfnl_ct_set_status(
struct nfnl_ct *ct, uint32_t status)
469 ct->ct_status_mask |= status;
470 ct->ct_status |= status;
471 ct->ce_mask |= CT_ATTR_STATUS;
474 void nfnl_ct_unset_status(
struct nfnl_ct *ct, uint32_t status)
476 ct->ct_status_mask |= status;
477 ct->ct_status &= ~status;
478 ct->ce_mask |= CT_ATTR_STATUS;
481 uint32_t nfnl_ct_get_status(
const struct nfnl_ct *ct)
483 return ct->ct_status;
486 static const struct trans_tbl status_flags[] = {
487 __ADD(IPS_EXPECTED, expected)
488 __ADD(IPS_SEEN_REPLY, seen_reply)
489 __ADD(IPS_ASSURED, assured)
490 __ADD(IPS_CONFIRMED, confirmed)
491 __ADD(IPS_SRC_NAT, snat)
492 __ADD(IPS_DST_NAT, dnat)
493 __ADD(IPS_SEQ_ADJUST, seqadjust)
494 __ADD(IPS_SRC_NAT_DONE, snat_done)
495 __ADD(IPS_DST_NAT_DONE, dnat_done)
496 __ADD(IPS_DYING, dying)
497 __ADD(IPS_FIXED_TIMEOUT, fixed_timeout)
500 char * nfnl_ct_status2str(
int flags,
char *buf,
size_t len)
502 return __flags2str(flags, buf, len, status_flags,
503 ARRAY_SIZE(status_flags));
506 int nfnl_ct_str2status(
const char *name)
508 return __str2flags(name, status_flags, ARRAY_SIZE(status_flags));
511 void nfnl_ct_set_timeout(
struct nfnl_ct *ct, uint32_t timeout)
513 ct->ct_timeout = timeout;
514 ct->ce_mask |= CT_ATTR_TIMEOUT;
517 int nfnl_ct_test_timeout(
const struct nfnl_ct *ct)
519 return !!(ct->ce_mask & CT_ATTR_TIMEOUT);
522 uint32_t nfnl_ct_get_timeout(
const struct nfnl_ct *ct)
524 return ct->ct_timeout;
527 void nfnl_ct_set_mark(
struct nfnl_ct *ct, uint32_t mark)
530 ct->ce_mask |= CT_ATTR_MARK;
533 int nfnl_ct_test_mark(
const struct nfnl_ct *ct)
535 return !!(ct->ce_mask & CT_ATTR_MARK);
538 uint32_t nfnl_ct_get_mark(
const struct nfnl_ct *ct)
543 void nfnl_ct_set_use(
struct nfnl_ct *ct, uint32_t use)
546 ct->ce_mask |= CT_ATTR_USE;
549 int nfnl_ct_test_use(
const struct nfnl_ct *ct)
551 return !!(ct->ce_mask & CT_ATTR_USE);
554 uint32_t nfnl_ct_get_use(
const struct nfnl_ct *ct)
559 void nfnl_ct_set_id(
struct nfnl_ct *ct, uint32_t
id)
562 ct->ce_mask |= CT_ATTR_ID;
565 int nfnl_ct_test_id(
const struct nfnl_ct *ct)
567 return !!(ct->ce_mask & CT_ATTR_ID);
570 uint32_t nfnl_ct_get_id(
const struct nfnl_ct *ct)
575 static int ct_set_addr(
struct nfnl_ct *ct,
struct nl_addr *addr,
576 int attr,
struct nl_addr ** ct_addr)
578 if (ct->ce_mask & CT_ATTR_FAMILY) {
579 if (addr->a_family != ct->ct_family)
580 return -NLE_AF_MISMATCH;
582 nfnl_ct_set_family(ct, addr->a_family);
585 nl_addr_put(*ct_addr);
594 int nfnl_ct_set_src(
struct nfnl_ct *ct,
int repl,
struct nl_addr *addr)
596 struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
597 int attr = repl ? CT_ATTR_REPL_SRC : CT_ATTR_ORIG_SRC;
598 return ct_set_addr(ct, addr, attr, &dir->src);
601 int nfnl_ct_set_dst(
struct nfnl_ct *ct,
int repl,
struct nl_addr *addr)
603 struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
604 int attr = repl ? CT_ATTR_REPL_DST : CT_ATTR_ORIG_DST;
605 return ct_set_addr(ct, addr, attr, &dir->dst);
608 struct nl_addr *nfnl_ct_get_src(
const struct nfnl_ct *ct,
int repl)
610 const struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
611 int attr = repl ? CT_ATTR_REPL_SRC : CT_ATTR_ORIG_SRC;
612 if (!(ct->ce_mask & attr))
617 struct nl_addr *nfnl_ct_get_dst(
const struct nfnl_ct *ct,
int repl)
619 const struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
620 int attr = repl ? CT_ATTR_REPL_DST : CT_ATTR_ORIG_DST;
621 if (!(ct->ce_mask & attr))
626 void nfnl_ct_set_src_port(
struct nfnl_ct *ct,
int repl, uint16_t port)
628 struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
629 int attr = repl ? CT_ATTR_REPL_SRC_PORT : CT_ATTR_ORIG_SRC_PORT;
631 dir->proto.port.src = port;
635 int nfnl_ct_test_src_port(
const struct nfnl_ct *ct,
int repl)
637 int attr = repl ? CT_ATTR_REPL_SRC_PORT : CT_ATTR_ORIG_SRC_PORT;
638 return !!(ct->ce_mask & attr);
641 uint16_t nfnl_ct_get_src_port(
const struct nfnl_ct *ct,
int repl)
643 const struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
645 return dir->proto.port.src;
648 void nfnl_ct_set_dst_port(
struct nfnl_ct *ct,
int repl, uint16_t port)
650 struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
651 int attr = repl ? CT_ATTR_REPL_DST_PORT : CT_ATTR_ORIG_DST_PORT;
653 dir->proto.port.dst = port;
657 int nfnl_ct_test_dst_port(
const struct nfnl_ct *ct,
int repl)
659 int attr = repl ? CT_ATTR_REPL_DST_PORT : CT_ATTR_ORIG_DST_PORT;
660 return !!(ct->ce_mask & attr);
663 uint16_t nfnl_ct_get_dst_port(
const struct nfnl_ct *ct,
int repl)
665 const struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
667 return dir->proto.port.dst;
670 void nfnl_ct_set_icmp_id(
struct nfnl_ct *ct,
int repl, uint16_t
id)
672 struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
673 int attr = repl ? CT_ATTR_REPL_ICMP_ID : CT_ATTR_ORIG_ICMP_ID;
675 dir->proto.icmp.id = id;
679 int nfnl_ct_test_icmp_id(
const struct nfnl_ct *ct,
int repl)
681 int attr = repl ? CT_ATTR_REPL_ICMP_ID : CT_ATTR_ORIG_ICMP_ID;
682 return !!(ct->ce_mask & attr);
685 uint16_t nfnl_ct_get_icmp_id(
const struct nfnl_ct *ct,
int repl)
687 const struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
689 return dir->proto.icmp.id;
692 void nfnl_ct_set_icmp_type(
struct nfnl_ct *ct,
int repl, uint8_t type)
694 struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
695 int attr = repl ? CT_ATTR_REPL_ICMP_TYPE : CT_ATTR_ORIG_ICMP_TYPE;
697 dir->proto.icmp.type = type;
701 int nfnl_ct_test_icmp_type(
const struct nfnl_ct *ct,
int repl)
703 int attr = repl ? CT_ATTR_REPL_ICMP_TYPE : CT_ATTR_ORIG_ICMP_TYPE;
704 return !!(ct->ce_mask & attr);
707 uint8_t nfnl_ct_get_icmp_type(
const struct nfnl_ct *ct,
int repl)
709 const struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
711 return dir->proto.icmp.type;
714 void nfnl_ct_set_icmp_code(
struct nfnl_ct *ct,
int repl, uint8_t code)
716 struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
717 int attr = repl ? CT_ATTR_REPL_ICMP_CODE : CT_ATTR_ORIG_ICMP_CODE;
719 dir->proto.icmp.code = code;
723 int nfnl_ct_test_icmp_code(
const struct nfnl_ct *ct,
int repl)
725 int attr = repl ? CT_ATTR_REPL_ICMP_CODE : CT_ATTR_ORIG_ICMP_CODE;
726 return !!(ct->ce_mask & attr);
729 uint8_t nfnl_ct_get_icmp_code(
const struct nfnl_ct *ct,
int repl)
731 const struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
733 return dir->proto.icmp.code;
736 void nfnl_ct_set_packets(
struct nfnl_ct *ct,
int repl, uint64_t packets)
738 struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
739 int attr = repl ? CT_ATTR_REPL_PACKETS : CT_ATTR_ORIG_PACKETS;
741 dir->packets = packets;
745 int nfnl_ct_test_packets(
const struct nfnl_ct *ct,
int repl)
747 int attr = repl ? CT_ATTR_REPL_PACKETS : CT_ATTR_ORIG_PACKETS;
748 return !!(ct->ce_mask & attr);
751 uint64_t nfnl_ct_get_packets(
const struct nfnl_ct *ct,
int repl)
753 const struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
758 void nfnl_ct_set_bytes(
struct nfnl_ct *ct,
int repl, uint64_t bytes)
760 struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
761 int attr = repl ? CT_ATTR_REPL_BYTES : CT_ATTR_ORIG_BYTES;
767 int nfnl_ct_test_bytes(
const struct nfnl_ct *ct,
int repl)
769 int attr = repl ? CT_ATTR_REPL_BYTES : CT_ATTR_ORIG_BYTES;
770 return !!(ct->ce_mask & attr);
773 uint64_t nfnl_ct_get_bytes(
const struct nfnl_ct *ct,
int repl)
775 const struct nfnl_ct_dir *dir = repl ? &ct->ct_repl : &ct->ct_orig;
784 .oo_size =
sizeof(
struct nfnl_ct),
785 .oo_free_data = ct_free_data,
786 .oo_clone = ct_clone,
792 .oo_compare = ct_compare,
793 .oo_attrs2str = ct_attrs2str,