Skip to content

Commit 4269fea

Browse files
committed
Revert "netfilter: nft_numgen: add map lookups for numgen random operations"
Laura found a better way to do this from userspace without requiring kernel infrastructure, revert this. Fixes: 978d8f9 ("netfilter: nft_numgen: add map lookups for numgen random operations") Signed-off-by: Laura Garcia Liebana <nevola@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 5a8de47 commit 4269fea

2 files changed

Lines changed: 2 additions & 129 deletions

File tree

‎include/uapi/linux/netfilter/nf_tables.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,8 +1635,8 @@ enum nft_ng_attributes {
16351635
NFTA_NG_MODULUS,
16361636
NFTA_NG_TYPE,
16371637
NFTA_NG_OFFSET,
1638-
NFTA_NG_SET_NAME,
1639-
NFTA_NG_SET_ID,
1638+
NFTA_NG_SET_NAME, /* deprecated */
1639+
NFTA_NG_SET_ID, /* deprecated */
16401640
__NFTA_NG_MAX
16411641
};
16421642
#define NFTA_NG_MAX (__NFTA_NG_MAX - 1)

‎net/netfilter/nft_numgen.c‎

Lines changed: 0 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ struct nft_ng_inc {
2424
u32 modulus;
2525
atomic_t counter;
2626
u32 offset;
27-
struct nft_set *map;
2827
};
2928

3029
static u32 nft_ng_inc_gen(struct nft_ng_inc *priv)
@@ -48,34 +47,11 @@ static void nft_ng_inc_eval(const struct nft_expr *expr,
4847
regs->data[priv->dreg] = nft_ng_inc_gen(priv);
4948
}
5049

51-
static void nft_ng_inc_map_eval(const struct nft_expr *expr,
52-
struct nft_regs *regs,
53-
const struct nft_pktinfo *pkt)
54-
{
55-
struct nft_ng_inc *priv = nft_expr_priv(expr);
56-
const struct nft_set *map = priv->map;
57-
const struct nft_set_ext *ext;
58-
u32 result;
59-
bool found;
60-
61-
result = nft_ng_inc_gen(priv);
62-
found = map->ops->lookup(nft_net(pkt), map, &result, &ext);
63-
64-
if (!found)
65-
return;
66-
67-
nft_data_copy(&regs->data[priv->dreg],
68-
nft_set_ext_data(ext), map->dlen);
69-
}
70-
7150
static const struct nla_policy nft_ng_policy[NFTA_NG_MAX + 1] = {
7251
[NFTA_NG_DREG] = { .type = NLA_U32 },
7352
[NFTA_NG_MODULUS] = { .type = NLA_U32 },
7453
[NFTA_NG_TYPE] = { .type = NLA_U32 },
7554
[NFTA_NG_OFFSET] = { .type = NLA_U32 },
76-
[NFTA_NG_SET_NAME] = { .type = NLA_STRING,
77-
.len = NFT_SET_MAXNAMELEN - 1 },
78-
[NFTA_NG_SET_ID] = { .type = NLA_U32 },
7955
};
8056

8157
static int nft_ng_inc_init(const struct nft_ctx *ctx,
@@ -101,22 +77,6 @@ static int nft_ng_inc_init(const struct nft_ctx *ctx,
10177
NFT_DATA_VALUE, sizeof(u32));
10278
}
10379

104-
static int nft_ng_inc_map_init(const struct nft_ctx *ctx,
105-
const struct nft_expr *expr,
106-
const struct nlattr * const tb[])
107-
{
108-
struct nft_ng_inc *priv = nft_expr_priv(expr);
109-
u8 genmask = nft_genmask_next(ctx->net);
110-
111-
nft_ng_inc_init(ctx, expr, tb);
112-
113-
priv->map = nft_set_lookup_global(ctx->net, ctx->table,
114-
tb[NFTA_NG_SET_NAME],
115-
tb[NFTA_NG_SET_ID], genmask);
116-
117-
return PTR_ERR_OR_ZERO(priv->map);
118-
}
119-
12080
static int nft_ng_dump(struct sk_buff *skb, enum nft_registers dreg,
12181
u32 modulus, enum nft_ng_types type, u32 offset)
12282
{
@@ -143,27 +103,10 @@ static int nft_ng_inc_dump(struct sk_buff *skb, const struct nft_expr *expr)
143103
priv->offset);
144104
}
145105

146-
static int nft_ng_inc_map_dump(struct sk_buff *skb,
147-
const struct nft_expr *expr)
148-
{
149-
const struct nft_ng_inc *priv = nft_expr_priv(expr);
150-
151-
if (nft_ng_dump(skb, priv->dreg, priv->modulus,
152-
NFT_NG_INCREMENTAL, priv->offset) ||
153-
nla_put_string(skb, NFTA_NG_SET_NAME, priv->map->name))
154-
goto nla_put_failure;
155-
156-
return 0;
157-
158-
nla_put_failure:
159-
return -1;
160-
}
161-
162106
struct nft_ng_random {
163107
enum nft_registers dreg:8;
164108
u32 modulus;
165109
u32 offset;
166-
struct nft_set *map;
167110
};
168111

