Some work adding a peer to a device

This commit is contained in:
2024-02-18 00:44:58 -08:00
parent 10fd07812c
commit 24b4e45eb7
2 changed files with 18 additions and 0 deletions

3
.gitignore vendored
View File

@@ -8,6 +8,9 @@
*.so
*.dylib
# main binary
wgenroll
# Test binary, built with `go test -c`
*.test

View File

@@ -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)
}