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 18static void print_usage(void) 19{ 20 printf( 21 "Usage: nf-exp-list [OPTION]... [EXPECTATION ENTRY]\n" 22 "\n" 23 "Options\n" 24 " -f, --format=TYPE Output format { brief | details }\n" 25 " -h, --help Show this help\n" 26 " -v, --version Show versioning information\n" 27 "\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" 43 //" --flags Flags\n" 44 ); 45 exit(0); 46} 47 48int main(int argc, char *argv[]) 49{ 50 struct nl_sock *sock; 51 struct nl_cache *exp_cache; 52 struct nfnl_exp *exp; 53 struct nl_dump_params params = { 54 .dp_type = NL_DUMP_LINE, 55 .dp_fd = stdout, 56 }; 57 58 exp = nl_cli_exp_alloc(); 59 60 for (;;) { 61 int c, optidx = 0; 62 enum { 63 ARG_MARK = 270, 64 ARG_TCP_STATE = 271, 65 ARG_EXPECT_PROTO, 66 ARG_EXPECT_SRC, 67 ARG_EXPECT_SPORT, 68 ARG_EXPECT_DST, 69 ARG_EXPECT_DPORT, 70 ARG_MASTER_PROTO, 71 ARG_MASTER_SRC, 72 ARG_MASTER_SPORT, 73 ARG_MASTER_DST, 74 ARG_MASTER_DPORT, 75 ARG_TIMEOUT, 76 ARG_HELPER_NAME, 77 ARG_FLAGS, 78 }; 79 static struct option long_opts[] = { 80 { "format", 1, 0, 'f' }, 81 { "help", 0, 0, 'h' }, 82 { "version", 0, 0, 'v' }, 83 { "id", 1, 0, 'i' }, 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}, 98 { 0, 0, 0, 0 } 99 }; 100 101 c = getopt_long(argc, argv, "46f:hvi:p:F:", long_opts, &optidx); 102 if (c == -1) 103 break; 104 105 switch (c) { 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; 127 } 128 } 129 130 sock = nl_cli_alloc_socket(); 131 nl_cli_connect(sock, NETLINK_NETFILTER); 132 exp_cache = nl_cli_exp_alloc_cache(sock); 133 134 nl_cache_dump_filter(exp_cache, ¶ms, OBJ_CAST(exp)); 135 136 return 0; 137} 138