@@ -215,22 +215,14 @@ static void nft_ct_l3proto_module_put(uint8_t family)
215
215
nf_ct_l3proto_module_put (family );
216
216
}
217
217
218
- static int nft_ct_init_validate_get (const struct nft_expr * expr ,
219
- const struct nlattr * const tb [])
218
+ static int nft_ct_get_init (const struct nft_ctx * ctx ,
219
+ const struct nft_expr * expr ,
220
+ const struct nlattr * const tb [])
220
221
{
221
222
struct nft_ct * priv = nft_expr_priv (expr );
223
+ int err ;
222
224
223
- if (tb [NFTA_CT_DIRECTION ] != NULL ) {
224
- priv -> dir = nla_get_u8 (tb [NFTA_CT_DIRECTION ]);
225
- switch (priv -> dir ) {
226
- case IP_CT_DIR_ORIGINAL :
227
- case IP_CT_DIR_REPLY :
228
- break ;
229
- default :
230
- return - EINVAL ;
231
- }
232
- }
233
-
225
+ priv -> key = ntohl (nla_get_be32 (tb [NFTA_CT_KEY ]));
234
226
switch (priv -> key ) {
235
227
case NFT_CT_STATE :
236
228
case NFT_CT_DIRECTION :
@@ -262,12 +254,42 @@ static int nft_ct_init_validate_get(const struct nft_expr *expr,
262
254
return - EOPNOTSUPP ;
263
255
}
264
256
257
+ if (tb [NFTA_CT_DIRECTION ] != NULL ) {
258
+ priv -> dir = nla_get_u8 (tb [NFTA_CT_DIRECTION ]);
259
+ switch (priv -> dir ) {
260
+ case IP_CT_DIR_ORIGINAL :
261
+ case IP_CT_DIR_REPLY :
262
+ break ;
263
+ default :
264
+ return - EINVAL ;
265
+ }
266
+ }
267
+
268
+ priv -> dreg = ntohl (nla_get_be32 (tb [NFTA_CT_DREG ]));
269
+ err = nft_validate_output_register (priv -> dreg );
270
+ if (err < 0 )
271
+ return err ;
272
+
273
+ err = nft_validate_data_load (ctx , priv -> dreg , NULL , NFT_DATA_VALUE );
274
+ if (err < 0 )
275
+ return err ;
276
+
277
+ err = nft_ct_l3proto_try_module_get (ctx -> afi -> family );
278
+ if (err < 0 )
279
+ return err ;
280
+
265
281
return 0 ;
266
282
}
267
283
268
- static int nft_ct_init_validate_set (uint32_t key )
284
+ static int nft_ct_set_init (const struct nft_ctx * ctx ,
285
+ const struct nft_expr * expr ,
286
+ const struct nlattr * const tb [])
269
287
{
270
- switch (key ) {
288
+ struct nft_ct * priv = nft_expr_priv (expr );
289
+ int err ;
290
+
291
+ priv -> key = ntohl (nla_get_be32 (tb [NFTA_CT_KEY ]));
292
+ switch (priv -> key ) {
271
293
#ifdef CONFIG_NF_CONNTRACK_MARK
272
294
case NFT_CT_MARK :
273
295
break ;
@@ -276,42 +298,10 @@ static int nft_ct_init_validate_set(uint32_t key)
276
298
return - EOPNOTSUPP ;
277
299
}
278
300
279
- return 0 ;
280
- }
281
-
282
- static int nft_ct_init (const struct nft_ctx * ctx ,
283
- const struct nft_expr * expr ,
284
- const struct nlattr * const tb [])
285
- {
286
- struct nft_ct * priv = nft_expr_priv (expr );
287
- int err ;
288
-
289
- priv -> key = ntohl (nla_get_be32 (tb [NFTA_CT_KEY ]));
290
-
291
- if (tb [NFTA_CT_DREG ]) {
292
- err = nft_ct_init_validate_get (expr , tb );
293
- if (err < 0 )
294
- return err ;
295
-
296
- priv -> dreg = ntohl (nla_get_be32 (tb [NFTA_CT_DREG ]));
297
- err = nft_validate_output_register (priv -> dreg );
298
- if (err < 0 )
299
- return err ;
300
-
301
- err = nft_validate_data_load (ctx , priv -> dreg , NULL ,
302
- NFT_DATA_VALUE );
303
- if (err < 0 )
304
- return err ;
305
- } else {
306
- err = nft_ct_init_validate_set (priv -> key );
307
- if (err < 0 )
308
- return err ;
309
-
310
- priv -> sreg = ntohl (nla_get_be32 (tb [NFTA_CT_SREG ]));
311
- err = nft_validate_input_register (priv -> sreg );
312
- if (err < 0 )
313
- return err ;
314
- }
301
+ priv -> sreg = ntohl (nla_get_be32 (tb [NFTA_CT_SREG ]));
302
+ err = nft_validate_input_register (priv -> sreg );
303
+ if (err < 0 )
304
+ return err ;
315
305
316
306
err = nft_ct_l3proto_try_module_get (ctx -> afi -> family );
317
307
if (err < 0 )
@@ -372,7 +362,7 @@ static const struct nft_expr_ops nft_ct_get_ops = {
372
362
.type = & nft_ct_type ,
373
363
.size = NFT_EXPR_SIZE (sizeof (struct nft_ct )),
374
364
.eval = nft_ct_get_eval ,
375
- .init = nft_ct_init ,
365
+ .init = nft_ct_get_init ,
376
366
.destroy = nft_ct_destroy ,
377
367
.dump = nft_ct_get_dump ,
378
368
};
@@ -381,7 +371,7 @@ static const struct nft_expr_ops nft_ct_set_ops = {
381
371
.type = & nft_ct_type ,
382
372
.size = NFT_EXPR_SIZE (sizeof (struct nft_ct )),
383
373
.eval = nft_ct_set_eval ,
384
- .init = nft_ct_init ,
374
+ .init = nft_ct_set_init ,
385
375
.destroy = nft_ct_destroy ,
386
376
.dump = nft_ct_set_dump ,
387
377
};
0 commit comments