fix: ipv6-only mode compatibility fixes (#23031)

Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
Jian Qiu
2025-08-06 22:02:08 +08:00
committed by GitHub
co-authored by Qiu Jian
parent 634bdf7b90
commit d0ec6885d6
32 changed files with 249 additions and 113 deletions
+2 -1
View File
@@ -20,6 +20,7 @@ import (
"io"
"net"
"net/http"
"strconv"
"time"
"github.com/gorilla/websocket"
@@ -102,7 +103,7 @@ func (s *WebsocketServer) initWs(w http.ResponseWriter, r *http.Request) error {
}
var err error
addr := fmt.Sprintf("%s:%d", s.Host, s.Port)
addr := net.JoinHostPort(s.Host, strconv.Itoa(s.Port))
s.conn, s.sshNetConn, err = NewSshClient("tcp", addr, config)
if err != nil {
return errors.Wrapf(err, "dial %s", addr)
+5 -1
View File
@@ -19,9 +19,11 @@ import (
"fmt"
"net"
"net/http"
"strconv"
"github.com/gorilla/websocket"
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/onecloud/pkg/webconsole/session"
@@ -69,7 +71,7 @@ func (s *WebsockifyServer) isBase64Subprotocol(wsConn *websocket.Conn) bool {
}
func (s *WebsockifyServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
targetAddr := fmt.Sprintf("%s:%d", s.TargetHost, s.TargetPort)
log.Debugf("ServeHTTP: %s, %s", r.URL.String(), jsonutils.Marshal(r.Header))
wsConn, err := upgrader.Upgrade(w, r, nil)
if err != nil {
log.Errorf("New websocket connection error: %v", err)
@@ -77,6 +79,7 @@ func (s *WebsockifyServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
log.Debugf("Get coordinate subprotocol: %s", wsConn.Subprotocol())
targetAddr := net.JoinHostPort(s.TargetHost, strconv.Itoa(int(s.TargetPort)))
log.Debugf("Handle websocket connect, target: %s", targetAddr)
targetConn, err := net.Dial("tcp", targetAddr)
if err != nil {
@@ -89,6 +92,7 @@ func (s *WebsockifyServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
func (s *WebsockifyServer) doProxy(wsConn *websocket.Conn, tcpConn net.Conn) {
log.Infof("doProxy bewteen ws: %s <--> tcp: %s", wsConn.RemoteAddr(), tcpConn.RemoteAddr())
s.Session.RegisterDuplicateHook(func() {
wsConn.Close()
tcpConn.Close()