From owner-freebsd-bugs Tue May 2 12:40: 7 2000 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id 0271C37BD39 for ; Tue, 2 May 2000 12:40:04 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id MAA53802; Tue, 2 May 2000 12:40:03 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Date: Tue, 2 May 2000 12:40:03 -0700 (PDT) Message-Id: <200005021940.MAA53802@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Darcy Buskermolen Subject: bin/18351 ipfw add with no rule number returns the wrong rule number Reply-To: Darcy Buskermolen Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org The following reply was made to PR bin/18351; it has been noted by GNATS. From: Darcy Buskermolen To: freebsd-gnats-submit@FreeBSD.org Cc: Subject: bin/18351 ipfw add with no rule number returns the wrong rule number Date: Tue, 02 May 2000 12:40:52 -0700 --=====================_957321652==_ Content-Type: text/plain; charset="us-ascii" Attached is my patch hopefully someone with a bit more hackers time can review and clean up this code \\DB --=====================_957321652==_ Content-Type: text/plain; charset="us-ascii" Content-Disposition: attachment; filename="ipfw.patch" *** ipfw.c.org Tue May 2 12:04:11 2000 --- ipfw.c Tue May 2 12:02:28 2000 *************** *** 1281,1300 **** int ac; char **av; { struct ip_fw rule; int i; u_char proto; struct protoent *pe; int saw_xmrc = 0, saw_via = 0; ! memset(&rule, 0, sizeof rule); av++; ac--; /* Rule number */ if (ac && isdigit(**av)) { rule.fw_number = atoi(*av); av++; ac--; } /* Action */ if (ac > 1 && !strncmp(*av, "prob", strlen(*av) ) ) { --- 1281,1341 ---- int ac; char **av; { + /* + struct ip_fw *rules; + + + void *data = NULL; + int pcwidth = 0; + int bcwidth = 0; + int n, num = 0; + + */ + struct dn_pipe *pipes; + int nbytes; + + struct ip_fw rule; + struct ip_fw *rules; int i; u_char proto; struct protoent *pe; + int num = 0; int saw_xmrc = 0, saw_via = 0; ! void *data=NULL; memset(&rule, 0, sizeof rule); av++; ac--; + { + const int unit = do_pipe ? sizeof(*pipes) : sizeof(*rules); + const int ocmd = do_pipe ? IP_DUMMYNET_GET : IP_FW_GET; + int nalloc = 0; + + while (num >= nalloc) { + nalloc = nalloc * 2 + 200; + nbytes = nalloc * unit; + if ((data = realloc(data, nbytes)) == NULL) + err(EX_OSERR, "realloc"); + if (getsockopt(s, IPPROTO_IP, ocmd, data, &nbytes) < 0) + err(EX_OSERR, "getsockopt(IP_%s_GET)", + do_pipe ? "DUMMYNET" : "FW"); + num = nbytes / unit; + } + } + /* Rule number */ if (ac && isdigit(**av)) { rule.fw_number = atoi(*av); av++; ac--; } + else { + rules = (struct ip_fw *) data; + num = 0; + while (rules[num].fw_number < 65535){ + num++; + } + rule.fw_number = num; + } /* Action */ if (ac > 1 && !strncmp(*av, "prob", strlen(*av) ) ) { --=====================_957321652==_-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message