blob: e192dc17c5833754fed42bc9c5de94e9c6cb0aa5 [file] [log] [blame]
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -07001#ifndef _NF_CONNTRACK_EXTEND_H
2#define _NF_CONNTRACK_EXTEND_H
3
4#include <net/netfilter/nf_conntrack.h>
5
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +00006enum nf_ct_ext_id {
Yasuyuki Kozakaiceceae12007-07-07 22:23:42 -07007 NF_CT_EXT_HELPER,
Yasuyuki Kozakai2d59e5c2007-07-07 22:24:28 -07008 NF_CT_EXT_NAT,
Krzysztof Piotr Oledzki58401572008-07-21 10:01:34 -07009 NF_CT_EXT_ACCT,
Pablo Neira Ayusoa0891aa2009-06-13 12:26:29 +020010 NF_CT_EXT_ECACHE,
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070011 NF_CT_EXT_NUM,
12};
13
Yasuyuki Kozakaiceceae12007-07-07 22:23:42 -070014#define NF_CT_EXT_HELPER_TYPE struct nf_conn_help
Yasuyuki Kozakai2d59e5c2007-07-07 22:24:28 -070015#define NF_CT_EXT_NAT_TYPE struct nf_conn_nat
Krzysztof Piotr Oledzki58401572008-07-21 10:01:34 -070016#define NF_CT_EXT_ACCT_TYPE struct nf_conn_counter
Pablo Neira Ayusoa0891aa2009-06-13 12:26:29 +020017#define NF_CT_EXT_ECACHE_TYPE struct nf_conntrack_ecache
Yasuyuki Kozakaiceceae12007-07-07 22:23:42 -070018
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070019/* Extensions: optional stuff which isn't permanently in struct. */
20struct nf_ct_ext {
Patrick McHardy68b80f12008-06-17 15:51:47 -070021 struct rcu_head rcu;
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070022 u8 offset[NF_CT_EXT_NUM];
23 u8 len;
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070024 char data[0];
25};
26
27static inline int nf_ct_ext_exist(const struct nf_conn *ct, u8 id)
28{
29 return (ct->ext && ct->ext->offset[id]);
30}
31
32static inline void *__nf_ct_ext_find(const struct nf_conn *ct, u8 id)
33{
34 if (!nf_ct_ext_exist(ct, id))
35 return NULL;
36
37 return (void *)ct->ext + ct->ext->offset[id];
38}
39#define nf_ct_ext_find(ext, id) \
40 ((id##_TYPE *)__nf_ct_ext_find((ext), (id)))
41
42/* Destroy all relationships */
43extern void __nf_ct_ext_destroy(struct nf_conn *ct);
44static inline void nf_ct_ext_destroy(struct nf_conn *ct)
45{
46 if (ct->ext)
47 __nf_ct_ext_destroy(ct);
48}
49
50/* Free operation. If you want to free a object referred from private area,
51 * please implement __nf_ct_ext_free() and call it.
52 */
53static inline void nf_ct_ext_free(struct nf_conn *ct)
54{
55 if (ct->ext)
56 kfree(ct->ext);
57}
58
59/* Add this type, returns pointer to data or NULL. */
60void *
61__nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp);
62#define nf_ct_ext_add(ct, id, gfp) \
63 ((id##_TYPE *)__nf_ct_ext_add((ct), (id), (gfp)))
64
65#define NF_CT_EXT_F_PREALLOC 0x0001
66
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +000067struct nf_ct_ext_type {
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070068 /* Destroys relationships (can be NULL). */
69 void (*destroy)(struct nf_conn *ct);
70 /* Called when realloacted (can be NULL).
71 Contents has already been moved. */
Patrick McHardy86577c62008-02-07 17:56:34 -080072 void (*move)(void *new, void *old);
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070073
74 enum nf_ct_ext_id id;
75
76 unsigned int flags;
77
78 /* Length and min alignment. */
79 u8 len;
80 u8 align;
81 /* initial size of nf_ct_ext. */
82 u8 alloc_size;
83};
84
85int nf_ct_extend_register(struct nf_ct_ext_type *type);
86void nf_ct_extend_unregister(struct nf_ct_ext_type *type);
87#endif /* _NF_CONNTRACK_EXTEND_H */