From owner-freebsd-ipfw Fri Mar 10 12:15:13 2000 Delivered-To: freebsd-ipfw@freebsd.org Received: from MailAndNews.com (MailAndNews.com [199.29.68.160]) by hub.freebsd.org (Postfix) with ESMTP id A254337BB03 for ; Fri, 10 Mar 2000 12:15:08 -0800 (PST) (envelope-from mheffner@mailandnews.com) Received: from muriel.penguinpowered.com [208.138.199.76] (mheffner@mailandnews.com); Fri, 10 Mar 2000 15:14:57 -0500 X-WM-Posted-At: MailAndNews.com; Fri, 10 Mar 00 15:14:57 -0500 Content-Length: 3382 Message-ID: X-Mailer: XFMail 1.4.4 on FreeBSD X-Priority: 3 (Normal) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="_=XFMail.1.4.4.FreeBSD:20000310151538:5922=_" In-Reply-To: <200003101136.MAA75621@info.iet.unipi.it> Date: Fri, 10 Mar 2000 15:15:38 -0500 (EST) Reply-To: Mike Heffner From: Mike Heffner To: Luigi Rizzo Subject: Re: ipfw doesn't match when src == dest Cc: freebsd-ipfw@FreeBSD.ORG Sender: owner-freebsd-ipfw@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG This message is in MIME format --_=XFMail.1.4.4.FreeBSD:20000310151538:5922=_ Content-Type: text/plain; charset=us-ascii On 10-Mar-2000 Luigi Rizzo wrote: |> Hello, |> |> When I recently redid my firewall, I wanted to block a strange packet from |> my |> cablemodem, |> |> Deny P:2 192.168.100.1 192.168.100.1 in via ed1 | | are you sure that the logging code prints the right thing ? | I noticed (from source code analysis) it does strange things with | fragments, it might as well misbehave with short packets etc. | Your right! When it logs ICMP or unknown ip packets, it'll incorrectly print the source and destination as the same address. This is from incorrect use of inet_ntoa(3)...from the manpage: "The string returned by inet_ntoa() resides in a static memory area. " So the following patch fixes it: (also attached as mailer will murder tabs) Index: sys/netinet/ip_fw.c =================================================================== RCS file: /home/ncvs/src/sys/netinet/ip_fw.c,v retrieving revision 1.131 diff -u -r1.131 ip_fw.c --- ip_fw.c 2000/02/29 17:51:25 1.131 +++ ip_fw.c 2000/03/10 20:04:13 @@ -464,7 +464,6 @@ } } - len = 0; switch (ip->ip_p) { case IPPROTO_TCP: len = snprintf(SNPARGS(proto, 0), "TCP %s", @@ -500,12 +499,13 @@ icmp->icmp_type, icmp->icmp_code); else len = snprintf(SNPARGS(proto, 0), "ICMP "); - snprintf(SNPARGS(proto, len), "%s %s", inet_ntoa(ip->ip_src), - inet_ntoa(ip->ip_dst)); + len += snprintf(SNPARGS(proto, len), "%s", inet_ntoa(ip->ip_src)); + snprintf(SNPARGS(proto, len), " %s", inet_ntoa(ip->ip_dst)); break; default: - snprintf(SNPARGS(proto, 0), "P:%d %s %s", ip->ip_p, - inet_ntoa(ip->ip_src), inet_ntoa(ip->ip_dst)); + len = snprintf(SNPARGS(proto, 0), "P:%d %s", ip->ip_p, + inet_ntoa(ip->ip_src)); + snprintf(SNPARGS(proto, len), " %s", inet_ntoa(ip->ip_dst)); break; } Later, /**************************************** * Mike Heffner * * Fredericksburg, VA -- ICQ# 882073 * * Sent at: 10-Mar-2000 -- 15:10:12 EST * * http://my.ispchannel.com/~mheffner * ****************************************/ --_=XFMail.1.4.4.FreeBSD:20000310151538:5922=_ Content-Disposition: attachment; filename="ip_fw.patch.gz" Content-Transfer-Encoding: base64 Content-Description: ip_fw.patch.gz Content-Type: application/octet-stream; name=ip_fw.patch.gz; SizeOnDisk=428 H4sICGVVyTgAA2lwX2Z3LnBhdGNoAK1S30vDMBB+Tv+KYzBYaWKSblMWUSZ7kD3oyub7mG2qwZmW Jk5F/N9Nuk5UrBM0kF+X++777i5TncknAebZUC2tcpOqcpk/HqTByd9HMJ8sIFdrKYDeFveS6nRj qKlS+g0h3gSVtJWSG6VvoHKbUYUGfsD7PMhUngN5AFLVd9iJJITszihmjFEW03gE/EgMuYiHaIuO ouiLV59yBjETbCB4PxiPgQwOB/gIIr8dwngcAEKvbnEzIGgtNZwAO3YG86hsegs9VZJTF7MM4cVZ 05WRME2S+exqtryaJMLjtyijy0ppm/cWl8nZ/HzRK6vCFhhYiKHjXKFrOriWMGQM89hpGI0w7zci ELih0ntP59alfS4l/mhIi0yGXhmSayNryC+Ip5OLBDoORxBqc3RhvGvX1BLBN2upbbHa5e4aGWIf oJb49TUzNnTxo62cqF3PO00bxzbKHniLxkaFq8p1JVd3/pTJfPWwtuKn1OsaJaKbwXv2Tb/bE67L sa8Oe9rSUH7ii5pP0Mb5z+XxP/4NvVZ2UhcEAAA= --_=XFMail.1.4.4.FreeBSD:20000310151538:5922=_-- End of MIME message To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-ipfw" in the body of the message