35
CLUSTER_OPT_TOTAL_NODES,
36
CLUSTER_OPT_LOCAL_NODE,
37
CLUSTER_OPT_NODE_MASK,
38
CLUSTER_OPT_HASH_SEED,
41
static const struct option cluster_opts[] = {
42
{.name = "cluster-total-nodes", .has_arg = true, .val = CLUSTER_OPT_TOTAL_NODES},
43
{.name = "cluster-local-node", .has_arg = true, .val = CLUSTER_OPT_LOCAL_NODE},
44
{.name = "cluster-local-nodemask", .has_arg = true, .val = CLUSTER_OPT_NODE_MASK},
45
{.name = "cluster-hash-seed", .has_arg = true, .val = CLUSTER_OPT_HASH_SEED},
50
cluster_parse(int c, char **argv, int invert, unsigned int *flags,
51
const void *entry, struct xt_entry_match **match)
28
F_CL_TOTAL_NODES = 1 << O_CL_TOTAL_NODES,
29
F_CL_LOCAL_NODE = 1 << O_CL_LOCAL_NODE,
30
F_CL_LOCAL_NODEMASK = 1 << O_CL_LOCAL_NODEMASK,
31
F_CL_HASH_SEED = 1 << O_CL_HASH_SEED,
34
#define s struct xt_cluster_match_info
35
static const struct xt_option_entry cluster_opts[] = {
36
{.name = "cluster-total-nodes", .id = O_CL_TOTAL_NODES,
37
.type = XTTYPE_UINT32, .min = 1, .max = XT_CLUSTER_NODES_MAX,
38
.flags = XTOPT_MAND | XTOPT_PUT, XTOPT_POINTER(s, total_nodes)},
39
{.name = "cluster-local-node", .id = O_CL_LOCAL_NODE,
40
.excl = F_CL_LOCAL_NODEMASK, .flags = XTOPT_INVERT,
41
.type = XTTYPE_UINT32, .min = 1, .max = XT_CLUSTER_NODES_MAX},
42
{.name = "cluster-local-nodemask", .id = O_CL_LOCAL_NODEMASK,
43
.excl = F_CL_LOCAL_NODE, .type = XTTYPE_UINT32,
44
.min = 1, .max = XT_CLUSTER_NODES_MAX,
45
.flags = XTOPT_INVERT | XTOPT_PUT, XTOPT_POINTER(s, node_mask)},
46
{.name = "cluster-hash-seed", .id = O_CL_HASH_SEED,
47
.type = XTTYPE_UINT32, .flags = XTOPT_MAND | XTOPT_PUT,
48
XTOPT_POINTER(s, hash_seed)},
52
static void cluster_parse(struct xt_option_call *cb)
53
struct xt_cluster_match_info *info = (void *)(*match)->data;
57
case CLUSTER_OPT_TOTAL_NODES:
58
if (*flags & (1 << c)) {
59
xtables_error(PARAMETER_PROBLEM,
61
"`--cluster-total-nodes' once");
63
if (!xtables_strtoui(optarg, NULL, &num, 1,
64
XT_CLUSTER_NODES_MAX)) {
65
xtables_error(PARAMETER_PROBLEM,
66
"Unable to parse `%s' in "
67
"`--cluster-total-nodes'", optarg);
70
info->total_nodes = total_nodes = num;
73
case CLUSTER_OPT_LOCAL_NODE:
74
if (*flags & (1 << c)) {
75
xtables_error(PARAMETER_PROBLEM,
77
"`--cluster-local-node' once");
79
if (*flags & (1 << CLUSTER_OPT_NODE_MASK)) {
80
xtables_error(PARAMETER_PROBLEM, "You cannot use "
81
"`--cluster-local-nodemask' and "
82
"`--cluster-local-node'");
84
xtables_check_inverse(optarg, &invert, &optind, 0, argv);
86
if (!xtables_strtoui(optarg, NULL, &num, 1,
87
XT_CLUSTER_NODES_MAX)) {
88
xtables_error(PARAMETER_PROBLEM,
89
"Unable to parse `%s' in "
90
"`--cluster-local-node'", optarg);
93
info->flags |= (1 << XT_CLUSTER_F_INV);
95
info->node_mask = node_mask = (1 << (num - 1));
98
case CLUSTER_OPT_NODE_MASK:
99
if (*flags & (1 << c)) {
100
xtables_error(PARAMETER_PROBLEM,
102
"`--cluster-local-node' once");
104
if (*flags & (1 << CLUSTER_OPT_LOCAL_NODE)) {
105
xtables_error(PARAMETER_PROBLEM, "You cannot use "
106
"`--cluster-local-nodemask' and "
107
"`--cluster-local-node'");
109
xtables_check_inverse(optarg, &invert, &optind, 0, argv);
111
if (!xtables_strtoui(optarg, NULL, &num, 1,
112
XT_CLUSTER_NODES_MAX)) {
113
xtables_error(PARAMETER_PROBLEM,
114
"Unable to parse `%s' in "
115
"`--cluster-local-node'", optarg);
118
info->flags |= (1 << XT_CLUSTER_F_INV);
120
info->node_mask = node_mask = num;
124
case CLUSTER_OPT_HASH_SEED:
125
if (*flags & (1 << c)) {
126
xtables_error(PARAMETER_PROBLEM,
128
"`--cluster-hash-seed' once");
130
if (!xtables_strtoui(optarg, NULL, &num, 0, UINT32_MAX)) {
131
xtables_error(PARAMETER_PROBLEM,
132
"Unable to parse `%s'", optarg);
134
info->hash_seed = num;
54
struct xt_cluster_match_info *info = cb->data;
56
xtables_option_parse(cb);
57
switch (cb->entry->id) {
60
info->flags |= XT_CLUSTER_F_INV;
61
info->node_mask = 1 << (cb->val.u32 - 1);
63
case O_CL_LOCAL_NODEMASK:
65
info->flags |= XT_CLUSTER_F_INV;
145
cluster_check(unsigned int flags)
70
static void cluster_check(struct xt_fcheck_call *cb)
147
if ((flags & ((1 << CLUSTER_OPT_TOTAL_NODES) |
148
(1 << CLUSTER_OPT_LOCAL_NODE) |
149
(1 << CLUSTER_OPT_HASH_SEED)))
150
== ((1 << CLUSTER_OPT_TOTAL_NODES) |
151
(1 << CLUSTER_OPT_LOCAL_NODE) |
152
(1 << CLUSTER_OPT_HASH_SEED))) {
153
if (node_mask >= (1ULL << total_nodes)) {
72
const struct xt_cluster_match_info *info = cb->data;
75
test = F_CL_TOTAL_NODES | F_CL_LOCAL_NODE | F_CL_HASH_SEED;
76
if ((cb->xflags & test) == test) {
77
if (info->node_mask >= (1ULL << info->total_nodes))
154
78
xtables_error(PARAMETER_PROBLEM,
156
80
"`--cluster-local-node' "
157
81
"must be <= `--cluster-total-nodes'");
161
if ((flags & ((1 << CLUSTER_OPT_TOTAL_NODES) |
162
(1 << CLUSTER_OPT_NODE_MASK) |
163
(1 << CLUSTER_OPT_HASH_SEED)))
164
== ((1 << CLUSTER_OPT_TOTAL_NODES) |
165
(1 << CLUSTER_OPT_NODE_MASK) |
166
(1 << CLUSTER_OPT_HASH_SEED))) {
167
if (node_mask >= (1ULL << total_nodes)) {
85
test = F_CL_TOTAL_NODES | F_CL_LOCAL_NODEMASK | F_CL_HASH_SEED;
86
if ((cb->xflags & test) == test) {
87
if (info->node_mask >= (1ULL << info->total_nodes))
168
88
xtables_error(PARAMETER_PROBLEM,
170
90
"`--cluster-local-nodemask' too big "
171
91
"for `--cluster-total-nodes'");
175
if (!(flags & (1 << CLUSTER_OPT_TOTAL_NODES))) {
176
xtables_error(PARAMETER_PROBLEM,
177
"cluster match: `--cluster-total-nodes' "
180
if (!(flags & (1 << CLUSTER_OPT_HASH_SEED))) {
181
xtables_error(PARAMETER_PROBLEM,
182
"cluster match: `--cluster-hash-seed' "
185
if (!(flags & ((1 << (CLUSTER_OPT_LOCAL_NODE) |
186
(1 << (CLUSTER_OPT_NODE_MASK)))))) {
94
if (!(cb->xflags & (F_CL_LOCAL_NODE | F_CL_LOCAL_NODEMASK)))
187
95
xtables_error(PARAMETER_PROBLEM,
188
96
"cluster match: `--cluster-local-node' or"
189
97
"`--cluster-local-nodemask' is missing");