summaryrefslogtreecommitdiffstats
path: root/src/ui.c
blob: bc01e61df3e5f92b044061801a6b5abfc2c414cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/* Copyright 2007-2010 Jozsef Kadlecsik (kadlec@blackhole.kfki.hu)
 *
 * This program is free software; you can redistribute it and/or modify   
 * it under the terms of the GNU General Public License version 2 as 
 * published by the Free Software Foundation.
 */
#include <libipset/linux_ip_set.h>		/* IPSET_CMD_* */
#include <libipset/types.h>			/* IPSET_*_ARG */
#include <libipset/session.h>			/* ipset_envopt_parse */
#include <libipset/parse.h>			/* ipset_parse_family */
#include <libipset/print.h>			/* ipset_print_family */
#include <libipset/ui.h>			/* prototypes */

/* Commands and environment options */

const struct ipset_commands ipset_commands[] = {
	[IPSET_CMD_CREATE - 1] = {
		.name = { "create", "c",  "-N", "--create", NULL },
		.has_arg = IPSET_MANDATORY_ARG2,
		.help = "SETNAME TYPENAME [type-specific-options]\n"
			"        Create a new set",
	},
	[IPSET_CMD_DESTROY - 1] = {
		.name = { "destroy", "x", "-X", "--destroy", NULL },
		.has_arg = IPSET_OPTIONAL_ARG,
		.help = "[SETNAME]\n"
		        "        Destroy a named set or all sets",
	},
	[IPSET_CMD_FLUSH - 1] = {
		.name = { "flush", "f",   "-F", "--flush", NULL },
		.has_arg = IPSET_OPTIONAL_ARG,
		.help = "[SETNAME]\n"
		        "        Flush a named set or all sets",
	},
	[IPSET_CMD_RENAME - 1] = {
		.name = { "rename", "e",  "-E", "--rename", NULL },
		.has_arg = IPSET_MANDATORY_ARG2,
		.help = "FROM-SETNAME TO-SETNAME\n"
		        "        Rename two sets",
	},
	[IPSET_CMD_SWAP - 1] = {
		.name = { "swap", "w",    "-W", "--swap", NULL },
		.has_arg = IPSET_MANDATORY_ARG2,
		.help = "FROM-SETNAME TO-SETNAME\n"
		        "        Swap the contect of two existing sets",
	},
	[IPSET_CMD_LIST - 1] = {
		.name = { "list", "l",    "-L", "--list", NULL },
		.has_arg = IPSET_OPTIONAL_ARG,
		.help = "[SETNAME]\n"
		        "        List the entries of a named set or all sets",
	},
	[IPSET_CMD_SAVE - 1] = {
		.name = { "save", "s",    "-S", "--save", NULL },
		.has_arg = IPSET_OPTIONAL_ARG,
		.help = "[SETNAME]\n"
		        "        Save the named set or all sets to stdout",
	},
	[IPSET_CMD_ADD - 1] = {
		.name = { "add", "a",     "-A", "--add", NULL },
		.has_arg = IPSET_MANDATORY_ARG2,
		.help = "SETNAME ENTRY\n"
		        "        Add entry to a named set",
	},
	[IPSET_CMD_DEL - 1] = {
		.name = { "del", "d",     "-D", "--del", NULL },
		.has_arg = IPSET_MANDATORY_ARG2,
		.help = "SETNAME ENTRY\n"
		        "        Delete entry from a named set",
	},
	[IPSET_CMD_TEST - 1] = {
		.name = { "test", "t",    "-T", "--test", NULL },
		.has_arg = IPSET_MANDATORY_ARG2,
		.help = "SETNAME ENTRY\n"
		        "        Test if entry exists in the named set",
	},
	[IPSET_CMD_HELP - 1] = {
		.name = { "help", "h",    "-H", "-h", "--help", NULL },
		.has_arg = IPSET_OPTIONAL_ARG,
		.help = "[TYPENAME]\n"
		        "        Print help, and settype specific help",
	},
	[IPSET_CMD_RESTORE - 1] = {
		.name = { "restore", "r", "-R", "--restore", NULL },
		.has_arg = IPSET_NO_ARG,
		.help = "\n"
		        "        Restore a saved state",
	},
	[IPSET_CMD_VERSION - 1] = {
		.name = { "version", "v", "-V", "-v", "--version", NULL },
		.has_arg = IPSET_NO_ARG,
		.help = "\n"
		        "        Print version information",
	},
	[IPSET_CMD_MAX - 1] = { },
};

const struct ipset_envopts ipset_envopts[] = {
	{ .name = { "family", "--family", NULL },
	  .has_arg = IPSET_MANDATORY_ARG,	.flag = IPSET_OPT_FAMILY,
	  .parse = ipset_parse_family,		.print = ipset_print_family,
	  .help = "inet|inet6\n"
	  	  "       Specify family when creating a set\n"
	  	  "       which supports multiple families.\n"
	  	  "       The default family is INET.",
	},
	{ .name = { "-o", "--output", NULL },
	  .has_arg = IPSET_MANDATORY_ARG,	.flag = IPSET_OPT_MAX,
	  .parse = ipset_parse_output,
	  .help = "plain|save|xml\n"
	  	  "       Specify output mode for listing sets.\n"
	  	  "       Default value for \"list\" command is mode \"plain\"\n"
	  	  "       and for \"save\" command is mode \"save\".",
	},
	{ .name = { "-s", "--sorted", NULL },
	  .parse = ipset_envopt_parse,
	  .has_arg = IPSET_NO_ARG,	.flag = IPSET_ENV_SORTED,
	  .help = "\n"
	          "        Print elements sorted (if supported by the set type).",
	},
	{ .name = { "-q", "--quiet", NULL },
	  .parse = ipset_envopt_parse,
	  .has_arg = IPSET_NO_ARG,	.flag = IPSET_ENV_QUIET,
	  .help = "\n"
	          "        Suppress any notice or warning message.",
	},
	{ .name = { "-r", "--resolve", NULL },
	  .parse = ipset_envopt_parse,
	  .has_arg = IPSET_NO_ARG,	.flag = IPSET_ENV_RESOLVE,
	  .help = "\n"
	          "        Try to resolve IP addresses in the output (slow!)",
	},
	{ .name = { "-x", "--exist", NULL },
	  .parse = ipset_envopt_parse,
	  .has_arg = IPSET_NO_ARG,	.flag = IPSET_ENV_EXIST,
	  .help = "\n"
	          "        Ignore errors when creating already created sets,\n"
	          "        when adding already existing elements\n"
		  "        or when deleting non-existing elements.",
	},
	/* Aliases */
	{ .name = { "-4", NULL },
	  .has_arg = IPSET_NO_ARG,		.flag = IPSET_OPT_FAMILY,
	  .parse = ipset_parse_family,
	},
	{ .name = { "-6", NULL },
	  .has_arg = IPSET_NO_ARG,		.flag = IPSET_OPT_FAMILY,
	  .parse = ipset_parse_family,
	},
	{ },
};