From owner-freebsd-ipfw@freebsd.org Fri Jul 29 13:23:44 2016 Return-Path: Delivered-To: freebsd-ipfw@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 86F7ABA7EB2 for ; Fri, 29 Jul 2016 13:23:44 +0000 (UTC) (envelope-from rj@obsigna.com) Received: from mo6-p00-ob.smtp.rzone.de (mo6-p00-ob.smtp.rzone.de [IPv6:2a01:238:20a:202:5300::4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.smtp.rzone.de", Issuer "TeleSec ServerPass DE-2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id F2D8D1712; Fri, 29 Jul 2016 13:23:43 +0000 (UTC) (envelope-from rj@obsigna.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1469798621; l=3695; s=domk; d=obsigna.com; h=To:References:Content-Transfer-Encoding:Cc:Date:In-Reply-To:From: Subject:Mime-Version:Content-Type; bh=3oxNXZ4GHD7G2qWCXMTzoX7lXBcpCGEQUVu8+zUVsWo=; b=OqTZSqnzAlozc5fmCO0JjW0lxOZCKTi6zLNmDUq9vb9U3rwHHoGSAZXNWv/7KaxCTKV qp1pLegaZ1O/1pi7uCHbvw0l9fbDazRvSGPcR+7R7k7lpkSWpknAJOj8tMGYV/JZoRITv s9612hMtKg7N4cfF0PCZSOdM6ulod4WmSxs= X-RZG-AUTH: :O2kGeEG7b/pS1EK7WHa0hxqKZr4lnx6UhToX1IWHkW4X7v2ImaU2BqlKi/2sgPrOHjSDsnQ= X-RZG-CLASS-ID: mo00 Received: from mail.obsigna.com (bd1d9e9f.virtua.com.br [189.29.158.159]) by smtp.strato.de (RZmta 38.13 DYNA|AUTH) with ESMTPSA id f057f3s6TDNdxHv (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Fri, 29 Jul 2016 15:23:39 +0200 (CEST) Received: from rolf.projectworld.net (rolf.projectworld.net [192.168.222.25]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.obsigna.com (Postfix) with ESMTPSA id 52AB7229861E; Fri, 29 Jul 2016 10:23:36 -0300 (BRT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) Subject: Re: ipfw divert filter for IPv4 geo-blocking From: "Dr. Rolf Jansen" In-Reply-To: Date: Fri, 29 Jul 2016 10:23:35 -0300 Cc: Julian Elischer Content-Transfer-Encoding: quoted-printable Message-Id: <9222BB10-C700-4DE7-83A3-BE7A38A11713@obsigna.com> References: <61DFB3E2-6E34-4EEA-8AC6-70094CEACA72@cyclaero.com> <4D047727-F7D0-4BEE-BD42-2501F44C9550@obsigna.com> <9641D08A-0501-4AA2-9DF6-D5AFE6CB2975@obsigna.com> <4d76a492-17ae-cbff-f92f-5bbbb1339aad@freebsd.org> <677900fb-c717-743f-fcfe-86b603466e33@freebsd.org> <0D3C9016-7A4A-46BA-B35F-3844D07562A8@obsigna.com> <1E1DB7E0-D354-4D7A-B657-0ECF94C12CE0@obsigna.com> <50d405a4-3f8f-a706-9cac-d1162925e56a@freebsd.org> To: freebsd-ipfw@freebsd.org X-Mailer: Apple Mail (2.3124) X-BeenThere: freebsd-ipfw@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: IPFW Technical Discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Jul 2016 13:23:44 -0000 > Am 29.07.2016 um 06:50 schrieb Julian Elischer : > On 29/07/2016 5:22 PM, Julian Elischer wrote: >> On 29/07/2016 4:53 PM, Dr. Rolf Jansen wrote: >>>> Am 28.07.2016 um 23:48 schrieb Lee Brown : >>>>=20 >>>> That makes sense to me. Your /20 range encompasses 201.222.16.0 - >>>> 201.222.31.255. >>>> If you want 201.222.20.0-201.222.31.255, you'll need 3 ranges: >>>>=20 >>>> 201.222.20.0/22 (201.222.20.0-201.222.23.255) >>>> 201.222.24.0/22 (201.222.24.0-201.222.27.255) >>>> 201.222.28.0/22 (201.222.28.0-201.222.31.255) >>>=20 >>> Ian, Julian and Lee, >>>=20 >>> Thank you vary much for your responses. In order not bloat the = thread, I answer only to one message. >>>=20 >>> I found the problem. As a matter of fact, the respective IP ranges = in the LACNIC delegation statistics file are 3 adjacent blocks with 1024 = addresses, i.e. those that you listed in your message above: >>>=20 >>> $grep 201.222.2 /usr/local/etc/ipdb/IPRanges/lacnic.dat >>> lacnic|BR|ipv4|201.222.20.0|1024|20140710|allocated|164725 >>> lacnic|BR|ipv4|201.222.24.0|1024|20140630|allocated|138376 >>> lacnic|BR|ipv4|201.222.28.0|1024|20140701|allocated|129095 >>>=20 >>> However, my database compilation combines adjacent blocks with the = same country code, and the ranges above turn into one block of 3072 = addresses, which obviously doesn't have a valid netmask - log(3072) =3D = 11,5849625. >>> ... >>> ..., it is not sufficient to forget about optimization but I need to = check also whether, the delegation files contain already some non-CIDR = ranges, which need to be broken down. >>=20 >> there is code to take ranges and produce cidr sets. >>=20 >> We used to have exactly that code in the appletalk code before we = took it out. Appletalk uses ranges. >> = https://svnweb.freebsd.org/base/release/3.2.0/sys/netatalk/at_control.c?vi= ew=3Dannotate#l703=20 >=20 > though htat uassumes input in the form af an appletak sockaddr.. > there is also this python module > = https://pythonhosted.org/netaddr/tutorial_01.html#support-for-non-standard= -address-ranges >=20 >> maybe you can find other versions on the net. >> however if you fully populate the table, you will get the correct = result because more specific entries will >> override less specific entries. To do that you would have to have a = way to describe to your program what >> value each table entry should output. >> If you did what you do now, then you would specify the value for the = required countries, and give a default falue for "all others". >> aggregation of adjacent ranges with same value would be an = optimisation. Don't worry, breaking down an arbitrary IP-range into a CIDR conforming = set of ranges, doesn't seem too difficult. I quickly hacked into the = for() loop for table generation in geoip.c a nested do while() for if = necessary breaking down the given range: for (i =3D 0; i < n; i++) { if (!*ccList || findCC(CCTable, sortedIPSets[i][2])) { ipv4_lo =3D sortedIPSets[i][0]; do { m =3D intlb(sortedIPSets[i][1] - ipv4_lo + 1); while (ipv4_lo % (k =3D (int)lround(exp2(m)))) m--; printRange(ipv4_lo, 32 - m, table_number, table_value); = =20 } while ((ipv4_lo +=3D k) < sortedIPSets[i][1]); } } This seems to work as expected, however, I need to check this more = carefully (in the course of the weekend) until pushing it to GitHub. At = the first glance, the tables become quite large. For example, the table = for Brazil of 824 joined entries is bloated to 6621 CIDR records. Once I came to a conclusion, I will post it to this mailing list. Best regards Rolf