Repository: go
Issue: net: udp listener should use received ip address for sending
Labels: NeedsInvestigation

<!--
Please answer these questions before submitting your issue. Thanks!
For questions please use one of our forums: https://github.com/golang/go/wiki/Questions
-->

### What version of Go are you using (`go version`)?

<pre>
$ go version
go version go1.12.1 linux/amd64

</pre>

### Does this issue reproduce with the latest release?
Yes


### What operating system and processor architecture are you using (`go env`)?

<details><summary><code>go env</code> Output</summary><br><pre>
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/data/go_work"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build134300587=/tmp/go-build -gno-record-gcc-switches"
</pre></details>

### What did you do?

<!--
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
-->
At the very first time, we found that when I dig the backend dns server, which is written in go, we got an unexpect source alert, it seems that the reply came from another interface from the machine.
![image](https://user-images.githubusercontent.com/5792148/71864909-31b58580-313c-11ea-9b2a-58829b949605.png)

So I want to stimulate this issue with a tiny program like:
```go
package main
import (
    "fmt"
    "net"
)
func main() {
    listener, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("0.0.0.0"), Port: 9999})
    if err != nil {
        fmt.Println(err)
        return
    }
    fmt.Printf("Local: <%s> \n", listener.LocalAddr().String())
    data := make([]byte, 1024)
    for {
        n, remoteAddr, err := listener.ReadFromUDP(data)
        if err != nil {
            fmt.Printf("error during read: %s", err)
        }
        fmt.Printf("<%s> %s\n", remoteAddr, data[:n])
        _, err = listener.WriteToUDP([]byte("world"), remoteAddr)
        if err != nil {
            fmt.Printf(err.Error())
        }
    }
}
```
UDP server listen on (:9999 or 0.0.0.0:9999)
![image](https://user-images.githubusercontent.com/5792148/71865291-447c8a00-313d-11ea-9077-fccd18615260.png)


### What did you expect to see?
The machine we are gonna access is bound with multiple interface, i.e. it has eth0/eth1/tun0/tun1 etc.
so when the client get access to this service from eth0, it is expect that the reply must be sent from interface eth0.
![image](https://user-images.githubusercontent.com/5792148/71876804-9c79b780-3162-11ea-83e4-14a273a37dfe.png)


### What did you see instead?
![image](https://user-images.githubusercontent.com/5792148/71876860-be733a00-3162-11ea-8bf5-d043d9c9e66a.png)

Udp server local ip (multi)
x.x.52.207
x.x.56.205
x.x.78.207

client  (remote IP) :  x.x.218.174 

run tcpdump from udp server
![image](https://user-images.githubusercontent.com/5792148/71865340-67a73980-313d-11ea-820f-c22fa8cd946c.png)

as you can see, the server always reply from the default interface, the steps are as belows:
1. client(x.x.218.174) -> udp server(x.x.52.207)  got reply from udp server(x.x.52.207)
2. client(x.x.218.174) -> udp server(x.x.56.205)  got reply from udp server(x.x.52.207) 

TCP connections all work as expect except UDP connections.

However, when we test this scenario with Nginx, it works:

![image](https://user-images.githubusercontent.com/5792148/71865503-ed2ae980-313d-11ea-8646-da61f6fef8b0.png)

![image](https://user-images.githubusercontent.com/5792148/71865507-f2883400-313d-11ea-836c-b76611751d40.png)

![image](https://user-images.githubusercontent.com/5792148/71865516-f6b45180-313d-11ea-91fe-c95d7b4d1371.png)

As you can see it reply the client with the incoming interface instead of the default one.

Here is the simplified config:
```
# nginx listen on 0.0.0.0:9999
stream {

    upstream dns {
       server x.x.41.44:9999;
    }

    server {
        listen 9999 udp;
... ...
    }
}
```