blob: 0772d296dfdb12b26a4bd8d97fecdd914c088536 [file] [log] [blame]
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -07001#ifndef _NF_CONNTRACK_EXTEND_H
2#define _NF_CONNTRACK_EXTEND_H
3
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09004#include <linux/slab.h>
5
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -07006#include <net/netfilter/nf_conntrack.h>
7
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +00008enum nf_ct_ext_id {
Yasuyuki Kozakaiceceae12007-07-07 22:23:42 -07009 NF_CT_EXT_HELPER,
Yasuyuki Kozakai2d59e5c2007-07-07 22:24:28 -070010 NF_CT_EXT_NAT,
Krzysztof Piotr Oledzki58401572008-07-21 10:01:34 -070011 NF_CT_EXT_ACCT,
Pablo Neira Ayusoa0891aa2009-06-13 12:26:29 +020012 NF_CT_EXT_ECACHE,
Patrick McHardy5d0aa2c2010-02-15 18:13:33 +010013 NF_CT_EXT_ZONE,
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070014 NF_CT_EXT_NUM,
15};
16
Yasuyuki Kozakaiceceae12007-07-07 22:23:42 -070017#define NF_CT_EXT_HELPER_TYPE struct nf_conn_help
Yasuyuki Kozakai2d59e5c2007-07-07 22:24:28 -070018#define NF_CT_EXT_NAT_TYPE struct nf_conn_nat
Krzysztof Piotr Oledzki58401572008-07-21 10:01:34 -070019#define NF_CT_EXT_ACCT_TYPE struct nf_conn_counter
Pablo Neira Ayusoa0891aa2009-06-13 12:26:29 +020020#define NF_CT_EXT_ECACHE_TYPE struct nf_conntrack_ecache
Patrick McHardy5d0aa2c2010-02-15 18:13:33 +010021#define NF_CT_EXT_ZONE_TYPE struct nf_conntrack_zone
Yasuyuki Kozakaiceceae12007-07-07 22:23:42 -070022
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070023/* Extensions: optional stuff which isn't permanently in struct. */
24struct nf_ct_ext {
Patrick McHardy68b80f12008-06-17 15:51:47 -070025 struct rcu_head rcu;
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070026 u8 offset[NF_CT_EXT_NUM];
27 u8 len;
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070028 char data[0];
29};
30
Changli Gaoee92d372010-08-02 17:06:19 +020031static inline bool __nf_ct_ext_exist(const struct nf_ct_ext *ext, u8 id)
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070032{
Changli Gaoee92d372010-08-02 17:06:19 +020033 return !!ext->offset[id];
34}
35
36static inline bool nf_ct_ext_exist(const struct nf_conn *ct, u8 id)
37{
38 return (ct->ext && __nf_ct_ext_exist(ct->ext, id));
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070039}
40
41static inline void *__nf_ct_ext_find(const struct nf_conn *ct, u8 id)
42{
43 if (!nf_ct_ext_exist(ct, id))
44 return NULL;
45
46 return (void *)ct->ext + ct->ext->offset[id];
47}
48#define nf_ct_ext_find(ext, id) \
49 ((id##_TYPE *)__nf_ct_ext_find((ext), (id)))
50
51/* Destroy all relationships */
52extern void __nf_ct_ext_destroy(struct nf_conn *ct);
53static inline void nf_ct_ext_destroy(struct nf_conn *ct)
54{
55 if (ct->ext)
56 __nf_ct_ext_destroy(ct);
57}
58
59/* Free operation. If you want to free a object referred from private area,
60 * please implement __nf_ct_ext_free() and call it.
61 */
62static inline void nf_ct_ext_free(struct nf_conn *ct)
63{
64 if (ct->ext)
65 kfree(ct->ext);
66}
67
68/* Add this type, returns pointer to data or NULL. */
69void *
70__nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp);
71#define nf_ct_ext_add(ct, id, gfp) \
72 ((id##_TYPE *)__nf_ct_ext_add((ct), (id), (gfp)))
73
74#define NF_CT_EXT_F_PREALLOC 0x0001
75
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +000076struct nf_ct_ext_type {
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070077 /* Destroys relationships (can be NULL). */
78 void (*destroy)(struct nf_conn *ct);
79 /* Called when realloacted (can be NULL).
80 Contents has already been moved. */
Patrick McHardy86577c62008-02-07 17:56:34 -080081 void (*move)(void *new, void *old);
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070082
83 enum nf_ct_ext_id id;
84
85 unsigned int flags;
86
87 /* Length and min alignment. */
88 u8 len;
89 u8 align;
90 /* initial size of nf_ct_ext. */
91 u8 alloc_size;
92};
93
94int nf_ct_extend_register(struct nf_ct_ext_type *type);
95void nf_ct_extend_unregister(struct nf_ct_ext_type *type);
96#endif /* _NF_CONNTRACK_EXTEND_H */