renames wgo to userspace flag
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
Marvin Steadfast 2021-01-25 11:06:27 +01:00
parent 367007267f
commit 08f83d4946
2 changed files with 24 additions and 19 deletions

View File

@ -22,7 +22,7 @@ var (
verbose bool
protocol int
metric int
wgo bool
userspace bool
)
var rootCmd = &cobra.Command{
@ -54,7 +54,7 @@ var upCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
c, log := loadConfig(args[0])
if err := wgquick.Up(c, iface, wgo, log); err != nil {
if err := wgquick.Up(c, iface, userspace, log); err != nil {
logrus.WithError(err).Errorln("cannot up interface")
}
},
@ -78,7 +78,7 @@ var syncCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
c, log := loadConfig(args[0])
if err := wgquick.Sync(c, iface, wgo, log); err != nil {
if err := wgquick.Sync(c, iface, userspace, log); err != nil {
logrus.WithError(err).Errorln("cannot sync interface")
}
},
@ -144,7 +144,12 @@ func init() {
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose")
rootCmd.PersistentFlags().IntVarP(&protocol, "route-protocol", "p", 0, "route protocol to use for our routes")
rootCmd.PersistentFlags().IntVarP(&metric, "route-metric", "m", 0, "route metric to use for our routes")
rootCmd.PersistentFlags().BoolVarP(&wgo, "wgo", "w", false, "enforce wireguard-go")
rootCmd.PersistentFlags().BoolVarP(
&userspace,
"userspace", "u",
false,
"enforce userspace implementation of wireguard",
)
rootCmd.AddCommand(upCmd)
rootCmd.AddCommand(downCmd)
rootCmd.AddCommand(syncCmd)

View File

@ -20,8 +20,8 @@ import (
"golang.zx2c4.com/wireguard/wgctrl"
)
// wgGo runs a embedded wireguard-go for interface creation.
func wgGo(iface string) error {
// userspace runs a embedded wireguard-go for interface creation.
func userspace(iface string) error {
wgob, err := assets.Asset("third_party/wireguard-go/wireguard-go")
if err != nil {
return fmt.Errorf("cannot get wireguard-go: %w", err)
@ -41,7 +41,7 @@ func wgGo(iface string) error {
}
// Up sets and configures the wg interface. Mostly equivalent to `wg-quick up iface`.
func Up(cfg *Config, iface string, wgo bool, logger logrus.FieldLogger) error {
func Up(cfg *Config, iface string, uspace bool, logger logrus.FieldLogger) error {
log := logger.WithField("iface", iface)
_, err := netlink.LinkByName(iface)
@ -67,7 +67,7 @@ func Up(cfg *Config, iface string, wgo bool, logger logrus.FieldLogger) error {
log.Infoln("applied pre-up command")
}
if err := Sync(cfg, iface, wgo, logger); err != nil {
if err := Sync(cfg, iface, uspace, logger); err != nil {
return err
}
@ -156,10 +156,10 @@ func execSh(command string, iface string, log logrus.FieldLogger, stdin ...strin
// * SyncWireguardDevice --> configures allowedIP & other wireguard specific settings.
// * SyncAddress --> synces linux addresses bounded to this interface.
// * SyncRoutes --> synces all allowedIP routes to route to this interface.
func Sync(cfg *Config, iface string, wgo bool, logger logrus.FieldLogger) error {
func Sync(cfg *Config, iface string, uspace bool, logger logrus.FieldLogger) error {
log := logger.WithField("iface", iface)
link, err := SyncLink(cfg, iface, wgo, log)
link, err := SyncLink(cfg, iface, uspace, log)
if err != nil {
log.WithError(err).Errorln("cannot sync wireguard link")
@ -223,7 +223,7 @@ func SyncWireguardDevice(cfg *Config, link netlink.Link, log logrus.FieldLogger)
// SyncLink synces link state with the config.
// It does not sync Wireguard settings, just makes sure the device is up and type wireguard.
func SyncLink(cfg *Config, iface string, wgo bool, log logrus.FieldLogger) (netlink.Link, error) {
func SyncLink(cfg *Config, iface string, uspace bool, log logrus.FieldLogger) (netlink.Link, error) {
link, err := netlink.LinkByName(iface)
// nolint: nestif
if err != nil {
@ -243,20 +243,20 @@ func SyncLink(cfg *Config, iface string, wgo bool, log logrus.FieldLogger) (netl
LinkType: "wireguard",
}
if wgo {
if uspace {
log.Info("enforcing embedded wireguard-go")
if err := wgGo(iface); err != nil {
if err := userspace(iface); err != nil {
log.WithError(err).Errorf("cannot create link through wireguard-go: %s", err.Error())
return nil, fmt.Errorf("cannot create link: %w", err)
}
} else if !wgo {
} else if !uspace {
if err := netlink.LinkAdd(wgLink); err != nil {
log.WithError(err).Errorf("cannot create link: %s", err.Error())
log.Info("trying to use embedded wireguard-go")
if err := wgGo(iface); err != nil {
if err := userspace(iface); err != nil {
log.WithError(err).Errorf("cannot create link through wireguard-go: %s", err.Error())
return nil, fmt.Errorf("cannot create link: %w", err)