@@ -98,13 +98,18 @@ static int nft_limit_dump(struct sk_buff *skb, const struct nft_limit *limit)
98
98
return -1 ;
99
99
}
100
100
101
+ struct nft_limit_pkts {
102
+ struct nft_limit limit ;
103
+ u64 cost ;
104
+ };
105
+
101
106
static void nft_limit_pkts_eval (const struct nft_expr * expr ,
102
107
struct nft_regs * regs ,
103
108
const struct nft_pktinfo * pkt )
104
109
{
105
- struct nft_limit * priv = nft_expr_priv (expr );
110
+ struct nft_limit_pkts * priv = nft_expr_priv (expr );
106
111
107
- if (nft_limit_eval (priv , div_u64 ( priv -> nsecs , priv -> rate ) ))
112
+ if (nft_limit_eval (& priv -> limit , priv -> cost ))
108
113
regs -> verdict .code = NFT_BREAK ;
109
114
}
110
115
@@ -118,22 +123,28 @@ static int nft_limit_pkts_init(const struct nft_ctx *ctx,
118
123
const struct nft_expr * expr ,
119
124
const struct nlattr * const tb [])
120
125
{
121
- struct nft_limit * priv = nft_expr_priv (expr );
126
+ struct nft_limit_pkts * priv = nft_expr_priv (expr );
127
+ int err ;
122
128
123
- return nft_limit_init (priv , tb );
129
+ err = nft_limit_init (& priv -> limit , tb );
130
+ if (err < 0 )
131
+ return err ;
132
+
133
+ priv -> cost = div_u64 (priv -> limit .nsecs , priv -> limit .rate );
134
+ return 0 ;
124
135
}
125
136
126
137
static int nft_limit_pkts_dump (struct sk_buff * skb , const struct nft_expr * expr )
127
138
{
128
- const struct nft_limit * priv = nft_expr_priv (expr );
139
+ const struct nft_limit_pkts * priv = nft_expr_priv (expr );
129
140
130
- return nft_limit_dump (skb , priv );
141
+ return nft_limit_dump (skb , & priv -> limit );
131
142
}
132
143
133
144
static struct nft_expr_type nft_limit_type ;
134
145
static const struct nft_expr_ops nft_limit_pkts_ops = {
135
146
.type = & nft_limit_type ,
136
- .size = NFT_EXPR_SIZE (sizeof (struct nft_limit )),
147
+ .size = NFT_EXPR_SIZE (sizeof (struct nft_limit_pkts )),
137
148
.eval = nft_limit_pkts_eval ,
138
149
.init = nft_limit_pkts_init ,
139
150
.dump = nft_limit_pkts_dump ,
0 commit comments