Date: Wed, 18 Oct 2023 14:11:43 -0700 From: Yuri <yuri@FreeBSD.org> To: "freebsd-net@freebsd.org" <freebsd-net@freebsd.org> Subject: Write into the route socket fails for unclear reason Message-ID: <3c68b45e-94a8-4f23-dc8a-cdfbb7d3d749@tsoft.com>
next in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
Hi,
I am troubleshooting the problem that the write call into the routing
socket fails with EINVAL.
The file descriptor is created like this:
fd = socket(PF_ROUTE, SOCK_RAW, 0);
Then the write is performed for this socket, that fails with errno=EINVAL:
write(fd, buf, 168);
buf has these bytes:
0: a8 00 05 04 00 00 00 00 00 04 00 00 01 00 00 00
16: 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00
32: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
48: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
64: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
96: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
112: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
128: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
144: 00 00 00 00 00 00 00 00|10 02 00 00 c0 a8 05 01
160: 00 00 00 00 00 00 00 00
Based on the code, the first 152 bytes represent 'struct rt_msghdr'.
It is followed with 16 bytes of 'struct sockaddr_in' representing the IP
address 192.168.5.1.
The file descriptor is valid at the moment of the write call. The
structures above looks fine.
Why does the write call fail then?
Can anybody figure this out without the need to rebuild the kernel?
Thanks,
Yuri
[-- Attachment #2 --]
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<p><font face="monospace">Hi,</font></p>
<p><font face="monospace"><br>
</font></p>
<p><font face="monospace">I am troubleshooting the problem that the
write call into the routing socket fails with EINVAL.</font></p>
<p><font face="monospace"><br>
</font></p>
<p><font face="monospace">The file descriptor is created like this:</font></p>
<p><font face="monospace">fd = socket(PF_ROUTE, SOCK_RAW, 0);</font></p>
<p><font face="monospace"><br>
</font></p>
<p><font face="monospace">Then the write is performed for this
socket, that fails with errno=EINVAL:</font></p>
<p><font face="monospace">write(fd, buf, 168);</font></p>
<p><font face="monospace">buf has these bytes:<br>
</font></p>
<p><font face="monospace">0: a8 00 05 04 00 00 00 00 00 04 00 00
01 00 00 00
<br>
16: 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00
<br>
32: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
<br>
48: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
<br>
64: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
<br>
80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
<br>
96: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
<br>
112: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
<br>
128: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
<br>
144: 00 00 00 00 00 00 00 00|10 02 00 00 c0 a8 05 01
<br>
160: 00 00 00 00 00 00 00 00<br>
</font>
<font face="monospace"><br>
</font></p>
<p><font face="monospace">Based on the code, the first 152 bytes
represent 'struct rt_msghdr'.</font></p>
<p><font face="monospace">It is followed with 16 bytes of 'struct
sockaddr_in' representing the IP address 192.168.5.1.</font></p>
<p><font face="monospace"><br>
</font></p>
<p><font face="monospace">The file descriptor is valid at the moment
of the write call. The structures above looks fine.</font></p>
<p><font face="monospace"><br>
</font></p>
<p><font face="monospace">Why does the write call fail then?</font></p>
<p><font face="monospace"><br>
</font></p>
<p><font face="monospace">Can anybody figure this out without the
need to rebuild the kernel?</font></p>
<p><font face="monospace"><br>
</font></p>
<p><font face="monospace"><br>
</font></p>
<p><font face="monospace">Thanks,</font></p>
<p><font face="monospace">Yuri<br>
</font></p>
<p><span style="font-family:monospace"><br>
</span></p>
</body>
</html>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3c68b45e-94a8-4f23-dc8a-cdfbb7d3d749>
