diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2020-06-06 23:46:01 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2020-06-06 23:46:01 +0200 |
commit | e46000f076b3b5389b60f4497c8b40c203202d84 (patch) | |
tree | 9ad48351d1fe2dc262367a56bfd6a545cbfb3abe /sys/src/9/ip | |
parent | 1a5dafcc3d8c455b0e7b36dd9bd45c13dd4d91eb (diff) |
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.
Diffstat (limited to 'sys/src/9/ip')
-rw-r--r-- | sys/src/9/ip/rudp.c | 4 | ||||
-rw-r--r-- | sys/src/9/ip/udp.c | 4 |
2 files changed, 6 insertions, 2 deletions
diff --git a/sys/src/9/ip/rudp.c b/sys/src/9/ip/rudp.c index 9b6c96438..c374f6abc 100644 --- a/sys/src/9/ip/rudp.c +++ b/sys/src/9/ip/rudp.c @@ -552,7 +552,9 @@ rudpiput(Proto *rudp, Ipifc *ifc, Block *bp) 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; diff --git a/sys/src/9/ip/udp.c b/sys/src/9/ip/udp.c index 86205caec..5800c7e8c 100644 --- a/sys/src/9/ip/udp.c +++ b/sys/src/9/ip/udp.c @@ -471,7 +471,9 @@ udpiput(Proto *udp, Ipifc *ifc, Block *bp) 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; |