Skip to content

Commit 0d9932b

Browse files
Laura Garcia Liebanaummakynes
authored andcommitted
netfilter: nft_numgen: rename until attribute by modulus
The _until_ attribute is renamed to _modulus_ as the behaviour is similar to other expresions with number limits (ex. nft_hash). Renaming is possible because there isn't a kernel release yet with these changes. Signed-off-by: Laura Garcia Liebana <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent ddb075b commit 0d9932b

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

include/uapi/linux/netfilter/nf_tables.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,13 +1126,13 @@ enum nft_trace_types {
11261126
* enum nft_ng_attributes - nf_tables number generator expression netlink attributes
11271127
*
11281128
* @NFTA_NG_DREG: destination register (NLA_U32)
1129-
* @NFTA_NG_UNTIL: source value to increment the counter until reset (NLA_U32)
1129+
* @NFTA_NG_MODULUS: maximum counter value (NLA_U32)
11301130
* @NFTA_NG_TYPE: operation type (NLA_U32)
11311131
*/
11321132
enum nft_ng_attributes {
11331133
NFTA_NG_UNSPEC,
11341134
NFTA_NG_DREG,
1135-
NFTA_NG_UNTIL,
1135+
NFTA_NG_MODULUS,
11361136
NFTA_NG_TYPE,
11371137
__NFTA_NG_MAX
11381138
};

net/netfilter/nft_numgen.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static DEFINE_PER_CPU(struct rnd_state, nft_numgen_prandom_state);
2121

2222
struct nft_ng_inc {
2323
enum nft_registers dreg:8;
24-
u32 until;
24+
u32 modulus;
2525
atomic_t counter;
2626
};
2727

@@ -34,15 +34,15 @@ static void nft_ng_inc_eval(const struct nft_expr *expr,
3434

3535
do {
3636
oval = atomic_read(&priv->counter);
37-
nval = (oval + 1 < priv->until) ? oval + 1 : 0;
37+
nval = (oval + 1 < priv->modulus) ? oval + 1 : 0;
3838
} while (atomic_cmpxchg(&priv->counter, oval, nval) != oval);
3939

4040
memcpy(&regs->data[priv->dreg], &priv->counter, sizeof(u32));
4141
}
4242

4343
static const struct nla_policy nft_ng_policy[NFTA_NG_MAX + 1] = {
4444
[NFTA_NG_DREG] = { .type = NLA_U32 },
45-
[NFTA_NG_UNTIL] = { .type = NLA_U32 },
45+
[NFTA_NG_MODULUS] = { .type = NLA_U32 },
4646
[NFTA_NG_TYPE] = { .type = NLA_U32 },
4747
};
4848

@@ -52,8 +52,8 @@ static int nft_ng_inc_init(const struct nft_ctx *ctx,
5252
{
5353
struct nft_ng_inc *priv = nft_expr_priv(expr);
5454

55-
priv->until = ntohl(nla_get_be32(tb[NFTA_NG_UNTIL]));
56-
if (priv->until == 0)
55+
priv->modulus = ntohl(nla_get_be32(tb[NFTA_NG_MODULUS]));
56+
if (priv->modulus == 0)
5757
return -ERANGE;
5858

5959
priv->dreg = nft_parse_register(tb[NFTA_NG_DREG]);
@@ -64,11 +64,11 @@ static int nft_ng_inc_init(const struct nft_ctx *ctx,
6464
}
6565

6666
static int nft_ng_dump(struct sk_buff *skb, enum nft_registers dreg,
67-
u32 until, enum nft_ng_types type)
67+
u32 modulus, enum nft_ng_types type)
6868
{
6969
if (nft_dump_register(skb, NFTA_NG_DREG, dreg))
7070
goto nla_put_failure;
71-
if (nla_put_be32(skb, NFTA_NG_UNTIL, htonl(until)))
71+
if (nla_put_be32(skb, NFTA_NG_MODULUS, htonl(modulus)))
7272
goto nla_put_failure;
7373
if (nla_put_be32(skb, NFTA_NG_TYPE, htonl(type)))
7474
goto nla_put_failure;
@@ -83,12 +83,12 @@ static int nft_ng_inc_dump(struct sk_buff *skb, const struct nft_expr *expr)
8383
{
8484
const struct nft_ng_inc *priv = nft_expr_priv(expr);
8585

86-
return nft_ng_dump(skb, priv->dreg, priv->until, NFT_NG_INCREMENTAL);
86+
return nft_ng_dump(skb, priv->dreg, priv->modulus, NFT_NG_INCREMENTAL);
8787
}
8888

8989
struct nft_ng_random {
9090
enum nft_registers dreg:8;
91-
u32 until;
91+
u32 modulus;
9292
};
9393

9494
static void nft_ng_random_eval(const struct nft_expr *expr,
@@ -99,7 +99,7 @@ static void nft_ng_random_eval(const struct nft_expr *expr,
9999
struct rnd_state *state = this_cpu_ptr(&nft_numgen_prandom_state);
100100

101101
regs->data[priv->dreg] = reciprocal_scale(prandom_u32_state(state),
102-
priv->until);
102+
priv->modulus);
103103
}
104104

105105
static int nft_ng_random_init(const struct nft_ctx *ctx,
@@ -108,8 +108,8 @@ static int nft_ng_random_init(const struct nft_ctx *ctx,
108108
{
109109
struct nft_ng_random *priv = nft_expr_priv(expr);
110110

111-
priv->until = ntohl(nla_get_be32(tb[NFTA_NG_UNTIL]));
112-
if (priv->until == 0)
111+
priv->modulus = ntohl(nla_get_be32(tb[NFTA_NG_MODULUS]));
112+
if (priv->modulus == 0)
113113
return -ERANGE;
114114

115115
prandom_init_once(&nft_numgen_prandom_state);
@@ -124,7 +124,7 @@ static int nft_ng_random_dump(struct sk_buff *skb, const struct nft_expr *expr)
124124
{
125125
const struct nft_ng_random *priv = nft_expr_priv(expr);
126126

127-
return nft_ng_dump(skb, priv->dreg, priv->until, NFT_NG_RANDOM);
127+
return nft_ng_dump(skb, priv->dreg, priv->modulus, NFT_NG_RANDOM);
128128
}
129129

130130
static struct nft_expr_type nft_ng_type;
@@ -149,8 +149,8 @@ nft_ng_select_ops(const struct nft_ctx *ctx, const struct nlattr * const tb[])
149149
{
150150
u32 type;
151151

152-
if (!tb[NFTA_NG_DREG] ||
153-
!tb[NFTA_NG_UNTIL] ||
152+
if (!tb[NFTA_NG_DREG] ||
153+
!tb[NFTA_NG_MODULUS] ||
154154
!tb[NFTA_NG_TYPE])
155155
return ERR_PTR(-EINVAL);
156156

0 commit comments

Comments
 (0)