From 189f142fae25451e9e418155d462eab871e515a8 Mon Sep 17 00:00:00 2001 From: Alexey Khit Date: Thu, 20 Jul 2023 21:51:55 +0300 Subject: [PATCH] Restore IPv6 support for API and RTSP #532 --- internal/api/api.go | 13 +++++++------ internal/rtsp/rtsp.go | 4 ++-- internal/srtp/srtp.go | 5 +++-- internal/webrtc/webrtc.go | 2 +- pkg/bubble/client.go | 2 +- pkg/rtsp/client_test.go | 7 ++++--- 6 files changed, 18 insertions(+), 15 deletions(-) diff --git a/internal/api/api.go b/internal/api/api.go index 540f0f6d..a14cb28e 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -4,14 +4,15 @@ import ( "crypto/tls" "encoding/json" "fmt" - "github.com/AlexxIT/go2rtc/internal/app" - "github.com/rs/zerolog" "net" "net/http" "os" "strconv" "strings" "sync" + + "github.com/AlexxIT/go2rtc/internal/app" + "github.com/rs/zerolog" ) func Init() { @@ -30,7 +31,7 @@ func Init() { } // default config - cfg.Mod.Listen = ":1984" + cfg.Mod.Listen = "0.0.0.0:1984" // load config from YAML app.LoadConfig(&cfg) @@ -49,7 +50,7 @@ func Init() { HandleFunc("api/exit", exitHandler) // ensure we can listen without errors - listener, err := net.Listen("tcp4", cfg.Mod.Listen) + listener, err := net.Listen("tcp", cfg.Mod.Listen) if err != nil { log.Fatal().Err(err).Msg("[api] listen") return @@ -87,7 +88,7 @@ func Init() { return } - tlsListener, err := net.Listen("tcp4", cfg.Mod.TLSListen) + tlsListener, err := net.Listen("tcp", cfg.Mod.TLSListen) if err != nil { log.Fatal().Err(err).Caller().Send() return @@ -169,7 +170,7 @@ func middlewareLog(next http.Handler) http.Handler { func middlewareAuth(username, password string, next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if !strings.HasPrefix(r.RemoteAddr, "127.") { + if !strings.HasPrefix(r.RemoteAddr, "127.") && !strings.HasPrefix(r.RemoteAddr, "[::1]") { user, pass, ok := r.BasicAuth() if !ok || user != username || pass != password { w.Header().Set("Www-Authenticate", `Basic realm="go2rtc"`) diff --git a/internal/rtsp/rtsp.go b/internal/rtsp/rtsp.go index 9d9c3cb5..14372200 100644 --- a/internal/rtsp/rtsp.go +++ b/internal/rtsp/rtsp.go @@ -26,7 +26,7 @@ func Init() { } // default config - conf.Mod.Listen = ":8554" + conf.Mod.Listen = "0.0.0.0:8554" conf.Mod.DefaultQuery = "video&audio" app.LoadConfig(&conf) @@ -45,7 +45,7 @@ func Init() { return } - ln, err := net.Listen("tcp4", address) + ln, err := net.Listen("tcp", address) if err != nil { log.Error().Err(err).Msg("[rtsp] listen") return diff --git a/internal/srtp/srtp.go b/internal/srtp/srtp.go index 6cb2b546..90b8e145 100644 --- a/internal/srtp/srtp.go +++ b/internal/srtp/srtp.go @@ -1,9 +1,10 @@ package srtp import ( + "net" + "github.com/AlexxIT/go2rtc/internal/app" "github.com/AlexxIT/go2rtc/pkg/srtp" - "net" ) func Init() { @@ -14,7 +15,7 @@ func Init() { } // default config - cfg.Mod.Listen = ":8443" + cfg.Mod.Listen = "0.0.0.0:8443" // load config from YAML app.LoadConfig(&cfg) diff --git a/internal/webrtc/webrtc.go b/internal/webrtc/webrtc.go index ed74ebbb..d488a818 100644 --- a/internal/webrtc/webrtc.go +++ b/internal/webrtc/webrtc.go @@ -23,7 +23,7 @@ func Init() { } `yaml:"webrtc"` } - cfg.Mod.Listen = ":8555/tcp" + cfg.Mod.Listen = "0.0.0.0:8555/tcp" cfg.Mod.IceServers = []pion.ICEServer{ {URLs: []string{"stun:stun.l.google.com:19302"}}, } diff --git a/pkg/bubble/client.go b/pkg/bubble/client.go index bbd0a489..0dec2b30 100644 --- a/pkg/bubble/client.go +++ b/pkg/bubble/client.go @@ -62,7 +62,7 @@ func (c *Client) Dial() (err error) { return } - if c.conn, err = net.DialTimeout("tcp4", u.Host, Timeout); err != nil { + if c.conn, err = net.DialTimeout("tcp", u.Host, Timeout); err != nil { return } diff --git a/pkg/rtsp/client_test.go b/pkg/rtsp/client_test.go index ea7c3b44..5d714a55 100644 --- a/pkg/rtsp/client_test.go +++ b/pkg/rtsp/client_test.go @@ -1,17 +1,18 @@ package rtsp import ( - "github.com/stretchr/testify/require" "net" "os" "testing" "time" + + "github.com/stretchr/testify/require" ) func TestTimeout(t *testing.T) { Timeout = time.Millisecond - ln, err := net.Listen("tcp4", "localhost:0") + ln, err := net.Listen("tcp", "localhost:0") require.Nil(t, err) client := NewClient("rtsp://" + ln.Addr().String() + "/stream") @@ -27,7 +28,7 @@ func TestTimeout(t *testing.T) { func TestMissedControl(t *testing.T) { Timeout = time.Millisecond - ln, err := net.Listen("tcp4", "localhost:0") + ln, err := net.Listen("tcp", "localhost:0") require.Nil(t, err) go func() {