]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
ecfab2c9 YK |
2 | #ifndef _NF_CONNTRACK_EXTEND_H |
3 | #define _NF_CONNTRACK_EXTEND_H | |
4 | ||
5a0e3ad6 TH |
5 | #include <linux/slab.h> |
6 | ||
ecfab2c9 YK |
7 | #include <net/netfilter/nf_conntrack.h> |
8 | ||
fd2c3ef7 | 9 | enum nf_ct_ext_id { |
ceceae1b | 10 | NF_CT_EXT_HELPER, |
e0e76c83 | 11 | #if defined(CONFIG_NF_NAT) || defined(CONFIG_NF_NAT_MODULE) |
2d59e5ca | 12 | NF_CT_EXT_NAT, |
e0e76c83 | 13 | #endif |
48b1de4c | 14 | NF_CT_EXT_SEQADJ, |
58401572 | 15 | NF_CT_EXT_ACCT, |
e0e76c83 | 16 | #ifdef CONFIG_NF_CONNTRACK_EVENTS |
a0891aa6 | 17 | NF_CT_EXT_ECACHE, |
e0e76c83 | 18 | #endif |
a992ca2a PNA |
19 | #ifdef CONFIG_NF_CONNTRACK_TIMESTAMP |
20 | NF_CT_EXT_TSTAMP, | |
dd705072 PNA |
21 | #endif |
22 | #ifdef CONFIG_NF_CONNTRACK_TIMEOUT | |
23 | NF_CT_EXT_TIMEOUT, | |
c539f017 FW |
24 | #endif |
25 | #ifdef CONFIG_NF_CONNTRACK_LABELS | |
26 | NF_CT_EXT_LABELS, | |
48b1de4c PM |
27 | #endif |
28 | #if IS_ENABLED(CONFIG_NETFILTER_SYNPROXY) | |
29 | NF_CT_EXT_SYNPROXY, | |
e0e76c83 | 30 | #endif |
ecfab2c9 YK |
31 | NF_CT_EXT_NUM, |
32 | }; | |
33 | ||
ceceae1b | 34 | #define NF_CT_EXT_HELPER_TYPE struct nf_conn_help |
2d59e5ca | 35 | #define NF_CT_EXT_NAT_TYPE struct nf_conn_nat |
41d73ec0 | 36 | #define NF_CT_EXT_SEQADJ_TYPE struct nf_conn_seqadj |
f7b13e43 | 37 | #define NF_CT_EXT_ACCT_TYPE struct nf_conn_acct |
a0891aa6 | 38 | #define NF_CT_EXT_ECACHE_TYPE struct nf_conntrack_ecache |
a992ca2a | 39 | #define NF_CT_EXT_TSTAMP_TYPE struct nf_conn_tstamp |
dd705072 | 40 | #define NF_CT_EXT_TIMEOUT_TYPE struct nf_conn_timeout |
c539f017 | 41 | #define NF_CT_EXT_LABELS_TYPE struct nf_conn_labels |
48b1de4c | 42 | #define NF_CT_EXT_SYNPROXY_TYPE struct nf_conn_synproxy |
ceceae1b | 43 | |
ecfab2c9 YK |
44 | /* Extensions: optional stuff which isn't permanently in struct. */ |
45 | struct nf_ct_ext { | |
68b80f11 | 46 | struct rcu_head rcu; |
b3a5db10 FW |
47 | u8 offset[NF_CT_EXT_NUM]; |
48 | u8 len; | |
ecfab2c9 YK |
49 | char data[0]; |
50 | }; | |
51 | ||
ee92d378 | 52 | static inline bool __nf_ct_ext_exist(const struct nf_ct_ext *ext, u8 id) |
ecfab2c9 | 53 | { |
ee92d378 CG |
54 | return !!ext->offset[id]; |
55 | } | |
56 | ||
57 | static inline bool nf_ct_ext_exist(const struct nf_conn *ct, u8 id) | |
58 | { | |
59 | return (ct->ext && __nf_ct_ext_exist(ct->ext, id)); | |
ecfab2c9 YK |
60 | } |
61 | ||
62 | static inline void *__nf_ct_ext_find(const struct nf_conn *ct, u8 id) | |
63 | { | |
64 | if (!nf_ct_ext_exist(ct, id)) | |
65 | return NULL; | |
66 | ||
67 | return (void *)ct->ext + ct->ext->offset[id]; | |
68 | } | |
69 | #define nf_ct_ext_find(ext, id) \ | |
70 | ((id##_TYPE *)__nf_ct_ext_find((ext), (id))) | |
71 | ||
72 | /* Destroy all relationships */ | |
8eeef235 | 73 | void nf_ct_ext_destroy(struct nf_conn *ct); |
ecfab2c9 YK |
74 | |
75 | /* Free operation. If you want to free a object referred from private area, | |
76 | * please implement __nf_ct_ext_free() and call it. | |
77 | */ | |
78 | static inline void nf_ct_ext_free(struct nf_conn *ct) | |
79 | { | |
80 | if (ct->ext) | |
c13a84a8 | 81 | kfree_rcu(ct->ext, rcu); |
ecfab2c9 YK |
82 | } |
83 | ||
84 | /* Add this type, returns pointer to data or NULL. */ | |
faec865d | 85 | void *nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp); |
ecfab2c9 | 86 | |
fd2c3ef7 | 87 | struct nf_ct_ext_type { |
ecfab2c9 YK |
88 | /* Destroys relationships (can be NULL). */ |
89 | void (*destroy)(struct nf_conn *ct); | |
ecfab2c9 YK |
90 | |
91 | enum nf_ct_ext_id id; | |
92 | ||
ecfab2c9 YK |
93 | /* Length and min alignment. */ |
94 | u8 len; | |
95 | u8 align; | |
ecfab2c9 YK |
96 | }; |
97 | ||
23f671a1 FW |
98 | int nf_ct_extend_register(const struct nf_ct_ext_type *type); |
99 | void nf_ct_extend_unregister(const struct nf_ct_ext_type *type); | |
ecfab2c9 | 100 | #endif /* _NF_CONNTRACK_EXTEND_H */ |