Skip to content

Commit

Permalink
feat: use 127.0.0.1 as IPv4 if there's no external IPv4 addr
Browse files Browse the repository at this point in the history
Since commit 0bc0d3b ("feat: add vsock network type support
(dragonflyoss#1303)") we have vsock support, which means we could run dfget in a
constrained VM env that only has loopback net interface, and connect to
dfdaemon on host via vsock connection. So it's a valid setup to have no
external IPv4 addr.

Don't panic in this case and use "127.0.0.1" as IPv4.

Signed-off-by: Eryu Guan <[email protected]>
  • Loading branch information
eryugey committed May 31, 2022
1 parent a12ef5f commit 8c85455
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/util/net/iputils/ip_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,22 @@ import (
"sort"

"github.com/pkg/errors"
logger "d7y.io/dragonfly/v2/internal/dflog"
)

var IPv4 string

const internalIPv4 string = "127.0.0.1"

func init() {
ip, err := externalIPv4()
if err != nil {
panic(err)
logger.Warnf("Failed to get IPv4 address: %s", err.Error())
logger.Infof("Use %s as IPv4 addr", internalIPv4)
IPv4 = internalIPv4
} else {
IPv4 = ip
}

IPv4 = ip
}

// IsIPv4 returns whether the ip is a valid IPv4 Address.
Expand Down

0 comments on commit 8c85455

Please sign in to comment.