diff --git a/.gitignore b/.gitignore index 3b735ec..b39751d 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,9 @@ *.so *.dylib +# main binary +wgenroll + # Test binary, built with `go test -c` *.test diff --git a/wgenroll.go b/wgenroll.go index 81a404a..25f32fd 100644 --- a/wgenroll.go +++ b/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) +}