Skip to contentSkip to conversation

double call to ip_conntrack_put() ?

DISCUSSION Wang Jian 4 participants 7 messages Apr 18, 2005 netfilter

lore
Share & tools
lore

Wang Jian

author
#0 lore raw

Hi,

death_by_timeout() calls ip_conntrack_put() before return. And death_by_timeout() is called combined with ip_conntrack_put() in some places, such as

in early_drop()

        if (del_timer(&ct->timeout)) {
                death_by_timeout((unsigned long)ct);
                dropped = 1;
                CONNTRACK_STAT_INC(early_drop);
        }
        ip_conntrack_put(ct);

and in ip_ct_iterate_cleanup()

        while ((h = get_next_corpse(iter, data, &bucket)) != NULL) {
                struct ip_conntrack *ct = tuplehash_to_ctrack(h);
                /* Time to push up daises... */
                if (del_timer(&ct->timeout))
                        death_by_timeout((unsigned long)ct);
                /* ... else the timer will get him soon. */

                ip_conntrack_put(ct);
        }

Is this intended or misuse?

Signature · 1 line
  lark
#1 lore raw

Hi,

2005-04-18, h keltezéssel 17.29-kor Wang Jian ezt írta:

Quoted 4 lines

death_by_timeout() calls ip_conntrack_put() before return. And death_by_timeout() is called combined with ip_conntrack_put() in some places, such as

Quoted 8 lines

in early_drop()

        if (del_timer(&ct->timeout)) {
                death_by_timeout((unsigned long)ct);
                dropped = 1;
                CONNTRACK_STAT_INC(early_drop);
        }
        ip_conntrack_put(ct);

This isn't a bug. The function gets a reference to the conntrack entry
before releasing the read lock of the hash table, so it must release the entry after deleting it from the hash.

Quoted 11 lines

and in ip_ct_iterate_cleanup()

        while ((h = get_next_corpse(iter, data, &bucket)) != NULL) {
                struct ip_conntrack *ct = tuplehash_to_ctrack(h);
                /* Time to push up daises... */
                if (del_timer(&ct->timeout))
                        death_by_timeout((unsigned long)ct);
                /* ... else the timer will get him soon. */

                ip_conntrack_put(ct);
        }

Same here. get_next_corpse() increases the refcount of the returned
conntrack, so the caller has to dereference it.

Signature · 1 line
KOVACS Krisztian <[email protected]>
#2 lore raw
In reply to Wang Jian
Quoted 25 lines · Wang Jian

death_by_timeout() calls ip_conntrack_put() before return. And death_by_timeout() is called combined with ip_conntrack_put() in some places, such as

in early_drop()

        if (del_timer(&ct->timeout)) {
                death_by_timeout((unsigned long)ct);
                dropped = 1;
                CONNTRACK_STAT_INC(early_drop);
        }
        ip_conntrack_put(ct);

and in ip_ct_iterate_cleanup()

        while ((h = get_next_corpse(iter, data, &bucket)) != NULL) {
                struct ip_conntrack *ct = tuplehash_to_ctrack(h);
                /* Time to push up daises... */
                if (del_timer(&ct->timeout))
                        death_by_timeout((unsigned long)ct);
                /* ... else the timer will get him soon. */

                ip_conntrack_put(ct);
        }
Quoted 1 line

Is this intended or misuse?

This is intended. tuplehash_to_ctrack() generates a reference to the conntrack record. In death_by_timeout() the refcount is decremented, yielding 1 for the second call to ip_conntrack_put(). The dec_and_test in nf_conntrack_put() (called by ip_conntrack_put()) will result in a refcount of 0, sending the record to the destroy_conntrack() function (or more properly, whatever's registered in nfct->destroy(), which I'm pretty sure is always either NULL or destroy_conntrack()).

Signature · 2 lines
[ Tobias DiPasquale ]
0x636f6465736c696e67657240676d61696c2e636f6d
author
#3 lore raw

Hi Tobias DiPasquale,

Quoted 9 lines · Tobias DiPasquale

This is intended. tuplehash_to_ctrack() generates a reference to the conntrack record. In death_by_timeout() the refcount is decremented, yielding 1 for the second call to ip_conntrack_put(). The dec_and_test in nf_conntrack_put() (called by ip_conntrack_put()) will result in a refcount of 0, sending the record to the destroy_conntrack() function (or more properly, whatever's registered in nfct->destroy(), which I'm pretty sure is always either NULL or destroy_conntrack()).

Thanks for your clear answer :)

Signature · 1 line
  lark
#4 lore raw
In reply to Tobias DiPasquale
Quoted 7 lines · Tobias DiPasquale

This is intended. tuplehash_to_ctrack() generates a reference to the conntrack record. In death_by_timeout() the refcount is decremented, yielding 1 for the second call to ip_conntrack_put(). The dec_and_test in nf_conntrack_put() (called by ip_conntrack_put()) will result in a refcount of 0, sending the record to the destroy_conntrack() function (or more properly, whatever's registered in nfct->destroy(), which I'm pretty sure is always either NULL or destroy_conntrack()).

What I found confusing initially was that "put" in "ip_conntrack_put" means "release" or "refcount--" instead of "write" or "store" which would have been my first guess.

Sam Azez

#5 lore raw
Quoted 3 lines · Amin Azez

What I found confusing initially was that "put" in "ip_conntrack_put" means "release" or "refcount--" instead of "write" or "store" which would have been my first guess.

In the Linux kernel sources, *_get() usually increments a reference count on an object, and *_put() decrements it. This is a common naming convention, although I can see how it could be confusing.

Signature · 2 lines
[ Tobias DiPasquale ]
0x636f6465736c696e67657240676d61696c2e636f6d
author
#6 lore raw
In reply to Amin Azez

Hi Amin Azez,

Yes, I am also confused by the _put for a while until I read the code. IMHO, it's more clear to rename it to _release.

Quoted 15 lines · Amin Azez
Quoted 7 lines · Tobias DiPasquale

This is intended. tuplehash_to_ctrack() generates a reference to the conntrack record. In death_by_timeout() the refcount is decremented, yielding 1 for the second call to ip_conntrack_put(). The dec_and_test in nf_conntrack_put() (called by ip_conntrack_put()) will result in a refcount of 0, sending the record to the destroy_conntrack() function (or more properly, whatever's registered in nfct->destroy(), which I'm pretty sure is always either NULL or destroy_conntrack()).

What I found confusing initially was that "put" in "ip_conntrack_put" means "release" or "refcount--" instead of "write" or "store" which would have been my first guess.

Sam Azez

Signature · 1 line
  lark