fix CIDR notation for Peer IPs
This commit is contained in:
parent
dfd617273b
commit
5477a321b2
22
add.go
22
add.go
@ -3,14 +3,13 @@ package dsnet
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"net"
|
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const wgQuickPeerConf = `[Interface]
|
const wgQuickPeerConf = `[Interface]
|
||||||
Address={{ .Peer.IP }}/22
|
Address={{ .Peer.IP }}/{{ .CidrSize }}
|
||||||
Address={{ .Peer.IP6 }}/64
|
Address={{ .Peer.IP6 }}/{{ .CidrSize6 }}
|
||||||
PrivateKey={{ .Peer.PrivateKey.Key }}
|
PrivateKey={{ .Peer.PrivateKey.Key }}
|
||||||
{{- if .DsnetConfig.DNS }}
|
{{- if .DsnetConfig.DNS }}
|
||||||
DNS={{ .DsnetConfig.DNS }}
|
DNS={{ .DsnetConfig.DNS }}
|
||||||
@ -38,7 +37,8 @@ AllowedIPs={{ . }}
|
|||||||
|
|
||||||
// TODO use random wg0-wg999 to hopefully avoid conflict by default?
|
// TODO use random wg0-wg999 to hopefully avoid conflict by default?
|
||||||
const vyattaPeerConf = `configure
|
const vyattaPeerConf = `configure
|
||||||
set interfaces wireguard wg0 address {{ .Peer.IP }}/{{ .Cidrmask }}
|
set interfaces wireguard wg0 address {{ .Peer.IP }}/{{ .CidrSize }}
|
||||||
|
set interfaces wireguard wg0 address {{ .Peer.IP6 }}/{{ .CidrSize6 }}
|
||||||
set interfaces wireguard wg0 route-allowed-ips true
|
set interfaces wireguard wg0 route-allowed-ips true
|
||||||
set interfaces wireguard wg0 private-key {{ .Peer.PrivateKey.Key }}
|
set interfaces wireguard wg0 private-key {{ .Peer.PrivateKey.Key }}
|
||||||
set interfaces wireguard wg0 description {{ conf.InterfaceName }}
|
set interfaces wireguard wg0 description {{ conf.InterfaceName }}
|
||||||
@ -135,22 +135,16 @@ func PrintPeerCfg(peer PeerConfig, conf *DsnetConfig) {
|
|||||||
ExitFail("Unrecognised DSNET_OUTPUT type")
|
ExitFail("Unrecognised DSNET_OUTPUT type")
|
||||||
}
|
}
|
||||||
|
|
||||||
cidrmask, _ := conf.Network.IPNet.Mask.Size()
|
cidrSize, _ := conf.Network.IPNet.Mask.Size()
|
||||||
|
cidrSize6, _ := conf.Network6.IPNet.Mask.Size()
|
||||||
|
|
||||||
t := template.Must(template.New("peerConf").Parse(peerConf))
|
t := template.Must(template.New("peerConf").Parse(peerConf))
|
||||||
err := t.Execute(os.Stdout, map[string]interface{}{
|
err := t.Execute(os.Stdout, map[string]interface{}{
|
||||||
"Peer": peer,
|
"Peer": peer,
|
||||||
"DsnetConfig": conf,
|
"DsnetConfig": conf,
|
||||||
"Keepalive": time.Duration(KEEPALIVE).Seconds(),
|
"Keepalive": time.Duration(KEEPALIVE).Seconds(),
|
||||||
"Cidrmask": cidrmask,
|
"CidrSize": cidrSize,
|
||||||
"Address": net.IPNet{
|
"CidrSize6": cidrSize6,
|
||||||
IP: peer.IP,
|
|
||||||
Mask: conf.Network.IPNet.Mask,
|
|
||||||
},
|
|
||||||
"Address6": net.IPNet{
|
|
||||||
IP: peer.IP6,
|
|
||||||
Mask: conf.Network6.IPNet.Mask,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
check(err)
|
check(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user