blob: 2dcf31703acba7a18b9f167866390827054f9d98 [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,
Changli Gaoe0e76c82010-11-15 12:23:24 +010010#if defined(CONFIG_NF_NAT) || defined(CONFIG_NF_NAT_MODULE)
Yasuyuki Kozakai2d59e5c2007-07-07 22:24:28 -070011 NF_CT_EXT_NAT,
Changli Gaoe0e76c82010-11-15 12:23:24 +010012#endif
Krzysztof Piotr Oledzki58401572008-07-21 10:01:34 -070013 NF_CT_EXT_ACCT,
Changli Gaoe0e76c82010-11-15 12:23:24 +010014#ifdef CONFIG_NF_CONNTRACK_EVENTS
Pablo Neira Ayusoa0891aa2009-06-13 12:26:29 +020015 NF_CT_EXT_ECACHE,
Changli Gaoe0e76c82010-11-15 12:23:24 +010016#endif
17#ifdef CONFIG_NF_CONNTRACK_ZONES
Patrick McHardy5d0aa2c2010-02-15 18:13:33 +010018 NF_CT_EXT_ZONE,
Changli Gaoe0e76c82010-11-15 12:23:24 +010019#endif
Pablo Neira Ayusoa992ca22011-01-19 16:00:07 +010020#ifdef CONFIG_NF_CONNTRACK_TIMESTAMP
21 NF_CT_EXT_TSTAMP,
22#endif
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070023 NF_CT_EXT_NUM,
24};
25
Yasuyuki Kozakaiceceae12007-07-07 22:23:42 -070026#define NF_CT_EXT_HELPER_TYPE struct nf_conn_help
Yasuyuki Kozakai2d59e5c2007-07-07 22:24:28 -070027#define NF_CT_EXT_NAT_TYPE struct nf_conn_nat
Krzysztof Piotr Oledzki58401572008-07-21 10:01:34 -070028#define NF_CT_EXT_ACCT_TYPE struct nf_conn_counter
Pablo Neira Ayusoa0891aa2009-06-13 12:26:29 +020029#define NF_CT_EXT_ECACHE_TYPE struct nf_conntrack_ecache
Patrick McHardy5d0aa2c2010-02-15 18:13:33 +010030#define NF_CT_EXT_ZONE_TYPE struct nf_conntrack_zone
Pablo Neira Ayusoa992ca22011-01-19 16:00:07 +010031#define NF_CT_EXT_TSTAMP_TYPE struct nf_conn_tstamp
Yasuyuki Kozakaiceceae12007-07-07 22:23:42 -070032
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070033/* Extensions: optional stuff which isn't permanently in struct. */
34struct nf_ct_ext {
Patrick McHardy68b80f12008-06-17 15:51:47 -070035 struct rcu_head rcu;
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070036 u8 offset[NF_CT_EXT_NUM];
37 u8 len;
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070038 char data[0];
39};
40
Changli Gaoee92d372010-08-02 17:06:19 +020041static inline bool __nf_ct_ext_exist(const struct nf_ct_ext *ext, u8 id)
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070042{
Changli Gaoee92d372010-08-02 17:06:19 +020043 return !!ext->offset[id];
44}
45
46static inline bool nf_ct_ext_exist(const struct nf_conn *ct, u8 id)
47{
48 return (ct->ext && __nf_ct_ext_exist(ct->ext, id));
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070049}
50
51static inline void *__nf_ct_ext_find(const struct nf_conn *ct, u8 id)
52{
53 if (!nf_ct_ext_exist(ct, id))
54 return NULL;
55
56 return (void *)ct->ext + ct->ext->offset[id];
57}
58#define nf_ct_ext_find(ext, id) \
59 ((id##_TYPE *)__nf_ct_ext_find((ext), (id)))
60
61/* Destroy all relationships */
62extern void __nf_ct_ext_destroy(struct nf_conn *ct);
63static inline void nf_ct_ext_destroy(struct nf_conn *ct)
64{
65 if (ct->ext)
66 __nf_ct_ext_destroy(ct);
67}
68
69/* Free operation. If you want to free a object referred from private area,
70 * please implement __nf_ct_ext_free() and call it.
71 */
72static inline void nf_ct_ext_free(struct nf_conn *ct)
73{
74 if (ct->ext)
75 kfree(ct->ext);
76}
77
78/* Add this type, returns pointer to data or NULL. */
79void *
80__nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp);
81#define nf_ct_ext_add(ct, id, gfp) \
82 ((id##_TYPE *)__nf_ct_ext_add((ct), (id), (gfp)))
83
84#define NF_CT_EXT_F_PREALLOC 0x0001
85
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +000086struct nf_ct_ext_type {
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070087 /* Destroys relationships (can be NULL). */
88 void (*destroy)(struct nf_conn *ct);
89 /* Called when realloacted (can be NULL).
90 Contents has already been moved. */
Patrick McHardy86577c62008-02-07 17:56:34 -080091 void (*move)(void *new, void *old);
Yasuyuki Kozakaiecfab2c2007-07-07 22:23:21 -070092
93 enum nf_ct_ext_id id;
94
95 unsigned int flags;
96
97 /* Length and min alignment. */
98 u8 len;
99 u8 align;
100 /* initial size of nf_ct_ext. */
101 u8 alloc_size;
102};
103
104int nf_ct_extend_register(struct nf_ct_ext_type *type);
105void nf_ct_extend_unregister(struct nf_ct_ext_type *type);
106#endif /* _NF_CONNTRACK_EXTEND_H */