mirror of
https://github.com/muety/wakapi.git
synced 2025-12-05 22:20:24 -08:00
fix: gracefully handle ipv4-mapped addresses / dual-stack (resolve #860)
This commit is contained in:
17
main.go
17
main.go
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
"github.com/lpar/gzipped/v2"
|
||||
"github.com/muety/wakapi/utils"
|
||||
httpSwagger "github.com/swaggo/http-swagger"
|
||||
_ "gorm.io/driver/mysql"
|
||||
_ "gorm.io/driver/postgres"
|
||||
@@ -378,11 +379,15 @@ func listen(handler http.Handler) {
|
||||
}
|
||||
|
||||
if config.UseTLS() {
|
||||
if s4 != nil {
|
||||
if s4 != nil && !utils.IPv4HandledByDualStackHttp(s4, s6) { // https://github.com/muety/wakapi/issues/860
|
||||
slog.Info("👉 Listening for HTTPS... ✅", "address", s4.Addr)
|
||||
go func() {
|
||||
if err := s4.ListenAndServeTLS(config.Server.TlsCertPath, config.Server.TlsKeyPath); err != nil {
|
||||
conf.Log().Fatal(err.Error())
|
||||
err := err.Error()
|
||||
if s6 != nil {
|
||||
err += " - possibly a dual-stack problem (https://github.com/muety/wakapi/issues/860)?"
|
||||
}
|
||||
conf.Log().Fatal(err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
@@ -410,11 +415,15 @@ func listen(handler http.Handler) {
|
||||
}()
|
||||
}
|
||||
} else {
|
||||
if s4 != nil {
|
||||
if s4 != nil && !utils.IPv4HandledByDualStackHttp(s4, s6) { // https://github.com/muety/wakapi/issues/860
|
||||
slog.Info("👉 Listening for HTTP... ✅", "address", s4.Addr)
|
||||
go func() {
|
||||
if err := s4.ListenAndServe(); err != nil {
|
||||
conf.Log().Fatal(err.Error())
|
||||
err := err.Error()
|
||||
if s6 != nil {
|
||||
err += " - possibly a dual-stack problem (https://github.com/muety/wakapi/issues/860)?"
|
||||
}
|
||||
conf.Log().Fatal(err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
14
utils/net.go
Normal file
14
utils/net.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func IPv4HandledByDualStack(ip4, ip6 string) bool {
|
||||
return strings.HasPrefix(ip6, "[::]") && strings.HasPrefix(ip4, "0.0.0.0")
|
||||
}
|
||||
|
||||
func IPv4HandledByDualStackHttp(server4, server6 *http.Server) bool {
|
||||
return server4 == nil || (server6 != nil && IPv4HandledByDualStack(server4.Addr, server6.Addr))
|
||||
}
|
||||
Reference in New Issue
Block a user