From owner-freebsd-net@FreeBSD.ORG Wed Oct 24 09:16:32 2012 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id BD241BCE; Wed, 24 Oct 2012 09:16:32 +0000 (UTC) (envelope-from simon@comsys.ntu-kpi.kiev.ua) Received: from comsys.kpi.ua (comsys.kpi.ua [77.47.192.42]) by mx1.freebsd.org (Postfix) with ESMTP id 66D6A8FC18; Wed, 24 Oct 2012 09:16:32 +0000 (UTC) Received: from pm513-1.comsys.kpi.ua ([10.18.52.101] helo=pm513-1.comsys.ntu-kpi.kiev.ua) by comsys.kpi.ua with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1TQwlT-0001Ww-Gn; Wed, 24 Oct 2012 11:56:39 +0300 Received: by pm513-1.comsys.ntu-kpi.kiev.ua (Postfix, from userid 1001) id 6213C1CC1E; Wed, 24 Oct 2012 11:56:37 +0300 (EEST) Date: Wed, 24 Oct 2012 11:56:37 +0300 From: Andrey Simonenko To: Adrian Chadd Subject: Re: kern/92880: [libc] [patch] almost rewritten inet_network(3) function Message-ID: <20121024085637.GA57899@pm513-1.comsys.ntu-kpi.kiev.ua> References: <201210230840.q9N8e038066538@freefall.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Authenticated-User: simon@comsys.ntu-kpi.kiev.ua X-Authenticator: plain X-Sender-Verify: SUCCEEDED (sender exists & accepts mail) X-Exim-Version: 4.63 (build at 28-Apr-2011 07:11:12) X-Date: 2012-10-24 11:56:39 X-Connected-IP: 10.18.52.101:51438 X-Message-Linecount: 200 X-Body-Linecount: 183 X-Message-Size: 8404 X-Body-Size: 7626 Cc: freebsd-net@freebsd.org X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Oct 2012 09:16:32 -0000 On Tue, Oct 23, 2012 at 10:37:56AM -0700, Adrian Chadd wrote: > ... don't suppose you want to throw this into a test case somewhere in the tree? > This was the bug-followup to my PR [1], that was created because I needed own version of inet_network() for another my PR [2] and found out that the current version of inet_network() has mistakes and is not optimal. This bug-followup has inet_network_new() that is a rewritten implementation of inet_network(). This message was sent to the net@ mailing list, since this PR was assigned to freebsd-net. > The new ATF import would be ideal for this. :) I have not checked how ATF works yet, but I wrote socket/unix_cmsg that verifies correctness of AF_LOCAL control messages implementation. It cannot be used on recent versions, because changes from PR [3] were not committed yet. What do you think about lines pointed by "<---" where inet_network() and my implementation gives different results? [1] http://www.freebsd.org/cgi/query-pr.cgi?pr=kern/92880 [2] http://www.freebsd.org/cgi/query-pr.cgi?pr=kern/136865 [3] http://www.freebsd.org/cgi/query-pr.cgi?pr=bin/131567 > > > > Adrian > > On 23 October 2012 01:40, Andrey Simonenko wrote: > > The following reply was made to PR kern/92880; it has been noted by GNATS. > > > > From: Andrey Simonenko > > To: bug-followup@FreeBSD.org > > Cc: > > Subject: kern/92880: [libc] [patch] almost rewritten inet_network(3) function > > Date: Tue, 23 Oct 2012 11:36:04 +0300 > > > > I optimized inet_network() again. > > > > Difference between implementation of inet_network(3) from 9.1-PRERELEASE > > and my implementation. > > > > STRING INET_NETWORK INET_NETWORK_NEW > > "0x12" 0x00000012 0x00000012 > > "127.1" 0x00007f01 0x00007f01 > > "127.1.2.3" 0x7f010203 0x7f010203 > > "0x123456" INADDR_NONE INADDR_NONE > > "0x12.0x34" 0x00001234 0x00001234 > > "0x12.0x345" INADDR_NONE INADDR_NONE > > "1.2.3.4.5" INADDR_NONE INADDR_NONE > > "1..3.4" INADDR_NONE INADDR_NONE > > "." INADDR_NONE INADDR_NONE > > "1." INADDR_NONE INADDR_NONE > > ".1" INADDR_NONE INADDR_NONE > > "0x" 0x00000000 INADDR_NONE <--- > > "0" 0x00000000 0x00000000 > > "01.02.07.077" 0x0102073f 0x0102073f > > "0x1.23.045.0" 0x01172500 0x01172500 > > "" INADDR_NONE INADDR_NONE > > " " INADDR_NONE INADDR_NONE > > " f" INADDR_NONE INADDR_NONE > > "bar" INADDR_NONE INADDR_NONE > > "1.2bar" INADDR_NONE INADDR_NONE > > "1." INADDR_NONE INADDR_NONE > > "=CA=C3=D5=CB=C5=CE" INADDR_NONE INADDR_NONE > > "255.255.255.255" INADDR_NONE INADDR_NONE > > "x" INADDR_NONE INADDR_NONE > > "0X12" 0x00000012 0x00000012 > > "078" INADDR_NONE INADDR_NONE > > "1 bar" 0x00000001 INADDR_NONE <--- > > "127.0xabcd" INADDR_NONE INADDR_NONE > > "128" 0x00000080 0x00000080 > > "0.1.2" 0x00000102 0x00000102 > > "0xff.010.23.0xa0" 0xff0817a0 0xff0817a0 > > "x10" 0x00000010 INADDR_NONE <--- > > "X20" 0x00000020 INADDR_NONE <--- > > "x10.x20" 0x00001020 INADDR_NONE <--- > > "4294967297" 0x00000001 INADDR_NONE <--- > > "0x10000000f" 0x0000000f INADDR_NONE <--- > > "040000000003" 0x00000003 INADDR_NONE <--- > > > > #include > > #include > > > > #include > > #include > > > > #include > > #include > > #include > > #include > > #include > > #include > > > > static in_addr_t > > inet_network_new(const char *s) > > { > > u_int d, base, dots; > > in_addr_t addr, byte; > > u_char c; > > bool flag; > > > > addr =3D 0; > > dots =3D 0; > > for (;; ++s) { > > byte =3D 0; > > flag =3D false; > > if (*s =3D=3D '0') { > > ++s; > > if (*s =3D=3D 'x' || *s =3D=3D 'X') { > > ++s; > > base =3D 16; > > } else { > > base =3D 8; > > flag =3D true; > > } > > } else > > base =3D 10; > > for (; (c =3D *s) !=3D '\0'; ++s) { > > d =3D digittoint(c); > > if (c !=3D '0' && (d =3D=3D 0 || d >=3D base)) > > break; > > byte =3D byte * base + d; > > if (byte > UINT8_MAX) > > return (INADDR_NONE); > > flag =3D true; > > } > > if (!flag) > > return (INADDR_NONE); > > addr =3D (addr << 8) | byte; > > if (c !=3D '.') > > break; > > if (++dots =3D=3D 4) > > return (INADDR_NONE); > > } > > return (c =3D=3D '\0' ? addr : INADDR_NONE); > > } > > > > int > > main(void) > > { > > const char *const addr_str_tbl[] =3D { > > "0x12", "127.1", "127.1.2.3", "0x123456", "0x12.0x34", > > "0x12.0x345", "1.2.3.4.5", "1..3.4", ".", "1.", ".1", "0x", > > "0", "01.02.07.077", "0x1.23.045.0", "", " ", " f", "bar", > > "1.2bar", "1.", "=CA=C3=D5=CB=C5=CE", "255.255.255.255", "x", "0X12"= > > , "078", > > "1 bar", "127.0xabcd", "128", "0.1.2", "0xff.010.23.0xa0", > > "x10", "X20", "x10.x20", "4294967297", "0x10000000f", > > "040000000003", NULL }; > > const char *const *addr_str; > > size_t len; > > in_addr_t addr1, addr2; > > > > printf("STRING\t\t\tINET_NETWORK\tINET_NETWORK_NEW\n"); > > for (addr_str =3D addr_str_tbl; *addr_str !=3D NULL; ++addr_str) { > > printf("\"%s\"", *addr_str); > > len =3D strlen(*addr_str) + 2; > > if (len < 8) > > printf("\t\t\t"); > > else if (len < 16) > > printf("\t\t"); > > else > > printf("\t"); > > addr1 =3D inet_network(*addr_str); > > if (addr1 =3D=3D INADDR_NONE) > > printf("INADDR_NONE\t"); > > else > > printf("0x%08x\t", addr1); > > addr2 =3D inet_network_new(*addr_str); > > if (addr2 =3D=3D INADDR_NONE) > > printf("INADDR_NONE"); > > else > > printf("0x%08x", addr2); > > if (addr1 !=3D addr2) > > printf("\t<---"); > > printf("\n"); > > } > > return (0); > > }