mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-10-30 08:50:48 +01:00
fix(util): ignore loopback source for outbound TCP dials
A loopback bind address can never originate connections to non-loopback targets, so recording it pinned every outbound dial (e.g. to a remote master) to an unreachable source.
This commit is contained in:
1 parent
717966a656
commit
d8b725d607
2 files changed
+6
-3
No files matched your search
@@ -20,8 +20,9 @@ var (
|
||||
)
|
||||
|
||||
// SetOutboundLocalIP records ip as the source address for outbound TCP
|
||||
// connections. An empty, wildcard (0.0.0.0 / ::), or unparseable value leaves
|
||||
// the source address to the OS.
|
||||
// connections. An empty, wildcard (0.0.0.0 / ::), loopback, or unparseable
|
||||
// value leaves the source address to the OS. A loopback source can only
|
||||
// originate connections to loopback targets, which already skip binding.
|
||||
//
|
||||
// The first call wins. `weed server` applies the top-level -ip.bind before its
|
||||
// embedded master/volume/filer/s3/... start, so a component's own (possibly
|
||||
@@ -32,7 +33,7 @@ func SetOutboundLocalIP(ip string) {
|
||||
return
|
||||
}
|
||||
parsed := net.ParseIP(ip)
|
||||
if parsed == nil || parsed.IsUnspecified() {
|
||||
if parsed == nil || parsed.IsUnspecified() || parsed.IsLoopback() {
|
||||
return
|
||||
}
|
||||
outboundLocalAddr.Store(&net.TCPAddr{IP: parsed})
|
||||
|
||||
@@ -24,6 +24,8 @@ func TestSetOutboundLocalIP(t *testing.T) {
|
||||
{"empty", "", ""},
|
||||
{"wildcard v4", "0.0.0.0", ""},
|
||||
{"wildcard v6", "::", ""},
|
||||
{"loopback v4", "127.0.0.2", ""},
|
||||
{"loopback v6", "::1", ""},
|
||||
{"garbage", "not-an-ip", ""},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
|
||||
Reference in new issue
Block a user