use ExternalIP6 if ExternalIP not available

This commit is contained in:
Callan Bryant 2020-10-26 18:27:35 +00:00
parent 608dbf176f
commit 5a870dab60
No known key found for this signature in database
GPG Key ID: C31FA9DF3ACBFFAA
2 changed files with 5 additions and 1 deletions

4
add.go
View File

@ -19,7 +19,11 @@ DNS={{ .DsnetConfig.DNS }}
[Peer] [Peer]
PublicKey={{ .DsnetConfig.PrivateKey.PublicKey.Key }} PublicKey={{ .DsnetConfig.PrivateKey.PublicKey.Key }}
PresharedKey={{ .Peer.PresharedKey.Key }} PresharedKey={{ .Peer.PresharedKey.Key }}
{{ if gt (.DsnetConfig.ExternalIP | len) 0 -}}
Endpoint={{ .DsnetConfig.ExternalIP }}:{{ .DsnetConfig.ListenPort }} Endpoint={{ .DsnetConfig.ExternalIP }}:{{ .DsnetConfig.ListenPort }}
{{ else -}}
Endpoint={{ .DsnetConfig.ExternalIP6 }}:{{ .DsnetConfig.ListenPort }}
{{ end -}}
PersistentKeepalive={{ .Keepalive }} PersistentKeepalive={{ .Keepalive }}
{{ with .DsnetConfig.Network -}} {{ with .DsnetConfig.Network -}}
AllowedIPs={{ . }} AllowedIPs={{ . }}

View File

@ -36,7 +36,7 @@ type PeerConfig struct {
type DsnetConfig struct { type DsnetConfig struct {
// domain to append to hostnames. Relies on separate DNS server for // domain to append to hostnames. Relies on separate DNS server for
// resolution. Informational only. // resolution. Informational only.
ExternalIP net.IP `validate:"required"` ExternalIP net.IP
ExternalIP6 net.IP ExternalIP6 net.IP
ListenPort int `validate:"gte=1024,lte=65535"` ListenPort int `validate:"gte=1024,lte=65535"`
Domain string `validate:"required,gte=1,lte=255"` Domain string `validate:"required,gte=1,lte=255"`