8#include <netlink/cli/utils.h>
9#include <netlink/cli/ct.h>
11#include <linux/netlink.h>
13static void print_usage(
void)
16 "Usage: nf-ct-list [OPTION]... [CONNTRACK ENTRY]\n"
19 " -f, --format=TYPE Output format { brief | details | stats }\n"
20 " -h, --help Show this help\n"
21 " -v, --version Show versioning information\n"
23 "Conntrack Selection\n"
24 " -i, --id=NUM Identifier\n"
25 " -p, --proto=PROTOCOL Protocol\n"
26 " --tcp-state=STATE TCP connection state\n"
27 " --orig-src=ADDR Original source address\n"
28 " --orig-sport=PORT Original source port\n"
29 " --orig-dst=ADDR Original destination address\n"
30 " --orig-dport=PORT Original destination port\n"
31 " --reply-src=ADDR Reply source address\n"
32 " --reply-sport=PORT Reply source port\n"
33 " --reply-dst=ADDR Reply destination address\n"
34 " --reply-dport=PORT Reply destination port\n"
35 " -F, --family=FAMILY Address family\n"
36 " --mark=NUM Mark value\n"
37 " --timeout=NUM Timeout value\n"
38 " --refcnt=NUM Use counter value\n"
44int main(
int argc,
char *argv[])
47 struct nl_cache *ct_cache;
54 ct = nl_cli_ct_alloc();
73 static struct option long_opts[] = {
74 {
"format", 1, 0,
'f' },
75 {
"help", 0, 0,
'h' },
76 {
"version", 0, 0,
'v' },
78 {
"proto", 1, 0,
'p' },
79 {
"tcp-state", 1, 0, ARG_TCP_STATE },
80 {
"orig-src", 1, 0, ARG_ORIG_SRC },
81 {
"orig-sport", 1, 0, ARG_ORIG_SPORT },
82 {
"orig-dst", 1, 0, ARG_ORIG_DST },
83 {
"orig-dport", 1, 0, ARG_ORIG_DPORT },
84 {
"reply-src", 1, 0, ARG_REPLY_SRC },
85 {
"reply-sport", 1, 0, ARG_REPLY_SPORT },
86 {
"reply-dst", 1, 0, ARG_REPLY_DST },
87 {
"reply-dport", 1, 0, ARG_REPLY_DPORT },
88 {
"family", 1, 0,
'F' },
89 {
"mark", 1, 0, ARG_MARK },
90 {
"timeout", 1, 0, ARG_TIMEOUT },
91 {
"refcnt", 1, 0, ARG_REFCNT },
95 c = getopt_long(argc, argv,
"46f:hvi:p:F:", long_opts, &optidx);
100 case '?': exit(NLE_INVAL);
101 case '4': nfnl_ct_set_family(ct, AF_INET);
break;
102 case '6': nfnl_ct_set_family(ct, AF_INET6);
break;
103 case 'f': params.
dp_type = nl_cli_parse_dumptype(optarg);
break;
104 case 'h': print_usage();
break;
105 case 'v': nl_cli_print_version();
break;
106 case 'i': nl_cli_ct_parse_id(ct, optarg);
break;
107 case 'p': nl_cli_ct_parse_protocol(ct, optarg);
break;
108 case ARG_TCP_STATE: nl_cli_ct_parse_tcp_state(ct, optarg);
break;
109 case ARG_ORIG_SRC: nl_cli_ct_parse_src(ct, 0, optarg);
break;
110 case ARG_ORIG_SPORT: nl_cli_ct_parse_src_port(ct, 0, optarg);
break;
111 case ARG_ORIG_DST: nl_cli_ct_parse_dst(ct, 0, optarg);
break;
112 case ARG_ORIG_DPORT: nl_cli_ct_parse_dst_port(ct, 0, optarg);
break;
113 case ARG_REPLY_SRC: nl_cli_ct_parse_src(ct, 1, optarg);
break;
114 case ARG_REPLY_SPORT: nl_cli_ct_parse_src_port(ct, 1, optarg);
break;
115 case ARG_REPLY_DST: nl_cli_ct_parse_dst(ct, 1, optarg);
break;
116 case ARG_REPLY_DPORT: nl_cli_ct_parse_dst_port(ct, 1, optarg);
break;
117 case 'F': nl_cli_ct_parse_family(ct, optarg);
break;
118 case ARG_MARK: nl_cli_ct_parse_mark(ct, optarg);
break;
119 case ARG_TIMEOUT: nl_cli_ct_parse_timeout(ct, optarg);
break;
120 case ARG_REFCNT: nl_cli_ct_parse_use(ct, optarg);
break;
121 case ARG_FLAGS: nl_cli_ct_parse_status(ct, optarg);
break;
125 sock = nl_cli_alloc_socket();
126 nl_cli_connect(sock, NETLINK_NETFILTER);
127 ct_cache = nl_cli_ct_alloc_cache(sock);
void nl_cache_dump_filter(struct nl_cache *cache, struct nl_dump_params *params, struct nl_object *filter)
Dump all elements of a cache (filtered).
@ NL_DUMP_LINE
Dump object briefly on one line.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.