]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - include/net/netfilter/nf_conntrack_extend.h
Merge tag 'modules-next-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[mirror_ubuntu-artful-kernel.git] / include / net / netfilter / nf_conntrack_extend.h
CommitLineData
ecfab2c9
YK
1#ifndef _NF_CONNTRACK_EXTEND_H
2#define _NF_CONNTRACK_EXTEND_H
3
5a0e3ad6
TH
4#include <linux/slab.h>
5
ecfab2c9
YK
6#include <net/netfilter/nf_conntrack.h>
7
fd2c3ef7 8enum nf_ct_ext_id {
ceceae1b 9 NF_CT_EXT_HELPER,
e0e76c83 10#if defined(CONFIG_NF_NAT) || defined(CONFIG_NF_NAT_MODULE)
2d59e5ca 11 NF_CT_EXT_NAT,
e0e76c83 12#endif
48b1de4c 13 NF_CT_EXT_SEQADJ,
58401572 14 NF_CT_EXT_ACCT,
e0e76c83 15#ifdef CONFIG_NF_CONNTRACK_EVENTS
a0891aa6 16 NF_CT_EXT_ECACHE,
e0e76c83 17#endif
a992ca2a
PNA
18#ifdef CONFIG_NF_CONNTRACK_TIMESTAMP
19 NF_CT_EXT_TSTAMP,
dd705072
PNA
20#endif
21#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
22 NF_CT_EXT_TIMEOUT,
c539f017
FW
23#endif
24#ifdef CONFIG_NF_CONNTRACK_LABELS
25 NF_CT_EXT_LABELS,
48b1de4c
PM
26#endif
27#if IS_ENABLED(CONFIG_NETFILTER_SYNPROXY)
28 NF_CT_EXT_SYNPROXY,
e0e76c83 29#endif
ecfab2c9
YK
30 NF_CT_EXT_NUM,
31};
32
ceceae1b 33#define NF_CT_EXT_HELPER_TYPE struct nf_conn_help
2d59e5ca 34#define NF_CT_EXT_NAT_TYPE struct nf_conn_nat
41d73ec0 35#define NF_CT_EXT_SEQADJ_TYPE struct nf_conn_seqadj
f7b13e43 36#define NF_CT_EXT_ACCT_TYPE struct nf_conn_acct
a0891aa6 37#define NF_CT_EXT_ECACHE_TYPE struct nf_conntrack_ecache
a992ca2a 38#define NF_CT_EXT_TSTAMP_TYPE struct nf_conn_tstamp
dd705072 39#define NF_CT_EXT_TIMEOUT_TYPE struct nf_conn_timeout
c539f017 40#define NF_CT_EXT_LABELS_TYPE struct nf_conn_labels
48b1de4c 41#define NF_CT_EXT_SYNPROXY_TYPE struct nf_conn_synproxy
ceceae1b 42
ecfab2c9
YK
43/* Extensions: optional stuff which isn't permanently in struct. */
44struct nf_ct_ext {
68b80f11 45 struct rcu_head rcu;
223b02d9
AV
46 u16 offset[NF_CT_EXT_NUM];
47 u16 len;
ecfab2c9
YK
48 char data[0];
49};
50
ee92d378 51static inline bool __nf_ct_ext_exist(const struct nf_ct_ext *ext, u8 id)
ecfab2c9 52{
ee92d378
CG
53 return !!ext->offset[id];
54}
55
56static 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));
ecfab2c9
YK
59}
60
61static 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 */
4e77be46 72void __nf_ct_ext_destroy(struct nf_conn *ct);
ecfab2c9
YK
73static 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 */
82static inline void nf_ct_ext_free(struct nf_conn *ct)
83{
84 if (ct->ext)
c13a84a8 85 kfree_rcu(ct->ext, rcu);
ecfab2c9
YK
86}
87
88/* Add this type, returns pointer to data or NULL. */
3cf4c7e3
PNA
89void *__nf_ct_ext_add_length(struct nf_conn *ct, enum nf_ct_ext_id id,
90 size_t var_alloc_len, gfp_t gfp);
91
ecfab2c9 92#define nf_ct_ext_add(ct, id, gfp) \
3cf4c7e3
PNA
93 ((id##_TYPE *)__nf_ct_ext_add_length((ct), (id), 0, (gfp)))
94#define nf_ct_ext_add_length(ct, id, len, gfp) \
95 ((id##_TYPE *)__nf_ct_ext_add_length((ct), (id), (len), (gfp)))
ecfab2c9
YK
96
97#define NF_CT_EXT_F_PREALLOC 0x0001
98
fd2c3ef7 99struct nf_ct_ext_type {
ecfab2c9
YK
100 /* Destroys relationships (can be NULL). */
101 void (*destroy)(struct nf_conn *ct);
ecfab2c9
YK
102
103 enum nf_ct_ext_id id;
104
105 unsigned int flags;
106
107 /* Length and min alignment. */
108 u8 len;
109 u8 align;
110 /* initial size of nf_ct_ext. */
111 u8 alloc_size;
112};
113
114int nf_ct_extend_register(struct nf_ct_ext_type *type);
115void nf_ct_extend_unregister(struct nf_ct_ext_type *type);
116#endif /* _NF_CONNTRACK_EXTEND_H */