@@ -840,64 +840,64 @@ static void nft_ctx_init(struct nft_ctx *ctx,
840
840
*/
841
841
842
842
/**
843
- * nft_register_expr - register nf_tables expr operations
844
- * @ops: expr operations
843
+ * nft_register_expr - register nf_tables expr type
844
+ * @ops: expr type
845
845
*
846
- * Registers the expr operations for use with nf_tables. Returns zero on
846
+ * Registers the expr type for use with nf_tables. Returns zero on
847
847
* success or a negative errno code otherwise.
848
848
*/
849
- int nft_register_expr (struct nft_expr_ops * ops )
849
+ int nft_register_expr (struct nft_expr_type * type )
850
850
{
851
851
nfnl_lock (NFNL_SUBSYS_NFTABLES );
852
- list_add_tail (& ops -> list , & nf_tables_expressions );
852
+ list_add_tail (& type -> list , & nf_tables_expressions );
853
853
nfnl_unlock (NFNL_SUBSYS_NFTABLES );
854
854
return 0 ;
855
855
}
856
856
EXPORT_SYMBOL_GPL (nft_register_expr );
857
857
858
858
/**
859
- * nft_unregister_expr - unregister nf_tables expr operations
860
- * @ops: expr operations
859
+ * nft_unregister_expr - unregister nf_tables expr type
860
+ * @ops: expr type
861
861
*
862
- * Unregisters the expr operations for use with nf_tables.
862
+ * Unregisters the expr typefor use with nf_tables.
863
863
*/
864
- void nft_unregister_expr (struct nft_expr_ops * ops )
864
+ void nft_unregister_expr (struct nft_expr_type * type )
865
865
{
866
866
nfnl_lock (NFNL_SUBSYS_NFTABLES );
867
- list_del (& ops -> list );
867
+ list_del (& type -> list );
868
868
nfnl_unlock (NFNL_SUBSYS_NFTABLES );
869
869
}
870
870
EXPORT_SYMBOL_GPL (nft_unregister_expr );
871
871
872
- static const struct nft_expr_ops * __nft_expr_ops_get (struct nlattr * nla )
872
+ static const struct nft_expr_type * __nft_expr_type_get (struct nlattr * nla )
873
873
{
874
- const struct nft_expr_ops * ops ;
874
+ const struct nft_expr_type * type ;
875
875
876
- list_for_each_entry (ops , & nf_tables_expressions , list ) {
877
- if (!nla_strcmp (nla , ops -> name ))
878
- return ops ;
876
+ list_for_each_entry (type , & nf_tables_expressions , list ) {
877
+ if (!nla_strcmp (nla , type -> name ))
878
+ return type ;
879
879
}
880
880
return NULL ;
881
881
}
882
882
883
- static const struct nft_expr_ops * nft_expr_ops_get (struct nlattr * nla )
883
+ static const struct nft_expr_type * nft_expr_type_get (struct nlattr * nla )
884
884
{
885
- const struct nft_expr_ops * ops ;
885
+ const struct nft_expr_type * type ;
886
886
887
887
if (nla == NULL )
888
888
return ERR_PTR (- EINVAL );
889
889
890
- ops = __nft_expr_ops_get (nla );
891
- if (ops != NULL && try_module_get (ops -> owner ))
892
- return ops ;
890
+ type = __nft_expr_type_get (nla );
891
+ if (type != NULL && try_module_get (type -> owner ))
892
+ return type ;
893
893
894
894
#ifdef CONFIG_MODULES
895
- if (ops == NULL ) {
895
+ if (type == NULL ) {
896
896
nfnl_unlock (NFNL_SUBSYS_NFTABLES );
897
897
request_module ("nft-expr-%.*s" ,
898
898
nla_len (nla ), (char * )nla_data (nla ));
899
899
nfnl_lock (NFNL_SUBSYS_NFTABLES );
900
- if (__nft_expr_ops_get (nla ))
900
+ if (__nft_expr_type_get (nla ))
901
901
return ERR_PTR (- EAGAIN );
902
902
}
903
903
#endif
@@ -912,7 +912,7 @@ static const struct nla_policy nft_expr_policy[NFTA_EXPR_MAX + 1] = {
912
912
static int nf_tables_fill_expr_info (struct sk_buff * skb ,
913
913
const struct nft_expr * expr )
914
914
{
915
- if (nla_put_string (skb , NFTA_EXPR_NAME , expr -> ops -> name ))
915
+ if (nla_put_string (skb , NFTA_EXPR_NAME , expr -> ops -> type -> name ))
916
916
goto nla_put_failure ;
917
917
918
918
if (expr -> ops -> dump ) {
@@ -932,52 +932,64 @@ static int nf_tables_fill_expr_info(struct sk_buff *skb,
932
932
933
933
struct nft_expr_info {
934
934
const struct nft_expr_ops * ops ;
935
- struct nlattr * tb [NFTA_EXPR_MAX + 1 ];
935
+ struct nlattr * tb [NFT_EXPR_MAXATTR + 1 ];
936
936
};
937
937
938
938
static int nf_tables_expr_parse (const struct nlattr * nla ,
939
939
struct nft_expr_info * info )
940
940
{
941
+ const struct nft_expr_type * type ;
941
942
const struct nft_expr_ops * ops ;
943
+ struct nlattr * tb [NFTA_EXPR_MAX + 1 ];
942
944
int err ;
943
945
944
- err = nla_parse_nested (info -> tb , NFTA_EXPR_MAX , nla , nft_expr_policy );
946
+ err = nla_parse_nested (tb , NFTA_EXPR_MAX , nla , nft_expr_policy );
945
947
if (err < 0 )
946
948
return err ;
947
949
948
- ops = nft_expr_ops_get (info -> tb [NFTA_EXPR_NAME ]);
949
- if (IS_ERR (ops ))
950
- return PTR_ERR (ops );
950
+ type = nft_expr_type_get (tb [NFTA_EXPR_NAME ]);
951
+ if (IS_ERR (type ))
952
+ return PTR_ERR (type );
953
+
954
+ if (tb [NFTA_EXPR_DATA ]) {
955
+ err = nla_parse_nested (info -> tb , type -> maxattr ,
956
+ tb [NFTA_EXPR_DATA ], type -> policy );
957
+ if (err < 0 )
958
+ goto err1 ;
959
+ } else
960
+ memset (info -> tb , 0 , sizeof (info -> tb [0 ]) * (type -> maxattr + 1 ));
961
+
962
+ if (type -> select_ops != NULL ) {
963
+ ops = type -> select_ops ((const struct nlattr * const * )info -> tb );
964
+ if (IS_ERR (ops )) {
965
+ err = PTR_ERR (ops );
966
+ goto err1 ;
967
+ }
968
+ } else
969
+ ops = type -> ops ;
970
+
951
971
info -> ops = ops ;
952
972
return 0 ;
973
+
974
+ err1 :
975
+ module_put (type -> owner );
976
+ return err ;
953
977
}
954
978
955
979
static int nf_tables_newexpr (const struct nft_ctx * ctx ,
956
- struct nft_expr_info * info ,
980
+ const struct nft_expr_info * info ,
957
981
struct nft_expr * expr )
958
982
{
959
983
const struct nft_expr_ops * ops = info -> ops ;
960
984
int err ;
961
985
962
986
expr -> ops = ops ;
963
987
if (ops -> init ) {
964
- struct nlattr * ma [ops -> maxattr + 1 ];
965
-
966
- if (info -> tb [NFTA_EXPR_DATA ]) {
967
- err = nla_parse_nested (ma , ops -> maxattr ,
968
- info -> tb [NFTA_EXPR_DATA ],
969
- ops -> policy );
970
- if (err < 0 )
971
- goto err1 ;
972
- } else
973
- memset (ma , 0 , sizeof (ma [0 ]) * (ops -> maxattr + 1 ));
974
-
975
- err = ops -> init (ctx , expr , (const struct nlattr * * )ma );
988
+ err = ops -> init (ctx , expr , (const struct nlattr * * )info -> tb );
976
989
if (err < 0 )
977
990
goto err1 ;
978
991
}
979
992
980
- info -> ops = NULL ;
981
993
return 0 ;
982
994
983
995
err1 :
@@ -989,7 +1001,7 @@ static void nf_tables_expr_destroy(struct nft_expr *expr)
989
1001
{
990
1002
if (expr -> ops -> destroy )
991
1003
expr -> ops -> destroy (expr );
992
- module_put (expr -> ops -> owner );
1004
+ module_put (expr -> ops -> type -> owner );
993
1005
}
994
1006
995
1007
/*
@@ -1313,6 +1325,7 @@ static int nf_tables_newrule(struct sock *nlsk, struct sk_buff *skb,
1313
1325
err = nf_tables_newexpr (& ctx , & info [i ], expr );
1314
1326
if (err < 0 )
1315
1327
goto err2 ;
1328
+ info [i ].ops = NULL ;
1316
1329
expr = nft_expr_next (expr );
1317
1330
}
1318
1331
@@ -1341,7 +1354,7 @@ static int nf_tables_newrule(struct sock *nlsk, struct sk_buff *skb,
1341
1354
err1 :
1342
1355
for (i = 0 ; i < n ; i ++ ) {
1343
1356
if (info [i ].ops != NULL )
1344
- module_put (info [i ].ops -> owner );
1357
+ module_put (info [i ].ops -> type -> owner );
1345
1358
}
1346
1359
return err ;
1347
1360
}
0 commit comments