9#include <netlink/cli/utils.h>
10#include <netlink/cli/exp.h>
12#include <linux/rtnetlink.h>
16static void print_usage(
void)
19 "Usage: nf-exp-list [OPTION]... [CONNTRACK ENTRY]\n"
22 " --replace Replace the address if it exists.\n"
23 " -q, --quiet Do not print informal notifications.\n"
24 " -h, --help Show this help\n"
25 " -v, --version Show versioning information\n"
27 "Expectation Selection\n"
28 " -i, --id=NUM Identifier\n"
29 " --expect-proto=PROTOCOL Expectation protocol\n"
30 " --expect-src=ADDR Expectation source address\n"
31 " --expect-sport=PORT Expectation source port\n"
32 " --expect-dst=ADDR Expectation destination address\n"
33 " --expect-dport=PORT Expectation destination port\n"
34 " --master-proto=PROTOCOL Master conntrack protocol\n"
35 " --master-src=ADDR Master conntrack source address\n"
36 " --master-sport=PORT Master conntrack source port\n"
37 " --master-dst=ADDR Master conntrack destination address\n"
38 " --master-dport=PORT Master conntrack destination port\n"
39 " --mask-proto=PROTOCOL Mask protocol\n"
40 " --mask-src=ADDR Mask source address\n"
41 " --mask-sport=PORT Mask source port\n"
42 " --mask-dst=ADDR Mask destination address\n"
43 " --mask-dport=PORT Mask destination port\n"
44 " -F, --family=FAMILY Address family\n"
45 " --timeout=NUM Timeout value\n"
46 " --helper=STRING Helper Name\n"
52int main(
int argc,
char *argv[])
62 exp = nl_cli_exp_alloc();
88 static struct option long_opts[] = {
89 {
"quiet", 0, 0,
'q' },
90 {
"help", 0, 0,
'h' },
91 {
"version", 0, 0,
'v' },
93 {
"expect-proto", 1, 0, ARG_EXPECT_PROTO },
94 {
"expect-src", 1, 0, ARG_EXPECT_SRC },
95 {
"expect-sport", 1, 0, ARG_EXPECT_SPORT },
96 {
"expect-dst", 1, 0, ARG_EXPECT_DST },
97 {
"expect-dport", 1, 0, ARG_EXPECT_DPORT },
98 {
"master-proto", 1, 0, ARG_MASTER_PROTO },
99 {
"master-src", 1, 0, ARG_MASTER_SRC },
100 {
"master-sport", 1, 0, ARG_MASTER_SPORT },
101 {
"master-dst", 1, 0, ARG_MASTER_DST },
102 {
"master-dport", 1, 0, ARG_MASTER_DPORT },
103 {
"mask-proto", 1, 0, ARG_MASK_PROTO },
104 {
"mask-src", 1, 0, ARG_MASK_SRC },
105 {
"mask-sport", 1, 0, ARG_MASK_SPORT },
106 {
"mask-dst", 1, 0, ARG_MASK_DST },
107 {
"mask-dport", 1, 0, ARG_MASK_DPORT },
108 {
"family", 1, 0,
'F' },
109 {
"timeout", 1, 0, ARG_TIMEOUT },
110 {
"helper", 1, 0, ARG_HELPER_NAME },
111 {
"flags", 1, 0, ARG_FLAGS},
115 c = getopt_long(argc, argv,
"46f:hvi:p:F:", long_opts, &optidx);
120 case '?': exit(NLE_INVAL);
121 case 'q': quiet = 1;
break;
122 case '4': nfnl_exp_set_family(exp, AF_INET);
break;
123 case '6': nfnl_exp_set_family(exp, AF_INET6);
break;
124 case 'h': print_usage();
break;
125 case 'v': nl_cli_print_version();
break;
126 case 'i': nl_cli_exp_parse_id(exp, optarg);
break;
127 case ARG_EXPECT_PROTO: nl_cli_exp_parse_l4protonum(exp, NFNL_EXP_TUPLE_EXPECT, optarg);
break;
128 case ARG_EXPECT_SRC: nl_cli_exp_parse_src(exp, NFNL_EXP_TUPLE_EXPECT, optarg);
break;
129 case ARG_EXPECT_SPORT: nl_cli_exp_parse_src_port(exp, NFNL_EXP_TUPLE_EXPECT, optarg);
break;
130 case ARG_EXPECT_DST: nl_cli_exp_parse_dst(exp, NFNL_EXP_TUPLE_EXPECT, optarg);
break;
131 case ARG_EXPECT_DPORT: nl_cli_exp_parse_dst_port(exp, NFNL_EXP_TUPLE_EXPECT, optarg);
break;
132 case ARG_MASTER_PROTO: nl_cli_exp_parse_l4protonum(exp, NFNL_EXP_TUPLE_MASTER, optarg);
break;
133 case ARG_MASTER_SRC: nl_cli_exp_parse_src(exp, NFNL_EXP_TUPLE_MASTER, optarg);
break;
134 case ARG_MASTER_SPORT: nl_cli_exp_parse_src_port(exp, NFNL_EXP_TUPLE_MASTER, optarg);
break;
135 case ARG_MASTER_DST: nl_cli_exp_parse_dst(exp, NFNL_EXP_TUPLE_MASTER, optarg);
break;
136 case ARG_MASTER_DPORT: nl_cli_exp_parse_dst_port(exp, NFNL_EXP_TUPLE_MASTER, optarg);
break;
137 case ARG_MASK_PROTO: nl_cli_exp_parse_l4protonum(exp, NFNL_EXP_TUPLE_MASK, optarg);
break;
138 case ARG_MASK_SRC: nl_cli_exp_parse_src(exp, NFNL_EXP_TUPLE_MASK, optarg);
break;
139 case ARG_MASK_SPORT: nl_cli_exp_parse_src_port(exp, NFNL_EXP_TUPLE_MASK, optarg);
break;
140 case ARG_MASK_DST: nl_cli_exp_parse_dst(exp, NFNL_EXP_TUPLE_MASK, optarg);
break;
141 case ARG_MASK_DPORT: nl_cli_exp_parse_dst_port(exp, NFNL_EXP_TUPLE_MASK, optarg);
break;
142 case 'F': nl_cli_exp_parse_family(exp, optarg);
break;
143 case ARG_TIMEOUT: nl_cli_exp_parse_timeout(exp, optarg);
break;
144 case ARG_HELPER_NAME: nl_cli_exp_parse_helper_name(exp, optarg);
break;
145 case ARG_FLAGS: nl_cli_exp_parse_flags(exp, optarg);
break;
149 sock = nl_cli_alloc_socket();
150 nl_cli_connect(sock, NETLINK_NETFILTER);
152 if ((err = nfnl_exp_del(sock, exp, nlflags)) < 0)
153 nl_cli_fatal(err,
"Unable to delete expectation: %s", nl_geterror(err));
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
void nl_object_dump(struct nl_object *obj, struct nl_dump_params *params)
Dump this object according to the specified parameters.
@ NL_DUMP_LINE
Dump object briefly on one line.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.