diff --git a/config/config.go b/config/config.go index 9bfac8a..8d834db 100644 --- a/config/config.go +++ b/config/config.go @@ -32,6 +32,13 @@ const ( SecretModeTLS ) +type PreferIP uint8 + +const ( + PreferIPv4 PreferIP = iota + PreferIPv6 +) + const SimpleSecretLength = 16 type OptionType uint8 @@ -40,6 +47,8 @@ const ( OptionTypeDebug OptionType = iota OptionTypeVerbose + OptionTypePreferIP + OptionTypeBind OptionTypePublicIPv4 OptionTypePublicIPv6 @@ -86,6 +95,7 @@ type Config struct { Debug bool `json:"debug"` Verbose bool `json:"verbose"` SecretMode SecretMode `json:"secret_mode"` + PreferIP PreferIP `json:"prefer_ip"` Secret []byte `json:"secret"` AdTag []byte `json:"adtag"` @@ -105,6 +115,16 @@ func Init(options ...Opt) error { // nolint: gocyclo, funlen C.Debug = opt.Value.(bool) case OptionTypeVerbose: C.Verbose = opt.Value.(bool) + case OptionTypePreferIP: + value := opt.Value.(string) + switch value { + case "ipv4": + C.PreferIP = PreferIPv4 + case "ipv6": + C.PreferIP = PreferIPv6 + default: + return fmt.Errorf("incorrect direct IP mode %s", value) + } case OptionTypeBind: C.Bind = opt.Value.(*net.TCPAddr) case OptionTypePublicIPv4: diff --git a/main.go b/main.go index c8ffc1b..f500882 100644 --- a/main.go +++ b/main.go @@ -43,6 +43,11 @@ var ( Short('v'). Envar("MTG_VERBOSE"). Bool() + runPreferIP = runCommand.Flag("prefer-ip", + "Prefer this IP protocol if possible. Valid options are 'ipv4' and 'ipv6'"). + Envar("MTG_PREFER_DIRECT_IP"). + Default("ipv6"). + Enum("ipv4", "ipv6") runBind = runCommand.Flag("bind", "Host:Port to bind proxy to."). Short('b'). @@ -130,6 +135,7 @@ func main() { err := config.Init( config.Opt{Option: config.OptionTypeDebug, Value: *runDebug}, config.Opt{Option: config.OptionTypeVerbose, Value: *runVerbose}, + config.Opt{Option: config.OptionTypePreferIP, Value: *runPreferIP}, config.Opt{Option: config.OptionTypeBind, Value: *runBind}, config.Opt{Option: config.OptionTypePublicIPv4, Value: *runPublicIPv4}, config.Opt{Option: config.OptionTypePublicIPv6, Value: *runPublicIPv6},