Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 203982
b: refs/heads/master
c: ee92d37
h: refs/heads/master
v: v3
  • Loading branch information
Changli Gao authored and Patrick McHardy committed Aug 2, 2010
1 parent 51f0fb7 commit 705c183
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 24b36f0193467fa727b85b4c004016a8dae999b9
refs/heads/master: ee92d37861a90b8f14fa621ae5abcfb29a89aaa9
9 changes: 7 additions & 2 deletions trunk/include/net/netfilter/nf_conntrack_extend.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ struct nf_ct_ext {
char data[0];
};

static inline int nf_ct_ext_exist(const struct nf_conn *ct, u8 id)
static inline bool __nf_ct_ext_exist(const struct nf_ct_ext *ext, u8 id)
{
return (ct->ext && ct->ext->offset[id]);
return !!ext->offset[id];
}

static inline bool nf_ct_ext_exist(const struct nf_conn *ct, u8 id)
{
return (ct->ext && __nf_ct_ext_exist(ct->ext, id));
}

static inline void *__nf_ct_ext_find(const struct nf_conn *ct, u8 id)
Expand Down
22 changes: 12 additions & 10 deletions trunk/net/netfilter/nf_conntrack_extend.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ void __nf_ct_ext_destroy(struct nf_conn *ct)
{
unsigned int i;
struct nf_ct_ext_type *t;
struct nf_ct_ext *ext = ct->ext;

for (i = 0; i < NF_CT_EXT_NUM; i++) {
if (!nf_ct_ext_exist(ct, i))
if (!__nf_ct_ext_exist(ext, i))
continue;

rcu_read_lock();
Expand Down Expand Up @@ -73,44 +74,45 @@ static void __nf_ct_ext_free_rcu(struct rcu_head *head)

void *__nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp)
{
struct nf_ct_ext *new;
struct nf_ct_ext *old, *new;
int i, newlen, newoff;
struct nf_ct_ext_type *t;

/* Conntrack must not be confirmed to avoid races on reallocation. */
NF_CT_ASSERT(!nf_ct_is_confirmed(ct));

if (!ct->ext)
old = ct->ext;
if (!old)
return nf_ct_ext_create(&ct->ext, id, gfp);

if (nf_ct_ext_exist(ct, id))
if (__nf_ct_ext_exist(old, id))
return NULL;

rcu_read_lock();
t = rcu_dereference(nf_ct_ext_types[id]);
BUG_ON(t == NULL);

newoff = ALIGN(ct->ext->len, t->align);
newoff = ALIGN(old->len, t->align);
newlen = newoff + t->len;
rcu_read_unlock();

new = __krealloc(ct->ext, newlen, gfp);
new = __krealloc(old, newlen, gfp);
if (!new)
return NULL;

if (new != ct->ext) {
if (new != old) {
for (i = 0; i < NF_CT_EXT_NUM; i++) {
if (!nf_ct_ext_exist(ct, i))
if (!__nf_ct_ext_exist(old, i))
continue;

rcu_read_lock();
t = rcu_dereference(nf_ct_ext_types[i]);
if (t && t->move)
t->move((void *)new + new->offset[i],
(void *)ct->ext + ct->ext->offset[i]);
(void *)old + old->offset[i]);
rcu_read_unlock();
}
call_rcu(&ct->ext->rcu, __nf_ct_ext_free_rcu);
call_rcu(&old->rcu, __nf_ct_ext_free_rcu);
ct->ext = new;
}

Expand Down

0 comments on commit 705c183

Please sign in to comment.