support additional networks

This commit is contained in:
Callan Bryant 2020-03-08 20:48:10 +00:00
parent cf467c346b
commit d250f2b23b
No known key found for this signature in database
GPG Key ID: C31FA9DF3ACBFFAA
3 changed files with 13 additions and 1 deletions

11
add.go
View File

@ -3,6 +3,7 @@ package dsnet
import (
"fmt"
"os"
"strings"
"text/template"
"time"
)
@ -49,6 +50,13 @@ func Add() {
}
func PrintPeerCfg(peer PeerConfig, conf *DsnetConfig) {
allowedIPsStr := make([]string, len(conf.Networks)+1)
allowedIPsStr[0] = conf.Network.String()
for i, net := range conf.Networks {
allowedIPsStr[i+1] = net.String()
}
const peerConf = `[Interface]
Address = {{ .Peer.IP }}
PrivateKey={{ .Peer.PrivateKey.Key }}
@ -58,7 +66,7 @@ DNS = {{ .DsnetConfig.DNS }}
PublicKey={{ .DsnetConfig.PrivateKey.PublicKey.Key }}
PresharedKey={{ .Peer.PresharedKey.Key }}
Endpoint={{ .DsnetConfig.ExternalIP }}:{{ .DsnetConfig.ListenPort }}
AllowedIPs={{ .DsnetConfig.Network }}
AllowedIPs={{ .AllowedIPs }}
PersistentKeepalive={{ .Keepalive }}
`
@ -67,6 +75,7 @@ PersistentKeepalive={{ .Keepalive }}
"Peer": peer,
"DsnetConfig": conf,
"Keepalive": time.Duration(KEEPALIVE).Seconds(),
"AllowedIPs": strings.Join(allowedIPsStr, ","),
})
check(err)
}

View File

@ -45,6 +45,8 @@ type DsnetConfig struct {
ReportFile string `validate:"required"`
PrivateKey JSONKey `validate:"required,len=44"`
Peers []PeerConfig `validate:"dive"`
// extra networks available, will be added to AllowedIPs
Networks []JSONIPNet `validate:"required"`
}
func MustLoadDsnetConfig() *DsnetConfig {

View File

@ -27,6 +27,7 @@ func Init() {
ReportFile: DEFAULT_REPORT_FILE,
ExternalIP: getExternalIP(),
InterfaceName: DEFAULT_INTERFACE_NAME,
Networks: []JSONIPNet{},
}
IP := conf.MustAllocateIP()