separate internal/external IP
This commit is contained in:
parent
e02a1552e9
commit
c4cb15c45e
1
add.go
1
add.go
@ -33,7 +33,6 @@ func Add(hostname string, owner string, description string) { //, publicKey stri
|
|||||||
conf.MustSave()
|
conf.MustSave()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func GetPeerWgQuickConf(peer PeerConfig, privKey JSONKey) string {
|
func GetPeerWgQuickConf(peer PeerConfig, privKey JSONKey) string {
|
||||||
return `[Interface]
|
return `[Interface]
|
||||||
Address = 10.50.60.2/24
|
Address = 10.50.60.2/24
|
||||||
|
4
init.go
4
init.go
@ -22,8 +22,8 @@ func Init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
IP := conf.MustAllocateIP()
|
IP := conf.MustAllocateIP()
|
||||||
conf.IP = IP
|
conf.InternalIP = IP
|
||||||
conf.DNS = IP
|
conf.InternalDNS = IP
|
||||||
|
|
||||||
conf.MustSave()
|
conf.MustSave()
|
||||||
|
|
||||||
|
25
types.go
25
types.go
@ -19,11 +19,11 @@ 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"`
|
||||||
|
|
||||||
PublicKey JSONKey `validate:"required,len=44"`
|
PublicKey JSONKey `validate:"required,len=44"`
|
||||||
PresharedKey JSONKey `validate:"required,len=44"`
|
PresharedKey JSONKey `validate:"required,len=44"`
|
||||||
// TODO endpoint support
|
// TODO endpoint support
|
||||||
//Endpoint net.UDPAddr `validate:"required,udp4_addr"`
|
//Endpoint net.UDPAddr `validate:"required,udp4_addr"`
|
||||||
AllowedIPs []JSONIPNet `validate:"dive,required,cidr"`
|
AllowedIPs []JSONIPNet `validate:"dive,required,cidr"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Peer struct {
|
type Peer struct {
|
||||||
@ -38,8 +38,8 @@ type Peer struct {
|
|||||||
// if no data for x days, consider revoking access
|
// if no data for x days, consider revoking access
|
||||||
Expired bool
|
Expired bool
|
||||||
|
|
||||||
PublicKey wgtypes.Key
|
PublicKey wgtypes.Key
|
||||||
PresharedKey wgtypes.Key
|
PresharedKey wgtypes.Key
|
||||||
// TODO peer endpoint support
|
// TODO peer endpoint support
|
||||||
//Endpoint *net.UDPAddr
|
//Endpoint *net.UDPAddr
|
||||||
LastHandshakeTime time.Time
|
LastHandshakeTime time.Time
|
||||||
@ -54,12 +54,13 @@ type DsnetConfig struct {
|
|||||||
Domain string `validate:"required,gte=1,lte=255"`
|
Domain string `validate:"required,gte=1,lte=255"`
|
||||||
// IP network from which to allocate automatic sequential addresses
|
// IP network from which to allocate automatic sequential addresses
|
||||||
// Network is chosen randomly when not specified
|
// Network is chosen randomly when not specified
|
||||||
Network JSONIPNet `validate:"required"`
|
Network JSONIPNet `validate:"required"`
|
||||||
IP net.IP `validate:"required,cidr"`
|
ExternalIP net.IP `validate:"required,cidr"`
|
||||||
Port int `validate:"gte=1024,lte=65535"`
|
ExternalPort int `validate:"gte=1024,lte=65535"`
|
||||||
DNS net.IP `validate:"required,cidr"`
|
InternalIP net.IP `validate:"required,cidr"`
|
||||||
|
InternalDNS net.IP `validate:"required,cidr"`
|
||||||
// TODO Default subnets to route via VPN
|
// TODO Default subnets to route via VPN
|
||||||
ReportFile string `validate:"required"`
|
ReportFile string `validate:"required"`
|
||||||
PrivateKey JSONKey `validate:"required,len=44"`
|
PrivateKey JSONKey `validate:"required,len=44"`
|
||||||
PresharedKey JSONKey `validate:"required,len=44"`
|
PresharedKey JSONKey `validate:"required,len=44"`
|
||||||
Peers []PeerConfig
|
Peers []PeerConfig
|
||||||
@ -99,7 +100,7 @@ func (conf *DsnetConfig) MustAddPeer(peer PeerConfig) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (conf DsnetConfig) IPAllocated(IP net.IP) bool {
|
func (conf DsnetConfig) IPAllocated(IP net.IP) bool {
|
||||||
if IP.Equal(conf.IP) {
|
if IP.Equal(conf.InternalIP) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +133,7 @@ func (conf DsnetConfig) MustAllocateIP() net.IP {
|
|||||||
IP[j] = IP[j] | byte(i>>shift)
|
IP[j] = IP[j] | byte(i>>shift)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ! conf.IPAllocated(IP) {
|
if !conf.IPAllocated(IP) {
|
||||||
return IP
|
return IP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user