private-octopus / picoquic

Minimal implementation of the QUIC protocol
MIT License
540 stars 159 forks source link

Fix source IP address when sending packets #1443

Closed muxamilian closed 1 year ago

muxamilian commented 1 year ago

I think that currently the source IP address is not set correctly on Linux. When having several network interfaces, in my experience, setting the source IP address has no effect and packets are sent with another source IP address, not the one specified.

My change seems to fix this problem. I tested it with some live machines with multiple network interfaces. I think my changed version is also consistent with the documentation of Linux's IP implementation.

If IP_PKTINFO is passed to sendmsg(2) and ipi_spec_dst is not zero, then it is used as the local source address for the routing table lookup and for setting up IP source route options. When ipi_ifindex is not zero, the primary local address of the interface specified by the index overwrites ipi_spec_dst for the routing table lookup.

I guess for IPv6 this isn't a problem as in6_pktinfo has only one IP address inside of it.

huitema commented 1 year ago

Thanks for doing this! I am traveling, will review this code tomorrow or Monday.