@@ -875,6 +875,7 @@ unsigned int nft_do_chain(struct nft_pktinfo *pkt, void *priv);
875
875
* @list: used internally
876
876
* @chains: chains in the table
877
877
* @sets: sets in the table
878
+ * @objects: stateful objects in the table
878
879
* @hgenerator: handle generator state
879
880
* @use: number of chain references to this table
880
881
* @flags: table flag (see enum nft_table_flags)
@@ -885,6 +886,7 @@ struct nft_table {
885
886
struct list_head list ;
886
887
struct list_head chains ;
887
888
struct list_head sets ;
889
+ struct list_head objects ;
888
890
u64 hgenerator ;
889
891
u32 use ;
890
892
u16 flags :14 ,
@@ -934,6 +936,73 @@ void nft_unregister_expr(struct nft_expr_type *);
934
936
int nft_verdict_dump (struct sk_buff * skb , int type ,
935
937
const struct nft_verdict * v );
936
938
939
+ /**
940
+ * struct nft_object - nf_tables stateful object
941
+ *
942
+ * @list: table stateful object list node
943
+ * @type: pointer to object type
944
+ * @data: pointer to object data
945
+ * @name: name of this stateful object
946
+ * @genmask: generation mask
947
+ * @use: number of references to this stateful object
948
+ * @data: object data, layout depends on type
949
+ */
950
+ struct nft_object {
951
+ struct list_head list ;
952
+ char name [NFT_OBJ_MAXNAMELEN ];
953
+ u32 genmask :2 ,
954
+ use :30 ;
955
+ /* runtime data below here */
956
+ const struct nft_object_type * type ____cacheline_aligned ;
957
+ unsigned char data []
958
+ __attribute__((aligned (__alignof__(u64 ))));
959
+ };
960
+
961
+ static inline void * nft_obj_data (const struct nft_object * obj )
962
+ {
963
+ return (void * )obj -> data ;
964
+ }
965
+
966
+ #define nft_expr_obj (expr ) *((struct nft_object **)nft_expr_priv(expr))
967
+
968
+ struct nft_object * nf_tables_obj_lookup (const struct nft_table * table ,
969
+ const struct nlattr * nla , u32 objtype ,
970
+ u8 genmask );
971
+
972
+ /**
973
+ * struct nft_object_type - stateful object type
974
+ *
975
+ * @eval: stateful object evaluation function
976
+ * @list: list node in list of object types
977
+ * @type: stateful object numeric type
978
+ * @size: stateful object size
979
+ * @owner: module owner
980
+ * @maxattr: maximum netlink attribute
981
+ * @policy: netlink attribute policy
982
+ * @init: initialize object from netlink attributes
983
+ * @destroy: release existing stateful object
984
+ * @dump: netlink dump stateful object
985
+ */
986
+ struct nft_object_type {
987
+ void (* eval )(struct nft_object * obj ,
988
+ struct nft_regs * regs ,
989
+ const struct nft_pktinfo * pkt );
990
+ struct list_head list ;
991
+ u32 type ;
992
+ unsigned int size ;
993
+ unsigned int maxattr ;
994
+ struct module * owner ;
995
+ const struct nla_policy * policy ;
996
+ int (* init )(const struct nlattr * const tb [],
997
+ struct nft_object * obj );
998
+ void (* destroy )(struct nft_object * obj );
999
+ int (* dump )(struct sk_buff * skb ,
1000
+ const struct nft_object * obj );
1001
+ };
1002
+
1003
+ int nft_register_obj (struct nft_object_type * obj_type );
1004
+ void nft_unregister_obj (struct nft_object_type * obj_type );
1005
+
937
1006
/**
938
1007
* struct nft_traceinfo - nft tracing information and state
939
1008
*
@@ -981,6 +1050,9 @@ void nft_trace_notify(struct nft_traceinfo *info);
981
1050
#define MODULE_ALIAS_NFT_SET () \
982
1051
MODULE_ALIAS("nft-set")
983
1052
1053
+ #define MODULE_ALIAS_NFT_OBJ (type ) \
1054
+ MODULE_ALIAS("nft-obj-" __stringify(type))
1055
+
984
1056
/*
985
1057
* The gencursor defines two generations, the currently active and the
986
1058
* next one. Objects contain a bitmask of 2 bits specifying the generations
@@ -1157,4 +1229,11 @@ struct nft_trans_elem {
1157
1229
#define nft_trans_elem (trans ) \
1158
1230
(((struct nft_trans_elem *)trans->data)->elem)
1159
1231
1232
+ struct nft_trans_obj {
1233
+ struct nft_object * obj ;
1234
+ };
1235
+
1236
+ #define nft_trans_obj (trans ) \
1237
+ (((struct nft_trans_obj *)trans->data)->obj)
1238
+
1160
1239
#endif /* _NET_NF_TABLES_H */
0 commit comments