Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 28 Oct 2002 23:07:37 -0800 (PST)
From:      Kelly Yancey <kelly@nttmcl.com>
To:        freebsd-arch@freebsd.org
Subject:   RFC: Exporting number of bytes of protocol data to userland
Message-ID:  <20021028230434.U91753-200000@alicia.nttmcl.com>

next in thread | raw e-mail | index | archive | help
  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.
  Send mail to mime@docserver.cac.washington.edu for more info.

--0-34758017-1035866312=:87083
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
Content-ID: <20021028230434.O91753@alicia.nttmcl.com>


  The attached patch is rather short so the impatient can probably skip
right to the source.

  The background is that there are at least 3 interfaces which report the
"number of bytes in the socket buffer" to userland:
	ioctl(s, FIONREAD, &len)
	stat(2) via the st_size member of struct stat
	kqueue(2) via data member of struct kevents returned for
		EVFILT_READ filters.

  The problem is that the number of bytes in a receive socket buffer is a
trivial piece of information at best.  Since there is no way for an
application to determine how much of that data is non-protocol data (i.e.
OOB, control, etc), it cannot use the number of anything: all of the
kernel interfaces for reading from a socket buffer take the number of
bytes of *protocol data* as their length parameter (actually, this is a
slight exageration: TCP does well since OOB data is handled differently
than OSI protocols).
  PR 30634 touches on this issue; UDP sockets are particularly visible
examples since they always include 16 bytes of address information in
addition to the datagram received.

  The attached patch adds an additional member to the sockbuf structure to
track the amount of non-protocol data in the buffer so that interfaces can
account for that before reporting to userland.  The patch also updates
stat(2) and kqueue(2) to report the number of bytes of protocol data
rather than the total number of bytes of all data in the socket buffer.
While ioctl(s, FIONREAD, &len) is also a candidate, I didn't dare touch it
because it is an old, well-documented interface.  But the point is that
there needs to be at least one interface which reports a value to userland
that it can actually use.
  As alluded to above, TCP sockets should be unaffected because they have
no non-protocol data in the socket buffer so the majority of socket-using
applications won't notice the change at all.  However, UDP sockets and
non-IP sockets will benefit from knowing how much readable data is
available.

  A version of this patch has been floating around -net for over a week
now with no comments but since it slightly changes API semantics I thought
it best to give it another round of review on -arch before committing.

  Thanks,

  Kelly

--
Kelly Yancey -- kbyanc@{posi.net,FreeBSD.org} -- kelly@nttmcl.com

--0-34758017-1035866312=:87083
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII; NAME="sb_ctl.diff"
Content-Transfer-Encoding: BASE64
Content-ID: <20021028203832.K87083@alicia.nttmcl.com>
Content-Description: 
Content-Disposition: ATTACHMENT; FILENAME="sb_ctl.diff"

SW5kZXg6IGxpYi9saWJjL3N5cy9rcXVldWUuMg0KPT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PQ0KUkNTIGZpbGU6IC9ob21lL25jdnMvc3JjL2xpYi9saWJjL3N5
cy9rcXVldWUuMix2DQpyZXRyaWV2aW5nIHJldmlzaW9uIDEuMjgNCmRpZmYg
LXUgLXAgLXUgLXIxLjI4IGtxdWV1ZS4yDQotLS0gbGliL2xpYmMvc3lzL2tx
dWV1ZS4yCTIgSnVsIDIwMDIgMjE6MDQ6MDAgLTAwMDAJMS4yOA0KKysrIGxp
Yi9saWJjL3N5cy9rcXVldWUuMgkyOSBPY3QgMjAwMiAwMzo0MjowMyAtMDAw
MA0KQEAgLTIyNiw3ICsyMjYsNyBAQCBhbmQgc3BlY2lmeWluZyB0aGUgbmV3
IGxvdyB3YXRlciBtYXJrIGluDQogLlZhIGRhdGEgLg0KIE9uIHJldHVybiwN
CiAuVmEgZGF0YQ0KLWNvbnRhaW5zIHRoZSBudW1iZXIgb2YgYnl0ZXMgaW4g
dGhlIHNvY2tldCBidWZmZXIuDQorY29udGFpbnMgdGhlIG51bWJlciBvZiBi
eXRlcyBvZiBwcm90b2NvbCBkYXRhIGF2YWlsYWJsZSB0byByZWFkLg0KIC5Q
cA0KIElmIHRoZSByZWFkIGRpcmVjdGlvbiBvZiB0aGUgc29ja2V0IGhhcyBz
aHV0ZG93biwgdGhlbiB0aGUgZmlsdGVyDQogYWxzbyBzZXRzIEVWX0VPRiBp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zOCw4IEBAIHN0cnVjdCB4c29ja2V0IHsNCiAvKiBhZGp1c3Qg
Y291bnRlcnMgaW4gc2IgcmVmbGVjdGluZyBmcmVlaW5nIG9mIG0gKi8NCiAj
ZGVmaW5lCXNiZnJlZShzYiwgbSkgeyBcDQogCShzYiktPnNiX2NjIC09ICht
KS0+bV9sZW47IFwNCisJaWYgKChtKS0+bV90eXBlICE9IE1UX0RBVEEpIFwN
CisJCShzYiktPnNiX2N0bCAtPSAobSktPm1fbGVuOyBcDQogCShzYiktPnNi
X21iY250IC09IE1TSVpFOyBcDQogCWlmICgobSktPm1fZmxhZ3MgJiBNX0VY
VCkgXA0KIAkJKHNiKS0+c2JfbWJjbnQgLT0gKG0pLT5tX2V4dC5leHRfc2l6
ZTsgXA0K
--0-34758017-1035866312=:87083--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




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