[LARTC] LIST_FIND in netfilter_ipv4/listhelp.h

Thomas Graf tgr@reeler.org
Tue, 7 Oct 2003 16:25:08 +0200


Hi

* jeremie le-hen <20031006144458.GD24864@carpediem.epita.fr> 2003-10-06 16:44

> Unless I really drank too much yesterday evening, I'm pretty sure this
> algorithm will fail if the list has only one element, returning NULL
> immediately without even trying to compare the element.
> On the other hand, it seems to work pretty well for months, since it is
> widely used accross the NetFilter conntrack code. So where am I wrong ?

The code is correct.

Check include/linux/list.h, it's a cyclic list:
head->next points to first element
head->prev points to last element

the list iteration code will make it clear:
#define __list_for_each(pos, head) \
    for (pos = (head)->next; pos != (head); pos = pos->next)

Regards

-- 
Thomas GRAF <tgraf@suug.ch>