successful adding of peers!
This commit is contained in:
parent
deef2574e7
commit
e5dcbd8e35
@ -5,7 +5,9 @@ import (
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
@ -143,3 +145,29 @@ func (conf DsnetConfig) MustAllocateIP() net.IP {
|
||||
|
||||
return net.IP{}
|
||||
}
|
||||
|
||||
func (conf DsnetConfig) GetWgPeerConfigs() []wgtypes.PeerConfig {
|
||||
wgPeers := make([]wgtypes.PeerConfig, 0, len(conf.Peers))
|
||||
|
||||
interval := time.Second * KEEPALIVE_SECONDS;
|
||||
|
||||
for _, peer := range conf.Peers {
|
||||
wgPeers = append(wgPeers, wgtypes.PeerConfig{
|
||||
PublicKey: peer.PublicKey.Key,
|
||||
Remove: false,
|
||||
UpdateOnly: false,
|
||||
PresharedKey: &peer.PresharedKey.Key,
|
||||
Endpoint: nil,
|
||||
PersistentKeepaliveInterval: &interval,
|
||||
ReplaceAllowedIPs: true,
|
||||
AllowedIPs: []net.IPNet{
|
||||
net.IPNet{
|
||||
IP: peer.IP,
|
||||
Mask: conf.Network.IPNet.Mask,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return wgPeers
|
||||
}
|
||||
|
6
up.go
6
up.go
@ -39,15 +39,17 @@ func CreateInterface(conf *DsnetConfig) {
|
||||
ExitFail("Could not add addr %s to interface %s", addr.IP, err)
|
||||
}
|
||||
|
||||
deviceConfig := wgtypes.Config{
|
||||
wgConfig := wgtypes.Config{
|
||||
PrivateKey: &conf.PrivateKey.Key,
|
||||
ListenPort: &conf.ListenPort,
|
||||
ReplacePeers: true,
|
||||
Peers: conf.GetWgPeerConfigs(),
|
||||
}
|
||||
|
||||
wg, err := wgctrl.New()
|
||||
check(err)
|
||||
|
||||
err = wg.ConfigureDevice(linkAttrs.Name, deviceConfig)
|
||||
err = wg.ConfigureDevice(linkAttrs.Name, wgConfig)
|
||||
|
||||
if err != nil {
|
||||
ExitFail("Could not configure device '%s' (%v)", linkAttrs.Name, err)
|
||||
|
Loading…
Reference in New Issue
Block a user