fix lookup of v6: do not require
This commit is contained in:
parent
d58b2f5a54
commit
f57fa3473d
21
add.go
21
add.go
@ -21,9 +21,15 @@ PublicKey={{ .DsnetConfig.PrivateKey.PublicKey.Key }}
|
|||||||
PresharedKey={{ .Peer.PresharedKey.Key }}
|
PresharedKey={{ .Peer.PresharedKey.Key }}
|
||||||
Endpoint={{ .DsnetConfig.ExternalIP }}:{{ .DsnetConfig.ListenPort }}
|
Endpoint={{ .DsnetConfig.ExternalIP }}:{{ .DsnetConfig.ListenPort }}
|
||||||
PersistentKeepalive={{ .Keepalive }}
|
PersistentKeepalive={{ .Keepalive }}
|
||||||
{{ range .AllowedIPs -}}
|
{{ with .DsnetConfig.Network -}}
|
||||||
AllowedIPs={{ . }}
|
AllowedIPs={{ . }}
|
||||||
{{ end }}
|
{{ end -}}
|
||||||
|
{{ with .DsnetConfig.Network6 -}}
|
||||||
|
AllowedIPs={{ . }}
|
||||||
|
{{ end -}}
|
||||||
|
{{ range .DsnetConfig.Networks -}}
|
||||||
|
AllowedIPs={{ . }}
|
||||||
|
{{ end -}}
|
||||||
`
|
`
|
||||||
|
|
||||||
// TODO use random wg0-wg999 to hopefully avoid conflict by default?
|
// TODO use random wg0-wg999 to hopefully avoid conflict by default?
|
||||||
@ -39,9 +45,15 @@ set interfaces wireguard wg0 description {{ conf.InterfaceName }}
|
|||||||
set interfaces wireguard wg0 peer {{ .DsnetConfig.PrivateKey.PublicKey.Key }} endpoint {{ .DsnetConfig.ExternalIP }}:{{ .DsnetConfig.ListenPort }}
|
set interfaces wireguard wg0 peer {{ .DsnetConfig.PrivateKey.PublicKey.Key }} endpoint {{ .DsnetConfig.ExternalIP }}:{{ .DsnetConfig.ListenPort }}
|
||||||
set interfaces wireguard wg0 peer {{ .DsnetConfig.PrivateKey.PublicKey.Key }} persistent-keepalive {{ .Keepalive }}
|
set interfaces wireguard wg0 peer {{ .DsnetConfig.PrivateKey.PublicKey.Key }} persistent-keepalive {{ .Keepalive }}
|
||||||
set interfaces wireguard wg0 peer {{ .DsnetConfig.PrivateKey.PublicKey.Key }} preshared-key {{ .Peer.PresharedKey.Key }}
|
set interfaces wireguard wg0 peer {{ .DsnetConfig.PrivateKey.PublicKey.Key }} preshared-key {{ .Peer.PresharedKey.Key }}
|
||||||
{{ range .AllowedIPs -}}
|
{{ with .DsnetConfig.Network -}}
|
||||||
set interfaces wireguard wg0 peer {{ .DsnetConfig.PrivateKey.PublicKey.Key }} allowed-ips {{ . }}
|
set interfaces wireguard wg0 peer {{ .DsnetConfig.PrivateKey.PublicKey.Key }} allowed-ips {{ . }}
|
||||||
{{ end }}
|
{{ end -}}
|
||||||
|
{{ with .DsnetConfig.Network6 -}}
|
||||||
|
set interfaces wireguard wg0 peer {{ .DsnetConfig.PrivateKey.PublicKey.Key }} allowed-ips {{ . }}
|
||||||
|
{{ end -}}
|
||||||
|
{{ range .DsnetConfig.Networks -}}
|
||||||
|
set interfaces wireguard wg0 peer {{ .DsnetConfig.PrivateKey.PublicKey.Key }} allowed-ips {{ . }}
|
||||||
|
{{ end -}}
|
||||||
commit; save
|
commit; save
|
||||||
`
|
`
|
||||||
|
|
||||||
@ -122,7 +134,6 @@ func PrintPeerCfg(peer PeerConfig, conf *DsnetConfig) {
|
|||||||
"Peer": peer,
|
"Peer": peer,
|
||||||
"DsnetConfig": conf,
|
"DsnetConfig": conf,
|
||||||
"Keepalive": time.Duration(KEEPALIVE).Seconds(),
|
"Keepalive": time.Duration(KEEPALIVE).Seconds(),
|
||||||
"AllowedIPs": allowedIPs,
|
|
||||||
"Cidrmask": cidrmask,
|
"Cidrmask": cidrmask,
|
||||||
"Address": net.IPNet{
|
"Address": net.IPNet{
|
||||||
IP: peer.IP,
|
IP: peer.IP,
|
||||||
|
@ -21,8 +21,8 @@ type PeerConfig struct {
|
|||||||
// Description of what the host is and/or does
|
// Description of what the host is and/or does
|
||||||
Description string `validate:"required,gte=1,lte=255"`
|
Description string `validate:"required,gte=1,lte=255"`
|
||||||
// Internal VPN IP address. Added to AllowedIPs in server config as a /32
|
// Internal VPN IP address. Added to AllowedIPs in server config as a /32
|
||||||
IP net.IP `validate:"required`
|
IP net.IP
|
||||||
IP6 net.IP `validate:"required`
|
IP6 net.IP
|
||||||
Added time.Time `validate:"required"`
|
Added time.Time `validate:"required"`
|
||||||
// TODO ExternalIP support (Endpoint)
|
// TODO ExternalIP support (Endpoint)
|
||||||
//ExternalIP net.UDPAddr `validate:"required,udp4_addr"`
|
//ExternalIP net.UDPAddr `validate:"required,udp4_addr"`
|
||||||
@ -45,8 +45,8 @@ type DsnetConfig struct {
|
|||||||
// Network is chosen randomly when not specified
|
// Network is chosen randomly when not specified
|
||||||
Network JSONIPNet `validate:"required"`
|
Network JSONIPNet `validate:"required"`
|
||||||
Network6 JSONIPNet `validate:"required"`
|
Network6 JSONIPNet `validate:"required"`
|
||||||
IP net.IP `validate:"required"`
|
IP net.IP
|
||||||
IP6 net.IP `validate:"required"`
|
IP6 net.IP
|
||||||
DNS net.IP
|
DNS net.IP
|
||||||
// extra networks available, will be added to AllowedIPs
|
// extra networks available, will be added to AllowedIPs
|
||||||
Networks []JSONIPNet `validate:"required"`
|
Networks []JSONIPNet `validate:"required"`
|
||||||
|
7
init.go
7
init.go
@ -77,7 +77,7 @@ func getExternalIP() net.IP {
|
|||||||
// arbitrary external IP is used (one that's guaranteed to route outside.
|
// arbitrary external IP is used (one that's guaranteed to route outside.
|
||||||
// In this case, Google's DNS server. Doesn't actually need to be online.)
|
// In this case, Google's DNS server. Doesn't actually need to be online.)
|
||||||
conn, err := net.Dial("udp", "8.8.8.8:53")
|
conn, err := net.Dial("udp", "8.8.8.8:53")
|
||||||
if err != nil {
|
if err == nil {
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
localAddr := conn.LocalAddr().String()
|
localAddr := conn.LocalAddr().String()
|
||||||
@ -111,7 +111,7 @@ func getExternalIP() net.IP {
|
|||||||
func getExternalIP6() net.IP {
|
func getExternalIP6() net.IP {
|
||||||
var IP net.IP
|
var IP net.IP
|
||||||
conn, err := net.Dial("udp", "2001:4860:4860::8888:53")
|
conn, err := net.Dial("udp", "2001:4860:4860::8888:53")
|
||||||
if err != nil {
|
if err == nil {
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
localAddr := conn.LocalAddr().String()
|
localAddr := conn.LocalAddr().String()
|
||||||
@ -123,7 +123,7 @@ func getExternalIP6() net.IP {
|
|||||||
Timeout: 5 * time.Second,
|
Timeout: 5 * time.Second,
|
||||||
}
|
}
|
||||||
resp, err := client.Get("https://ipv6.icanhazip.com/")
|
resp, err := client.Get("https://ipv6.icanhazip.com/")
|
||||||
check(err)
|
if err == nil {
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode == http.StatusOK {
|
if resp.StatusCode == http.StatusOK {
|
||||||
@ -132,6 +132,7 @@ func getExternalIP6() net.IP {
|
|||||||
IP = net.ParseIP(strings.TrimSpace(string(body)))
|
IP = net.ParseIP(strings.TrimSpace(string(body)))
|
||||||
return IP
|
return IP
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return net.IP{}
|
return net.IP{}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user