mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-07-16 09:36:07 +00:00
fix(settings): detect a wildcard listen collision between the web and sub ports
The web/sub same-port check compared the two listen addresses as raw strings, so
binding both on all interfaces with different spellings (webListen 0.0.0.0 vs an
empty subListen) slipped past validation and only failed at startup with an
opaque bind error. Treat any wildcard listen ('', 0.0.0.0, ::) as overlapping so
the clash is reported up front, while still allowing two distinct specific
addresses to share a port.
This commit is contained in:
@@ -172,7 +172,7 @@ func (s *AllSetting) CheckValid() error {
|
||||
return common.NewError("Sub port is not a valid port:", s.SubPort)
|
||||
}
|
||||
|
||||
if (s.SubPort == s.WebPort) && (s.WebListen == s.SubListen) {
|
||||
if (s.SubPort == s.WebPort) && listenAddressesConflict(s.WebListen, s.SubListen) {
|
||||
return common.NewError("Sub and Web could not use same ip:port, ", s.SubListen, ":", s.SubPort, " & ", s.WebListen, ":", s.WebPort)
|
||||
}
|
||||
|
||||
@@ -258,6 +258,27 @@ func (s *AllSetting) CheckValid() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// listenAddressesConflict reports whether two listen addresses on the same port
|
||||
// would collide at bind time. A wildcard listen ("", "0.0.0.0", "::") overlaps
|
||||
// every address, so it conflicts with anything on that port; two specific
|
||||
// addresses conflict only when identical.
|
||||
func listenAddressesConflict(a, b string) bool {
|
||||
if a == b {
|
||||
return true
|
||||
}
|
||||
return isWildcardListen(a) || isWildcardListen(b)
|
||||
}
|
||||
|
||||
func isWildcardListen(listen string) bool {
|
||||
if listen == "" {
|
||||
return true
|
||||
}
|
||||
if ip := net.ParseIP(listen); ip != nil {
|
||||
return ip.IsUnspecified()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type HostGroup struct {
|
||||
GroupId string `json:"groupId"`
|
||||
InboundIds []int `json:"inboundIds" validate:"required,min=1"`
|
||||
|
||||
Reference in New Issue
Block a user