Skip to content

Commit

Permalink
down command removes wireguard-go sock to stop process
Browse files Browse the repository at this point in the history
  • Loading branch information
xsteadfastx committed Apr 14, 2021
1 parent 57bcab7 commit 4c295e7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
},
Expand Down
12 changes: 10 additions & 2 deletions wgquick/wg.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// nolint: errorlint, cyclop
// nolint:errorlint,cyclop
package wgquick

import (
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 4c295e7

Please sign in to comment.