Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 12 Mar 2020 10:54:13 -0700
From:      Gleb Smirnoff <glebius@freebsd.org>
To:        Dimitry Andric <dim@freebsd.org>
Cc:        Slawa Olhovchenkov <slw@zxy.spb.ru>, svn-src-head <svn-src-head@freebsd.org>, svn-src-all <svn-src-all@freebsd.org>, src-committers@freebsd.org
Subject:   Re: svn commit: r358655 - head/sbin/mount_nfs
Message-ID:  <20200312175413.GI55834@FreeBSD.org>
In-Reply-To: <CAD43B77-A0F0-45BA-BB24-2FEFA154A436@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> <CAD43B77-A0F0-45BA-BB24-2FEFA154A436@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20200312175413.GI55834>