blob: 8a988d136465685766df0e0f610390bdad4f0bc4 [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{
8 NF_CT_EXT_NUM,
9};
10
11/* Extensions: optional stuff which isn't permanently in struct. */
12struct nf_ct_ext {
13 u8 offset[NF_CT_EXT_NUM];
14 u8 len;
15 u8 real_len;
16 char data[0];
17};
18
19static inline int nf_ct_ext_exist(const struct nf_conn *ct, u8 id)
20{
21 return (ct->ext && ct->ext->offset[id]);
22}
23
24static inline void *__nf_ct_ext_find(const struct nf_conn *ct, u8 id)
25{
26 if (!nf_ct_ext_exist(ct, id))
27 return NULL;
28
29 return (void *)ct->ext + ct->ext->offset[id];
30}
31#define nf_ct_ext_find(ext, id) \
32 ((id##_TYPE *)__nf_ct_ext_find((ext), (id)))
33
34/* Destroy all relationships */
35extern void __nf_ct_ext_destroy(struct nf_conn *ct);
36static inline void nf_ct_ext_destroy(struct nf_conn *ct)
37{
38 if (ct->ext)
39 __nf_ct_ext_destroy(ct);
40}
41
42/* Free operation. If you want to free a object referred from private area,
43 * please implement __nf_ct_ext_free() and call it.
44 */
45static inline void nf_ct_ext_free(struct nf_conn *ct)
46{
47 if (ct->ext)
48 kfree(ct->ext);
49}
50
51/* Add this type, returns pointer to data or NULL. */
52void *
53__nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp);
54#define nf_ct_ext_add(ct, id, gfp) \
55 ((id##_TYPE *)__nf_ct_ext_add((ct), (id), (gfp)))
56
57#define NF_CT_EXT_F_PREALLOC 0x0001
58
59struct nf_ct_ext_type
60{
61 /* Destroys relationships (can be NULL). */
62 void (*destroy)(struct nf_conn *ct);
63 /* Called when realloacted (can be NULL).
64 Contents has already been moved. */
65 void (*move)(struct nf_conn *ct, void *old);
66
67 enum nf_ct_ext_id id;
68
69 unsigned int flags;
70
71 /* Length and min alignment. */
72 u8 len;
73 u8 align;
74 /* initial size of nf_ct_ext. */
75 u8 alloc_size;
76};
77
78int nf_ct_extend_register(struct nf_ct_ext_type *type);
79void nf_ct_extend_unregister(struct nf_ct_ext_type *type);
80#endif /* _NF_CONNTRACK_EXTEND_H */