Skip to content

Commit

Permalink
feat: support selecting wireguard-go binary
Browse files Browse the repository at this point in the history
  • Loading branch information
BaiMeow committed Sep 26, 2023
1 parent 5a0a355 commit d29d5e4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
},
}

Expand Down
5 changes: 5 additions & 0 deletions quick/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down
30 changes: 20 additions & 10 deletions quick/wg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d29d5e4

Please sign in to comment.