down command removes wireguard-go sock to stop process
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Marvin Steadfast 2021-04-14 10:48:12 +02:00
parent 57bcab7996
commit 4c295e7654
2 changed files with 11 additions and 3 deletions

View File

@ -66,7 +66,7 @@ var downCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
c, log := loadConfig(args[0])
if err := wgquick.Down(c, iface, log); err != nil {
if err := wgquick.Down(c, iface, userspace, log); err != nil {
logrus.WithError(err).Errorln("cannot down interface")
}
},

View File

@ -1,4 +1,4 @@
// nolint: errorlint, cyclop
// nolint:errorlint,cyclop
package wgquick
import (
@ -83,7 +83,7 @@ func Up(cfg *Config, iface string, uspace bool, logger logrus.FieldLogger) error
}
// Down destroys the wg interface. Mostly equivalent to `wg-quick down iface`.
func Down(cfg *Config, iface string, logger logrus.FieldLogger) error {
func Down(cfg *Config, iface string, uspace bool, logger logrus.FieldLogger) error {
log := logger.WithField("iface", iface)
link, err := netlink.LinkByName(iface)
@ -119,6 +119,14 @@ func Down(cfg *Config, iface string, logger logrus.FieldLogger) error {
log.Infoln("applied post-down command")
}
// If using userland wireguard, the sock file indicates a running wireguard-go process.
// By removing it, it will close itself.
if uspace {
if err := os.Remove(fmt.Sprintf("/var/run/wireguard/%s.sock", iface)); err != nil {
return err
}
}
return nil
}