9#include <netlink/cli/utils.h>
10#include <netlink/cli/exp.h>
12#include <linux/netlink.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"
47 " --flags Flags (Kernel 2.6.37)\n"
52int main(
int argc,
char *argv[])
60 int err, nlflags = NLM_F_CREATE;
62 exp = nl_cli_exp_alloc();
95 static struct option long_opts[] = {
96 {
"replace", 1, 0, ARG_REPLACE },
97 {
"quiet", 0, 0,
'q' },
98 {
"help", 0, 0,
'h' },
99 {
"version", 0, 0,
'v' },
101 {
"expect-proto", 1, 0, ARG_EXPECT_PROTO },
102 {
"expect-src", 1, 0, ARG_EXPECT_SRC },
103 {
"expect-sport", 1, 0, ARG_EXPECT_SPORT },
104 {
"expect-dst", 1, 0, ARG_EXPECT_DST },
105 {
"expect-dport", 1, 0, ARG_EXPECT_DPORT },
106 {
"master-proto", 1, 0, ARG_MASTER_PROTO },
107 {
"master-src", 1, 0, ARG_MASTER_SRC },
108 {
"master-sport", 1, 0, ARG_MASTER_SPORT },
109 {
"master-dst", 1, 0, ARG_MASTER_DST },
110 {
"master-dport", 1, 0, ARG_MASTER_DPORT },
111 {
"mask-proto", 1, 0, ARG_MASK_PROTO },
112 {
"mask-src", 1, 0, ARG_MASK_SRC },
113 {
"mask-sport", 1, 0, ARG_MASK_SPORT },
114 {
"mask-dst", 1, 0, ARG_MASK_DST },
115 {
"mask-dport", 1, 0, ARG_MASK_DPORT },
116 {
"nat-proto", 1, 0, ARG_NAT_PROTO },
117 {
"nat-src", 1, 0, ARG_NAT_SRC },
118 {
"nat-sport", 1, 0, ARG_NAT_SPORT },
119 {
"nat-dst", 1, 0, ARG_NAT_DST },
120 {
"nat-dport", 1, 0, ARG_NAT_DPORT },
121 {
"nat-dir", 1, 0, ARG_NAT_DIR },
122 {
"family", 1, 0,
'F' },
123 {
"timeout", 1, 0, ARG_TIMEOUT },
124 {
"helper", 1, 0, ARG_HELPER_NAME },
125 {
"flags", 1, 0, ARG_FLAGS},
129 c = getopt_long(argc, argv,
"46f:hvi:p:F:", long_opts, &optidx);
134 case '?': exit(NLE_INVAL);
135 case ARG_REPLACE: nlflags |= NLM_F_REPLACE;
break;
136 case 'q': quiet = 1;
break;
137 case '4': nfnl_exp_set_family(exp, AF_INET);
break;
138 case '6': nfnl_exp_set_family(exp, AF_INET6);
break;
139 case 'h': print_usage();
break;
140 case 'v': nl_cli_print_version();
break;
141 case 'i': nl_cli_exp_parse_id(exp, optarg);
break;
142 case ARG_EXPECT_PROTO: nl_cli_exp_parse_l4protonum(exp, NFNL_EXP_TUPLE_EXPECT, optarg);
break;
143 case ARG_EXPECT_SRC: nl_cli_exp_parse_src(exp, NFNL_EXP_TUPLE_EXPECT, optarg);
break;
144 case ARG_EXPECT_SPORT: nl_cli_exp_parse_src_port(exp, NFNL_EXP_TUPLE_EXPECT, optarg);
break;
145 case ARG_EXPECT_DST: nl_cli_exp_parse_dst(exp, NFNL_EXP_TUPLE_EXPECT, optarg);
break;
146 case ARG_EXPECT_DPORT: nl_cli_exp_parse_dst_port(exp, NFNL_EXP_TUPLE_EXPECT, optarg);
break;
147 case ARG_MASTER_PROTO: nl_cli_exp_parse_l4protonum(exp, NFNL_EXP_TUPLE_MASTER, optarg);
break;
148 case ARG_MASTER_SRC: nl_cli_exp_parse_src(exp, NFNL_EXP_TUPLE_MASTER, optarg);
break;
149 case ARG_MASTER_SPORT: nl_cli_exp_parse_src_port(exp, NFNL_EXP_TUPLE_MASTER, optarg);
break;
150 case ARG_MASTER_DST: nl_cli_exp_parse_dst(exp, NFNL_EXP_TUPLE_MASTER, optarg);
break;
151 case ARG_MASTER_DPORT: nl_cli_exp_parse_dst_port(exp, NFNL_EXP_TUPLE_MASTER, optarg);
break;
152 case ARG_MASK_PROTO: nl_cli_exp_parse_l4protonum(exp, NFNL_EXP_TUPLE_MASK, optarg);
break;
153 case ARG_MASK_SRC: nl_cli_exp_parse_src(exp, NFNL_EXP_TUPLE_MASK, optarg);
break;
154 case ARG_MASK_SPORT: nl_cli_exp_parse_src_port(exp, NFNL_EXP_TUPLE_MASK, optarg);
break;
155 case ARG_MASK_DST: nl_cli_exp_parse_dst(exp, NFNL_EXP_TUPLE_MASK, optarg);
break;
156 case ARG_MASK_DPORT: nl_cli_exp_parse_dst_port(exp, NFNL_EXP_TUPLE_MASK, optarg);
break;
157 case ARG_NAT_PROTO: nl_cli_exp_parse_l4protonum(exp, NFNL_EXP_TUPLE_NAT, optarg);
break;
158 case ARG_NAT_SRC: nl_cli_exp_parse_src(exp, NFNL_EXP_TUPLE_NAT, optarg);
break;
159 case ARG_NAT_SPORT: nl_cli_exp_parse_src_port(exp, NFNL_EXP_TUPLE_NAT, optarg);
break;
160 case ARG_NAT_DST: nl_cli_exp_parse_dst(exp, NFNL_EXP_TUPLE_NAT, optarg);
break;
161 case ARG_NAT_DPORT: nl_cli_exp_parse_dst_port(exp, NFNL_EXP_TUPLE_NAT, optarg);
break;
162 case ARG_NAT_DIR: nl_cli_exp_parse_nat_dir(exp, optarg);
break;
163 case 'F': nl_cli_exp_parse_family(exp, optarg);
break;
164 case ARG_TIMEOUT: nl_cli_exp_parse_timeout(exp, optarg);
break;
165 case ARG_HELPER_NAME: nl_cli_exp_parse_helper_name(exp, optarg);
break;
166 case ARG_FLAGS: nl_cli_exp_parse_flags(exp, optarg);
break;
170 sock = nl_cli_alloc_socket();
171 nl_cli_connect(sock, NETLINK_NETFILTER);
173 if ((err = nfnl_exp_add(sock, exp, nlflags)) < 0)
174 nl_cli_fatal(err,
"Unable to add 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.