blob: f80c0ed6d870f3514e39f9da71ce399927919465 [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
6enum nf_ct_ext_id
7{
Yasuyuki Kozakaiceceae12007-07-07 22:23:42 -07008 NF_CT_EXT_HELPER,
Yasuyuki Kozakai2d59e5c2007-07-07 22:24:28 -07009 NF_CT_EXT_NAT,
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070010 NF_CT_EXT_NUM,
11};
12
Yasuyuki Kozakaiceceae12007-07-07 22:23:42 -070013#define NF_CT_EXT_HELPER_TYPE struct nf_conn_help
Yasuyuki Kozakai2d59e5c2007-07-07 22:24:28 -070014#define NF_CT_EXT_NAT_TYPE struct nf_conn_nat
Yasuyuki Kozakaiceceae12007-07-07 22:23:42 -070015
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070016/* Extensions: optional stuff which isn't permanently in struct. */
17struct nf_ct_ext {
Patrick McHardy68b80f12008-06-17 15:51:47 -070018 struct rcu_head rcu;
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070019 u8 offset[NF_CT_EXT_NUM];
20 u8 len;
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070021 char data[0];
22};
23
24static inline int nf_ct_ext_exist(const struct nf_conn *ct, u8 id)
25{
26 return (ct->ext && ct->ext->offset[id]);
27}
28
29static inline void *__nf_ct_ext_find(const struct nf_conn *ct, u8 id)
30{
31 if (!nf_ct_ext_exist(ct, id))
32 return NULL;
33
34 return (void *)ct->ext + ct->ext->offset[id];
35}
36#define nf_ct_ext_find(ext, id) \
37 ((id##_TYPE *)__nf_ct_ext_find((ext), (id)))
38
39/* Destroy all relationships */
40extern void __nf_ct_ext_destroy(struct nf_conn *ct);
41static inline void nf_ct_ext_destroy(struct nf_conn *ct)
42{
43 if (ct->ext)
44 __nf_ct_ext_destroy(ct);
45}
46
47/* Free operation. If you want to free a object referred from private area,
48 * please implement __nf_ct_ext_free() and call it.
49 */
50static inline void nf_ct_ext_free(struct nf_conn *ct)
51{
52 if (ct->ext)
53 kfree(ct->ext);
54}
55
56/* Add this type, returns pointer to data or NULL. */
57void *
58__nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp);
59#define nf_ct_ext_add(ct, id, gfp) \
60 ((id##_TYPE *)__nf_ct_ext_add((ct), (id), (gfp)))
61
62#define NF_CT_EXT_F_PREALLOC 0x0001
63
64struct nf_ct_ext_type
65{
66 /* Destroys relationships (can be NULL). */
67 void (*destroy)(struct nf_conn *ct);
68 /* Called when realloacted (can be NULL).
69 Contents has already been moved. */
Patrick McHardy86577c62008-02-07 17:56:34 -080070 void (*move)(void *new, void *old);
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070071
72 enum nf_ct_ext_id id;
73
74 unsigned int flags;
75
76 /* Length and min alignment. */
77 u8 len;
78 u8 align;
79 /* initial size of nf_ct_ext. */
80 u8 alloc_size;
81};
82
83int nf_ct_extend_register(struct nf_ct_ext_type *type);
84void nf_ct_extend_unregister(struct nf_ct_ext_type *type);
85#endif /* _NF_CONNTRACK_EXTEND_H */