@@ -840,64 +840,64 @@ static void nft_ctx_init(struct nft_ctx *ctx,
840840 */
841841
842842/**
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
845845 *
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
847847 * success or a negative errno code otherwise.
848848 */
849- int nft_register_expr (struct nft_expr_ops * ops )
849+ int nft_register_expr (struct nft_expr_type * type )
850850{
851851 nfnl_lock (NFNL_SUBSYS_NFTABLES );
852- list_add_tail (& ops -> list , & nf_tables_expressions );
852+ list_add_tail (& type -> list , & nf_tables_expressions );
853853 nfnl_unlock (NFNL_SUBSYS_NFTABLES );
854854 return 0 ;
855855}
856856EXPORT_SYMBOL_GPL (nft_register_expr );
857857
858858/**
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
861861 *
862- * Unregisters the expr operations for use with nf_tables.
862+ * Unregisters the expr typefor use with nf_tables.
863863 */
864- void nft_unregister_expr (struct nft_expr_ops * ops )
864+ void nft_unregister_expr (struct nft_expr_type * type )
865865{
866866 nfnl_lock (NFNL_SUBSYS_NFTABLES );
867- list_del (& ops -> list );
867+ list_del (& type -> list );
868868 nfnl_unlock (NFNL_SUBSYS_NFTABLES );
869869}
870870EXPORT_SYMBOL_GPL (nft_unregister_expr );
871871
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 )
873873{
874- const struct nft_expr_ops * ops ;
874+ const struct nft_expr_type * type ;
875875
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 ;
879879 }
880880 return NULL ;
881881}
882882
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 )
884884{
885- const struct nft_expr_ops * ops ;
885+ const struct nft_expr_type * type ;
886886
887887 if (nla == NULL )
888888 return ERR_PTR (- EINVAL );
889889
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 ;
893893
894894#ifdef CONFIG_MODULES
895- if (ops == NULL ) {
895+ if (type == NULL ) {
896896 nfnl_unlock (NFNL_SUBSYS_NFTABLES );
897897 request_module ("nft-expr-%.*s" ,
898898 nla_len (nla ), (char * )nla_data (nla ));
899899 nfnl_lock (NFNL_SUBSYS_NFTABLES );
900- if (__nft_expr_ops_get (nla ))
900+ if (__nft_expr_type_get (nla ))
901901 return ERR_PTR (- EAGAIN );
902902 }
903903#endif
@@ -912,7 +912,7 @@ static const struct nla_policy nft_expr_policy[NFTA_EXPR_MAX + 1] = {
912912static int nf_tables_fill_expr_info (struct sk_buff * skb ,
913913 const struct nft_expr * expr )
914914{
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 ))
916916 goto nla_put_failure ;
917917
918918 if (expr -> ops -> dump ) {
@@ -932,52 +932,64 @@ static int nf_tables_fill_expr_info(struct sk_buff *skb,
932932
933933struct nft_expr_info {
934934 const struct nft_expr_ops * ops ;
935- struct nlattr * tb [NFTA_EXPR_MAX + 1 ];
935+ struct nlattr * tb [NFT_EXPR_MAXATTR + 1 ];
936936};
937937
938938static int nf_tables_expr_parse (const struct nlattr * nla ,
939939 struct nft_expr_info * info )
940940{
941+ const struct nft_expr_type * type ;
941942 const struct nft_expr_ops * ops ;
943+ struct nlattr * tb [NFTA_EXPR_MAX + 1 ];
942944 int err ;
943945
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 );
945947 if (err < 0 )
946948 return err ;
947949
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+
951971 info -> ops = ops ;
952972 return 0 ;
973+
974+ err1 :
975+ module_put (type -> owner );
976+ return err ;
953977}
954978
955979static int nf_tables_newexpr (const struct nft_ctx * ctx ,
956- struct nft_expr_info * info ,
980+ const struct nft_expr_info * info ,
957981 struct nft_expr * expr )
958982{
959983 const struct nft_expr_ops * ops = info -> ops ;
960984 int err ;
961985
962986 expr -> ops = ops ;
963987 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 );
976989 if (err < 0 )
977990 goto err1 ;
978991 }
979992
980- info -> ops = NULL ;
981993 return 0 ;
982994
983995err1 :
@@ -989,7 +1001,7 @@ static void nf_tables_expr_destroy(struct nft_expr *expr)
9891001{
9901002 if (expr -> ops -> destroy )
9911003 expr -> ops -> destroy (expr );
992- module_put (expr -> ops -> owner );
1004+ module_put (expr -> ops -> type -> owner );
9931005}
9941006
9951007/*
@@ -1313,6 +1325,7 @@ static int nf_tables_newrule(struct sock *nlsk, struct sk_buff *skb,
13131325 err = nf_tables_newexpr (& ctx , & info [i ], expr );
13141326 if (err < 0 )
13151327 goto err2 ;
1328+ info [i ].ops = NULL ;
13161329 expr = nft_expr_next (expr );
13171330 }
13181331
@@ -1341,7 +1354,7 @@ static int nf_tables_newrule(struct sock *nlsk, struct sk_buff *skb,
13411354err1 :
13421355 for (i = 0 ; i < n ; i ++ ) {
13431356 if (info [i ].ops != NULL )
1344- module_put (info [i ].ops -> owner );
1357+ module_put (info [i ].ops -> type -> owner );
13451358 }
13461359 return err ;
13471360}
0 commit comments