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.
This commit is contained in:
cinap_lenrek 2020-06-06 23:46:01 +02:00
parent 1a5dafcc3d
commit e46000f076
2 changed files with 6 additions and 2 deletions

View file

@ -552,7 +552,9 @@ rudpiput(Proto *rudp, Ipifc *ifc, Block *bp)
p = bp->rp; p = bp->rp;
ipmove(p, raddr); p += IPaddrlen; ipmove(p, raddr); p += IPaddrlen;
ipmove(p, laddr); 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, rport); p += 2;
hnputs(p, lport); hnputs(p, lport);
break; break;

View file

@ -471,7 +471,9 @@ udpiput(Proto *udp, Ipifc *ifc, Block *bp)
p = bp->rp; p = bp->rp;
ipmove(p, raddr); p += IPaddrlen; ipmove(p, raddr); p += IPaddrlen;
ipmove(p, laddr); 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, rport); p += 2;
hnputs(p, lport); hnputs(p, lport);
break; break;