@@ -169,7 +169,8 @@ static void nft_trans_destroy(struct nft_trans *trans)
169
169
kfree (trans );
170
170
}
171
171
172
- static void nft_set_trans_bind (const struct nft_ctx * ctx , struct nft_set * set )
172
+ static void __nft_set_trans_bind (const struct nft_ctx * ctx , struct nft_set * set ,
173
+ bool bind )
173
174
{
174
175
struct nftables_pernet * nft_net ;
175
176
struct net * net = ctx -> net ;
@@ -183,17 +184,28 @@ static void nft_set_trans_bind(const struct nft_ctx *ctx, struct nft_set *set)
183
184
switch (trans -> msg_type ) {
184
185
case NFT_MSG_NEWSET :
185
186
if (nft_trans_set (trans ) == set )
186
- nft_trans_set_bound (trans ) = true ;
187
+ nft_trans_set_bound (trans ) = bind ;
187
188
break ;
188
189
case NFT_MSG_NEWSETELEM :
189
190
if (nft_trans_elem_set (trans ) == set )
190
- nft_trans_elem_set_bound (trans ) = true ;
191
+ nft_trans_elem_set_bound (trans ) = bind ;
191
192
break ;
192
193
}
193
194
}
194
195
}
195
196
196
- static void nft_chain_trans_bind (const struct nft_ctx * ctx , struct nft_chain * chain )
197
+ static void nft_set_trans_bind (const struct nft_ctx * ctx , struct nft_set * set )
198
+ {
199
+ return __nft_set_trans_bind (ctx , set , true);
200
+ }
201
+
202
+ static void nft_set_trans_unbind (const struct nft_ctx * ctx , struct nft_set * set )
203
+ {
204
+ return __nft_set_trans_bind (ctx , set , false);
205
+ }
206
+
207
+ static void __nft_chain_trans_bind (const struct nft_ctx * ctx ,
208
+ struct nft_chain * chain , bool bind )
197
209
{
198
210
struct nftables_pernet * nft_net ;
199
211
struct net * net = ctx -> net ;
@@ -207,16 +219,22 @@ static void nft_chain_trans_bind(const struct nft_ctx *ctx, struct nft_chain *ch
207
219
switch (trans -> msg_type ) {
208
220
case NFT_MSG_NEWCHAIN :
209
221
if (nft_trans_chain (trans ) == chain )
210
- nft_trans_chain_bound (trans ) = true ;
222
+ nft_trans_chain_bound (trans ) = bind ;
211
223
break ;
212
224
case NFT_MSG_NEWRULE :
213
225
if (trans -> ctx .chain == chain )
214
- nft_trans_rule_bound (trans ) = true ;
226
+ nft_trans_rule_bound (trans ) = bind ;
215
227
break ;
216
228
}
217
229
}
218
230
}
219
231
232
+ static void nft_chain_trans_bind (const struct nft_ctx * ctx ,
233
+ struct nft_chain * chain )
234
+ {
235
+ __nft_chain_trans_bind (ctx , chain , true);
236
+ }
237
+
220
238
int nf_tables_bind_chain (const struct nft_ctx * ctx , struct nft_chain * chain )
221
239
{
222
240
if (!nft_chain_binding (chain ))
@@ -235,6 +253,11 @@ int nf_tables_bind_chain(const struct nft_ctx *ctx, struct nft_chain *chain)
235
253
return 0 ;
236
254
}
237
255
256
+ void nf_tables_unbind_chain (const struct nft_ctx * ctx , struct nft_chain * chain )
257
+ {
258
+ __nft_chain_trans_bind (ctx , chain , false);
259
+ }
260
+
238
261
static int nft_netdev_register_hooks (struct net * net ,
239
262
struct list_head * hook_list )
240
263
{
@@ -3884,7 +3907,7 @@ static int nf_tables_newrule(struct sk_buff *skb, const struct nfnl_info *info,
3884
3907
if (flow )
3885
3908
nft_flow_rule_destroy (flow );
3886
3909
err_release_rule :
3887
- nft_rule_expr_deactivate (& ctx , rule , NFT_TRANS_PREPARE );
3910
+ nft_rule_expr_deactivate (& ctx , rule , NFT_TRANS_PREPARE_ERROR );
3888
3911
nf_tables_rule_destroy (& ctx , rule );
3889
3912
err_release_expr :
3890
3913
for (i = 0 ; i < n ; i ++ ) {
@@ -5183,6 +5206,13 @@ void nf_tables_deactivate_set(const struct nft_ctx *ctx, struct nft_set *set,
5183
5206
enum nft_trans_phase phase )
5184
5207
{
5185
5208
switch (phase ) {
5209
+ case NFT_TRANS_PREPARE_ERROR :
5210
+ nft_set_trans_unbind (ctx , set );
5211
+ if (nft_set_is_anonymous (set ))
5212
+ nft_deactivate_next (ctx -> net , set );
5213
+
5214
+ set -> use -- ;
5215
+ break ;
5186
5216
case NFT_TRANS_PREPARE :
5187
5217
if (nft_set_is_anonymous (set ))
5188
5218
nft_deactivate_next (ctx -> net , set );
@@ -7701,6 +7731,7 @@ void nf_tables_deactivate_flowtable(const struct nft_ctx *ctx,
7701
7731
enum nft_trans_phase phase )
7702
7732
{
7703
7733
switch (phase ) {
7734
+ case NFT_TRANS_PREPARE_ERROR :
7704
7735
case NFT_TRANS_PREPARE :
7705
7736
case NFT_TRANS_ABORT :
7706
7737
case NFT_TRANS_RELEASE :
0 commit comments