diff --git a/cmd/version.go b/cmd/version.go index bddcb5e..2e2a0fe 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -12,7 +12,7 @@ var versionCmd = &cobra.Command{ Short: "Print the version number of wg-quick-op", Long: `All software has versions. This is wg-quick-op's`, Run: func(cmd *cobra.Command, args []string) { - fmt.Println("Wireguard Quick for Openwrt v0.0.5") + fmt.Println("Wireguard Quick for Openwrt v0.1.0") }, } diff --git a/quick/config.go b/quick/config.go index 17c7629..ce3f6c2 100644 --- a/quick/config.go +++ b/quick/config.go @@ -52,6 +52,9 @@ type Config struct { // SaveConfig — if set to ‘true’, the configuration is saved from the current state of the interface upon shutdown. // Currently unsupported SaveConfig bool + + // WireGuard-go binary path, left empty for kernel WireGuard + WgBin string } func newConfig() *Config { @@ -356,6 +359,8 @@ func parseInterfaceLine(cfg *Config, lhs string, rhs string) error { return fmt.Errorf("cannot decode key %v", err) } cfg.PrivateKey = &key + case "WgBin": + cfg.WgBin = rhs default: return fmt.Errorf("unknown directive %s", lhs) } diff --git a/quick/wg.go b/quick/wg.go index ee3f6cd..e4c2ef8 100644 --- a/quick/wg.go +++ b/quick/wg.go @@ -179,16 +179,26 @@ func SyncLink(cfg *Config, iface string, log logrus.FieldLogger) (netlink.Link, return nil, err } log.Info("link not found, creating") - wgLink := &netlink.GenericLink{ - LinkAttrs: netlink.LinkAttrs{ - Name: iface, - MTU: cfg.MTU, - }, - LinkType: "wireguard", - } - if err := netlink.LinkAdd(wgLink); err != nil { - log.WithError(err).Error("cannot create link") - return nil, err + + if cfg.WgBin == "" { + wgLink := &netlink.GenericLink{ + LinkAttrs: netlink.LinkAttrs{ + Name: iface, + MTU: cfg.MTU, + }, + LinkType: "wireguard", + } + if err := netlink.LinkAdd(wgLink); err != nil { + log.WithError(err).Error("cannot create link") + return nil, err + } + } else { + log.Infof("using %s to create link", cfg.WgBin) + output, err := exec.Command(cfg.WgBin, iface).CombinedOutput() + if err != nil { + log.WithError(err).WithField("output", string(output)).Error("cannot create link") + return nil, err + } } link, err = netlink.LinkByName(iface)