16 #include <netlink/cli/utils.h> 17 #include <netlink/cli/exp.h> 19 #include <linux/netlink.h> 21 static void print_usage(
void)
24 "Usage: nf-exp-list [OPTION]... [EXPECTATION ENTRY]\n" 27 " -f, --format=TYPE Output format { brief | details }\n" 28 " -h, --help Show this help\n" 29 " -v, --version Show versioning information\n" 31 "Expectation Selection\n" 32 " -i, --id=NUM Identifier\n" 33 " --expect-proto=PROTOCOL Expectation protocol\n" 34 " --expect-src=ADDR Expectation source address\n" 35 " --expect-sport=PORT Expectation source port\n" 36 " --expect-dst=ADDR Expectation destination address\n" 37 " --expect-dport=PORT Expectation destination port\n" 38 " --master-proto=PROTOCOL Master conntrack protocol\n" 39 " --master-src=ADDR Master conntrack source address\n" 40 " --master-sport=PORT Master conntrack source port\n" 41 " --master-dst=ADDR Master conntrack destination address\n" 42 " --master-dport=PORT Master conntrack destination port\n" 43 " -F, --family=FAMILY Address family\n" 44 " --timeout=NUM Timeout value\n" 45 " --helper=STRING Helper Name\n" 51 int main(
int argc,
char *argv[])
54 struct nl_cache *exp_cache;
61 exp = nl_cli_exp_alloc();
82 static struct option long_opts[] = {
83 {
"format", 1, 0,
'f' },
84 {
"help", 0, 0,
'h' },
85 {
"version", 0, 0,
'v' },
87 {
"expect-proto", 1, 0, ARG_EXPECT_PROTO },
88 {
"expect-src", 1, 0, ARG_EXPECT_SRC },
89 {
"expect-sport", 1, 0, ARG_EXPECT_SPORT },
90 {
"expect-dst", 1, 0, ARG_EXPECT_DST },
91 {
"expect-dport", 1, 0, ARG_EXPECT_DPORT },
92 {
"master-proto", 1, 0, ARG_MASTER_PROTO },
93 {
"master-src", 1, 0, ARG_MASTER_SRC },
94 {
"master-sport", 1, 0, ARG_MASTER_SPORT },
95 {
"master-dst", 1, 0, ARG_MASTER_DST },
96 {
"master-dport", 1, 0, ARG_MASTER_DPORT },
97 {
"family", 1, 0,
'F' },
98 {
"timeout", 1, 0, ARG_TIMEOUT },
99 {
"helper", 1, 0, ARG_HELPER_NAME },
100 {
"flags", 1, 0, ARG_FLAGS},
104 c = getopt_long(argc, argv,
"46f:hvi:p:F:", long_opts, &optidx);
109 case '?': exit(NLE_INVAL);
110 case '4': nfnl_exp_set_family(exp, AF_INET);
break;
111 case '6': nfnl_exp_set_family(exp, AF_INET6);
break;
112 case 'f': params.
dp_type = nl_cli_parse_dumptype(optarg);
break;
113 case 'h': print_usage();
break;
114 case 'v': nl_cli_print_version();
break;
115 case 'i': nl_cli_exp_parse_id(exp, optarg);
break;
116 case ARG_EXPECT_PROTO: nl_cli_exp_parse_l4protonum(exp, NFNL_EXP_TUPLE_EXPECT, optarg);
break;
117 case ARG_EXPECT_SRC: nl_cli_exp_parse_src(exp, NFNL_EXP_TUPLE_EXPECT, optarg);
break;
118 case ARG_EXPECT_SPORT: nl_cli_exp_parse_src_port(exp, NFNL_EXP_TUPLE_EXPECT, optarg);
break;
119 case ARG_EXPECT_DST: nl_cli_exp_parse_dst(exp, NFNL_EXP_TUPLE_EXPECT, optarg);
break;
120 case ARG_EXPECT_DPORT: nl_cli_exp_parse_dst_port(exp, NFNL_EXP_TUPLE_EXPECT, optarg);
break;
121 case ARG_MASTER_PROTO: nl_cli_exp_parse_l4protonum(exp, NFNL_EXP_TUPLE_MASTER, optarg);
break;
122 case ARG_MASTER_SRC: nl_cli_exp_parse_src(exp, NFNL_EXP_TUPLE_MASTER, optarg);
break;
123 case ARG_MASTER_SPORT: nl_cli_exp_parse_src_port(exp, NFNL_EXP_TUPLE_MASTER, optarg);
break;
124 case ARG_MASTER_DST: nl_cli_exp_parse_dst(exp, NFNL_EXP_TUPLE_MASTER, optarg);
break;
125 case ARG_MASTER_DPORT: nl_cli_exp_parse_dst_port(exp, NFNL_EXP_TUPLE_MASTER, optarg);
break;
126 case 'F': nl_cli_exp_parse_family(exp, optarg);
break;
127 case ARG_TIMEOUT: nl_cli_exp_parse_timeout(exp, optarg);
break;
128 case ARG_HELPER_NAME: nl_cli_exp_parse_helper_name(exp, optarg);
break;
129 case ARG_FLAGS: nl_cli_exp_parse_flags(exp, optarg);
break;
133 sock = nl_cli_alloc_socket();
134 nl_cli_connect(sock, NETLINK_NETFILTER);
135 exp_cache = nl_cli_exp_alloc_cache(sock);
Dump object briefly on one line.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.
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).