Use LatestHandshake to validate endpoint (#149)

* wireguard: `wg show iface dump` reader and parser

* mesh: use LatestHandshake to validate NAT Endpoints

* add skip on error

* switch to loop parsing

So the stop on error pattern can be used

* Add error handling to ParseDump
This commit is contained in:
Julien Viard de Galbert
2021-07-06 14:14:59 +02:00
committed by GitHub
parent 0733c83a0a
commit e12b5029d7
4 changed files with 278 additions and 48 deletions

View File

@@ -119,3 +119,15 @@ func ShowConf(iface string) ([]byte, error) {
}
return stdout.Bytes(), nil
}
// ShowDump gets the WireGuard configuration and runtime information for the given interface.
func ShowDump(iface string) ([]byte, error) {
cmd := exec.Command("wg", "show", iface, "dump")
var stderr, stdout bytes.Buffer
cmd.Stderr = &stderr
cmd.Stdout = &stdout
if err := cmd.Run(); err != nil {
return nil, fmt.Errorf("failed to read the WireGuard dump output: %s", stderr.String())
}
return stdout.Bytes(), nil
}