support additional networks
This commit is contained in:
parent
cf467c346b
commit
d250f2b23b
11
add.go
11
add.go
@ -3,6 +3,7 @@ package dsnet
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -49,6 +50,13 @@ func Add() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func PrintPeerCfg(peer PeerConfig, conf *DsnetConfig) {
|
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]
|
const peerConf = `[Interface]
|
||||||
Address = {{ .Peer.IP }}
|
Address = {{ .Peer.IP }}
|
||||||
PrivateKey={{ .Peer.PrivateKey.Key }}
|
PrivateKey={{ .Peer.PrivateKey.Key }}
|
||||||
@ -58,7 +66,7 @@ DNS = {{ .DsnetConfig.DNS }}
|
|||||||
PublicKey={{ .DsnetConfig.PrivateKey.PublicKey.Key }}
|
PublicKey={{ .DsnetConfig.PrivateKey.PublicKey.Key }}
|
||||||
PresharedKey={{ .Peer.PresharedKey.Key }}
|
PresharedKey={{ .Peer.PresharedKey.Key }}
|
||||||
Endpoint={{ .DsnetConfig.ExternalIP }}:{{ .DsnetConfig.ListenPort }}
|
Endpoint={{ .DsnetConfig.ExternalIP }}:{{ .DsnetConfig.ListenPort }}
|
||||||
AllowedIPs={{ .DsnetConfig.Network }}
|
AllowedIPs={{ .AllowedIPs }}
|
||||||
PersistentKeepalive={{ .Keepalive }}
|
PersistentKeepalive={{ .Keepalive }}
|
||||||
`
|
`
|
||||||
|
|
||||||
@ -67,6 +75,7 @@ PersistentKeepalive={{ .Keepalive }}
|
|||||||
"Peer": peer,
|
"Peer": peer,
|
||||||
"DsnetConfig": conf,
|
"DsnetConfig": conf,
|
||||||
"Keepalive": time.Duration(KEEPALIVE).Seconds(),
|
"Keepalive": time.Duration(KEEPALIVE).Seconds(),
|
||||||
|
"AllowedIPs": strings.Join(allowedIPsStr, ","),
|
||||||
})
|
})
|
||||||
check(err)
|
check(err)
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,8 @@ type DsnetConfig struct {
|
|||||||
ReportFile string `validate:"required"`
|
ReportFile string `validate:"required"`
|
||||||
PrivateKey JSONKey `validate:"required,len=44"`
|
PrivateKey JSONKey `validate:"required,len=44"`
|
||||||
Peers []PeerConfig `validate:"dive"`
|
Peers []PeerConfig `validate:"dive"`
|
||||||
|
// extra networks available, will be added to AllowedIPs
|
||||||
|
Networks []JSONIPNet `validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func MustLoadDsnetConfig() *DsnetConfig {
|
func MustLoadDsnetConfig() *DsnetConfig {
|
||||||
|
1
init.go
1
init.go
@ -27,6 +27,7 @@ func Init() {
|
|||||||
ReportFile: DEFAULT_REPORT_FILE,
|
ReportFile: DEFAULT_REPORT_FILE,
|
||||||
ExternalIP: getExternalIP(),
|
ExternalIP: getExternalIP(),
|
||||||
InterfaceName: DEFAULT_INTERFACE_NAME,
|
InterfaceName: DEFAULT_INTERFACE_NAME,
|
||||||
|
Networks: []JSONIPNet{},
|
||||||
}
|
}
|
||||||
|
|
||||||
IP := conf.MustAllocateIP()
|
IP := conf.MustAllocateIP()
|
||||||
|
Loading…
Reference in New Issue
Block a user