blob: 2d2a1f9a61d868acb94b6e3bd92f47e074ccef8e [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,
Patrick McHardy5d0aa2c2010-02-15 18:13:33 +010011 NF_CT_EXT_ZONE,
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070012 NF_CT_EXT_NUM,
13};
14
Yasuyuki Kozakaiceceae12007-07-07 22:23:42 -070015#define NF_CT_EXT_HELPER_TYPE struct nf_conn_help
Yasuyuki Kozakai2d59e5c2007-07-07 22:24:28 -070016#define NF_CT_EXT_NAT_TYPE struct nf_conn_nat
Krzysztof Piotr Oledzki58401572008-07-21 10:01:34 -070017#define NF_CT_EXT_ACCT_TYPE struct nf_conn_counter
Pablo Neira Ayusoa0891aa2009-06-13 12:26:29 +020018#define NF_CT_EXT_ECACHE_TYPE struct nf_conntrack_ecache
Patrick McHardy5d0aa2c2010-02-15 18:13:33 +010019#define NF_CT_EXT_ZONE_TYPE struct nf_conntrack_zone
Yasuyuki Kozakaiceceae12007-07-07 22:23:42 -070020
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070021/* Extensions: optional stuff which isn't permanently in struct. */
22struct nf_ct_ext {
Patrick McHardy68b80f12008-06-17 15:51:47 -070023 struct rcu_head rcu;
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070024 u8 offset[NF_CT_EXT_NUM];
25 u8 len;
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070026 char data[0];
27};
28
29static inline int nf_ct_ext_exist(const struct nf_conn *ct, u8 id)
30{
31 return (ct->ext && ct->ext->offset[id]);
32}
33
34static inline void *__nf_ct_ext_find(const struct nf_conn *ct, u8 id)
35{
36 if (!nf_ct_ext_exist(ct, id))
37 return NULL;
38
39 return (void *)ct->ext + ct->ext->offset[id];
40}
41#define nf_ct_ext_find(ext, id) \
42 ((id##_TYPE *)__nf_ct_ext_find((ext), (id)))
43
44/* Destroy all relationships */
45extern void __nf_ct_ext_destroy(struct nf_conn *ct);
46static inline void nf_ct_ext_destroy(struct nf_conn *ct)
47{
48 if (ct->ext)
49 __nf_ct_ext_destroy(ct);
50}
51
52/* Free operation. If you want to free a object referred from private area,
53 * please implement __nf_ct_ext_free() and call it.
54 */
55static inline void nf_ct_ext_free(struct nf_conn *ct)
56{
57 if (ct->ext)
58 kfree(ct->ext);
59}
60
61/* Add this type, returns pointer to data or NULL. */
62void *
63__nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp);
64#define nf_ct_ext_add(ct, id, gfp) \
65 ((id##_TYPE *)__nf_ct_ext_add((ct), (id), (gfp)))
66
67#define NF_CT_EXT_F_PREALLOC 0x0001
68
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +000069struct nf_ct_ext_type {
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070070 /* Destroys relationships (can be NULL). */
71 void (*destroy)(struct nf_conn *ct);
72 /* Called when realloacted (can be NULL).
73 Contents has already been moved. */
Patrick McHardy86577c62008-02-07 17:56:34 -080074 void (*move)(void *new, void *old);
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070075
76 enum nf_ct_ext_id id;
77
78 unsigned int flags;
79
80 /* Length and min alignment. */
81 u8 len;
82 u8 align;
83 /* initial size of nf_ct_ext. */
84 u8 alloc_size;
85};
86
87int nf_ct_extend_register(struct nf_ct_ext_type *type);
88void nf_ct_extend_unregister(struct nf_ct_ext_type *type);
89#endif /* _NF_CONNTRACK_EXTEND_H */