From owner-freebsd-ipfw@FreeBSD.ORG Sun Nov 30 04:26:38 2003 Return-Path: Delivered-To: freebsd-ipfw@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9CBC516A4CF for ; Sun, 30 Nov 2003 04:26:38 -0800 (PST) Received: from spf13.us4.outblaze.com (205-158-62-67.outblaze.com [205.158.62.67]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6DE6843FDD for ; Sun, 30 Nov 2003 04:26:33 -0800 (PST) (envelope-from ivo@bsdmail.org) Received: from 205-158-62-68.outblaze.com (205-158-62-68.outblaze.com [205.158.62.68]) by spf13.us4.outblaze.com (Postfix) with QMQP id 9F5821801D6E for ; Sun, 30 Nov 2003 12:26:31 +0000 (GMT) Received: (qmail 99824 invoked from network); 30 Nov 2003 12:26:31 -0000 Received: from unknown (HELO ws5-2.us4.outblaze.com) (205.158.62.133) by 205-158-62-153.outblaze.com with SMTP; 30 Nov 2003 12:26:31 -0000 Received: (qmail 7869 invoked by uid 1001); 30 Nov 2003 12:26:31 -0000 Message-ID: <20031130122631.7868.qmail@bsdmail.com> Content-Type: multipart/mixed; boundary="----------=_1070195191-6845-0" Content-Transfer-Encoding: 7bit MIME-Version: 1.0 X-Mailer: MIME-tools 5.41 (Entity 5.404) Received: from [62.73.96.164] by ws5-3.us4.outblaze.com with http for ivo@bsdmail.org; Sun, 30 Nov 2003 14:26:31 +0200 From: "Ivo Vachkov" To: freebsd-ipfw@freebsd.org Date: Sun, 30 Nov 2003 14:26:31 +0200 X-Originating-Ip: 62.73.96.164 X-Originating-Server: ws5-3.us4.outblaze.com cc: freebsd-net@freebsd.org Subject: X-BeenThere: freebsd-ipfw@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: IPFW Technical Discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 30 Nov 2003 12:26:38 -0000 This is a multi-part message in MIME format... ------------=_1070195191-6845-0 Content-Type: text/plain; charset="iso-8859-1" Content-Disposition: inline Content-Transfer-Encoding: 7bit Hi all, I've been trying to write some code using divert(4) sockets, but i meet the following difficulties: - when i get diverted packet it has both source and destination IP addresses the same. The attached code shows: 192.168.0.2 -> 192.168.0.2 getting 84 bytes, real: 84 and the way I run it is (on 192.168.0.2): ipfw add 100 divert 8670 ip from any to 192.168.0.1 burstd then on 192.168.0.2 I issue "ping 192.168.0.1" - the manual says this happens with recvfrom()/sendto(), but recv() is mentioned to be same as recvfrom() and read()/write() sometimes fail. After digging some kernel code I've found that around line 167 in ip_divert.c we have: /* * Record receive interface address, if any. * But only for incoming packets. */ divsrc.sin_addr.s_addr = 0; if (incoming) { struct ifaddr *ifa; /* Sanity check */ KASSERT((m->m_flags & M_PKTHDR), ("%s: !PKTHDR", __FUNCTION__)); /* Find IP address for receive interface */ TAILQ_FOREACH(ifa, &m->m_pkthdr.rcvif->if_addrhead, ifa_link) { if (ifa->ifa_addr == NULL) continue; if (ifa->ifa_addr->sa_family != AF_INET) continue; divsrc.sin_addr = ((struct sockaddr_in *) ifa->ifa_addr)->sin_addr; break; } } which (as I think) changes the address of diverted packet. What is the reason for that and are there any workarounds to get real source and destination IP addresses from a diverted packet. I need both because I try to make connection tracking based on src<->dst . Any help with that is appretiated. Any divert code welcome. I've looked through natd.c and it was helpfull. Ivo Vachkov P.S. Excuse my: - English - long pastes - (sometimes) lack of kernel code understanding -- _______________________________________________ Get your free email from http://mymail.bsdmail.com Powered by Outblaze ------------=_1070195191-6845-0 Content-Type: application/octet-stream; name="Makefile" Content-Disposition: attachment; filename="Makefile" Content-Transfer-Encoding: base64 Q0MJPQljYwpDRkxBR1MJPQktZyAtV2FsbCAtV3BvaW50ZXItYXJpdGgKTElC Uwk9CgpTUkMJPQlidXJzdGQuYwpPQkoJPQkKUFJPRwk9CWJ1cnN0ZAoKYWxs OiQoU1JDKQoJJChDQykgJChDRkxBR1MpIC1jICouYwoJJChDQykgJChDRkxB R1MpIC1vICQoUFJPRykgJChTUkMpICQoT0JKKSAkKExJQlMpCgpjbGVhbjoK CXJtIC1mICQoUFJPRykgKi5jb3JlICoubyBldGMvKgo= ------------=_1070195191-6845-0 Content-Type: application/octet-stream; name="burstd.h" Content-Disposition: attachment; filename="burstd.h" Content-Transfer-Encoding: base64 I2luY2x1ZGUgPHN5cy90eXBlcy5oPgojaW5jbHVkZSA8c3lzL3NvY2tldC5o PgojaW5jbHVkZSA8c3lzL3N5c2N0bC5oPgojaW5jbHVkZSA8c3lzL3RpbWUu aD4KI2luY2x1ZGUgPG5ldGluZXQvaW4uaD4KI2luY2x1ZGUgPG5ldGluZXQv aW5fc3lzdG0uaD4KI2luY2x1ZGUgPG5ldGluZXQvaXAuaD4KI2luY2x1ZGUg PG1hY2hpbmUvaW5fY2tzdW0uaD4KI2luY2x1ZGUgPG5ldGluZXQvdGNwLmg+ CiNpbmNsdWRlIDxuZXRpbmV0L3VkcC5oPgojaW5jbHVkZSA8bmV0aW5ldC9p cF9pY21wLmg+CiNpbmNsdWRlIDxuZXQvaWYuaD4KI2luY2x1ZGUgPG5ldC9p Zl9kbC5oPgojaW5jbHVkZSA8bmV0L3JvdXRlLmg+CiNpbmNsdWRlIDxhcnBh L2luZXQuaD4KI2luY2x1ZGUgPGFsaWFzLmg+CiNpbmNsdWRlIDxjdHlwZS5o PgojaW5jbHVkZSA8ZXJyLmg+CiNpbmNsdWRlIDxlcnJuby5oPgojaW5jbHVk ZSA8bmV0ZGIuaD4KI2luY2x1ZGUgPHNpZ25hbC5oPgojaW5jbHVkZSA8c3Rk aW8uaD4KI2luY2x1ZGUgPHN0ZGxpYi5oPgojaW5jbHVkZSA8c3RyaW5nLmg+ CiNpbmNsdWRlIDxzeXNsb2cuaD4KI2luY2x1ZGUgPHVuaXN0ZC5oPgoKLy8g I2luY2x1ZGUgInF1ZXVlLmgiCgojZGVmaW5lIENPTkYJCSJidXJzdGQuY29u ZiIKCi8qIENvbm5lY3Rpb24gdHlwZTsgYnVyc3RpbmcgKi8KdHlwZWRlZiBz dHJ1Y3QgX2Zsb3cKewoJc3RydWN0IGluX2FkZHIgCXNyY19hZGRyOwoJc3Ry dWN0IGluX2FkZHIJZHN0X2FkZHI7Cglsb25nIGxvbmcJYnl0ZXM7Cglsb25n IGxvbmcJbGFzdDsKCWludAkJYWxpdmU7CglpbnQgCQl1c2VkOwp9Q09OTkVD VElPTjsKCnR5cGVkZWYgc3RydWN0IF9ub2RlCnsKCXN0cnVjdCBfbm9kZSAJ Km5leHQ7CglzdHJ1Y3QgX2Zsb3cJKmRhdGE7Cn1DT05OX0xJU1Q7Cgpsb25n IGxvbmcgCWxpbWl0LCByYXRlOwoKLyogU29tZSBmdW5jdGlvbnMgKi8KCi8q IHNpZ25hbC5jICovCnZvaWQgc2lnX2Fscm1faG5kKGludCBzaWcpOwovKiBp bml0LmMgKi8Kdm9pZCBzZXRfcmF0ZV9saW1pdCgpOwovKiBwYXJlbnQuYyAq LwppbnQgc2VhcmNoX2Nvbm4oQ09OTkVDVElPTiBjb25zW10sIHN0cnVjdCBp bl9hZGRyIHNhZGRyLCBzdHJ1Y3QgaW5fYWRkciBkYWRkcik7CmludCBhZGRf Y29ubihDT05ORUNUSU9OIGNvbnNbXSwgQ09OTkVDVElPTiBzX2Nvbm4pOwo= ------------=_1070195191-6845-0 Content-Type: application/octet-stream; name="burstd.c" Content-Disposition: attachment; filename="burstd.c" Content-Transfer-Encoding: base64 I2luY2x1ZGUgImJ1cnN0ZC5oIgoKaW50IG1haW4oaW50IGFyZ2MsIGNoYXIg Kiphcmd2KQp7CglpbnQgCQkJZGl2SU87CglmZF9zZXQJCQlyZWFkbWFzazsK CXN0cnVjdCBzb2NrYWRkcl9pbiAJc2E7CglpbnQgCQkJYnl0ZXMsIG9sZGJ5 dGVzLCBhZGRyU2l6ZTsKCXN0cnVjdCBpcCoJCWlwOwoJdm9pZCoJCQlidWZm OwoJCgoJYnVmZiA9ICh2b2lkICopbWFsbG9jKElQX01BWFBBQ0t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pLCBpbmV0X250b2Eo aXAtPmlwX2RzdCkpOwoJCQlwcmludGYoImdldHRpbmcgJWQgYnl0ZXMsIHJl YWw6ICVkXG4iLCBvbGRieXRlcywgbnRvaHMoaXAtPmlwX2xlbikpOwoJCQlw cmludGYoInNhLnNpbl9hZGRyLnNfYWRkciA9ICVzXG4iLCBpbmV0X250b2Eo c2Euc2luX2FkZHIpKTsKCQkJCgkJCWlmKChieXRlcyA9IHNlbmR0byhkaXZJ TywgYnVmZiwgb2xkYnl0ZXMsIDAsIChzdHJ1Y3Qgc29ja2FkZHIqKSAmc2Es IGFkZHJTaXplKSkgIT0gb2xkYnl0ZXMpCgkJCXsKCQkJCXByaW50ZigiRGlm ZmVyZW50IHJlY2lldmVkL3NlbnQgdmFsdWVzOiAlZCA8LT4gJWRcbiIsIG9s ZGJ5dGVzLCBieXRlcyk7CgkJCQlwZXJyb3IoInNlbmR0byIpOwoJCQkJZXhp dCgtMSk7CgkJCX0KCQl9Cgl9CglyZXR1cm4gMDsKfQo= ------------=_1070195191-6845-0-- From owner-freebsd-ipfw@FreeBSD.ORG Sun Nov 30 08:31:04 2003 Return-Path: Delivered-To: freebsd-ipfw@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A731716A4DE; Sun, 30 Nov 2003 08:31:04 -0800 (PST) Received: from whizzo.transsys.com (whizzo.TransSys.COM [144.202.42.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id 92A5743FB1; Sun, 30 Nov 2003 08:31:03 -0800 (PST) (envelope-from louie@whizzo.transsys.com) Received: from whizzo.transsys.com (#6@localhost [127.0.0.1]) by whizzo.transsys.com (8.12.9p2/8.12.9) with ESMTP id hAUGUoIg060968; Sun, 30 Nov 2003 11:30:50 -0500 (EST) (envelope-from louie@whizzo.transsys.com) Message-Id: <200311301630.hAUGUoIg060968@whizzo.transsys.com> X-Mailer: exmh version 2.6.3 04/04/2003 with nmh-1.0.4 To: "Ivo Vachkov" X-Image-URL: http://www.transsys.com/louie/images/louie-mail.jpg From: "Louis A. Mamakos" References: <20031130122631.7868.qmail@bsdmail.com> In-reply-to: Your message of "Sun, 30 Nov 2003 14:26:31 +0200." <20031130122631.7868.qmail@bsdmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sun, 30 Nov 2003 11:30:50 -0500 Sender: louie@TransSys.COM cc: freebsd-ipfw@freebsd.org cc: freebsd-net@freebsd.org Subject: Re: X-BeenThere: freebsd-ipfw@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: IPFW Technical Discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 30 Nov 2003 16:31:04 -0000 The problem is in your test program; you're calling inet_ntoa() twice in your printf() invocation, and the second call to inet_ntoa() overwrites the static buffer that's returned. louie From owner-freebsd-ipfw@FreeBSD.ORG Sun Nov 30 14:42:22 2003 Return-Path: Delivered-To: freebsd-ipfw@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5E5B616A4CE for ; Sun, 30 Nov 2003 14:42:22 -0800 (PST) Received: from cisovanet.pl (toudi.cisovanet.pl [212.160.158.193]) by mx1.FreeBSD.org (Postfix) with SMTP id 5CE7A43FA3 for ; Sun, 30 Nov 2003 14:42:19 -0800 (PST) (envelope-from robert@toudi.cisovanet.pl) Received: (qmail 97999 invoked from network); 30 Nov 2003 22:42:20 -0000 Received: from unknown (HELO toudi.cisovanet.pl) (212.160.158.193) by 0 with SMTP; 30 Nov 2003 22:42:20 -0000 Received: (from robert@localhost) by toudi.cisovanet.pl (8.12.6/8.12.6/Submit) id hAUMgJDT097994 for ipfw@freebsd.org; Sun, 30 Nov 2003 23:42:19 +0100 (CET) Date: Sun, 30 Nov 2003 23:42:19 +0100 From: Robert Krasicki To: ipfw@freebsd.org Message-ID: <20031130224219.GA96501@toudi.cisovanet.pl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i Subject: Dummynet problem X-BeenThere: freebsd-ipfw@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: IPFW Technical Discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 30 Nov 2003 22:42:22 -0000 Hello, My machine stopped responding while working on pipes. Here's the info I got. # /var/log/messages Nov 30 21:30:58 devel stunnel[670]: pop3s connected from 80.56.52.238:1859 Nov 30 21:31:23 devel stunnel[670]: Connection closed: 8013 bytes sent to SSL, 126 bytes sent to socket Nov 30 21:35:16 devel kernel: dummynet: ++ ref to pipe 11 from fs 1 Nov 30 21:35:16 devel kernel: dummynet: ++ ref to pipe 11 from fs 3 Nov 30 21:35:16 devel kernel: dummynet: ++ ref to pipe 11 from fs 5 Nov 30 21:35:16 devel kernel: dummynet: ++ ref to pipe 11 from fs 7 Nov 30 21:35:16 devel kernel: dummynet: ++ ref to pipe 11 from fs 9 Nov 30 21:35:16 devel kernel: dummynet: ++ ref to pipe 11 from fs 11 Nov 30 21:35:16 devel kernel: dummynet: ++ ref to pipe 11 from fs 15 Nov 30 21:35:45 devel stunnel[670]: pop3s connected from 80.56.52.238:1892 Nov 30 21:35:52 devel stunnel[670]: Connection closed: 2247 bytes sent to SSL, 62 bytes sent to socket Nov 30 22:17:12 devel syslogd: kernel boot file is /boot/kernel/kernel Nov 30 22:17:12 devel kernel: Copyright (c) 1992-2003 The FreeBSD Project. Nov 30 22:17:12 devel kernel: Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994 Nov 30 22:17:12 devel kernel: The Regents of the University of California. All rights reserved. .... Because of I had no direct access to the machine I had to call and ask for rebooting it (As I can see, reset button was used) The error occured when I was flushing pipes. I'm sure that there were 2 rules set, both allowing access. ( I just wanted to make sure, that some traffic is controlled by ipfw). Before, few rules used queues & pipes, but all of them have been deleted successfuly (so I assume that I could safely flush the pipes ?) Maybe ony of you had the same problem or maybe I missed with ipfw configuration? Thanks! Regards, Robert More detailed information: System information: FreeBSD devel.foo.com 5.1-RELEASE-p10 FreeBSD 5.1-RELEASE-p10 #1: Wed Oct 22 22:32:11 CEST 2003 Kernel (firewall) options: options IPFIREWALL options IPFIREWALL_VERBOSE options IPFIREWALL_VERBOSE_LIMIT=200 options IPDIVERT options DUMMYNET options HZ=1000 options IPFIREWALL_DEFAULT_TO_ACCEPT sysctls: net.link.ether.bridge_ipfw: 1 net.link.ether.bridge_ipfw_drop: 0 net.link.ether.bridge_ipfw_collisions: 0 net.link.ether.ipfw: 0 net.inet.ip.fw.one_pass: 1 (machine is acting as a bridge) Machine was not overloaded at that moment. Dmesg: Copyright (c) 1992-2003 The FreeBSD Project. Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994 The Regents of the University of California. All rights reserved. FreeBSD 5.1-RELEASE-p10 #1: Wed Oct 22 22:32:11 CEST 2003 robert@devel.foo.com:/usr/obj/usr/src/sys/TUNED Preloaded elf kernel "/boot/kernel/kernel" at 0xc04d9000. Preloaded elf module "/boot/kernel/acpi.ko" at 0xc04d9278. Timecounter "i8254" frequency 1193182 Hz Timecounter "TSC" frequency 2400099508 Hz CPU: Intel(R) Pentium(R) 4 CPU 2.40GHz (2400.10-MHz 686-class CPU) Origin = "GenuineIntel" Id = 0xf27 Stepping = 7 Features=0xbfebfbff real memory = 1073725440 (1023 MB) avail memory = 1037737984 (989 MB) Pentium Pro MTRR support enabled altq: major number is 96 npx0: on motherboard npx0: INT 16 interface acpi0: on motherboard pcibios: BIOS version 2.10 Using $PIR table, 11 entries at 0xc00f2320 acpi0: power button is handled as a fixed feature programming model. Timecounter "ACPI-fast" frequency 3579545 Hz acpi_timer0: <24-bit timer at 3.579545MHz> port 0xe408-0xe40b on acpi0 acpi_cpu0: on acpi0 acpi_cpu1: on acpi0 acpi_button0: on acpi0 pcib0: port 0xcf8-0xcff on acpi0 pci0: on pcib0 agp0: mem 0xf0000000-0xf3ffffff at device 0.0 on pci0 pcib1: mem 0xe8000000-0xebffffff at device 1.0 on pci0 pci1: on pcib1 pci1: at device 0.0 (no driver attached) pci0: at device 29.0 (no driver attached) pci0: at device 29.1 (no driver attached) pci0: at device 29.2 (no driver attached) pci0: at device 29.7 (no driver attached) pcib2: at device 30.0 on pci0 pci2: on pcib2 ed0: port 0xa800-0xa81f at device 2.0 on pci2 pcib2: slot 2 INTA is routed to irq 10 ed0: address 00:c0:26:ef:3a:d4, type NE2000 (16 bit) pci2: at device 3.0 (no driver attached) pci2: at device 4.0 (no driver attached) bge0: mem 0xdc800000-0xdc80ffff at device 5.0 on pci2 pcib2: slot 5 INTA is routed to irq 9 bge0: Ethernet address: 00:0c:6e:0f:7a:6b miibus0: on bge0 brgphy0: on miibus0 brgphy0: 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, 1000baseTX, 1000baseTX-FDX, auto isab0: at device 31.0 on pci0 isa0: on isab0 atapci0: port 0xf000-0xf00f,0-0x3,0-0x7,0-0x3,0-0x7 irq 9 at device 31.1 on pci0 ata0: at 0x1f0 irq 14 on atapci0 ata1: at 0x170 irq 15 on atapci0 pci0: at device 31.5 (no driver attached) fdc0: port 0x3f7,0x3f2-0x3f5 irq 6 drq 2 on acpi0 fdc0: FIFO enabled, 8 bytes threshold ppc0 port 0x778-0x77b,0x378-0x37f irq 7 drq 3 on acpi0 ppc0: SMC-like chipset (ECP/EPP/PS2/NIBBLE) in COMPATIBLE mode ppc0: FIFO with 16/16/16 bytes threshold ppbus0: on ppc0 plip0: on ppbus0 ppi0: on ppbus0 sio0 port 0x3f8-0x3ff irq 4 on acpi0 sio0: type 16550A sio1 port 0x2f8-0x2ff irq 3 on acpi0 sio1: type 16550A atkbdc0: port 0x64,0x60 irq 1 on acpi0 atkbd0: flags 0x1 irq 1 on atkbdc0 kbd0 at atkbd0 pmtimer0 on isa0 orm0: