提交 3cf4c7e3 编写于 作者: P Pablo Neira Ayuso

netfilter: nf_ct_ext: support variable length extensions

We can now define conntrack extensions of variable size. This
patch is useful to get rid of these unions:

union nf_conntrack_help
union nf_conntrack_proto
union nf_conntrack_nat_help
Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
上级 3a8fc53a
...@@ -80,10 +80,13 @@ static inline void nf_ct_ext_free(struct nf_conn *ct) ...@@ -80,10 +80,13 @@ static inline void nf_ct_ext_free(struct nf_conn *ct)
} }
/* Add this type, returns pointer to data or NULL. */ /* Add this type, returns pointer to data or NULL. */
void * void *__nf_ct_ext_add_length(struct nf_conn *ct, enum nf_ct_ext_id id,
__nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp); size_t var_alloc_len, gfp_t gfp);
#define nf_ct_ext_add(ct, id, gfp) \ #define nf_ct_ext_add(ct, id, gfp) \
((id##_TYPE *)__nf_ct_ext_add((ct), (id), (gfp))) ((id##_TYPE *)__nf_ct_ext_add_length((ct), (id), 0, (gfp)))
#define nf_ct_ext_add_length(ct, id, len, gfp) \
((id##_TYPE *)__nf_ct_ext_add_length((ct), (id), (len), (gfp)))
#define NF_CT_EXT_F_PREALLOC 0x0001 #define NF_CT_EXT_F_PREALLOC 0x0001
......
...@@ -44,7 +44,8 @@ void __nf_ct_ext_destroy(struct nf_conn *ct) ...@@ -44,7 +44,8 @@ void __nf_ct_ext_destroy(struct nf_conn *ct)
EXPORT_SYMBOL(__nf_ct_ext_destroy); EXPORT_SYMBOL(__nf_ct_ext_destroy);
static void * static void *
nf_ct_ext_create(struct nf_ct_ext **ext, enum nf_ct_ext_id id, gfp_t gfp) nf_ct_ext_create(struct nf_ct_ext **ext, enum nf_ct_ext_id id,
size_t var_alloc_len, gfp_t gfp)
{ {
unsigned int off, len; unsigned int off, len;
struct nf_ct_ext_type *t; struct nf_ct_ext_type *t;
...@@ -54,8 +55,8 @@ nf_ct_ext_create(struct nf_ct_ext **ext, enum nf_ct_ext_id id, gfp_t gfp) ...@@ -54,8 +55,8 @@ nf_ct_ext_create(struct nf_ct_ext **ext, enum nf_ct_ext_id id, gfp_t gfp)
t = rcu_dereference(nf_ct_ext_types[id]); t = rcu_dereference(nf_ct_ext_types[id]);
BUG_ON(t == NULL); BUG_ON(t == NULL);
off = ALIGN(sizeof(struct nf_ct_ext), t->align); off = ALIGN(sizeof(struct nf_ct_ext), t->align);
len = off + t->len; len = off + t->len + var_alloc_len;
alloc_size = t->alloc_size; alloc_size = t->alloc_size + var_alloc_len;
rcu_read_unlock(); rcu_read_unlock();
*ext = kzalloc(alloc_size, gfp); *ext = kzalloc(alloc_size, gfp);
...@@ -68,7 +69,8 @@ nf_ct_ext_create(struct nf_ct_ext **ext, enum nf_ct_ext_id id, gfp_t gfp) ...@@ -68,7 +69,8 @@ nf_ct_ext_create(struct nf_ct_ext **ext, enum nf_ct_ext_id id, gfp_t gfp)
return (void *)(*ext) + off; return (void *)(*ext) + off;
} }
void *__nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp) void *__nf_ct_ext_add_length(struct nf_conn *ct, enum nf_ct_ext_id id,
size_t var_alloc_len, gfp_t gfp)
{ {
struct nf_ct_ext *old, *new; struct nf_ct_ext *old, *new;
int i, newlen, newoff; int i, newlen, newoff;
...@@ -79,7 +81,7 @@ void *__nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp) ...@@ -79,7 +81,7 @@ void *__nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp)
old = ct->ext; old = ct->ext;
if (!old) if (!old)
return nf_ct_ext_create(&ct->ext, id, gfp); return nf_ct_ext_create(&ct->ext, id, var_alloc_len, gfp);
if (__nf_ct_ext_exist(old, id)) if (__nf_ct_ext_exist(old, id))
return NULL; return NULL;
...@@ -89,7 +91,7 @@ void *__nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp) ...@@ -89,7 +91,7 @@ void *__nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp)
BUG_ON(t == NULL); BUG_ON(t == NULL);
newoff = ALIGN(old->len, t->align); newoff = ALIGN(old->len, t->align);
newlen = newoff + t->len; newlen = newoff + t->len + var_alloc_len;
rcu_read_unlock(); rcu_read_unlock();
new = __krealloc(old, newlen, gfp); new = __krealloc(old, newlen, gfp);
...@@ -117,7 +119,7 @@ void *__nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp) ...@@ -117,7 +119,7 @@ void *__nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp)
memset((void *)new + newoff, 0, newlen - newoff); memset((void *)new + newoff, 0, newlen - newoff);
return (void *)new + newoff; return (void *)new + newoff;
} }
EXPORT_SYMBOL(__nf_ct_ext_add); EXPORT_SYMBOL(__nf_ct_ext_add_length);
static void update_alloc_size(struct nf_ct_ext_type *type) static void update_alloc_size(struct nf_ct_ext_type *type)
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册