mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-12-07 11:28:05 +00:00
proxy: add a multiplexing server frontend
On a Hyper-V system we can only register one listening endpoint (with a GUID), so we need to accept connections, read a header and then start the proxy. If the binary has argv[0] == "proxy-vsockd" then run this new frontend. Signed-off-by: David Scott <dave.scott@docker.com>
This commit is contained in:
@@ -35,10 +35,10 @@ func NewTCPProxy(listener net.Listener, backendAddr *net.TCPAddr) (*TCPProxy, er
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (proxy *TCPProxy) clientLoop(client Conn, quit chan bool) {
|
||||
backend, err := net.DialTCP("tcp", nil, proxy.backendAddr)
|
||||
func HandleTCPConnection(client Conn, backendAddr *net.TCPAddr, quit chan bool) {
|
||||
backend, err := net.DialTCP("tcp", nil, backendAddr)
|
||||
if err != nil {
|
||||
logrus.Printf("Can't forward traffic to backend tcp/%v: %s\n", proxy.backendAddr, err)
|
||||
logrus.Printf("Can't forward traffic to backend tcp/%v: %s\n", backendAddr, err)
|
||||
client.Close()
|
||||
return
|
||||
}
|
||||
@@ -89,7 +89,7 @@ func (proxy *TCPProxy) Run() {
|
||||
logrus.Printf("Stopping proxy on tcp/%v for tcp/%v (%s)", proxy.frontendAddr, proxy.backendAddr, err)
|
||||
return
|
||||
}
|
||||
go proxy.clientLoop(client.(Conn), quit)
|
||||
go HandleTCPConnection(client.(Conn), proxy.backendAddr, quit)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,6 +75,19 @@ func (u *udpEncapsulator) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewUDPConn(conn net.Conn) udpListener {
|
||||
var m sync.Mutex
|
||||
var r sync.Mutex
|
||||
var w sync.Mutex
|
||||
return &udpEncapsulator{
|
||||
conn: &conn,
|
||||
listener: nil,
|
||||
m: &m,
|
||||
r: &r,
|
||||
w: &w,
|
||||
}
|
||||
}
|
||||
|
||||
func NewUDPListener(listener net.Listener) udpListener {
|
||||
var m sync.Mutex
|
||||
var r sync.Mutex
|
||||
|
||||
Reference in New Issue
Block a user