fix lookup of v6: do not require

This commit is contained in:
Callan Bryant 2020-10-26 17:58:15 +00:00
parent d58b2f5a54
commit f57fa3473d
No known key found for this signature in database
GPG Key ID: C31FA9DF3ACBFFAA
3 changed files with 30 additions and 18 deletions

21
add.go
View File

@ -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,

View File

@ -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"`

19
init.go
View File

@ -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,14 +123,15 @@ 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 {
body, err := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
check(err) check(err)
IP = net.ParseIP(strings.TrimSpace(string(body))) IP = net.ParseIP(strings.TrimSpace(string(body)))
return IP return IP
}
} }
return net.IP{} return net.IP{}