10#include <linux/netlink.h>
12#include <netlink/cli/utils.h>
13#include <netlink/cli/ct.h>
15static void print_usage(
void)
18 "Usage: nf-ct-list [OPTION]... [CONNTRACK ENTRY]\n"
21 " -f, --format=TYPE Output format { brief | details | stats }\n"
22 " -h, --help Show this help\n"
23 " -v, --version Show versioning information\n"
25 "Conntrack Selection\n"
26 " -i, --id=NUM Identifier\n"
27 " -p, --proto=PROTOCOL Protocol\n"
28 " --tcp-state=STATE TCP connection state\n"
29 " --orig-src=ADDR Original source address\n"
30 " --orig-sport=PORT Original source port\n"
31 " --orig-dst=ADDR Original destination address\n"
32 " --orig-dport=PORT Original destination port\n"
33 " --reply-src=ADDR Reply source address\n"
34 " --reply-sport=PORT Reply source port\n"
35 " --reply-dst=ADDR Reply destination address\n"
36 " --reply-dport=PORT Reply destination port\n"
37 " -F, --family=FAMILY Address family\n"
38 " --mark=NUM Mark value\n"
39 " --timeout=NUM Timeout value\n"
40 " --refcnt=NUM Use counter value\n"
46int main(
int argc,
char *argv[])
49 struct nl_cache *ct_cache;
56 ct = nl_cli_ct_alloc();
75 static struct option long_opts[] = {
76 {
"format", 1, 0,
'f' },
77 {
"help", 0, 0,
'h' },
78 {
"version", 0, 0,
'v' },
80 {
"proto", 1, 0,
'p' },
81 {
"tcp-state", 1, 0, ARG_TCP_STATE },
82 {
"orig-src", 1, 0, ARG_ORIG_SRC },
83 {
"orig-sport", 1, 0, ARG_ORIG_SPORT },
84 {
"orig-dst", 1, 0, ARG_ORIG_DST },
85 {
"orig-dport", 1, 0, ARG_ORIG_DPORT },
86 {
"reply-src", 1, 0, ARG_REPLY_SRC },
87 {
"reply-sport", 1, 0, ARG_REPLY_SPORT },
88 {
"reply-dst", 1, 0, ARG_REPLY_DST },
89 {
"reply-dport", 1, 0, ARG_REPLY_DPORT },
90 {
"family", 1, 0,
'F' },
91 {
"mark", 1, 0, ARG_MARK },
92 {
"timeout", 1, 0, ARG_TIMEOUT },
93 {
"refcnt", 1, 0, ARG_REFCNT },
97 c = getopt_long(argc, argv,
"46f:hvi:p:F:", long_opts, &optidx);
102 case '?': exit(NLE_INVAL);
103 case '4': nfnl_ct_set_family(ct, AF_INET);
break;
104 case '6': nfnl_ct_set_family(ct, AF_INET6);
break;
105 case 'f': params.
dp_type = nl_cli_parse_dumptype(optarg);
break;
106 case 'h': print_usage();
break;
107 case 'v': nl_cli_print_version();
break;
108 case 'i': nl_cli_ct_parse_id(ct, optarg);
break;
109 case 'p': nl_cli_ct_parse_protocol(ct, optarg);
break;
110 case ARG_TCP_STATE: nl_cli_ct_parse_tcp_state(ct, optarg);
break;
111 case ARG_ORIG_SRC: nl_cli_ct_parse_src(ct, 0, optarg);
break;
112 case ARG_ORIG_SPORT: nl_cli_ct_parse_src_port(ct, 0, optarg);
break;
113 case ARG_ORIG_DST: nl_cli_ct_parse_dst(ct, 0, optarg);
break;
114 case ARG_ORIG_DPORT: nl_cli_ct_parse_dst_port(ct, 0, optarg);
break;
115 case ARG_REPLY_SRC: nl_cli_ct_parse_src(ct, 1, optarg);
break;
116 case ARG_REPLY_SPORT: nl_cli_ct_parse_src_port(ct, 1, optarg);
break;
117 case ARG_REPLY_DST: nl_cli_ct_parse_dst(ct, 1, optarg);
break;
118 case ARG_REPLY_DPORT: nl_cli_ct_parse_dst_port(ct, 1, optarg);
break;
119 case 'F': nl_cli_ct_parse_family(ct, optarg);
break;
120 case ARG_MARK: nl_cli_ct_parse_mark(ct, optarg);
break;
121 case ARG_TIMEOUT: nl_cli_ct_parse_timeout(ct, optarg);
break;
122 case ARG_REFCNT: nl_cli_ct_parse_use(ct, optarg);
break;
123 case ARG_FLAGS: nl_cli_ct_parse_status(ct, optarg);
break;
127 sock = nl_cli_alloc_socket();
128 nl_cli_connect(sock, NETLINK_NETFILTER);
129 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.