libnl  3.3.0
nf-exp-list.c
1 /*
2  * src/nf-exp-list.c List Expectation Entries
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation version 2.1
7  * of the License.
8  *
9  * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch>
10  * Copyright (c) 2007 Philip Craig <philipc@snapgear.com>
11  * Copyright (c) 2007 Secure Computing Corporation
12  * Copyright (c) 2012 Rich Fought <rich.fought@watchguard.com>
13  */
14 
15 #include <netlink/cli/utils.h>
16 #include <netlink/cli/exp.h>
17 
18 #include <linux/netlink.h>
19 
20 static void print_usage(void)
21 {
22  printf(
23  "Usage: nf-exp-list [OPTION]... [EXPECTATION ENTRY]\n"
24  "\n"
25  "Options\n"
26  " -f, --format=TYPE Output format { brief | details }\n"
27  " -h, --help Show this help\n"
28  " -v, --version Show versioning information\n"
29  "\n"
30  "Expectation Selection\n"
31  " -i, --id=NUM Identifier\n"
32  " --expect-proto=PROTOCOL Expectation protocol\n"
33  " --expect-src=ADDR Expectation source address\n"
34  " --expect-sport=PORT Expectation source port\n"
35  " --expect-dst=ADDR Expectation destination address\n"
36  " --expect-dport=PORT Expectation destination port\n"
37  " --master-proto=PROTOCOL Master conntrack protocol\n"
38  " --master-src=ADDR Master conntrack source address\n"
39  " --master-sport=PORT Master conntrack source port\n"
40  " --master-dst=ADDR Master conntrack destination address\n"
41  " --master-dport=PORT Master conntrack destination port\n"
42  " -F, --family=FAMILY Address family\n"
43  " --timeout=NUM Timeout value\n"
44  " --helper=STRING Helper Name\n"
45  //" --flags Flags\n"
46  );
47  exit(0);
48 }
49 
50 int main(int argc, char *argv[])
51 {
52  struct nl_sock *sock;
53  struct nl_cache *exp_cache;
54  struct nfnl_exp *exp;
55  struct nl_dump_params params = {
57  .dp_fd = stdout,
58  };
59 
60  exp = nl_cli_exp_alloc();
61 
62  for (;;) {
63  int c, optidx = 0;
64  enum {
65  ARG_MARK = 270,
66  ARG_TCP_STATE = 271,
67  ARG_EXPECT_PROTO,
68  ARG_EXPECT_SRC,
69  ARG_EXPECT_SPORT,
70  ARG_EXPECT_DST,
71  ARG_EXPECT_DPORT,
72  ARG_MASTER_PROTO,
73  ARG_MASTER_SRC,
74  ARG_MASTER_SPORT,
75  ARG_MASTER_DST,
76  ARG_MASTER_DPORT,
77  ARG_TIMEOUT,
78  ARG_HELPER_NAME,
79  ARG_FLAGS,
80  };
81  static struct option long_opts[] = {
82  { "format", 1, 0, 'f' },
83  { "help", 0, 0, 'h' },
84  { "version", 0, 0, 'v' },
85  { "id", 1, 0, 'i' },
86  { "expect-proto", 1, 0, ARG_EXPECT_PROTO },
87  { "expect-src", 1, 0, ARG_EXPECT_SRC },
88  { "expect-sport", 1, 0, ARG_EXPECT_SPORT },
89  { "expect-dst", 1, 0, ARG_EXPECT_DST },
90  { "expect-dport", 1, 0, ARG_EXPECT_DPORT },
91  { "master-proto", 1, 0, ARG_MASTER_PROTO },
92  { "master-src", 1, 0, ARG_MASTER_SRC },
93  { "master-sport", 1, 0, ARG_MASTER_SPORT },
94  { "master-dst", 1, 0, ARG_MASTER_DST },
95  { "master-dport", 1, 0, ARG_MASTER_DPORT },
96  { "family", 1, 0, 'F' },
97  { "timeout", 1, 0, ARG_TIMEOUT },
98  { "helper", 1, 0, ARG_HELPER_NAME },
99  { "flags", 1, 0, ARG_FLAGS},
100  { 0, 0, 0, 0 }
101  };
102 
103  c = getopt_long(argc, argv, "46f:hvi:p:F:", long_opts, &optidx);
104  if (c == -1)
105  break;
106 
107  switch (c) {
108  case '?': exit(NLE_INVAL);
109  case '4': nfnl_exp_set_family(exp, AF_INET); break;
110  case '6': nfnl_exp_set_family(exp, AF_INET6); break;
111  case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break;
112  case 'h': print_usage(); break;
113  case 'v': nl_cli_print_version(); break;
114  case 'i': nl_cli_exp_parse_id(exp, optarg); break;
115  case ARG_EXPECT_PROTO: nl_cli_exp_parse_l4protonum(exp, NFNL_EXP_TUPLE_EXPECT, optarg); break;
116  case ARG_EXPECT_SRC: nl_cli_exp_parse_src(exp, NFNL_EXP_TUPLE_EXPECT, optarg); break;
117  case ARG_EXPECT_SPORT: nl_cli_exp_parse_src_port(exp, NFNL_EXP_TUPLE_EXPECT, optarg); break;
118  case ARG_EXPECT_DST: nl_cli_exp_parse_dst(exp, NFNL_EXP_TUPLE_EXPECT, optarg); break;
119  case ARG_EXPECT_DPORT: nl_cli_exp_parse_dst_port(exp, NFNL_EXP_TUPLE_EXPECT, optarg); break;
120  case ARG_MASTER_PROTO: nl_cli_exp_parse_l4protonum(exp, NFNL_EXP_TUPLE_MASTER, optarg); break;
121  case ARG_MASTER_SRC: nl_cli_exp_parse_src(exp, NFNL_EXP_TUPLE_MASTER, optarg); break;
122  case ARG_MASTER_SPORT: nl_cli_exp_parse_src_port(exp, NFNL_EXP_TUPLE_MASTER, optarg); break;
123  case ARG_MASTER_DST: nl_cli_exp_parse_dst(exp, NFNL_EXP_TUPLE_MASTER, optarg); break;
124  case ARG_MASTER_DPORT: nl_cli_exp_parse_dst_port(exp, NFNL_EXP_TUPLE_MASTER, optarg); break;
125  case 'F': nl_cli_exp_parse_family(exp, optarg); break;
126  case ARG_TIMEOUT: nl_cli_exp_parse_timeout(exp, optarg); break;
127  case ARG_HELPER_NAME: nl_cli_exp_parse_helper_name(exp, optarg); break;
128  case ARG_FLAGS: nl_cli_exp_parse_flags(exp, optarg); break;
129  }
130  }
131 
132  sock = nl_cli_alloc_socket();
133  nl_cli_connect(sock, NETLINK_NETFILTER);
134  exp_cache = nl_cli_exp_alloc_cache(sock);
135 
136  nl_cache_dump_filter(exp_cache, &params, OBJ_CAST(exp));
137 
138  return 0;
139 }
Dump object briefly on one line.
Definition: types.h:22
enum nl_dump_type dp_type
Specifies the type of dump that is requested.
Definition: types.h:38
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).
Definition: cache.c:1216
Dumping parameters.
Definition: types.h:33