1
/* Copyright 2007-2010 Jozsef Kadlecsik (kadlec@blackhole.kfki.hu)
3
* This program is free software; you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License version 2 as
5
* published by the Free Software Foundation.
7
#include <libipset/data.h> /* IPSET_OPT_* */
8
#include <libipset/parse.h> /* parser functions */
9
#include <libipset/print.h> /* printing functions */
10
#include <libipset/ui.h> /* ipset_port_usage */
11
#include <libipset/types.h> /* prototypes */
13
/* Parse commandline arguments */
14
static const struct ipset_arg hash_ipportip_create_args[] = {
15
{ .name = { "family", NULL },
16
.has_arg = IPSET_MANDATORY_ARG, .opt = IPSET_OPT_FAMILY,
17
.parse = ipset_parse_family, .print = ipset_print_family,
19
/* Alias: family inet */
20
{ .name = { "-4", NULL },
21
.has_arg = IPSET_NO_ARG, .opt = IPSET_OPT_FAMILY,
22
.parse = ipset_parse_family,
24
/* Alias: family inet6 */
25
{ .name = { "-6", NULL },
26
.has_arg = IPSET_NO_ARG, .opt = IPSET_OPT_FAMILY,
27
.parse = ipset_parse_family,
29
{ .name = { "hashsize", NULL },
30
.has_arg = IPSET_MANDATORY_ARG, .opt = IPSET_OPT_HASHSIZE,
31
.parse = ipset_parse_uint32, .print = ipset_print_number,
33
{ .name = { "maxelem", NULL },
34
.has_arg = IPSET_MANDATORY_ARG, .opt = IPSET_OPT_MAXELEM,
35
.parse = ipset_parse_uint32, .print = ipset_print_number,
37
{ .name = { "timeout", NULL },
38
.has_arg = IPSET_MANDATORY_ARG, .opt = IPSET_OPT_TIMEOUT,
39
.parse = ipset_parse_uint32, .print = ipset_print_number,
41
/* Backward compatibility */
42
{ .name = { "probes", NULL },
43
.has_arg = IPSET_MANDATORY_ARG, .opt = IPSET_OPT_PROBES,
44
.parse = ipset_parse_ignored, .print = ipset_print_number,
46
{ .name = { "resize", NULL },
47
.has_arg = IPSET_MANDATORY_ARG, .opt = IPSET_OPT_RESIZE,
48
.parse = ipset_parse_ignored, .print = ipset_print_number,
50
{ .name = { "from", NULL },
51
.has_arg = IPSET_MANDATORY_ARG, .opt = IPSET_OPT_IP,
52
.parse = ipset_parse_ignored,
54
{ .name = { "to", NULL },
55
.has_arg = IPSET_MANDATORY_ARG, .opt = IPSET_OPT_IP_TO,
56
.parse = ipset_parse_ignored,
58
{ .name = { "network", NULL },
59
.has_arg = IPSET_MANDATORY_ARG, .opt = IPSET_OPT_IP,
60
.parse = ipset_parse_ignored,
65
static const struct ipset_arg hash_ipportip_add_args[] = {
66
{ .name = { "timeout", NULL },
67
.has_arg = IPSET_MANDATORY_ARG, .opt = IPSET_OPT_TIMEOUT,
68
.parse = ipset_parse_uint32, .print = ipset_print_number,
73
static const char hash_ipportip_usage[] =
74
"create SETNAME hash:ip,port,ip\n"
75
" [family inet|inet6]\n"
76
" [hashsize VALUE] [maxelem VALUE]\n"
78
"add SETNAME IP,PROTO:PORT,IP [timeout VALUE]\n"
79
"del SETNAME IP,PROTO:PORT,IP\n"
80
"test SETNAME IP,PROTO:PORT,IP\n\n"
81
"where depending on the INET family\n"
82
" IP is a valid IPv4 or IPv6 address (or hostname).\n"
83
" Adding/deleting multiple elements in IP/CIDR or FROM-TO form\n"
84
" in the first IP component is supported for IPv4.\n"
85
" Adding/deleting multiple elements with TCP/UDP port range\n"
86
" is supported both for IPv4 and IPv6.\n";
88
struct ipset_type ipset_hash_ipportip0 = {
89
.name = "hash:ip,port,ip",
90
.alias = { "ipportiphash", NULL },
93
.dimension = IPSET_DIM_THREE,
96
.parse = ipset_parse_ip4_single6,
97
.print = ipset_print_ip,
101
.parse = ipset_parse_proto_port,
102
.print = ipset_print_proto_port,
103
.opt = IPSET_OPT_PORT
105
[IPSET_DIM_THREE] = {
106
.parse = ipset_parse_single_ip,
107
.print = ipset_print_ip,
112
[IPSET_CREATE] = hash_ipportip_create_args,
113
[IPSET_ADD] = hash_ipportip_add_args,
117
[IPSET_ADD] = IPSET_FLAG(IPSET_OPT_IP)
118
| IPSET_FLAG(IPSET_OPT_PORT)
119
| IPSET_FLAG(IPSET_OPT_PROTO)
120
| IPSET_FLAG(IPSET_OPT_IP2),
121
[IPSET_DEL] = IPSET_FLAG(IPSET_OPT_IP)
122
| IPSET_FLAG(IPSET_OPT_PORT)
123
| IPSET_FLAG(IPSET_OPT_PROTO)
124
| IPSET_FLAG(IPSET_OPT_IP2),
125
[IPSET_TEST] = IPSET_FLAG(IPSET_OPT_IP)
126
| IPSET_FLAG(IPSET_OPT_PORT)
127
| IPSET_FLAG(IPSET_OPT_PROTO)
128
| IPSET_FLAG(IPSET_OPT_IP2),
131
[IPSET_CREATE] = IPSET_FLAG(IPSET_OPT_HASHSIZE)
132
| IPSET_FLAG(IPSET_OPT_MAXELEM)
133
| IPSET_FLAG(IPSET_OPT_TIMEOUT),
134
[IPSET_ADD] = IPSET_FLAG(IPSET_OPT_IP)
135
| IPSET_FLAG(IPSET_OPT_IP_TO)
136
| IPSET_FLAG(IPSET_OPT_PORT)
137
| IPSET_FLAG(IPSET_OPT_PORT_TO)
138
| IPSET_FLAG(IPSET_OPT_PROTO)
139
| IPSET_FLAG(IPSET_OPT_IP2)
140
| IPSET_FLAG(IPSET_OPT_TIMEOUT),
141
[IPSET_DEL] = IPSET_FLAG(IPSET_OPT_IP)
142
| IPSET_FLAG(IPSET_OPT_IP_TO)
143
| IPSET_FLAG(IPSET_OPT_PORT)
144
| IPSET_FLAG(IPSET_OPT_PORT_TO)
145
| IPSET_FLAG(IPSET_OPT_PROTO)
146
| IPSET_FLAG(IPSET_OPT_IP2),
147
[IPSET_TEST] = IPSET_FLAG(IPSET_OPT_IP)
148
| IPSET_FLAG(IPSET_OPT_PORT)
149
| IPSET_FLAG(IPSET_OPT_PROTO)
150
| IPSET_FLAG(IPSET_OPT_IP2),
153
.usage = hash_ipportip_usage,
154
.usagefn = ipset_port_usage,