diff options
author | alex <alex@FreeBSD.org> | 1996-06-17 00:00:35 +0000 |
---|---|---|
committer | alex <alex@FreeBSD.org> | 1996-06-17 00:00:35 +0000 |
commit | 0839ad4b61f9bff959b4034f24697cdf728e8158 (patch) | |
tree | 054023bd2420a849c650da5bf078d12435cb822c /sys/netinet/ip_fw.c | |
parent | fabf4e3fc071a9e1de4d598ed0e22000da144f9b (diff) | |
download | FreeBSD-src-0839ad4b61f9bff959b4034f24697cdf728e8158.zip FreeBSD-src-0839ad4b61f9bff959b4034f24697cdf728e8158.tar.gz |
Fix chain numbering bug when the highest line number installed >= 65435
and the rule being added has no explicit line number set.
Submitted by: Archie Cobbs <archie@whistle.com>
Diffstat (limited to 'sys/netinet/ip_fw.c')
-rw-r--r-- | sys/netinet/ip_fw.c | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/sys/netinet/ip_fw.c b/sys/netinet/ip_fw.c index a719803..b9c754e 100644 --- a/sys/netinet/ip_fw.c +++ b/sys/netinet/ip_fw.c @@ -12,7 +12,7 @@ * * This software is provided ``AS IS'' without any warranties of any kind. * - * $Id: ip_fw.c,v 1.38 1996/06/12 19:34:33 gpalmer Exp $ + * $Id: ip_fw.c,v 1.39 1996/06/13 17:35:28 gpalmer Exp $ */ /* @@ -499,29 +499,40 @@ add_entry(struct ip_fw_head *chainptr, struct ip_fw *frwl) if (!chainptr->lh_first) { LIST_INSERT_HEAD(chainptr, fwc, chain); + splx(s); + return(0); } else if (ftmp->fw_number == (u_short)-1) { if (fwc) free(fwc, M_IPFW); if (ftmp) free(ftmp, M_IPFW); splx(s); return (EINVAL); - } else { - nbr=0; - for (fcp = chainptr->lh_first; fcp; fcp = fcp->chain.le_next) - if (fcp->rule->fw_number == (u_short)-1 || - ( ftmp->fw_number && - fcp->rule->fw_number > ftmp->fw_number)) { - if (!ftmp->fw_number) - ftmp->fw_number = nbr + 100; - if (fcpl) { - LIST_INSERT_AFTER(fcpl, fwc, chain); - } else { - LIST_INSERT_HEAD(chainptr, fwc, chain); - } + } + + /* If entry number is 0, find highest numbered rule and add 100 */ + if (ftmp->fw_number == 0) { + for (fcp = chainptr->lh_first; fcp; fcp = fcp->chain.le_next) { + if (fcp->rule->fw_number != (u_short)-1) + nbr = fcp->rule->fw_number; + else break; + } + if (nbr < (u_short)-1 - 100) + nbr += 100; + ftmp->fw_number = nbr; + } + + /* Got a valid number; now insert it, keeping the list ordered */ + for (fcp = chainptr->lh_first; fcp; fcp = fcp->chain.le_next) { + if (fcp->rule->fw_number > ftmp->fw_number) { + if (fcpl) { + LIST_INSERT_AFTER(fcpl, fwc, chain); } else { - nbr=fcp->rule->fw_number; - fcpl = fcp; + LIST_INSERT_HEAD(chainptr, fwc, chain); } + break; + } else { + fcpl = fcp; + } } splx(s); |