Skip to content

Commit

Permalink
Merge pull request etcd-io#11845 from xiang90/tcp_proxy
Browse files Browse the repository at this point in the history
etcdmain: best effort detection of self pointing in tcp proxy
  • Loading branch information
gyuho committed May 31, 2020
2 parents b2d2286 + 16810cd commit 09fcf55
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions etcdmain/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,40 @@ func startGateway(cmd *cobra.Command, args []string) {
}
}

lhost, lport, err := net.SplitHostPort(gatewayListenAddr)
if err != nil {
fmt.Println("failed to validate listen address:", gatewayListenAddr)
os.Exit(1)
}

laddrs, err := net.LookupHost(lhost)
if err != nil {
fmt.Println("failed to resolve listen host:", lhost)
os.Exit(1)
}
laddrsMap := make(map[string]bool)
for _, addr := range laddrs {
laddrsMap[addr] = true
}

for _, srv := range srvs.SRVs {
eaddrs, err := net.LookupHost(srv.Target)
if err != nil {
fmt.Println("failed to resolve endpoint host:", srv.Target)
os.Exit(1)
}
if fmt.Sprintf("%d", srv.Port) != lport {
continue
}

for _, ea := range eaddrs {
if laddrsMap[ea] {
fmt.Printf("SRV or endpoint (%s:%d->%s:%d) should not resolve to the gateway listen addr (%s)\n", srv.Target, srv.Port, ea, srv.Port, gatewayListenAddr)
os.Exit(1)
}
}
}

if len(srvs.Endpoints) == 0 {
fmt.Println("no endpoints found")
os.Exit(1)
Expand Down

0 comments on commit 09fcf55

Please sign in to comment.