Hi,
I am facing the following problem and I have made a workound, but it's
quite ugly, so I'd like your advice.
I have device that's listening on a UDP port, on both ipv4 and ipv6. The
socket is bound but as address the wildcard address is used and address
family AF_INET6 is used.
This works, both ipv4 and ipv6 packets are received and sent successfully.
The problems start when assigning a static ipv6 address. SLAAC is
enabled and the device receives a SLAAC address, just fine. But this is
not the address I want to use, I only use SLAAC/RA to receive the
router's address. The device should be reachable using a shorted
address, something like 1234:5678:9abc::1. So I add this static address
when the SLAAC address is set (there is a callback for that, no problems
there).
When requesting all ip addresses on the interface, all addresses are
listed: link-local, SLAAC and static. Perfectly fine.
Now here is the problem: when I send a UDP packet to the static address,
it's received and processed and the device sends a reply, but it's using
the SLAAC address instead of the static address (which was used for
sending the packet). As the client does a quasi-connect on the UDP
socket, the reply is not recognised and dropped.
My workaround has been to
- bind the socket on the device to the wildcard address (so it receives
both ipv4 and ipv6)
- when a packet needs to be send to a ipv6 client AND a static address
is used
* (re)bind the socket to the static ipv6 address
* do the send(to)
* (re)bind the socket to the wildcard address
This seems to work. But it's ugly as hell.
I see LWIP implements IP_PKTINFO, which would allow to retrieve and set
the local source address (using recvmsg/sendmsg, ancilliary data). But a
short glance on the source revealed that this is only implemented for ipv4.
I don't think raw sockets would work, if you register the IP protocol,
other (TCP/UDP) IP sockets won't get any connections, apparently.
Another option would be to create separate UDP sockets for ipv4 and ipv6
and bind them to their respective addresses. Also kind of ugly. I am not
sure that would even work using LWIP, when the port number is equal.
Or removing the SLAAC address after it has been added by the system...
But maybe that also removes the routing table entry.
So, please, any ideas?
_______________________________________________
lwip-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/lwip-users