Some work adding a peer to a device
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -8,6 +8,9 @@
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
# main binary
|
||||
wgenroll
|
||||
|
||||
# Test binary, built with `go test -c`
|
||||
*.test
|
||||
|
||||
|
||||
15
wgenroll.go
15
wgenroll.go
@@ -2,10 +2,15 @@ package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net"
|
||||
|
||||
"golang.zx2c4.com/wireguard/wgctrl"
|
||||
"golang.zx2c4.com/wireguard/wgtypes"
|
||||
)
|
||||
|
||||
// TODO: replace this with a config value
|
||||
const deviceName = "wg0"
|
||||
|
||||
func main() {
|
||||
client, err := wgctrl.New()
|
||||
defer client.Close()
|
||||
@@ -17,3 +22,13 @@ func main() {
|
||||
log.Println(client.Devices())
|
||||
|
||||
}
|
||||
|
||||
func addPeer(client *wgctrl.Client, deviceName string, key wgtypes.Key) error {
|
||||
// TODO: load from config
|
||||
_, allowedNetwork, _ := net.ParseCIDR("172.16.0.1/20")
|
||||
allowedIps := []net.IPNet{allowedNetwork}
|
||||
peer := wgtypes.PeerConfig{Key: key, AllowedIPs: allowedIps}
|
||||
|
||||
config := wgtypes.Config{Peers: []PeerConfig{peer}, ReplacePeers: false}
|
||||
return client.ConfigureDevice(name, config)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user