ref: 8aa5c0bc73861ee57955e1462fb853cb44d160d3
parent: 2f1b07a1985b040a8cd459273f1571631b1a2590
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Jun 6 19:46:01 EDT 2020
devip: pick less surprising interface address in header for incoming UDP packets We used to just return the first address of the incoming interface regardless of if the address matches the source ip type and scope. This change tries to find the best interface address that will match the source ip so it can be used as a source address when replying to the packet.
--- a/sys/src/9/ip/rudp.c
+++ b/sys/src/9/ip/rudp.c
@@ -552,7 +552,9 @@
p = bp->rp;
ipmove(p, raddr); p += IPaddrlen;
ipmove(p, laddr); p += IPaddrlen;
- ipmove(p, ifc->lifc->local); p += IPaddrlen;
+ if(!ipv6local(ifc, p, 0, raddr))
+ ipmove(p, ifc->lifc != nil ? ifc->lifc->local : IPnoaddr);
+ p += IPaddrlen;
hnputs(p, rport); p += 2;
hnputs(p, lport);
break;
--- a/sys/src/9/ip/udp.c
+++ b/sys/src/9/ip/udp.c
@@ -471,7 +471,9 @@
p = bp->rp;
ipmove(p, raddr); p += IPaddrlen;
ipmove(p, laddr); p += IPaddrlen;
- ipmove(p, ifc->lifc->local); p += IPaddrlen;
+ if(!ipv6local(ifc, p, 0, raddr))
+ ipmove(p, ifc->lifc != nil ? ifc->lifc->local : IPnoaddr);
+ p += IPaddrlen;
hnputs(p, rport); p += 2;
hnputs(p, lport);
break;
--
⑨