1 /* 2 * src/nf-exp-delete.c Delete an expectation 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 (at) suug.ch> 10 * Copyright (c) 2007 Philip Craig <philipc (at) snapgear.com> 11 * Copyright (c) 2007 Secure Computing Corporation 12 * Copyright (c) 2012 Rich Fought <rich.fought (at) watchguard.com> 13 */ 14 15 #include <netlink/cli/utils.h> 16 #include <netlink/cli/exp.h> 17 18 static int quiet = 0; 19 20 static void print_usage(void) 21 { 22 printf( 23 "Usage: nf-exp-list [OPTION]... [CONNTRACK ENTRY]\n" 24 "\n" 25 "Options\n" 26 " --replace Replace the address if it exists.\n" 27 " -q, --quiet Do not print informal notifications.\n" 28 " -h, --help Show this help\n" 29 " -v, --version Show versioning information\n" 30 "\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 " --mask-proto=PROTOCOL Mask protocol\n" 44 " --mask-src=ADDR Mask source address\n" 45 " --mask-sport=PORT Mask source port\n" 46 " --mask-dst=ADDR Mask destination address\n" 47 " --mask-dport=PORT Mask destination port\n" 48 " -F, --family=FAMILY Address family\n" 49 " --timeout=NUM Timeout value\n" 50 " --helper=STRING Helper Name\n" 51 " --flags Flags\n" 52 ); 53 exit(0); 54 } 55 56 int main(int argc, char *argv[]) 57 { 58 struct nl_sock *sock; 59 struct nfnl_exp *exp; 60 struct nl_dump_params params = { 61 .dp_type = NL_DUMP_LINE, 62 .dp_fd = stdout, 63 }; 64 int err, nlflags = 0; 65 66 exp = nl_cli_exp_alloc(); 67 68 for (;;) { 69 int c, optidx = 0; 70 enum { 71 ARG_MARK = 270, 72 ARG_TCP_STATE = 271, 73 ARG_EXPECT_PROTO, 74 ARG_EXPECT_SRC, 75 ARG_EXPECT_SPORT, 76 ARG_EXPECT_DST, 77 ARG_EXPECT_DPORT, 78 ARG_MASTER_PROTO, 79 ARG_MASTER_SRC, 80 ARG_MASTER_SPORT, 81 ARG_MASTER_DST, 82 ARG_MASTER_DPORT, 83 ARG_MASK_PROTO, 84 ARG_MASK_SRC, 85 ARG_MASK_SPORT, 86 ARG_MASK_DST, 87 ARG_MASK_DPORT, 88 ARG_TIMEOUT, 89 ARG_HELPER_NAME, 90 ARG_FLAGS, 91 }; 92 static struct option long_opts[] = { 93 { "quiet", 0, 0, 'q' }, 94 { "help", 0, 0, 'h' }, 95 { "version", 0, 0, 'v' }, 96 { "id", 1, 0, 'i' }, 97 { "expect-proto", 1, 0, ARG_EXPECT_PROTO }, 98 { "expect-src", 1, 0, ARG_EXPECT_SRC }, 99 { "expect-sport", 1, 0, ARG_EXPECT_SPORT }, 100 { "expect-dst", 1, 0, ARG_EXPECT_DST }, 101 { "expect-dport", 1, 0, ARG_EXPECT_DPORT }, 102 { "master-proto", 1, 0, ARG_MASTER_PROTO }, 103 { "master-src", 1, 0, ARG_MASTER_SRC }, 104 { "master-sport", 1, 0, ARG_MASTER_SPORT }, 105 { "master-dst", 1, 0, ARG_MASTER_DST }, 106 { "master-dport", 1, 0, ARG_MASTER_DPORT }, 107 { "mask-proto", 1, 0, ARG_MASK_PROTO }, 108 { "mask-src", 1, 0, ARG_MASK_SRC }, 109 { "mask-sport", 1, 0, ARG_MASK_SPORT }, 110 { "mask-dst", 1, 0, ARG_MASK_DST }, 111 { "mask-dport", 1, 0, ARG_MASK_DPORT }, 112 { "family", 1, 0, 'F' }, 113 { "timeout", 1, 0, ARG_TIMEOUT }, 114 { "helper", 1, 0, ARG_HELPER_NAME }, 115 { "flags", 1, 0, ARG_FLAGS}, 116 { 0, 0, 0, 0 } 117 }; 118 119 c = getopt_long(argc, argv, "46f:hvi:p:F:", long_opts, &optidx); 120 if (c == -1) 121 break; 122 123 switch (c) { 124 case '?': exit(NLE_INVAL); 125 case 'q': quiet = 1; break; 126 case '4': nfnl_exp_set_family(exp, AF_INET); break; 127 case '6': nfnl_exp_set_family(exp, AF_INET6); break; 128 case 'h': print_usage(); break; 129 case 'v': nl_cli_print_version(); break; 130 case 'i': nl_cli_exp_parse_id(exp, optarg); break; 131 case ARG_EXPECT_PROTO: nl_cli_exp_parse_l4protonum(exp, NFNL_EXP_TUPLE_EXPECT, optarg); break; 132 case ARG_EXPECT_SRC: nl_cli_exp_parse_src(exp, NFNL_EXP_TUPLE_EXPECT, optarg); break; 133 case ARG_EXPECT_SPORT: nl_cli_exp_parse_src_port(exp, NFNL_EXP_TUPLE_EXPECT, optarg); break; 134 case ARG_EXPECT_DST: nl_cli_exp_parse_dst(exp, NFNL_EXP_TUPLE_EXPECT, optarg); break; 135 case ARG_EXPECT_DPORT: nl_cli_exp_parse_dst_port(exp, NFNL_EXP_TUPLE_EXPECT, optarg); break; 136 case ARG_MASTER_PROTO: nl_cli_exp_parse_l4protonum(exp, NFNL_EXP_TUPLE_MASTER, optarg); break; 137 case ARG_MASTER_SRC: nl_cli_exp_parse_src(exp, NFNL_EXP_TUPLE_MASTER, optarg); break; 138 case ARG_MASTER_SPORT: nl_cli_exp_parse_src_port(exp, NFNL_EXP_TUPLE_MASTER, optarg); break; 139 case ARG_MASTER_DST: nl_cli_exp_parse_dst(exp, NFNL_EXP_TUPLE_MASTER, optarg); break; 140 case ARG_MASTER_DPORT: nl_cli_exp_parse_dst_port(exp, NFNL_EXP_TUPLE_MASTER, optarg); break; 141 case ARG_MASK_PROTO: nl_cli_exp_parse_l4protonum(exp, NFNL_EXP_TUPLE_MASK, optarg); break; 142 case ARG_MASK_SRC: nl_cli_exp_parse_src(exp, NFNL_EXP_TUPLE_MASK, optarg); break; 143 case ARG_MASK_SPORT: nl_cli_exp_parse_src_port(exp, NFNL_EXP_TUPLE_MASK, optarg); break; 144 case ARG_MASK_DST: nl_cli_exp_parse_dst(exp, NFNL_EXP_TUPLE_MASK, optarg); break; 145 case ARG_MASK_DPORT: nl_cli_exp_parse_dst_port(exp, NFNL_EXP_TUPLE_MASK, optarg); break; 146 case 'F': nl_cli_exp_parse_family(exp, optarg); break; 147 case ARG_TIMEOUT: nl_cli_exp_parse_timeout(exp, optarg); break; 148 case ARG_HELPER_NAME: nl_cli_exp_parse_helper_name(exp, optarg); break; 149 case ARG_FLAGS: nl_cli_exp_parse_flags(exp, optarg); break; 150 } 151 } 152 153 sock = nl_cli_alloc_socket(); 154 nl_cli_connect(sock, NETLINK_NETFILTER); 155 156 if ((err = nfnl_exp_del(sock, exp, nlflags)) < 0) 157 nl_cli_fatal(err, "Unable to delete expectation: %s", nl_geterror(err)); 158 159 if (!quiet) { 160 printf("Deleted "); 161 nl_object_dump(OBJ_CAST(exp), ¶ms); 162 } 163 164 return 0; 165 } 166