From owner-freebsd-ipfw Wed Oct 11 8: 9:30 2000 Delivered-To: freebsd-ipfw@freebsd.org Received: from whale.sunbay.crimea.ua (whale.sunbay.crimea.ua [212.110.138.65]) by hub.freebsd.org (Postfix) with ESMTP id 3475637B503; Wed, 11 Oct 2000 08:08:04 -0700 (PDT) Received: (from ru@localhost) by whale.sunbay.crimea.ua (8.11.0/8.11.0) id e9BF7gB85848; Wed, 11 Oct 2000 18:07:42 +0300 (EEST) (envelope-from ru) Date: Wed, 11 Oct 2000 18:07:42 +0300 From: Ruslan Ermilov To: luigi@FreeBSD.org Cc: ipfw@FreeBSD.org Subject: CFR: patch for bin/18351: ipfw add with no rule number returns the wrong rule number Message-ID: <20001011180742.A85291@sunbay.com> Mail-Followup-To: luigi@FreeBSD.org, ipfw@FreeBSD.org References: <200010111440.HAA89914@freefall.freebsd.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="5mCyUwZo2JvN/JJP" Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <200010111440.HAA89914@freefall.freebsd.org>; from ru@FreeBSD.org on Wed, Oct 11, 2000 at 07:40:48AM -0700 Sender: owner-freebsd-ipfw@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG --5mCyUwZo2JvN/JJP Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Oct 11, 2000 at 07:40:48AM -0700, ru@FreeBSD.org wrote: > Synopsis: ipfw add with no rule number returns the wrong rule number > > Responsible-Changed-From-To: luigi->ru > Responsible-Changed-By: ru > Responsible-Changed-When: Wed Oct 11 07:40:11 PDT 2000 > Responsible-Changed-Why: > I have a working patch. > This patch simply changes the IP_FW_ADD sockopt from SOPT_SET to SOPT_GET, thus allowing IPFW to return the assigned rule number back to userland in case it was not specified explicitly. Does this patch look OK to you? Do I need to bump the __FreeBSD_version or not? -- Ruslan Ermilov Oracle Developer/DBA, ru@sunbay.com Sunbay Software AG, ru@FreeBSD.org FreeBSD committer, +380.652.512.251 Simferopol, Ukraine http://www.FreeBSD.org The Power To Serve http://www.oracle.com Enabling The Information Age --5mCyUwZo2JvN/JJP Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=p Index: ipfw/ipfw.c =================================================================== RCS file: /home/ncvs/src/sbin/ipfw/ipfw.c,v retrieving revision 1.96 diff -u -p -r1.96 ipfw.c --- ipfw/ipfw.c 2000/10/11 13:02:30 1.96 +++ ipfw/ipfw.c 2000/10/11 14:42:47 @@ -2131,11 +2131,11 @@ badviacombo: rule.fw_loghighest = rule.fw_logamount; } done: + i = sizeof(rule); + if (getsockopt(s, IPPROTO_IP, IP_FW_ADD, &rule, &i) == -1) + err(EX_UNAVAILABLE, "getsockopt(%s)", "IP_FW_ADD"); if (!do_quiet) show_ipfw(&rule, 10, 10); - i = setsockopt(s, IPPROTO_IP, IP_FW_ADD, &rule, sizeof rule); - if (i) - err(EX_UNAVAILABLE, "setsockopt(%s)", "IP_FW_ADD"); } static void Index: sys_netinet/ip_fw.c =================================================================== RCS file: /home/ncvs/src/sys/netinet/ip_fw.c,v retrieving revision 1.144 diff -u -p -r1.144 ip_fw.c --- sys_netinet/ip_fw.c 2000/10/06 12:12:09 1.144 +++ sys_netinet/ip_fw.c 2000/10/11 14:42:50 @@ -1512,7 +1512,7 @@ add_entry(struct ip_fw_head *chainptr, s } if (nbr < IPFW_DEFAULT_RULE - 100) nbr += 100; - ftmp->fw_number = nbr; + ftmp->fw_number = frwl->fw_number = nbr; } /* Got a valid number; now insert it, keeping the list ordered */ @@ -1928,6 +1928,8 @@ ip_fw_ctl(struct sockopt *sopt) error = EINVAL; } else { error = add_entry(&ip_fw_chain, &frwl); + if (!error) + error = sooptcopyout(sopt, &frwl, sizeof frwl); } break; Index: sys_netinet/raw_ip.c =================================================================== RCS file: /home/ncvs/src/sys/netinet/raw_ip.c,v retrieving revision 1.69 diff -u -p -r1.69 raw_ip.c --- sys_netinet/raw_ip.c 2000/09/14 14:42:03 1.69 +++ sys_netinet/raw_ip.c 2000/10/11 14:42:51 @@ -259,6 +259,7 @@ rip_ctloutput(so, sopt) error = sooptcopyout(sopt, &optval, sizeof optval); break; + case IP_FW_ADD: case IP_FW_GET: if (ip_fw_ctl_ptr == 0) error = ENOPROTOOPT; @@ -305,7 +306,6 @@ rip_ctloutput(so, sopt) inp->inp_flags &= ~INP_HDRINCL; break; - case IP_FW_ADD: case IP_FW_DEL: case IP_FW_FLUSH: case IP_FW_ZERO: --5mCyUwZo2JvN/JJP-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-ipfw" in the body of the message