]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - include/net/netfilter/nf_conntrack_extend.h
5fc908dc9f3281a2f5ea755a5448747cce70a7c9
[mirror_ubuntu-artful-kernel.git] / include / net / netfilter / nf_conntrack_extend.h
1 #ifndef _NF_CONNTRACK_EXTEND_H
2 #define _NF_CONNTRACK_EXTEND_H
3
4 #include <linux/slab.h>
5
6 #include <net/netfilter/nf_conntrack.h>
7
8 enum nf_ct_ext_id {
9 NF_CT_EXT_HELPER,
10 #if defined(CONFIG_NF_NAT) || defined(CONFIG_NF_NAT_MODULE)
11 NF_CT_EXT_NAT,
12 #endif
13 NF_CT_EXT_SEQADJ,
14 NF_CT_EXT_ACCT,
15 #ifdef CONFIG_NF_CONNTRACK_EVENTS
16 NF_CT_EXT_ECACHE,
17 #endif
18 #ifdef CONFIG_NF_CONNTRACK_TIMESTAMP
19 NF_CT_EXT_TSTAMP,
20 #endif
21 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
22 NF_CT_EXT_TIMEOUT,
23 #endif
24 #ifdef CONFIG_NF_CONNTRACK_LABELS
25 NF_CT_EXT_LABELS,
26 #endif
27 #if IS_ENABLED(CONFIG_NETFILTER_SYNPROXY)
28 NF_CT_EXT_SYNPROXY,
29 #endif
30 NF_CT_EXT_NUM,
31 };
32
33 #define NF_CT_EXT_HELPER_TYPE struct nf_conn_help
34 #define NF_CT_EXT_NAT_TYPE struct nf_conn_nat
35 #define NF_CT_EXT_SEQADJ_TYPE struct nf_conn_seqadj
36 #define NF_CT_EXT_ACCT_TYPE struct nf_conn_acct
37 #define NF_CT_EXT_ECACHE_TYPE struct nf_conntrack_ecache
38 #define NF_CT_EXT_TSTAMP_TYPE struct nf_conn_tstamp
39 #define NF_CT_EXT_TIMEOUT_TYPE struct nf_conn_timeout
40 #define NF_CT_EXT_LABELS_TYPE struct nf_conn_labels
41 #define NF_CT_EXT_SYNPROXY_TYPE struct nf_conn_synproxy
42
43 /* Extensions: optional stuff which isn't permanently in struct. */
44 struct nf_ct_ext {
45 struct rcu_head rcu;
46 u8 offset[NF_CT_EXT_NUM];
47 u8 len;
48 char data[0];
49 };
50
51 static inline bool __nf_ct_ext_exist(const struct nf_ct_ext *ext, u8 id)
52 {
53 return !!ext->offset[id];
54 }
55
56 static inline bool nf_ct_ext_exist(const struct nf_conn *ct, u8 id)
57 {
58 return (ct->ext && __nf_ct_ext_exist(ct->ext, id));
59 }
60
61 static inline void *__nf_ct_ext_find(const struct nf_conn *ct, u8 id)
62 {
63 if (!nf_ct_ext_exist(ct, id))
64 return NULL;
65
66 return (void *)ct->ext + ct->ext->offset[id];
67 }
68 #define nf_ct_ext_find(ext, id) \
69 ((id##_TYPE *)__nf_ct_ext_find((ext), (id)))
70
71 /* Destroy all relationships */
72 void __nf_ct_ext_destroy(struct nf_conn *ct);
73 static inline void nf_ct_ext_destroy(struct nf_conn *ct)
74 {
75 if (ct->ext)
76 __nf_ct_ext_destroy(ct);
77 }
78
79 /* Free operation. If you want to free a object referred from private area,
80 * please implement __nf_ct_ext_free() and call it.
81 */
82 static inline void nf_ct_ext_free(struct nf_conn *ct)
83 {
84 if (ct->ext)
85 kfree_rcu(ct->ext, rcu);
86 }
87
88 /* Add this type, returns pointer to data or NULL. */
89 void *nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp);
90
91 #define NF_CT_EXT_F_PREALLOC 0x0001
92
93 struct nf_ct_ext_type {
94 /* Destroys relationships (can be NULL). */
95 void (*destroy)(struct nf_conn *ct);
96
97 enum nf_ct_ext_id id;
98
99 unsigned int flags;
100
101 /* Length and min alignment. */
102 u8 len;
103 u8 align;
104 /* initial size of nf_ct_ext. */
105 u8 alloc_size;
106 };
107
108 int nf_ct_extend_register(struct nf_ct_ext_type *type);
109 void nf_ct_extend_unregister(struct nf_ct_ext_type *type);
110 #endif /* _NF_CONNTRACK_EXTEND_H */