From 4952c641b3a759a562f0664059738d32f63da876 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Wed, 28 Jun 2023 20:22:59 -0700 Subject: [PATCH] Fix regression when bind-address is not explicitly provided (#1837) when bind address is set to loopback, it would break RTC IP discovery. --- cmd/server/main.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index 5e93b7cd..1092bd53 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" "math/rand" + "net" "os" "os/signal" "runtime" @@ -204,15 +205,27 @@ func getConfig(c *cli.Context) (*config.Config, error) { conf.Keys = map[string]string{ "devkey": "secret", } + shouldMatchRTCIP := false // when dev mode and using shared keys, we'll bind to localhost by default if conf.BindAddresses == nil { conf.BindAddresses = []string{ "127.0.0.1", "::1", } + } else { + // if non-loopback addresses are provided, then we'll match RTC IP to bind address + // our IP discovery ignores loopback addresses + for _, addr := range conf.BindAddresses { + ip := net.ParseIP(addr) + if ip != nil && !ip.IsLoopback() { + shouldMatchRTCIP = true + } + } } - for _, bindAddr := range conf.BindAddresses { - conf.RTC.IPs.Includes = append(conf.RTC.IPs.Includes, bindAddr + "/24") + if shouldMatchRTCIP { + for _, bindAddr := range conf.BindAddresses { + conf.RTC.IPs.Includes = append(conf.RTC.IPs.Includes, bindAddr+"/24") + } } } }