15 #include <netlink/cli/utils.h>
16 #include <netlink/cli/exp.h>
18 static void print_usage(
void)
21 "Usage: nf-exp-list [OPTION]... [EXPECTATION ENTRY]\n"
24 " -f, --format=TYPE Output format { brief | details }\n"
25 " -h, --help Show this help\n"
26 " -v, --version Show versioning information\n"
28 "Expectation Selection\n"
29 " -i, --id=NUM Identifier\n"
30 " --expect-proto=PROTOCOL Expectation protocol\n"
31 " --expect-src=ADDR Expectation source address\n"
32 " --expect-sport=PORT Expectation source port\n"
33 " --expect-dst=ADDR Expectation destination address\n"
34 " --expect-dport=PORT Expectation destination port\n"
35 " --master-proto=PROTOCOL Master conntrack protocol\n"
36 " --master-src=ADDR Master conntrack source address\n"
37 " --master-sport=PORT Master conntrack source port\n"
38 " --master-dst=ADDR Master conntrack destination address\n"
39 " --master-dport=PORT Master conntrack destination port\n"
40 " -F, --family=FAMILY Address family\n"
41 " --timeout=NUM Timeout value\n"
42 " --helper=STRING Helper Name\n"
48 int main(
int argc,
char *argv[])
51 struct nl_cache *exp_cache;
58 exp = nl_cli_exp_alloc();
79 static struct option long_opts[] = {
80 {
"format", 1, 0,
'f' },
81 {
"help", 0, 0,
'h' },
82 {
"version", 0, 0,
'v' },
84 {
"expect-proto", 1, 0, ARG_EXPECT_PROTO },
85 {
"expect-src", 1, 0, ARG_EXPECT_SRC },
86 {
"expect-sport", 1, 0, ARG_EXPECT_SPORT },
87 {
"expect-dst", 1, 0, ARG_EXPECT_DST },
88 {
"expect-dport", 1, 0, ARG_EXPECT_DPORT },
89 {
"master-proto", 1, 0, ARG_MASTER_PROTO },
90 {
"master-src", 1, 0, ARG_MASTER_SRC },
91 {
"master-sport", 1, 0, ARG_MASTER_SPORT },
92 {
"master-dst", 1, 0, ARG_MASTER_DST },
93 {
"master-dport", 1, 0, ARG_MASTER_DPORT },
94 {
"family", 1, 0,
'F' },
95 {
"timeout", 1, 0, ARG_TIMEOUT },
96 {
"helper", 1, 0, ARG_HELPER_NAME },
97 {
"flags", 1, 0, ARG_FLAGS},
101 c = getopt_long(argc, argv,
"46f:hvi:p:F:", long_opts, &optidx);
106 case '?': exit(NLE_INVAL);
107 case '4': nfnl_exp_set_family(exp, AF_INET);
break;
108 case '6': nfnl_exp_set_family(exp, AF_INET6);
break;
109 case 'f': params.
dp_type = nl_cli_parse_dumptype(optarg);
break;
110 case 'h': print_usage();
break;
111 case 'v': nl_cli_print_version();
break;
112 case 'i': nl_cli_exp_parse_id(exp, optarg);
break;
113 case ARG_EXPECT_PROTO: nl_cli_exp_parse_l4protonum(exp, NFNL_EXP_TUPLE_EXPECT, optarg);
break;
114 case ARG_EXPECT_SRC: nl_cli_exp_parse_src(exp, NFNL_EXP_TUPLE_EXPECT, optarg);
break;
115 case ARG_EXPECT_SPORT: nl_cli_exp_parse_src_port(exp, NFNL_EXP_TUPLE_EXPECT, optarg);
break;
116 case ARG_EXPECT_DST: nl_cli_exp_parse_dst(exp, NFNL_EXP_TUPLE_EXPECT, optarg);
break;
117 case ARG_EXPECT_DPORT: nl_cli_exp_parse_dst_port(exp, NFNL_EXP_TUPLE_EXPECT, optarg);
break;
118 case ARG_MASTER_PROTO: nl_cli_exp_parse_l4protonum(exp, NFNL_EXP_TUPLE_MASTER, optarg);
break;
119 case ARG_MASTER_SRC: nl_cli_exp_parse_src(exp, NFNL_EXP_TUPLE_MASTER, optarg);
break;
120 case ARG_MASTER_SPORT: nl_cli_exp_parse_src_port(exp, NFNL_EXP_TUPLE_MASTER, optarg);
break;
121 case ARG_MASTER_DST: nl_cli_exp_parse_dst(exp, NFNL_EXP_TUPLE_MASTER, optarg);
break;
122 case ARG_MASTER_DPORT: nl_cli_exp_parse_dst_port(exp, NFNL_EXP_TUPLE_MASTER, optarg);
break;
123 case 'F': nl_cli_exp_parse_family(exp, optarg);
break;
124 case ARG_TIMEOUT: nl_cli_exp_parse_timeout(exp, optarg);
break;
125 case ARG_HELPER_NAME: nl_cli_exp_parse_helper_name(exp, optarg);
break;
126 case ARG_FLAGS: nl_cli_exp_parse_flags(exp, optarg);
break;
130 sock = nl_cli_alloc_socket();
131 nl_cli_connect(sock, NETLINK_NETFILTER);
132 exp_cache = nl_cli_exp_alloc_cache(sock);