169112
static u32 nft_ng_random_gen(struct nft_ng_random *priv)
@@ -183,25 +126,6 @@ static void nft_ng_random_eval(const struct nft_expr *expr,
183126
regs->data[priv->dreg] = nft_ng_random_gen(priv);
184127
}
185128

186-
static void nft_ng_random_map_eval(const struct nft_expr *expr,
187-
struct nft_regs *regs,
188-
const struct nft_pktinfo *pkt)
189-
{
190-
struct nft_ng_random *priv = nft_expr_priv(expr);
191-
const struct nft_set *map = priv->map;
192-
const struct nft_set_ext *ext;
193-
u32 result;
194-
bool found;
195-
196-
result = nft_ng_random_gen(priv);
197-
found = map->ops->lookup(nft_net(pkt), map, &result, &ext);
198-
if (!found)
199-
return;
200-
201-
nft_data_copy(&regs->data[priv->dreg],
202-
nft_set_ext_data(ext), map->dlen);
203-
}
204-
205129
static int nft_ng_random_init(const struct nft_ctx *ctx,
206130
const struct nft_expr *expr,
207131
const struct nlattr * const tb[])
@@ -226,21 +150,6 @@ static int nft_ng_random_init(const struct nft_ctx *ctx,
226150
NFT_DATA_VALUE, sizeof(u32));
227151
}
228152

229-
static int nft_ng_random_map_init(const struct nft_ctx *ctx,
230-
const struct nft_expr *expr,
231-
const struct nlattr * const tb[])
232-
{
233-
struct nft_ng_random *priv = nft_expr_priv(expr);
234-
u8 genmask = nft_genmask_next(ctx->net);
235-
236-
nft_ng_random_init(ctx, expr, tb);
237-
priv->map = nft_set_lookup_global(ctx->net, ctx->table,
238-
tb[NFTA_NG_SET_NAME],
239-
tb[NFTA_NG_SET_ID], genmask);
240-
241-
return PTR_ERR_OR_ZERO(priv->map);
242-
}
243-
244153
static int nft_ng_random_dump(struct sk_buff *skb, const struct nft_expr *expr)
245154
{
246155
const struct nft_ng_random *priv = nft_expr_priv(expr);
@@ -249,22 +158,6 @@ static int nft_ng_random_dump(struct sk_buff *skb, const struct nft_expr *expr)
249158
priv->offset);
250159
}
251160

252-
static int nft_ng_random_map_dump(struct sk_buff *skb,
253-
const struct nft_expr *expr)
254-
{
255-
const struct nft_ng_random *priv = nft_expr_priv(expr);
256-
257-
if (nft_ng_dump(skb, priv->dreg, priv->modulus,
258-
NFT_NG_RANDOM, priv->offset) ||
259-
nla_put_string(skb, NFTA_NG_SET_NAME, priv->map->name))
260-
goto nla_put_failure;
261-
262-
return 0;
263-
264-
nla_put_failure:
265-
return -1;
266-
}
267-
268161
static struct nft_expr_type nft_ng_type;
269162
static const struct nft_expr_ops nft_ng_inc_ops = {
270163
.type = &nft_ng_type,
@@ -274,14 +167,6 @@ static const struct nft_expr_ops nft_ng_inc_ops = {
274167
.dump = nft_ng_inc_dump,
275168
};
276169

277-
static const struct nft_expr_ops nft_ng_inc_map_ops = {
278-
.type = &nft_ng_type,
279-
.size = NFT_EXPR_SIZE(sizeof(struct nft_ng_inc)),
280-
.eval = nft_ng_inc_map_eval,
281-
.init = nft_ng_inc_map_init,
282-
.dump = nft_ng_inc_map_dump,
283-
};
284-
285170
static const struct nft_expr_ops nft_ng_random_ops = {
286171
.type = &nft_ng_type,
287172
.size = NFT_EXPR_SIZE(sizeof(struct nft_ng_random)),
@@ -290,14 +175,6 @@ static const struct nft_expr_ops nft_ng_random_ops = {
290175
.dump = nft_ng_random_dump,
291176
};
292177

293-
static const struct nft_expr_ops nft_ng_random_map_ops = {
294-
.type = &nft_ng_type,
295-
.size = NFT_EXPR_SIZE(sizeof(struct nft_ng_random)),
296-
.eval = nft_ng_random_map_eval,
297-
.init = nft_ng_random_map_init,
298-
.dump = nft_ng_random_map_dump,
299-
};
300-
301178
static const struct nft_expr_ops *
302179
nft_ng_select_ops(const struct nft_ctx *ctx, const struct nlattr * const tb[])
303180
{
@@ -312,12 +189,8 @@ nft_ng_select_ops(const struct nft_ctx *ctx, const struct nlattr * const tb[])
312189

313190
switch (type) {
314191
case NFT_NG_INCREMENTAL:
315-
if (tb[NFTA_NG_SET_NAME])
316-
return &nft_ng_inc_map_ops;
317192
return &nft_ng_inc_ops;
318193
case NFT_NG_RANDOM:
319-
if (tb[NFTA_NG_SET_NAME])
320-
return &nft_ng_random_map_ops;
321194
return &nft_ng_random_ops;
322195
}
323196

0 commit comments

Comments
 (0)