diff --git a/cmd/root.go b/cmd/root.go index 7cc90bf..1f6654a 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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") } }, diff --git a/wgquick/wg.go b/wgquick/wg.go index d22bf2c..d1a3cd7 100644 --- a/wgquick/wg.go +++ b/wgquick/wg.go @@ -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 }