From owner-svn-src-all@freebsd.org Fri Apr 21 09:26:54 2017 Return-Path: Delivered-To: svn-src-all@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 D386DD47044; Fri, 21 Apr 2017 09:26:54 +0000 (UTC) (envelope-from hps@selasky.org) Received: from mail.turbocat.net (turbocat.net [IPv6:2a01:4f8:c17:6c4b::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7FC82FAC; Fri, 21 Apr 2017 09:26:54 +0000 (UTC) (envelope-from hps@selasky.org) Received: from hps2016.home.selasky.org (unknown [62.141.129.119]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.turbocat.net (Postfix) with ESMTPSA id 7ABBF1FE022; Fri, 21 Apr 2017 11:26:52 +0200 (CEST) Subject: Re: svn commit: r317208 - head/sys/netinet To: Bruce Evans , Michael Tuexen References: <201704210143.v3L1h99s037727@slippy.cwsent.com> <20170421131041.G966@besplex.bde.org> <8BBC38A0-DDBA-4C04-9654-98755B3E4E13@freebsd.org> <20170421173453.J1735@besplex.bde.org> Cc: Cy Schubert , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org From: Hans Petter Selasky Message-ID: <1920616c-1993-07d5-4855-73264dce0980@selasky.org> Date: Fri, 21 Apr 2017 11:25:02 +0200 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: <20170421173453.J1735@besplex.bde.org> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Apr 2017 09:26:54 -0000 On 04/21/17 10:10, Bruce Evans wrote: > On Fri, 21 Apr 2017, Michael Tuexen wrote: > >>> On 21. Apr 2017, at 05:16, Bruce Evans wrote: >>> >>> On Thu, 20 Apr 2017, Cy Schubert wrote: >>> >>> Please trim quotes. >>> >>>> In message <201704201919.v3KJJYko052651@repo.freebsd.org>, Michael >>>> Tuexen >>>> write >>>> s: >>> >>> [>> ... 5 lines trimmed] >>> >>>>> Log: >>>>> Syncoockies can be used in combination with the syncache. If the >>>>> cache >>>>> overflows, syncookies are used. >>> >>> [>> ... 16 lines trimmed] >>> >>>>> Modified: head/sys/netinet/tcp_syncache.c >>>>> ============================================================================= >>>>> >>>>> = >>>>> --- head/sys/netinet/tcp_syncache.c Thu Apr 20 19:14:52 2017 >>>>> (r31720 >>>>> 7) >>>>> +++ head/sys/netinet/tcp_syncache.c Thu Apr 20 19:19:33 2017 >>>>> (r31720 >>>>> 8) >>>>> @@ -260,6 +260,7 @@ syncache_init(void) >>>>> &V_tcp_syncache.hashbase[i].sch_mtx, 0); >>>>> V_tcp_syncache.hashbase[i].sch_length = 0; >>>>> V_tcp_syncache.hashbase[i].sch_sc = &V_tcp_syncache; >>>>> + V_tcp_syncache.hashbase[i].sch_last_overflow = INT64_MIN; >>>> ... >>>> This line produced the following on i386: >>>> >>>> /opt/src/svn-current/sys/netinet/tcp_syncache.c:263:50: error: implicit >>>> conversion from 'long long' to 'time_t' (aka 'int') changes value from >>>> -9223372036854775808 to 0 [-Werror,-Wconstant-conversion] >>>> V_tcp_syncache.hashbase[i].sch_last_overflow = INT64_MIN; >>>> ~ ^~~~~~~~~ >>>> ./x86/_stdint.h:91:41: note: expanded from macro 'INT64_MIN' >>>> #define INT64_MIN (-0x7fffffffffffffffLL-1) >>>> ~~~~~~~~~~~~~~~~~~~~~^~ >>>> >>>> Looks like it needs a time_t cast. >>> >>> A cast would just break the warning. INT64_MIN has nothing to do with >>> time_t. The expression (time_t)INT64_MIN would be more obviously >>> garbage >>> since in the above it is not clear that sch_last_overflow has a type >>> unrelated to the constant. >> Fixed in https://svnweb.freebsd.org/changeset/base/317244 >>> >>> INT64_MIN is also broken if time_t is 64 bits but unsigned. Then it is >>> converted to half of plus infinity instead of the intended minus >>> infinity. >> The patch assumes that time_t is signed, which is true for FreeBSD on all >> platforms. Or am I missing a platform? > > Only future platforms. > > i386 should use time_t = uint32_t to fully support years 2038-2106 instead > of time_t = int32_t to partially support years 1902-1970 > (even time 0 (the Epoch) and other early hours in 1970 are not fully > supported now and would be broken by unsigned time_t, since subtraction > of the timezone offset from 0 gives negative values with signed time_t > and overflowing values with unsigned time_t). (time_t)-1 is special, > so the time 1 second before the Epoch cannot work with signed time_t. > This value works better with unsigned time_t because it is not in the > middle of the range, but times before the Epoch are just unrepresentable > with unsigned time_t. > > Changing the signedness of time_t would break the ABI less than changing > its size, but it still causes problems with buggy software which assumes > that time_t is signed or encodes special values in it. Negative times > are at best unspecified by POSIX. They give a large range of magic out > of band values below 0, provided nothing assumes that the system is better > designed than POSIX so supports times before the Epoch. Even the Standard > C library is not that bad, except POSIX forces a bad design for time_t so > mktime() and friends are restricted to times. If time_t is unsigned, > then no times before the Epoch can work, and if it is signed then times > before > the Epoch are unportable. > > netinet could use non-negative times far in the past as out-of-band > values if there are any. But it mostly uses monotonic times. The > Epoch for monotonic times starts at boot time (modulo other bugs), so > there are not enough times far enough in the past shortly after booting. > If time_t is unsigned, there just aren't enough, and if it is signed > there are only enough by using unportable negative times. Hi, Your proposal to change time_t to unsigned type is potentially dangerous in combination with NTP, where negative time deltas may occur. Consider existing code like this, both in three and outside the tree. static time_t last; time_t now = time(); time_t delta delta = now - last; if (delta > 0) { /* do something */ } else { /* ignore */ } If time_t is now unsigned, then the check above becomes true for alomost all values of time_t, except zero, which is wrong! Can C-compilers assert signedness of a variable? I propose, utime_t -> unsigned time and stime_t -> signed time. --HPS