From owner-svn-src-head@freebsd.org Thu Mar 12 17:54:22 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 2BA55267112; Thu, 12 Mar 2020 17:54:22 +0000 (UTC) (envelope-from glebius@freebsd.org) Received: from cell.glebi.us (glebi.us [162.251.186.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "cell.glebi.us", Issuer "cell.glebi.us" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 48dc0F2BXwz4GKg; Thu, 12 Mar 2020 17:54:20 +0000 (UTC) (envelope-from glebius@freebsd.org) Received: from cell.glebi.us (localhost [127.0.0.1]) by cell.glebi.us (8.15.2/8.15.2) with ESMTPS id 02CHsFrV073231 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Thu, 12 Mar 2020 10:54:15 -0700 (PDT) (envelope-from glebius@freebsd.org) Received: (from glebius@localhost) by cell.glebi.us (8.15.2/8.15.2/Submit) id 02CHsDDB073230; Thu, 12 Mar 2020 10:54:13 -0700 (PDT) (envelope-from glebius@freebsd.org) X-Authentication-Warning: cell.glebi.us: glebius set sender to glebius@freebsd.org using -f Date: Thu, 12 Mar 2020 10:54:13 -0700 From: Gleb Smirnoff To: Dimitry Andric Cc: Slawa Olhovchenkov , svn-src-head , svn-src-all , src-committers@freebsd.org Subject: Re: svn commit: r358655 - head/sbin/mount_nfs Message-ID: <20200312175413.GI55834@FreeBSD.org> References: <202003042227.024MRGsW072613@repo.freebsd.org> <244e28ea-1217-cefc-354e-02ecb201637a@FreeBSD.org> <20200305163350.GU5741@FreeBSD.org> <20200305172454.GJ8028@zxy.spb.ru> <20200305173515.GK8028@zxy.spb.ru> <20200305174411.GV5741@FreeBSD.org> <1A13B93C-7D87-4210-AD3D-2B198C166CE1@FreeBSD.org> <20200305183041.GU8012@zxy.spb.ru> <20200305210114.GX5741@FreeBSD.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 48dc0F2BXwz4GKg X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-0.21 / 15.00]; local_wl_from(0.00)[freebsd.org]; NEURAL_HAM_LONG(-0.91)[-0.914,0]; NEURAL_SPAM_MEDIUM(0.70)[0.703,0]; ASN(0.00)[asn:27348, ipnet:162.251.186.0/24, country:US] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Mar 2020 17:54:22 -0000 On Thu, Mar 05, 2020 at 11:15:04PM +0100, Dimitry Andric wrote: D> > S> > Why don't just declare the buffer as: D> > S> > D> > S> > struct if_msghdr buf; D> > S> > D> > S> > and then do: D> > S> > D> > S> > nread = read(s, &buf, sizeof buf); D> > S> > D> > S> > ? You are never reading more than one if_msghdr anyway, and then there D> > S> > is no need to cast anything. D> > S> D> > S> My inspiration: route socket can return other messages (man 4 route) D> > D> > Yes, exactly. We don't know what size next datagram is going to be. D> D> Oh, in that case this code seems completely wrong. How do you know the D> full datagram will be delivered with one read() call? D> D> If it always is, then there is no need to read more than the size of D> struct if_msghdr, since you are not using any data beyond it. So in D> that case, you can suffice with read(..., sizeof(if_msghdr)). D> D> If the read() call will return partial results, you must repeatedly call D> it in a loop, until you either reach EOF, or have enough data. In that D> case, a buffer with the size of if_msghdr is also enough, since you D> never need to read beyond that. Sorry for delayed answer. The routing socket is a datagram socket, it isn't like TCP, it can't deliver partial datagrams. If we don't supply enough space for datagram that arrived, it won't be delivered. So the right solution is suppling plenty of space, but parse only part we are interested in. -- Gleb Smirnoff