separate internal/external IP

This commit is contained in:
Callan Bryant 2020-03-02 21:02:21 +00:00
parent e02a1552e9
commit c4cb15c45e
No known key found for this signature in database
GPG Key ID: C31FA9DF3ACBFFAA
3 changed files with 15 additions and 15 deletions

1
add.go
View File

@ -33,7 +33,6 @@ func Add(hostname string, owner string, description string) { //, publicKey stri
conf.MustSave()
}
func GetPeerWgQuickConf(peer PeerConfig, privKey JSONKey) string {
return `[Interface]
Address = 10.50.60.2/24

View File

@ -22,8 +22,8 @@ func Init() {
}
IP := conf.MustAllocateIP()
conf.IP = IP
conf.DNS = IP
conf.InternalIP = IP
conf.InternalDNS = IP
conf.MustSave()

View File

@ -55,9 +55,10 @@ type DsnetConfig struct {
// IP network from which to allocate automatic sequential addresses
// Network is chosen randomly when not specified
Network JSONIPNet `validate:"required"`
IP net.IP `validate:"required,cidr"`
Port int `validate:"gte=1024,lte=65535"`
DNS net.IP `validate:"required,cidr"`
ExternalIP net.IP `validate:"required,cidr"`
ExternalPort int `validate:"gte=1024,lte=65535"`
InternalIP net.IP `validate:"required,cidr"`
InternalDNS net.IP `validate:"required,cidr"`
// TODO Default subnets to route via VPN
ReportFile string `validate:"required"`
PrivateKey JSONKey `validate:"required,len=44"`
@ -99,7 +100,7 @@ func (conf *DsnetConfig) MustAddPeer(peer PeerConfig) {
}
func (conf DsnetConfig) IPAllocated(IP net.IP) bool {
if IP.Equal(conf.IP) {
if IP.Equal(conf.InternalIP) {
return true
}
@ -132,7 +133,7 @@ func (conf DsnetConfig) MustAllocateIP() net.IP {
IP[j] = IP[j] | byte(i>>shift)
}
if ! conf.IPAllocated(IP) {
if !conf.IPAllocated(IP) {
return IP
}
}