net: ReadMsg and reading error queue

570 views
Skip to first unread message

Robert

unread,
Feb 24, 2013, 11:15:53 AM2/24/13
to golang-nuts
Hello,

I want to read a socket's error queue and cannot find a way to do that
for an UDPConn.

I am trying to implement a traceroute-like utility in Go. In order to
do that I would like to open an UDP socket, send some packets, and
read the error queue of the socket. At least on Linux, the last is
achieved by recvmsg(MSG_ERRQUEUE) on a socket that had IP_RECVERR flag
set. There are two problems with this approach: UDPConn.ReadMsgUDP
doesn't allow one to pass flags to runtime.Recvmsg (it always passes
0) and I'm not sure if setting IP_RECVERR on a duplicate fd (returned
by UDPConn.File()) would have the desired effect.

I don't know if other operating systems implement a mechanism to
retrieve errors in some similar fashion (recvmsg(MSG_ERRQUEUE) isn't
in Posix and in fact, it doesn't seem to say anything about error
queues), but I'd assume it'd be significantly different.

It seems that in order to solve my problem on Linux without any
modifications to Go, I would need to use syscall package directly and
either do a lot of blocking syscalls or use a separate instance of
some kind of poll server. Would adding a way to call ReadMsg with
flags be reasonable?

Robert

Mikio Hara

unread,
Feb 27, 2013, 8:58:52 PM2/27/13
to Robert, golang-nuts
Hi,

On Mon, Feb 25, 2013 at 1:15 AM, Robert <rob...@gmail.com> wrote:

> It seems that in order to solve my problem on Linux without any
> modifications to Go, I would need to use syscall package directly and
> either do a lot of blocking syscalls or use a separate instance of
> some kind of poll server.

Yes, at least under the Go 1 contract.

> Would adding a way to call ReadMsg with flags be reasonable?

And WriteMsg too? Not sure, but Read/WriteMsgIP, UDP methods
are new API for Go 1.1. I think you can contribute a bugfix patch
until Go 1.1 cutoff if you think that's an API design bug.

Robert Obryk

unread,
Feb 28, 2013, 8:31:54 AM2/28/13
to Mikio Hara, golan...@googlegroups.com
+cc golang-dev
+bcc golang-nuts

Hello,

I would like to propose a change in the net package in the
{Read,Write}Msg* methods (they are to be new in Go1.1), so that they
allow flags to be passed in. As far as I know, the only way to read a
socket's error queue in Linux is to use recvmsg with MSG_ERRQUEUE flag
set. The {Read,Write}Msg methods don't allow flags to be passed in and
set them always to 0.

I propose that both ReadMsg* and WriteMsg* take an additional argument
for flags. This obviously exports system-specific flags out of the net
package, but we already do that in the other direction in these same
methods. ReadMsg should filter out MSG_WAITALL (because it seems
nonsensical or poorly defined for nonblocking operations); all other
flags from POSIX and Linux-specific ones seem not to interfere with
the assumptions related to the poll server or nonblocking behaviour. I
also propose that ReadMsgUnix set MSG_CMSG_CLOEXEC, for similar
reasons we set O_CLOEXEC in open() (although I'm not sure if that
shouldn't be the domain of someone who actually uses SCM_RIGHTS). For
WriteMsg* I didn't find any flags that would seem to interfere with
assumptions related to the poll server and nonblocking behaviour.

I will send a CL upon request; I didn't do it first because the
contributing guidelines strongly advise against that. This is a change
that, as far as I understand the backwards compatibility guarantees,
should be made before Go1.1 or not at all in the foreseeable future.

Robert

aman...@gmail.com

unread,
Jul 14, 2017, 9:01:25 AM7/14/17
to golang-nuts, mikioh...@gmail.com, golan...@googlegroups.com
I want to process the ICMP error and implement UDP PMTU discovery,  so I have to call recvmsg with MSG_ERRQUEUE

It has been 4 years, any reasonable solutions for this problem??

在 2013年2月28日星期四 UTC+8下午9:31:54,Robert写道:

Matt Harden

unread,
Jul 14, 2017, 9:40:38 PM7/14/17
to aman...@gmail.com, golang-nuts, mikioh...@gmail.com, golan...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Atela Wu

unread,
Jul 14, 2017, 11:38:35 PM7/14/17
to golang-nuts, aman...@gmail.com, mikioh...@gmail.com, golan...@googlegroups.com
I don't think this is the same thing.  after I send out a too big UDP and receive the ICMP need fragment error,  I can use MSG_ERRQUEUE flag to receive the mtu info from the same UDP socket.
the icmp package only works when you send out a icmp package.





在 2017年7月15日星期六 UTC+8上午9:40:38,Matt Harden写道:

mikioh...@gmail.com

unread,
Jul 18, 2017, 8:50:41 PM7/18/17
to golang-nuts
From go1.9, the {TCP,UDP,IP,Unix}Conn of net package satisfies the RawConn interface of syscall package. I think you can implement own platform dependent stuff by using the new exposed API.
Reply all
Reply to author
Forward
0 new messages