Hi folks, I''m currently trying to make a patch on conntrack module. While reading some code I saw the following in include/linux/netfilter_ipv4/listhelp.h : /* Works on circular linked list. */ #define LIST_FIND(head, cmpfn, type, args...) \ ({ \ const struct list_head *__i = (head); \ \ ASSERT_READ_LOCK(head); \ do { \ __i = __i->next; \ if (__i == (head)) { \ __i = NULL; \ break; \ } \ } while (!cmpfn((const type)__i , ## args)); \ (type)__i; \ }) 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 ? Thanks in advance. Regards, -- Jeremie LE HEN aka TtZ/TataZ jeremie.le-hen@epita.fr ttz@epita.fr Hi! I''m a .signature virus! Copy me into your ~/.signature to help me spread! _______________________________________________ LARTC mailing list / LARTC@mailman.ds9a.nl http://mailman.ds9a.nl/mailman/listinfo/lartc HOWTO: http://lartc.org/
Hello, I would like to have some testers for this script which should save and restore ip rules and associated tables. Thanks #!/bin/bash # # chkconfig: 2345 85 15 # description: save and restore ip rules settings # config: /etc/sysconfig/iprules # source function library . /etc/rc.d/init.d/functions CONFIG=/etc/sysconfig/iprules RETVAL=0 case "$1" in save) echo -n "Saving ip rules:" rm $CONFIG > /dev/null 2>&1 ip ru ls | grep -v "^3276.:" | grep -v "^0:" | sed -e "s/://" -e "s/from all//" -e "s/^/ip ru add preference /" | echo $LINE >> $CONFIG done ip ru ls | grep -v "lookup local" | grep -v "lookup main" | grep -v "lookup default" | sed -e "s/^.*lookup //" | ip ro ls ta $LINE | sed -e "s/$/ ta $LINE/" -e "s/^/ip ro add /" >> $CONFIG done echo ;; stop) echo -n "Stopping ip rules:" ip ru ls | grep -v "lookup local" | grep -v "lookup main" | grep -v "lookup default" | sed -e "s/^.*lookup //" | ip ro flush ta $LINE done ip ru ls | grep -v "^3276.:" | grep -v "^0:" | sed -e "s/://" -e "s/from all//" -e "s/^/ip ru del preference /" /sbin/$LINE done rm -f /var/lock/subsys/rules echo ;; start) echo -n "Starting ip rules:" if [ -f /var/lock/subsys/rules ] ; then $0 stop fi # real start cat $CONFIG | while read LINE ; do /sbin/$LINE done touch /var/lock/subsys/rules echo ;; restart|reload) $0 stop $0 start RETVAL=$? ;; status) status gpm RETVAL=$? ;; *) echo "Usage: gpm {start|stop|status|restart|reload}" exit 1 esac exit $RETVAL _______________________________________________ LARTC mailing list / LARTC@mailman.ds9a.nl http://mailman.ds9a.nl/mailman/listinfo/lartc HOWTO: http://lartc.org/
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> _______________________________________________ LARTC mailing list / LARTC@mailman.ds9a.nl http://mailman.ds9a.nl/mailman/listinfo/lartc HOWTO: http://lartc.org/