tech-net archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: sendmsg(2) with IP_PKTINFO



On 08/12/2017 05:46, Ryo Shimizu wrote:
I implemented IP_PKTINFO for sendmsg(2). For recvmsg(2) IP_PKTINFO is already
supported, but it is not supported for sending. This causes problems
described in https://mail-index.netbsd.org/tech-net/2013/09/22/msg004252.html

patch is here.
       http://www.netbsd.org/~ryo/ip_pktinfo.patch
    or https://github.com/ryo/netbsd-src/compare/master...ip_pktinfo

+				/* Checking laddr:port already in use? */
+				xinp = in_pcblookup_bind(&udbtable,
+				    laddr.sin_addr, inp->inp_lport);
+				if ((xinp != NULL) && (xinp != inp)) {
+					error = EADDRINUSE;
+					goto release;
+				}
+				break;

Why is this check needed and why is it UDP specific?

In dhcpcd's case it's already bound the local address the socket and the
kernel then claims the address is already in use which is wrong.

I thought that it should fail with EADDRINUSE if sendmsg with IP_PKTINFO
using address:port same as already bound on other socket.

Certainly, this behavior is different from IP6_PKTINFO and linux.
Should I fix to be able to PKTINFO with address:port that another socket bound?

Yes please!

Consider this use case:
https://roy.marples.name/git/dhcpcd.git/tree/src/dhcp.c#n1687
I am only using IP_PKTINFO to set the outbound interface, not influence any address.

As things stand the kernel check noted above returns EADDRINUSE.
If I either remove the kernel check OR disable IP_PKTINFO in dhcpcd then the message is sent.

To make the code easier to read, I bind to the unspecified address:BOOTPC so that ICMP unreachable messages are not sent by the kernel during DHCP init. This socket is kept open for the lifetime of dhcpcd and just drained down.

When dhcpcd needs to unicast to the DHCP server, it opens another socket, binds DHCPADDRESS:BOOTPC and then sends. This works fine without IP_PKTINFO and I would like to use IP_PKTINFO just to force the outbound interface. We're not actively listening on this socket, just sending. My expectation is that this should work.

Can you fix this please?

Roy


Home | Main Index | Thread Index | Old Index