@@ -875,6 +875,7 @@ unsigned int nft_do_chain(struct nft_pktinfo *pkt, void *priv);
875875 * @list: used internally
876876 * @chains: chains in the table
877877 * @sets: sets in the table
878+ * @objects: stateful objects in the table
878879 * @hgenerator: handle generator state
879880 * @use: number of chain references to this table
880881 * @flags: table flag (see enum nft_table_flags)
@@ -885,6 +886,7 @@ struct nft_table {
885886 struct list_head list ;
886887 struct list_head chains ;
887888 struct list_head sets ;
889+ struct list_head objects ;
888890 u64 hgenerator ;
889891 u32 use ;
890892 u16 flags :14 ,
@@ -934,6 +936,73 @@ void nft_unregister_expr(struct nft_expr_type *);
934936int nft_verdict_dump (struct sk_buff * skb , int type ,
935937 const struct nft_verdict * v );
936938
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+
9371006/**
9381007 * struct nft_traceinfo - nft tracing information and state
9391008 *
@@ -981,6 +1050,9 @@ void nft_trace_notify(struct nft_traceinfo *info);
9811050#define MODULE_ALIAS_NFT_SET () \
9821051 MODULE_ALIAS("nft-set")
9831052
1053+ #define MODULE_ALIAS_NFT_OBJ (type ) \
1054+ MODULE_ALIAS("nft-obj-" __stringify(type))
1055+
9841056/*
9851057 * The gencursor defines two generations, the currently active and the
9861058 * next one. Objects contain a bitmask of 2 bits specifying the generations
@@ -1157,4 +1229,11 @@ struct nft_trans_elem {
11571229#define nft_trans_elem (trans ) \
11581230 (((struct nft_trans_elem *)trans->data)->elem)
11591231
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+
11601239#endif /* _NET_NF_TABLES_H */
0 commit comments